Home | History | Annotate | Line # | Download | only in gen
getpwent.c revision 1.11.4.1
      1       1.1      cgd /*
      2       1.1      cgd  * Copyright (c) 1988 The Regents of the University of California.
      3       1.1      cgd  * All rights reserved.
      4       1.1      cgd  *
      5       1.1      cgd  * Redistribution and use in source and binary forms, with or without
      6       1.1      cgd  * modification, are permitted provided that the following conditions
      7       1.1      cgd  * are met:
      8       1.1      cgd  * 1. Redistributions of source code must retain the above copyright
      9       1.1      cgd  *    notice, this list of conditions and the following disclaimer.
     10       1.1      cgd  * 2. Redistributions in binary form must reproduce the above copyright
     11       1.1      cgd  *    notice, this list of conditions and the following disclaimer in the
     12       1.1      cgd  *    documentation and/or other materials provided with the distribution.
     13       1.1      cgd  * 3. All advertising materials mentioning features or use of this software
     14       1.1      cgd  *    must display the following acknowledgement:
     15       1.1      cgd  *	This product includes software developed by the University of
     16       1.1      cgd  *	California, Berkeley and its contributors.
     17       1.1      cgd  * 4. Neither the name of the University nor the names of its contributors
     18       1.1      cgd  *    may be used to endorse or promote products derived from this software
     19       1.1      cgd  *    without specific prior written permission.
     20       1.1      cgd  *
     21       1.1      cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     22       1.1      cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23       1.1      cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24       1.1      cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     25       1.1      cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     26       1.1      cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     27       1.1      cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     28       1.1      cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     29       1.1      cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     30       1.1      cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     31       1.1      cgd  * SUCH DAMAGE.
     32       1.1      cgd  */
     33       1.1      cgd 
     34       1.1      cgd #if defined(LIBC_SCCS) && !defined(lint)
     35       1.7      jtc /*static char *sccsid = "from: @(#)getpwent.c	5.21 (Berkeley) 3/14/91";*/
     36  1.11.4.1      jtc static char *rcsid = "$Id: getpwent.c,v 1.11.4.1 1995/05/02 19:34:49 jtc Exp $";
     37       1.1      cgd #endif /* LIBC_SCCS and not lint */
     38       1.1      cgd 
     39  1.11.4.1      jtc #include "namespace.h"
     40       1.1      cgd #include <sys/param.h>
     41       1.1      cgd #include <fcntl.h>
     42       1.1      cgd #include <db.h>
     43       1.1      cgd #include <syslog.h>
     44       1.1      cgd #include <pwd.h>
     45       1.1      cgd #include <utmp.h>
     46       1.1      cgd #include <errno.h>
     47       1.1      cgd #include <unistd.h>
     48       1.1      cgd #include <stdlib.h>
     49       1.1      cgd #include <string.h>
     50       1.1      cgd #include <limits.h>
     51       1.4  deraadt #ifdef YP
     52       1.4  deraadt #include <stdio.h>
     53       1.4  deraadt #include <rpc/rpc.h>
     54       1.4  deraadt #include <rpcsvc/yp_prot.h>
     55       1.4  deraadt #include <rpcsvc/ypclnt.h>
     56       1.4  deraadt #endif
     57       1.1      cgd 
     58       1.1      cgd static struct passwd _pw_passwd;	/* password structure */
     59       1.1      cgd static DB *_pw_db;			/* password database */
     60       1.1      cgd static int _pw_keynum;			/* key counter */
     61       1.1      cgd static int _pw_stayopen;		/* keep fd's open */
     62       1.1      cgd static int __hashpw(), __initdb();
     63       1.1      cgd 
     64       1.4  deraadt #ifdef YP
     65       1.4  deraadt static char     *__ypcurrent, *__ypdomain;
     66       1.4  deraadt static int      __ypcurrentlen, __ypmode=0;
     67       1.4  deraadt static char	line[1024];
     68       1.4  deraadt 
     69       1.5  deraadt static int
     70       1.5  deraadt __ypparse(pw, s)
     71       1.4  deraadt struct passwd *pw;
     72       1.4  deraadt char *s;
     73       1.4  deraadt {
     74       1.4  deraadt 	char *bp, *cp;
     75       1.4  deraadt 
     76       1.4  deraadt 	bp = s;
     77       1.4  deraadt 	pw->pw_name = strsep(&bp, ":\n");
     78       1.4  deraadt 	pw->pw_passwd = strsep(&bp, ":\n");
     79       1.4  deraadt 	if (!(cp = strsep(&bp, ":\n")))
     80       1.4  deraadt 		return 1;
     81       1.4  deraadt 	pw->pw_uid = atoi(cp);
     82       1.4  deraadt 	if (!(cp = strsep(&bp, ":\n")))
     83       1.4  deraadt 		return 0;
     84       1.4  deraadt 	pw->pw_gid = atoi(cp);
     85       1.4  deraadt 	pw->pw_change = 0;
     86       1.4  deraadt 	pw->pw_class = "";
     87       1.4  deraadt 	pw->pw_gecos = strsep(&bp, ":\n");
     88       1.4  deraadt 	pw->pw_dir = strsep(&bp, ":\n");
     89       1.4  deraadt 	pw->pw_shell = strsep(&bp, ":\n");
     90       1.4  deraadt 	pw->pw_expire = 0;
     91       1.4  deraadt 	return 0;
     92       1.4  deraadt }
     93       1.4  deraadt #endif
     94       1.4  deraadt 
     95       1.1      cgd struct passwd *
     96       1.1      cgd getpwent()
     97       1.1      cgd {
     98       1.1      cgd 	DBT key;
     99       1.1      cgd 	char bf[sizeof(_pw_keynum) + 1];
    100       1.4  deraadt #ifdef YP
    101       1.4  deraadt 	char *bp, *cp;
    102       1.4  deraadt #endif
    103       1.1      cgd 
    104       1.1      cgd 	if (!_pw_db && !__initdb())
    105       1.1      cgd 		return((struct passwd *)NULL);
    106       1.1      cgd 
    107       1.4  deraadt #ifdef YP
    108       1.4  deraadt again:
    109       1.4  deraadt 	if(__ypmode) {
    110       1.4  deraadt 		char *key, *data;
    111       1.4  deraadt 		int keylen, datalen;
    112       1.4  deraadt 		int r;
    113       1.4  deraadt 
    114       1.4  deraadt 		if(!__ypdomain) {
    115       1.4  deraadt 			if( _yp_check(&__ypdomain) == 0) {
    116       1.4  deraadt 				__ypmode = 0;
    117       1.4  deraadt 				goto again;
    118       1.4  deraadt 			}
    119       1.4  deraadt 		}
    120       1.4  deraadt 		if(__ypcurrent) {
    121       1.4  deraadt 			r = yp_next(__ypdomain, "passwd.byname",
    122       1.4  deraadt 				__ypcurrent, __ypcurrentlen,
    123       1.4  deraadt 				&key, &keylen, &data, &datalen);
    124       1.4  deraadt 			free(__ypcurrent);
    125       1.4  deraadt 			__ypcurrent = NULL;
    126       1.4  deraadt 			/*printf("yp_next %d\n", r);*/
    127       1.4  deraadt 			switch(r) {
    128       1.4  deraadt 			case 0:
    129       1.4  deraadt 				break;
    130       1.4  deraadt 			default:
    131       1.4  deraadt 				__ypcurrent = NULL;
    132       1.4  deraadt 				__ypmode = 0;
    133       1.4  deraadt 				free(data);
    134       1.4  deraadt 				data = NULL;
    135       1.4  deraadt 				goto again;
    136       1.4  deraadt 			}
    137       1.4  deraadt 			__ypcurrent = key;
    138       1.4  deraadt 			__ypcurrentlen = keylen;
    139       1.4  deraadt 			bcopy(data, line, datalen);
    140       1.4  deraadt 			free(data);
    141       1.4  deraadt 			data = NULL;
    142       1.4  deraadt 		} else {
    143       1.4  deraadt 			r = yp_first(__ypdomain, "passwd.byname",
    144       1.4  deraadt 				&__ypcurrent, &__ypcurrentlen,
    145       1.4  deraadt 				&data, &datalen);
    146       1.4  deraadt 			/*printf("yp_first %d\n", r);*/
    147       1.4  deraadt 			switch(r) {
    148       1.4  deraadt 			case 0:
    149       1.4  deraadt 				break;
    150       1.4  deraadt 			default:
    151       1.4  deraadt 				__ypmode = 0;
    152       1.4  deraadt 				free(data);
    153       1.4  deraadt 				goto again;
    154       1.4  deraadt 			}
    155       1.4  deraadt 			bcopy(data, line, datalen);
    156       1.4  deraadt 			free(data);
    157       1.4  deraadt 			data = NULL;
    158       1.4  deraadt 		}
    159       1.4  deraadt 		line[datalen] = '\0';
    160       1.4  deraadt 		/*printf("line = %s\n", line);*/
    161       1.4  deraadt 		bp = line;
    162       1.4  deraadt 		goto parse;
    163       1.4  deraadt 	}
    164       1.4  deraadt #endif
    165       1.4  deraadt 
    166       1.1      cgd 	++_pw_keynum;
    167       1.1      cgd 	bf[0] = _PW_KEYBYNUM;
    168       1.1      cgd 	bcopy((char *)&_pw_keynum, bf + 1, sizeof(_pw_keynum));
    169       1.1      cgd 	key.data = (u_char *)bf;
    170       1.1      cgd 	key.size = sizeof(_pw_keynum) + 1;
    171       1.4  deraadt 	if(__hashpw(&key)) {
    172       1.4  deraadt #ifdef YP
    173       1.4  deraadt 		if(strcmp(_pw_passwd.pw_name, "+") == 0) {
    174       1.4  deraadt 			__ypmode = 1;
    175       1.4  deraadt 			goto again;
    176       1.4  deraadt 		}
    177       1.4  deraadt #endif
    178       1.4  deraadt 		return &_pw_passwd;
    179       1.4  deraadt 	}
    180       1.4  deraadt 	return (struct passwd *)NULL;
    181       1.4  deraadt 
    182       1.4  deraadt #ifdef YP
    183       1.4  deraadt parse:
    184       1.4  deraadt 	_pw_passwd.pw_name = strsep(&bp, ":\n");
    185       1.4  deraadt 	_pw_passwd.pw_passwd = strsep(&bp, ":\n");
    186       1.4  deraadt 	if (!(cp = strsep(&bp, ":\n")))
    187       1.4  deraadt 		goto again;
    188       1.4  deraadt 	_pw_passwd.pw_uid = atoi(cp);
    189       1.4  deraadt 	if (!(cp = strsep(&bp, ":\n")))
    190       1.4  deraadt 		goto again;
    191       1.4  deraadt 	_pw_passwd.pw_gid = atoi(cp);
    192       1.4  deraadt 	_pw_passwd.pw_change = 0;
    193       1.4  deraadt 	_pw_passwd.pw_class = "";
    194       1.4  deraadt 	_pw_passwd.pw_gecos = strsep(&bp, ":\n");
    195       1.4  deraadt 	_pw_passwd.pw_dir = strsep(&bp, ":\n");
    196       1.4  deraadt 	_pw_passwd.pw_shell = strsep(&bp, ":\n");
    197       1.4  deraadt 	_pw_passwd.pw_expire = 0;
    198       1.4  deraadt 	return &_pw_passwd;
    199       1.4  deraadt #endif
    200       1.1      cgd }
    201       1.1      cgd 
    202       1.1      cgd struct passwd *
    203       1.1      cgd getpwnam(name)
    204       1.1      cgd 	const char *name;
    205       1.1      cgd {
    206       1.1      cgd 	DBT key;
    207      1.10  deraadt 	int len, rval;
    208      1.10  deraadt 	char bf[UT_NAMESIZE + 1];
    209      1.10  deraadt 
    210      1.10  deraadt 	if (!_pw_db && !__initdb())
    211      1.10  deraadt 		return((struct passwd *)NULL);
    212       1.4  deraadt 
    213       1.4  deraadt #ifdef YP
    214      1.10  deraadt 	bf[0] = _PW_KEYBYNAME;
    215      1.10  deraadt 	len = strlen("+");
    216      1.10  deraadt 	bcopy("+", bf + 1, MIN(len, UT_NAMESIZE));
    217      1.10  deraadt 	key.data = (u_char *)bf;
    218      1.10  deraadt 	key.size = len + 1;
    219       1.4  deraadt 
    220      1.10  deraadt 	/*
    221      1.10  deraadt 	 * If there is a user called "+", then YP is active. In that
    222      1.10  deraadt 	 * case we must sequence through the passwd file in sequence.
    223      1.10  deraadt 	 */
    224      1.10  deraadt 	if ( __hashpw(&key)) {
    225      1.10  deraadt 		int r;
    226       1.4  deraadt 
    227      1.10  deraadt 		for(_pw_keynum=1; _pw_keynum; _pw_keynum++) {
    228      1.10  deraadt 			bf[0] = _PW_KEYBYNUM;
    229      1.10  deraadt 			bcopy((char *)&_pw_keynum, bf + 1, sizeof(_pw_keynum));
    230      1.10  deraadt 			key.data = (u_char *)bf;
    231      1.10  deraadt 			key.size = sizeof(_pw_keynum) + 1;
    232      1.10  deraadt 			if(__hashpw(&key) == 0)
    233      1.10  deraadt 				break;
    234      1.10  deraadt 			if(strcmp(_pw_passwd.pw_name, "+") == 0) {
    235      1.10  deraadt 				if(!__ypdomain) {
    236      1.10  deraadt 					if(_yp_check(&__ypdomain) == 0) {
    237      1.10  deraadt 						continue;
    238      1.10  deraadt 					}
    239      1.10  deraadt 				}
    240      1.10  deraadt 				if(__ypcurrent) {
    241      1.10  deraadt 					free(__ypcurrent);
    242      1.10  deraadt 					__ypcurrent = NULL;
    243      1.10  deraadt 				}
    244      1.10  deraadt 				r = yp_match(__ypdomain, "passwd.byname",
    245      1.10  deraadt 					name, strlen(name),
    246      1.10  deraadt 					&__ypcurrent, &__ypcurrentlen);
    247      1.10  deraadt 				switch(r) {
    248      1.10  deraadt 				case 0:
    249      1.10  deraadt 					break;
    250      1.10  deraadt 				default:
    251      1.10  deraadt 					free(__ypcurrent);
    252      1.10  deraadt 					__ypcurrent = NULL;
    253       1.4  deraadt 					continue;
    254       1.4  deraadt 				}
    255      1.10  deraadt 				bcopy(__ypcurrent, line, __ypcurrentlen);
    256      1.10  deraadt 				line[__ypcurrentlen] = '\0';
    257      1.10  deraadt 				if(__ypparse(&_pw_passwd, line))
    258      1.10  deraadt 					continue;
    259       1.4  deraadt 			}
    260      1.10  deraadt 			if( strcmp(_pw_passwd.pw_name, name) == 0) {
    261      1.10  deraadt 				if (!_pw_stayopen) {
    262      1.10  deraadt 					(void)(_pw_db->close)(_pw_db);
    263      1.10  deraadt 					_pw_db = (DB *)NULL;
    264      1.10  deraadt 				}
    265      1.10  deraadt 				return &_pw_passwd;
    266       1.4  deraadt 			}
    267      1.10  deraadt 			continue;
    268       1.4  deraadt 		}
    269      1.10  deraadt 		if (!_pw_stayopen) {
    270      1.10  deraadt 			(void)(_pw_db->close)(_pw_db);
    271      1.10  deraadt 			_pw_db = (DB *)NULL;
    272       1.4  deraadt 		}
    273      1.10  deraadt 		return (struct passwd *)NULL;
    274       1.4  deraadt 	}
    275      1.10  deraadt #endif /* YP */
    276       1.1      cgd 
    277       1.1      cgd 	bf[0] = _PW_KEYBYNAME;
    278       1.1      cgd 	len = strlen(name);
    279       1.1      cgd 	bcopy(name, bf + 1, MIN(len, UT_NAMESIZE));
    280       1.1      cgd 	key.data = (u_char *)bf;
    281       1.1      cgd 	key.size = len + 1;
    282       1.1      cgd 	rval = __hashpw(&key);
    283       1.1      cgd 
    284       1.1      cgd 	if (!_pw_stayopen) {
    285       1.1      cgd 		(void)(_pw_db->close)(_pw_db);
    286       1.1      cgd 		_pw_db = (DB *)NULL;
    287       1.1      cgd 	}
    288       1.1      cgd 	return(rval ? &_pw_passwd : (struct passwd *)NULL);
    289       1.1      cgd }
    290       1.1      cgd 
    291       1.1      cgd struct passwd *
    292       1.1      cgd #ifdef __STDC__
    293       1.1      cgd getpwuid(uid_t uid)
    294       1.1      cgd #else
    295       1.1      cgd getpwuid(uid)
    296       1.1      cgd 	int uid;
    297       1.1      cgd #endif
    298       1.1      cgd {
    299       1.1      cgd 	DBT key;
    300      1.10  deraadt 	char bf[sizeof(_pw_keynum) + 1];
    301      1.10  deraadt 	int keyuid, rval, len;
    302      1.10  deraadt 
    303      1.10  deraadt 	if (!_pw_db && !__initdb())
    304      1.10  deraadt 		return((struct passwd *)NULL);
    305       1.4  deraadt 
    306       1.4  deraadt #ifdef YP
    307      1.10  deraadt 	bf[0] = _PW_KEYBYNAME;
    308      1.10  deraadt 	len = strlen("+");
    309      1.10  deraadt 	bcopy("+", bf + 1, MIN(len, UT_NAMESIZE));
    310      1.10  deraadt 	key.data = (u_char *)bf;
    311      1.10  deraadt 	key.size = len + 1;
    312       1.4  deraadt 
    313      1.10  deraadt 	/*
    314      1.10  deraadt 	 * If there is a user called "+", then YP is active. In that
    315      1.10  deraadt 	 * case we must sequence through the passwd file in sequence.
    316      1.10  deraadt 	 */
    317      1.10  deraadt 	if ( __hashpw(&key)) {
    318      1.10  deraadt 		char uidbuf[20];
    319      1.10  deraadt 		int r;
    320       1.4  deraadt 
    321      1.10  deraadt 		for(_pw_keynum=1; _pw_keynum; _pw_keynum++) {
    322      1.10  deraadt 			bf[0] = _PW_KEYBYNUM;
    323      1.10  deraadt 			bcopy((char *)&_pw_keynum, bf + 1, sizeof(_pw_keynum));
    324      1.10  deraadt 			key.data = (u_char *)bf;
    325      1.10  deraadt 			key.size = sizeof(_pw_keynum) + 1;
    326      1.10  deraadt 			if(__hashpw(&key) == 0)
    327      1.10  deraadt 				break;
    328      1.10  deraadt 			if(strcmp(_pw_passwd.pw_name, "+") == 0) {
    329      1.10  deraadt 				if(!__ypdomain) {
    330      1.10  deraadt 					if(_yp_check(&__ypdomain) == 0) {
    331      1.10  deraadt 						continue;
    332      1.10  deraadt 					}
    333      1.10  deraadt 				}
    334      1.10  deraadt 				if(__ypcurrent) {
    335      1.10  deraadt 					free(__ypcurrent);
    336      1.10  deraadt 					__ypcurrent = NULL;
    337      1.10  deraadt 				}
    338      1.10  deraadt 				sprintf(uidbuf, "%d", uid);
    339      1.10  deraadt 				r = yp_match(__ypdomain, "passwd.byuid",
    340      1.10  deraadt 					uidbuf, strlen(uidbuf),
    341      1.10  deraadt 					&__ypcurrent, &__ypcurrentlen);
    342      1.10  deraadt 				switch(r) {
    343      1.10  deraadt 				case 0:
    344      1.10  deraadt 					break;
    345      1.10  deraadt 				default:
    346      1.10  deraadt 					free(__ypcurrent);
    347      1.10  deraadt 					__ypcurrent = NULL;
    348       1.4  deraadt 					continue;
    349       1.4  deraadt 				}
    350      1.10  deraadt 				bcopy(__ypcurrent, line, __ypcurrentlen);
    351      1.10  deraadt 				line[__ypcurrentlen] = '\0';
    352      1.10  deraadt 				if(__ypparse(&_pw_passwd, line))
    353      1.10  deraadt 					continue;
    354       1.4  deraadt 			}
    355      1.10  deraadt 			if( _pw_passwd.pw_uid == uid) {
    356      1.10  deraadt 				if (!_pw_stayopen) {
    357      1.10  deraadt 					(void)(_pw_db->close)(_pw_db);
    358      1.10  deraadt 					_pw_db = (DB *)NULL;
    359      1.10  deraadt 				}
    360      1.10  deraadt 				return &_pw_passwd;
    361       1.4  deraadt 			}
    362      1.10  deraadt 			continue;
    363       1.4  deraadt 		}
    364      1.10  deraadt 		if (!_pw_stayopen) {
    365      1.10  deraadt 			(void)(_pw_db->close)(_pw_db);
    366      1.10  deraadt 			_pw_db = (DB *)NULL;
    367       1.4  deraadt 		}
    368      1.10  deraadt 		return (struct passwd *)NULL;
    369       1.4  deraadt 	}
    370      1.10  deraadt #endif /* YP */
    371       1.1      cgd 
    372       1.1      cgd 	bf[0] = _PW_KEYBYUID;
    373       1.1      cgd 	keyuid = uid;
    374       1.1      cgd 	bcopy(&keyuid, bf + 1, sizeof(keyuid));
    375       1.1      cgd 	key.data = (u_char *)bf;
    376       1.1      cgd 	key.size = sizeof(keyuid) + 1;
    377       1.1      cgd 	rval = __hashpw(&key);
    378       1.1      cgd 
    379       1.1      cgd 	if (!_pw_stayopen) {
    380       1.1      cgd 		(void)(_pw_db->close)(_pw_db);
    381       1.1      cgd 		_pw_db = (DB *)NULL;
    382       1.1      cgd 	}
    383       1.1      cgd 	return(rval ? &_pw_passwd : (struct passwd *)NULL);
    384       1.1      cgd }
    385       1.1      cgd 
    386       1.1      cgd int
    387       1.1      cgd setpassent(stayopen)
    388       1.1      cgd 	int stayopen;
    389       1.1      cgd {
    390       1.1      cgd 	_pw_keynum = 0;
    391       1.1      cgd 	_pw_stayopen = stayopen;
    392       1.9      jtc #ifdef YP
    393       1.9      jtc 	__ypmode = 0;
    394       1.9      jtc 	if(__ypcurrent)
    395       1.9      jtc 		free(__ypcurrent);
    396       1.9      jtc 	__ypcurrent = NULL;
    397       1.9      jtc #endif
    398       1.1      cgd 	return(1);
    399       1.1      cgd }
    400       1.1      cgd 
    401       1.8      jtc void
    402       1.1      cgd setpwent()
    403       1.1      cgd {
    404       1.9      jtc 	(void) setpassent(0);
    405       1.1      cgd }
    406       1.1      cgd 
    407       1.1      cgd void
    408       1.1      cgd endpwent()
    409       1.1      cgd {
    410       1.1      cgd 	_pw_keynum = 0;
    411       1.1      cgd 	if (_pw_db) {
    412       1.1      cgd 		(void)(_pw_db->close)(_pw_db);
    413       1.1      cgd 		_pw_db = (DB *)NULL;
    414       1.1      cgd 	}
    415       1.4  deraadt #ifdef YP
    416       1.4  deraadt 	__ypmode = 0;
    417       1.4  deraadt 	if(__ypcurrent)
    418       1.4  deraadt 		free(__ypcurrent);
    419       1.4  deraadt 	__ypcurrent = NULL;
    420       1.4  deraadt #endif
    421       1.1      cgd }
    422       1.1      cgd 
    423       1.4  deraadt static int
    424       1.1      cgd __initdb()
    425       1.1      cgd {
    426       1.1      cgd 	static int warned;
    427       1.1      cgd 	char *p;
    428       1.1      cgd 
    429       1.1      cgd 	p = (geteuid()) ? _PATH_MP_DB : _PATH_SMP_DB;
    430       1.3   proven 	_pw_db = dbopen(p, O_RDONLY, 0, DB_HASH, NULL);
    431       1.1      cgd 	if (_pw_db)
    432       1.1      cgd 		return(1);
    433       1.1      cgd 	if (!warned)
    434       1.1      cgd 		syslog(LOG_ERR, "%s: %m", p);
    435      1.11  deraadt 	warned = 1;
    436       1.1      cgd 	return(0);
    437       1.1      cgd }
    438       1.1      cgd 
    439       1.4  deraadt static int
    440       1.1      cgd __hashpw(key)
    441       1.1      cgd 	DBT *key;
    442       1.1      cgd {
    443       1.1      cgd 	register char *p, *t;
    444       1.1      cgd 	static u_int max;
    445       1.1      cgd 	static char *line;
    446       1.1      cgd 	DBT data;
    447       1.1      cgd 
    448       1.1      cgd 	if ((_pw_db->get)(_pw_db, key, &data, 0))
    449       1.1      cgd 		return(0);
    450       1.1      cgd 	p = (char *)data.data;
    451       1.1      cgd 	if (data.size > max && !(line = realloc(line, max += 1024)))
    452       1.1      cgd 		return(0);
    453       1.1      cgd 
    454       1.1      cgd 	t = line;
    455       1.1      cgd #define	EXPAND(e)	e = t; while (*t++ = *p++);
    456       1.1      cgd 	EXPAND(_pw_passwd.pw_name);
    457       1.1      cgd 	EXPAND(_pw_passwd.pw_passwd);
    458       1.1      cgd 	bcopy(p, (char *)&_pw_passwd.pw_uid, sizeof(int));
    459       1.1      cgd 	p += sizeof(int);
    460       1.1      cgd 	bcopy(p, (char *)&_pw_passwd.pw_gid, sizeof(int));
    461       1.1      cgd 	p += sizeof(int);
    462       1.1      cgd 	bcopy(p, (char *)&_pw_passwd.pw_change, sizeof(time_t));
    463       1.1      cgd 	p += sizeof(time_t);
    464       1.1      cgd 	EXPAND(_pw_passwd.pw_class);
    465       1.1      cgd 	EXPAND(_pw_passwd.pw_gecos);
    466       1.1      cgd 	EXPAND(_pw_passwd.pw_dir);
    467       1.1      cgd 	EXPAND(_pw_passwd.pw_shell);
    468       1.1      cgd 	bcopy(p, (char *)&_pw_passwd.pw_expire, sizeof(time_t));
    469       1.1      cgd 	p += sizeof(time_t);
    470       1.1      cgd 	return(1);
    471       1.1      cgd }
    472