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