libc/nss: Ensure that setgroupent(3) actually works as advertised

Because the "files" and "compat" implementations failed to set the
"stayopen", keyed lookups would close the database handle, contrary to
the purpose of setgroupent(3).  setpassent(3)'s implementation does not
have this bug.

PR:		165527
Submitted by:	Andrey Simonenko
MFC after:	1 month
This commit is contained in:
Mark Johnston 2021-01-21 14:30:19 -05:00
parent 6e411d8b14
commit 48a1868634

View File

@ -824,6 +824,7 @@ files_setgrent(void *retval, void *mdata, va_list ap)
rewind(st->fp);
else if (stayopen)
st->fp = fopen(_PATH_GROUP, "re");
st->stayopen = stayopen;
break;
case ENDGRENT:
if (st->fp != NULL) {
@ -1271,6 +1272,7 @@ compat_setgrent(void *retval, void *mdata, va_list ap)
rewind(st->fp);
else if (stayopen)
st->fp = fopen(_PATH_GROUP, "re");
st->stayopen = stayopen;
set_setent(dtab, mdata);
(void)_nsdispatch(NULL, dtab, NSDB_GROUP_COMPAT, "setgrent",
compatsrc, 0);