17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* 237c478bd9Sstevel@tonic-gate * Copyright 1990 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 27*5d54f3d8Smuffin #pragma ident "%Z%%M% %I% %E% SMI" 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #include <stdio.h> 307c478bd9Sstevel@tonic-gate #include <grp.h> 317c478bd9Sstevel@tonic-gate #include <grpadj.h> 327c478bd9Sstevel@tonic-gate #include <rpcsvc/ypclnt.h> 33*5d54f3d8Smuffin #include <string.h> 34*5d54f3d8Smuffin #include <malloc.h> 357c478bd9Sstevel@tonic-gate 367c478bd9Sstevel@tonic-gate extern void rewind(); 377c478bd9Sstevel@tonic-gate extern long strtol(); 387c478bd9Sstevel@tonic-gate extern int fclose(); 397c478bd9Sstevel@tonic-gate 40*5d54f3d8Smuffin void setgraent(void); 41*5d54f3d8Smuffin void endgraent(void); 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate static struct gradata { 447c478bd9Sstevel@tonic-gate char *domain; 457c478bd9Sstevel@tonic-gate FILE *grfa; 467c478bd9Sstevel@tonic-gate char *yp; 477c478bd9Sstevel@tonic-gate int yplen; 487c478bd9Sstevel@tonic-gate char *oldyp; 497c478bd9Sstevel@tonic-gate int oldyplen; 507c478bd9Sstevel@tonic-gate struct list { 517c478bd9Sstevel@tonic-gate char *name; 527c478bd9Sstevel@tonic-gate struct list *nxt; 537c478bd9Sstevel@tonic-gate } *minuslist; /* list of - items */ 547c478bd9Sstevel@tonic-gate struct group_adjunct interpgra; 557c478bd9Sstevel@tonic-gate char interpline[BUFSIZ+1]; 567c478bd9Sstevel@tonic-gate struct group_adjunct *sv; 57*5d54f3d8Smuffin } *gradata, *_gradata(void); 587c478bd9Sstevel@tonic-gate 597c478bd9Sstevel@tonic-gate static char *GROUPADJ = "/etc/security/group.adjunct"; 60*5d54f3d8Smuffin 61*5d54f3d8Smuffin static struct group_adjunct *interpret(char *, int); 62*5d54f3d8Smuffin static struct group_adjunct *interpretwithsave(char *, int, 63*5d54f3d8Smuffin struct group_adjunct *); 64*5d54f3d8Smuffin static struct group_adjunct *save(struct group_adjunct *); 65*5d54f3d8Smuffin static struct group_adjunct *getnamefromyellow(char *, 66*5d54f3d8Smuffin struct group_adjunct *); 67*5d54f3d8Smuffin static int onminuslist(struct group_adjunct *); 68*5d54f3d8Smuffin static int matchname(char [], struct group_adjunct **, char *); 69*5d54f3d8Smuffin static void freeminuslist(void); 70*5d54f3d8Smuffin static void getnextfromyellow(void); 71*5d54f3d8Smuffin static void getfirstfromyellow(void); 72*5d54f3d8Smuffin static void addtominuslist(char *); 73*5d54f3d8Smuffin 747c478bd9Sstevel@tonic-gate 757c478bd9Sstevel@tonic-gate static struct gradata * 76*5d54f3d8Smuffin _gradata(void) 777c478bd9Sstevel@tonic-gate { 78*5d54f3d8Smuffin struct gradata *g = gradata; 797c478bd9Sstevel@tonic-gate 807c478bd9Sstevel@tonic-gate if (g == 0) { 817c478bd9Sstevel@tonic-gate g = (struct gradata *)calloc(1, sizeof (struct gradata)); 827c478bd9Sstevel@tonic-gate gradata = g; 837c478bd9Sstevel@tonic-gate } 847c478bd9Sstevel@tonic-gate return (g); 857c478bd9Sstevel@tonic-gate } 867c478bd9Sstevel@tonic-gate 877c478bd9Sstevel@tonic-gate struct group_adjunct * 88*5d54f3d8Smuffin getgranam(char *name) 897c478bd9Sstevel@tonic-gate { 90*5d54f3d8Smuffin struct gradata *g = _gradata(); 917c478bd9Sstevel@tonic-gate struct group_adjunct *gra; 927c478bd9Sstevel@tonic-gate char line[BUFSIZ+1]; 937c478bd9Sstevel@tonic-gate 947c478bd9Sstevel@tonic-gate setgraent(); 957c478bd9Sstevel@tonic-gate if (g == 0) 967c478bd9Sstevel@tonic-gate return (0); 977c478bd9Sstevel@tonic-gate if (!g->grfa) 98*5d54f3d8Smuffin return (NULL); 997c478bd9Sstevel@tonic-gate while (fgets(line, BUFSIZ, g->grfa) != NULL) { 1007c478bd9Sstevel@tonic-gate if ((gra = interpret(line, strlen(line))) == NULL) 1017c478bd9Sstevel@tonic-gate continue; 1027c478bd9Sstevel@tonic-gate if (matchname(line, &gra, name)) { 1037c478bd9Sstevel@tonic-gate endgraent(); 1047c478bd9Sstevel@tonic-gate return (gra); 1057c478bd9Sstevel@tonic-gate } 1067c478bd9Sstevel@tonic-gate } 1077c478bd9Sstevel@tonic-gate endgraent(); 1087c478bd9Sstevel@tonic-gate return (NULL); 1097c478bd9Sstevel@tonic-gate } 1107c478bd9Sstevel@tonic-gate 1117c478bd9Sstevel@tonic-gate void 112*5d54f3d8Smuffin setgraent(void) 1137c478bd9Sstevel@tonic-gate { 114*5d54f3d8Smuffin struct gradata *g = _gradata(); 1157c478bd9Sstevel@tonic-gate 1167c478bd9Sstevel@tonic-gate if (g == NULL) 1177c478bd9Sstevel@tonic-gate return; 1187c478bd9Sstevel@tonic-gate if (g->domain == NULL) 1197c478bd9Sstevel@tonic-gate (void) yp_get_default_domain(&g->domain); 1207c478bd9Sstevel@tonic-gate if (!g->grfa) 1217c478bd9Sstevel@tonic-gate g->grfa = fopen(GROUPADJ, "r"); 1227c478bd9Sstevel@tonic-gate else 1237c478bd9Sstevel@tonic-gate rewind(g->grfa); 1247c478bd9Sstevel@tonic-gate if (g->yp) 1257c478bd9Sstevel@tonic-gate free(g->yp); 1267c478bd9Sstevel@tonic-gate g->yp = NULL; 1277c478bd9Sstevel@tonic-gate freeminuslist(); 1287c478bd9Sstevel@tonic-gate } 1297c478bd9Sstevel@tonic-gate 1307c478bd9Sstevel@tonic-gate void 131*5d54f3d8Smuffin endgraent(void) 1327c478bd9Sstevel@tonic-gate { 133*5d54f3d8Smuffin struct gradata *g = _gradata(); 1347c478bd9Sstevel@tonic-gate 1357c478bd9Sstevel@tonic-gate if (g == 0) 1367c478bd9Sstevel@tonic-gate return; 1377c478bd9Sstevel@tonic-gate if (g->grfa) { 1387c478bd9Sstevel@tonic-gate (void) fclose(g->grfa); 1397c478bd9Sstevel@tonic-gate g->grfa = NULL; 1407c478bd9Sstevel@tonic-gate } 1417c478bd9Sstevel@tonic-gate if (g->yp) 1427c478bd9Sstevel@tonic-gate free(g->yp); 1437c478bd9Sstevel@tonic-gate g->yp = NULL; 1447c478bd9Sstevel@tonic-gate freeminuslist(); 1457c478bd9Sstevel@tonic-gate } 1467c478bd9Sstevel@tonic-gate 1477c478bd9Sstevel@tonic-gate struct group_adjunct * 148*5d54f3d8Smuffin fgetgraent(FILE *f) 1497c478bd9Sstevel@tonic-gate { 1507c478bd9Sstevel@tonic-gate char line1[BUFSIZ+1]; 1517c478bd9Sstevel@tonic-gate 1527c478bd9Sstevel@tonic-gate if(fgets(line1, BUFSIZ, f) == NULL) 1537c478bd9Sstevel@tonic-gate return (NULL); 1547c478bd9Sstevel@tonic-gate return (interpret(line1, strlen(line1))); 1557c478bd9Sstevel@tonic-gate } 1567c478bd9Sstevel@tonic-gate 1577c478bd9Sstevel@tonic-gate static char * 158*5d54f3d8Smuffin grskip(char *p, int c) 1597c478bd9Sstevel@tonic-gate { 1607c478bd9Sstevel@tonic-gate while(*p && *p != c && *p != '\n') ++p; 1617c478bd9Sstevel@tonic-gate if (*p == '\n') 1627c478bd9Sstevel@tonic-gate *p = '\0'; 1637c478bd9Sstevel@tonic-gate else if (*p != '\0') 1647c478bd9Sstevel@tonic-gate *p++ = '\0'; 1657c478bd9Sstevel@tonic-gate return (p); 1667c478bd9Sstevel@tonic-gate } 1677c478bd9Sstevel@tonic-gate 1687c478bd9Sstevel@tonic-gate struct group_adjunct * 169*5d54f3d8Smuffin getgraent(void) 1707c478bd9Sstevel@tonic-gate { 171*5d54f3d8Smuffin struct gradata *g = _gradata(); 1727c478bd9Sstevel@tonic-gate char line1[BUFSIZ+1]; 1737c478bd9Sstevel@tonic-gate static struct group_adjunct *savegra; 1747c478bd9Sstevel@tonic-gate struct group_adjunct *gra; 1757c478bd9Sstevel@tonic-gate 1767c478bd9Sstevel@tonic-gate if (g == 0) 1777c478bd9Sstevel@tonic-gate return (0); 1787c478bd9Sstevel@tonic-gate if (g->domain == NULL) { 1797c478bd9Sstevel@tonic-gate (void) yp_get_default_domain(&g->domain); 1807c478bd9Sstevel@tonic-gate } 1817c478bd9Sstevel@tonic-gate if(!g->grfa && !(g->grfa = fopen(GROUPADJ, "r"))) 1827c478bd9Sstevel@tonic-gate return (NULL); 1837c478bd9Sstevel@tonic-gate again: 1847c478bd9Sstevel@tonic-gate if (g->yp) { 1857c478bd9Sstevel@tonic-gate gra = interpretwithsave(g->yp, g->yplen, savegra); 1867c478bd9Sstevel@tonic-gate free(g->yp); 1877c478bd9Sstevel@tonic-gate if (gra == NULL) 1887c478bd9Sstevel@tonic-gate return (NULL); 1897c478bd9Sstevel@tonic-gate getnextfromyellow(); 1907c478bd9Sstevel@tonic-gate if (onminuslist(gra)) 1917c478bd9Sstevel@tonic-gate goto again; 1927c478bd9Sstevel@tonic-gate else 1937c478bd9Sstevel@tonic-gate return (gra); 1947c478bd9Sstevel@tonic-gate } 1957c478bd9Sstevel@tonic-gate else if (fgets(line1, BUFSIZ, g->grfa) == NULL) 1967c478bd9Sstevel@tonic-gate return (NULL); 1977c478bd9Sstevel@tonic-gate if ((gra = interpret(line1, strlen(line1))) == NULL) 1987c478bd9Sstevel@tonic-gate return (NULL); 1997c478bd9Sstevel@tonic-gate switch(line1[0]) { 2007c478bd9Sstevel@tonic-gate case '+': 2017c478bd9Sstevel@tonic-gate if (strcmp(gra->gra_name, "+") == 0) { 2027c478bd9Sstevel@tonic-gate getfirstfromyellow(); 2037c478bd9Sstevel@tonic-gate savegra = save(gra); 2047c478bd9Sstevel@tonic-gate goto again; 2057c478bd9Sstevel@tonic-gate } 2067c478bd9Sstevel@tonic-gate /* 2077c478bd9Sstevel@tonic-gate * else look up this entry in NIS 2087c478bd9Sstevel@tonic-gate */ 2097c478bd9Sstevel@tonic-gate savegra = save(gra); 2107c478bd9Sstevel@tonic-gate gra = getnamefromyellow(gra->gra_name+1, savegra); 2117c478bd9Sstevel@tonic-gate if (gra == NULL) 2127c478bd9Sstevel@tonic-gate goto again; 2137c478bd9Sstevel@tonic-gate else if (onminuslist(gra)) 2147c478bd9Sstevel@tonic-gate goto again; 2157c478bd9Sstevel@tonic-gate else 2167c478bd9Sstevel@tonic-gate return (gra); 2177c478bd9Sstevel@tonic-gate break; 2187c478bd9Sstevel@tonic-gate case '-': 2197c478bd9Sstevel@tonic-gate addtominuslist(gra->gra_name+1); 2207c478bd9Sstevel@tonic-gate goto again; 2217c478bd9Sstevel@tonic-gate break; 2227c478bd9Sstevel@tonic-gate default: 2237c478bd9Sstevel@tonic-gate if (onminuslist(gra)) 2247c478bd9Sstevel@tonic-gate goto again; 2257c478bd9Sstevel@tonic-gate return (gra); 2267c478bd9Sstevel@tonic-gate break; 2277c478bd9Sstevel@tonic-gate } 2287c478bd9Sstevel@tonic-gate /* NOTREACHED */ 2297c478bd9Sstevel@tonic-gate } 2307c478bd9Sstevel@tonic-gate 2317c478bd9Sstevel@tonic-gate static struct group_adjunct * 232*5d54f3d8Smuffin interpret(char *val, int len) 2337c478bd9Sstevel@tonic-gate { 234*5d54f3d8Smuffin struct gradata *g = _gradata(); 235*5d54f3d8Smuffin char *p; 2367c478bd9Sstevel@tonic-gate 2377c478bd9Sstevel@tonic-gate if (g == 0) 2387c478bd9Sstevel@tonic-gate return (0); 2397c478bd9Sstevel@tonic-gate strncpy(g->interpline, val, len); 2407c478bd9Sstevel@tonic-gate p = g->interpline; 2417c478bd9Sstevel@tonic-gate g->interpline[len] = '\n'; 2427c478bd9Sstevel@tonic-gate g->interpline[len+1] = 0; 2437c478bd9Sstevel@tonic-gate g->interpgra.gra_name = p; 2447c478bd9Sstevel@tonic-gate p = grskip(p,':'); 2457c478bd9Sstevel@tonic-gate if (strcmp(g->interpgra.gra_name, "+") == 0) { 2467c478bd9Sstevel@tonic-gate /* we are going to the NIS - fix the 2477c478bd9Sstevel@tonic-gate * rest of the struct as much as is needed 2487c478bd9Sstevel@tonic-gate */ 2497c478bd9Sstevel@tonic-gate g->interpgra.gra_passwd = ""; 2507c478bd9Sstevel@tonic-gate return (&g->interpgra); 2517c478bd9Sstevel@tonic-gate } 2527c478bd9Sstevel@tonic-gate g->interpgra.gra_passwd = p; 2537c478bd9Sstevel@tonic-gate while(*p && *p != '\n') p++; 2547c478bd9Sstevel@tonic-gate *p = '\0'; 2557c478bd9Sstevel@tonic-gate return (&g->interpgra); 2567c478bd9Sstevel@tonic-gate } 2577c478bd9Sstevel@tonic-gate 258*5d54f3d8Smuffin static void 259*5d54f3d8Smuffin freeminuslist(void) 260*5d54f3d8Smuffin { 261*5d54f3d8Smuffin struct gradata *g = _gradata(); 2627c478bd9Sstevel@tonic-gate struct list *ls; 2637c478bd9Sstevel@tonic-gate 2647c478bd9Sstevel@tonic-gate if (g == 0) 2657c478bd9Sstevel@tonic-gate return; 2667c478bd9Sstevel@tonic-gate for (ls = g->minuslist; ls != NULL; ls = ls->nxt) { 2677c478bd9Sstevel@tonic-gate free(ls->name); 2687c478bd9Sstevel@tonic-gate free(ls); 2697c478bd9Sstevel@tonic-gate } 2707c478bd9Sstevel@tonic-gate g->minuslist = NULL; 2717c478bd9Sstevel@tonic-gate } 2727c478bd9Sstevel@tonic-gate 2737c478bd9Sstevel@tonic-gate static struct group_adjunct * 274*5d54f3d8Smuffin interpretwithsave(char *val, int len, struct group_adjunct *savegra) 2757c478bd9Sstevel@tonic-gate { 276*5d54f3d8Smuffin struct gradata *g = _gradata(); 2777c478bd9Sstevel@tonic-gate struct group_adjunct *gra; 2787c478bd9Sstevel@tonic-gate 2797c478bd9Sstevel@tonic-gate if (g == 0) 2807c478bd9Sstevel@tonic-gate return (0); 2817c478bd9Sstevel@tonic-gate if ((gra = interpret(val, len)) == NULL) 2827c478bd9Sstevel@tonic-gate return (NULL); 2837c478bd9Sstevel@tonic-gate if (savegra->gra_passwd && *savegra->gra_passwd) 2847c478bd9Sstevel@tonic-gate gra->gra_passwd = savegra->gra_passwd; 2857c478bd9Sstevel@tonic-gate return (gra); 2867c478bd9Sstevel@tonic-gate } 2877c478bd9Sstevel@tonic-gate 288*5d54f3d8Smuffin static int 289*5d54f3d8Smuffin onminuslist(struct group_adjunct *gra) 2907c478bd9Sstevel@tonic-gate { 291*5d54f3d8Smuffin struct gradata *g = _gradata(); 2927c478bd9Sstevel@tonic-gate struct list *ls; 293*5d54f3d8Smuffin char *nm; 2947c478bd9Sstevel@tonic-gate 2957c478bd9Sstevel@tonic-gate if (g == 0) 296*5d54f3d8Smuffin return (0); 2977c478bd9Sstevel@tonic-gate nm = gra->gra_name; 2987c478bd9Sstevel@tonic-gate for (ls = g->minuslist; ls != NULL; ls = ls->nxt) 2997c478bd9Sstevel@tonic-gate if (strcmp(ls->name, nm) == 0) 300*5d54f3d8Smuffin return (1); 301*5d54f3d8Smuffin return (0); 3027c478bd9Sstevel@tonic-gate } 3037c478bd9Sstevel@tonic-gate 304*5d54f3d8Smuffin static void 305*5d54f3d8Smuffin getnextfromyellow(void) 3067c478bd9Sstevel@tonic-gate { 307*5d54f3d8Smuffin struct gradata *g = _gradata(); 3087c478bd9Sstevel@tonic-gate int reason; 3097c478bd9Sstevel@tonic-gate char *key = NULL; 3107c478bd9Sstevel@tonic-gate int keylen; 3117c478bd9Sstevel@tonic-gate 3127c478bd9Sstevel@tonic-gate if (g == 0) 3137c478bd9Sstevel@tonic-gate return; 3147c478bd9Sstevel@tonic-gate if (reason = yp_next(g->domain, "group.adjunct.byname", 3157c478bd9Sstevel@tonic-gate g->oldyp, g->oldyplen, &key, &keylen, 3167c478bd9Sstevel@tonic-gate &g->yp, &g->yplen)) { 3177c478bd9Sstevel@tonic-gate #ifdef DEBUG 3187c478bd9Sstevel@tonic-gate fprintf(stderr, "reason yp_next failed is %d\n", reason); 3197c478bd9Sstevel@tonic-gate #endif 3207c478bd9Sstevel@tonic-gate g->yp = NULL; 3217c478bd9Sstevel@tonic-gate } 3227c478bd9Sstevel@tonic-gate if (g->oldyp) 3237c478bd9Sstevel@tonic-gate free(g->oldyp); 3247c478bd9Sstevel@tonic-gate g->oldyp = key; 3257c478bd9Sstevel@tonic-gate g->oldyplen = keylen; 3267c478bd9Sstevel@tonic-gate } 3277c478bd9Sstevel@tonic-gate 328*5d54f3d8Smuffin static void 329*5d54f3d8Smuffin getfirstfromyellow(void) 3307c478bd9Sstevel@tonic-gate { 331*5d54f3d8Smuffin struct gradata *g = _gradata(); 3327c478bd9Sstevel@tonic-gate int reason; 3337c478bd9Sstevel@tonic-gate char *key = NULL; 3347c478bd9Sstevel@tonic-gate int keylen; 3357c478bd9Sstevel@tonic-gate 3367c478bd9Sstevel@tonic-gate if (g == 0) 3377c478bd9Sstevel@tonic-gate return; 3387c478bd9Sstevel@tonic-gate if (reason = yp_first(g->domain, "group.adjunct.byname", 3397c478bd9Sstevel@tonic-gate &key, &keylen, &g->yp, &g->yplen)) { 3407c478bd9Sstevel@tonic-gate #ifdef DEBUG 3417c478bd9Sstevel@tonic-gate fprintf(stderr, "reason yp_first failed is %d\n", reason); 3427c478bd9Sstevel@tonic-gate #endif 3437c478bd9Sstevel@tonic-gate g->yp = NULL; 3447c478bd9Sstevel@tonic-gate } 3457c478bd9Sstevel@tonic-gate if (g->oldyp) 3467c478bd9Sstevel@tonic-gate free(g->oldyp); 3477c478bd9Sstevel@tonic-gate g->oldyp = key; 3487c478bd9Sstevel@tonic-gate g->oldyplen = keylen; 3497c478bd9Sstevel@tonic-gate } 3507c478bd9Sstevel@tonic-gate 3517c478bd9Sstevel@tonic-gate static struct group_adjunct * 352*5d54f3d8Smuffin getnamefromyellow(char *name, struct group_adjunct *savegra) 3537c478bd9Sstevel@tonic-gate { 354*5d54f3d8Smuffin struct gradata *g = _gradata(); 3557c478bd9Sstevel@tonic-gate struct group_adjunct *gra; 3567c478bd9Sstevel@tonic-gate int reason; 3577c478bd9Sstevel@tonic-gate char *val; 3587c478bd9Sstevel@tonic-gate int vallen; 3597c478bd9Sstevel@tonic-gate 3607c478bd9Sstevel@tonic-gate if (g == 0) 3617c478bd9Sstevel@tonic-gate return (NULL); 3627c478bd9Sstevel@tonic-gate if (reason = yp_match(g->domain, "group.adjunct.byname", 3637c478bd9Sstevel@tonic-gate name, strlen(name), &val, &vallen)) { 3647c478bd9Sstevel@tonic-gate #ifdef DEBUG 3657c478bd9Sstevel@tonic-gate fprintf(stderr, "reason yp_next failed is %d\n", reason); 3667c478bd9Sstevel@tonic-gate #endif 367*5d54f3d8Smuffin return (NULL); 3687c478bd9Sstevel@tonic-gate } 3697c478bd9Sstevel@tonic-gate else { 3707c478bd9Sstevel@tonic-gate gra = interpret(val, vallen); 3717c478bd9Sstevel@tonic-gate free(val); 3727c478bd9Sstevel@tonic-gate if (gra == NULL) 373*5d54f3d8Smuffin return (NULL); 3747c478bd9Sstevel@tonic-gate if (savegra->gra_passwd && *savegra->gra_passwd) 3757c478bd9Sstevel@tonic-gate gra->gra_passwd = savegra->gra_passwd; 376*5d54f3d8Smuffin return (gra); 3777c478bd9Sstevel@tonic-gate } 3787c478bd9Sstevel@tonic-gate } 3797c478bd9Sstevel@tonic-gate 380*5d54f3d8Smuffin static void 381*5d54f3d8Smuffin addtominuslist(char *name) 3827c478bd9Sstevel@tonic-gate { 383*5d54f3d8Smuffin struct gradata *g = _gradata(); 3847c478bd9Sstevel@tonic-gate struct list *ls; 3857c478bd9Sstevel@tonic-gate char *buf; 3867c478bd9Sstevel@tonic-gate 3877c478bd9Sstevel@tonic-gate if (g == 0) 3887c478bd9Sstevel@tonic-gate return; 3897c478bd9Sstevel@tonic-gate ls = (struct list *)malloc(sizeof(struct list)); 3907c478bd9Sstevel@tonic-gate buf = (char *)malloc(strlen(name) + 1); 3917c478bd9Sstevel@tonic-gate (void) strcpy(buf, name); 3927c478bd9Sstevel@tonic-gate ls->name = buf; 3937c478bd9Sstevel@tonic-gate ls->nxt = g->minuslist; 3947c478bd9Sstevel@tonic-gate g->minuslist = ls; 3957c478bd9Sstevel@tonic-gate } 3967c478bd9Sstevel@tonic-gate 3977c478bd9Sstevel@tonic-gate /* 3987c478bd9Sstevel@tonic-gate * save away psswd field, which is the only 3997c478bd9Sstevel@tonic-gate * one which can be specified in a local + entry to override the 4007c478bd9Sstevel@tonic-gate * value in the NIS 4017c478bd9Sstevel@tonic-gate */ 4027c478bd9Sstevel@tonic-gate static struct group_adjunct * 403*5d54f3d8Smuffin save(struct group_adjunct *gra) 4047c478bd9Sstevel@tonic-gate { 405*5d54f3d8Smuffin struct gradata *g = _gradata(); 4067c478bd9Sstevel@tonic-gate 4077c478bd9Sstevel@tonic-gate if (g == 0) 408*5d54f3d8Smuffin return (0); 4097c478bd9Sstevel@tonic-gate /* 4107c478bd9Sstevel@tonic-gate * free up stuff from last time around 4117c478bd9Sstevel@tonic-gate */ 4127c478bd9Sstevel@tonic-gate if (g->sv) { 4137c478bd9Sstevel@tonic-gate free(g->sv->gra_passwd); 4147c478bd9Sstevel@tonic-gate free(g->sv); 4157c478bd9Sstevel@tonic-gate } 4167c478bd9Sstevel@tonic-gate g->sv = (struct group_adjunct *)calloc(1, sizeof(struct group_adjunct)); 4177c478bd9Sstevel@tonic-gate g->sv->gra_passwd = (char *)malloc(strlen(gra->gra_passwd) + 1); 4187c478bd9Sstevel@tonic-gate (void) strcpy(g->sv->gra_passwd, gra->gra_passwd); 419*5d54f3d8Smuffin return (g->sv); 4207c478bd9Sstevel@tonic-gate } 4217c478bd9Sstevel@tonic-gate 422*5d54f3d8Smuffin static int 423*5d54f3d8Smuffin matchname(char line1[], struct group_adjunct **grap, char *name) 4247c478bd9Sstevel@tonic-gate { 4257c478bd9Sstevel@tonic-gate struct group_adjunct *savegra; 4267c478bd9Sstevel@tonic-gate struct group_adjunct *gra = *grap; 4277c478bd9Sstevel@tonic-gate 4287c478bd9Sstevel@tonic-gate switch (line1[0]) { 4297c478bd9Sstevel@tonic-gate case '+': 4307c478bd9Sstevel@tonic-gate if (strcmp(gra->gra_name, "+") == 0) { 4317c478bd9Sstevel@tonic-gate savegra = save(gra); 4327c478bd9Sstevel@tonic-gate gra = getnamefromyellow(name, savegra); 4337c478bd9Sstevel@tonic-gate if (gra) { 4347c478bd9Sstevel@tonic-gate *grap = gra; 435*5d54f3d8Smuffin return (1); 4367c478bd9Sstevel@tonic-gate } 4377c478bd9Sstevel@tonic-gate else 438*5d54f3d8Smuffin return (0); 4397c478bd9Sstevel@tonic-gate } 4407c478bd9Sstevel@tonic-gate if (strcmp(gra->gra_name+1, name) == 0) { 4417c478bd9Sstevel@tonic-gate savegra = save(gra); 4427c478bd9Sstevel@tonic-gate gra = getnamefromyellow(gra->gra_name+1, savegra); 4437c478bd9Sstevel@tonic-gate if (gra) { 4447c478bd9Sstevel@tonic-gate *grap = gra; 445*5d54f3d8Smuffin return (1); 4467c478bd9Sstevel@tonic-gate } 4477c478bd9Sstevel@tonic-gate else 448*5d54f3d8Smuffin return (0); 4497c478bd9Sstevel@tonic-gate } 4507c478bd9Sstevel@tonic-gate break; 4517c478bd9Sstevel@tonic-gate case '-': 4527c478bd9Sstevel@tonic-gate if (strcmp(gra->gra_name+1, name) == 0) { 4537c478bd9Sstevel@tonic-gate *grap = NULL; 454*5d54f3d8Smuffin return (1); 4557c478bd9Sstevel@tonic-gate } 4567c478bd9Sstevel@tonic-gate break; 4577c478bd9Sstevel@tonic-gate default: 4587c478bd9Sstevel@tonic-gate if (strcmp(gra->gra_name, name) == 0) 459*5d54f3d8Smuffin return (1); 4607c478bd9Sstevel@tonic-gate } 461*5d54f3d8Smuffin return (0); 4627c478bd9Sstevel@tonic-gate } 463