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