summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/libc/gen/getpwent.c228
1 files changed, 114 insertions, 114 deletions
diff --git a/lib/libc/gen/getpwent.c b/lib/libc/gen/getpwent.c
index 217352b90ea..d99be6d9e91 100644
--- a/lib/libc/gen/getpwent.c
+++ b/lib/libc/gen/getpwent.c
@@ -33,7 +33,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: getpwent.c,v 1.15 1999/09/03 16:23:18 millert Exp $";
+static char rcsid[] = "$OpenBSD: getpwent.c,v 1.16 1999/09/14 21:03:15 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
@@ -107,21 +107,21 @@ __ypexclude_add(name)
struct _ypexclude *new;
if (name[0] == '\0') /* skip */
- return(0);
+ return (0);
new = (struct _ypexclude *)malloc(sizeof(struct _ypexclude));
if (new == (struct _ypexclude *)NULL)
- return(1);
+ return (1);
new->name = strdup(name);
if (new->name == (char *)NULL) {
free(new);
- return(1);
+ return (1);
}
new->next = __ypexclude;
__ypexclude = new;
- return(0);
+ return (0);
}
static int
@@ -133,9 +133,9 @@ __ypexclude_is(name)
for (curr = __ypexclude; curr != (struct _ypexclude *)NULL;
curr = curr->next) {
if (strcmp(curr->name, name) == 0)
- return(1); /* excluded */
+ return (1); /* excluded */
}
- return(0);
+ return (0);
}
static void
@@ -167,7 +167,7 @@ __ypproto_set()
ptr += sizeof(struct passwd);
/* name */
- if(pw->pw_name && (pw->pw_name)[0]) {
+ 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;
@@ -176,7 +176,7 @@ __ypproto_set()
__ypproto->pw_name = (char *)NULL;
/* password */
- if(pw->pw_passwd && (pw->pw_passwd)[0]) {
+ 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;
@@ -197,7 +197,7 @@ __ypproto_set()
__ypproto->pw_class = "";
/* gecos */
- if(pw->pw_gecos && (pw->pw_gecos)[0]) {
+ 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;
@@ -206,7 +206,7 @@ __ypproto_set()
__ypproto->pw_gecos = (char *)NULL;
/* dir */
- if(pw->pw_dir && (pw->pw_dir)[0]) {
+ 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;
@@ -215,7 +215,7 @@ __ypproto_set()
__ypproto->pw_dir = (char *)NULL;
/* shell */
- if(pw->pw_shell && (pw->pw_shell)[0]) {
+ 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;
@@ -290,18 +290,18 @@ char *s;
pw->pw_shell = strsep(&bp, ":\n");
/* now let the prototype override, if set. */
- if(__ypproto != (struct passwd *)NULL) {
- if(__yp_override_passwd && __ypproto->pw_passwd != (char *)NULL)
+ if (__ypproto != (struct passwd *)NULL) {
+ if (__yp_override_passwd && __ypproto->pw_passwd != (char *)NULL)
pw->pw_passwd = __ypproto->pw_passwd;
- if(!(__ypflags & _PASSWORD_NOUID))
+ if (!(__ypflags & _PASSWORD_NOUID))
pw->pw_uid = __ypproto->pw_uid;
- if(!(__ypflags & _PASSWORD_NOGID))
+ if (!(__ypflags & _PASSWORD_NOGID))
pw->pw_gid = __ypproto->pw_gid;
- if(__ypproto->pw_gecos != (char *)NULL)
+ if (__ypproto->pw_gecos != (char *)NULL)
pw->pw_gecos = __ypproto->pw_gecos;
- if(__ypproto->pw_dir != (char *)NULL)
+ if (__ypproto->pw_dir != (char *)NULL)
pw->pw_dir = __ypproto->pw_dir;
- if(__ypproto->pw_shell != (char *)NULL)
+ if (__ypproto->pw_shell != (char *)NULL)
pw->pw_shell = __ypproto->pw_shell;
}
return 0;
@@ -321,35 +321,35 @@ getpwent()
#endif
if (!_pw_db && !__initdb())
- return((struct passwd *)NULL);
+ return ((struct passwd *)NULL);
#ifdef YP
if (__getpwent_has_yppw == -1)
__getpwent_has_yppw = __has_yppw();
again:
- if(__getpwent_has_yppw && (__ypmode != YPMODE_NONE)) {
+ if (__getpwent_has_yppw && (__ypmode != YPMODE_NONE)) {
char *key, *data;
int keylen, datalen;
int r, s;
- if(!__ypdomain) {
- if( _yp_check(&__ypdomain) == 0) {
+ if (!__ypdomain) {
+ if (_yp_check(&__ypdomain) == 0) {
__ypmode = YPMODE_NONE;
goto again;
}
}
- switch(__ypmode) {
+ switch (__ypmode) {
case YPMODE_FULL:
- if(__ypcurrent) {
+ if (__ypcurrent) {
r = yp_next(__ypdomain, (PASSWD_BYNAME),
__ypcurrent, __ypcurrentlen,
&key, &keylen, &data, &datalen);
free(__ypcurrent);
- if(r != 0) {
+ if (r != 0) {
__ypcurrent = NULL;
__ypmode = YPMODE_NONE;
- if(data)
+ if (data)
free(data);
data = NULL;
goto again;
@@ -363,9 +363,9 @@ again:
r = yp_first(__ypdomain, (PASSWD_BYNAME),
&__ypcurrent, &__ypcurrentlen,
&data, &datalen);
- if(r != 0) {
+ if (r != 0) {
__ypmode = YPMODE_NONE;
- if(data)
+ if (data)
free(data);
goto again;
}
@@ -376,23 +376,23 @@ again:
break;
case YPMODE_NETGRP:
s = getnetgrent(&host, &user, &dom);
- if(s == 0) { /* end of group */
+ if (s == 0) { /* end of group */
endnetgrent();
__ypmode = YPMODE_NONE;
goto again;
}
- if(user && *user) {
+ if (user && *user) {
r = yp_match(__ypdomain, (PASSWD_BYNAME),
user, strlen(user),
&data, &datalen);
} else
goto again;
- if(r != 0) {
+ if (r != 0) {
/*
* if the netgroup is invalid, keep looking
* as there may be valid users later on.
*/
- if(data)
+ if (data)
free(data);
goto again;
}
@@ -401,15 +401,15 @@ again:
data = (char *)NULL;
break;
case YPMODE_USER:
- if(name != (char *)NULL) {
+ if (name != (char *)NULL) {
r = yp_match(__ypdomain, (PASSWD_BYNAME),
name, strlen(name),
&data, &datalen);
__ypmode = YPMODE_NONE;
free(name);
name = (char *)NULL;
- if(r != 0) {
- if(data)
+ if (r != 0) {
+ if (data)
free(data);
goto again;
}
@@ -435,13 +435,13 @@ again:
bcopy((char *)&_pw_keynum, bf + 1, sizeof(_pw_keynum));
key.data = (u_char *)bf;
key.size = sizeof(_pw_keynum) + 1;
- if(__hashpw(&key)) {
+ if (__hashpw(&key)) {
#ifdef YP
/* if we don't have YP at all, don't bother. */
if (__getpwent_has_yppw) {
- if(_pw_passwd.pw_name[0] == '+') {
+ if (_pw_passwd.pw_name[0] == '+') {
/* set the mode */
- switch(_pw_passwd.pw_name[1]) {
+ switch (_pw_passwd.pw_name[1]) {
case '\0':
__ypmode = YPMODE_FULL;
break;
@@ -458,15 +458,15 @@ again:
/* save the prototype */
__ypproto_set();
goto again;
- } else if(_pw_passwd.pw_name[0] == '-') {
+ } else if (_pw_passwd.pw_name[0] == '-') {
/* an attempted exclusion */
- switch(_pw_passwd.pw_name[1]) {
+ switch (_pw_passwd.pw_name[1]) {
case '\0':
break;
case '@':
setnetgrent(_pw_passwd.pw_name + 2);
- while(getnetgrent(&host, &user, &dom)) {
- if(user && *user)
+ while (getnetgrent(&host, &user, &dom)) {
+ if (user && *user)
__ypexclude_add(user);
}
endnetgrent();
@@ -510,8 +510,8 @@ __has_yppw()
if ((_pw_db->get)(_pw_db, &key, &data, 0)
&& (_pw_db->get)(_pw_db, &pkey, &pdata, 0))
- return(0); /* No YP. */
- return(1);
+ return (0); /* No YP. */
+ return (1);
}
/*
@@ -526,29 +526,29 @@ __has_ypmaster()
static int checked = -1;
if (checked != -1)
- return(checked);
+ return (checked);
- if(geteuid() != 0) {
+ if (geteuid() != 0) {
checked = 0;
- return(checked);
+ return (checked);
}
- if(!__ypdomain) {
- if(_yp_check(&__ypdomain) == 0) {
+ if (!__ypdomain) {
+ if (_yp_check(&__ypdomain) == 0) {
checked = 0;
- return(checked); /* No domain. */
+ return (checked); /* No domain. */
}
}
if (yp_first(__ypdomain, "master.passwd.byname",
&key, &keylen, &result, &resultlen)) {
checked = 0;
- return(checked);
+ return (checked);
}
free(result);
checked = 1;
- return(checked);
+ return (checked);
}
#endif
@@ -561,7 +561,7 @@ getpwnam(name)
char bf[UT_NAMESIZE + 1];
if (!_pw_db && !__initdb())
- return((struct passwd *)NULL);
+ return ((struct passwd *)NULL);
#ifdef YP
/*
@@ -573,26 +573,26 @@ getpwnam(name)
int s = -1;
const char *host, *user, *dom;
- for(_pw_keynum=1; _pw_keynum; _pw_keynum++) {
+ 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)
+ if (__hashpw(&key) == 0)
break;
- switch(_pw_passwd.pw_name[0]) {
+ switch (_pw_passwd.pw_name[0]) {
case '+':
- if(!__ypdomain) {
- if(_yp_check(&__ypdomain) == 0) {
+ if (!__ypdomain) {
+ if (_yp_check(&__ypdomain) == 0) {
continue;
}
}
/* save the prototype */
__ypproto_set();
- switch(_pw_passwd.pw_name[1]) {
+ switch (_pw_passwd.pw_name[1]) {
case '\0':
- if(__ypcurrent) {
+ if (__ypcurrent) {
free(__ypcurrent);
__ypcurrent = NULL;
}
@@ -600,8 +600,8 @@ getpwnam(name)
(PASSWD_BYNAME),
name, strlen(name),
&__ypcurrent, &__ypcurrentlen);
- if(r != 0) {
- if(__ypcurrent)
+ if (r != 0) {
+ if (__ypcurrent)
free(__ypcurrent);
__ypcurrent = NULL;
continue;
@@ -609,19 +609,19 @@ getpwnam(name)
break;
case '@':
pwnam_netgrp:
- if(__ypcurrent) {
+ if (__ypcurrent) {
free(__ypcurrent);
__ypcurrent = NULL;
}
- if(s == -1) /* first time */
+ if (s == -1) /* first time */
setnetgrent(_pw_passwd.pw_name + 2);
s = getnetgrent(&host, &user, &dom);
- if(s == 0) { /* end of group */
+ if (s == 0) { /* end of group */
endnetgrent();
s = -1;
continue;
} else {
- if(user && *user) {
+ if (user && *user) {
r = yp_match(__ypdomain,
(PASSWD_BYNAME),
user, strlen(user),
@@ -629,8 +629,8 @@ pwnam_netgrp:
&__ypcurrentlen);
} else
goto pwnam_netgrp;
- if(r != 0) {
- if(__ypcurrent)
+ if (r != 0) {
+ if (__ypcurrent)
free(__ypcurrent);
__ypcurrent = NULL;
/*
@@ -643,7 +643,7 @@ pwnam_netgrp:
}
break;
default:
- if(__ypcurrent) {
+ if (__ypcurrent) {
free(__ypcurrent);
__ypcurrent = NULL;
}
@@ -653,8 +653,8 @@ pwnam_netgrp:
user, strlen(user),
&__ypcurrent,
&__ypcurrentlen);
- if(r != 0) {
- if(__ypcurrent)
+ if (r != 0) {
+ if (__ypcurrent)
free(__ypcurrent);
__ypcurrent = NULL;
continue;
@@ -663,22 +663,22 @@ pwnam_netgrp:
}
bcopy(__ypcurrent, __ypline, __ypcurrentlen);
__ypline[__ypcurrentlen] = '\0';
- if(__ypparse(&_pw_passwd, __ypline)
+ if (__ypparse(&_pw_passwd, __ypline)
|| __ypexclude_is(_pw_passwd.pw_name)) {
- if(s == 1) /* inside netgrp */
+ if (s == 1) /* inside netgrp */
goto pwnam_netgrp;
continue;
}
break;
case '-':
/* attempted exclusion */
- switch(_pw_passwd.pw_name[1]) {
+ switch (_pw_passwd.pw_name[1]) {
case '\0':
break;
case '@':
setnetgrent(_pw_passwd.pw_name + 2);
- while(getnetgrent(&host, &user, &dom)) {
- if(user && *user)
+ while (getnetgrent(&host, &user, &dom)) {
+ if (user && *user)
__ypexclude_add(user);
}
endnetgrent();
@@ -689,7 +689,7 @@ pwnam_netgrp:
}
break;
}
- if(strcmp(_pw_passwd.pw_name, name) == 0) {
+ if (strcmp(_pw_passwd.pw_name, name) == 0) {
if (!_pw_stayopen) {
(void)(_pw_db->close)(_pw_db);
_pw_db = (DB *)NULL;
@@ -698,7 +698,7 @@ pwnam_netgrp:
__ypproto = (struct passwd *)NULL;
return &_pw_passwd;
}
- if(s == 1) /* inside netgrp */
+ if (s == 1) /* inside netgrp */
goto pwnam_netgrp;
continue;
}
@@ -727,7 +727,7 @@ pwnam_netgrp:
(void)(_pw_db->close)(_pw_db);
_pw_db = (DB *)NULL;
}
- return(rval ? &_pw_passwd : (struct passwd *)NULL);
+ return (rval ? &_pw_passwd : (struct passwd *)NULL);
}
struct passwd *
@@ -744,7 +744,7 @@ getpwuid(uid)
int rval;
if (!_pw_db && !__initdb())
- return((struct passwd *)NULL);
+ return ((struct passwd *)NULL);
#ifdef YP
/*
@@ -758,34 +758,34 @@ getpwuid(uid)
const char *host, *user, *dom;
sprintf(uidbuf, "%u", uid);
- for(_pw_keynum=1; _pw_keynum; _pw_keynum++) {
+ 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)
+ if (__hashpw(&key) == 0)
break;
- switch(_pw_passwd.pw_name[0]) {
+ switch (_pw_passwd.pw_name[0]) {
case '+':
- if(!__ypdomain) {
- if(_yp_check(&__ypdomain) == 0) {
+ if (!__ypdomain) {
+ if (_yp_check(&__ypdomain) == 0) {
continue;
}
}
/* save the prototype */
__ypproto_set();
- switch(_pw_passwd.pw_name[1]) {
+ switch (_pw_passwd.pw_name[1]) {
case '\0':
- if(__ypcurrent) {
+ if (__ypcurrent) {
free(__ypcurrent);
__ypcurrent = NULL;
}
r = yp_match(__ypdomain, (PASSWD_BYUID),
uidbuf, strlen(uidbuf),
&__ypcurrent, &__ypcurrentlen);
- if(r != 0) {
- if(__ypcurrent)
+ if (r != 0) {
+ if (__ypcurrent)
free(__ypcurrent);
__ypcurrent = NULL;
continue;
@@ -793,19 +793,19 @@ getpwuid(uid)
break;
case '@':
pwuid_netgrp:
- if(__ypcurrent) {
+ if (__ypcurrent) {
free(__ypcurrent);
__ypcurrent = NULL;
}
- if(s == -1) /* first time */
+ if (s == -1) /* first time */
setnetgrent(_pw_passwd.pw_name + 2);
s = getnetgrent(&host, &user, &dom);
- if(s == 0) { /* end of group */
+ if (s == 0) { /* end of group */
endnetgrent();
s = -1;
continue;
} else {
- if(user && *user) {
+ if (user && *user) {
r = yp_match(__ypdomain,
(PASSWD_BYNAME),
user, strlen(user),
@@ -813,8 +813,8 @@ pwuid_netgrp:
&__ypcurrentlen);
} else
goto pwuid_netgrp;
- if(r != 0) {
- if(__ypcurrent)
+ if (r != 0) {
+ if (__ypcurrent)
free(__ypcurrent);
__ypcurrent = NULL;
/*
@@ -827,7 +827,7 @@ pwuid_netgrp:
}
break;
default:
- if(__ypcurrent) {
+ if (__ypcurrent) {
free(__ypcurrent);
__ypcurrent = NULL;
}
@@ -837,8 +837,8 @@ pwuid_netgrp:
user, strlen(user),
&__ypcurrent,
&__ypcurrentlen);
- if(r != 0) {
- if(__ypcurrent)
+ if (r != 0) {
+ if (__ypcurrent)
free(__ypcurrent);
__ypcurrent = NULL;
continue;
@@ -847,22 +847,22 @@ pwuid_netgrp:
}
bcopy(__ypcurrent, __ypline, __ypcurrentlen);
__ypline[__ypcurrentlen] = '\0';
- if(__ypparse(&_pw_passwd, __ypline)
+ if (__ypparse(&_pw_passwd, __ypline)
|| __ypexclude_is(_pw_passwd.pw_name)) {
- if(s == 1) /* inside netgroup */
+ if (s == 1) /* inside netgroup */
goto pwuid_netgrp;
continue;
}
break;
case '-':
/* attempted exclusion */
- switch(_pw_passwd.pw_name[1]) {
+ switch (_pw_passwd.pw_name[1]) {
case '\0':
break;
case '@':
setnetgrent(_pw_passwd.pw_name + 2);
- while(getnetgrent(&host, &user, &dom)) {
- if(user && *user)
+ while (getnetgrent(&host, &user, &dom)) {
+ if (user && *user)
__ypexclude_add(user);
}
endnetgrent();
@@ -873,7 +873,7 @@ pwuid_netgrp:
}
break;
}
- if( _pw_passwd.pw_uid == uid) {
+ if (_pw_passwd.pw_uid == uid) {
if (!_pw_stayopen) {
(void)(_pw_db->close)(_pw_db);
_pw_db = (DB *)NULL;
@@ -882,7 +882,7 @@ pwuid_netgrp:
__ypproto = NULL;
return &_pw_passwd;
}
- if(s == 1) /* inside netgroup */
+ if (s == 1) /* inside netgroup */
goto pwuid_netgrp;
continue;
}
@@ -907,7 +907,7 @@ pwuid_netgrp:
(void)(_pw_db->close)(_pw_db);
_pw_db = (DB *)NULL;
}
- return(rval ? &_pw_passwd : (struct passwd *)NULL);
+ return (rval ? &_pw_passwd : (struct passwd *)NULL);
}
int
@@ -918,13 +918,13 @@ setpassent(stayopen)
_pw_stayopen = stayopen;
#ifdef YP
__ypmode = YPMODE_NONE;
- if(__ypcurrent)
+ if (__ypcurrent)
free(__ypcurrent);
__ypcurrent = NULL;
__ypexclude_free();
__ypproto = (struct passwd *)NULL;
#endif
- return(1);
+ return (1);
}
void
@@ -943,7 +943,7 @@ endpwent()
}
#ifdef YP
__ypmode = YPMODE_NONE;
- if(__ypcurrent)
+ if (__ypcurrent)
free(__ypcurrent);
__ypcurrent = NULL;
__ypexclude_free();
@@ -964,11 +964,11 @@ __initdb()
p = (geteuid()) ? _PATH_MP_DB : _PATH_SMP_DB;
_pw_db = dbopen(p, O_RDONLY, 0, DB_HASH, NULL);
if (_pw_db)
- return(1);
+ return (1);
if (!warned)
syslog(LOG_ERR, "%s: %m", p);
warned = 1;
- return(0);
+ return (0);
}
static int
@@ -981,7 +981,7 @@ __hashpw(key)
DBT data;
if ((_pw_db->get)(_pw_db, key, &data, 0))
- return(0);
+ return (0);
p = (char *)data.data;
if (data.size > max) {
char *nline;
@@ -1021,5 +1021,5 @@ __hashpw(key)
} else
_pw_flags = _PASSWORD_NOUID|_PASSWORD_NOGID; /* default */
- return(1);
+ return (1);
}