diff options
author | Dag-Erling Smørgrav <des@FreeBSD.org> | 2004-02-26 10:38:49 +0000 |
---|---|---|
committer | Dag-Erling Smørgrav <des@FreeBSD.org> | 2004-02-26 10:38:49 +0000 |
commit | efcad6b72fe9d4f7ea99c021f4903d09ca31b666 (patch) | |
tree | 44704f8b727acba451fd902fe3c26053cb6ce73e /crypto/openssh/groupaccess.c | |
parent | 002696701b39a951525861c3d0da4984e29e7360 (diff) | |
download | src-test2-efcad6b72fe9d4f7ea99c021f4903d09ca31b666.tar.gz src-test2-efcad6b72fe9d4f7ea99c021f4903d09ca31b666.zip |
Notes
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 fbf794fc87b8..f50879f83a9f 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); } } |