xref: /titanic_50/usr/src/lib/libbc/libc/gen/common/getpwaent.c (revision 5d54f3d8999eac1762fe0a8c7177d20f1f201fae)
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 1991 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 
307c478bd9Sstevel@tonic-gate #include <stdio.h>
317c478bd9Sstevel@tonic-gate #include <sys/types.h>
327c478bd9Sstevel@tonic-gate #include <sys/label.h>
337c478bd9Sstevel@tonic-gate #include <sys/audit.h>
347c478bd9Sstevel@tonic-gate #include <pwdadj.h>
357c478bd9Sstevel@tonic-gate #include <pwd.h>
367c478bd9Sstevel@tonic-gate #include <rpcsvc/ypclnt.h>
37*5d54f3d8Smuffin #include <string.h>
38*5d54f3d8Smuffin #include <malloc.h>
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate extern void rewind();
417c478bd9Sstevel@tonic-gate extern long strtol();
427c478bd9Sstevel@tonic-gate extern int fclose();
437c478bd9Sstevel@tonic-gate 
44*5d54f3d8Smuffin void	setpwaent(void);
45*5d54f3d8Smuffin void	endpwaent(void);
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate static struct _pwajunk {
487c478bd9Sstevel@tonic-gate 	struct passwd _NULLPW;
497c478bd9Sstevel@tonic-gate 	FILE *_pwfadj;
507c478bd9Sstevel@tonic-gate 	char *_yp;
517c478bd9Sstevel@tonic-gate 	int _yplen;
527c478bd9Sstevel@tonic-gate 	char *_oldyp;
537c478bd9Sstevel@tonic-gate 	int _oldyplen;
547c478bd9Sstevel@tonic-gate 	struct list {
557c478bd9Sstevel@tonic-gate 		char *name;
567c478bd9Sstevel@tonic-gate 		struct list *nxt;
577c478bd9Sstevel@tonic-gate 	} *_minuslist;
587c478bd9Sstevel@tonic-gate 	struct passwd _interppasswd;
597c478bd9Sstevel@tonic-gate 	struct passwd_adjunct _apwadj;
607c478bd9Sstevel@tonic-gate 	char _interpline[BUFSIZ+1];
617c478bd9Sstevel@tonic-gate 	char *_domain;
62*5d54f3d8Smuffin } *__pwajunk, *_pwajunk(void);
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate #define	NULLPW (_pwa->_NULLPW)
657c478bd9Sstevel@tonic-gate #define pwfadj (_pwa->_pwfadj)
667c478bd9Sstevel@tonic-gate #define yp (_pwa->_yp)
677c478bd9Sstevel@tonic-gate #define yplen (_pwa->_yplen)
687c478bd9Sstevel@tonic-gate #define oldyp (_pwa->_oldyp)
697c478bd9Sstevel@tonic-gate #define oldyplen (_pwa->_oldyplen)
707c478bd9Sstevel@tonic-gate #define minuslist (_pwa->_minuslist)
717c478bd9Sstevel@tonic-gate #define interppasswd (_pwa->_interppasswd)
727c478bd9Sstevel@tonic-gate #define apwadj (_pwa->_apwadj)
737c478bd9Sstevel@tonic-gate #define interpline (_pwa->_interpline)
747c478bd9Sstevel@tonic-gate #define domain (_pwa->_domain)
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate static char *PASSWDADJ	= "/etc/security/passwd.adjunct";
777c478bd9Sstevel@tonic-gate 
78*5d54f3d8Smuffin static struct passwd_adjunct	*interpret(char *, int);
79*5d54f3d8Smuffin static struct passwd_adjunct	*interpretwithsave(char *, int,
80*5d54f3d8Smuffin     struct passwd_adjunct *);
81*5d54f3d8Smuffin static struct passwd_adjunct	*save(struct passwd_adjunct *);
82*5d54f3d8Smuffin static struct passwd_adjunct	*getnamefromyellow(char *,
83*5d54f3d8Smuffin     struct passwd_adjunct *);
84*5d54f3d8Smuffin static int	matchname(char [], struct passwd_adjunct **, char *);
85*5d54f3d8Smuffin static int	onminuslist(struct passwd_adjunct *);
86*5d54f3d8Smuffin static void	getnextfromyellow(void);
87*5d54f3d8Smuffin static void	getfirstfromyellow(void);
88*5d54f3d8Smuffin static void	freeminuslist(void);
89*5d54f3d8Smuffin static void	addtominuslist(char *);
90*5d54f3d8Smuffin 
91*5d54f3d8Smuffin 
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate static struct _pwajunk *
_pwajunk(void)94*5d54f3d8Smuffin _pwajunk(void)
957c478bd9Sstevel@tonic-gate {
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate 	if (__pwajunk == 0)
987c478bd9Sstevel@tonic-gate 		__pwajunk = (struct _pwajunk *)calloc(1, sizeof (*__pwajunk));
997c478bd9Sstevel@tonic-gate 	return (__pwajunk);
1007c478bd9Sstevel@tonic-gate }
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate struct passwd_adjunct *
getpwanam(char * name)103*5d54f3d8Smuffin getpwanam(char *name)
1047c478bd9Sstevel@tonic-gate {
105*5d54f3d8Smuffin 	struct _pwajunk *_pwa = _pwajunk();
1067c478bd9Sstevel@tonic-gate 	struct passwd_adjunct *pwadj;
1077c478bd9Sstevel@tonic-gate 	char line[BUFSIZ+1];
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate 	if (_pwa == 0)
110*5d54f3d8Smuffin 		return (NULL);
1117c478bd9Sstevel@tonic-gate 	setpwaent();
1127c478bd9Sstevel@tonic-gate 	if (!pwfadj)
113*5d54f3d8Smuffin 		return (NULL);
1147c478bd9Sstevel@tonic-gate 	while (fgets(line, BUFSIZ, pwfadj) != NULL) {
1157c478bd9Sstevel@tonic-gate 		if ((pwadj = interpret(line, strlen(line))) == NULL)
1167c478bd9Sstevel@tonic-gate 			continue;
1177c478bd9Sstevel@tonic-gate 		if (matchname(line, &pwadj, name)) {
1187c478bd9Sstevel@tonic-gate 			endpwaent();
119*5d54f3d8Smuffin 			return (pwadj);
1207c478bd9Sstevel@tonic-gate 		}
1217c478bd9Sstevel@tonic-gate 	}
1227c478bd9Sstevel@tonic-gate 	endpwaent();
123*5d54f3d8Smuffin 	return (NULL);
1247c478bd9Sstevel@tonic-gate }
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate void
setpwaent(void)128*5d54f3d8Smuffin setpwaent(void)
1297c478bd9Sstevel@tonic-gate {
130*5d54f3d8Smuffin 	struct _pwajunk *_pwa = _pwajunk();
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate 	if (_pwa == 0)
1337c478bd9Sstevel@tonic-gate 		return;
1347c478bd9Sstevel@tonic-gate 	if (domain == NULL) {
1357c478bd9Sstevel@tonic-gate 		(void) yp_get_default_domain(&domain );
1367c478bd9Sstevel@tonic-gate 	}
1377c478bd9Sstevel@tonic-gate 	if (pwfadj == NULL)
1387c478bd9Sstevel@tonic-gate 		pwfadj = fopen(PASSWDADJ, "r");
1397c478bd9Sstevel@tonic-gate 	else
1407c478bd9Sstevel@tonic-gate 		rewind(pwfadj);
1417c478bd9Sstevel@tonic-gate 	if (yp)
1427c478bd9Sstevel@tonic-gate 		free(yp);
1437c478bd9Sstevel@tonic-gate 	yp = NULL;
1447c478bd9Sstevel@tonic-gate 	freeminuslist();
1457c478bd9Sstevel@tonic-gate }
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate void
endpwaent(void)150*5d54f3d8Smuffin endpwaent(void)
1517c478bd9Sstevel@tonic-gate {
152*5d54f3d8Smuffin 	struct _pwajunk *_pwa = _pwajunk();
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate 	if (_pwa == 0)
1557c478bd9Sstevel@tonic-gate 		return;
1567c478bd9Sstevel@tonic-gate 	if (pwfadj != NULL) {
1577c478bd9Sstevel@tonic-gate 		(void) fclose(pwfadj);
1587c478bd9Sstevel@tonic-gate 		pwfadj = NULL;
1597c478bd9Sstevel@tonic-gate 	}
1607c478bd9Sstevel@tonic-gate 	if (yp)
1617c478bd9Sstevel@tonic-gate 		free(yp);
1627c478bd9Sstevel@tonic-gate 	yp = NULL;
1637c478bd9Sstevel@tonic-gate 	freeminuslist();
1647c478bd9Sstevel@tonic-gate 	endnetgrent();
1657c478bd9Sstevel@tonic-gate }
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate 
1697c478bd9Sstevel@tonic-gate struct passwd_adjunct *
getpwaent(void)170*5d54f3d8Smuffin getpwaent(void)
1717c478bd9Sstevel@tonic-gate {
172*5d54f3d8Smuffin 	struct _pwajunk *_pwa = _pwajunk();
1737c478bd9Sstevel@tonic-gate 	char line[BUFSIZ+1];
1747c478bd9Sstevel@tonic-gate 	static struct passwd_adjunct *savepwadj;
1757c478bd9Sstevel@tonic-gate 	struct passwd_adjunct *pwadj;
1767c478bd9Sstevel@tonic-gate 	char *user;
1777c478bd9Sstevel@tonic-gate 	char *mach;
1787c478bd9Sstevel@tonic-gate 	char *dom;
1797c478bd9Sstevel@tonic-gate 
1807c478bd9Sstevel@tonic-gate 	if (_pwa == 0)
181*5d54f3d8Smuffin 		return (NULL);
1827c478bd9Sstevel@tonic-gate 	if (domain == NULL) {
1837c478bd9Sstevel@tonic-gate 		(void) yp_get_default_domain(&domain );
1847c478bd9Sstevel@tonic-gate 	}
1857c478bd9Sstevel@tonic-gate 	if (pwfadj == NULL && (pwfadj = fopen(PASSWDADJ, "r")) == NULL) {
1867c478bd9Sstevel@tonic-gate 		return (NULL);
1877c478bd9Sstevel@tonic-gate 	}
1887c478bd9Sstevel@tonic-gate 
1897c478bd9Sstevel@tonic-gate 	for (;;) {
1907c478bd9Sstevel@tonic-gate 		if (yp) {
1917c478bd9Sstevel@tonic-gate 			pwadj = interpretwithsave(yp, yplen, savepwadj);
1927c478bd9Sstevel@tonic-gate 			free(yp);
1937c478bd9Sstevel@tonic-gate 			if (pwadj == NULL)
1947c478bd9Sstevel@tonic-gate 				return (NULL);
1957c478bd9Sstevel@tonic-gate 			getnextfromyellow();
1967c478bd9Sstevel@tonic-gate 			if (!onminuslist(pwadj)) {
1977c478bd9Sstevel@tonic-gate 				return (pwadj);
1987c478bd9Sstevel@tonic-gate 			}
1997c478bd9Sstevel@tonic-gate 		} else if (getnetgrent(&mach,&user,&dom)) {
2007c478bd9Sstevel@tonic-gate 			if (user) {
2017c478bd9Sstevel@tonic-gate 				pwadj = getnamefromyellow(user, savepwadj);
2027c478bd9Sstevel@tonic-gate 				if (pwadj != NULL && !onminuslist(pwadj)) {
2037c478bd9Sstevel@tonic-gate 					return (pwadj);
2047c478bd9Sstevel@tonic-gate 				}
2057c478bd9Sstevel@tonic-gate 			}
2067c478bd9Sstevel@tonic-gate 		} else {
2077c478bd9Sstevel@tonic-gate 			endnetgrent();
2087c478bd9Sstevel@tonic-gate 			if (fgets(line, BUFSIZ, pwfadj) == NULL)  {
2097c478bd9Sstevel@tonic-gate 				return (NULL);
2107c478bd9Sstevel@tonic-gate 			}
2117c478bd9Sstevel@tonic-gate 			if ((pwadj = interpret(line, strlen(line))) == NULL)
2127c478bd9Sstevel@tonic-gate 				return (NULL);
2137c478bd9Sstevel@tonic-gate 			switch(line[0]) {
2147c478bd9Sstevel@tonic-gate 			case '+':
2157c478bd9Sstevel@tonic-gate 				if (strcmp(pwadj->pwa_name, "+") == 0) {
2167c478bd9Sstevel@tonic-gate 					getfirstfromyellow();
2177c478bd9Sstevel@tonic-gate 					savepwadj = save(pwadj);
2187c478bd9Sstevel@tonic-gate 				} else if (line[1] == '@') {
2197c478bd9Sstevel@tonic-gate 					savepwadj = save(pwadj);
2207c478bd9Sstevel@tonic-gate 					if (innetgr(pwadj->pwa_name+2,(char *) NULL,"*",domain)) {
2217c478bd9Sstevel@tonic-gate 						/* include the whole NIS database */
2227c478bd9Sstevel@tonic-gate 						getfirstfromyellow();
2237c478bd9Sstevel@tonic-gate 					} else {
2247c478bd9Sstevel@tonic-gate 						setnetgrent(pwadj->pwa_name+2);
2257c478bd9Sstevel@tonic-gate 					}
2267c478bd9Sstevel@tonic-gate 				} else {
2277c478bd9Sstevel@tonic-gate 					/*
2287c478bd9Sstevel@tonic-gate 					 * else look up this entry in NIS
2297c478bd9Sstevel@tonic-gate 				 	 */
2307c478bd9Sstevel@tonic-gate 					savepwadj = save(pwadj);
2317c478bd9Sstevel@tonic-gate 					pwadj = getnamefromyellow(pwadj->pwa_name+1, savepwadj);
2327c478bd9Sstevel@tonic-gate 					if (pwadj != NULL && !onminuslist(pwadj)) {
2337c478bd9Sstevel@tonic-gate 						return (pwadj);
2347c478bd9Sstevel@tonic-gate 					}
2357c478bd9Sstevel@tonic-gate 				}
2367c478bd9Sstevel@tonic-gate 				break;
2377c478bd9Sstevel@tonic-gate 			case '-':
2387c478bd9Sstevel@tonic-gate 				if (line[1] == '@') {
2397c478bd9Sstevel@tonic-gate 					if (innetgr(pwadj->pwa_name+2,(char *) NULL,"*",domain)) {
2407c478bd9Sstevel@tonic-gate 						/* everybody was subtracted */
2417c478bd9Sstevel@tonic-gate 						return (NULL);
2427c478bd9Sstevel@tonic-gate 					}
2437c478bd9Sstevel@tonic-gate 					setnetgrent(pwadj->pwa_name+2);
2447c478bd9Sstevel@tonic-gate 					while (getnetgrent(&mach,&user,&dom)) {
2457c478bd9Sstevel@tonic-gate 						if (user) {
2467c478bd9Sstevel@tonic-gate 							addtominuslist(user);
2477c478bd9Sstevel@tonic-gate 						}
2487c478bd9Sstevel@tonic-gate 					}
2497c478bd9Sstevel@tonic-gate 					endnetgrent();
2507c478bd9Sstevel@tonic-gate 				} else {
2517c478bd9Sstevel@tonic-gate 					addtominuslist(pwadj->pwa_name+1);
2527c478bd9Sstevel@tonic-gate 				}
2537c478bd9Sstevel@tonic-gate 				break;
2547c478bd9Sstevel@tonic-gate 			default:
2557c478bd9Sstevel@tonic-gate 				if (!onminuslist(pwadj)) {
2567c478bd9Sstevel@tonic-gate 					return (pwadj);
2577c478bd9Sstevel@tonic-gate 				}
2587c478bd9Sstevel@tonic-gate 				break;
2597c478bd9Sstevel@tonic-gate 			}
2607c478bd9Sstevel@tonic-gate 		}
2617c478bd9Sstevel@tonic-gate 	}
2627c478bd9Sstevel@tonic-gate }
2637c478bd9Sstevel@tonic-gate 
264*5d54f3d8Smuffin static int
matchname(char line1[],struct passwd_adjunct ** pwadjp,char * name)265*5d54f3d8Smuffin matchname(char line1[], struct passwd_adjunct **pwadjp, char *name)
2667c478bd9Sstevel@tonic-gate {
267*5d54f3d8Smuffin 	struct _pwajunk *_pwa = _pwajunk();
2687c478bd9Sstevel@tonic-gate 	struct passwd_adjunct *savepwadj;
2697c478bd9Sstevel@tonic-gate 	struct passwd_adjunct *pwadj = *pwadjp;
2707c478bd9Sstevel@tonic-gate 
2717c478bd9Sstevel@tonic-gate 	if (_pwa == 0)
2727c478bd9Sstevel@tonic-gate 		return (0);
2737c478bd9Sstevel@tonic-gate 	switch(line1[0]) {
2747c478bd9Sstevel@tonic-gate 		case '+':
2757c478bd9Sstevel@tonic-gate 			if (strcmp(pwadj->pwa_name, "+") == 0) {
2767c478bd9Sstevel@tonic-gate 				savepwadj = save(pwadj);
2777c478bd9Sstevel@tonic-gate 				pwadj = getnamefromyellow(name, savepwadj);
2787c478bd9Sstevel@tonic-gate 				if (pwadj) {
2797c478bd9Sstevel@tonic-gate 					*pwadjp = pwadj;
280*5d54f3d8Smuffin 					return (1);
2817c478bd9Sstevel@tonic-gate 				}
2827c478bd9Sstevel@tonic-gate 				else
283*5d54f3d8Smuffin 					return (0);
2847c478bd9Sstevel@tonic-gate 			}
2857c478bd9Sstevel@tonic-gate 			if (line1[1] == '@') {
2867c478bd9Sstevel@tonic-gate 				if (innetgr(pwadj->pwa_name+2,(char *) NULL,name,domain)) {
2877c478bd9Sstevel@tonic-gate 					savepwadj = save(pwadj);
2887c478bd9Sstevel@tonic-gate 					pwadj = getnamefromyellow(name,savepwadj);
2897c478bd9Sstevel@tonic-gate 					if (pwadj) {
2907c478bd9Sstevel@tonic-gate 						*pwadjp = pwadj;
291*5d54f3d8Smuffin 						return (1);
2927c478bd9Sstevel@tonic-gate 					}
2937c478bd9Sstevel@tonic-gate 				}
294*5d54f3d8Smuffin 				return (0);
2957c478bd9Sstevel@tonic-gate 			}
2967c478bd9Sstevel@tonic-gate 			if (strcmp(pwadj->pwa_name+1, name) == 0) {
2977c478bd9Sstevel@tonic-gate 				savepwadj = save(pwadj);
2987c478bd9Sstevel@tonic-gate 				pwadj = getnamefromyellow(pwadj->pwa_name+1, savepwadj);
2997c478bd9Sstevel@tonic-gate 				if (pwadj) {
3007c478bd9Sstevel@tonic-gate 					*pwadjp = pwadj;
301*5d54f3d8Smuffin 					return (1);
3027c478bd9Sstevel@tonic-gate 				}
3037c478bd9Sstevel@tonic-gate 				else
304*5d54f3d8Smuffin 					return (0);
3057c478bd9Sstevel@tonic-gate 			}
3067c478bd9Sstevel@tonic-gate 			break;
3077c478bd9Sstevel@tonic-gate 		case '-':
3087c478bd9Sstevel@tonic-gate 			if (line1[1] == '@') {
3097c478bd9Sstevel@tonic-gate 				if (innetgr(pwadj->pwa_name+2,(char *) NULL,name,domain)) {
3107c478bd9Sstevel@tonic-gate 					*pwadjp = NULL;
311*5d54f3d8Smuffin 					return (1);
3127c478bd9Sstevel@tonic-gate 				}
3137c478bd9Sstevel@tonic-gate 			}
3147c478bd9Sstevel@tonic-gate 			else if (strcmp(pwadj->pwa_name+1, name) == 0) {
3157c478bd9Sstevel@tonic-gate 				*pwadjp = NULL;
316*5d54f3d8Smuffin 				return (1);
3177c478bd9Sstevel@tonic-gate 			}
3187c478bd9Sstevel@tonic-gate 			break;
3197c478bd9Sstevel@tonic-gate 		default:
3207c478bd9Sstevel@tonic-gate 			if (strcmp(pwadj->pwa_name, name) == 0)
321*5d54f3d8Smuffin 				return (1);
3227c478bd9Sstevel@tonic-gate 	}
323*5d54f3d8Smuffin 	return (0);
3247c478bd9Sstevel@tonic-gate }
3257c478bd9Sstevel@tonic-gate 
326*5d54f3d8Smuffin static void
getnextfromyellow(void)327*5d54f3d8Smuffin getnextfromyellow(void)
3287c478bd9Sstevel@tonic-gate {
329*5d54f3d8Smuffin 	struct _pwajunk *_pwa = _pwajunk();
3307c478bd9Sstevel@tonic-gate 	int reason;
3317c478bd9Sstevel@tonic-gate 	char *key;
3327c478bd9Sstevel@tonic-gate 	int keylen;
3337c478bd9Sstevel@tonic-gate 
3347c478bd9Sstevel@tonic-gate 	if (_pwa == 0)
3357c478bd9Sstevel@tonic-gate 		return;
3367c478bd9Sstevel@tonic-gate 	reason = yp_next(domain, "passwd_adjunct",oldyp, oldyplen, &key
3377c478bd9Sstevel@tonic-gate 	    ,&keylen,&yp,&yplen);
3387c478bd9Sstevel@tonic-gate 	if (reason) {
3397c478bd9Sstevel@tonic-gate #ifdef DEBUG
3407c478bd9Sstevel@tonic-gate fprintf(stderr, "reason yp_next failed is %d\n", reason);
3417c478bd9Sstevel@tonic-gate #endif
3427c478bd9Sstevel@tonic-gate 		yp = NULL;
3437c478bd9Sstevel@tonic-gate 	}
3447c478bd9Sstevel@tonic-gate 	if (oldyp)
3457c478bd9Sstevel@tonic-gate 		free(oldyp);
3467c478bd9Sstevel@tonic-gate 	oldyp = key;
3477c478bd9Sstevel@tonic-gate 	oldyplen = keylen;
3487c478bd9Sstevel@tonic-gate }
3497c478bd9Sstevel@tonic-gate 
350*5d54f3d8Smuffin static void
getfirstfromyellow(void)351*5d54f3d8Smuffin getfirstfromyellow(void)
3527c478bd9Sstevel@tonic-gate {
353*5d54f3d8Smuffin 	struct _pwajunk *_pwa = _pwajunk();
3547c478bd9Sstevel@tonic-gate 	int reason;
3557c478bd9Sstevel@tonic-gate 	char *key;
3567c478bd9Sstevel@tonic-gate 	int keylen;
3577c478bd9Sstevel@tonic-gate 
3587c478bd9Sstevel@tonic-gate 	if (_pwa == 0)
3597c478bd9Sstevel@tonic-gate 		return;
3607c478bd9Sstevel@tonic-gate 	reason =  yp_first(domain, "passwd_adjunct", &key, &keylen, &yp, &yplen);
3617c478bd9Sstevel@tonic-gate 	if (reason) {
3627c478bd9Sstevel@tonic-gate #ifdef DEBUG
3637c478bd9Sstevel@tonic-gate fprintf(stderr, "reason yp_first failed is %d\n", reason);
3647c478bd9Sstevel@tonic-gate #endif
3657c478bd9Sstevel@tonic-gate 		yp = NULL;
3667c478bd9Sstevel@tonic-gate 	}
3677c478bd9Sstevel@tonic-gate 	if (oldyp)
3687c478bd9Sstevel@tonic-gate 		free(oldyp);
3697c478bd9Sstevel@tonic-gate 	oldyp = key;
3707c478bd9Sstevel@tonic-gate 	oldyplen = keylen;
3717c478bd9Sstevel@tonic-gate }
3727c478bd9Sstevel@tonic-gate 
3737c478bd9Sstevel@tonic-gate static struct passwd_adjunct *
getnamefromyellow(char * name,struct passwd_adjunct * savepwadj)374*5d54f3d8Smuffin getnamefromyellow(char *name, struct passwd_adjunct *savepwadj)
3757c478bd9Sstevel@tonic-gate {
376*5d54f3d8Smuffin 	struct _pwajunk *_pwa = _pwajunk();
3777c478bd9Sstevel@tonic-gate 	struct passwd_adjunct *pwadj;
3787c478bd9Sstevel@tonic-gate 	int reason;
3797c478bd9Sstevel@tonic-gate 	char *val;
3807c478bd9Sstevel@tonic-gate 	int vallen;
3817c478bd9Sstevel@tonic-gate 
3827c478bd9Sstevel@tonic-gate 	if (_pwa == 0)
383*5d54f3d8Smuffin 		return (NULL);
3847c478bd9Sstevel@tonic-gate 	reason = yp_match(domain, "passwd.adjunct.byname", name, strlen(name)
3857c478bd9Sstevel@tonic-gate 		, &val, &vallen);
3867c478bd9Sstevel@tonic-gate 	if (reason) {
3877c478bd9Sstevel@tonic-gate #ifdef DEBUG
3887c478bd9Sstevel@tonic-gate fprintf(stderr, "reason yp_match failed is %d\n", reason);
3897c478bd9Sstevel@tonic-gate #endif
390*5d54f3d8Smuffin 		return (NULL);
3917c478bd9Sstevel@tonic-gate 	} else {
3927c478bd9Sstevel@tonic-gate 		pwadj = interpret(val, vallen);
3937c478bd9Sstevel@tonic-gate 		free(val);
3947c478bd9Sstevel@tonic-gate 		if (pwadj == NULL)
395*5d54f3d8Smuffin 			return (NULL);
3967c478bd9Sstevel@tonic-gate 		if (savepwadj->pwa_passwd && *savepwadj->pwa_passwd)
3977c478bd9Sstevel@tonic-gate 			pwadj->pwa_passwd =  savepwadj->pwa_passwd;
398*5d54f3d8Smuffin 		return (pwadj);
3997c478bd9Sstevel@tonic-gate 	}
4007c478bd9Sstevel@tonic-gate }
4017c478bd9Sstevel@tonic-gate 
4027c478bd9Sstevel@tonic-gate static struct passwd_adjunct *
interpretwithsave(char * val,int len,struct passwd_adjunct * savepwadj)403*5d54f3d8Smuffin interpretwithsave(char *val, int len, struct passwd_adjunct *savepwadj)
4047c478bd9Sstevel@tonic-gate {
405*5d54f3d8Smuffin 	struct _pwajunk *_pwa = _pwajunk();
4067c478bd9Sstevel@tonic-gate 	struct passwd_adjunct *pwadj;
4077c478bd9Sstevel@tonic-gate 
4087c478bd9Sstevel@tonic-gate 	if (_pwa == 0)
409*5d54f3d8Smuffin 		return (NULL);
4107c478bd9Sstevel@tonic-gate 	if ((pwadj = interpret(val, len)) == NULL)
411*5d54f3d8Smuffin 		return (NULL);
4127c478bd9Sstevel@tonic-gate 	if (savepwadj->pwa_passwd && *savepwadj->pwa_passwd)
4137c478bd9Sstevel@tonic-gate 		pwadj->pwa_passwd =  savepwadj->pwa_passwd;
414*5d54f3d8Smuffin 	return (pwadj);
4157c478bd9Sstevel@tonic-gate }
4167c478bd9Sstevel@tonic-gate 
4177c478bd9Sstevel@tonic-gate static char *
pwskip(char * p)418*5d54f3d8Smuffin pwskip(char *p)
4197c478bd9Sstevel@tonic-gate {
4207c478bd9Sstevel@tonic-gate 	while(*p && *p != ':' && *p != '\n')
4217c478bd9Sstevel@tonic-gate 		++p;
4227c478bd9Sstevel@tonic-gate 	if (*p == '\n')
4237c478bd9Sstevel@tonic-gate 		*p = '\0';
4247c478bd9Sstevel@tonic-gate 	else if (*p != '\0')
4257c478bd9Sstevel@tonic-gate 		*p++ = '\0';
4267c478bd9Sstevel@tonic-gate 	return (p);
4277c478bd9Sstevel@tonic-gate }
4287c478bd9Sstevel@tonic-gate 
4297c478bd9Sstevel@tonic-gate static struct passwd_adjunct *
interpret(char * val,int len)430*5d54f3d8Smuffin interpret(char *val, int len)
4317c478bd9Sstevel@tonic-gate {
432*5d54f3d8Smuffin 	struct _pwajunk *_pwa = _pwajunk();
433*5d54f3d8Smuffin 	char *p;
4347c478bd9Sstevel@tonic-gate 	char *field;
4357c478bd9Sstevel@tonic-gate 
4367c478bd9Sstevel@tonic-gate 	if (_pwa == 0)
437*5d54f3d8Smuffin 		return (NULL);
4387c478bd9Sstevel@tonic-gate 	(void) strncpy(interpline, val, len);
4397c478bd9Sstevel@tonic-gate 	p = interpline;
4407c478bd9Sstevel@tonic-gate 	interpline[len] = '\n';
4417c478bd9Sstevel@tonic-gate 	interpline[len+1] = 0;
4427c478bd9Sstevel@tonic-gate 
4437c478bd9Sstevel@tonic-gate 	apwadj.pwa_name = p;
4447c478bd9Sstevel@tonic-gate 	p = pwskip(p);
4457c478bd9Sstevel@tonic-gate 	if (strcmp(apwadj.pwa_name, "+") == 0) {
4467c478bd9Sstevel@tonic-gate 		/* we are going to the NIS - fix the
4477c478bd9Sstevel@tonic-gate 		 * rest of the struct as much as is needed
4487c478bd9Sstevel@tonic-gate 		 */
4497c478bd9Sstevel@tonic-gate 		apwadj.pwa_passwd = "";
4507c478bd9Sstevel@tonic-gate 		return (&apwadj);
4517c478bd9Sstevel@tonic-gate 	}
4527c478bd9Sstevel@tonic-gate 	apwadj.pwa_passwd = p;
4537c478bd9Sstevel@tonic-gate 	p = pwskip(p);
4547c478bd9Sstevel@tonic-gate 	field = p;
4557c478bd9Sstevel@tonic-gate 	p = pwskip(p);
4567c478bd9Sstevel@tonic-gate 	labelfromstring(0, field, &apwadj.pwa_minimum);
4577c478bd9Sstevel@tonic-gate 	field = p;
4587c478bd9Sstevel@tonic-gate 	p = pwskip(p);
4597c478bd9Sstevel@tonic-gate 	labelfromstring(0, field, &apwadj.pwa_maximum);
4607c478bd9Sstevel@tonic-gate 	field = p;
4617c478bd9Sstevel@tonic-gate 	p = pwskip(p);
4627c478bd9Sstevel@tonic-gate 	labelfromstring(0, field, &apwadj.pwa_def);
4637c478bd9Sstevel@tonic-gate 	field = p;
4647c478bd9Sstevel@tonic-gate 	p = pwskip(p);
4657c478bd9Sstevel@tonic-gate 	apwadj.pwa_au_always.as_success = 0;
4667c478bd9Sstevel@tonic-gate 	apwadj.pwa_au_always.as_failure = 0;
4677c478bd9Sstevel@tonic-gate 	if (getauditflagsbin(field, &apwadj.pwa_au_always) != 0)
468*5d54f3d8Smuffin 		return (NULL);
4697c478bd9Sstevel@tonic-gate 	field = p;
4707c478bd9Sstevel@tonic-gate 	(void) pwskip(p);
4717c478bd9Sstevel@tonic-gate 	p = apwadj.pwa_passwd;
4727c478bd9Sstevel@tonic-gate 	while (*p && *p != ',')
4737c478bd9Sstevel@tonic-gate 		p++;
4747c478bd9Sstevel@tonic-gate 	if (*p)
4757c478bd9Sstevel@tonic-gate 		*p = '\0';
4767c478bd9Sstevel@tonic-gate 	apwadj.pwa_age = p;
4777c478bd9Sstevel@tonic-gate 	apwadj.pwa_au_never.as_success = 0;
4787c478bd9Sstevel@tonic-gate 	apwadj.pwa_au_never.as_failure = 0;
4797c478bd9Sstevel@tonic-gate 	if (getauditflagsbin(field, &apwadj.pwa_au_never) != 0)
480*5d54f3d8Smuffin 		return (NULL);
4817c478bd9Sstevel@tonic-gate 	return (&apwadj);
4827c478bd9Sstevel@tonic-gate }
4837c478bd9Sstevel@tonic-gate 
484*5d54f3d8Smuffin static void
freeminuslist(void)485*5d54f3d8Smuffin freeminuslist(void) {
486*5d54f3d8Smuffin 	struct _pwajunk *_pwa = _pwajunk();
4877c478bd9Sstevel@tonic-gate 	struct list *ls;
4887c478bd9Sstevel@tonic-gate 
4897c478bd9Sstevel@tonic-gate 	if (_pwa == 0)
4907c478bd9Sstevel@tonic-gate 		return;
4917c478bd9Sstevel@tonic-gate 	for (ls = minuslist; ls != NULL; ls = ls->nxt) {
4927c478bd9Sstevel@tonic-gate 		free(ls->name);
4937c478bd9Sstevel@tonic-gate 		free((char *) ls);
4947c478bd9Sstevel@tonic-gate 	}
4957c478bd9Sstevel@tonic-gate 	minuslist = NULL;
4967c478bd9Sstevel@tonic-gate }
4977c478bd9Sstevel@tonic-gate 
498*5d54f3d8Smuffin static void
addtominuslist(char * name)499*5d54f3d8Smuffin addtominuslist(char *name)
5007c478bd9Sstevel@tonic-gate {
501*5d54f3d8Smuffin 	struct _pwajunk *_pwa = _pwajunk();
5027c478bd9Sstevel@tonic-gate 	struct list *ls;
5037c478bd9Sstevel@tonic-gate 	char *buf;
5047c478bd9Sstevel@tonic-gate 
5057c478bd9Sstevel@tonic-gate 	if (_pwa == 0)
5067c478bd9Sstevel@tonic-gate 		return;
5077c478bd9Sstevel@tonic-gate 	ls = (struct list *) malloc(sizeof(struct list));
5087c478bd9Sstevel@tonic-gate 	buf = malloc((unsigned) strlen(name) + 1);
5097c478bd9Sstevel@tonic-gate 	(void) strcpy(buf, name);
5107c478bd9Sstevel@tonic-gate 	ls->name = buf;
5117c478bd9Sstevel@tonic-gate 	ls->nxt = minuslist;
5127c478bd9Sstevel@tonic-gate 	minuslist = ls;
5137c478bd9Sstevel@tonic-gate }
5147c478bd9Sstevel@tonic-gate 
5157c478bd9Sstevel@tonic-gate /*
5167c478bd9Sstevel@tonic-gate  * save away the psswd field, which is the only one which can be
5177c478bd9Sstevel@tonic-gate  * specified in a local + entry to override the value in the NIS
5187c478bd9Sstevel@tonic-gate  * for passwd.adjunct
5197c478bd9Sstevel@tonic-gate  */
5207c478bd9Sstevel@tonic-gate static struct passwd_adjunct *
save(struct passwd_adjunct * pwadj)521*5d54f3d8Smuffin save(struct passwd_adjunct *pwadj)
5227c478bd9Sstevel@tonic-gate {
523*5d54f3d8Smuffin 	struct _pwajunk *_pwa = _pwajunk();
5247c478bd9Sstevel@tonic-gate 	static struct passwd_adjunct *sv;
5257c478bd9Sstevel@tonic-gate 
5267c478bd9Sstevel@tonic-gate 	if (_pwa == 0)
527*5d54f3d8Smuffin 		return (NULL);
5287c478bd9Sstevel@tonic-gate 	/* free up stuff from last call */
5297c478bd9Sstevel@tonic-gate 	if (sv) {
5307c478bd9Sstevel@tonic-gate 		free(sv->pwa_passwd);
5317c478bd9Sstevel@tonic-gate 		free((char *) sv);
5327c478bd9Sstevel@tonic-gate 	}
5337c478bd9Sstevel@tonic-gate 	sv = (struct passwd_adjunct *) malloc(sizeof(struct passwd_adjunct));
5347c478bd9Sstevel@tonic-gate 
5357c478bd9Sstevel@tonic-gate 	sv->pwa_passwd = malloc((unsigned) strlen(pwadj->pwa_passwd) + 1);
5367c478bd9Sstevel@tonic-gate 	(void) strcpy(sv->pwa_passwd, pwadj->pwa_passwd);
5377c478bd9Sstevel@tonic-gate 
538*5d54f3d8Smuffin 	return (sv);
5397c478bd9Sstevel@tonic-gate }
5407c478bd9Sstevel@tonic-gate 
541*5d54f3d8Smuffin static int
onminuslist(struct passwd_adjunct * pwadj)542*5d54f3d8Smuffin onminuslist(struct passwd_adjunct *pwadj)
5437c478bd9Sstevel@tonic-gate {
544*5d54f3d8Smuffin 	struct _pwajunk *_pwa = _pwajunk();
5457c478bd9Sstevel@tonic-gate 	struct list *ls;
546*5d54f3d8Smuffin 	char *nm;
5477c478bd9Sstevel@tonic-gate 
5487c478bd9Sstevel@tonic-gate 	if (_pwa == 0)
549*5d54f3d8Smuffin 		return (0);
5507c478bd9Sstevel@tonic-gate 	nm = pwadj->pwa_name;
5517c478bd9Sstevel@tonic-gate 	for (ls = minuslist; ls != NULL; ls = ls->nxt) {
5527c478bd9Sstevel@tonic-gate 		if (strcmp(ls->name,nm) == 0) {
5537c478bd9Sstevel@tonic-gate 			return (1);
5547c478bd9Sstevel@tonic-gate 		}
5557c478bd9Sstevel@tonic-gate 	}
5567c478bd9Sstevel@tonic-gate 	return (0);
5577c478bd9Sstevel@tonic-gate }
558