MCPcopy Index your code
hub / github.com/RsyncProject/rsync / parse_name_map

Function parse_name_map

uidlist.c:497–573  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

495}
496
497void parse_name_map(char *map, BOOL usernames)
498{
499 struct idlist **idmap_ptr = usernames ? &uidmap : &gidmap;
500 struct idlist **idlist_ptr = usernames ? &uidlist : &gidlist;
501 char *colon, *cp = map + strlen(map);
502 union name_or_id noiu;
503 id_t id1;
504 uint16 flags;
505
506 /* Parse the list in reverse, so the order in the struct is right. */
507 while (1) {
508 while (cp > map && cp[-1] != ',') cp--;
509 if (!(colon = strchr(cp, ':'))) {
510 rprintf(FERROR, "No colon found in --%smap: %s\n",
511 usernames ? "user" : "group", cp);
512 exit_cleanup(RERR_SYNTAX);
513 }
514 if (!colon[1]) {
515 rprintf(FERROR, "No name found after colon --%smap: %s\n",
516 usernames ? "user" : "group", cp);
517 exit_cleanup(RERR_SYNTAX);
518 }
519 *colon = '\0';
520
521 if (isDigit(cp)) {
522 char *dash = strchr(cp, '-');
523 if (strspn(cp, "0123456789-") != (size_t)(colon - cp)
524 || (dash && (!dash[1] || strchr(dash+1, '-')))) {
525 rprintf(FERROR, "Invalid number in --%smap: %s\n",
526 usernames ? "user" : "group", cp);
527 exit_cleanup(RERR_SYNTAX);
528 }
529 if (dash) {
530 *dash = '\0';
531 noiu.max_id = id_parse(dash+1);
532 } else
533 noiu.max_id = 0;
534 flags = 0;
535 id1 = id_parse(cp);
536 if (dash)
537 *dash = '-';
538 } else if (strpbrk(cp, "*[?")) {
539 flags = NFLAGS_WILD_NAME_MATCH;
540 noiu.name = cp;
541 id1 = 0;
542 } else {
543 flags = NFLAGS_NAME_MATCH;
544 noiu.name = cp;
545 id1 = 0;
546 }
547
548 if (usernames) {
549 uid_t uid;
550 if (user_to_uid(colon+1, &uid, True))
551 add_to_list(idmap_ptr, id1, noiu, uid, flags);
552 else {
553 rprintf(FERROR, "Unknown --usermap name on receiver: %s\n", colon+1);
554 }

Callers 1

recv_file_listFunction · 0.85

Calls 8

isDigitFunction · 0.85
id_parseFunction · 0.85
strpbrkFunction · 0.85
user_to_uidFunction · 0.85
add_to_listFunction · 0.85
group_to_gidFunction · 0.85
recv_add_idFunction · 0.85
rprintfFunction · 0.70

Tested by

no test coverage detected