diff options
author | Volker Lendecke <vl@samba.org> | 2011-02-19 23:21:07 +0100 |
---|---|---|
committer | Andreas Schneider <asn@samba.org> | 2011-10-06 12:14:49 +0200 |
commit | c682ee32b8155776f73665c5671fec0dee83a8ab (patch) | |
tree | 37cc46e86768e5e596778abbddda245f74554d77 | |
parent | f6b7bd4a01205e442d3aa06d8edc3634a12945b2 (diff) | |
download | samba-c682ee32b8155776f73665c5671fec0dee83a8ab.tar.gz samba-c682ee32b8155776f73665c5671fec0dee83a8ab.tar.xz samba-c682ee32b8155776f73665c5671fec0dee83a8ab.zip |
uid_wrapper: We have talloc_array_length, no need for an explicit length
Signed-off-by: Andreas Schneider <asn@samba.org>
-rw-r--r-- | lib/uid_wrapper/uid_wrapper.c | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/lib/uid_wrapper/uid_wrapper.c b/lib/uid_wrapper/uid_wrapper.c index c67679777c..05d226b034 100644 --- a/lib/uid_wrapper/uid_wrapper.c +++ b/lib/uid_wrapper/uid_wrapper.c @@ -40,7 +40,6 @@ static struct { bool enabled; uid_t euid; gid_t egid; - unsigned ngroups; gid_t *groups; } uwrap; @@ -51,7 +50,6 @@ static void uwrap_init(void) if (getenv("UID_WRAPPER")) { uwrap.enabled = true; /* put us in one group */ - uwrap.ngroups = 1; uwrap.groups = talloc_array(NULL, gid_t, 1); uwrap.groups[0] = 0; } @@ -112,7 +110,6 @@ _PUBLIC_ int uwrap_setgroups(size_t size, const gid_t *list) } talloc_free(uwrap.groups); - uwrap.ngroups = 0; uwrap.groups = NULL; if (size != 0) { @@ -122,30 +119,33 @@ _PUBLIC_ int uwrap_setgroups(size_t size, const gid_t *list) return -1; } memcpy(uwrap.groups, list, size*sizeof(gid_t)); - uwrap.ngroups = size; } return 0; } _PUBLIC_ int uwrap_getgroups(int size, gid_t *list) { + size_t ngroups; + uwrap_init(); if (!uwrap.enabled) { return getgroups(size, list); } - if (size > uwrap.ngroups) { - size = uwrap.ngroups; + ngroups = talloc_array_length(uwrap.groups); + + if (size > ngroups) { + size = ngroups; } if (size == 0) { - return uwrap.ngroups; + return ngroups; } - if (size < uwrap.ngroups) { + if (size < ngroups) { errno = EINVAL; return -1; } memcpy(list, uwrap.groups, size*sizeof(gid_t)); - return uwrap.ngroups; + return ngroups; } _PUBLIC_ uid_t uwrap_getuid(void) |