summaryrefslogtreecommitdiff
path: root/groupaccess.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2004-02-24 13:05:11 +1100
committerDamien Miller <djm@mindrot.org>2004-02-24 13:05:11 +1100
commita811d9a9a167ffb018f18be84dc810826e73c8f2 (patch)
tree3595346bd26b9252a270f8982b140b973502b499 /groupaccess.c
parent8a4e4f8779ca39e97a8580263c94dc91cfb745ca (diff)
- (djm) [groupaccess.c uidswap.c] Bug #787: Size group arrays at runtime
using sysconf() if available Based on patches from holger AT van-lengerich.de and openssh_bugzilla AT hockin.org
Diffstat (limited to 'groupaccess.c')
-rw-r--r--groupaccess.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/groupaccess.c b/groupaccess.c
index fbf794fc8..f50879f83 100644
--- a/groupaccess.c
+++ b/groupaccess.c
@@ -31,7 +31,7 @@ RCSID("$OpenBSD: groupaccess.c,v 1.6 2003/04/08 20:21:28 itojun Exp $");
31#include "log.h" 31#include "log.h"
32 32
33static int ngroups; 33static int ngroups;
34static char *groups_byname[NGROUPS_MAX + 1]; /* +1 for base/primary group */ 34static char **groups_byname;
35 35
36/* 36/*
37 * Initialize group access list for user with primary (base) and 37 * 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 */
40int 40int
41ga_init(const char *user, gid_t base) 41ga_init(const char *user, gid_t base)
42{ 42{
43 gid_t groups_bygid[NGROUPS_MAX + 1]; 43 gid_t *groups_bygid;
44 int i, j; 44 int i, j;
45 struct group *gr; 45 struct group *gr;
46 46
47 if (ngroups > 0) 47 if (ngroups > 0)
48 ga_free(); 48 ga_free();
49 49
50 ngroups = sizeof(groups_bygid) / sizeof(gid_t); 50 ngroups = NGROUPS_MAX;
51#if defined(HAVE_SYSCONF) && defined(_SC_NGROUPS_MAX)
52 ngroups = MAX(NGROUPS_MAX, sysconf(_SC_NGROUPS_MAX));
53#endif
54
55 groups_bygid = xmalloc(ngroups * sizeof(*groups_bygid));
56 groups_byname = xmalloc(ngroups * sizeof(*groups_byname));
57
51 if (getgrouplist(user, base, groups_bygid, &ngroups) == -1) 58 if (getgrouplist(user, base, groups_bygid, &ngroups) == -1)
52 logit("getgrouplist: groups list too small"); 59 logit("getgrouplist: groups list too small");
53 for (i = 0, j = 0; i < ngroups; i++) 60 for (i = 0, j = 0; i < ngroups; i++)
54 if ((gr = getgrgid(groups_bygid[i])) != NULL) 61 if ((gr = getgrgid(groups_bygid[i])) != NULL)
55 groups_byname[j++] = xstrdup(gr->gr_name); 62 groups_byname[j++] = xstrdup(gr->gr_name);
63 xfree(groups_bygid);
56 return (ngroups = j); 64 return (ngroups = j);
57} 65}
58 66
@@ -84,5 +92,6 @@ ga_free(void)
84 for (i = 0; i < ngroups; i++) 92 for (i = 0; i < ngroups; i++)
85 xfree(groups_byname[i]); 93 xfree(groups_byname[i]);
86 ngroups = 0; 94 ngroups = 0;
95 xfree(groups_byname);
87 } 96 }
88} 97}