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 1991 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
31 #include <sys/types.h>
32 #include <sys/label.h>
33 #include <sys/audit.h>
36 #include <rpcsvc/ypclnt.h>
47 static struct _pwajunk
{
48 struct passwd _NULLPW
;
58 struct passwd _interppasswd
;
59 struct passwd_adjunct _apwadj
;
60 char _interpline
[BUFSIZ
+1];
62 } *__pwajunk
, *_pwajunk(void);
64 #define NULLPW (_pwa->_NULLPW)
65 #define pwfadj (_pwa->_pwfadj)
66 #define yp (_pwa->_yp)
67 #define yplen (_pwa->_yplen)
68 #define oldyp (_pwa->_oldyp)
69 #define oldyplen (_pwa->_oldyplen)
70 #define minuslist (_pwa->_minuslist)
71 #define interppasswd (_pwa->_interppasswd)
72 #define apwadj (_pwa->_apwadj)
73 #define interpline (_pwa->_interpline)
74 #define domain (_pwa->_domain)
76 static char *PASSWDADJ
= "/etc/security/passwd.adjunct";
78 static struct passwd_adjunct
*interpret(char *, int);
79 static struct passwd_adjunct
*interpretwithsave(char *, int,
80 struct passwd_adjunct
*);
81 static struct passwd_adjunct
*save(struct passwd_adjunct
*);
82 static struct passwd_adjunct
*getnamefromyellow(char *,
83 struct passwd_adjunct
*);
84 static int matchname(char [], struct passwd_adjunct
**, char *);
85 static int onminuslist(struct passwd_adjunct
*);
86 static void getnextfromyellow(void);
87 static void getfirstfromyellow(void);
88 static void freeminuslist(void);
89 static void addtominuslist(char *);
93 static struct _pwajunk
*
98 __pwajunk
= (struct _pwajunk
*)calloc(1, sizeof (*__pwajunk
));
102 struct passwd_adjunct
*
103 getpwanam(char *name
)
105 struct _pwajunk
*_pwa
= _pwajunk();
106 struct passwd_adjunct
*pwadj
;
114 while (fgets(line
, BUFSIZ
, pwfadj
) != NULL
) {
115 if ((pwadj
= interpret(line
, strlen(line
))) == NULL
)
117 if (matchname(line
, &pwadj
, name
)) {
130 struct _pwajunk
*_pwa
= _pwajunk();
134 if (domain
== NULL
) {
135 (void) yp_get_default_domain(&domain
);
138 pwfadj
= fopen(PASSWDADJ
, "r");
152 struct _pwajunk
*_pwa
= _pwajunk();
156 if (pwfadj
!= NULL
) {
157 (void) fclose(pwfadj
);
169 struct passwd_adjunct
*
172 struct _pwajunk
*_pwa
= _pwajunk();
174 static struct passwd_adjunct
*savepwadj
;
175 struct passwd_adjunct
*pwadj
;
182 if (domain
== NULL
) {
183 (void) yp_get_default_domain(&domain
);
185 if (pwfadj
== NULL
&& (pwfadj
= fopen(PASSWDADJ
, "r")) == NULL
) {
191 pwadj
= interpretwithsave(yp
, yplen
, savepwadj
);
196 if (!onminuslist(pwadj
)) {
199 } else if (getnetgrent(&mach
,&user
,&dom
)) {
201 pwadj
= getnamefromyellow(user
, savepwadj
);
202 if (pwadj
!= NULL
&& !onminuslist(pwadj
)) {
208 if (fgets(line
, BUFSIZ
, pwfadj
) == NULL
) {
211 if ((pwadj
= interpret(line
, strlen(line
))) == NULL
)
215 if (strcmp(pwadj
->pwa_name
, "+") == 0) {
216 getfirstfromyellow();
217 savepwadj
= save(pwadj
);
218 } else if (line
[1] == '@') {
219 savepwadj
= save(pwadj
);
220 if (innetgr(pwadj
->pwa_name
+2,(char *) NULL
,"*",domain
)) {
221 /* include the whole NIS database */
222 getfirstfromyellow();
224 setnetgrent(pwadj
->pwa_name
+2);
228 * else look up this entry in NIS
230 savepwadj
= save(pwadj
);
231 pwadj
= getnamefromyellow(pwadj
->pwa_name
+1, savepwadj
);
232 if (pwadj
!= NULL
&& !onminuslist(pwadj
)) {
238 if (line
[1] == '@') {
239 if (innetgr(pwadj
->pwa_name
+2,(char *) NULL
,"*",domain
)) {
240 /* everybody was subtracted */
243 setnetgrent(pwadj
->pwa_name
+2);
244 while (getnetgrent(&mach
,&user
,&dom
)) {
246 addtominuslist(user
);
251 addtominuslist(pwadj
->pwa_name
+1);
255 if (!onminuslist(pwadj
)) {
265 matchname(char line1
[], struct passwd_adjunct
**pwadjp
, char *name
)
267 struct _pwajunk
*_pwa
= _pwajunk();
268 struct passwd_adjunct
*savepwadj
;
269 struct passwd_adjunct
*pwadj
= *pwadjp
;
275 if (strcmp(pwadj
->pwa_name
, "+") == 0) {
276 savepwadj
= save(pwadj
);
277 pwadj
= getnamefromyellow(name
, savepwadj
);
285 if (line1
[1] == '@') {
286 if (innetgr(pwadj
->pwa_name
+2,(char *) NULL
,name
,domain
)) {
287 savepwadj
= save(pwadj
);
288 pwadj
= getnamefromyellow(name
,savepwadj
);
296 if (strcmp(pwadj
->pwa_name
+1, name
) == 0) {
297 savepwadj
= save(pwadj
);
298 pwadj
= getnamefromyellow(pwadj
->pwa_name
+1, savepwadj
);
308 if (line1
[1] == '@') {
309 if (innetgr(pwadj
->pwa_name
+2,(char *) NULL
,name
,domain
)) {
314 else if (strcmp(pwadj
->pwa_name
+1, name
) == 0) {
320 if (strcmp(pwadj
->pwa_name
, name
) == 0)
327 getnextfromyellow(void)
329 struct _pwajunk
*_pwa
= _pwajunk();
336 reason
= yp_next(domain
, "passwd_adjunct",oldyp
, oldyplen
, &key
337 ,&keylen
,&yp
,&yplen
);
340 fprintf(stderr
, "reason yp_next failed is %d\n", reason
);
351 getfirstfromyellow(void)
353 struct _pwajunk
*_pwa
= _pwajunk();
360 reason
= yp_first(domain
, "passwd_adjunct", &key
, &keylen
, &yp
, &yplen
);
363 fprintf(stderr
, "reason yp_first failed is %d\n", reason
);
373 static struct passwd_adjunct
*
374 getnamefromyellow(char *name
, struct passwd_adjunct
*savepwadj
)
376 struct _pwajunk
*_pwa
= _pwajunk();
377 struct passwd_adjunct
*pwadj
;
384 reason
= yp_match(domain
, "passwd.adjunct.byname", name
, strlen(name
)
388 fprintf(stderr
, "reason yp_match failed is %d\n", reason
);
392 pwadj
= interpret(val
, vallen
);
396 if (savepwadj
->pwa_passwd
&& *savepwadj
->pwa_passwd
)
397 pwadj
->pwa_passwd
= savepwadj
->pwa_passwd
;
402 static struct passwd_adjunct
*
403 interpretwithsave(char *val
, int len
, struct passwd_adjunct
*savepwadj
)
405 struct _pwajunk
*_pwa
= _pwajunk();
406 struct passwd_adjunct
*pwadj
;
410 if ((pwadj
= interpret(val
, len
)) == NULL
)
412 if (savepwadj
->pwa_passwd
&& *savepwadj
->pwa_passwd
)
413 pwadj
->pwa_passwd
= savepwadj
->pwa_passwd
;
420 while(*p
&& *p
!= ':' && *p
!= '\n')
429 static struct passwd_adjunct
*
430 interpret(char *val
, int len
)
432 struct _pwajunk
*_pwa
= _pwajunk();
438 (void) strncpy(interpline
, val
, len
);
440 interpline
[len
] = '\n';
441 interpline
[len
+1] = 0;
445 if (strcmp(apwadj
.pwa_name
, "+") == 0) {
446 /* we are going to the NIS - fix the
447 * rest of the struct as much as is needed
449 apwadj
.pwa_passwd
= "";
452 apwadj
.pwa_passwd
= p
;
456 labelfromstring(0, field
, &apwadj
.pwa_minimum
);
459 labelfromstring(0, field
, &apwadj
.pwa_maximum
);
462 labelfromstring(0, field
, &apwadj
.pwa_def
);
465 apwadj
.pwa_au_always
.as_success
= 0;
466 apwadj
.pwa_au_always
.as_failure
= 0;
467 if (getauditflagsbin(field
, &apwadj
.pwa_au_always
) != 0)
471 p
= apwadj
.pwa_passwd
;
472 while (*p
&& *p
!= ',')
477 apwadj
.pwa_au_never
.as_success
= 0;
478 apwadj
.pwa_au_never
.as_failure
= 0;
479 if (getauditflagsbin(field
, &apwadj
.pwa_au_never
) != 0)
485 freeminuslist(void) {
486 struct _pwajunk
*_pwa
= _pwajunk();
491 for (ls
= minuslist
; ls
!= NULL
; ls
= ls
->nxt
) {
499 addtominuslist(char *name
)
501 struct _pwajunk
*_pwa
= _pwajunk();
507 ls
= (struct list
*) malloc(sizeof(struct list
));
508 buf
= malloc((unsigned) strlen(name
) + 1);
509 (void) strcpy(buf
, name
);
516 * save away the psswd field, which is the only one which can be
517 * specified in a local + entry to override the value in the NIS
520 static struct passwd_adjunct
*
521 save(struct passwd_adjunct
*pwadj
)
523 struct _pwajunk
*_pwa
= _pwajunk();
524 static struct passwd_adjunct
*sv
;
528 /* free up stuff from last call */
530 free(sv
->pwa_passwd
);
533 sv
= (struct passwd_adjunct
*) malloc(sizeof(struct passwd_adjunct
));
535 sv
->pwa_passwd
= malloc((unsigned) strlen(pwadj
->pwa_passwd
) + 1);
536 (void) strcpy(sv
->pwa_passwd
, pwadj
->pwa_passwd
);
542 onminuslist(struct passwd_adjunct
*pwadj
)
544 struct _pwajunk
*_pwa
= _pwajunk();
550 nm
= pwadj
->pwa_name
;
551 for (ls
= minuslist
; ls
!= NULL
; ls
= ls
->nxt
) {
552 if (strcmp(ls
->name
,nm
) == 0) {