blob: 32b574e33daf60adf09a4133572b537a5391e595 [file] [log] [blame]
Wayne Davison0f78b812006-04-25 20:23:34 +00001/*
2 * Command-line (and received via daemon-socket) option parsing.
Wayne Davisondfa32482003-03-21 18:58:50 +00003 *
Wayne Davison0f78b812006-04-25 20:23:34 +00004 * Copyright (C) 1998-2001 Andrew Tridgell <tridge@samba.org>
5 * Copyright (C) 2000, 2001, 2002 Martin Pool <mbp@samba.org>
Wayne Davisonba2133d2007-02-04 14:54:58 +00006 * Copyright (C) 2002-2007 Wayne Davison
Wayne Davisondfa32482003-03-21 18:58:50 +00007 *
Martin Pooldafe63c2002-04-16 01:38:21 +00008 * This program is free software; you can redistribute it and/or modify
Wayne Davison8e41b682007-07-10 13:55:49 +00009 * 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.
Wayne Davisondfa32482003-03-21 18:58:50 +000012 *
Martin Pooldafe63c2002-04-16 01:38:21 +000013 * 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.
Wayne Davisondfa32482003-03-21 18:58:50 +000017 *
Wayne Davisone7c67062006-04-25 23:51:12 +000018 * You should have received a copy of the GNU General Public License along
Wayne Davison4fd842f2007-07-07 05:33:14 +000019 * with this program; if not, visit the http://fsf.org website.
Martin Pooldafe63c2002-04-16 01:38:21 +000020 */
Andrew Tridgell7a6421f1998-05-10 07:25:40 +000021
Andrew Tridgell7a6421f1998-05-10 07:25:40 +000022#include "rsync.h"
Wayne Davison35bf8fa2006-01-26 22:28:08 +000023#include <popt.h>
Wayne Davison854a1aa2005-10-26 16:47:15 +000024#include "zlib/zlib.h"
Andrew Tridgell7a6421f1998-05-10 07:25:40 +000025
Wayne Davison7bc90b32005-01-29 20:48:20 +000026extern int module_id;
Wayne Davison7be73df2004-03-27 09:46:42 +000027extern int sanitize_paths;
Wayne Davisone2086312007-08-11 16:53:31 +000028extern int daemon_over_rsh;
Wayne Davison78424182005-01-25 10:39:14 +000029extern struct filter_list_struct filter_list;
30extern struct filter_list_struct server_filter_list;
Wayne Davison8645af12003-07-01 21:45:23 +000031
Andrew Tridgell7a6421f1998-05-10 07:25:40 +000032int make_backups = 0;
Martin Pool1bfbf402002-03-19 03:21:53 +000033
34/**
Wayne Davisondfa32482003-03-21 18:58:50 +000035 * If 1, send the whole file as literal data rather than trying to
Martin Pooldafe63c2002-04-16 01:38:21 +000036 * create an incremental diff.
Martin Pool1bfbf402002-03-19 03:21:53 +000037 *
Wayne Davisondfa32482003-03-21 18:58:50 +000038 * If -1, then look at whether we're local or remote and go by that.
Martin Pooldafe63c2002-04-16 01:38:21 +000039 *
40 * @sa disable_deltas_p()
Martin Pool1bfbf402002-03-19 03:21:53 +000041 **/
Wayne Davisondfa32482003-03-21 18:58:50 +000042int whole_file = -1;
Martin Pool1bfbf402002-03-19 03:21:53 +000043
Wayne Davisona0157882005-07-28 01:46:09 +000044int append_mode = 0;
Wayne Davison716e73d2004-06-05 16:16:30 +000045int keep_dirlinks = 0;
Wayne Davison2dbf36e2006-02-24 17:54:30 +000046int copy_dirlinks = 0;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +000047int copy_links = 0;
48int preserve_links = 0;
49int preserve_hard_links = 0;
Wayne Davison1c3344a2007-03-11 00:13:34 +000050int preserve_acls = 0;
Wayne Davison16edf862007-04-07 17:22:25 +000051int preserve_xattrs = 0;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +000052int preserve_perms = 0;
Wayne Davison344f9ba2006-01-31 02:29:58 +000053int preserve_executability = 0;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +000054int preserve_devices = 0;
Wayne Davisonb5c6a6a2006-01-26 10:38:58 +000055int preserve_specials = 0;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +000056int preserve_uid = 0;
57int preserve_gid = 0;
58int preserve_times = 0;
Wayne Davison20fb7b92005-01-24 00:51:32 +000059int omit_dir_times = 0;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +000060int update_only = 0;
61int cvs_exclude = 0;
Wayne Davisona5c11132004-02-09 17:45:22 +000062int dry_run = 0;
Wayne Davison11e758a2005-04-09 18:59:47 +000063int do_xfers = 1;
Wayne Davisona5c11132004-02-09 17:45:22 +000064int ignore_times = 0;
65int delete_mode = 0;
Wayne Davisona51b3162005-01-24 01:41:54 +000066int delete_during = 0;
Wayne Davison51d48392005-01-22 22:48:34 +000067int delete_before = 0;
68int delete_after = 0;
Wayne Davisona5c11132004-02-09 17:45:22 +000069int delete_excluded = 0;
Wayne Davison47c11972006-06-30 15:52:52 +000070int remove_source_files = 0;
Wayne Davisona5c11132004-02-09 17:45:22 +000071int one_file_system = 0;
Wayne Davison4f3e9a02003-09-09 15:58:56 +000072int protocol_version = PROTOCOL_VERSION;
Wayne Davisona5c11132004-02-09 17:45:22 +000073int sparse_files = 0;
74int do_compression = 0;
Wayne Davison854a1aa2005-10-26 16:47:15 +000075int def_compress_level = Z_DEFAULT_COMPRESSION;
Wayne Davison9439c0c2007-04-24 07:32:44 +000076int am_root = 0; /* 0 = normal, 1 = root, 2 = --super, -1 = --fake-super */
Wayne Davison7f2a1f62005-02-25 17:08:31 +000077int am_server = 0;
78int am_sender = 0;
79int am_generator = 0;
80int am_starting_up = 1;
Wayne Davisonea5164d2003-03-30 23:00:42 +000081int relative_paths = -1;
82int implied_dirs = 1;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +000083int numeric_ids = 0;
Wayne Davison5974c662006-02-06 18:41:32 +000084int allow_8bit_chars = 0;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +000085int force_delete = 0;
86int io_timeout = 0;
Wayne Davison9ac756c2005-05-19 08:52:17 +000087int allowed_lull = 0;
Wayne Davison876c9932006-01-28 00:13:55 +000088int prune_empty_dirs = 0;
Wayne Davison8487f9c2007-05-24 02:50:35 +000089int use_qsort = 0;
Wayne Davisonea5164d2003-03-30 23:00:42 +000090char *files_from = NULL;
91int filesfrom_fd = -1;
Wayne Davison305666b2005-03-01 01:15:57 +000092char *filesfrom_host = NULL;
Wayne Davisonea5164d2003-03-30 23:00:42 +000093int eol_nulls = 0;
Wayne Davison8f14cc42005-11-12 19:53:17 +000094int human_readable = 0;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +000095int recurse = 0;
Wayne Davison52750292007-03-14 00:00:01 +000096int allow_inc_recurse = 1;
Wayne Davisonb6164932005-08-27 21:01:45 +000097int xfer_dirs = -1;
Wayne Davison1312d9f2002-08-01 00:37:01 +000098int am_daemon = 0;
Wayne Davisona5c11132004-02-09 17:45:22 +000099int do_stats = 0;
100int do_progress = 0;
101int keep_partial = 0;
102int safe_symlinks = 0;
103int copy_unsafe_links = 0;
104int size_only = 0;
Wayne Davison9fb08442004-11-17 19:29:20 +0000105int daemon_bwlimit = 0;
Wayne Davisona5c11132004-02-09 17:45:22 +0000106int bwlimit = 0;
Wayne Davisonc4ed1482005-02-14 02:41:15 +0000107int fuzzy_basis = 0;
Wayne Davison3c74c3a2004-05-27 21:51:53 +0000108size_t bwlimit_writemax = 0;
Wayne Davisone90aab42005-09-29 18:07:55 +0000109int ignore_existing = 0;
110int ignore_non_existing = 0;
Wayne Davison07c6ae72005-02-20 01:04:40 +0000111int need_messages_from_generator = 0;
Wayne Davison7b9598b2007-07-15 05:42:30 +0000112int max_delete = INT_MIN;
Wayne Davison7d5acf12004-11-11 01:45:25 +0000113OFF_T max_size = 0;
Wayne Davison74de13d2005-10-14 20:15:18 +0000114OFF_T min_size = 0;
Wayne Davisona5c11132004-02-09 17:45:22 +0000115int ignore_errors = 0;
116int modify_window = 0;
117int blocking_io = -1;
Wayne Davison2289bf62004-02-09 18:32:54 +0000118int checksum_seed = 0;
Wayne Davisona3221d22004-07-16 20:06:24 +0000119int inplace = 0;
Wayne Davisonf06e7082005-01-27 22:46:14 +0000120int delay_updates = 0;
Wayne Davisona06b4192005-01-01 21:08:14 +0000121long block_size = 0; /* "long" because popt can't set an int32. */
Wayne Davisonb1e436e2007-07-14 19:24:32 +0000122char *skip_compress = NULL;
Martin Poolb35d0d82002-04-08 04:10:20 +0000123
Martin Pool13e29992001-12-18 05:54:57 +0000124/** Network address family. **/
Wayne Davison24d677f2007-08-22 00:36:56 +0000125int default_af_hint
Wayne Davison4f5b0752005-02-14 00:53:43 +0000126#ifdef INET6
Wayne Davison24d677f2007-08-22 00:36:56 +0000127 = 0; /* Any protocol */
David Dykstra6ab6d4b2001-12-14 18:25:51 +0000128#else
Wayne Davison24d677f2007-08-22 00:36:56 +0000129 = AF_INET; /* Must use IPv4 */
130# ifdef AF_INET6
131# undef AF_INET6
132# endif
133# define AF_INET6 AF_INET /* make -6 option a no-op */
David Dykstra6ab6d4b2001-12-14 18:25:51 +0000134#endif
Martin Pool06963d02001-11-23 07:35:49 +0000135
Martin Pool13e29992001-12-18 05:54:57 +0000136/** Do not go into the background when run as --daemon. Good
137 * for debugging and required for running as a service on W32,
138 * or under Unix process-monitors. **/
Wayne Davison1f35bab2005-02-21 00:31:31 +0000139int no_detach
140#if defined _WIN32 || defined __WIN32__
141 = 1;
142#else
143 = 0;
144#endif
Martin Pool13e29992001-12-18 05:54:57 +0000145
David Dykstra088aac82002-02-06 21:20:48 +0000146int write_batch = 0;
147int read_batch = 0;
Wayne Davisond175d7e2003-08-01 07:58:44 +0000148int backup_dir_len = 0;
149int backup_suffix_len;
Wayne Davisone0391f82004-02-11 04:30:41 +0000150unsigned int backup_dir_remainder;
Martin Pool6902ed12001-08-14 02:04:47 +0000151
Wayne Davisond175d7e2003-08-01 07:58:44 +0000152char *backup_suffix = NULL;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +0000153char *tmpdir = NULL;
Wayne Davisona7260c42004-07-29 16:06:38 +0000154char *partial_dir = NULL;
Wayne Davisone012f852004-11-27 17:52:51 +0000155char *basis_dir[MAX_BASIS_DIRS+1];
David Dykstra30e8c8e2002-08-30 23:27:26 +0000156char *config_file = NULL;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +0000157char *shell_cmd = NULL;
Wayne Davison87c0f9d2006-05-09 18:31:03 +0000158char *logfile_name = NULL;
159char *logfile_format = NULL;
Wayne Davisonb3e4e7e2006-05-29 22:56:45 +0000160char *stdout_format = NULL;
Andrew Tridgell65575e91999-01-08 10:32:56 +0000161char *password_file = NULL;
David Dykstra41bd28f2001-06-12 19:33:41 +0000162char *rsync_path = RSYNC_PATH;
Andrew Tridgell66203a92000-01-24 04:58:53 +0000163char *backup_dir = NULL;
Wayne Davisone0391f82004-02-11 04:30:41 +0000164char backup_dir_buf[MAXPATHLEN];
Wayne Davison831f06a2006-01-26 12:31:24 +0000165char *sockopts = NULL;
Wayne Davison0c56b1a2004-11-27 18:24:12 +0000166int rsync_port = 0;
Wayne Davisondfd7d542005-01-15 20:54:25 +0000167int compare_dest = 0;
Wayne Davison1de3e992005-03-11 17:35:59 +0000168int copy_dest = 0;
David Dykstra59c95e42002-08-29 14:44:55 +0000169int link_dest = 0;
Wayne Davisonce0b3842005-01-15 21:12:58 +0000170int basis_dir_cnt = 0;
Wayne Davisonf9a9f542005-03-09 18:53:53 +0000171char *dest_option = NULL;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +0000172
173int verbose = 0;
David Dykstrab86f0ce1999-02-09 17:25:35 +0000174int quiet = 0;
Wayne Davisondc1f7b92006-10-24 00:36:38 +0000175int output_motd = 1;
Wayne Davisone7651882005-02-16 08:10:31 +0000176int log_before_transfer = 0;
Wayne Davisonb3e4e7e2006-05-29 22:56:45 +0000177int stdout_format_has_i = 0;
178int stdout_format_has_o_or_i = 0;
Wayne Davison87c0f9d2006-05-09 18:31:03 +0000179int logfile_format_has_i = 0;
Wayne Davison87c0f9d2006-05-09 18:31:03 +0000180int logfile_format_has_o_or_i = 0;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +0000181int always_checksum = 0;
Andrew Tridgellf7632fc1998-11-02 00:52:01 +0000182int list_only = 0;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +0000183
Wayne Davison9b3318b2004-07-15 16:27:02 +0000184#define MAX_BATCH_NAME_LEN 256 /* Must be less than MAXPATHLEN-13 */
185char *batch_name = NULL;
Martin Pool6902ed12001-08-14 02:04:47 +0000186
Wayne Davison332cf6d2007-04-26 05:53:13 +0000187#ifdef ICONV_OPTION
188int need_unsorted_flist = 0;
189char *iconv_opt = ICONV_OPTION;
190#endif
191
Wayne Davisondd32e2c2005-11-07 04:28:35 +0000192struct chmod_mode_struct *chmod_modes = NULL;
193
Wayne Davisone1add892004-02-01 17:29:41 +0000194static int daemon_opt; /* sets am_daemon after option error-reporting */
Wayne Davisonaa4d3b42005-01-25 00:52:56 +0000195static int F_option_cnt = 0;
Andrew Tridgell5b56cc12000-09-06 02:12:13 +0000196static int modify_window_set;
Wayne Davison624d6be2005-03-31 00:21:15 +0000197static int itemize_changes = 0;
Wayne Davison854a1aa2005-10-26 16:47:15 +0000198static int refused_delete, refused_archive_part, refused_compress;
Wayne Davison3296f912005-02-15 21:15:58 +0000199static int refused_partial, refused_progress, refused_delete_before;
Wayne Davisone0e32032006-12-28 07:54:10 +0000200static int refused_delete_during;
Wayne Davisona0157882005-07-28 01:46:09 +0000201static int refused_inplace;
Wayne Davison74de13d2005-10-14 20:15:18 +0000202static char *max_size_arg, *min_size_arg;
Wayne Davison77860ba2006-01-29 19:17:13 +0000203static char tmp_partialdir[] = ".~tmp~";
Andrew Tridgell5b56cc12000-09-06 02:12:13 +0000204
Martin Pool06963d02001-11-23 07:35:49 +0000205/** Local address to bind. As a character string because it's
Wayne Davisonfdf57ed2004-06-20 19:47:05 +0000206 * interpreted by the IPv6 layer: should be a numeric IP4 or IP6
Martin Pool06963d02001-11-23 07:35:49 +0000207 * address, or a hostname. **/
208char *bind_address;
Andrew Tridgell5c9730a1999-10-31 03:21:02 +0000209
Martin Pool7a24c342000-11-09 09:05:14 +0000210
Martin Pool27a12342001-12-05 13:45:51 +0000211static void print_rsync_version(enum logcode f)
Martin Pool7a24c342000-11-09 09:05:14 +0000212{
Wayne Davison2ed790f2007-04-23 19:54:07 +0000213 char *subprotocol = "";
Wayne Davisondfa32482003-03-21 18:58:50 +0000214 char const *got_socketpair = "no ";
Wayne Davisona3221d22004-07-16 20:06:24 +0000215 char const *have_inplace = "no ";
Wayne Davisondfa32482003-03-21 18:58:50 +0000216 char const *hardlinks = "no ";
Wayne Davison1c3344a2007-03-11 00:13:34 +0000217 char const *acls = "no ";
Wayne Davison16edf862007-04-07 17:22:25 +0000218 char const *xattrs = "no ";
Wayne Davisondfa32482003-03-21 18:58:50 +0000219 char const *links = "no ";
Wayne Davison332cf6d2007-04-26 05:53:13 +0000220 char const *iconv = "no ";
Martin Poola3584492001-11-24 04:57:41 +0000221 char const *ipv6 = "no ";
Martin Pool736a6a22002-01-11 07:15:16 +0000222 STRUCT_STAT *dumstat;
Martin Pool0c80cd82000-11-10 03:41:47 +0000223
Wayne Davison2ed790f2007-04-23 19:54:07 +0000224#if SUBPROTOCOL_VERSION != 0
225 asprintf(&subprotocol, ".PR%d", SUBPROTOCOL_VERSION);
226#endif
Wayne Davison4f5b0752005-02-14 00:53:43 +0000227#ifdef HAVE_SOCKETPAIR
Wayne Davisondfa32482003-03-21 18:58:50 +0000228 got_socketpair = "";
Martin Pool0c80cd82000-11-10 03:41:47 +0000229#endif
Wayne Davison4f5b0752005-02-14 00:53:43 +0000230#ifdef HAVE_FTRUNCATE
Wayne Davisona3221d22004-07-16 20:06:24 +0000231 have_inplace = "";
232#endif
Wayne Davison4f5b0752005-02-14 00:53:43 +0000233#ifdef SUPPORT_HARD_LINKS
Wayne Davisondfa32482003-03-21 18:58:50 +0000234 hardlinks = "";
Martin Pool2855f612001-02-23 01:02:31 +0000235#endif
Wayne Davison1c3344a2007-03-11 00:13:34 +0000236#ifdef SUPPORT_ACLS
237 acls = "";
238#endif
Wayne Davison16edf862007-04-07 17:22:25 +0000239#ifdef SUPPORT_XATTRS
240 xattrs = "";
241#endif
Wayne Davison4f5b0752005-02-14 00:53:43 +0000242#ifdef SUPPORT_LINKS
Wayne Davisondfa32482003-03-21 18:58:50 +0000243 links = "";
Martin Pool2855f612001-02-23 01:02:31 +0000244#endif
Wayne Davison4f5b0752005-02-14 00:53:43 +0000245#ifdef INET6
Martin Poola3584492001-11-24 04:57:41 +0000246 ipv6 = "";
Wayne Davisondfa32482003-03-21 18:58:50 +0000247#endif
Wayne Davison332cf6d2007-04-26 05:53:13 +0000248#ifdef ICONV_OPTION
249 iconv = "";
250#endif
Martin Poola3584492001-11-24 04:57:41 +0000251
Wayne Davison719522b2007-04-21 19:46:19 +0000252 rprintf(f, "%s version %s protocol version %d%s\n",
Wayne Davison2ed790f2007-04-23 19:54:07 +0000253 RSYNC_NAME, RSYNC_VERSION, PROTOCOL_VERSION, subprotocol);
Wayne Davison100018b2007-01-31 21:46:49 +0000254 rprintf(f, "Copyright (C) 1996-2007 by Andrew Tridgell, Wayne Davison, and others.\n");
Wayne Davison719522b2007-04-21 19:46:19 +0000255 rprintf(f, "Web site: http://rsync.samba.org/\n");
256 rprintf(f, "Capabilities:\n");
257 rprintf(f, " %d-bit files, %d-bit inums, %d-bit timestamps, %d-bit long ints,\n",
Wayne Davisond619ff12006-12-01 18:29:18 +0000258 (int)(sizeof (OFF_T) * 8),
259 (int)(sizeof dumstat->st_ino * 8), /* Don't check ino_t! */
Wayne Davisonbb257792007-04-21 19:31:54 +0000260 (int)(sizeof (time_t) * 8),
Wayne Davisond619ff12006-12-01 18:29:18 +0000261 (int)(sizeof (int64) * 8));
262 rprintf(f, " %ssocketpairs, %shardlinks, %ssymlinks, %sIPv6, batchfiles, %sinplace,\n",
263 got_socketpair, hardlinks, links, ipv6, have_inplace);
Wayne Davison332cf6d2007-04-26 05:53:13 +0000264 rprintf(f, " %sappend, %sACLs, %sxattrs, %siconv\n",
265 have_inplace, acls, xattrs, iconv);
Martin Pool2855f612001-02-23 01:02:31 +0000266
Martin Poolfc0302c2002-04-08 07:36:05 +0000267#ifdef MAINTAINER_MODE
Wayne Davison29433532006-02-02 11:40:32 +0000268 rprintf(f, "Panic Action: \"%s\"\n", get_panic_action());
Martin Poolfc0302c2002-04-08 07:36:05 +0000269#endif
Martin Pool736a6a22002-01-11 07:15:16 +0000270
Wayne Davison031fa9a2005-01-28 06:46:33 +0000271#if SIZEOF_INT64 < 8
272 rprintf(f, "WARNING: no 64-bit integers on this platform!\n");
Martin Pool7a24c342000-11-09 09:05:14 +0000273#endif
Wayne Davisonc561eda2005-01-28 06:51:44 +0000274 if (sizeof (int64) != SIZEOF_INT64) {
275 rprintf(f,
276 "WARNING: size mismatch in SIZEOF_INT64 define (%d != %d)\n",
277 (int) SIZEOF_INT64, (int) sizeof (int64));
278 }
Martin Pool7b329a22002-03-19 05:00:05 +0000279
Wayne Davisonb64ee912006-06-01 08:04:47 +0000280 rprintf(f,"\n");
281 rprintf(f,"rsync comes with ABSOLUTELY NO WARRANTY. This is free software, and you\n");
Wayne Davison6ab423a2006-01-17 04:26:12 +0000282 rprintf(f,"are welcome to redistribute it under certain conditions. See the GNU\n");
283 rprintf(f,"General Public Licence for details.\n");
Martin Pool7a24c342000-11-09 09:05:14 +0000284}
285
286
Andrew Tridgell0f3203c2000-01-29 02:49:03 +0000287void usage(enum logcode F)
Andrew Tridgell7a6421f1998-05-10 07:25:40 +0000288{
Martin Pool2855f612001-02-23 01:02:31 +0000289 print_rsync_version(F);
Andrew Tridgell704f9081998-06-18 09:31:42 +0000290
Wayne Davisonb64ee912006-06-01 08:04:47 +0000291 rprintf(F,"\n");
292 rprintf(F,"rsync is a file transfer program capable of efficient remote update\n");
Wayne Davison6ab423a2006-01-17 04:26:12 +0000293 rprintf(F,"via a fast differencing algorithm.\n");
Andrew Tridgell704f9081998-06-18 09:31:42 +0000294
Wayne Davisonb64ee912006-06-01 08:04:47 +0000295 rprintf(F,"\n");
296 rprintf(F,"Usage: rsync [OPTION]... SRC [SRC]... DEST\n");
Wayne Davison868676d2005-09-21 22:39:49 +0000297 rprintf(F," or rsync [OPTION]... SRC [SRC]... [USER@]HOST:DEST\n");
David Dykstra9ef53901999-02-10 19:33:05 +0000298 rprintf(F," or rsync [OPTION]... SRC [SRC]... [USER@]HOST::DEST\n");
Wayne Davisoneaa4c152002-08-01 17:55:11 +0000299 rprintf(F," or rsync [OPTION]... SRC [SRC]... rsync://[USER@]HOST[:PORT]/DEST\n");
Wayne Davison868676d2005-09-21 22:39:49 +0000300 rprintf(F," or rsync [OPTION]... [USER@]HOST:SRC [DEST]\n");
301 rprintf(F," or rsync [OPTION]... [USER@]HOST::SRC [DEST]\n");
302 rprintf(F," or rsync [OPTION]... rsync://[USER@]HOST[:PORT]/SRC [DEST]\n");
Wayne Davison08d82b82005-09-13 01:02:54 +0000303 rprintf(F,"The ':' usages connect via remote shell, while '::' & 'rsync://' usages connect\n");
304 rprintf(F,"to an rsync daemon, and require SRC or DEST to start with a module name.\n");
Wayne Davisonb64ee912006-06-01 08:04:47 +0000305 rprintf(F,"\n");
306 rprintf(F,"Options\n");
Andrew Tridgell704f9081998-06-18 09:31:42 +0000307 rprintf(F," -v, --verbose increase verbosity\n");
Wayne Davisonb3708ac2005-01-28 09:55:18 +0000308 rprintf(F," -q, --quiet suppress non-error messages\n");
Wayne Davisondc1f7b92006-10-24 00:36:38 +0000309 rprintf(F," --no-motd suppress daemon-mode MOTD (see manpage caveat)\n");
Wayne Davisonb3708ac2005-01-28 09:55:18 +0000310 rprintf(F," -c, --checksum skip based on checksum, not mod-time & size\n");
Wayne Davison16edf862007-04-07 17:22:25 +0000311 rprintf(F," -a, --archive archive mode; equals -rlptgoD (no -H,-A,-X)\n");
Wayne Davison8938d672005-11-15 07:05:55 +0000312 rprintf(F," --no-OPTION turn off an implied OPTION (e.g. --no-D)\n");
Andrew Tridgell704f9081998-06-18 09:31:42 +0000313 rprintf(F," -r, --recursive recurse into directories\n");
314 rprintf(F," -R, --relative use relative path names\n");
Wayne Davison11bfaf62005-08-27 20:01:45 +0000315 rprintf(F," --no-implied-dirs don't send implied dirs with --relative\n");
Wayne Davison68391402003-12-30 18:16:25 +0000316 rprintf(F," -b, --backup make backups (see --suffix & --backup-dir)\n");
Wayne Davisonb3708ac2005-01-28 09:55:18 +0000317 rprintf(F," --backup-dir=DIR make backups into hierarchy based in DIR\n");
318 rprintf(F," --suffix=SUFFIX set backup suffix (default %s w/o --backup-dir)\n",BACKUP_SUFFIX);
319 rprintf(F," -u, --update skip files that are newer on the receiver\n");
Wayne Davison4ce838e2005-01-17 23:11:18 +0000320 rprintf(F," --inplace update destination files in-place (SEE MAN PAGE)\n");
Wayne Davisona0157882005-07-28 01:46:09 +0000321 rprintf(F," --append append data onto shorter files\n");
Wayne Davison936fa862007-09-01 16:38:00 +0000322 rprintf(F," --append-verify like --append, but with old data in file checksum\n");
Wayne Davison65e4cda2005-01-24 00:17:39 +0000323 rprintf(F," -d, --dirs transfer directories without recursing\n");
Martin Pool13e29992001-12-18 05:54:57 +0000324 rprintf(F," -l, --links copy symlinks as symlinks\n");
Wayne Davisonb3708ac2005-01-28 09:55:18 +0000325 rprintf(F," -L, --copy-links transform symlink into referent file/dir\n");
326 rprintf(F," --copy-unsafe-links only \"unsafe\" symlinks are transformed\n");
327 rprintf(F," --safe-links ignore symlinks that point outside the source tree\n");
Wayne Davison2dbf36e2006-02-24 17:54:30 +0000328 rprintf(F," -k, --copy-dirlinks transform symlink to a dir into referent dir\n");
Wayne Davison65e4cda2005-01-24 00:17:39 +0000329 rprintf(F," -K, --keep-dirlinks treat symlinked dir on receiver as dir\n");
Wayne Davison2dbf36e2006-02-24 17:54:30 +0000330 rprintf(F," -H, --hard-links preserve hard links\n");
Andrew Tridgell704f9081998-06-18 09:31:42 +0000331 rprintf(F," -p, --perms preserve permissions\n");
Wayne Davison344f9ba2006-01-31 02:29:58 +0000332 rprintf(F," -E, --executability preserve the file's executability\n");
Wayne Davisondfe1ed52006-10-09 00:55:04 +0000333 rprintf(F," --chmod=CHMOD affect file and/or directory permissions\n");
Wayne Davison1c3344a2007-03-11 00:13:34 +0000334#ifdef SUPPORT_ACLS
335 rprintf(F," -A, --acls preserve ACLs (implies --perms)\n");
336#endif
Wayne Davison16edf862007-04-07 17:22:25 +0000337#ifdef SUPPORT_XATTRS
Wayne Davison3caafdf2007-08-04 22:19:43 +0000338 rprintf(F," -X, --xattrs preserve extended attributes\n");
Wayne Davison16edf862007-04-07 17:22:25 +0000339#endif
Wayne Davisondef97ff2006-01-26 11:10:32 +0000340 rprintf(F," -o, --owner preserve owner (super-user only)\n");
Andrew Tridgell704f9081998-06-18 09:31:42 +0000341 rprintf(F," -g, --group preserve group\n");
Wayne Davisondef97ff2006-01-26 11:10:32 +0000342 rprintf(F," --devices preserve device files (super-user only)\n");
Wayne Davisonb5c6a6a2006-01-26 10:38:58 +0000343 rprintf(F," --specials preserve special files\n");
344 rprintf(F," -D same as --devices --specials\n");
Wayne Davison42b06482007-07-12 14:43:26 +0000345 rprintf(F," -t, --times preserve modification times\n");
346 rprintf(F," -O, --omit-dir-times omit directories from --times\n");
Wayne Davisondef97ff2006-01-26 11:10:32 +0000347 rprintf(F," --super receiver attempts super-user activities\n");
Wayne Davison9439c0c2007-04-24 07:32:44 +0000348#ifdef SUPPORT_XATTRS
349 rprintf(F," --fake-super store/recover privileged attrs using xattrs\n");
350#endif
Andrew Tridgell704f9081998-06-18 09:31:42 +0000351 rprintf(F," -S, --sparse handle sparse files efficiently\n");
352 rprintf(F," -n, --dry-run show what would have been transferred\n");
Wayne Davison98bf61c2005-02-14 19:09:30 +0000353 rprintf(F," -W, --whole-file copy files whole (without rsync algorithm)\n");
Andrew Tridgell704f9081998-06-18 09:31:42 +0000354 rprintf(F," -x, --one-file-system don't cross filesystem boundaries\n");
Wayne Davison9cd339e2004-08-03 08:05:20 +0000355 rprintf(F," -B, --block-size=SIZE force a fixed checksum block-size\n");
Wayne Davisonb3708ac2005-01-28 09:55:18 +0000356 rprintf(F," -e, --rsh=COMMAND specify the remote shell to use\n");
Wayne Davison05ee4862005-03-02 09:17:42 +0000357 rprintf(F," --rsync-path=PROGRAM specify the rsync to run on the remote machine\n");
Wayne Davisonfcecb702006-05-05 06:16:22 +0000358 rprintf(F," --existing skip creating new files on receiver\n");
359 rprintf(F," --ignore-existing skip updating files that already exist on receiver\n");
Wayne Davison47c11972006-06-30 15:52:52 +0000360 rprintf(F," --remove-source-files sender removes synchronized files (non-dirs)\n");
Wayne Davison3359acb2005-01-25 03:08:58 +0000361 rprintf(F," --del an alias for --delete-during\n");
Wayne Davisonfcecb702006-05-05 06:16:22 +0000362 rprintf(F," --delete delete extraneous files from destination dirs\n");
Wayne Davisone0e32032006-12-28 07:54:10 +0000363 rprintf(F," --delete-before receiver deletes before transfer, not during\n");
364 rprintf(F," --delete-during receiver deletes during transfer (default)\n");
Wayne Davisonb0cacef2006-11-22 20:49:23 +0000365 rprintf(F," --delete-delay find deletions during, delete after\n");
Wayne Davisone0e32032006-12-28 07:54:10 +0000366 rprintf(F," --delete-after receiver deletes after transfer, not during\n");
Wayne Davisonfcecb702006-05-05 06:16:22 +0000367 rprintf(F," --delete-excluded also delete excluded files from destination dirs\n");
Wayne Davisondb2b5cb2004-01-23 09:32:50 +0000368 rprintf(F," --ignore-errors delete even if there are I/O errors\n");
Wayne Davison51d48392005-01-22 22:48:34 +0000369 rprintf(F," --force force deletion of directories even if not empty\n");
Andrew Tridgell0b73ca12000-01-23 11:43:04 +0000370 rprintf(F," --max-delete=NUM don't delete more than NUM files\n");
Wayne Davison7d5acf12004-11-11 01:45:25 +0000371 rprintf(F," --max-size=SIZE don't transfer any file larger than SIZE\n");
Wayne Davison74de13d2005-10-14 20:15:18 +0000372 rprintf(F," --min-size=SIZE don't transfer any file smaller than SIZE\n");
Andrew Tridgellc95da961998-07-01 03:36:03 +0000373 rprintf(F," --partial keep partially transferred files\n");
Wayne Davisona7260c42004-07-29 16:06:38 +0000374 rprintf(F," --partial-dir=DIR put a partially transferred file into DIR\n");
Wayne Davisonb3708ac2005-01-28 09:55:18 +0000375 rprintf(F," --delay-updates put all updated files into place at transfer's end\n");
Wayne Davison876c9932006-01-28 00:13:55 +0000376 rprintf(F," -m, --prune-empty-dirs prune empty directory chains from the file-list\n");
Andrew Tridgell704f9081998-06-18 09:31:42 +0000377 rprintf(F," --numeric-ids don't map uid/gid values by user/group name\n");
Wayne Davisondb2b5cb2004-01-23 09:32:50 +0000378 rprintf(F," --timeout=TIME set I/O timeout in seconds\n");
Wayne Davisonb3708ac2005-01-28 09:55:18 +0000379 rprintf(F," -I, --ignore-times don't skip files that match in size and mod-time\n");
380 rprintf(F," --size-only skip files that match in size\n");
381 rprintf(F," --modify-window=NUM compare mod-times with reduced accuracy\n");
Wayne Davison4db88e52004-07-22 15:43:28 +0000382 rprintf(F," -T, --temp-dir=DIR create temporary files in directory DIR\n");
Wayne Davisonc4ed1482005-02-14 02:41:15 +0000383 rprintf(F," -y, --fuzzy find similar file for basis if no dest file\n");
David Dykstra375a4551998-10-26 21:42:38 +0000384 rprintf(F," --compare-dest=DIR also compare destination files relative to DIR\n");
Wayne Davison1de3e992005-03-11 17:35:59 +0000385 rprintf(F," --copy-dest=DIR ... and include copies of unchanged files\n");
Wayne Davisone012f852004-11-27 17:52:51 +0000386 rprintf(F," --link-dest=DIR hardlink to files in DIR when unchanged\n");
Wayne Davisonf9249462005-02-12 22:22:14 +0000387 rprintf(F," -z, --compress compress file data during the transfer\n");
Wayne Davison854a1aa2005-10-26 16:47:15 +0000388 rprintf(F," --compress-level=NUM explicitly set compression level\n");
Wayne Davisonb1e436e2007-07-14 19:24:32 +0000389 rprintf(F," --skip-compress=LIST skip compressing files with a suffix in LIST\n");
Wayne Davisonb3708ac2005-01-28 09:55:18 +0000390 rprintf(F," -C, --cvs-exclude auto-ignore files the same way CVS does\n");
Wayne Davisonaa4d3b42005-01-25 00:52:56 +0000391 rprintf(F," -f, --filter=RULE add a file-filtering RULE\n");
Wayne Davison9c71f562005-02-13 05:44:29 +0000392 rprintf(F," -F same as --filter='dir-merge /.rsync-filter'\n");
Wayne Davisonaa4d3b42005-01-25 00:52:56 +0000393 rprintf(F," repeated: --filter='- .rsync-filter'\n");
David Dykstra2acf81e1998-11-03 21:17:40 +0000394 rprintf(F," --exclude=PATTERN exclude files matching PATTERN\n");
Wayne Davisonb3708ac2005-01-28 09:55:18 +0000395 rprintf(F," --exclude-from=FILE read exclude patterns from FILE\n");
David Dykstra2acf81e1998-11-03 21:17:40 +0000396 rprintf(F," --include=PATTERN don't exclude files matching PATTERN\n");
Wayne Davisonb3708ac2005-01-28 09:55:18 +0000397 rprintf(F," --include-from=FILE read include patterns from FILE\n");
398 rprintf(F," --files-from=FILE read list of source-file names from FILE\n");
Wayne Davison72316022005-05-02 17:23:08 +0000399 rprintf(F," -0, --from0 all *-from/filter files are delimited by 0s\n");
Wayne Davisonb4ef0bc2005-04-05 05:59:49 +0000400 rprintf(F," --address=ADDRESS bind address for outgoing socket to daemon\n");
Wayne Davisonb4713292004-12-08 17:29:54 +0000401 rprintf(F," --port=PORT specify double-colon alternate port number\n");
Wayne Davison831f06a2006-01-26 12:31:24 +0000402 rprintf(F," --sockopts=OPTIONS specify custom TCP options\n");
Wayne Davisondb2b5cb2004-01-23 09:32:50 +0000403 rprintf(F," --blocking-io use blocking I/O for the remote shell\n");
Wayne Davisonb3708ac2005-01-28 09:55:18 +0000404 rprintf(F," --stats give some file-transfer stats\n");
Wayne Davisona6a27602006-02-06 18:51:25 +0000405 rprintf(F," -8, --8-bit-output leave high-bit chars unescaped in output\n");
Wayne Davison05724c02005-11-15 06:35:27 +0000406 rprintf(F," -h, --human-readable output numbers in a human-readable format\n");
Wayne Davisondfa32482003-03-21 18:58:50 +0000407 rprintf(F," --progress show progress during transfer\n");
Wayne Davisonb3708ac2005-01-28 09:55:18 +0000408 rprintf(F," -P same as --partial --progress\n");
Wayne Davisonb78296c2005-02-15 07:41:13 +0000409 rprintf(F," -i, --itemize-changes output a change-summary for all updates\n");
Wayne Davisonb3e4e7e2006-05-29 22:56:45 +0000410 rprintf(F," --out-format=FORMAT output updates using the specified FORMAT\n");
411 rprintf(F," --log-file=FILE log what we're doing to the specified FILE\n");
412 rprintf(F," --log-file-format=FMT log updates using the specified FMT\n");
Wayne Davison09a54c32006-12-24 01:30:24 +0000413 rprintf(F," --password-file=FILE read daemon-access password from FILE\n");
Wayne Davison65e4cda2005-01-24 00:17:39 +0000414 rprintf(F," --list-only list the files instead of copying them\n");
Wayne Davisonb3708ac2005-01-28 09:55:18 +0000415 rprintf(F," --bwlimit=KBPS limit I/O bandwidth; KBytes per second\n");
416 rprintf(F," --write-batch=FILE write a batched update to FILE\n");
Wayne Davison11e758a2005-04-09 18:59:47 +0000417 rprintf(F," --only-write-batch=FILE like --write-batch but w/o updating destination\n");
Wayne Davisonb3708ac2005-01-28 09:55:18 +0000418 rprintf(F," --read-batch=FILE read a batched update from FILE\n");
Wayne Davisonda9f5922005-03-28 20:40:25 +0000419 rprintf(F," --protocol=NUM force an older protocol version to be used\n");
Wayne Davison332cf6d2007-04-26 05:53:13 +0000420#ifdef ICONV_OPTION
421 rprintf(F," --iconv=CONVERT_SPEC request charset conversion of filesnames\n");
422#endif
Wayne Davison4db88e52004-07-22 15:43:28 +0000423 rprintf(F," -4, --ipv4 prefer IPv4\n");
424 rprintf(F," -6, --ipv6 prefer IPv6\n");
Wayne Davison4a34c6f2005-05-03 16:46:49 +0000425 rprintf(F," --version print version number\n");
Wayne Davison375d8f92006-02-11 00:01:22 +0000426 rprintf(F,"(-h) --help show this help (-h works with no other options)\n");
Andrew Tridgell7a6421f1998-05-10 07:25:40 +0000427
Wayne Davisonb64ee912006-06-01 08:04:47 +0000428 rprintf(F,"\n");
429 rprintf(F,"Use \"rsync --daemon --help\" to see the daemon-mode command-line options.\n");
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000430 rprintf(F,"Please see the rsync(1) and rsyncd.conf(5) man pages for full documentation.\n");
Martin Pool2855f612001-02-23 01:02:31 +0000431 rprintf(F,"See http://rsync.samba.org/ for updates, bug reports, and answers\n");
Andrew Tridgell7a6421f1998-05-10 07:25:40 +0000432}
433
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000434enum {OPT_VERSION = 1000, OPT_DAEMON, OPT_SENDER, OPT_EXCLUDE, OPT_EXCLUDE_FROM,
Wayne Davison05724c02005-11-15 06:35:27 +0000435 OPT_FILTER, OPT_COMPARE_DEST, OPT_COPY_DEST, OPT_LINK_DEST, OPT_HELP,
Wayne Davisone16adcd2006-01-21 09:14:42 +0000436 OPT_INCLUDE, OPT_INCLUDE_FROM, OPT_MODIFY_WINDOW, OPT_MIN_SIZE, OPT_CHMOD,
Wayne Davison9ac756c2005-05-19 08:52:17 +0000437 OPT_READ_BATCH, OPT_WRITE_BATCH, OPT_ONLY_WRITE_BATCH, OPT_MAX_SIZE,
Wayne Davison936fa862007-09-01 16:38:00 +0000438 OPT_NO_D, OPT_APPEND,
Wayne Davison0ccffd72006-01-21 20:15:49 +0000439 OPT_SERVER, OPT_REFUSED_BASE = 9000};
Andrew Tridgell7a6421f1998-05-10 07:25:40 +0000440
Martin Pool2855f612001-02-23 01:02:31 +0000441static struct poptOption long_options[] = {
442 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
Wayne Davison05724c02005-11-15 06:35:27 +0000443 {"help", 0, POPT_ARG_NONE, 0, OPT_HELP, 0, 0 },
Wayne Davison8db7cc22004-10-11 10:43:25 +0000444 {"version", 0, POPT_ARG_NONE, 0, OPT_VERSION, 0, 0},
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000445 {"verbose", 'v', POPT_ARG_NONE, 0, 'v', 0, 0 },
Wayne Davisonb6164932005-08-27 21:01:45 +0000446 {"no-verbose", 0, POPT_ARG_VAL, &verbose, 0, 0, 0 },
Wayne Davison4afcb702005-08-28 00:43:51 +0000447 {"no-v", 0, POPT_ARG_VAL, &verbose, 0, 0, 0 },
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000448 {"quiet", 'q', POPT_ARG_NONE, 0, 'q', 0, 0 },
Wayne Davisondc1f7b92006-10-24 00:36:38 +0000449 {"motd", 0, POPT_ARG_VAL, &output_motd, 1, 0, 0 },
450 {"no-motd", 0, POPT_ARG_VAL, &output_motd, 0, 0, 0 },
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000451 {"stats", 0, POPT_ARG_NONE, &do_stats, 0, 0, 0 },
Wayne Davison3ca9e5d2006-02-08 16:52:25 +0000452 {"human-readable", 'h', POPT_ARG_NONE, 0, 'h', 0, 0},
Wayne Davison8487f9c2007-05-24 02:50:35 +0000453 {"no-human-readable",0, POPT_ARG_VAL, &human_readable, 0, 0, 0},
454 {"no-h", 0, POPT_ARG_VAL, &human_readable, 0, 0, 0},
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000455 {"dry-run", 'n', POPT_ARG_NONE, &dry_run, 0, 0, 0 },
Wayne Davisonb6164932005-08-27 21:01:45 +0000456 {"archive", 'a', POPT_ARG_NONE, 0, 'a', 0, 0 },
457 {"recursive", 'r', POPT_ARG_VAL, &recurse, 2, 0, 0 },
458 {"no-recursive", 0, POPT_ARG_VAL, &recurse, 0, 0, 0 },
459 {"no-r", 0, POPT_ARG_VAL, &recurse, 0, 0, 0 },
Wayne Davison8487f9c2007-05-24 02:50:35 +0000460 {"inc-recursive", 0, POPT_ARG_VAL, &allow_inc_recurse, 1, 0, 0 },
461 {"no-inc-recursive", 0, POPT_ARG_VAL, &allow_inc_recurse, 0, 0, 0 },
462 {"ir", 0, POPT_ARG_VAL, &allow_inc_recurse, 1, 0, 0 },
463 {"no-ir", 0, POPT_ARG_VAL, &allow_inc_recurse, 0, 0, 0 },
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000464 {"dirs", 'd', POPT_ARG_VAL, &xfer_dirs, 2, 0, 0 },
Wayne Davisonb6164932005-08-27 21:01:45 +0000465 {"no-dirs", 0, POPT_ARG_VAL, &xfer_dirs, 0, 0, 0 },
466 {"no-d", 0, POPT_ARG_VAL, &xfer_dirs, 0, 0, 0 },
467 {"perms", 'p', POPT_ARG_VAL, &preserve_perms, 1, 0, 0 },
468 {"no-perms", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
469 {"no-p", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
Wayne Davison344f9ba2006-01-31 02:29:58 +0000470 {"executability", 'E', POPT_ARG_NONE, &preserve_executability, 0, 0, 0 },
Wayne Davison1c3344a2007-03-11 00:13:34 +0000471 {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 },
472 {"no-acls", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
473 {"no-A", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
Wayne Davison16edf862007-04-07 17:22:25 +0000474 {"xattrs", 'X', POPT_ARG_NONE, 0, 'X', 0, 0 },
475 {"no-xattrs", 0, POPT_ARG_VAL, &preserve_xattrs, 0, 0, 0 },
476 {"no-X", 0, POPT_ARG_VAL, &preserve_xattrs, 0, 0, 0 },
Wayne Davisonb6164932005-08-27 21:01:45 +0000477 {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
Wayne Davisonb6164932005-08-27 21:01:45 +0000478 {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
479 {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
Wayne Davison38b91702005-08-27 21:12:44 +0000480 {"omit-dir-times", 'O', POPT_ARG_VAL, &omit_dir_times, 2, 0, 0 },
481 {"modify-window", 0, POPT_ARG_INT, &modify_window, OPT_MODIFY_WINDOW, 0, 0 },
Wayne Davisondef97ff2006-01-26 11:10:32 +0000482 {"super", 0, POPT_ARG_VAL, &am_root, 2, 0, 0 },
483 {"no-super", 0, POPT_ARG_VAL, &am_root, 0, 0, 0 },
Wayne Davison9439c0c2007-04-24 07:32:44 +0000484 {"fake-super", 0, POPT_ARG_VAL, &am_root, -1, 0, 0 },
Wayne Davisonb6164932005-08-27 21:01:45 +0000485 {"owner", 'o', POPT_ARG_VAL, &preserve_uid, 1, 0, 0 },
486 {"no-owner", 0, POPT_ARG_VAL, &preserve_uid, 0, 0, 0 },
487 {"no-o", 0, POPT_ARG_VAL, &preserve_uid, 0, 0, 0 },
488 {"group", 'g', POPT_ARG_VAL, &preserve_gid, 1, 0, 0 },
489 {"no-group", 0, POPT_ARG_VAL, &preserve_gid, 0, 0, 0 },
490 {"no-g", 0, POPT_ARG_VAL, &preserve_gid, 0, 0, 0 },
Wayne Davisonb5c6a6a2006-01-26 10:38:58 +0000491 {0, 'D', POPT_ARG_NONE, 0, 'D', 0, 0 },
492 {"no-D", 0, POPT_ARG_NONE, 0, OPT_NO_D, 0, 0 },
493 {"devices", 0, POPT_ARG_VAL, &preserve_devices, 1, 0, 0 },
Wayne Davisonb6164932005-08-27 21:01:45 +0000494 {"no-devices", 0, POPT_ARG_VAL, &preserve_devices, 0, 0, 0 },
Wayne Davisonb5c6a6a2006-01-26 10:38:58 +0000495 {"specials", 0, POPT_ARG_VAL, &preserve_specials, 1, 0, 0 },
496 {"no-specials", 0, POPT_ARG_VAL, &preserve_specials, 0, 0, 0 },
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000497 {"links", 'l', POPT_ARG_VAL, &preserve_links, 1, 0, 0 },
Wayne Davisonb6164932005-08-27 21:01:45 +0000498 {"no-links", 0, POPT_ARG_VAL, &preserve_links, 0, 0, 0 },
499 {"no-l", 0, POPT_ARG_VAL, &preserve_links, 0, 0, 0 },
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000500 {"copy-links", 'L', POPT_ARG_NONE, &copy_links, 0, 0, 0 },
501 {"copy-unsafe-links",0, POPT_ARG_NONE, &copy_unsafe_links, 0, 0, 0 },
502 {"safe-links", 0, POPT_ARG_NONE, &safe_symlinks, 0, 0, 0 },
Wayne Davison2dbf36e2006-02-24 17:54:30 +0000503 {"copy-dirlinks", 'k', POPT_ARG_NONE, &copy_dirlinks, 0, 0, 0 },
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000504 {"keep-dirlinks", 'K', POPT_ARG_NONE, &keep_dirlinks, 0, 0, 0 },
Wayne Davisone0e32032006-12-28 07:54:10 +0000505 {"hard-links", 'H', POPT_ARG_NONE, 0, 'H', 0, 0 },
Wayne Davisonbeab3072006-02-27 23:35:18 +0000506 {"no-hard-links", 0, POPT_ARG_VAL, &preserve_hard_links, 0, 0, 0 },
507 {"no-H", 0, POPT_ARG_VAL, &preserve_hard_links, 0, 0, 0 },
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000508 {"relative", 'R', POPT_ARG_VAL, &relative_paths, 1, 0, 0 },
509 {"no-relative", 0, POPT_ARG_VAL, &relative_paths, 0, 0, 0 },
Wayne Davisonb6164932005-08-27 21:01:45 +0000510 {"no-R", 0, POPT_ARG_VAL, &relative_paths, 0, 0, 0 },
Wayne Davison2dbf36e2006-02-24 17:54:30 +0000511 {"implied-dirs", 0, POPT_ARG_VAL, &implied_dirs, 1, 0, 0 },
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000512 {"no-implied-dirs", 0, POPT_ARG_VAL, &implied_dirs, 0, 0, 0 },
Wayne Davisone16adcd2006-01-21 09:14:42 +0000513 {"chmod", 0, POPT_ARG_STRING, 0, OPT_CHMOD, 0, 0 },
Wayne Davisonafb6e942003-03-21 19:17:23 +0000514 {"ignore-times", 'I', POPT_ARG_NONE, &ignore_times, 0, 0, 0 },
515 {"size-only", 0, POPT_ARG_NONE, &size_only, 0, 0, 0 },
Wayne Davison243c9952006-01-21 00:36:15 +0000516 {"one-file-system", 'x', POPT_ARG_NONE, 0, 'x', 0, 0 },
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000517 {"update", 'u', POPT_ARG_NONE, &update_only, 0, 0, 0 },
Wayne Davisone90aab42005-09-29 18:07:55 +0000518 {"existing", 0, POPT_ARG_NONE, &ignore_non_existing, 0, 0, 0 },
Wayne Davisone90aab42005-09-29 18:07:55 +0000519 {"ignore-non-existing",0,POPT_ARG_NONE, &ignore_non_existing, 0, 0, 0 },
Wayne Davisond2da9152005-12-19 01:59:00 +0000520 {"ignore-existing", 0, POPT_ARG_NONE, &ignore_existing, 0, 0, 0 },
Wayne Davisonaeb213e2005-10-14 18:56:07 +0000521 {"max-size", 0, POPT_ARG_STRING, &max_size_arg, OPT_MAX_SIZE, 0, 0 },
Wayne Davison74de13d2005-10-14 20:15:18 +0000522 {"min-size", 0, POPT_ARG_STRING, &min_size_arg, OPT_MIN_SIZE, 0, 0 },
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000523 {"sparse", 'S', POPT_ARG_NONE, &sparse_files, 0, 0, 0 },
524 {"inplace", 0, POPT_ARG_NONE, &inplace, 0, 0, 0 },
Wayne Davison936fa862007-09-01 16:38:00 +0000525 {"append", 0, POPT_ARG_NONE, 0, OPT_APPEND, 0, 0 },
526 {"append-verify", 0, POPT_ARG_VAL, &append_mode, 2, 0, 0 },
527 {"no-append", 0, POPT_ARG_VAL, &append_mode, 0, 0, 0 },
Wayne Davison36719872005-02-11 10:42:55 +0000528 {"del", 0, POPT_ARG_NONE, &delete_during, 0, 0, 0 },
Wayne Davison3359acb2005-01-25 03:08:58 +0000529 {"delete", 0, POPT_ARG_NONE, &delete_mode, 0, 0, 0 },
Wayne Davisone0e32032006-12-28 07:54:10 +0000530 {"delete-before", 0, POPT_ARG_NONE, &delete_before, 0, 0, 0 },
Wayne Davisonb0cacef2006-11-22 20:49:23 +0000531 {"delete-during", 0, POPT_ARG_VAL, &delete_during, 1, 0, 0 },
532 {"delete-delay", 0, POPT_ARG_VAL, &delete_during, 2, 0, 0 },
Wayne Davison51d48392005-01-22 22:48:34 +0000533 {"delete-after", 0, POPT_ARG_NONE, &delete_after, 0, 0, 0 },
534 {"delete-excluded", 0, POPT_ARG_NONE, &delete_excluded, 0, 0, 0 },
Wayne Davison47c11972006-06-30 15:52:52 +0000535 {"remove-sent-files",0, POPT_ARG_VAL, &remove_source_files, 2, 0, 0 }, /* deprecated */
536 {"remove-source-files",0,POPT_ARG_VAL, &remove_source_files, 1, 0, 0 },
Wayne Davisonafb6e942003-03-21 19:17:23 +0000537 {"force", 0, POPT_ARG_NONE, &force_delete, 0, 0, 0 },
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000538 {"ignore-errors", 0, POPT_ARG_NONE, &ignore_errors, 0, 0, 0 },
539 {"max-delete", 0, POPT_ARG_INT, &max_delete, 0, 0, 0 },
540 {0, 'F', POPT_ARG_NONE, 0, 'F', 0, 0 },
Wayne Davisonaa4d3b42005-01-25 00:52:56 +0000541 {"filter", 'f', POPT_ARG_STRING, 0, OPT_FILTER, 0, 0 },
Wayne Davison8db7cc22004-10-11 10:43:25 +0000542 {"exclude", 0, POPT_ARG_STRING, 0, OPT_EXCLUDE, 0, 0 },
543 {"include", 0, POPT_ARG_STRING, 0, OPT_INCLUDE, 0, 0 },
544 {"exclude-from", 0, POPT_ARG_STRING, 0, OPT_EXCLUDE_FROM, 0, 0 },
545 {"include-from", 0, POPT_ARG_STRING, 0, OPT_INCLUDE_FROM, 0, 0 },
Wayne Davisonafb6e942003-03-21 19:17:23 +0000546 {"cvs-exclude", 'C', POPT_ARG_NONE, &cvs_exclude, 0, 0, 0 },
Wayne Davison11bfaf62005-08-27 20:01:45 +0000547 {"whole-file", 'W', POPT_ARG_VAL, &whole_file, 1, 0, 0 },
548 {"no-whole-file", 0, POPT_ARG_VAL, &whole_file, 0, 0, 0 },
Wayne Davisonb6164932005-08-27 21:01:45 +0000549 {"no-W", 0, POPT_ARG_VAL, &whole_file, 0, 0, 0 },
Wayne Davison8487f9c2007-05-24 02:50:35 +0000550 {"checksum", 'c', POPT_ARG_VAL, &always_checksum, 1, 0, 0 },
551 {"no-checksum", 0, POPT_ARG_VAL, &always_checksum, 0, 0, 0 },
552 {"no-c", 0, POPT_ARG_VAL, &always_checksum, 0, 0, 0 },
Wayne Davisona06b4192005-01-01 21:08:14 +0000553 {"block-size", 'B', POPT_ARG_LONG, &block_size, 0, 0, 0 },
Wayne Davisone012f852004-11-27 17:52:51 +0000554 {"compare-dest", 0, POPT_ARG_STRING, 0, OPT_COMPARE_DEST, 0, 0 },
Wayne Davison1de3e992005-03-11 17:35:59 +0000555 {"copy-dest", 0, POPT_ARG_STRING, 0, OPT_COPY_DEST, 0, 0 },
Wayne Davisone012f852004-11-27 17:52:51 +0000556 {"link-dest", 0, POPT_ARG_STRING, 0, OPT_LINK_DEST, 0, 0 },
Wayne Davisonc4ed1482005-02-14 02:41:15 +0000557 {"fuzzy", 'y', POPT_ARG_NONE, &fuzzy_basis, 0, 0, 0 },
Wayne Davison854a1aa2005-10-26 16:47:15 +0000558 {"compress", 'z', POPT_ARG_NONE, 0, 'z', 0, 0 },
Wayne Davison8487f9c2007-05-24 02:50:35 +0000559 {"no-compress", 0, POPT_ARG_VAL, &do_compression, 0, 0, 0 },
Wayne Davisonb1e436e2007-07-14 19:24:32 +0000560 {"skip-compress", 0, POPT_ARG_STRING, &skip_compress, 0, 0, 0 },
Wayne Davison8487f9c2007-05-24 02:50:35 +0000561 {"no-z", 0, POPT_ARG_VAL, &do_compression, 0, 0, 0 },
Wayne Davison854a1aa2005-10-26 16:47:15 +0000562 {"compress-level", 0, POPT_ARG_INT, &def_compress_level, 'z', 0, 0 },
Wayne Davison11bfaf62005-08-27 20:01:45 +0000563 {0, 'P', POPT_ARG_NONE, 0, 'P', 0, 0 },
Wayne Davisonb6164932005-08-27 21:01:45 +0000564 {"progress", 0, POPT_ARG_VAL, &do_progress, 1, 0, 0 },
565 {"no-progress", 0, POPT_ARG_VAL, &do_progress, 0, 0, 0 },
566 {"partial", 0, POPT_ARG_VAL, &keep_partial, 1, 0, 0 },
567 {"no-partial", 0, POPT_ARG_VAL, &keep_partial, 0, 0, 0 },
Wayne Davisona7260c42004-07-29 16:06:38 +0000568 {"partial-dir", 0, POPT_ARG_STRING, &partial_dir, 0, 0, 0 },
Wayne Davison8487f9c2007-05-24 02:50:35 +0000569 {"delay-updates", 0, POPT_ARG_VAL, &delay_updates, 1, 0, 0 },
570 {"no-delay-updates", 0, POPT_ARG_VAL, &delay_updates, 0, 0, 0 },
Wayne Davison876c9932006-01-28 00:13:55 +0000571 {"prune-empty-dirs",'m', POPT_ARG_NONE, &prune_empty_dirs, 0, 0, 0 },
Wayne Davison87c0f9d2006-05-09 18:31:03 +0000572 {"log-file", 0, POPT_ARG_STRING, &logfile_name, 0, 0, 0 },
Wayne Davisonb3e4e7e2006-05-29 22:56:45 +0000573 {"log-file-format", 0, POPT_ARG_STRING, &logfile_format, 0, 0, 0 },
574 {"out-format", 0, POPT_ARG_STRING, &stdout_format, 0, 0, 0 },
575 {"log-format", 0, POPT_ARG_STRING, &stdout_format, 0, 0, 0 }, /* DEPRECATED */
Wayne Davison487094a2006-01-20 18:49:07 +0000576 {"itemize-changes", 'i', POPT_ARG_NONE, 0, 'i', 0, 0 },
Wayne Davison8487f9c2007-05-24 02:50:35 +0000577 {"no-itemize-changes",0, POPT_ARG_VAL, &itemize_changes, 0, 0, 0 },
578 {"no-i", 0, POPT_ARG_VAL, &itemize_changes, 0, 0, 0 },
Wayne Davisonafb6e942003-03-21 19:17:23 +0000579 {"bwlimit", 0, POPT_ARG_INT, &bwlimit, 0, 0, 0 },
Wayne Davison8487f9c2007-05-24 02:50:35 +0000580 {"no-bwlimit", 0, POPT_ARG_VAL, &bwlimit, 0, 0, 0 },
581 {"backup", 'b', POPT_ARG_VAL, &make_backups, 1, 0, 0 },
582 {"no-backup", 0, POPT_ARG_VAL, &make_backups, 0, 0, 0 },
Wayne Davisonafb6e942003-03-21 19:17:23 +0000583 {"backup-dir", 0, POPT_ARG_STRING, &backup_dir, 0, 0, 0 },
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000584 {"suffix", 0, POPT_ARG_STRING, &backup_suffix, 0, 0, 0 },
585 {"list-only", 0, POPT_ARG_VAL, &list_only, 2, 0, 0 },
Wayne Davison8db7cc22004-10-11 10:43:25 +0000586 {"read-batch", 0, POPT_ARG_STRING, &batch_name, OPT_READ_BATCH, 0, 0 },
587 {"write-batch", 0, POPT_ARG_STRING, &batch_name, OPT_WRITE_BATCH, 0, 0 },
Wayne Davison11e758a2005-04-09 18:59:47 +0000588 {"only-write-batch", 0, POPT_ARG_STRING, &batch_name, OPT_ONLY_WRITE_BATCH, 0, 0 },
Wayne Davisonea5164d2003-03-30 23:00:42 +0000589 {"files-from", 0, POPT_ARG_STRING, &files_from, 0, 0, 0 },
Wayne Davison8487f9c2007-05-24 02:50:35 +0000590 {"from0", '0', POPT_ARG_VAL, &eol_nulls, 1, 0, 0},
591 {"no-from0", 0, POPT_ARG_VAL, &eol_nulls, 0, 0, 0},
592 {"numeric-ids", 0, POPT_ARG_VAL, &numeric_ids, 1, 0, 0 },
593 {"no-numeric-ids", 0, POPT_ARG_VAL, &numeric_ids, 0, 0, 0 },
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000594 {"timeout", 0, POPT_ARG_INT, &io_timeout, 0, 0, 0 },
Wayne Davison8487f9c2007-05-24 02:50:35 +0000595 {"no-timeout", 0, POPT_ARG_VAL, &io_timeout, 0, 0, 0 },
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000596 {"rsh", 'e', POPT_ARG_STRING, &shell_cmd, 0, 0, 0 },
597 {"rsync-path", 0, POPT_ARG_STRING, &rsync_path, 0, 0, 0 },
598 {"temp-dir", 'T', POPT_ARG_STRING, &tmpdir, 0, 0, 0 },
Wayne Davison332cf6d2007-04-26 05:53:13 +0000599#ifdef ICONV_OPTION
600 {"iconv", 0, POPT_ARG_STRING, &iconv_opt, 0, 0, 0 },
601#endif
Wayne Davison3dd22902004-05-06 21:08:01 +0000602 {"ipv4", '4', POPT_ARG_VAL, &default_af_hint, AF_INET, 0, 0 },
603 {"ipv6", '6', POPT_ARG_VAL, &default_af_hint, AF_INET6, 0, 0 },
Wayne Davisona6a27602006-02-06 18:51:25 +0000604 {"8-bit-output", '8', POPT_ARG_NONE, &allow_8bit_chars, 0, 0, 0 },
Wayne Davison8487f9c2007-05-24 02:50:35 +0000605 {"qsort", 0, POPT_ARG_NONE, &use_qsort, 0, 0, 0 },
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000606 {"address", 0, POPT_ARG_STRING, &bind_address, 0, 0, 0 },
607 {"port", 0, POPT_ARG_INT, &rsync_port, 0, 0, 0 },
Wayne Davison831f06a2006-01-26 12:31:24 +0000608 {"sockopts", 0, POPT_ARG_STRING, &sockopts, 0, 0, 0 },
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000609 {"password-file", 0, POPT_ARG_STRING, &password_file, 0, 0, 0 },
610 {"blocking-io", 0, POPT_ARG_VAL, &blocking_io, 1, 0, 0 },
611 {"no-blocking-io", 0, POPT_ARG_VAL, &blocking_io, 0, 0, 0 },
612 {"protocol", 0, POPT_ARG_INT, &protocol_version, 0, 0, 0 },
613 {"checksum-seed", 0, POPT_ARG_INT, &checksum_seed, 0, 0, 0 },
Wayne Davison0ccffd72006-01-21 20:15:49 +0000614 {"server", 0, POPT_ARG_NONE, 0, OPT_SERVER, 0, 0 },
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000615 {"sender", 0, POPT_ARG_NONE, 0, OPT_SENDER, 0, 0 },
616 /* All the following options switch us into daemon-mode option-parsing. */
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000617 {"config", 0, POPT_ARG_STRING, 0, OPT_DAEMON, 0, 0 },
618 {"daemon", 0, POPT_ARG_NONE, 0, OPT_DAEMON, 0, 0 },
Wayne Davison1f35bab2005-02-21 00:31:31 +0000619 {"detach", 0, POPT_ARG_NONE, 0, OPT_DAEMON, 0, 0 },
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000620 {"no-detach", 0, POPT_ARG_NONE, 0, OPT_DAEMON, 0, 0 },
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000621 {0,0,0,0, 0, 0, 0}
622};
623
624static void daemon_usage(enum logcode F)
625{
626 print_rsync_version(F);
627
Wayne Davisonb64ee912006-06-01 08:04:47 +0000628 rprintf(F,"\n");
629 rprintf(F,"Usage: rsync --daemon [OPTION]...\n");
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000630 rprintf(F," --address=ADDRESS bind to the specified address\n");
Wayne Davisonb3708ac2005-01-28 09:55:18 +0000631 rprintf(F," --bwlimit=KBPS limit I/O bandwidth; KBytes per second\n");
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000632 rprintf(F," --config=FILE specify alternate rsyncd.conf file\n");
633 rprintf(F," --no-detach do not detach from the parent\n");
Wayne Davisonb3708ac2005-01-28 09:55:18 +0000634 rprintf(F," --port=PORT listen on alternate port number\n");
Wayne Davison87c0f9d2006-05-09 18:31:03 +0000635 rprintf(F," --log-file=FILE override the \"log file\" setting\n");
Wayne Davison232658d2006-05-30 17:14:17 +0000636 rprintf(F," --log-file-format=FMT override the \"log format\" setting\n");
Wayne Davison831f06a2006-01-26 12:31:24 +0000637 rprintf(F," --sockopts=OPTIONS specify custom TCP options\n");
Wayne Davison1bd9db72005-01-28 17:07:54 +0000638 rprintf(F," -v, --verbose increase verbosity\n");
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000639 rprintf(F," -4, --ipv4 prefer IPv4\n");
640 rprintf(F," -6, --ipv6 prefer IPv6\n");
Wayne Davison05724c02005-11-15 06:35:27 +0000641 rprintf(F," --help show this help screen\n");
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000642
Wayne Davisonb64ee912006-06-01 08:04:47 +0000643 rprintf(F,"\n");
644 rprintf(F,"If you were not trying to invoke rsync as a daemon, avoid using any of the\n");
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000645 rprintf(F,"daemon-specific rsync options. See also the rsyncd.conf(5) man page.\n");
646}
647
648static struct poptOption long_daemon_options[] = {
649 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
650 {"address", 0, POPT_ARG_STRING, &bind_address, 0, 0, 0 },
Wayne Davison9fb08442004-11-17 19:29:20 +0000651 {"bwlimit", 0, POPT_ARG_INT, &daemon_bwlimit, 0, 0, 0 },
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000652 {"config", 0, POPT_ARG_STRING, &config_file, 0, 0, 0 },
653 {"daemon", 0, POPT_ARG_NONE, &daemon_opt, 0, 0, 0 },
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000654 {"ipv4", '4', POPT_ARG_VAL, &default_af_hint, AF_INET, 0, 0 },
655 {"ipv6", '6', POPT_ARG_VAL, &default_af_hint, AF_INET6, 0, 0 },
Wayne Davison1f35bab2005-02-21 00:31:31 +0000656 {"detach", 0, POPT_ARG_VAL, &no_detach, 0, 0, 0 },
Wayne Davison8487f9c2007-05-24 02:50:35 +0000657 {"no-detach", 0, POPT_ARG_VAL, &no_detach, 1, 0, 0 },
Wayne Davison87c0f9d2006-05-09 18:31:03 +0000658 {"log-file", 0, POPT_ARG_STRING, &logfile_name, 0, 0, 0 },
Wayne Davison232658d2006-05-30 17:14:17 +0000659 {"log-file-format", 0, POPT_ARG_STRING, &logfile_format, 0, 0, 0 },
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000660 {"port", 0, POPT_ARG_INT, &rsync_port, 0, 0, 0 },
Wayne Davison831f06a2006-01-26 12:31:24 +0000661 {"sockopts", 0, POPT_ARG_STRING, &sockopts, 0, 0, 0 },
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000662 {"protocol", 0, POPT_ARG_INT, &protocol_version, 0, 0, 0 },
663 {"server", 0, POPT_ARG_NONE, &am_server, 0, 0, 0 },
Wayne Davisonb8cc3582005-08-30 05:00:56 +0000664 {"temp-dir", 'T', POPT_ARG_STRING, &tmpdir, 0, 0, 0 },
Wayne Davison1bd9db72005-01-28 17:07:54 +0000665 {"verbose", 'v', POPT_ARG_NONE, 0, 'v', 0, 0 },
Wayne Davisonb6e22a42005-08-30 16:13:54 +0000666 {"no-verbose", 0, POPT_ARG_VAL, &verbose, 0, 0, 0 },
667 {"no-v", 0, POPT_ARG_VAL, &verbose, 0, 0, 0 },
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000668 {"help", 'h', POPT_ARG_NONE, 0, 'h', 0, 0 },
Wayne Davisonad715002004-10-14 09:11:12 +0000669 {0,0,0,0, 0, 0, 0}
Martin Pool2855f612001-02-23 01:02:31 +0000670};
Andrew Tridgell7a6421f1998-05-10 07:25:40 +0000671
Martin Pool06963d02001-11-23 07:35:49 +0000672
Wayne Davisone51094b2004-05-21 09:41:38 +0000673static char err_buf[200];
Andrew Tridgellcd8185f1998-11-19 06:35:49 +0000674
Martin Pool2855f612001-02-23 01:02:31 +0000675
Martin Pooldafe63c2002-04-16 01:38:21 +0000676/**
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 **/
Andrew Tridgellcd8185f1998-11-19 06:35:49 +0000681void option_error(void)
682{
Wayne Davisone51094b2004-05-21 09:41:38 +0000683 if (!err_buf[0]) {
Wayne Davisonc9bce0b2006-10-13 23:17:33 +0000684 strlcpy(err_buf, "Error parsing options: option may "
685 "be supported on client but not on server?\n",
686 sizeof err_buf);
Andrew Tridgellcd8185f1998-11-19 06:35:49 +0000687 }
Wayne Davisone51094b2004-05-21 09:41:38 +0000688
Wayne Davisone51094b2004-05-21 09:41:38 +0000689 rprintf(FERROR, RSYNC_NAME ": %s", err_buf);
Wayne Davison8f1dc162006-02-20 17:58:13 +0000690 msleep(20);
Andrew Tridgellcd8185f1998-11-19 06:35:49 +0000691}
692
Martin Pooldafe63c2002-04-16 01:38:21 +0000693
694/**
Wayne Davison27ed20f2004-02-21 21:12:49 +0000695 * Tweak the option table to disable all options that the rsyncd.conf
696 * file has told us to refuse.
Martin Pooldafe63c2002-04-16 01:38:21 +0000697 **/
Wayne Davison27ed20f2004-02-21 21:12:49 +0000698static void set_refuse_options(char *bp)
Andrew Tridgellcd8185f1998-11-19 06:35:49 +0000699{
Wayne Davison27ed20f2004-02-21 21:12:49 +0000700 struct poptOption *op;
Wayne Davison093e8162004-08-02 07:40:34 +0000701 char *cp, shortname[2];
Wayne Davisond73e7f62004-08-04 21:20:34 +0000702 int is_wild, found_match;
Wayne Davison093e8162004-08-02 07:40:34 +0000703
704 shortname[1] = '\0';
Andrew Tridgellcd8185f1998-11-19 06:35:49 +0000705
Wayne Davison27ed20f2004-02-21 21:12:49 +0000706 while (1) {
Wayne Davison06a50542004-08-02 05:00:30 +0000707 while (*bp == ' ') bp++;
708 if (!*bp)
709 break;
Wayne Davison27ed20f2004-02-21 21:12:49 +0000710 if ((cp = strchr(bp, ' ')) != NULL)
711 *cp= '\0';
Wayne Davison093e8162004-08-02 07:40:34 +0000712 is_wild = strpbrk(bp, "*?[") != NULL;
Wayne Davisond73e7f62004-08-04 21:20:34 +0000713 found_match = 0;
Wayne Davison55afbb52004-02-21 21:36:55 +0000714 for (op = long_options; ; op++) {
Wayne Davison093e8162004-08-02 07:40:34 +0000715 *shortname = op->shortName;
Wayne Davisond73e7f62004-08-04 21:20:34 +0000716 if (!op->longName && !*shortname)
717 break;
718 if ((op->longName && wildmatch(bp, op->longName))
Wayne Davison684d7582005-02-19 22:16:39 +0000719 || (*shortname && wildmatch(bp, shortname))) {
Wayne Davisone57211c2005-01-23 01:25:36 +0000720 if (op->argInfo == POPT_ARG_VAL)
721 op->argInfo = POPT_ARG_NONE;
Wayne Davison06a50542004-08-02 05:00:30 +0000722 op->val = (op - long_options) + OPT_REFUSED_BASE;
Wayne Davisond73e7f62004-08-04 21:20:34 +0000723 found_match = 1;
Wayne Davison36719872005-02-11 10:42:55 +0000724 /* These flags are set to let us easily check
725 * an implied option later in the code. */
726 switch (*shortname) {
Wayne Davison36719872005-02-11 10:42:55 +0000727 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;
Wayne Davison854a1aa2005-10-26 16:47:15 +0000731 case 'z':
732 refused_compress = op->val;
733 break;
Wayne Davison36719872005-02-11 10:42:55 +0000734 case '\0':
735 if (wildmatch("delete", op->longName))
736 refused_delete = op->val;
Wayne Davison3296f912005-02-15 21:15:58 +0000737 else if (wildmatch("delete-before", op->longName))
738 refused_delete_before = op->val;
Wayne Davisone0e32032006-12-28 07:54:10 +0000739 else if (wildmatch("delete-during", op->longName))
740 refused_delete_during = op->val;
Wayne Davison36719872005-02-11 10:42:55 +0000741 else if (wildmatch("partial", op->longName))
742 refused_partial = op->val;
743 else if (wildmatch("progress", op->longName))
744 refused_progress = op->val;
Wayne Davisona0157882005-07-28 01:46:09 +0000745 else if (wildmatch("inplace", op->longName))
746 refused_inplace = op->val;
Wayne Davison36719872005-02-11 10:42:55 +0000747 break;
748 }
Wayne Davison06a50542004-08-02 05:00:30 +0000749 if (!is_wild)
750 break;
Wayne Davison27ed20f2004-02-21 21:12:49 +0000751 }
Andrew Tridgellcd8185f1998-11-19 06:35:49 +0000752 }
Wayne Davisond73e7f62004-08-04 21:20:34 +0000753 if (!found_match) {
754 rprintf(FLOG, "No match for refuse-options string \"%s\"\n",
755 bp);
756 }
Wayne Davison27ed20f2004-02-21 21:12:49 +0000757 if (!cp)
758 break;
759 *cp = ' ';
760 bp = cp + 1;
Andrew Tridgellcd8185f1998-11-19 06:35:49 +0000761 }
Andrew Tridgellcd8185f1998-11-19 06:35:49 +0000762}
763
764
Wayne Davison8db7cc22004-10-11 10:43:25 +0000765static int count_args(const char **argv)
Martin Pool2855f612001-02-23 01:02:31 +0000766{
Wayne Davisondfa32482003-03-21 18:58:50 +0000767 int i = 0;
Martin Pool2855f612001-02-23 01:02:31 +0000768
Wayne Davison8db7cc22004-10-11 10:43:25 +0000769 if (argv) {
770 while (argv[i] != NULL)
771 i++;
772 }
Wayne Davisondfa32482003-03-21 18:58:50 +0000773
774 return i;
Martin Pool2855f612001-02-23 01:02:31 +0000775}
776
777
Wayne Davison837d01d2005-10-14 19:48:34 +0000778static OFF_T parse_size_arg(char **size_arg, char def_suf)
Wayne Davison95e107d2005-04-28 16:11:32 +0000779{
Wayne Davison3c19f722005-11-15 17:49:59 +0000780 int reps, mult, make_compatible = 0;
781 const char *arg;
782 OFF_T size = 1;
Wayne Davison95e107d2005-04-28 16:11:32 +0000783
Wayne Davison2dc7b8b2006-11-09 02:39:29 +0000784 for (arg = *size_arg; isDigit(arg); arg++) {}
Wayne Davison95e107d2005-04-28 16:11:32 +0000785 if (*arg == '.')
Wayne Davison2dc7b8b2006-11-09 02:39:29 +0000786 for (arg++; isDigit(arg); arg++) {}
Wayne Davison3c19f722005-11-15 17:49:59 +0000787 switch (*arg && *arg != '+' && *arg != '-' ? *arg++ : def_suf) {
Wayne Davison837d01d2005-10-14 19:48:34 +0000788 case 'b': case 'B':
Wayne Davison3c19f722005-11-15 17:49:59 +0000789 reps = 0;
Wayne Davison837d01d2005-10-14 19:48:34 +0000790 break;
Wayne Davison95e107d2005-04-28 16:11:32 +0000791 case 'k': case 'K':
Wayne Davison3c19f722005-11-15 17:49:59 +0000792 reps = 1;
Wayne Davison95e107d2005-04-28 16:11:32 +0000793 break;
794 case 'm': case 'M':
Wayne Davison3c19f722005-11-15 17:49:59 +0000795 reps = 2;
Wayne Davison95e107d2005-04-28 16:11:32 +0000796 break;
797 case 'g': case 'G':
Wayne Davison3c19f722005-11-15 17:49:59 +0000798 reps = 3;
Wayne Davison95e107d2005-04-28 16:11:32 +0000799 break;
800 default:
Wayne Davison3c19f722005-11-15 17:49:59 +0000801 return -1;
Wayne Davison95e107d2005-04-28 16:11:32 +0000802 }
Wayne Davison3c19f722005-11-15 17:49:59 +0000803 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;
Wayne Davisonaeb213e2005-10-14 18:56:07 +0000818 if (size > 0 && make_compatible) {
Wayne Davison74de13d2005-10-14 20:15:18 +0000819 /* We convert this manually because we may need %lld precision,
820 * and that's not a portable sprintf() escape. */
Wayne Davison8f14cc42005-11-12 19:53:17 +0000821 char buf[128], *s = buf + sizeof buf - 1;
Wayne Davisonaeb213e2005-10-14 18:56:07 +0000822 OFF_T num = size;
Wayne Davison8f14cc42005-11-12 19:53:17 +0000823 *s = '\0';
Wayne Davisonaeb213e2005-10-14 18:56:07 +0000824 while (num) {
Wayne Davison26404272006-11-21 08:35:58 +0000825 *--s = (char)(num % 10) + '0';
Wayne Davisonaeb213e2005-10-14 18:56:07 +0000826 num /= 10;
827 }
828 if (!(*size_arg = strdup(s)))
829 out_of_memory("parse_size_arg");
830 }
Wayne Davison95e107d2005-04-28 16:11:32 +0000831 return size;
832}
833
834
Wayne Davison36719872005-02-11 10:42:55 +0000835static 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
Martin Pooldafe63c2002-04-16 01:38:21 +0000849/**
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 **/
Martin Pool2855f612001-02-23 01:02:31 +0000857int parse_arguments(int *argc, const char ***argv, int frommain)
Andrew Tridgell7a6421f1998-05-10 07:25:40 +0000858{
Andrew Tridgelld8537831998-07-17 10:00:43 +0000859 int opt;
Andrew Tridgellcd8185f1998-11-19 06:35:49 +0000860 char *ref = lp_refuse_options(module_id);
Wayne Davison7be73df2004-03-27 09:46:42 +0000861 const char *arg;
Wayne Davisondfa32482003-03-21 18:58:50 +0000862 poptContext pc;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +0000863
Wayne Davison27ed20f2004-02-21 21:12:49 +0000864 if (ref && *ref)
865 set_refuse_options(ref);
Wayne Davison232658d2006-05-30 17:14:17 +0000866 if (am_daemon)
867 set_refuse_options("log-file*");
Wayne Davison27ed20f2004-02-21 21:12:49 +0000868
Wayne Davison332cf6d2007-04-26 05:53:13 +0000869#ifdef ICONV_OPTION
870 if (!am_daemon && (arg = getenv("RSYNC_ICONV")) != NULL && *arg)
871 iconv_opt = strdup(arg);
872#endif
873
Wayne Davisondfa32482003-03-21 18:58:50 +0000874 /* TODO: Call poptReadDefaultConfig; handle errors. */
Andrew Tridgellcd8185f1998-11-19 06:35:49 +0000875
Wayne Davisondfa32482003-03-21 18:58:50 +0000876 /* 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);
Wayne Davison9fb08442004-11-17 19:29:20 +0000879 poptReadDefaultConfig(pc, 0);
Martin Pool2855f612001-02-23 01:02:31 +0000880
881 while ((opt = poptGetNextOpt(pc)) != -1) {
Wayne Davisondfa32482003-03-21 18:58:50 +0000882 /* most options are handled automatically by popt;
883 * only special cases are returned and listed here. */
Martin Pool2855f612001-02-23 01:02:31 +0000884
Andrew Tridgelld8537831998-07-17 10:00:43 +0000885 switch (opt) {
886 case OPT_VERSION:
Wayne Davisondfa32482003-03-21 18:58:50 +0000887 print_rsync_version(FINFO);
Andrew Tridgelld8537831998-07-17 10:00:43 +0000888 exit_cleanup(0);
Wayne Davisondfa32482003-03-21 18:58:50 +0000889
Wayne Davison0ccffd72006-01-21 20:15:49 +0000890 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 }
Wayne Davison332cf6d2007-04-26 05:53:13 +0000899#ifdef ICONV_OPTION
900 iconv_opt = NULL;
901#endif
Wayne Davison0ccffd72006-01-21 20:15:49 +0000902 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
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000912 case OPT_DAEMON:
913 if (am_daemon) {
Wayne Davisonc9bce0b2006-10-13 23:17:33 +0000914 strlcpy(err_buf,
915 "Attempt to hack rsync thwarted!\n",
916 sizeof err_buf);
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000917 return 0;
918 }
Wayne Davison332cf6d2007-04-26 05:53:13 +0000919#ifdef ICONV_OPTION
920 iconv_opt = NULL;
921#endif
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000922 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
Wayne Davison1bd9db72005-01-28 17:07:54 +0000931 case 'v':
932 verbose++;
933 break;
934
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000935 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 }
Wayne Davisonb6e22a42005-08-30 16:13:54 +0000943
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
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000950 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 }
Wayne Davisonb6e22a42005-08-30 16:13:54 +0000957
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000958 *argv = poptGetArgs(pc);
959 *argc = count_args(*argv);
Wayne Davison7f2a1f62005-02-25 17:08:31 +0000960 am_starting_up = 0;
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000961 daemon_opt = 0;
962 am_daemon = 1;
963 return 1;
964
Andrew Tridgell5b56cc12000-09-06 02:12:13 +0000965 case OPT_MODIFY_WINDOW:
Wayne Davisondfa32482003-03-21 18:58:50 +0000966 /* The value has already been set by popt, but
967 * we need to remember that we're using a
968 * non-default setting. */
Andrew Tridgell5b56cc12000-09-06 02:12:13 +0000969 modify_window_set = 1;
970 break;
Wayne Davison1de50992002-05-03 22:59:17 +0000971
Wayne Davisonaa4d3b42005-01-25 00:52:56 +0000972 case OPT_FILTER:
Wayne Davison3a5e9222005-02-04 21:13:03 +0000973 parse_rule(&filter_list, poptGetOptArg(pc), 0, 0);
Andrew Tridgelld8537831998-07-17 10:00:43 +0000974 break;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +0000975
Wayne Davisonaa4d3b42005-01-25 00:52:56 +0000976 case OPT_EXCLUDE:
Wayne Davison3a5e9222005-02-04 21:13:03 +0000977 parse_rule(&filter_list, poptGetOptArg(pc),
Wayne Davison0a68f862005-02-03 19:00:17 +0000978 0, XFLG_OLD_PREFIXES);
Wayne Davisonaa4d3b42005-01-25 00:52:56 +0000979 break;
980
Andrew Tridgelld8537831998-07-17 10:00:43 +0000981 case OPT_INCLUDE:
Wayne Davison3a5e9222005-02-04 21:13:03 +0000982 parse_rule(&filter_list, poptGetOptArg(pc),
Wayne Davison0a68f862005-02-03 19:00:17 +0000983 MATCHFLG_INCLUDE, XFLG_OLD_PREFIXES);
Andrew Tridgelld8537831998-07-17 10:00:43 +0000984 break;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +0000985
Andrew Tridgelld8537831998-07-17 10:00:43 +0000986 case OPT_EXCLUDE_FROM:
David Dykstra93695762002-02-27 22:49:57 +0000987 case OPT_INCLUDE_FROM:
Wayne Davison7be73df2004-03-27 09:46:42 +0000988 arg = poptGetOptArg(pc);
Wayne Davison1a7f3d92006-10-12 03:01:18 +0000989 if (sanitize_paths)
Wayne Davison91f4b312006-05-03 00:48:20 +0000990 arg = sanitize_path(NULL, arg, NULL, 0, NULL);
Wayne Davison78424182005-01-25 10:39:14 +0000991 if (server_filter_list.head) {
Wayne Davisond3ef9852006-04-28 17:34:53 +0000992 char *cp = strdup(arg);
993 if (!cp)
994 out_of_memory("parse_arguments");
Wayne Davison36719872005-02-11 10:42:55 +0000995 if (!*cp)
996 goto options_rejected;
Wayne Davisonba3db472004-08-26 17:39:48 +0000997 clean_fname(cp, 1);
Wayne Davison78424182005-01-25 10:39:14 +0000998 if (check_filter(&server_filter_list, cp, 0) < 0)
Wayne Davisonba3db472004-08-26 17:39:48 +0000999 goto options_rejected;
Wayne Davisond3ef9852006-04-28 17:34:53 +00001000 free(cp);
Wayne Davisonba3db472004-08-26 17:39:48 +00001001 }
Wayne Davison3a5e9222005-02-04 21:13:03 +00001002 parse_filter_file(&filter_list, arg,
1003 opt == OPT_INCLUDE_FROM ? MATCHFLG_INCLUDE : 0,
1004 XFLG_FATAL_ERRORS | XFLG_OLD_PREFIXES);
David Dykstra93695762002-02-27 22:49:57 +00001005 break;
1006
Wayne Davisonb6164932005-08-27 21:01:45 +00001007 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;
Wayne Davisonb5c6a6a2006-01-26 10:38:58 +00001022 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;
Wayne Davisonb6164932005-08-27 21:01:45 +00001031 break;
1032
Wayne Davison3ca9e5d2006-02-08 16:52:25 +00001033 case 'h':
1034 human_readable++;
1035 break;
1036
Wayne Davisone0e32032006-12-28 07:54:10 +00001037 case 'H':
1038 preserve_hard_links++;
1039 break;
1040
Wayne Davison487094a2006-01-20 18:49:07 +00001041 case 'i':
1042 itemize_changes++;
1043 break;
1044
Andrew Tridgelld8537831998-07-17 10:00:43 +00001045 case 'v':
1046 verbose++;
1047 break;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +00001048
David Dykstrab86f0ce1999-02-09 17:25:35 +00001049 case 'q':
Wayne Davisonf98c60b2004-02-09 18:10:57 +00001050 if (frommain)
1051 quiet++;
David Dykstrab86f0ce1999-02-09 17:25:35 +00001052 break;
1053
Wayne Davison243c9952006-01-21 00:36:15 +00001054 case 'x':
1055 one_file_system++;
1056 break;
1057
Wayne Davisonaa4d3b42005-01-25 00:52:56 +00001058 case 'F':
1059 switch (++F_option_cnt) {
1060 case 1:
Wayne Davison3a5e9222005-02-04 21:13:03 +00001061 parse_rule(&filter_list,": /.rsync-filter",0,0);
Wayne Davisonaa4d3b42005-01-25 00:52:56 +00001062 break;
1063 case 2:
Wayne Davison3a5e9222005-02-04 21:13:03 +00001064 parse_rule(&filter_list,"- .rsync-filter",0,0);
Wayne Davisonaa4d3b42005-01-25 00:52:56 +00001065 break;
1066 }
1067 break;
1068
Andrew Tridgelld9fcc191999-10-31 02:47:30 +00001069 case 'P':
Wayne Davison36719872005-02-11 10:42:55 +00001070 if (refused_partial || refused_progress) {
1071 create_refuse_error(refused_partial
1072 ? refused_partial : refused_progress);
1073 return 0;
1074 }
Andrew Tridgelld9fcc191999-10-31 02:47:30 +00001075 do_progress = 1;
1076 keep_partial = 1;
1077 break;
1078
Wayne Davison854a1aa2005-10-26 16:47:15 +00001079 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
David Dykstra088aac82002-02-06 21:20:48 +00001094 case OPT_WRITE_BATCH:
Wayne Davison9b3318b2004-07-15 16:27:02 +00001095 /* batch_name is already set */
David Dykstra088aac82002-02-06 21:20:48 +00001096 write_batch = 1;
1097 break;
1098
Wayne Davison11e758a2005-04-09 18:59:47 +00001099 case OPT_ONLY_WRITE_BATCH:
1100 /* batch_name is already set */
1101 write_batch = -1;
1102 break;
1103
Martin Pool76f79ba2002-01-23 05:51:06 +00001104 case OPT_READ_BATCH:
Wayne Davison9b3318b2004-07-15 16:27:02 +00001105 /* batch_name is already set */
Martin Pool6902ed12001-08-14 02:04:47 +00001106 read_batch = 1;
1107 break;
Wayne Davisonea5164d2003-03-30 23:00:42 +00001108
Wayne Davison7d5acf12004-11-11 01:45:25 +00001109 case OPT_MAX_SIZE:
Wayne Davison837d01d2005-10-14 19:48:34 +00001110 if ((max_size = parse_size_arg(&max_size_arg, 'b')) <= 0) {
Wayne Davisone012f852004-11-27 17:52:51 +00001111 snprintf(err_buf, sizeof err_buf,
Wayne Davison7d5acf12004-11-11 01:45:25 +00001112 "--max-size value is invalid: %s\n",
1113 max_size_arg);
Wayne Davisone012f852004-11-27 17:52:51 +00001114 return 0;
Wayne Davison7d5acf12004-11-11 01:45:25 +00001115 }
1116 break;
1117
Wayne Davison74de13d2005-10-14 20:15:18 +00001118 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
Wayne Davison936fa862007-09-01 16:38:00 +00001127 case OPT_APPEND:
1128 if (am_server)
1129 append_mode++;
1130 else
1131 append_mode = 1;
1132 break;
1133
David Dykstra59c95e42002-08-29 14:44:55 +00001134 case OPT_LINK_DEST:
Wayne Davisonfcecb702006-05-05 06:16:22 +00001135#ifdef SUPPORT_HARD_LINKS
David Dykstra59c95e42002-08-29 14:44:55 +00001136 link_dest = 1;
Wayne Davisone012f852004-11-27 17:52:51 +00001137 dest_option = "--link-dest";
1138 goto set_dest_dir;
David Dykstra59c95e42002-08-29 14:44:55 +00001139#else
Wayne Davisond175d7e2003-08-01 07:58:44 +00001140 snprintf(err_buf, sizeof err_buf,
Wayne Davisondfa32482003-03-21 18:58:50 +00001141 "hard links are not supported on this %s\n",
David Dykstra59c95e42002-08-29 14:44:55 +00001142 am_server ? "server" : "client");
David Dykstra59c95e42002-08-29 14:44:55 +00001143 return 0;
1144#endif
1145
Wayne Davison1de3e992005-03-11 17:35:59 +00001146 case OPT_COPY_DEST:
1147 copy_dest = 1;
1148 dest_option = "--copy-dest";
1149 goto set_dest_dir;
1150
Wayne Davisone012f852004-11-27 17:52:51 +00001151 case OPT_COMPARE_DEST:
1152 compare_dest = 1;
1153 dest_option = "--compare-dest";
1154 set_dest_dir:
Wayne Davison3b26bba2005-01-15 21:23:04 +00001155 if (basis_dir_cnt >= MAX_BASIS_DIRS) {
Wayne Davisone012f852004-11-27 17:52:51 +00001156 snprintf(err_buf, sizeof err_buf,
1157 "ERROR: at most %d %s args may be specified\n",
1158 MAX_BASIS_DIRS, dest_option);
1159 return 0;
1160 }
Wayne Davisonad77db82006-04-28 16:57:39 +00001161 /* We defer sanitizing this arg until we know what
1162 * our destination directory is going to be. */
1163 basis_dir[basis_dir_cnt++] = (char *)poptGetOptArg(pc);
Wayne Davisone012f852004-11-27 17:52:51 +00001164 break;
1165
Wayne Davisone16adcd2006-01-21 09:14:42 +00001166 case OPT_CHMOD:
1167 arg = poptGetOptArg(pc);
Wayne Davisonbbe42182006-01-30 17:53:19 +00001168 if (!parse_chmod(arg, &chmod_modes)) {
Wayne Davisone16adcd2006-01-21 09:14:42 +00001169 snprintf(err_buf, sizeof err_buf,
1170 "Invalid argument passed to --chmod (%s)\n",
1171 arg);
1172 return 0;
1173 }
1174 break;
1175
Wayne Davisonf5a910d2006-01-21 19:52:55 +00001176 case OPT_HELP:
1177 usage(FINFO);
1178 exit_cleanup(0);
1179
Wayne Davison1c3344a2007-03-11 00:13:34 +00001180 case 'A':
1181#ifdef SUPPORT_ACLS
1182 preserve_acls = 1;
1183 preserve_perms = 1;
1184 break;
1185#else
1186 /* FIXME: this should probably be ignored with a
1187 * warning and then countermeasures taken to
1188 * restrict group and other access in the presence
1189 * of any more restrictive ACLs, but this is safe
1190 * for now */
1191 snprintf(err_buf,sizeof(err_buf),
1192 "ACLs are not supported on this %s\n",
1193 am_server ? "server" : "client");
1194 return 0;
1195#endif
1196
Wayne Davison16edf862007-04-07 17:22:25 +00001197 case 'X':
1198#ifdef SUPPORT_XATTRS
Wayne Davison524eaa82007-07-02 21:35:14 +00001199 preserve_xattrs++;
Wayne Davison16edf862007-04-07 17:22:25 +00001200 break;
1201#else
1202 snprintf(err_buf,sizeof(err_buf),
1203 "extended attributes are not supported on this %s\n",
1204 am_server ? "server" : "client");
1205 return 0;
1206#endif
Wayne Davison1c3344a2007-03-11 00:13:34 +00001207
Andrew Tridgelld8537831998-07-17 10:00:43 +00001208 default:
Wayne Davison55afbb52004-02-21 21:36:55 +00001209 /* A large opt value means that set_refuse_options()
Wayne Davison36719872005-02-11 10:42:55 +00001210 * turned this option off. */
Wayne Davisonc67d1382004-02-22 08:56:43 +00001211 if (opt >= OPT_REFUSED_BASE) {
Wayne Davison36719872005-02-11 10:42:55 +00001212 create_refuse_error(opt);
1213 return 0;
Wayne Davison27ed20f2004-02-21 21:12:49 +00001214 }
Wayne Davison36719872005-02-11 10:42:55 +00001215 snprintf(err_buf, sizeof err_buf, "%s%s: %s\n",
1216 am_server ? "on remote machine: " : "",
1217 poptBadOption(pc, POPT_BADOPTION_NOALIAS),
1218 poptStrerror(opt));
Wayne Davisondfa32482003-03-21 18:58:50 +00001219 return 0;
Andrew Tridgelld8537831998-07-17 10:00:43 +00001220 }
Andrew Tridgell7a6421f1998-05-10 07:25:40 +00001221 }
Martin Pool2855f612001-02-23 01:02:31 +00001222
Wayne Davison05724c02005-11-15 06:35:27 +00001223 if (human_readable && *argc == 2) {
Wayne Davison3ca9e5d2006-02-08 16:52:25 +00001224 /* Allow the old meaning of 'h' (--help) on its own. */
Wayne Davison05724c02005-11-15 06:35:27 +00001225 usage(FINFO);
1226 exit_cleanup(0);
1227 }
1228
Wayne Davison332cf6d2007-04-26 05:53:13 +00001229#ifdef ICONV_OPTION
1230 if (iconv_opt) {
1231 if (!am_server && strcmp(iconv_opt, "-") == 0)
1232 iconv_opt = NULL;
1233 else
1234 need_unsorted_flist = 1;
1235 }
1236#endif
1237
Wayne Davison4f5b0752005-02-14 00:53:43 +00001238#ifndef SUPPORT_LINKS
Wayne Davison54e87b42004-02-02 21:33:10 +00001239 if (preserve_links && !am_sender) {
Wayne Davisone1add892004-02-01 17:29:41 +00001240 snprintf(err_buf, sizeof err_buf,
1241 "symlinks are not supported on this %s\n",
1242 am_server ? "server" : "client");
Wayne Davisone1add892004-02-01 17:29:41 +00001243 return 0;
1244 }
1245#endif
1246
Wayne Davison4f5b0752005-02-14 00:53:43 +00001247#ifndef SUPPORT_HARD_LINKS
Wayne Davisone1add892004-02-01 17:29:41 +00001248 if (preserve_hard_links) {
1249 snprintf(err_buf, sizeof err_buf,
1250 "hard links are not supported on this %s\n",
1251 am_server ? "server" : "client");
Wayne Davisone1add892004-02-01 17:29:41 +00001252 return 0;
1253 }
1254#endif
1255
Wayne Davison9439c0c2007-04-24 07:32:44 +00001256#ifndef SUPPORT_XATTRS
1257 if (am_root < 0) {
1258 snprintf(err_buf, sizeof err_buf,
1259 "--fake-super requires an rsync with extended attributes enabled\n");
1260 return 0;
1261 }
1262#endif
1263
David Dykstra088aac82002-02-06 21:20:48 +00001264 if (write_batch && read_batch) {
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001265 snprintf(err_buf, sizeof err_buf,
Wayne Davison36119892004-07-21 22:50:11 +00001266 "--write-batch and --read-batch can not be used together\n");
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001267 return 0;
David Dykstra088aac82002-02-06 21:20:48 +00001268 }
Wayne Davison11e758a2005-04-09 18:59:47 +00001269 if (write_batch > 0 || read_batch) {
Wayne Davison94327ff2004-07-15 19:06:32 +00001270 if (am_server) {
1271 rprintf(FINFO,
1272 "ignoring --%s-batch option sent to server\n",
1273 write_batch ? "write" : "read");
1274 /* We don't actually exit_cleanup(), so that we can
1275 * still service older version clients that still send
1276 * batch args to server. */
1277 read_batch = write_batch = 0;
1278 batch_name = NULL;
Wayne Davison254ee3b2005-03-24 16:41:16 +00001279 } else if (dry_run)
1280 write_batch = 0;
Wayne Davisonb9f592f2004-07-15 02:20:08 +00001281 }
Wayne Davison36119892004-07-21 22:50:11 +00001282 if (read_batch && files_from) {
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001283 snprintf(err_buf, sizeof err_buf,
Wayne Davison36119892004-07-21 22:50:11 +00001284 "--read-batch cannot be used with --files-from\n");
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001285 return 0;
Wayne Davison36119892004-07-21 22:50:11 +00001286 }
Wayne Davison9b3318b2004-07-15 16:27:02 +00001287 if (batch_name && strlen(batch_name) > MAX_BATCH_NAME_LEN) {
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001288 snprintf(err_buf, sizeof err_buf,
Wayne Davison9b3318b2004-07-15 16:27:02 +00001289 "the batch-file name must be %d characters or less.\n",
1290 MAX_BATCH_NAME_LEN);
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001291 return 0;
Wayne Davisonbeb93682004-01-19 23:33:02 +00001292 }
David Dykstra088aac82002-02-06 21:20:48 +00001293
Wayne Davisonce58b1b2004-01-22 01:20:24 +00001294 if (tmpdir && strlen(tmpdir) >= MAXPATHLEN - 10) {
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001295 snprintf(err_buf, sizeof err_buf,
1296 "the --temp-dir path is WAY too long.\n");
1297 return 0;
Wayne Davisonce58b1b2004-01-22 01:20:24 +00001298 }
1299
Wayne Davison7b9598b2007-07-15 05:42:30 +00001300 if (max_delete < 0 && max_delete != INT_MIN) {
1301 /* Negative numbers are treated as "no deletions". */
1302 max_delete = 0;
1303 }
1304
Wayne Davison1de3e992005-03-11 17:35:59 +00001305 if (compare_dest + copy_dest + link_dest > 1) {
Wayne Davisone012f852004-11-27 17:52:51 +00001306 snprintf(err_buf, sizeof err_buf,
Wayne Davison1de3e992005-03-11 17:35:59 +00001307 "You may not mix --compare-dest, --copy-dest, and --link-dest.\n");
Wayne Davisone012f852004-11-27 17:52:51 +00001308 return 0;
1309 }
1310
Wayne Davisonb6164932005-08-27 21:01:45 +00001311 if (files_from) {
1312 if (recurse == 1) /* preserve recurse == 2 */
1313 recurse = 0;
Wayne Davison550d4e22005-09-29 17:27:11 +00001314 if (xfer_dirs < 0)
Wayne Davisonb6164932005-08-27 21:01:45 +00001315 xfer_dirs = 1;
Wayne Davisondfa32482003-03-21 18:58:50 +00001316 }
Wayne Davison51d48392005-01-22 22:48:34 +00001317
Wayne Davisonb6164932005-08-27 21:01:45 +00001318 if (xfer_dirs < 1)
1319 xfer_dirs = recurse || list_only;
Wayne Davisondfa32482003-03-21 18:58:50 +00001320
Wayne Davisonea5164d2003-03-30 23:00:42 +00001321 if (relative_paths < 0)
1322 relative_paths = files_from? 1 : 0;
Wayne Davison89f2a4c2005-07-22 19:05:25 +00001323 if (!relative_paths)
1324 implied_dirs = 0;
Wayne Davisonea5164d2003-03-30 23:00:42 +00001325
Wayne Davisone0e32032006-12-28 07:54:10 +00001326 if (delete_before + !!delete_during + delete_after > 1) {
Wayne Davison3359acb2005-01-25 03:08:58 +00001327 snprintf(err_buf, sizeof err_buf,
Wayne Davisonc6eb7fa2005-01-28 07:39:09 +00001328 "You may not combine multiple --delete-WHEN options.\n");
Wayne Davison3359acb2005-01-25 03:08:58 +00001329 return 0;
1330 }
Wayne Davisonf5a910d2006-01-21 19:52:55 +00001331 if (delete_before || delete_during || delete_after)
Wayne Davison51d48392005-01-22 22:48:34 +00001332 delete_mode = 1;
Wayne Davison3296f912005-02-15 21:15:58 +00001333 else if (delete_mode || delete_excluded) {
Wayne Davisone0e32032006-12-28 07:54:10 +00001334 /* Only choose now between before & during if one is refused. */
Wayne Davison3296f912005-02-15 21:15:58 +00001335 if (refused_delete_before) {
Wayne Davisone0e32032006-12-28 07:54:10 +00001336 if (!refused_delete_during)
1337 delete_during = 1;
1338 else {
1339 create_refuse_error(refused_delete_before);
1340 return 0;
1341 }
1342 } else if (refused_delete_during)
1343 delete_before = 1;
1344 delete_mode = 1;
Wayne Davison3296f912005-02-15 21:15:58 +00001345 }
Wayne Davison89fb5022006-03-28 23:09:36 +00001346 if (!xfer_dirs && delete_mode) {
1347 snprintf(err_buf, sizeof err_buf,
1348 "--delete does not work without -r or -d.\n");
1349 return 0;
Wayne Davisonf5a910d2006-01-21 19:52:55 +00001350 }
Wayne Davison51d48392005-01-22 22:48:34 +00001351
Wayne Davison36719872005-02-11 10:42:55 +00001352 if (delete_mode && refused_delete) {
1353 create_refuse_error(refused_delete);
1354 return 0;
1355 }
1356
Wayne Davison47c11972006-06-30 15:52:52 +00001357 if (remove_source_files) {
1358 /* We only want to infer this refusal of --remove-source-files
Wayne Davison07c6ae72005-02-20 01:04:40 +00001359 * via the refusal of "delete", not any of the "delete-FOO"
1360 * options. */
1361 if (refused_delete && am_sender) {
1362 create_refuse_error(refused_delete);
1363 return 0;
1364 }
1365 need_messages_from_generator = 1;
1366 }
1367
Wayne Davison7be73df2004-03-27 09:46:42 +00001368 *argv = poptGetArgs(pc);
Wayne Davison8db7cc22004-10-11 10:43:25 +00001369 *argc = count_args(*argv);
Wayne Davison7be73df2004-03-27 09:46:42 +00001370
1371 if (sanitize_paths) {
1372 int i;
1373 for (i = *argc; i-- > 0; )
Wayne Davison91f4b312006-05-03 00:48:20 +00001374 (*argv)[i] = sanitize_path(NULL, (*argv)[i], "", 0, NULL);
Wayne Davison1a7f3d92006-10-12 03:01:18 +00001375 if (tmpdir)
Wayne Davison91f4b312006-05-03 00:48:20 +00001376 tmpdir = sanitize_path(NULL, tmpdir, NULL, 0, NULL);
Wayne Davison1a7f3d92006-10-12 03:01:18 +00001377 if (backup_dir)
Wayne Davison91f4b312006-05-03 00:48:20 +00001378 backup_dir = sanitize_path(NULL, backup_dir, NULL, 0, NULL);
Wayne Davison7be73df2004-03-27 09:46:42 +00001379 }
Wayne Davison78424182005-01-25 10:39:14 +00001380 if (server_filter_list.head && !am_sender) {
1381 struct filter_list_struct *elp = &server_filter_list;
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001382 if (tmpdir) {
Wayne Davison36719872005-02-11 10:42:55 +00001383 if (!*tmpdir)
1384 goto options_rejected;
Wayne Davison58b19992004-08-12 18:20:07 +00001385 clean_fname(tmpdir, 1);
Wayne Davison78424182005-01-25 10:39:14 +00001386 if (check_filter(elp, tmpdir, 1) < 0)
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001387 goto options_rejected;
1388 }
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001389 if (backup_dir) {
Wayne Davison36719872005-02-11 10:42:55 +00001390 if (!*backup_dir)
1391 goto options_rejected;
Wayne Davison58b19992004-08-12 18:20:07 +00001392 clean_fname(backup_dir, 1);
Wayne Davisonf0fa8c62006-11-19 04:39:35 +00001393 if (check_filter(elp, backup_dir, 1) < 0)
1394 goto options_rejected;
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001395 }
1396 }
Wayne Davison7be73df2004-03-27 09:46:42 +00001397
Wayne Davisond175d7e2003-08-01 07:58:44 +00001398 if (!backup_suffix)
Wayne Davisone0391f82004-02-11 04:30:41 +00001399 backup_suffix = backup_dir ? "" : BACKUP_SUFFIX;
Wayne Davisond175d7e2003-08-01 07:58:44 +00001400 backup_suffix_len = strlen(backup_suffix);
Wayne Davison80ddadb2003-08-01 19:40:31 +00001401 if (strchr(backup_suffix, '/') != NULL) {
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001402 snprintf(err_buf, sizeof err_buf,
1403 "--suffix cannot contain slashes: %s\n",
Wayne Davison80ddadb2003-08-01 19:40:31 +00001404 backup_suffix);
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001405 return 0;
Wayne Davison80ddadb2003-08-01 19:40:31 +00001406 }
Wayne Davisone0391f82004-02-11 04:30:41 +00001407 if (backup_dir) {
1408 backup_dir_len = strlcpy(backup_dir_buf, backup_dir, sizeof backup_dir_buf);
1409 backup_dir_remainder = sizeof backup_dir_buf - backup_dir_len;
1410 if (backup_dir_remainder < 32) {
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001411 snprintf(err_buf, sizeof err_buf,
1412 "the --backup-dir path is WAY too long.\n");
1413 return 0;
Wayne Davisone0391f82004-02-11 04:30:41 +00001414 }
1415 if (backup_dir_buf[backup_dir_len - 1] != '/') {
1416 backup_dir_buf[backup_dir_len++] = '/';
1417 backup_dir_buf[backup_dir_len] = '\0';
1418 }
Wayne Davison0ee6ca92006-01-13 22:06:31 +00001419 if (verbose > 1 && !am_sender)
1420 rprintf(FINFO, "backup_dir is %s\n", backup_dir_buf);
Wayne Davison8dcf9332004-03-31 17:02:22 +00001421 } else if (!backup_suffix_len && (!am_server || !am_sender)) {
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001422 snprintf(err_buf, sizeof err_buf,
Wayne Davisond175d7e2003-08-01 07:58:44 +00001423 "--suffix cannot be a null string without --backup-dir\n");
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001424 return 0;
Wayne Davisonf41152d2007-03-05 17:08:00 +00001425 } else if (make_backups && delete_mode && !delete_excluded && !am_server) {
1426 snprintf(backup_dir_buf, sizeof backup_dir_buf,
1427 "P *%s", backup_suffix);
1428 parse_rule(&filter_list, backup_dir_buf, 0, 0);
Wayne Davisond175d7e2003-08-01 07:58:44 +00001429 }
Wayne Davisond4021b62005-02-21 10:03:23 +00001430 if (make_backups && !backup_dir)
1431 omit_dir_times = 1;
Wayne Davisond175d7e2003-08-01 07:58:44 +00001432
Wayne Davisonb3e4e7e2006-05-29 22:56:45 +00001433 if (stdout_format) {
1434 if (am_server && log_format_has(stdout_format, 'I'))
1435 stdout_format_has_i = 2;
1436 else if (log_format_has(stdout_format, 'i'))
1437 stdout_format_has_i = itemize_changes | 1;
1438 if (!log_format_has(stdout_format, 'b')
1439 && !log_format_has(stdout_format, 'c'))
Wayne Davisone7651882005-02-16 08:10:31 +00001440 log_before_transfer = !am_server;
1441 } else if (itemize_changes) {
Wayne Davisonb3e4e7e2006-05-29 22:56:45 +00001442 stdout_format = "%i %n%L";
1443 stdout_format_has_i = itemize_changes;
Wayne Davisone7651882005-02-16 08:10:31 +00001444 log_before_transfer = !am_server;
1445 }
Wayne Davison87383692005-02-16 17:02:08 +00001446
Wayne Davisona892d902006-02-07 20:06:43 +00001447 if (do_progress && !verbose && !log_before_transfer && !am_server)
J.W. Schultze2559db2003-08-06 06:45:14 +00001448 verbose = 1;
Wayne Davison87383692005-02-16 17:02:08 +00001449
Wayne Davison11e758a2005-04-09 18:59:47 +00001450 if (dry_run)
1451 do_xfers = 0;
1452
Wayne Davison9ac756c2005-05-19 08:52:17 +00001453 set_io_timeout(io_timeout);
1454
Wayne Davisonb3e4e7e2006-05-29 22:56:45 +00001455 if (verbose && !stdout_format) {
1456 stdout_format = "%n%L";
Wayne Davison87383692005-02-16 17:02:08 +00001457 log_before_transfer = !am_server;
Wayne Davison36719872005-02-11 10:42:55 +00001458 }
Wayne Davisonb3e4e7e2006-05-29 22:56:45 +00001459 if (stdout_format_has_i || log_format_has(stdout_format, 'o'))
1460 stdout_format_has_o_or_i = 1;
J.W. Schultze2559db2003-08-06 06:45:14 +00001461
Wayne Davison232658d2006-05-30 17:14:17 +00001462 if (logfile_name && !am_daemon) {
Wayne Davisonb3e4e7e2006-05-29 22:56:45 +00001463 if (!logfile_format) {
Wayne Davison232658d2006-05-30 17:14:17 +00001464 logfile_format = "%i %n%L";
Wayne Davison87c0f9d2006-05-09 18:31:03 +00001465 logfile_format_has_i = logfile_format_has_o_or_i = 1;
Wayne Davisonb3e4e7e2006-05-29 22:56:45 +00001466 } else {
1467 if (log_format_has(logfile_format, 'i'))
Wayne Davison19b85872006-06-01 06:49:15 +00001468 logfile_format_has_i = 1;
Wayne Davisonb3e4e7e2006-05-29 22:56:45 +00001469 if (logfile_format_has_i || log_format_has(logfile_format, 'o'))
1470 logfile_format_has_o_or_i = 1;
Wayne Davison87c0f9d2006-05-09 18:31:03 +00001471 }
Wayne Davison6dc9b742006-06-07 23:05:24 +00001472 log_init(0);
Wayne Davison28736032006-05-30 17:41:54 +00001473 } else if (!am_daemon)
1474 logfile_format = NULL;
Wayne Davison87c0f9d2006-05-09 18:31:03 +00001475
Wayne Davison9fb08442004-11-17 19:29:20 +00001476 if (daemon_bwlimit && (!bwlimit || bwlimit > daemon_bwlimit))
1477 bwlimit = daemon_bwlimit;
Wayne Davison3c74c3a2004-05-27 21:51:53 +00001478 if (bwlimit) {
1479 bwlimit_writemax = (size_t)bwlimit * 128;
1480 if (bwlimit_writemax < 512)
1481 bwlimit_writemax = 512;
1482 }
1483
Wayne Davisoncfce9f62005-08-30 02:57:19 +00001484 if (sparse_files && inplace) {
Wayne Davisonc3851182005-08-30 02:59:30 +00001485 /* Note: we don't check for this below, because --append is
Wayne Davisoncfce9f62005-08-30 02:57:19 +00001486 * OK with --sparse (as long as redos are handled right). */
1487 snprintf(err_buf, sizeof err_buf,
1488 "--sparse cannot be used with --inplace\n");
1489 return 0;
1490 }
1491
Wayne Davisona0157882005-07-28 01:46:09 +00001492 if (append_mode) {
1493 if (whole_file > 0) {
1494 snprintf(err_buf, sizeof err_buf,
1495 "--append cannot be used with --whole-file\n");
1496 return 0;
1497 }
1498 if (refused_inplace) {
1499 create_refuse_error(refused_inplace);
1500 return 0;
1501 }
1502 inplace = 1;
1503 }
1504
Wayne Davisonf06e7082005-01-27 22:46:14 +00001505 if (delay_updates && !partial_dir)
Wayne Davison77860ba2006-01-29 19:17:13 +00001506 partial_dir = tmp_partialdir;
Wayne Davisonf06e7082005-01-27 22:46:14 +00001507
Wayne Davisona3221d22004-07-16 20:06:24 +00001508 if (inplace) {
Wayne Davison4f5b0752005-02-14 00:53:43 +00001509#ifdef HAVE_FTRUNCATE
Wayne Davisona7260c42004-07-29 16:06:38 +00001510 if (partial_dir) {
1511 snprintf(err_buf, sizeof err_buf,
Wayne Davisona0157882005-07-28 01:46:09 +00001512 "--%s cannot be used with --%s\n",
1513 append_mode ? "append" : "inplace",
Wayne Davisonf06e7082005-01-27 22:46:14 +00001514 delay_updates ? "delay-updates" : "partial-dir");
Wayne Davisona7260c42004-07-29 16:06:38 +00001515 return 0;
1516 }
Wayne Davison36719872005-02-11 10:42:55 +00001517 /* --inplace implies --partial for refusal purposes, but we
1518 * clear the keep_partial flag for internal logic purposes. */
1519 if (refused_partial) {
1520 create_refuse_error(refused_partial);
1521 return 0;
1522 }
Wayne Davisona3221d22004-07-16 20:06:24 +00001523 keep_partial = 0;
Wayne Davisonded4daf2005-01-15 20:22:54 +00001524#else
1525 snprintf(err_buf, sizeof err_buf,
Wayne Davisona0157882005-07-28 01:46:09 +00001526 "--%s is not supported on this %s\n",
1527 append_mode ? "append" : "inplace",
Wayne Davisonded4daf2005-01-15 20:22:54 +00001528 am_server ? "server" : "client");
1529 return 0;
1530#endif
Wayne Davison075aa182004-09-18 17:34:56 +00001531 } else {
Wayne Davisonbc880cb2006-02-07 19:12:37 +00001532 if (keep_partial && !partial_dir && !am_server) {
Wayne Davison36719872005-02-11 10:42:55 +00001533 if ((arg = getenv("RSYNC_PARTIAL_DIR")) != NULL && *arg)
1534 partial_dir = strdup(arg);
1535 }
Wayne Davison075aa182004-09-18 17:34:56 +00001536 if (partial_dir) {
Wayne Davison36719872005-02-11 10:42:55 +00001537 if (*partial_dir)
1538 clean_fname(partial_dir, 1);
Wayne Davison075aa182004-09-18 17:34:56 +00001539 if (!*partial_dir || strcmp(partial_dir, ".") == 0)
1540 partial_dir = NULL;
Wayne Davison36719872005-02-11 10:42:55 +00001541 if (!partial_dir && refused_partial) {
1542 create_refuse_error(refused_partial);
1543 return 0;
1544 }
Wayne Davison075aa182004-09-18 17:34:56 +00001545 keep_partial = 1;
1546 }
Wayne Davisona3221d22004-07-16 20:06:24 +00001547 }
1548
Wayne Davisonea5164d2003-03-30 23:00:42 +00001549 if (files_from) {
Wayne Davison305666b2005-03-01 01:15:57 +00001550 char *h, *p;
1551 int q;
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001552 if (*argc > 2 || (!am_daemon && *argc == 1)) {
Wayne Davisonea5164d2003-03-30 23:00:42 +00001553 usage(FERROR);
1554 exit_cleanup(RERR_SYNTAX);
1555 }
Wayne Davison63596e12003-12-15 00:53:07 +00001556 if (strcmp(files_from, "-") == 0) {
Wayne Davisonea5164d2003-03-30 23:00:42 +00001557 filesfrom_fd = 0;
Wayne Davison63596e12003-12-15 00:53:07 +00001558 if (am_server)
Wayne Davison305666b2005-03-01 01:15:57 +00001559 filesfrom_host = ""; /* reading from socket */
1560 } else if ((p = check_for_hostspec(files_from, &h, &q)) != 0) {
Wayne Davisonea5164d2003-03-30 23:00:42 +00001561 if (am_server) {
Wayne Davison305666b2005-03-01 01:15:57 +00001562 snprintf(err_buf, sizeof err_buf,
1563 "The --files-from sent to the server cannot specify a host.\n");
1564 return 0;
Wayne Davisonea5164d2003-03-30 23:00:42 +00001565 }
Wayne Davison305666b2005-03-01 01:15:57 +00001566 files_from = p;
1567 filesfrom_host = h;
1568 if (strcmp(files_from, "-") == 0) {
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001569 snprintf(err_buf, sizeof err_buf,
1570 "Invalid --files-from remote filename\n");
1571 return 0;
Wayne Davisonea5164d2003-03-30 23:00:42 +00001572 }
1573 } else {
Wayne Davison305666b2005-03-01 01:15:57 +00001574 if (sanitize_paths)
Wayne Davison91f4b312006-05-03 00:48:20 +00001575 files_from = sanitize_path(NULL, files_from, NULL, 0, NULL);
Wayne Davison305666b2005-03-01 01:15:57 +00001576 if (server_filter_list.head) {
1577 if (!*files_from)
1578 goto options_rejected;
1579 clean_fname(files_from, 1);
1580 if (check_filter(&server_filter_list, files_from, 0) < 0)
1581 goto options_rejected;
1582 }
Wayne Davisonea5164d2003-03-30 23:00:42 +00001583 filesfrom_fd = open(files_from, O_RDONLY|O_BINARY);
1584 if (filesfrom_fd < 0) {
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001585 snprintf(err_buf, sizeof err_buf,
1586 "failed to open files-from file %s: %s\n",
1587 files_from, strerror(errno));
1588 return 0;
Wayne Davisonea5164d2003-03-30 23:00:42 +00001589 }
1590 }
1591 }
1592
Wayne Davison7f2a1f62005-02-25 17:08:31 +00001593 am_starting_up = 0;
1594
Andrew Tridgellb11ed3b1998-07-19 04:50:48 +00001595 return 1;
Wayne Davisonf0fa8c62006-11-19 04:39:35 +00001596
1597 options_rejected:
1598 snprintf(err_buf, sizeof err_buf,
1599 "Your options have been rejected by the server.\n");
1600 return 0;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +00001601}
1602
1603
Martin Pooldafe63c2002-04-16 01:38:21 +00001604/**
1605 * Construct a filtered list of options to pass through from the
1606 * client to the server.
1607 *
1608 * This involves setting options that will tell the server how to
1609 * behave, and also filtering out options that are processed only
1610 * locally.
1611 **/
Andrew Tridgell7a6421f1998-05-10 07:25:40 +00001612void server_options(char **args,int *argc)
1613{
Wayne Davison74ba98a2005-05-03 17:01:59 +00001614 static char argstr[64];
Andrew Tridgelld8537831998-07-17 10:00:43 +00001615 int ac = *argc;
Wayne Davisonf98c60b2004-02-09 18:10:57 +00001616 char *arg;
David Dykstraef5d23e2000-06-06 21:13:05 +00001617
Andrew Tridgelld8537831998-07-17 10:00:43 +00001618 int i, x;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +00001619
David Dykstra93689aa2002-02-05 23:05:31 +00001620 if (blocking_io == -1)
1621 blocking_io = 0;
1622
Wayne Davisondef97ff2006-01-26 11:10:32 +00001623 /* This should always remain first on the server's command-line. */
Andrew Tridgelld8537831998-07-17 10:00:43 +00001624 args[ac++] = "--server";
Andrew Tridgell7a6421f1998-05-10 07:25:40 +00001625
Wayne Davisone2086312007-08-11 16:53:31 +00001626 if (daemon_over_rsh > 0) {
Wayne Davison1312d9f2002-08-01 00:37:01 +00001627 args[ac++] = "--daemon";
1628 *argc = ac;
1629 /* if we're passing --daemon, we're done */
1630 return;
1631 }
1632
Andrew Tridgelld8537831998-07-17 10:00:43 +00001633 if (!am_sender)
1634 args[ac++] = "--sender";
Andrew Tridgell7a6421f1998-05-10 07:25:40 +00001635
Andrew Tridgelld8537831998-07-17 10:00:43 +00001636 x = 1;
1637 argstr[0] = '-';
Wayne Davisonf98c60b2004-02-09 18:10:57 +00001638 for (i = 0; i < verbose; i++)
Andrew Tridgelld8537831998-07-17 10:00:43 +00001639 argstr[x++] = 'v';
Andrew Tridgellf0b36a42000-08-29 04:46:27 +00001640
David Dykstrab86f0ce1999-02-09 17:25:35 +00001641 /* the -q option is intentionally left out */
Andrew Tridgelld8537831998-07-17 10:00:43 +00001642 if (make_backups)
1643 argstr[x++] = 'b';
1644 if (update_only)
1645 argstr[x++] = 'u';
Wayne Davison2dbf36e2006-02-24 17:54:30 +00001646 if (!do_xfers) /* Note: NOT "dry_run"! */
Andrew Tridgelld8537831998-07-17 10:00:43 +00001647 argstr[x++] = 'n';
1648 if (preserve_links)
1649 argstr[x++] = 'l';
Wayne Davison4d51f0d2006-10-13 06:27:59 +00001650 if (xfer_dirs > (recurse || !delete_mode || !am_sender ? 1 : 0))
Wayne Davison5454d222005-01-29 21:25:44 +00001651 argstr[x++] = 'd';
Wayne Davison35bf8fa2006-01-26 22:28:08 +00001652 if (am_sender) {
1653 if (keep_dirlinks)
1654 argstr[x++] = 'K';
Wayne Davison876c9932006-01-28 00:13:55 +00001655 if (prune_empty_dirs)
1656 argstr[x++] = 'm';
Wayne Davison35bf8fa2006-01-26 22:28:08 +00001657 if (omit_dir_times == 2)
1658 argstr[x++] = 'O';
Wayne Davison2dbf36e2006-02-24 17:54:30 +00001659 } else {
1660 if (copy_links)
1661 argstr[x++] = 'L';
1662 if (copy_dirlinks)
1663 argstr[x++] = 'k';
Wayne Davison35bf8fa2006-01-26 22:28:08 +00001664 }
Martin Pool1bfbf402002-03-19 03:21:53 +00001665
Wayne Davisondfa32482003-03-21 18:58:50 +00001666 if (whole_file > 0)
Andrew Tridgelld8537831998-07-17 10:00:43 +00001667 argstr[x++] = 'W';
Martin Poolbceec822002-03-19 03:39:42 +00001668 /* We don't need to send --no-whole-file, because it's the
1669 * default for remote transfers, and in any case old versions
1670 * of rsync will not understand it. */
Wayne Davisondfa32482003-03-21 18:58:50 +00001671
Wayne Davisone0e32032006-12-28 07:54:10 +00001672 if (preserve_hard_links) {
Andrew Tridgelld8537831998-07-17 10:00:43 +00001673 argstr[x++] = 'H';
Wayne Davisone0e32032006-12-28 07:54:10 +00001674 if (preserve_hard_links > 1)
1675 argstr[x++] = 'H';
1676 }
Andrew Tridgelld8537831998-07-17 10:00:43 +00001677 if (preserve_uid)
1678 argstr[x++] = 'o';
1679 if (preserve_gid)
1680 argstr[x++] = 'g';
Wayne Davisonb5c6a6a2006-01-26 10:38:58 +00001681 if (preserve_devices) /* ignore preserve_specials here */
Andrew Tridgelld8537831998-07-17 10:00:43 +00001682 argstr[x++] = 'D';
1683 if (preserve_times)
1684 argstr[x++] = 't';
1685 if (preserve_perms)
1686 argstr[x++] = 'p';
Wayne Davison344f9ba2006-01-31 02:29:58 +00001687 else if (preserve_executability && am_sender)
1688 argstr[x++] = 'E';
Wayne Davison1c3344a2007-03-11 00:13:34 +00001689#ifdef SUPPORT_ACLS
1690 if (preserve_acls)
1691 argstr[x++] = 'A';
1692#endif
Wayne Davison16edf862007-04-07 17:22:25 +00001693#ifdef SUPPORT_XATTRS
Wayne Davison524eaa82007-07-02 21:35:14 +00001694 if (preserve_xattrs) {
Wayne Davison16edf862007-04-07 17:22:25 +00001695 argstr[x++] = 'X';
Wayne Davison524eaa82007-07-02 21:35:14 +00001696 if (preserve_xattrs > 1)
1697 argstr[x++] = 'X';
1698 }
Wayne Davison16edf862007-04-07 17:22:25 +00001699#endif
Wayne Davisonaa7a6e82005-03-14 17:30:13 +00001700 if (recurse)
Andrew Tridgelld8537831998-07-17 10:00:43 +00001701 argstr[x++] = 'r';
1702 if (always_checksum)
1703 argstr[x++] = 'c';
1704 if (cvs_exclude)
1705 argstr[x++] = 'C';
1706 if (ignore_times)
1707 argstr[x++] = 'I';
1708 if (relative_paths)
1709 argstr[x++] = 'R';
Wayne Davison243c9952006-01-21 00:36:15 +00001710 if (one_file_system) {
Andrew Tridgelld8537831998-07-17 10:00:43 +00001711 argstr[x++] = 'x';
Wayne Davison243c9952006-01-21 00:36:15 +00001712 if (one_file_system > 1)
1713 argstr[x++] = 'x';
1714 }
Andrew Tridgelld8537831998-07-17 10:00:43 +00001715 if (sparse_files)
1716 argstr[x++] = 'S';
1717 if (do_compression)
1718 argstr[x++] = 'z';
Andrew Tridgellf0b36a42000-08-29 04:46:27 +00001719
Wayne Davison51d48392005-01-22 22:48:34 +00001720 /* This is a complete hack - blame Rusty. FIXME!
1721 * This hack is only needed for older rsync versions that
1722 * don't understand the --list-only option. */
Wayne Davisonda2a6c12005-03-17 00:52:33 +00001723 if (list_only == 1 && !recurse)
Andrew Tridgellf0b36a42000-08-29 04:46:27 +00001724 argstr[x++] = 'r';
1725
Wayne Davison2ed790f2007-04-23 19:54:07 +00001726#if SUBPROTOCOL_VERSION != 0
Wayne Davison486f8cd2007-04-23 19:03:29 +00001727 /* If we're speaking a pre-release version of a protocol, we tell
1728 * the server about this by (ab)using the -e option. */
Wayne Davison2ed790f2007-04-23 19:54:07 +00001729 if (protocol_version == PROTOCOL_VERSION) {
Wayne Davison486f8cd2007-04-23 19:03:29 +00001730 x += snprintf(argstr+x, sizeof argstr - x,
1731 "e%d.%d", PROTOCOL_VERSION, SUBPROTOCOL_VERSION);
1732 }
Wayne Davison2ed790f2007-04-23 19:54:07 +00001733#endif
Wayne Davison486f8cd2007-04-23 19:03:29 +00001734
Wayne Davison332cf6d2007-04-26 05:53:13 +00001735 argstr[x] = '\0';
1736
Wayne Davisonf98c60b2004-02-09 18:10:57 +00001737 if (x != 1)
1738 args[ac++] = argstr;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +00001739
Wayne Davison51d48392005-01-22 22:48:34 +00001740 if (list_only > 1)
1741 args[ac++] = "--list-only";
1742
Wayne Davisonf5a910d2006-01-21 19:52:55 +00001743 /* This makes sure that the remote rsync can handle deleting with -d
1744 * sans -r because the --no-r option was added at the same time. */
1745 if (xfer_dirs && !recurse && delete_mode && am_sender)
1746 args[ac++] = "--no-r";
1747
Wayne Davison854a1aa2005-10-26 16:47:15 +00001748 if (do_compression && def_compress_level != Z_DEFAULT_COMPRESSION) {
1749 if (asprintf(&arg, "--compress-level=%d", def_compress_level) < 0)
1750 goto oom;
1751 args[ac++] = arg;
1752 }
1753
Wayne Davisonb5c6a6a2006-01-26 10:38:58 +00001754 if (preserve_devices) {
1755 /* Note: sending "--devices" would not be backward-compatible. */
1756 if (!preserve_specials)
1757 args[ac++] = "--no-specials"; /* -D is already set. */
1758 } else if (preserve_specials)
1759 args[ac++] = "--specials";
1760
Wayne Davison5c5e1592005-02-19 03:54:11 +00001761 /* The server side doesn't use our log-format, but in certain
1762 * circumstances they need to know a little about the option. */
Wayne Davisonb3e4e7e2006-05-29 22:56:45 +00001763 if (stdout_format && am_sender) {
1764 /* Use --log-format, not --out-format, for compatibility. */
1765 if (stdout_format_has_i > 1)
Wayne Davison487094a2006-01-20 18:49:07 +00001766 args[ac++] = "--log-format=%i%I";
Wayne Davisonb3e4e7e2006-05-29 22:56:45 +00001767 else if (stdout_format_has_i)
Wayne Davison684d7582005-02-19 22:16:39 +00001768 args[ac++] = "--log-format=%i";
Wayne Davisonb3e4e7e2006-05-29 22:56:45 +00001769 else if (stdout_format_has_o_or_i)
Wayne Davison5c5e1592005-02-19 03:54:11 +00001770 args[ac++] = "--log-format=%o";
1771 else if (!verbose)
1772 args[ac++] = "--log-format=X";
1773 }
Wayne Davison1f30a672005-02-19 02:39:30 +00001774
Wayne Davison332cf6d2007-04-26 05:53:13 +00001775#ifdef ICONV_OPTION
1776 if (iconv_opt) {
1777 char *set = strchr(iconv_opt, ',');
1778 if (set)
1779 set++;
1780 else
1781 set = iconv_opt;
1782 if (asprintf(&arg, "--iconv=%s", set) < 0)
1783 goto oom;
1784 args[ac++] = arg;
1785 }
1786#endif
1787
J.W. Schultz195bd902003-04-10 02:04:58 +00001788 if (block_size) {
Wayne Davisona06b4192005-01-01 21:08:14 +00001789 if (asprintf(&arg, "-B%lu", block_size) < 0)
Wayne Davisonf98c60b2004-02-09 18:10:57 +00001790 goto oom;
1791 args[ac++] = arg;
Wayne Davisondfa32482003-03-21 18:58:50 +00001792 }
Andrew Tridgell7a6421f1998-05-10 07:25:40 +00001793
Andrew Tridgelld8537831998-07-17 10:00:43 +00001794 if (io_timeout) {
Wayne Davisonf98c60b2004-02-09 18:10:57 +00001795 if (asprintf(&arg, "--timeout=%d", io_timeout) < 0)
1796 goto oom;
1797 args[ac++] = arg;
Wayne Davisondfa32482003-03-21 18:58:50 +00001798 }
Andrew Tridgell7a6421f1998-05-10 07:25:40 +00001799
David Dykstraef5d23e2000-06-06 21:13:05 +00001800 if (bwlimit) {
Wayne Davisonf98c60b2004-02-09 18:10:57 +00001801 if (asprintf(&arg, "--bwlimit=%d", bwlimit) < 0)
1802 goto oom;
1803 args[ac++] = arg;
David Dykstraef5d23e2000-06-06 21:13:05 +00001804 }
1805
Wayne Davisond175d7e2003-08-01 07:58:44 +00001806 if (backup_dir) {
1807 args[ac++] = "--backup-dir";
1808 args[ac++] = backup_dir;
1809 }
1810
1811 /* Only send --suffix if it specifies a non-default value. */
Wayne Davisonf98c60b2004-02-09 18:10:57 +00001812 if (strcmp(backup_suffix, backup_dir ? "" : BACKUP_SUFFIX) != 0) {
Wayne Davison191e40d2003-08-01 20:19:51 +00001813 /* We use the following syntax to avoid weirdness with '~'. */
Wayne Davisonf98c60b2004-02-09 18:10:57 +00001814 if (asprintf(&arg, "--suffix=%s", backup_suffix) < 0)
1815 goto oom;
1816 args[ac++] = arg;
Andrew Tridgelld8537831998-07-17 10:00:43 +00001817 }
Andrew Tridgell7a6421f1998-05-10 07:25:40 +00001818
Wayne Davison06a50542004-08-02 05:00:30 +00001819 if (am_sender) {
Wayne Davison7b9598b2007-07-15 05:42:30 +00001820 if (max_delete > 0) {
1821 if (asprintf(&arg, "--max-delete=%d", max_delete) < 0)
1822 goto oom;
1823 args[ac++] = arg;
1824 } else if (max_delete == 0)
1825 args[ac++] = "--max_delete=-1";
1826 if (min_size) {
1827 args[ac++] = "--min-size";
1828 args[ac++] = min_size_arg;
1829 }
1830 if (max_size) {
1831 args[ac++] = "--max-size";
1832 args[ac++] = max_size_arg;
1833 }
Wayne Davisone0e32032006-12-28 07:54:10 +00001834 if (delete_before)
Wayne Davisonc6eb7fa2005-01-28 07:39:09 +00001835 args[ac++] = "--delete-before";
Wayne Davison0d152432006-12-13 14:52:59 +00001836 else if (delete_during == 2)
1837 args[ac++] = "--delete-delay";
1838 else if (delete_during)
1839 args[ac++] = "--delete-during";
1840 else if (delete_after)
Wayne Davison06a50542004-08-02 05:00:30 +00001841 args[ac++] = "--delete-after";
Wayne Davisone0e32032006-12-28 07:54:10 +00001842 else if (delete_mode && !delete_excluded)
1843 args[ac++] = "--delete";
1844 if (delete_excluded)
1845 args[ac++] = "--delete-excluded";
Wayne Davison06a50542004-08-02 05:00:30 +00001846 if (force_delete)
1847 args[ac++] = "--force";
Wayne Davison11e758a2005-04-09 18:59:47 +00001848 if (write_batch < 0)
1849 args[ac++] = "--only-write-batch=X";
Wayne Davisondef97ff2006-01-26 11:10:32 +00001850 if (am_root > 1)
1851 args[ac++] = "--super";
Wayne Davisonf17e7692006-02-09 01:15:04 +00001852 if (size_only)
1853 args[ac++] = "--size-only";
Wayne Davisonb1e436e2007-07-14 19:24:32 +00001854 } else {
1855 if (skip_compress) {
1856 if (asprintf(&arg, "--skip-compress=%s", skip_compress) < 0)
1857 goto oom;
1858 args[ac++] = arg;
1859 }
Wayne Davison06a50542004-08-02 05:00:30 +00001860 }
David Dykstrab33b7911999-02-22 19:55:57 +00001861
Andrew Tridgell5b56cc12000-09-06 02:12:13 +00001862 if (modify_window_set) {
Wayne Davisonf98c60b2004-02-09 18:10:57 +00001863 if (asprintf(&arg, "--modify-window=%d", modify_window) < 0)
1864 goto oom;
1865 args[ac++] = arg;
Andrew Tridgell5b56cc12000-09-06 02:12:13 +00001866 }
1867
Wayne Davisonc8d895d2004-05-21 09:44:32 +00001868 if (checksum_seed) {
Wayne Davison221ddb92004-05-22 06:09:22 +00001869 if (asprintf(&arg, "--checksum-seed=%d", checksum_seed) < 0)
Wayne Davisonc8d895d2004-05-21 09:44:32 +00001870 goto oom;
1871 args[ac++] = arg;
1872 }
1873
Wayne Davisona7260c42004-07-29 16:06:38 +00001874 if (partial_dir && am_sender) {
Wayne Davison77860ba2006-01-29 19:17:13 +00001875 if (partial_dir != tmp_partialdir) {
Wayne Davison36719872005-02-11 10:42:55 +00001876 args[ac++] = "--partial-dir";
1877 args[ac++] = partial_dir;
1878 }
Wayne Davisonf06e7082005-01-27 22:46:14 +00001879 if (delay_updates)
1880 args[ac++] = "--delay-updates";
Wayne Davison77860ba2006-01-29 19:17:13 +00001881 } else if (keep_partial && am_sender)
Andrew Tridgelld8537831998-07-17 10:00:43 +00001882 args[ac++] = "--partial";
Andrew Tridgellc95da961998-07-01 03:36:03 +00001883
Andrew Tridgellef55c682000-03-21 04:06:04 +00001884 if (ignore_errors)
1885 args[ac++] = "--ignore-errors";
1886
David Dykstrab5313601999-02-17 19:34:40 +00001887 if (copy_unsafe_links)
1888 args[ac++] = "--copy-unsafe-links";
1889
Andrew Tridgelld8537831998-07-17 10:00:43 +00001890 if (safe_symlinks)
1891 args[ac++] = "--safe-links";
Andrew Tridgell7a6421f1998-05-10 07:25:40 +00001892
Andrew Tridgelld8537831998-07-17 10:00:43 +00001893 if (numeric_ids)
1894 args[ac++] = "--numeric-ids";
Andrew Tridgell7a6421f1998-05-10 07:25:40 +00001895
Wayne Davison5d935dc2007-07-24 04:09:46 +00001896 if (!allow_inc_recurse)
1897 args[ac++] = "--no-ir";
1898
Wayne Davison4f3797c2007-05-05 18:34:37 +00001899 if (am_sender) {
1900 if (ignore_existing)
1901 args[ac++] = "--ignore-existing";
Martin Pool3d6fead2002-01-25 10:42:23 +00001902
Wayne Davison4f3797c2007-05-05 18:34:37 +00001903 /* Backward compatibility: send --existing, not --ignore-non-existing. */
1904 if (ignore_non_existing)
1905 args[ac++] = "--existing";
1906
1907 if (tmpdir) {
1908 args[ac++] = "--temp-dir";
1909 args[ac++] = tmpdir;
1910 }
1911
1912 if (basis_dir[0]) {
1913 /* the server only needs this option if it is not the sender,
1914 * and it may be an older version that doesn't know this
1915 * option, so don't send it if client is the sender.
1916 */
1917 int i;
1918 for (i = 0; i < basis_dir_cnt; i++) {
1919 args[ac++] = dest_option;
1920 args[ac++] = basis_dir[i];
1921 }
1922 }
1923 }
Wayne Davisone90aab42005-09-29 18:07:55 +00001924
Wayne Davison936fa862007-09-01 16:38:00 +00001925 if (append_mode) {
1926 if (append_mode > 1)
1927 args[ac++] = "--append";
Wayne Davisona0157882005-07-28 01:46:09 +00001928 args[ac++] = "--append";
Wayne Davison936fa862007-09-01 16:38:00 +00001929 } else if (inplace)
Wayne Davisona3221d22004-07-16 20:06:24 +00001930 args[ac++] = "--inplace";
1931
Wayne Davison305666b2005-03-01 01:15:57 +00001932 if (files_from && (!am_sender || filesfrom_host)) {
1933 if (filesfrom_host) {
Wayne Davisonea5164d2003-03-30 23:00:42 +00001934 args[ac++] = "--files-from";
Wayne Davison305666b2005-03-01 01:15:57 +00001935 args[ac++] = files_from;
Wayne Davisonea5164d2003-03-30 23:00:42 +00001936 if (eol_nulls)
1937 args[ac++] = "--from0";
1938 } else {
1939 args[ac++] = "--files-from=-";
1940 args[ac++] = "--from0";
1941 }
Wayne Davisonc0ab28d2004-12-22 09:10:08 +00001942 if (!relative_paths)
1943 args[ac++] = "--no-relative";
Wayne Davisonea5164d2003-03-30 23:00:42 +00001944 }
Wayne Davison89f2a4c2005-07-22 19:05:25 +00001945 if (relative_paths && !implied_dirs && !am_sender)
Wayne Davison3a90ea02005-01-19 00:23:32 +00001946 args[ac++] = "--no-implied-dirs";
Wayne Davisonea5164d2003-03-30 23:00:42 +00001947
Wayne Davisonc4ed1482005-02-14 02:41:15 +00001948 if (fuzzy_basis && am_sender)
1949 args[ac++] = "--fuzzy";
1950
Wayne Davison47c11972006-06-30 15:52:52 +00001951 if (remove_source_files == 1)
1952 args[ac++] = "--remove-source-files";
1953 else if (remove_source_files)
Wayne Davison07c6ae72005-02-20 01:04:40 +00001954 args[ac++] = "--remove-sent-files";
1955
Andrew Tridgelld8537831998-07-17 10:00:43 +00001956 *argc = ac;
Wayne Davisonf98c60b2004-02-09 18:10:57 +00001957 return;
1958
1959 oom:
1960 out_of_memory("server_options");
Andrew Tridgell7a6421f1998-05-10 07:25:40 +00001961}
1962
Wayne Davison305666b2005-03-01 01:15:57 +00001963/* Look for a HOST specfication of the form "HOST:PATH", "HOST::PATH", or
1964 * "rsync://HOST:PORT/PATH". If found, *host_ptr will be set to some allocated
1965 * memory with the HOST. If a daemon-accessing spec was specified, the value
1966 * of *port_ptr will contain a non-0 port number, otherwise it will be set to
1967 * 0. The return value is a pointer to the PATH. Note that the HOST spec can
1968 * be an IPv6 literal address enclosed in '[' and ']' (such as "[::1]" or
1969 * "[::ffff:127.0.0.1]") which is returned without the '[' and ']'. */
1970char *check_for_hostspec(char *s, char **host_ptr, int *port_ptr)
Wayne Davisonea5164d2003-03-30 23:00:42 +00001971{
Wayne Davison305666b2005-03-01 01:15:57 +00001972 char *p;
1973 int not_host;
Wayne Davison8f4ae682006-09-18 17:39:13 +00001974 int hostlen;
Wayne Davisonea5164d2003-03-30 23:00:42 +00001975
Wayne Davison305666b2005-03-01 01:15:57 +00001976 if (port_ptr && strncasecmp(URL_PREFIX, s, strlen(URL_PREFIX)) == 0) {
1977 char *path;
Wayne Davison305666b2005-03-01 01:15:57 +00001978 s += strlen(URL_PREFIX);
1979 if ((p = strchr(s, '/')) != NULL) {
1980 hostlen = p - s;
1981 path = p + 1;
1982 } else {
1983 hostlen = strlen(s);
1984 path = "";
1985 }
1986 if (*s == '[' && (p = strchr(s, ']')) != NULL) {
1987 s++;
1988 hostlen = p - s;
Wayne Davisonc60b7052005-03-01 05:49:11 +00001989 if (p[1] == ':')
1990 *port_ptr = atoi(p+2);
Wayne Davison305666b2005-03-01 01:15:57 +00001991 } else {
Wayne Davison444f9f72007-08-01 22:25:02 +00001992 if ((p = strchr(s, ':')) != NULL && p < s + hostlen) {
Wayne Davison305666b2005-03-01 01:15:57 +00001993 hostlen = p - s;
1994 *port_ptr = atoi(p+1);
Wayne Davisonc60b7052005-03-01 05:49:11 +00001995 }
Wayne Davison305666b2005-03-01 01:15:57 +00001996 }
Wayne Davisonc60b7052005-03-01 05:49:11 +00001997 if (!*port_ptr)
1998 *port_ptr = RSYNC_PORT;
Wayne Davison305666b2005-03-01 01:15:57 +00001999 *host_ptr = new_array(char, hostlen + 1);
2000 strlcpy(*host_ptr, s, hostlen + 1);
2001 return path;
2002 }
Wayne Davisonea5164d2003-03-30 23:00:42 +00002003
Wayne Davison305666b2005-03-01 01:15:57 +00002004 if (*s == '[' && (p = strchr(s, ']')) != NULL && p[1] == ':') {
Wayne Davison8f4ae682006-09-18 17:39:13 +00002005 s++;
2006 hostlen = p - s;
Wayne Davison305666b2005-03-01 01:15:57 +00002007 *p = '\0';
2008 not_host = strchr(s, '/') || !strchr(s, ':');
2009 *p = ']';
2010 if (not_host)
2011 return NULL;
Wayne Davisonc60b7052005-03-01 05:49:11 +00002012 p++;
Wayne Davison305666b2005-03-01 01:15:57 +00002013 } else {
2014 if (!(p = strchr(s, ':')))
2015 return NULL;
Wayne Davison8f4ae682006-09-18 17:39:13 +00002016 hostlen = p - s;
Wayne Davison305666b2005-03-01 01:15:57 +00002017 *p = '\0';
2018 not_host = strchr(s, '/') != NULL;
2019 *p = ':';
2020 if (not_host)
2021 return NULL;
2022 }
Wayne Davisonea5164d2003-03-30 23:00:42 +00002023
Wayne Davison8f4ae682006-09-18 17:39:13 +00002024 *host_ptr = new_array(char, hostlen + 1);
2025 strlcpy(*host_ptr, s, hostlen + 1);
Wayne Davison305666b2005-03-01 01:15:57 +00002026
2027 if (p[1] == ':') {
2028 if (port_ptr && !*port_ptr)
2029 *port_ptr = RSYNC_PORT;
2030 return p + 2;
2031 }
2032 if (port_ptr)
2033 *port_ptr = 0;
2034
2035 return p + 1;
Wayne Davisonea5164d2003-03-30 23:00:42 +00002036}