Rsync "sync then chown/chgrp" feature
Doug
doug at sneakyfrog.com
Thu Oct 11 12:51:58 EST 2001
the attached patch adds the "synchronize these files and then chown/chgrp
them to a specified user/group, no matter who owns the originals" feature.
the relevant usage lines are now:
-o, --owner preserve owner (root only)
-o, --owner=OWNER specify owner (root only)
-g, --group preserve group
-g, --group=GROUP specify group
with this patch, the feature works locally but not remotely.
in options.c:server_options(), i've added code to pass args on to the
server, but i don't think i'm doing it correctly. if anyone would
be willing to take a look and see what they think is happening, i'd
be grateful. other comments/nitpicks also welcome.
i've attached the output of 'diff -c origsrcdir mysrcdir'. thanks for
any help.
-- doug
-------------- next part --------------
diff -c orig/rsync-2.4.6/options.c rsync-2.4.6/options.c
*** orig/rsync-2.4.6/options.c Tue Sep 5 19:46:43 2000
--- rsync-2.4.6/options.c Tue Oct 9 18:38:16 2001
***************
*** 83,88 ****
--- 84,91 ----
char *password_file = NULL;
char *rsync_path = RSYNC_NAME;
char *backup_dir = NULL;
+ char *set_username = NULL;
+ char *set_groupname = NULL;
int rsync_port = RSYNC_PORT;
int verbose = 0;
***************
*** 129,135 ****
--- 132,140 ----
rprintf(F," -H, --hard-links preserve hard links\n");
rprintf(F," -p, --perms preserve permissions\n");
rprintf(F," -o, --owner preserve owner (root only)\n");
+ rprintf(F," -o, --owner=OWNER specify owner (root only)\n");
rprintf(F," -g, --group preserve group\n");
+ rprintf(F," -g, --group=GROUP specify group\n");
rprintf(F," -D, --devices preserve devices (root only)\n");
rprintf(F," -t, --times preserve times\n");
rprintf(F," -S, --sparse handle sparse files efficiently\n");
***************
*** 231,238 ****
{"safe-links", 0, 0, OPT_SAFE_LINKS},
{"whole-file", 0, 0, 'W'},
{"hard-links", 0, 0, 'H'},
! {"owner", 0, 0, 'o'},
! {"group", 0, 0, 'g'},
{"times", 0, 0, 't'},
{"rsh", 1, 0, 'e'},
{"suffix", 1, 0, OPT_SUFFIX},
--- 236,243 ----
{"safe-links", 0, 0, OPT_SAFE_LINKS},
{"whole-file", 0, 0, 'W'},
{"hard-links", 0, 0, 'H'},
! {"owner", 2, 0, 'o'},
! {"group", 2, 0, 'g'},
{"times", 0, 0, 't'},
{"rsh", 1, 0, 'e'},
{"suffix", 1, 0, OPT_SUFFIX},
***************
*** 451,461 ****
break;
case 'o':
! preserve_uid=1;
break;
case 'g':
! preserve_gid=1;
break;
case 'D':
--- 457,473 ----
break;
case 'o':
! if (optarg == 0)
! preserve_uid=1;
! else
! set_username = optarg;
break;
case 'g':
! if (optarg == 0)
! preserve_gid=1;
! else
! set_groupname = optarg;
break;
case 'D':
***************
*** 681,686 ****
--- 697,712 ----
argstr[x] = 0;
if (x != 1) args[ac++] = argstr;
+
+ if (set_username) {
+ args[ac++] = "--owner";
+ args[ac++] = set_username;
+ }
+
+ if (set_groupname) {
+ args[ac++] = "--group";
+ args[ac++] = set_groupname;
+ }
if (block_size != BLOCK_SIZE) {
slprintf(bsize,sizeof(bsize),"-B%d",block_size);
diff -c orig/rsync-2.4.6/rsync.c rsync-2.4.6/rsync.c
*** orig/rsync-2.4.6/rsync.c Tue Sep 5 19:46:43 2000
--- rsync-2.4.6/rsync.c Sun Oct 7 19:39:17 2001
***************
*** 27,33 ****
--- 27,35 ----
extern int preserve_times;
extern int am_root;
extern int preserve_uid;
+ extern char *set_username;
extern int preserve_gid;
+ extern char *set_groupname;
extern int preserve_perms;
extern int make_backups;
***************
*** 175,183 ****
}
}
! change_uid = am_root && preserve_uid && st->st_uid != file->uid;
! change_gid = preserve_gid && file->gid != (gid_t) -1 && \
! st->st_gid != file->gid;
if (change_gid && !am_root) {
/* enforce bsd-style group semantics: non-root can only
change to groups that the user is a member of */
--- 177,206 ----
}
}
! if (am_root) {
! if (preserve_uid || set_username) {
! if (set_username) {
! if (0 == name_to_uid(set_username, &file->uid)) {
! rprintf(FERROR, "couldn't look up uid for %s\n", set_username);
! return 0;
! }
! }
! change_uid = st->st_uid != file->uid;
! }
! }
! else change_uid = 0;
!
! if (preserve_gid || set_groupname) {
! if (set_groupname) {
! if (0 == name_to_gid(set_groupname, &file->gid)) {
! rprintf(FERROR, "couldn't look up gid for %s\n", set_groupname);
! return 0;
! }
! }
! change_gid = file->gid != (gid_t) -1 && st->st_gid != file->gid;
! }
! else change_gid = 0;
!
if (change_gid && !am_root) {
/* enforce bsd-style group semantics: non-root can only
change to groups that the user is a member of */
More information about the rsync
mailing list