@@ -33,6 +33,7 @@ extern int preserve_uid;
33
33
extern int preserve_gid ;
34
34
extern int preserve_acls ;
35
35
extern int numeric_ids ;
36
+ extern int xmit_id0_names ;
36
37
extern gid_t our_gid ;
37
38
extern char * usermap ;
38
39
extern char * groupmap ;
@@ -295,9 +296,6 @@ const char *add_uid(uid_t uid)
295
296
struct idlist * node ;
296
297
union name_or_id noiu ;
297
298
298
- if (uid == 0 ) /* don't map root */
299
- return NULL ;
300
-
301
299
for (list = uidlist ; list ; list = list -> next ) {
302
300
if (list -> id == uid )
303
301
return NULL ;
@@ -315,9 +313,6 @@ const char *add_gid(gid_t gid)
315
313
struct idlist * node ;
316
314
union name_or_id noiu ;
317
315
318
- if (gid == 0 ) /* don't map root */
319
- return NULL ;
320
-
321
316
for (list = gidlist ; list ; list = list -> next ) {
322
317
if (list -> id == gid )
323
318
return NULL ;
@@ -328,40 +323,43 @@ const char *add_gid(gid_t gid)
328
323
return node -> u .name ;
329
324
}
330
325
331
- /* send a complete uid/gid mapping to the peer */
332
- void send_id_list (int f )
326
+ static void send_one_name (int f , id_t id , const char * name )
333
327
{
334
- struct idlist * list ;
328
+ int len = strlen (name );
329
+ if (len > 255 ) /* Impossible? */
330
+ len = 255 ;
335
331
336
- if (preserve_uid || preserve_acls ) {
337
- int len ;
338
- /* we send sequences of uid/byte-length/name */
339
- for (list = uidlist ; list ; list = list -> next ) {
340
- if (!list -> u .name )
341
- continue ;
342
- len = strlen (list -> u .name );
343
- write_varint30 (f , list -> id );
344
- write_byte (f , len );
345
- write_buf (f , list -> u .name , len );
346
- }
332
+ write_varint30 (f , id );
333
+ write_byte (f , len );
334
+ write_buf (f , name , len );
335
+ }
347
336
348
- /* terminate the uid list with a 0 uid. We explicitly exclude
349
- * 0 from the list */
350
- write_varint30 (f , 0 );
337
+ static void send_one_list (int f , struct idlist * idlist , int usernames )
338
+ {
339
+ struct idlist * list ;
340
+
341
+ /* we send sequences of id/byte-len/name */
342
+ for (list = idlist ; list ; list = list -> next ) {
343
+ if (list -> id && list -> u .name )
344
+ send_one_name (f , list -> id , list -> u .name );
351
345
}
352
346
353
- if (preserve_gid || preserve_acls ) {
354
- int len ;
355
- for (list = gidlist ; list ; list = list -> next ) {
356
- if (!list -> u .name )
357
- continue ;
358
- len = strlen (list -> u .name );
359
- write_varint30 (f , list -> id );
360
- write_byte (f , len );
361
- write_buf (f , list -> u .name , len );
362
- }
347
+ /* Terminate the uid list with 0 (which was excluded above).
348
+ * A modern rsync also sends the name of id 0. */
349
+ if (xmit_id0_names )
350
+ send_one_name (f , 0 , usernames ? uid_to_user (0 ) : gid_to_group (0 ));
351
+ else
363
352
write_varint30 (f , 0 );
364
- }
353
+ }
354
+
355
+ /* send a complete uid/gid mapping to the peer */
356
+ void send_id_lists (int f )
357
+ {
358
+ if (preserve_uid || preserve_acls )
359
+ send_one_list (f , uidlist , 1 );
360
+
361
+ if (preserve_gid || preserve_acls )
362
+ send_one_list (f , gidlist , 0 );
365
363
}
366
364
367
365
uid_t recv_user_name (int f , uid_t uid )
@@ -405,12 +403,16 @@ void recv_id_list(int f, struct file_list *flist)
405
403
/* read the uid list */
406
404
while ((id = read_varint30 (f )) != 0 )
407
405
recv_user_name (f , id );
406
+ if (xmit_id0_names )
407
+ recv_user_name (f , 0 );
408
408
}
409
409
410
410
if ((preserve_gid || preserve_acls ) && numeric_ids <= 0 ) {
411
411
/* read the gid list */
412
412
while ((id = read_varint30 (f )) != 0 )
413
413
recv_group_name (f , id , NULL );
414
+ if (xmit_id0_names )
415
+ recv_group_name (f , 0 , NULL );
414
416
}
415
417
416
418
/* Now convert all the uids/gids from sender values to our values. */
@@ -502,8 +504,9 @@ void parse_name_map(char *map, BOOL usernames)
502
504
* -- cp = '\0' ; /* replace comma */
503
505
}
504
506
505
- /* The 0 user/group doesn't get its name sent, so add it explicitly. */
506
- recv_add_id (idlist_ptr , * idmap_ptr , 0 , numeric_ids ? NULL : usernames ? uid_to_user (0 ) : gid_to_group (0 ));
507
+ /* If the sender isn't going to xmit the id0 name, we assume it's "root". */
508
+ if (!xmit_id0_names )
509
+ recv_add_id (idlist_ptr , * idmap_ptr , 0 , numeric_ids ? NULL : "root" );
507
510
}
508
511
509
512
#ifdef HAVE_GETGROUPLIST
0 commit comments