MCPcopy Index your code
hub / github.com/RsyncProject/rsync / getallgroups

Function getallgroups

uidlist.c:576–620  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

574
575#ifdef HAVE_GETGROUPLIST
576const char *getallgroups(uid_t uid, item_list *gid_list)
577{
578 struct passwd *pw;
579 gid_t *gid_array;
580 int size;
581
582 if ((pw = getpwuid(uid)) == NULL)
583 return "getpwuid failed";
584
585 gid_list->count = 0; /* We're overwriting any items in the list */
586 (void)EXPAND_ITEM_LIST(gid_list, gid_t, 32);
587 size = gid_list->malloced;
588
589 /* Get all the process's groups, with the pw_gid group first. */
590 if (getgrouplist(pw->pw_name, pw->pw_gid, gid_list->items, &size) < 0) {
591 if (size > (int)gid_list->malloced) {
592 gid_list->count = gid_list->malloced;
593 (void)EXPAND_ITEM_LIST(gid_list, gid_t, size);
594 if (getgrouplist(pw->pw_name, pw->pw_gid, gid_list->items, &size) < 0)
595 size = -1;
596 } else
597 size = -1;
598 if (size < 0)
599 return "getgrouplist failed";
600 }
601 gid_list->count = size;
602 gid_array = gid_list->items;
603
604 /* Paranoia: is the default group not first in the list? */
605 if (gid_array[0] != pw->pw_gid) {
606 int j;
607 for (j = 1; j < size; j++) {
608 if (gid_array[j] == pw->pw_gid)
609 break;
610 }
611 if (j == size) { /* The default group wasn't found! */
612 (void)EXPAND_ITEM_LIST(gid_list, gid_t, size+1);
613 gid_array = gid_list->items;
614 }
615 gid_array[j] = gid_array[0];
616 gid_array[0] = pw->pw_gid;
617 }
618
619 return NULL;
620}
621#endif

Callers 2

auth_serverFunction · 0.85
want_all_groupsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected