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