./configure (optional if already run)
make
+based-on: 40afd365cc8ca968fd16e161d24df5b8a8a520cc
diff --git a/flist.c b/flist.c
--- a/flist.c
+++ b/flist.c
-@@ -71,6 +71,7 @@ extern int sender_symlink_iconv;
- extern int unsort_ndx;
+@@ -70,6 +70,7 @@ extern int unsort_ndx;
+ extern uid_t our_uid;
extern struct stats stats;
extern char *filesfrom_host;
+extern char *usermap, *groupmap;
extern char curr_dir[MAXPATHLEN];
-@@ -767,7 +768,7 @@ static struct file_struct *recv_file_entry(struct file_list *flist,
+@@ -776,7 +777,7 @@ static struct file_struct *recv_file_entry(int f, struct file_list *flist, int x
uid = (uid_t)read_varint(f);
if (xflags & XMIT_USER_NAME_FOLLOWS)
uid = recv_user_name(f, uid);
uid = match_uid(uid);
}
}
-@@ -779,7 +780,7 @@ static struct file_struct *recv_file_entry(struct file_list *flist,
+@@ -788,7 +789,7 @@ static struct file_struct *recv_file_entry(int f, struct file_list *flist, int x
gid_flags = 0;
if (xflags & XMIT_GROUP_NAME_FOLLOWS)
gid = recv_group_name(f, gid, &gid_flags);
gid = match_gid(gid, &gid_flags);
}
}
-@@ -2264,8 +2265,13 @@ struct file_list *recv_file_list(int f)
- int dstart, flags;
+@@ -2319,8 +2320,13 @@ struct file_list *recv_file_list(int f)
int64 start_read;
+ int save_verbose = verbose;
- if (!first_flist)
+ if (!first_flist) {
diff --git a/options.c b/options.c
--- a/options.c
+++ b/options.c
-@@ -167,6 +167,8 @@ char *rsync_path = RSYNC_PATH;
+@@ -165,6 +165,8 @@ char *rsync_path = RSYNC_PATH;
char *backup_dir = NULL;
char backup_dir_buf[MAXPATHLEN];
char *sockopts = NULL;
int rsync_port = 0;
int compare_dest = 0;
int copy_dest = 0;
-@@ -384,6 +386,9 @@ void usage(enum logcode F)
+@@ -383,6 +385,9 @@ void usage(enum logcode F)
rprintf(F," --delay-updates put all updated files into place at transfer's end\n");
rprintf(F," -m, --prune-empty-dirs prune empty directory chains from the file-list\n");
rprintf(F," --numeric-ids don't map uid/gid values by user/group name\n");
rprintf(F," --timeout=SECONDS set I/O timeout in seconds\n");
rprintf(F," --contimeout=SECONDS set daemon connection timeout in seconds\n");
rprintf(F," -I, --ignore-times don't skip files that match in size and mod-time\n");
-@@ -446,7 +451,7 @@ enum {OPT_VERSION = 1000, OPT_DAEMON, OPT_SENDER, OPT_EXCLUDE, OPT_EXCLUDE_FROM,
+@@ -445,7 +450,7 @@ enum {OPT_VERSION = 1000, OPT_DAEMON, OPT_SENDER, OPT_EXCLUDE, OPT_EXCLUDE_FROM,
OPT_FILTER, OPT_COMPARE_DEST, OPT_COPY_DEST, OPT_LINK_DEST, OPT_HELP,
OPT_INCLUDE, OPT_INCLUDE_FROM, OPT_MODIFY_WINDOW, OPT_MIN_SIZE, OPT_CHMOD,
OPT_READ_BATCH, OPT_WRITE_BATCH, OPT_ONLY_WRITE_BATCH, OPT_MAX_SIZE,
OPT_SERVER, OPT_REFUSED_BASE = 9000};
static struct poptOption long_options[] = {
-@@ -622,6 +627,9 @@ static struct poptOption long_options[] = {
+@@ -621,6 +626,9 @@ static struct poptOption long_options[] = {
{"no-s", 0, POPT_ARG_VAL, &protect_args, 0, 0, 0},
{"numeric-ids", 0, POPT_ARG_VAL, &numeric_ids, 1, 0, 0 },
{"no-numeric-ids", 0, POPT_ARG_VAL, &numeric_ids, 0, 0, 0 },
{"timeout", 0, POPT_ARG_INT, &io_timeout, 0, 0, 0 },
{"no-timeout", 0, POPT_ARG_VAL, &io_timeout, 0, 0, 0 },
{"contimeout", 0, POPT_ARG_INT, &connect_timeout, 0, 0, 0 },
-@@ -1228,6 +1236,43 @@ int parse_arguments(int *argc_p, const char ***argv_p)
+@@ -1227,6 +1235,43 @@ int parse_arguments(int *argc_p, const char ***argv_p)
}
break;
case OPT_HELP:
usage(FINFO);
exit_cleanup(0);
-@@ -2005,6 +2050,18 @@ void server_options(char **args, int *argc_p)
+@@ -2018,6 +2063,18 @@ void server_options(char **args, int *argc_p)
args[ac++] = "--use-qsort";
if (am_sender) {
diff --git a/rsync.yo b/rsync.yo
--- a/rsync.yo
+++ b/rsync.yo
-@@ -378,6 +378,9 @@ to the detailed description below for a complete description. verb(
+@@ -395,6 +395,9 @@ to the detailed description below for a complete description. verb(
--delay-updates put all updated files into place at end
-m, --prune-empty-dirs prune empty directory chains from file-list
--numeric-ids don't map uid/gid values by user/group name
--timeout=SECONDS set I/O timeout in seconds
--contimeout=SECONDS set daemon connection timeout in seconds
-I, --ignore-times don't skip files that match size and time
-@@ -1620,6 +1623,57 @@ from the source system is used instead. See also the comments on the
+@@ -1739,6 +1742,57 @@ from the source system is used instead. See also the comments on the
the chroot setting affects rsync's ability to look up the names of the
users and groups and what you can do about it.
#ifdef HAVE_GETGROUPS
# ifndef GETGROUPS_T
-@@ -41,6 +44,9 @@ extern int numeric_ids;
-
- #define GID_NONE ((gid_t)-1)
+@@ -39,6 +42,9 @@ extern int numeric_ids;
+ # endif
+ #endif
+#define NFLAGS_WILD_NAME_MATCH (1<<0)
+#define NFLAGS_NAME_MATCH (1<<1)
struct idlist {
struct idlist *next;
const char *name;
-@@ -48,8 +54,8 @@ struct idlist {
+@@ -46,8 +52,28 @@ struct idlist {
uint16 flags;
};
-static struct idlist *gidlist;
+static struct idlist *uidlist, *uidmap;
+static struct idlist *gidlist, *gidmap;
++
++static id_t id_parse(const char *num_str)
++{
++ id_t tmp, num = 0;
++ const char *cp = num_str;
++
++ while (*cp) {
++ if (!isDigit(cp)) {
++ invalid_num:
++ rprintf(FERROR, "Invalid ID number: %s\n", num_str);
++ exit_cleanup(RERR_SYNTAX);
++ }
++ tmp = num * 10 + *cp++ - '0';
++ if (tmp < num)
++ goto invalid_num;
++ num = tmp;
++ }
++
++ return num;
++}
static struct idlist *add_to_list(struct idlist **root, id_t id, const char *name,
id_t id2, uint16 flags)
-@@ -84,22 +90,6 @@ static const char *gid_to_name(gid_t gid)
+@@ -82,22 +108,6 @@ static const char *gid_to_name(gid_t gid)
return NULL;
}
static int is_in_group(gid_t gid)
{
#ifdef HAVE_GETGROUPS
-@@ -159,34 +149,53 @@ static int is_in_group(gid_t gid)
+@@ -157,34 +167,53 @@ static int is_in_group(gid_t gid)
#endif
}
+ if (node)
+ id2 = node->id2;
+ else if (*name && id) {
-+ if (idmap == uidmap) {
++ if (idlist_ptr == &uidlist) {
+ uid_t uid;
+ id2 = name_to_uid(name, &uid) ? uid : id;
+ } else {
-
- node = add_to_list(&gidlist, id, name, id2,
- !am_root && !is_in_group(id2) ? FLAG_SKIP_GROUP : 0);
-+ flag = idmap == gidmap && !am_root && !is_in_group(id2) ? FLAG_SKIP_GROUP : 0;
++ flag = idlist_ptr == &gidlist && !am_root && !is_in_group(id2) ? FLAG_SKIP_GROUP : 0;
+ node = add_to_list(idlist_ptr, id, *name ? name : NULL, id2, flag);
if (verbose > 3) {
- rprintf(FINFO, "gid %u(%s) maps to %u\n",
- (unsigned)id, name ? name : "", (unsigned)id2);
+ rprintf(FINFO, "%sid %u(%s) maps to %u\n",
-+ idmap == uidmap ? "u" : "g",
++ idlist_ptr == &uidlist ? "u" : "g",
+ (unsigned)id, name, (unsigned)id2);
}
return node;
-@@ -195,12 +204,9 @@ static struct idlist *recv_add_gid(gid_t id, const char *name)
+@@ -193,23 +222,22 @@ static struct idlist *recv_add_gid(gid_t id, const char *name)
/* 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;
++ static struct idlist *last = NULL;
struct idlist *list;
- if (uid == 0)
- return 0;
-
- if (uid == last_in)
- return last_out;
-
-@@ -208,10 +214,13 @@ uid_t match_uid(uid_t uid)
+- if (uid == last_in)
+- return last_out;
+-
+- last_in = uid;
++ if (last && uid == last->id)
++ return last->id2;
for (list = uidlist; list; list = list->next) {
if (list->id == uid)
- return last_out = uid;
+ if (!list)
+ list = recv_add_id(&uidlist, uidmap, uid, NULL);
++ last = list;
+
-+ return last_out = list->id2;
++ return list->id2;
}
gid_t match_gid(gid_t gid, uint16 *flags_ptr)
-@@ -227,7 +236,7 @@ gid_t match_gid(gid_t gid, uint16 *flags_ptr)
+@@ -225,7 +253,7 @@ gid_t match_gid(gid_t gid, uint16 *flags_ptr)
break;
}
if (!list)
last = list;
}
-@@ -320,7 +329,7 @@ uid_t recv_user_name(int f, uid_t uid)
+@@ -318,7 +346,7 @@ uid_t recv_user_name(int f, uid_t uid)
free(name);
name = NULL;
}
return node->id2;
}
-@@ -336,7 +345,7 @@ gid_t recv_group_name(int f, gid_t gid, uint16 *flags_ptr)
+@@ -334,7 +362,7 @@ gid_t recv_group_name(int f, gid_t gid, uint16 *flags_ptr)
free(name);
name = NULL;
}
if (flags_ptr && node->flags & FLAG_SKIP_GROUP)
*flags_ptr |= FLAG_SKIP_GROUP;
return node->id2;
-@@ -363,17 +372,103 @@ void recv_id_list(int f, struct file_list *flist)
+@@ -361,17 +389,103 @@ void recv_id_list(int f, struct file_list *flist)
/* Now convert all the uids/gids from sender values to our values. */
#ifdef SUPPORT_ACLS
}
}
+
-+void parse_name_map(char *map, int usernames)
++void parse_name_map(char *map, BOOL usernames)
+{
+ struct idlist **idmap_ptr = usernames ? &uidmap : &gidmap;
+ struct idlist **idlist_ptr = usernames ? &uidlist : &gidlist;
+ exit_cleanup(RERR_SYNTAX);
+ }
+ if (dash)
-+ name = (char *)atol(dash+1);
++ name = (char *)id_parse(dash+1);
+ else
+ name = (char *)0;
+ flags = 0;
-+ id1 = atol(cp);
++ id1 = id_parse(cp);
+ } else if (strpbrk(cp, "*[?")) {
+ flags = NFLAGS_WILD_NAME_MATCH;
+ name = cp;
+ cp = colon+1;
+ goto bad_number;
+ }
-+ add_to_list(idmap_ptr, id1, name, atol(colon+1), flags);
++ add_to_list(idmap_ptr, id1, name, id_parse(colon+1), flags);
+ } else if (usernames) {
+ uid_t uid;
+ if (name_to_uid(colon+1, &uid))