diff options
author | Sean Finney <sean.finney@sonyericsson.com> | 2011-04-19 11:05:47 -0400 |
---|---|---|
committer | Steve Dickson <steved@redhat.com> | 2011-04-19 12:30:22 -0400 |
commit | 9274e94db85bac04e170414cb8e0f4be271cde90 (patch) | |
tree | 382d0202e3f02b6388496403e6fc8d9f54e27412 /utils/mountd/cache.c | |
parent | a99269230a0e77e7bed4fa31c9547f0d61c7f206 (diff) | |
download | nfs-utils-9274e94db85bac04e170414cb8e0f4be271cde90.tar.gz nfs-utils-9274e94db85bac04e170414cb8e0f4be271cde90.tar.xz nfs-utils-9274e94db85bac04e170414cb8e0f4be271cde90.zip |
mountd: Use a dynamic buffer for storing lists of gid's
Previously, in auth_unix_gid, group lists were stored in an array of
hard-coded length 100, and in the situation that the group lists for a
particular call were too large, the array was swapped with a dynamically
allocated/freed buffer. For environments where users are commonly in
a large number of groups, this isn't an ideal approach.
Instead, use malloc/realloc to grow the list on an as-needed basis.
Signed-off-by: Sean Finney <sean.finney@sonyericsson.com>
Signed-off-by: Steve Dickson <steved@redhat.com>
Diffstat (limited to 'utils/mountd/cache.c')
-rw-r--r-- | utils/mountd/cache.c | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/utils/mountd/cache.c b/utils/mountd/cache.c index 1d6e953..ce93e3c 100644 --- a/utils/mountd/cache.c +++ b/utils/mountd/cache.c @@ -64,6 +64,7 @@ enum nfsd_fsid { */ static int cache_export_ent(char *domain, struct exportent *exp, char *p); +#define INITIAL_MANAGED_GROUPS 100 char *lbuf = NULL; int lbuflen = 0; @@ -134,11 +135,21 @@ static void auth_unix_gid(FILE *f) */ uid_t uid; struct passwd *pw; - gid_t glist[100], *groups = glist; - int ngroups = 100; + static gid_t *groups = NULL; + static int groups_len = 0; + gid_t *more_groups; + int ngroups = 0; int rv, i; char *cp; + if (groups_len == 0) { + groups = malloc(sizeof(gid_t) * INITIAL_MANAGED_GROUPS); + if (!groups) + return; + + groups_len = ngroups = INITIAL_MANAGED_GROUPS; + } + if (readline(fileno(f), &lbuf, &lbuflen) != 1) return; @@ -151,13 +162,16 @@ static void auth_unix_gid(FILE *f) rv = -1; else { rv = getgrouplist(pw->pw_name, pw->pw_gid, groups, &ngroups); - if (rv == -1 && ngroups >= 100) { - groups = malloc(sizeof(gid_t)*ngroups); - if (!groups) + if (rv == -1 && ngroups >= groups_len) { + more_groups = realloc(groups, sizeof(gid_t)*ngroups); + if (!more_groups) rv = -1; - else + else { + groups = more_groups; + groups_len = ngroups; rv = getgrouplist(pw->pw_name, pw->pw_gid, groups, &ngroups); + } } } qword_printuint(f, uid); @@ -169,9 +183,6 @@ static void auth_unix_gid(FILE *f) } else qword_printuint(f, 0); qword_eol(f); - - if (groups != glist) - free(groups); } #if USE_BLKID |