Added an "ndx" arg to all the finish_hard_link() calls.
[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 },
8487f9cf
WD
464 {"ir", 0, POPT_ARG_VAL, &allow_inc_recurse, 1, 0, 0 },
465 {"no-ir", 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 },
e16adcdf 517 {"chmod", 0, POPT_ARG_STRING, 0, OPT_CHMOD, 0, 0 },
afb6e945
WD
518 {"ignore-times", 'I', POPT_ARG_NONE, &ignore_times, 0, 0, 0 },
519 {"size-only", 0, POPT_ARG_NONE, &size_only, 0, 0, 0 },
243c995f 520 {"one-file-system", 'x', POPT_ARG_NONE, 0, 'x', 0, 0 },
e86e2fa1 521 {"update", 'u', POPT_ARG_NONE, &update_only, 0, 0, 0 },
e90aab49 522 {"existing", 0, POPT_ARG_NONE, &ignore_non_existing, 0, 0, 0 },
e90aab49 523 {"ignore-non-existing",0,POPT_ARG_NONE, &ignore_non_existing, 0, 0, 0 },
d2da915c 524 {"ignore-existing", 0, POPT_ARG_NONE, &ignore_existing, 0, 0, 0 },
aeb213ea 525 {"max-size", 0, POPT_ARG_STRING, &max_size_arg, OPT_MAX_SIZE, 0, 0 },
74de13d1 526 {"min-size", 0, POPT_ARG_STRING, &min_size_arg, OPT_MIN_SIZE, 0, 0 },
e86e2fa1
WD
527 {"sparse", 'S', POPT_ARG_NONE, &sparse_files, 0, 0, 0 },
528 {"inplace", 0, POPT_ARG_NONE, &inplace, 0, 0, 0 },
936fa865
WD
529 {"append", 0, POPT_ARG_NONE, 0, OPT_APPEND, 0, 0 },
530 {"append-verify", 0, POPT_ARG_VAL, &append_mode, 2, 0, 0 },
531 {"no-append", 0, POPT_ARG_VAL, &append_mode, 0, 0, 0 },
3671987f 532 {"del", 0, POPT_ARG_NONE, &delete_during, 0, 0, 0 },
3359acb8 533 {"delete", 0, POPT_ARG_NONE, &delete_mode, 0, 0, 0 },
e0e32031 534 {"delete-before", 0, POPT_ARG_NONE, &delete_before, 0, 0, 0 },
b0cacef1
WD
535 {"delete-during", 0, POPT_ARG_VAL, &delete_during, 1, 0, 0 },
536 {"delete-delay", 0, POPT_ARG_VAL, &delete_during, 2, 0, 0 },
51d48398
WD
537 {"delete-after", 0, POPT_ARG_NONE, &delete_after, 0, 0, 0 },
538 {"delete-excluded", 0, POPT_ARG_NONE, &delete_excluded, 0, 0, 0 },
47c11975
WD
539 {"remove-sent-files",0, POPT_ARG_VAL, &remove_source_files, 2, 0, 0 }, /* deprecated */
540 {"remove-source-files",0,POPT_ARG_VAL, &remove_source_files, 1, 0, 0 },
afb6e945 541 {"force", 0, POPT_ARG_NONE, &force_delete, 0, 0, 0 },
e86e2fa1
WD
542 {"ignore-errors", 0, POPT_ARG_NONE, &ignore_errors, 0, 0, 0 },
543 {"max-delete", 0, POPT_ARG_INT, &max_delete, 0, 0, 0 },
544 {0, 'F', POPT_ARG_NONE, 0, 'F', 0, 0 },
aa4d3b4c 545 {"filter", 'f', POPT_ARG_STRING, 0, OPT_FILTER, 0, 0 },
8db7cc2c
WD
546 {"exclude", 0, POPT_ARG_STRING, 0, OPT_EXCLUDE, 0, 0 },
547 {"include", 0, POPT_ARG_STRING, 0, OPT_INCLUDE, 0, 0 },
548 {"exclude-from", 0, POPT_ARG_STRING, 0, OPT_EXCLUDE_FROM, 0, 0 },
549 {"include-from", 0, POPT_ARG_STRING, 0, OPT_INCLUDE_FROM, 0, 0 },
afb6e945 550 {"cvs-exclude", 'C', POPT_ARG_NONE, &cvs_exclude, 0, 0, 0 },
afb6e945
WD
551 {"whole-file", 'W', POPT_ARG_VAL, &whole_file, 1, 0, 0 },
552 {"no-whole-file", 0, POPT_ARG_VAL, &whole_file, 0, 0, 0 },
b6164938 553 {"no-W", 0, POPT_ARG_VAL, &whole_file, 0, 0, 0 },
8487f9cf
WD
554 {"checksum", 'c', POPT_ARG_VAL, &always_checksum, 1, 0, 0 },
555 {"no-checksum", 0, POPT_ARG_VAL, &always_checksum, 0, 0, 0 },
556 {"no-c", 0, POPT_ARG_VAL, &always_checksum, 0, 0, 0 },
a06b419d 557 {"block-size", 'B', POPT_ARG_LONG, &block_size, 0, 0, 0 },
e012f858 558 {"compare-dest", 0, POPT_ARG_STRING, 0, OPT_COMPARE_DEST, 0, 0 },
1de3e99b 559 {"copy-dest", 0, POPT_ARG_STRING, 0, OPT_COPY_DEST, 0, 0 },
e012f858 560 {"link-dest", 0, POPT_ARG_STRING, 0, OPT_LINK_DEST, 0, 0 },
c4ed1487 561 {"fuzzy", 'y', POPT_ARG_NONE, &fuzzy_basis, 0, 0, 0 },
854a1aad 562 {"compress", 'z', POPT_ARG_NONE, 0, 'z', 0, 0 },
8487f9cf 563 {"no-compress", 0, POPT_ARG_VAL, &do_compression, 0, 0, 0 },
b1e436ec 564 {"skip-compress", 0, POPT_ARG_STRING, &skip_compress, 0, 0, 0 },
8487f9cf 565 {"no-z", 0, POPT_ARG_VAL, &do_compression, 0, 0, 0 },
854a1aad 566 {"compress-level", 0, POPT_ARG_INT, &def_compress_level, 'z', 0, 0 },
11bfaf63 567 {0, 'P', POPT_ARG_NONE, 0, 'P', 0, 0 },
b6164938
WD
568 {"progress", 0, POPT_ARG_VAL, &do_progress, 1, 0, 0 },
569 {"no-progress", 0, POPT_ARG_VAL, &do_progress, 0, 0, 0 },
570 {"partial", 0, POPT_ARG_VAL, &keep_partial, 1, 0, 0 },
571 {"no-partial", 0, POPT_ARG_VAL, &keep_partial, 0, 0, 0 },
a7260c40 572 {"partial-dir", 0, POPT_ARG_STRING, &partial_dir, 0, 0, 0 },
8487f9cf
WD
573 {"delay-updates", 0, POPT_ARG_VAL, &delay_updates, 1, 0, 0 },
574 {"no-delay-updates", 0, POPT_ARG_VAL, &delay_updates, 0, 0, 0 },
876c9936 575 {"prune-empty-dirs",'m', POPT_ARG_NONE, &prune_empty_dirs, 0, 0, 0 },
87c0f9d6 576 {"log-file", 0, POPT_ARG_STRING, &logfile_name, 0, 0, 0 },
b3e4e7ef
WD
577 {"log-file-format", 0, POPT_ARG_STRING, &logfile_format, 0, 0, 0 },
578 {"out-format", 0, POPT_ARG_STRING, &stdout_format, 0, 0, 0 },
579 {"log-format", 0, POPT_ARG_STRING, &stdout_format, 0, 0, 0 }, /* DEPRECATED */
487094a0 580 {"itemize-changes", 'i', POPT_ARG_NONE, 0, 'i', 0, 0 },
8487f9cf
WD
581 {"no-itemize-changes",0, POPT_ARG_VAL, &itemize_changes, 0, 0, 0 },
582 {"no-i", 0, POPT_ARG_VAL, &itemize_changes, 0, 0, 0 },
afb6e945 583 {"bwlimit", 0, POPT_ARG_INT, &bwlimit, 0, 0, 0 },
8487f9cf
WD
584 {"no-bwlimit", 0, POPT_ARG_VAL, &bwlimit, 0, 0, 0 },
585 {"backup", 'b', POPT_ARG_VAL, &make_backups, 1, 0, 0 },
586 {"no-backup", 0, POPT_ARG_VAL, &make_backups, 0, 0, 0 },
afb6e945 587 {"backup-dir", 0, POPT_ARG_STRING, &backup_dir, 0, 0, 0 },
e86e2fa1
WD
588 {"suffix", 0, POPT_ARG_STRING, &backup_suffix, 0, 0, 0 },
589 {"list-only", 0, POPT_ARG_VAL, &list_only, 2, 0, 0 },
8db7cc2c
WD
590 {"read-batch", 0, POPT_ARG_STRING, &batch_name, OPT_READ_BATCH, 0, 0 },
591 {"write-batch", 0, POPT_ARG_STRING, &batch_name, OPT_WRITE_BATCH, 0, 0 },
11e758a4 592 {"only-write-batch", 0, POPT_ARG_STRING, &batch_name, OPT_ONLY_WRITE_BATCH, 0, 0 },
ea5164d1 593 {"files-from", 0, POPT_ARG_STRING, &files_from, 0, 0, 0 },
8487f9cf
WD
594 {"from0", '0', POPT_ARG_VAL, &eol_nulls, 1, 0, 0},
595 {"no-from0", 0, POPT_ARG_VAL, &eol_nulls, 0, 0, 0},
c35d6e35
WD
596 {"protect-args", 's', POPT_ARG_VAL, &protect_args, 1, 0, 0},
597 {"no-protect-args", 0, POPT_ARG_VAL, &protect_args, 0, 0, 0},
598 {"no-s", 0, POPT_ARG_VAL, &protect_args, 0, 0, 0},
8487f9cf
WD
599 {"numeric-ids", 0, POPT_ARG_VAL, &numeric_ids, 1, 0, 0 },
600 {"no-numeric-ids", 0, POPT_ARG_VAL, &numeric_ids, 0, 0, 0 },
e86e2fa1 601 {"timeout", 0, POPT_ARG_INT, &io_timeout, 0, 0, 0 },
8487f9cf 602 {"no-timeout", 0, POPT_ARG_VAL, &io_timeout, 0, 0, 0 },
e86e2fa1
WD
603 {"rsh", 'e', POPT_ARG_STRING, &shell_cmd, 0, 0, 0 },
604 {"rsync-path", 0, POPT_ARG_STRING, &rsync_path, 0, 0, 0 },
605 {"temp-dir", 'T', POPT_ARG_STRING, &tmpdir, 0, 0, 0 },
332cf6df
WD
606#ifdef ICONV_OPTION
607 {"iconv", 0, POPT_ARG_STRING, &iconv_opt, 0, 0, 0 },
608#endif
3dd22903
WD
609 {"ipv4", '4', POPT_ARG_VAL, &default_af_hint, AF_INET, 0, 0 },
610 {"ipv6", '6', POPT_ARG_VAL, &default_af_hint, AF_INET6, 0, 0 },
a6a27602 611 {"8-bit-output", '8', POPT_ARG_NONE, &allow_8bit_chars, 0, 0, 0 },
8487f9cf 612 {"qsort", 0, POPT_ARG_NONE, &use_qsort, 0, 0, 0 },
e86e2fa1
WD
613 {"address", 0, POPT_ARG_STRING, &bind_address, 0, 0, 0 },
614 {"port", 0, POPT_ARG_INT, &rsync_port, 0, 0, 0 },
831f06a5 615 {"sockopts", 0, POPT_ARG_STRING, &sockopts, 0, 0, 0 },
e86e2fa1
WD
616 {"password-file", 0, POPT_ARG_STRING, &password_file, 0, 0, 0 },
617 {"blocking-io", 0, POPT_ARG_VAL, &blocking_io, 1, 0, 0 },
618 {"no-blocking-io", 0, POPT_ARG_VAL, &blocking_io, 0, 0, 0 },
619 {"protocol", 0, POPT_ARG_INT, &protocol_version, 0, 0, 0 },
620 {"checksum-seed", 0, POPT_ARG_INT, &checksum_seed, 0, 0, 0 },
0ccffd7c 621 {"server", 0, POPT_ARG_NONE, 0, OPT_SERVER, 0, 0 },
e86e2fa1
WD
622 {"sender", 0, POPT_ARG_NONE, 0, OPT_SENDER, 0, 0 },
623 /* All the following options switch us into daemon-mode option-parsing. */
3ac7f5d4
WD
624 {"config", 0, POPT_ARG_STRING, 0, OPT_DAEMON, 0, 0 },
625 {"daemon", 0, POPT_ARG_NONE, 0, OPT_DAEMON, 0, 0 },
1f35babc 626 {"detach", 0, POPT_ARG_NONE, 0, OPT_DAEMON, 0, 0 },
3ac7f5d4 627 {"no-detach", 0, POPT_ARG_NONE, 0, OPT_DAEMON, 0, 0 },
3ac7f5d4
WD
628 {0,0,0,0, 0, 0, 0}
629};
630
631static void daemon_usage(enum logcode F)
632{
633 print_rsync_version(F);
634
b64ee91a
WD
635 rprintf(F,"\n");
636 rprintf(F,"Usage: rsync --daemon [OPTION]...\n");
3ac7f5d4 637 rprintf(F," --address=ADDRESS bind to the specified address\n");
b3708acf 638 rprintf(F," --bwlimit=KBPS limit I/O bandwidth; KBytes per second\n");
3ac7f5d4
WD
639 rprintf(F," --config=FILE specify alternate rsyncd.conf file\n");
640 rprintf(F," --no-detach do not detach from the parent\n");
b3708acf 641 rprintf(F," --port=PORT listen on alternate port number\n");
87c0f9d6 642 rprintf(F," --log-file=FILE override the \"log file\" setting\n");
232658d9 643 rprintf(F," --log-file-format=FMT override the \"log format\" setting\n");
831f06a5 644 rprintf(F," --sockopts=OPTIONS specify custom TCP options\n");
1bd9db74 645 rprintf(F," -v, --verbose increase verbosity\n");
3ac7f5d4
WD
646 rprintf(F," -4, --ipv4 prefer IPv4\n");
647 rprintf(F," -6, --ipv6 prefer IPv6\n");
05724c07 648 rprintf(F," --help show this help screen\n");
3ac7f5d4 649
b64ee91a
WD
650 rprintf(F,"\n");
651 rprintf(F,"If you were not trying to invoke rsync as a daemon, avoid using any of the\n");
3ac7f5d4
WD
652 rprintf(F,"daemon-specific rsync options. See also the rsyncd.conf(5) man page.\n");
653}
654
655static struct poptOption long_daemon_options[] = {
656 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
657 {"address", 0, POPT_ARG_STRING, &bind_address, 0, 0, 0 },
9fb08441 658 {"bwlimit", 0, POPT_ARG_INT, &daemon_bwlimit, 0, 0, 0 },
3ac7f5d4
WD
659 {"config", 0, POPT_ARG_STRING, &config_file, 0, 0, 0 },
660 {"daemon", 0, POPT_ARG_NONE, &daemon_opt, 0, 0, 0 },
3ac7f5d4
WD
661 {"ipv4", '4', POPT_ARG_VAL, &default_af_hint, AF_INET, 0, 0 },
662 {"ipv6", '6', POPT_ARG_VAL, &default_af_hint, AF_INET6, 0, 0 },
1f35babc 663 {"detach", 0, POPT_ARG_VAL, &no_detach, 0, 0, 0 },
8487f9cf 664 {"no-detach", 0, POPT_ARG_VAL, &no_detach, 1, 0, 0 },
87c0f9d6 665 {"log-file", 0, POPT_ARG_STRING, &logfile_name, 0, 0, 0 },
232658d9 666 {"log-file-format", 0, POPT_ARG_STRING, &logfile_format, 0, 0, 0 },
3ac7f5d4 667 {"port", 0, POPT_ARG_INT, &rsync_port, 0, 0, 0 },
831f06a5 668 {"sockopts", 0, POPT_ARG_STRING, &sockopts, 0, 0, 0 },
3ac7f5d4
WD
669 {"protocol", 0, POPT_ARG_INT, &protocol_version, 0, 0, 0 },
670 {"server", 0, POPT_ARG_NONE, &am_server, 0, 0, 0 },
b8cc3587 671 {"temp-dir", 'T', POPT_ARG_STRING, &tmpdir, 0, 0, 0 },
1bd9db74 672 {"verbose", 'v', POPT_ARG_NONE, 0, 'v', 0, 0 },
b6e22a47
WD
673 {"no-verbose", 0, POPT_ARG_VAL, &verbose, 0, 0, 0 },
674 {"no-v", 0, POPT_ARG_VAL, &verbose, 0, 0, 0 },
3ac7f5d4 675 {"help", 'h', POPT_ARG_NONE, 0, 'h', 0, 0 },
ad715008 676 {0,0,0,0, 0, 0, 0}
2855f61f 677};
7a6421fa 678
06963d0f 679
e51094b7 680static char err_buf[200];
cd8185f2 681
2855f61f 682
dafe63ca
MP
683/**
684 * Store the option error message, if any, so that we can log the
685 * connection attempt (which requires parsing the options), and then
686 * show the error later on.
687 **/
cd8185f2
AT
688void option_error(void)
689{
e51094b7 690 if (!err_buf[0]) {
c9bce0b8
WD
691 strlcpy(err_buf, "Error parsing options: option may "
692 "be supported on client but not on server?\n",
693 sizeof err_buf);
cd8185f2 694 }
e51094b7 695
e51094b7 696 rprintf(FERROR, RSYNC_NAME ": %s", err_buf);
8f1dc165 697 msleep(20);
cd8185f2
AT
698}
699
dafe63ca
MP
700
701/**
27ed20f7
WD
702 * Tweak the option table to disable all options that the rsyncd.conf
703 * file has told us to refuse.
dafe63ca 704 **/
27ed20f7 705static void set_refuse_options(char *bp)
cd8185f2 706{
27ed20f7 707 struct poptOption *op;
093e816c 708 char *cp, shortname[2];
d73e7f6e 709 int is_wild, found_match;
093e816c
WD
710
711 shortname[1] = '\0';
27ed20f7
WD
712
713 while (1) {
06a50542
WD
714 while (*bp == ' ') bp++;
715 if (!*bp)
716 break;
27ed20f7
WD
717 if ((cp = strchr(bp, ' ')) != NULL)
718 *cp= '\0';
093e816c 719 is_wild = strpbrk(bp, "*?[") != NULL;
d73e7f6e 720 found_match = 0;
55afbb52 721 for (op = long_options; ; op++) {
093e816c 722 *shortname = op->shortName;
d73e7f6e
WD
723 if (!op->longName && !*shortname)
724 break;
725 if ((op->longName && wildmatch(bp, op->longName))
684d7582 726 || (*shortname && wildmatch(bp, shortname))) {
e57211c5
WD
727 if (op->argInfo == POPT_ARG_VAL)
728 op->argInfo = POPT_ARG_NONE;
06a50542 729 op->val = (op - long_options) + OPT_REFUSED_BASE;
d73e7f6e 730 found_match = 1;
3671987f
WD
731 /* These flags are set to let us easily check
732 * an implied option later in the code. */
733 switch (*shortname) {
3671987f
WD
734 case 'r': case 'd': case 'l': case 'p':
735 case 't': case 'g': case 'o': case 'D':
736 refused_archive_part = op->val;
737 break;
854a1aad
WD
738 case 'z':
739 refused_compress = op->val;
740 break;
3671987f
WD
741 case '\0':
742 if (wildmatch("delete", op->longName))
743 refused_delete = op->val;
3296f91b
WD
744 else if (wildmatch("delete-before", op->longName))
745 refused_delete_before = op->val;
e0e32031
WD
746 else if (wildmatch("delete-during", op->longName))
747 refused_delete_during = op->val;
3671987f
WD
748 else if (wildmatch("partial", op->longName))
749 refused_partial = op->val;
750 else if (wildmatch("progress", op->longName))
751 refused_progress = op->val;
a015788d
WD
752 else if (wildmatch("inplace", op->longName))
753 refused_inplace = op->val;
3671987f
WD
754 break;
755 }
06a50542
WD
756 if (!is_wild)
757 break;
27ed20f7 758 }
cd8185f2 759 }
d73e7f6e
WD
760 if (!found_match) {
761 rprintf(FLOG, "No match for refuse-options string \"%s\"\n",
762 bp);
763 }
27ed20f7
WD
764 if (!cp)
765 break;
766 *cp = ' ';
767 bp = cp + 1;
cd8185f2 768 }
cd8185f2
AT
769}
770
771
8db7cc2c 772static int count_args(const char **argv)
2855f61f 773{
dfa32483 774 int i = 0;
2855f61f 775
8db7cc2c
WD
776 if (argv) {
777 while (argv[i] != NULL)
778 i++;
779 }
dfa32483
WD
780
781 return i;
2855f61f
MP
782}
783
784
837d01dd 785static OFF_T parse_size_arg(char **size_arg, char def_suf)
95e107db 786{
3c19f72c
WD
787 int reps, mult, make_compatible = 0;
788 const char *arg;
789 OFF_T size = 1;
95e107db 790
2dc7b8bd 791 for (arg = *size_arg; isDigit(arg); arg++) {}
95e107db 792 if (*arg == '.')
2dc7b8bd 793 for (arg++; isDigit(arg); arg++) {}
3c19f72c 794 switch (*arg && *arg != '+' && *arg != '-' ? *arg++ : def_suf) {
837d01dd 795 case 'b': case 'B':
3c19f72c 796 reps = 0;
837d01dd 797 break;
95e107db 798 case 'k': case 'K':
3c19f72c 799 reps = 1;
95e107db
WD
800 break;
801 case 'm': case 'M':
3c19f72c 802 reps = 2;
95e107db
WD
803 break;
804 case 'g': case 'G':
3c19f72c 805 reps = 3;
95e107db
WD
806 break;
807 default:
3c19f72c 808 return -1;
95e107db 809 }
3c19f72c
WD
810 if (*arg == 'b' || *arg == 'B')
811 mult = 1000, make_compatible = 1, arg++;
812 else if (!*arg || *arg == '+' || *arg == '-')
813 mult = 1024;
814 else if (strncasecmp(arg, "ib", 2) == 0)
815 mult = 1024, arg += 2;
816 else
817 return -1;
818 while (reps--)
819 size *= mult;
820 size *= atof(*size_arg);
821 if ((*arg == '+' || *arg == '-') && arg[1] == '1')
822 size += atoi(arg), make_compatible = 1, arg += 2;
823 if (*arg)
824 return -1;
aeb213ea 825 if (size > 0 && make_compatible) {
74de13d1
WD
826 /* We convert this manually because we may need %lld precision,
827 * and that's not a portable sprintf() escape. */
8f14cc49 828 char buf[128], *s = buf + sizeof buf - 1;
aeb213ea 829 OFF_T num = size;
8f14cc49 830 *s = '\0';
aeb213ea 831 while (num) {
26404276 832 *--s = (char)(num % 10) + '0';
aeb213ea
WD
833 num /= 10;
834 }
835 if (!(*size_arg = strdup(s)))
836 out_of_memory("parse_size_arg");
837 }
95e107db
WD
838 return size;
839}
840
841
3671987f
WD
842static void create_refuse_error(int which)
843{
844 /* The "which" value is the index + OPT_REFUSED_BASE. */
845 struct poptOption *op = &long_options[which - OPT_REFUSED_BASE];
846 int n = snprintf(err_buf, sizeof err_buf,
847 "The server is configured to refuse --%s\n",
848 op->longName) - 1;
849 if (op->shortName) {
850 snprintf(err_buf + n, sizeof err_buf - n,
851 " (-%c)\n", op->shortName);
852 }
853}
854
855
dafe63ca
MP
856/**
857 * Process command line arguments. Called on both local and remote.
858 *
859 * @retval 1 if all options are OK; with globals set to appropriate
860 * values
861 *
862 * @retval 0 on error, with err_buf containing an explanation
863 **/
ffbffc64 864int parse_arguments(int *argc_p, const char ***argv_p, int frommain)
7a6421fa 865{
7a4addaa 866 static poptContext pc;
ffbffc64
WD
867 char *ref = lp_refuse_options(module_id);
868 const char *arg, **argv = *argv_p;
869 int argc = *argc_p;
870 int opt;
d853783f 871
27ed20f7
WD
872 if (ref && *ref)
873 set_refuse_options(ref);
232658d9
WD
874 if (am_daemon)
875 set_refuse_options("log-file*");
27ed20f7 876
332cf6df
WD
877#ifdef ICONV_OPTION
878 if (!am_daemon && (arg = getenv("RSYNC_ICONV")) != NULL && *arg)
879 iconv_opt = strdup(arg);
880#endif
881
dfa32483 882 /* TODO: Call poptReadDefaultConfig; handle errors. */
cd8185f2 883
dfa32483
WD
884 /* The context leaks in case of an error, but if there's a
885 * problem we always exit anyhow. */
7a4addaa
WD
886 if (pc)
887 poptFreeContext(pc);
888 pc = poptGetContext(RSYNC_NAME, argc, argv, long_options, 0);
889 if (!am_server)
890 poptReadDefaultConfig(pc, 0);
2855f61f
MP
891
892 while ((opt = poptGetNextOpt(pc)) != -1) {
dfa32483
WD
893 /* most options are handled automatically by popt;
894 * only special cases are returned and listed here. */
2855f61f 895
d853783f
AT
896 switch (opt) {
897 case OPT_VERSION:
dfa32483 898 print_rsync_version(FINFO);
d853783f 899 exit_cleanup(0);
dfa32483 900
0ccffd7c
WD
901 case OPT_SERVER:
902 if (!am_server) {
903 /* Disable popt aliases on the server side and
904 * then start parsing the options again. */
905 poptFreeContext(pc);
ffbffc64 906 pc = poptGetContext(RSYNC_NAME, argc, argv,
0ccffd7c
WD
907 long_options, 0);
908 am_server = 1;
909 }
332cf6df
WD
910#ifdef ICONV_OPTION
911 iconv_opt = NULL;
912#endif
0ccffd7c
WD
913 break;
914
915 case OPT_SENDER:
916 if (!am_server) {
917 usage(FERROR);
918 exit_cleanup(RERR_SYNTAX);
919 }
920 am_sender = 1;
921 break;
922
3ac7f5d4
WD
923 case OPT_DAEMON:
924 if (am_daemon) {
c9bce0b8
WD
925 strlcpy(err_buf,
926 "Attempt to hack rsync thwarted!\n",
927 sizeof err_buf);
3ac7f5d4
WD
928 return 0;
929 }
332cf6df
WD
930#ifdef ICONV_OPTION
931 iconv_opt = NULL;
932#endif
3ac7f5d4 933 poptFreeContext(pc);
ffbffc64 934 pc = poptGetContext(RSYNC_NAME, argc, argv,
3ac7f5d4
WD
935 long_daemon_options, 0);
936 while ((opt = poptGetNextOpt(pc)) != -1) {
937 switch (opt) {
938 case 'h':
939 daemon_usage(FINFO);
940 exit_cleanup(0);
941
1bd9db74
WD
942 case 'v':
943 verbose++;
944 break;
945
3ac7f5d4
WD
946 default:
947 rprintf(FERROR,
948 "rsync: %s: %s (in daemon mode)\n",
949 poptBadOption(pc, POPT_BADOPTION_NOALIAS),
950 poptStrerror(opt));
951 goto daemon_error;
952 }
953 }
b6e22a47
WD
954
955 if (tmpdir && strlen(tmpdir) >= MAXPATHLEN - 10) {
956 snprintf(err_buf, sizeof err_buf,
957 "the --temp-dir path is WAY too long.\n");
958 return 0;
959 }
960
3ac7f5d4
WD
961 if (!daemon_opt) {
962 rprintf(FERROR, "Daemon option(s) used without --daemon.\n");
963 daemon_error:
964 rprintf(FERROR,
965 "(Type \"rsync --daemon --help\" for assistance with daemon mode.)\n");
966 exit_cleanup(RERR_SYNTAX);
967 }
b6e22a47 968
ffbffc64
WD
969 *argv_p = argv = poptGetArgs(pc);
970 *argc_p = argc = count_args(argv);
7f2a1f65 971 am_starting_up = 0;
3ac7f5d4
WD
972 daemon_opt = 0;
973 am_daemon = 1;
974 return 1;
975
5b56cc19 976 case OPT_MODIFY_WINDOW:
dfa32483
WD
977 /* The value has already been set by popt, but
978 * we need to remember that we're using a
979 * non-default setting. */
5b56cc19
AT
980 modify_window_set = 1;
981 break;
1de50993 982
aa4d3b4c 983 case OPT_FILTER:
3a5e9224 984 parse_rule(&filter_list, poptGetOptArg(pc), 0, 0);
d853783f
AT
985 break;
986
aa4d3b4c 987 case OPT_EXCLUDE:
3a5e9224 988 parse_rule(&filter_list, poptGetOptArg(pc),
0a68f869 989 0, XFLG_OLD_PREFIXES);
aa4d3b4c
WD
990 break;
991
d853783f 992 case OPT_INCLUDE:
3a5e9224 993 parse_rule(&filter_list, poptGetOptArg(pc),
0a68f869 994 MATCHFLG_INCLUDE, XFLG_OLD_PREFIXES);
d853783f
AT
995 break;
996
997 case OPT_EXCLUDE_FROM:
93695764 998 case OPT_INCLUDE_FROM:
7be73df4 999 arg = poptGetOptArg(pc);
1a7f3d99 1000 if (sanitize_paths)
91f4b31f 1001 arg = sanitize_path(NULL, arg, NULL, 0, NULL);
7842418b 1002 if (server_filter_list.head) {
d3ef9859
WD
1003 char *cp = strdup(arg);
1004 if (!cp)
1005 out_of_memory("parse_arguments");
3671987f
WD
1006 if (!*cp)
1007 goto options_rejected;
ba3db479 1008 clean_fname(cp, 1);
7842418b 1009 if (check_filter(&server_filter_list, cp, 0) < 0)
ba3db479 1010 goto options_rejected;
d3ef9859 1011 free(cp);
ba3db479 1012 }
3a5e9224
WD
1013 parse_filter_file(&filter_list, arg,
1014 opt == OPT_INCLUDE_FROM ? MATCHFLG_INCLUDE : 0,
1015 XFLG_FATAL_ERRORS | XFLG_OLD_PREFIXES);
93695764
DD
1016 break;
1017
b6164938
WD
1018 case 'a':
1019 if (refused_archive_part) {
1020 create_refuse_error(refused_archive_part);
1021 return 0;
1022 }
1023 if (!recurse) /* preserve recurse == 2 */
1024 recurse = 1;
1025#ifdef SUPPORT_LINKS
1026 preserve_links = 1;
1027#endif
1028 preserve_perms = 1;
f9998046 1029 preserve_times = 2;
b6164938
WD
1030 preserve_gid = 1;
1031 preserve_uid = 1;
1032 preserve_devices = 1;
b5c6a6ae
WD
1033 preserve_specials = 1;
1034 break;
1035
1036 case 'D':
1037 preserve_devices = preserve_specials = 1;
1038 break;
1039
1040 case OPT_NO_D:
1041 preserve_devices = preserve_specials = 0;
b6164938
WD
1042 break;
1043
3ca9e5d8
WD
1044 case 'h':
1045 human_readable++;
1046 break;
1047
e0e32031
WD
1048 case 'H':
1049 preserve_hard_links++;
1050 break;
1051
487094a0
WD
1052 case 'i':
1053 itemize_changes++;
1054 break;
1055
d853783f
AT
1056 case 'v':
1057 verbose++;
1058 break;
7a6421fa 1059
b86f0cef 1060 case 'q':
f98c60bf
WD
1061 if (frommain)
1062 quiet++;
b86f0cef
DD
1063 break;
1064
243c995f
WD
1065 case 'x':
1066 one_file_system++;
1067 break;
1068
aa4d3b4c
WD
1069 case 'F':
1070 switch (++F_option_cnt) {
1071 case 1:
3a5e9224 1072 parse_rule(&filter_list,": /.rsync-filter",0,0);
aa4d3b4c
WD
1073 break;
1074 case 2:
3a5e9224 1075 parse_rule(&filter_list,"- .rsync-filter",0,0);
aa4d3b4c
WD
1076 break;
1077 }
1078 break;
1079
d9fcc198 1080 case 'P':
3671987f
WD
1081 if (refused_partial || refused_progress) {
1082 create_refuse_error(refused_partial
1083 ? refused_partial : refused_progress);
1084 return 0;
1085 }
d9fcc198
AT
1086 do_progress = 1;
1087 keep_partial = 1;
1088 break;
1089
854a1aad
WD
1090 case 'z':
1091 if (def_compress_level < Z_DEFAULT_COMPRESSION
1092 || def_compress_level > Z_BEST_COMPRESSION) {
1093 snprintf(err_buf, sizeof err_buf,
1094 "--compress-level value is invalid: %d\n",
1095 def_compress_level);
1096 return 0;
1097 }
1098 do_compression = def_compress_level != Z_NO_COMPRESSION;
1099 if (do_compression && refused_compress) {
1100 create_refuse_error(refused_compress);
1101 return 0;
1102 }
1103 break;
1104
088aac85 1105 case OPT_WRITE_BATCH:
9b3318b0 1106 /* batch_name is already set */
088aac85
DD
1107 write_batch = 1;
1108 break;
1109
11e758a4
WD
1110 case OPT_ONLY_WRITE_BATCH:
1111 /* batch_name is already set */
1112 write_batch = -1;
1113 break;
1114
76f79ba7 1115 case OPT_READ_BATCH:
9b3318b0 1116 /* batch_name is already set */
6902ed17
MP
1117 read_batch = 1;
1118 break;
ea5164d1 1119
7d5acf1d 1120 case OPT_MAX_SIZE:
837d01dd 1121 if ((max_size = parse_size_arg(&max_size_arg, 'b')) <= 0) {
e012f858 1122 snprintf(err_buf, sizeof err_buf,
7d5acf1d
WD
1123 "--max-size value is invalid: %s\n",
1124 max_size_arg);
e012f858 1125 return 0;
7d5acf1d
WD
1126 }
1127 break;
1128
74de13d1
WD
1129 case OPT_MIN_SIZE:
1130 if ((min_size = parse_size_arg(&min_size_arg, 'b')) <= 0) {
1131 snprintf(err_buf, sizeof err_buf,
1132 "--min-size value is invalid: %s\n",
1133 min_size_arg);
1134 return 0;
1135 }
1136 break;
1137
936fa865
WD
1138 case OPT_APPEND:
1139 if (am_server)
1140 append_mode++;
1141 else
1142 append_mode = 1;
1143 break;
1144
59c95e42 1145 case OPT_LINK_DEST:
fcecb70b 1146#ifdef SUPPORT_HARD_LINKS
59c95e42 1147 link_dest = 1;
e012f858
WD
1148 dest_option = "--link-dest";
1149 goto set_dest_dir;
59c95e42 1150#else
d175d7e1 1151 snprintf(err_buf, sizeof err_buf,
dfa32483 1152 "hard links are not supported on this %s\n",
59c95e42 1153 am_server ? "server" : "client");
59c95e42
DD
1154 return 0;
1155#endif
1156
1de3e99b
WD
1157 case OPT_COPY_DEST:
1158 copy_dest = 1;
1159 dest_option = "--copy-dest";
1160 goto set_dest_dir;
1161
e012f858
WD
1162 case OPT_COMPARE_DEST:
1163 compare_dest = 1;
1164 dest_option = "--compare-dest";
1165 set_dest_dir:
3b26bba0 1166 if (basis_dir_cnt >= MAX_BASIS_DIRS) {
e012f858
WD
1167 snprintf(err_buf, sizeof err_buf,
1168 "ERROR: at most %d %s args may be specified\n",
1169 MAX_BASIS_DIRS, dest_option);
1170 return 0;
1171 }
ad77db8b
WD
1172 /* We defer sanitizing this arg until we know what
1173 * our destination directory is going to be. */
1174 basis_dir[basis_dir_cnt++] = (char *)poptGetOptArg(pc);
e012f858
WD
1175 break;
1176
e16adcdf
WD
1177 case OPT_CHMOD:
1178 arg = poptGetOptArg(pc);
bbe42182 1179 if (!parse_chmod(arg, &chmod_modes)) {
e16adcdf
WD
1180 snprintf(err_buf, sizeof err_buf,
1181 "Invalid argument passed to --chmod (%s)\n",
1182 arg);
1183 return 0;
1184 }
1185 break;
1186
f5a910dd
WD
1187 case OPT_HELP:
1188 usage(FINFO);
1189 exit_cleanup(0);
1190
1c3344a1
WD
1191 case 'A':
1192#ifdef SUPPORT_ACLS
1193 preserve_acls = 1;
1194 preserve_perms = 1;
1195 break;
1196#else
1197 /* FIXME: this should probably be ignored with a
1198 * warning and then countermeasures taken to
1199 * restrict group and other access in the presence
1200 * of any more restrictive ACLs, but this is safe
1201 * for now */
1202 snprintf(err_buf,sizeof(err_buf),
1203 "ACLs are not supported on this %s\n",
1204 am_server ? "server" : "client");
1205 return 0;
1206#endif
1207
16edf865
WD
1208 case 'X':
1209#ifdef SUPPORT_XATTRS
524eaa82 1210 preserve_xattrs++;
16edf865
WD
1211 break;
1212#else
1213 snprintf(err_buf,sizeof(err_buf),
1214 "extended attributes are not supported on this %s\n",
1215 am_server ? "server" : "client");
1216 return 0;
1217#endif
1c3344a1 1218
d853783f 1219 default:
55afbb52 1220 /* A large opt value means that set_refuse_options()
3671987f 1221 * turned this option off. */
c67d1386 1222 if (opt >= OPT_REFUSED_BASE) {
3671987f
WD
1223 create_refuse_error(opt);
1224 return 0;
27ed20f7 1225 }
3671987f
WD
1226 snprintf(err_buf, sizeof err_buf, "%s%s: %s\n",
1227 am_server ? "on remote machine: " : "",
1228 poptBadOption(pc, POPT_BADOPTION_NOALIAS),
1229 poptStrerror(opt));
dfa32483 1230 return 0;
d853783f 1231 }
7a6421fa 1232 }
2855f61f 1233
ffbffc64 1234 if (human_readable && argc == 2) {
3ca9e5d8 1235 /* Allow the old meaning of 'h' (--help) on its own. */
05724c07
WD
1236 usage(FINFO);
1237 exit_cleanup(0);
1238 }
1239
7a4addaa
WD
1240 if (protect_args) {
1241 if (!frommain)
1242 protect_args = 0;
1243 else if (am_server)
1244 return 1;
1245 }
1246
332cf6df
WD
1247#ifdef ICONV_OPTION
1248 if (iconv_opt) {
1249 if (!am_server && strcmp(iconv_opt, "-") == 0)
1250 iconv_opt = NULL;
1251 else
1252 need_unsorted_flist = 1;
1253 }
1254#endif
1255
4f5b0756 1256#ifndef SUPPORT_LINKS
54e87b4b 1257 if (preserve_links && !am_sender) {
e1add893
WD
1258 snprintf(err_buf, sizeof err_buf,
1259 "symlinks are not supported on this %s\n",
1260 am_server ? "server" : "client");
e1add893
WD
1261 return 0;
1262 }
1263#endif
1264
4f5b0756 1265#ifndef SUPPORT_HARD_LINKS
e1add893
WD
1266 if (preserve_hard_links) {
1267 snprintf(err_buf, sizeof err_buf,
1268 "hard links are not supported on this %s\n",
1269 am_server ? "server" : "client");
e1add893
WD
1270 return 0;
1271 }
1272#endif
1273
9439c0cb
WD
1274#ifndef SUPPORT_XATTRS
1275 if (am_root < 0) {
1276 snprintf(err_buf, sizeof err_buf,
1277 "--fake-super requires an rsync with extended attributes enabled\n");
1278 return 0;
1279 }
1280#endif
1281
088aac85 1282 if (write_batch && read_batch) {
c3ea0990 1283 snprintf(err_buf, sizeof err_buf,
36119893 1284 "--write-batch and --read-batch can not be used together\n");
c3ea0990 1285 return 0;
088aac85 1286 }
11e758a4 1287 if (write_batch > 0 || read_batch) {
94327ff0
WD
1288 if (am_server) {
1289 rprintf(FINFO,
1290 "ignoring --%s-batch option sent to server\n",
1291 write_batch ? "write" : "read");
1292 /* We don't actually exit_cleanup(), so that we can
1293 * still service older version clients that still send
1294 * batch args to server. */
1295 read_batch = write_batch = 0;
1296 batch_name = NULL;
254ee3ba
WD
1297 } else if (dry_run)
1298 write_batch = 0;
b9f592fb 1299 }
36119893 1300 if (read_batch && files_from) {
c3ea0990 1301 snprintf(err_buf, sizeof err_buf,
36119893 1302 "--read-batch cannot be used with --files-from\n");
c3ea0990 1303 return 0;
36119893 1304 }
9b3318b0 1305 if (batch_name && strlen(batch_name) > MAX_BATCH_NAME_LEN) {
c3ea0990 1306 snprintf(err_buf, sizeof err_buf,
9b3318b0
WD
1307 "the batch-file name must be %d characters or less.\n",
1308 MAX_BATCH_NAME_LEN);
c3ea0990 1309 return 0;
beb93684 1310 }
088aac85 1311
ce58b1b4 1312 if (tmpdir && strlen(tmpdir) >= MAXPATHLEN - 10) {
c3ea0990
WD
1313 snprintf(err_buf, sizeof err_buf,
1314 "the --temp-dir path is WAY too long.\n");
1315 return 0;
ce58b1b4
WD
1316 }
1317
7b9598b2
WD
1318 if (max_delete < 0 && max_delete != INT_MIN) {
1319 /* Negative numbers are treated as "no deletions". */
1320 max_delete = 0;
1321 }
1322
1de3e99b 1323 if (compare_dest + copy_dest + link_dest > 1) {
e012f858 1324 snprintf(err_buf, sizeof err_buf,
1de3e99b 1325 "You may not mix --compare-dest, --copy-dest, and --link-dest.\n");
e012f858
WD
1326 return 0;
1327 }
1328
b6164938
WD
1329 if (files_from) {
1330 if (recurse == 1) /* preserve recurse == 2 */
1331 recurse = 0;
550d4e23 1332 if (xfer_dirs < 0)
b6164938 1333 xfer_dirs = 1;
dfa32483 1334 }
51d48398 1335
b6164938
WD
1336 if (xfer_dirs < 1)
1337 xfer_dirs = recurse || list_only;
dfa32483 1338
ea5164d1
WD
1339 if (relative_paths < 0)
1340 relative_paths = files_from? 1 : 0;
89f2a4c2
WD
1341 if (!relative_paths)
1342 implied_dirs = 0;
ea5164d1 1343
e0e32031 1344 if (delete_before + !!delete_during + delete_after > 1) {
3359acb8 1345 snprintf(err_buf, sizeof err_buf,
c6eb7fad 1346 "You may not combine multiple --delete-WHEN options.\n");
3359acb8
WD
1347 return 0;
1348 }
f5a910dd 1349 if (delete_before || delete_during || delete_after)
51d48398 1350 delete_mode = 1;
3296f91b 1351 else if (delete_mode || delete_excluded) {
e0e32031 1352 /* Only choose now between before & during if one is refused. */
3296f91b 1353 if (refused_delete_before) {
e0e32031
WD
1354 if (!refused_delete_during)
1355 delete_during = 1;
1356 else {
1357 create_refuse_error(refused_delete_before);
1358 return 0;
1359 }
1360 } else if (refused_delete_during)
1361 delete_before = 1;
1362 delete_mode = 1;
3296f91b 1363 }
89fb5026
WD
1364 if (!xfer_dirs && delete_mode) {
1365 snprintf(err_buf, sizeof err_buf,
1366 "--delete does not work without -r or -d.\n");
1367 return 0;
f5a910dd 1368 }
51d48398 1369
3671987f
WD
1370 if (delete_mode && refused_delete) {
1371 create_refuse_error(refused_delete);
1372 return 0;
1373 }
1374
47c11975
WD
1375 if (remove_source_files) {
1376 /* We only want to infer this refusal of --remove-source-files
07c6ae7d
WD
1377 * via the refusal of "delete", not any of the "delete-FOO"
1378 * options. */
1379 if (refused_delete && am_sender) {
1380 create_refuse_error(refused_delete);
1381 return 0;
1382 }
1383 need_messages_from_generator = 1;
1384 }
1385
ffbffc64
WD
1386 *argv_p = argv = poptGetArgs(pc);
1387 *argc_p = argc = count_args(argv);
7be73df4
WD
1388
1389 if (sanitize_paths) {
1390 int i;
ffbffc64
WD
1391 for (i = argc; i-- > 0; )
1392 argv[i] = sanitize_path(NULL, argv[i], "", 0, NULL);
1a7f3d99 1393 if (tmpdir)
91f4b31f 1394 tmpdir = sanitize_path(NULL, tmpdir, NULL, 0, NULL);
1a7f3d99 1395 if (backup_dir)
91f4b31f 1396 backup_dir = sanitize_path(NULL, backup_dir, NULL, 0, NULL);
7be73df4 1397 }
7842418b
WD
1398 if (server_filter_list.head && !am_sender) {
1399 struct filter_list_struct *elp = &server_filter_list;
c3ea0990 1400 if (tmpdir) {
3671987f
WD
1401 if (!*tmpdir)
1402 goto options_rejected;
58b1999e 1403 clean_fname(tmpdir, 1);
7842418b 1404 if (check_filter(elp, tmpdir, 1) < 0)
c3ea0990
WD
1405 goto options_rejected;
1406 }
c3ea0990 1407 if (backup_dir) {
3671987f
WD
1408 if (!*backup_dir)
1409 goto options_rejected;
58b1999e 1410 clean_fname(backup_dir, 1);
f0fa8c6d
WD
1411 if (check_filter(elp, backup_dir, 1) < 0)
1412 goto options_rejected;
c3ea0990
WD
1413 }
1414 }
7be73df4 1415
d175d7e1 1416 if (!backup_suffix)
e0391f81 1417 backup_suffix = backup_dir ? "" : BACKUP_SUFFIX;
d175d7e1 1418 backup_suffix_len = strlen(backup_suffix);
80ddadb7 1419 if (strchr(backup_suffix, '/') != NULL) {
c3ea0990
WD
1420 snprintf(err_buf, sizeof err_buf,
1421 "--suffix cannot contain slashes: %s\n",
80ddadb7 1422 backup_suffix);
c3ea0990 1423 return 0;
80ddadb7 1424 }
e0391f81
WD
1425 if (backup_dir) {
1426 backup_dir_len = strlcpy(backup_dir_buf, backup_dir, sizeof backup_dir_buf);
1427 backup_dir_remainder = sizeof backup_dir_buf - backup_dir_len;
1428 if (backup_dir_remainder < 32) {
c3ea0990
WD
1429 snprintf(err_buf, sizeof err_buf,
1430 "the --backup-dir path is WAY too long.\n");
1431 return 0;
e0391f81
WD
1432 }
1433 if (backup_dir_buf[backup_dir_len - 1] != '/') {
1434 backup_dir_buf[backup_dir_len++] = '/';
1435 backup_dir_buf[backup_dir_len] = '\0';
1436 }
0ee6ca98
WD
1437 if (verbose > 1 && !am_sender)
1438 rprintf(FINFO, "backup_dir is %s\n", backup_dir_buf);
8dcf9335 1439 } else if (!backup_suffix_len && (!am_server || !am_sender)) {
c3ea0990 1440 snprintf(err_buf, sizeof err_buf,
d175d7e1 1441 "--suffix cannot be a null string without --backup-dir\n");
c3ea0990 1442 return 0;
f41152d3
WD
1443 } else if (make_backups && delete_mode && !delete_excluded && !am_server) {
1444 snprintf(backup_dir_buf, sizeof backup_dir_buf,
1445 "P *%s", backup_suffix);
1446 parse_rule(&filter_list, backup_dir_buf, 0, 0);
d175d7e1 1447 }
fbd91cae
WD
1448
1449 if (make_backups && !backup_dir) {
1450 omit_dir_times = 0; /* Implied, so avoid -O to sender. */
1451 if (preserve_times > 1)
1452 preserve_times = 1;
1453 } else if (omit_dir_times) {
1454 if (preserve_times > 1)
1455 preserve_times = 1;
1456 }
d175d7e1 1457
b3e4e7ef
WD
1458 if (stdout_format) {
1459 if (am_server && log_format_has(stdout_format, 'I'))
1460 stdout_format_has_i = 2;
1461 else if (log_format_has(stdout_format, 'i'))
1462 stdout_format_has_i = itemize_changes | 1;
1463 if (!log_format_has(stdout_format, 'b')
1464 && !log_format_has(stdout_format, 'c'))
e7651884
WD
1465 log_before_transfer = !am_server;
1466 } else if (itemize_changes) {
b3e4e7ef
WD
1467 stdout_format = "%i %n%L";
1468 stdout_format_has_i = itemize_changes;
e7651884
WD
1469 log_before_transfer = !am_server;
1470 }
87383697 1471
a892d905 1472 if (do_progress && !verbose && !log_before_transfer && !am_server)
e2559dbe 1473 verbose = 1;
87383697 1474
11e758a4
WD
1475 if (dry_run)
1476 do_xfers = 0;
1477
9ac756c6
WD
1478 set_io_timeout(io_timeout);
1479
b3e4e7ef
WD
1480 if (verbose && !stdout_format) {
1481 stdout_format = "%n%L";
87383697 1482 log_before_transfer = !am_server;
3671987f 1483 }
b3e4e7ef
WD
1484 if (stdout_format_has_i || log_format_has(stdout_format, 'o'))
1485 stdout_format_has_o_or_i = 1;
e2559dbe 1486
232658d9 1487 if (logfile_name && !am_daemon) {
b3e4e7ef 1488 if (!logfile_format) {
232658d9 1489 logfile_format = "%i %n%L";
87c0f9d6 1490 logfile_format_has_i = logfile_format_has_o_or_i = 1;
b3e4e7ef
WD
1491 } else {
1492 if (log_format_has(logfile_format, 'i'))
19b85876 1493 logfile_format_has_i = 1;
b3e4e7ef
WD
1494 if (logfile_format_has_i || log_format_has(logfile_format, 'o'))
1495 logfile_format_has_o_or_i = 1;
87c0f9d6 1496 }
6dc9b74b 1497 log_init(0);
2873603a
WD
1498 } else if (!am_daemon)
1499 logfile_format = NULL;
87c0f9d6 1500
9fb08441
WD
1501 if (daemon_bwlimit && (!bwlimit || bwlimit > daemon_bwlimit))
1502 bwlimit = daemon_bwlimit;
3c74c3a3
WD
1503 if (bwlimit) {
1504 bwlimit_writemax = (size_t)bwlimit * 128;
1505 if (bwlimit_writemax < 512)
1506 bwlimit_writemax = 512;
1507 }
1508
cfce9f6d 1509 if (sparse_files && inplace) {
c3851185 1510 /* Note: we don't check for this below, because --append is
cfce9f6d
WD
1511 * OK with --sparse (as long as redos are handled right). */
1512 snprintf(err_buf, sizeof err_buf,
1513 "--sparse cannot be used with --inplace\n");
1514 return 0;
1515 }
1516
a015788d
WD
1517 if (append_mode) {
1518 if (whole_file > 0) {
1519 snprintf(err_buf, sizeof err_buf,
1520 "--append cannot be used with --whole-file\n");
1521 return 0;
1522 }
1523 if (refused_inplace) {
1524 create_refuse_error(refused_inplace);
1525 return 0;
1526 }
1527 inplace = 1;
1528 }
1529
f06e7082 1530 if (delay_updates && !partial_dir)
77860bac 1531 partial_dir = tmp_partialdir;
f06e7082 1532
a3221d2a 1533 if (inplace) {
4f5b0756 1534#ifdef HAVE_FTRUNCATE
a7260c40
WD
1535 if (partial_dir) {
1536 snprintf(err_buf, sizeof err_buf,
a015788d
WD
1537 "--%s cannot be used with --%s\n",
1538 append_mode ? "append" : "inplace",
f06e7082 1539 delay_updates ? "delay-updates" : "partial-dir");
a7260c40
WD
1540 return 0;
1541 }
3671987f
WD
1542 /* --inplace implies --partial for refusal purposes, but we
1543 * clear the keep_partial flag for internal logic purposes. */
1544 if (refused_partial) {
1545 create_refuse_error(refused_partial);
1546 return 0;
1547 }
a3221d2a 1548 keep_partial = 0;
ded4daf0
WD
1549#else
1550 snprintf(err_buf, sizeof err_buf,
a015788d
WD
1551 "--%s is not supported on this %s\n",
1552 append_mode ? "append" : "inplace",
ded4daf0
WD
1553 am_server ? "server" : "client");
1554 return 0;
1555#endif
075aa18f 1556 } else {
bc880cb8 1557 if (keep_partial && !partial_dir && !am_server) {
3671987f
WD
1558 if ((arg = getenv("RSYNC_PARTIAL_DIR")) != NULL && *arg)
1559 partial_dir = strdup(arg);
1560 }
075aa18f 1561 if (partial_dir) {
3671987f
WD
1562 if (*partial_dir)
1563 clean_fname(partial_dir, 1);
075aa18f
WD
1564 if (!*partial_dir || strcmp(partial_dir, ".") == 0)
1565 partial_dir = NULL;
3671987f
WD
1566 if (!partial_dir && refused_partial) {
1567 create_refuse_error(refused_partial);
1568 return 0;
1569 }
075aa18f
WD
1570 keep_partial = 1;
1571 }
a3221d2a
WD
1572 }
1573
ea5164d1 1574 if (files_from) {
305666bf
WD
1575 char *h, *p;
1576 int q;
ffbffc64 1577 if (argc > 2 || (!am_daemon && argc == 1)) {
ea5164d1
WD
1578 usage(FERROR);
1579 exit_cleanup(RERR_SYNTAX);
1580 }
63596e1c 1581 if (strcmp(files_from, "-") == 0) {
ea5164d1 1582 filesfrom_fd = 0;
63596e1c 1583 if (am_server)
305666bf
WD
1584 filesfrom_host = ""; /* reading from socket */
1585 } else if ((p = check_for_hostspec(files_from, &h, &q)) != 0) {
ea5164d1 1586 if (am_server) {
305666bf
WD
1587 snprintf(err_buf, sizeof err_buf,
1588 "The --files-from sent to the server cannot specify a host.\n");
1589 return 0;
ea5164d1 1590 }
305666bf
WD
1591 files_from = p;
1592 filesfrom_host = h;
1593 if (strcmp(files_from, "-") == 0) {
c3ea0990
WD
1594 snprintf(err_buf, sizeof err_buf,
1595 "Invalid --files-from remote filename\n");
1596 return 0;
ea5164d1
WD
1597 }
1598 } else {
305666bf 1599 if (sanitize_paths)
91f4b31f 1600 files_from = sanitize_path(NULL, files_from, NULL, 0, NULL);
305666bf
WD
1601 if (server_filter_list.head) {
1602 if (!*files_from)
1603 goto options_rejected;
1604 clean_fname(files_from, 1);
1605 if (check_filter(&server_filter_list, files_from, 0) < 0)
1606 goto options_rejected;
1607 }
ea5164d1
WD
1608 filesfrom_fd = open(files_from, O_RDONLY|O_BINARY);
1609 if (filesfrom_fd < 0) {
c3ea0990
WD
1610 snprintf(err_buf, sizeof err_buf,
1611 "failed to open files-from file %s: %s\n",
1612 files_from, strerror(errno));
1613 return 0;
ea5164d1
WD
1614 }
1615 }
1616 }
1617
7f2a1f65
WD
1618 am_starting_up = 0;
1619
b11ed3b1 1620 return 1;
f0fa8c6d
WD
1621
1622 options_rejected:
1623 snprintf(err_buf, sizeof err_buf,
1624 "Your options have been rejected by the server.\n");
1625 return 0;
7a6421fa
AT
1626}
1627
1628
dafe63ca
MP
1629/**
1630 * Construct a filtered list of options to pass through from the
1631 * client to the server.
1632 *
1633 * This involves setting options that will tell the server how to
1634 * behave, and also filtering out options that are processed only
1635 * locally.
1636 **/
ffbffc64 1637void server_options(char **args, int *argc_p)
7a6421fa 1638{
74ba98a5 1639 static char argstr[64];
ffbffc64 1640 int ac = *argc_p;
f98c60bf 1641 char *arg;
ef5d23eb 1642
d853783f
AT
1643 int i, x;
1644
93689aa5
DD
1645 if (blocking_io == -1)
1646 blocking_io = 0;
1647
def97ff9 1648 /* This should always remain first on the server's command-line. */
d853783f
AT
1649 args[ac++] = "--server";
1650
e208631a 1651 if (daemon_over_rsh > 0) {
1312d9fc 1652 args[ac++] = "--daemon";
ffbffc64 1653 *argc_p = ac;
1312d9fc
WD
1654 /* if we're passing --daemon, we're done */
1655 return;
1656 }
1657
d853783f
AT
1658 if (!am_sender)
1659 args[ac++] = "--sender";
1660
1661 x = 1;
1662 argstr[0] = '-';
f98c60bf 1663 for (i = 0; i < verbose; i++)
d853783f 1664 argstr[x++] = 'v';
f0b36a48 1665
b86f0cef 1666 /* the -q option is intentionally left out */
d853783f
AT
1667 if (make_backups)
1668 argstr[x++] = 'b';
1669 if (update_only)
1670 argstr[x++] = 'u';
2dbf36ef 1671 if (!do_xfers) /* Note: NOT "dry_run"! */
d853783f
AT
1672 argstr[x++] = 'n';
1673 if (preserve_links)
1674 argstr[x++] = 'l';
4d51f0db 1675 if (xfer_dirs > (recurse || !delete_mode || !am_sender ? 1 : 0))
5454d22a 1676 argstr[x++] = 'd';
35bf8fa0
WD
1677 if (am_sender) {
1678 if (keep_dirlinks)
1679 argstr[x++] = 'K';
876c9936
WD
1680 if (prune_empty_dirs)
1681 argstr[x++] = 'm';
f9998046 1682 if (omit_dir_times)
35bf8fa0 1683 argstr[x++] = 'O';
2dbf36ef
WD
1684 } else {
1685 if (copy_links)
1686 argstr[x++] = 'L';
1687 if (copy_dirlinks)
1688 argstr[x++] = 'k';
35bf8fa0 1689 }
1bfbf40b 1690
dfa32483 1691 if (whole_file > 0)
d853783f 1692 argstr[x++] = 'W';
bceec82f
MP
1693 /* We don't need to send --no-whole-file, because it's the
1694 * default for remote transfers, and in any case old versions
1695 * of rsync will not understand it. */
dfa32483 1696
e0e32031 1697 if (preserve_hard_links) {
d853783f 1698 argstr[x++] = 'H';
e0e32031
WD
1699 if (preserve_hard_links > 1)
1700 argstr[x++] = 'H';
1701 }
d853783f
AT
1702 if (preserve_uid)
1703 argstr[x++] = 'o';
1704 if (preserve_gid)
1705 argstr[x++] = 'g';
b5c6a6ae 1706 if (preserve_devices) /* ignore preserve_specials here */
d853783f
AT
1707 argstr[x++] = 'D';
1708 if (preserve_times)
1709 argstr[x++] = 't';
1710 if (preserve_perms)
1711 argstr[x++] = 'p';
344f9ba7
WD
1712 else if (preserve_executability && am_sender)
1713 argstr[x++] = 'E';
1c3344a1
WD
1714#ifdef SUPPORT_ACLS
1715 if (preserve_acls)
1716 argstr[x++] = 'A';
16edf865
WD
1717#endif
1718#ifdef SUPPORT_XATTRS
524eaa82 1719 if (preserve_xattrs) {
16edf865 1720 argstr[x++] = 'X';
524eaa82
WD
1721 if (preserve_xattrs > 1)
1722 argstr[x++] = 'X';
1723 }
1c3344a1 1724#endif
aa7a6e87 1725 if (recurse)
d853783f
AT
1726 argstr[x++] = 'r';
1727 if (always_checksum)
1728 argstr[x++] = 'c';
1729 if (cvs_exclude)
1730 argstr[x++] = 'C';
1731 if (ignore_times)
1732 argstr[x++] = 'I';
1733 if (relative_paths)
1734 argstr[x++] = 'R';
243c995f 1735 if (one_file_system) {
d853783f 1736 argstr[x++] = 'x';
243c995f
WD
1737 if (one_file_system > 1)
1738 argstr[x++] = 'x';
1739 }
d853783f
AT
1740 if (sparse_files)
1741 argstr[x++] = 'S';
1742 if (do_compression)
1743 argstr[x++] = 'z';
f0b36a48 1744
51d48398
WD
1745 /* This is a complete hack - blame Rusty. FIXME!
1746 * This hack is only needed for older rsync versions that
1747 * don't understand the --list-only option. */
da2a6c1f 1748 if (list_only == 1 && !recurse)
f0b36a48
AT
1749 argstr[x++] = 'r';
1750
2ed790f3 1751#if SUBPROTOCOL_VERSION != 0
486f8cd1
WD
1752 /* If we're speaking a pre-release version of a protocol, we tell
1753 * the server about this by (ab)using the -e option. */
2ed790f3 1754 if (protocol_version == PROTOCOL_VERSION) {
486f8cd1
WD
1755 x += snprintf(argstr+x, sizeof argstr - x,
1756 "e%d.%d", PROTOCOL_VERSION, SUBPROTOCOL_VERSION);
1757 }
2ed790f3 1758#endif
486f8cd1 1759
332cf6df
WD
1760 argstr[x] = '\0';
1761
f98c60bf
WD
1762 if (x != 1)
1763 args[ac++] = argstr;
d853783f 1764
51d48398
WD
1765 if (list_only > 1)
1766 args[ac++] = "--list-only";
1767
f5a910dd
WD
1768 /* This makes sure that the remote rsync can handle deleting with -d
1769 * sans -r because the --no-r option was added at the same time. */
1770 if (xfer_dirs && !recurse && delete_mode && am_sender)
1771 args[ac++] = "--no-r";
1772
854a1aad
WD
1773 if (do_compression && def_compress_level != Z_DEFAULT_COMPRESSION) {
1774 if (asprintf(&arg, "--compress-level=%d", def_compress_level) < 0)
1775 goto oom;
1776 args[ac++] = arg;
1777 }
1778
b5c6a6ae
WD
1779 if (preserve_devices) {
1780 /* Note: sending "--devices" would not be backward-compatible. */
1781 if (!preserve_specials)
1782 args[ac++] = "--no-specials"; /* -D is already set. */
1783 } else if (preserve_specials)
1784 args[ac++] = "--specials";
1785
5c5e1598
WD
1786 /* The server side doesn't use our log-format, but in certain
1787 * circumstances they need to know a little about the option. */
b3e4e7ef
WD
1788 if (stdout_format && am_sender) {
1789 /* Use --log-format, not --out-format, for compatibility. */
1790 if (stdout_format_has_i > 1)
487094a0 1791 args[ac++] = "--log-format=%i%I";
b3e4e7ef 1792 else if (stdout_format_has_i)
684d7582 1793 args[ac++] = "--log-format=%i";
b3e4e7ef 1794 else if (stdout_format_has_o_or_i)
5c5e1598
WD
1795 args[ac++] = "--log-format=%o";
1796 else if (!verbose)
1797 args[ac++] = "--log-format=X";
1798 }
1f30a674 1799
332cf6df
WD
1800#ifdef ICONV_OPTION
1801 if (iconv_opt) {
1802 char *set = strchr(iconv_opt, ',');
1803 if (set)
1804 set++;
1805 else
1806 set = iconv_opt;
1807 if (asprintf(&arg, "--iconv=%s", set) < 0)
1808 goto oom;
1809 args[ac++] = arg;
1810 }
1811#endif
1812
195bd906 1813 if (block_size) {
a06b419d 1814 if (asprintf(&arg, "-B%lu", block_size) < 0)
f98c60bf
WD
1815 goto oom;
1816 args[ac++] = arg;
dfa32483 1817 }
d853783f
AT
1818
1819 if (io_timeout) {
f98c60bf
WD
1820 if (asprintf(&arg, "--timeout=%d", io_timeout) < 0)
1821 goto oom;
1822 args[ac++] = arg;
dfa32483 1823 }
d853783f 1824
ef5d23eb 1825 if (bwlimit) {
f98c60bf
WD
1826 if (asprintf(&arg, "--bwlimit=%d", bwlimit) < 0)
1827 goto oom;
1828 args[ac++] = arg;
ef5d23eb
DD
1829 }
1830
d175d7e1
WD
1831 if (backup_dir) {
1832 args[ac++] = "--backup-dir";
1833 args[ac++] = backup_dir;
1834 }
1835
1836 /* Only send --suffix if it specifies a non-default value. */
f98c60bf 1837 if (strcmp(backup_suffix, backup_dir ? "" : BACKUP_SUFFIX) != 0) {
191e40da 1838 /* We use the following syntax to avoid weirdness with '~'. */
f98c60bf
WD
1839 if (asprintf(&arg, "--suffix=%s", backup_suffix) < 0)
1840 goto oom;
1841 args[ac++] = arg;
d853783f
AT
1842 }
1843
06a50542 1844 if (am_sender) {
7b9598b2
WD
1845 if (max_delete > 0) {
1846 if (asprintf(&arg, "--max-delete=%d", max_delete) < 0)
1847 goto oom;
1848 args[ac++] = arg;
1849 } else if (max_delete == 0)
1850 args[ac++] = "--max_delete=-1";
1851 if (min_size) {
1852 args[ac++] = "--min-size";
1853 args[ac++] = min_size_arg;
1854 }
1855 if (max_size) {
1856 args[ac++] = "--max-size";
1857 args[ac++] = max_size_arg;
1858 }
e0e32031 1859 if (delete_before)
c6eb7fad 1860 args[ac++] = "--delete-before";
0d152437
WD
1861 else if (delete_during == 2)
1862 args[ac++] = "--delete-delay";
1863 else if (delete_during)
1864 args[ac++] = "--delete-during";
1865 else if (delete_after)
06a50542 1866 args[ac++] = "--delete-after";
e0e32031
WD
1867 else if (delete_mode && !delete_excluded)
1868 args[ac++] = "--delete";
1869 if (delete_excluded)
1870 args[ac++] = "--delete-excluded";
06a50542
WD
1871 if (force_delete)
1872 args[ac++] = "--force";
11e758a4
WD
1873 if (write_batch < 0)
1874 args[ac++] = "--only-write-batch=X";
def97ff9
WD
1875 if (am_root > 1)
1876 args[ac++] = "--super";
f17e769e
WD
1877 if (size_only)
1878 args[ac++] = "--size-only";
b1e436ec
WD
1879 } else {
1880 if (skip_compress) {
1881 if (asprintf(&arg, "--skip-compress=%s", skip_compress) < 0)
1882 goto oom;
1883 args[ac++] = arg;
1884 }
06a50542 1885 }
b33b791e 1886
5b56cc19 1887 if (modify_window_set) {
f98c60bf
WD
1888 if (asprintf(&arg, "--modify-window=%d", modify_window) < 0)
1889 goto oom;
1890 args[ac++] = arg;
5b56cc19
AT
1891 }
1892
c8d895de 1893 if (checksum_seed) {
221ddb94 1894 if (asprintf(&arg, "--checksum-seed=%d", checksum_seed) < 0)
c8d895de
WD
1895 goto oom;
1896 args[ac++] = arg;
1897 }
1898
a7260c40 1899 if (partial_dir && am_sender) {
77860bac 1900 if (partial_dir != tmp_partialdir) {
3671987f
WD
1901 args[ac++] = "--partial-dir";
1902 args[ac++] = partial_dir;
1903 }
f06e7082
WD
1904 if (delay_updates)
1905 args[ac++] = "--delay-updates";
77860bac 1906 } else if (keep_partial && am_sender)
d853783f
AT
1907 args[ac++] = "--partial";
1908
ef55c686
AT
1909 if (ignore_errors)
1910 args[ac++] = "--ignore-errors";
1911
b5313607
DD
1912 if (copy_unsafe_links)
1913 args[ac++] = "--copy-unsafe-links";
1914
d853783f
AT
1915 if (safe_symlinks)
1916 args[ac++] = "--safe-links";
1917
1918 if (numeric_ids)
1919 args[ac++] = "--numeric-ids";
1920
5d935dce
WD
1921 if (!allow_inc_recurse)
1922 args[ac++] = "--no-ir";
1923
4f3797c7
WD
1924 if (am_sender) {
1925 if (ignore_existing)
1926 args[ac++] = "--ignore-existing";
1927
1928 /* Backward compatibility: send --existing, not --ignore-non-existing. */
1929 if (ignore_non_existing)
1930 args[ac++] = "--existing";
3d6feada 1931
4f3797c7
WD
1932 if (tmpdir) {
1933 args[ac++] = "--temp-dir";
1934 args[ac++] = tmpdir;
1935 }
1936
1937 if (basis_dir[0]) {
1938 /* the server only needs this option if it is not the sender,
1939 * and it may be an older version that doesn't know this
1940 * option, so don't send it if client is the sender.
1941 */
1942 int i;
1943 for (i = 0; i < basis_dir_cnt; i++) {
1944 args[ac++] = dest_option;
1945 args[ac++] = basis_dir[i];
1946 }
1947 }
1948 }
e90aab49 1949
936fa865
WD
1950 if (append_mode) {
1951 if (append_mode > 1)
1952 args[ac++] = "--append";
a015788d 1953 args[ac++] = "--append";
936fa865 1954 } else if (inplace)
a3221d2a
WD
1955 args[ac++] = "--inplace";
1956
305666bf
WD
1957 if (files_from && (!am_sender || filesfrom_host)) {
1958 if (filesfrom_host) {
ea5164d1 1959 args[ac++] = "--files-from";
305666bf 1960 args[ac++] = files_from;
ea5164d1
WD
1961 if (eol_nulls)
1962 args[ac++] = "--from0";
1963 } else {
1964 args[ac++] = "--files-from=-";
1965 args[ac++] = "--from0";
1966 }
c0ab28d1
WD
1967 if (!relative_paths)
1968 args[ac++] = "--no-relative";
ea5164d1 1969 }
89f2a4c2 1970 if (relative_paths && !implied_dirs && !am_sender)
3a90ea0a 1971 args[ac++] = "--no-implied-dirs";
ea5164d1 1972
c4ed1487
WD
1973 if (fuzzy_basis && am_sender)
1974 args[ac++] = "--fuzzy";
1975
47c11975
WD
1976 if (remove_source_files == 1)
1977 args[ac++] = "--remove-source-files";
1978 else if (remove_source_files)
07c6ae7d
WD
1979 args[ac++] = "--remove-sent-files";
1980
ffbffc64 1981 *argc_p = ac;
f98c60bf
WD
1982 return;
1983
1984 oom:
1985 out_of_memory("server_options");
7a6421fa
AT
1986}
1987
305666bf
WD
1988/* Look for a HOST specfication of the form "HOST:PATH", "HOST::PATH", or
1989 * "rsync://HOST:PORT/PATH". If found, *host_ptr will be set to some allocated
1990 * memory with the HOST. If a daemon-accessing spec was specified, the value
1991 * of *port_ptr will contain a non-0 port number, otherwise it will be set to
1992 * 0. The return value is a pointer to the PATH. Note that the HOST spec can
1993 * be an IPv6 literal address enclosed in '[' and ']' (such as "[::1]" or
1994 * "[::ffff:127.0.0.1]") which is returned without the '[' and ']'. */
1995char *check_for_hostspec(char *s, char **host_ptr, int *port_ptr)
ea5164d1 1996{
305666bf
WD
1997 char *p;
1998 int not_host;
8f4ae68c 1999 int hostlen;
305666bf
WD
2000
2001 if (port_ptr && strncasecmp(URL_PREFIX, s, strlen(URL_PREFIX)) == 0) {
2002 char *path;
305666bf
WD
2003 s += strlen(URL_PREFIX);
2004 if ((p = strchr(s, '/')) != NULL) {
2005 hostlen = p - s;
2006 path = p + 1;
2007 } else {
2008 hostlen = strlen(s);
2009 path = "";
2010 }
2011 if (*s == '[' && (p = strchr(s, ']')) != NULL) {
2012 s++;
2013 hostlen = p - s;
c60b7056
WD
2014 if (p[1] == ':')
2015 *port_ptr = atoi(p+2);
305666bf 2016 } else {
444f9f7b 2017 if ((p = strchr(s, ':')) != NULL && p < s + hostlen) {
305666bf
WD
2018 hostlen = p - s;
2019 *port_ptr = atoi(p+1);
c60b7056 2020 }
305666bf 2021 }
c60b7056
WD
2022 if (!*port_ptr)
2023 *port_ptr = RSYNC_PORT;
305666bf
WD
2024 *host_ptr = new_array(char, hostlen + 1);
2025 strlcpy(*host_ptr, s, hostlen + 1);
2026 return path;
2027 }
ea5164d1 2028
305666bf 2029 if (*s == '[' && (p = strchr(s, ']')) != NULL && p[1] == ':') {
8f4ae68c
WD
2030 s++;
2031 hostlen = p - s;
305666bf
WD
2032 *p = '\0';
2033 not_host = strchr(s, '/') || !strchr(s, ':');
2034 *p = ']';
2035 if (not_host)
2036 return NULL;
c60b7056 2037 p++;
305666bf
WD
2038 } else {
2039 if (!(p = strchr(s, ':')))
2040 return NULL;
8f4ae68c 2041 hostlen = p - s;
305666bf
WD
2042 *p = '\0';
2043 not_host = strchr(s, '/') != NULL;
2044 *p = ':';
2045 if (not_host)
2046 return NULL;
2047 }
2048
8f4ae68c
WD
2049 *host_ptr = new_array(char, hostlen + 1);
2050 strlcpy(*host_ptr, s, hostlen + 1);
ea5164d1 2051
305666bf
WD
2052 if (p[1] == ':') {
2053 if (port_ptr && !*port_ptr)
2054 *port_ptr = RSYNC_PORT;
2055 return p + 2;
2056 }
2057 if (port_ptr)
2058 *port_ptr = 0;
ea5164d1 2059
305666bf 2060 return p + 1;
ea5164d1 2061}