From: Wayne Davison Date: Sun, 6 May 2007 06:44:22 +0000 (+0000) Subject: Fixed a few bugs, including the ability to map --numeric-ids. X-Git-Url: https://mattmccutchen.net/rsync/rsync-patches.git/commitdiff_plain/409bd73e8ff169c78566917425525bce60cf8ec7 Fixed a few bugs, including the ability to map --numeric-ids. --- diff --git a/usermap.diff b/usermap.diff index 3f04d26..081a2b3 100644 --- a/usermap.diff +++ b/usermap.diff @@ -1,6 +1,11 @@ -This adds a --usermap and a --groupmap option. +This adds a --usermap and a --groupmap option. See the man page for +more details. -TODO: make this work when --numeric-ids was specified. +To use this patch, run these commands for a successful build: + + patch -p1 next) { -+ switch (list->id) { -+ case -2: -+ if (!wildmatch(list->name, name)) -+ continue; -+ break; -+ case -1: -+ if (strcmp(list->name, name) != 0) -+ continue; -+ break; -+ default: -+ if (list->id != (int)id) -+ continue; -+ break; -+ } -+ id2 = list->id2; ++ for (node = uidmap; node; node = node->next) { ++ switch (node->id) { ++ case -2: ++ if (!wildmatch(node->name, name)) ++ continue; ++ break; ++ case -1: ++ if (strcmp(node->name, name) != 0) ++ continue; ++ break; ++ default: ++ if (node->id != (int)id) ++ continue; + break; + } -+ if (!list) -+ id2 = id ? map_uid(id, name) : 0; /* don't map root */ -+ } else -+ id2 = id; ++ break; ++ } ++ if (node) ++ id2 = node->id2; ++ else if (*name && id) ++ id2 = map_uid(id, name); ++ else ++ id2 = id; ++ ++ node = add_to_list(&uidlist, (int)id, *name ? name : NULL, (int)id2); - node = add_to_list(&uidlist, (int)id, name, (int)id2); + if (verbose > 3) { + rprintf(FINFO, "uid %d(%s) maps to %d\n", +- (int)id, name ? name : "", (int)id2); ++ (int)id, name, (int)id2); + } -@@ -174,8 +200,33 @@ static uid_t recv_add_uid(uid_t id, char + return id2; +@@ -174,16 +203,43 @@ static uid_t recv_add_uid(uid_t id, char /* Add a gid to the list of gids. Only called on receiving side. */ static gid_t recv_add_gid(gid_t id, char *name) { @@ -181,35 +232,51 @@ TODO: make this work when --numeric-ids was specified. struct idlist *node; + gid_t id2; + -+ if (name) { -+ struct idlist *list; -+ for (list = gidmap; list; list = list->next) { -+ switch (list->id) { -+ case -2: -+ if (!wildmatch(list->name, name)) -+ continue; -+ break; -+ case -1: -+ if (strcmp(list->name, name) != 0) -+ continue; -+ break; -+ default: -+ if (list->id != (int)id) -+ continue; -+ break; -+ } -+ id2 = list->id2; ++ if (!name) ++ name = ""; ++ ++ for (node = gidmap; node; node = node->next) { ++ switch (node->id) { ++ case -2: ++ if (!wildmatch(node->name, name)) ++ continue; ++ break; ++ case -1: ++ if (strcmp(node->name, name) != 0) ++ continue; ++ break; ++ default: ++ if (node->id != (int)id) ++ continue; + break; + } -+ if (!list) -+ id2 = id ? map_gid(id, name) : 0; /* don't map root */ -+ } else -+ id2 = id; ++ break; ++ } ++ if (node) ++ id2 = node->id2; ++ else if (*name && id) ++ id2 = map_gid(id, name); ++ else ++ id2 = id; if (!am_root && !is_in_group(id2)) id2 = GID_NONE; -@@ -195,9 +246,6 @@ uid_t match_uid(uid_t uid) - static uid_t last_in, last_out; +- node = add_to_list(&gidlist, (int)id, name, (int)id2); ++ node = add_to_list(&gidlist, (int)id, name ? name : NULL, (int)id2); + + if (verbose > 3) { + rprintf(FINFO, "gid %d(%s) maps to %d\n", +- (int)id, name ? name : "", (int)id2); ++ (int)id, name, (int)id2); + } + + return id2; +@@ -192,12 +248,9 @@ static gid_t recv_add_gid(gid_t id, char + /* this function is a definate candidate for a faster algorithm */ + uid_t match_uid(uid_t uid) + { +- static uid_t last_in, last_out; ++ static uid_t last_in = -1, last_out = -1; struct idlist *list; - if (uid == 0) @@ -218,25 +285,31 @@ TODO: make this work when --numeric-ids was specified. if (uid == last_in) return last_out; -@@ -238,7 +286,7 @@ char *add_uid(uid_t uid) - struct idlist *list; - struct idlist *node; - -- if (uid == 0) /* don't map root */ -+ if (uid == 0 && protocol_version < 30) - return NULL; +@@ -208,7 +261,7 @@ uid_t match_uid(uid_t uid) + return last_out = (uid_t)list->id2; + } - for (list = uidlist; list; list = list->next) { -@@ -256,7 +304,7 @@ char *add_gid(gid_t gid) - struct idlist *list; - struct idlist *node; +- return last_out = uid; ++ return last_out = recv_add_uid(uid, NULL); + } -- if (gid == 0) /* don't map root */ -+ if (gid == 0 && protocol_version < 30) - return NULL; + gid_t match_gid(gid_t gid) +@@ -344,15 +397,95 @@ void recv_uid_list(int f, struct file_li - for (list = gidlist; list; list = list->next) { -@@ -356,3 +404,70 @@ void recv_uid_list(int f, struct file_li + /* Now convert all the uids/gids from sender values to our values. */ + #ifdef SUPPORT_ACLS +- if (preserve_acls && !numeric_ids) ++ if (preserve_acls && (!numeric_ids || usermap)) + match_acl_ids(); + #endif +- if (am_root && preserve_uid && !numeric_ids) { ++ if (am_root && preserve_uid && (!numeric_ids || usermap)) { + for (i = 0; i < flist->count; i++) + F_OWNER(flist->files[i]) = match_uid(F_UID(flist->files[i])); + } +- if (preserve_gid && (!am_root || !numeric_ids)) { ++ if (preserve_gid && (!am_root || !numeric_ids || groupmap)) { + for (i = 0; i < flist->count; i++) F_GROUP(flist->files[i]) = match_gid(F_GID(flist->files[i])); } } @@ -296,14 +369,27 @@ TODO: make this work when --numeric-ids was specified. + } + } + -+ if (usernames) ++ if (usernames) { + add_to_list(&uidmap, id1, id1 < 0 ? cp : NULL, id2); -+ else ++ if (numeric_ids && id2 >= 0) ++ add_to_list(&uidlist, id1, NULL, id2); ++ } else { + add_to_list(&gidmap, id1, id1 < 0 ? cp : NULL, id2); ++ if (numeric_ids && id2 >= 0) ++ add_to_list(&gidlist, id1, NULL, id2); ++ } + + if (cp == map) + break; + + *--cp = '\0'; /* replace comma */ + } ++ ++ if (usernames) { ++ char *name = uid_to_name(0); ++ recv_add_uid(0, name ? name : "root"); ++ } else { ++ char *name = gid_to_name(0); ++ recv_add_gid(0, name ? name : "root"); ++ } +}