diff options
author | des <des@FreeBSD.org> | 2004-02-26 10:38:49 +0000 |
---|---|---|
committer | des <des@FreeBSD.org> | 2004-02-26 10:38:49 +0000 |
commit | 7d1750f1d6c24163bf22790f8527f1783315c5e7 (patch) | |
tree | 44704f8b727acba451fd902fe3c26053cb6ce73e /crypto/openssh/groupaccess.c | |
parent | 5c8d98dfbd6964b6be84da30b9d16df0cab3c42d (diff) | |
download | FreeBSD-src-7d1750f1d6c24163bf22790f8527f1783315c5e7.zip FreeBSD-src-7d1750f1d6c24163bf22790f8527f1783315c5e7.tar.gz |
Vendor import of OpenSSH 3.8p1.
Diffstat (limited to 'crypto/openssh/groupaccess.c')
-rw-r--r-- | crypto/openssh/groupaccess.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/crypto/openssh/groupaccess.c b/crypto/openssh/groupaccess.c index fbf794f..f50879f 100644 --- a/crypto/openssh/groupaccess.c +++ b/crypto/openssh/groupaccess.c @@ -31,7 +31,7 @@ RCSID("$OpenBSD: groupaccess.c,v 1.6 2003/04/08 20:21:28 itojun Exp $"); #include "log.h" static int ngroups; -static char *groups_byname[NGROUPS_MAX + 1]; /* +1 for base/primary group */ +static char **groups_byname; /* * Initialize group access list for user with primary (base) and @@ -40,19 +40,27 @@ static char *groups_byname[NGROUPS_MAX + 1]; /* +1 for base/primary group */ int ga_init(const char *user, gid_t base) { - gid_t groups_bygid[NGROUPS_MAX + 1]; + gid_t *groups_bygid; int i, j; struct group *gr; if (ngroups > 0) ga_free(); - ngroups = sizeof(groups_bygid) / sizeof(gid_t); + ngroups = NGROUPS_MAX; +#if defined(HAVE_SYSCONF) && defined(_SC_NGROUPS_MAX) + ngroups = MAX(NGROUPS_MAX, sysconf(_SC_NGROUPS_MAX)); +#endif + + groups_bygid = xmalloc(ngroups * sizeof(*groups_bygid)); + groups_byname = xmalloc(ngroups * sizeof(*groups_byname)); + if (getgrouplist(user, base, groups_bygid, &ngroups) == -1) logit("getgrouplist: groups list too small"); for (i = 0, j = 0; i < ngroups; i++) if ((gr = getgrgid(groups_bygid[i])) != NULL) groups_byname[j++] = xstrdup(gr->gr_name); + xfree(groups_bygid); return (ngroups = j); } @@ -84,5 +92,6 @@ ga_free(void) for (i = 0; i < ngroups; i++) xfree(groups_byname[i]); ngroups = 0; + xfree(groups_byname); } } |