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