From e882d43eca044dd302623f4497a941954dbdb3d8 Mon Sep 17 00:00:00 2001 From: Bill Paul Date: Mon, 13 Oct 1997 17:09:15 +0000 Subject: 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. --- lib/libc/gen/getnetgrent.c | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) (limited to 'lib') diff --git a/lib/libc/gen/getnetgrent.c b/lib/libc/gen/getnetgrent.c index ba4c1470f8bf..605dd500e422 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 #include @@ -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)) && -- cgit v1.3