blob: 74a42790448236bbddbf0180a5bffbe4ca1bad69 [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>
6 * Copyright (C) 2002, 2003, 2004, 2005, 2006 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
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 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
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
Martin Pooldafe63c2002-04-16 01:38:21 +000021 */
Andrew Tridgell7a6421f1998-05-10 07:25:40 +000022
Andrew Tridgell7a6421f1998-05-10 07:25:40 +000023#include "rsync.h"
Wayne Davison35bf8fa2006-01-26 22:28:08 +000024#include <popt.h>
Wayne Davison854a1aa2005-10-26 16:47:15 +000025#include "zlib/zlib.h"
Andrew Tridgell7a6421f1998-05-10 07:25:40 +000026
Wayne Davison7bc90b32005-01-29 20:48:20 +000027extern int module_id;
Wayne Davison7be73df2004-03-27 09:46:42 +000028extern int sanitize_paths;
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;
50int preserve_perms = 0;
Wayne Davison344f9ba2006-01-31 02:29:58 +000051int preserve_executability = 0;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +000052int preserve_devices = 0;
Wayne Davisonb5c6a6a2006-01-26 10:38:58 +000053int preserve_specials = 0;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +000054int preserve_uid = 0;
55int preserve_gid = 0;
56int preserve_times = 0;
Wayne Davison20fb7b92005-01-24 00:51:32 +000057int omit_dir_times = 0;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +000058int update_only = 0;
59int cvs_exclude = 0;
Wayne Davisona5c11132004-02-09 17:45:22 +000060int dry_run = 0;
Wayne Davison11e758a2005-04-09 18:59:47 +000061int do_xfers = 1;
Wayne Davisona5c11132004-02-09 17:45:22 +000062int ignore_times = 0;
63int delete_mode = 0;
Wayne Davisona51b3162005-01-24 01:41:54 +000064int delete_during = 0;
Wayne Davison51d48392005-01-22 22:48:34 +000065int delete_before = 0;
66int delete_after = 0;
Wayne Davisona5c11132004-02-09 17:45:22 +000067int delete_excluded = 0;
Wayne Davison47c11972006-06-30 15:52:52 +000068int remove_source_files = 0;
Wayne Davisona5c11132004-02-09 17:45:22 +000069int one_file_system = 0;
Wayne Davison4f3e9a02003-09-09 15:58:56 +000070int protocol_version = PROTOCOL_VERSION;
Wayne Davisona5c11132004-02-09 17:45:22 +000071int sparse_files = 0;
72int do_compression = 0;
Wayne Davison854a1aa2005-10-26 16:47:15 +000073int def_compress_level = Z_DEFAULT_COMPRESSION;
Wayne Davisona5c11132004-02-09 17:45:22 +000074int am_root = 0;
Wayne Davison7f2a1f62005-02-25 17:08:31 +000075int am_server = 0;
76int am_sender = 0;
77int am_generator = 0;
78int am_starting_up = 1;
Wayne Davisonea5164d2003-03-30 23:00:42 +000079int relative_paths = -1;
80int implied_dirs = 1;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +000081int numeric_ids = 0;
Wayne Davison5974c662006-02-06 18:41:32 +000082int allow_8bit_chars = 0;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +000083int force_delete = 0;
84int io_timeout = 0;
Wayne Davison9ac756c2005-05-19 08:52:17 +000085int allowed_lull = 0;
Wayne Davison876c9932006-01-28 00:13:55 +000086int prune_empty_dirs = 0;
Wayne Davisonea5164d2003-03-30 23:00:42 +000087char *files_from = NULL;
88int filesfrom_fd = -1;
Wayne Davison305666b2005-03-01 01:15:57 +000089char *filesfrom_host = NULL;
Wayne Davisonea5164d2003-03-30 23:00:42 +000090int eol_nulls = 0;
Wayne Davison8f14cc42005-11-12 19:53:17 +000091int human_readable = 0;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +000092int recurse = 0;
Wayne Davisonb6164932005-08-27 21:01:45 +000093int xfer_dirs = -1;
Wayne Davison1312d9f2002-08-01 00:37:01 +000094int am_daemon = 0;
95int daemon_over_rsh = 0;
Wayne Davisona5c11132004-02-09 17:45:22 +000096int do_stats = 0;
97int do_progress = 0;
98int keep_partial = 0;
99int safe_symlinks = 0;
100int copy_unsafe_links = 0;
101int size_only = 0;
Wayne Davison9fb08442004-11-17 19:29:20 +0000102int daemon_bwlimit = 0;
Wayne Davisona5c11132004-02-09 17:45:22 +0000103int bwlimit = 0;
Wayne Davisonc4ed1482005-02-14 02:41:15 +0000104int fuzzy_basis = 0;
Wayne Davison3c74c3a2004-05-27 21:51:53 +0000105size_t bwlimit_writemax = 0;
Wayne Davisone90aab42005-09-29 18:07:55 +0000106int ignore_existing = 0;
107int ignore_non_existing = 0;
Wayne Davison07c6ae72005-02-20 01:04:40 +0000108int need_messages_from_generator = 0;
Wayne Davisona5c11132004-02-09 17:45:22 +0000109int max_delete = 0;
Wayne Davison7d5acf12004-11-11 01:45:25 +0000110OFF_T max_size = 0;
Wayne Davison74de13d2005-10-14 20:15:18 +0000111OFF_T min_size = 0;
Wayne Davisona5c11132004-02-09 17:45:22 +0000112int ignore_errors = 0;
113int modify_window = 0;
114int blocking_io = -1;
Wayne Davison2289bf62004-02-09 18:32:54 +0000115int checksum_seed = 0;
Wayne Davisona3221d22004-07-16 20:06:24 +0000116int inplace = 0;
Wayne Davisonf06e7082005-01-27 22:46:14 +0000117int delay_updates = 0;
Wayne Davisona06b4192005-01-01 21:08:14 +0000118long block_size = 0; /* "long" because popt can't set an int32. */
Andrew Tridgell7a6421f1998-05-10 07:25:40 +0000119
Martin Poolb35d0d82002-04-08 04:10:20 +0000120
Martin Pool13e29992001-12-18 05:54:57 +0000121/** Network address family. **/
Wayne Davison4f5b0752005-02-14 00:53:43 +0000122#ifdef INET6
Martin Pool13e29992001-12-18 05:54:57 +0000123int default_af_hint = 0; /* Any protocol */
David Dykstra6ab6d4b2001-12-14 18:25:51 +0000124#else
Martin Pool13e29992001-12-18 05:54:57 +0000125int default_af_hint = AF_INET; /* Must use IPv4 */
David Dykstra6ab6d4b2001-12-14 18:25:51 +0000126#endif
Martin Pool06963d02001-11-23 07:35:49 +0000127
Martin Pool13e29992001-12-18 05:54:57 +0000128/** Do not go into the background when run as --daemon. Good
129 * for debugging and required for running as a service on W32,
130 * or under Unix process-monitors. **/
Wayne Davison1f35bab2005-02-21 00:31:31 +0000131int no_detach
132#if defined _WIN32 || defined __WIN32__
133 = 1;
134#else
135 = 0;
136#endif
Martin Pool13e29992001-12-18 05:54:57 +0000137
David Dykstra088aac82002-02-06 21:20:48 +0000138int write_batch = 0;
139int read_batch = 0;
Wayne Davisond175d7e2003-08-01 07:58:44 +0000140int backup_dir_len = 0;
141int backup_suffix_len;
Wayne Davisone0391f82004-02-11 04:30:41 +0000142unsigned int backup_dir_remainder;
Martin Pool6902ed12001-08-14 02:04:47 +0000143
Wayne Davisond175d7e2003-08-01 07:58:44 +0000144char *backup_suffix = NULL;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +0000145char *tmpdir = NULL;
Wayne Davisona7260c42004-07-29 16:06:38 +0000146char *partial_dir = NULL;
Wayne Davisone012f852004-11-27 17:52:51 +0000147char *basis_dir[MAX_BASIS_DIRS+1];
David Dykstra30e8c8e2002-08-30 23:27:26 +0000148char *config_file = NULL;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +0000149char *shell_cmd = NULL;
Wayne Davison87c0f9d2006-05-09 18:31:03 +0000150char *logfile_name = NULL;
151char *logfile_format = NULL;
Wayne Davisonb3e4e7e2006-05-29 22:56:45 +0000152char *stdout_format = NULL;
Andrew Tridgell65575e91999-01-08 10:32:56 +0000153char *password_file = NULL;
David Dykstra41bd28f2001-06-12 19:33:41 +0000154char *rsync_path = RSYNC_PATH;
Andrew Tridgell66203a92000-01-24 04:58:53 +0000155char *backup_dir = NULL;
Wayne Davisone0391f82004-02-11 04:30:41 +0000156char backup_dir_buf[MAXPATHLEN];
Wayne Davison831f06a2006-01-26 12:31:24 +0000157char *sockopts = NULL;
Wayne Davison0c56b1a2004-11-27 18:24:12 +0000158int rsync_port = 0;
Wayne Davisondfd7d542005-01-15 20:54:25 +0000159int compare_dest = 0;
Wayne Davison1de3e992005-03-11 17:35:59 +0000160int copy_dest = 0;
David Dykstra59c95e42002-08-29 14:44:55 +0000161int link_dest = 0;
Wayne Davisonce0b3842005-01-15 21:12:58 +0000162int basis_dir_cnt = 0;
Wayne Davisonf9a9f542005-03-09 18:53:53 +0000163char *dest_option = NULL;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +0000164
165int verbose = 0;
David Dykstrab86f0ce1999-02-09 17:25:35 +0000166int quiet = 0;
Wayne Davisone7651882005-02-16 08:10:31 +0000167int log_before_transfer = 0;
Wayne Davisonb3e4e7e2006-05-29 22:56:45 +0000168int stdout_format_has_i = 0;
169int stdout_format_has_o_or_i = 0;
Wayne Davison87c0f9d2006-05-09 18:31:03 +0000170int logfile_format_has_i = 0;
Wayne Davison87c0f9d2006-05-09 18:31:03 +0000171int logfile_format_has_o_or_i = 0;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +0000172int always_checksum = 0;
Andrew Tridgellf7632fc1998-11-02 00:52:01 +0000173int list_only = 0;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +0000174
Wayne Davison9b3318b2004-07-15 16:27:02 +0000175#define MAX_BATCH_NAME_LEN 256 /* Must be less than MAXPATHLEN-13 */
176char *batch_name = NULL;
Martin Pool6902ed12001-08-14 02:04:47 +0000177
Wayne Davisondd32e2c2005-11-07 04:28:35 +0000178struct chmod_mode_struct *chmod_modes = NULL;
179
Wayne Davisone1add892004-02-01 17:29:41 +0000180static int daemon_opt; /* sets am_daemon after option error-reporting */
Wayne Davisonaa4d3b42005-01-25 00:52:56 +0000181static int F_option_cnt = 0;
Andrew Tridgell5b56cc12000-09-06 02:12:13 +0000182static int modify_window_set;
Wayne Davison624d6be2005-03-31 00:21:15 +0000183static int itemize_changes = 0;
Wayne Davison854a1aa2005-10-26 16:47:15 +0000184static int refused_delete, refused_archive_part, refused_compress;
Wayne Davison3296f912005-02-15 21:15:58 +0000185static int refused_partial, refused_progress, refused_delete_before;
Wayne Davisona0157882005-07-28 01:46:09 +0000186static int refused_inplace;
Wayne Davison74de13d2005-10-14 20:15:18 +0000187static char *max_size_arg, *min_size_arg;
Wayne Davison77860ba2006-01-29 19:17:13 +0000188static char tmp_partialdir[] = ".~tmp~";
Andrew Tridgell5b56cc12000-09-06 02:12:13 +0000189
Martin Pool06963d02001-11-23 07:35:49 +0000190/** Local address to bind. As a character string because it's
Wayne Davisonfdf57ed2004-06-20 19:47:05 +0000191 * interpreted by the IPv6 layer: should be a numeric IP4 or IP6
Martin Pool06963d02001-11-23 07:35:49 +0000192 * address, or a hostname. **/
193char *bind_address;
Andrew Tridgell5c9730a1999-10-31 03:21:02 +0000194
Martin Pool7a24c342000-11-09 09:05:14 +0000195
Martin Pool27a12342001-12-05 13:45:51 +0000196static void print_rsync_version(enum logcode f)
Martin Pool7a24c342000-11-09 09:05:14 +0000197{
Wayne Davisondfa32482003-03-21 18:58:50 +0000198 char const *got_socketpair = "no ";
Wayne Davisona3221d22004-07-16 20:06:24 +0000199 char const *have_inplace = "no ";
Wayne Davisondfa32482003-03-21 18:58:50 +0000200 char const *hardlinks = "no ";
201 char const *links = "no ";
Martin Poola3584492001-11-24 04:57:41 +0000202 char const *ipv6 = "no ";
Martin Pool736a6a22002-01-11 07:15:16 +0000203 STRUCT_STAT *dumstat;
Martin Pool0c80cd82000-11-10 03:41:47 +0000204
Wayne Davison4f5b0752005-02-14 00:53:43 +0000205#ifdef HAVE_SOCKETPAIR
Wayne Davisondfa32482003-03-21 18:58:50 +0000206 got_socketpair = "";
Martin Pool0c80cd82000-11-10 03:41:47 +0000207#endif
Martin Pool2855f612001-02-23 01:02:31 +0000208
Wayne Davison4f5b0752005-02-14 00:53:43 +0000209#ifdef HAVE_FTRUNCATE
Wayne Davisona3221d22004-07-16 20:06:24 +0000210 have_inplace = "";
211#endif
212
Wayne Davison4f5b0752005-02-14 00:53:43 +0000213#ifdef SUPPORT_HARD_LINKS
Wayne Davisondfa32482003-03-21 18:58:50 +0000214 hardlinks = "";
Martin Pool2855f612001-02-23 01:02:31 +0000215#endif
216
Wayne Davison4f5b0752005-02-14 00:53:43 +0000217#ifdef SUPPORT_LINKS
Wayne Davisondfa32482003-03-21 18:58:50 +0000218 links = "";
Martin Pool2855f612001-02-23 01:02:31 +0000219#endif
220
Wayne Davison4f5b0752005-02-14 00:53:43 +0000221#ifdef INET6
Martin Poola3584492001-11-24 04:57:41 +0000222 ipv6 = "";
Wayne Davisondfa32482003-03-21 18:58:50 +0000223#endif
Martin Poola3584492001-11-24 04:57:41 +0000224
Wayne Davisondfa32482003-03-21 18:58:50 +0000225 rprintf(f, "%s version %s protocol version %d\n",
226 RSYNC_NAME, RSYNC_VERSION, PROTOCOL_VERSION);
Wayne Davisonccb8f572006-01-23 18:48:12 +0000227 rprintf(f, "Copyright (C) 1996-2006 by Andrew Tridgell, Wayne Davison, and others.\n");
Martin Pool3b4b1982001-08-14 02:08:17 +0000228 rprintf(f, "<http://rsync.samba.org/>\n");
Wayne Davisondfa32482003-03-21 18:58:50 +0000229 rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, "
Wayne Davison29433532006-02-02 11:40:32 +0000230 "%shard links, %ssymlinks, batchfiles,\n",
Wayne Davisona5c11132004-02-09 17:45:22 +0000231 (int) (sizeof (OFF_T) * 8),
Wayne Davisondfa32482003-03-21 18:58:50 +0000232 got_socketpair, hardlinks, links);
Martin Pool2855f612001-02-23 01:02:31 +0000233
Martin Pool736a6a22002-01-11 07:15:16 +0000234 /* Note that this field may not have type ino_t. It depends
235 * on the complicated interaction between largefile feature
236 * macros. */
Wayne Davison29433532006-02-02 11:40:32 +0000237 rprintf(f, " %sinplace, %sIPv6, "
238 "%d-bit system inums, %d-bit internal inums\n",
Wayne Davisona3221d22004-07-16 20:06:24 +0000239 have_inplace, ipv6,
Wayne Davisona5c11132004-02-09 17:45:22 +0000240 (int) (sizeof dumstat->st_ino * 8),
Wayne Davison14908122005-01-20 22:42:47 +0000241 (int) (sizeof (int64) * 8));
Martin Poolfc0302c2002-04-08 07:36:05 +0000242#ifdef MAINTAINER_MODE
Wayne Davison29433532006-02-02 11:40:32 +0000243 rprintf(f, "Panic Action: \"%s\"\n", get_panic_action());
Martin Poolfc0302c2002-04-08 07:36:05 +0000244#endif
Martin Pool736a6a22002-01-11 07:15:16 +0000245
Wayne Davison031fa9a2005-01-28 06:46:33 +0000246#if SIZEOF_INT64 < 8
247 rprintf(f, "WARNING: no 64-bit integers on this platform!\n");
Martin Pool7a24c342000-11-09 09:05:14 +0000248#endif
Wayne Davisonc561eda2005-01-28 06:51:44 +0000249 if (sizeof (int64) != SIZEOF_INT64) {
250 rprintf(f,
251 "WARNING: size mismatch in SIZEOF_INT64 define (%d != %d)\n",
252 (int) SIZEOF_INT64, (int) sizeof (int64));
253 }
Martin Pool7b329a22002-03-19 05:00:05 +0000254
Wayne Davisonb64ee912006-06-01 08:04:47 +0000255 rprintf(f,"\n");
256 rprintf(f,"rsync comes with ABSOLUTELY NO WARRANTY. This is free software, and you\n");
Wayne Davison6ab423a2006-01-17 04:26:12 +0000257 rprintf(f,"are welcome to redistribute it under certain conditions. See the GNU\n");
258 rprintf(f,"General Public Licence for details.\n");
Martin Pool7a24c342000-11-09 09:05:14 +0000259}
260
261
Andrew Tridgell0f3203c2000-01-29 02:49:03 +0000262void usage(enum logcode F)
Andrew Tridgell7a6421f1998-05-10 07:25:40 +0000263{
Martin Pool2855f612001-02-23 01:02:31 +0000264 print_rsync_version(F);
Andrew Tridgell704f9081998-06-18 09:31:42 +0000265
Wayne Davisonb64ee912006-06-01 08:04:47 +0000266 rprintf(F,"\n");
267 rprintf(F,"rsync is a file transfer program capable of efficient remote update\n");
Wayne Davison6ab423a2006-01-17 04:26:12 +0000268 rprintf(F,"via a fast differencing algorithm.\n");
Andrew Tridgell704f9081998-06-18 09:31:42 +0000269
Wayne Davisonb64ee912006-06-01 08:04:47 +0000270 rprintf(F,"\n");
271 rprintf(F,"Usage: rsync [OPTION]... SRC [SRC]... DEST\n");
Wayne Davison868676d2005-09-21 22:39:49 +0000272 rprintf(F," or rsync [OPTION]... SRC [SRC]... [USER@]HOST:DEST\n");
David Dykstra9ef53901999-02-10 19:33:05 +0000273 rprintf(F," or rsync [OPTION]... SRC [SRC]... [USER@]HOST::DEST\n");
Wayne Davisoneaa4c152002-08-01 17:55:11 +0000274 rprintf(F," or rsync [OPTION]... SRC [SRC]... rsync://[USER@]HOST[:PORT]/DEST\n");
Wayne Davison868676d2005-09-21 22:39:49 +0000275 rprintf(F," or rsync [OPTION]... [USER@]HOST:SRC [DEST]\n");
276 rprintf(F," or rsync [OPTION]... [USER@]HOST::SRC [DEST]\n");
277 rprintf(F," or rsync [OPTION]... rsync://[USER@]HOST[:PORT]/SRC [DEST]\n");
Wayne Davison08d82b82005-09-13 01:02:54 +0000278 rprintf(F,"The ':' usages connect via remote shell, while '::' & 'rsync://' usages connect\n");
279 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 +0000280 rprintf(F,"\n");
281 rprintf(F,"Options\n");
Andrew Tridgell704f9081998-06-18 09:31:42 +0000282 rprintf(F," -v, --verbose increase verbosity\n");
Wayne Davisonb3708ac2005-01-28 09:55:18 +0000283 rprintf(F," -q, --quiet suppress non-error messages\n");
284 rprintf(F," -c, --checksum skip based on checksum, not mod-time & size\n");
285 rprintf(F," -a, --archive archive mode; same as -rlptgoD (no -H)\n");
Wayne Davison8938d672005-11-15 07:05:55 +0000286 rprintf(F," --no-OPTION turn off an implied OPTION (e.g. --no-D)\n");
Andrew Tridgell704f9081998-06-18 09:31:42 +0000287 rprintf(F," -r, --recursive recurse into directories\n");
288 rprintf(F," -R, --relative use relative path names\n");
Wayne Davison11bfaf62005-08-27 20:01:45 +0000289 rprintf(F," --no-implied-dirs don't send implied dirs with --relative\n");
Wayne Davison68391402003-12-30 18:16:25 +0000290 rprintf(F," -b, --backup make backups (see --suffix & --backup-dir)\n");
Wayne Davisonb3708ac2005-01-28 09:55:18 +0000291 rprintf(F," --backup-dir=DIR make backups into hierarchy based in DIR\n");
292 rprintf(F," --suffix=SUFFIX set backup suffix (default %s w/o --backup-dir)\n",BACKUP_SUFFIX);
293 rprintf(F," -u, --update skip files that are newer on the receiver\n");
Wayne Davison4ce838e2005-01-17 23:11:18 +0000294 rprintf(F," --inplace update destination files in-place (SEE MAN PAGE)\n");
Wayne Davisona0157882005-07-28 01:46:09 +0000295 rprintf(F," --append append data onto shorter files\n");
Wayne Davison65e4cda2005-01-24 00:17:39 +0000296 rprintf(F," -d, --dirs transfer directories without recursing\n");
Martin Pool13e29992001-12-18 05:54:57 +0000297 rprintf(F," -l, --links copy symlinks as symlinks\n");
Wayne Davisonb3708ac2005-01-28 09:55:18 +0000298 rprintf(F," -L, --copy-links transform symlink into referent file/dir\n");
299 rprintf(F," --copy-unsafe-links only \"unsafe\" symlinks are transformed\n");
300 rprintf(F," --safe-links ignore symlinks that point outside the source tree\n");
Wayne Davison2dbf36e2006-02-24 17:54:30 +0000301 rprintf(F," -k, --copy-dirlinks transform symlink to a dir into referent dir\n");
Wayne Davison65e4cda2005-01-24 00:17:39 +0000302 rprintf(F," -K, --keep-dirlinks treat symlinked dir on receiver as dir\n");
Wayne Davison2dbf36e2006-02-24 17:54:30 +0000303 rprintf(F," -H, --hard-links preserve hard links\n");
Andrew Tridgell704f9081998-06-18 09:31:42 +0000304 rprintf(F," -p, --perms preserve permissions\n");
Wayne Davison344f9ba2006-01-31 02:29:58 +0000305 rprintf(F," -E, --executability preserve the file's executability\n");
Wayne Davisondfe1ed52006-10-09 00:55:04 +0000306 rprintf(F," --chmod=CHMOD affect file and/or directory permissions\n");
Wayne Davisondef97ff2006-01-26 11:10:32 +0000307 rprintf(F," -o, --owner preserve owner (super-user only)\n");
Andrew Tridgell704f9081998-06-18 09:31:42 +0000308 rprintf(F," -g, --group preserve group\n");
Wayne Davisondef97ff2006-01-26 11:10:32 +0000309 rprintf(F," --devices preserve device files (super-user only)\n");
Wayne Davisonb5c6a6a2006-01-26 10:38:58 +0000310 rprintf(F," --specials preserve special files\n");
311 rprintf(F," -D same as --devices --specials\n");
Wayne Davisondfa32482003-03-21 18:58:50 +0000312 rprintf(F," -t, --times preserve times\n");
Wayne Davison20fb7b92005-01-24 00:51:32 +0000313 rprintf(F," -O, --omit-dir-times omit directories when preserving times\n");
Wayne Davisondef97ff2006-01-26 11:10:32 +0000314 rprintf(F," --super receiver attempts super-user activities\n");
Andrew Tridgell704f9081998-06-18 09:31:42 +0000315 rprintf(F," -S, --sparse handle sparse files efficiently\n");
316 rprintf(F," -n, --dry-run show what would have been transferred\n");
Wayne Davison98bf61c2005-02-14 19:09:30 +0000317 rprintf(F," -W, --whole-file copy files whole (without rsync algorithm)\n");
Andrew Tridgell704f9081998-06-18 09:31:42 +0000318 rprintf(F," -x, --one-file-system don't cross filesystem boundaries\n");
Wayne Davison9cd339e2004-08-03 08:05:20 +0000319 rprintf(F," -B, --block-size=SIZE force a fixed checksum block-size\n");
Wayne Davisonb3708ac2005-01-28 09:55:18 +0000320 rprintf(F," -e, --rsh=COMMAND specify the remote shell to use\n");
Wayne Davison05ee4862005-03-02 09:17:42 +0000321 rprintf(F," --rsync-path=PROGRAM specify the rsync to run on the remote machine\n");
Wayne Davisonfcecb702006-05-05 06:16:22 +0000322 rprintf(F," --existing skip creating new files on receiver\n");
323 rprintf(F," --ignore-existing skip updating files that already exist on receiver\n");
Wayne Davison47c11972006-06-30 15:52:52 +0000324 rprintf(F," --remove-source-files sender removes synchronized files (non-dirs)\n");
Wayne Davison3359acb2005-01-25 03:08:58 +0000325 rprintf(F," --del an alias for --delete-during\n");
Wayne Davisonfcecb702006-05-05 06:16:22 +0000326 rprintf(F," --delete delete extraneous files from destination dirs\n");
Wayne Davisonc6eb7fa2005-01-28 07:39:09 +0000327 rprintf(F," --delete-before receiver deletes before transfer (default)\n");
Wayne Davison3359acb2005-01-25 03:08:58 +0000328 rprintf(F," --delete-during receiver deletes during transfer, not before\n");
329 rprintf(F," --delete-after receiver deletes after transfer, not before\n");
Wayne Davisonfcecb702006-05-05 06:16:22 +0000330 rprintf(F," --delete-excluded also delete excluded files from destination dirs\n");
Wayne Davisondb2b5cb2004-01-23 09:32:50 +0000331 rprintf(F," --ignore-errors delete even if there are I/O errors\n");
Wayne Davison51d48392005-01-22 22:48:34 +0000332 rprintf(F," --force force deletion of directories even if not empty\n");
Andrew Tridgell0b73ca12000-01-23 11:43:04 +0000333 rprintf(F," --max-delete=NUM don't delete more than NUM files\n");
Wayne Davison7d5acf12004-11-11 01:45:25 +0000334 rprintf(F," --max-size=SIZE don't transfer any file larger than SIZE\n");
Wayne Davison74de13d2005-10-14 20:15:18 +0000335 rprintf(F," --min-size=SIZE don't transfer any file smaller than SIZE\n");
Andrew Tridgellc95da961998-07-01 03:36:03 +0000336 rprintf(F," --partial keep partially transferred files\n");
Wayne Davisona7260c42004-07-29 16:06:38 +0000337 rprintf(F," --partial-dir=DIR put a partially transferred file into DIR\n");
Wayne Davisonb3708ac2005-01-28 09:55:18 +0000338 rprintf(F," --delay-updates put all updated files into place at transfer's end\n");
Wayne Davison876c9932006-01-28 00:13:55 +0000339 rprintf(F," -m, --prune-empty-dirs prune empty directory chains from the file-list\n");
Andrew Tridgell704f9081998-06-18 09:31:42 +0000340 rprintf(F," --numeric-ids don't map uid/gid values by user/group name\n");
Wayne Davisondb2b5cb2004-01-23 09:32:50 +0000341 rprintf(F," --timeout=TIME set I/O timeout in seconds\n");
Wayne Davisonb3708ac2005-01-28 09:55:18 +0000342 rprintf(F," -I, --ignore-times don't skip files that match in size and mod-time\n");
343 rprintf(F," --size-only skip files that match in size\n");
344 rprintf(F," --modify-window=NUM compare mod-times with reduced accuracy\n");
Wayne Davison4db88e52004-07-22 15:43:28 +0000345 rprintf(F," -T, --temp-dir=DIR create temporary files in directory DIR\n");
Wayne Davisonc4ed1482005-02-14 02:41:15 +0000346 rprintf(F," -y, --fuzzy find similar file for basis if no dest file\n");
David Dykstra375a4551998-10-26 21:42:38 +0000347 rprintf(F," --compare-dest=DIR also compare destination files relative to DIR\n");
Wayne Davison1de3e992005-03-11 17:35:59 +0000348 rprintf(F," --copy-dest=DIR ... and include copies of unchanged files\n");
Wayne Davisone012f852004-11-27 17:52:51 +0000349 rprintf(F," --link-dest=DIR hardlink to files in DIR when unchanged\n");
Wayne Davisonf9249462005-02-12 22:22:14 +0000350 rprintf(F," -z, --compress compress file data during the transfer\n");
Wayne Davison854a1aa2005-10-26 16:47:15 +0000351 rprintf(F," --compress-level=NUM explicitly set compression level\n");
Wayne Davisonb3708ac2005-01-28 09:55:18 +0000352 rprintf(F," -C, --cvs-exclude auto-ignore files the same way CVS does\n");
Wayne Davisonaa4d3b42005-01-25 00:52:56 +0000353 rprintf(F," -f, --filter=RULE add a file-filtering RULE\n");
Wayne Davison9c71f562005-02-13 05:44:29 +0000354 rprintf(F," -F same as --filter='dir-merge /.rsync-filter'\n");
Wayne Davisonaa4d3b42005-01-25 00:52:56 +0000355 rprintf(F," repeated: --filter='- .rsync-filter'\n");
David Dykstra2acf81e1998-11-03 21:17:40 +0000356 rprintf(F," --exclude=PATTERN exclude files matching PATTERN\n");
Wayne Davisonb3708ac2005-01-28 09:55:18 +0000357 rprintf(F," --exclude-from=FILE read exclude patterns from FILE\n");
David Dykstra2acf81e1998-11-03 21:17:40 +0000358 rprintf(F," --include=PATTERN don't exclude files matching PATTERN\n");
Wayne Davisonb3708ac2005-01-28 09:55:18 +0000359 rprintf(F," --include-from=FILE read include patterns from FILE\n");
360 rprintf(F," --files-from=FILE read list of source-file names from FILE\n");
Wayne Davison72316022005-05-02 17:23:08 +0000361 rprintf(F," -0, --from0 all *-from/filter files are delimited by 0s\n");
Wayne Davisonb4ef0bc2005-04-05 05:59:49 +0000362 rprintf(F," --address=ADDRESS bind address for outgoing socket to daemon\n");
Wayne Davisonb4713292004-12-08 17:29:54 +0000363 rprintf(F," --port=PORT specify double-colon alternate port number\n");
Wayne Davison831f06a2006-01-26 12:31:24 +0000364 rprintf(F," --sockopts=OPTIONS specify custom TCP options\n");
Wayne Davisondb2b5cb2004-01-23 09:32:50 +0000365 rprintf(F," --blocking-io use blocking I/O for the remote shell\n");
Wayne Davisonb3708ac2005-01-28 09:55:18 +0000366 rprintf(F," --stats give some file-transfer stats\n");
Wayne Davisona6a27602006-02-06 18:51:25 +0000367 rprintf(F," -8, --8-bit-output leave high-bit chars unescaped in output\n");
Wayne Davison05724c02005-11-15 06:35:27 +0000368 rprintf(F," -h, --human-readable output numbers in a human-readable format\n");
Wayne Davisondfa32482003-03-21 18:58:50 +0000369 rprintf(F," --progress show progress during transfer\n");
Wayne Davisonb3708ac2005-01-28 09:55:18 +0000370 rprintf(F," -P same as --partial --progress\n");
Wayne Davisonb78296c2005-02-15 07:41:13 +0000371 rprintf(F," -i, --itemize-changes output a change-summary for all updates\n");
Wayne Davisonb3e4e7e2006-05-29 22:56:45 +0000372 rprintf(F," --out-format=FORMAT output updates using the specified FORMAT\n");
373 rprintf(F," --log-file=FILE log what we're doing to the specified FILE\n");
374 rprintf(F," --log-file-format=FMT log updates using the specified FMT\n");
Wayne Davisonb3708ac2005-01-28 09:55:18 +0000375 rprintf(F," --password-file=FILE read password from FILE\n");
Wayne Davison65e4cda2005-01-24 00:17:39 +0000376 rprintf(F," --list-only list the files instead of copying them\n");
Wayne Davisonb3708ac2005-01-28 09:55:18 +0000377 rprintf(F," --bwlimit=KBPS limit I/O bandwidth; KBytes per second\n");
378 rprintf(F," --write-batch=FILE write a batched update to FILE\n");
Wayne Davison11e758a2005-04-09 18:59:47 +0000379 rprintf(F," --only-write-batch=FILE like --write-batch but w/o updating destination\n");
Wayne Davisonb3708ac2005-01-28 09:55:18 +0000380 rprintf(F," --read-batch=FILE read a batched update from FILE\n");
Wayne Davisonda9f5922005-03-28 20:40:25 +0000381 rprintf(F," --protocol=NUM force an older protocol version to be used\n");
Wayne Davison4f5b0752005-02-14 00:53:43 +0000382#ifdef INET6
Wayne Davison4db88e52004-07-22 15:43:28 +0000383 rprintf(F," -4, --ipv4 prefer IPv4\n");
384 rprintf(F," -6, --ipv6 prefer IPv6\n");
Martin Pool06963d02001-11-23 07:35:49 +0000385#endif
Wayne Davison4a34c6f2005-05-03 16:46:49 +0000386 rprintf(F," --version print version number\n");
Wayne Davison375d8f92006-02-11 00:01:22 +0000387 rprintf(F,"(-h) --help show this help (-h works with no other options)\n");
Andrew Tridgell7a6421f1998-05-10 07:25:40 +0000388
Wayne Davisonb64ee912006-06-01 08:04:47 +0000389 rprintf(F,"\n");
390 rprintf(F,"Use \"rsync --daemon --help\" to see the daemon-mode command-line options.\n");
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000391 rprintf(F,"Please see the rsync(1) and rsyncd.conf(5) man pages for full documentation.\n");
Martin Pool2855f612001-02-23 01:02:31 +0000392 rprintf(F,"See http://rsync.samba.org/ for updates, bug reports, and answers\n");
Andrew Tridgell7a6421f1998-05-10 07:25:40 +0000393}
394
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000395enum {OPT_VERSION = 1000, OPT_DAEMON, OPT_SENDER, OPT_EXCLUDE, OPT_EXCLUDE_FROM,
Wayne Davison05724c02005-11-15 06:35:27 +0000396 OPT_FILTER, OPT_COMPARE_DEST, OPT_COPY_DEST, OPT_LINK_DEST, OPT_HELP,
Wayne Davisone16adcd2006-01-21 09:14:42 +0000397 OPT_INCLUDE, OPT_INCLUDE_FROM, OPT_MODIFY_WINDOW, OPT_MIN_SIZE, OPT_CHMOD,
Wayne Davison9ac756c2005-05-19 08:52:17 +0000398 OPT_READ_BATCH, OPT_WRITE_BATCH, OPT_ONLY_WRITE_BATCH, OPT_MAX_SIZE,
Wayne Davisonb5c6a6a2006-01-26 10:38:58 +0000399 OPT_NO_D,
Wayne Davison0ccffd72006-01-21 20:15:49 +0000400 OPT_SERVER, OPT_REFUSED_BASE = 9000};
Andrew Tridgell7a6421f1998-05-10 07:25:40 +0000401
Martin Pool2855f612001-02-23 01:02:31 +0000402static struct poptOption long_options[] = {
403 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
Wayne Davison05724c02005-11-15 06:35:27 +0000404 {"help", 0, POPT_ARG_NONE, 0, OPT_HELP, 0, 0 },
Wayne Davison8db7cc22004-10-11 10:43:25 +0000405 {"version", 0, POPT_ARG_NONE, 0, OPT_VERSION, 0, 0},
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000406 {"verbose", 'v', POPT_ARG_NONE, 0, 'v', 0, 0 },
Wayne Davisonb6164932005-08-27 21:01:45 +0000407 {"no-verbose", 0, POPT_ARG_VAL, &verbose, 0, 0, 0 },
Wayne Davison4afcb702005-08-28 00:43:51 +0000408 {"no-v", 0, POPT_ARG_VAL, &verbose, 0, 0, 0 },
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000409 {"quiet", 'q', POPT_ARG_NONE, 0, 'q', 0, 0 },
410 {"stats", 0, POPT_ARG_NONE, &do_stats, 0, 0, 0 },
Wayne Davison3ca9e5d2006-02-08 16:52:25 +0000411 {"human-readable", 'h', POPT_ARG_NONE, 0, 'h', 0, 0},
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000412 {"dry-run", 'n', POPT_ARG_NONE, &dry_run, 0, 0, 0 },
Wayne Davisonb6164932005-08-27 21:01:45 +0000413 {"archive", 'a', POPT_ARG_NONE, 0, 'a', 0, 0 },
414 {"recursive", 'r', POPT_ARG_VAL, &recurse, 2, 0, 0 },
415 {"no-recursive", 0, POPT_ARG_VAL, &recurse, 0, 0, 0 },
416 {"no-r", 0, POPT_ARG_VAL, &recurse, 0, 0, 0 },
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000417 {"dirs", 'd', POPT_ARG_VAL, &xfer_dirs, 2, 0, 0 },
Wayne Davisonb6164932005-08-27 21:01:45 +0000418 {"no-dirs", 0, POPT_ARG_VAL, &xfer_dirs, 0, 0, 0 },
419 {"no-d", 0, POPT_ARG_VAL, &xfer_dirs, 0, 0, 0 },
420 {"perms", 'p', POPT_ARG_VAL, &preserve_perms, 1, 0, 0 },
421 {"no-perms", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
422 {"no-p", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
Wayne Davison344f9ba2006-01-31 02:29:58 +0000423 {"executability", 'E', POPT_ARG_NONE, &preserve_executability, 0, 0, 0 },
Wayne Davisonb6164932005-08-27 21:01:45 +0000424 {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
Wayne Davisonb6164932005-08-27 21:01:45 +0000425 {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
426 {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
Wayne Davison38b91702005-08-27 21:12:44 +0000427 {"omit-dir-times", 'O', POPT_ARG_VAL, &omit_dir_times, 2, 0, 0 },
428 {"modify-window", 0, POPT_ARG_INT, &modify_window, OPT_MODIFY_WINDOW, 0, 0 },
Wayne Davisondef97ff2006-01-26 11:10:32 +0000429 {"super", 0, POPT_ARG_VAL, &am_root, 2, 0, 0 },
430 {"no-super", 0, POPT_ARG_VAL, &am_root, 0, 0, 0 },
Wayne Davisonb6164932005-08-27 21:01:45 +0000431 {"owner", 'o', POPT_ARG_VAL, &preserve_uid, 1, 0, 0 },
432 {"no-owner", 0, POPT_ARG_VAL, &preserve_uid, 0, 0, 0 },
433 {"no-o", 0, POPT_ARG_VAL, &preserve_uid, 0, 0, 0 },
434 {"group", 'g', POPT_ARG_VAL, &preserve_gid, 1, 0, 0 },
435 {"no-group", 0, POPT_ARG_VAL, &preserve_gid, 0, 0, 0 },
436 {"no-g", 0, POPT_ARG_VAL, &preserve_gid, 0, 0, 0 },
Wayne Davisonb5c6a6a2006-01-26 10:38:58 +0000437 {0, 'D', POPT_ARG_NONE, 0, 'D', 0, 0 },
438 {"no-D", 0, POPT_ARG_NONE, 0, OPT_NO_D, 0, 0 },
439 {"devices", 0, POPT_ARG_VAL, &preserve_devices, 1, 0, 0 },
Wayne Davisonb6164932005-08-27 21:01:45 +0000440 {"no-devices", 0, POPT_ARG_VAL, &preserve_devices, 0, 0, 0 },
Wayne Davisonb5c6a6a2006-01-26 10:38:58 +0000441 {"specials", 0, POPT_ARG_VAL, &preserve_specials, 1, 0, 0 },
442 {"no-specials", 0, POPT_ARG_VAL, &preserve_specials, 0, 0, 0 },
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000443 {"links", 'l', POPT_ARG_VAL, &preserve_links, 1, 0, 0 },
Wayne Davisonb6164932005-08-27 21:01:45 +0000444 {"no-links", 0, POPT_ARG_VAL, &preserve_links, 0, 0, 0 },
445 {"no-l", 0, POPT_ARG_VAL, &preserve_links, 0, 0, 0 },
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000446 {"copy-links", 'L', POPT_ARG_NONE, &copy_links, 0, 0, 0 },
447 {"copy-unsafe-links",0, POPT_ARG_NONE, &copy_unsafe_links, 0, 0, 0 },
448 {"safe-links", 0, POPT_ARG_NONE, &safe_symlinks, 0, 0, 0 },
Wayne Davison2dbf36e2006-02-24 17:54:30 +0000449 {"copy-dirlinks", 'k', POPT_ARG_NONE, &copy_dirlinks, 0, 0, 0 },
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000450 {"keep-dirlinks", 'K', POPT_ARG_NONE, &keep_dirlinks, 0, 0, 0 },
Wayne Davisonbeab3072006-02-27 23:35:18 +0000451 {"hard-links", 'H', POPT_ARG_VAL, &preserve_hard_links, 1, 0, 0 },
452 {"no-hard-links", 0, POPT_ARG_VAL, &preserve_hard_links, 0, 0, 0 },
453 {"no-H", 0, POPT_ARG_VAL, &preserve_hard_links, 0, 0, 0 },
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000454 {"relative", 'R', POPT_ARG_VAL, &relative_paths, 1, 0, 0 },
455 {"no-relative", 0, POPT_ARG_VAL, &relative_paths, 0, 0, 0 },
Wayne Davisonb6164932005-08-27 21:01:45 +0000456 {"no-R", 0, POPT_ARG_VAL, &relative_paths, 0, 0, 0 },
Wayne Davison2dbf36e2006-02-24 17:54:30 +0000457 {"implied-dirs", 0, POPT_ARG_VAL, &implied_dirs, 1, 0, 0 },
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000458 {"no-implied-dirs", 0, POPT_ARG_VAL, &implied_dirs, 0, 0, 0 },
Wayne Davisone16adcd2006-01-21 09:14:42 +0000459 {"chmod", 0, POPT_ARG_STRING, 0, OPT_CHMOD, 0, 0 },
Wayne Davisonafb6e942003-03-21 19:17:23 +0000460 {"ignore-times", 'I', POPT_ARG_NONE, &ignore_times, 0, 0, 0 },
461 {"size-only", 0, POPT_ARG_NONE, &size_only, 0, 0, 0 },
Wayne Davison243c9952006-01-21 00:36:15 +0000462 {"one-file-system", 'x', POPT_ARG_NONE, 0, 'x', 0, 0 },
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000463 {"update", 'u', POPT_ARG_NONE, &update_only, 0, 0, 0 },
Wayne Davisone90aab42005-09-29 18:07:55 +0000464 {"existing", 0, POPT_ARG_NONE, &ignore_non_existing, 0, 0, 0 },
Wayne Davisone90aab42005-09-29 18:07:55 +0000465 {"ignore-non-existing",0,POPT_ARG_NONE, &ignore_non_existing, 0, 0, 0 },
Wayne Davisond2da9152005-12-19 01:59:00 +0000466 {"ignore-existing", 0, POPT_ARG_NONE, &ignore_existing, 0, 0, 0 },
Wayne Davisonaeb213e2005-10-14 18:56:07 +0000467 {"max-size", 0, POPT_ARG_STRING, &max_size_arg, OPT_MAX_SIZE, 0, 0 },
Wayne Davison74de13d2005-10-14 20:15:18 +0000468 {"min-size", 0, POPT_ARG_STRING, &min_size_arg, OPT_MIN_SIZE, 0, 0 },
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000469 {"sparse", 'S', POPT_ARG_NONE, &sparse_files, 0, 0, 0 },
470 {"inplace", 0, POPT_ARG_NONE, &inplace, 0, 0, 0 },
471 {"append", 0, POPT_ARG_VAL, &append_mode, 1, 0, 0 },
Wayne Davison36719872005-02-11 10:42:55 +0000472 {"del", 0, POPT_ARG_NONE, &delete_during, 0, 0, 0 },
Wayne Davison3359acb2005-01-25 03:08:58 +0000473 {"delete", 0, POPT_ARG_NONE, &delete_mode, 0, 0, 0 },
Wayne Davisonc6eb7fa2005-01-28 07:39:09 +0000474 {"delete-before", 0, POPT_ARG_VAL, &delete_before, 2, 0, 0 },
Wayne Davison3359acb2005-01-25 03:08:58 +0000475 {"delete-during", 0, POPT_ARG_NONE, &delete_during, 0, 0, 0 },
Wayne Davison51d48392005-01-22 22:48:34 +0000476 {"delete-after", 0, POPT_ARG_NONE, &delete_after, 0, 0, 0 },
477 {"delete-excluded", 0, POPT_ARG_NONE, &delete_excluded, 0, 0, 0 },
Wayne Davison47c11972006-06-30 15:52:52 +0000478 {"remove-sent-files",0, POPT_ARG_VAL, &remove_source_files, 2, 0, 0 }, /* deprecated */
479 {"remove-source-files",0,POPT_ARG_VAL, &remove_source_files, 1, 0, 0 },
Wayne Davisonafb6e942003-03-21 19:17:23 +0000480 {"force", 0, POPT_ARG_NONE, &force_delete, 0, 0, 0 },
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000481 {"ignore-errors", 0, POPT_ARG_NONE, &ignore_errors, 0, 0, 0 },
482 {"max-delete", 0, POPT_ARG_INT, &max_delete, 0, 0, 0 },
483 {0, 'F', POPT_ARG_NONE, 0, 'F', 0, 0 },
Wayne Davisonaa4d3b42005-01-25 00:52:56 +0000484 {"filter", 'f', POPT_ARG_STRING, 0, OPT_FILTER, 0, 0 },
Wayne Davison8db7cc22004-10-11 10:43:25 +0000485 {"exclude", 0, POPT_ARG_STRING, 0, OPT_EXCLUDE, 0, 0 },
486 {"include", 0, POPT_ARG_STRING, 0, OPT_INCLUDE, 0, 0 },
487 {"exclude-from", 0, POPT_ARG_STRING, 0, OPT_EXCLUDE_FROM, 0, 0 },
488 {"include-from", 0, POPT_ARG_STRING, 0, OPT_INCLUDE_FROM, 0, 0 },
Wayne Davisonafb6e942003-03-21 19:17:23 +0000489 {"cvs-exclude", 'C', POPT_ARG_NONE, &cvs_exclude, 0, 0, 0 },
Wayne Davison11bfaf62005-08-27 20:01:45 +0000490 {"whole-file", 'W', POPT_ARG_VAL, &whole_file, 1, 0, 0 },
491 {"no-whole-file", 0, POPT_ARG_VAL, &whole_file, 0, 0, 0 },
Wayne Davisonb6164932005-08-27 21:01:45 +0000492 {"no-W", 0, POPT_ARG_VAL, &whole_file, 0, 0, 0 },
Wayne Davisonafb6e942003-03-21 19:17:23 +0000493 {"checksum", 'c', POPT_ARG_NONE, &always_checksum, 0, 0, 0 },
Wayne Davisona06b4192005-01-01 21:08:14 +0000494 {"block-size", 'B', POPT_ARG_LONG, &block_size, 0, 0, 0 },
Wayne Davisone012f852004-11-27 17:52:51 +0000495 {"compare-dest", 0, POPT_ARG_STRING, 0, OPT_COMPARE_DEST, 0, 0 },
Wayne Davison1de3e992005-03-11 17:35:59 +0000496 {"copy-dest", 0, POPT_ARG_STRING, 0, OPT_COPY_DEST, 0, 0 },
Wayne Davisone012f852004-11-27 17:52:51 +0000497 {"link-dest", 0, POPT_ARG_STRING, 0, OPT_LINK_DEST, 0, 0 },
Wayne Davisonc4ed1482005-02-14 02:41:15 +0000498 {"fuzzy", 'y', POPT_ARG_NONE, &fuzzy_basis, 0, 0, 0 },
Wayne Davison854a1aa2005-10-26 16:47:15 +0000499 {"compress", 'z', POPT_ARG_NONE, 0, 'z', 0, 0 },
500 {"compress-level", 0, POPT_ARG_INT, &def_compress_level, 'z', 0, 0 },
Wayne Davison11bfaf62005-08-27 20:01:45 +0000501 {0, 'P', POPT_ARG_NONE, 0, 'P', 0, 0 },
Wayne Davisonb6164932005-08-27 21:01:45 +0000502 {"progress", 0, POPT_ARG_VAL, &do_progress, 1, 0, 0 },
503 {"no-progress", 0, POPT_ARG_VAL, &do_progress, 0, 0, 0 },
504 {"partial", 0, POPT_ARG_VAL, &keep_partial, 1, 0, 0 },
505 {"no-partial", 0, POPT_ARG_VAL, &keep_partial, 0, 0, 0 },
Wayne Davisona7260c42004-07-29 16:06:38 +0000506 {"partial-dir", 0, POPT_ARG_STRING, &partial_dir, 0, 0, 0 },
Wayne Davisonf06e7082005-01-27 22:46:14 +0000507 {"delay-updates", 0, POPT_ARG_NONE, &delay_updates, 0, 0, 0 },
Wayne Davison876c9932006-01-28 00:13:55 +0000508 {"prune-empty-dirs",'m', POPT_ARG_NONE, &prune_empty_dirs, 0, 0, 0 },
Wayne Davison87c0f9d2006-05-09 18:31:03 +0000509 {"log-file", 0, POPT_ARG_STRING, &logfile_name, 0, 0, 0 },
Wayne Davisonb3e4e7e2006-05-29 22:56:45 +0000510 {"log-file-format", 0, POPT_ARG_STRING, &logfile_format, 0, 0, 0 },
511 {"out-format", 0, POPT_ARG_STRING, &stdout_format, 0, 0, 0 },
512 {"log-format", 0, POPT_ARG_STRING, &stdout_format, 0, 0, 0 }, /* DEPRECATED */
Wayne Davison487094a2006-01-20 18:49:07 +0000513 {"itemize-changes", 'i', POPT_ARG_NONE, 0, 'i', 0, 0 },
Wayne Davisonafb6e942003-03-21 19:17:23 +0000514 {"bwlimit", 0, POPT_ARG_INT, &bwlimit, 0, 0, 0 },
Wayne Davison11bfaf62005-08-27 20:01:45 +0000515 {"backup", 'b', POPT_ARG_NONE, &make_backups, 0, 0, 0 },
Wayne Davisonafb6e942003-03-21 19:17:23 +0000516 {"backup-dir", 0, POPT_ARG_STRING, &backup_dir, 0, 0, 0 },
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000517 {"suffix", 0, POPT_ARG_STRING, &backup_suffix, 0, 0, 0 },
518 {"list-only", 0, POPT_ARG_VAL, &list_only, 2, 0, 0 },
Wayne Davison8db7cc22004-10-11 10:43:25 +0000519 {"read-batch", 0, POPT_ARG_STRING, &batch_name, OPT_READ_BATCH, 0, 0 },
520 {"write-batch", 0, POPT_ARG_STRING, &batch_name, OPT_WRITE_BATCH, 0, 0 },
Wayne Davison11e758a2005-04-09 18:59:47 +0000521 {"only-write-batch", 0, POPT_ARG_STRING, &batch_name, OPT_ONLY_WRITE_BATCH, 0, 0 },
Wayne Davisonea5164d2003-03-30 23:00:42 +0000522 {"files-from", 0, POPT_ARG_STRING, &files_from, 0, 0, 0 },
523 {"from0", '0', POPT_ARG_NONE, &eol_nulls, 0, 0, 0},
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000524 {"numeric-ids", 0, POPT_ARG_NONE, &numeric_ids, 0, 0, 0 },
525 {"timeout", 0, POPT_ARG_INT, &io_timeout, 0, 0, 0 },
526 {"rsh", 'e', POPT_ARG_STRING, &shell_cmd, 0, 0, 0 },
527 {"rsync-path", 0, POPT_ARG_STRING, &rsync_path, 0, 0, 0 },
528 {"temp-dir", 'T', POPT_ARG_STRING, &tmpdir, 0, 0, 0 },
Wayne Davison4f5b0752005-02-14 00:53:43 +0000529#ifdef INET6
Wayne Davison3dd22902004-05-06 21:08:01 +0000530 {"ipv4", '4', POPT_ARG_VAL, &default_af_hint, AF_INET, 0, 0 },
531 {"ipv6", '6', POPT_ARG_VAL, &default_af_hint, AF_INET6, 0, 0 },
Martin Pool06963d02001-11-23 07:35:49 +0000532#endif
Wayne Davisona6a27602006-02-06 18:51:25 +0000533 {"8-bit-output", '8', POPT_ARG_NONE, &allow_8bit_chars, 0, 0, 0 },
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000534 {"address", 0, POPT_ARG_STRING, &bind_address, 0, 0, 0 },
535 {"port", 0, POPT_ARG_INT, &rsync_port, 0, 0, 0 },
Wayne Davison831f06a2006-01-26 12:31:24 +0000536 {"sockopts", 0, POPT_ARG_STRING, &sockopts, 0, 0, 0 },
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000537 {"password-file", 0, POPT_ARG_STRING, &password_file, 0, 0, 0 },
538 {"blocking-io", 0, POPT_ARG_VAL, &blocking_io, 1, 0, 0 },
539 {"no-blocking-io", 0, POPT_ARG_VAL, &blocking_io, 0, 0, 0 },
540 {"protocol", 0, POPT_ARG_INT, &protocol_version, 0, 0, 0 },
541 {"checksum-seed", 0, POPT_ARG_INT, &checksum_seed, 0, 0, 0 },
Wayne Davison0ccffd72006-01-21 20:15:49 +0000542 {"server", 0, POPT_ARG_NONE, 0, OPT_SERVER, 0, 0 },
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000543 {"sender", 0, POPT_ARG_NONE, 0, OPT_SENDER, 0, 0 },
544 /* All the following options switch us into daemon-mode option-parsing. */
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000545 {"config", 0, POPT_ARG_STRING, 0, OPT_DAEMON, 0, 0 },
546 {"daemon", 0, POPT_ARG_NONE, 0, OPT_DAEMON, 0, 0 },
Wayne Davison1f35bab2005-02-21 00:31:31 +0000547 {"detach", 0, POPT_ARG_NONE, 0, OPT_DAEMON, 0, 0 },
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000548 {"no-detach", 0, POPT_ARG_NONE, 0, OPT_DAEMON, 0, 0 },
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000549 {0,0,0,0, 0, 0, 0}
550};
551
552static void daemon_usage(enum logcode F)
553{
554 print_rsync_version(F);
555
Wayne Davisonb64ee912006-06-01 08:04:47 +0000556 rprintf(F,"\n");
557 rprintf(F,"Usage: rsync --daemon [OPTION]...\n");
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000558 rprintf(F," --address=ADDRESS bind to the specified address\n");
Wayne Davisonb3708ac2005-01-28 09:55:18 +0000559 rprintf(F," --bwlimit=KBPS limit I/O bandwidth; KBytes per second\n");
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000560 rprintf(F," --config=FILE specify alternate rsyncd.conf file\n");
561 rprintf(F," --no-detach do not detach from the parent\n");
Wayne Davisonb3708ac2005-01-28 09:55:18 +0000562 rprintf(F," --port=PORT listen on alternate port number\n");
Wayne Davison87c0f9d2006-05-09 18:31:03 +0000563 rprintf(F," --log-file=FILE override the \"log file\" setting\n");
Wayne Davison232658d2006-05-30 17:14:17 +0000564 rprintf(F," --log-file-format=FMT override the \"log format\" setting\n");
Wayne Davison831f06a2006-01-26 12:31:24 +0000565 rprintf(F," --sockopts=OPTIONS specify custom TCP options\n");
Wayne Davison1bd9db72005-01-28 17:07:54 +0000566 rprintf(F," -v, --verbose increase verbosity\n");
Wayne Davison4f5b0752005-02-14 00:53:43 +0000567#ifdef INET6
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000568 rprintf(F," -4, --ipv4 prefer IPv4\n");
569 rprintf(F," -6, --ipv6 prefer IPv6\n");
570#endif
Wayne Davison05724c02005-11-15 06:35:27 +0000571 rprintf(F," --help show this help screen\n");
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000572
Wayne Davisonb64ee912006-06-01 08:04:47 +0000573 rprintf(F,"\n");
574 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 +0000575 rprintf(F,"daemon-specific rsync options. See also the rsyncd.conf(5) man page.\n");
576}
577
578static struct poptOption long_daemon_options[] = {
579 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
580 {"address", 0, POPT_ARG_STRING, &bind_address, 0, 0, 0 },
Wayne Davison9fb08442004-11-17 19:29:20 +0000581 {"bwlimit", 0, POPT_ARG_INT, &daemon_bwlimit, 0, 0, 0 },
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000582 {"config", 0, POPT_ARG_STRING, &config_file, 0, 0, 0 },
583 {"daemon", 0, POPT_ARG_NONE, &daemon_opt, 0, 0, 0 },
Wayne Davison4f5b0752005-02-14 00:53:43 +0000584#ifdef INET6
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000585 {"ipv4", '4', POPT_ARG_VAL, &default_af_hint, AF_INET, 0, 0 },
586 {"ipv6", '6', POPT_ARG_VAL, &default_af_hint, AF_INET6, 0, 0 },
587#endif
Wayne Davison1f35bab2005-02-21 00:31:31 +0000588 {"detach", 0, POPT_ARG_VAL, &no_detach, 0, 0, 0 },
Wayne Davison87c0f9d2006-05-09 18:31:03 +0000589 {"log-file", 0, POPT_ARG_STRING, &logfile_name, 0, 0, 0 },
Wayne Davison232658d2006-05-30 17:14:17 +0000590 {"log-file-format", 0, POPT_ARG_STRING, &logfile_format, 0, 0, 0 },
Wayne Davison1f35bab2005-02-21 00:31:31 +0000591 {"no-detach", 0, POPT_ARG_VAL, &no_detach, 1, 0, 0 },
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000592 {"port", 0, POPT_ARG_INT, &rsync_port, 0, 0, 0 },
Wayne Davison831f06a2006-01-26 12:31:24 +0000593 {"sockopts", 0, POPT_ARG_STRING, &sockopts, 0, 0, 0 },
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000594 {"protocol", 0, POPT_ARG_INT, &protocol_version, 0, 0, 0 },
595 {"server", 0, POPT_ARG_NONE, &am_server, 0, 0, 0 },
Wayne Davisonb8cc3582005-08-30 05:00:56 +0000596 {"temp-dir", 'T', POPT_ARG_STRING, &tmpdir, 0, 0, 0 },
Wayne Davison1bd9db72005-01-28 17:07:54 +0000597 {"verbose", 'v', POPT_ARG_NONE, 0, 'v', 0, 0 },
Wayne Davisonb6e22a42005-08-30 16:13:54 +0000598 {"no-verbose", 0, POPT_ARG_VAL, &verbose, 0, 0, 0 },
599 {"no-v", 0, POPT_ARG_VAL, &verbose, 0, 0, 0 },
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000600 {"help", 'h', POPT_ARG_NONE, 0, 'h', 0, 0 },
Wayne Davisonad715002004-10-14 09:11:12 +0000601 {0,0,0,0, 0, 0, 0}
Martin Pool2855f612001-02-23 01:02:31 +0000602};
Andrew Tridgell7a6421f1998-05-10 07:25:40 +0000603
Martin Pool06963d02001-11-23 07:35:49 +0000604
Wayne Davisone51094b2004-05-21 09:41:38 +0000605static char err_buf[200];
Andrew Tridgellcd8185f1998-11-19 06:35:49 +0000606
Martin Pool2855f612001-02-23 01:02:31 +0000607
Martin Pooldafe63c2002-04-16 01:38:21 +0000608/**
609 * Store the option error message, if any, so that we can log the
610 * connection attempt (which requires parsing the options), and then
611 * show the error later on.
612 **/
Andrew Tridgellcd8185f1998-11-19 06:35:49 +0000613void option_error(void)
614{
Wayne Davisone51094b2004-05-21 09:41:38 +0000615 if (!err_buf[0]) {
616 strcpy(err_buf, "Error parsing options: "
617 "option may be supported on client but not on server?\n");
Andrew Tridgellcd8185f1998-11-19 06:35:49 +0000618 }
Wayne Davisone51094b2004-05-21 09:41:38 +0000619
Wayne Davisone51094b2004-05-21 09:41:38 +0000620 rprintf(FERROR, RSYNC_NAME ": %s", err_buf);
Wayne Davison8f1dc162006-02-20 17:58:13 +0000621 msleep(20);
Andrew Tridgellcd8185f1998-11-19 06:35:49 +0000622}
623
Martin Pooldafe63c2002-04-16 01:38:21 +0000624
625/**
Wayne Davison27ed20f2004-02-21 21:12:49 +0000626 * Tweak the option table to disable all options that the rsyncd.conf
627 * file has told us to refuse.
Martin Pooldafe63c2002-04-16 01:38:21 +0000628 **/
Wayne Davison27ed20f2004-02-21 21:12:49 +0000629static void set_refuse_options(char *bp)
Andrew Tridgellcd8185f1998-11-19 06:35:49 +0000630{
Wayne Davison27ed20f2004-02-21 21:12:49 +0000631 struct poptOption *op;
Wayne Davison093e8162004-08-02 07:40:34 +0000632 char *cp, shortname[2];
Wayne Davisond73e7f62004-08-04 21:20:34 +0000633 int is_wild, found_match;
Wayne Davison093e8162004-08-02 07:40:34 +0000634
635 shortname[1] = '\0';
Andrew Tridgellcd8185f1998-11-19 06:35:49 +0000636
Wayne Davison27ed20f2004-02-21 21:12:49 +0000637 while (1) {
Wayne Davison06a50542004-08-02 05:00:30 +0000638 while (*bp == ' ') bp++;
639 if (!*bp)
640 break;
Wayne Davison27ed20f2004-02-21 21:12:49 +0000641 if ((cp = strchr(bp, ' ')) != NULL)
642 *cp= '\0';
Wayne Davison093e8162004-08-02 07:40:34 +0000643 is_wild = strpbrk(bp, "*?[") != NULL;
Wayne Davisond73e7f62004-08-04 21:20:34 +0000644 found_match = 0;
Wayne Davison55afbb52004-02-21 21:36:55 +0000645 for (op = long_options; ; op++) {
Wayne Davison093e8162004-08-02 07:40:34 +0000646 *shortname = op->shortName;
Wayne Davisond73e7f62004-08-04 21:20:34 +0000647 if (!op->longName && !*shortname)
648 break;
649 if ((op->longName && wildmatch(bp, op->longName))
Wayne Davison684d7582005-02-19 22:16:39 +0000650 || (*shortname && wildmatch(bp, shortname))) {
Wayne Davisone57211c2005-01-23 01:25:36 +0000651 if (op->argInfo == POPT_ARG_VAL)
652 op->argInfo = POPT_ARG_NONE;
Wayne Davison06a50542004-08-02 05:00:30 +0000653 op->val = (op - long_options) + OPT_REFUSED_BASE;
Wayne Davisond73e7f62004-08-04 21:20:34 +0000654 found_match = 1;
Wayne Davison36719872005-02-11 10:42:55 +0000655 /* These flags are set to let us easily check
656 * an implied option later in the code. */
657 switch (*shortname) {
Wayne Davison36719872005-02-11 10:42:55 +0000658 case 'r': case 'd': case 'l': case 'p':
659 case 't': case 'g': case 'o': case 'D':
660 refused_archive_part = op->val;
661 break;
Wayne Davison854a1aa2005-10-26 16:47:15 +0000662 case 'z':
663 refused_compress = op->val;
664 break;
Wayne Davison36719872005-02-11 10:42:55 +0000665 case '\0':
666 if (wildmatch("delete", op->longName))
667 refused_delete = op->val;
Wayne Davison3296f912005-02-15 21:15:58 +0000668 else if (wildmatch("delete-before", op->longName))
669 refused_delete_before = op->val;
Wayne Davison36719872005-02-11 10:42:55 +0000670 else if (wildmatch("partial", op->longName))
671 refused_partial = op->val;
672 else if (wildmatch("progress", op->longName))
673 refused_progress = op->val;
Wayne Davisona0157882005-07-28 01:46:09 +0000674 else if (wildmatch("inplace", op->longName))
675 refused_inplace = op->val;
Wayne Davison36719872005-02-11 10:42:55 +0000676 break;
677 }
Wayne Davison06a50542004-08-02 05:00:30 +0000678 if (!is_wild)
679 break;
Wayne Davison27ed20f2004-02-21 21:12:49 +0000680 }
Andrew Tridgellcd8185f1998-11-19 06:35:49 +0000681 }
Wayne Davisond73e7f62004-08-04 21:20:34 +0000682 if (!found_match) {
683 rprintf(FLOG, "No match for refuse-options string \"%s\"\n",
684 bp);
685 }
Wayne Davison27ed20f2004-02-21 21:12:49 +0000686 if (!cp)
687 break;
688 *cp = ' ';
689 bp = cp + 1;
Andrew Tridgellcd8185f1998-11-19 06:35:49 +0000690 }
Andrew Tridgellcd8185f1998-11-19 06:35:49 +0000691}
692
693
Wayne Davison8db7cc22004-10-11 10:43:25 +0000694static int count_args(const char **argv)
Martin Pool2855f612001-02-23 01:02:31 +0000695{
Wayne Davisondfa32482003-03-21 18:58:50 +0000696 int i = 0;
Martin Pool2855f612001-02-23 01:02:31 +0000697
Wayne Davison8db7cc22004-10-11 10:43:25 +0000698 if (argv) {
699 while (argv[i] != NULL)
700 i++;
701 }
Wayne Davisondfa32482003-03-21 18:58:50 +0000702
703 return i;
Martin Pool2855f612001-02-23 01:02:31 +0000704}
705
706
Wayne Davison837d01d2005-10-14 19:48:34 +0000707static OFF_T parse_size_arg(char **size_arg, char def_suf)
Wayne Davison95e107d2005-04-28 16:11:32 +0000708{
Wayne Davison3c19f722005-11-15 17:49:59 +0000709 int reps, mult, make_compatible = 0;
710 const char *arg;
711 OFF_T size = 1;
Wayne Davison95e107d2005-04-28 16:11:32 +0000712
Wayne Davisonaeb213e2005-10-14 18:56:07 +0000713 for (arg = *size_arg; isdigit(*(uchar*)arg); arg++) {}
Wayne Davison95e107d2005-04-28 16:11:32 +0000714 if (*arg == '.')
715 for (arg++; isdigit(*(uchar*)arg); arg++) {}
Wayne Davison3c19f722005-11-15 17:49:59 +0000716 switch (*arg && *arg != '+' && *arg != '-' ? *arg++ : def_suf) {
Wayne Davison837d01d2005-10-14 19:48:34 +0000717 case 'b': case 'B':
Wayne Davison3c19f722005-11-15 17:49:59 +0000718 reps = 0;
Wayne Davison837d01d2005-10-14 19:48:34 +0000719 break;
Wayne Davison95e107d2005-04-28 16:11:32 +0000720 case 'k': case 'K':
Wayne Davison3c19f722005-11-15 17:49:59 +0000721 reps = 1;
Wayne Davison95e107d2005-04-28 16:11:32 +0000722 break;
723 case 'm': case 'M':
Wayne Davison3c19f722005-11-15 17:49:59 +0000724 reps = 2;
Wayne Davison95e107d2005-04-28 16:11:32 +0000725 break;
726 case 'g': case 'G':
Wayne Davison3c19f722005-11-15 17:49:59 +0000727 reps = 3;
Wayne Davison95e107d2005-04-28 16:11:32 +0000728 break;
729 default:
Wayne Davison3c19f722005-11-15 17:49:59 +0000730 return -1;
Wayne Davison95e107d2005-04-28 16:11:32 +0000731 }
Wayne Davison3c19f722005-11-15 17:49:59 +0000732 if (*arg == 'b' || *arg == 'B')
733 mult = 1000, make_compatible = 1, arg++;
734 else if (!*arg || *arg == '+' || *arg == '-')
735 mult = 1024;
736 else if (strncasecmp(arg, "ib", 2) == 0)
737 mult = 1024, arg += 2;
738 else
739 return -1;
740 while (reps--)
741 size *= mult;
742 size *= atof(*size_arg);
743 if ((*arg == '+' || *arg == '-') && arg[1] == '1')
744 size += atoi(arg), make_compatible = 1, arg += 2;
745 if (*arg)
746 return -1;
Wayne Davisonaeb213e2005-10-14 18:56:07 +0000747 if (size > 0 && make_compatible) {
Wayne Davison74de13d2005-10-14 20:15:18 +0000748 /* We convert this manually because we may need %lld precision,
749 * and that's not a portable sprintf() escape. */
Wayne Davison8f14cc42005-11-12 19:53:17 +0000750 char buf[128], *s = buf + sizeof buf - 1;
Wayne Davisonaeb213e2005-10-14 18:56:07 +0000751 OFF_T num = size;
Wayne Davison8f14cc42005-11-12 19:53:17 +0000752 *s = '\0';
Wayne Davisonaeb213e2005-10-14 18:56:07 +0000753 while (num) {
Wayne Davisonaeb213e2005-10-14 18:56:07 +0000754 *--s = (num % 10) + '0';
755 num /= 10;
756 }
757 if (!(*size_arg = strdup(s)))
758 out_of_memory("parse_size_arg");
759 }
Wayne Davison95e107d2005-04-28 16:11:32 +0000760 return size;
761}
762
763
Wayne Davison36719872005-02-11 10:42:55 +0000764static void create_refuse_error(int which)
765{
766 /* The "which" value is the index + OPT_REFUSED_BASE. */
767 struct poptOption *op = &long_options[which - OPT_REFUSED_BASE];
768 int n = snprintf(err_buf, sizeof err_buf,
769 "The server is configured to refuse --%s\n",
770 op->longName) - 1;
771 if (op->shortName) {
772 snprintf(err_buf + n, sizeof err_buf - n,
773 " (-%c)\n", op->shortName);
774 }
775}
776
777
Martin Pooldafe63c2002-04-16 01:38:21 +0000778/**
779 * Process command line arguments. Called on both local and remote.
780 *
781 * @retval 1 if all options are OK; with globals set to appropriate
782 * values
783 *
784 * @retval 0 on error, with err_buf containing an explanation
785 **/
Martin Pool2855f612001-02-23 01:02:31 +0000786int parse_arguments(int *argc, const char ***argv, int frommain)
Andrew Tridgell7a6421f1998-05-10 07:25:40 +0000787{
Andrew Tridgelld8537831998-07-17 10:00:43 +0000788 int opt;
Andrew Tridgellcd8185f1998-11-19 06:35:49 +0000789 char *ref = lp_refuse_options(module_id);
Wayne Davison7be73df2004-03-27 09:46:42 +0000790 const char *arg;
Wayne Davisondfa32482003-03-21 18:58:50 +0000791 poptContext pc;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +0000792
Wayne Davison27ed20f2004-02-21 21:12:49 +0000793 if (ref && *ref)
794 set_refuse_options(ref);
Wayne Davison232658d2006-05-30 17:14:17 +0000795 if (am_daemon)
796 set_refuse_options("log-file*");
Wayne Davison27ed20f2004-02-21 21:12:49 +0000797
Wayne Davisondfa32482003-03-21 18:58:50 +0000798 /* TODO: Call poptReadDefaultConfig; handle errors. */
Andrew Tridgellcd8185f1998-11-19 06:35:49 +0000799
Wayne Davisondfa32482003-03-21 18:58:50 +0000800 /* The context leaks in case of an error, but if there's a
801 * problem we always exit anyhow. */
802 pc = poptGetContext(RSYNC_NAME, *argc, *argv, long_options, 0);
Wayne Davison9fb08442004-11-17 19:29:20 +0000803 poptReadDefaultConfig(pc, 0);
Martin Pool2855f612001-02-23 01:02:31 +0000804
805 while ((opt = poptGetNextOpt(pc)) != -1) {
Wayne Davisondfa32482003-03-21 18:58:50 +0000806 /* most options are handled automatically by popt;
807 * only special cases are returned and listed here. */
Martin Pool2855f612001-02-23 01:02:31 +0000808
Andrew Tridgelld8537831998-07-17 10:00:43 +0000809 switch (opt) {
810 case OPT_VERSION:
Wayne Davisondfa32482003-03-21 18:58:50 +0000811 print_rsync_version(FINFO);
Andrew Tridgelld8537831998-07-17 10:00:43 +0000812 exit_cleanup(0);
Wayne Davisondfa32482003-03-21 18:58:50 +0000813
Wayne Davison0ccffd72006-01-21 20:15:49 +0000814 case OPT_SERVER:
815 if (!am_server) {
816 /* Disable popt aliases on the server side and
817 * then start parsing the options again. */
818 poptFreeContext(pc);
819 pc = poptGetContext(RSYNC_NAME, *argc, *argv,
820 long_options, 0);
821 am_server = 1;
822 }
823 break;
824
825 case OPT_SENDER:
826 if (!am_server) {
827 usage(FERROR);
828 exit_cleanup(RERR_SYNTAX);
829 }
830 am_sender = 1;
831 break;
832
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000833 case OPT_DAEMON:
834 if (am_daemon) {
835 strcpy(err_buf, "Attempt to hack rsync thwarted!\n");
836 return 0;
837 }
838 poptFreeContext(pc);
839 pc = poptGetContext(RSYNC_NAME, *argc, *argv,
840 long_daemon_options, 0);
841 while ((opt = poptGetNextOpt(pc)) != -1) {
842 switch (opt) {
843 case 'h':
844 daemon_usage(FINFO);
845 exit_cleanup(0);
846
Wayne Davison1bd9db72005-01-28 17:07:54 +0000847 case 'v':
848 verbose++;
849 break;
850
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000851 default:
852 rprintf(FERROR,
853 "rsync: %s: %s (in daemon mode)\n",
854 poptBadOption(pc, POPT_BADOPTION_NOALIAS),
855 poptStrerror(opt));
856 goto daemon_error;
857 }
858 }
Wayne Davisonb6e22a42005-08-30 16:13:54 +0000859
860 if (tmpdir && strlen(tmpdir) >= MAXPATHLEN - 10) {
861 snprintf(err_buf, sizeof err_buf,
862 "the --temp-dir path is WAY too long.\n");
863 return 0;
864 }
865
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000866 if (!daemon_opt) {
867 rprintf(FERROR, "Daemon option(s) used without --daemon.\n");
868 daemon_error:
869 rprintf(FERROR,
870 "(Type \"rsync --daemon --help\" for assistance with daemon mode.)\n");
871 exit_cleanup(RERR_SYNTAX);
872 }
Wayne Davisonb6e22a42005-08-30 16:13:54 +0000873
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000874 *argv = poptGetArgs(pc);
875 *argc = count_args(*argv);
Wayne Davison7f2a1f62005-02-25 17:08:31 +0000876 am_starting_up = 0;
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000877 daemon_opt = 0;
878 am_daemon = 1;
879 return 1;
880
Andrew Tridgell5b56cc12000-09-06 02:12:13 +0000881 case OPT_MODIFY_WINDOW:
Wayne Davisondfa32482003-03-21 18:58:50 +0000882 /* The value has already been set by popt, but
883 * we need to remember that we're using a
884 * non-default setting. */
Andrew Tridgell5b56cc12000-09-06 02:12:13 +0000885 modify_window_set = 1;
886 break;
Wayne Davison1de50992002-05-03 22:59:17 +0000887
Wayne Davisonaa4d3b42005-01-25 00:52:56 +0000888 case OPT_FILTER:
Wayne Davison3a5e9222005-02-04 21:13:03 +0000889 parse_rule(&filter_list, poptGetOptArg(pc), 0, 0);
Andrew Tridgelld8537831998-07-17 10:00:43 +0000890 break;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +0000891
Wayne Davisonaa4d3b42005-01-25 00:52:56 +0000892 case OPT_EXCLUDE:
Wayne Davison3a5e9222005-02-04 21:13:03 +0000893 parse_rule(&filter_list, poptGetOptArg(pc),
Wayne Davison0a68f862005-02-03 19:00:17 +0000894 0, XFLG_OLD_PREFIXES);
Wayne Davisonaa4d3b42005-01-25 00:52:56 +0000895 break;
896
Andrew Tridgelld8537831998-07-17 10:00:43 +0000897 case OPT_INCLUDE:
Wayne Davison3a5e9222005-02-04 21:13:03 +0000898 parse_rule(&filter_list, poptGetOptArg(pc),
Wayne Davison0a68f862005-02-03 19:00:17 +0000899 MATCHFLG_INCLUDE, XFLG_OLD_PREFIXES);
Andrew Tridgelld8537831998-07-17 10:00:43 +0000900 break;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +0000901
Andrew Tridgelld8537831998-07-17 10:00:43 +0000902 case OPT_EXCLUDE_FROM:
David Dykstra93695762002-02-27 22:49:57 +0000903 case OPT_INCLUDE_FROM:
Wayne Davison7be73df2004-03-27 09:46:42 +0000904 arg = poptGetOptArg(pc);
Wayne Davisond1e6b0e2006-05-05 15:58:44 +0000905 if (sanitize_paths) {
Wayne Davison91f4b312006-05-03 00:48:20 +0000906 arg = sanitize_path(NULL, arg, NULL, 0, NULL);
Wayne Davisond1e6b0e2006-05-05 15:58:44 +0000907 die_on_unsafe_path((char*)arg, 0);
908 }
Wayne Davison78424182005-01-25 10:39:14 +0000909 if (server_filter_list.head) {
Wayne Davisond3ef9852006-04-28 17:34:53 +0000910 char *cp = strdup(arg);
911 if (!cp)
912 out_of_memory("parse_arguments");
Wayne Davison36719872005-02-11 10:42:55 +0000913 if (!*cp)
914 goto options_rejected;
Wayne Davisonba3db472004-08-26 17:39:48 +0000915 clean_fname(cp, 1);
Wayne Davison78424182005-01-25 10:39:14 +0000916 if (check_filter(&server_filter_list, cp, 0) < 0)
Wayne Davisonba3db472004-08-26 17:39:48 +0000917 goto options_rejected;
Wayne Davisond3ef9852006-04-28 17:34:53 +0000918 free(cp);
Wayne Davisonba3db472004-08-26 17:39:48 +0000919 }
Wayne Davison3a5e9222005-02-04 21:13:03 +0000920 parse_filter_file(&filter_list, arg,
921 opt == OPT_INCLUDE_FROM ? MATCHFLG_INCLUDE : 0,
922 XFLG_FATAL_ERRORS | XFLG_OLD_PREFIXES);
David Dykstra93695762002-02-27 22:49:57 +0000923 break;
924
Wayne Davisonb6164932005-08-27 21:01:45 +0000925 case 'a':
926 if (refused_archive_part) {
927 create_refuse_error(refused_archive_part);
928 return 0;
929 }
930 if (!recurse) /* preserve recurse == 2 */
931 recurse = 1;
932#ifdef SUPPORT_LINKS
933 preserve_links = 1;
934#endif
935 preserve_perms = 1;
936 preserve_times = 1;
937 preserve_gid = 1;
938 preserve_uid = 1;
939 preserve_devices = 1;
Wayne Davisonb5c6a6a2006-01-26 10:38:58 +0000940 preserve_specials = 1;
941 break;
942
943 case 'D':
944 preserve_devices = preserve_specials = 1;
945 break;
946
947 case OPT_NO_D:
948 preserve_devices = preserve_specials = 0;
Wayne Davisonb6164932005-08-27 21:01:45 +0000949 break;
950
Wayne Davison3ca9e5d2006-02-08 16:52:25 +0000951 case 'h':
952 human_readable++;
953 break;
954
Wayne Davison487094a2006-01-20 18:49:07 +0000955 case 'i':
956 itemize_changes++;
957 break;
958
Andrew Tridgelld8537831998-07-17 10:00:43 +0000959 case 'v':
960 verbose++;
961 break;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +0000962
David Dykstrab86f0ce1999-02-09 17:25:35 +0000963 case 'q':
Wayne Davisonf98c60b2004-02-09 18:10:57 +0000964 if (frommain)
965 quiet++;
David Dykstrab86f0ce1999-02-09 17:25:35 +0000966 break;
967
Wayne Davison243c9952006-01-21 00:36:15 +0000968 case 'x':
969 one_file_system++;
970 break;
971
Wayne Davisonaa4d3b42005-01-25 00:52:56 +0000972 case 'F':
973 switch (++F_option_cnt) {
974 case 1:
Wayne Davison3a5e9222005-02-04 21:13:03 +0000975 parse_rule(&filter_list,": /.rsync-filter",0,0);
Wayne Davisonaa4d3b42005-01-25 00:52:56 +0000976 break;
977 case 2:
Wayne Davison3a5e9222005-02-04 21:13:03 +0000978 parse_rule(&filter_list,"- .rsync-filter",0,0);
Wayne Davisonaa4d3b42005-01-25 00:52:56 +0000979 break;
980 }
981 break;
982
Andrew Tridgelld9fcc191999-10-31 02:47:30 +0000983 case 'P':
Wayne Davison36719872005-02-11 10:42:55 +0000984 if (refused_partial || refused_progress) {
985 create_refuse_error(refused_partial
986 ? refused_partial : refused_progress);
987 return 0;
988 }
Andrew Tridgelld9fcc191999-10-31 02:47:30 +0000989 do_progress = 1;
990 keep_partial = 1;
991 break;
992
Wayne Davison854a1aa2005-10-26 16:47:15 +0000993 case 'z':
994 if (def_compress_level < Z_DEFAULT_COMPRESSION
995 || def_compress_level > Z_BEST_COMPRESSION) {
996 snprintf(err_buf, sizeof err_buf,
997 "--compress-level value is invalid: %d\n",
998 def_compress_level);
999 return 0;
1000 }
1001 do_compression = def_compress_level != Z_NO_COMPRESSION;
1002 if (do_compression && refused_compress) {
1003 create_refuse_error(refused_compress);
1004 return 0;
1005 }
1006 break;
1007
David Dykstra088aac82002-02-06 21:20:48 +00001008 case OPT_WRITE_BATCH:
Wayne Davison9b3318b2004-07-15 16:27:02 +00001009 /* batch_name is already set */
David Dykstra088aac82002-02-06 21:20:48 +00001010 write_batch = 1;
1011 break;
1012
Wayne Davison11e758a2005-04-09 18:59:47 +00001013 case OPT_ONLY_WRITE_BATCH:
1014 /* batch_name is already set */
1015 write_batch = -1;
1016 break;
1017
Martin Pool76f79ba2002-01-23 05:51:06 +00001018 case OPT_READ_BATCH:
Wayne Davison9b3318b2004-07-15 16:27:02 +00001019 /* batch_name is already set */
Martin Pool6902ed12001-08-14 02:04:47 +00001020 read_batch = 1;
1021 break;
Wayne Davisonea5164d2003-03-30 23:00:42 +00001022
Wayne Davison7d5acf12004-11-11 01:45:25 +00001023 case OPT_MAX_SIZE:
Wayne Davison837d01d2005-10-14 19:48:34 +00001024 if ((max_size = parse_size_arg(&max_size_arg, 'b')) <= 0) {
Wayne Davisone012f852004-11-27 17:52:51 +00001025 snprintf(err_buf, sizeof err_buf,
Wayne Davison7d5acf12004-11-11 01:45:25 +00001026 "--max-size value is invalid: %s\n",
1027 max_size_arg);
Wayne Davisone012f852004-11-27 17:52:51 +00001028 return 0;
Wayne Davison7d5acf12004-11-11 01:45:25 +00001029 }
1030 break;
1031
Wayne Davison74de13d2005-10-14 20:15:18 +00001032 case OPT_MIN_SIZE:
1033 if ((min_size = parse_size_arg(&min_size_arg, 'b')) <= 0) {
1034 snprintf(err_buf, sizeof err_buf,
1035 "--min-size value is invalid: %s\n",
1036 min_size_arg);
1037 return 0;
1038 }
1039 break;
1040
David Dykstra59c95e42002-08-29 14:44:55 +00001041 case OPT_LINK_DEST:
Wayne Davisonfcecb702006-05-05 06:16:22 +00001042#ifdef SUPPORT_HARD_LINKS
David Dykstra59c95e42002-08-29 14:44:55 +00001043 link_dest = 1;
Wayne Davisone012f852004-11-27 17:52:51 +00001044 dest_option = "--link-dest";
1045 goto set_dest_dir;
David Dykstra59c95e42002-08-29 14:44:55 +00001046#else
Wayne Davisond175d7e2003-08-01 07:58:44 +00001047 snprintf(err_buf, sizeof err_buf,
Wayne Davisondfa32482003-03-21 18:58:50 +00001048 "hard links are not supported on this %s\n",
David Dykstra59c95e42002-08-29 14:44:55 +00001049 am_server ? "server" : "client");
David Dykstra59c95e42002-08-29 14:44:55 +00001050 return 0;
1051#endif
1052
Wayne Davison1de3e992005-03-11 17:35:59 +00001053 case OPT_COPY_DEST:
1054 copy_dest = 1;
1055 dest_option = "--copy-dest";
1056 goto set_dest_dir;
1057
Wayne Davisone012f852004-11-27 17:52:51 +00001058 case OPT_COMPARE_DEST:
1059 compare_dest = 1;
1060 dest_option = "--compare-dest";
1061 set_dest_dir:
Wayne Davison3b26bba2005-01-15 21:23:04 +00001062 if (basis_dir_cnt >= MAX_BASIS_DIRS) {
Wayne Davisone012f852004-11-27 17:52:51 +00001063 snprintf(err_buf, sizeof err_buf,
1064 "ERROR: at most %d %s args may be specified\n",
1065 MAX_BASIS_DIRS, dest_option);
1066 return 0;
1067 }
Wayne Davisonad77db82006-04-28 16:57:39 +00001068 /* We defer sanitizing this arg until we know what
1069 * our destination directory is going to be. */
1070 basis_dir[basis_dir_cnt++] = (char *)poptGetOptArg(pc);
Wayne Davisone012f852004-11-27 17:52:51 +00001071 break;
1072
Wayne Davisone16adcd2006-01-21 09:14:42 +00001073 case OPT_CHMOD:
1074 arg = poptGetOptArg(pc);
Wayne Davisonbbe42182006-01-30 17:53:19 +00001075 if (!parse_chmod(arg, &chmod_modes)) {
Wayne Davisone16adcd2006-01-21 09:14:42 +00001076 snprintf(err_buf, sizeof err_buf,
1077 "Invalid argument passed to --chmod (%s)\n",
1078 arg);
1079 return 0;
1080 }
1081 break;
1082
Wayne Davisonf5a910d2006-01-21 19:52:55 +00001083 case OPT_HELP:
1084 usage(FINFO);
1085 exit_cleanup(0);
1086
Andrew Tridgelld8537831998-07-17 10:00:43 +00001087 default:
Wayne Davison55afbb52004-02-21 21:36:55 +00001088 /* A large opt value means that set_refuse_options()
Wayne Davison36719872005-02-11 10:42:55 +00001089 * turned this option off. */
Wayne Davisonc67d1382004-02-22 08:56:43 +00001090 if (opt >= OPT_REFUSED_BASE) {
Wayne Davison36719872005-02-11 10:42:55 +00001091 create_refuse_error(opt);
1092 return 0;
Wayne Davison27ed20f2004-02-21 21:12:49 +00001093 }
Wayne Davison36719872005-02-11 10:42:55 +00001094 snprintf(err_buf, sizeof err_buf, "%s%s: %s\n",
1095 am_server ? "on remote machine: " : "",
1096 poptBadOption(pc, POPT_BADOPTION_NOALIAS),
1097 poptStrerror(opt));
Wayne Davisondfa32482003-03-21 18:58:50 +00001098 return 0;
Andrew Tridgelld8537831998-07-17 10:00:43 +00001099 }
Andrew Tridgell7a6421f1998-05-10 07:25:40 +00001100 }
Martin Pool2855f612001-02-23 01:02:31 +00001101
Wayne Davison05724c02005-11-15 06:35:27 +00001102 if (human_readable && *argc == 2) {
Wayne Davison3ca9e5d2006-02-08 16:52:25 +00001103 /* Allow the old meaning of 'h' (--help) on its own. */
Wayne Davison05724c02005-11-15 06:35:27 +00001104 usage(FINFO);
1105 exit_cleanup(0);
1106 }
1107
Wayne Davison4f5b0752005-02-14 00:53:43 +00001108#ifndef SUPPORT_LINKS
Wayne Davison54e87b42004-02-02 21:33:10 +00001109 if (preserve_links && !am_sender) {
Wayne Davisone1add892004-02-01 17:29:41 +00001110 snprintf(err_buf, sizeof err_buf,
1111 "symlinks are not supported on this %s\n",
1112 am_server ? "server" : "client");
Wayne Davisone1add892004-02-01 17:29:41 +00001113 return 0;
1114 }
1115#endif
1116
Wayne Davison4f5b0752005-02-14 00:53:43 +00001117#ifndef SUPPORT_HARD_LINKS
Wayne Davisone1add892004-02-01 17:29:41 +00001118 if (preserve_hard_links) {
1119 snprintf(err_buf, sizeof err_buf,
1120 "hard links are not supported on this %s\n",
1121 am_server ? "server" : "client");
Wayne Davisone1add892004-02-01 17:29:41 +00001122 return 0;
1123 }
1124#endif
1125
David Dykstra088aac82002-02-06 21:20:48 +00001126 if (write_batch && read_batch) {
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001127 snprintf(err_buf, sizeof err_buf,
Wayne Davison36119892004-07-21 22:50:11 +00001128 "--write-batch and --read-batch can not be used together\n");
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001129 return 0;
David Dykstra088aac82002-02-06 21:20:48 +00001130 }
Wayne Davison11e758a2005-04-09 18:59:47 +00001131 if (write_batch > 0 || read_batch) {
Wayne Davison94327ff2004-07-15 19:06:32 +00001132 if (am_server) {
1133 rprintf(FINFO,
1134 "ignoring --%s-batch option sent to server\n",
1135 write_batch ? "write" : "read");
1136 /* We don't actually exit_cleanup(), so that we can
1137 * still service older version clients that still send
1138 * batch args to server. */
1139 read_batch = write_batch = 0;
1140 batch_name = NULL;
Wayne Davison254ee3b2005-03-24 16:41:16 +00001141 } else if (dry_run)
1142 write_batch = 0;
Wayne Davisonb9f592f2004-07-15 02:20:08 +00001143 }
Wayne Davison36119892004-07-21 22:50:11 +00001144 if (read_batch && files_from) {
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001145 snprintf(err_buf, sizeof err_buf,
Wayne Davison36119892004-07-21 22:50:11 +00001146 "--read-batch cannot be used with --files-from\n");
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001147 return 0;
Wayne Davison36119892004-07-21 22:50:11 +00001148 }
Wayne Davison9b3318b2004-07-15 16:27:02 +00001149 if (batch_name && strlen(batch_name) > MAX_BATCH_NAME_LEN) {
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001150 snprintf(err_buf, sizeof err_buf,
Wayne Davison9b3318b2004-07-15 16:27:02 +00001151 "the batch-file name must be %d characters or less.\n",
1152 MAX_BATCH_NAME_LEN);
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001153 return 0;
Wayne Davisonbeb93682004-01-19 23:33:02 +00001154 }
David Dykstra088aac82002-02-06 21:20:48 +00001155
Wayne Davisonce58b1b2004-01-22 01:20:24 +00001156 if (tmpdir && strlen(tmpdir) >= MAXPATHLEN - 10) {
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001157 snprintf(err_buf, sizeof err_buf,
1158 "the --temp-dir path is WAY too long.\n");
1159 return 0;
Wayne Davisonce58b1b2004-01-22 01:20:24 +00001160 }
1161
Wayne Davison1de3e992005-03-11 17:35:59 +00001162 if (compare_dest + copy_dest + link_dest > 1) {
Wayne Davisone012f852004-11-27 17:52:51 +00001163 snprintf(err_buf, sizeof err_buf,
Wayne Davison1de3e992005-03-11 17:35:59 +00001164 "You may not mix --compare-dest, --copy-dest, and --link-dest.\n");
Wayne Davisone012f852004-11-27 17:52:51 +00001165 return 0;
1166 }
1167
Wayne Davisonb6164932005-08-27 21:01:45 +00001168 if (files_from) {
1169 if (recurse == 1) /* preserve recurse == 2 */
1170 recurse = 0;
Wayne Davison550d4e22005-09-29 17:27:11 +00001171 if (xfer_dirs < 0)
Wayne Davisonb6164932005-08-27 21:01:45 +00001172 xfer_dirs = 1;
Wayne Davisondfa32482003-03-21 18:58:50 +00001173 }
Wayne Davison51d48392005-01-22 22:48:34 +00001174
Wayne Davisonb6164932005-08-27 21:01:45 +00001175 if (xfer_dirs < 1)
1176 xfer_dirs = recurse || list_only;
Wayne Davisondfa32482003-03-21 18:58:50 +00001177
Wayne Davisonea5164d2003-03-30 23:00:42 +00001178 if (relative_paths < 0)
1179 relative_paths = files_from? 1 : 0;
Wayne Davison89f2a4c2005-07-22 19:05:25 +00001180 if (!relative_paths)
1181 implied_dirs = 0;
Wayne Davisonea5164d2003-03-30 23:00:42 +00001182
Wayne Davisonc6eb7fa2005-01-28 07:39:09 +00001183 if (!!delete_before + delete_during + delete_after > 1) {
Wayne Davison3359acb2005-01-25 03:08:58 +00001184 snprintf(err_buf, sizeof err_buf,
Wayne Davisonc6eb7fa2005-01-28 07:39:09 +00001185 "You may not combine multiple --delete-WHEN options.\n");
Wayne Davison3359acb2005-01-25 03:08:58 +00001186 return 0;
1187 }
Wayne Davisonf5a910d2006-01-21 19:52:55 +00001188 if (delete_before || delete_during || delete_after)
Wayne Davison51d48392005-01-22 22:48:34 +00001189 delete_mode = 1;
Wayne Davison3296f912005-02-15 21:15:58 +00001190 else if (delete_mode || delete_excluded) {
1191 if (refused_delete_before) {
1192 create_refuse_error(refused_delete_before);
1193 return 0;
1194 }
Wayne Davison3359acb2005-01-25 03:08:58 +00001195 delete_mode = delete_before = 1;
Wayne Davison3296f912005-02-15 21:15:58 +00001196 }
Wayne Davison89fb5022006-03-28 23:09:36 +00001197 if (!xfer_dirs && delete_mode) {
1198 snprintf(err_buf, sizeof err_buf,
1199 "--delete does not work without -r or -d.\n");
1200 return 0;
Wayne Davisonf5a910d2006-01-21 19:52:55 +00001201 }
Wayne Davison51d48392005-01-22 22:48:34 +00001202
Wayne Davison36719872005-02-11 10:42:55 +00001203 if (delete_mode && refused_delete) {
1204 create_refuse_error(refused_delete);
1205 return 0;
1206 }
1207
Wayne Davison47c11972006-06-30 15:52:52 +00001208 if (remove_source_files) {
1209 /* We only want to infer this refusal of --remove-source-files
Wayne Davison07c6ae72005-02-20 01:04:40 +00001210 * via the refusal of "delete", not any of the "delete-FOO"
1211 * options. */
1212 if (refused_delete && am_sender) {
1213 create_refuse_error(refused_delete);
1214 return 0;
1215 }
1216 need_messages_from_generator = 1;
1217 }
1218
Wayne Davison7be73df2004-03-27 09:46:42 +00001219 *argv = poptGetArgs(pc);
Wayne Davison8db7cc22004-10-11 10:43:25 +00001220 *argc = count_args(*argv);
Wayne Davison7be73df2004-03-27 09:46:42 +00001221
1222 if (sanitize_paths) {
1223 int i;
1224 for (i = *argc; i-- > 0; )
Wayne Davison91f4b312006-05-03 00:48:20 +00001225 (*argv)[i] = sanitize_path(NULL, (*argv)[i], "", 0, NULL);
Wayne Davisond1e6b0e2006-05-05 15:58:44 +00001226 if (tmpdir) {
Wayne Davison91f4b312006-05-03 00:48:20 +00001227 tmpdir = sanitize_path(NULL, tmpdir, NULL, 0, NULL);
Wayne Davisond1e6b0e2006-05-05 15:58:44 +00001228 die_on_unsafe_path(tmpdir, 0);
1229 }
1230 if (backup_dir) {
Wayne Davison91f4b312006-05-03 00:48:20 +00001231 backup_dir = sanitize_path(NULL, backup_dir, NULL, 0, NULL);
Wayne Davisond1e6b0e2006-05-05 15:58:44 +00001232 die_on_unsafe_path(backup_dir, 0);
1233 }
Wayne Davison7be73df2004-03-27 09:46:42 +00001234 }
Wayne Davison78424182005-01-25 10:39:14 +00001235 if (server_filter_list.head && !am_sender) {
1236 struct filter_list_struct *elp = &server_filter_list;
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001237 if (tmpdir) {
Wayne Davison36719872005-02-11 10:42:55 +00001238 if (!*tmpdir)
1239 goto options_rejected;
Wayne Davison58b19992004-08-12 18:20:07 +00001240 clean_fname(tmpdir, 1);
Wayne Davison78424182005-01-25 10:39:14 +00001241 if (check_filter(elp, tmpdir, 1) < 0)
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001242 goto options_rejected;
1243 }
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001244 if (backup_dir) {
Wayne Davison36719872005-02-11 10:42:55 +00001245 if (!*backup_dir)
1246 goto options_rejected;
Wayne Davison58b19992004-08-12 18:20:07 +00001247 clean_fname(backup_dir, 1);
Wayne Davison305666b2005-03-01 01:15:57 +00001248 if (check_filter(elp, backup_dir, 1) < 0) {
1249 options_rejected:
1250 snprintf(err_buf, sizeof err_buf,
1251 "Your options have been rejected by the server.\n");
1252 return 0;
1253 }
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001254 }
1255 }
Wayne Davison7be73df2004-03-27 09:46:42 +00001256
Wayne Davisond175d7e2003-08-01 07:58:44 +00001257 if (!backup_suffix)
Wayne Davisone0391f82004-02-11 04:30:41 +00001258 backup_suffix = backup_dir ? "" : BACKUP_SUFFIX;
Wayne Davisond175d7e2003-08-01 07:58:44 +00001259 backup_suffix_len = strlen(backup_suffix);
Wayne Davison80ddadb2003-08-01 19:40:31 +00001260 if (strchr(backup_suffix, '/') != NULL) {
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001261 snprintf(err_buf, sizeof err_buf,
1262 "--suffix cannot contain slashes: %s\n",
Wayne Davison80ddadb2003-08-01 19:40:31 +00001263 backup_suffix);
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001264 return 0;
Wayne Davison80ddadb2003-08-01 19:40:31 +00001265 }
Wayne Davisone0391f82004-02-11 04:30:41 +00001266 if (backup_dir) {
1267 backup_dir_len = strlcpy(backup_dir_buf, backup_dir, sizeof backup_dir_buf);
1268 backup_dir_remainder = sizeof backup_dir_buf - backup_dir_len;
1269 if (backup_dir_remainder < 32) {
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001270 snprintf(err_buf, sizeof err_buf,
1271 "the --backup-dir path is WAY too long.\n");
1272 return 0;
Wayne Davisone0391f82004-02-11 04:30:41 +00001273 }
1274 if (backup_dir_buf[backup_dir_len - 1] != '/') {
1275 backup_dir_buf[backup_dir_len++] = '/';
1276 backup_dir_buf[backup_dir_len] = '\0';
1277 }
Wayne Davison0ee6ca92006-01-13 22:06:31 +00001278 if (verbose > 1 && !am_sender)
1279 rprintf(FINFO, "backup_dir is %s\n", backup_dir_buf);
Wayne Davison8dcf9332004-03-31 17:02:22 +00001280 } else if (!backup_suffix_len && (!am_server || !am_sender)) {
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001281 snprintf(err_buf, sizeof err_buf,
Wayne Davisond175d7e2003-08-01 07:58:44 +00001282 "--suffix cannot be a null string without --backup-dir\n");
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001283 return 0;
Wayne Davisonc2226072006-01-28 01:55:55 +00001284 } else if (make_backups && delete_mode && !delete_excluded) {
Wayne Davisonc2c56822005-12-16 17:18:29 +00001285 snprintf(backup_dir_buf, sizeof backup_dir_buf,
1286 "P *%s", backup_suffix);
1287 parse_rule(&filter_list, backup_dir_buf, 0, 0);
Wayne Davisond175d7e2003-08-01 07:58:44 +00001288 }
Wayne Davisond4021b62005-02-21 10:03:23 +00001289 if (make_backups && !backup_dir)
1290 omit_dir_times = 1;
Wayne Davisond175d7e2003-08-01 07:58:44 +00001291
Wayne Davisonb3e4e7e2006-05-29 22:56:45 +00001292 if (stdout_format) {
1293 if (am_server && log_format_has(stdout_format, 'I'))
1294 stdout_format_has_i = 2;
1295 else if (log_format_has(stdout_format, 'i'))
1296 stdout_format_has_i = itemize_changes | 1;
1297 if (!log_format_has(stdout_format, 'b')
1298 && !log_format_has(stdout_format, 'c'))
Wayne Davisone7651882005-02-16 08:10:31 +00001299 log_before_transfer = !am_server;
1300 } else if (itemize_changes) {
Wayne Davisonb3e4e7e2006-05-29 22:56:45 +00001301 stdout_format = "%i %n%L";
1302 stdout_format_has_i = itemize_changes;
Wayne Davisone7651882005-02-16 08:10:31 +00001303 log_before_transfer = !am_server;
1304 }
Wayne Davison87383692005-02-16 17:02:08 +00001305
Wayne Davisona892d902006-02-07 20:06:43 +00001306 if (do_progress && !verbose && !log_before_transfer && !am_server)
J.W. Schultze2559db2003-08-06 06:45:14 +00001307 verbose = 1;
Wayne Davison87383692005-02-16 17:02:08 +00001308
Wayne Davison11e758a2005-04-09 18:59:47 +00001309 if (dry_run)
1310 do_xfers = 0;
1311
Wayne Davison9ac756c2005-05-19 08:52:17 +00001312 set_io_timeout(io_timeout);
1313
Wayne Davisonb3e4e7e2006-05-29 22:56:45 +00001314 if (verbose && !stdout_format) {
1315 stdout_format = "%n%L";
Wayne Davison87383692005-02-16 17:02:08 +00001316 log_before_transfer = !am_server;
Wayne Davison36719872005-02-11 10:42:55 +00001317 }
Wayne Davisonb3e4e7e2006-05-29 22:56:45 +00001318 if (stdout_format_has_i || log_format_has(stdout_format, 'o'))
1319 stdout_format_has_o_or_i = 1;
J.W. Schultze2559db2003-08-06 06:45:14 +00001320
Wayne Davison232658d2006-05-30 17:14:17 +00001321 if (logfile_name && !am_daemon) {
Wayne Davisonb3e4e7e2006-05-29 22:56:45 +00001322 if (!logfile_format) {
Wayne Davison232658d2006-05-30 17:14:17 +00001323 logfile_format = "%i %n%L";
Wayne Davison87c0f9d2006-05-09 18:31:03 +00001324 logfile_format_has_i = logfile_format_has_o_or_i = 1;
Wayne Davisonb3e4e7e2006-05-29 22:56:45 +00001325 } else {
1326 if (log_format_has(logfile_format, 'i'))
Wayne Davison19b85872006-06-01 06:49:15 +00001327 logfile_format_has_i = 1;
Wayne Davisonb3e4e7e2006-05-29 22:56:45 +00001328 if (logfile_format_has_i || log_format_has(logfile_format, 'o'))
1329 logfile_format_has_o_or_i = 1;
Wayne Davison87c0f9d2006-05-09 18:31:03 +00001330 }
Wayne Davison6dc9b742006-06-07 23:05:24 +00001331 log_init(0);
Wayne Davison28736032006-05-30 17:41:54 +00001332 } else if (!am_daemon)
1333 logfile_format = NULL;
Wayne Davison87c0f9d2006-05-09 18:31:03 +00001334
Wayne Davison9fb08442004-11-17 19:29:20 +00001335 if (daemon_bwlimit && (!bwlimit || bwlimit > daemon_bwlimit))
1336 bwlimit = daemon_bwlimit;
Wayne Davison3c74c3a2004-05-27 21:51:53 +00001337 if (bwlimit) {
1338 bwlimit_writemax = (size_t)bwlimit * 128;
1339 if (bwlimit_writemax < 512)
1340 bwlimit_writemax = 512;
1341 }
1342
Wayne Davisoncfce9f62005-08-30 02:57:19 +00001343 if (sparse_files && inplace) {
Wayne Davisonc3851182005-08-30 02:59:30 +00001344 /* Note: we don't check for this below, because --append is
Wayne Davisoncfce9f62005-08-30 02:57:19 +00001345 * OK with --sparse (as long as redos are handled right). */
1346 snprintf(err_buf, sizeof err_buf,
1347 "--sparse cannot be used with --inplace\n");
1348 return 0;
1349 }
1350
Wayne Davisona0157882005-07-28 01:46:09 +00001351 if (append_mode) {
1352 if (whole_file > 0) {
1353 snprintf(err_buf, sizeof err_buf,
1354 "--append cannot be used with --whole-file\n");
1355 return 0;
1356 }
1357 if (refused_inplace) {
1358 create_refuse_error(refused_inplace);
1359 return 0;
1360 }
1361 inplace = 1;
1362 }
1363
Wayne Davisonf06e7082005-01-27 22:46:14 +00001364 if (delay_updates && !partial_dir)
Wayne Davison77860ba2006-01-29 19:17:13 +00001365 partial_dir = tmp_partialdir;
Wayne Davisonf06e7082005-01-27 22:46:14 +00001366
Wayne Davisona3221d22004-07-16 20:06:24 +00001367 if (inplace) {
Wayne Davison4f5b0752005-02-14 00:53:43 +00001368#ifdef HAVE_FTRUNCATE
Wayne Davisona7260c42004-07-29 16:06:38 +00001369 if (partial_dir) {
1370 snprintf(err_buf, sizeof err_buf,
Wayne Davisona0157882005-07-28 01:46:09 +00001371 "--%s cannot be used with --%s\n",
1372 append_mode ? "append" : "inplace",
Wayne Davisonf06e7082005-01-27 22:46:14 +00001373 delay_updates ? "delay-updates" : "partial-dir");
Wayne Davisona7260c42004-07-29 16:06:38 +00001374 return 0;
1375 }
Wayne Davison36719872005-02-11 10:42:55 +00001376 /* --inplace implies --partial for refusal purposes, but we
1377 * clear the keep_partial flag for internal logic purposes. */
1378 if (refused_partial) {
1379 create_refuse_error(refused_partial);
1380 return 0;
1381 }
Wayne Davisona3221d22004-07-16 20:06:24 +00001382 keep_partial = 0;
Wayne Davisonded4daf2005-01-15 20:22:54 +00001383#else
1384 snprintf(err_buf, sizeof err_buf,
Wayne Davisona0157882005-07-28 01:46:09 +00001385 "--%s is not supported on this %s\n",
1386 append_mode ? "append" : "inplace",
Wayne Davisonded4daf2005-01-15 20:22:54 +00001387 am_server ? "server" : "client");
1388 return 0;
1389#endif
Wayne Davison075aa182004-09-18 17:34:56 +00001390 } else {
Wayne Davisonbc880cb2006-02-07 19:12:37 +00001391 if (keep_partial && !partial_dir && !am_server) {
Wayne Davison36719872005-02-11 10:42:55 +00001392 if ((arg = getenv("RSYNC_PARTIAL_DIR")) != NULL && *arg)
1393 partial_dir = strdup(arg);
1394 }
Wayne Davison075aa182004-09-18 17:34:56 +00001395 if (partial_dir) {
Wayne Davison36719872005-02-11 10:42:55 +00001396 if (*partial_dir)
1397 clean_fname(partial_dir, 1);
Wayne Davison075aa182004-09-18 17:34:56 +00001398 if (!*partial_dir || strcmp(partial_dir, ".") == 0)
1399 partial_dir = NULL;
Wayne Davison7eaabd82006-02-03 23:40:37 +00001400 else if (*partial_dir != '/') {
Wayne Davison3a5e9222005-02-04 21:13:03 +00001401 parse_rule(&filter_list, partial_dir,
Wayne Davison0a68f862005-02-03 19:00:17 +00001402 MATCHFLG_NO_PREFIXES|MATCHFLG_DIRECTORY, 0);
Wayne Davison13791b12004-09-22 04:12:13 +00001403 }
Wayne Davison36719872005-02-11 10:42:55 +00001404 if (!partial_dir && refused_partial) {
1405 create_refuse_error(refused_partial);
1406 return 0;
1407 }
Wayne Davison075aa182004-09-18 17:34:56 +00001408 keep_partial = 1;
1409 }
Wayne Davisona3221d22004-07-16 20:06:24 +00001410 }
1411
Wayne Davisonea5164d2003-03-30 23:00:42 +00001412 if (files_from) {
Wayne Davison305666b2005-03-01 01:15:57 +00001413 char *h, *p;
1414 int q;
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001415 if (*argc > 2 || (!am_daemon && *argc == 1)) {
Wayne Davisonea5164d2003-03-30 23:00:42 +00001416 usage(FERROR);
1417 exit_cleanup(RERR_SYNTAX);
1418 }
Wayne Davison63596e12003-12-15 00:53:07 +00001419 if (strcmp(files_from, "-") == 0) {
Wayne Davisonea5164d2003-03-30 23:00:42 +00001420 filesfrom_fd = 0;
Wayne Davison63596e12003-12-15 00:53:07 +00001421 if (am_server)
Wayne Davison305666b2005-03-01 01:15:57 +00001422 filesfrom_host = ""; /* reading from socket */
1423 } else if ((p = check_for_hostspec(files_from, &h, &q)) != 0) {
Wayne Davisonea5164d2003-03-30 23:00:42 +00001424 if (am_server) {
Wayne Davison305666b2005-03-01 01:15:57 +00001425 snprintf(err_buf, sizeof err_buf,
1426 "The --files-from sent to the server cannot specify a host.\n");
1427 return 0;
Wayne Davisonea5164d2003-03-30 23:00:42 +00001428 }
Wayne Davison305666b2005-03-01 01:15:57 +00001429 files_from = p;
1430 filesfrom_host = h;
1431 if (strcmp(files_from, "-") == 0) {
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001432 snprintf(err_buf, sizeof err_buf,
1433 "Invalid --files-from remote filename\n");
1434 return 0;
Wayne Davisonea5164d2003-03-30 23:00:42 +00001435 }
1436 } else {
Wayne Davison305666b2005-03-01 01:15:57 +00001437 if (sanitize_paths)
Wayne Davison91f4b312006-05-03 00:48:20 +00001438 files_from = sanitize_path(NULL, files_from, NULL, 0, NULL);
Wayne Davison305666b2005-03-01 01:15:57 +00001439 if (server_filter_list.head) {
1440 if (!*files_from)
1441 goto options_rejected;
1442 clean_fname(files_from, 1);
1443 if (check_filter(&server_filter_list, files_from, 0) < 0)
1444 goto options_rejected;
1445 }
Wayne Davisonea5164d2003-03-30 23:00:42 +00001446 filesfrom_fd = open(files_from, O_RDONLY|O_BINARY);
1447 if (filesfrom_fd < 0) {
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001448 snprintf(err_buf, sizeof err_buf,
1449 "failed to open files-from file %s: %s\n",
1450 files_from, strerror(errno));
1451 return 0;
Wayne Davisonea5164d2003-03-30 23:00:42 +00001452 }
1453 }
1454 }
1455
Wayne Davison7f2a1f62005-02-25 17:08:31 +00001456 am_starting_up = 0;
1457
Andrew Tridgellb11ed3b1998-07-19 04:50:48 +00001458 return 1;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +00001459}
1460
1461
Martin Pooldafe63c2002-04-16 01:38:21 +00001462/**
1463 * Construct a filtered list of options to pass through from the
1464 * client to the server.
1465 *
1466 * This involves setting options that will tell the server how to
1467 * behave, and also filtering out options that are processed only
1468 * locally.
1469 **/
Andrew Tridgell7a6421f1998-05-10 07:25:40 +00001470void server_options(char **args,int *argc)
1471{
Wayne Davison74ba98a2005-05-03 17:01:59 +00001472 static char argstr[64];
Andrew Tridgelld8537831998-07-17 10:00:43 +00001473 int ac = *argc;
Wayne Davisonf98c60b2004-02-09 18:10:57 +00001474 char *arg;
David Dykstraef5d23e2000-06-06 21:13:05 +00001475
Andrew Tridgelld8537831998-07-17 10:00:43 +00001476 int i, x;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +00001477
David Dykstra93689aa2002-02-05 23:05:31 +00001478 if (blocking_io == -1)
1479 blocking_io = 0;
1480
Wayne Davisondef97ff2006-01-26 11:10:32 +00001481 /* This should always remain first on the server's command-line. */
Andrew Tridgelld8537831998-07-17 10:00:43 +00001482 args[ac++] = "--server";
Andrew Tridgell7a6421f1998-05-10 07:25:40 +00001483
Wayne Davison1312d9f2002-08-01 00:37:01 +00001484 if (daemon_over_rsh) {
1485 args[ac++] = "--daemon";
1486 *argc = ac;
1487 /* if we're passing --daemon, we're done */
1488 return;
1489 }
1490
Andrew Tridgelld8537831998-07-17 10:00:43 +00001491 if (!am_sender)
1492 args[ac++] = "--sender";
Andrew Tridgell7a6421f1998-05-10 07:25:40 +00001493
Andrew Tridgelld8537831998-07-17 10:00:43 +00001494 x = 1;
1495 argstr[0] = '-';
Wayne Davisonf98c60b2004-02-09 18:10:57 +00001496 for (i = 0; i < verbose; i++)
Andrew Tridgelld8537831998-07-17 10:00:43 +00001497 argstr[x++] = 'v';
Andrew Tridgellf0b36a42000-08-29 04:46:27 +00001498
David Dykstrab86f0ce1999-02-09 17:25:35 +00001499 /* the -q option is intentionally left out */
Andrew Tridgelld8537831998-07-17 10:00:43 +00001500 if (make_backups)
1501 argstr[x++] = 'b';
1502 if (update_only)
1503 argstr[x++] = 'u';
Wayne Davison2dbf36e2006-02-24 17:54:30 +00001504 if (!do_xfers) /* Note: NOT "dry_run"! */
Andrew Tridgelld8537831998-07-17 10:00:43 +00001505 argstr[x++] = 'n';
1506 if (preserve_links)
1507 argstr[x++] = 'l';
Wayne Davisonf5a910d2006-01-21 19:52:55 +00001508 if (xfer_dirs > (recurse || !delete_mode || !am_sender))
Wayne Davison5454d222005-01-29 21:25:44 +00001509 argstr[x++] = 'd';
Wayne Davison35bf8fa2006-01-26 22:28:08 +00001510 if (am_sender) {
1511 if (keep_dirlinks)
1512 argstr[x++] = 'K';
Wayne Davison876c9932006-01-28 00:13:55 +00001513 if (prune_empty_dirs)
1514 argstr[x++] = 'm';
Wayne Davison35bf8fa2006-01-26 22:28:08 +00001515 if (omit_dir_times == 2)
1516 argstr[x++] = 'O';
Wayne Davison2dbf36e2006-02-24 17:54:30 +00001517 } else {
1518 if (copy_links)
1519 argstr[x++] = 'L';
1520 if (copy_dirlinks)
1521 argstr[x++] = 'k';
Wayne Davison35bf8fa2006-01-26 22:28:08 +00001522 }
Martin Pool1bfbf402002-03-19 03:21:53 +00001523
Wayne Davisondfa32482003-03-21 18:58:50 +00001524 if (whole_file > 0)
Andrew Tridgelld8537831998-07-17 10:00:43 +00001525 argstr[x++] = 'W';
Martin Poolbceec822002-03-19 03:39:42 +00001526 /* We don't need to send --no-whole-file, because it's the
1527 * default for remote transfers, and in any case old versions
1528 * of rsync will not understand it. */
Wayne Davisondfa32482003-03-21 18:58:50 +00001529
Andrew Tridgelld8537831998-07-17 10:00:43 +00001530 if (preserve_hard_links)
1531 argstr[x++] = 'H';
1532 if (preserve_uid)
1533 argstr[x++] = 'o';
1534 if (preserve_gid)
1535 argstr[x++] = 'g';
Wayne Davisonb5c6a6a2006-01-26 10:38:58 +00001536 if (preserve_devices) /* ignore preserve_specials here */
Andrew Tridgelld8537831998-07-17 10:00:43 +00001537 argstr[x++] = 'D';
1538 if (preserve_times)
1539 argstr[x++] = 't';
1540 if (preserve_perms)
1541 argstr[x++] = 'p';
Wayne Davison344f9ba2006-01-31 02:29:58 +00001542 else if (preserve_executability && am_sender)
1543 argstr[x++] = 'E';
Wayne Davisonaa7a6e82005-03-14 17:30:13 +00001544 if (recurse)
Andrew Tridgelld8537831998-07-17 10:00:43 +00001545 argstr[x++] = 'r';
1546 if (always_checksum)
1547 argstr[x++] = 'c';
1548 if (cvs_exclude)
1549 argstr[x++] = 'C';
1550 if (ignore_times)
1551 argstr[x++] = 'I';
1552 if (relative_paths)
1553 argstr[x++] = 'R';
Wayne Davison243c9952006-01-21 00:36:15 +00001554 if (one_file_system) {
Andrew Tridgelld8537831998-07-17 10:00:43 +00001555 argstr[x++] = 'x';
Wayne Davison243c9952006-01-21 00:36:15 +00001556 if (one_file_system > 1)
1557 argstr[x++] = 'x';
1558 }
Andrew Tridgelld8537831998-07-17 10:00:43 +00001559 if (sparse_files)
1560 argstr[x++] = 'S';
1561 if (do_compression)
1562 argstr[x++] = 'z';
Andrew Tridgellf0b36a42000-08-29 04:46:27 +00001563
Wayne Davison51d48392005-01-22 22:48:34 +00001564 /* This is a complete hack - blame Rusty. FIXME!
1565 * This hack is only needed for older rsync versions that
1566 * don't understand the --list-only option. */
Wayne Davisonda2a6c12005-03-17 00:52:33 +00001567 if (list_only == 1 && !recurse)
Andrew Tridgellf0b36a42000-08-29 04:46:27 +00001568 argstr[x++] = 'r';
1569
Wayne Davisonf5a910d2006-01-21 19:52:55 +00001570 argstr[x] = '\0';
Andrew Tridgell7a6421f1998-05-10 07:25:40 +00001571
Wayne Davisonf98c60b2004-02-09 18:10:57 +00001572 if (x != 1)
1573 args[ac++] = argstr;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +00001574
Wayne Davison51d48392005-01-22 22:48:34 +00001575 if (list_only > 1)
1576 args[ac++] = "--list-only";
1577
Wayne Davisonf5a910d2006-01-21 19:52:55 +00001578 /* This makes sure that the remote rsync can handle deleting with -d
1579 * sans -r because the --no-r option was added at the same time. */
1580 if (xfer_dirs && !recurse && delete_mode && am_sender)
1581 args[ac++] = "--no-r";
1582
Wayne Davison854a1aa2005-10-26 16:47:15 +00001583 if (do_compression && def_compress_level != Z_DEFAULT_COMPRESSION) {
1584 if (asprintf(&arg, "--compress-level=%d", def_compress_level) < 0)
1585 goto oom;
1586 args[ac++] = arg;
1587 }
1588
Wayne Davisonb5c6a6a2006-01-26 10:38:58 +00001589 if (preserve_devices) {
1590 /* Note: sending "--devices" would not be backward-compatible. */
1591 if (!preserve_specials)
1592 args[ac++] = "--no-specials"; /* -D is already set. */
1593 } else if (preserve_specials)
1594 args[ac++] = "--specials";
1595
Wayne Davison5c5e1592005-02-19 03:54:11 +00001596 /* The server side doesn't use our log-format, but in certain
1597 * circumstances they need to know a little about the option. */
Wayne Davisonb3e4e7e2006-05-29 22:56:45 +00001598 if (stdout_format && am_sender) {
1599 /* Use --log-format, not --out-format, for compatibility. */
1600 if (stdout_format_has_i > 1)
Wayne Davison487094a2006-01-20 18:49:07 +00001601 args[ac++] = "--log-format=%i%I";
Wayne Davisonb3e4e7e2006-05-29 22:56:45 +00001602 else if (stdout_format_has_i)
Wayne Davison684d7582005-02-19 22:16:39 +00001603 args[ac++] = "--log-format=%i";
Wayne Davisonb3e4e7e2006-05-29 22:56:45 +00001604 else if (stdout_format_has_o_or_i)
Wayne Davison5c5e1592005-02-19 03:54:11 +00001605 args[ac++] = "--log-format=%o";
1606 else if (!verbose)
1607 args[ac++] = "--log-format=X";
1608 }
Wayne Davison1f30a672005-02-19 02:39:30 +00001609
J.W. Schultz195bd902003-04-10 02:04:58 +00001610 if (block_size) {
Wayne Davisona06b4192005-01-01 21:08:14 +00001611 if (asprintf(&arg, "-B%lu", block_size) < 0)
Wayne Davisonf98c60b2004-02-09 18:10:57 +00001612 goto oom;
1613 args[ac++] = arg;
Wayne Davisondfa32482003-03-21 18:58:50 +00001614 }
Andrew Tridgell7a6421f1998-05-10 07:25:40 +00001615
Andrew Tridgell0b73ca12000-01-23 11:43:04 +00001616 if (max_delete && am_sender) {
Wayne Davisonf98c60b2004-02-09 18:10:57 +00001617 if (asprintf(&arg, "--max-delete=%d", max_delete) < 0)
1618 goto oom;
1619 args[ac++] = arg;
Wayne Davisondfa32482003-03-21 18:58:50 +00001620 }
1621
Wayne Davison74de13d2005-10-14 20:15:18 +00001622 if (min_size && am_sender) {
1623 args[ac++] = "--min-size";
1624 args[ac++] = min_size_arg;
1625 }
1626
Wayne Davison7d5acf12004-11-11 01:45:25 +00001627 if (max_size && am_sender) {
1628 args[ac++] = "--max-size";
1629 args[ac++] = max_size_arg;
1630 }
1631
Andrew Tridgelld8537831998-07-17 10:00:43 +00001632 if (io_timeout) {
Wayne Davisonf98c60b2004-02-09 18:10:57 +00001633 if (asprintf(&arg, "--timeout=%d", io_timeout) < 0)
1634 goto oom;
1635 args[ac++] = arg;
Wayne Davisondfa32482003-03-21 18:58:50 +00001636 }
Andrew Tridgell7a6421f1998-05-10 07:25:40 +00001637
David Dykstraef5d23e2000-06-06 21:13:05 +00001638 if (bwlimit) {
Wayne Davisonf98c60b2004-02-09 18:10:57 +00001639 if (asprintf(&arg, "--bwlimit=%d", bwlimit) < 0)
1640 goto oom;
1641 args[ac++] = arg;
David Dykstraef5d23e2000-06-06 21:13:05 +00001642 }
1643
Wayne Davisond175d7e2003-08-01 07:58:44 +00001644 if (backup_dir) {
1645 args[ac++] = "--backup-dir";
1646 args[ac++] = backup_dir;
1647 }
1648
1649 /* Only send --suffix if it specifies a non-default value. */
Wayne Davisonf98c60b2004-02-09 18:10:57 +00001650 if (strcmp(backup_suffix, backup_dir ? "" : BACKUP_SUFFIX) != 0) {
Wayne Davison191e40d2003-08-01 20:19:51 +00001651 /* We use the following syntax to avoid weirdness with '~'. */
Wayne Davisonf98c60b2004-02-09 18:10:57 +00001652 if (asprintf(&arg, "--suffix=%s", backup_suffix) < 0)
1653 goto oom;
1654 args[ac++] = arg;
Andrew Tridgelld8537831998-07-17 10:00:43 +00001655 }
Andrew Tridgell7a6421f1998-05-10 07:25:40 +00001656
Wayne Davison06a50542004-08-02 05:00:30 +00001657 if (am_sender) {
1658 if (delete_excluded)
1659 args[ac++] = "--delete-excluded";
Wayne Davisonc6eb7fa2005-01-28 07:39:09 +00001660 else if (delete_before == 1 || delete_after)
Wayne Davison06a50542004-08-02 05:00:30 +00001661 args[ac++] = "--delete";
Wayne Davison57f74bd2005-01-28 07:50:00 +00001662 if (delete_before > 1)
Wayne Davisonc6eb7fa2005-01-28 07:39:09 +00001663 args[ac++] = "--delete-before";
Wayne Davison3359acb2005-01-25 03:08:58 +00001664 if (delete_during)
1665 args[ac++] = "--delete-during";
Wayne Davison06a50542004-08-02 05:00:30 +00001666 if (delete_after)
1667 args[ac++] = "--delete-after";
Wayne Davison06a50542004-08-02 05:00:30 +00001668 if (force_delete)
1669 args[ac++] = "--force";
Wayne Davison11e758a2005-04-09 18:59:47 +00001670 if (write_batch < 0)
1671 args[ac++] = "--only-write-batch=X";
Wayne Davisondef97ff2006-01-26 11:10:32 +00001672 if (am_root > 1)
1673 args[ac++] = "--super";
Wayne Davisonf17e7692006-02-09 01:15:04 +00001674 if (size_only)
1675 args[ac++] = "--size-only";
Wayne Davison06a50542004-08-02 05:00:30 +00001676 }
David Dykstrab33b7911999-02-22 19:55:57 +00001677
Andrew Tridgell5b56cc12000-09-06 02:12:13 +00001678 if (modify_window_set) {
Wayne Davisonf98c60b2004-02-09 18:10:57 +00001679 if (asprintf(&arg, "--modify-window=%d", modify_window) < 0)
1680 goto oom;
1681 args[ac++] = arg;
Andrew Tridgell5b56cc12000-09-06 02:12:13 +00001682 }
1683
Wayne Davisonc8d895d2004-05-21 09:44:32 +00001684 if (checksum_seed) {
Wayne Davison221ddb92004-05-22 06:09:22 +00001685 if (asprintf(&arg, "--checksum-seed=%d", checksum_seed) < 0)
Wayne Davisonc8d895d2004-05-21 09:44:32 +00001686 goto oom;
1687 args[ac++] = arg;
1688 }
1689
Wayne Davisona7260c42004-07-29 16:06:38 +00001690 if (partial_dir && am_sender) {
Wayne Davison77860ba2006-01-29 19:17:13 +00001691 if (partial_dir != tmp_partialdir) {
Wayne Davison36719872005-02-11 10:42:55 +00001692 args[ac++] = "--partial-dir";
1693 args[ac++] = partial_dir;
1694 }
Wayne Davisonf06e7082005-01-27 22:46:14 +00001695 if (delay_updates)
1696 args[ac++] = "--delay-updates";
Wayne Davison77860ba2006-01-29 19:17:13 +00001697 } else if (keep_partial && am_sender)
Andrew Tridgelld8537831998-07-17 10:00:43 +00001698 args[ac++] = "--partial";
Andrew Tridgellc95da961998-07-01 03:36:03 +00001699
Andrew Tridgellef55c682000-03-21 04:06:04 +00001700 if (ignore_errors)
1701 args[ac++] = "--ignore-errors";
1702
David Dykstrab5313601999-02-17 19:34:40 +00001703 if (copy_unsafe_links)
1704 args[ac++] = "--copy-unsafe-links";
1705
Andrew Tridgelld8537831998-07-17 10:00:43 +00001706 if (safe_symlinks)
1707 args[ac++] = "--safe-links";
Andrew Tridgell7a6421f1998-05-10 07:25:40 +00001708
Andrew Tridgelld8537831998-07-17 10:00:43 +00001709 if (numeric_ids)
1710 args[ac++] = "--numeric-ids";
Andrew Tridgell7a6421f1998-05-10 07:25:40 +00001711
Wayne Davisone90aab42005-09-29 18:07:55 +00001712 if (ignore_existing && am_sender)
Martin Pool3d6fead2002-01-25 10:42:23 +00001713 args[ac++] = "--ignore-existing";
1714
Wayne Davisone90aab42005-09-29 18:07:55 +00001715 /* Backward compatibility: send --existing, not --ignore-non-existing. */
1716 if (ignore_non_existing && am_sender)
1717 args[ac++] = "--existing";
1718
Wayne Davisona0157882005-07-28 01:46:09 +00001719 if (append_mode)
1720 args[ac++] = "--append";
1721 else if (inplace)
Wayne Davisona3221d22004-07-16 20:06:24 +00001722 args[ac++] = "--inplace";
1723
Wayne Davison120cde92006-01-29 07:19:38 +00001724 if (tmpdir && am_sender) {
Andrew Tridgelld8537831998-07-17 10:00:43 +00001725 args[ac++] = "--temp-dir";
1726 args[ac++] = tmpdir;
1727 }
1728
Wayne Davisone012f852004-11-27 17:52:51 +00001729 if (basis_dir[0] && am_sender) {
David Dykstra375a4551998-10-26 21:42:38 +00001730 /* the server only needs this option if it is not the sender,
1731 * and it may be an older version that doesn't know this
1732 * option, so don't send it if client is the sender.
1733 */
Wayne Davisone012f852004-11-27 17:52:51 +00001734 int i;
1735 for (i = 0; i < basis_dir_cnt; i++) {
1736 args[ac++] = dest_option;
1737 args[ac++] = basis_dir[i];
1738 }
David Dykstra375a4551998-10-26 21:42:38 +00001739 }
1740
Wayne Davison305666b2005-03-01 01:15:57 +00001741 if (files_from && (!am_sender || filesfrom_host)) {
1742 if (filesfrom_host) {
Wayne Davisonea5164d2003-03-30 23:00:42 +00001743 args[ac++] = "--files-from";
Wayne Davison305666b2005-03-01 01:15:57 +00001744 args[ac++] = files_from;
Wayne Davisonea5164d2003-03-30 23:00:42 +00001745 if (eol_nulls)
1746 args[ac++] = "--from0";
1747 } else {
1748 args[ac++] = "--files-from=-";
1749 args[ac++] = "--from0";
1750 }
Wayne Davisonc0ab28d2004-12-22 09:10:08 +00001751 if (!relative_paths)
1752 args[ac++] = "--no-relative";
Wayne Davisonea5164d2003-03-30 23:00:42 +00001753 }
Wayne Davison89f2a4c2005-07-22 19:05:25 +00001754 if (relative_paths && !implied_dirs && !am_sender)
Wayne Davison3a90ea02005-01-19 00:23:32 +00001755 args[ac++] = "--no-implied-dirs";
Wayne Davisonea5164d2003-03-30 23:00:42 +00001756
Wayne Davisonc4ed1482005-02-14 02:41:15 +00001757 if (fuzzy_basis && am_sender)
1758 args[ac++] = "--fuzzy";
1759
Wayne Davison47c11972006-06-30 15:52:52 +00001760 if (remove_source_files == 1)
1761 args[ac++] = "--remove-source-files";
1762 else if (remove_source_files)
Wayne Davison07c6ae72005-02-20 01:04:40 +00001763 args[ac++] = "--remove-sent-files";
1764
Andrew Tridgelld8537831998-07-17 10:00:43 +00001765 *argc = ac;
Wayne Davisonf98c60b2004-02-09 18:10:57 +00001766 return;
1767
1768 oom:
1769 out_of_memory("server_options");
Andrew Tridgell7a6421f1998-05-10 07:25:40 +00001770}
1771
Wayne Davison305666b2005-03-01 01:15:57 +00001772/* Look for a HOST specfication of the form "HOST:PATH", "HOST::PATH", or
1773 * "rsync://HOST:PORT/PATH". If found, *host_ptr will be set to some allocated
1774 * memory with the HOST. If a daemon-accessing spec was specified, the value
1775 * of *port_ptr will contain a non-0 port number, otherwise it will be set to
1776 * 0. The return value is a pointer to the PATH. Note that the HOST spec can
1777 * be an IPv6 literal address enclosed in '[' and ']' (such as "[::1]" or
1778 * "[::ffff:127.0.0.1]") which is returned without the '[' and ']'. */
1779char *check_for_hostspec(char *s, char **host_ptr, int *port_ptr)
Wayne Davisonea5164d2003-03-30 23:00:42 +00001780{
Wayne Davison305666b2005-03-01 01:15:57 +00001781 char *p;
1782 int not_host;
Wayne Davison8f4ae682006-09-18 17:39:13 +00001783 int hostlen;
Wayne Davisonea5164d2003-03-30 23:00:42 +00001784
Wayne Davison305666b2005-03-01 01:15:57 +00001785 if (port_ptr && strncasecmp(URL_PREFIX, s, strlen(URL_PREFIX)) == 0) {
1786 char *path;
Wayne Davison305666b2005-03-01 01:15:57 +00001787 s += strlen(URL_PREFIX);
1788 if ((p = strchr(s, '/')) != NULL) {
1789 hostlen = p - s;
1790 path = p + 1;
1791 } else {
1792 hostlen = strlen(s);
1793 path = "";
1794 }
1795 if (*s == '[' && (p = strchr(s, ']')) != NULL) {
1796 s++;
1797 hostlen = p - s;
Wayne Davisonc60b7052005-03-01 05:49:11 +00001798 if (p[1] == ':')
1799 *port_ptr = atoi(p+2);
Wayne Davison305666b2005-03-01 01:15:57 +00001800 } else {
1801 if ((p = strchr(s, ':')) != NULL) {
1802 hostlen = p - s;
1803 *port_ptr = atoi(p+1);
Wayne Davisonc60b7052005-03-01 05:49:11 +00001804 }
Wayne Davison305666b2005-03-01 01:15:57 +00001805 }
Wayne Davisonc60b7052005-03-01 05:49:11 +00001806 if (!*port_ptr)
1807 *port_ptr = RSYNC_PORT;
Wayne Davison305666b2005-03-01 01:15:57 +00001808 *host_ptr = new_array(char, hostlen + 1);
1809 strlcpy(*host_ptr, s, hostlen + 1);
1810 return path;
1811 }
Wayne Davisonea5164d2003-03-30 23:00:42 +00001812
Wayne Davison305666b2005-03-01 01:15:57 +00001813 if (*s == '[' && (p = strchr(s, ']')) != NULL && p[1] == ':') {
Wayne Davison8f4ae682006-09-18 17:39:13 +00001814 s++;
1815 hostlen = p - s;
Wayne Davison305666b2005-03-01 01:15:57 +00001816 *p = '\0';
1817 not_host = strchr(s, '/') || !strchr(s, ':');
1818 *p = ']';
1819 if (not_host)
1820 return NULL;
Wayne Davisonc60b7052005-03-01 05:49:11 +00001821 p++;
Wayne Davison305666b2005-03-01 01:15:57 +00001822 } else {
1823 if (!(p = strchr(s, ':')))
1824 return NULL;
Wayne Davison8f4ae682006-09-18 17:39:13 +00001825 hostlen = p - s;
Wayne Davison305666b2005-03-01 01:15:57 +00001826 *p = '\0';
1827 not_host = strchr(s, '/') != NULL;
1828 *p = ':';
1829 if (not_host)
1830 return NULL;
1831 }
Wayne Davisonea5164d2003-03-30 23:00:42 +00001832
Wayne Davison8f4ae682006-09-18 17:39:13 +00001833 *host_ptr = new_array(char, hostlen + 1);
1834 strlcpy(*host_ptr, s, hostlen + 1);
Wayne Davison305666b2005-03-01 01:15:57 +00001835
1836 if (p[1] == ':') {
1837 if (port_ptr && !*port_ptr)
1838 *port_ptr = RSYNC_PORT;
1839 return p + 2;
1840 }
1841 if (port_ptr)
1842 *port_ptr = 0;
1843
1844 return p + 1;
Wayne Davisonea5164d2003-03-30 23:00:42 +00001845}