- static int j = 0;
-
- if (pair_cnt) {
- int start = j;
- fprintf(stderr, "start = %d\n", start);
- /* We start our search where we left off because
- * the IDs usually come in clumps. */
- do {
- fprintf(stderr, "checking %d\n", j);
- if (uid == pair_list[j].uid && gid == pair_list[j].gid)
- return pair_list + j;
- if (++j == pair_cnt)
- j = 0;
- } while (j != start);
- }
+ 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);
+ }
+ if (dash)
+ name = (char *)atol(dash+1);
+ else
+ name = (char *)0;
+ flags = 0;
+ id1 = atol(cp);
+ } else if (strpbrk(cp, "*[?")) {
+ flags = NFLAGS_WILD_NAME_MATCH;
+ name = cp;
+ id1 = 0;
+ } else {
+ flags = NFLAGS_NAME_MATCH;
+ name = cp;
+ id1 = 0;
+ }
+
+ if (usernames) {
+ uid_t uid;
+ if (user_to_uid(colon+1, &uid, True))
+ add_to_list(idmap_ptr, id1, name, uid, flags);
+ else {
+ rprintf(FERROR,
+ "Unknown --usermap name on receiver: %s\n",
+ colon+1);
+ }
+ } else {
+ gid_t gid;
+ if (group_to_gid(colon+1, &gid, True))
+ add_to_list(idmap_ptr, id1, name, gid, flags);
+ else {
+ rprintf(FERROR,
+ "Unknown --groupmap name on receiver: %s\n",
+ colon+1);
+ }
+ }
+
+ if (cp == map)
+ break;