4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 1990 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
32 #include <rpcsvc/ypclnt.h>
43 static struct gradata
{
53 } *minuslist
; /* list of - items */
54 struct group_adjunct interpgra
;
55 char interpline
[BUFSIZ
+1];
56 struct group_adjunct
*sv
;
57 } *gradata
, *_gradata(void);
59 static char *GROUPADJ
= "/etc/security/group.adjunct";
61 static struct group_adjunct
*interpret(char *, int);
62 static struct group_adjunct
*interpretwithsave(char *, int,
63 struct group_adjunct
*);
64 static struct group_adjunct
*save(struct group_adjunct
*);
65 static struct group_adjunct
*getnamefromyellow(char *,
66 struct group_adjunct
*);
67 static int onminuslist(struct group_adjunct
*);
68 static int matchname(char [], struct group_adjunct
**, char *);
69 static void freeminuslist(void);
70 static void getnextfromyellow(void);
71 static void getfirstfromyellow(void);
72 static void addtominuslist(char *);
75 static struct gradata
*
78 struct gradata
*g
= gradata
;
81 g
= (struct gradata
*)calloc(1, sizeof (struct gradata
));
87 struct group_adjunct
*
90 struct gradata
*g
= _gradata();
91 struct group_adjunct
*gra
;
99 while (fgets(line
, BUFSIZ
, g
->grfa
) != NULL
) {
100 if ((gra
= interpret(line
, strlen(line
))) == NULL
)
102 if (matchname(line
, &gra
, name
)) {
114 struct gradata
*g
= _gradata();
118 if (g
->domain
== NULL
)
119 (void) yp_get_default_domain(&g
->domain
);
121 g
->grfa
= fopen(GROUPADJ
, "r");
133 struct gradata
*g
= _gradata();
138 (void) fclose(g
->grfa
);
147 struct group_adjunct
*
150 char line1
[BUFSIZ
+1];
152 if(fgets(line1
, BUFSIZ
, f
) == NULL
)
154 return (interpret(line1
, strlen(line1
)));
158 grskip(char *p
, int c
)
160 while(*p
&& *p
!= c
&& *p
!= '\n') ++p
;
168 struct group_adjunct
*
171 struct gradata
*g
= _gradata();
172 char line1
[BUFSIZ
+1];
173 static struct group_adjunct
*savegra
;
174 struct group_adjunct
*gra
;
178 if (g
->domain
== NULL
) {
179 (void) yp_get_default_domain(&g
->domain
);
181 if(!g
->grfa
&& !(g
->grfa
= fopen(GROUPADJ
, "r")))
185 gra
= interpretwithsave(g
->yp
, g
->yplen
, savegra
);
190 if (onminuslist(gra
))
195 else if (fgets(line1
, BUFSIZ
, g
->grfa
) == NULL
)
197 if ((gra
= interpret(line1
, strlen(line1
))) == NULL
)
201 if (strcmp(gra
->gra_name
, "+") == 0) {
202 getfirstfromyellow();
207 * else look up this entry in NIS
210 gra
= getnamefromyellow(gra
->gra_name
+1, savegra
);
213 else if (onminuslist(gra
))
219 addtominuslist(gra
->gra_name
+1);
223 if (onminuslist(gra
))
231 static struct group_adjunct
*
232 interpret(char *val
, int len
)
234 struct gradata
*g
= _gradata();
239 strncpy(g
->interpline
, val
, len
);
241 g
->interpline
[len
] = '\n';
242 g
->interpline
[len
+1] = 0;
243 g
->interpgra
.gra_name
= p
;
245 if (strcmp(g
->interpgra
.gra_name
, "+") == 0) {
246 /* we are going to the NIS - fix the
247 * rest of the struct as much as is needed
249 g
->interpgra
.gra_passwd
= "";
250 return (&g
->interpgra
);
252 g
->interpgra
.gra_passwd
= p
;
253 while(*p
&& *p
!= '\n') p
++;
255 return (&g
->interpgra
);
261 struct gradata
*g
= _gradata();
266 for (ls
= g
->minuslist
; ls
!= NULL
; ls
= ls
->nxt
) {
273 static struct group_adjunct
*
274 interpretwithsave(char *val
, int len
, struct group_adjunct
*savegra
)
276 struct gradata
*g
= _gradata();
277 struct group_adjunct
*gra
;
281 if ((gra
= interpret(val
, len
)) == NULL
)
283 if (savegra
->gra_passwd
&& *savegra
->gra_passwd
)
284 gra
->gra_passwd
= savegra
->gra_passwd
;
289 onminuslist(struct group_adjunct
*gra
)
291 struct gradata
*g
= _gradata();
298 for (ls
= g
->minuslist
; ls
!= NULL
; ls
= ls
->nxt
)
299 if (strcmp(ls
->name
, nm
) == 0)
305 getnextfromyellow(void)
307 struct gradata
*g
= _gradata();
314 if (reason
= yp_next(g
->domain
, "group.adjunct.byname",
315 g
->oldyp
, g
->oldyplen
, &key
, &keylen
,
316 &g
->yp
, &g
->yplen
)) {
318 fprintf(stderr
, "reason yp_next failed is %d\n", reason
);
325 g
->oldyplen
= keylen
;
329 getfirstfromyellow(void)
331 struct gradata
*g
= _gradata();
338 if (reason
= yp_first(g
->domain
, "group.adjunct.byname",
339 &key
, &keylen
, &g
->yp
, &g
->yplen
)) {
341 fprintf(stderr
, "reason yp_first failed is %d\n", reason
);
348 g
->oldyplen
= keylen
;
351 static struct group_adjunct
*
352 getnamefromyellow(char *name
, struct group_adjunct
*savegra
)
354 struct gradata
*g
= _gradata();
355 struct group_adjunct
*gra
;
362 if (reason
= yp_match(g
->domain
, "group.adjunct.byname",
363 name
, strlen(name
), &val
, &vallen
)) {
365 fprintf(stderr
, "reason yp_next failed is %d\n", reason
);
370 gra
= interpret(val
, vallen
);
374 if (savegra
->gra_passwd
&& *savegra
->gra_passwd
)
375 gra
->gra_passwd
= savegra
->gra_passwd
;
381 addtominuslist(char *name
)
383 struct gradata
*g
= _gradata();
389 ls
= (struct list
*)malloc(sizeof(struct list
));
390 buf
= (char *)malloc(strlen(name
) + 1);
391 (void) strcpy(buf
, name
);
393 ls
->nxt
= g
->minuslist
;
398 * save away psswd field, which is the only
399 * one which can be specified in a local + entry to override the
402 static struct group_adjunct
*
403 save(struct group_adjunct
*gra
)
405 struct gradata
*g
= _gradata();
410 * free up stuff from last time around
413 free(g
->sv
->gra_passwd
);
416 g
->sv
= (struct group_adjunct
*)calloc(1, sizeof(struct group_adjunct
));
417 g
->sv
->gra_passwd
= (char *)malloc(strlen(gra
->gra_passwd
) + 1);
418 (void) strcpy(g
->sv
->gra_passwd
, gra
->gra_passwd
);
423 matchname(char line1
[], struct group_adjunct
**grap
, char *name
)
425 struct group_adjunct
*savegra
;
426 struct group_adjunct
*gra
= *grap
;
430 if (strcmp(gra
->gra_name
, "+") == 0) {
432 gra
= getnamefromyellow(name
, savegra
);
440 if (strcmp(gra
->gra_name
+1, name
) == 0) {
442 gra
= getnamefromyellow(gra
->gra_name
+1, savegra
);
452 if (strcmp(gra
->gra_name
+1, name
) == 0) {
458 if (strcmp(gra
->gra_name
, name
) == 0)