diff options
author | wpaul <wpaul@FreeBSD.org> | 1997-10-13 17:09:15 +0000 |
---|---|---|
committer | wpaul <wpaul@FreeBSD.org> | 1997-10-13 17:09:15 +0000 |
commit | 36e2a3d8e91590900201d68269018446008eb684 (patch) | |
tree | 18dc5014378023398c9f1cb868c7fa642348000b /lib/libc/gen/getnetgrent.c | |
parent | b5347d93d3a62f4bb83daf6588efc9f0f2e1e644 (diff) | |
download | FreeBSD-src-36e2a3d8e91590900201d68269018446008eb684.zip FreeBSD-src-36e2a3d8e91590900201d68269018446008eb684.tar.gz |
Improve the innetgr() NIS+ compat kludge. We should only fail over to the
'slow' lookup if we get a YPERR_MAP (no such map in server's domain) error
instead of failing over on any error. In the latter case, if the 'fast'
search fails legitimately (i.e. the user or host really isn't a member
of the specified netgroup) then we end up doing the 'slow' search and
failing all over again. The result is still correct, but cycles are
consumed for no good reason.
Also removed the #ifdef CHARITABLE since the compat kludge is no longer
optional.
Diffstat (limited to 'lib/libc/gen/getnetgrent.c')
-rw-r--r-- | lib/libc/gen/getnetgrent.c | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/lib/libc/gen/getnetgrent.c b/lib/libc/gen/getnetgrent.c index ba4c147..605dd50 100644 --- a/lib/libc/gen/getnetgrent.c +++ b/lib/libc/gen/getnetgrent.c @@ -82,12 +82,6 @@ static char sccsid[] = "@(#)getnetgrent.c 8.2 (Berkeley) 4/27/95"; * netgroup entries, we use just those local entries and ignore * NIS (this is the original, pre-NIS behavior). */ -/* - * NIS+ servers in YP emulation mode suport only the netgroup map - * (they have no netgroup.byhost and netgroup.byuser 'reverse' maps) - * so we need this for compatibility. - */ -#define CHARITABLE #include <rpc/rpc.h> #include <rpcsvc/yp_prot.h> @@ -349,14 +343,23 @@ innetgr(group, host, user, dom) */ if (_use_only_yp) { char _key[MAXHOSTNAMELEN]; - int rot = 0; + int rot = 0, y = 0; if(yp_get_default_domain(&_netgr_yp_domain)) return(0); while(_buildkey(_key, user ? user : host, dom, &rot)) { - if (!yp_match(_netgr_yp_domain, user? "netgroup.byuser": + y = yp_match(_netgr_yp_domain, user? "netgroup.byuser": "netgroup.byhost", _key, strlen(_key), &result, - &resultlen)) { + &resultlen); + if (y) { + /* + * If we get an error other than 'no + * such key in map' then something is + * wrong and we should stop the search. + */ + if (y != YPERR_KEY) + break; + } else { rv = _listmatch(result, group, resultlen); free(result); if (rv) @@ -365,18 +368,22 @@ innetgr(group, host, user, dom) return(0); } } -#ifdef CHARITABLE + /* + * Couldn't match using NIS-exclusive mode. If the error + * was YPERR_MAP, then the failure happened because there + * was no netgroup.byhost or netgroup.byuser map. The odds + * are we are talking to an Sun NIS+ server in YP emulation + * mode; if this is the case, then we have to do the check + * the 'old-fashioned' way by grovelling through the netgroup + * map and resolving memberships on the fly. + */ + if (y != YPERR_MAP) + return(0); } - /* - * Couldn't match using NIS-exclusive mode -- try - * standard mode. - */ + setnetgrent(group); -#else - return(0); - } -#endif /* CHARITABLE */ #endif /* YP */ + while (getnetgrent(&hst, &usr, &dm)) if ((host == NULL || hst == NULL || !strcmp(host, hst)) && (user == NULL || usr == NULL || !strcmp(user, usr)) && |