uid_wrapper: We have talloc_array_length, no need for an explicit length
authorVolker Lendecke <vl@samba.org>
Sat, 19 Feb 2011 22:21:07 +0000 (23:21 +0100)
committerAndreas Schneider <asn@samba.org>
Thu, 6 Oct 2011 10:14:49 +0000 (12:14 +0200)
Signed-off-by: Andreas Schneider <asn@samba.org>
lib/uid_wrapper/uid_wrapper.c

index c67679777c5fdaefa7ad442181472bb4d2897e53..05d226b034ca2a59795920bced74bbc708b1bc46 100644 (file)
@@ -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)