enum nss_status _nss_compat_initgroups_dyn (const char *user, gid_t group, long int *start, long int *size, gid_t **groupsp, long int limit, int *errnop) { size_t buflen = sysconf (_SC_GETPW_R_SIZE_MAX); char *tmpbuf; enum nss_status status; ent_t intern = { TRUE, NULL, {NULL, 0, 0} }; status = internal_setgrent (&intern); if (status != NSS_STATUS_SUCCESS) return status; tmpbuf = __alloca (buflen); do { while ((status = internal_getgrent_r (&intern, tmpbuf, buflen, user, group, start, size, groupsp, limit, errnop)) == NSS_STATUS_TRYAGAIN && *errnop == ERANGE) tmpbuf = extend_alloca (tmpbuf, buflen, 2 * buflen); } while (status == NSS_STATUS_SUCCESS); internal_endgrent (&intern); return NSS_STATUS_SUCCESS; }
enum nss_status _nss_nisplus_endgrent (void) { __libc_lock_lock (lock); internal_endgrent (); __libc_lock_unlock (lock); return NSS_STATUS_SUCCESS; }
enum nss_status _nss_compat_initgroups_dyn (const char *user, gid_t group, long int *start, long int *size, gid_t **groupsp, long int limit, int *errnop) { size_t buflen = sysconf (_SC_GETPW_R_SIZE_MAX); char *tmpbuf; enum nss_status status; ent_t intern = { true, false, false, NULL, {NULL, 0, 0} }; bool use_malloc = false; status = internal_setgrent (&intern); if (status != NSS_STATUS_SUCCESS) return status; tmpbuf = __alloca (buflen); do { while ((status = internal_getgrent_r (&intern, tmpbuf, buflen, user, group, start, size, groupsp, limit, errnop)) == NSS_STATUS_TRYAGAIN && *errnop == ERANGE) if (__libc_use_alloca (buflen * 2)) tmpbuf = extend_alloca (tmpbuf, buflen, 2 * buflen); else { buflen *= 2; char *newbuf = realloc (use_malloc ? tmpbuf : NULL, buflen); if (newbuf == NULL) { status = NSS_STATUS_TRYAGAIN; goto done; } use_malloc = true; tmpbuf = newbuf; } } while (status == NSS_STATUS_SUCCESS); status = NSS_STATUS_SUCCESS; done: if (use_malloc) free (tmpbuf); internal_endgrent (&intern); return status; }
enum nss_status _nss_nisplus_setgrent (int stayopen) { enum nss_status status; __libc_lock_lock (lock); internal_endgrent (); // XXX We need to be able to set errno. Pass in new parameter. int err; status = internal_setgrent (&err); __libc_lock_unlock (lock); return status; }