static Npuser * _alloc_user (Npsrv *srv, struct passwd *pwd) { Npuser *u; if (!(u = malloc (sizeof (*u)))) { np_uerror (ENOMEM); np_logerr (srv, "_alloc_user: %s", pwd->pw_name); goto error; } u->sg = NULL; u->nsg = 0; if (!(u->uname = strdup (pwd->pw_name))) { np_uerror (ENOMEM); np_logerr (srv, "_alloc_user: %s", pwd->pw_name); goto error; } u->uid = pwd->pw_uid; u->gid = pwd->pw_gid; if (u->uid != 0 && _getgrouplist(srv, u) < 0) goto error; pthread_mutex_init (&u->lock, NULL); u->refcount = 0; u->t = time (NULL); u->next = NULL; if (srv->flags & SRV_FLAGS_DEBUG_USER) np_logmsg (srv, "user lookup: %d", u->uid); return u; error: if (u) _free_user (u); return NULL; }
int initgroups(const char*user,gid_t group) { int n=NGROUPS_MAX; gid_t grouplist[NGROUPS_MAX]; _getgrouplist(user,group,grouplist,&n); return setgroups(n,grouplist); }