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