--- embedaddon/rsync/uidlist.c 2013/10/14 07:51:14 1.1.1.2 +++ embedaddon/rsync/uidlist.c 2016/11/01 09:54:32 1.1.1.3 @@ -3,7 +3,7 @@ * * Copyright (C) 1996 Andrew Tridgell * Copyright (C) 1996 Paul Mackerras - * Copyright (C) 2004-2013 Wayne Davison + * Copyright (C) 2004-2015 Wayne Davison * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -473,12 +473,15 @@ void parse_name_map(char *map, BOOL usernames) usernames ? "user" : "group", cp); exit_cleanup(RERR_SYNTAX); } - if (dash) + if (dash) { + *dash = '\0'; noiu.max_id = id_parse(dash+1); - else + } else noiu.max_id = 0; flags = 0; id1 = id_parse(cp); + if (dash) + *dash = '-'; } else if (strpbrk(cp, "*[?")) { flags = NFLAGS_WILD_NAME_MATCH; noiu.name = cp; @@ -521,25 +524,49 @@ void parse_name_map(char *map, BOOL usernames) } #ifdef HAVE_GETGROUPLIST -const char *getallgroups(uid_t uid, gid_t *gid_list, int *size_ptr) +const char *getallgroups(uid_t uid, item_list *gid_list) { struct passwd *pw; + gid_t *gid_array; + int size; + if ((pw = getpwuid(uid)) == NULL) return "getpwuid failed"; + + gid_list->count = 0; /* We're overwriting any items in the list */ + EXPAND_ITEM_LIST(gid_list, gid_t, 32); + size = gid_list->malloced; + /* Get all the process's groups, with the pw_gid group first. */ - if (getgrouplist(pw->pw_name, pw->pw_gid, gid_list, size_ptr) < 0) - return "getgrouplist failed"; + if (getgrouplist(pw->pw_name, pw->pw_gid, gid_list->items, &size) < 0) { + if (size > (int)gid_list->malloced) { + gid_list->count = gid_list->malloced; + EXPAND_ITEM_LIST(gid_list, gid_t, size); + if (getgrouplist(pw->pw_name, pw->pw_gid, gid_list->items, &size) < 0) + size = -1; + } else + size = -1; + if (size < 0) + return "getgrouplist failed"; + } + gid_list->count = size; + gid_array = gid_list->items; + /* Paranoia: is the default group not first in the list? */ - if (gid_list[0] != pw->pw_gid) { + if (gid_array[0] != pw->pw_gid) { int j; - for (j = 0; j < *size_ptr; j++) { - if (gid_list[j] == pw->pw_gid) { - gid_list[j] = gid_list[0]; - gid_list[0] = pw->pw_gid; + for (j = 1; j < size; j++) { + if (gid_array[j] == pw->pw_gid) break; - } } + if (j == size) { /* The default group wasn't found! */ + EXPAND_ITEM_LIST(gid_list, gid_t, size+1); + gid_array = gid_list->items; + } + gid_array[j] = gid_array[0]; + gid_array[0] = pw->pw_gid; } + return NULL; } #endif