Compare commits
2 Commits
ba56e9c55b
...
1e7460c17b
Author | SHA1 | Date |
---|---|---|
Mike Yuan | 1e7460c17b | |
Mike Yuan | 2890403e21 |
|
@ -526,21 +526,23 @@ int merge_gid_lists(const gid_t *list1, size_t size1, const gid_t *list2, size_t
|
|||
return (int)nresult;
|
||||
}
|
||||
|
||||
int getgroups_alloc(gid_t** gids) {
|
||||
gid_t *allocated;
|
||||
_cleanup_free_ gid_t *p = NULL;
|
||||
int getgroups_alloc(gid_t **ret) {
|
||||
int ngroups = 8;
|
||||
unsigned attempt = 0;
|
||||
|
||||
allocated = new(gid_t, ngroups);
|
||||
if (!allocated)
|
||||
assert(ret);
|
||||
|
||||
for (unsigned attempt = 0;;) {
|
||||
_cleanup_free_ gid_t *p = NULL;
|
||||
|
||||
p = new(gid_t, ngroups);
|
||||
if (!p)
|
||||
return -ENOMEM;
|
||||
p = allocated;
|
||||
|
||||
for (;;) {
|
||||
ngroups = getgroups(ngroups, p);
|
||||
if (ngroups >= 0)
|
||||
break;
|
||||
if (ngroups >= 0) {
|
||||
*ret = TAKE_PTR(p);
|
||||
return ngroups;
|
||||
}
|
||||
if (errno != EINVAL)
|
||||
return -errno;
|
||||
|
||||
|
@ -553,18 +555,11 @@ int getgroups_alloc(gid_t** gids) {
|
|||
ngroups = getgroups(0, NULL);
|
||||
if (ngroups < 0)
|
||||
return -errno;
|
||||
if (ngroups == 0)
|
||||
return false;
|
||||
|
||||
free(allocated);
|
||||
|
||||
p = allocated = new(gid_t, ngroups);
|
||||
if (!allocated)
|
||||
return -ENOMEM;
|
||||
if (ngroups == 0) {
|
||||
*ret = NULL;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
*gids = TAKE_PTR(p);
|
||||
return ngroups;
|
||||
}
|
||||
|
||||
int get_home_dir(char **ret) {
|
||||
|
|
|
@ -64,7 +64,7 @@ int in_gid(gid_t gid);
|
|||
int in_group(const char *name);
|
||||
|
||||
int merge_gid_lists(const gid_t *list1, size_t size1, const gid_t *list2, size_t size2, gid_t **result);
|
||||
int getgroups_alloc(gid_t** gids);
|
||||
int getgroups_alloc(gid_t **ret);
|
||||
|
||||
int get_home_dir(char **ret);
|
||||
int get_shell(char **ret);
|
||||
|
|
Loading…
Reference in New Issue