blob: b0100678b3bf532bccf9478d0f13ab38d1fabefd [file] [log] [blame]
Wayne Davison0f78b812006-04-25 20:23:34 +00001/*
2 * Command-line (and received via daemon-socket) option parsing.
Wayne Davisondfa32482003-03-21 18:58:50 +00003 *
Wayne Davison0f78b812006-04-25 20:23:34 +00004 * Copyright (C) 1998-2001 Andrew Tridgell <tridge@samba.org>
5 * Copyright (C) 2000, 2001, 2002 Martin Pool <mbp@samba.org>
Wayne Davison559bd2f2011-01-01 11:27:40 -08006 * Copyright (C) 2002-2011 Wayne Davison
Wayne Davisondfa32482003-03-21 18:58:50 +00007 *
Martin Pooldafe63c2002-04-16 01:38:21 +00008 * This program is free software; you can redistribute it and/or modify
Wayne Davison8e41b682007-07-10 13:55:49 +00009 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
Wayne Davisondfa32482003-03-21 18:58:50 +000012 *
Martin Pooldafe63c2002-04-16 01:38:21 +000013 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
Wayne Davisondfa32482003-03-21 18:58:50 +000017 *
Wayne Davisone7c67062006-04-25 23:51:12 +000018 * You should have received a copy of the GNU General Public License along
Wayne Davison4fd842f2007-07-07 05:33:14 +000019 * with this program; if not, visit the http://fsf.org website.
Martin Pooldafe63c2002-04-16 01:38:21 +000020 */
Andrew Tridgell7a6421f1998-05-10 07:25:40 +000021
Andrew Tridgell7a6421f1998-05-10 07:25:40 +000022#include "rsync.h"
Wayne Davison1b42f622007-09-22 16:52:58 +000023#include "ifuncs.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 Davison53936ef2008-03-15 11:25:01 -070028extern int local_server;
Wayne Davison7be73df2004-03-27 09:46:42 +000029extern int sanitize_paths;
Wayne Davisone2086312007-08-11 16:53:31 +000030extern int daemon_over_rsh;
Wayne Davisona1018692007-12-16 14:16:37 -080031extern unsigned int module_dirlen;
Wayne Davison78424182005-01-25 10:39:14 +000032extern struct filter_list_struct filter_list;
Wayne Davison819bfe42008-03-20 10:42:43 -070033extern struct filter_list_struct daemon_filter_list;
Wayne Davison8645af12003-07-01 21:45:23 +000034
Andrew Tridgell7a6421f1998-05-10 07:25:40 +000035int make_backups = 0;
Martin Pool1bfbf402002-03-19 03:21:53 +000036
37/**
Wayne Davisondfa32482003-03-21 18:58:50 +000038 * If 1, send the whole file as literal data rather than trying to
Martin Pooldafe63c2002-04-16 01:38:21 +000039 * create an incremental diff.
Martin Pool1bfbf402002-03-19 03:21:53 +000040 *
Wayne Davisondfa32482003-03-21 18:58:50 +000041 * If -1, then look at whether we're local or remote and go by that.
Martin Pooldafe63c2002-04-16 01:38:21 +000042 *
43 * @sa disable_deltas_p()
Martin Pool1bfbf402002-03-19 03:21:53 +000044 **/
Wayne Davisondfa32482003-03-21 18:58:50 +000045int whole_file = -1;
Martin Pool1bfbf402002-03-19 03:21:53 +000046
Wayne Davisona0157882005-07-28 01:46:09 +000047int append_mode = 0;
Wayne Davison716e73d2004-06-05 16:16:30 +000048int keep_dirlinks = 0;
Wayne Davison2dbf36e2006-02-24 17:54:30 +000049int copy_dirlinks = 0;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +000050int copy_links = 0;
51int preserve_links = 0;
52int preserve_hard_links = 0;
Wayne Davison1c3344a2007-03-11 00:13:34 +000053int preserve_acls = 0;
Wayne Davison16edf862007-04-07 17:22:25 +000054int preserve_xattrs = 0;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +000055int preserve_perms = 0;
Wayne Davison344f9ba2006-01-31 02:29:58 +000056int preserve_executability = 0;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +000057int preserve_devices = 0;
Wayne Davisonb5c6a6a2006-01-26 10:38:58 +000058int preserve_specials = 0;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +000059int preserve_uid = 0;
60int preserve_gid = 0;
61int preserve_times = 0;
62int update_only = 0;
63int cvs_exclude = 0;
Wayne Davisona5c11132004-02-09 17:45:22 +000064int dry_run = 0;
Wayne Davison11e758a2005-04-09 18:59:47 +000065int do_xfers = 1;
Wayne Davisona5c11132004-02-09 17:45:22 +000066int ignore_times = 0;
67int delete_mode = 0;
Wayne Davisona51b3162005-01-24 01:41:54 +000068int delete_during = 0;
Wayne Davison51d48392005-01-22 22:48:34 +000069int delete_before = 0;
70int delete_after = 0;
Wayne Davisona5c11132004-02-09 17:45:22 +000071int delete_excluded = 0;
Wayne Davison47c11972006-06-30 15:52:52 +000072int remove_source_files = 0;
Wayne Davisona5c11132004-02-09 17:45:22 +000073int one_file_system = 0;
Wayne Davison4f3e9a02003-09-09 15:58:56 +000074int protocol_version = PROTOCOL_VERSION;
Wayne Davisona5c11132004-02-09 17:45:22 +000075int sparse_files = 0;
76int do_compression = 0;
Wayne Davison854a1aa2005-10-26 16:47:15 +000077int def_compress_level = Z_DEFAULT_COMPRESSION;
Wayne Davison9439c0c2007-04-24 07:32:44 +000078int am_root = 0; /* 0 = normal, 1 = root, 2 = --super, -1 = --fake-super */
Wayne Davison7f2a1f62005-02-25 17:08:31 +000079int am_server = 0;
80int am_sender = 0;
Wayne Davison7f2a1f62005-02-25 17:08:31 +000081int am_starting_up = 1;
Wayne Davisonea5164d2003-03-30 23:00:42 +000082int relative_paths = -1;
83int implied_dirs = 1;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +000084int numeric_ids = 0;
Wayne Davison5974c662006-02-06 18:41:32 +000085int allow_8bit_chars = 0;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +000086int force_delete = 0;
87int io_timeout = 0;
Wayne Davison876c9932006-01-28 00:13:55 +000088int prune_empty_dirs = 0;
Wayne Davison8487f9c2007-05-24 02:50:35 +000089int use_qsort = 0;
Wayne Davisonea5164d2003-03-30 23:00:42 +000090char *files_from = NULL;
91int filesfrom_fd = -1;
Wayne Davison305666b2005-03-01 01:15:57 +000092char *filesfrom_host = NULL;
Wayne Davisonea5164d2003-03-30 23:00:42 +000093int eol_nulls = 0;
Wayne Davison7a4adda2007-09-09 07:53:18 +000094int protect_args = 0;
Wayne Davison8f14cc42005-11-12 19:53:17 +000095int human_readable = 0;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +000096int recurse = 0;
Wayne Davison52750292007-03-14 00:00:01 +000097int allow_inc_recurse = 1;
Wayne Davisonb6164932005-08-27 21:01:45 +000098int xfer_dirs = -1;
Wayne Davison1312d9f2002-08-01 00:37:01 +000099int am_daemon = 0;
Wayne Davisona5c11132004-02-09 17:45:22 +0000100int do_stats = 0;
101int do_progress = 0;
Wayne Davisonba22c9e2007-11-28 00:28:26 -0800102int connect_timeout = 0;
Wayne Davisona5c11132004-02-09 17:45:22 +0000103int keep_partial = 0;
104int safe_symlinks = 0;
105int copy_unsafe_links = 0;
106int size_only = 0;
Wayne Davison9fb08442004-11-17 19:29:20 +0000107int daemon_bwlimit = 0;
Wayne Davisona5c11132004-02-09 17:45:22 +0000108int bwlimit = 0;
Wayne Davisonc4ed1482005-02-14 02:41:15 +0000109int fuzzy_basis = 0;
Wayne Davison3c74c3a2004-05-27 21:51:53 +0000110size_t bwlimit_writemax = 0;
Wayne Davisone90aab42005-09-29 18:07:55 +0000111int ignore_existing = 0;
112int ignore_non_existing = 0;
Wayne Davison07c6ae72005-02-20 01:04:40 +0000113int need_messages_from_generator = 0;
Wayne Davison7b9598b2007-07-15 05:42:30 +0000114int max_delete = INT_MIN;
Wayne Davison7d5acf12004-11-11 01:45:25 +0000115OFF_T max_size = 0;
Wayne Davison74de13d2005-10-14 20:15:18 +0000116OFF_T min_size = 0;
Wayne Davisona5c11132004-02-09 17:45:22 +0000117int ignore_errors = 0;
118int modify_window = 0;
119int blocking_io = -1;
Wayne Davison2289bf62004-02-09 18:32:54 +0000120int checksum_seed = 0;
Wayne Davisona3221d22004-07-16 20:06:24 +0000121int inplace = 0;
Wayne Davisonf06e7082005-01-27 22:46:14 +0000122int delay_updates = 0;
Wayne Davisona06b4192005-01-01 21:08:14 +0000123long block_size = 0; /* "long" because popt can't set an int32. */
Wayne Davisonb1e436e2007-07-14 19:24:32 +0000124char *skip_compress = NULL;
Martin Poolb35d0d82002-04-08 04:10:20 +0000125
Martin Pool13e29992001-12-18 05:54:57 +0000126/** Network address family. **/
Wayne Davison24d677f2007-08-22 00:36:56 +0000127int default_af_hint
Wayne Davison4f5b0752005-02-14 00:53:43 +0000128#ifdef INET6
Wayne Davison24d677f2007-08-22 00:36:56 +0000129 = 0; /* Any protocol */
David Dykstra6ab6d4b2001-12-14 18:25:51 +0000130#else
Wayne Davison24d677f2007-08-22 00:36:56 +0000131 = AF_INET; /* Must use IPv4 */
132# ifdef AF_INET6
133# undef AF_INET6
134# endif
135# define AF_INET6 AF_INET /* make -6 option a no-op */
David Dykstra6ab6d4b2001-12-14 18:25:51 +0000136#endif
Martin Pool06963d02001-11-23 07:35:49 +0000137
Martin Pool13e29992001-12-18 05:54:57 +0000138/** Do not go into the background when run as --daemon. Good
139 * for debugging and required for running as a service on W32,
140 * or under Unix process-monitors. **/
Wayne Davison1f35bab2005-02-21 00:31:31 +0000141int no_detach
142#if defined _WIN32 || defined __WIN32__
143 = 1;
144#else
145 = 0;
146#endif
Martin Pool13e29992001-12-18 05:54:57 +0000147
David Dykstra088aac82002-02-06 21:20:48 +0000148int write_batch = 0;
149int read_batch = 0;
Wayne Davisond175d7e2003-08-01 07:58:44 +0000150int backup_dir_len = 0;
151int backup_suffix_len;
Wayne Davisone0391f82004-02-11 04:30:41 +0000152unsigned int backup_dir_remainder;
Martin Pool6902ed12001-08-14 02:04:47 +0000153
Wayne Davisond175d7e2003-08-01 07:58:44 +0000154char *backup_suffix = NULL;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +0000155char *tmpdir = NULL;
Wayne Davisona7260c42004-07-29 16:06:38 +0000156char *partial_dir = NULL;
Wayne Davisone012f852004-11-27 17:52:51 +0000157char *basis_dir[MAX_BASIS_DIRS+1];
David Dykstra30e8c8e2002-08-30 23:27:26 +0000158char *config_file = NULL;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +0000159char *shell_cmd = NULL;
Wayne Davison87c0f9d2006-05-09 18:31:03 +0000160char *logfile_name = NULL;
161char *logfile_format = NULL;
Wayne Davisonb3e4e7e2006-05-29 22:56:45 +0000162char *stdout_format = NULL;
Andrew Tridgell65575e91999-01-08 10:32:56 +0000163char *password_file = NULL;
David Dykstra41bd28f2001-06-12 19:33:41 +0000164char *rsync_path = RSYNC_PATH;
Andrew Tridgell66203a92000-01-24 04:58:53 +0000165char *backup_dir = NULL;
Wayne Davisone0391f82004-02-11 04:30:41 +0000166char backup_dir_buf[MAXPATHLEN];
Wayne Davison831f06a2006-01-26 12:31:24 +0000167char *sockopts = NULL;
Wayne Davison0c56b1a2004-11-27 18:24:12 +0000168int rsync_port = 0;
Wayne Davisondfd7d542005-01-15 20:54:25 +0000169int compare_dest = 0;
Wayne Davison1de3e992005-03-11 17:35:59 +0000170int copy_dest = 0;
David Dykstra59c95e42002-08-29 14:44:55 +0000171int link_dest = 0;
Wayne Davisonce0b3842005-01-15 21:12:58 +0000172int basis_dir_cnt = 0;
Wayne Davisonf9a9f542005-03-09 18:53:53 +0000173char *dest_option = NULL;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +0000174
175int verbose = 0;
David Dykstrab86f0ce1999-02-09 17:25:35 +0000176int quiet = 0;
Wayne Davisondc1f7b92006-10-24 00:36:38 +0000177int output_motd = 1;
Wayne Davisone7651882005-02-16 08:10:31 +0000178int log_before_transfer = 0;
Wayne Davisonb3e4e7e2006-05-29 22:56:45 +0000179int stdout_format_has_i = 0;
180int stdout_format_has_o_or_i = 0;
Wayne Davison87c0f9d2006-05-09 18:31:03 +0000181int logfile_format_has_i = 0;
Wayne Davison87c0f9d2006-05-09 18:31:03 +0000182int logfile_format_has_o_or_i = 0;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +0000183int always_checksum = 0;
Andrew Tridgellf7632fc1998-11-02 00:52:01 +0000184int list_only = 0;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +0000185
Wayne Davison9b3318b2004-07-15 16:27:02 +0000186#define MAX_BATCH_NAME_LEN 256 /* Must be less than MAXPATHLEN-13 */
187char *batch_name = NULL;
Martin Pool6902ed12001-08-14 02:04:47 +0000188
Wayne Davison332cf6d2007-04-26 05:53:13 +0000189int need_unsorted_flist = 0;
Wayne Davisonf7a76b92007-11-06 15:25:02 +0000190#ifdef ICONV_OPTION
Wayne Davison332cf6d2007-04-26 05:53:13 +0000191char *iconv_opt = ICONV_OPTION;
192#endif
193
Wayne Davisondd32e2c2005-11-07 04:28:35 +0000194struct chmod_mode_struct *chmod_modes = NULL;
195
Wayne Davisone1add892004-02-01 17:29:41 +0000196static int daemon_opt; /* sets am_daemon after option error-reporting */
Wayne Davisonf9998042007-09-01 16:57:01 +0000197static int omit_dir_times = 0;
Wayne Davisonaa4d3b42005-01-25 00:52:56 +0000198static int F_option_cnt = 0;
Andrew Tridgell5b56cc12000-09-06 02:12:13 +0000199static int modify_window_set;
Wayne Davison624d6be2005-03-31 00:21:15 +0000200static int itemize_changes = 0;
Wayne Davison854a1aa2005-10-26 16:47:15 +0000201static int refused_delete, refused_archive_part, refused_compress;
Wayne Davison3296f912005-02-15 21:15:58 +0000202static int refused_partial, refused_progress, refused_delete_before;
Wayne Davisone0e32032006-12-28 07:54:10 +0000203static int refused_delete_during;
Wayne Davison0b52f942008-02-14 13:24:16 -0800204static int refused_inplace, refused_no_iconv;
Wayne Davison74de13d2005-10-14 20:15:18 +0000205static char *max_size_arg, *min_size_arg;
Wayne Davison77860ba2006-01-29 19:17:13 +0000206static char tmp_partialdir[] = ".~tmp~";
Andrew Tridgell5b56cc12000-09-06 02:12:13 +0000207
Martin Pool06963d02001-11-23 07:35:49 +0000208/** Local address to bind. As a character string because it's
Wayne Davisonfdf57ed2004-06-20 19:47:05 +0000209 * interpreted by the IPv6 layer: should be a numeric IP4 or IP6
Martin Pool06963d02001-11-23 07:35:49 +0000210 * address, or a hostname. **/
211char *bind_address;
Andrew Tridgell5c9730a1999-10-31 03:21:02 +0000212
Martin Pool7a24c342000-11-09 09:05:14 +0000213
Martin Pool27a12342001-12-05 13:45:51 +0000214static void print_rsync_version(enum logcode f)
Martin Pool7a24c342000-11-09 09:05:14 +0000215{
Wayne Davison2ed790f2007-04-23 19:54:07 +0000216 char *subprotocol = "";
Wayne Davisondfa32482003-03-21 18:58:50 +0000217 char const *got_socketpair = "no ";
Wayne Davisona3221d22004-07-16 20:06:24 +0000218 char const *have_inplace = "no ";
Wayne Davisondfa32482003-03-21 18:58:50 +0000219 char const *hardlinks = "no ";
Wayne Davison1ed56a02008-02-18 14:10:13 -0800220 char const *symtimes = "no ";
Wayne Davison1c3344a2007-03-11 00:13:34 +0000221 char const *acls = "no ";
Wayne Davison16edf862007-04-07 17:22:25 +0000222 char const *xattrs = "no ";
Wayne Davisondfa32482003-03-21 18:58:50 +0000223 char const *links = "no ";
Wayne Davison332cf6d2007-04-26 05:53:13 +0000224 char const *iconv = "no ";
Martin Poola3584492001-11-24 04:57:41 +0000225 char const *ipv6 = "no ";
Martin Pool736a6a22002-01-11 07:15:16 +0000226 STRUCT_STAT *dumstat;
Martin Pool0c80cd82000-11-10 03:41:47 +0000227
Wayne Davison2ed790f2007-04-23 19:54:07 +0000228#if SUBPROTOCOL_VERSION != 0
Wayne Davison3082dff2008-11-09 18:55:14 -0800229 if (asprintf(&subprotocol, ".PR%d", SUBPROTOCOL_VERSION) < 0)
230 out_of_memory("print_rsync_version");
Wayne Davison2ed790f2007-04-23 19:54:07 +0000231#endif
Wayne Davison4f5b0752005-02-14 00:53:43 +0000232#ifdef HAVE_SOCKETPAIR
Wayne Davisondfa32482003-03-21 18:58:50 +0000233 got_socketpair = "";
Martin Pool0c80cd82000-11-10 03:41:47 +0000234#endif
Wayne Davison4f5b0752005-02-14 00:53:43 +0000235#ifdef HAVE_FTRUNCATE
Wayne Davisona3221d22004-07-16 20:06:24 +0000236 have_inplace = "";
237#endif
Wayne Davison4f5b0752005-02-14 00:53:43 +0000238#ifdef SUPPORT_HARD_LINKS
Wayne Davisondfa32482003-03-21 18:58:50 +0000239 hardlinks = "";
Martin Pool2855f612001-02-23 01:02:31 +0000240#endif
Wayne Davison1c3344a2007-03-11 00:13:34 +0000241#ifdef SUPPORT_ACLS
242 acls = "";
243#endif
Wayne Davison16edf862007-04-07 17:22:25 +0000244#ifdef SUPPORT_XATTRS
245 xattrs = "";
246#endif
Wayne Davison4f5b0752005-02-14 00:53:43 +0000247#ifdef SUPPORT_LINKS
Wayne Davisondfa32482003-03-21 18:58:50 +0000248 links = "";
Martin Pool2855f612001-02-23 01:02:31 +0000249#endif
Wayne Davison4f5b0752005-02-14 00:53:43 +0000250#ifdef INET6
Martin Poola3584492001-11-24 04:57:41 +0000251 ipv6 = "";
Wayne Davisondfa32482003-03-21 18:58:50 +0000252#endif
Wayne Davison332cf6d2007-04-26 05:53:13 +0000253#ifdef ICONV_OPTION
254 iconv = "";
255#endif
Wayne Davison8f48ba02011-02-21 09:48:37 -0800256#ifdef CAN_SET_SYMLINK_TIMES
Wayne Davison1ed56a02008-02-18 14:10:13 -0800257 symtimes = "";
258#endif
Martin Poola3584492001-11-24 04:57:41 +0000259
Wayne Davison719522b2007-04-21 19:46:19 +0000260 rprintf(f, "%s version %s protocol version %d%s\n",
Wayne Davison2ed790f2007-04-23 19:54:07 +0000261 RSYNC_NAME, RSYNC_VERSION, PROTOCOL_VERSION, subprotocol);
Wayne Davison559bd2f2011-01-01 11:27:40 -0800262 rprintf(f, "Copyright (C) 1996-2011 by Andrew Tridgell, Wayne Davison, and others.\n");
Wayne Davison719522b2007-04-21 19:46:19 +0000263 rprintf(f, "Web site: http://rsync.samba.org/\n");
264 rprintf(f, "Capabilities:\n");
265 rprintf(f, " %d-bit files, %d-bit inums, %d-bit timestamps, %d-bit long ints,\n",
Wayne Davisond619ff12006-12-01 18:29:18 +0000266 (int)(sizeof (OFF_T) * 8),
267 (int)(sizeof dumstat->st_ino * 8), /* Don't check ino_t! */
Wayne Davisonbb257792007-04-21 19:31:54 +0000268 (int)(sizeof (time_t) * 8),
Wayne Davisond619ff12006-12-01 18:29:18 +0000269 (int)(sizeof (int64) * 8));
270 rprintf(f, " %ssocketpairs, %shardlinks, %ssymlinks, %sIPv6, batchfiles, %sinplace,\n",
271 got_socketpair, hardlinks, links, ipv6, have_inplace);
Wayne Davison1ed56a02008-02-18 14:10:13 -0800272 rprintf(f, " %sappend, %sACLs, %sxattrs, %siconv, %ssymtimes\n",
273 have_inplace, acls, xattrs, iconv, symtimes);
Martin Pool2855f612001-02-23 01:02:31 +0000274
Martin Poolfc0302c2002-04-08 07:36:05 +0000275#ifdef MAINTAINER_MODE
Wayne Davison29433532006-02-02 11:40:32 +0000276 rprintf(f, "Panic Action: \"%s\"\n", get_panic_action());
Martin Poolfc0302c2002-04-08 07:36:05 +0000277#endif
Martin Pool736a6a22002-01-11 07:15:16 +0000278
Wayne Davison031fa9a2005-01-28 06:46:33 +0000279#if SIZEOF_INT64 < 8
280 rprintf(f, "WARNING: no 64-bit integers on this platform!\n");
Martin Pool7a24c342000-11-09 09:05:14 +0000281#endif
Wayne Davisonc561eda2005-01-28 06:51:44 +0000282 if (sizeof (int64) != SIZEOF_INT64) {
283 rprintf(f,
284 "WARNING: size mismatch in SIZEOF_INT64 define (%d != %d)\n",
285 (int) SIZEOF_INT64, (int) sizeof (int64));
286 }
Martin Pool7b329a22002-03-19 05:00:05 +0000287
Wayne Davisonb64ee912006-06-01 08:04:47 +0000288 rprintf(f,"\n");
289 rprintf(f,"rsync comes with ABSOLUTELY NO WARRANTY. This is free software, and you\n");
Wayne Davison6ab423a2006-01-17 04:26:12 +0000290 rprintf(f,"are welcome to redistribute it under certain conditions. See the GNU\n");
291 rprintf(f,"General Public Licence for details.\n");
Martin Pool7a24c342000-11-09 09:05:14 +0000292}
293
294
Andrew Tridgell0f3203c2000-01-29 02:49:03 +0000295void usage(enum logcode F)
Andrew Tridgell7a6421f1998-05-10 07:25:40 +0000296{
Martin Pool2855f612001-02-23 01:02:31 +0000297 print_rsync_version(F);
Andrew Tridgell704f9081998-06-18 09:31:42 +0000298
Wayne Davisonb64ee912006-06-01 08:04:47 +0000299 rprintf(F,"\n");
300 rprintf(F,"rsync is a file transfer program capable of efficient remote update\n");
Wayne Davison6ab423a2006-01-17 04:26:12 +0000301 rprintf(F,"via a fast differencing algorithm.\n");
Andrew Tridgell704f9081998-06-18 09:31:42 +0000302
Wayne Davisonb64ee912006-06-01 08:04:47 +0000303 rprintf(F,"\n");
304 rprintf(F,"Usage: rsync [OPTION]... SRC [SRC]... DEST\n");
Wayne Davison868676d2005-09-21 22:39:49 +0000305 rprintf(F," or rsync [OPTION]... SRC [SRC]... [USER@]HOST:DEST\n");
David Dykstra9ef53901999-02-10 19:33:05 +0000306 rprintf(F," or rsync [OPTION]... SRC [SRC]... [USER@]HOST::DEST\n");
Wayne Davisoneaa4c152002-08-01 17:55:11 +0000307 rprintf(F," or rsync [OPTION]... SRC [SRC]... rsync://[USER@]HOST[:PORT]/DEST\n");
Wayne Davison868676d2005-09-21 22:39:49 +0000308 rprintf(F," or rsync [OPTION]... [USER@]HOST:SRC [DEST]\n");
309 rprintf(F," or rsync [OPTION]... [USER@]HOST::SRC [DEST]\n");
310 rprintf(F," or rsync [OPTION]... rsync://[USER@]HOST[:PORT]/SRC [DEST]\n");
Wayne Davison08d82b82005-09-13 01:02:54 +0000311 rprintf(F,"The ':' usages connect via remote shell, while '::' & 'rsync://' usages connect\n");
312 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 +0000313 rprintf(F,"\n");
314 rprintf(F,"Options\n");
Andrew Tridgell704f9081998-06-18 09:31:42 +0000315 rprintf(F," -v, --verbose increase verbosity\n");
Wayne Davisonb3708ac2005-01-28 09:55:18 +0000316 rprintf(F," -q, --quiet suppress non-error messages\n");
Wayne Davisondc1f7b92006-10-24 00:36:38 +0000317 rprintf(F," --no-motd suppress daemon-mode MOTD (see manpage caveat)\n");
Wayne Davisonb3708ac2005-01-28 09:55:18 +0000318 rprintf(F," -c, --checksum skip based on checksum, not mod-time & size\n");
Wayne Davison16edf862007-04-07 17:22:25 +0000319 rprintf(F," -a, --archive archive mode; equals -rlptgoD (no -H,-A,-X)\n");
Wayne Davison8938d672005-11-15 07:05:55 +0000320 rprintf(F," --no-OPTION turn off an implied OPTION (e.g. --no-D)\n");
Andrew Tridgell704f9081998-06-18 09:31:42 +0000321 rprintf(F," -r, --recursive recurse into directories\n");
322 rprintf(F," -R, --relative use relative path names\n");
Wayne Davison11bfaf62005-08-27 20:01:45 +0000323 rprintf(F," --no-implied-dirs don't send implied dirs with --relative\n");
Wayne Davison68391402003-12-30 18:16:25 +0000324 rprintf(F," -b, --backup make backups (see --suffix & --backup-dir)\n");
Wayne Davisonb3708ac2005-01-28 09:55:18 +0000325 rprintf(F," --backup-dir=DIR make backups into hierarchy based in DIR\n");
326 rprintf(F," --suffix=SUFFIX set backup suffix (default %s w/o --backup-dir)\n",BACKUP_SUFFIX);
327 rprintf(F," -u, --update skip files that are newer on the receiver\n");
Wayne Davison4ce838e2005-01-17 23:11:18 +0000328 rprintf(F," --inplace update destination files in-place (SEE MAN PAGE)\n");
Wayne Davisona0157882005-07-28 01:46:09 +0000329 rprintf(F," --append append data onto shorter files\n");
Wayne Davison936fa862007-09-01 16:38:00 +0000330 rprintf(F," --append-verify like --append, but with old data in file checksum\n");
Wayne Davison65e4cda2005-01-24 00:17:39 +0000331 rprintf(F," -d, --dirs transfer directories without recursing\n");
Martin Pool13e29992001-12-18 05:54:57 +0000332 rprintf(F," -l, --links copy symlinks as symlinks\n");
Wayne Davisonb3708ac2005-01-28 09:55:18 +0000333 rprintf(F," -L, --copy-links transform symlink into referent file/dir\n");
334 rprintf(F," --copy-unsafe-links only \"unsafe\" symlinks are transformed\n");
335 rprintf(F," --safe-links ignore symlinks that point outside the source tree\n");
Wayne Davison2dbf36e2006-02-24 17:54:30 +0000336 rprintf(F," -k, --copy-dirlinks transform symlink to a dir into referent dir\n");
Wayne Davison65e4cda2005-01-24 00:17:39 +0000337 rprintf(F," -K, --keep-dirlinks treat symlinked dir on receiver as dir\n");
Wayne Davison2dbf36e2006-02-24 17:54:30 +0000338 rprintf(F," -H, --hard-links preserve hard links\n");
Andrew Tridgell704f9081998-06-18 09:31:42 +0000339 rprintf(F," -p, --perms preserve permissions\n");
Wayne Davison344f9ba2006-01-31 02:29:58 +0000340 rprintf(F," -E, --executability preserve the file's executability\n");
Wayne Davisondfe1ed52006-10-09 00:55:04 +0000341 rprintf(F," --chmod=CHMOD affect file and/or directory permissions\n");
Wayne Davison1c3344a2007-03-11 00:13:34 +0000342#ifdef SUPPORT_ACLS
343 rprintf(F," -A, --acls preserve ACLs (implies --perms)\n");
344#endif
Wayne Davison16edf862007-04-07 17:22:25 +0000345#ifdef SUPPORT_XATTRS
Wayne Davison3caafdf2007-08-04 22:19:43 +0000346 rprintf(F," -X, --xattrs preserve extended attributes\n");
Wayne Davison16edf862007-04-07 17:22:25 +0000347#endif
Wayne Davisondef97ff2006-01-26 11:10:32 +0000348 rprintf(F," -o, --owner preserve owner (super-user only)\n");
Andrew Tridgell704f9081998-06-18 09:31:42 +0000349 rprintf(F," -g, --group preserve group\n");
Wayne Davisondef97ff2006-01-26 11:10:32 +0000350 rprintf(F," --devices preserve device files (super-user only)\n");
Wayne Davisonb5c6a6a2006-01-26 10:38:58 +0000351 rprintf(F," --specials preserve special files\n");
352 rprintf(F," -D same as --devices --specials\n");
Wayne Davison42b06482007-07-12 14:43:26 +0000353 rprintf(F," -t, --times preserve modification times\n");
354 rprintf(F," -O, --omit-dir-times omit directories from --times\n");
Wayne Davisondef97ff2006-01-26 11:10:32 +0000355 rprintf(F," --super receiver attempts super-user activities\n");
Wayne Davison9439c0c2007-04-24 07:32:44 +0000356#ifdef SUPPORT_XATTRS
357 rprintf(F," --fake-super store/recover privileged attrs using xattrs\n");
358#endif
Andrew Tridgell704f9081998-06-18 09:31:42 +0000359 rprintf(F," -S, --sparse handle sparse files efficiently\n");
Wayne Davisond100e732007-11-08 00:06:48 +0000360 rprintf(F," -n, --dry-run perform a trial run with no changes made\n");
Wayne Davisonf7a2ac02007-12-15 08:35:45 -0800361 rprintf(F," -W, --whole-file copy files whole (without delta-xfer algorithm)\n");
Andrew Tridgell704f9081998-06-18 09:31:42 +0000362 rprintf(F," -x, --one-file-system don't cross filesystem boundaries\n");
Wayne Davison9cd339e2004-08-03 08:05:20 +0000363 rprintf(F," -B, --block-size=SIZE force a fixed checksum block-size\n");
Wayne Davisonb3708ac2005-01-28 09:55:18 +0000364 rprintf(F," -e, --rsh=COMMAND specify the remote shell to use\n");
Wayne Davison05ee4862005-03-02 09:17:42 +0000365 rprintf(F," --rsync-path=PROGRAM specify the rsync to run on the remote machine\n");
Wayne Davisonfcecb702006-05-05 06:16:22 +0000366 rprintf(F," --existing skip creating new files on receiver\n");
367 rprintf(F," --ignore-existing skip updating files that already exist on receiver\n");
Wayne Davison47c11972006-06-30 15:52:52 +0000368 rprintf(F," --remove-source-files sender removes synchronized files (non-dirs)\n");
Wayne Davison3359acb2005-01-25 03:08:58 +0000369 rprintf(F," --del an alias for --delete-during\n");
Wayne Davisonfcecb702006-05-05 06:16:22 +0000370 rprintf(F," --delete delete extraneous files from destination dirs\n");
Wayne Davisone0e32032006-12-28 07:54:10 +0000371 rprintf(F," --delete-before receiver deletes before transfer, not during\n");
372 rprintf(F," --delete-during receiver deletes during transfer (default)\n");
Wayne Davisonb0cacef2006-11-22 20:49:23 +0000373 rprintf(F," --delete-delay find deletions during, delete after\n");
Wayne Davisone0e32032006-12-28 07:54:10 +0000374 rprintf(F," --delete-after receiver deletes after transfer, not during\n");
Wayne Davisonfcecb702006-05-05 06:16:22 +0000375 rprintf(F," --delete-excluded also delete excluded files from destination dirs\n");
Wayne Davisondb2b5cb2004-01-23 09:32:50 +0000376 rprintf(F," --ignore-errors delete even if there are I/O errors\n");
Wayne Davison51d48392005-01-22 22:48:34 +0000377 rprintf(F," --force force deletion of directories even if not empty\n");
Andrew Tridgell0b73ca12000-01-23 11:43:04 +0000378 rprintf(F," --max-delete=NUM don't delete more than NUM files\n");
Wayne Davison7d5acf12004-11-11 01:45:25 +0000379 rprintf(F," --max-size=SIZE don't transfer any file larger than SIZE\n");
Wayne Davison74de13d2005-10-14 20:15:18 +0000380 rprintf(F," --min-size=SIZE don't transfer any file smaller than SIZE\n");
Andrew Tridgellc95da961998-07-01 03:36:03 +0000381 rprintf(F," --partial keep partially transferred files\n");
Wayne Davisona7260c42004-07-29 16:06:38 +0000382 rprintf(F," --partial-dir=DIR put a partially transferred file into DIR\n");
Wayne Davisonb3708ac2005-01-28 09:55:18 +0000383 rprintf(F," --delay-updates put all updated files into place at transfer's end\n");
Wayne Davison876c9932006-01-28 00:13:55 +0000384 rprintf(F," -m, --prune-empty-dirs prune empty directory chains from the file-list\n");
Andrew Tridgell704f9081998-06-18 09:31:42 +0000385 rprintf(F," --numeric-ids don't map uid/gid values by user/group name\n");
Wayne Davisonba22c9e2007-11-28 00:28:26 -0800386 rprintf(F," --timeout=SECONDS set I/O timeout in seconds\n");
387 rprintf(F," --contimeout=SECONDS set daemon connection timeout in seconds\n");
Wayne Davisonb3708ac2005-01-28 09:55:18 +0000388 rprintf(F," -I, --ignore-times don't skip files that match in size and mod-time\n");
389 rprintf(F," --size-only skip files that match in size\n");
390 rprintf(F," --modify-window=NUM compare mod-times with reduced accuracy\n");
Wayne Davison4db88e52004-07-22 15:43:28 +0000391 rprintf(F," -T, --temp-dir=DIR create temporary files in directory DIR\n");
Wayne Davisonc4ed1482005-02-14 02:41:15 +0000392 rprintf(F," -y, --fuzzy find similar file for basis if no dest file\n");
David Dykstra375a4551998-10-26 21:42:38 +0000393 rprintf(F," --compare-dest=DIR also compare destination files relative to DIR\n");
Wayne Davison1de3e992005-03-11 17:35:59 +0000394 rprintf(F," --copy-dest=DIR ... and include copies of unchanged files\n");
Wayne Davisone012f852004-11-27 17:52:51 +0000395 rprintf(F," --link-dest=DIR hardlink to files in DIR when unchanged\n");
Wayne Davisonf9249462005-02-12 22:22:14 +0000396 rprintf(F," -z, --compress compress file data during the transfer\n");
Wayne Davison854a1aa2005-10-26 16:47:15 +0000397 rprintf(F," --compress-level=NUM explicitly set compression level\n");
Wayne Davisonb1e436e2007-07-14 19:24:32 +0000398 rprintf(F," --skip-compress=LIST skip compressing files with a suffix in LIST\n");
Wayne Davisonb3708ac2005-01-28 09:55:18 +0000399 rprintf(F," -C, --cvs-exclude auto-ignore files the same way CVS does\n");
Wayne Davisonaa4d3b42005-01-25 00:52:56 +0000400 rprintf(F," -f, --filter=RULE add a file-filtering RULE\n");
Wayne Davison9c71f562005-02-13 05:44:29 +0000401 rprintf(F," -F same as --filter='dir-merge /.rsync-filter'\n");
Wayne Davisonaa4d3b42005-01-25 00:52:56 +0000402 rprintf(F," repeated: --filter='- .rsync-filter'\n");
David Dykstra2acf81e1998-11-03 21:17:40 +0000403 rprintf(F," --exclude=PATTERN exclude files matching PATTERN\n");
Wayne Davisonb3708ac2005-01-28 09:55:18 +0000404 rprintf(F," --exclude-from=FILE read exclude patterns from FILE\n");
David Dykstra2acf81e1998-11-03 21:17:40 +0000405 rprintf(F," --include=PATTERN don't exclude files matching PATTERN\n");
Wayne Davisonb3708ac2005-01-28 09:55:18 +0000406 rprintf(F," --include-from=FILE read include patterns from FILE\n");
407 rprintf(F," --files-from=FILE read list of source-file names from FILE\n");
Wayne Davison72316022005-05-02 17:23:08 +0000408 rprintf(F," -0, --from0 all *-from/filter files are delimited by 0s\n");
Wayne Davison7a4adda2007-09-09 07:53:18 +0000409 rprintf(F," -s, --protect-args no space-splitting; only wildcard special-chars\n");
Wayne Davisonb4ef0bc2005-04-05 05:59:49 +0000410 rprintf(F," --address=ADDRESS bind address for outgoing socket to daemon\n");
Wayne Davisonb4713292004-12-08 17:29:54 +0000411 rprintf(F," --port=PORT specify double-colon alternate port number\n");
Wayne Davison831f06a2006-01-26 12:31:24 +0000412 rprintf(F," --sockopts=OPTIONS specify custom TCP options\n");
Wayne Davisondb2b5cb2004-01-23 09:32:50 +0000413 rprintf(F," --blocking-io use blocking I/O for the remote shell\n");
Wayne Davisonb3708ac2005-01-28 09:55:18 +0000414 rprintf(F," --stats give some file-transfer stats\n");
Wayne Davisona6a27602006-02-06 18:51:25 +0000415 rprintf(F," -8, --8-bit-output leave high-bit chars unescaped in output\n");
Wayne Davison05724c02005-11-15 06:35:27 +0000416 rprintf(F," -h, --human-readable output numbers in a human-readable format\n");
Wayne Davisondfa32482003-03-21 18:58:50 +0000417 rprintf(F," --progress show progress during transfer\n");
Wayne Davisonb3708ac2005-01-28 09:55:18 +0000418 rprintf(F," -P same as --partial --progress\n");
Wayne Davisonb78296c2005-02-15 07:41:13 +0000419 rprintf(F," -i, --itemize-changes output a change-summary for all updates\n");
Wayne Davisonb3e4e7e2006-05-29 22:56:45 +0000420 rprintf(F," --out-format=FORMAT output updates using the specified FORMAT\n");
421 rprintf(F," --log-file=FILE log what we're doing to the specified FILE\n");
422 rprintf(F," --log-file-format=FMT log updates using the specified FMT\n");
Wayne Davison09a54c32006-12-24 01:30:24 +0000423 rprintf(F," --password-file=FILE read daemon-access password from FILE\n");
Wayne Davison65e4cda2005-01-24 00:17:39 +0000424 rprintf(F," --list-only list the files instead of copying them\n");
Wayne Davisonb3708ac2005-01-28 09:55:18 +0000425 rprintf(F," --bwlimit=KBPS limit I/O bandwidth; KBytes per second\n");
426 rprintf(F," --write-batch=FILE write a batched update to FILE\n");
Wayne Davison11e758a2005-04-09 18:59:47 +0000427 rprintf(F," --only-write-batch=FILE like --write-batch but w/o updating destination\n");
Wayne Davisonb3708ac2005-01-28 09:55:18 +0000428 rprintf(F," --read-batch=FILE read a batched update from FILE\n");
Wayne Davisonda9f5922005-03-28 20:40:25 +0000429 rprintf(F," --protocol=NUM force an older protocol version to be used\n");
Wayne Davison332cf6d2007-04-26 05:53:13 +0000430#ifdef ICONV_OPTION
Wayne Davison84e1a342007-11-05 18:33:09 +0000431 rprintf(F," --iconv=CONVERT_SPEC request charset conversion of filenames\n");
Wayne Davison332cf6d2007-04-26 05:53:13 +0000432#endif
Wayne Davison4db88e52004-07-22 15:43:28 +0000433 rprintf(F," -4, --ipv4 prefer IPv4\n");
434 rprintf(F," -6, --ipv6 prefer IPv6\n");
Wayne Davison4a34c6f2005-05-03 16:46:49 +0000435 rprintf(F," --version print version number\n");
Wayne Davison375d8f92006-02-11 00:01:22 +0000436 rprintf(F,"(-h) --help show this help (-h works with no other options)\n");
Andrew Tridgell7a6421f1998-05-10 07:25:40 +0000437
Wayne Davisonb64ee912006-06-01 08:04:47 +0000438 rprintf(F,"\n");
439 rprintf(F,"Use \"rsync --daemon --help\" to see the daemon-mode command-line options.\n");
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000440 rprintf(F,"Please see the rsync(1) and rsyncd.conf(5) man pages for full documentation.\n");
Martin Pool2855f612001-02-23 01:02:31 +0000441 rprintf(F,"See http://rsync.samba.org/ for updates, bug reports, and answers\n");
Andrew Tridgell7a6421f1998-05-10 07:25:40 +0000442}
443
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000444enum {OPT_VERSION = 1000, OPT_DAEMON, OPT_SENDER, OPT_EXCLUDE, OPT_EXCLUDE_FROM,
Wayne Davison05724c02005-11-15 06:35:27 +0000445 OPT_FILTER, OPT_COMPARE_DEST, OPT_COPY_DEST, OPT_LINK_DEST, OPT_HELP,
Wayne Davisone16adcd2006-01-21 09:14:42 +0000446 OPT_INCLUDE, OPT_INCLUDE_FROM, OPT_MODIFY_WINDOW, OPT_MIN_SIZE, OPT_CHMOD,
Wayne Davison9ac756c2005-05-19 08:52:17 +0000447 OPT_READ_BATCH, OPT_WRITE_BATCH, OPT_ONLY_WRITE_BATCH, OPT_MAX_SIZE,
Wayne Davison0b52f942008-02-14 13:24:16 -0800448 OPT_NO_D, OPT_APPEND, OPT_NO_ICONV,
Wayne Davison0ccffd72006-01-21 20:15:49 +0000449 OPT_SERVER, OPT_REFUSED_BASE = 9000};
Andrew Tridgell7a6421f1998-05-10 07:25:40 +0000450
Martin Pool2855f612001-02-23 01:02:31 +0000451static struct poptOption long_options[] = {
452 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
Wayne Davison05724c02005-11-15 06:35:27 +0000453 {"help", 0, POPT_ARG_NONE, 0, OPT_HELP, 0, 0 },
Wayne Davison8db7cc22004-10-11 10:43:25 +0000454 {"version", 0, POPT_ARG_NONE, 0, OPT_VERSION, 0, 0},
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000455 {"verbose", 'v', POPT_ARG_NONE, 0, 'v', 0, 0 },
Wayne Davisonb6164932005-08-27 21:01:45 +0000456 {"no-verbose", 0, POPT_ARG_VAL, &verbose, 0, 0, 0 },
Wayne Davison4afcb702005-08-28 00:43:51 +0000457 {"no-v", 0, POPT_ARG_VAL, &verbose, 0, 0, 0 },
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000458 {"quiet", 'q', POPT_ARG_NONE, 0, 'q', 0, 0 },
Wayne Davisondc1f7b92006-10-24 00:36:38 +0000459 {"motd", 0, POPT_ARG_VAL, &output_motd, 1, 0, 0 },
460 {"no-motd", 0, POPT_ARG_VAL, &output_motd, 0, 0, 0 },
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000461 {"stats", 0, POPT_ARG_NONE, &do_stats, 0, 0, 0 },
Wayne Davison3ca9e5d2006-02-08 16:52:25 +0000462 {"human-readable", 'h', POPT_ARG_NONE, 0, 'h', 0, 0},
Wayne Davison8487f9c2007-05-24 02:50:35 +0000463 {"no-human-readable",0, POPT_ARG_VAL, &human_readable, 0, 0, 0},
464 {"no-h", 0, POPT_ARG_VAL, &human_readable, 0, 0, 0},
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000465 {"dry-run", 'n', POPT_ARG_NONE, &dry_run, 0, 0, 0 },
Wayne Davisonb6164932005-08-27 21:01:45 +0000466 {"archive", 'a', POPT_ARG_NONE, 0, 'a', 0, 0 },
467 {"recursive", 'r', POPT_ARG_VAL, &recurse, 2, 0, 0 },
468 {"no-recursive", 0, POPT_ARG_VAL, &recurse, 0, 0, 0 },
469 {"no-r", 0, POPT_ARG_VAL, &recurse, 0, 0, 0 },
Wayne Davison8487f9c2007-05-24 02:50:35 +0000470 {"inc-recursive", 0, POPT_ARG_VAL, &allow_inc_recurse, 1, 0, 0 },
471 {"no-inc-recursive", 0, POPT_ARG_VAL, &allow_inc_recurse, 0, 0, 0 },
Wayne Davisond6ca2552007-09-15 20:54:31 +0000472 {"i-r", 0, POPT_ARG_VAL, &allow_inc_recurse, 1, 0, 0 },
473 {"no-i-r", 0, POPT_ARG_VAL, &allow_inc_recurse, 0, 0, 0 },
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000474 {"dirs", 'd', POPT_ARG_VAL, &xfer_dirs, 2, 0, 0 },
Wayne Davisonb6164932005-08-27 21:01:45 +0000475 {"no-dirs", 0, POPT_ARG_VAL, &xfer_dirs, 0, 0, 0 },
476 {"no-d", 0, POPT_ARG_VAL, &xfer_dirs, 0, 0, 0 },
Wayne Davison73cb6732008-03-24 09:33:07 -0700477 {"old-dirs", 0, POPT_ARG_VAL, &xfer_dirs, 4, 0, 0 },
478 {"old-d", 0, POPT_ARG_VAL, &xfer_dirs, 4, 0, 0 },
Wayne Davisonb6164932005-08-27 21:01:45 +0000479 {"perms", 'p', POPT_ARG_VAL, &preserve_perms, 1, 0, 0 },
480 {"no-perms", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
481 {"no-p", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
Wayne Davison344f9ba2006-01-31 02:29:58 +0000482 {"executability", 'E', POPT_ARG_NONE, &preserve_executability, 0, 0, 0 },
Wayne Davison1c3344a2007-03-11 00:13:34 +0000483 {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 },
484 {"no-acls", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
485 {"no-A", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
Wayne Davison16edf862007-04-07 17:22:25 +0000486 {"xattrs", 'X', POPT_ARG_NONE, 0, 'X', 0, 0 },
487 {"no-xattrs", 0, POPT_ARG_VAL, &preserve_xattrs, 0, 0, 0 },
488 {"no-X", 0, POPT_ARG_VAL, &preserve_xattrs, 0, 0, 0 },
Wayne Davison8f48ba02011-02-21 09:48:37 -0800489 {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
Wayne Davisonb6164932005-08-27 21:01:45 +0000490 {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
491 {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
Wayne Davisonf9998042007-09-01 16:57:01 +0000492 {"omit-dir-times", 'O', POPT_ARG_VAL, &omit_dir_times, 1, 0, 0 },
Wayne Davisoneb7a6e02007-09-02 06:20:42 +0000493 {"no-omit-dir-times",0, POPT_ARG_VAL, &omit_dir_times, 0, 0, 0 },
494 {"no-O", 0, POPT_ARG_VAL, &omit_dir_times, 0, 0, 0 },
Wayne Davison38b91702005-08-27 21:12:44 +0000495 {"modify-window", 0, POPT_ARG_INT, &modify_window, OPT_MODIFY_WINDOW, 0, 0 },
Wayne Davisondef97ff2006-01-26 11:10:32 +0000496 {"super", 0, POPT_ARG_VAL, &am_root, 2, 0, 0 },
497 {"no-super", 0, POPT_ARG_VAL, &am_root, 0, 0, 0 },
Wayne Davison9439c0c2007-04-24 07:32:44 +0000498 {"fake-super", 0, POPT_ARG_VAL, &am_root, -1, 0, 0 },
Wayne Davisonb6164932005-08-27 21:01:45 +0000499 {"owner", 'o', POPT_ARG_VAL, &preserve_uid, 1, 0, 0 },
500 {"no-owner", 0, POPT_ARG_VAL, &preserve_uid, 0, 0, 0 },
501 {"no-o", 0, POPT_ARG_VAL, &preserve_uid, 0, 0, 0 },
502 {"group", 'g', POPT_ARG_VAL, &preserve_gid, 1, 0, 0 },
503 {"no-group", 0, POPT_ARG_VAL, &preserve_gid, 0, 0, 0 },
504 {"no-g", 0, POPT_ARG_VAL, &preserve_gid, 0, 0, 0 },
Wayne Davisonb5c6a6a2006-01-26 10:38:58 +0000505 {0, 'D', POPT_ARG_NONE, 0, 'D', 0, 0 },
506 {"no-D", 0, POPT_ARG_NONE, 0, OPT_NO_D, 0, 0 },
507 {"devices", 0, POPT_ARG_VAL, &preserve_devices, 1, 0, 0 },
Wayne Davisonb6164932005-08-27 21:01:45 +0000508 {"no-devices", 0, POPT_ARG_VAL, &preserve_devices, 0, 0, 0 },
Wayne Davisonb5c6a6a2006-01-26 10:38:58 +0000509 {"specials", 0, POPT_ARG_VAL, &preserve_specials, 1, 0, 0 },
510 {"no-specials", 0, POPT_ARG_VAL, &preserve_specials, 0, 0, 0 },
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000511 {"links", 'l', POPT_ARG_VAL, &preserve_links, 1, 0, 0 },
Wayne Davisonb6164932005-08-27 21:01:45 +0000512 {"no-links", 0, POPT_ARG_VAL, &preserve_links, 0, 0, 0 },
513 {"no-l", 0, POPT_ARG_VAL, &preserve_links, 0, 0, 0 },
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000514 {"copy-links", 'L', POPT_ARG_NONE, &copy_links, 0, 0, 0 },
515 {"copy-unsafe-links",0, POPT_ARG_NONE, &copy_unsafe_links, 0, 0, 0 },
516 {"safe-links", 0, POPT_ARG_NONE, &safe_symlinks, 0, 0, 0 },
Wayne Davison2dbf36e2006-02-24 17:54:30 +0000517 {"copy-dirlinks", 'k', POPT_ARG_NONE, &copy_dirlinks, 0, 0, 0 },
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000518 {"keep-dirlinks", 'K', POPT_ARG_NONE, &keep_dirlinks, 0, 0, 0 },
Wayne Davisone0e32032006-12-28 07:54:10 +0000519 {"hard-links", 'H', POPT_ARG_NONE, 0, 'H', 0, 0 },
Wayne Davisonbeab3072006-02-27 23:35:18 +0000520 {"no-hard-links", 0, POPT_ARG_VAL, &preserve_hard_links, 0, 0, 0 },
521 {"no-H", 0, POPT_ARG_VAL, &preserve_hard_links, 0, 0, 0 },
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000522 {"relative", 'R', POPT_ARG_VAL, &relative_paths, 1, 0, 0 },
523 {"no-relative", 0, POPT_ARG_VAL, &relative_paths, 0, 0, 0 },
Wayne Davisonb6164932005-08-27 21:01:45 +0000524 {"no-R", 0, POPT_ARG_VAL, &relative_paths, 0, 0, 0 },
Wayne Davison2dbf36e2006-02-24 17:54:30 +0000525 {"implied-dirs", 0, POPT_ARG_VAL, &implied_dirs, 1, 0, 0 },
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000526 {"no-implied-dirs", 0, POPT_ARG_VAL, &implied_dirs, 0, 0, 0 },
Wayne Davisond6ca2552007-09-15 20:54:31 +0000527 {"i-d", 0, POPT_ARG_VAL, &implied_dirs, 1, 0, 0 },
528 {"no-i-d", 0, POPT_ARG_VAL, &implied_dirs, 0, 0, 0 },
Wayne Davisone16adcd2006-01-21 09:14:42 +0000529 {"chmod", 0, POPT_ARG_STRING, 0, OPT_CHMOD, 0, 0 },
Wayne Davisonafb6e942003-03-21 19:17:23 +0000530 {"ignore-times", 'I', POPT_ARG_NONE, &ignore_times, 0, 0, 0 },
531 {"size-only", 0, POPT_ARG_NONE, &size_only, 0, 0, 0 },
Wayne Davison243c9952006-01-21 00:36:15 +0000532 {"one-file-system", 'x', POPT_ARG_NONE, 0, 'x', 0, 0 },
Wayne Davisonde20d722010-08-26 07:58:22 -0700533 {"no-one-file-system",0, POPT_ARG_VAL, &one_file_system, 0, 0, 0 },
534 {"no-x", 0, POPT_ARG_VAL, &one_file_system, 0, 0, 0 },
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000535 {"update", 'u', POPT_ARG_NONE, &update_only, 0, 0, 0 },
Wayne Davisone90aab42005-09-29 18:07:55 +0000536 {"existing", 0, POPT_ARG_NONE, &ignore_non_existing, 0, 0, 0 },
Wayne Davisone90aab42005-09-29 18:07:55 +0000537 {"ignore-non-existing",0,POPT_ARG_NONE, &ignore_non_existing, 0, 0, 0 },
Wayne Davisond2da9152005-12-19 01:59:00 +0000538 {"ignore-existing", 0, POPT_ARG_NONE, &ignore_existing, 0, 0, 0 },
Wayne Davisonaeb213e2005-10-14 18:56:07 +0000539 {"max-size", 0, POPT_ARG_STRING, &max_size_arg, OPT_MAX_SIZE, 0, 0 },
Wayne Davison74de13d2005-10-14 20:15:18 +0000540 {"min-size", 0, POPT_ARG_STRING, &min_size_arg, OPT_MIN_SIZE, 0, 0 },
Wayne Davison852e7632008-03-06 09:38:48 -0800541 {"sparse", 'S', POPT_ARG_VAL, &sparse_files, 1, 0, 0 },
542 {"no-sparse", 0, POPT_ARG_VAL, &sparse_files, 0, 0, 0 },
543 {"no-S", 0, POPT_ARG_VAL, &sparse_files, 0, 0, 0 },
544 {"inplace", 0, POPT_ARG_VAL, &inplace, 1, 0, 0 },
545 {"no-inplace", 0, POPT_ARG_VAL, &inplace, 0, 0, 0 },
Wayne Davison936fa862007-09-01 16:38:00 +0000546 {"append", 0, POPT_ARG_NONE, 0, OPT_APPEND, 0, 0 },
547 {"append-verify", 0, POPT_ARG_VAL, &append_mode, 2, 0, 0 },
548 {"no-append", 0, POPT_ARG_VAL, &append_mode, 0, 0, 0 },
Wayne Davison36719872005-02-11 10:42:55 +0000549 {"del", 0, POPT_ARG_NONE, &delete_during, 0, 0, 0 },
Wayne Davison3359acb2005-01-25 03:08:58 +0000550 {"delete", 0, POPT_ARG_NONE, &delete_mode, 0, 0, 0 },
Wayne Davisone0e32032006-12-28 07:54:10 +0000551 {"delete-before", 0, POPT_ARG_NONE, &delete_before, 0, 0, 0 },
Wayne Davisonb0cacef2006-11-22 20:49:23 +0000552 {"delete-during", 0, POPT_ARG_VAL, &delete_during, 1, 0, 0 },
553 {"delete-delay", 0, POPT_ARG_VAL, &delete_during, 2, 0, 0 },
Wayne Davison51d48392005-01-22 22:48:34 +0000554 {"delete-after", 0, POPT_ARG_NONE, &delete_after, 0, 0, 0 },
555 {"delete-excluded", 0, POPT_ARG_NONE, &delete_excluded, 0, 0, 0 },
Wayne Davison47c11972006-06-30 15:52:52 +0000556 {"remove-sent-files",0, POPT_ARG_VAL, &remove_source_files, 2, 0, 0 }, /* deprecated */
557 {"remove-source-files",0,POPT_ARG_VAL, &remove_source_files, 1, 0, 0 },
Wayne Davison852e7632008-03-06 09:38:48 -0800558 {"force", 0, POPT_ARG_VAL, &force_delete, 1, 0, 0 },
559 {"no-force", 0, POPT_ARG_VAL, &force_delete, 0, 0, 0 },
560 {"ignore-errors", 0, POPT_ARG_VAL, &ignore_errors, 1, 0, 0 },
561 {"no-ignore-errors", 0, POPT_ARG_VAL, &ignore_errors, 0, 0, 0 },
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000562 {"max-delete", 0, POPT_ARG_INT, &max_delete, 0, 0, 0 },
563 {0, 'F', POPT_ARG_NONE, 0, 'F', 0, 0 },
Wayne Davisonaa4d3b42005-01-25 00:52:56 +0000564 {"filter", 'f', POPT_ARG_STRING, 0, OPT_FILTER, 0, 0 },
Wayne Davison8db7cc22004-10-11 10:43:25 +0000565 {"exclude", 0, POPT_ARG_STRING, 0, OPT_EXCLUDE, 0, 0 },
566 {"include", 0, POPT_ARG_STRING, 0, OPT_INCLUDE, 0, 0 },
567 {"exclude-from", 0, POPT_ARG_STRING, 0, OPT_EXCLUDE_FROM, 0, 0 },
568 {"include-from", 0, POPT_ARG_STRING, 0, OPT_INCLUDE_FROM, 0, 0 },
Wayne Davisonafb6e942003-03-21 19:17:23 +0000569 {"cvs-exclude", 'C', POPT_ARG_NONE, &cvs_exclude, 0, 0, 0 },
Wayne Davison11bfaf62005-08-27 20:01:45 +0000570 {"whole-file", 'W', POPT_ARG_VAL, &whole_file, 1, 0, 0 },
571 {"no-whole-file", 0, POPT_ARG_VAL, &whole_file, 0, 0, 0 },
Wayne Davisonb6164932005-08-27 21:01:45 +0000572 {"no-W", 0, POPT_ARG_VAL, &whole_file, 0, 0, 0 },
Wayne Davison8487f9c2007-05-24 02:50:35 +0000573 {"checksum", 'c', POPT_ARG_VAL, &always_checksum, 1, 0, 0 },
574 {"no-checksum", 0, POPT_ARG_VAL, &always_checksum, 0, 0, 0 },
575 {"no-c", 0, POPT_ARG_VAL, &always_checksum, 0, 0, 0 },
Wayne Davisona06b4192005-01-01 21:08:14 +0000576 {"block-size", 'B', POPT_ARG_LONG, &block_size, 0, 0, 0 },
Wayne Davisone012f852004-11-27 17:52:51 +0000577 {"compare-dest", 0, POPT_ARG_STRING, 0, OPT_COMPARE_DEST, 0, 0 },
Wayne Davison1de3e992005-03-11 17:35:59 +0000578 {"copy-dest", 0, POPT_ARG_STRING, 0, OPT_COPY_DEST, 0, 0 },
Wayne Davisone012f852004-11-27 17:52:51 +0000579 {"link-dest", 0, POPT_ARG_STRING, 0, OPT_LINK_DEST, 0, 0 },
Wayne Davison852e7632008-03-06 09:38:48 -0800580 {"fuzzy", 'y', POPT_ARG_VAL, &fuzzy_basis, 1, 0, 0 },
581 {"no-fuzzy", 0, POPT_ARG_VAL, &fuzzy_basis, 0, 0, 0 },
Wayne Davison492ad042008-03-10 21:40:04 -0700582 {"no-y", 0, POPT_ARG_VAL, &fuzzy_basis, 0, 0, 0 },
Wayne Davison854a1aa2005-10-26 16:47:15 +0000583 {"compress", 'z', POPT_ARG_NONE, 0, 'z', 0, 0 },
Wayne Davison8487f9c2007-05-24 02:50:35 +0000584 {"no-compress", 0, POPT_ARG_VAL, &do_compression, 0, 0, 0 },
585 {"no-z", 0, POPT_ARG_VAL, &do_compression, 0, 0, 0 },
Wayne Davison852e7632008-03-06 09:38:48 -0800586 {"skip-compress", 0, POPT_ARG_STRING, &skip_compress, 0, 0, 0 },
Wayne Davison854a1aa2005-10-26 16:47:15 +0000587 {"compress-level", 0, POPT_ARG_INT, &def_compress_level, 'z', 0, 0 },
Wayne Davison11bfaf62005-08-27 20:01:45 +0000588 {0, 'P', POPT_ARG_NONE, 0, 'P', 0, 0 },
Wayne Davisonb6164932005-08-27 21:01:45 +0000589 {"progress", 0, POPT_ARG_VAL, &do_progress, 1, 0, 0 },
590 {"no-progress", 0, POPT_ARG_VAL, &do_progress, 0, 0, 0 },
591 {"partial", 0, POPT_ARG_VAL, &keep_partial, 1, 0, 0 },
592 {"no-partial", 0, POPT_ARG_VAL, &keep_partial, 0, 0, 0 },
Wayne Davisona7260c42004-07-29 16:06:38 +0000593 {"partial-dir", 0, POPT_ARG_STRING, &partial_dir, 0, 0, 0 },
Wayne Davison8487f9c2007-05-24 02:50:35 +0000594 {"delay-updates", 0, POPT_ARG_VAL, &delay_updates, 1, 0, 0 },
595 {"no-delay-updates", 0, POPT_ARG_VAL, &delay_updates, 0, 0, 0 },
Wayne Davison852e7632008-03-06 09:38:48 -0800596 {"prune-empty-dirs",'m', POPT_ARG_VAL, &prune_empty_dirs, 1, 0, 0 },
597 {"no-prune-empty-dirs",0,POPT_ARG_VAL, &prune_empty_dirs, 0, 0, 0 },
598 {"no-m", 0, POPT_ARG_VAL, &prune_empty_dirs, 0, 0, 0 },
Wayne Davison87c0f9d2006-05-09 18:31:03 +0000599 {"log-file", 0, POPT_ARG_STRING, &logfile_name, 0, 0, 0 },
Wayne Davisonb3e4e7e2006-05-29 22:56:45 +0000600 {"log-file-format", 0, POPT_ARG_STRING, &logfile_format, 0, 0, 0 },
601 {"out-format", 0, POPT_ARG_STRING, &stdout_format, 0, 0, 0 },
602 {"log-format", 0, POPT_ARG_STRING, &stdout_format, 0, 0, 0 }, /* DEPRECATED */
Wayne Davison487094a2006-01-20 18:49:07 +0000603 {"itemize-changes", 'i', POPT_ARG_NONE, 0, 'i', 0, 0 },
Wayne Davison8487f9c2007-05-24 02:50:35 +0000604 {"no-itemize-changes",0, POPT_ARG_VAL, &itemize_changes, 0, 0, 0 },
605 {"no-i", 0, POPT_ARG_VAL, &itemize_changes, 0, 0, 0 },
Wayne Davisonafb6e942003-03-21 19:17:23 +0000606 {"bwlimit", 0, POPT_ARG_INT, &bwlimit, 0, 0, 0 },
Wayne Davison8487f9c2007-05-24 02:50:35 +0000607 {"no-bwlimit", 0, POPT_ARG_VAL, &bwlimit, 0, 0, 0 },
608 {"backup", 'b', POPT_ARG_VAL, &make_backups, 1, 0, 0 },
609 {"no-backup", 0, POPT_ARG_VAL, &make_backups, 0, 0, 0 },
Wayne Davisonafb6e942003-03-21 19:17:23 +0000610 {"backup-dir", 0, POPT_ARG_STRING, &backup_dir, 0, 0, 0 },
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000611 {"suffix", 0, POPT_ARG_STRING, &backup_suffix, 0, 0, 0 },
612 {"list-only", 0, POPT_ARG_VAL, &list_only, 2, 0, 0 },
Wayne Davison8db7cc22004-10-11 10:43:25 +0000613 {"read-batch", 0, POPT_ARG_STRING, &batch_name, OPT_READ_BATCH, 0, 0 },
614 {"write-batch", 0, POPT_ARG_STRING, &batch_name, OPT_WRITE_BATCH, 0, 0 },
Wayne Davison11e758a2005-04-09 18:59:47 +0000615 {"only-write-batch", 0, POPT_ARG_STRING, &batch_name, OPT_ONLY_WRITE_BATCH, 0, 0 },
Wayne Davisonea5164d2003-03-30 23:00:42 +0000616 {"files-from", 0, POPT_ARG_STRING, &files_from, 0, 0, 0 },
Wayne Davison8487f9c2007-05-24 02:50:35 +0000617 {"from0", '0', POPT_ARG_VAL, &eol_nulls, 1, 0, 0},
618 {"no-from0", 0, POPT_ARG_VAL, &eol_nulls, 0, 0, 0},
Wayne Davisonc35d6e32007-09-09 07:58:19 +0000619 {"protect-args", 's', POPT_ARG_VAL, &protect_args, 1, 0, 0},
620 {"no-protect-args", 0, POPT_ARG_VAL, &protect_args, 0, 0, 0},
621 {"no-s", 0, POPT_ARG_VAL, &protect_args, 0, 0, 0},
Wayne Davison8487f9c2007-05-24 02:50:35 +0000622 {"numeric-ids", 0, POPT_ARG_VAL, &numeric_ids, 1, 0, 0 },
623 {"no-numeric-ids", 0, POPT_ARG_VAL, &numeric_ids, 0, 0, 0 },
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000624 {"timeout", 0, POPT_ARG_INT, &io_timeout, 0, 0, 0 },
Wayne Davison8487f9c2007-05-24 02:50:35 +0000625 {"no-timeout", 0, POPT_ARG_VAL, &io_timeout, 0, 0, 0 },
Wayne Davisonba22c9e2007-11-28 00:28:26 -0800626 {"contimeout", 0, POPT_ARG_INT, &connect_timeout, 0, 0, 0 },
Wayne Davison852e7632008-03-06 09:38:48 -0800627 {"no-contimeout", 0, POPT_ARG_VAL, &connect_timeout, 0, 0, 0 },
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000628 {"rsh", 'e', POPT_ARG_STRING, &shell_cmd, 0, 0, 0 },
629 {"rsync-path", 0, POPT_ARG_STRING, &rsync_path, 0, 0, 0 },
630 {"temp-dir", 'T', POPT_ARG_STRING, &tmpdir, 0, 0, 0 },
Wayne Davison332cf6d2007-04-26 05:53:13 +0000631#ifdef ICONV_OPTION
632 {"iconv", 0, POPT_ARG_STRING, &iconv_opt, 0, 0, 0 },
Wayne Davison0b52f942008-02-14 13:24:16 -0800633 {"no-iconv", 0, POPT_ARG_NONE, 0, OPT_NO_ICONV, 0, 0 },
Wayne Davison332cf6d2007-04-26 05:53:13 +0000634#endif
Wayne Davison3dd22902004-05-06 21:08:01 +0000635 {"ipv4", '4', POPT_ARG_VAL, &default_af_hint, AF_INET, 0, 0 },
636 {"ipv6", '6', POPT_ARG_VAL, &default_af_hint, AF_INET6, 0, 0 },
Wayne Davison852e7632008-03-06 09:38:48 -0800637 {"8-bit-output", '8', POPT_ARG_VAL, &allow_8bit_chars, 1, 0, 0 },
638 {"no-8-bit-output", 0, POPT_ARG_VAL, &allow_8bit_chars, 0, 0, 0 },
639 {"no-8", 0, POPT_ARG_VAL, &allow_8bit_chars, 0, 0, 0 },
Wayne Davison8487f9c2007-05-24 02:50:35 +0000640 {"qsort", 0, POPT_ARG_NONE, &use_qsort, 0, 0, 0 },
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000641 {"address", 0, POPT_ARG_STRING, &bind_address, 0, 0, 0 },
642 {"port", 0, POPT_ARG_INT, &rsync_port, 0, 0, 0 },
Wayne Davison831f06a2006-01-26 12:31:24 +0000643 {"sockopts", 0, POPT_ARG_STRING, &sockopts, 0, 0, 0 },
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000644 {"password-file", 0, POPT_ARG_STRING, &password_file, 0, 0, 0 },
645 {"blocking-io", 0, POPT_ARG_VAL, &blocking_io, 1, 0, 0 },
646 {"no-blocking-io", 0, POPT_ARG_VAL, &blocking_io, 0, 0, 0 },
647 {"protocol", 0, POPT_ARG_INT, &protocol_version, 0, 0, 0 },
648 {"checksum-seed", 0, POPT_ARG_INT, &checksum_seed, 0, 0, 0 },
Wayne Davison0ccffd72006-01-21 20:15:49 +0000649 {"server", 0, POPT_ARG_NONE, 0, OPT_SERVER, 0, 0 },
Wayne Davisone86e2fa2005-08-27 20:43:35 +0000650 {"sender", 0, POPT_ARG_NONE, 0, OPT_SENDER, 0, 0 },
651 /* All the following options switch us into daemon-mode option-parsing. */
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000652 {"config", 0, POPT_ARG_STRING, 0, OPT_DAEMON, 0, 0 },
653 {"daemon", 0, POPT_ARG_NONE, 0, OPT_DAEMON, 0, 0 },
Wayne Davison1f35bab2005-02-21 00:31:31 +0000654 {"detach", 0, POPT_ARG_NONE, 0, OPT_DAEMON, 0, 0 },
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000655 {"no-detach", 0, POPT_ARG_NONE, 0, OPT_DAEMON, 0, 0 },
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000656 {0,0,0,0, 0, 0, 0}
657};
658
659static void daemon_usage(enum logcode F)
660{
661 print_rsync_version(F);
662
Wayne Davisonb64ee912006-06-01 08:04:47 +0000663 rprintf(F,"\n");
664 rprintf(F,"Usage: rsync --daemon [OPTION]...\n");
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000665 rprintf(F," --address=ADDRESS bind to the specified address\n");
Wayne Davisonb3708ac2005-01-28 09:55:18 +0000666 rprintf(F," --bwlimit=KBPS limit I/O bandwidth; KBytes per second\n");
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000667 rprintf(F," --config=FILE specify alternate rsyncd.conf file\n");
668 rprintf(F," --no-detach do not detach from the parent\n");
Wayne Davisonb3708ac2005-01-28 09:55:18 +0000669 rprintf(F," --port=PORT listen on alternate port number\n");
Wayne Davison87c0f9d2006-05-09 18:31:03 +0000670 rprintf(F," --log-file=FILE override the \"log file\" setting\n");
Wayne Davison232658d2006-05-30 17:14:17 +0000671 rprintf(F," --log-file-format=FMT override the \"log format\" setting\n");
Wayne Davison831f06a2006-01-26 12:31:24 +0000672 rprintf(F," --sockopts=OPTIONS specify custom TCP options\n");
Wayne Davison1bd9db72005-01-28 17:07:54 +0000673 rprintf(F," -v, --verbose increase verbosity\n");
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000674 rprintf(F," -4, --ipv4 prefer IPv4\n");
675 rprintf(F," -6, --ipv6 prefer IPv6\n");
Wayne Davison05724c02005-11-15 06:35:27 +0000676 rprintf(F," --help show this help screen\n");
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000677
Wayne Davisonb64ee912006-06-01 08:04:47 +0000678 rprintf(F,"\n");
679 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 +0000680 rprintf(F,"daemon-specific rsync options. See also the rsyncd.conf(5) man page.\n");
681}
682
683static struct poptOption long_daemon_options[] = {
684 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
685 {"address", 0, POPT_ARG_STRING, &bind_address, 0, 0, 0 },
Wayne Davison9fb08442004-11-17 19:29:20 +0000686 {"bwlimit", 0, POPT_ARG_INT, &daemon_bwlimit, 0, 0, 0 },
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000687 {"config", 0, POPT_ARG_STRING, &config_file, 0, 0, 0 },
688 {"daemon", 0, POPT_ARG_NONE, &daemon_opt, 0, 0, 0 },
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000689 {"ipv4", '4', POPT_ARG_VAL, &default_af_hint, AF_INET, 0, 0 },
690 {"ipv6", '6', POPT_ARG_VAL, &default_af_hint, AF_INET6, 0, 0 },
Wayne Davison1f35bab2005-02-21 00:31:31 +0000691 {"detach", 0, POPT_ARG_VAL, &no_detach, 0, 0, 0 },
Wayne Davison8487f9c2007-05-24 02:50:35 +0000692 {"no-detach", 0, POPT_ARG_VAL, &no_detach, 1, 0, 0 },
Wayne Davison87c0f9d2006-05-09 18:31:03 +0000693 {"log-file", 0, POPT_ARG_STRING, &logfile_name, 0, 0, 0 },
Wayne Davison232658d2006-05-30 17:14:17 +0000694 {"log-file-format", 0, POPT_ARG_STRING, &logfile_format, 0, 0, 0 },
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000695 {"port", 0, POPT_ARG_INT, &rsync_port, 0, 0, 0 },
Wayne Davison831f06a2006-01-26 12:31:24 +0000696 {"sockopts", 0, POPT_ARG_STRING, &sockopts, 0, 0, 0 },
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000697 {"protocol", 0, POPT_ARG_INT, &protocol_version, 0, 0, 0 },
698 {"server", 0, POPT_ARG_NONE, &am_server, 0, 0, 0 },
Wayne Davisonb8cc3582005-08-30 05:00:56 +0000699 {"temp-dir", 'T', POPT_ARG_STRING, &tmpdir, 0, 0, 0 },
Wayne Davison1bd9db72005-01-28 17:07:54 +0000700 {"verbose", 'v', POPT_ARG_NONE, 0, 'v', 0, 0 },
Wayne Davisonb6e22a42005-08-30 16:13:54 +0000701 {"no-verbose", 0, POPT_ARG_VAL, &verbose, 0, 0, 0 },
702 {"no-v", 0, POPT_ARG_VAL, &verbose, 0, 0, 0 },
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000703 {"help", 'h', POPT_ARG_NONE, 0, 'h', 0, 0 },
Wayne Davisonad715002004-10-14 09:11:12 +0000704 {0,0,0,0, 0, 0, 0}
Martin Pool2855f612001-02-23 01:02:31 +0000705};
Andrew Tridgell7a6421f1998-05-10 07:25:40 +0000706
Martin Pool06963d02001-11-23 07:35:49 +0000707
Wayne Davisone51094b2004-05-21 09:41:38 +0000708static char err_buf[200];
Andrew Tridgellcd8185f1998-11-19 06:35:49 +0000709
Martin Pool2855f612001-02-23 01:02:31 +0000710
Martin Pooldafe63c2002-04-16 01:38:21 +0000711/**
712 * Store the option error message, if any, so that we can log the
713 * connection attempt (which requires parsing the options), and then
714 * show the error later on.
715 **/
Andrew Tridgellcd8185f1998-11-19 06:35:49 +0000716void option_error(void)
717{
Wayne Davisone51094b2004-05-21 09:41:38 +0000718 if (!err_buf[0]) {
Wayne Davisonc9bce0b2006-10-13 23:17:33 +0000719 strlcpy(err_buf, "Error parsing options: option may "
720 "be supported on client but not on server?\n",
721 sizeof err_buf);
Andrew Tridgellcd8185f1998-11-19 06:35:49 +0000722 }
Wayne Davisone51094b2004-05-21 09:41:38 +0000723
Wayne Davisone51094b2004-05-21 09:41:38 +0000724 rprintf(FERROR, RSYNC_NAME ": %s", err_buf);
Wayne Davison8f1dc162006-02-20 17:58:13 +0000725 msleep(20);
Andrew Tridgellcd8185f1998-11-19 06:35:49 +0000726}
727
Martin Pooldafe63c2002-04-16 01:38:21 +0000728
729/**
Wayne Davison27ed20f2004-02-21 21:12:49 +0000730 * Tweak the option table to disable all options that the rsyncd.conf
731 * file has told us to refuse.
Martin Pooldafe63c2002-04-16 01:38:21 +0000732 **/
Wayne Davison27ed20f2004-02-21 21:12:49 +0000733static void set_refuse_options(char *bp)
Andrew Tridgellcd8185f1998-11-19 06:35:49 +0000734{
Wayne Davison27ed20f2004-02-21 21:12:49 +0000735 struct poptOption *op;
Wayne Davison093e8162004-08-02 07:40:34 +0000736 char *cp, shortname[2];
Wayne Davisond73e7f62004-08-04 21:20:34 +0000737 int is_wild, found_match;
Wayne Davison093e8162004-08-02 07:40:34 +0000738
739 shortname[1] = '\0';
Andrew Tridgellcd8185f1998-11-19 06:35:49 +0000740
Wayne Davison27ed20f2004-02-21 21:12:49 +0000741 while (1) {
Wayne Davison06a50542004-08-02 05:00:30 +0000742 while (*bp == ' ') bp++;
743 if (!*bp)
744 break;
Wayne Davison27ed20f2004-02-21 21:12:49 +0000745 if ((cp = strchr(bp, ' ')) != NULL)
746 *cp= '\0';
Wayne Davison093e8162004-08-02 07:40:34 +0000747 is_wild = strpbrk(bp, "*?[") != NULL;
Wayne Davisond73e7f62004-08-04 21:20:34 +0000748 found_match = 0;
Wayne Davison55afbb52004-02-21 21:36:55 +0000749 for (op = long_options; ; op++) {
Wayne Davison093e8162004-08-02 07:40:34 +0000750 *shortname = op->shortName;
Wayne Davisond73e7f62004-08-04 21:20:34 +0000751 if (!op->longName && !*shortname)
752 break;
753 if ((op->longName && wildmatch(bp, op->longName))
Wayne Davison684d7582005-02-19 22:16:39 +0000754 || (*shortname && wildmatch(bp, shortname))) {
Wayne Davisone57211c2005-01-23 01:25:36 +0000755 if (op->argInfo == POPT_ARG_VAL)
756 op->argInfo = POPT_ARG_NONE;
Wayne Davison06a50542004-08-02 05:00:30 +0000757 op->val = (op - long_options) + OPT_REFUSED_BASE;
Wayne Davisond73e7f62004-08-04 21:20:34 +0000758 found_match = 1;
Wayne Davison36719872005-02-11 10:42:55 +0000759 /* These flags are set to let us easily check
760 * an implied option later in the code. */
761 switch (*shortname) {
Wayne Davison36719872005-02-11 10:42:55 +0000762 case 'r': case 'd': case 'l': case 'p':
763 case 't': case 'g': case 'o': case 'D':
764 refused_archive_part = op->val;
765 break;
Wayne Davison854a1aa2005-10-26 16:47:15 +0000766 case 'z':
767 refused_compress = op->val;
768 break;
Wayne Davison36719872005-02-11 10:42:55 +0000769 case '\0':
770 if (wildmatch("delete", op->longName))
771 refused_delete = op->val;
Wayne Davison3296f912005-02-15 21:15:58 +0000772 else if (wildmatch("delete-before", op->longName))
773 refused_delete_before = op->val;
Wayne Davisone0e32032006-12-28 07:54:10 +0000774 else if (wildmatch("delete-during", op->longName))
775 refused_delete_during = op->val;
Wayne Davison36719872005-02-11 10:42:55 +0000776 else if (wildmatch("partial", op->longName))
777 refused_partial = op->val;
778 else if (wildmatch("progress", op->longName))
779 refused_progress = op->val;
Wayne Davisona0157882005-07-28 01:46:09 +0000780 else if (wildmatch("inplace", op->longName))
781 refused_inplace = op->val;
Wayne Davison0b52f942008-02-14 13:24:16 -0800782 else if (wildmatch("no-iconv", op->longName))
783 refused_no_iconv = op->val;
Wayne Davison36719872005-02-11 10:42:55 +0000784 break;
785 }
Wayne Davison06a50542004-08-02 05:00:30 +0000786 if (!is_wild)
787 break;
Wayne Davison27ed20f2004-02-21 21:12:49 +0000788 }
Andrew Tridgellcd8185f1998-11-19 06:35:49 +0000789 }
Wayne Davisond73e7f62004-08-04 21:20:34 +0000790 if (!found_match) {
791 rprintf(FLOG, "No match for refuse-options string \"%s\"\n",
792 bp);
793 }
Wayne Davison27ed20f2004-02-21 21:12:49 +0000794 if (!cp)
795 break;
796 *cp = ' ';
797 bp = cp + 1;
Andrew Tridgellcd8185f1998-11-19 06:35:49 +0000798 }
Andrew Tridgellcd8185f1998-11-19 06:35:49 +0000799}
800
801
Wayne Davison8db7cc22004-10-11 10:43:25 +0000802static int count_args(const char **argv)
Martin Pool2855f612001-02-23 01:02:31 +0000803{
Wayne Davisondfa32482003-03-21 18:58:50 +0000804 int i = 0;
Martin Pool2855f612001-02-23 01:02:31 +0000805
Wayne Davison8db7cc22004-10-11 10:43:25 +0000806 if (argv) {
807 while (argv[i] != NULL)
808 i++;
809 }
Wayne Davisondfa32482003-03-21 18:58:50 +0000810
811 return i;
Martin Pool2855f612001-02-23 01:02:31 +0000812}
813
814
Wayne Davison837d01d2005-10-14 19:48:34 +0000815static OFF_T parse_size_arg(char **size_arg, char def_suf)
Wayne Davison95e107d2005-04-28 16:11:32 +0000816{
Wayne Davison3c19f722005-11-15 17:49:59 +0000817 int reps, mult, make_compatible = 0;
818 const char *arg;
819 OFF_T size = 1;
Wayne Davison95e107d2005-04-28 16:11:32 +0000820
Wayne Davison2dc7b8b2006-11-09 02:39:29 +0000821 for (arg = *size_arg; isDigit(arg); arg++) {}
Wayne Davison95e107d2005-04-28 16:11:32 +0000822 if (*arg == '.')
Wayne Davison2dc7b8b2006-11-09 02:39:29 +0000823 for (arg++; isDigit(arg); arg++) {}
Wayne Davison3c19f722005-11-15 17:49:59 +0000824 switch (*arg && *arg != '+' && *arg != '-' ? *arg++ : def_suf) {
Wayne Davison837d01d2005-10-14 19:48:34 +0000825 case 'b': case 'B':
Wayne Davison3c19f722005-11-15 17:49:59 +0000826 reps = 0;
Wayne Davison837d01d2005-10-14 19:48:34 +0000827 break;
Wayne Davison95e107d2005-04-28 16:11:32 +0000828 case 'k': case 'K':
Wayne Davison3c19f722005-11-15 17:49:59 +0000829 reps = 1;
Wayne Davison95e107d2005-04-28 16:11:32 +0000830 break;
831 case 'm': case 'M':
Wayne Davison3c19f722005-11-15 17:49:59 +0000832 reps = 2;
Wayne Davison95e107d2005-04-28 16:11:32 +0000833 break;
834 case 'g': case 'G':
Wayne Davison3c19f722005-11-15 17:49:59 +0000835 reps = 3;
Wayne Davison95e107d2005-04-28 16:11:32 +0000836 break;
837 default:
Wayne Davison3c19f722005-11-15 17:49:59 +0000838 return -1;
Wayne Davison95e107d2005-04-28 16:11:32 +0000839 }
Wayne Davison3c19f722005-11-15 17:49:59 +0000840 if (*arg == 'b' || *arg == 'B')
841 mult = 1000, make_compatible = 1, arg++;
842 else if (!*arg || *arg == '+' || *arg == '-')
843 mult = 1024;
844 else if (strncasecmp(arg, "ib", 2) == 0)
845 mult = 1024, arg += 2;
846 else
847 return -1;
848 while (reps--)
849 size *= mult;
850 size *= atof(*size_arg);
851 if ((*arg == '+' || *arg == '-') && arg[1] == '1')
852 size += atoi(arg), make_compatible = 1, arg += 2;
853 if (*arg)
854 return -1;
Wayne Davisonaeb213e2005-10-14 18:56:07 +0000855 if (size > 0 && make_compatible) {
Wayne Davison74de13d2005-10-14 20:15:18 +0000856 /* We convert this manually because we may need %lld precision,
857 * and that's not a portable sprintf() escape. */
Wayne Davison8f14cc42005-11-12 19:53:17 +0000858 char buf[128], *s = buf + sizeof buf - 1;
Wayne Davisonaeb213e2005-10-14 18:56:07 +0000859 OFF_T num = size;
Wayne Davison8f14cc42005-11-12 19:53:17 +0000860 *s = '\0';
Wayne Davisonaeb213e2005-10-14 18:56:07 +0000861 while (num) {
Wayne Davison26404272006-11-21 08:35:58 +0000862 *--s = (char)(num % 10) + '0';
Wayne Davisonaeb213e2005-10-14 18:56:07 +0000863 num /= 10;
864 }
865 if (!(*size_arg = strdup(s)))
866 out_of_memory("parse_size_arg");
867 }
Wayne Davison95e107d2005-04-28 16:11:32 +0000868 return size;
869}
870
871
Wayne Davison36719872005-02-11 10:42:55 +0000872static void create_refuse_error(int which)
873{
874 /* The "which" value is the index + OPT_REFUSED_BASE. */
875 struct poptOption *op = &long_options[which - OPT_REFUSED_BASE];
876 int n = snprintf(err_buf, sizeof err_buf,
877 "The server is configured to refuse --%s\n",
878 op->longName) - 1;
879 if (op->shortName) {
880 snprintf(err_buf + n, sizeof err_buf - n,
881 " (-%c)\n", op->shortName);
882 }
883}
884
885
Martin Pooldafe63c2002-04-16 01:38:21 +0000886/**
887 * Process command line arguments. Called on both local and remote.
888 *
889 * @retval 1 if all options are OK; with globals set to appropriate
890 * values
891 *
892 * @retval 0 on error, with err_buf containing an explanation
893 **/
Wayne Davison53936ef2008-03-15 11:25:01 -0700894int parse_arguments(int *argc_p, const char ***argv_p)
Andrew Tridgell7a6421f1998-05-10 07:25:40 +0000895{
Wayne Davison7a4adda2007-09-09 07:53:18 +0000896 static poptContext pc;
Wayne Davisonffbffc62007-09-08 19:42:27 +0000897 char *ref = lp_refuse_options(module_id);
898 const char *arg, **argv = *argv_p;
899 int argc = *argc_p;
900 int opt;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +0000901
Wayne Davison27ed20f2004-02-21 21:12:49 +0000902 if (ref && *ref)
903 set_refuse_options(ref);
Wayne Davison0b52f942008-02-14 13:24:16 -0800904 if (am_daemon) {
Wayne Davison232658d2006-05-30 17:14:17 +0000905 set_refuse_options("log-file*");
Wayne Davison2357a512008-03-16 12:11:19 -0700906#ifdef ICONV_OPTION
Wayne Davison0b52f942008-02-14 13:24:16 -0800907 if (!*lp_charset(module_id))
908 set_refuse_options("iconv");
Wayne Davison2357a512008-03-16 12:11:19 -0700909#endif
Wayne Davison0b52f942008-02-14 13:24:16 -0800910 }
Wayne Davison27ed20f2004-02-21 21:12:49 +0000911
Wayne Davison332cf6d2007-04-26 05:53:13 +0000912#ifdef ICONV_OPTION
Wayne Davisona4453602007-09-18 01:11:54 +0000913 if (!am_daemon && !protect_args && (arg = getenv("RSYNC_ICONV")) != NULL && *arg)
Wayne Davison332cf6d2007-04-26 05:53:13 +0000914 iconv_opt = strdup(arg);
915#endif
916
Wayne Davisondfa32482003-03-21 18:58:50 +0000917 /* TODO: Call poptReadDefaultConfig; handle errors. */
Andrew Tridgellcd8185f1998-11-19 06:35:49 +0000918
Wayne Davisondfa32482003-03-21 18:58:50 +0000919 /* The context leaks in case of an error, but if there's a
920 * problem we always exit anyhow. */
Wayne Davison7a4adda2007-09-09 07:53:18 +0000921 if (pc)
922 poptFreeContext(pc);
923 pc = poptGetContext(RSYNC_NAME, argc, argv, long_options, 0);
924 if (!am_server)
925 poptReadDefaultConfig(pc, 0);
Martin Pool2855f612001-02-23 01:02:31 +0000926
927 while ((opt = poptGetNextOpt(pc)) != -1) {
Wayne Davisondfa32482003-03-21 18:58:50 +0000928 /* most options are handled automatically by popt;
929 * only special cases are returned and listed here. */
Martin Pool2855f612001-02-23 01:02:31 +0000930
Andrew Tridgelld8537831998-07-17 10:00:43 +0000931 switch (opt) {
932 case OPT_VERSION:
Wayne Davisondfa32482003-03-21 18:58:50 +0000933 print_rsync_version(FINFO);
Andrew Tridgelld8537831998-07-17 10:00:43 +0000934 exit_cleanup(0);
Wayne Davisondfa32482003-03-21 18:58:50 +0000935
Wayne Davison0ccffd72006-01-21 20:15:49 +0000936 case OPT_SERVER:
937 if (!am_server) {
938 /* Disable popt aliases on the server side and
939 * then start parsing the options again. */
940 poptFreeContext(pc);
Wayne Davisonffbffc62007-09-08 19:42:27 +0000941 pc = poptGetContext(RSYNC_NAME, argc, argv,
Wayne Davison0ccffd72006-01-21 20:15:49 +0000942 long_options, 0);
943 am_server = 1;
944 }
Wayne Davison332cf6d2007-04-26 05:53:13 +0000945#ifdef ICONV_OPTION
946 iconv_opt = NULL;
947#endif
Wayne Davison0ccffd72006-01-21 20:15:49 +0000948 break;
949
950 case OPT_SENDER:
951 if (!am_server) {
952 usage(FERROR);
953 exit_cleanup(RERR_SYNTAX);
954 }
955 am_sender = 1;
956 break;
957
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000958 case OPT_DAEMON:
959 if (am_daemon) {
Wayne Davisonc9bce0b2006-10-13 23:17:33 +0000960 strlcpy(err_buf,
961 "Attempt to hack rsync thwarted!\n",
962 sizeof err_buf);
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000963 return 0;
964 }
Wayne Davison332cf6d2007-04-26 05:53:13 +0000965#ifdef ICONV_OPTION
966 iconv_opt = NULL;
967#endif
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000968 poptFreeContext(pc);
Wayne Davisonffbffc62007-09-08 19:42:27 +0000969 pc = poptGetContext(RSYNC_NAME, argc, argv,
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000970 long_daemon_options, 0);
971 while ((opt = poptGetNextOpt(pc)) != -1) {
972 switch (opt) {
973 case 'h':
974 daemon_usage(FINFO);
975 exit_cleanup(0);
976
Wayne Davison1bd9db72005-01-28 17:07:54 +0000977 case 'v':
978 verbose++;
979 break;
980
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000981 default:
982 rprintf(FERROR,
983 "rsync: %s: %s (in daemon mode)\n",
984 poptBadOption(pc, POPT_BADOPTION_NOALIAS),
985 poptStrerror(opt));
986 goto daemon_error;
987 }
988 }
Wayne Davisonb6e22a42005-08-30 16:13:54 +0000989
990 if (tmpdir && strlen(tmpdir) >= MAXPATHLEN - 10) {
991 snprintf(err_buf, sizeof err_buf,
992 "the --temp-dir path is WAY too long.\n");
993 return 0;
994 }
995
Wayne Davison3ac7f5d2004-10-14 17:08:15 +0000996 if (!daemon_opt) {
997 rprintf(FERROR, "Daemon option(s) used without --daemon.\n");
998 daemon_error:
999 rprintf(FERROR,
1000 "(Type \"rsync --daemon --help\" for assistance with daemon mode.)\n");
1001 exit_cleanup(RERR_SYNTAX);
1002 }
Wayne Davisonb6e22a42005-08-30 16:13:54 +00001003
Wayne Davisonffbffc62007-09-08 19:42:27 +00001004 *argv_p = argv = poptGetArgs(pc);
1005 *argc_p = argc = count_args(argv);
Wayne Davison7f2a1f62005-02-25 17:08:31 +00001006 am_starting_up = 0;
Wayne Davison3ac7f5d2004-10-14 17:08:15 +00001007 daemon_opt = 0;
1008 am_daemon = 1;
1009 return 1;
1010
Andrew Tridgell5b56cc12000-09-06 02:12:13 +00001011 case OPT_MODIFY_WINDOW:
Wayne Davisondfa32482003-03-21 18:58:50 +00001012 /* The value has already been set by popt, but
1013 * we need to remember that we're using a
1014 * non-default setting. */
Andrew Tridgell5b56cc12000-09-06 02:12:13 +00001015 modify_window_set = 1;
1016 break;
Wayne Davison1de50992002-05-03 22:59:17 +00001017
Wayne Davisonaa4d3b42005-01-25 00:52:56 +00001018 case OPT_FILTER:
Wayne Davison3a5e9222005-02-04 21:13:03 +00001019 parse_rule(&filter_list, poptGetOptArg(pc), 0, 0);
Andrew Tridgelld8537831998-07-17 10:00:43 +00001020 break;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +00001021
Wayne Davisonaa4d3b42005-01-25 00:52:56 +00001022 case OPT_EXCLUDE:
Wayne Davison3a5e9222005-02-04 21:13:03 +00001023 parse_rule(&filter_list, poptGetOptArg(pc),
Wayne Davison0a68f862005-02-03 19:00:17 +00001024 0, XFLG_OLD_PREFIXES);
Wayne Davisonaa4d3b42005-01-25 00:52:56 +00001025 break;
1026
Andrew Tridgelld8537831998-07-17 10:00:43 +00001027 case OPT_INCLUDE:
Wayne Davison3a5e9222005-02-04 21:13:03 +00001028 parse_rule(&filter_list, poptGetOptArg(pc),
Wayne Davison0a68f862005-02-03 19:00:17 +00001029 MATCHFLG_INCLUDE, XFLG_OLD_PREFIXES);
Andrew Tridgelld8537831998-07-17 10:00:43 +00001030 break;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +00001031
Andrew Tridgelld8537831998-07-17 10:00:43 +00001032 case OPT_EXCLUDE_FROM:
David Dykstra93695762002-02-27 22:49:57 +00001033 case OPT_INCLUDE_FROM:
Wayne Davison7be73df2004-03-27 09:46:42 +00001034 arg = poptGetOptArg(pc);
Wayne Davison1a7f3d92006-10-12 03:01:18 +00001035 if (sanitize_paths)
Wayne Davisond48810b2008-03-20 11:59:54 -07001036 arg = sanitize_path(NULL, arg, NULL, 0, SP_DEFAULT);
Wayne Davison819bfe42008-03-20 10:42:43 -07001037 if (daemon_filter_list.head) {
Wayne Davison200aec72007-09-23 19:10:10 +00001038 int rej;
Wayne Davisona1018692007-12-16 14:16:37 -08001039 char *dir, *cp = strdup(arg);
Wayne Davisond3ef9852006-04-28 17:34:53 +00001040 if (!cp)
1041 out_of_memory("parse_arguments");
Wayne Davison36719872005-02-11 10:42:55 +00001042 if (!*cp)
1043 goto options_rejected;
Wayne Davisona1018692007-12-16 14:16:37 -08001044 dir = cp + (*cp == '/' ? module_dirlen : 0);
1045 clean_fname(dir, CFN_COLLAPSE_DOT_DOT_DIRS);
Wayne Davison1df02d12008-03-24 10:09:00 -07001046 rej = check_filter(&daemon_filter_list, FLOG, dir, 0) < 0;
Wayne Davisond3ef9852006-04-28 17:34:53 +00001047 free(cp);
Wayne Davison200aec72007-09-23 19:10:10 +00001048 if (rej)
1049 goto options_rejected;
Wayne Davisonba3db472004-08-26 17:39:48 +00001050 }
Wayne Davison3a5e9222005-02-04 21:13:03 +00001051 parse_filter_file(&filter_list, arg,
1052 opt == OPT_INCLUDE_FROM ? MATCHFLG_INCLUDE : 0,
1053 XFLG_FATAL_ERRORS | XFLG_OLD_PREFIXES);
David Dykstra93695762002-02-27 22:49:57 +00001054 break;
1055
Wayne Davisonb6164932005-08-27 21:01:45 +00001056 case 'a':
1057 if (refused_archive_part) {
1058 create_refuse_error(refused_archive_part);
1059 return 0;
1060 }
1061 if (!recurse) /* preserve recurse == 2 */
1062 recurse = 1;
1063#ifdef SUPPORT_LINKS
1064 preserve_links = 1;
1065#endif
1066 preserve_perms = 1;
Wayne Davison8f48ba02011-02-21 09:48:37 -08001067 preserve_times = 1;
Wayne Davisonb6164932005-08-27 21:01:45 +00001068 preserve_gid = 1;
1069 preserve_uid = 1;
1070 preserve_devices = 1;
Wayne Davisonb5c6a6a2006-01-26 10:38:58 +00001071 preserve_specials = 1;
1072 break;
1073
1074 case 'D':
1075 preserve_devices = preserve_specials = 1;
1076 break;
1077
1078 case OPT_NO_D:
1079 preserve_devices = preserve_specials = 0;
Wayne Davisonb6164932005-08-27 21:01:45 +00001080 break;
1081
Wayne Davison3ca9e5d2006-02-08 16:52:25 +00001082 case 'h':
1083 human_readable++;
1084 break;
1085
Wayne Davisone0e32032006-12-28 07:54:10 +00001086 case 'H':
1087 preserve_hard_links++;
1088 break;
1089
Wayne Davison487094a2006-01-20 18:49:07 +00001090 case 'i':
1091 itemize_changes++;
1092 break;
1093
Andrew Tridgelld8537831998-07-17 10:00:43 +00001094 case 'v':
1095 verbose++;
1096 break;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +00001097
David Dykstrab86f0ce1999-02-09 17:25:35 +00001098 case 'q':
Wayne Davison53936ef2008-03-15 11:25:01 -07001099 quiet++;
David Dykstrab86f0ce1999-02-09 17:25:35 +00001100 break;
1101
Wayne Davison243c9952006-01-21 00:36:15 +00001102 case 'x':
1103 one_file_system++;
1104 break;
1105
Wayne Davisonaa4d3b42005-01-25 00:52:56 +00001106 case 'F':
1107 switch (++F_option_cnt) {
1108 case 1:
Wayne Davison3a5e9222005-02-04 21:13:03 +00001109 parse_rule(&filter_list,": /.rsync-filter",0,0);
Wayne Davisonaa4d3b42005-01-25 00:52:56 +00001110 break;
1111 case 2:
Wayne Davison3a5e9222005-02-04 21:13:03 +00001112 parse_rule(&filter_list,"- .rsync-filter",0,0);
Wayne Davisonaa4d3b42005-01-25 00:52:56 +00001113 break;
1114 }
1115 break;
1116
Andrew Tridgelld9fcc191999-10-31 02:47:30 +00001117 case 'P':
Wayne Davison36719872005-02-11 10:42:55 +00001118 if (refused_partial || refused_progress) {
1119 create_refuse_error(refused_partial
1120 ? refused_partial : refused_progress);
1121 return 0;
1122 }
Andrew Tridgelld9fcc191999-10-31 02:47:30 +00001123 do_progress = 1;
1124 keep_partial = 1;
1125 break;
1126
Wayne Davison854a1aa2005-10-26 16:47:15 +00001127 case 'z':
1128 if (def_compress_level < Z_DEFAULT_COMPRESSION
1129 || def_compress_level > Z_BEST_COMPRESSION) {
1130 snprintf(err_buf, sizeof err_buf,
1131 "--compress-level value is invalid: %d\n",
1132 def_compress_level);
1133 return 0;
1134 }
1135 do_compression = def_compress_level != Z_NO_COMPRESSION;
1136 if (do_compression && refused_compress) {
1137 create_refuse_error(refused_compress);
1138 return 0;
1139 }
1140 break;
1141
David Dykstra088aac82002-02-06 21:20:48 +00001142 case OPT_WRITE_BATCH:
Wayne Davison9b3318b2004-07-15 16:27:02 +00001143 /* batch_name is already set */
David Dykstra088aac82002-02-06 21:20:48 +00001144 write_batch = 1;
1145 break;
1146
Wayne Davison11e758a2005-04-09 18:59:47 +00001147 case OPT_ONLY_WRITE_BATCH:
1148 /* batch_name is already set */
1149 write_batch = -1;
1150 break;
1151
Martin Pool76f79ba2002-01-23 05:51:06 +00001152 case OPT_READ_BATCH:
Wayne Davison9b3318b2004-07-15 16:27:02 +00001153 /* batch_name is already set */
Martin Pool6902ed12001-08-14 02:04:47 +00001154 read_batch = 1;
1155 break;
Wayne Davisonea5164d2003-03-30 23:00:42 +00001156
Wayne Davison0b52f942008-02-14 13:24:16 -08001157 case OPT_NO_ICONV:
Wayne Davison15dbffc2008-02-18 16:48:20 -08001158#ifdef ICONV_OPTION
Wayne Davison0b52f942008-02-14 13:24:16 -08001159 iconv_opt = NULL;
Wayne Davison15dbffc2008-02-18 16:48:20 -08001160#endif
Wayne Davison0b52f942008-02-14 13:24:16 -08001161 break;
1162
Wayne Davison7d5acf12004-11-11 01:45:25 +00001163 case OPT_MAX_SIZE:
Wayne Davison837d01d2005-10-14 19:48:34 +00001164 if ((max_size = parse_size_arg(&max_size_arg, 'b')) <= 0) {
Wayne Davisone012f852004-11-27 17:52:51 +00001165 snprintf(err_buf, sizeof err_buf,
Wayne Davison7d5acf12004-11-11 01:45:25 +00001166 "--max-size value is invalid: %s\n",
1167 max_size_arg);
Wayne Davisone012f852004-11-27 17:52:51 +00001168 return 0;
Wayne Davison7d5acf12004-11-11 01:45:25 +00001169 }
1170 break;
1171
Wayne Davison74de13d2005-10-14 20:15:18 +00001172 case OPT_MIN_SIZE:
1173 if ((min_size = parse_size_arg(&min_size_arg, 'b')) <= 0) {
1174 snprintf(err_buf, sizeof err_buf,
1175 "--min-size value is invalid: %s\n",
1176 min_size_arg);
1177 return 0;
1178 }
1179 break;
1180
Wayne Davison936fa862007-09-01 16:38:00 +00001181 case OPT_APPEND:
1182 if (am_server)
1183 append_mode++;
1184 else
1185 append_mode = 1;
1186 break;
1187
David Dykstra59c95e42002-08-29 14:44:55 +00001188 case OPT_LINK_DEST:
Wayne Davisonfcecb702006-05-05 06:16:22 +00001189#ifdef SUPPORT_HARD_LINKS
David Dykstra59c95e42002-08-29 14:44:55 +00001190 link_dest = 1;
Wayne Davisone012f852004-11-27 17:52:51 +00001191 dest_option = "--link-dest";
1192 goto set_dest_dir;
David Dykstra59c95e42002-08-29 14:44:55 +00001193#else
Wayne Davisond175d7e2003-08-01 07:58:44 +00001194 snprintf(err_buf, sizeof err_buf,
Wayne Davisondfa32482003-03-21 18:58:50 +00001195 "hard links are not supported on this %s\n",
David Dykstra59c95e42002-08-29 14:44:55 +00001196 am_server ? "server" : "client");
David Dykstra59c95e42002-08-29 14:44:55 +00001197 return 0;
1198#endif
1199
Wayne Davison1de3e992005-03-11 17:35:59 +00001200 case OPT_COPY_DEST:
1201 copy_dest = 1;
1202 dest_option = "--copy-dest";
1203 goto set_dest_dir;
1204
Wayne Davisone012f852004-11-27 17:52:51 +00001205 case OPT_COMPARE_DEST:
1206 compare_dest = 1;
1207 dest_option = "--compare-dest";
1208 set_dest_dir:
Wayne Davison3b26bba2005-01-15 21:23:04 +00001209 if (basis_dir_cnt >= MAX_BASIS_DIRS) {
Wayne Davisone012f852004-11-27 17:52:51 +00001210 snprintf(err_buf, sizeof err_buf,
1211 "ERROR: at most %d %s args may be specified\n",
1212 MAX_BASIS_DIRS, dest_option);
1213 return 0;
1214 }
Wayne Davisonad77db82006-04-28 16:57:39 +00001215 /* We defer sanitizing this arg until we know what
1216 * our destination directory is going to be. */
1217 basis_dir[basis_dir_cnt++] = (char *)poptGetOptArg(pc);
Wayne Davisone012f852004-11-27 17:52:51 +00001218 break;
1219
Wayne Davisone16adcd2006-01-21 09:14:42 +00001220 case OPT_CHMOD:
1221 arg = poptGetOptArg(pc);
Wayne Davisonbbe42182006-01-30 17:53:19 +00001222 if (!parse_chmod(arg, &chmod_modes)) {
Wayne Davisone16adcd2006-01-21 09:14:42 +00001223 snprintf(err_buf, sizeof err_buf,
1224 "Invalid argument passed to --chmod (%s)\n",
1225 arg);
1226 return 0;
1227 }
1228 break;
1229
Wayne Davisonf5a910d2006-01-21 19:52:55 +00001230 case OPT_HELP:
1231 usage(FINFO);
1232 exit_cleanup(0);
1233
Wayne Davison1c3344a2007-03-11 00:13:34 +00001234 case 'A':
1235#ifdef SUPPORT_ACLS
1236 preserve_acls = 1;
1237 preserve_perms = 1;
1238 break;
1239#else
1240 /* FIXME: this should probably be ignored with a
Wayne Davisoneb8f5c72007-09-30 07:30:48 +00001241 * warning and then countermeasures taken to
1242 * restrict group and other access in the presence
1243 * of any more restrictive ACLs, but this is safe
Wayne Davison1c3344a2007-03-11 00:13:34 +00001244 * for now */
1245 snprintf(err_buf,sizeof(err_buf),
1246 "ACLs are not supported on this %s\n",
1247 am_server ? "server" : "client");
1248 return 0;
1249#endif
1250
Wayne Davison16edf862007-04-07 17:22:25 +00001251 case 'X':
1252#ifdef SUPPORT_XATTRS
Wayne Davison524eaa82007-07-02 21:35:14 +00001253 preserve_xattrs++;
Wayne Davison16edf862007-04-07 17:22:25 +00001254 break;
1255#else
1256 snprintf(err_buf,sizeof(err_buf),
1257 "extended attributes are not supported on this %s\n",
1258 am_server ? "server" : "client");
1259 return 0;
1260#endif
Wayne Davison1c3344a2007-03-11 00:13:34 +00001261
Andrew Tridgelld8537831998-07-17 10:00:43 +00001262 default:
Wayne Davison55afbb52004-02-21 21:36:55 +00001263 /* A large opt value means that set_refuse_options()
Wayne Davison36719872005-02-11 10:42:55 +00001264 * turned this option off. */
Wayne Davisonc67d1382004-02-22 08:56:43 +00001265 if (opt >= OPT_REFUSED_BASE) {
Wayne Davison36719872005-02-11 10:42:55 +00001266 create_refuse_error(opt);
1267 return 0;
Wayne Davison27ed20f2004-02-21 21:12:49 +00001268 }
Wayne Davison36719872005-02-11 10:42:55 +00001269 snprintf(err_buf, sizeof err_buf, "%s%s: %s\n",
1270 am_server ? "on remote machine: " : "",
1271 poptBadOption(pc, POPT_BADOPTION_NOALIAS),
1272 poptStrerror(opt));
Wayne Davisondfa32482003-03-21 18:58:50 +00001273 return 0;
Andrew Tridgelld8537831998-07-17 10:00:43 +00001274 }
Andrew Tridgell7a6421f1998-05-10 07:25:40 +00001275 }
Martin Pool2855f612001-02-23 01:02:31 +00001276
Wayne Davison20893752008-03-30 08:05:50 -07001277 if (human_readable && argc == 2 && !am_server) {
Wayne Davison3ca9e5d2006-02-08 16:52:25 +00001278 /* Allow the old meaning of 'h' (--help) on its own. */
Wayne Davison05724c02005-11-15 06:35:27 +00001279 usage(FINFO);
1280 exit_cleanup(0);
1281 }
1282
Wayne Davison332cf6d2007-04-26 05:53:13 +00001283#ifdef ICONV_OPTION
Wayne Davisona4453602007-09-18 01:11:54 +00001284 if (iconv_opt && protect_args != 2) {
Wayne Davison332cf6d2007-04-26 05:53:13 +00001285 if (!am_server && strcmp(iconv_opt, "-") == 0)
1286 iconv_opt = NULL;
1287 else
1288 need_unsorted_flist = 1;
1289 }
Wayne Davison0b52f942008-02-14 13:24:16 -08001290 if (refused_no_iconv && !iconv_opt) {
1291 create_refuse_error(refused_no_iconv);
1292 return 0;
1293 }
Wayne Davison332cf6d2007-04-26 05:53:13 +00001294#endif
1295
Wayne Davison53936ef2008-03-15 11:25:01 -07001296 if (protect_args == 1 && am_server)
1297 return 1;
Wayne Davisona4453602007-09-18 01:11:54 +00001298
Wayne Davison73cb6732008-03-24 09:33:07 -07001299 *argv_p = argv = poptGetArgs(pc);
1300 *argc_p = argc = count_args(argv);
1301
Wayne Davison4f5b0752005-02-14 00:53:43 +00001302#ifndef SUPPORT_LINKS
Wayne Davison54e87b42004-02-02 21:33:10 +00001303 if (preserve_links && !am_sender) {
Wayne Davisone1add892004-02-01 17:29:41 +00001304 snprintf(err_buf, sizeof err_buf,
1305 "symlinks are not supported on this %s\n",
1306 am_server ? "server" : "client");
Wayne Davisone1add892004-02-01 17:29:41 +00001307 return 0;
1308 }
1309#endif
1310
Wayne Davison4f5b0752005-02-14 00:53:43 +00001311#ifndef SUPPORT_HARD_LINKS
Wayne Davisone1add892004-02-01 17:29:41 +00001312 if (preserve_hard_links) {
1313 snprintf(err_buf, sizeof err_buf,
1314 "hard links are not supported on this %s\n",
1315 am_server ? "server" : "client");
Wayne Davisone1add892004-02-01 17:29:41 +00001316 return 0;
1317 }
1318#endif
1319
Wayne Davisoncbbd8e22008-03-07 15:23:39 -08001320#ifdef SUPPORT_XATTRS
1321 if (am_root < 0 && preserve_xattrs > 1) {
1322 snprintf(err_buf, sizeof err_buf,
1323 "--fake-super conflicts with -XX\n");
1324 return 0;
1325 }
1326#else
Wayne Davison9439c0c2007-04-24 07:32:44 +00001327 if (am_root < 0) {
1328 snprintf(err_buf, sizeof err_buf,
1329 "--fake-super requires an rsync with extended attributes enabled\n");
1330 return 0;
1331 }
1332#endif
1333
David Dykstra088aac82002-02-06 21:20:48 +00001334 if (write_batch && read_batch) {
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001335 snprintf(err_buf, sizeof err_buf,
Wayne Davison36119892004-07-21 22:50:11 +00001336 "--write-batch and --read-batch can not be used together\n");
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001337 return 0;
David Dykstra088aac82002-02-06 21:20:48 +00001338 }
Wayne Davison11e758a2005-04-09 18:59:47 +00001339 if (write_batch > 0 || read_batch) {
Wayne Davison94327ff2004-07-15 19:06:32 +00001340 if (am_server) {
1341 rprintf(FINFO,
1342 "ignoring --%s-batch option sent to server\n",
1343 write_batch ? "write" : "read");
1344 /* We don't actually exit_cleanup(), so that we can
1345 * still service older version clients that still send
1346 * batch args to server. */
1347 read_batch = write_batch = 0;
1348 batch_name = NULL;
Wayne Davison254ee3b2005-03-24 16:41:16 +00001349 } else if (dry_run)
1350 write_batch = 0;
Wayne Davison69e2b4e2008-01-19 11:20:17 -08001351 } else if (write_batch < 0 && dry_run)
1352 write_batch = 0;
Wayne Davison36119892004-07-21 22:50:11 +00001353 if (read_batch && files_from) {
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001354 snprintf(err_buf, sizeof err_buf,
Wayne Davison36119892004-07-21 22:50:11 +00001355 "--read-batch cannot be used with --files-from\n");
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001356 return 0;
Wayne Davison36119892004-07-21 22:50:11 +00001357 }
Wayne Davison9be50932009-04-12 12:57:31 -07001358 if (read_batch && remove_source_files) {
1359 snprintf(err_buf, sizeof err_buf,
1360 "--read-batch cannot be used with --remove-%s-files\n",
1361 remove_source_files == 1 ? "source" : "sent");
1362 return 0;
1363 }
Wayne Davison9b3318b2004-07-15 16:27:02 +00001364 if (batch_name && strlen(batch_name) > MAX_BATCH_NAME_LEN) {
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001365 snprintf(err_buf, sizeof err_buf,
Wayne Davison9b3318b2004-07-15 16:27:02 +00001366 "the batch-file name must be %d characters or less.\n",
1367 MAX_BATCH_NAME_LEN);
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001368 return 0;
Wayne Davisonbeb93682004-01-19 23:33:02 +00001369 }
David Dykstra088aac82002-02-06 21:20:48 +00001370
Wayne Davisonce58b1b2004-01-22 01:20:24 +00001371 if (tmpdir && strlen(tmpdir) >= MAXPATHLEN - 10) {
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001372 snprintf(err_buf, sizeof err_buf,
1373 "the --temp-dir path is WAY too long.\n");
1374 return 0;
Wayne Davisonce58b1b2004-01-22 01:20:24 +00001375 }
1376
Wayne Davison7b9598b2007-07-15 05:42:30 +00001377 if (max_delete < 0 && max_delete != INT_MIN) {
1378 /* Negative numbers are treated as "no deletions". */
1379 max_delete = 0;
1380 }
1381
Wayne Davison1de3e992005-03-11 17:35:59 +00001382 if (compare_dest + copy_dest + link_dest > 1) {
Wayne Davisone012f852004-11-27 17:52:51 +00001383 snprintf(err_buf, sizeof err_buf,
Wayne Davison1de3e992005-03-11 17:35:59 +00001384 "You may not mix --compare-dest, --copy-dest, and --link-dest.\n");
Wayne Davisone012f852004-11-27 17:52:51 +00001385 return 0;
1386 }
1387
Wayne Davisonb6164932005-08-27 21:01:45 +00001388 if (files_from) {
1389 if (recurse == 1) /* preserve recurse == 2 */
1390 recurse = 0;
Wayne Davison550d4e22005-09-29 17:27:11 +00001391 if (xfer_dirs < 0)
Wayne Davisonb6164932005-08-27 21:01:45 +00001392 xfer_dirs = 1;
Wayne Davisondfa32482003-03-21 18:58:50 +00001393 }
Wayne Davison51d48392005-01-22 22:48:34 +00001394
Wayne Davison20893752008-03-30 08:05:50 -07001395 if (argc < 2 && !read_batch && !am_server)
Wayne Davison73cb6732008-03-24 09:33:07 -07001396 list_only |= 1;
1397
1398 if (xfer_dirs >= 4) {
1399 parse_rule(&filter_list, "- /*/*", 0, 0);
1400 recurse = xfer_dirs = 1;
1401 } else if (recurse)
1402 xfer_dirs = 1;
1403 else if (xfer_dirs < 0)
1404 xfer_dirs = list_only ? 1 : 0;
Wayne Davisondfa32482003-03-21 18:58:50 +00001405
Wayne Davisonea5164d2003-03-30 23:00:42 +00001406 if (relative_paths < 0)
1407 relative_paths = files_from? 1 : 0;
Wayne Davison89f2a4c2005-07-22 19:05:25 +00001408 if (!relative_paths)
1409 implied_dirs = 0;
Wayne Davisonea5164d2003-03-30 23:00:42 +00001410
Wayne Davisone0e32032006-12-28 07:54:10 +00001411 if (delete_before + !!delete_during + delete_after > 1) {
Wayne Davison3359acb2005-01-25 03:08:58 +00001412 snprintf(err_buf, sizeof err_buf,
Wayne Davisonc6eb7fa2005-01-28 07:39:09 +00001413 "You may not combine multiple --delete-WHEN options.\n");
Wayne Davison3359acb2005-01-25 03:08:58 +00001414 return 0;
1415 }
Wayne Davisonf5a910d2006-01-21 19:52:55 +00001416 if (delete_before || delete_during || delete_after)
Wayne Davison51d48392005-01-22 22:48:34 +00001417 delete_mode = 1;
Wayne Davison3296f912005-02-15 21:15:58 +00001418 else if (delete_mode || delete_excluded) {
Wayne Davisone0e32032006-12-28 07:54:10 +00001419 /* Only choose now between before & during if one is refused. */
Wayne Davison3296f912005-02-15 21:15:58 +00001420 if (refused_delete_before) {
Wayne Davisone0e32032006-12-28 07:54:10 +00001421 if (!refused_delete_during)
1422 delete_during = 1;
1423 else {
1424 create_refuse_error(refused_delete_before);
1425 return 0;
1426 }
1427 } else if (refused_delete_during)
1428 delete_before = 1;
1429 delete_mode = 1;
Wayne Davison3296f912005-02-15 21:15:58 +00001430 }
Wayne Davison89fb5022006-03-28 23:09:36 +00001431 if (!xfer_dirs && delete_mode) {
1432 snprintf(err_buf, sizeof err_buf,
Wayne Davison95236702009-09-07 14:22:59 -07001433 "--delete does not work without --recursive (-r) or --dirs (-d).\n");
Wayne Davison89fb5022006-03-28 23:09:36 +00001434 return 0;
Wayne Davisonf5a910d2006-01-21 19:52:55 +00001435 }
Wayne Davison51d48392005-01-22 22:48:34 +00001436
Wayne Davison36719872005-02-11 10:42:55 +00001437 if (delete_mode && refused_delete) {
1438 create_refuse_error(refused_delete);
1439 return 0;
1440 }
1441
Wayne Davison47c11972006-06-30 15:52:52 +00001442 if (remove_source_files) {
1443 /* We only want to infer this refusal of --remove-source-files
Wayne Davison07c6ae72005-02-20 01:04:40 +00001444 * via the refusal of "delete", not any of the "delete-FOO"
1445 * options. */
1446 if (refused_delete && am_sender) {
1447 create_refuse_error(refused_delete);
1448 return 0;
1449 }
1450 need_messages_from_generator = 1;
1451 }
1452
Wayne Davison7be73df2004-03-27 09:46:42 +00001453 if (sanitize_paths) {
1454 int i;
Wayne Davisonffbffc62007-09-08 19:42:27 +00001455 for (i = argc; i-- > 0; )
Wayne Davisond48810b2008-03-20 11:59:54 -07001456 argv[i] = sanitize_path(NULL, argv[i], "", 0, SP_KEEP_DOT_DIRS);
Wayne Davison1a7f3d92006-10-12 03:01:18 +00001457 if (tmpdir)
Wayne Davisond48810b2008-03-20 11:59:54 -07001458 tmpdir = sanitize_path(NULL, tmpdir, NULL, 0, SP_DEFAULT);
Wayne Davison1a7f3d92006-10-12 03:01:18 +00001459 if (backup_dir)
Wayne Davisond48810b2008-03-20 11:59:54 -07001460 backup_dir = sanitize_path(NULL, backup_dir, NULL, 0, SP_DEFAULT);
Wayne Davison7be73df2004-03-27 09:46:42 +00001461 }
Wayne Davison819bfe42008-03-20 10:42:43 -07001462 if (daemon_filter_list.head && !am_sender) {
1463 struct filter_list_struct *elp = &daemon_filter_list;
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001464 if (tmpdir) {
Wayne Davisona1018692007-12-16 14:16:37 -08001465 char *dir;
Wayne Davison36719872005-02-11 10:42:55 +00001466 if (!*tmpdir)
1467 goto options_rejected;
Wayne Davisona1018692007-12-16 14:16:37 -08001468 dir = tmpdir + (*tmpdir == '/' ? module_dirlen : 0);
1469 clean_fname(dir, CFN_COLLAPSE_DOT_DOT_DIRS);
Wayne Davison1df02d12008-03-24 10:09:00 -07001470 if (check_filter(elp, FLOG, dir, 1) < 0)
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001471 goto options_rejected;
1472 }
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001473 if (backup_dir) {
Wayne Davisona1018692007-12-16 14:16:37 -08001474 char *dir;
Wayne Davison36719872005-02-11 10:42:55 +00001475 if (!*backup_dir)
1476 goto options_rejected;
Wayne Davisona1018692007-12-16 14:16:37 -08001477 dir = backup_dir + (*backup_dir == '/' ? module_dirlen : 0);
1478 clean_fname(dir, CFN_COLLAPSE_DOT_DOT_DIRS);
Wayne Davison1df02d12008-03-24 10:09:00 -07001479 if (check_filter(elp, FLOG, dir, 1) < 0)
Wayne Davisonf0fa8c62006-11-19 04:39:35 +00001480 goto options_rejected;
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001481 }
1482 }
Wayne Davison7be73df2004-03-27 09:46:42 +00001483
Wayne Davisond175d7e2003-08-01 07:58:44 +00001484 if (!backup_suffix)
Wayne Davisone0391f82004-02-11 04:30:41 +00001485 backup_suffix = backup_dir ? "" : BACKUP_SUFFIX;
Wayne Davisond175d7e2003-08-01 07:58:44 +00001486 backup_suffix_len = strlen(backup_suffix);
Wayne Davison80ddadb2003-08-01 19:40:31 +00001487 if (strchr(backup_suffix, '/') != NULL) {
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001488 snprintf(err_buf, sizeof err_buf,
1489 "--suffix cannot contain slashes: %s\n",
Wayne Davison80ddadb2003-08-01 19:40:31 +00001490 backup_suffix);
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001491 return 0;
Wayne Davison80ddadb2003-08-01 19:40:31 +00001492 }
Wayne Davisone0391f82004-02-11 04:30:41 +00001493 if (backup_dir) {
Wayne Davisonefad2e82010-12-16 22:15:04 -08001494 size_t len = strlcpy(backup_dir_buf, backup_dir, sizeof backup_dir_buf);
1495 if (len > sizeof backup_dir_buf - 128) {
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001496 snprintf(err_buf, sizeof err_buf,
1497 "the --backup-dir path is WAY too long.\n");
1498 return 0;
Wayne Davisone0391f82004-02-11 04:30:41 +00001499 }
Wayne Davisonefad2e82010-12-16 22:15:04 -08001500 backup_dir_len = (int)len;
Wayne Davisone0391f82004-02-11 04:30:41 +00001501 if (backup_dir_buf[backup_dir_len - 1] != '/') {
1502 backup_dir_buf[backup_dir_len++] = '/';
1503 backup_dir_buf[backup_dir_len] = '\0';
1504 }
Wayne Davisonefad2e82010-12-16 22:15:04 -08001505 backup_dir_remainder = sizeof backup_dir_buf - backup_dir_len;
Wayne Davison0ee6ca92006-01-13 22:06:31 +00001506 if (verbose > 1 && !am_sender)
1507 rprintf(FINFO, "backup_dir is %s\n", backup_dir_buf);
Wayne Davison8dcf9332004-03-31 17:02:22 +00001508 } else if (!backup_suffix_len && (!am_server || !am_sender)) {
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001509 snprintf(err_buf, sizeof err_buf,
Wayne Davisond175d7e2003-08-01 07:58:44 +00001510 "--suffix cannot be a null string without --backup-dir\n");
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001511 return 0;
Wayne Davisoneb8f5c72007-09-30 07:30:48 +00001512 } else if (make_backups && delete_mode && !delete_excluded && !am_server) {
1513 snprintf(backup_dir_buf, sizeof backup_dir_buf,
Wayne Davisonf41152d2007-03-05 17:08:00 +00001514 "P *%s", backup_suffix);
Wayne Davisoneb8f5c72007-09-30 07:30:48 +00001515 parse_rule(&filter_list, backup_dir_buf, 0, 0);
Wayne Davisond175d7e2003-08-01 07:58:44 +00001516 }
Wayne Davisonfbd91ca2007-09-02 06:25:26 +00001517
Wayne Davison8f48ba02011-02-21 09:48:37 -08001518 if (preserve_times) {
1519 preserve_times = PRESERVE_FILE_TIMES;
1520 if (!omit_dir_times)
1521 preserve_times |= PRESERVE_DIR_TIMES;
1522#ifdef CAN_SET_SYMLINK_TIMES
1523 preserve_times |= PRESERVE_LINK_TIMES;
1524#endif
1525 }
1526
Wayne Davisonfbd91ca2007-09-02 06:25:26 +00001527 if (make_backups && !backup_dir) {
1528 omit_dir_times = 0; /* Implied, so avoid -O to sender. */
Wayne Davison8f48ba02011-02-21 09:48:37 -08001529 preserve_times &= ~PRESERVE_DIR_TIMES;
Wayne Davisonfbd91ca2007-09-02 06:25:26 +00001530 }
Wayne Davisond175d7e2003-08-01 07:58:44 +00001531
Wayne Davisonb3e4e7e2006-05-29 22:56:45 +00001532 if (stdout_format) {
1533 if (am_server && log_format_has(stdout_format, 'I'))
1534 stdout_format_has_i = 2;
1535 else if (log_format_has(stdout_format, 'i'))
1536 stdout_format_has_i = itemize_changes | 1;
1537 if (!log_format_has(stdout_format, 'b')
1538 && !log_format_has(stdout_format, 'c'))
Wayne Davisone7651882005-02-16 08:10:31 +00001539 log_before_transfer = !am_server;
1540 } else if (itemize_changes) {
Wayne Davisonb3e4e7e2006-05-29 22:56:45 +00001541 stdout_format = "%i %n%L";
1542 stdout_format_has_i = itemize_changes;
Wayne Davisone7651882005-02-16 08:10:31 +00001543 log_before_transfer = !am_server;
1544 }
Wayne Davison87383692005-02-16 17:02:08 +00001545
Wayne Davisona892d902006-02-07 20:06:43 +00001546 if (do_progress && !verbose && !log_before_transfer && !am_server)
J.W. Schultze2559db2003-08-06 06:45:14 +00001547 verbose = 1;
Wayne Davison87383692005-02-16 17:02:08 +00001548
Wayne Davison11e758a2005-04-09 18:59:47 +00001549 if (dry_run)
1550 do_xfers = 0;
1551
Wayne Davison9ac756c2005-05-19 08:52:17 +00001552 set_io_timeout(io_timeout);
1553
Wayne Davisonb3e4e7e2006-05-29 22:56:45 +00001554 if (verbose && !stdout_format) {
1555 stdout_format = "%n%L";
Wayne Davison87383692005-02-16 17:02:08 +00001556 log_before_transfer = !am_server;
Wayne Davison36719872005-02-11 10:42:55 +00001557 }
Wayne Davisonb3e4e7e2006-05-29 22:56:45 +00001558 if (stdout_format_has_i || log_format_has(stdout_format, 'o'))
1559 stdout_format_has_o_or_i = 1;
J.W. Schultze2559db2003-08-06 06:45:14 +00001560
Wayne Davison232658d2006-05-30 17:14:17 +00001561 if (logfile_name && !am_daemon) {
Wayne Davisonb3e4e7e2006-05-29 22:56:45 +00001562 if (!logfile_format) {
Wayne Davison232658d2006-05-30 17:14:17 +00001563 logfile_format = "%i %n%L";
Wayne Davison87c0f9d2006-05-09 18:31:03 +00001564 logfile_format_has_i = logfile_format_has_o_or_i = 1;
Wayne Davisonb3e4e7e2006-05-29 22:56:45 +00001565 } else {
1566 if (log_format_has(logfile_format, 'i'))
Wayne Davison19b85872006-06-01 06:49:15 +00001567 logfile_format_has_i = 1;
Wayne Davisonb3e4e7e2006-05-29 22:56:45 +00001568 if (logfile_format_has_i || log_format_has(logfile_format, 'o'))
1569 logfile_format_has_o_or_i = 1;
Wayne Davison87c0f9d2006-05-09 18:31:03 +00001570 }
Wayne Davison6dc9b742006-06-07 23:05:24 +00001571 log_init(0);
Wayne Davison28736032006-05-30 17:41:54 +00001572 } else if (!am_daemon)
1573 logfile_format = NULL;
Wayne Davison87c0f9d2006-05-09 18:31:03 +00001574
Wayne Davison9fb08442004-11-17 19:29:20 +00001575 if (daemon_bwlimit && (!bwlimit || bwlimit > daemon_bwlimit))
1576 bwlimit = daemon_bwlimit;
Wayne Davison3c74c3a2004-05-27 21:51:53 +00001577 if (bwlimit) {
1578 bwlimit_writemax = (size_t)bwlimit * 128;
1579 if (bwlimit_writemax < 512)
1580 bwlimit_writemax = 512;
1581 }
1582
Wayne Davisoncfce9f62005-08-30 02:57:19 +00001583 if (sparse_files && inplace) {
Wayne Davisonc3851182005-08-30 02:59:30 +00001584 /* Note: we don't check for this below, because --append is
Wayne Davisoncfce9f62005-08-30 02:57:19 +00001585 * OK with --sparse (as long as redos are handled right). */
1586 snprintf(err_buf, sizeof err_buf,
1587 "--sparse cannot be used with --inplace\n");
1588 return 0;
1589 }
1590
Wayne Davisona0157882005-07-28 01:46:09 +00001591 if (append_mode) {
1592 if (whole_file > 0) {
1593 snprintf(err_buf, sizeof err_buf,
1594 "--append cannot be used with --whole-file\n");
1595 return 0;
1596 }
1597 if (refused_inplace) {
1598 create_refuse_error(refused_inplace);
1599 return 0;
1600 }
1601 inplace = 1;
1602 }
1603
Wayne Davisonf06e7082005-01-27 22:46:14 +00001604 if (delay_updates && !partial_dir)
Wayne Davison77860ba2006-01-29 19:17:13 +00001605 partial_dir = tmp_partialdir;
Wayne Davisonf06e7082005-01-27 22:46:14 +00001606
Wayne Davisona3221d22004-07-16 20:06:24 +00001607 if (inplace) {
Wayne Davison4f5b0752005-02-14 00:53:43 +00001608#ifdef HAVE_FTRUNCATE
Wayne Davisona7260c42004-07-29 16:06:38 +00001609 if (partial_dir) {
1610 snprintf(err_buf, sizeof err_buf,
Wayne Davisona0157882005-07-28 01:46:09 +00001611 "--%s cannot be used with --%s\n",
1612 append_mode ? "append" : "inplace",
Wayne Davisonf06e7082005-01-27 22:46:14 +00001613 delay_updates ? "delay-updates" : "partial-dir");
Wayne Davisona7260c42004-07-29 16:06:38 +00001614 return 0;
1615 }
Wayne Davison36719872005-02-11 10:42:55 +00001616 /* --inplace implies --partial for refusal purposes, but we
1617 * clear the keep_partial flag for internal logic purposes. */
1618 if (refused_partial) {
1619 create_refuse_error(refused_partial);
1620 return 0;
1621 }
Wayne Davisona3221d22004-07-16 20:06:24 +00001622 keep_partial = 0;
Wayne Davisonded4daf2005-01-15 20:22:54 +00001623#else
1624 snprintf(err_buf, sizeof err_buf,
Wayne Davisona0157882005-07-28 01:46:09 +00001625 "--%s is not supported on this %s\n",
1626 append_mode ? "append" : "inplace",
Wayne Davisonded4daf2005-01-15 20:22:54 +00001627 am_server ? "server" : "client");
1628 return 0;
1629#endif
Wayne Davison075aa182004-09-18 17:34:56 +00001630 } else {
Wayne Davisonbc880cb2006-02-07 19:12:37 +00001631 if (keep_partial && !partial_dir && !am_server) {
Wayne Davison36719872005-02-11 10:42:55 +00001632 if ((arg = getenv("RSYNC_PARTIAL_DIR")) != NULL && *arg)
1633 partial_dir = strdup(arg);
1634 }
Wayne Davison075aa182004-09-18 17:34:56 +00001635 if (partial_dir) {
Wayne Davison36719872005-02-11 10:42:55 +00001636 if (*partial_dir)
Wayne Davisonb58bfb22007-10-31 04:43:29 +00001637 clean_fname(partial_dir, CFN_COLLAPSE_DOT_DOT_DIRS);
Wayne Davison075aa182004-09-18 17:34:56 +00001638 if (!*partial_dir || strcmp(partial_dir, ".") == 0)
1639 partial_dir = NULL;
Wayne Davison36719872005-02-11 10:42:55 +00001640 if (!partial_dir && refused_partial) {
1641 create_refuse_error(refused_partial);
1642 return 0;
1643 }
Wayne Davison075aa182004-09-18 17:34:56 +00001644 keep_partial = 1;
1645 }
Wayne Davisona3221d22004-07-16 20:06:24 +00001646 }
1647
Wayne Davisonea5164d2003-03-30 23:00:42 +00001648 if (files_from) {
Wayne Davison305666b2005-03-01 01:15:57 +00001649 char *h, *p;
1650 int q;
Wayne Davisonffbffc62007-09-08 19:42:27 +00001651 if (argc > 2 || (!am_daemon && argc == 1)) {
Wayne Davisonea5164d2003-03-30 23:00:42 +00001652 usage(FERROR);
1653 exit_cleanup(RERR_SYNTAX);
1654 }
Wayne Davison63596e12003-12-15 00:53:07 +00001655 if (strcmp(files_from, "-") == 0) {
Wayne Davisonea5164d2003-03-30 23:00:42 +00001656 filesfrom_fd = 0;
Wayne Davison63596e12003-12-15 00:53:07 +00001657 if (am_server)
Wayne Davison305666b2005-03-01 01:15:57 +00001658 filesfrom_host = ""; /* reading from socket */
1659 } else if ((p = check_for_hostspec(files_from, &h, &q)) != 0) {
Wayne Davisonea5164d2003-03-30 23:00:42 +00001660 if (am_server) {
Wayne Davison305666b2005-03-01 01:15:57 +00001661 snprintf(err_buf, sizeof err_buf,
1662 "The --files-from sent to the server cannot specify a host.\n");
1663 return 0;
Wayne Davisonea5164d2003-03-30 23:00:42 +00001664 }
Wayne Davison305666b2005-03-01 01:15:57 +00001665 files_from = p;
1666 filesfrom_host = h;
1667 if (strcmp(files_from, "-") == 0) {
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001668 snprintf(err_buf, sizeof err_buf,
1669 "Invalid --files-from remote filename\n");
1670 return 0;
Wayne Davisonea5164d2003-03-30 23:00:42 +00001671 }
1672 } else {
Wayne Davison305666b2005-03-01 01:15:57 +00001673 if (sanitize_paths)
Wayne Davisond48810b2008-03-20 11:59:54 -07001674 files_from = sanitize_path(NULL, files_from, NULL, 0, SP_DEFAULT);
Wayne Davison819bfe42008-03-20 10:42:43 -07001675 if (daemon_filter_list.head) {
Wayne Davisona1018692007-12-16 14:16:37 -08001676 char *dir;
Wayne Davison305666b2005-03-01 01:15:57 +00001677 if (!*files_from)
1678 goto options_rejected;
Wayne Davisona1018692007-12-16 14:16:37 -08001679 dir = files_from + (*files_from == '/' ? module_dirlen : 0);
1680 clean_fname(dir, CFN_COLLAPSE_DOT_DOT_DIRS);
Wayne Davison1df02d12008-03-24 10:09:00 -07001681 if (check_filter(&daemon_filter_list, FLOG, dir, 0) < 0)
Wayne Davison305666b2005-03-01 01:15:57 +00001682 goto options_rejected;
1683 }
Wayne Davisonea5164d2003-03-30 23:00:42 +00001684 filesfrom_fd = open(files_from, O_RDONLY|O_BINARY);
1685 if (filesfrom_fd < 0) {
Wayne Davisonc3ea0992004-07-31 20:09:54 +00001686 snprintf(err_buf, sizeof err_buf,
1687 "failed to open files-from file %s: %s\n",
1688 files_from, strerror(errno));
1689 return 0;
Wayne Davisonea5164d2003-03-30 23:00:42 +00001690 }
1691 }
1692 }
1693
Wayne Davison7f2a1f62005-02-25 17:08:31 +00001694 am_starting_up = 0;
1695
Andrew Tridgellb11ed3b1998-07-19 04:50:48 +00001696 return 1;
Wayne Davisonf0fa8c62006-11-19 04:39:35 +00001697
1698 options_rejected:
1699 snprintf(err_buf, sizeof err_buf,
1700 "Your options have been rejected by the server.\n");
1701 return 0;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +00001702}
1703
1704
Martin Pooldafe63c2002-04-16 01:38:21 +00001705/**
1706 * Construct a filtered list of options to pass through from the
1707 * client to the server.
1708 *
1709 * This involves setting options that will tell the server how to
1710 * behave, and also filtering out options that are processed only
1711 * locally.
1712 **/
Wayne Davisonffbffc62007-09-08 19:42:27 +00001713void server_options(char **args, int *argc_p)
Andrew Tridgell7a6421f1998-05-10 07:25:40 +00001714{
Wayne Davison74ba98a2005-05-03 17:01:59 +00001715 static char argstr[64];
Wayne Davisonffbffc62007-09-08 19:42:27 +00001716 int ac = *argc_p;
Wayne Davisonf98c60b2004-02-09 18:10:57 +00001717 char *arg;
Andrew Tridgelld8537831998-07-17 10:00:43 +00001718 int i, x;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +00001719
Wayne Davisondef97ff2006-01-26 11:10:32 +00001720 /* This should always remain first on the server's command-line. */
Andrew Tridgelld8537831998-07-17 10:00:43 +00001721 args[ac++] = "--server";
Andrew Tridgell7a6421f1998-05-10 07:25:40 +00001722
Wayne Davisone2086312007-08-11 16:53:31 +00001723 if (daemon_over_rsh > 0) {
Wayne Davison1312d9f2002-08-01 00:37:01 +00001724 args[ac++] = "--daemon";
Wayne Davisonffbffc62007-09-08 19:42:27 +00001725 *argc_p = ac;
Wayne Davison1312d9f2002-08-01 00:37:01 +00001726 /* if we're passing --daemon, we're done */
1727 return;
1728 }
1729
Andrew Tridgelld8537831998-07-17 10:00:43 +00001730 if (!am_sender)
1731 args[ac++] = "--sender";
Andrew Tridgell7a6421f1998-05-10 07:25:40 +00001732
Andrew Tridgelld8537831998-07-17 10:00:43 +00001733 x = 1;
1734 argstr[0] = '-';
Wayne Davisona4453602007-09-18 01:11:54 +00001735
1736 if (protect_args)
1737 argstr[x++] = 's';
1738
Wayne Davisonf98c60b2004-02-09 18:10:57 +00001739 for (i = 0; i < verbose; i++)
Andrew Tridgelld8537831998-07-17 10:00:43 +00001740 argstr[x++] = 'v';
Andrew Tridgellf0b36a42000-08-29 04:46:27 +00001741
David Dykstrab86f0ce1999-02-09 17:25:35 +00001742 /* the -q option is intentionally left out */
Andrew Tridgelld8537831998-07-17 10:00:43 +00001743 if (make_backups)
1744 argstr[x++] = 'b';
1745 if (update_only)
1746 argstr[x++] = 'u';
Wayne Davison2dbf36e2006-02-24 17:54:30 +00001747 if (!do_xfers) /* Note: NOT "dry_run"! */
Andrew Tridgelld8537831998-07-17 10:00:43 +00001748 argstr[x++] = 'n';
1749 if (preserve_links)
1750 argstr[x++] = 'l';
Wayne Davison73cb6732008-03-24 09:33:07 -07001751 if ((xfer_dirs >= 2 && xfer_dirs < 4)
1752 || (xfer_dirs && !recurse && (list_only || (delete_mode && am_sender))))
Wayne Davison5454d222005-01-29 21:25:44 +00001753 argstr[x++] = 'd';
Wayne Davison35bf8fa2006-01-26 22:28:08 +00001754 if (am_sender) {
1755 if (keep_dirlinks)
1756 argstr[x++] = 'K';
Wayne Davison876c9932006-01-28 00:13:55 +00001757 if (prune_empty_dirs)
1758 argstr[x++] = 'm';
Wayne Davisonf9998042007-09-01 16:57:01 +00001759 if (omit_dir_times)
Wayne Davison35bf8fa2006-01-26 22:28:08 +00001760 argstr[x++] = 'O';
Wayne Davison2dbf36e2006-02-24 17:54:30 +00001761 } else {
1762 if (copy_links)
1763 argstr[x++] = 'L';
1764 if (copy_dirlinks)
1765 argstr[x++] = 'k';
Wayne Davison35bf8fa2006-01-26 22:28:08 +00001766 }
Martin Pool1bfbf402002-03-19 03:21:53 +00001767
Wayne Davisondfa32482003-03-21 18:58:50 +00001768 if (whole_file > 0)
Andrew Tridgelld8537831998-07-17 10:00:43 +00001769 argstr[x++] = 'W';
Martin Poolbceec822002-03-19 03:39:42 +00001770 /* We don't need to send --no-whole-file, because it's the
1771 * default for remote transfers, and in any case old versions
1772 * of rsync will not understand it. */
Wayne Davisondfa32482003-03-21 18:58:50 +00001773
Wayne Davisone0e32032006-12-28 07:54:10 +00001774 if (preserve_hard_links) {
Andrew Tridgelld8537831998-07-17 10:00:43 +00001775 argstr[x++] = 'H';
Wayne Davisone0e32032006-12-28 07:54:10 +00001776 if (preserve_hard_links > 1)
1777 argstr[x++] = 'H';
1778 }
Andrew Tridgelld8537831998-07-17 10:00:43 +00001779 if (preserve_uid)
1780 argstr[x++] = 'o';
1781 if (preserve_gid)
1782 argstr[x++] = 'g';
Wayne Davisonb5c6a6a2006-01-26 10:38:58 +00001783 if (preserve_devices) /* ignore preserve_specials here */
Andrew Tridgelld8537831998-07-17 10:00:43 +00001784 argstr[x++] = 'D';
1785 if (preserve_times)
1786 argstr[x++] = 't';
1787 if (preserve_perms)
1788 argstr[x++] = 'p';
Wayne Davison344f9ba2006-01-31 02:29:58 +00001789 else if (preserve_executability && am_sender)
1790 argstr[x++] = 'E';
Wayne Davison1c3344a2007-03-11 00:13:34 +00001791#ifdef SUPPORT_ACLS
1792 if (preserve_acls)
1793 argstr[x++] = 'A';
1794#endif
Wayne Davison16edf862007-04-07 17:22:25 +00001795#ifdef SUPPORT_XATTRS
Wayne Davison524eaa82007-07-02 21:35:14 +00001796 if (preserve_xattrs) {
Wayne Davison16edf862007-04-07 17:22:25 +00001797 argstr[x++] = 'X';
Wayne Davison524eaa82007-07-02 21:35:14 +00001798 if (preserve_xattrs > 1)
1799 argstr[x++] = 'X';
1800 }
Wayne Davison16edf862007-04-07 17:22:25 +00001801#endif
Wayne Davisonaa7a6e82005-03-14 17:30:13 +00001802 if (recurse)
Andrew Tridgelld8537831998-07-17 10:00:43 +00001803 argstr[x++] = 'r';
1804 if (always_checksum)
1805 argstr[x++] = 'c';
1806 if (cvs_exclude)
1807 argstr[x++] = 'C';
1808 if (ignore_times)
1809 argstr[x++] = 'I';
1810 if (relative_paths)
1811 argstr[x++] = 'R';
Wayne Davison243c9952006-01-21 00:36:15 +00001812 if (one_file_system) {
Andrew Tridgelld8537831998-07-17 10:00:43 +00001813 argstr[x++] = 'x';
Wayne Davison243c9952006-01-21 00:36:15 +00001814 if (one_file_system > 1)
1815 argstr[x++] = 'x';
1816 }
Andrew Tridgelld8537831998-07-17 10:00:43 +00001817 if (sparse_files)
1818 argstr[x++] = 'S';
1819 if (do_compression)
1820 argstr[x++] = 'z';
Andrew Tridgellf0b36a42000-08-29 04:46:27 +00001821
Wayne Davison1ed56a02008-02-18 14:10:13 -08001822 set_allow_inc_recurse();
Wayne Davison9e58ef42008-07-23 23:09:15 -07001823
1824 /* Checking the pre-negotiated value allows --protocol=29 override. */
1825 if (protocol_version >= 30) {
1826 /* We make use of the -e option to let the server know about
1827 * any pre-release protocol version && some behavior flags. */
1828 argstr[x++] = 'e';
1829#if SUBPROTOCOL_VERSION != 0
1830 if (protocol_version == PROTOCOL_VERSION) {
1831 x += snprintf(argstr+x, sizeof argstr - x,
1832 "%d.%d",
1833 PROTOCOL_VERSION, SUBPROTOCOL_VERSION);
1834 } else
Wayne Davison1ed56a02008-02-18 14:10:13 -08001835#endif
Wayne Davison9e58ef42008-07-23 23:09:15 -07001836 argstr[x++] = '.';
1837 if (allow_inc_recurse)
1838 argstr[x++] = 'i';
Wayne Davison8f48ba02011-02-21 09:48:37 -08001839#ifdef CAN_SET_SYMLINK_TIMES
Wayne Davison9e58ef42008-07-23 23:09:15 -07001840 argstr[x++] = 'L';
1841#endif
Wayne Davisoned12c8e2008-08-02 07:04:54 -07001842#ifdef ICONV_OPTION
1843 argstr[x++] = 's';
1844#endif
Wayne Davisonc11a7782009-12-21 14:27:55 -08001845 argstr[x++] = 'f';
Wayne Davisoned12c8e2008-08-02 07:04:54 -07001846 }
1847
1848 if (x >= (int)sizeof argstr) { /* Not possible... */
1849 rprintf(FERROR, "argstr overflow in server_options().\n");
1850 exit_cleanup(RERR_MALLOC);
Wayne Davison9e58ef42008-07-23 23:09:15 -07001851 }
1852
Wayne Davison332cf6d2007-04-26 05:53:13 +00001853 argstr[x] = '\0';
1854
Wayne Davisonac683452008-09-26 21:09:41 -07001855 if (x > 1)
1856 args[ac++] = argstr;
Andrew Tridgell7a6421f1998-05-10 07:25:40 +00001857
Wayne Davisona4453602007-09-18 01:11:54 +00001858#ifdef ICONV_OPTION
1859 if (iconv_opt) {
1860 char *set = strchr(iconv_opt, ',');
1861 if (set)
1862 set++;
1863 else
1864 set = iconv_opt;
1865 if (asprintf(&arg, "--iconv=%s", set) < 0)
1866 goto oom;
1867 args[ac++] = arg;
1868 }
1869#endif
1870
Wayne Davison53936ef2008-03-15 11:25:01 -07001871 if (protect_args && !local_server) /* unprotected args stop here */
Wayne Davisona4453602007-09-18 01:11:54 +00001872 args[ac++] = NULL;
1873
Wayne Davison51d48392005-01-22 22:48:34 +00001874 if (list_only > 1)
1875 args[ac++] = "--list-only";
1876
Wayne Davisonf5a910d2006-01-21 19:52:55 +00001877 /* This makes sure that the remote rsync can handle deleting with -d
1878 * sans -r because the --no-r option was added at the same time. */
1879 if (xfer_dirs && !recurse && delete_mode && am_sender)
1880 args[ac++] = "--no-r";
1881
Wayne Davison854a1aa2005-10-26 16:47:15 +00001882 if (do_compression && def_compress_level != Z_DEFAULT_COMPRESSION) {
1883 if (asprintf(&arg, "--compress-level=%d", def_compress_level) < 0)
1884 goto oom;
1885 args[ac++] = arg;
1886 }
1887
Wayne Davisonb5c6a6a2006-01-26 10:38:58 +00001888 if (preserve_devices) {
1889 /* Note: sending "--devices" would not be backward-compatible. */
1890 if (!preserve_specials)
1891 args[ac++] = "--no-specials"; /* -D is already set. */
1892 } else if (preserve_specials)
1893 args[ac++] = "--specials";
1894
Wayne Davison5c5e1592005-02-19 03:54:11 +00001895 /* The server side doesn't use our log-format, but in certain
1896 * circumstances they need to know a little about the option. */
Wayne Davisonb3e4e7e2006-05-29 22:56:45 +00001897 if (stdout_format && am_sender) {
1898 /* Use --log-format, not --out-format, for compatibility. */
1899 if (stdout_format_has_i > 1)
Wayne Davison487094a2006-01-20 18:49:07 +00001900 args[ac++] = "--log-format=%i%I";
Wayne Davisonb3e4e7e2006-05-29 22:56:45 +00001901 else if (stdout_format_has_i)
Wayne Davison684d7582005-02-19 22:16:39 +00001902 args[ac++] = "--log-format=%i";
Wayne Davisonb3e4e7e2006-05-29 22:56:45 +00001903 else if (stdout_format_has_o_or_i)
Wayne Davison5c5e1592005-02-19 03:54:11 +00001904 args[ac++] = "--log-format=%o";
1905 else if (!verbose)
1906 args[ac++] = "--log-format=X";
1907 }
Wayne Davison1f30a672005-02-19 02:39:30 +00001908
J.W. Schultz195bd902003-04-10 02:04:58 +00001909 if (block_size) {
Wayne Davisona06b4192005-01-01 21:08:14 +00001910 if (asprintf(&arg, "-B%lu", block_size) < 0)
Wayne Davisonf98c60b2004-02-09 18:10:57 +00001911 goto oom;
1912 args[ac++] = arg;
Wayne Davisondfa32482003-03-21 18:58:50 +00001913 }
Andrew Tridgell7a6421f1998-05-10 07:25:40 +00001914
Andrew Tridgelld8537831998-07-17 10:00:43 +00001915 if (io_timeout) {
Wayne Davisonf98c60b2004-02-09 18:10:57 +00001916 if (asprintf(&arg, "--timeout=%d", io_timeout) < 0)
1917 goto oom;
1918 args[ac++] = arg;
Wayne Davisondfa32482003-03-21 18:58:50 +00001919 }
Andrew Tridgell7a6421f1998-05-10 07:25:40 +00001920
David Dykstraef5d23e2000-06-06 21:13:05 +00001921 if (bwlimit) {
Wayne Davisonf98c60b2004-02-09 18:10:57 +00001922 if (asprintf(&arg, "--bwlimit=%d", bwlimit) < 0)
1923 goto oom;
1924 args[ac++] = arg;
David Dykstraef5d23e2000-06-06 21:13:05 +00001925 }
1926
Wayne Davisond175d7e2003-08-01 07:58:44 +00001927 if (backup_dir) {
1928 args[ac++] = "--backup-dir";
1929 args[ac++] = backup_dir;
1930 }
1931
1932 /* Only send --suffix if it specifies a non-default value. */
Wayne Davisonf98c60b2004-02-09 18:10:57 +00001933 if (strcmp(backup_suffix, backup_dir ? "" : BACKUP_SUFFIX) != 0) {
Wayne Davison191e40d2003-08-01 20:19:51 +00001934 /* We use the following syntax to avoid weirdness with '~'. */
Wayne Davisonf98c60b2004-02-09 18:10:57 +00001935 if (asprintf(&arg, "--suffix=%s", backup_suffix) < 0)
1936 goto oom;
1937 args[ac++] = arg;
Andrew Tridgelld8537831998-07-17 10:00:43 +00001938 }
Andrew Tridgell7a6421f1998-05-10 07:25:40 +00001939
Wayne Davison06a50542004-08-02 05:00:30 +00001940 if (am_sender) {
Wayne Davison7b9598b2007-07-15 05:42:30 +00001941 if (max_delete > 0) {
1942 if (asprintf(&arg, "--max-delete=%d", max_delete) < 0)
1943 goto oom;
1944 args[ac++] = arg;
1945 } else if (max_delete == 0)
Wayne Davisond6ca2552007-09-15 20:54:31 +00001946 args[ac++] = "--max-delete=-1";
Wayne Davison7b9598b2007-07-15 05:42:30 +00001947 if (min_size) {
1948 args[ac++] = "--min-size";
1949 args[ac++] = min_size_arg;
1950 }
1951 if (max_size) {
1952 args[ac++] = "--max-size";
1953 args[ac++] = max_size_arg;
1954 }
Wayne Davisone0e32032006-12-28 07:54:10 +00001955 if (delete_before)
Wayne Davisonc6eb7fa2005-01-28 07:39:09 +00001956 args[ac++] = "--delete-before";
Wayne Davison0d152432006-12-13 14:52:59 +00001957 else if (delete_during == 2)
1958 args[ac++] = "--delete-delay";
1959 else if (delete_during)
1960 args[ac++] = "--delete-during";
1961 else if (delete_after)
Wayne Davison06a50542004-08-02 05:00:30 +00001962 args[ac++] = "--delete-after";
Wayne Davisone0e32032006-12-28 07:54:10 +00001963 else if (delete_mode && !delete_excluded)
1964 args[ac++] = "--delete";
1965 if (delete_excluded)
1966 args[ac++] = "--delete-excluded";
Wayne Davison06a50542004-08-02 05:00:30 +00001967 if (force_delete)
1968 args[ac++] = "--force";
Wayne Davison11e758a2005-04-09 18:59:47 +00001969 if (write_batch < 0)
1970 args[ac++] = "--only-write-batch=X";
Wayne Davisondef97ff2006-01-26 11:10:32 +00001971 if (am_root > 1)
1972 args[ac++] = "--super";
Wayne Davisonf17e7692006-02-09 01:15:04 +00001973 if (size_only)
1974 args[ac++] = "--size-only";
Wayne Davisonb1e436e2007-07-14 19:24:32 +00001975 } else {
1976 if (skip_compress) {
1977 if (asprintf(&arg, "--skip-compress=%s", skip_compress) < 0)
1978 goto oom;
1979 args[ac++] = arg;
1980 }
Wayne Davison06a50542004-08-02 05:00:30 +00001981 }
David Dykstrab33b7911999-02-22 19:55:57 +00001982
Andrew Tridgell5b56cc12000-09-06 02:12:13 +00001983 if (modify_window_set) {
Wayne Davisonf98c60b2004-02-09 18:10:57 +00001984 if (asprintf(&arg, "--modify-window=%d", modify_window) < 0)
1985 goto oom;
1986 args[ac++] = arg;
Andrew Tridgell5b56cc12000-09-06 02:12:13 +00001987 }
1988
Wayne Davisonc8d895d2004-05-21 09:44:32 +00001989 if (checksum_seed) {
Wayne Davison221ddb92004-05-22 06:09:22 +00001990 if (asprintf(&arg, "--checksum-seed=%d", checksum_seed) < 0)
Wayne Davisonc8d895d2004-05-21 09:44:32 +00001991 goto oom;
1992 args[ac++] = arg;
1993 }
1994
Wayne Davisona7260c42004-07-29 16:06:38 +00001995 if (partial_dir && am_sender) {
Wayne Davison77860ba2006-01-29 19:17:13 +00001996 if (partial_dir != tmp_partialdir) {
Wayne Davison36719872005-02-11 10:42:55 +00001997 args[ac++] = "--partial-dir";
1998 args[ac++] = partial_dir;
1999 }
Wayne Davisonf06e7082005-01-27 22:46:14 +00002000 if (delay_updates)
2001 args[ac++] = "--delay-updates";
Wayne Davison77860ba2006-01-29 19:17:13 +00002002 } else if (keep_partial && am_sender)
Andrew Tridgelld8537831998-07-17 10:00:43 +00002003 args[ac++] = "--partial";
Andrew Tridgellc95da961998-07-01 03:36:03 +00002004
Andrew Tridgellef55c682000-03-21 04:06:04 +00002005 if (ignore_errors)
2006 args[ac++] = "--ignore-errors";
2007
David Dykstrab5313601999-02-17 19:34:40 +00002008 if (copy_unsafe_links)
2009 args[ac++] = "--copy-unsafe-links";
2010
Andrew Tridgelld8537831998-07-17 10:00:43 +00002011 if (safe_symlinks)
2012 args[ac++] = "--safe-links";
Andrew Tridgell7a6421f1998-05-10 07:25:40 +00002013
Andrew Tridgelld8537831998-07-17 10:00:43 +00002014 if (numeric_ids)
2015 args[ac++] = "--numeric-ids";
Andrew Tridgell7a6421f1998-05-10 07:25:40 +00002016
Wayne Davison95def6d2007-10-16 15:10:12 +00002017 if (use_qsort)
2018 args[ac++] = "--use-qsort";
2019
Wayne Davison4f3797c2007-05-05 18:34:37 +00002020 if (am_sender) {
2021 if (ignore_existing)
2022 args[ac++] = "--ignore-existing";
Martin Pool3d6fead2002-01-25 10:42:23 +00002023
Wayne Davison4f3797c2007-05-05 18:34:37 +00002024 /* Backward compatibility: send --existing, not --ignore-non-existing. */
2025 if (ignore_non_existing)
2026 args[ac++] = "--existing";
2027
2028 if (tmpdir) {
2029 args[ac++] = "--temp-dir";
2030 args[ac++] = tmpdir;
2031 }
2032
2033 if (basis_dir[0]) {
2034 /* the server only needs this option if it is not the sender,
2035 * and it may be an older version that doesn't know this
2036 * option, so don't send it if client is the sender.
2037 */
Wayne Davison4f3797c2007-05-05 18:34:37 +00002038 for (i = 0; i < basis_dir_cnt; i++) {
2039 args[ac++] = dest_option;
2040 args[ac++] = basis_dir[i];
2041 }
2042 }
2043 }
Wayne Davisone90aab42005-09-29 18:07:55 +00002044
Wayne Davison936fa862007-09-01 16:38:00 +00002045 if (append_mode) {
2046 if (append_mode > 1)
2047 args[ac++] = "--append";
Wayne Davisona0157882005-07-28 01:46:09 +00002048 args[ac++] = "--append";
Wayne Davison936fa862007-09-01 16:38:00 +00002049 } else if (inplace)
Wayne Davisona3221d22004-07-16 20:06:24 +00002050 args[ac++] = "--inplace";
2051
Wayne Davison305666b2005-03-01 01:15:57 +00002052 if (files_from && (!am_sender || filesfrom_host)) {
2053 if (filesfrom_host) {
Wayne Davisonea5164d2003-03-30 23:00:42 +00002054 args[ac++] = "--files-from";
Wayne Davison305666b2005-03-01 01:15:57 +00002055 args[ac++] = files_from;
Wayne Davisonea5164d2003-03-30 23:00:42 +00002056 if (eol_nulls)
2057 args[ac++] = "--from0";
2058 } else {
2059 args[ac++] = "--files-from=-";
2060 args[ac++] = "--from0";
2061 }
Wayne Davisonc0ab28d2004-12-22 09:10:08 +00002062 if (!relative_paths)
2063 args[ac++] = "--no-relative";
Wayne Davisonea5164d2003-03-30 23:00:42 +00002064 }
Wayne Davison33a04592007-09-22 21:43:19 +00002065 /* It's OK that this checks the upper-bound of the protocol_version. */
2066 if (relative_paths && !implied_dirs && (!am_sender || protocol_version >= 30))
Wayne Davison3a90ea02005-01-19 00:23:32 +00002067 args[ac++] = "--no-implied-dirs";
Wayne Davisonea5164d2003-03-30 23:00:42 +00002068
Wayne Davisonc4ed1482005-02-14 02:41:15 +00002069 if (fuzzy_basis && am_sender)
2070 args[ac++] = "--fuzzy";
2071
Wayne Davison47c11972006-06-30 15:52:52 +00002072 if (remove_source_files == 1)
2073 args[ac++] = "--remove-source-files";
2074 else if (remove_source_files)
Wayne Davison07c6ae72005-02-20 01:04:40 +00002075 args[ac++] = "--remove-sent-files";
2076
Wayne Davisoned12c8e2008-08-02 07:04:54 -07002077 if (ac > MAX_SERVER_ARGS) { /* Not possible... */
2078 rprintf(FERROR, "argc overflow in server_options().\n");
2079 exit_cleanup(RERR_MALLOC);
2080 }
2081
Wayne Davisonffbffc62007-09-08 19:42:27 +00002082 *argc_p = ac;
Wayne Davisonf98c60b2004-02-09 18:10:57 +00002083 return;
2084
2085 oom:
2086 out_of_memory("server_options");
Andrew Tridgell7a6421f1998-05-10 07:25:40 +00002087}
2088
Wayne Davison794f3802009-01-28 15:55:41 -08002089/* If str points to a valid hostspec, return allocated memory containing the
2090 * [USER@]HOST part of the string, and set the path_start_ptr to the part of
2091 * the string after the host part. Otherwise, return NULL. If port_ptr is
2092 * non-NULL, we must be parsing an rsync:// URL hostname, and we will set
2093 * *port_ptr if a port number is found. Note that IPv6 IPs will have their
2094 * (required for parsing) [ and ] chars elided from the returned string. */
2095static char *parse_hostspec(char *str, char **path_start_ptr, int *port_ptr)
2096{
Wayne Davison650bca32009-01-28 23:17:46 -08002097 char *s, *host_start = str;
Wayne Davison794f3802009-01-28 15:55:41 -08002098 int hostlen = 0, userlen = 0;
2099 char *ret;
2100
Wayne Davison650bca32009-01-28 23:17:46 -08002101 for (s = str; ; s++) {
Wayne Davison794f3802009-01-28 15:55:41 -08002102 if (!*s) {
2103 /* It is only OK if we run out of string with rsync:// */
Wayne Davison650bca32009-01-28 23:17:46 -08002104 if (!port_ptr)
2105 return NULL;
2106 if (!hostlen)
2107 hostlen = s - host_start;
2108 break;
Wayne Davison794f3802009-01-28 15:55:41 -08002109 }
2110 if (*s == ':' || *s == '/') {
2111 if (!hostlen)
2112 hostlen = s - host_start;
2113 if (*s++ == '/') {
2114 if (!port_ptr)
2115 return NULL;
2116 } else if (port_ptr) {
2117 *port_ptr = atoi(s);
2118 while (isDigit(s)) s++;
Wayne Davison650bca32009-01-28 23:17:46 -08002119 if (*s && *s++ != '/')
Wayne Davison794f3802009-01-28 15:55:41 -08002120 return NULL;
2121 }
2122 break;
2123 }
2124 if (*s == '@') {
2125 userlen = s - str + 1;
2126 host_start = s + 1;
2127 } else if (*s == '[') {
2128 if (s != host_start++)
2129 return NULL;
2130 while (*s && *s != ']' && *s != '/') s++; /*SHARED ITERATOR*/
2131 hostlen = s - host_start;
2132 if (*s != ']' || (s[1] && s[1] != '/' && s[1] != ':') || !hostlen)
2133 return NULL;
2134 }
2135 }
2136
2137 *path_start_ptr = s;
2138 ret = new_array(char, userlen + hostlen + 1);
2139 if (userlen)
2140 strlcpy(ret, str, userlen + 1);
2141 strlcpy(ret + userlen, host_start, hostlen + 1);
2142 return ret;
2143}
2144
Wayne Davison305666b2005-03-01 01:15:57 +00002145/* Look for a HOST specfication of the form "HOST:PATH", "HOST::PATH", or
2146 * "rsync://HOST:PORT/PATH". If found, *host_ptr will be set to some allocated
2147 * memory with the HOST. If a daemon-accessing spec was specified, the value
2148 * of *port_ptr will contain a non-0 port number, otherwise it will be set to
2149 * 0. The return value is a pointer to the PATH. Note that the HOST spec can
2150 * be an IPv6 literal address enclosed in '[' and ']' (such as "[::1]" or
2151 * "[::ffff:127.0.0.1]") which is returned without the '[' and ']'. */
2152char *check_for_hostspec(char *s, char **host_ptr, int *port_ptr)
Wayne Davisonea5164d2003-03-30 23:00:42 +00002153{
Wayne Davison794f3802009-01-28 15:55:41 -08002154 char *path;
Wayne Davisonea5164d2003-03-30 23:00:42 +00002155
Wayne Davison305666b2005-03-01 01:15:57 +00002156 if (port_ptr && strncasecmp(URL_PREFIX, s, strlen(URL_PREFIX)) == 0) {
Wayne Davison794f3802009-01-28 15:55:41 -08002157 *host_ptr = parse_hostspec(s + strlen(URL_PREFIX), &path, port_ptr);
2158 if (*host_ptr) {
2159 if (!*port_ptr)
2160 *port_ptr = RSYNC_PORT;
2161 return path;
Wayne Davison305666b2005-03-01 01:15:57 +00002162 }
Wayne Davison305666b2005-03-01 01:15:57 +00002163 }
Wayne Davisonea5164d2003-03-30 23:00:42 +00002164
Wayne Davison794f3802009-01-28 15:55:41 -08002165 *host_ptr = parse_hostspec(s, &path, NULL);
2166 if (!*host_ptr)
2167 return NULL;
Wayne Davisonea5164d2003-03-30 23:00:42 +00002168
Wayne Davison794f3802009-01-28 15:55:41 -08002169 if (*path == ':') {
Wayne Davison305666b2005-03-01 01:15:57 +00002170 if (port_ptr && !*port_ptr)
2171 *port_ptr = RSYNC_PORT;
Wayne Davison794f3802009-01-28 15:55:41 -08002172 return path + 1;
Wayne Davison305666b2005-03-01 01:15:57 +00002173 }
2174 if (port_ptr)
2175 *port_ptr = 0;
2176
Wayne Davison794f3802009-01-28 15:55:41 -08002177 return path;
Wayne Davisonea5164d2003-03-30 23:00:42 +00002178}