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