uwrap: Add a nwrap_setgroup which syncs all threads.
authorAndreas Schneider <asn@cryptomilk.org>
Tue, 30 Jul 2013 15:17:24 +0000 (17:17 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Sat, 9 Nov 2013 10:42:11 +0000 (11:42 +0100)
src/uid_wrapper.c

index 8c91d8b07a5f7ab07a8a4311baac3de1fab9a098..0a3b6f16aa12103911ba99c55f266b5cf636ff79 100644 (file)
@@ -688,13 +688,42 @@ out:
        return rc;
 }
 
+static int uwrap_setgroups(size_t size, const gid_t *list)
+{
+       struct uwrap_thread *id;
+       int rc = -1;
+
+       pthread_mutex_lock(&uwrap_id_mutex);
+       for (id = uwrap.ids; id; id = id->next) {
+               free(id->groups);
+               id->groups = NULL;
+               id->ngroups = 0;
+
+               if (size != 0) {
+                       id->groups = malloc(sizeof(gid_t) * size);
+                       if (id->groups == NULL) {
+                               errno = ENOMEM;
+                               goto out;
+                       }
+                       id->ngroups = size;
+                       memcpy(id->groups, list, size * sizeof(gid_t));
+               }
+       }
+
+       rc = 0;
+out:
+       pthread_mutex_unlock(&uwrap_id_mutex);
+
+       return rc;
+}
+
 int setgroups(size_t size, const gid_t *list)
 {
        if (!uwrap_enabled()) {
                return uwrap.libc.fns._libc_setgroups(size, list);
        }
 
-       return uwrap_setgroups_thread(size, list);
+       return uwrap_setgroups(size, list);
 }
 
 static int uwrap_getgroups(int size, gid_t *list)