Commit | Line | Data |
---|---|---|
0f78b815 WD |
1 | /* |
2 | * Command-line (and received via daemon-socket) option parsing. | |
dfa32483 | 3 | * |
0f78b815 WD |
4 | * Copyright (C) 1998-2001 Andrew Tridgell <tridge@samba.org> |
5 | * Copyright (C) 2000, 2001, 2002 Martin Pool <mbp@samba.org> | |
ba2133d6 | 6 | * Copyright (C) 2002-2007 Wayne Davison |
dfa32483 | 7 | * |
dafe63ca | 8 | * This program is free software; you can redistribute it and/or modify |
8e41b68e WD |
9 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation; either version 3 of the License, or | |
11 | * (at your option) any later version. | |
dfa32483 | 12 | * |
dafe63ca MP |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
dfa32483 | 17 | * |
e7c67065 | 18 | * You should have received a copy of the GNU General Public License along |
4fd842f9 | 19 | * with this program; if not, visit the http://fsf.org website. |
dafe63ca | 20 | */ |
7a6421fa | 21 | |
7a6421fa | 22 | #include "rsync.h" |
1b42f628 | 23 | #include "ifuncs.h" |
35bf8fa0 | 24 | #include <popt.h> |
854a1aad | 25 | #include "zlib/zlib.h" |
7a6421fa | 26 | |
7bc90b30 | 27 | extern int module_id; |
7be73df4 | 28 | extern int sanitize_paths; |
e208631a | 29 | extern int daemon_over_rsh; |
a1018691 | 30 | extern unsigned int module_dirlen; |
7842418b WD |
31 | extern struct filter_list_struct filter_list; |
32 | extern struct filter_list_struct server_filter_list; | |
8645af1d | 33 | |
7a6421fa | 34 | int make_backups = 0; |
1bfbf40b MP |
35 | |
36 | /** | |
dfa32483 | 37 | * If 1, send the whole file as literal data rather than trying to |
dafe63ca | 38 | * create an incremental diff. |
1bfbf40b | 39 | * |
dfa32483 | 40 | * If -1, then look at whether we're local or remote and go by that. |
dafe63ca MP |
41 | * |
42 | * @sa disable_deltas_p() | |
1bfbf40b | 43 | **/ |
dfa32483 | 44 | int whole_file = -1; |
1bfbf40b | 45 | |
a015788d | 46 | int append_mode = 0; |
716e73d4 | 47 | int keep_dirlinks = 0; |
2dbf36ef | 48 | int copy_dirlinks = 0; |
7a6421fa AT |
49 | int copy_links = 0; |
50 | int preserve_links = 0; | |
51 | int preserve_hard_links = 0; | |
1c3344a1 | 52 | int preserve_acls = 0; |
16edf865 | 53 | int preserve_xattrs = 0; |
7a6421fa | 54 | int preserve_perms = 0; |
344f9ba7 | 55 | int preserve_executability = 0; |
7a6421fa | 56 | int preserve_devices = 0; |
b5c6a6ae | 57 | int preserve_specials = 0; |
7a6421fa AT |
58 | int preserve_uid = 0; |
59 | int preserve_gid = 0; | |
60 | int preserve_times = 0; | |
61 | int update_only = 0; | |
62 | int cvs_exclude = 0; | |
a5c11139 | 63 | int dry_run = 0; |
11e758a4 | 64 | int do_xfers = 1; |
a5c11139 WD |
65 | int ignore_times = 0; |
66 | int delete_mode = 0; | |
a51b3168 | 67 | int delete_during = 0; |
51d48398 WD |
68 | int delete_before = 0; |
69 | int delete_after = 0; | |
a5c11139 | 70 | int delete_excluded = 0; |
47c11975 | 71 | int remove_source_files = 0; |
a5c11139 | 72 | int one_file_system = 0; |
4f3e9a0f | 73 | int protocol_version = PROTOCOL_VERSION; |
a5c11139 WD |
74 | int sparse_files = 0; |
75 | int do_compression = 0; | |
854a1aad | 76 | int def_compress_level = Z_DEFAULT_COMPRESSION; |
9439c0cb | 77 | int am_root = 0; /* 0 = normal, 1 = root, 2 = --super, -1 = --fake-super */ |
7f2a1f65 WD |
78 | int am_server = 0; |
79 | int am_sender = 0; | |
80 | int am_generator = 0; | |
81 | int am_starting_up = 1; | |
ea5164d1 WD |
82 | int relative_paths = -1; |
83 | int implied_dirs = 1; | |
7a6421fa | 84 | int numeric_ids = 0; |
5974c662 | 85 | int allow_8bit_chars = 0; |
7a6421fa AT |
86 | int force_delete = 0; |
87 | int io_timeout = 0; | |
9ac756c6 | 88 | int allowed_lull = 0; |
876c9936 | 89 | int prune_empty_dirs = 0; |
8487f9cf | 90 | int use_qsort = 0; |
ea5164d1 WD |
91 | char *files_from = NULL; |
92 | int filesfrom_fd = -1; | |
305666bf | 93 | char *filesfrom_host = NULL; |
ea5164d1 | 94 | int eol_nulls = 0; |
7a4addaa | 95 | int protect_args = 0; |
8f14cc49 | 96 | int human_readable = 0; |
7a6421fa | 97 | int recurse = 0; |
5275029d | 98 | int allow_inc_recurse = 1; |
b6164938 | 99 | int xfer_dirs = -1; |
1312d9fc | 100 | int am_daemon = 0; |
a5c11139 WD |
101 | int do_stats = 0; |
102 | int do_progress = 0; | |
ba22c9e2 | 103 | int connect_timeout = 0; |
a5c11139 WD |
104 | int keep_partial = 0; |
105 | int safe_symlinks = 0; | |
106 | int copy_unsafe_links = 0; | |
107 | int size_only = 0; | |
9fb08441 | 108 | int daemon_bwlimit = 0; |
a5c11139 | 109 | int bwlimit = 0; |
c4ed1487 | 110 | int fuzzy_basis = 0; |
3c74c3a3 | 111 | size_t bwlimit_writemax = 0; |
e90aab49 WD |
112 | int ignore_existing = 0; |
113 | int ignore_non_existing = 0; | |
07c6ae7d | 114 | int need_messages_from_generator = 0; |
7b9598b2 | 115 | int max_delete = INT_MIN; |
7d5acf1d | 116 | OFF_T max_size = 0; |
74de13d1 | 117 | OFF_T min_size = 0; |
a5c11139 WD |
118 | int ignore_errors = 0; |
119 | int modify_window = 0; | |
120 | int blocking_io = -1; | |
2289bf64 | 121 | int checksum_seed = 0; |
a3221d2a | 122 | int inplace = 0; |
f06e7082 | 123 | int delay_updates = 0; |
a06b419d | 124 | long block_size = 0; /* "long" because popt can't set an int32. */ |
b1e436ec | 125 | char *skip_compress = NULL; |
b35d0d8e | 126 | |
13e29995 | 127 | /** Network address family. **/ |
24d677fc | 128 | int default_af_hint |
4f5b0756 | 129 | #ifdef INET6 |
24d677fc | 130 | = 0; /* Any protocol */ |
6ab6d4bf | 131 | #else |
24d677fc WD |
132 | = AF_INET; /* Must use IPv4 */ |
133 | # ifdef AF_INET6 | |
134 | # undef AF_INET6 | |
135 | # endif | |
136 | # define AF_INET6 AF_INET /* make -6 option a no-op */ | |
6ab6d4bf | 137 | #endif |
06963d0f | 138 | |
13e29995 MP |
139 | /** Do not go into the background when run as --daemon. Good |
140 | * for debugging and required for running as a service on W32, | |
141 | * or under Unix process-monitors. **/ | |
1f35babc WD |
142 | int no_detach |
143 | #if defined _WIN32 || defined __WIN32__ | |
144 | = 1; | |
145 | #else | |
146 | = 0; | |
147 | #endif | |
13e29995 | 148 | |
088aac85 DD |
149 | int write_batch = 0; |
150 | int read_batch = 0; | |
d175d7e1 WD |
151 | int backup_dir_len = 0; |
152 | int backup_suffix_len; | |
e0391f81 | 153 | unsigned int backup_dir_remainder; |
6902ed17 | 154 | |
d175d7e1 | 155 | char *backup_suffix = NULL; |
7a6421fa | 156 | char *tmpdir = NULL; |
a7260c40 | 157 | char *partial_dir = NULL; |
e012f858 | 158 | char *basis_dir[MAX_BASIS_DIRS+1]; |
30e8c8e1 | 159 | char *config_file = NULL; |
7a6421fa | 160 | char *shell_cmd = NULL; |
87c0f9d6 WD |
161 | char *logfile_name = NULL; |
162 | char *logfile_format = NULL; | |
b3e4e7ef | 163 | char *stdout_format = NULL; |
65575e96 | 164 | char *password_file = NULL; |
41bd28fe | 165 | char *rsync_path = RSYNC_PATH; |
66203a98 | 166 | char *backup_dir = NULL; |
e0391f81 | 167 | char backup_dir_buf[MAXPATHLEN]; |
831f06a5 | 168 | char *sockopts = NULL; |
0c56b1ad | 169 | int rsync_port = 0; |
dfd7d541 | 170 | int compare_dest = 0; |
1de3e99b | 171 | int copy_dest = 0; |
59c95e42 | 172 | int link_dest = 0; |
ce0b384f | 173 | int basis_dir_cnt = 0; |
f9a9f547 | 174 | char *dest_option = NULL; |
7a6421fa AT |
175 | |
176 | int verbose = 0; | |
b86f0cef | 177 | int quiet = 0; |
dc1f7b9e | 178 | int output_motd = 1; |
e7651884 | 179 | int log_before_transfer = 0; |
b3e4e7ef WD |
180 | int stdout_format_has_i = 0; |
181 | int stdout_format_has_o_or_i = 0; | |
87c0f9d6 | 182 | int logfile_format_has_i = 0; |
87c0f9d6 | 183 | int logfile_format_has_o_or_i = 0; |
7a6421fa | 184 | int always_checksum = 0; |
f7632fc6 | 185 | int list_only = 0; |
7a6421fa | 186 | |
9b3318b0 WD |
187 | #define MAX_BATCH_NAME_LEN 256 /* Must be less than MAXPATHLEN-13 */ |
188 | char *batch_name = NULL; | |
6902ed17 | 189 | |
332cf6df | 190 | int need_unsorted_flist = 0; |
f7a76b9c | 191 | #ifdef ICONV_OPTION |
332cf6df WD |
192 | char *iconv_opt = ICONV_OPTION; |
193 | #endif | |
194 | ||
dd32e2c3 WD |
195 | struct chmod_mode_struct *chmod_modes = NULL; |
196 | ||
e1add893 | 197 | static int daemon_opt; /* sets am_daemon after option error-reporting */ |
f9998046 | 198 | static int omit_dir_times = 0; |
aa4d3b4c | 199 | static int F_option_cnt = 0; |
5b56cc19 | 200 | static int modify_window_set; |
624d6be2 | 201 | static int itemize_changes = 0; |
854a1aad | 202 | static int refused_delete, refused_archive_part, refused_compress; |
3296f91b | 203 | static int refused_partial, refused_progress, refused_delete_before; |
e0e32031 | 204 | static int refused_delete_during; |
0b52f94d | 205 | static int refused_inplace, refused_no_iconv; |
74de13d1 | 206 | static char *max_size_arg, *min_size_arg; |
77860bac | 207 | static char tmp_partialdir[] = ".~tmp~"; |
5b56cc19 | 208 | |
06963d0f | 209 | /** Local address to bind. As a character string because it's |
fdf57ede | 210 | * interpreted by the IPv6 layer: should be a numeric IP4 or IP6 |
06963d0f MP |
211 | * address, or a hostname. **/ |
212 | char *bind_address; | |
5c9730a4 | 213 | |
7a24c346 | 214 | |
27a12348 | 215 | static void print_rsync_version(enum logcode f) |
7a24c346 | 216 | { |
2ed790f3 | 217 | char *subprotocol = ""; |
dfa32483 | 218 | char const *got_socketpair = "no "; |
a3221d2a | 219 | char const *have_inplace = "no "; |
dfa32483 | 220 | char const *hardlinks = "no "; |
1ed56a05 | 221 | char const *symtimes = "no "; |
1c3344a1 | 222 | char const *acls = "no "; |
16edf865 | 223 | char const *xattrs = "no "; |
dfa32483 | 224 | char const *links = "no "; |
332cf6df | 225 | char const *iconv = "no "; |
a358449a | 226 | char const *ipv6 = "no "; |
736a6a29 | 227 | STRUCT_STAT *dumstat; |
0c80cd8e | 228 | |
2ed790f3 WD |
229 | #if SUBPROTOCOL_VERSION != 0 |
230 | asprintf(&subprotocol, ".PR%d", SUBPROTOCOL_VERSION); | |
231 | #endif | |
4f5b0756 | 232 | #ifdef HAVE_SOCKETPAIR |
dfa32483 | 233 | got_socketpair = ""; |
0c80cd8e | 234 | #endif |
4f5b0756 | 235 | #ifdef HAVE_FTRUNCATE |
a3221d2a WD |
236 | have_inplace = ""; |
237 | #endif | |
4f5b0756 | 238 | #ifdef SUPPORT_HARD_LINKS |
dfa32483 | 239 | hardlinks = ""; |
2855f61f | 240 | #endif |
1c3344a1 WD |
241 | #ifdef SUPPORT_ACLS |
242 | acls = ""; | |
243 | #endif | |
16edf865 WD |
244 | #ifdef SUPPORT_XATTRS |
245 | xattrs = ""; | |
246 | #endif | |
4f5b0756 | 247 | #ifdef SUPPORT_LINKS |
dfa32483 | 248 | links = ""; |
2855f61f | 249 | #endif |
4f5b0756 | 250 | #ifdef INET6 |
a358449a | 251 | ipv6 = ""; |
dfa32483 | 252 | #endif |
332cf6df WD |
253 | #ifdef ICONV_OPTION |
254 | iconv = ""; | |
255 | #endif | |
1ed56a05 WD |
256 | #if defined HAVE_LUTIMES && defined HAVE_UTIMES |
257 | symtimes = ""; | |
258 | #endif | |
a358449a | 259 | |
719522b9 | 260 | rprintf(f, "%s version %s protocol version %d%s\n", |
2ed790f3 | 261 | RSYNC_NAME, RSYNC_VERSION, PROTOCOL_VERSION, subprotocol); |
100018b7 | 262 | rprintf(f, "Copyright (C) 1996-2007 by Andrew Tridgell, Wayne Davison, and others.\n"); |
719522b9 WD |
263 | rprintf(f, "Web site: http://rsync.samba.org/\n"); |
264 | rprintf(f, "Capabilities:\n"); | |
265 | rprintf(f, " %d-bit files, %d-bit inums, %d-bit timestamps, %d-bit long ints,\n", | |
d619ff13 WD |
266 | (int)(sizeof (OFF_T) * 8), |
267 | (int)(sizeof dumstat->st_ino * 8), /* Don't check ino_t! */ | |
bb25779d | 268 | (int)(sizeof (time_t) * 8), |
d619ff13 WD |
269 | (int)(sizeof (int64) * 8)); |
270 | rprintf(f, " %ssocketpairs, %shardlinks, %ssymlinks, %sIPv6, batchfiles, %sinplace,\n", | |
271 | got_socketpair, hardlinks, links, ipv6, have_inplace); | |
1ed56a05 WD |
272 | rprintf(f, " %sappend, %sACLs, %sxattrs, %siconv, %ssymtimes\n", |
273 | have_inplace, acls, xattrs, iconv, symtimes); | |
2855f61f | 274 | |
fc0302cf | 275 | #ifdef MAINTAINER_MODE |
29433538 | 276 | rprintf(f, "Panic Action: \"%s\"\n", get_panic_action()); |
fc0302cf | 277 | #endif |
736a6a29 | 278 | |
031fa9ad WD |
279 | #if SIZEOF_INT64 < 8 |
280 | rprintf(f, "WARNING: no 64-bit integers on this platform!\n"); | |
7a24c346 | 281 | #endif |
c561edaa WD |
282 | if (sizeof (int64) != SIZEOF_INT64) { |
283 | rprintf(f, | |
284 | "WARNING: size mismatch in SIZEOF_INT64 define (%d != %d)\n", | |
285 | (int) SIZEOF_INT64, (int) sizeof (int64)); | |
286 | } | |
7b329a2d | 287 | |
b64ee91a WD |
288 | rprintf(f,"\n"); |
289 | rprintf(f,"rsync comes with ABSOLUTELY NO WARRANTY. This is free software, and you\n"); | |
6ab423a5 WD |
290 | rprintf(f,"are welcome to redistribute it under certain conditions. See the GNU\n"); |
291 | rprintf(f,"General Public Licence for details.\n"); | |
7a24c346 MP |
292 | } |
293 | ||
294 | ||
0f3203c3 | 295 | void usage(enum logcode F) |
7a6421fa | 296 | { |
2855f61f | 297 | print_rsync_version(F); |
704f908e | 298 | |
b64ee91a WD |
299 | rprintf(F,"\n"); |
300 | rprintf(F,"rsync is a file transfer program capable of efficient remote update\n"); | |
6ab423a5 | 301 | rprintf(F,"via a fast differencing algorithm.\n"); |
704f908e | 302 | |
b64ee91a WD |
303 | rprintf(F,"\n"); |
304 | rprintf(F,"Usage: rsync [OPTION]... SRC [SRC]... DEST\n"); | |
868676dc WD |
305 | rprintf(F," or rsync [OPTION]... SRC [SRC]... [USER@]HOST:DEST\n"); |
306 | rprintf(F," or rsync [OPTION]... SRC [SRC]... [USER@]HOST::DEST\n"); | |
307 | rprintf(F," or rsync [OPTION]... SRC [SRC]... rsync://[USER@]HOST[:PORT]/DEST\n"); | |
d0e94abb | 308 | rprintf(F," or rsync [OPTION]... [USER@]HOST:SRC [DEST]\n"); |
14d43f1f | 309 | rprintf(F," or rsync [OPTION]... [USER@]HOST::SRC [DEST]\n"); |
14d43f1f | 310 | rprintf(F," or rsync [OPTION]... rsync://[USER@]HOST[:PORT]/SRC [DEST]\n"); |
08d82b84 WD |
311 | rprintf(F,"The ':' usages connect via remote shell, while '::' & 'rsync://' usages connect\n"); |
312 | rprintf(F,"to an rsync daemon, and require SRC or DEST to start with a module name.\n"); | |
b64ee91a WD |
313 | rprintf(F,"\n"); |
314 | rprintf(F,"Options\n"); | |
704f908e | 315 | rprintf(F," -v, --verbose increase verbosity\n"); |
b3708acf | 316 | rprintf(F," -q, --quiet suppress non-error messages\n"); |
dc1f7b9e | 317 | rprintf(F," --no-motd suppress daemon-mode MOTD (see manpage caveat)\n"); |
b3708acf | 318 | rprintf(F," -c, --checksum skip based on checksum, not mod-time & size\n"); |
16edf865 | 319 | rprintf(F," -a, --archive archive mode; equals -rlptgoD (no -H,-A,-X)\n"); |
8938d67e | 320 | rprintf(F," --no-OPTION turn off an implied OPTION (e.g. --no-D)\n"); |
704f908e AT |
321 | rprintf(F," -r, --recursive recurse into directories\n"); |
322 | rprintf(F," -R, --relative use relative path names\n"); | |
11bfaf63 | 323 | rprintf(F," --no-implied-dirs don't send implied dirs with --relative\n"); |
6839140e | 324 | rprintf(F," -b, --backup make backups (see --suffix & --backup-dir)\n"); |
b3708acf WD |
325 | rprintf(F," --backup-dir=DIR make backups into hierarchy based in DIR\n"); |
326 | rprintf(F," --suffix=SUFFIX set backup suffix (default %s w/o --backup-dir)\n",BACKUP_SUFFIX); | |
327 | rprintf(F," -u, --update skip files that are newer on the receiver\n"); | |
4ce838e1 | 328 | rprintf(F," --inplace update destination files in-place (SEE MAN PAGE)\n"); |
a015788d | 329 | rprintf(F," --append append data onto shorter files\n"); |
936fa865 | 330 | rprintf(F," --append-verify like --append, but with old data in file checksum\n"); |
65e4cda0 | 331 | rprintf(F," -d, --dirs transfer directories without recursing\n"); |
13e29995 | 332 | rprintf(F," -l, --links copy symlinks as symlinks\n"); |
b3708acf WD |
333 | rprintf(F," -L, --copy-links transform symlink into referent file/dir\n"); |
334 | rprintf(F," --copy-unsafe-links only \"unsafe\" symlinks are transformed\n"); | |
335 | rprintf(F," --safe-links ignore symlinks that point outside the source tree\n"); | |
2dbf36ef | 336 | rprintf(F," -k, --copy-dirlinks transform symlink to a dir into referent dir\n"); |
65e4cda0 | 337 | rprintf(F," -K, --keep-dirlinks treat symlinked dir on receiver as dir\n"); |
2dbf36ef | 338 | rprintf(F," -H, --hard-links preserve hard links\n"); |
704f908e | 339 | rprintf(F," -p, --perms preserve permissions\n"); |
344f9ba7 | 340 | rprintf(F," -E, --executability preserve the file's executability\n"); |
dfe1ed5e | 341 | rprintf(F," --chmod=CHMOD affect file and/or directory permissions\n"); |
1c3344a1 WD |
342 | #ifdef SUPPORT_ACLS |
343 | rprintf(F," -A, --acls preserve ACLs (implies --perms)\n"); | |
16edf865 WD |
344 | #endif |
345 | #ifdef SUPPORT_XATTRS | |
3caafdfd | 346 | rprintf(F," -X, --xattrs preserve extended attributes\n"); |
1c3344a1 | 347 | #endif |
def97ff9 | 348 | rprintf(F," -o, --owner preserve owner (super-user only)\n"); |
704f908e | 349 | rprintf(F," -g, --group preserve group\n"); |
def97ff9 | 350 | rprintf(F," --devices preserve device files (super-user only)\n"); |
b5c6a6ae WD |
351 | rprintf(F," --specials preserve special files\n"); |
352 | rprintf(F," -D same as --devices --specials\n"); | |
42b06481 WD |
353 | rprintf(F," -t, --times preserve modification times\n"); |
354 | rprintf(F," -O, --omit-dir-times omit directories from --times\n"); | |
def97ff9 | 355 | rprintf(F," --super receiver attempts super-user activities\n"); |
9439c0cb WD |
356 | #ifdef SUPPORT_XATTRS |
357 | rprintf(F," --fake-super store/recover privileged attrs using xattrs\n"); | |
358 | #endif | |
704f908e | 359 | rprintf(F," -S, --sparse handle sparse files efficiently\n"); |
d100e733 | 360 | rprintf(F," -n, --dry-run perform a trial run with no changes made\n"); |
f7a2ac07 | 361 | rprintf(F," -W, --whole-file copy files whole (without delta-xfer algorithm)\n"); |
704f908e | 362 | rprintf(F," -x, --one-file-system don't cross filesystem boundaries\n"); |
9cd339eb | 363 | rprintf(F," -B, --block-size=SIZE force a fixed checksum block-size\n"); |
b3708acf | 364 | rprintf(F," -e, --rsh=COMMAND specify the remote shell to use\n"); |
05ee4866 | 365 | rprintf(F," --rsync-path=PROGRAM specify the rsync to run on the remote machine\n"); |
fcecb70b WD |
366 | rprintf(F," --existing skip creating new files on receiver\n"); |
367 | rprintf(F," --ignore-existing skip updating files that already exist on receiver\n"); | |
47c11975 | 368 | rprintf(F," --remove-source-files sender removes synchronized files (non-dirs)\n"); |
3359acb8 | 369 | rprintf(F," --del an alias for --delete-during\n"); |
fcecb70b | 370 | rprintf(F," --delete delete extraneous files from destination dirs\n"); |
e0e32031 WD |
371 | rprintf(F," --delete-before receiver deletes before transfer, not during\n"); |
372 | rprintf(F," --delete-during receiver deletes during transfer (default)\n"); | |
b0cacef1 | 373 | rprintf(F," --delete-delay find deletions during, delete after\n"); |
e0e32031 | 374 | rprintf(F," --delete-after receiver deletes after transfer, not during\n"); |
fcecb70b | 375 | rprintf(F," --delete-excluded also delete excluded files from destination dirs\n"); |
db2b5cb7 | 376 | rprintf(F," --ignore-errors delete even if there are I/O errors\n"); |
51d48398 | 377 | rprintf(F," --force force deletion of directories even if not empty\n"); |
0b73ca12 | 378 | rprintf(F," --max-delete=NUM don't delete more than NUM files\n"); |
7d5acf1d | 379 | rprintf(F," --max-size=SIZE don't transfer any file larger than SIZE\n"); |
74de13d1 | 380 | rprintf(F," --min-size=SIZE don't transfer any file smaller than SIZE\n"); |
c95da96a | 381 | rprintf(F," --partial keep partially transferred files\n"); |
a7260c40 | 382 | rprintf(F," --partial-dir=DIR put a partially transferred file into DIR\n"); |
b3708acf | 383 | rprintf(F," --delay-updates put all updated files into place at transfer's end\n"); |
876c9936 | 384 | rprintf(F," -m, --prune-empty-dirs prune empty directory chains from the file-list\n"); |
704f908e | 385 | rprintf(F," --numeric-ids don't map uid/gid values by user/group name\n"); |
ba22c9e2 WD |
386 | rprintf(F," --timeout=SECONDS set I/O timeout in seconds\n"); |
387 | rprintf(F," --contimeout=SECONDS set daemon connection timeout in seconds\n"); | |
b3708acf WD |
388 | rprintf(F," -I, --ignore-times don't skip files that match in size and mod-time\n"); |
389 | rprintf(F," --size-only skip files that match in size\n"); | |
390 | rprintf(F," --modify-window=NUM compare mod-times with reduced accuracy\n"); | |
4db88e5b | 391 | rprintf(F," -T, --temp-dir=DIR create temporary files in directory DIR\n"); |
c4ed1487 | 392 | rprintf(F," -y, --fuzzy find similar file for basis if no dest file\n"); |
375a4556 | 393 | rprintf(F," --compare-dest=DIR also compare destination files relative to DIR\n"); |
1de3e99b | 394 | rprintf(F," --copy-dest=DIR ... and include copies of unchanged files\n"); |
e012f858 | 395 | rprintf(F," --link-dest=DIR hardlink to files in DIR when unchanged\n"); |
f924946e | 396 | rprintf(F," -z, --compress compress file data during the transfer\n"); |
854a1aad | 397 | rprintf(F," --compress-level=NUM explicitly set compression level\n"); |
b1e436ec | 398 | rprintf(F," --skip-compress=LIST skip compressing files with a suffix in LIST\n"); |
b3708acf | 399 | rprintf(F," -C, --cvs-exclude auto-ignore files the same way CVS does\n"); |
aa4d3b4c | 400 | rprintf(F," -f, --filter=RULE add a file-filtering RULE\n"); |
9c71f56a | 401 | rprintf(F," -F same as --filter='dir-merge /.rsync-filter'\n"); |
aa4d3b4c | 402 | rprintf(F," repeated: --filter='- .rsync-filter'\n"); |
2acf81eb | 403 | rprintf(F," --exclude=PATTERN exclude files matching PATTERN\n"); |
b3708acf | 404 | rprintf(F," --exclude-from=FILE read exclude patterns from FILE\n"); |
2acf81eb | 405 | rprintf(F," --include=PATTERN don't exclude files matching PATTERN\n"); |
b3708acf WD |
406 | rprintf(F," --include-from=FILE read include patterns from FILE\n"); |
407 | rprintf(F," --files-from=FILE read list of source-file names from FILE\n"); | |
72316028 | 408 | rprintf(F," -0, --from0 all *-from/filter files are delimited by 0s\n"); |
7a4addaa | 409 | rprintf(F," -s, --protect-args no space-splitting; only wildcard special-chars\n"); |
b4ef0bca | 410 | rprintf(F," --address=ADDRESS bind address for outgoing socket to daemon\n"); |
b4713295 | 411 | rprintf(F," --port=PORT specify double-colon alternate port number\n"); |
831f06a5 | 412 | rprintf(F," --sockopts=OPTIONS specify custom TCP options\n"); |
db2b5cb7 | 413 | rprintf(F," --blocking-io use blocking I/O for the remote shell\n"); |
b3708acf | 414 | rprintf(F," --stats give some file-transfer stats\n"); |
a6a27602 | 415 | rprintf(F," -8, --8-bit-output leave high-bit chars unescaped in output\n"); |
05724c07 | 416 | rprintf(F," -h, --human-readable output numbers in a human-readable format\n"); |
dfa32483 | 417 | rprintf(F," --progress show progress during transfer\n"); |
b3708acf | 418 | rprintf(F," -P same as --partial --progress\n"); |
b78296cb | 419 | rprintf(F," -i, --itemize-changes output a change-summary for all updates\n"); |
b3e4e7ef WD |
420 | rprintf(F," --out-format=FORMAT output updates using the specified FORMAT\n"); |
421 | rprintf(F," --log-file=FILE log what we're doing to the specified FILE\n"); | |
422 | rprintf(F," --log-file-format=FMT log updates using the specified FMT\n"); | |
09a54c39 | 423 | rprintf(F," --password-file=FILE read daemon-access password from FILE\n"); |
65e4cda0 | 424 | rprintf(F," --list-only list the files instead of copying them\n"); |
b3708acf WD |
425 | rprintf(F," --bwlimit=KBPS limit I/O bandwidth; KBytes per second\n"); |
426 | rprintf(F," --write-batch=FILE write a batched update to FILE\n"); | |
11e758a4 | 427 | rprintf(F," --only-write-batch=FILE like --write-batch but w/o updating destination\n"); |
b3708acf | 428 | rprintf(F," --read-batch=FILE read a batched update from FILE\n"); |
da9f5926 | 429 | rprintf(F," --protocol=NUM force an older protocol version to be used\n"); |
332cf6df | 430 | #ifdef ICONV_OPTION |
84e1a34e | 431 | rprintf(F," --iconv=CONVERT_SPEC request charset conversion of filenames\n"); |
332cf6df | 432 | #endif |
4db88e5b WD |
433 | rprintf(F," -4, --ipv4 prefer IPv4\n"); |
434 | rprintf(F," -6, --ipv6 prefer IPv6\n"); | |
4a34c6f1 | 435 | rprintf(F," --version print version number\n"); |
375d8f91 | 436 | rprintf(F,"(-h) --help show this help (-h works with no other options)\n"); |
7a6421fa | 437 | |
b64ee91a WD |
438 | rprintf(F,"\n"); |
439 | rprintf(F,"Use \"rsync --daemon --help\" to see the daemon-mode command-line options.\n"); | |
3ac7f5d4 | 440 | rprintf(F,"Please see the rsync(1) and rsyncd.conf(5) man pages for full documentation.\n"); |
2855f61f | 441 | rprintf(F,"See http://rsync.samba.org/ for updates, bug reports, and answers\n"); |
7a6421fa AT |
442 | } |
443 | ||
3ac7f5d4 | 444 | enum {OPT_VERSION = 1000, OPT_DAEMON, OPT_SENDER, OPT_EXCLUDE, OPT_EXCLUDE_FROM, |
05724c07 | 445 | OPT_FILTER, OPT_COMPARE_DEST, OPT_COPY_DEST, OPT_LINK_DEST, OPT_HELP, |
e16adcdf | 446 | OPT_INCLUDE, OPT_INCLUDE_FROM, OPT_MODIFY_WINDOW, OPT_MIN_SIZE, OPT_CHMOD, |
9ac756c6 | 447 | OPT_READ_BATCH, OPT_WRITE_BATCH, OPT_ONLY_WRITE_BATCH, OPT_MAX_SIZE, |
0b52f94d | 448 | OPT_NO_D, OPT_APPEND, OPT_NO_ICONV, |
0ccffd7c | 449 | OPT_SERVER, OPT_REFUSED_BASE = 9000}; |
7a6421fa | 450 | |
2855f61f MP |
451 | static struct poptOption long_options[] = { |
452 | /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */ | |
05724c07 | 453 | {"help", 0, POPT_ARG_NONE, 0, OPT_HELP, 0, 0 }, |
8db7cc2c | 454 | {"version", 0, POPT_ARG_NONE, 0, OPT_VERSION, 0, 0}, |
e86e2fa1 | 455 | {"verbose", 'v', POPT_ARG_NONE, 0, 'v', 0, 0 }, |
b6164938 | 456 | {"no-verbose", 0, POPT_ARG_VAL, &verbose, 0, 0, 0 }, |
4afcb709 | 457 | {"no-v", 0, POPT_ARG_VAL, &verbose, 0, 0, 0 }, |
e86e2fa1 | 458 | {"quiet", 'q', POPT_ARG_NONE, 0, 'q', 0, 0 }, |
dc1f7b9e WD |
459 | {"motd", 0, POPT_ARG_VAL, &output_motd, 1, 0, 0 }, |
460 | {"no-motd", 0, POPT_ARG_VAL, &output_motd, 0, 0, 0 }, | |
e86e2fa1 | 461 | {"stats", 0, POPT_ARG_NONE, &do_stats, 0, 0, 0 }, |
3ca9e5d8 | 462 | {"human-readable", 'h', POPT_ARG_NONE, 0, 'h', 0, 0}, |
8487f9cf WD |
463 | {"no-human-readable",0, POPT_ARG_VAL, &human_readable, 0, 0, 0}, |
464 | {"no-h", 0, POPT_ARG_VAL, &human_readable, 0, 0, 0}, | |
e86e2fa1 | 465 | {"dry-run", 'n', POPT_ARG_NONE, &dry_run, 0, 0, 0 }, |
b6164938 WD |
466 | {"archive", 'a', POPT_ARG_NONE, 0, 'a', 0, 0 }, |
467 | {"recursive", 'r', POPT_ARG_VAL, &recurse, 2, 0, 0 }, | |
468 | {"no-recursive", 0, POPT_ARG_VAL, &recurse, 0, 0, 0 }, | |
8487f9cf | 469 | {"no-r", 0, POPT_ARG_VAL, &recurse, 0, 0, 0 }, |
5275029d | 470 | {"inc-recursive", 0, POPT_ARG_VAL, &allow_inc_recurse, 1, 0, 0 }, |
5275029d | 471 | {"no-inc-recursive", 0, POPT_ARG_VAL, &allow_inc_recurse, 0, 0, 0 }, |
d6ca255c WD |
472 | {"i-r", 0, POPT_ARG_VAL, &allow_inc_recurse, 1, 0, 0 }, |
473 | {"no-i-r", 0, POPT_ARG_VAL, &allow_inc_recurse, 0, 0, 0 }, | |
e86e2fa1 | 474 | {"dirs", 'd', POPT_ARG_VAL, &xfer_dirs, 2, 0, 0 }, |
b6164938 WD |
475 | {"no-dirs", 0, POPT_ARG_VAL, &xfer_dirs, 0, 0, 0 }, |
476 | {"no-d", 0, POPT_ARG_VAL, &xfer_dirs, 0, 0, 0 }, | |
477 | {"perms", 'p', POPT_ARG_VAL, &preserve_perms, 1, 0, 0 }, | |
478 | {"no-perms", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 }, | |
479 | {"no-p", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 }, | |
344f9ba7 | 480 | {"executability", 'E', POPT_ARG_NONE, &preserve_executability, 0, 0, 0 }, |
1c3344a1 WD |
481 | {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 }, |
482 | {"no-acls", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 }, | |
483 | {"no-A", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 }, | |
16edf865 WD |
484 | {"xattrs", 'X', POPT_ARG_NONE, 0, 'X', 0, 0 }, |
485 | {"no-xattrs", 0, POPT_ARG_VAL, &preserve_xattrs, 0, 0, 0 }, | |
486 | {"no-X", 0, POPT_ARG_VAL, &preserve_xattrs, 0, 0, 0 }, | |
f9998046 | 487 | {"times", 't', POPT_ARG_VAL, &preserve_times, 2, 0, 0 }, |
b6164938 WD |
488 | {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 }, |
489 | {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 }, | |
f9998046 | 490 | {"omit-dir-times", 'O', POPT_ARG_VAL, &omit_dir_times, 1, 0, 0 }, |
eb7a6e09 WD |
491 | {"no-omit-dir-times",0, POPT_ARG_VAL, &omit_dir_times, 0, 0, 0 }, |
492 | {"no-O", 0, POPT_ARG_VAL, &omit_dir_times, 0, 0, 0 }, | |
38b9170c | 493 | {"modify-window", 0, POPT_ARG_INT, &modify_window, OPT_MODIFY_WINDOW, 0, 0 }, |
def97ff9 WD |
494 | {"super", 0, POPT_ARG_VAL, &am_root, 2, 0, 0 }, |
495 | {"no-super", 0, POPT_ARG_VAL, &am_root, 0, 0, 0 }, | |
9439c0cb | 496 | {"fake-super", 0, POPT_ARG_VAL, &am_root, -1, 0, 0 }, |
b6164938 WD |
497 | {"owner", 'o', POPT_ARG_VAL, &preserve_uid, 1, 0, 0 }, |
498 | {"no-owner", 0, POPT_ARG_VAL, &preserve_uid, 0, 0, 0 }, | |
499 | {"no-o", 0, POPT_ARG_VAL, &preserve_uid, 0, 0, 0 }, | |
500 | {"group", 'g', POPT_ARG_VAL, &preserve_gid, 1, 0, 0 }, | |
501 | {"no-group", 0, POPT_ARG_VAL, &preserve_gid, 0, 0, 0 }, | |
502 | {"no-g", 0, POPT_ARG_VAL, &preserve_gid, 0, 0, 0 }, | |
b5c6a6ae WD |
503 | {0, 'D', POPT_ARG_NONE, 0, 'D', 0, 0 }, |
504 | {"no-D", 0, POPT_ARG_NONE, 0, OPT_NO_D, 0, 0 }, | |
505 | {"devices", 0, POPT_ARG_VAL, &preserve_devices, 1, 0, 0 }, | |
b6164938 | 506 | {"no-devices", 0, POPT_ARG_VAL, &preserve_devices, 0, 0, 0 }, |
b5c6a6ae WD |
507 | {"specials", 0, POPT_ARG_VAL, &preserve_specials, 1, 0, 0 }, |
508 | {"no-specials", 0, POPT_ARG_VAL, &preserve_specials, 0, 0, 0 }, | |
e86e2fa1 | 509 | {"links", 'l', POPT_ARG_VAL, &preserve_links, 1, 0, 0 }, |
b6164938 WD |
510 | {"no-links", 0, POPT_ARG_VAL, &preserve_links, 0, 0, 0 }, |
511 | {"no-l", 0, POPT_ARG_VAL, &preserve_links, 0, 0, 0 }, | |
e86e2fa1 WD |
512 | {"copy-links", 'L', POPT_ARG_NONE, ©_links, 0, 0, 0 }, |
513 | {"copy-unsafe-links",0, POPT_ARG_NONE, ©_unsafe_links, 0, 0, 0 }, | |
514 | {"safe-links", 0, POPT_ARG_NONE, &safe_symlinks, 0, 0, 0 }, | |
2dbf36ef | 515 | {"copy-dirlinks", 'k', POPT_ARG_NONE, ©_dirlinks, 0, 0, 0 }, |
e86e2fa1 | 516 | {"keep-dirlinks", 'K', POPT_ARG_NONE, &keep_dirlinks, 0, 0, 0 }, |
e0e32031 | 517 | {"hard-links", 'H', POPT_ARG_NONE, 0, 'H', 0, 0 }, |
beab3078 WD |
518 | {"no-hard-links", 0, POPT_ARG_VAL, &preserve_hard_links, 0, 0, 0 }, |
519 | {"no-H", 0, POPT_ARG_VAL, &preserve_hard_links, 0, 0, 0 }, | |
e86e2fa1 WD |
520 | {"relative", 'R', POPT_ARG_VAL, &relative_paths, 1, 0, 0 }, |
521 | {"no-relative", 0, POPT_ARG_VAL, &relative_paths, 0, 0, 0 }, | |
b6164938 | 522 | {"no-R", 0, POPT_ARG_VAL, &relative_paths, 0, 0, 0 }, |
2dbf36ef | 523 | {"implied-dirs", 0, POPT_ARG_VAL, &implied_dirs, 1, 0, 0 }, |
e86e2fa1 | 524 | {"no-implied-dirs", 0, POPT_ARG_VAL, &implied_dirs, 0, 0, 0 }, |
d6ca255c WD |
525 | {"i-d", 0, POPT_ARG_VAL, &implied_dirs, 1, 0, 0 }, |
526 | {"no-i-d", 0, POPT_ARG_VAL, &implied_dirs, 0, 0, 0 }, | |
e16adcdf | 527 | {"chmod", 0, POPT_ARG_STRING, 0, OPT_CHMOD, 0, 0 }, |
afb6e945 WD |
528 | {"ignore-times", 'I', POPT_ARG_NONE, &ignore_times, 0, 0, 0 }, |
529 | {"size-only", 0, POPT_ARG_NONE, &size_only, 0, 0, 0 }, | |
243c995f | 530 | {"one-file-system", 'x', POPT_ARG_NONE, 0, 'x', 0, 0 }, |
28fb6365 WD |
531 | {"no-one-file-system",'x',POPT_ARG_VAL, &one_file_system, 0, 0, 0 }, |
532 | {"no-x", 'x', POPT_ARG_VAL, &one_file_system, 0, 0, 0 }, | |
e86e2fa1 | 533 | {"update", 'u', POPT_ARG_NONE, &update_only, 0, 0, 0 }, |
e90aab49 | 534 | {"existing", 0, POPT_ARG_NONE, &ignore_non_existing, 0, 0, 0 }, |
e90aab49 | 535 | {"ignore-non-existing",0,POPT_ARG_NONE, &ignore_non_existing, 0, 0, 0 }, |
d2da915c | 536 | {"ignore-existing", 0, POPT_ARG_NONE, &ignore_existing, 0, 0, 0 }, |
aeb213ea | 537 | {"max-size", 0, POPT_ARG_STRING, &max_size_arg, OPT_MAX_SIZE, 0, 0 }, |
74de13d1 | 538 | {"min-size", 0, POPT_ARG_STRING, &min_size_arg, OPT_MIN_SIZE, 0, 0 }, |
e86e2fa1 WD |
539 | {"sparse", 'S', POPT_ARG_NONE, &sparse_files, 0, 0, 0 }, |
540 | {"inplace", 0, POPT_ARG_NONE, &inplace, 0, 0, 0 }, | |
936fa865 WD |
541 | {"append", 0, POPT_ARG_NONE, 0, OPT_APPEND, 0, 0 }, |
542 | {"append-verify", 0, POPT_ARG_VAL, &append_mode, 2, 0, 0 }, | |
543 | {"no-append", 0, POPT_ARG_VAL, &append_mode, 0, 0, 0 }, | |
3671987f | 544 | {"del", 0, POPT_ARG_NONE, &delete_during, 0, 0, 0 }, |
3359acb8 | 545 | {"delete", 0, POPT_ARG_NONE, &delete_mode, 0, 0, 0 }, |
e0e32031 | 546 | {"delete-before", 0, POPT_ARG_NONE, &delete_before, 0, 0, 0 }, |
b0cacef1 WD |
547 | {"delete-during", 0, POPT_ARG_VAL, &delete_during, 1, 0, 0 }, |
548 | {"delete-delay", 0, POPT_ARG_VAL, &delete_during, 2, 0, 0 }, | |
51d48398 WD |
549 | {"delete-after", 0, POPT_ARG_NONE, &delete_after, 0, 0, 0 }, |
550 | {"delete-excluded", 0, POPT_ARG_NONE, &delete_excluded, 0, 0, 0 }, | |
47c11975 WD |
551 | {"remove-sent-files",0, POPT_ARG_VAL, &remove_source_files, 2, 0, 0 }, /* deprecated */ |
552 | {"remove-source-files",0,POPT_ARG_VAL, &remove_source_files, 1, 0, 0 }, | |
afb6e945 | 553 | {"force", 0, POPT_ARG_NONE, &force_delete, 0, 0, 0 }, |
e86e2fa1 WD |
554 | {"ignore-errors", 0, POPT_ARG_NONE, &ignore_errors, 0, 0, 0 }, |
555 | {"max-delete", 0, POPT_ARG_INT, &max_delete, 0, 0, 0 }, | |
556 | {0, 'F', POPT_ARG_NONE, 0, 'F', 0, 0 }, | |
aa4d3b4c | 557 | {"filter", 'f', POPT_ARG_STRING, 0, OPT_FILTER, 0, 0 }, |
8db7cc2c WD |
558 | {"exclude", 0, POPT_ARG_STRING, 0, OPT_EXCLUDE, 0, 0 }, |
559 | {"include", 0, POPT_ARG_STRING, 0, OPT_INCLUDE, 0, 0 }, | |
560 | {"exclude-from", 0, POPT_ARG_STRING, 0, OPT_EXCLUDE_FROM, 0, 0 }, | |
561 | {"include-from", 0, POPT_ARG_STRING, 0, OPT_INCLUDE_FROM, 0, 0 }, | |
afb6e945 | 562 | {"cvs-exclude", 'C', POPT_ARG_NONE, &cvs_exclude, 0, 0, 0 }, |
afb6e945 WD |
563 | {"whole-file", 'W', POPT_ARG_VAL, &whole_file, 1, 0, 0 }, |
564 | {"no-whole-file", 0, POPT_ARG_VAL, &whole_file, 0, 0, 0 }, | |
b6164938 | 565 | {"no-W", 0, POPT_ARG_VAL, &whole_file, 0, 0, 0 }, |
8487f9cf WD |
566 | {"checksum", 'c', POPT_ARG_VAL, &always_checksum, 1, 0, 0 }, |
567 | {"no-checksum", 0, POPT_ARG_VAL, &always_checksum, 0, 0, 0 }, | |
568 | {"no-c", 0, POPT_ARG_VAL, &always_checksum, 0, 0, 0 }, | |
a06b419d | 569 | {"block-size", 'B', POPT_ARG_LONG, &block_size, 0, 0, 0 }, |
e012f858 | 570 | {"compare-dest", 0, POPT_ARG_STRING, 0, OPT_COMPARE_DEST, 0, 0 }, |
1de3e99b | 571 | {"copy-dest", 0, POPT_ARG_STRING, 0, OPT_COPY_DEST, 0, 0 }, |
e012f858 | 572 | {"link-dest", 0, POPT_ARG_STRING, 0, OPT_LINK_DEST, 0, 0 }, |
c4ed1487 | 573 | {"fuzzy", 'y', POPT_ARG_NONE, &fuzzy_basis, 0, 0, 0 }, |
854a1aad | 574 | {"compress", 'z', POPT_ARG_NONE, 0, 'z', 0, 0 }, |
8487f9cf | 575 | {"no-compress", 0, POPT_ARG_VAL, &do_compression, 0, 0, 0 }, |
b1e436ec | 576 | {"skip-compress", 0, POPT_ARG_STRING, &skip_compress, 0, 0, 0 }, |
8487f9cf | 577 | {"no-z", 0, POPT_ARG_VAL, &do_compression, 0, 0, 0 }, |
854a1aad | 578 | {"compress-level", 0, POPT_ARG_INT, &def_compress_level, 'z', 0, 0 }, |
11bfaf63 | 579 | {0, 'P', POPT_ARG_NONE, 0, 'P', 0, 0 }, |
b6164938 WD |
580 | {"progress", 0, POPT_ARG_VAL, &do_progress, 1, 0, 0 }, |
581 | {"no-progress", 0, POPT_ARG_VAL, &do_progress, 0, 0, 0 }, | |
582 | {"partial", 0, POPT_ARG_VAL, &keep_partial, 1, 0, 0 }, | |
583 | {"no-partial", 0, POPT_ARG_VAL, &keep_partial, 0, 0, 0 }, | |
a7260c40 | 584 | {"partial-dir", 0, POPT_ARG_STRING, &partial_dir, 0, 0, 0 }, |
8487f9cf WD |
585 | {"delay-updates", 0, POPT_ARG_VAL, &delay_updates, 1, 0, 0 }, |
586 | {"no-delay-updates", 0, POPT_ARG_VAL, &delay_updates, 0, 0, 0 }, | |
876c9936 | 587 | {"prune-empty-dirs",'m', POPT_ARG_NONE, &prune_empty_dirs, 0, 0, 0 }, |
87c0f9d6 | 588 | {"log-file", 0, POPT_ARG_STRING, &logfile_name, 0, 0, 0 }, |
b3e4e7ef WD |
589 | {"log-file-format", 0, POPT_ARG_STRING, &logfile_format, 0, 0, 0 }, |
590 | {"out-format", 0, POPT_ARG_STRING, &stdout_format, 0, 0, 0 }, | |
591 | {"log-format", 0, POPT_ARG_STRING, &stdout_format, 0, 0, 0 }, /* DEPRECATED */ | |
487094a0 | 592 | {"itemize-changes", 'i', POPT_ARG_NONE, 0, 'i', 0, 0 }, |
8487f9cf WD |
593 | {"no-itemize-changes",0, POPT_ARG_VAL, &itemize_changes, 0, 0, 0 }, |
594 | {"no-i", 0, POPT_ARG_VAL, &itemize_changes, 0, 0, 0 }, | |
afb6e945 | 595 | {"bwlimit", 0, POPT_ARG_INT, &bwlimit, 0, 0, 0 }, |
8487f9cf WD |
596 | {"no-bwlimit", 0, POPT_ARG_VAL, &bwlimit, 0, 0, 0 }, |
597 | {"backup", 'b', POPT_ARG_VAL, &make_backups, 1, 0, 0 }, | |
598 | {"no-backup", 0, POPT_ARG_VAL, &make_backups, 0, 0, 0 }, | |
afb6e945 | 599 | {"backup-dir", 0, POPT_ARG_STRING, &backup_dir, 0, 0, 0 }, |
e86e2fa1 WD |
600 | {"suffix", 0, POPT_ARG_STRING, &backup_suffix, 0, 0, 0 }, |
601 | {"list-only", 0, POPT_ARG_VAL, &list_only, 2, 0, 0 }, | |
8db7cc2c WD |
602 | {"read-batch", 0, POPT_ARG_STRING, &batch_name, OPT_READ_BATCH, 0, 0 }, |
603 | {"write-batch", 0, POPT_ARG_STRING, &batch_name, OPT_WRITE_BATCH, 0, 0 }, | |
11e758a4 | 604 | {"only-write-batch", 0, POPT_ARG_STRING, &batch_name, OPT_ONLY_WRITE_BATCH, 0, 0 }, |
ea5164d1 | 605 | {"files-from", 0, POPT_ARG_STRING, &files_from, 0, 0, 0 }, |
8487f9cf WD |
606 | {"from0", '0', POPT_ARG_VAL, &eol_nulls, 1, 0, 0}, |
607 | {"no-from0", 0, POPT_ARG_VAL, &eol_nulls, 0, 0, 0}, | |
c35d6e35 WD |
608 | {"protect-args", 's', POPT_ARG_VAL, &protect_args, 1, 0, 0}, |
609 | {"no-protect-args", 0, POPT_ARG_VAL, &protect_args, 0, 0, 0}, | |
610 | {"no-s", 0, POPT_ARG_VAL, &protect_args, 0, 0, 0}, | |
8487f9cf WD |
611 | {"numeric-ids", 0, POPT_ARG_VAL, &numeric_ids, 1, 0, 0 }, |
612 | {"no-numeric-ids", 0, POPT_ARG_VAL, &numeric_ids, 0, 0, 0 }, | |
e86e2fa1 | 613 | {"timeout", 0, POPT_ARG_INT, &io_timeout, 0, 0, 0 }, |
8487f9cf | 614 | {"no-timeout", 0, POPT_ARG_VAL, &io_timeout, 0, 0, 0 }, |
ba22c9e2 | 615 | {"contimeout", 0, POPT_ARG_INT, &connect_timeout, 0, 0, 0 }, |
e86e2fa1 WD |
616 | {"rsh", 'e', POPT_ARG_STRING, &shell_cmd, 0, 0, 0 }, |
617 | {"rsync-path", 0, POPT_ARG_STRING, &rsync_path, 0, 0, 0 }, | |
618 | {"temp-dir", 'T', POPT_ARG_STRING, &tmpdir, 0, 0, 0 }, | |
332cf6df WD |
619 | #ifdef ICONV_OPTION |
620 | {"iconv", 0, POPT_ARG_STRING, &iconv_opt, 0, 0, 0 }, | |
0b52f94d | 621 | {"no-iconv", 0, POPT_ARG_NONE, 0, OPT_NO_ICONV, 0, 0 }, |
332cf6df | 622 | #endif |
3dd22903 WD |
623 | {"ipv4", '4', POPT_ARG_VAL, &default_af_hint, AF_INET, 0, 0 }, |
624 | {"ipv6", '6', POPT_ARG_VAL, &default_af_hint, AF_INET6, 0, 0 }, | |
a6a27602 | 625 | {"8-bit-output", '8', POPT_ARG_NONE, &allow_8bit_chars, 0, 0, 0 }, |
8487f9cf | 626 | {"qsort", 0, POPT_ARG_NONE, &use_qsort, 0, 0, 0 }, |
e86e2fa1 WD |
627 | {"address", 0, POPT_ARG_STRING, &bind_address, 0, 0, 0 }, |
628 | {"port", 0, POPT_ARG_INT, &rsync_port, 0, 0, 0 }, | |
831f06a5 | 629 | {"sockopts", 0, POPT_ARG_STRING, &sockopts, 0, 0, 0 }, |
e86e2fa1 WD |
630 | {"password-file", 0, POPT_ARG_STRING, &password_file, 0, 0, 0 }, |
631 | {"blocking-io", 0, POPT_ARG_VAL, &blocking_io, 1, 0, 0 }, | |
632 | {"no-blocking-io", 0, POPT_ARG_VAL, &blocking_io, 0, 0, 0 }, | |
633 | {"protocol", 0, POPT_ARG_INT, &protocol_version, 0, 0, 0 }, | |
634 | {"checksum-seed", 0, POPT_ARG_INT, &checksum_seed, 0, 0, 0 }, | |
0ccffd7c | 635 | {"server", 0, POPT_ARG_NONE, 0, OPT_SERVER, 0, 0 }, |
e86e2fa1 WD |
636 | {"sender", 0, POPT_ARG_NONE, 0, OPT_SENDER, 0, 0 }, |
637 | /* All the following options switch us into daemon-mode option-parsing. */ | |
3ac7f5d4 WD |
638 | {"config", 0, POPT_ARG_STRING, 0, OPT_DAEMON, 0, 0 }, |
639 | {"daemon", 0, POPT_ARG_NONE, 0, OPT_DAEMON, 0, 0 }, | |
1f35babc | 640 | {"detach", 0, POPT_ARG_NONE, 0, OPT_DAEMON, 0, 0 }, |
3ac7f5d4 | 641 | {"no-detach", 0, POPT_ARG_NONE, 0, OPT_DAEMON, 0, 0 }, |
3ac7f5d4 WD |
642 | {0,0,0,0, 0, 0, 0} |
643 | }; | |
644 | ||
645 | static void daemon_usage(enum logcode F) | |
646 | { | |
647 | print_rsync_version(F); | |
648 | ||
b64ee91a WD |
649 | rprintf(F,"\n"); |
650 | rprintf(F,"Usage: rsync --daemon [OPTION]...\n"); | |
3ac7f5d4 | 651 | rprintf(F," --address=ADDRESS bind to the specified address\n"); |
b3708acf | 652 | rprintf(F," --bwlimit=KBPS limit I/O bandwidth; KBytes per second\n"); |
3ac7f5d4 WD |
653 | rprintf(F," --config=FILE specify alternate rsyncd.conf file\n"); |
654 | rprintf(F," --no-detach do not detach from the parent\n"); | |
b3708acf | 655 | rprintf(F," --port=PORT listen on alternate port number\n"); |
87c0f9d6 | 656 | rprintf(F," --log-file=FILE override the \"log file\" setting\n"); |
232658d9 | 657 | rprintf(F," --log-file-format=FMT override the \"log format\" setting\n"); |
831f06a5 | 658 | rprintf(F," --sockopts=OPTIONS specify custom TCP options\n"); |
1bd9db74 | 659 | rprintf(F," -v, --verbose increase verbosity\n"); |
3ac7f5d4 WD |
660 | rprintf(F," -4, --ipv4 prefer IPv4\n"); |
661 | rprintf(F," -6, --ipv6 prefer IPv6\n"); | |
05724c07 | 662 | rprintf(F," --help show this help screen\n"); |
3ac7f5d4 | 663 | |
b64ee91a WD |
664 | rprintf(F,"\n"); |
665 | rprintf(F,"If you were not trying to invoke rsync as a daemon, avoid using any of the\n"); | |
3ac7f5d4 WD |
666 | rprintf(F,"daemon-specific rsync options. See also the rsyncd.conf(5) man page.\n"); |
667 | } | |
668 | ||
669 | static struct poptOption long_daemon_options[] = { | |
670 | /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */ | |
671 | {"address", 0, POPT_ARG_STRING, &bind_address, 0, 0, 0 }, | |
9fb08441 | 672 | {"bwlimit", 0, POPT_ARG_INT, &daemon_bwlimit, 0, 0, 0 }, |
3ac7f5d4 WD |
673 | {"config", 0, POPT_ARG_STRING, &config_file, 0, 0, 0 }, |
674 | {"daemon", 0, POPT_ARG_NONE, &daemon_opt, 0, 0, 0 }, | |
3ac7f5d4 WD |
675 | {"ipv4", '4', POPT_ARG_VAL, &default_af_hint, AF_INET, 0, 0 }, |
676 | {"ipv6", '6', POPT_ARG_VAL, &default_af_hint, AF_INET6, 0, 0 }, | |
1f35babc | 677 | {"detach", 0, POPT_ARG_VAL, &no_detach, 0, 0, 0 }, |
8487f9cf | 678 | {"no-detach", 0, POPT_ARG_VAL, &no_detach, 1, 0, 0 }, |
87c0f9d6 | 679 | {"log-file", 0, POPT_ARG_STRING, &logfile_name, 0, 0, 0 }, |
232658d9 | 680 | {"log-file-format", 0, POPT_ARG_STRING, &logfile_format, 0, 0, 0 }, |
3ac7f5d4 | 681 | {"port", 0, POPT_ARG_INT, &rsync_port, 0, 0, 0 }, |
831f06a5 | 682 | {"sockopts", 0, POPT_ARG_STRING, &sockopts, 0, 0, 0 }, |
3ac7f5d4 WD |
683 | {"protocol", 0, POPT_ARG_INT, &protocol_version, 0, 0, 0 }, |
684 | {"server", 0, POPT_ARG_NONE, &am_server, 0, 0, 0 }, | |
b8cc3587 | 685 | {"temp-dir", 'T', POPT_ARG_STRING, &tmpdir, 0, 0, 0 }, |
1bd9db74 | 686 | {"verbose", 'v', POPT_ARG_NONE, 0, 'v', 0, 0 }, |
b6e22a47 WD |
687 | {"no-verbose", 0, POPT_ARG_VAL, &verbose, 0, 0, 0 }, |
688 | {"no-v", 0, POPT_ARG_VAL, &verbose, 0, 0, 0 }, | |
3ac7f5d4 | 689 | {"help", 'h', POPT_ARG_NONE, 0, 'h', 0, 0 }, |
ad715008 | 690 | {0,0,0,0, 0, 0, 0} |
2855f61f | 691 | }; |
7a6421fa | 692 | |
06963d0f | 693 | |
e51094b7 | 694 | static char err_buf[200]; |
cd8185f2 | 695 | |
2855f61f | 696 | |
dafe63ca MP |
697 | /** |
698 | * Store the option error message, if any, so that we can log the | |
699 | * connection attempt (which requires parsing the options), and then | |
700 | * show the error later on. | |
701 | **/ | |
cd8185f2 AT |
702 | void option_error(void) |
703 | { | |
e51094b7 | 704 | if (!err_buf[0]) { |
c9bce0b8 WD |
705 | strlcpy(err_buf, "Error parsing options: option may " |
706 | "be supported on client but not on server?\n", | |
707 | sizeof err_buf); | |
cd8185f2 | 708 | } |
e51094b7 | 709 | |
e51094b7 | 710 | rprintf(FERROR, RSYNC_NAME ": %s", err_buf); |
8f1dc165 | 711 | msleep(20); |
cd8185f2 AT |
712 | } |
713 | ||
dafe63ca MP |
714 | |
715 | /** | |
27ed20f7 WD |
716 | * Tweak the option table to disable all options that the rsyncd.conf |
717 | * file has told us to refuse. | |
dafe63ca | 718 | **/ |
27ed20f7 | 719 | static void set_refuse_options(char *bp) |
cd8185f2 | 720 | { |
27ed20f7 | 721 | struct poptOption *op; |
093e816c | 722 | char *cp, shortname[2]; |
d73e7f6e | 723 | int is_wild, found_match; |
093e816c WD |
724 | |
725 | shortname[1] = '\0'; | |
27ed20f7 WD |
726 | |
727 | while (1) { | |
06a50542 WD |
728 | while (*bp == ' ') bp++; |
729 | if (!*bp) | |
730 | break; | |
27ed20f7 WD |
731 | if ((cp = strchr(bp, ' ')) != NULL) |
732 | *cp= '\0'; | |
093e816c | 733 | is_wild = strpbrk(bp, "*?[") != NULL; |
d73e7f6e | 734 | found_match = 0; |
55afbb52 | 735 | for (op = long_options; ; op++) { |
093e816c | 736 | *shortname = op->shortName; |
d73e7f6e WD |
737 | if (!op->longName && !*shortname) |
738 | break; | |
739 | if ((op->longName && wildmatch(bp, op->longName)) | |
684d7582 | 740 | || (*shortname && wildmatch(bp, shortname))) { |
e57211c5 WD |
741 | if (op->argInfo == POPT_ARG_VAL) |
742 | op->argInfo = POPT_ARG_NONE; | |
06a50542 | 743 | op->val = (op - long_options) + OPT_REFUSED_BASE; |
d73e7f6e | 744 | found_match = 1; |
3671987f WD |
745 | /* These flags are set to let us easily check |
746 | * an implied option later in the code. */ | |
747 | switch (*shortname) { | |
3671987f WD |
748 | case 'r': case 'd': case 'l': case 'p': |
749 | case 't': case 'g': case 'o': case 'D': | |
750 | refused_archive_part = op->val; | |
751 | break; | |
854a1aad WD |
752 | case 'z': |
753 | refused_compress = op->val; | |
754 | break; | |
3671987f WD |
755 | case '\0': |
756 | if (wildmatch("delete", op->longName)) | |
757 | refused_delete = op->val; | |
3296f91b WD |
758 | else if (wildmatch("delete-before", op->longName)) |
759 | refused_delete_before = op->val; | |
e0e32031 WD |
760 | else if (wildmatch("delete-during", op->longName)) |
761 | refused_delete_during = op->val; | |
3671987f WD |
762 | else if (wildmatch("partial", op->longName)) |
763 | refused_partial = op->val; | |
764 | else if (wildmatch("progress", op->longName)) | |
765 | refused_progress = op->val; | |
a015788d WD |
766 | else if (wildmatch("inplace", op->longName)) |
767 | refused_inplace = op->val; | |
0b52f94d WD |
768 | else if (wildmatch("no-iconv", op->longName)) |
769 | refused_no_iconv = op->val; | |
3671987f WD |
770 | break; |
771 | } | |
06a50542 WD |
772 | if (!is_wild) |
773 | break; | |
27ed20f7 | 774 | } |
cd8185f2 | 775 | } |
d73e7f6e WD |
776 | if (!found_match) { |
777 | rprintf(FLOG, "No match for refuse-options string \"%s\"\n", | |
778 | bp); | |
779 | } | |
27ed20f7 WD |
780 | if (!cp) |
781 | break; | |
782 | *cp = ' '; | |
783 | bp = cp + 1; | |
cd8185f2 | 784 | } |
cd8185f2 AT |
785 | } |
786 | ||
787 | ||
8db7cc2c | 788 | static int count_args(const char **argv) |
2855f61f | 789 | { |
dfa32483 | 790 | int i = 0; |
2855f61f | 791 | |
8db7cc2c WD |
792 | if (argv) { |
793 | while (argv[i] != NULL) | |
794 | i++; | |
795 | } | |
dfa32483 WD |
796 | |
797 | return i; | |
2855f61f MP |
798 | } |
799 | ||
800 | ||
837d01dd | 801 | static OFF_T parse_size_arg(char **size_arg, char def_suf) |
95e107db | 802 | { |
3c19f72c WD |
803 | int reps, mult, make_compatible = 0; |
804 | const char *arg; | |
805 | OFF_T size = 1; | |
95e107db | 806 | |
2dc7b8bd | 807 | for (arg = *size_arg; isDigit(arg); arg++) {} |
95e107db | 808 | if (*arg == '.') |
2dc7b8bd | 809 | for (arg++; isDigit(arg); arg++) {} |
3c19f72c | 810 | switch (*arg && *arg != '+' && *arg != '-' ? *arg++ : def_suf) { |
837d01dd | 811 | case 'b': case 'B': |
3c19f72c | 812 | reps = 0; |
837d01dd | 813 | break; |
95e107db | 814 | case 'k': case 'K': |
3c19f72c | 815 | reps = 1; |
95e107db WD |
816 | break; |
817 | case 'm': case 'M': | |
3c19f72c | 818 | reps = 2; |
95e107db WD |
819 | break; |
820 | case 'g': case 'G': | |
3c19f72c | 821 | reps = 3; |
95e107db WD |
822 | break; |
823 | default: | |
3c19f72c | 824 | return -1; |
95e107db | 825 | } |
3c19f72c WD |
826 | if (*arg == 'b' || *arg == 'B') |
827 | mult = 1000, make_compatible = 1, arg++; | |
828 | else if (!*arg || *arg == '+' || *arg == '-') | |
829 | mult = 1024; | |
830 | else if (strncasecmp(arg, "ib", 2) == 0) | |
831 | mult = 1024, arg += 2; | |
832 | else | |
833 | return -1; | |
834 | while (reps--) | |
835 | size *= mult; | |
836 | size *= atof(*size_arg); | |
837 | if ((*arg == '+' || *arg == '-') && arg[1] == '1') | |
838 | size += atoi(arg), make_compatible = 1, arg += 2; | |
839 | if (*arg) | |
840 | return -1; | |
aeb213ea | 841 | if (size > 0 && make_compatible) { |
74de13d1 WD |
842 | /* We convert this manually because we may need %lld precision, |
843 | * and that's not a portable sprintf() escape. */ | |
8f14cc49 | 844 | char buf[128], *s = buf + sizeof buf - 1; |
aeb213ea | 845 | OFF_T num = size; |
8f14cc49 | 846 | *s = '\0'; |
aeb213ea | 847 | while (num) { |
26404276 | 848 | *--s = (char)(num % 10) + '0'; |
aeb213ea WD |
849 | num /= 10; |
850 | } | |
851 | if (!(*size_arg = strdup(s))) | |
852 | out_of_memory("parse_size_arg"); | |
853 | } | |
95e107db WD |
854 | return size; |
855 | } | |
856 | ||
857 | ||
3671987f WD |
858 | static void create_refuse_error(int which) |
859 | { | |
860 | /* The "which" value is the index + OPT_REFUSED_BASE. */ | |
861 | struct poptOption *op = &long_options[which - OPT_REFUSED_BASE]; | |
862 | int n = snprintf(err_buf, sizeof err_buf, | |
863 | "The server is configured to refuse --%s\n", | |
864 | op->longName) - 1; | |
865 | if (op->shortName) { | |
866 | snprintf(err_buf + n, sizeof err_buf - n, | |
867 | " (-%c)\n", op->shortName); | |
868 | } | |
869 | } | |
870 | ||
871 | ||
dafe63ca MP |
872 | /** |
873 | * Process command line arguments. Called on both local and remote. | |
874 | * | |
875 | * @retval 1 if all options are OK; with globals set to appropriate | |
876 | * values | |
877 | * | |
878 | * @retval 0 on error, with err_buf containing an explanation | |
879 | **/ | |
ffbffc64 | 880 | int parse_arguments(int *argc_p, const char ***argv_p, int frommain) |
7a6421fa | 881 | { |
7a4addaa | 882 | static poptContext pc; |
ffbffc64 WD |
883 | char *ref = lp_refuse_options(module_id); |
884 | const char *arg, **argv = *argv_p; | |
885 | int argc = *argc_p; | |
886 | int opt; | |
d853783f | 887 | |
27ed20f7 WD |
888 | if (ref && *ref) |
889 | set_refuse_options(ref); | |
0b52f94d | 890 | if (am_daemon) { |
232658d9 | 891 | set_refuse_options("log-file*"); |
0b52f94d WD |
892 | if (!*lp_charset(module_id)) |
893 | set_refuse_options("iconv"); | |
894 | } | |
27ed20f7 | 895 | |
332cf6df | 896 | #ifdef ICONV_OPTION |
a4453606 | 897 | if (!am_daemon && !protect_args && (arg = getenv("RSYNC_ICONV")) != NULL && *arg) |
332cf6df WD |
898 | iconv_opt = strdup(arg); |
899 | #endif | |
900 | ||
dfa32483 | 901 | /* TODO: Call poptReadDefaultConfig; handle errors. */ |
cd8185f2 | 902 | |
dfa32483 WD |
903 | /* The context leaks in case of an error, but if there's a |
904 | * problem we always exit anyhow. */ | |
7a4addaa WD |
905 | if (pc) |
906 | poptFreeContext(pc); | |
907 | pc = poptGetContext(RSYNC_NAME, argc, argv, long_options, 0); | |
908 | if (!am_server) | |
909 | poptReadDefaultConfig(pc, 0); | |
2855f61f MP |
910 | |
911 | while ((opt = poptGetNextOpt(pc)) != -1) { | |
dfa32483 WD |
912 | /* most options are handled automatically by popt; |
913 | * only special cases are returned and listed here. */ | |
2855f61f | 914 | |
d853783f AT |
915 | switch (opt) { |
916 | case OPT_VERSION: | |
dfa32483 | 917 | print_rsync_version(FINFO); |
d853783f | 918 | exit_cleanup(0); |
dfa32483 | 919 | |
0ccffd7c WD |
920 | case OPT_SERVER: |
921 | if (!am_server) { | |
922 | /* Disable popt aliases on the server side and | |
923 | * then start parsing the options again. */ | |
924 | poptFreeContext(pc); | |
ffbffc64 | 925 | pc = poptGetContext(RSYNC_NAME, argc, argv, |
0ccffd7c WD |
926 | long_options, 0); |
927 | am_server = 1; | |
928 | } | |
332cf6df WD |
929 | #ifdef ICONV_OPTION |
930 | iconv_opt = NULL; | |
931 | #endif | |
0ccffd7c WD |
932 | break; |
933 | ||
934 | case OPT_SENDER: | |
935 | if (!am_server) { | |
936 | usage(FERROR); | |
937 | exit_cleanup(RERR_SYNTAX); | |
938 | } | |
939 | am_sender = 1; | |
940 | break; | |
941 | ||
3ac7f5d4 WD |
942 | case OPT_DAEMON: |
943 | if (am_daemon) { | |
c9bce0b8 WD |
944 | strlcpy(err_buf, |
945 | "Attempt to hack rsync thwarted!\n", | |
946 | sizeof err_buf); | |
3ac7f5d4 WD |
947 | return 0; |
948 | } | |
332cf6df WD |
949 | #ifdef ICONV_OPTION |
950 | iconv_opt = NULL; | |
951 | #endif | |
3ac7f5d4 | 952 | poptFreeContext(pc); |
ffbffc64 | 953 | pc = poptGetContext(RSYNC_NAME, argc, argv, |
3ac7f5d4 WD |
954 | long_daemon_options, 0); |
955 | while ((opt = poptGetNextOpt(pc)) != -1) { | |
956 | switch (opt) { | |
957 | case 'h': | |
958 | daemon_usage(FINFO); | |
959 | exit_cleanup(0); | |
960 | ||
1bd9db74 WD |
961 | case 'v': |
962 | verbose++; | |
963 | break; | |
964 | ||
3ac7f5d4 WD |
965 | default: |
966 | rprintf(FERROR, | |
967 | "rsync: %s: %s (in daemon mode)\n", | |
968 | poptBadOption(pc, POPT_BADOPTION_NOALIAS), | |
969 | poptStrerror(opt)); | |
970 | goto daemon_error; | |
971 | } | |
972 | } | |
b6e22a47 WD |
973 | |
974 | if (tmpdir && strlen(tmpdir) >= MAXPATHLEN - 10) { | |
975 | snprintf(err_buf, sizeof err_buf, | |
976 | "the --temp-dir path is WAY too long.\n"); | |
977 | return 0; | |
978 | } | |
979 | ||
3ac7f5d4 WD |
980 | if (!daemon_opt) { |
981 | rprintf(FERROR, "Daemon option(s) used without --daemon.\n"); | |
982 | daemon_error: | |
983 | rprintf(FERROR, | |
984 | "(Type \"rsync --daemon --help\" for assistance with daemon mode.)\n"); | |
985 | exit_cleanup(RERR_SYNTAX); | |
986 | } | |
b6e22a47 | 987 | |
ffbffc64 WD |
988 | *argv_p = argv = poptGetArgs(pc); |
989 | *argc_p = argc = count_args(argv); | |
7f2a1f65 | 990 | am_starting_up = 0; |
3ac7f5d4 WD |
991 | daemon_opt = 0; |
992 | am_daemon = 1; | |
993 | return 1; | |
994 | ||
5b56cc19 | 995 | case OPT_MODIFY_WINDOW: |
dfa32483 WD |
996 | /* The value has already been set by popt, but |
997 | * we need to remember that we're using a | |
998 | * non-default setting. */ | |
5b56cc19 AT |
999 | modify_window_set = 1; |
1000 | break; | |
1de50993 | 1001 | |
aa4d3b4c | 1002 | case OPT_FILTER: |
3a5e9224 | 1003 | parse_rule(&filter_list, poptGetOptArg(pc), 0, 0); |
d853783f AT |
1004 | break; |
1005 | ||
aa4d3b4c | 1006 | case OPT_EXCLUDE: |
3a5e9224 | 1007 | parse_rule(&filter_list, poptGetOptArg(pc), |
0a68f869 | 1008 | 0, XFLG_OLD_PREFIXES); |
aa4d3b4c WD |
1009 | break; |
1010 | ||
d853783f | 1011 | case OPT_INCLUDE: |
3a5e9224 | 1012 | parse_rule(&filter_list, poptGetOptArg(pc), |
0a68f869 | 1013 | MATCHFLG_INCLUDE, XFLG_OLD_PREFIXES); |
d853783f AT |
1014 | break; |
1015 | ||
1016 | case OPT_EXCLUDE_FROM: | |
93695764 | 1017 | case OPT_INCLUDE_FROM: |
7be73df4 | 1018 | arg = poptGetOptArg(pc); |
1a7f3d99 | 1019 | if (sanitize_paths) |
29bca53f | 1020 | arg = sanitize_path(NULL, arg, NULL, 0); |
7842418b | 1021 | if (server_filter_list.head) { |
200aec7d | 1022 | int rej; |
a1018691 | 1023 | char *dir, *cp = strdup(arg); |
d3ef9859 WD |
1024 | if (!cp) |
1025 | out_of_memory("parse_arguments"); | |
3671987f WD |
1026 | if (!*cp) |
1027 | goto options_rejected; | |
a1018691 WD |
1028 | dir = cp + (*cp == '/' ? module_dirlen : 0); |
1029 | clean_fname(dir, CFN_COLLAPSE_DOT_DOT_DIRS); | |
1030 | rej = check_filter(&server_filter_list, dir, 0) < 0; | |
d3ef9859 | 1031 | free(cp); |
200aec7d WD |
1032 | if (rej) |
1033 | goto options_rejected; | |
ba3db479 | 1034 | } |
3a5e9224 WD |
1035 | parse_filter_file(&filter_list, arg, |
1036 | opt == OPT_INCLUDE_FROM ? MATCHFLG_INCLUDE : 0, | |
1037 | XFLG_FATAL_ERRORS | XFLG_OLD_PREFIXES); | |
93695764 DD |
1038 | break; |
1039 | ||
b6164938 WD |
1040 | case 'a': |
1041 | if (refused_archive_part) { | |
1042 | create_refuse_error(refused_archive_part); | |
1043 | return 0; | |
1044 | } | |
1045 | if (!recurse) /* preserve recurse == 2 */ | |
1046 | recurse = 1; | |
1047 | #ifdef SUPPORT_LINKS | |
1048 | preserve_links = 1; | |
1049 | #endif | |
1050 | preserve_perms = 1; | |
f9998046 | 1051 | preserve_times = 2; |
b6164938 WD |
1052 | preserve_gid = 1; |
1053 | preserve_uid = 1; | |
1054 | preserve_devices = 1; | |
b5c6a6ae WD |
1055 | preserve_specials = 1; |
1056 | break; | |
1057 | ||
1058 | case 'D': | |
1059 | preserve_devices = preserve_specials = 1; | |
1060 | break; | |
1061 | ||
1062 | case OPT_NO_D: | |
1063 | preserve_devices = preserve_specials = 0; | |
b6164938 WD |
1064 | break; |
1065 | ||
3ca9e5d8 WD |
1066 | case 'h': |
1067 | human_readable++; | |
1068 | break; | |
1069 | ||
e0e32031 WD |
1070 | case 'H': |
1071 | preserve_hard_links++; | |
1072 | break; | |
1073 | ||
487094a0 WD |
1074 | case 'i': |
1075 | itemize_changes++; | |
1076 | break; | |
1077 | ||
d853783f AT |
1078 | case 'v': |
1079 | verbose++; | |
1080 | break; | |
7a6421fa | 1081 | |
b86f0cef | 1082 | case 'q': |
f98c60bf WD |
1083 | if (frommain) |
1084 | quiet++; | |
b86f0cef DD |
1085 | break; |
1086 | ||
243c995f WD |
1087 | case 'x': |
1088 | one_file_system++; | |
1089 | break; | |
1090 | ||
aa4d3b4c WD |
1091 | case 'F': |
1092 | switch (++F_option_cnt) { | |
1093 | case 1: | |
3a5e9224 | 1094 | parse_rule(&filter_list,": /.rsync-filter",0,0); |
aa4d3b4c WD |
1095 | break; |
1096 | case 2: | |
3a5e9224 | 1097 | parse_rule(&filter_list,"- .rsync-filter",0,0); |
aa4d3b4c WD |
1098 | break; |
1099 | } | |
1100 | break; | |
1101 | ||
d9fcc198 | 1102 | case 'P': |
3671987f WD |
1103 | if (refused_partial || refused_progress) { |
1104 | create_refuse_error(refused_partial | |
1105 | ? refused_partial : refused_progress); | |
1106 | return 0; | |
1107 | } | |
d9fcc198 AT |
1108 | do_progress = 1; |
1109 | keep_partial = 1; | |
1110 | break; | |
1111 | ||
854a1aad WD |
1112 | case 'z': |
1113 | if (def_compress_level < Z_DEFAULT_COMPRESSION | |
1114 | || def_compress_level > Z_BEST_COMPRESSION) { | |
1115 | snprintf(err_buf, sizeof err_buf, | |
1116 | "--compress-level value is invalid: %d\n", | |
1117 | def_compress_level); | |
1118 | return 0; | |
1119 | } | |
1120 | do_compression = def_compress_level != Z_NO_COMPRESSION; | |
1121 | if (do_compression && refused_compress) { | |
1122 | create_refuse_error(refused_compress); | |
1123 | return 0; | |
1124 | } | |
1125 | break; | |
1126 | ||
088aac85 | 1127 | case OPT_WRITE_BATCH: |
9b3318b0 | 1128 | /* batch_name is already set */ |
088aac85 DD |
1129 | write_batch = 1; |
1130 | break; | |
1131 | ||
11e758a4 WD |
1132 | case OPT_ONLY_WRITE_BATCH: |
1133 | /* batch_name is already set */ | |
1134 | write_batch = -1; | |
1135 | break; | |
1136 | ||
76f79ba7 | 1137 | case OPT_READ_BATCH: |
9b3318b0 | 1138 | /* batch_name is already set */ |
6902ed17 MP |
1139 | read_batch = 1; |
1140 | break; | |
ea5164d1 | 1141 | |
0b52f94d | 1142 | case OPT_NO_ICONV: |
15dbffc2 | 1143 | #ifdef ICONV_OPTION |
0b52f94d | 1144 | iconv_opt = NULL; |
15dbffc2 | 1145 | #endif |
0b52f94d WD |
1146 | break; |
1147 | ||
7d5acf1d | 1148 | case OPT_MAX_SIZE: |
837d01dd | 1149 | if ((max_size = parse_size_arg(&max_size_arg, 'b')) <= 0) { |
e012f858 | 1150 | snprintf(err_buf, sizeof err_buf, |
7d5acf1d WD |
1151 | "--max-size value is invalid: %s\n", |
1152 | max_size_arg); | |
e012f858 | 1153 | return 0; |
7d5acf1d WD |
1154 | } |
1155 | break; | |
1156 | ||
74de13d1 WD |
1157 | case OPT_MIN_SIZE: |
1158 | if ((min_size = parse_size_arg(&min_size_arg, 'b')) <= 0) { | |
1159 | snprintf(err_buf, sizeof err_buf, | |
1160 | "--min-size value is invalid: %s\n", | |
1161 | min_size_arg); | |
1162 | return 0; | |
1163 | } | |
1164 | break; | |
1165 | ||
936fa865 WD |
1166 | case OPT_APPEND: |
1167 | if (am_server) | |
1168 | append_mode++; | |
1169 | else | |
1170 | append_mode = 1; | |
1171 | break; | |
1172 | ||
59c95e42 | 1173 | case OPT_LINK_DEST: |
fcecb70b | 1174 | #ifdef SUPPORT_HARD_LINKS |
59c95e42 | 1175 | link_dest = 1; |
e012f858 WD |
1176 | dest_option = "--link-dest"; |
1177 | goto set_dest_dir; | |
59c95e42 | 1178 | #else |
d175d7e1 | 1179 | snprintf(err_buf, sizeof err_buf, |
dfa32483 | 1180 | "hard links are not supported on this %s\n", |
59c95e42 | 1181 | am_server ? "server" : "client"); |
59c95e42 DD |
1182 | return 0; |
1183 | #endif | |
1184 | ||
1de3e99b WD |
1185 | case OPT_COPY_DEST: |
1186 | copy_dest = 1; | |
1187 | dest_option = "--copy-dest"; | |
1188 | goto set_dest_dir; | |
1189 | ||
e012f858 WD |
1190 | case OPT_COMPARE_DEST: |
1191 | compare_dest = 1; | |
1192 | dest_option = "--compare-dest"; | |
1193 | set_dest_dir: | |
3b26bba0 | 1194 | if (basis_dir_cnt >= MAX_BASIS_DIRS) { |
e012f858 WD |
1195 | snprintf(err_buf, sizeof err_buf, |
1196 | "ERROR: at most %d %s args may be specified\n", | |
1197 | MAX_BASIS_DIRS, dest_option); | |
1198 | return 0; | |
1199 | } | |
ad77db8b WD |
1200 | /* We defer sanitizing this arg until we know what |
1201 | * our destination directory is going to be. */ | |
1202 | basis_dir[basis_dir_cnt++] = (char *)poptGetOptArg(pc); | |
e012f858 WD |
1203 | break; |
1204 | ||
e16adcdf WD |
1205 | case OPT_CHMOD: |
1206 | arg = poptGetOptArg(pc); | |
bbe42182 | 1207 | if (!parse_chmod(arg, &chmod_modes)) { |
e16adcdf WD |
1208 | snprintf(err_buf, sizeof err_buf, |
1209 | "Invalid argument passed to --chmod (%s)\n", | |
1210 | arg); | |
1211 | return 0; | |
1212 | } | |
1213 | break; | |
1214 | ||
f5a910dd WD |
1215 | case OPT_HELP: |
1216 | usage(FINFO); | |
1217 | exit_cleanup(0); | |
1218 | ||
1c3344a1 WD |
1219 | case 'A': |
1220 | #ifdef SUPPORT_ACLS | |
1221 | preserve_acls = 1; | |
1222 | preserve_perms = 1; | |
1223 | break; | |
1224 | #else | |
1225 | /* FIXME: this should probably be ignored with a | |
eb8f5c74 WD |
1226 | * warning and then countermeasures taken to |
1227 | * restrict group and other access in the presence | |
1228 | * of any more restrictive ACLs, but this is safe | |
1c3344a1 WD |
1229 | * for now */ |
1230 | snprintf(err_buf,sizeof(err_buf), | |
1231 | "ACLs are not supported on this %s\n", | |
1232 | am_server ? "server" : "client"); | |
1233 | return 0; | |
1234 | #endif | |
1235 | ||
16edf865 WD |
1236 | case 'X': |
1237 | #ifdef SUPPORT_XATTRS | |
524eaa82 | 1238 | preserve_xattrs++; |
16edf865 WD |
1239 | break; |
1240 | #else | |
1241 | snprintf(err_buf,sizeof(err_buf), | |
1242 | "extended attributes are not supported on this %s\n", | |
1243 | am_server ? "server" : "client"); | |
1244 | return 0; | |
1245 | #endif | |
1c3344a1 | 1246 | |
d853783f | 1247 | default: |
55afbb52 | 1248 | /* A large opt value means that set_refuse_options() |
3671987f | 1249 | * turned this option off. */ |
c67d1386 | 1250 | if (opt >= OPT_REFUSED_BASE) { |
3671987f WD |
1251 | create_refuse_error(opt); |
1252 | return 0; | |
27ed20f7 | 1253 | } |
3671987f WD |
1254 | snprintf(err_buf, sizeof err_buf, "%s%s: %s\n", |
1255 | am_server ? "on remote machine: " : "", | |
1256 | poptBadOption(pc, POPT_BADOPTION_NOALIAS), | |
1257 | poptStrerror(opt)); | |
dfa32483 | 1258 | return 0; |
d853783f | 1259 | } |
7a6421fa | 1260 | } |
2855f61f | 1261 | |
ffbffc64 | 1262 | if (human_readable && argc == 2) { |
3ca9e5d8 | 1263 | /* Allow the old meaning of 'h' (--help) on its own. */ |
05724c07 WD |
1264 | usage(FINFO); |
1265 | exit_cleanup(0); | |
1266 | } | |
1267 | ||
332cf6df | 1268 | #ifdef ICONV_OPTION |
a4453606 | 1269 | if (iconv_opt && protect_args != 2) { |
332cf6df WD |
1270 | if (!am_server && strcmp(iconv_opt, "-") == 0) |
1271 | iconv_opt = NULL; | |
1272 | else | |
1273 | need_unsorted_flist = 1; | |
1274 | } | |
0b52f94d WD |
1275 | if (refused_no_iconv && !iconv_opt) { |
1276 | create_refuse_error(refused_no_iconv); | |
1277 | return 0; | |
1278 | } | |
332cf6df WD |
1279 | #endif |
1280 | ||
a4453606 WD |
1281 | if (protect_args == 1) { |
1282 | if (!frommain) | |
1283 | protect_args = 0; | |
1284 | else if (am_server) | |
1285 | return 1; | |
1286 | } | |
1287 | ||
4f5b0756 | 1288 | #ifndef SUPPORT_LINKS |
54e87b4b | 1289 | if (preserve_links && !am_sender) { |
e1add893 WD |
1290 | snprintf(err_buf, sizeof err_buf, |
1291 | "symlinks are not supported on this %s\n", | |
1292 | am_server ? "server" : "client"); | |
e1add893 WD |
1293 | return 0; |
1294 | } | |
1295 | #endif | |
1296 | ||
4f5b0756 | 1297 | #ifndef SUPPORT_HARD_LINKS |
e1add893 WD |
1298 | if (preserve_hard_links) { |
1299 | snprintf(err_buf, sizeof err_buf, | |
1300 | "hard links are not supported on this %s\n", | |
1301 | am_server ? "server" : "client"); | |
e1add893 WD |
1302 | return 0; |
1303 | } | |
1304 | #endif | |
1305 | ||
9439c0cb WD |
1306 | #ifndef SUPPORT_XATTRS |
1307 | if (am_root < 0) { | |
1308 | snprintf(err_buf, sizeof err_buf, | |
1309 | "--fake-super requires an rsync with extended attributes enabled\n"); | |
1310 | return 0; | |
1311 | } | |
1312 | #endif | |
1313 | ||
088aac85 | 1314 | if (write_batch && read_batch) { |
c3ea0990 | 1315 | snprintf(err_buf, sizeof err_buf, |
36119893 | 1316 | "--write-batch and --read-batch can not be used together\n"); |
c3ea0990 | 1317 | return 0; |
088aac85 | 1318 | } |
11e758a4 | 1319 | if (write_batch > 0 || read_batch) { |
94327ff0 WD |
1320 | if (am_server) { |
1321 | rprintf(FINFO, | |
1322 | "ignoring --%s-batch option sent to server\n", | |
1323 | write_batch ? "write" : "read"); | |
1324 | /* We don't actually exit_cleanup(), so that we can | |
1325 | * still service older version clients that still send | |
1326 | * batch args to server. */ | |
1327 | read_batch = write_batch = 0; | |
1328 | batch_name = NULL; | |
254ee3ba WD |
1329 | } else if (dry_run) |
1330 | write_batch = 0; | |
69e2b4ee WD |
1331 | } else if (write_batch < 0 && dry_run) |
1332 | write_batch = 0; | |
36119893 | 1333 | if (read_batch && files_from) { |
c3ea0990 | 1334 | snprintf(err_buf, sizeof err_buf, |
36119893 | 1335 | "--read-batch cannot be used with --files-from\n"); |
c3ea0990 | 1336 | return 0; |
36119893 | 1337 | } |
9b3318b0 | 1338 | if (batch_name && strlen(batch_name) > MAX_BATCH_NAME_LEN) { |
c3ea0990 | 1339 | snprintf(err_buf, sizeof err_buf, |
9b3318b0 WD |
1340 | "the batch-file name must be %d characters or less.\n", |
1341 | MAX_BATCH_NAME_LEN); | |
c3ea0990 | 1342 | return 0; |
beb93684 | 1343 | } |
088aac85 | 1344 | |
ce58b1b4 | 1345 | if (tmpdir && strlen(tmpdir) >= MAXPATHLEN - 10) { |
c3ea0990 WD |
1346 | snprintf(err_buf, sizeof err_buf, |
1347 | "the --temp-dir path is WAY too long.\n"); | |
1348 | return 0; | |
ce58b1b4 WD |
1349 | } |
1350 | ||
7b9598b2 WD |
1351 | if (max_delete < 0 && max_delete != INT_MIN) { |
1352 | /* Negative numbers are treated as "no deletions". */ | |
1353 | max_delete = 0; | |
1354 | } | |
1355 | ||
1de3e99b | 1356 | if (compare_dest + copy_dest + link_dest > 1) { |
e012f858 | 1357 | snprintf(err_buf, sizeof err_buf, |
1de3e99b | 1358 | "You may not mix --compare-dest, --copy-dest, and --link-dest.\n"); |
e012f858 WD |
1359 | return 0; |
1360 | } | |
1361 | ||
b6164938 WD |
1362 | if (files_from) { |
1363 | if (recurse == 1) /* preserve recurse == 2 */ | |
1364 | recurse = 0; | |
550d4e23 | 1365 | if (xfer_dirs < 0) |
b6164938 | 1366 | xfer_dirs = 1; |
dfa32483 | 1367 | } |
51d48398 | 1368 | |
b6164938 WD |
1369 | if (xfer_dirs < 1) |
1370 | xfer_dirs = recurse || list_only; | |
dfa32483 | 1371 | |
ea5164d1 WD |
1372 | if (relative_paths < 0) |
1373 | relative_paths = files_from? 1 : 0; | |
89f2a4c2 WD |
1374 | if (!relative_paths) |
1375 | implied_dirs = 0; | |
ea5164d1 | 1376 | |
e0e32031 | 1377 | if (delete_before + !!delete_during + delete_after > 1) { |
3359acb8 | 1378 | snprintf(err_buf, sizeof err_buf, |
c6eb7fad | 1379 | "You may not combine multiple --delete-WHEN options.\n"); |
3359acb8 WD |
1380 | return 0; |
1381 | } | |
f5a910dd | 1382 | if (delete_before || delete_during || delete_after) |
51d48398 | 1383 | delete_mode = 1; |
3296f91b | 1384 | else if (delete_mode || delete_excluded) { |
e0e32031 | 1385 | /* Only choose now between before & during if one is refused. */ |
3296f91b | 1386 | if (refused_delete_before) { |
e0e32031 WD |
1387 | if (!refused_delete_during) |
1388 | delete_during = 1; | |
1389 | else { | |
1390 | create_refuse_error(refused_delete_before); | |
1391 | return 0; | |
1392 | } | |
1393 | } else if (refused_delete_during) | |
1394 | delete_before = 1; | |
1395 | delete_mode = 1; | |
3296f91b | 1396 | } |
89fb5026 WD |
1397 | if (!xfer_dirs && delete_mode) { |
1398 | snprintf(err_buf, sizeof err_buf, | |
1399 | "--delete does not work without -r or -d.\n"); | |
1400 | return 0; | |
f5a910dd | 1401 | } |
51d48398 | 1402 | |
3671987f WD |
1403 | if (delete_mode && refused_delete) { |
1404 | create_refuse_error(refused_delete); | |
1405 | return 0; | |
1406 | } | |
1407 | ||
47c11975 WD |
1408 | if (remove_source_files) { |
1409 | /* We only want to infer this refusal of --remove-source-files | |
07c6ae7d WD |
1410 | * via the refusal of "delete", not any of the "delete-FOO" |
1411 | * options. */ | |
1412 | if (refused_delete && am_sender) { | |
1413 | create_refuse_error(refused_delete); | |
1414 | return 0; | |
1415 | } | |
1416 | need_messages_from_generator = 1; | |
1417 | } | |
1418 | ||
ffbffc64 WD |
1419 | *argv_p = argv = poptGetArgs(pc); |
1420 | *argc_p = argc = count_args(argv); | |
7be73df4 WD |
1421 | |
1422 | if (sanitize_paths) { | |
1423 | int i; | |
ffbffc64 | 1424 | for (i = argc; i-- > 0; ) |
29bca53f | 1425 | argv[i] = sanitize_path(NULL, argv[i], "", 0); |
1a7f3d99 | 1426 | if (tmpdir) |
29bca53f | 1427 | tmpdir = sanitize_path(NULL, tmpdir, NULL, 0); |
1a7f3d99 | 1428 | if (backup_dir) |
29bca53f | 1429 | backup_dir = sanitize_path(NULL, backup_dir, NULL, 0); |
7be73df4 | 1430 | } |
7842418b WD |
1431 | if (server_filter_list.head && !am_sender) { |
1432 | struct filter_list_struct *elp = &server_filter_list; | |
c3ea0990 | 1433 | if (tmpdir) { |
a1018691 | 1434 | char *dir; |
3671987f WD |
1435 | if (!*tmpdir) |
1436 | goto options_rejected; | |
a1018691 WD |
1437 | dir = tmpdir + (*tmpdir == '/' ? module_dirlen : 0); |
1438 | clean_fname(dir, CFN_COLLAPSE_DOT_DOT_DIRS); | |
1439 | if (check_filter(elp, dir, 1) < 0) | |
c3ea0990 WD |
1440 | goto options_rejected; |
1441 | } | |
c3ea0990 | 1442 | if (backup_dir) { |
a1018691 | 1443 | char *dir; |
3671987f WD |
1444 | if (!*backup_dir) |
1445 | goto options_rejected; | |
a1018691 WD |
1446 | dir = backup_dir + (*backup_dir == '/' ? module_dirlen : 0); |
1447 | clean_fname(dir, CFN_COLLAPSE_DOT_DOT_DIRS); | |
1448 | if (check_filter(elp, dir, 1) < 0) | |
f0fa8c6d | 1449 | goto options_rejected; |
c3ea0990 WD |
1450 | } |
1451 | } | |
7be73df4 | 1452 | |
d175d7e1 | 1453 | if (!backup_suffix) |
e0391f81 | 1454 | backup_suffix = backup_dir ? "" : BACKUP_SUFFIX; |
d175d7e1 | 1455 | backup_suffix_len = strlen(backup_suffix); |
80ddadb7 | 1456 | if (strchr(backup_suffix, '/') != NULL) { |
c3ea0990 WD |
1457 | snprintf(err_buf, sizeof err_buf, |
1458 | "--suffix cannot contain slashes: %s\n", | |
80ddadb7 | 1459 | backup_suffix); |
c3ea0990 | 1460 | return 0; |
80ddadb7 | 1461 | } |
e0391f81 WD |
1462 | if (backup_dir) { |
1463 | backup_dir_len = strlcpy(backup_dir_buf, backup_dir, sizeof backup_dir_buf); | |
1464 | backup_dir_remainder = sizeof backup_dir_buf - backup_dir_len; | |
1465 | if (backup_dir_remainder < 32) { | |
c3ea0990 WD |
1466 | snprintf(err_buf, sizeof err_buf, |
1467 | "the --backup-dir path is WAY too long.\n"); | |
1468 | return 0; | |
e0391f81 WD |
1469 | } |
1470 | if (backup_dir_buf[backup_dir_len - 1] != '/') { | |
1471 | backup_dir_buf[backup_dir_len++] = '/'; | |
1472 | backup_dir_buf[backup_dir_len] = '\0'; | |
1473 | } | |
0ee6ca98 WD |
1474 | if (verbose > 1 && !am_sender) |
1475 | rprintf(FINFO, "backup_dir is %s\n", backup_dir_buf); | |
8dcf9335 | 1476 | } else if (!backup_suffix_len && (!am_server || !am_sender)) { |
c3ea0990 | 1477 | snprintf(err_buf, sizeof err_buf, |
d175d7e1 | 1478 | "--suffix cannot be a null string without --backup-dir\n"); |
c3ea0990 | 1479 | return 0; |
eb8f5c74 WD |
1480 | } else if (make_backups && delete_mode && !delete_excluded && !am_server) { |
1481 | snprintf(backup_dir_buf, sizeof backup_dir_buf, | |
f41152d3 | 1482 | "P *%s", backup_suffix); |
eb8f5c74 | 1483 | parse_rule(&filter_list, backup_dir_buf, 0, 0); |
d175d7e1 | 1484 | } |
fbd91cae WD |
1485 | |
1486 | if (make_backups && !backup_dir) { | |
1487 | omit_dir_times = 0; /* Implied, so avoid -O to sender. */ | |
1488 | if (preserve_times > 1) | |
1489 | preserve_times = 1; | |
1490 | } else if (omit_dir_times) { | |
1491 | if (preserve_times > 1) | |
1492 | preserve_times = 1; | |
1493 | } | |
d175d7e1 | 1494 | |
b3e4e7ef WD |
1495 | if (stdout_format) { |
1496 | if (am_server && log_format_has(stdout_format, 'I')) | |
1497 | stdout_format_has_i = 2; | |
1498 | else if (log_format_has(stdout_format, 'i')) | |
1499 | stdout_format_has_i = itemize_changes | 1; | |
1500 | if (!log_format_has(stdout_format, 'b') | |
1501 | && !log_format_has(stdout_format, 'c')) | |
e7651884 WD |
1502 | log_before_transfer = !am_server; |
1503 | } else if (itemize_changes) { | |
b3e4e7ef WD |
1504 | stdout_format = "%i %n%L"; |
1505 | stdout_format_has_i = itemize_changes; | |
e7651884 WD |
1506 | log_before_transfer = !am_server; |
1507 | } | |
87383697 | 1508 | |
a892d905 | 1509 | if (do_progress && !verbose && !log_before_transfer && !am_server) |
e2559dbe | 1510 | verbose = 1; |
87383697 | 1511 | |
11e758a4 WD |
1512 | if (dry_run) |
1513 | do_xfers = 0; | |
1514 | ||
9ac756c6 WD |
1515 | set_io_timeout(io_timeout); |
1516 | ||
b3e4e7ef WD |
1517 | if (verbose && !stdout_format) { |
1518 | stdout_format = "%n%L"; | |
87383697 | 1519 | log_before_transfer = !am_server; |
3671987f | 1520 | } |
b3e4e7ef WD |
1521 | if (stdout_format_has_i || log_format_has(stdout_format, 'o')) |
1522 | stdout_format_has_o_or_i = 1; | |
e2559dbe | 1523 | |
232658d9 | 1524 | if (logfile_name && !am_daemon) { |
b3e4e7ef | 1525 | if (!logfile_format) { |
232658d9 | 1526 | logfile_format = "%i %n%L"; |
87c0f9d6 | 1527 | logfile_format_has_i = logfile_format_has_o_or_i = 1; |
b3e4e7ef WD |
1528 | } else { |
1529 | if (log_format_has(logfile_format, 'i')) | |
19b85876 | 1530 | logfile_format_has_i = 1; |
b3e4e7ef WD |
1531 | if (logfile_format_has_i || log_format_has(logfile_format, 'o')) |
1532 | logfile_format_has_o_or_i = 1; | |
87c0f9d6 | 1533 | } |
6dc9b74b | 1534 | log_init(0); |
2873603a WD |
1535 | } else if (!am_daemon) |
1536 | logfile_format = NULL; | |
87c0f9d6 | 1537 | |
9fb08441 WD |
1538 | if (daemon_bwlimit && (!bwlimit || bwlimit > daemon_bwlimit)) |
1539 | bwlimit = daemon_bwlimit; | |
3c74c3a3 WD |
1540 | if (bwlimit) { |
1541 | bwlimit_writemax = (size_t)bwlimit * 128; | |
1542 | if (bwlimit_writemax < 512) | |
1543 | bwlimit_writemax = 512; | |
1544 | } | |
1545 | ||
cfce9f6d | 1546 | if (sparse_files && inplace) { |
c3851185 | 1547 | /* Note: we don't check for this below, because --append is |
cfce9f6d WD |
1548 | * OK with --sparse (as long as redos are handled right). */ |
1549 | snprintf(err_buf, sizeof err_buf, | |
1550 | "--sparse cannot be used with --inplace\n"); | |
1551 | return 0; | |
1552 | } | |
1553 | ||
a015788d WD |
1554 | if (append_mode) { |
1555 | if (whole_file > 0) { | |
1556 | snprintf(err_buf, sizeof err_buf, | |
1557 | "--append cannot be used with --whole-file\n"); | |
1558 | return 0; | |
1559 | } | |
1560 | if (refused_inplace) { | |
1561 | create_refuse_error(refused_inplace); | |
1562 | return 0; | |
1563 | } | |
1564 | inplace = 1; | |
1565 | } | |
1566 | ||
f06e7082 | 1567 | if (delay_updates && !partial_dir) |
77860bac | 1568 | partial_dir = tmp_partialdir; |
f06e7082 | 1569 | |
a3221d2a | 1570 | if (inplace) { |
4f5b0756 | 1571 | #ifdef HAVE_FTRUNCATE |
a7260c40 WD |
1572 | if (partial_dir) { |
1573 | snprintf(err_buf, sizeof err_buf, | |
a015788d WD |
1574 | "--%s cannot be used with --%s\n", |
1575 | append_mode ? "append" : "inplace", | |
f06e7082 | 1576 | delay_updates ? "delay-updates" : "partial-dir"); |
a7260c40 WD |
1577 | return 0; |
1578 | } | |
3671987f WD |
1579 | /* --inplace implies --partial for refusal purposes, but we |
1580 | * clear the keep_partial flag for internal logic purposes. */ | |
1581 | if (refused_partial) { | |
1582 | create_refuse_error(refused_partial); | |
1583 | return 0; | |
1584 | } | |
a3221d2a | 1585 | keep_partial = 0; |
ded4daf0 WD |
1586 | #else |
1587 | snprintf(err_buf, sizeof err_buf, | |
a015788d WD |
1588 | "--%s is not supported on this %s\n", |
1589 | append_mode ? "append" : "inplace", | |
ded4daf0 WD |
1590 | am_server ? "server" : "client"); |
1591 | return 0; | |
1592 | #endif | |
075aa18f | 1593 | } else { |
bc880cb8 | 1594 | if (keep_partial && !partial_dir && !am_server) { |
3671987f WD |
1595 | if ((arg = getenv("RSYNC_PARTIAL_DIR")) != NULL && *arg) |
1596 | partial_dir = strdup(arg); | |
1597 | } | |
075aa18f | 1598 | if (partial_dir) { |
3671987f | 1599 | if (*partial_dir) |
b58bfb2f | 1600 | clean_fname(partial_dir, CFN_COLLAPSE_DOT_DOT_DIRS); |
075aa18f WD |
1601 | if (!*partial_dir || strcmp(partial_dir, ".") == 0) |
1602 | partial_dir = NULL; | |
3671987f WD |
1603 | if (!partial_dir && refused_partial) { |
1604 | create_refuse_error(refused_partial); | |
1605 | return 0; | |
1606 | } | |
075aa18f WD |
1607 | keep_partial = 1; |
1608 | } | |
a3221d2a WD |
1609 | } |
1610 | ||
ea5164d1 | 1611 | if (files_from) { |
305666bf WD |
1612 | char *h, *p; |
1613 | int q; | |
ffbffc64 | 1614 | if (argc > 2 || (!am_daemon && argc == 1)) { |
ea5164d1 WD |
1615 | usage(FERROR); |
1616 | exit_cleanup(RERR_SYNTAX); | |
1617 | } | |
63596e1c | 1618 | if (strcmp(files_from, "-") == 0) { |
ea5164d1 | 1619 | filesfrom_fd = 0; |
63596e1c | 1620 | if (am_server) |
305666bf WD |
1621 | filesfrom_host = ""; /* reading from socket */ |
1622 | } else if ((p = check_for_hostspec(files_from, &h, &q)) != 0) { | |
ea5164d1 | 1623 | if (am_server) { |
305666bf WD |
1624 | snprintf(err_buf, sizeof err_buf, |
1625 | "The --files-from sent to the server cannot specify a host.\n"); | |
1626 | return 0; | |
ea5164d1 | 1627 | } |
305666bf WD |
1628 | files_from = p; |
1629 | filesfrom_host = h; | |
1630 | if (strcmp(files_from, "-") == 0) { | |
c3ea0990 WD |
1631 | snprintf(err_buf, sizeof err_buf, |
1632 | "Invalid --files-from remote filename\n"); | |
1633 | return 0; | |
ea5164d1 WD |
1634 | } |
1635 | } else { | |
305666bf | 1636 | if (sanitize_paths) |
29bca53f | 1637 | files_from = sanitize_path(NULL, files_from, NULL, 0); |
305666bf | 1638 | if (server_filter_list.head) { |
a1018691 | 1639 | char *dir; |
305666bf WD |
1640 | if (!*files_from) |
1641 | goto options_rejected; | |
a1018691 WD |
1642 | dir = files_from + (*files_from == '/' ? module_dirlen : 0); |
1643 | clean_fname(dir, CFN_COLLAPSE_DOT_DOT_DIRS); | |
1644 | if (check_filter(&server_filter_list, dir, 0) < 0) | |
305666bf WD |
1645 | goto options_rejected; |
1646 | } | |
ea5164d1 WD |
1647 | filesfrom_fd = open(files_from, O_RDONLY|O_BINARY); |
1648 | if (filesfrom_fd < 0) { | |
c3ea0990 WD |
1649 | snprintf(err_buf, sizeof err_buf, |
1650 | "failed to open files-from file %s: %s\n", | |
1651 | files_from, strerror(errno)); | |
1652 | return 0; | |
ea5164d1 WD |
1653 | } |
1654 | } | |
1655 | } | |
1656 | ||
7f2a1f65 WD |
1657 | am_starting_up = 0; |
1658 | ||
b11ed3b1 | 1659 | return 1; |
f0fa8c6d WD |
1660 | |
1661 | options_rejected: | |
1662 | snprintf(err_buf, sizeof err_buf, | |
1663 | "Your options have been rejected by the server.\n"); | |
1664 | return 0; | |
7a6421fa AT |
1665 | } |
1666 | ||
1667 | ||
dafe63ca MP |
1668 | /** |
1669 | * Construct a filtered list of options to pass through from the | |
1670 | * client to the server. | |
1671 | * | |
1672 | * This involves setting options that will tell the server how to | |
1673 | * behave, and also filtering out options that are processed only | |
1674 | * locally. | |
1675 | **/ | |
ffbffc64 | 1676 | void server_options(char **args, int *argc_p) |
7a6421fa | 1677 | { |
74ba98a5 | 1678 | static char argstr[64]; |
ffbffc64 | 1679 | int ac = *argc_p; |
f98c60bf | 1680 | char *arg; |
d853783f AT |
1681 | int i, x; |
1682 | ||
def97ff9 | 1683 | /* This should always remain first on the server's command-line. */ |
d853783f AT |
1684 | args[ac++] = "--server"; |
1685 | ||
e208631a | 1686 | if (daemon_over_rsh > 0) { |
1312d9fc | 1687 | args[ac++] = "--daemon"; |
ffbffc64 | 1688 | *argc_p = ac; |
1312d9fc WD |
1689 | /* if we're passing --daemon, we're done */ |
1690 | return; | |
1691 | } | |
1692 | ||
d853783f AT |
1693 | if (!am_sender) |
1694 | args[ac++] = "--sender"; | |
1695 | ||
1696 | x = 1; | |
1697 | argstr[0] = '-'; | |
a4453606 WD |
1698 | |
1699 | if (protect_args) | |
1700 | argstr[x++] = 's'; | |
1701 | ||
f98c60bf | 1702 | for (i = 0; i < verbose; i++) |
d853783f | 1703 | argstr[x++] = 'v'; |
f0b36a48 | 1704 | |
b86f0cef | 1705 | /* the -q option is intentionally left out */ |
d853783f AT |
1706 | if (make_backups) |
1707 | argstr[x++] = 'b'; | |
1708 | if (update_only) | |
1709 | argstr[x++] = 'u'; | |
2dbf36ef | 1710 | if (!do_xfers) /* Note: NOT "dry_run"! */ |
d853783f AT |
1711 | argstr[x++] = 'n'; |
1712 | if (preserve_links) | |
1713 | argstr[x++] = 'l'; | |
3caf4035 WD |
1714 | if ((list_only && !recurse) || xfer_dirs > 1 |
1715 | || (xfer_dirs && !recurse && delete_mode && am_sender)) | |
5454d22a | 1716 | argstr[x++] = 'd'; |
35bf8fa0 WD |
1717 | if (am_sender) { |
1718 | if (keep_dirlinks) | |
1719 | argstr[x++] = 'K'; | |
876c9936 WD |
1720 | if (prune_empty_dirs) |
1721 | argstr[x++] = 'm'; | |
f9998046 | 1722 | if (omit_dir_times) |
35bf8fa0 | 1723 | argstr[x++] = 'O'; |
2dbf36ef WD |
1724 | } else { |
1725 | if (copy_links) | |
1726 | argstr[x++] = 'L'; | |
1727 | if (copy_dirlinks) | |
1728 | argstr[x++] = 'k'; | |
35bf8fa0 | 1729 | } |
1bfbf40b | 1730 | |
dfa32483 | 1731 | if (whole_file > 0) |
d853783f | 1732 | argstr[x++] = 'W'; |
bceec82f MP |
1733 | /* We don't need to send --no-whole-file, because it's the |
1734 | * default for remote transfers, and in any case old versions | |
1735 | * of rsync will not understand it. */ | |
dfa32483 | 1736 | |
e0e32031 | 1737 | if (preserve_hard_links) { |
d853783f | 1738 | argstr[x++] = 'H'; |
e0e32031 WD |
1739 | if (preserve_hard_links > 1) |
1740 | argstr[x++] = 'H'; | |
1741 | } | |
d853783f AT |
1742 | if (preserve_uid) |
1743 | argstr[x++] = 'o'; | |
1744 | if (preserve_gid) | |
1745 | argstr[x++] = 'g'; | |
b5c6a6ae | 1746 | if (preserve_devices) /* ignore preserve_specials here */ |
d853783f AT |
1747 | argstr[x++] = 'D'; |
1748 | if (preserve_times) | |
1749 | argstr[x++] = 't'; | |
1750 | if (preserve_perms) | |
1751 | argstr[x++] = 'p'; | |
344f9ba7 WD |
1752 | else if (preserve_executability && am_sender) |
1753 | argstr[x++] = 'E'; | |
1c3344a1 WD |
1754 | #ifdef SUPPORT_ACLS |
1755 | if (preserve_acls) | |
1756 | argstr[x++] = 'A'; | |
16edf865 WD |
1757 | #endif |
1758 | #ifdef SUPPORT_XATTRS | |
524eaa82 | 1759 | if (preserve_xattrs) { |
16edf865 | 1760 | argstr[x++] = 'X'; |
524eaa82 WD |
1761 | if (preserve_xattrs > 1) |
1762 | argstr[x++] = 'X'; | |
1763 | } | |
1c3344a1 | 1764 | #endif |
aa7a6e87 | 1765 | if (recurse) |
d853783f AT |
1766 | argstr[x++] = 'r'; |
1767 | if (always_checksum) | |
1768 | argstr[x++] = 'c'; | |
1769 | if (cvs_exclude) | |
1770 | argstr[x++] = 'C'; | |
1771 | if (ignore_times) | |
1772 | argstr[x++] = 'I'; | |
1773 | if (relative_paths) | |
1774 | argstr[x++] = 'R'; | |
243c995f | 1775 | if (one_file_system) { |
d853783f | 1776 | argstr[x++] = 'x'; |
243c995f WD |
1777 | if (one_file_system > 1) |
1778 | argstr[x++] = 'x'; | |
1779 | } | |
d853783f AT |
1780 | if (sparse_files) |
1781 | argstr[x++] = 'S'; | |
1782 | if (do_compression) | |
1783 | argstr[x++] = 'z'; | |
f0b36a48 | 1784 | |
95def6d9 | 1785 | /* We make use of the -e option to let the server know about any |
1ed56a05 WD |
1786 | * pre-release protocol version && some behavior flags. */ |
1787 | argstr[x++] = 'e'; | |
2ed790f3 | 1788 | #if SUBPROTOCOL_VERSION != 0 |
2ed790f3 | 1789 | if (protocol_version == PROTOCOL_VERSION) { |
486f8cd1 | 1790 | x += snprintf(argstr+x, sizeof argstr - x, |
1ed56a05 | 1791 | "%d.%d", PROTOCOL_VERSION, SUBPROTOCOL_VERSION); |
95def6d9 | 1792 | } else |
2ed790f3 | 1793 | #endif |
1ed56a05 WD |
1794 | argstr[x++] = '.'; |
1795 | set_allow_inc_recurse(); | |
1796 | if (allow_inc_recurse) | |
95def6d9 | 1797 | argstr[x++] = 'i'; |
1ed56a05 WD |
1798 | #if defined HAVE_LUTIMES && defined HAVE_UTIMES |
1799 | argstr[x++] = 'L'; | |
1800 | #endif | |
332cf6df WD |
1801 | argstr[x] = '\0'; |
1802 | ||
1ed56a05 | 1803 | args[ac++] = argstr; |
d853783f | 1804 | |
a4453606 WD |
1805 | #ifdef ICONV_OPTION |
1806 | if (iconv_opt) { | |
1807 | char *set = strchr(iconv_opt, ','); | |
1808 | if (set) | |
1809 | set++; | |
1810 | else | |
1811 | set = iconv_opt; | |
1812 | if (asprintf(&arg, "--iconv=%s", set) < 0) | |
1813 | goto oom; | |
1814 | args[ac++] = arg; | |
1815 | } | |
1816 | #endif | |
1817 | ||
1818 | if (protect_args) /* initial args break here */ | |
1819 | args[ac++] = NULL; | |
1820 | ||
51d48398 WD |
1821 | if (list_only > 1) |
1822 | args[ac++] = "--list-only"; | |
1823 | ||
f5a910dd WD |
1824 | /* This makes sure that the remote rsync can handle deleting with -d |
1825 | * sans -r because the --no-r option was added at the same time. */ | |
1826 | if (xfer_dirs && !recurse && delete_mode && am_sender) | |
1827 | args[ac++] = "--no-r"; | |
1828 | ||
854a1aad WD |
1829 | if (do_compression && def_compress_level != Z_DEFAULT_COMPRESSION) { |
1830 | if (asprintf(&arg, "--compress-level=%d", def_compress_level) < 0) | |
1831 | goto oom; | |
1832 | args[ac++] = arg; | |
1833 | } | |
1834 | ||
b5c6a6ae WD |
1835 | if (preserve_devices) { |
1836 | /* Note: sending "--devices" would not be backward-compatible. */ | |
1837 | if (!preserve_specials) | |
1838 | args[ac++] = "--no-specials"; /* -D is already set. */ | |
1839 | } else if (preserve_specials) | |
1840 | args[ac++] = "--specials"; | |
1841 | ||
5c5e1598 WD |
1842 | /* The server side doesn't use our log-format, but in certain |
1843 | * circumstances they need to know a little about the option. */ | |
b3e4e7ef WD |
1844 | if (stdout_format && am_sender) { |
1845 | /* Use --log-format, not --out-format, for compatibility. */ | |
1846 | if (stdout_format_has_i > 1) | |
487094a0 | 1847 | args[ac++] = "--log-format=%i%I"; |
b3e4e7ef | 1848 | else if (stdout_format_has_i) |
684d7582 | 1849 | args[ac++] = "--log-format=%i"; |
b3e4e7ef | 1850 | else if (stdout_format_has_o_or_i) |
5c5e1598 WD |
1851 | args[ac++] = "--log-format=%o"; |
1852 | else if (!verbose) | |
1853 | args[ac++] = "--log-format=X"; | |
1854 | } | |
1f30a674 | 1855 | |
195bd906 | 1856 | if (block_size) { |
a06b419d | 1857 | if (asprintf(&arg, "-B%lu", block_size) < 0) |
f98c60bf WD |
1858 | goto oom; |
1859 | args[ac++] = arg; | |
dfa32483 | 1860 | } |
d853783f AT |
1861 | |
1862 | if (io_timeout) { | |
f98c60bf WD |
1863 | if (asprintf(&arg, "--timeout=%d", io_timeout) < 0) |
1864 | goto oom; | |
1865 | args[ac++] = arg; | |
dfa32483 | 1866 | } |
d853783f | 1867 | |
ef5d23eb | 1868 | if (bwlimit) { |
f98c60bf WD |
1869 | if (asprintf(&arg, "--bwlimit=%d", bwlimit) < 0) |
1870 | goto oom; | |
1871 | args[ac++] = arg; | |
ef5d23eb DD |
1872 | } |
1873 | ||
d175d7e1 WD |
1874 | if (backup_dir) { |
1875 | args[ac++] = "--backup-dir"; | |
1876 | args[ac++] = backup_dir; | |
1877 | } | |
1878 | ||
1879 | /* Only send --suffix if it specifies a non-default value. */ | |
f98c60bf | 1880 | if (strcmp(backup_suffix, backup_dir ? "" : BACKUP_SUFFIX) != 0) { |
191e40da | 1881 | /* We use the following syntax to avoid weirdness with '~'. */ |
f98c60bf WD |
1882 | if (asprintf(&arg, "--suffix=%s", backup_suffix) < 0) |
1883 | goto oom; | |
1884 | args[ac++] = arg; | |
d853783f AT |
1885 | } |
1886 | ||
06a50542 | 1887 | if (am_sender) { |
7b9598b2 WD |
1888 | if (max_delete > 0) { |
1889 | if (asprintf(&arg, "--max-delete=%d", max_delete) < 0) | |
1890 | goto oom; | |
1891 | args[ac++] = arg; | |
1892 | } else if (max_delete == 0) | |
d6ca255c | 1893 | args[ac++] = "--max-delete=-1"; |
7b9598b2 WD |
1894 | if (min_size) { |
1895 | args[ac++] = "--min-size"; | |
1896 | args[ac++] = min_size_arg; | |
1897 | } | |
1898 | if (max_size) { | |
1899 | args[ac++] = "--max-size"; | |
1900 | args[ac++] = max_size_arg; | |
1901 | } | |
e0e32031 | 1902 | if (delete_before) |
c6eb7fad | 1903 | args[ac++] = "--delete-before"; |
0d152437 WD |
1904 | else if (delete_during == 2) |
1905 | args[ac++] = "--delete-delay"; | |
1906 | else if (delete_during) | |
1907 | args[ac++] = "--delete-during"; | |
1908 | else if (delete_after) | |
06a50542 | 1909 | args[ac++] = "--delete-after"; |
e0e32031 WD |
1910 | else if (delete_mode && !delete_excluded) |
1911 | args[ac++] = "--delete"; | |
1912 | if (delete_excluded) | |
1913 | args[ac++] = "--delete-excluded"; | |
06a50542 WD |
1914 | if (force_delete) |
1915 | args[ac++] = "--force"; | |
11e758a4 WD |
1916 | if (write_batch < 0) |
1917 | args[ac++] = "--only-write-batch=X"; | |
def97ff9 WD |
1918 | if (am_root > 1) |
1919 | args[ac++] = "--super"; | |
f17e769e WD |
1920 | if (size_only) |
1921 | args[ac++] = "--size-only"; | |
b1e436ec WD |
1922 | } else { |
1923 | if (skip_compress) { | |
1924 | if (asprintf(&arg, "--skip-compress=%s", skip_compress) < 0) | |
1925 | goto oom; | |
1926 | args[ac++] = arg; | |
1927 | } | |
06a50542 | 1928 | } |
b33b791e | 1929 | |
5b56cc19 | 1930 | if (modify_window_set) { |
f98c60bf WD |
1931 | if (asprintf(&arg, "--modify-window=%d", modify_window) < 0) |
1932 | goto oom; | |
1933 | args[ac++] = arg; | |
5b56cc19 AT |
1934 | } |
1935 | ||
c8d895de | 1936 | if (checksum_seed) { |
221ddb94 | 1937 | if (asprintf(&arg, "--checksum-seed=%d", checksum_seed) < 0) |
c8d895de WD |
1938 | goto oom; |
1939 | args[ac++] = arg; | |
1940 | } | |
1941 | ||
a7260c40 | 1942 | if (partial_dir && am_sender) { |
77860bac | 1943 | if (partial_dir != tmp_partialdir) { |
3671987f WD |
1944 | args[ac++] = "--partial-dir"; |
1945 | args[ac++] = partial_dir; | |
1946 | } | |
f06e7082 WD |
1947 | if (delay_updates) |
1948 | args[ac++] = "--delay-updates"; | |
77860bac | 1949 | } else if (keep_partial && am_sender) |
d853783f AT |
1950 | args[ac++] = "--partial"; |
1951 | ||
ef55c686 AT |
1952 | if (ignore_errors) |
1953 | args[ac++] = "--ignore-errors"; | |
1954 | ||
b5313607 DD |
1955 | if (copy_unsafe_links) |
1956 | args[ac++] = "--copy-unsafe-links"; | |
1957 | ||
d853783f AT |
1958 | if (safe_symlinks) |
1959 | args[ac++] = "--safe-links"; | |
1960 | ||
1961 | if (numeric_ids) | |
1962 | args[ac++] = "--numeric-ids"; | |
1963 | ||
95def6d9 WD |
1964 | if (use_qsort) |
1965 | args[ac++] = "--use-qsort"; | |
1966 | ||
4f3797c7 WD |
1967 | if (am_sender) { |
1968 | if (ignore_existing) | |
1969 | args[ac++] = "--ignore-existing"; | |
1970 | ||
1971 | /* Backward compatibility: send --existing, not --ignore-non-existing. */ | |
1972 | if (ignore_non_existing) | |
1973 | args[ac++] = "--existing"; | |
3d6feada | 1974 | |
4f3797c7 WD |
1975 | if (tmpdir) { |
1976 | args[ac++] = "--temp-dir"; | |
1977 | args[ac++] = tmpdir; | |
1978 | } | |
1979 | ||
1980 | if (basis_dir[0]) { | |
1981 | /* the server only needs this option if it is not the sender, | |
1982 | * and it may be an older version that doesn't know this | |
1983 | * option, so don't send it if client is the sender. | |
1984 | */ | |
1985 | int i; | |
1986 | for (i = 0; i < basis_dir_cnt; i++) { | |
1987 | args[ac++] = dest_option; | |
1988 | args[ac++] = basis_dir[i]; | |
1989 | } | |
1990 | } | |
1991 | } | |
e90aab49 | 1992 | |
936fa865 WD |
1993 | if (append_mode) { |
1994 | if (append_mode > 1) | |
1995 | args[ac++] = "--append"; | |
a015788d | 1996 | args[ac++] = "--append"; |
936fa865 | 1997 | } else if (inplace) |
a3221d2a WD |
1998 | args[ac++] = "--inplace"; |
1999 | ||
305666bf WD |
2000 | if (files_from && (!am_sender || filesfrom_host)) { |
2001 | if (filesfrom_host) { | |
ea5164d1 | 2002 | args[ac++] = "--files-from"; |
305666bf | 2003 | args[ac++] = files_from; |
ea5164d1 WD |
2004 | if (eol_nulls) |
2005 | args[ac++] = "--from0"; | |
2006 | } else { | |
2007 | args[ac++] = "--files-from=-"; | |
2008 | args[ac++] = "--from0"; | |
2009 | } | |
c0ab28d1 WD |
2010 | if (!relative_paths) |
2011 | args[ac++] = "--no-relative"; | |
ea5164d1 | 2012 | } |
33a04593 WD |
2013 | /* It's OK that this checks the upper-bound of the protocol_version. */ |
2014 | if (relative_paths && !implied_dirs && (!am_sender || protocol_version >= 30)) | |
3a90ea0a | 2015 | args[ac++] = "--no-implied-dirs"; |
ea5164d1 | 2016 | |
c4ed1487 WD |
2017 | if (fuzzy_basis && am_sender) |
2018 | args[ac++] = "--fuzzy"; | |
2019 | ||
47c11975 WD |
2020 | if (remove_source_files == 1) |
2021 | args[ac++] = "--remove-source-files"; | |
2022 | else if (remove_source_files) | |
07c6ae7d WD |
2023 | args[ac++] = "--remove-sent-files"; |
2024 | ||
ffbffc64 | 2025 | *argc_p = ac; |
f98c60bf WD |
2026 | return; |
2027 | ||
2028 | oom: | |
2029 | out_of_memory("server_options"); | |
7a6421fa AT |
2030 | } |
2031 | ||
305666bf WD |
2032 | /* Look for a HOST specfication of the form "HOST:PATH", "HOST::PATH", or |
2033 | * "rsync://HOST:PORT/PATH". If found, *host_ptr will be set to some allocated | |
2034 | * memory with the HOST. If a daemon-accessing spec was specified, the value | |
2035 | * of *port_ptr will contain a non-0 port number, otherwise it will be set to | |
2036 | * 0. The return value is a pointer to the PATH. Note that the HOST spec can | |
2037 | * be an IPv6 literal address enclosed in '[' and ']' (such as "[::1]" or | |
2038 | * "[::ffff:127.0.0.1]") which is returned without the '[' and ']'. */ | |
2039 | char *check_for_hostspec(char *s, char **host_ptr, int *port_ptr) | |
ea5164d1 | 2040 | { |
305666bf WD |
2041 | char *p; |
2042 | int not_host; | |
8f4ae68c | 2043 | int hostlen; |
305666bf WD |
2044 | |
2045 | if (port_ptr && strncasecmp(URL_PREFIX, s, strlen(URL_PREFIX)) == 0) { | |
2046 | char *path; | |
305666bf WD |
2047 | s += strlen(URL_PREFIX); |
2048 | if ((p = strchr(s, '/')) != NULL) { | |
2049 | hostlen = p - s; | |
2050 | path = p + 1; | |
2051 | } else { | |
2052 | hostlen = strlen(s); | |
2053 | path = ""; | |
2054 | } | |
2055 | if (*s == '[' && (p = strchr(s, ']')) != NULL) { | |
2056 | s++; | |
2057 | hostlen = p - s; | |
c60b7056 WD |
2058 | if (p[1] == ':') |
2059 | *port_ptr = atoi(p+2); | |
305666bf | 2060 | } else { |
444f9f7b | 2061 | if ((p = strchr(s, ':')) != NULL && p < s + hostlen) { |
305666bf WD |
2062 | hostlen = p - s; |
2063 | *port_ptr = atoi(p+1); | |
c60b7056 | 2064 | } |
305666bf | 2065 | } |
c60b7056 WD |
2066 | if (!*port_ptr) |
2067 | *port_ptr = RSYNC_PORT; | |
305666bf WD |
2068 | *host_ptr = new_array(char, hostlen + 1); |
2069 | strlcpy(*host_ptr, s, hostlen + 1); | |
2070 | return path; | |
2071 | } | |
ea5164d1 | 2072 | |
305666bf | 2073 | if (*s == '[' && (p = strchr(s, ']')) != NULL && p[1] == ':') { |
8f4ae68c WD |
2074 | s++; |
2075 | hostlen = p - s; | |
305666bf WD |
2076 | *p = '\0'; |
2077 | not_host = strchr(s, '/') || !strchr(s, ':'); | |
2078 | *p = ']'; | |
2079 | if (not_host) | |
2080 | return NULL; | |
c60b7056 | 2081 | p++; |
305666bf WD |
2082 | } else { |
2083 | if (!(p = strchr(s, ':'))) | |
2084 | return NULL; | |
8f4ae68c | 2085 | hostlen = p - s; |
305666bf WD |
2086 | *p = '\0'; |
2087 | not_host = strchr(s, '/') != NULL; | |
2088 | *p = ':'; | |
2089 | if (not_host) | |
2090 | return NULL; | |
2091 | } | |
2092 | ||
8f4ae68c WD |
2093 | *host_ptr = new_array(char, hostlen + 1); |
2094 | strlcpy(*host_ptr, s, hostlen + 1); | |
ea5164d1 | 2095 | |
305666bf WD |
2096 | if (p[1] == ':') { |
2097 | if (port_ptr && !*port_ptr) | |
2098 | *port_ptr = RSYNC_PORT; | |
2099 | return p + 2; | |
2100 | } | |
2101 | if (port_ptr) | |
2102 | *port_ptr = 0; | |
ea5164d1 | 2103 | |
305666bf | 2104 | return p + 1; |
ea5164d1 | 2105 | } |