1 --- Makefile.in 10 Feb 2004 17:06:11 -0000 1.98
2 +++ Makefile.in 22 Apr 2004 23:39:42 -0000
3 @@ -34,7 +34,7 @@ ZLIBOBJ=zlib/deflate.o zlib/infblock.o z
4 OBJS1=rsync.o generator.o receiver.o cleanup.o sender.o exclude.o util.o \
5 main.o checksum.o match.o syscall.o log.o backup.o
6 OBJS2=options.o flist.o io.o compat.o hlink.o token.o uidlist.o socket.o \
7 - fileio.o batch.o clientname.o
8 + fileio.o batch.o clientname.o chmod.o
9 OBJS3=progress.o pipe.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 --- /dev/null 1 Jan 1970 00:00:00 -0000
13 +++ chmod.c 22 Apr 2004 23:39:43 -0000
17 +#define FLAG_X_KEEP (1<<0)
18 +#define FLAG_DIRS_ONLY (1<<1)
19 +#define FLAG_FILES_ONLY (1<<2)
21 +struct chmod_mode_struct {
22 + struct chmod_mode_struct *next;
23 + int ModeAND, ModeOR;
31 +#define STATE_ERROR 0
32 +#define STATE_1ST_HALF 1
33 +#define STATE_2ND_HALF 2
35 +/* Parse a chmod-style argument, and break it down into one or more AND/OR
36 + * pairs in a linked list. We use a state machine to walk through the
38 +struct chmod_mode_struct *parse_chmod(char *modestr)
40 + int state = STATE_1ST_HALF;
41 + int where = 0, what = 0, op = 0, topbits = 0, topoct = 0, flags = 0;
42 + struct chmod_mode_struct *first_mode = NULL, *curr_mode = NULL,
45 + while (state != STATE_ERROR) {
46 + if (!*modestr || *modestr == ',') {
48 + state = STATE_ERROR;
51 + prev_mode = curr_mode;
52 + curr_mode = new_array(struct chmod_mode_struct, 1);
54 + prev_mode->next = curr_mode;
56 + first_mode = curr_mode;
57 + curr_mode->next = NULL;
61 + curr_mode->ModeAND = 07777;
62 + curr_mode->ModeOR = (where * what) + topoct;
65 + curr_mode->ModeAND = 07777 - (where * what) - topoct;
66 + curr_mode->ModeOR = 0;
69 + curr_mode->ModeAND = 07777 - (where * 7);
70 + curr_mode->ModeOR = where * what - topoct;
74 + curr_mode->flags = flags;
80 + state = STATE_1ST_HALF;
81 + where = what = op = topoct = topbits = flags = 0;
84 + if (state != STATE_2ND_HALF) {
87 + if (flags & FLAG_FILES_ONLY)
88 + state = STATE_ERROR;
89 + flags |= FLAG_DIRS_ONLY;
92 + if (flags & FLAG_DIRS_ONLY)
93 + state = STATE_ERROR;
94 + flags |= FLAG_FILES_ONLY;
112 + state = STATE_2ND_HALF;
116 + state = STATE_2ND_HALF;
120 + state = STATE_2ND_HALF;
123 + state = STATE_ERROR;
127 + switch (*modestr) {
135 + flags |= FLAG_X_KEEP;
150 + state = STATE_ERROR;
157 + if (state == STATE_ERROR) {
158 + free_chmod_mode(first_mode);
165 +/* Takes an existing file permission and a list of AND/OR changes, and
166 + * create a new permissions. */
167 +int tweak_mode(int mode, struct chmod_mode_struct *chmod_modes)
169 + int IsX = mode & 0111;
170 + int NonPerm = mode & ~07777;
172 + for ( ; chmod_modes; chmod_modes = chmod_modes->next) {
173 + if ((chmod_modes->flags & FLAG_DIRS_ONLY) && !S_ISDIR(NonPerm))
175 + if ((chmod_modes->flags & FLAG_FILES_ONLY) && S_ISDIR(NonPerm))
177 + mode &= chmod_modes->ModeAND;
178 + if ((chmod_modes->flags & FLAG_X_KEEP) && !IsX && !S_ISDIR(NonPerm))
179 + mode |= chmod_modes->ModeOR & ~0111;
181 + mode |= chmod_modes->ModeOR;
184 + return mode | NonPerm;
187 +/* Free the linked list created by parse_chmod. */
188 +int free_chmod_mode(struct chmod_mode_struct *chmod_modes)
190 + struct chmod_mode_struct *next;
192 + while (chmod_modes) {
193 + next = chmod_modes->next;
195 + chmod_modes = next;
199 --- flist.c 22 Apr 2004 22:17:15 -0000 1.216
200 +++ flist.c 22 Apr 2004 23:39:43 -0000
201 @@ -33,6 +33,7 @@ extern int verbose;
202 extern int do_progress;
204 extern int am_server;
205 +extern int am_sender;
206 extern int am_daemon;
207 extern int always_checksum;
208 extern int module_id;
209 @@ -64,6 +65,8 @@ extern int sanitize_paths;
210 extern int read_batch;
211 extern int write_batch;
213 +extern struct chmod_mode_struct *chmod_modes;
215 extern struct exclude_list_struct exclude_list;
216 extern struct exclude_list_struct server_exclude_list;
217 extern struct exclude_list_struct local_exclude_list;
218 @@ -853,7 +856,10 @@ skip_excludes:
220 file->modtime = st.st_mtime;
221 file->length = st.st_size;
222 - file->mode = st.st_mode;
223 + if (chmod_modes && am_sender && (S_ISREG(st.st_mode) || S_ISDIR(st.st_mode)))
224 + file->mode = tweak_mode(st.st_mode, chmod_modes);
226 + file->mode = st.st_mode;
227 file->uid = st.st_uid;
228 file->gid = st.st_gid;
230 --- options.c 17 Apr 2004 17:07:23 -0000 1.147
231 +++ options.c 22 Apr 2004 23:39:43 -0000
232 @@ -121,6 +121,7 @@ char *log_format = NULL;
233 char *password_file = NULL;
234 char *rsync_path = RSYNC_PATH;
235 char *backup_dir = NULL;
236 +char *chmod_mode = NULL;
237 char backup_dir_buf[MAXPATHLEN];
238 int rsync_port = RSYNC_PORT;
240 @@ -134,6 +135,8 @@ int list_only = 0;
241 #define MAX_BATCH_PREFIX_LEN 256 /* Must be less than MAXPATHLEN-13 */
242 char *batch_prefix = NULL;
244 +struct chmod_mode_struct *chmod_modes = NULL;
246 static int daemon_opt; /* sets am_daemon after option error-reporting */
247 static int modify_window_set;
249 @@ -241,6 +244,7 @@ void usage(enum logcode F)
250 rprintf(F," -g, --group preserve group\n");
251 rprintf(F," -D, --devices preserve devices (root only)\n");
252 rprintf(F," -t, --times preserve times\n");
253 + rprintf(F," --chmod=CHMOD change destination permissions\n");
254 rprintf(F," -S, --sparse handle sparse files efficiently\n");
255 rprintf(F," -n, --dry-run show what would have been transferred\n");
256 rprintf(F," -W, --whole-file copy whole files, no incremental checks\n");
257 @@ -344,6 +348,7 @@ static struct poptOption long_options[]
258 {"perms", 'p', POPT_ARG_NONE, &preserve_perms, 0, 0, 0 },
259 {"owner", 'o', POPT_ARG_NONE, &preserve_uid, 0, 0, 0 },
260 {"group", 'g', POPT_ARG_NONE, &preserve_gid, 0, 0, 0 },
261 + {"chmod", 0, POPT_ARG_STRING, &chmod_mode, 0, 0, 0 },
262 {"devices", 'D', POPT_ARG_NONE, &preserve_devices, 0, 0, 0 },
263 {"times", 't', POPT_ARG_NONE, &preserve_times, 0, 0, 0 },
264 {"checksum", 'c', POPT_ARG_NONE, &always_checksum, 0, 0, 0 },
265 @@ -720,6 +725,13 @@ int parse_arguments(int *argc, const cha
266 exit_cleanup(RERR_SYNTAX);
269 + if (chmod_mode && !(chmod_modes = parse_chmod(chmod_mode))) {
270 + snprintf(err_buf, sizeof err_buf,
271 + "Invalid argument passed to chmod\n");
272 + rprintf(FERROR, "ERROR: %s", err_buf);
276 if (do_progress && !verbose)
279 @@ -951,6 +963,11 @@ void server_options(char **args,int *arg
281 args[ac++] = link_dest ? "--link-dest" : "--compare-dest";
282 args[ac++] = compare_dest;
285 + if (chmod_mode && !am_sender) {
286 + args[ac++] = "--chmod";
287 + args[ac++] = chmod_mode;
290 if (files_from && (!am_sender || remote_filesfrom_file)) {
291 --- proto.h 22 Apr 2004 09:58:09 -0000 1.189
292 +++ proto.h 22 Apr 2004 23:39:43 -0000
293 @@ -25,6 +25,9 @@ void file_checksum(char *fname,char *sum
295 void sum_update(char *p, int len);
296 void sum_end(char *sum);
297 +struct chmod_mode_struct *parse_chmod(char *modestr);
298 +int tweak_mode(int mode, struct chmod_mode_struct *chmod_modes);
299 +int free_chmod_mode(struct chmod_mode_struct *chmod_modes);
300 void close_all(void);
301 void _exit_cleanup(int code, const char *file, int line);
302 void cleanup_disable(void);
303 --- rsync.yo 22 Apr 2004 21:35:45 -0000 1.161
304 +++ rsync.yo 22 Apr 2004 23:39:44 -0000
305 @@ -299,6 +299,7 @@ verb(
306 -g, --group preserve group
307 -D, --devices preserve devices (root only)
308 -t, --times preserve times
309 + --chmod=CHMOD change destination permissions
310 -S, --sparse handle sparse files efficiently
311 -n, --dry-run show what would have been transferred
312 -W, --whole-file copy whole files, no incremental checks
313 @@ -536,6 +537,14 @@ modified cannot be effective; in other w
314 cause the next transfer to behave as if it used -I, and all files will have
315 their checksums compared and show up in log messages even if they haven't
318 +dit(bf(--chmod)) This options tells rsync to apply the listed "chmod" pattern
319 +to the permission of the files on the destination. In addition to the normal
320 +parsing rules specified in the chmod manpage, you can specify an item that
321 +should only apply to a directory by prefixing it with a 'D', or specify an
322 +item that should only apply to a file by prefixing it with a 'F'. For example:
324 +quote(--chmod=Dg+s,ug+w,Fo-w,+X)
326 dit(bf(-n, --dry-run)) This tells rsync to not do any file transfers,
327 instead it will just report the actions it would have taken.
328 --- /dev/null 1 Jan 1970 00:00:00 -0000
329 +++ testsuite/chmod.test 22 Apr 2004 23:39:44 -0000
333 +# Copyright (C) 2002 by Martin Pool <mbp@samba.org>
335 +# This program is distributable under the terms of the GNU GPL (see
338 +# Test that the --chmod option functions correctly.
340 +. $srcdir/testsuite/rsync.fns
346 +fromdir="$scratchdir/from"
347 +todir="$scratchdir/to"
348 +checkdir="$scratchdir/check"
351 +name1="$fromdir/name1"
352 +name2="$fromdir/name2"
353 +dir1="$fromdir/dir1"
354 +dir2="$fromdir/dir2"
355 +echo "This is the file" > "$name1"
356 +echo "This is the other file" > "$name2"
357 +mkdir "$dir1" "$dir2"
359 +chmod 4700 "$name1" || test_skipped "Can't chmod"
363 +# Copy the files we've created over to another directory
364 +checkit "$RSYNC -avv \"$fromdir/\" \"$checkdir/\"" "$fromdir" "$checkdir"
366 +# And then manually make the changes which should occur
367 +chmod ug-s,a+rX "$checkdir"/*
368 +chmod g+w "$checkdir" "$checkdir"/dir*
370 +checkit "$RSYNC -avv --chmod ug-s,a+rX,Dg+w \"$fromdir/\" \"$todir/\"" "$checkdir" "$todir"
372 +# The script would have aborted on error, so getting here means we've won.