- if (preserve_gid) {
- /* and the gid list */
- list = gidlist;
- while ((id = read_int(f)) != 0) {
- int len = read_byte(f);
- name = new_array(char, len+1);
- if (!name) out_of_memory("recv_uid_list");
- read_sbuf(f, name, len);
- if (!list) {
- gidlist = add_list(id, name);
- list = gidlist;
- } else {
- list->next = add_list(id, name);
- list = list->next;
+ /* Now convert all the uids/gids from sender values to our values. */
+#ifdef SUPPORT_ACLS
+ if (preserve_acls && (!numeric_ids || usermap || groupmap))
+ match_acl_ids();
+#endif
+ if (am_root && preserve_uid && (!numeric_ids || usermap)) {
+ for (i = 0; i < flist->used; i++)
+ F_OWNER(flist->files[i]) = match_uid(F_OWNER(flist->files[i]));
+ }
+ if (preserve_gid && (!am_root || !numeric_ids || groupmap)) {
+ for (i = 0; i < flist->used; i++) {
+ F_GROUP(flist->files[i]) = match_gid(F_GROUP(flist->files[i]),
+ &flist->files[i]->flags);
+ }
+ }
+}
+
+void parse_name_map(char *map, BOOL usernames)
+{
+ struct idlist **idmap_ptr = usernames ? &uidmap : &gidmap;
+ struct idlist **idlist_ptr = usernames ? &uidlist : &gidlist;
+ char *colon, *end, *name, *cp = map + strlen(map);
+ id_t id1;
+ uint16 flags;
+
+ /* Parse the list in reverse, so the order in the struct is right. */
+ while (1) {
+ end = cp;
+ while (cp > map && cp[-1] != ',') cp--;
+ if (!(colon = strchr(cp, ':'))) {
+ rprintf(FERROR, "No colon found in --%smap: %s\n",
+ usernames ? "user" : "group", cp);
+ exit_cleanup(RERR_SYNTAX);
+ }
+ if (!colon[1]) {
+ rprintf(FERROR, "No name found after colon --%smap: %s\n",
+ usernames ? "user" : "group", cp);
+ exit_cleanup(RERR_SYNTAX);
+ }
+ *colon = '\0';
+
+ if (isDigit(cp)) {
+ char *dash = strchr(cp, '-');
+ if (strspn(cp, "0123456789-") != (size_t)(colon - cp)
+ || (dash && (!dash[1] || strchr(dash+1, '-')))) {
+ rprintf(FERROR, "Invalid number in --%smap: %s\n",
+ usernames ? "user" : "group", cp);
+ exit_cleanup(RERR_SYNTAX);