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