The patches for 3.0.9.
[rsync.git/patches.git] / usermap.diff
1 This adds a --usermap and a --groupmap option.  See the man page for
2 more details.
3
4 To use this patch, run these commands for a successful build:
5
6     patch -p1 <patches/usermap.diff
7     ./configure                         (optional if already run)
8     make
9
10 based-on: 40afd365cc8ca968fd16e161d24df5b8a8a520cc
11 diff --git a/flist.c b/flist.c
12 --- a/flist.c
13 +++ b/flist.c
14 @@ -70,6 +70,7 @@ extern int unsort_ndx;
15  extern uid_t our_uid;
16  extern struct stats stats;
17  extern char *filesfrom_host;
18 +extern char *usermap, *groupmap;
19  
20  extern char curr_dir[MAXPATHLEN];
21  
22 @@ -776,7 +777,7 @@ static struct file_struct *recv_file_entry(int f, struct file_list *flist, int x
23                         uid = (uid_t)read_varint(f);
24                         if (xflags & XMIT_USER_NAME_FOLLOWS)
25                                 uid = recv_user_name(f, uid);
26 -                       else if (inc_recurse && am_root && !numeric_ids)
27 +                       else if (inc_recurse && am_root && (!numeric_ids || usermap))
28                                 uid = match_uid(uid);
29                 }
30         }
31 @@ -788,7 +789,7 @@ static struct file_struct *recv_file_entry(int f, struct file_list *flist, int x
32                         gid_flags = 0;
33                         if (xflags & XMIT_GROUP_NAME_FOLLOWS)
34                                 gid = recv_group_name(f, gid, &gid_flags);
35 -                       else if (inc_recurse && (!am_root || !numeric_ids))
36 +                       else if (inc_recurse && (!am_root || !numeric_ids || groupmap))
37                                 gid = match_gid(gid, &gid_flags);
38                 }
39         }
40 @@ -2319,8 +2320,13 @@ struct file_list *recv_file_list(int f)
41         int64 start_read;
42         int save_verbose = verbose;
43  
44 -       if (!first_flist)
45 +       if (!first_flist) {
46                 rprintf(FLOG, "receiving file list\n");
47 +               if (usermap)
48 +                       parse_name_map(usermap, 1);
49 +               if (groupmap)
50 +                       parse_name_map(groupmap, 0);
51 +       }
52         if (show_filelist_p())
53                 start_filelist_progress("receiving file list");
54         else if (inc_recurse && verbose && !am_server && !first_flist)
55 diff --git a/options.c b/options.c
56 --- a/options.c
57 +++ b/options.c
58 @@ -165,6 +165,8 @@ char *rsync_path = RSYNC_PATH;
59  char *backup_dir = NULL;
60  char backup_dir_buf[MAXPATHLEN];
61  char *sockopts = NULL;
62 +char *usermap = NULL;
63 +char *groupmap = NULL;
64  int rsync_port = 0;
65  int compare_dest = 0;
66  int copy_dest = 0;
67 @@ -383,6 +385,9 @@ void usage(enum logcode F)
68    rprintf(F,"     --delay-updates         put all updated files into place at transfer's end\n");
69    rprintf(F," -m, --prune-empty-dirs      prune empty directory chains from the file-list\n");
70    rprintf(F,"     --numeric-ids           don't map uid/gid values by user/group name\n");
71 +  rprintf(F,"     --usermap=STRING        custom username mapping\n");
72 +  rprintf(F,"     --groupmap=STRING       custom groupname mapping\n");
73 +  rprintf(F,"     --chown=USER:GROUP      simple username/groupname mapping\n");
74    rprintf(F,"     --timeout=SECONDS       set I/O timeout in seconds\n");
75    rprintf(F,"     --contimeout=SECONDS    set daemon connection timeout in seconds\n");
76    rprintf(F," -I, --ignore-times          don't skip files that match in size and mod-time\n");
77 @@ -445,7 +450,7 @@ enum {OPT_VERSION = 1000, OPT_DAEMON, OPT_SENDER, OPT_EXCLUDE, OPT_EXCLUDE_FROM,
78        OPT_FILTER, OPT_COMPARE_DEST, OPT_COPY_DEST, OPT_LINK_DEST, OPT_HELP,
79        OPT_INCLUDE, OPT_INCLUDE_FROM, OPT_MODIFY_WINDOW, OPT_MIN_SIZE, OPT_CHMOD,
80        OPT_READ_BATCH, OPT_WRITE_BATCH, OPT_ONLY_WRITE_BATCH, OPT_MAX_SIZE,
81 -      OPT_NO_D, OPT_APPEND, OPT_NO_ICONV,
82 +      OPT_NO_D, OPT_APPEND, OPT_NO_ICONV, OPT_USERMAP, OPT_GROUPMAP, OPT_CHOWN,
83        OPT_SERVER, OPT_REFUSED_BASE = 9000};
84  
85  static struct poptOption long_options[] = {
86 @@ -621,6 +626,9 @@ static struct poptOption long_options[] = {
87    {"no-s",             0,  POPT_ARG_VAL,    &protect_args, 0, 0, 0},
88    {"numeric-ids",      0,  POPT_ARG_VAL,    &numeric_ids, 1, 0, 0 },
89    {"no-numeric-ids",   0,  POPT_ARG_VAL,    &numeric_ids, 0, 0, 0 },
90 +  {"usermap",          0,  POPT_ARG_STRING, 0, OPT_USERMAP, 0, 0 },
91 +  {"groupmap",         0,  POPT_ARG_STRING, 0, OPT_GROUPMAP, 0, 0 },
92 +  {"chown",            0,  POPT_ARG_STRING, 0, OPT_CHOWN, 0, 0 },
93    {"timeout",          0,  POPT_ARG_INT,    &io_timeout, 0, 0, 0 },
94    {"no-timeout",       0,  POPT_ARG_VAL,    &io_timeout, 0, 0, 0 },
95    {"contimeout",       0,  POPT_ARG_INT,    &connect_timeout, 0, 0, 0 },
96 @@ -1227,6 +1235,43 @@ int parse_arguments(int *argc_p, const char ***argv_p)
97                         }
98                         break;
99  
100 +               case OPT_USERMAP:
101 +                       if (usermap) {
102 +                               snprintf(err_buf, sizeof err_buf,
103 +                                   "You can only specify --usermap once.\n");
104 +                               return 0;
105 +                       }
106 +                       usermap = (char *)poptGetOptArg(pc);
107 +                       break;
108 +
109 +               case OPT_GROUPMAP:
110 +                       if (groupmap) {
111 +                               snprintf(err_buf, sizeof err_buf,
112 +                                   "You can only specify --groupmap once.\n");
113 +                               return 0;
114 +                       }
115 +                       groupmap = (char *)poptGetOptArg(pc);
116 +                       break;
117 +
118 +               case OPT_CHOWN:
119 +                       if (usermap || groupmap) {
120 +                               snprintf(err_buf, sizeof err_buf,
121 +                                   "You can only specify --chown once.\n");
122 +                               return 0;
123 +                       } else {
124 +                               const char *chown = poptGetOptArg(pc);
125 +                               int len;
126 +                               if ((arg = strchr(chown, ':')) != NULL) {
127 +                                       if (arg[1] && asprintf(&groupmap, "*:%s", arg+1) < 0)
128 +                                               out_of_memory("parse_arguments");
129 +                                       len = arg - chown;
130 +                               } else
131 +                                       len = strlen(chown);
132 +                               if (len && asprintf(&usermap, "*:%.*s", len, chown) < 0)
133 +                                       out_of_memory("parse_arguments");
134 +                       }
135 +                       break;
136 +
137                 case OPT_HELP:
138                         usage(FINFO);
139                         exit_cleanup(0);
140 @@ -2018,6 +2063,18 @@ void server_options(char **args, int *argc_p)
141                 args[ac++] = "--use-qsort";
142  
143         if (am_sender) {
144 +               if (usermap) {
145 +                       if (asprintf(&arg, "--usermap=%s", usermap) < 0)
146 +                               goto oom;
147 +                       args[ac++] = arg;
148 +               }
149 +
150 +               if (groupmap) {
151 +                       if (asprintf(&arg, "--groupmap=%s", groupmap) < 0)
152 +                               goto oom;
153 +                       args[ac++] = arg;
154 +               }
155 +
156                 if (ignore_existing)
157                         args[ac++] = "--ignore-existing";
158  
159 diff --git a/rsync.yo b/rsync.yo
160 --- a/rsync.yo
161 +++ b/rsync.yo
162 @@ -395,6 +395,9 @@ to the detailed description below for a complete description.  verb(
163       --delay-updates         put all updated files into place at end
164   -m, --prune-empty-dirs      prune empty directory chains from file-list
165       --numeric-ids           don't map uid/gid values by user/group name
166 +     --usermap=STRING        custom username mapping
167 +     --groupmap=STRING       custom groupname mapping
168 +     --chown=USER:GROUP      simple username/groupname mapping
169       --timeout=SECONDS       set I/O timeout in seconds
170       --contimeout=SECONDS    set daemon connection timeout in seconds
171   -I, --ignore-times          don't skip files that match size and time
172 @@ -1739,6 +1742,57 @@ from the source system is used instead.  See also the comments on the
173  the chroot setting affects rsync's ability to look up the names of the
174  users and groups and what you can do about it.
175  
176 +dit(bf(--usermap=STRING, --groupmap=STRING)) These options allow you to
177 +specify users and groups that should be mapped to other values by the
178 +receiving side.  The bf(STRING) is one or more bf(FROM):bf(TO) pairs of
179 +values separated by commas.  Any matching bf(FROM) value from the sender is
180 +replaced with a bf(TO) value from the receiver.  You may specify usernames
181 +or user IDs for the bf(FROM) and bf(TO) values, and the bf(FROM) value may
182 +also be a wild-card string, which will be matched against the sender's
183 +names (wild-cards do NOT match against ID numbers, though see below for
184 +why a '*' matches everything).  You may instead specify a range of ID
185 +numbers via an inclusive range: LOW-HIGH.  For example:
186 +
187 +verb(  --usermap=0-99:nobody,wayne:admin,*:normal --groupmap=usr:1,1:usr)
188 +
189 +The first match in the list is the one that is used.  You should specify
190 +all your user mappings using a single bf(--usermap) option, and/or all
191 +your group mappings using a single bf(--groupmap) option.
192 +
193 +Note that the sender's name for the 0 user and group are not transmitted
194 +to the receiver, so you should either match these values using a 0, or use
195 +the names in effect on the receiving side (typically "root").  All other
196 +bf(FROM) names match those in use on the sending side.  All bf(TO) names
197 +match those in use on the receiving side.
198 +
199 +Any IDs that do not have a name on the sending side are treated as having an
200 +empty name for the purpose of matching.  This allows them to be matched via
201 +a "*" or using an empty name.  For instance:
202 +
203 +verb(  --usermap=:nobody --groupmap=*:nobody)
204 +
205 +When the bf(--numeric-ids) option is used,the sender does not send any
206 +names, so all the IDs are treated as having an empty name.  This means that
207 +you will need to specify numeric bf(FROM) values if you want to map these
208 +nameless IDs to different values.
209 +
210 +For the bf(--usermap) option to have any effect, the bf(-o) (bf(--owner))
211 +option must be used (or implied), and the receiver will need to be running
212 +as a super-user (see also the bf(--fake-super) option).  For the bf(--groupmap)
213 +option to have any effect, the bf(-g) (bf(--groups)) option must be used
214 +(or implied), and the receiver will need to have permissions to set that
215 +group.
216 +
217 +dit(bf(--chown=USER:GROUP)) This option forces all files to be owned by USER
218 +with group GROUP.  This is a simpler interface than using bf(--usermap) and
219 +bf(--groupmap) directly, but it is implemented using those options internally,
220 +so you cannot mix them.  If either the USER or GROUP is empty, no mapping for
221 +the omitted user/group will occur.  If GROUP is empty, the trailing colon may
222 +be omitted, but if USER is empty, a leading colon must be supplied.
223 +
224 +If you specify "--chown=foo:bar, this is exactly the same as specifying
225 +"--usermap=*:foo --groupmap=*:bar", only easier.
226 +
227  dit(bf(--timeout=TIMEOUT)) This option allows you to set a maximum I/O
228  timeout in seconds. If no data is transferred for the specified time
229  then rsync will exit. The default is 0, which means no timeout.
230 diff --git a/support/mapfrom b/support/mapfrom
231 new file mode 100755
232 --- /dev/null
233 +++ b/support/mapfrom
234 @@ -0,0 +1,5 @@
235 +#!/usr/bin/perl
236 +while (<>) {
237 +    push @_, "$2:$1" if /^(\w+):[^:]+:(\d+)/;
238 +}
239 +print join(',', @_), "\n";
240 diff --git a/support/mapto b/support/mapto
241 new file mode 100755
242 --- /dev/null
243 +++ b/support/mapto
244 @@ -0,0 +1,5 @@
245 +#!/usr/bin/perl
246 +while (<>) {
247 +    push @_, "$1:$2" if /^(\w+):[^:]+:(\d+)/;
248 +}
249 +print join(',', @_), "\n";
250 diff --git a/uidlist.c b/uidlist.c
251 --- a/uidlist.c
252 +++ b/uidlist.c
253 @@ -24,6 +24,7 @@
254   * are special. */
255  
256  #include "rsync.h"
257 +#include "ifuncs.h"
258  #include "io.h"
259  
260  extern int verbose;
261 @@ -32,6 +33,8 @@ extern int preserve_uid;
262  extern int preserve_gid;
263  extern int preserve_acls;
264  extern int numeric_ids;
265 +extern char *usermap;
266 +extern char *groupmap;
267  
268  #ifdef HAVE_GETGROUPS
269  # ifndef GETGROUPS_T
270 @@ -39,6 +42,9 @@ extern int numeric_ids;
271  # endif
272  #endif
273  
274 +#define NFLAGS_WILD_NAME_MATCH (1<<0)
275 +#define NFLAGS_NAME_MATCH (1<<1)
276 +
277  struct idlist {
278         struct idlist *next;
279         const char *name;
280 @@ -46,8 +52,28 @@ struct idlist {
281         uint16 flags;
282  };
283  
284 -static struct idlist *uidlist;
285 -static struct idlist *gidlist;
286 +static struct idlist *uidlist, *uidmap;
287 +static struct idlist *gidlist, *gidmap;
288 +
289 +static id_t id_parse(const char *num_str)
290 +{
291 +       id_t tmp, num = 0;
292 +       const char *cp = num_str;
293 +
294 +       while (*cp) {
295 +               if (!isDigit(cp)) {
296 +                 invalid_num:
297 +                       rprintf(FERROR, "Invalid ID number: %s\n", num_str);
298 +                       exit_cleanup(RERR_SYNTAX);
299 +               }
300 +               tmp = num * 10 + *cp++ - '0';
301 +               if (tmp < num)
302 +                       goto invalid_num;
303 +               num = tmp;
304 +       }
305 +
306 +       return num;
307 +}
308  
309  static struct idlist *add_to_list(struct idlist **root, id_t id, const char *name,
310                                   id_t id2, uint16 flags)
311 @@ -82,22 +108,6 @@ static const char *gid_to_name(gid_t gid)
312         return NULL;
313  }
314  
315 -static uid_t map_uid(uid_t id, const char *name)
316 -{
317 -       uid_t uid;
318 -       if (id != 0 && name_to_uid(name, &uid))
319 -               return uid;
320 -       return id;
321 -}
322 -
323 -static gid_t map_gid(gid_t id, const char *name)
324 -{
325 -       gid_t gid;
326 -       if (id != 0 && name_to_gid(name, &gid))
327 -               return gid;
328 -       return id;
329 -}
330 -
331  static int is_in_group(gid_t gid)
332  {
333  #ifdef HAVE_GETGROUPS
334 @@ -157,34 +167,53 @@ static int is_in_group(gid_t gid)
335  #endif
336  }
337  
338 -/* Add a uid to the list of uids.  Only called on receiving side. */
339 -static struct idlist *recv_add_uid(uid_t id, const char *name)
340 +/* Add a uid/gid to its list of ids.  Only called on receiving side. */
341 +static struct idlist *recv_add_id(struct idlist **idlist_ptr, struct idlist *idmap,
342 +                                 id_t id, const char *name)
343  {
344 -       uid_t id2 = name ? map_uid(id, name) : id;
345         struct idlist *node;
346 +       int flag;
347 +       id_t id2;
348  
349 -       node = add_to_list(&uidlist, id, name, id2, 0);
350 +       if (!name)
351 +               name = "";
352  
353 -       if (verbose > 3) {
354 -               rprintf(FINFO, "uid %u(%s) maps to %u\n",
355 -                       (unsigned)id, name ? name : "", (unsigned)id2);
356 +       for (node = idmap; node; node = node->next) {
357 +               if (node->flags & NFLAGS_WILD_NAME_MATCH) {
358 +                       if (!wildmatch(node->name, name))
359 +                               continue;
360 +               } else if (node->flags & NFLAGS_NAME_MATCH) {
361 +                       if (strcmp(node->name, name) != 0)
362 +                               continue;
363 +               } else if (node->name) {
364 +                       if (id < node->id || id > (unsigned long)node->name)
365 +                               continue;
366 +               } else {
367 +                       if (node->id != id)
368 +                               continue;
369 +               }
370 +               break;
371         }
372 +       if (node)
373 +               id2 = node->id2;
374 +       else if (*name && id) {
375 +               if (idlist_ptr == &uidlist) {
376 +                       uid_t uid;
377 +                       id2 = name_to_uid(name, &uid) ? uid : id;
378 +               } else {
379 +                       gid_t gid;
380 +                       id2 = name_to_gid(name, &gid) ? gid : id;
381 +               }
382 +       } else
383 +               id2 = id;
384  
385 -       return node;
386 -}
387 -
388 -/* Add a gid to the list of gids.  Only called on receiving side. */
389 -static struct idlist *recv_add_gid(gid_t id, const char *name)
390 -{
391 -       gid_t id2 = name ? map_gid(id, name) : id;
392 -       struct idlist *node;
393 -
394 -       node = add_to_list(&gidlist, id, name, id2,
395 -               !am_root && !is_in_group(id2) ? FLAG_SKIP_GROUP : 0);
396 +       flag = idlist_ptr == &gidlist && !am_root && !is_in_group(id2) ? FLAG_SKIP_GROUP : 0;
397 +       node = add_to_list(idlist_ptr, id, *name ? name : NULL, id2, flag);
398  
399         if (verbose > 3) {
400 -               rprintf(FINFO, "gid %u(%s) maps to %u\n",
401 -                       (unsigned)id, name ? name : "", (unsigned)id2);
402 +               rprintf(FINFO, "%sid %u(%s) maps to %u\n",
403 +                       idlist_ptr == &uidlist ? "u" : "g",
404 +                       (unsigned)id, name, (unsigned)id2);
405         }
406  
407         return node;
408 @@ -193,23 +222,22 @@ static struct idlist *recv_add_gid(gid_t id, const char *name)
409  /* this function is a definate candidate for a faster algorithm */
410  uid_t match_uid(uid_t uid)
411  {
412 -       static uid_t last_in, last_out;
413 +       static struct idlist *last = NULL;
414         struct idlist *list;
415  
416 -       if (uid == 0)
417 -               return 0;
418 -
419 -       if (uid == last_in)
420 -               return last_out;
421 -
422 -       last_in = uid;
423 +       if (last && uid == last->id)
424 +               return last->id2;
425  
426         for (list = uidlist; list; list = list->next) {
427                 if (list->id == uid)
428 -                       return last_out = list->id2;
429 +                       break;
430         }
431  
432 -       return last_out = uid;
433 +       if (!list)
434 +               list = recv_add_id(&uidlist, uidmap, uid, NULL);
435 +       last = list;
436 +
437 +       return list->id2;
438  }
439  
440  gid_t match_gid(gid_t gid, uint16 *flags_ptr)
441 @@ -225,7 +253,7 @@ gid_t match_gid(gid_t gid, uint16 *flags_ptr)
442                                 break;
443                 }
444                 if (!list)
445 -                       list = recv_add_gid(gid, NULL);
446 +                       list = recv_add_id(&gidlist, gidmap, gid, NULL);
447                 last = list;
448         }
449  
450 @@ -318,7 +346,7 @@ uid_t recv_user_name(int f, uid_t uid)
451                 free(name);
452                 name = NULL;
453         }
454 -       node = recv_add_uid(uid, name); /* node keeps name's memory */
455 +       node = recv_add_id(&uidlist, uidmap, uid, name); /* node keeps name's memory */
456         return node->id2;
457  }
458  
459 @@ -334,7 +362,7 @@ gid_t recv_group_name(int f, gid_t gid, uint16 *flags_ptr)
460                 free(name);
461                 name = NULL;
462         }
463 -       node = recv_add_gid(gid, name); /* node keeps name's memory */
464 +       node = recv_add_id(&gidlist, gidmap, gid, name); /* node keeps name's memory */
465         if (flags_ptr && node->flags & FLAG_SKIP_GROUP)
466                 *flags_ptr |= FLAG_SKIP_GROUP;
467         return node->id2;
468 @@ -361,17 +389,103 @@ void recv_id_list(int f, struct file_list *flist)
469  
470         /* Now convert all the uids/gids from sender values to our values. */
471  #ifdef SUPPORT_ACLS
472 -       if (preserve_acls && !numeric_ids)
473 +       if (preserve_acls && (!numeric_ids || usermap || groupmap))
474                 match_acl_ids();
475  #endif
476 -       if (am_root && preserve_uid && !numeric_ids) {
477 +       if (am_root && preserve_uid && (!numeric_ids || usermap)) {
478                 for (i = 0; i < flist->used; i++)
479                         F_OWNER(flist->files[i]) = match_uid(F_OWNER(flist->files[i]));
480         }
481 -       if (preserve_gid && (!am_root || !numeric_ids)) {
482 +       if (preserve_gid && (!am_root || !numeric_ids || groupmap)) {
483                 for (i = 0; i < flist->used; i++) {
484                         F_GROUP(flist->files[i]) = match_gid(F_GROUP(flist->files[i]),
485                                                              &flist->files[i]->flags);
486                 }
487         }
488  }
489 +
490 +void parse_name_map(char *map, BOOL usernames)
491 +{
492 +       struct idlist **idmap_ptr = usernames ? &uidmap : &gidmap;
493 +       struct idlist **idlist_ptr = usernames ? &uidlist : &gidlist;
494 +       char *colon, *end, *name, *cp = map + strlen(map);
495 +       id_t id1;
496 +       uint16 flags;
497 +
498 +       /* Parse the list in reverse, so the order in the struct is right. */
499 +       while (1) {
500 +               end = cp;
501 +               while (cp > map && cp[-1] != ',') cp--;
502 +               if (!(colon = strchr(cp, ':'))) {
503 +                       rprintf(FERROR, "No colon found in --%smap: %s\n",
504 +                               usernames ? "user" : "group", cp);
505 +                       exit_cleanup(RERR_SYNTAX);
506 +               }
507 +               if (!colon[1]) {
508 +                       rprintf(FERROR, "No name found after colon --%smap: %s\n",
509 +                               usernames ? "user" : "group", cp);
510 +                       exit_cleanup(RERR_SYNTAX);
511 +               }
512 +               *colon = '\0';
513 +
514 +               if (isDigit(cp)) {
515 +                       char *dash = strchr(cp, '-');
516 +                       if (strspn(cp, "0123456789-") != (size_t)(colon - cp)
517 +                        || (dash && (!dash[1] || strchr(dash+1, '-')))) {
518 +                         bad_number:
519 +                               rprintf(FERROR, "Invalid number in --%smap: %s\n",
520 +                                       usernames ? "user" : "group", cp);
521 +                               exit_cleanup(RERR_SYNTAX);
522 +                       }
523 +                       if (dash)
524 +                               name = (char *)id_parse(dash+1);
525 +                       else
526 +                               name = (char *)0;
527 +                       flags = 0;
528 +                       id1 = id_parse(cp);
529 +               } else if (strpbrk(cp, "*[?")) {
530 +                       flags = NFLAGS_WILD_NAME_MATCH;
531 +                       name = cp;
532 +                       id1 = 0;
533 +               } else {
534 +                       flags = NFLAGS_NAME_MATCH;
535 +                       name = cp;
536 +                       id1 = 0;
537 +               }
538 +
539 +               if (isDigit(colon+1)) {
540 +                       if (strspn(colon+1, "0123456789") != (size_t)(end - colon - 1)) {
541 +                               cp = colon+1;
542 +                               goto bad_number;
543 +                       }
544 +                       add_to_list(idmap_ptr, id1, name, id_parse(colon+1), flags);
545 +               } else if (usernames) {
546 +                       uid_t uid;
547 +                       if (name_to_uid(colon+1, &uid))
548 +                               add_to_list(idmap_ptr, id1, name, uid, flags);
549 +                       else {
550 +                               rprintf(FERROR,
551 +                                   "Unknown --usermap name on receiver: %s\n",
552 +                                   colon+1);
553 +                       }
554 +               } else {
555 +                       gid_t gid;
556 +                       if (name_to_gid(colon+1, &gid))
557 +                               add_to_list(idmap_ptr, id1, name, gid, flags);
558 +                       else {
559 +                               rprintf(FERROR,
560 +                                   "Unknown --groupmap name on receiver: %s\n",
561 +                                   colon+1);
562 +                       }
563 +               }
564 +
565 +               if (cp == map)
566 +                       break;
567 +
568 +               *--cp = '\0'; /* replace comma */
569 +       }
570 +
571 +       /* The 0 user/group doesn't get its name sent, so add it explicitly. */
572 +       recv_add_id(idlist_ptr, *idmap_ptr, 0,
573 +                   numeric_ids ? NULL : usernames ? uid_to_name(0) : gid_to_name(0));
574 +}