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