1997-05-22 07:14:42 +04:00
|
|
|
/* $NetBSD: getpwent.c,v 1.19 1997/05/22 03:14:42 lukem Exp $ */
|
1995-02-27 07:12:15 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1995-02-27 07:12:15 +03:00
|
|
|
* Copyright (c) 1988, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1995-07-28 09:43:01 +04:00
|
|
|
* Portions Copyright (c) 1994, 1995, Jason Downs. All rights reserved.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if defined(LIBC_SCCS) && !defined(lint)
|
1995-02-27 07:12:15 +03:00
|
|
|
#if 0
|
|
|
|
static char sccsid[] = "@(#)getpwent.c 8.1 (Berkeley) 6/4/93";
|
|
|
|
#else
|
1997-05-22 07:14:42 +04:00
|
|
|
static char rcsid[] = "$NetBSD: getpwent.c,v 1.19 1997/05/22 03:14:42 lukem Exp $";
|
1995-02-27 07:12:15 +03:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif /* LIBC_SCCS and not lint */
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <db.h>
|
|
|
|
#include <syslog.h>
|
|
|
|
#include <pwd.h>
|
|
|
|
#include <utmp.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <limits.h>
|
1995-07-28 09:43:01 +04:00
|
|
|
#include <netgroup.h>
|
1993-05-04 09:10:45 +04:00
|
|
|
#ifdef YP
|
1995-07-28 09:43:01 +04:00
|
|
|
#include <machine/param.h>
|
1993-05-04 09:10:45 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <rpc/rpc.h>
|
|
|
|
#include <rpcsvc/yp_prot.h>
|
|
|
|
#include <rpcsvc/ypclnt.h>
|
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
static struct passwd _pw_passwd; /* password structure */
|
|
|
|
static DB *_pw_db; /* password database */
|
|
|
|
static int _pw_keynum; /* key counter */
|
|
|
|
static int _pw_stayopen; /* keep fd's open */
|
1995-07-28 09:43:01 +04:00
|
|
|
static int _pw_flags; /* password flags */
|
|
|
|
static int __hashpw __P((DBT *));
|
|
|
|
static int __initdb __P((void));
|
|
|
|
|
|
|
|
const char __yp_token[] = "__YP!"; /* Let pwd_mkdb pull this in. */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1993-05-04 09:10:45 +04:00
|
|
|
#ifdef YP
|
1995-07-28 09:43:01 +04:00
|
|
|
enum _ypmode { YPMODE_NONE, YPMODE_FULL, YPMODE_USER, YPMODE_NETGRP };
|
|
|
|
static enum _ypmode __ypmode;
|
|
|
|
|
1993-05-04 09:10:45 +04:00
|
|
|
static char *__ypcurrent, *__ypdomain;
|
1995-07-28 09:43:01 +04:00
|
|
|
static int __ypcurrentlen;
|
|
|
|
static struct passwd *__ypproto = (struct passwd *)NULL;
|
|
|
|
static int __ypflags;
|
1993-05-04 09:10:45 +04:00
|
|
|
static char line[1024];
|
1995-07-28 09:43:01 +04:00
|
|
|
static long prbuf[1024 / sizeof(long)];
|
|
|
|
static DB *__ypexclude = (DB *)NULL;
|
|
|
|
|
|
|
|
static int __has_yppw __P((void));
|
|
|
|
static int __ypexclude_add __P((const char *));
|
|
|
|
static int __ypexclude_is __P((const char *));
|
|
|
|
static void __ypproto_set __P((void));
|
|
|
|
|
|
|
|
static int
|
|
|
|
__ypexclude_add(name)
|
|
|
|
const char *name;
|
|
|
|
{
|
|
|
|
DBT key, data;
|
|
|
|
|
|
|
|
/* initialize the exclusion table if needed. */
|
|
|
|
if(__ypexclude == (DB *)NULL) {
|
|
|
|
__ypexclude = dbopen(NULL, O_RDWR, 600, DB_HASH, NULL);
|
|
|
|
if(__ypexclude == (DB *)NULL)
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set up the key */
|
|
|
|
key.data = (char *)name;
|
|
|
|
key.size = strlen(name);
|
|
|
|
|
|
|
|
/* data is nothing. */
|
|
|
|
data.data = NULL;
|
|
|
|
data.size = 0;
|
|
|
|
|
|
|
|
/* store it */
|
|
|
|
if((__ypexclude->put)(__ypexclude, &key, &data, 0) == -1)
|
|
|
|
return(1);
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
__ypexclude_is(name)
|
|
|
|
const char *name;
|
|
|
|
{
|
|
|
|
DBT key, data;
|
|
|
|
|
|
|
|
if(__ypexclude == (DB *)NULL)
|
|
|
|
return(0); /* nothing excluded */
|
|
|
|
|
|
|
|
/* set up the key */
|
|
|
|
key.data = (char *)name;
|
|
|
|
key.size = strlen(name);
|
|
|
|
|
|
|
|
if((__ypexclude->get)(__ypexclude, &key, &data, 0) == 0)
|
|
|
|
return(1); /* excluded */
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
__ypproto_set()
|
|
|
|
{
|
1997-05-20 19:59:59 +04:00
|
|
|
char *ptr;
|
|
|
|
struct passwd *pw = &_pw_passwd;
|
1995-07-28 09:43:01 +04:00
|
|
|
|
|
|
|
/* make this the new prototype */
|
|
|
|
ptr = (char *)prbuf;
|
|
|
|
|
|
|
|
/* first allocate the struct. */
|
|
|
|
__ypproto = (struct passwd *)ptr;
|
|
|
|
ptr += sizeof(struct passwd);
|
|
|
|
|
|
|
|
/* name */
|
|
|
|
if(pw->pw_name && (pw->pw_name)[0]) {
|
|
|
|
ptr = (char *)ALIGN(ptr);
|
|
|
|
bcopy(pw->pw_name, ptr, strlen(pw->pw_name) + 1);
|
|
|
|
__ypproto->pw_name = ptr;
|
|
|
|
ptr += (strlen(pw->pw_name) + 1);
|
|
|
|
} else
|
|
|
|
__ypproto->pw_name = (char *)NULL;
|
|
|
|
|
|
|
|
/* password */
|
|
|
|
if(pw->pw_passwd && (pw->pw_passwd)[0]) {
|
|
|
|
ptr = (char *)ALIGN(ptr);
|
|
|
|
bcopy(pw->pw_passwd, ptr, strlen(pw->pw_passwd) + 1);
|
|
|
|
__ypproto->pw_passwd = ptr;
|
|
|
|
ptr += (strlen(pw->pw_passwd) + 1);
|
|
|
|
} else
|
|
|
|
__ypproto->pw_passwd = (char *)NULL;
|
|
|
|
|
|
|
|
/* uid */
|
|
|
|
__ypproto->pw_uid = pw->pw_uid;
|
|
|
|
|
|
|
|
/* gid */
|
|
|
|
__ypproto->pw_gid = pw->pw_gid;
|
|
|
|
|
|
|
|
/* change (ignored anyway) */
|
|
|
|
__ypproto->pw_change = pw->pw_change;
|
|
|
|
|
|
|
|
/* class (ignored anyway) */
|
|
|
|
__ypproto->pw_class = "";
|
|
|
|
|
|
|
|
/* gecos */
|
|
|
|
if(pw->pw_gecos && (pw->pw_gecos)[0]) {
|
|
|
|
ptr = (char *)ALIGN(ptr);
|
|
|
|
bcopy(pw->pw_gecos, ptr, strlen(pw->pw_gecos) + 1);
|
|
|
|
__ypproto->pw_gecos = ptr;
|
|
|
|
ptr += (strlen(pw->pw_gecos) + 1);
|
|
|
|
} else
|
|
|
|
__ypproto->pw_gecos = (char *)NULL;
|
|
|
|
|
|
|
|
/* dir */
|
|
|
|
if(pw->pw_dir && (pw->pw_dir)[0]) {
|
|
|
|
ptr = (char *)ALIGN(ptr);
|
|
|
|
bcopy(pw->pw_dir, ptr, strlen(pw->pw_dir) + 1);
|
|
|
|
__ypproto->pw_dir = ptr;
|
|
|
|
ptr += (strlen(pw->pw_dir) + 1);
|
|
|
|
} else
|
|
|
|
__ypproto->pw_dir = (char *)NULL;
|
|
|
|
|
|
|
|
/* shell */
|
|
|
|
if(pw->pw_shell && (pw->pw_shell)[0]) {
|
|
|
|
ptr = (char *)ALIGN(ptr);
|
|
|
|
bcopy(pw->pw_shell, ptr, strlen(pw->pw_shell) + 1);
|
|
|
|
__ypproto->pw_shell = ptr;
|
|
|
|
ptr += (strlen(pw->pw_shell) + 1);
|
|
|
|
} else
|
|
|
|
__ypproto->pw_shell = (char *)NULL;
|
|
|
|
|
|
|
|
/* expire (ignored anyway) */
|
|
|
|
__ypproto->pw_expire = pw->pw_expire;
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
__ypflags = _pw_flags;
|
|
|
|
}
|
1993-05-04 09:10:45 +04:00
|
|
|
|
1993-07-24 22:28:32 +04:00
|
|
|
static int
|
|
|
|
__ypparse(pw, s)
|
1993-05-04 09:10:45 +04:00
|
|
|
struct passwd *pw;
|
|
|
|
char *s;
|
|
|
|
{
|
1997-05-22 07:14:42 +04:00
|
|
|
char *bp, *cp, *ep;
|
|
|
|
unsigned long id;
|
1993-05-04 09:10:45 +04:00
|
|
|
|
1995-07-28 09:43:01 +04:00
|
|
|
/* since this is currently using strsep(), parse it first */
|
1993-05-04 09:10:45 +04:00
|
|
|
bp = s;
|
|
|
|
pw->pw_name = strsep(&bp, ":\n");
|
|
|
|
pw->pw_passwd = strsep(&bp, ":\n");
|
|
|
|
if (!(cp = strsep(&bp, ":\n")))
|
|
|
|
return 1;
|
1997-05-22 07:14:42 +04:00
|
|
|
id = strtoul(cp, &ep, 10);
|
|
|
|
if (id > UID_MAX || *ep == '\0')
|
|
|
|
return 1;
|
|
|
|
pw->pw_uid = (uid_t)id;
|
1993-05-04 09:10:45 +04:00
|
|
|
if (!(cp = strsep(&bp, ":\n")))
|
1995-05-17 21:36:43 +04:00
|
|
|
return 1;
|
1997-05-22 07:14:42 +04:00
|
|
|
id = strtoul(cp, &ep, 10);
|
|
|
|
if (id > GID_MAX || *ep == '\0')
|
|
|
|
return 1;
|
|
|
|
pw->pw_gid = (gid_t)id;
|
1993-05-04 09:10:45 +04:00
|
|
|
pw->pw_change = 0;
|
|
|
|
pw->pw_class = "";
|
|
|
|
pw->pw_gecos = strsep(&bp, ":\n");
|
|
|
|
pw->pw_dir = strsep(&bp, ":\n");
|
|
|
|
pw->pw_shell = strsep(&bp, ":\n");
|
|
|
|
pw->pw_expire = 0;
|
1995-07-28 09:43:01 +04:00
|
|
|
|
|
|
|
/* now let the prototype override, if set. */
|
|
|
|
if(__ypproto != (struct passwd *)NULL) {
|
|
|
|
#ifdef YP_OVERRIDE_PASSWD
|
|
|
|
if(__ypproto->pw_passwd != (char *)NULL)
|
|
|
|
pw->pw_passwd = __ypproto->pw_passwd;
|
|
|
|
#endif
|
|
|
|
if(!(__ypflags & _PASSWORD_NOUID))
|
|
|
|
pw->pw_uid = __ypproto->pw_uid;
|
|
|
|
if(!(__ypflags & _PASSWORD_NOGID))
|
|
|
|
pw->pw_gid = __ypproto->pw_gid;
|
|
|
|
if(__ypproto->pw_gecos != (char *)NULL)
|
|
|
|
pw->pw_gecos = __ypproto->pw_gecos;
|
|
|
|
if(__ypproto->pw_dir != (char *)NULL)
|
|
|
|
pw->pw_dir = __ypproto->pw_dir;
|
|
|
|
if(__ypproto->pw_shell != (char *)NULL)
|
|
|
|
pw->pw_shell = __ypproto->pw_shell;
|
|
|
|
}
|
1993-05-04 09:10:45 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
struct passwd *
|
|
|
|
getpwent()
|
|
|
|
{
|
|
|
|
DBT key;
|
|
|
|
char bf[sizeof(_pw_keynum) + 1];
|
1993-05-04 09:10:45 +04:00
|
|
|
#ifdef YP
|
1995-05-17 21:36:43 +04:00
|
|
|
char *cp;
|
1995-07-28 09:43:01 +04:00
|
|
|
static char *name = (char *)NULL;
|
|
|
|
const char *user, *host, *dom;
|
|
|
|
int has_yppw;
|
1993-05-04 09:10:45 +04:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
if (!_pw_db && !__initdb())
|
|
|
|
return((struct passwd *)NULL);
|
|
|
|
|
1993-05-04 09:10:45 +04:00
|
|
|
#ifdef YP
|
1995-07-28 09:43:01 +04:00
|
|
|
has_yppw = __has_yppw();
|
|
|
|
|
1993-05-04 09:10:45 +04:00
|
|
|
again:
|
1995-07-28 09:43:01 +04:00
|
|
|
if(has_yppw && (__ypmode != YPMODE_NONE)) {
|
1993-05-04 09:10:45 +04:00
|
|
|
char *key, *data;
|
|
|
|
int keylen, datalen;
|
1995-07-28 09:43:01 +04:00
|
|
|
int r, s;
|
1993-05-04 09:10:45 +04:00
|
|
|
|
|
|
|
if(!__ypdomain) {
|
|
|
|
if( _yp_check(&__ypdomain) == 0) {
|
1995-07-28 09:43:01 +04:00
|
|
|
__ypmode = YPMODE_NONE;
|
1993-05-04 09:10:45 +04:00
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
}
|
1995-07-28 09:43:01 +04:00
|
|
|
switch(__ypmode) {
|
|
|
|
case YPMODE_FULL:
|
1997-05-20 19:59:59 +04:00
|
|
|
data = NULL;
|
1995-07-28 09:43:01 +04:00
|
|
|
if(__ypcurrent) {
|
1997-05-21 05:51:39 +04:00
|
|
|
key = NULL;
|
1995-07-28 09:43:01 +04:00
|
|
|
r = yp_next(__ypdomain, "passwd.byname",
|
|
|
|
__ypcurrent, __ypcurrentlen,
|
|
|
|
&key, &keylen, &data, &datalen);
|
|
|
|
free(__ypcurrent);
|
1997-05-21 05:51:39 +04:00
|
|
|
if(r != 0) {
|
1995-07-28 09:43:01 +04:00
|
|
|
__ypcurrent = NULL;
|
1997-05-21 05:51:39 +04:00
|
|
|
if (key)
|
|
|
|
free(key);
|
|
|
|
}
|
1997-05-20 19:59:59 +04:00
|
|
|
else {
|
|
|
|
__ypcurrent = key;
|
|
|
|
__ypcurrentlen = keylen;
|
1995-07-28 09:43:01 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
r = yp_first(__ypdomain, "passwd.byname",
|
|
|
|
&__ypcurrent, &__ypcurrentlen,
|
|
|
|
&data, &datalen);
|
1997-05-20 19:59:59 +04:00
|
|
|
}
|
|
|
|
if(r != 0) {
|
|
|
|
__ypmode = YPMODE_NONE;
|
|
|
|
if(data)
|
|
|
|
free(data);
|
1995-07-28 09:43:01 +04:00
|
|
|
data = NULL;
|
1997-05-20 19:59:59 +04:00
|
|
|
goto again;
|
1995-07-28 09:43:01 +04:00
|
|
|
}
|
1997-05-20 19:59:59 +04:00
|
|
|
bcopy(data, line, datalen);
|
|
|
|
free(data);
|
|
|
|
data = NULL;
|
1995-07-28 09:43:01 +04:00
|
|
|
break;
|
|
|
|
case YPMODE_NETGRP:
|
|
|
|
s = getnetgrent(&host, &user, &dom);
|
|
|
|
if(s == 0) { /* end of group */
|
|
|
|
endnetgrent();
|
|
|
|
__ypmode = YPMODE_NONE;
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
if(user && *user) {
|
1997-05-20 19:59:59 +04:00
|
|
|
data = NULL;
|
1995-07-28 09:43:01 +04:00
|
|
|
r = yp_match(__ypdomain, "passwd.byname",
|
|
|
|
user, strlen(user),
|
|
|
|
&data, &datalen);
|
|
|
|
} else
|
|
|
|
goto again;
|
|
|
|
if(r != 0) {
|
|
|
|
/*
|
|
|
|
* if the netgroup is invalid, keep looking
|
|
|
|
* as there may be valid users later on.
|
|
|
|
*/
|
|
|
|
if(data)
|
|
|
|
free(data);
|
1993-05-04 09:10:45 +04:00
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
bcopy(data, line, datalen);
|
|
|
|
free(data);
|
1997-05-20 19:59:59 +04:00
|
|
|
data = NULL;
|
1995-07-28 09:43:01 +04:00
|
|
|
break;
|
|
|
|
case YPMODE_USER:
|
|
|
|
if(name != (char *)NULL) {
|
1997-05-20 19:59:59 +04:00
|
|
|
data = NULL;
|
1995-07-28 09:43:01 +04:00
|
|
|
r = yp_match(__ypdomain, "passwd.byname",
|
|
|
|
name, strlen(name),
|
|
|
|
&data, &datalen);
|
|
|
|
__ypmode = YPMODE_NONE;
|
|
|
|
free(name);
|
1997-05-20 19:59:59 +04:00
|
|
|
name = NULL;
|
1995-07-28 09:43:01 +04:00
|
|
|
if(r != 0) {
|
|
|
|
if(data)
|
|
|
|
free(data);
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
bcopy(data, line, datalen);
|
1993-05-04 09:10:45 +04:00
|
|
|
free(data);
|
1995-07-28 09:43:01 +04:00
|
|
|
data = (char *)NULL;
|
|
|
|
} else { /* XXX */
|
|
|
|
__ypmode = YPMODE_NONE;
|
1993-05-04 09:10:45 +04:00
|
|
|
goto again;
|
|
|
|
}
|
1995-07-28 09:43:01 +04:00
|
|
|
break;
|
1993-05-04 09:10:45 +04:00
|
|
|
}
|
1995-07-28 09:43:01 +04:00
|
|
|
|
1993-05-04 09:10:45 +04:00
|
|
|
line[datalen] = '\0';
|
1995-05-17 21:36:43 +04:00
|
|
|
if (__ypparse(&_pw_passwd, line))
|
|
|
|
goto again;
|
|
|
|
return &_pw_passwd;
|
1993-05-04 09:10:45 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
++_pw_keynum;
|
|
|
|
bf[0] = _PW_KEYBYNUM;
|
|
|
|
bcopy((char *)&_pw_keynum, bf + 1, sizeof(_pw_keynum));
|
|
|
|
key.data = (u_char *)bf;
|
|
|
|
key.size = sizeof(_pw_keynum) + 1;
|
1993-05-04 09:10:45 +04:00
|
|
|
if(__hashpw(&key)) {
|
|
|
|
#ifdef YP
|
1995-07-28 09:43:01 +04:00
|
|
|
/* if we don't have YP at all, don't bother. */
|
|
|
|
if(has_yppw) {
|
|
|
|
if(_pw_passwd.pw_name[0] == '+') {
|
|
|
|
/* set the mode */
|
|
|
|
switch(_pw_passwd.pw_name[1]) {
|
|
|
|
case '\0':
|
|
|
|
__ypmode = YPMODE_FULL;
|
|
|
|
break;
|
|
|
|
case '@':
|
|
|
|
__ypmode = YPMODE_NETGRP;
|
|
|
|
setnetgrent(_pw_passwd.pw_name + 2);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
__ypmode = YPMODE_USER;
|
|
|
|
name = strdup(_pw_passwd.pw_name + 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* save the prototype */
|
|
|
|
__ypproto_set();
|
|
|
|
goto again;
|
|
|
|
} else if(_pw_passwd.pw_name[0] == '-') {
|
|
|
|
/* an attempted exclusion */
|
|
|
|
switch(_pw_passwd.pw_name[1]) {
|
|
|
|
case '\0':
|
|
|
|
break;
|
|
|
|
case '@':
|
|
|
|
setnetgrent(_pw_passwd.pw_name + 2);
|
|
|
|
while(getnetgrent(&host, &user, &dom)) {
|
|
|
|
if(user && *user)
|
|
|
|
__ypexclude_add(user);
|
|
|
|
}
|
|
|
|
endnetgrent();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
__ypexclude_add(_pw_passwd.pw_name + 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
goto again;
|
|
|
|
}
|
1993-05-04 09:10:45 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return &_pw_passwd;
|
|
|
|
}
|
|
|
|
return (struct passwd *)NULL;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1995-07-28 09:43:01 +04:00
|
|
|
#ifdef YP
|
|
|
|
|
|
|
|
/*
|
|
|
|
* See if the YP token is in the database. Only works if pwd_mkdb knows
|
|
|
|
* about the token.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
__has_yppw()
|
|
|
|
{
|
|
|
|
DBT key, data;
|
|
|
|
DBT pkey, pdata;
|
|
|
|
int len;
|
1996-12-20 23:16:05 +03:00
|
|
|
char bf[MAXLOGNAME];
|
1995-07-28 09:43:01 +04:00
|
|
|
|
|
|
|
key.data = (u_char *)__yp_token;
|
|
|
|
key.size = strlen(__yp_token);
|
|
|
|
|
|
|
|
/* Pre-token database support. */
|
|
|
|
bf[0] = _PW_KEYBYNAME;
|
1996-12-20 23:16:05 +03:00
|
|
|
bf[1] = '+';
|
1995-07-28 09:43:01 +04:00
|
|
|
pkey.data = (u_char *)bf;
|
1996-12-20 23:16:05 +03:00
|
|
|
pkey.size = 2;
|
1995-07-28 09:43:01 +04:00
|
|
|
|
|
|
|
if ((_pw_db->get)(_pw_db, &key, &data, 0)
|
|
|
|
&& (_pw_db->get)(_pw_db, &pkey, &pdata, 0))
|
|
|
|
return(0); /* No YP. */
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
struct passwd *
|
|
|
|
getpwnam(name)
|
|
|
|
const char *name;
|
|
|
|
{
|
|
|
|
DBT key;
|
1993-12-10 15:46:29 +03:00
|
|
|
int len, rval;
|
1996-12-20 23:16:05 +03:00
|
|
|
char bf[MAXLOGNAME + 1];
|
1993-05-04 09:10:45 +04:00
|
|
|
|
|
|
|
if (!_pw_db && !__initdb())
|
|
|
|
return((struct passwd *)NULL);
|
|
|
|
|
1993-12-10 15:46:29 +03:00
|
|
|
#ifdef YP
|
|
|
|
/*
|
1995-07-28 09:43:01 +04:00
|
|
|
* If YP is active, we must sequence through the passwd file
|
|
|
|
* in sequence.
|
1993-12-10 15:46:29 +03:00
|
|
|
*/
|
1995-07-28 09:43:01 +04:00
|
|
|
if (__has_yppw()) {
|
1993-12-10 15:46:29 +03:00
|
|
|
int r;
|
1995-07-28 09:43:01 +04:00
|
|
|
int s = -1;
|
|
|
|
const char *host, *user, *dom;
|
1993-12-10 15:46:29 +03:00
|
|
|
|
|
|
|
for(_pw_keynum=1; _pw_keynum; _pw_keynum++) {
|
|
|
|
bf[0] = _PW_KEYBYNUM;
|
|
|
|
bcopy((char *)&_pw_keynum, bf + 1, sizeof(_pw_keynum));
|
|
|
|
key.data = (u_char *)bf;
|
|
|
|
key.size = sizeof(_pw_keynum) + 1;
|
|
|
|
if(__hashpw(&key) == 0)
|
|
|
|
break;
|
1995-07-28 09:43:01 +04:00
|
|
|
switch(_pw_passwd.pw_name[0]) {
|
|
|
|
case '+':
|
1993-12-10 15:46:29 +03:00
|
|
|
if(!__ypdomain) {
|
|
|
|
if(_yp_check(&__ypdomain) == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
1995-07-28 09:43:01 +04:00
|
|
|
/* save the prototype */
|
|
|
|
__ypproto_set();
|
|
|
|
|
|
|
|
switch(_pw_passwd.pw_name[1]) {
|
|
|
|
case '\0':
|
|
|
|
if(__ypcurrent) {
|
|
|
|
free(__ypcurrent);
|
|
|
|
__ypcurrent = NULL;
|
|
|
|
}
|
|
|
|
r = yp_match(__ypdomain,
|
|
|
|
"passwd.byname",
|
|
|
|
name, strlen(name),
|
|
|
|
&__ypcurrent, &__ypcurrentlen);
|
|
|
|
if(r != 0) {
|
|
|
|
if(__ypcurrent)
|
|
|
|
free(__ypcurrent);
|
|
|
|
__ypcurrent = NULL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '@':
|
|
|
|
pwnam_netgrp:
|
|
|
|
if(__ypcurrent) {
|
|
|
|
free(__ypcurrent);
|
|
|
|
__ypcurrent = NULL;
|
|
|
|
}
|
|
|
|
if(s == -1) /* first time */
|
|
|
|
setnetgrent(_pw_passwd.pw_name + 2);
|
|
|
|
s = getnetgrent(&host, &user, &dom);
|
|
|
|
if(s == 0) { /* end of group */
|
|
|
|
endnetgrent();
|
|
|
|
s = -1;
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
if(user && *user) {
|
|
|
|
r = yp_match(__ypdomain,
|
|
|
|
"passwd.byname",
|
|
|
|
user, strlen(user),
|
|
|
|
&__ypcurrent,
|
|
|
|
&__ypcurrentlen);
|
|
|
|
} else
|
|
|
|
goto pwnam_netgrp;
|
|
|
|
if(r != 0) {
|
|
|
|
if(__ypcurrent)
|
|
|
|
free(__ypcurrent);
|
|
|
|
__ypcurrent = NULL;
|
|
|
|
/*
|
|
|
|
* just because this
|
|
|
|
* user is bad, doesn't
|
|
|
|
* mean they all are.
|
|
|
|
*/
|
|
|
|
goto pwnam_netgrp;
|
|
|
|
}
|
|
|
|
}
|
1993-12-10 15:46:29 +03:00
|
|
|
break;
|
|
|
|
default:
|
1995-07-28 09:43:01 +04:00
|
|
|
if(__ypcurrent) {
|
|
|
|
free(__ypcurrent);
|
|
|
|
__ypcurrent = NULL;
|
|
|
|
}
|
|
|
|
user = _pw_passwd.pw_name + 1;
|
|
|
|
r = yp_match(__ypdomain,
|
|
|
|
"passwd.byname",
|
|
|
|
user, strlen(user),
|
|
|
|
&__ypcurrent,
|
|
|
|
&__ypcurrentlen);
|
|
|
|
if(r != 0) {
|
|
|
|
if(__ypcurrent)
|
|
|
|
free(__ypcurrent);
|
|
|
|
__ypcurrent = NULL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
1993-05-04 09:10:45 +04:00
|
|
|
}
|
1993-12-10 15:46:29 +03:00
|
|
|
bcopy(__ypcurrent, line, __ypcurrentlen);
|
|
|
|
line[__ypcurrentlen] = '\0';
|
1995-07-28 09:43:01 +04:00
|
|
|
if(__ypparse(&_pw_passwd, line)
|
|
|
|
|| __ypexclude_is(_pw_passwd.pw_name)) {
|
|
|
|
if(s == 1) /* inside netgrp */
|
|
|
|
goto pwnam_netgrp;
|
1993-12-10 15:46:29 +03:00
|
|
|
continue;
|
1995-07-28 09:43:01 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '-':
|
|
|
|
/* attempted exclusion */
|
|
|
|
switch(_pw_passwd.pw_name[1]) {
|
|
|
|
case '\0':
|
|
|
|
break;
|
|
|
|
case '@':
|
|
|
|
setnetgrent(_pw_passwd.pw_name + 2);
|
|
|
|
while(getnetgrent(&host, &user, &dom)) {
|
|
|
|
if(user && *user)
|
|
|
|
__ypexclude_add(user);
|
|
|
|
}
|
|
|
|
endnetgrent();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
__ypexclude_add(_pw_passwd.pw_name + 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
continue;
|
1993-05-04 09:10:45 +04:00
|
|
|
}
|
1995-07-28 09:43:01 +04:00
|
|
|
if(strcmp(_pw_passwd.pw_name, name) == 0) {
|
1993-12-10 15:46:29 +03:00
|
|
|
if (!_pw_stayopen) {
|
|
|
|
(void)(_pw_db->close)(_pw_db);
|
|
|
|
_pw_db = (DB *)NULL;
|
|
|
|
}
|
1995-07-28 09:43:01 +04:00
|
|
|
if(__ypexclude != (DB *)NULL) {
|
|
|
|
(void)(__ypexclude->close)(__ypexclude);
|
|
|
|
__ypexclude = (DB *)NULL;
|
|
|
|
}
|
|
|
|
__ypproto = (struct passwd *)NULL;
|
1993-12-10 15:46:29 +03:00
|
|
|
return &_pw_passwd;
|
1993-05-04 09:10:45 +04:00
|
|
|
}
|
1995-07-28 09:43:01 +04:00
|
|
|
if(s == 1) /* inside netgrp */
|
|
|
|
goto pwnam_netgrp;
|
1993-12-10 15:46:29 +03:00
|
|
|
continue;
|
1993-05-04 09:10:45 +04:00
|
|
|
}
|
1993-12-10 15:46:29 +03:00
|
|
|
if (!_pw_stayopen) {
|
|
|
|
(void)(_pw_db->close)(_pw_db);
|
|
|
|
_pw_db = (DB *)NULL;
|
1993-05-04 09:10:45 +04:00
|
|
|
}
|
1995-07-28 09:43:01 +04:00
|
|
|
if(__ypexclude != (DB *)NULL) {
|
|
|
|
(void)(__ypexclude->close)(__ypexclude);
|
|
|
|
__ypexclude = (DB *)NULL;
|
|
|
|
}
|
|
|
|
__ypproto = (struct passwd *)NULL;
|
1993-12-10 15:46:29 +03:00
|
|
|
return (struct passwd *)NULL;
|
1993-05-04 09:10:45 +04:00
|
|
|
}
|
1993-12-10 15:46:29 +03:00
|
|
|
#endif /* YP */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
bf[0] = _PW_KEYBYNAME;
|
|
|
|
len = strlen(name);
|
1996-12-20 23:16:05 +03:00
|
|
|
len = MIN(len, MAXLOGNAME);
|
|
|
|
bcopy(name, bf + 1, len);
|
1993-03-21 12:45:37 +03:00
|
|
|
key.data = (u_char *)bf;
|
|
|
|
key.size = len + 1;
|
|
|
|
rval = __hashpw(&key);
|
|
|
|
|
|
|
|
if (!_pw_stayopen) {
|
|
|
|
(void)(_pw_db->close)(_pw_db);
|
|
|
|
_pw_db = (DB *)NULL;
|
|
|
|
}
|
|
|
|
return(rval ? &_pw_passwd : (struct passwd *)NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct passwd *
|
|
|
|
#ifdef __STDC__
|
|
|
|
getpwuid(uid_t uid)
|
|
|
|
#else
|
|
|
|
getpwuid(uid)
|
|
|
|
int uid;
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
DBT key;
|
1993-12-10 15:46:29 +03:00
|
|
|
char bf[sizeof(_pw_keynum) + 1];
|
1997-05-22 07:14:42 +04:00
|
|
|
uid_t keyuid;
|
|
|
|
int rval;
|
1993-05-04 09:10:45 +04:00
|
|
|
|
|
|
|
if (!_pw_db && !__initdb())
|
|
|
|
return((struct passwd *)NULL);
|
|
|
|
|
1993-12-10 15:46:29 +03:00
|
|
|
#ifdef YP
|
|
|
|
/*
|
1995-07-28 09:43:01 +04:00
|
|
|
* If YP is active, we must sequence through the passwd file
|
|
|
|
* in sequence.
|
1993-12-10 15:46:29 +03:00
|
|
|
*/
|
1995-07-28 09:43:01 +04:00
|
|
|
if (__has_yppw()) {
|
1993-12-10 15:46:29 +03:00
|
|
|
char uidbuf[20];
|
|
|
|
int r;
|
1995-07-28 09:43:01 +04:00
|
|
|
int s = -1;
|
|
|
|
const char *host, *user, *dom;
|
1993-12-10 15:46:29 +03:00
|
|
|
|
1997-05-22 07:14:42 +04:00
|
|
|
snprintf(uidbuf, sizeof(uidbuf), "%u", uid);
|
1993-12-10 15:46:29 +03:00
|
|
|
for(_pw_keynum=1; _pw_keynum; _pw_keynum++) {
|
|
|
|
bf[0] = _PW_KEYBYNUM;
|
|
|
|
bcopy((char *)&_pw_keynum, bf + 1, sizeof(_pw_keynum));
|
|
|
|
key.data = (u_char *)bf;
|
|
|
|
key.size = sizeof(_pw_keynum) + 1;
|
|
|
|
if(__hashpw(&key) == 0)
|
|
|
|
break;
|
1995-07-28 09:43:01 +04:00
|
|
|
switch(_pw_passwd.pw_name[0]) {
|
|
|
|
case '+':
|
1993-12-10 15:46:29 +03:00
|
|
|
if(!__ypdomain) {
|
|
|
|
if(_yp_check(&__ypdomain) == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
1995-07-28 09:43:01 +04:00
|
|
|
/* save the prototype */
|
|
|
|
__ypproto_set();
|
|
|
|
|
|
|
|
switch(_pw_passwd.pw_name[1]) {
|
|
|
|
case '\0':
|
|
|
|
if(__ypcurrent) {
|
|
|
|
free(__ypcurrent);
|
|
|
|
__ypcurrent = NULL;
|
|
|
|
}
|
|
|
|
r = yp_match(__ypdomain, "passwd.byuid",
|
|
|
|
uidbuf, strlen(uidbuf),
|
|
|
|
&__ypcurrent, &__ypcurrentlen);
|
|
|
|
if(r != 0) {
|
|
|
|
if(__ypcurrent)
|
|
|
|
free(__ypcurrent);
|
|
|
|
__ypcurrent = NULL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '@':
|
|
|
|
pwuid_netgrp:
|
|
|
|
if(__ypcurrent) {
|
|
|
|
free(__ypcurrent);
|
|
|
|
__ypcurrent = NULL;
|
|
|
|
}
|
|
|
|
if(s == -1) /* first time */
|
|
|
|
setnetgrent(_pw_passwd.pw_name + 2);
|
|
|
|
s = getnetgrent(&host, &user, &dom);
|
|
|
|
if(s == 0) { /* end of group */
|
|
|
|
endnetgrent();
|
|
|
|
s = -1;
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
if(user && *user) {
|
|
|
|
r = yp_match(__ypdomain,
|
|
|
|
"passwd.byname",
|
|
|
|
user, strlen(user),
|
|
|
|
&__ypcurrent,
|
|
|
|
&__ypcurrentlen);
|
|
|
|
} else
|
|
|
|
goto pwuid_netgrp;
|
|
|
|
if(r != 0) {
|
|
|
|
if(__ypcurrent)
|
|
|
|
free(__ypcurrent);
|
|
|
|
__ypcurrent = NULL;
|
|
|
|
/*
|
|
|
|
* just because this
|
|
|
|
* user is bad, doesn't
|
|
|
|
* mean they all are.
|
|
|
|
*/
|
|
|
|
goto pwuid_netgrp;
|
|
|
|
}
|
|
|
|
}
|
1993-12-10 15:46:29 +03:00
|
|
|
break;
|
|
|
|
default:
|
1995-07-28 09:43:01 +04:00
|
|
|
if(__ypcurrent) {
|
|
|
|
free(__ypcurrent);
|
|
|
|
__ypcurrent = NULL;
|
|
|
|
}
|
|
|
|
user = _pw_passwd.pw_name + 1;
|
|
|
|
r = yp_match(__ypdomain,
|
|
|
|
"passwd.byname",
|
|
|
|
user, strlen(user),
|
|
|
|
&__ypcurrent,
|
|
|
|
&__ypcurrentlen);
|
|
|
|
if(r != 0) {
|
|
|
|
if(__ypcurrent)
|
|
|
|
free(__ypcurrent);
|
|
|
|
__ypcurrent = NULL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
1993-05-04 09:10:45 +04:00
|
|
|
}
|
1993-12-10 15:46:29 +03:00
|
|
|
bcopy(__ypcurrent, line, __ypcurrentlen);
|
|
|
|
line[__ypcurrentlen] = '\0';
|
1995-07-28 09:43:01 +04:00
|
|
|
if(__ypparse(&_pw_passwd, line)
|
|
|
|
|| __ypexclude_is(_pw_passwd.pw_name)) {
|
|
|
|
if(s == 1) /* inside netgroup */
|
|
|
|
goto pwuid_netgrp;
|
1993-12-10 15:46:29 +03:00
|
|
|
continue;
|
1995-07-28 09:43:01 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '-':
|
|
|
|
/* attempted exclusion */
|
|
|
|
switch(_pw_passwd.pw_name[1]) {
|
|
|
|
case '\0':
|
|
|
|
break;
|
|
|
|
case '@':
|
|
|
|
setnetgrent(_pw_passwd.pw_name + 2);
|
|
|
|
while(getnetgrent(&host, &user, &dom)) {
|
|
|
|
if(user && *user)
|
|
|
|
__ypexclude_add(user);
|
|
|
|
}
|
|
|
|
endnetgrent();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
__ypexclude_add(_pw_passwd.pw_name + 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
continue;
|
1993-05-04 09:10:45 +04:00
|
|
|
}
|
1993-12-10 15:46:29 +03:00
|
|
|
if( _pw_passwd.pw_uid == uid) {
|
|
|
|
if (!_pw_stayopen) {
|
|
|
|
(void)(_pw_db->close)(_pw_db);
|
|
|
|
_pw_db = (DB *)NULL;
|
|
|
|
}
|
1995-07-28 09:43:01 +04:00
|
|
|
if (__ypexclude != (DB *)NULL) {
|
|
|
|
(void)(__ypexclude->close)(__ypexclude);
|
|
|
|
__ypexclude = (DB *)NULL;
|
|
|
|
}
|
|
|
|
__ypproto = NULL;
|
1993-12-10 15:46:29 +03:00
|
|
|
return &_pw_passwd;
|
1993-05-04 09:10:45 +04:00
|
|
|
}
|
1995-07-28 09:43:01 +04:00
|
|
|
if(s == 1) /* inside netgroup */
|
|
|
|
goto pwuid_netgrp;
|
1993-12-10 15:46:29 +03:00
|
|
|
continue;
|
1993-05-04 09:10:45 +04:00
|
|
|
}
|
1993-12-10 15:46:29 +03:00
|
|
|
if (!_pw_stayopen) {
|
|
|
|
(void)(_pw_db->close)(_pw_db);
|
|
|
|
_pw_db = (DB *)NULL;
|
1993-05-04 09:10:45 +04:00
|
|
|
}
|
1995-07-28 09:43:01 +04:00
|
|
|
if(__ypexclude != (DB *)NULL) {
|
|
|
|
(void)(__ypexclude->close)(__ypexclude);
|
|
|
|
__ypexclude = (DB *)NULL;
|
|
|
|
}
|
|
|
|
__ypproto = (struct passwd *)NULL;
|
1993-12-10 15:46:29 +03:00
|
|
|
return (struct passwd *)NULL;
|
1993-05-04 09:10:45 +04:00
|
|
|
}
|
1993-12-10 15:46:29 +03:00
|
|
|
#endif /* YP */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
bf[0] = _PW_KEYBYUID;
|
|
|
|
keyuid = uid;
|
|
|
|
bcopy(&keyuid, bf + 1, sizeof(keyuid));
|
|
|
|
key.data = (u_char *)bf;
|
|
|
|
key.size = sizeof(keyuid) + 1;
|
|
|
|
rval = __hashpw(&key);
|
|
|
|
|
|
|
|
if (!_pw_stayopen) {
|
|
|
|
(void)(_pw_db->close)(_pw_db);
|
|
|
|
_pw_db = (DB *)NULL;
|
|
|
|
}
|
|
|
|
return(rval ? &_pw_passwd : (struct passwd *)NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
setpassent(stayopen)
|
|
|
|
int stayopen;
|
|
|
|
{
|
|
|
|
_pw_keynum = 0;
|
|
|
|
_pw_stayopen = stayopen;
|
1993-05-04 09:10:45 +04:00
|
|
|
#ifdef YP
|
1995-07-28 09:43:01 +04:00
|
|
|
__ypmode = YPMODE_NONE;
|
1993-05-04 09:10:45 +04:00
|
|
|
if(__ypcurrent)
|
|
|
|
free(__ypcurrent);
|
|
|
|
__ypcurrent = NULL;
|
1995-07-28 09:43:01 +04:00
|
|
|
if(__ypexclude != (DB *)NULL) {
|
|
|
|
(void)(__ypexclude->close)(__ypexclude);
|
|
|
|
__ypexclude = (DB *)NULL;
|
|
|
|
}
|
|
|
|
__ypproto = (struct passwd *)NULL;
|
1993-05-04 09:10:45 +04:00
|
|
|
#endif
|
1993-10-26 02:36:51 +03:00
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
setpwent()
|
|
|
|
{
|
|
|
|
(void) setpassent(0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
endpwent()
|
|
|
|
{
|
|
|
|
_pw_keynum = 0;
|
|
|
|
if (_pw_db) {
|
|
|
|
(void)(_pw_db->close)(_pw_db);
|
|
|
|
_pw_db = (DB *)NULL;
|
|
|
|
}
|
1993-05-04 09:10:45 +04:00
|
|
|
#ifdef YP
|
1995-07-28 09:43:01 +04:00
|
|
|
__ypmode = YPMODE_NONE;
|
1993-05-04 09:10:45 +04:00
|
|
|
if(__ypcurrent)
|
|
|
|
free(__ypcurrent);
|
|
|
|
__ypcurrent = NULL;
|
1995-07-28 09:43:01 +04:00
|
|
|
if(__ypexclude != (DB *)NULL) {
|
|
|
|
(void)(__ypexclude->close)(__ypexclude);
|
|
|
|
__ypexclude = (DB *)NULL;
|
|
|
|
}
|
|
|
|
__ypproto = (struct passwd *)NULL;
|
1993-05-04 09:10:45 +04:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1993-05-04 09:10:45 +04:00
|
|
|
static int
|
1993-03-21 12:45:37 +03:00
|
|
|
__initdb()
|
|
|
|
{
|
|
|
|
static int warned;
|
|
|
|
char *p;
|
|
|
|
|
1995-07-28 09:43:01 +04:00
|
|
|
#ifdef YP
|
|
|
|
__ypmode = YPMODE_NONE;
|
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
p = (geteuid()) ? _PATH_MP_DB : _PATH_SMP_DB;
|
1993-04-21 08:26:21 +04:00
|
|
|
_pw_db = dbopen(p, O_RDONLY, 0, DB_HASH, NULL);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (_pw_db)
|
|
|
|
return(1);
|
|
|
|
if (!warned)
|
|
|
|
syslog(LOG_ERR, "%s: %m", p);
|
1994-03-09 13:10:29 +03:00
|
|
|
warned = 1;
|
1993-03-21 12:45:37 +03:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
1993-05-04 09:10:45 +04:00
|
|
|
static int
|
1993-03-21 12:45:37 +03:00
|
|
|
__hashpw(key)
|
|
|
|
DBT *key;
|
|
|
|
{
|
1997-05-20 19:59:59 +04:00
|
|
|
char *p, *t;
|
1993-03-21 12:45:37 +03:00
|
|
|
static u_int max;
|
|
|
|
static char *line;
|
|
|
|
DBT data;
|
|
|
|
|
|
|
|
if ((_pw_db->get)(_pw_db, key, &data, 0))
|
|
|
|
return(0);
|
|
|
|
p = (char *)data.data;
|
1995-07-28 09:43:01 +04:00
|
|
|
if (data.size > max && !(line = realloc(line, (max += 1024))))
|
1993-03-21 12:45:37 +03:00
|
|
|
return(0);
|
|
|
|
|
|
|
|
t = line;
|
1995-07-28 09:43:01 +04:00
|
|
|
#define EXPAND(e) e = t; while ((*t++ = *p++));
|
1993-03-21 12:45:37 +03:00
|
|
|
EXPAND(_pw_passwd.pw_name);
|
|
|
|
EXPAND(_pw_passwd.pw_passwd);
|
|
|
|
bcopy(p, (char *)&_pw_passwd.pw_uid, sizeof(int));
|
|
|
|
p += sizeof(int);
|
|
|
|
bcopy(p, (char *)&_pw_passwd.pw_gid, sizeof(int));
|
|
|
|
p += sizeof(int);
|
|
|
|
bcopy(p, (char *)&_pw_passwd.pw_change, sizeof(time_t));
|
|
|
|
p += sizeof(time_t);
|
|
|
|
EXPAND(_pw_passwd.pw_class);
|
|
|
|
EXPAND(_pw_passwd.pw_gecos);
|
|
|
|
EXPAND(_pw_passwd.pw_dir);
|
|
|
|
EXPAND(_pw_passwd.pw_shell);
|
|
|
|
bcopy(p, (char *)&_pw_passwd.pw_expire, sizeof(time_t));
|
|
|
|
p += sizeof(time_t);
|
1995-07-28 09:43:01 +04:00
|
|
|
|
|
|
|
/* See if there's any data left. If so, read in flags. */
|
|
|
|
if (data.size > (p - (char *)data.data)) {
|
|
|
|
bcopy(p, (char *)&_pw_flags, sizeof(int));
|
|
|
|
p += sizeof(int);
|
|
|
|
} else
|
|
|
|
_pw_flags = _PASSWORD_NOUID|_PASSWORD_NOGID; /* default */
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
return(1);
|
|
|
|
}
|