Don't initialize NIS until it is really necessary. Now, in case of network

or NIS server problems, local user can login without a pause.

Also, -Wsomething cleanup.
This commit is contained in:
dt 1998-09-15 16:22:30 +00:00
parent 74a908a88d
commit 864c030677

View File

@ -71,7 +71,7 @@ static struct passwd _pw_copy;
static DBT empty = { NULL, 0 }; static DBT empty = { NULL, 0 };
static DB *_ypcache = (DB *)NULL; static DB *_ypcache = (DB *)NULL;
static int _yp_exclusions = 0; static int _yp_exclusions = 0;
static int _yp_enabled; /* set true when yp enabled */ static int _yp_enabled = -1;
static int _pw_stepping_yp; /* set true when stepping thru map */ static int _pw_stepping_yp; /* set true when stepping thru map */
static char _ypnam[YPMAXRECORD]; static char _ypnam[YPMAXRECORD];
#define YP_HAVE_MASTER 2 #define YP_HAVE_MASTER 2
@ -80,12 +80,18 @@ static char _ypnam[YPMAXRECORD];
static int _gotmaster; static int _gotmaster;
static char *_pw_yp_domain; static char *_pw_yp_domain;
static inline int unwind __P(( char * )); static inline int unwind __P(( char * ));
static inline void _ypinitdb __P(( void )); static void _ypinitdb __P(( void ));
static int _havemaster __P((char *)); static int _havemaster __P((char *));
static int _getyppass __P((struct passwd *, const char *, const char * )); static int _getyppass __P((struct passwd *, const char *, const char * ));
static int _nextyppass __P((struct passwd *)); static int _nextyppass __P((struct passwd *));
static inline int lookup __P((const char *));
static inline void store __P((const char *));
static inline int ingr __P((const char *, const char*));
static inline int verf __P((const char *));
static char * _get_adjunct_pw __P((const char *));
#endif #endif
static int __hashpw(), __initdb(); static int __hashpw(DBT *);
static int __initdb(void);
struct passwd * struct passwd *
getpwent() getpwent()
@ -115,6 +121,8 @@ getpwent()
if(!rv) return (struct passwd *)NULL; if(!rv) return (struct passwd *)NULL;
#ifdef YP #ifdef YP
if(_pw_passwd.pw_name[0] == '+' || _pw_passwd.pw_name[0] == '-') { if(_pw_passwd.pw_name[0] == '+' || _pw_passwd.pw_name[0] == '-') {
if (_yp_enabled == -1)
_ypinitdb();
bzero((char *)&_ypnam, sizeof(_ypnam)); bzero((char *)&_ypnam, sizeof(_ypnam));
bcopy(_pw_passwd.pw_name, _ypnam, bcopy(_pw_passwd.pw_name, _ypnam,
strlen(_pw_passwd.pw_name)); strlen(_pw_passwd.pw_name));
@ -152,8 +160,12 @@ getpwnam(name)
rval = __hashpw(&key); rval = __hashpw(&key);
#ifdef YP #ifdef YP
if (!rval && _yp_enabled) if (!rval) {
rval = _getyppass(&_pw_passwd, name, "passwd.byname"); if (_yp_enabled == -1)
_ypinitdb();
if (_yp_enabled)
rval = _getyppass(&_pw_passwd, name, "passwd.byname");
}
#endif #endif
/* /*
* Prevent login attempts when YP is not enabled but YP entries * Prevent login attempts when YP is not enabled but YP entries
@ -185,10 +197,14 @@ getpwuid(uid)
rval = __hashpw(&key); rval = __hashpw(&key);
#ifdef YP #ifdef YP
if (!rval && _yp_enabled) { if (!rval) {
char ypbuf[16]; /* big enough for 32-bit uids and then some */ if (_yp_enabled == -1)
snprintf(ypbuf, sizeof ypbuf, "%u", (unsigned)uid); _ypinitdb();
rval = _getyppass(&_pw_passwd, ypbuf, "passwd.byuid"); if (_yp_enabled) {
char ypbuf[16]; /* big enough for 32-bit uids */
snprintf(ypbuf, sizeof ypbuf, "%u", (unsigned)uid);
rval = _getyppass(&_pw_passwd, ypbuf, "passwd.byuid");
}
} }
#endif #endif
/* /*
@ -248,29 +264,8 @@ __initdb()
p = (geteuid()) ? _PATH_MP_DB : _PATH_SMP_DB; p = (geteuid()) ? _PATH_MP_DB : _PATH_SMP_DB;
_pw_db = dbopen(p, O_RDONLY, 0, DB_HASH, NULL); _pw_db = dbopen(p, O_RDONLY, 0, DB_HASH, NULL);
if (_pw_db) { if (_pw_db)
#ifdef YP
DBT key, data;
char buf[] = { _PW_KEYYPENABLED };
key.data = buf;
key.size = 1;
if ((_pw_db->get)(_pw_db, &key, &data, 0)) {
_yp_enabled = 0;
} else {
_yp_enabled = (int)*((char *)data.data) - 2;
/* Don't even bother with this if we aren't root. */
if (!geteuid()) {
if (!_pw_yp_domain)
if (yp_get_default_domain(&_pw_yp_domain))
return(1);
_gotmaster = _havemaster(_pw_yp_domain);
} else _gotmaster = YP_HAVE_NONE;
if (!_ypcache)
_ypinitdb();
}
#endif
return(1); return(1);
}
if (!warned++) if (!warned++)
syslog(LOG_ERR, "%s: %m", p); syslog(LOG_ERR, "%s: %m", p);
return(0); return(0);
@ -317,29 +312,45 @@ __hashpw(key)
#ifdef YP #ifdef YP
/* static void
* Create a DB hash database in memory. Bet you didn't know you _ypinitdb()
* could do a dbopen() will a NULL filename, did you.
*/
static inline void _ypinitdb()
{ {
if (_ypcache == (DB *)NULL) DBT key, data;
_ypcache = dbopen(NULL, O_RDWR, 600, DB_HASH, NULL); char buf[] = { _PW_KEYYPENABLED };
return; key.data = buf;
key.size = 1;
_yp_enabled = 0;
if ((_pw_db->get)(_pw_db, &key, &data, 0) == 0) {
_yp_enabled = (int)*((char *)data.data) - 2;
/* Don't even bother with this if we aren't root. */
if (!geteuid()) {
if (!_pw_yp_domain)
if (yp_get_default_domain(&_pw_yp_domain))
return;
_gotmaster = _havemaster(_pw_yp_domain);
} else _gotmaster = YP_HAVE_NONE;
/*
* Create a DB hash database in memory. Bet you didn't know you
* could do a dbopen() with a NULL filename, did you.
*/
if (_ypcache == (DB *)NULL)
_ypcache = dbopen(NULL, O_RDWR, 600, DB_HASH, NULL);
}
} }
/* /*
* See if a user is in the blackballed list. * See if a user is in the blackballed list.
*/ */
static inline int lookup(name) static inline int
char *name; lookup(name)
const char *name;
{ {
DBT key; DBT key;
if (!_yp_exclusions) if (!_yp_exclusions)
return(0); return(0);
key.data = name; key.data = (char *)name;
key.size = strlen(name); key.size = strlen(name);
if ((_ypcache->get)(_ypcache, &key, &empty, 0)) { if ((_ypcache->get)(_ypcache, &key, &empty, 0)) {
@ -352,8 +363,9 @@ static inline int lookup(name)
/* /*
* Store a blackballed user in an in-core hash database. * Store a blackballed user in an in-core hash database.
*/ */
static inline void store(key) static inline void
char *key; store(key)
const char *key;
{ {
DBT lkey; DBT lkey;
/* /*
@ -363,7 +375,7 @@ static inline void store(key)
_yp_exclusions = 1; _yp_exclusions = 1;
lkey.data = key; lkey.data = (char *)key;
lkey.size = strlen(key); lkey.size = strlen(key);
(void)(_ypcache->put)(_ypcache, &lkey, &empty, R_NOOVERWRITE); (void)(_ypcache->put)(_ypcache, &lkey, &empty, R_NOOVERWRITE);
@ -381,7 +393,8 @@ static inline void store(key)
* we don't consider them when processing other + lines that appear * we don't consider them when processing other + lines that appear
* later. * later.
*/ */
static inline int unwind(grp) static inline int
unwind(grp)
char *grp; char *grp;
{ {
char *user, *host, *domain; char *user, *host, *domain;
@ -448,8 +461,8 @@ static inline int unwind(grp)
rv++; rv++;
} }
if (!rv && (gr = getgrnam(grp+2)) != NULL) { if (!rv && (gr = getgrnam(grp+2)) != NULL) {
while(gr->gr_mem) { while(*gr->gr_mem) {
store(gr->gr_mem); store(*gr->gr_mem);
gr->gr_mem++; gr->gr_mem++;
} }
} }
@ -463,9 +476,10 @@ static inline int unwind(grp)
/* /*
* See if a user is a member of a particular group. * See if a user is a member of a particular group.
*/ */
static inline int ingr(grp, name) static inline int
char *grp; ingr(grp, name)
char *name; const char *grp;
const char *name;
{ {
register struct group *gr; register struct group *gr;
@ -490,8 +504,9 @@ static inline int ingr(grp, name)
* If no netgroup exists that matches +@netgroup/-@netgroup, * If no netgroup exists that matches +@netgroup/-@netgroup,
* try searching regular groups with the same name. * try searching regular groups with the same name.
*/ */
static inline int verf(name) static inline int
char *name; verf(name)
const char *name;
{ {
DBT key; DBT key;
char bf[sizeof(_pw_keynum) + 1]; char bf[sizeof(_pw_keynum) + 1];
@ -553,8 +568,9 @@ static inline int verf(name)
return(0); return(0);
} }
static char * _get_adjunct_pw(name) static char *
char *name; _get_adjunct_pw(name)
const char *name;
{ {
static char adjunctbuf[YPMAXRECORD+2]; static char adjunctbuf[YPMAXRECORD+2];
int rval; int rval;