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