1 diff --unified -r --new-file rsync-2.5.5.orig/Makefile.in rsync-2.5.5/Makefile.in
2 --- rsync-2.5.5.orig/Makefile.in Mon Mar 25 15:36:56 2002
3 +++ rsync-2.5.5/Makefile.in Wed Apr 3 21:45:22 2002
5 zlib/zutil.o zlib/adler32.o
6 OBJS1=rsync.o generator.o receiver.o cleanup.o sender.o exclude.o util.o main.o checksum.o match.o syscall.o log.o backup.o
7 OBJS2=options.o flist.o io.o compat.o hlink.o token.o uidlist.o socket.o fileio.o batch.o \
10 DAEMON_OBJ = params.o loadparm.o clientserver.o access.o connection.o authenticate.o
11 popt_OBJS=popt/findme.o popt/popt.o popt/poptconfig.o \
12 popt/popthelp.o popt/poptparse.o
13 diff --unified -r --new-file rsync-2.5.5.orig/chmod.c rsync-2.5.5/chmod.c
14 --- rsync-2.5.5.orig/chmod.c Thu Jan 1 10:00:00 1970
15 +++ rsync-2.5.5/chmod.c Wed Apr 3 22:56:30 2002
19 +struct chmod_mode_struct {
23 + struct chmod_mode_struct *next;
30 +/* Parse a chmod-style argument, and break it down into one or more AND/OR
31 + pairs in a linked list.
32 + We use a state machine to walk through the options - states 1 and 3
33 + before/including the operation (+, - or =), state 2 after the operation and
34 + state 4 if we hit an error.
36 +struct chmod_mode_struct *parse_chmod (char *modestr)
39 + int where = 0, what = 0, op = 0, topbits = 0, topoct = 0, Xkeep=0;
40 + struct chmod_mode_struct *first_mode = NULL, *curr_mode = NULL, *prev_mode = NULL;
45 + case 'u' : where |= 0100; topbits |= 04000; break;
46 + case 'g' : where |= 0010; topbits |= 02000; break;
47 + case 'o' : where |= 0001; break;
48 + case 'a' : where |= 0111; break;
49 + case '+' : op = CHMOD_ADD; state=2; break;
50 + case '-' : op = CHMOD_SUB; state=2; break;
51 + case '=' : op = CHMOD_EQ; state=2; break;
53 + default : state=4; /* Invalid Mode! */
55 + } else if (state==2) {
57 + case 'r' : what |= 4; break;
58 + case 'w' : what |= 2; break;
59 + case 'X' : Xkeep = 1;
60 + case 'x' : what |= 1; break;
61 + case 's' : if (topbits) {
67 + case 't' : topoct |= 01000; break;
68 + default : state=4; /* Invalid Mode! */
77 + if (!*modestr || *modestr == ',') {
78 + prev_mode = curr_mode;
79 + curr_mode = malloc(sizeof(struct chmod_mode_struct));
81 + prev_mode->next = curr_mode;
83 + first_mode = curr_mode;
85 + curr_mode->next = NULL;
89 + curr_mode->ModeAND = 07777;
90 + curr_mode->ModeOR = (where * what) + topoct;
93 + curr_mode->ModeAND = 07777 - (where * what) - topoct;
94 + curr_mode->ModeOR = 0;
97 + curr_mode->ModeAND = 07777 - (where * 7);
98 + curr_mode->ModeOR = where * what - topoct;
102 + curr_mode->Xkeep = Xkeep;
105 + where = what = topoct = topbits = Xkeep = 0;
110 + free_chmod_mode(first_mode);
117 +/* Takes an existing file permission and a list of AND/OR changes, and create a
120 +int newmode (int oldmode, struct chmod_mode_struct *chmod_modes)
122 + int IsX = (oldmode & 0111);
123 + int NonPerm = oldmode - (oldmode & 07777);
125 + while (chmod_modes) {
126 + oldmode &= chmod_modes->ModeAND;
127 + if (chmod_modes->Xkeep && !IsX) {
128 + oldmode |= chmod_modes->ModeOR & (07777 - 0111);
130 + oldmode |= chmod_modes->ModeOR;
132 + chmod_modes = chmod_modes->next;
135 + return (oldmode + NonPerm);
138 +/* Free the linked list created by parse_chmod
140 +int free_chmod_mode (struct chmod_mode_struct *chmod_modes)
142 + struct chmod_mode_struct *next;
144 + while (chmod_modes) {
145 + next = chmod_modes->next;
147 + chmod_modes = next;
151 diff --unified -r --new-file rsync-2.5.5.orig/flist.c rsync-2.5.5/flist.c
152 --- rsync-2.5.5.orig/flist.c Fri Mar 15 08:20:20 2002
153 +++ rsync-2.5.5/flist.c Wed Apr 3 21:54:42 2002
156 extern int do_progress;
157 extern int am_server;
158 +extern int am_sender;
159 extern int always_checksum;
161 extern int cvs_exclude;
163 extern int read_batch;
164 extern int write_batch;
166 +extern struct chmod_mode_struct *chmod_modes;
168 static char topsrcname[MAXPATHLEN];
170 static struct exclude_struct **local_exclude_list;
172 #ifdef HAVE_STRUCT_STAT_ST_RDEV
173 file->rdev = st.st_rdev;
176 + if (am_sender && chmod_modes && S_ISREG(st.st_mode)) {
177 + file->mode = newmode(file->mode, chmod_modes);
181 if (S_ISLNK(st.st_mode)) {
182 diff --unified -r --new-file rsync-2.5.5.orig/options.c rsync-2.5.5/options.c
183 --- rsync-2.5.5.orig/options.c Wed Mar 20 07:16:42 2002
184 +++ rsync-2.5.5/options.c Wed Apr 3 22:24:46 2002
186 char *password_file = NULL;
187 char *rsync_path = RSYNC_PATH;
188 char *backup_dir = NULL;
189 +char *chmod_mode = NULL;
190 int rsync_port = RSYNC_PORT;
194 * address, or a hostname. **/
197 +struct chmod_mode_struct *chmod_modes = NULL;
199 static void print_rsync_version(enum logcode f)
202 rprintf(F," -g, --group preserve group\n");
203 rprintf(F," -D, --devices preserve devices (root only)\n");
204 rprintf(F," -t, --times preserve times\n");
205 + rprintf(F," --chmod=CHMOD change destination permissions\n");
206 rprintf(F," -S, --sparse handle sparse files efficiently\n");
207 rprintf(F," -n, --dry-run show what would have been transferred\n");
208 rprintf(F," -W, --whole-file copy whole files, no incremental checks\n");
210 OPT_COPY_UNSAFE_LINKS, OPT_SAFE_LINKS, OPT_COMPARE_DEST,
211 OPT_LOG_FORMAT, OPT_PASSWORD_FILE, OPT_SIZE_ONLY, OPT_ADDRESS,
212 OPT_DELETE_AFTER, OPT_EXISTING, OPT_MAX_DELETE, OPT_BACKUP_DIR,
213 - OPT_IGNORE_ERRORS, OPT_BWLIMIT, OPT_BLOCKING_IO,
214 + OPT_IGNORE_ERRORS, OPT_BWLIMIT, OPT_BLOCKING_IO, OPT_CHMOD,
215 OPT_NO_BLOCKING_IO, OPT_WHOLE_FILE, OPT_NO_WHOLE_FILE,
216 OPT_MODIFY_WINDOW, OPT_READ_BATCH, OPT_WRITE_BATCH, OPT_IGNORE_EXISTING};
219 {"perms", 'p', POPT_ARG_NONE, &preserve_perms , 0, 0, 0 },
220 {"owner", 'o', POPT_ARG_NONE, &preserve_uid , 0, 0, 0 },
221 {"group", 'g', POPT_ARG_NONE, &preserve_gid , 0, 0, 0 },
222 + {"chmod", 0, POPT_ARG_STRING, &chmod_mode, OPT_CHMOD, 0, 0 },
223 {"devices", 'D', POPT_ARG_NONE, &preserve_devices , 0, 0, 0 },
224 {"times", 't', POPT_ARG_NONE, &preserve_times , 0, 0, 0 },
225 {"checksum", 'c', POPT_ARG_NONE, &always_checksum , 0, 0, 0 },
231 + chmod_modes = parse_chmod(chmod_mode);
232 + if (!chmod_modes) {
233 + snprintf(err_buf,sizeof(err_buf),
234 + "Invalud argument passed to chmod\n");
235 + rprintf(FERROR,"ERROR: Invalid argument passed to chmod\n");
240 /* FIXME: If --daemon is specified, then errors for later
241 * parameters seem to disappear. */
244 args[ac++] = "--compare-dest";
245 args[ac++] = compare_dest;
248 + if (chmod_mode && !am_sender) {
249 + args[ac++] = "--chmod";
250 + args[ac++] = chmod_mode;
254 diff --unified -r --new-file rsync-2.5.5.orig/proto.h rsync-2.5.5/proto.h
255 --- rsync-2.5.5.orig/proto.h Mon Mar 25 14:51:17 2002
256 +++ rsync-2.5.5/proto.h Wed Apr 3 21:51:32 2002
259 void sum_update(char *p,int len);
260 void sum_end(char *sum);
261 +struct chmod_mode_struct *parse_chmod (char *modestr);
262 +int newmode (int oldmode, struct chmod_mode_struct *chmod_modes);
263 +int free_chmod_mode (struct chmod_mode_struct *chmod_modes);
264 void _exit_cleanup(int code, const char *file, int line);
265 void cleanup_disable(void);
266 void cleanup_set(char *fnametmp, char *fname, struct file_struct *file,
267 diff --unified -r --new-file rsync-2.5.5.orig/rsync.yo rsync-2.5.5/rsync.yo
268 --- rsync-2.5.5.orig/rsync.yo Thu Feb 7 08:20:49 2002
269 +++ rsync-2.5.5/rsync.yo Wed Apr 3 23:32:30 2002
271 -g, --group preserve group
272 -D, --devices preserve devices (root only)
273 -t, --times preserve times
274 + --chmod=CHMOD change destination permissions
275 -S, --sparse handle sparse files efficiently
276 -n, --dry-run show what would have been transferred
277 -W, --whole-file copy whole files, no incremental checks
279 cause the next transfer to behave as if it used -I, and all files will have
280 their checksums compared and show up in log messages even if they haven't
283 +dit(bf(--chmod)) This options tells rsync to apply the listed "chmod" pattern
284 +to the permission of the files on the destination.
286 dit(bf(-n, --dry-run)) This tells rsync to not do any file transfers,
287 instead it will just report the actions it would have taken.
288 diff --unified -r --new-file rsync-2.5.5.orig/testsuite/chmod.test rsync-2.5.5/testsuite/chmod.test
289 --- rsync-2.5.5.orig/testsuite/chmod.test Thu Jan 1 10:00:00 1970
290 +++ rsync-2.5.5/testsuite/chmod.test Wed Apr 3 23:23:36 2002
294 +# Copyright (C) 2002 by Martin Pool <mbp@samba.org>
296 +# This program is distributable under the terms of the GNU GPL (see
299 +# Test that the --chmod option functions correctly.
301 +. $srcdir/testsuite/rsync.fns
307 +fromdir="$scratchdir/from"
308 +todir="$scratchdir/to"
309 +checkdir="$scratchdir/check"
312 +name1="$fromdir/name1"
313 +name2="$fromdir/name2"
314 +echo "This is the file" > "$name1"
315 +echo "This is the other file" > "$name2"
317 +chmod 4700 "$name1" || test_skipped "Can't chown"
319 +# Copy the files we've created over to another directory
320 +checkit "rsync -avv \"$fromdir/\" \"$checkdir/\"" "$fromdir" "$checkdir"
322 +# And then manually make the changes which should occur
323 +chmod ug-s,a+rX $checkdir/*
325 +checkit "rsync -avv --chmod ug-s,a+rX \"$fromdir/\" \"$todir/\"" "$checkdir" "$todir"
328 +# last [] may have failed but if we get here then we've won