From 78748acfc60b88987b419de1eada1d6b9828a33b Mon Sep 17 00:00:00 2001 From: wpaul Date: Mon, 15 Apr 1996 16:17:04 +0000 Subject: Fix a few NIS-related bogons: - Clear the _yp_innetgr flag immediately after calling setnetgrent() from innetgr(). We only need the flag set to temporarily alter setnetgrent()'s behavior. Previously, it was being cleared too late. - When in NIS-only mode, innetgr() was wasting time doing unecessary extra processing after it had already found a match. - Remember to free memory allocated by the NIS functions during innetgr() searches. --- lib/libc/gen/getnetgrent.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'lib') diff --git a/lib/libc/gen/getnetgrent.c b/lib/libc/gen/getnetgrent.c index 2997f63..a15252d 100644 --- a/lib/libc/gen/getnetgrent.c +++ b/lib/libc/gen/getnetgrent.c @@ -166,7 +166,7 @@ setnetgrent(group) /* Presumed guilty until proven innocent. */ _use_only_yp = 0; /* - * IF /etc/netgroup doesn't exist or is empty, + * If /etc/netgroup doesn't exist or is empty, * use NIS exclusively. */ if (((stat(_PATH_NETGROUP, &_yp_statp) < 0) && @@ -280,11 +280,12 @@ int len; { char *ptr = list; - while (ptr != (char *)(list + len)) { - if (!strncmp(group, ptr, strlen(group))) - return(1); - ptr++; - } + if ((ptr = strstr(list, group)) == NULL) + return(0); + + if (*(ptr + strlen(group)) == ',' || *(ptr + strlen(group)) == '\n') + return(1); + return(0); } @@ -320,6 +321,7 @@ innetgr(group, host, user, dom) #ifdef YP char *result; int resultlen; + int rv; #endif /* Sanity check */ @@ -331,6 +333,7 @@ innetgr(group, host, user, dom) #endif setnetgrent(group); #ifdef YP + _yp_innetgr = 0; /* * If we're in NIS-only mode, do the search using * NIS 'reverse netgroup' lookups. @@ -347,20 +350,20 @@ innetgr(group, host, user, dom) &resultlen)) free(result); else { - if (_listmatch(result, group, resultlen)) { - free(result); + rv = _listmatch(result, group, resultlen); + free(result); + if (rv) return(1); - } + else + return(0); } } - free(result); #ifdef CHARITABLE } /* * Couldn't match using NIS-exclusive mode -- try * standard mode. */ - _yp_innetgr = 0; setnetgrent(group); #else return(0); -- cgit v1.1