diff options
Diffstat (limited to 'grp/initgroups.c')
-rw-r--r-- | grp/initgroups.c | 39 |
1 files changed, 19 insertions, 20 deletions
diff --git a/grp/initgroups.c b/grp/initgroups.c index 73c15c6..35af575 100644 --- a/grp/initgroups.c +++ b/grp/initgroups.c @@ -70,28 +70,27 @@ initgroups (user, group) register char **m; for (m = g->gr_mem; *m != NULL; ++m) - if (!strcmp (*m, user)) - break; - - if (*m == NULL) - { - /* Matched the user. Insert this group. */ - if (n == ngroups && limit <= 0) - { - /* Need a bigger buffer. */ - groups = memcpy (__alloca (ngroups * 2 * sizeof *groups), - groups, ngroups * sizeof *groups); - ngroups *= 2; - } - - groups[n++] = g->gr_gid; - - if (n == limit) - /* Can't take any more groups; stop searching. */ + if (strcmp (*m, user) == 0) + { + /* Matches user. Insert this group. */ + if (n == ngroups && limit <= 0) + { + /* Need a bigger buffer. */ + groups = memcpy (__alloca (ngroups * 2 * sizeof *groups), + groups, ngroups * sizeof *groups); + ngroups *= 2; + } + + groups[n++] = g->gr_gid; + + if (n == limit) + /* Can't take any more groups; stop searching. */ + goto done; + break; - } + } } - +done: endgrent (); return setgroups (n, groups); |