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