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