summaryrefslogtreecommitdiffstats
path: root/lib/libc/gen/getgrent.c
diff options
context:
space:
mode:
authorwpaul <wpaul@FreeBSD.org>1995-10-06 21:29:01 +0000
committerwpaul <wpaul@FreeBSD.org>1995-10-06 21:29:01 +0000
commited7403dd1f73c0327199e7f41ec610af92052151 (patch)
tree0eda0aa4185b01af35e3c80e1c4610219b93da40 /lib/libc/gen/getgrent.c
parent5373386fa0110f4c877f0013b70fd5070c2adcc7 (diff)
downloadFreeBSD-src-ed7403dd1f73c0327199e7f41ec610af92052151.zip
FreeBSD-src-ed7403dd1f73c0327199e7f41ec610af92052151.tar.gz
Some NIS bug stomping:
- In some cases, we don't properly resolve _all_ possible group memberships. If a user is a member of both local and NIS groups, we sometimes lose some of the membership info from NIS. (Reported by: Thorsten Kukuk <kukuk@uni-paderborn.de>) - Make NIS +groupname overrides actually work the way the SunOS group(5) man page says they should (make them work for all cases: getgrent(), getgrnam() and getgrgid()). - When not compiled with -DYP, grscan() should ignore entries that begin with a '+'. When compiled _with_ -DYP, grscan() should ignore +groupname entries that don't refer to real NIS groups. - Remove redundant redeclaration of fgets(), strsep() and index() inside grscan(). We already #include all the right header files for these. Note: -groupname exclusion as specified in the Sun documentation still isn't supported. This'll be a 2.2 addition. Right now I just want this stuff to work.
Diffstat (limited to 'lib/libc/gen/getgrent.c')
-rw-r--r--lib/libc/gen/getgrent.c65
1 files changed, 41 insertions, 24 deletions
diff --git a/lib/libc/gen/getgrent.c b/lib/libc/gen/getgrent.c
index d4e0794..9ba9a71 100644
--- a/lib/libc/gen/getgrent.c
+++ b/lib/libc/gen/getgrent.c
@@ -99,11 +99,15 @@ getgrnam(name)
if (!start_gr())
return(NULL);
+#ifdef YP
+ tryagain:
+#endif
rval = grscan(1, 0, name);
#ifdef YP
- if(!rval && (_gr_yp_enabled < 0 || (_gr_yp_enabled &&
+ if(rval == -1 && (_gr_yp_enabled < 0 || (_gr_yp_enabled &&
_gr_group.gr_name[0] == '+'))) {
- rval = _getypgroup(&_gr_group, name, "group.byname");
+ if (!(rval = _getypgroup(&_gr_group, name, "group.byname")))
+ goto tryagain;
}
#endif
if (!_gr_stayopen)
@@ -123,12 +127,16 @@ getgrgid(gid)
if (!start_gr())
return(NULL);
+#ifdef YP
+ tryagain:
+#endif
rval = grscan(1, gid, NULL);
#ifdef YP
- if(!rval && _gr_yp_enabled) {
+ if(rval == -1 && _gr_yp_enabled) {
char buf[16];
snprintf(buf, sizeof buf, "%d", (unsigned)gid);
- rval = _getypgroup(&_gr_group, buf, "group.bygid");
+ if (!(rval = _getypgroup(&_gr_group, buf, "group.bygid")))
+ goto tryagain;
}
#endif
if (!_gr_stayopen)
@@ -209,8 +217,9 @@ grscan(search, gid, name)
{
register char *cp, **m;
char *bp;
- char *fgets(), *strsep(), *index();
-
+#ifdef YP
+ int _ypfound = 0;
+#endif;
for (;;) {
if (!fgets(line, sizeof(line), _gr_fp))
return(0);
@@ -223,21 +232,8 @@ grscan(search, gid, name)
;
continue;
}
- _gr_group.gr_name = strsep(&bp, ":\n");
- if (search && name) {
-#ifdef YP
- if(_gr_group.gr_name[0] == '+') {
- if(strcmp(&_gr_group.gr_name[1], name)) {
- continue;
- }
- return _getypgroup(&_gr_group, name,
- "group.byname");
- }
-#endif /* YP */
- if(strcmp(_gr_group.gr_name, name)) {
- continue;
- }
- }
+ if ((_gr_group.gr_name = strsep(&bp, ":\n")) == NULL)
+ break;
#ifdef YP
/*
* XXX We need to be careful to avoid proceeding
@@ -245,19 +241,40 @@ grscan(search, gid, name)
* we risk dereferencing null pointers down below.
*/
if (_gr_group.gr_name[0] == '+') {
- switch(search) {
+ if (strlen(_gr_group.gr_name) == 1) {
+ switch(search) {
case 0:
return(1);
case 1:
- return(0);
+ return(-1);
default:
return(0);
+ }
+ } else {
+ if (!_getypgroup(&_gr_group, &_gr_group.gr_name[1],
+ "group.byname"))
+ continue;
+ /* We're going to override -- tell the world. */
+ members[0] = NULL;
+ _ypfound++;
}
}
+#else
+ if (_gr_group.gr_name[0] == '+')
+ continue;
#endif /* YP */
- _gr_group.gr_passwd = strsep(&bp, ":\n");
+ if (search && name) {
+ if(strcmp(_gr_group.gr_name, name)) {
+ continue;
+ }
+ }
+ if ((_gr_group.gr_passwd = strsep(&bp, ":\n")) == NULL)
+ break;;
if (!(cp = strsep(&bp, ":\n")))
continue;
+#ifdef YP
+ if (!_ypfound)
+#endif
_gr_group.gr_gid = atoi(cp);
if (search && name == NULL && _gr_group.gr_gid != gid)
continue;
OpenPOWER on IntegriCloud