static NSS_STATUS _nss_winbind_getgroupsbymember_solwrap(nss_backend_t* be, void* args) { int errnop; struct nss_groupsbymem *gmem = (struct nss_groupsbymem *)args; long int numgids = gmem->numgids; long int maxgids = gmem->maxgids; NSS_DEBUG("_nss_winbind_getgroupsbymember"); _nss_winbind_initgroups_dyn(gmem->username, gmem->gid_array[0], /* Primary Group */ &numgids, &maxgids, &gmem->gid_array, gmem->maxgids, &errnop); gmem->numgids = numgids; gmem->maxgids = maxgids; /* * If the maximum number of gids have been found, return * SUCCESS so the switch engine will stop searching. Otherwise * return NOTFOUND so nsswitch will continue to get groups * from the remaining database backends specified in the * nsswitch.conf file. */ return (gmem->numgids == gmem->maxgids ? NSS_STATUS_SUCCESS : NSS_STATUS_NOTFOUND); }
int __freebsd_getgroupmembership(void *retval, void *mdata, va_list ap) { const char *uname = va_arg(ap, const char *); gid_t group = va_arg(ap, gid_t); gid_t *groups = va_arg(ap, gid_t *); int maxgrp = va_arg(ap, int); int *groupc = va_arg(ap, int *); NSS_STATUS ret; long int lcount, lsize; int i, errnop; gid_t *tmpgroups; /* Can be realloc() inside _nss_winbind_initgroups_dyn() */ if ((tmpgroups=calloc(maxgrp, sizeof(gid_t))) == NULL) { errno = ENOMEM; return NS_TRYAGAIN; } lcount = 0; lsize = maxgrp; /* insert primary membership(possibly already there) */ gr_addgid(group, groups, maxgrp, groupc); /* Don't limit number of groups, we want to know total size */ ret = _nss_winbind_initgroups_dyn(uname, group, &lcount, &lsize, &tmpgroups, 0, &errnop); if (ret == NSS_STATUS_SUCCESS) { /* lcount potentially can be bigger than maxgrp, so would groupc */ for (i = 0; i < lcount; i++) gr_addgid(tmpgroups[i], groups, maxgrp, groupc); } free(tmpgroups); /* Let following nsswitch backend(s) add more groups(?) */ return NSS_STATUS_NOTFOUND; }