]>
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 |
ba2133d6 WD |
9 | * it under the terms of the GNU General Public License version 2 as |
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 WD |
17 | * You should have received a copy of the GNU General Public License along |
18 | * with this program; if not, write to the Free Software Foundation, Inc., | |
19 | * 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. | |
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; |
7842418b WD |
28 | extern struct filter_list_struct filter_list; |
29 | extern struct filter_list_struct server_filter_list; | |
8645af1d | 30 | |
7a6421fa | 31 | int make_backups = 0; |
1bfbf40b MP |
32 | |
33 | /** | |
dfa32483 | 34 | * If 1, send the whole file as literal data rather than trying to |
dafe63ca | 35 | * create an incremental diff. |
1bfbf40b | 36 | * |
dfa32483 | 37 | * If -1, then look at whether we're local or remote and go by that. |
dafe63ca MP |
38 | * |
39 | * @sa disable_deltas_p() | |
1bfbf40b | 40 | **/ |
dfa32483 | 41 | int whole_file = -1; |
1bfbf40b | 42 | |
a015788d | 43 | int append_mode = 0; |
716e73d4 | 44 | int keep_dirlinks = 0; |
2dbf36ef | 45 | int copy_dirlinks = 0; |
7a6421fa AT |
46 | int copy_links = 0; |
47 | int preserve_links = 0; | |
48 | int preserve_hard_links = 0; | |
1c3344a1 | 49 | int preserve_acls = 0; |
16edf865 | 50 | int preserve_xattrs = 0; |
7a6421fa | 51 | int preserve_perms = 0; |
344f9ba7 | 52 | int preserve_executability = 0; |
7a6421fa | 53 | int preserve_devices = 0; |
b5c6a6ae | 54 | int preserve_specials = 0; |
7a6421fa AT |
55 | int preserve_uid = 0; |
56 | int preserve_gid = 0; | |
57 | int preserve_times = 0; | |
20fb7b91 | 58 | int omit_dir_times = 0; |
7a6421fa AT |
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; |
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}, |
e86e2fa1 | 446 | {"dry-run", 'n', POPT_ARG_NONE, &dry_run, 0, 0, 0 }, |
b6164938 WD |
447 | {"archive", 'a', POPT_ARG_NONE, 0, 'a', 0, 0 }, |
448 | {"recursive", 'r', POPT_ARG_VAL, &recurse, 2, 0, 0 }, | |
449 | {"no-recursive", 0, POPT_ARG_VAL, &recurse, 0, 0, 0 }, | |
5275029d WD |
450 | {"ir", 0, POPT_ARG_VAL, &allow_inc_recurse, 1, 0, 0 }, |
451 | {"inc-recursive", 0, POPT_ARG_VAL, &allow_inc_recurse, 1, 0, 0 }, | |
452 | {"no-ir", 0, POPT_ARG_VAL, &allow_inc_recurse, 0, 0, 0 }, | |
453 | {"no-inc-recursive", 0, POPT_ARG_VAL, &allow_inc_recurse, 0, 0, 0 }, | |
b6164938 | 454 | {"no-r", 0, POPT_ARG_VAL, &recurse, 0, 0, 0 }, |
e86e2fa1 | 455 | {"dirs", 'd', POPT_ARG_VAL, &xfer_dirs, 2, 0, 0 }, |
b6164938 WD |
456 | {"no-dirs", 0, POPT_ARG_VAL, &xfer_dirs, 0, 0, 0 }, |
457 | {"no-d", 0, POPT_ARG_VAL, &xfer_dirs, 0, 0, 0 }, | |
458 | {"perms", 'p', POPT_ARG_VAL, &preserve_perms, 1, 0, 0 }, | |
459 | {"no-perms", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 }, | |
460 | {"no-p", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 }, | |
344f9ba7 | 461 | {"executability", 'E', POPT_ARG_NONE, &preserve_executability, 0, 0, 0 }, |
1c3344a1 WD |
462 | {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 }, |
463 | {"no-acls", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 }, | |
464 | {"no-A", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 }, | |
16edf865 WD |
465 | {"xattrs", 'X', POPT_ARG_NONE, 0, 'X', 0, 0 }, |
466 | {"no-xattrs", 0, POPT_ARG_VAL, &preserve_xattrs, 0, 0, 0 }, | |
467 | {"no-X", 0, POPT_ARG_VAL, &preserve_xattrs, 0, 0, 0 }, | |
b6164938 | 468 | {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 }, |
b6164938 WD |
469 | {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 }, |
470 | {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 }, | |
38b9170c WD |
471 | {"omit-dir-times", 'O', POPT_ARG_VAL, &omit_dir_times, 2, 0, 0 }, |
472 | {"modify-window", 0, POPT_ARG_INT, &modify_window, OPT_MODIFY_WINDOW, 0, 0 }, | |
def97ff9 WD |
473 | {"super", 0, POPT_ARG_VAL, &am_root, 2, 0, 0 }, |
474 | {"no-super", 0, POPT_ARG_VAL, &am_root, 0, 0, 0 }, | |
9439c0cb | 475 | {"fake-super", 0, POPT_ARG_VAL, &am_root, -1, 0, 0 }, |
b6164938 WD |
476 | {"owner", 'o', POPT_ARG_VAL, &preserve_uid, 1, 0, 0 }, |
477 | {"no-owner", 0, POPT_ARG_VAL, &preserve_uid, 0, 0, 0 }, | |
478 | {"no-o", 0, POPT_ARG_VAL, &preserve_uid, 0, 0, 0 }, | |
479 | {"group", 'g', POPT_ARG_VAL, &preserve_gid, 1, 0, 0 }, | |
480 | {"no-group", 0, POPT_ARG_VAL, &preserve_gid, 0, 0, 0 }, | |
481 | {"no-g", 0, POPT_ARG_VAL, &preserve_gid, 0, 0, 0 }, | |
b5c6a6ae WD |
482 | {0, 'D', POPT_ARG_NONE, 0, 'D', 0, 0 }, |
483 | {"no-D", 0, POPT_ARG_NONE, 0, OPT_NO_D, 0, 0 }, | |
484 | {"devices", 0, POPT_ARG_VAL, &preserve_devices, 1, 0, 0 }, | |
b6164938 | 485 | {"no-devices", 0, POPT_ARG_VAL, &preserve_devices, 0, 0, 0 }, |
b5c6a6ae WD |
486 | {"specials", 0, POPT_ARG_VAL, &preserve_specials, 1, 0, 0 }, |
487 | {"no-specials", 0, POPT_ARG_VAL, &preserve_specials, 0, 0, 0 }, | |
e86e2fa1 | 488 | {"links", 'l', POPT_ARG_VAL, &preserve_links, 1, 0, 0 }, |
b6164938 WD |
489 | {"no-links", 0, POPT_ARG_VAL, &preserve_links, 0, 0, 0 }, |
490 | {"no-l", 0, POPT_ARG_VAL, &preserve_links, 0, 0, 0 }, | |
e86e2fa1 WD |
491 | {"copy-links", 'L', POPT_ARG_NONE, ©_links, 0, 0, 0 }, |
492 | {"copy-unsafe-links",0, POPT_ARG_NONE, ©_unsafe_links, 0, 0, 0 }, | |
493 | {"safe-links", 0, POPT_ARG_NONE, &safe_symlinks, 0, 0, 0 }, | |
2dbf36ef | 494 | {"copy-dirlinks", 'k', POPT_ARG_NONE, ©_dirlinks, 0, 0, 0 }, |
e86e2fa1 | 495 | {"keep-dirlinks", 'K', POPT_ARG_NONE, &keep_dirlinks, 0, 0, 0 }, |
e0e32031 | 496 | {"hard-links", 'H', POPT_ARG_NONE, 0, 'H', 0, 0 }, |
beab3078 WD |
497 | {"no-hard-links", 0, POPT_ARG_VAL, &preserve_hard_links, 0, 0, 0 }, |
498 | {"no-H", 0, POPT_ARG_VAL, &preserve_hard_links, 0, 0, 0 }, | |
e86e2fa1 WD |
499 | {"relative", 'R', POPT_ARG_VAL, &relative_paths, 1, 0, 0 }, |
500 | {"no-relative", 0, POPT_ARG_VAL, &relative_paths, 0, 0, 0 }, | |
b6164938 | 501 | {"no-R", 0, POPT_ARG_VAL, &relative_paths, 0, 0, 0 }, |
2dbf36ef | 502 | {"implied-dirs", 0, POPT_ARG_VAL, &implied_dirs, 1, 0, 0 }, |
e86e2fa1 | 503 | {"no-implied-dirs", 0, POPT_ARG_VAL, &implied_dirs, 0, 0, 0 }, |
e16adcdf | 504 | {"chmod", 0, POPT_ARG_STRING, 0, OPT_CHMOD, 0, 0 }, |
afb6e945 WD |
505 | {"ignore-times", 'I', POPT_ARG_NONE, &ignore_times, 0, 0, 0 }, |
506 | {"size-only", 0, POPT_ARG_NONE, &size_only, 0, 0, 0 }, | |
243c995f | 507 | {"one-file-system", 'x', POPT_ARG_NONE, 0, 'x', 0, 0 }, |
e86e2fa1 | 508 | {"update", 'u', POPT_ARG_NONE, &update_only, 0, 0, 0 }, |
e90aab49 | 509 | {"existing", 0, POPT_ARG_NONE, &ignore_non_existing, 0, 0, 0 }, |
e90aab49 | 510 | {"ignore-non-existing",0,POPT_ARG_NONE, &ignore_non_existing, 0, 0, 0 }, |
d2da915c | 511 | {"ignore-existing", 0, POPT_ARG_NONE, &ignore_existing, 0, 0, 0 }, |
aeb213ea | 512 | {"max-size", 0, POPT_ARG_STRING, &max_size_arg, OPT_MAX_SIZE, 0, 0 }, |
74de13d1 | 513 | {"min-size", 0, POPT_ARG_STRING, &min_size_arg, OPT_MIN_SIZE, 0, 0 }, |
e86e2fa1 WD |
514 | {"sparse", 'S', POPT_ARG_NONE, &sparse_files, 0, 0, 0 }, |
515 | {"inplace", 0, POPT_ARG_NONE, &inplace, 0, 0, 0 }, | |
516 | {"append", 0, POPT_ARG_VAL, &append_mode, 1, 0, 0 }, | |
3671987f | 517 | {"del", 0, POPT_ARG_NONE, &delete_during, 0, 0, 0 }, |
3359acb8 | 518 | {"delete", 0, POPT_ARG_NONE, &delete_mode, 0, 0, 0 }, |
e0e32031 | 519 | {"delete-before", 0, POPT_ARG_NONE, &delete_before, 0, 0, 0 }, |
b0cacef1 WD |
520 | {"delete-during", 0, POPT_ARG_VAL, &delete_during, 1, 0, 0 }, |
521 | {"delete-delay", 0, POPT_ARG_VAL, &delete_during, 2, 0, 0 }, | |
51d48398 WD |
522 | {"delete-after", 0, POPT_ARG_NONE, &delete_after, 0, 0, 0 }, |
523 | {"delete-excluded", 0, POPT_ARG_NONE, &delete_excluded, 0, 0, 0 }, | |
47c11975 WD |
524 | {"remove-sent-files",0, POPT_ARG_VAL, &remove_source_files, 2, 0, 0 }, /* deprecated */ |
525 | {"remove-source-files",0,POPT_ARG_VAL, &remove_source_files, 1, 0, 0 }, | |
afb6e945 | 526 | {"force", 0, POPT_ARG_NONE, &force_delete, 0, 0, 0 }, |
e86e2fa1 WD |
527 | {"ignore-errors", 0, POPT_ARG_NONE, &ignore_errors, 0, 0, 0 }, |
528 | {"max-delete", 0, POPT_ARG_INT, &max_delete, 0, 0, 0 }, | |
529 | {0, 'F', POPT_ARG_NONE, 0, 'F', 0, 0 }, | |
aa4d3b4c | 530 | {"filter", 'f', POPT_ARG_STRING, 0, OPT_FILTER, 0, 0 }, |
8db7cc2c WD |
531 | {"exclude", 0, POPT_ARG_STRING, 0, OPT_EXCLUDE, 0, 0 }, |
532 | {"include", 0, POPT_ARG_STRING, 0, OPT_INCLUDE, 0, 0 }, | |
533 | {"exclude-from", 0, POPT_ARG_STRING, 0, OPT_EXCLUDE_FROM, 0, 0 }, | |
534 | {"include-from", 0, POPT_ARG_STRING, 0, OPT_INCLUDE_FROM, 0, 0 }, | |
afb6e945 | 535 | {"cvs-exclude", 'C', POPT_ARG_NONE, &cvs_exclude, 0, 0, 0 }, |
afb6e945 WD |
536 | {"whole-file", 'W', POPT_ARG_VAL, &whole_file, 1, 0, 0 }, |
537 | {"no-whole-file", 0, POPT_ARG_VAL, &whole_file, 0, 0, 0 }, | |
b6164938 | 538 | {"no-W", 0, POPT_ARG_VAL, &whole_file, 0, 0, 0 }, |
afb6e945 | 539 | {"checksum", 'c', POPT_ARG_NONE, &always_checksum, 0, 0, 0 }, |
a06b419d | 540 | {"block-size", 'B', POPT_ARG_LONG, &block_size, 0, 0, 0 }, |
e012f858 | 541 | {"compare-dest", 0, POPT_ARG_STRING, 0, OPT_COMPARE_DEST, 0, 0 }, |
1de3e99b | 542 | {"copy-dest", 0, POPT_ARG_STRING, 0, OPT_COPY_DEST, 0, 0 }, |
e012f858 | 543 | {"link-dest", 0, POPT_ARG_STRING, 0, OPT_LINK_DEST, 0, 0 }, |
c4ed1487 | 544 | {"fuzzy", 'y', POPT_ARG_NONE, &fuzzy_basis, 0, 0, 0 }, |
854a1aad WD |
545 | {"compress", 'z', POPT_ARG_NONE, 0, 'z', 0, 0 }, |
546 | {"compress-level", 0, POPT_ARG_INT, &def_compress_level, 'z', 0, 0 }, | |
11bfaf63 | 547 | {0, 'P', POPT_ARG_NONE, 0, 'P', 0, 0 }, |
b6164938 WD |
548 | {"progress", 0, POPT_ARG_VAL, &do_progress, 1, 0, 0 }, |
549 | {"no-progress", 0, POPT_ARG_VAL, &do_progress, 0, 0, 0 }, | |
550 | {"partial", 0, POPT_ARG_VAL, &keep_partial, 1, 0, 0 }, | |
551 | {"no-partial", 0, POPT_ARG_VAL, &keep_partial, 0, 0, 0 }, | |
a7260c40 | 552 | {"partial-dir", 0, POPT_ARG_STRING, &partial_dir, 0, 0, 0 }, |
f06e7082 | 553 | {"delay-updates", 0, POPT_ARG_NONE, &delay_updates, 0, 0, 0 }, |
876c9936 | 554 | {"prune-empty-dirs",'m', POPT_ARG_NONE, &prune_empty_dirs, 0, 0, 0 }, |
87c0f9d6 | 555 | {"log-file", 0, POPT_ARG_STRING, &logfile_name, 0, 0, 0 }, |
b3e4e7ef WD |
556 | {"log-file-format", 0, POPT_ARG_STRING, &logfile_format, 0, 0, 0 }, |
557 | {"out-format", 0, POPT_ARG_STRING, &stdout_format, 0, 0, 0 }, | |
558 | {"log-format", 0, POPT_ARG_STRING, &stdout_format, 0, 0, 0 }, /* DEPRECATED */ | |
487094a0 | 559 | {"itemize-changes", 'i', POPT_ARG_NONE, 0, 'i', 0, 0 }, |
afb6e945 | 560 | {"bwlimit", 0, POPT_ARG_INT, &bwlimit, 0, 0, 0 }, |
11bfaf63 | 561 | {"backup", 'b', POPT_ARG_NONE, &make_backups, 0, 0, 0 }, |
afb6e945 | 562 | {"backup-dir", 0, POPT_ARG_STRING, &backup_dir, 0, 0, 0 }, |
e86e2fa1 WD |
563 | {"suffix", 0, POPT_ARG_STRING, &backup_suffix, 0, 0, 0 }, |
564 | {"list-only", 0, POPT_ARG_VAL, &list_only, 2, 0, 0 }, | |
8db7cc2c WD |
565 | {"read-batch", 0, POPT_ARG_STRING, &batch_name, OPT_READ_BATCH, 0, 0 }, |
566 | {"write-batch", 0, POPT_ARG_STRING, &batch_name, OPT_WRITE_BATCH, 0, 0 }, | |
11e758a4 | 567 | {"only-write-batch", 0, POPT_ARG_STRING, &batch_name, OPT_ONLY_WRITE_BATCH, 0, 0 }, |
ea5164d1 WD |
568 | {"files-from", 0, POPT_ARG_STRING, &files_from, 0, 0, 0 }, |
569 | {"from0", '0', POPT_ARG_NONE, &eol_nulls, 0, 0, 0}, | |
e86e2fa1 WD |
570 | {"numeric-ids", 0, POPT_ARG_NONE, &numeric_ids, 0, 0, 0 }, |
571 | {"timeout", 0, POPT_ARG_INT, &io_timeout, 0, 0, 0 }, | |
572 | {"rsh", 'e', POPT_ARG_STRING, &shell_cmd, 0, 0, 0 }, | |
573 | {"rsync-path", 0, POPT_ARG_STRING, &rsync_path, 0, 0, 0 }, | |
574 | {"temp-dir", 'T', POPT_ARG_STRING, &tmpdir, 0, 0, 0 }, | |
332cf6df WD |
575 | #ifdef ICONV_OPTION |
576 | {"iconv", 0, POPT_ARG_STRING, &iconv_opt, 0, 0, 0 }, | |
577 | #endif | |
4f5b0756 | 578 | #ifdef INET6 |
3dd22903 WD |
579 | {"ipv4", '4', POPT_ARG_VAL, &default_af_hint, AF_INET, 0, 0 }, |
580 | {"ipv6", '6', POPT_ARG_VAL, &default_af_hint, AF_INET6, 0, 0 }, | |
06963d0f | 581 | #endif |
a6a27602 | 582 | {"8-bit-output", '8', POPT_ARG_NONE, &allow_8bit_chars, 0, 0, 0 }, |
e86e2fa1 WD |
583 | {"address", 0, POPT_ARG_STRING, &bind_address, 0, 0, 0 }, |
584 | {"port", 0, POPT_ARG_INT, &rsync_port, 0, 0, 0 }, | |
831f06a5 | 585 | {"sockopts", 0, POPT_ARG_STRING, &sockopts, 0, 0, 0 }, |
e86e2fa1 WD |
586 | {"password-file", 0, POPT_ARG_STRING, &password_file, 0, 0, 0 }, |
587 | {"blocking-io", 0, POPT_ARG_VAL, &blocking_io, 1, 0, 0 }, | |
588 | {"no-blocking-io", 0, POPT_ARG_VAL, &blocking_io, 0, 0, 0 }, | |
589 | {"protocol", 0, POPT_ARG_INT, &protocol_version, 0, 0, 0 }, | |
590 | {"checksum-seed", 0, POPT_ARG_INT, &checksum_seed, 0, 0, 0 }, | |
0ccffd7c | 591 | {"server", 0, POPT_ARG_NONE, 0, OPT_SERVER, 0, 0 }, |
e86e2fa1 WD |
592 | {"sender", 0, POPT_ARG_NONE, 0, OPT_SENDER, 0, 0 }, |
593 | /* All the following options switch us into daemon-mode option-parsing. */ | |
3ac7f5d4 WD |
594 | {"config", 0, POPT_ARG_STRING, 0, OPT_DAEMON, 0, 0 }, |
595 | {"daemon", 0, POPT_ARG_NONE, 0, OPT_DAEMON, 0, 0 }, | |
1f35babc | 596 | {"detach", 0, POPT_ARG_NONE, 0, OPT_DAEMON, 0, 0 }, |
3ac7f5d4 | 597 | {"no-detach", 0, POPT_ARG_NONE, 0, OPT_DAEMON, 0, 0 }, |
3ac7f5d4 WD |
598 | {0,0,0,0, 0, 0, 0} |
599 | }; | |
600 | ||
601 | static void daemon_usage(enum logcode F) | |
602 | { | |
603 | print_rsync_version(F); | |
604 | ||
b64ee91a WD |
605 | rprintf(F,"\n"); |
606 | rprintf(F,"Usage: rsync --daemon [OPTION]...\n"); | |
3ac7f5d4 | 607 | rprintf(F," --address=ADDRESS bind to the specified address\n"); |
b3708acf | 608 | rprintf(F," --bwlimit=KBPS limit I/O bandwidth; KBytes per second\n"); |
3ac7f5d4 WD |
609 | rprintf(F," --config=FILE specify alternate rsyncd.conf file\n"); |
610 | rprintf(F," --no-detach do not detach from the parent\n"); | |
b3708acf | 611 | rprintf(F," --port=PORT listen on alternate port number\n"); |
87c0f9d6 | 612 | rprintf(F," --log-file=FILE override the \"log file\" setting\n"); |
232658d9 | 613 | rprintf(F," --log-file-format=FMT override the \"log format\" setting\n"); |
831f06a5 | 614 | rprintf(F," --sockopts=OPTIONS specify custom TCP options\n"); |
1bd9db74 | 615 | rprintf(F," -v, --verbose increase verbosity\n"); |
4f5b0756 | 616 | #ifdef INET6 |
3ac7f5d4 WD |
617 | rprintf(F," -4, --ipv4 prefer IPv4\n"); |
618 | rprintf(F," -6, --ipv6 prefer IPv6\n"); | |
619 | #endif | |
05724c07 | 620 | rprintf(F," --help show this help screen\n"); |
3ac7f5d4 | 621 | |
b64ee91a WD |
622 | rprintf(F,"\n"); |
623 | rprintf(F,"If you were not trying to invoke rsync as a daemon, avoid using any of the\n"); | |
3ac7f5d4 WD |
624 | rprintf(F,"daemon-specific rsync options. See also the rsyncd.conf(5) man page.\n"); |
625 | } | |
626 | ||
627 | static struct poptOption long_daemon_options[] = { | |
628 | /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */ | |
629 | {"address", 0, POPT_ARG_STRING, &bind_address, 0, 0, 0 }, | |
9fb08441 | 630 | {"bwlimit", 0, POPT_ARG_INT, &daemon_bwlimit, 0, 0, 0 }, |
3ac7f5d4 WD |
631 | {"config", 0, POPT_ARG_STRING, &config_file, 0, 0, 0 }, |
632 | {"daemon", 0, POPT_ARG_NONE, &daemon_opt, 0, 0, 0 }, | |
4f5b0756 | 633 | #ifdef INET6 |
3ac7f5d4 WD |
634 | {"ipv4", '4', POPT_ARG_VAL, &default_af_hint, AF_INET, 0, 0 }, |
635 | {"ipv6", '6', POPT_ARG_VAL, &default_af_hint, AF_INET6, 0, 0 }, | |
636 | #endif | |
1f35babc | 637 | {"detach", 0, POPT_ARG_VAL, &no_detach, 0, 0, 0 }, |
87c0f9d6 | 638 | {"log-file", 0, POPT_ARG_STRING, &logfile_name, 0, 0, 0 }, |
232658d9 | 639 | {"log-file-format", 0, POPT_ARG_STRING, &logfile_format, 0, 0, 0 }, |
1f35babc | 640 | {"no-detach", 0, POPT_ARG_VAL, &no_detach, 1, 0, 0 }, |
3ac7f5d4 | 641 | {"port", 0, POPT_ARG_INT, &rsync_port, 0, 0, 0 }, |
831f06a5 | 642 | {"sockopts", 0, POPT_ARG_STRING, &sockopts, 0, 0, 0 }, |
3ac7f5d4 WD |
643 | {"protocol", 0, POPT_ARG_INT, &protocol_version, 0, 0, 0 }, |
644 | {"server", 0, POPT_ARG_NONE, &am_server, 0, 0, 0 }, | |
b8cc3587 | 645 | {"temp-dir", 'T', POPT_ARG_STRING, &tmpdir, 0, 0, 0 }, |
1bd9db74 | 646 | {"verbose", 'v', POPT_ARG_NONE, 0, 'v', 0, 0 }, |
b6e22a47 WD |
647 | {"no-verbose", 0, POPT_ARG_VAL, &verbose, 0, 0, 0 }, |
648 | {"no-v", 0, POPT_ARG_VAL, &verbose, 0, 0, 0 }, | |
3ac7f5d4 | 649 | {"help", 'h', POPT_ARG_NONE, 0, 'h', 0, 0 }, |
ad715008 | 650 | {0,0,0,0, 0, 0, 0} |
2855f61f | 651 | }; |
7a6421fa | 652 | |
06963d0f | 653 | |
e51094b7 | 654 | static char err_buf[200]; |
cd8185f2 | 655 | |
2855f61f | 656 | |
dafe63ca MP |
657 | /** |
658 | * Store the option error message, if any, so that we can log the | |
659 | * connection attempt (which requires parsing the options), and then | |
660 | * show the error later on. | |
661 | **/ | |
cd8185f2 AT |
662 | void option_error(void) |
663 | { | |
e51094b7 | 664 | if (!err_buf[0]) { |
c9bce0b8 WD |
665 | strlcpy(err_buf, "Error parsing options: option may " |
666 | "be supported on client but not on server?\n", | |
667 | sizeof err_buf); | |
cd8185f2 | 668 | } |
e51094b7 | 669 | |
e51094b7 | 670 | rprintf(FERROR, RSYNC_NAME ": %s", err_buf); |
8f1dc165 | 671 | msleep(20); |
cd8185f2 AT |
672 | } |
673 | ||
dafe63ca MP |
674 | |
675 | /** | |
27ed20f7 WD |
676 | * Tweak the option table to disable all options that the rsyncd.conf |
677 | * file has told us to refuse. | |
dafe63ca | 678 | **/ |
27ed20f7 | 679 | static void set_refuse_options(char *bp) |
cd8185f2 | 680 | { |
27ed20f7 | 681 | struct poptOption *op; |
093e816c | 682 | char *cp, shortname[2]; |
d73e7f6e | 683 | int is_wild, found_match; |
093e816c WD |
684 | |
685 | shortname[1] = '\0'; | |
27ed20f7 WD |
686 | |
687 | while (1) { | |
06a50542 WD |
688 | while (*bp == ' ') bp++; |
689 | if (!*bp) | |
690 | break; | |
27ed20f7 WD |
691 | if ((cp = strchr(bp, ' ')) != NULL) |
692 | *cp= '\0'; | |
093e816c | 693 | is_wild = strpbrk(bp, "*?[") != NULL; |
d73e7f6e | 694 | found_match = 0; |
55afbb52 | 695 | for (op = long_options; ; op++) { |
093e816c | 696 | *shortname = op->shortName; |
d73e7f6e WD |
697 | if (!op->longName && !*shortname) |
698 | break; | |
699 | if ((op->longName && wildmatch(bp, op->longName)) | |
684d7582 | 700 | || (*shortname && wildmatch(bp, shortname))) { |
e57211c5 WD |
701 | if (op->argInfo == POPT_ARG_VAL) |
702 | op->argInfo = POPT_ARG_NONE; | |
06a50542 | 703 | op->val = (op - long_options) + OPT_REFUSED_BASE; |
d73e7f6e | 704 | found_match = 1; |
3671987f WD |
705 | /* These flags are set to let us easily check |
706 | * an implied option later in the code. */ | |
707 | switch (*shortname) { | |
3671987f WD |
708 | case 'r': case 'd': case 'l': case 'p': |
709 | case 't': case 'g': case 'o': case 'D': | |
710 | refused_archive_part = op->val; | |
711 | break; | |
854a1aad WD |
712 | case 'z': |
713 | refused_compress = op->val; | |
714 | break; | |
3671987f WD |
715 | case '\0': |
716 | if (wildmatch("delete", op->longName)) | |
717 | refused_delete = op->val; | |
3296f91b WD |
718 | else if (wildmatch("delete-before", op->longName)) |
719 | refused_delete_before = op->val; | |
e0e32031 WD |
720 | else if (wildmatch("delete-during", op->longName)) |
721 | refused_delete_during = op->val; | |
3671987f WD |
722 | else if (wildmatch("partial", op->longName)) |
723 | refused_partial = op->val; | |
724 | else if (wildmatch("progress", op->longName)) | |
725 | refused_progress = op->val; | |
a015788d WD |
726 | else if (wildmatch("inplace", op->longName)) |
727 | refused_inplace = op->val; | |
3671987f WD |
728 | break; |
729 | } | |
06a50542 WD |
730 | if (!is_wild) |
731 | break; | |
27ed20f7 | 732 | } |
cd8185f2 | 733 | } |
d73e7f6e WD |
734 | if (!found_match) { |
735 | rprintf(FLOG, "No match for refuse-options string \"%s\"\n", | |
736 | bp); | |
737 | } | |
27ed20f7 WD |
738 | if (!cp) |
739 | break; | |
740 | *cp = ' '; | |
741 | bp = cp + 1; | |
cd8185f2 | 742 | } |
cd8185f2 AT |
743 | } |
744 | ||
745 | ||
8db7cc2c | 746 | static int count_args(const char **argv) |
2855f61f | 747 | { |
dfa32483 | 748 | int i = 0; |
2855f61f | 749 | |
8db7cc2c WD |
750 | if (argv) { |
751 | while (argv[i] != NULL) | |
752 | i++; | |
753 | } | |
dfa32483 WD |
754 | |
755 | return i; | |
2855f61f MP |
756 | } |
757 | ||
758 | ||
837d01dd | 759 | static OFF_T parse_size_arg(char **size_arg, char def_suf) |
95e107db | 760 | { |
3c19f72c WD |
761 | int reps, mult, make_compatible = 0; |
762 | const char *arg; | |
763 | OFF_T size = 1; | |
95e107db | 764 | |
2dc7b8bd | 765 | for (arg = *size_arg; isDigit(arg); arg++) {} |
95e107db | 766 | if (*arg == '.') |
2dc7b8bd | 767 | for (arg++; isDigit(arg); arg++) {} |
3c19f72c | 768 | switch (*arg && *arg != '+' && *arg != '-' ? *arg++ : def_suf) { |
837d01dd | 769 | case 'b': case 'B': |
3c19f72c | 770 | reps = 0; |
837d01dd | 771 | break; |
95e107db | 772 | case 'k': case 'K': |
3c19f72c | 773 | reps = 1; |
95e107db WD |
774 | break; |
775 | case 'm': case 'M': | |
3c19f72c | 776 | reps = 2; |
95e107db WD |
777 | break; |
778 | case 'g': case 'G': | |
3c19f72c | 779 | reps = 3; |
95e107db WD |
780 | break; |
781 | default: | |
3c19f72c | 782 | return -1; |
95e107db | 783 | } |
3c19f72c WD |
784 | if (*arg == 'b' || *arg == 'B') |
785 | mult = 1000, make_compatible = 1, arg++; | |
786 | else if (!*arg || *arg == '+' || *arg == '-') | |
787 | mult = 1024; | |
788 | else if (strncasecmp(arg, "ib", 2) == 0) | |
789 | mult = 1024, arg += 2; | |
790 | else | |
791 | return -1; | |
792 | while (reps--) | |
793 | size *= mult; | |
794 | size *= atof(*size_arg); | |
795 | if ((*arg == '+' || *arg == '-') && arg[1] == '1') | |
796 | size += atoi(arg), make_compatible = 1, arg += 2; | |
797 | if (*arg) | |
798 | return -1; | |
aeb213ea | 799 | if (size > 0 && make_compatible) { |
74de13d1 WD |
800 | /* We convert this manually because we may need %lld precision, |
801 | * and that's not a portable sprintf() escape. */ | |
8f14cc49 | 802 | char buf[128], *s = buf + sizeof buf - 1; |
aeb213ea | 803 | OFF_T num = size; |
8f14cc49 | 804 | *s = '\0'; |
aeb213ea | 805 | while (num) { |
26404276 | 806 | *--s = (char)(num % 10) + '0'; |
aeb213ea WD |
807 | num /= 10; |
808 | } | |
809 | if (!(*size_arg = strdup(s))) | |
810 | out_of_memory("parse_size_arg"); | |
811 | } | |
95e107db WD |
812 | return size; |
813 | } | |
814 | ||
815 | ||
3671987f WD |
816 | static void create_refuse_error(int which) |
817 | { | |
818 | /* The "which" value is the index + OPT_REFUSED_BASE. */ | |
819 | struct poptOption *op = &long_options[which - OPT_REFUSED_BASE]; | |
820 | int n = snprintf(err_buf, sizeof err_buf, | |
821 | "The server is configured to refuse --%s\n", | |
822 | op->longName) - 1; | |
823 | if (op->shortName) { | |
824 | snprintf(err_buf + n, sizeof err_buf - n, | |
825 | " (-%c)\n", op->shortName); | |
826 | } | |
827 | } | |
828 | ||
829 | ||
dafe63ca MP |
830 | /** |
831 | * Process command line arguments. Called on both local and remote. | |
832 | * | |
833 | * @retval 1 if all options are OK; with globals set to appropriate | |
834 | * values | |
835 | * | |
836 | * @retval 0 on error, with err_buf containing an explanation | |
837 | **/ | |
2855f61f | 838 | int parse_arguments(int *argc, const char ***argv, int frommain) |
7a6421fa | 839 | { |
d853783f | 840 | int opt; |
cd8185f2 | 841 | char *ref = lp_refuse_options(module_id); |
7be73df4 | 842 | const char *arg; |
dfa32483 | 843 | poptContext pc; |
d853783f | 844 | |
27ed20f7 WD |
845 | if (ref && *ref) |
846 | set_refuse_options(ref); | |
232658d9 WD |
847 | if (am_daemon) |
848 | set_refuse_options("log-file*"); | |
27ed20f7 | 849 | |
332cf6df WD |
850 | #ifdef ICONV_OPTION |
851 | if (!am_daemon && (arg = getenv("RSYNC_ICONV")) != NULL && *arg) | |
852 | iconv_opt = strdup(arg); | |
853 | #endif | |
854 | ||
dfa32483 | 855 | /* TODO: Call poptReadDefaultConfig; handle errors. */ |
cd8185f2 | 856 | |
dfa32483 WD |
857 | /* The context leaks in case of an error, but if there's a |
858 | * problem we always exit anyhow. */ | |
859 | pc = poptGetContext(RSYNC_NAME, *argc, *argv, long_options, 0); | |
9fb08441 | 860 | poptReadDefaultConfig(pc, 0); |
2855f61f MP |
861 | |
862 | while ((opt = poptGetNextOpt(pc)) != -1) { | |
dfa32483 WD |
863 | /* most options are handled automatically by popt; |
864 | * only special cases are returned and listed here. */ | |
2855f61f | 865 | |
d853783f AT |
866 | switch (opt) { |
867 | case OPT_VERSION: | |
dfa32483 | 868 | print_rsync_version(FINFO); |
d853783f | 869 | exit_cleanup(0); |
dfa32483 | 870 | |
0ccffd7c WD |
871 | case OPT_SERVER: |
872 | if (!am_server) { | |
873 | /* Disable popt aliases on the server side and | |
874 | * then start parsing the options again. */ | |
875 | poptFreeContext(pc); | |
876 | pc = poptGetContext(RSYNC_NAME, *argc, *argv, | |
877 | long_options, 0); | |
878 | am_server = 1; | |
879 | } | |
332cf6df WD |
880 | #ifdef ICONV_OPTION |
881 | iconv_opt = NULL; | |
882 | #endif | |
0ccffd7c WD |
883 | break; |
884 | ||
885 | case OPT_SENDER: | |
886 | if (!am_server) { | |
887 | usage(FERROR); | |
888 | exit_cleanup(RERR_SYNTAX); | |
889 | } | |
890 | am_sender = 1; | |
891 | break; | |
892 | ||
3ac7f5d4 WD |
893 | case OPT_DAEMON: |
894 | if (am_daemon) { | |
c9bce0b8 WD |
895 | strlcpy(err_buf, |
896 | "Attempt to hack rsync thwarted!\n", | |
897 | sizeof err_buf); | |
3ac7f5d4 WD |
898 | return 0; |
899 | } | |
332cf6df WD |
900 | #ifdef ICONV_OPTION |
901 | iconv_opt = NULL; | |
902 | #endif | |
3ac7f5d4 WD |
903 | poptFreeContext(pc); |
904 | pc = poptGetContext(RSYNC_NAME, *argc, *argv, | |
905 | long_daemon_options, 0); | |
906 | while ((opt = poptGetNextOpt(pc)) != -1) { | |
907 | switch (opt) { | |
908 | case 'h': | |
909 | daemon_usage(FINFO); | |
910 | exit_cleanup(0); | |
911 | ||
1bd9db74 WD |
912 | case 'v': |
913 | verbose++; | |
914 | break; | |
915 | ||
3ac7f5d4 WD |
916 | default: |
917 | rprintf(FERROR, | |
918 | "rsync: %s: %s (in daemon mode)\n", | |
919 | poptBadOption(pc, POPT_BADOPTION_NOALIAS), | |
920 | poptStrerror(opt)); | |
921 | goto daemon_error; | |
922 | } | |
923 | } | |
b6e22a47 WD |
924 | |
925 | if (tmpdir && strlen(tmpdir) >= MAXPATHLEN - 10) { | |
926 | snprintf(err_buf, sizeof err_buf, | |
927 | "the --temp-dir path is WAY too long.\n"); | |
928 | return 0; | |
929 | } | |
930 | ||
3ac7f5d4 WD |
931 | if (!daemon_opt) { |
932 | rprintf(FERROR, "Daemon option(s) used without --daemon.\n"); | |
933 | daemon_error: | |
934 | rprintf(FERROR, | |
935 | "(Type \"rsync --daemon --help\" for assistance with daemon mode.)\n"); | |
936 | exit_cleanup(RERR_SYNTAX); | |
937 | } | |
b6e22a47 | 938 | |
3ac7f5d4 WD |
939 | *argv = poptGetArgs(pc); |
940 | *argc = count_args(*argv); | |
7f2a1f65 | 941 | am_starting_up = 0; |
3ac7f5d4 WD |
942 | daemon_opt = 0; |
943 | am_daemon = 1; | |
944 | return 1; | |
945 | ||
5b56cc19 | 946 | case OPT_MODIFY_WINDOW: |
dfa32483 WD |
947 | /* The value has already been set by popt, but |
948 | * we need to remember that we're using a | |
949 | * non-default setting. */ | |
5b56cc19 AT |
950 | modify_window_set = 1; |
951 | break; | |
1de50993 | 952 | |
aa4d3b4c | 953 | case OPT_FILTER: |
3a5e9224 | 954 | parse_rule(&filter_list, poptGetOptArg(pc), 0, 0); |
d853783f AT |
955 | break; |
956 | ||
aa4d3b4c | 957 | case OPT_EXCLUDE: |
3a5e9224 | 958 | parse_rule(&filter_list, poptGetOptArg(pc), |
0a68f869 | 959 | 0, XFLG_OLD_PREFIXES); |
aa4d3b4c WD |
960 | break; |
961 | ||
d853783f | 962 | case OPT_INCLUDE: |
3a5e9224 | 963 | parse_rule(&filter_list, poptGetOptArg(pc), |
0a68f869 | 964 | MATCHFLG_INCLUDE, XFLG_OLD_PREFIXES); |
d853783f AT |
965 | break; |
966 | ||
967 | case OPT_EXCLUDE_FROM: | |
93695764 | 968 | case OPT_INCLUDE_FROM: |
7be73df4 | 969 | arg = poptGetOptArg(pc); |
1a7f3d99 | 970 | if (sanitize_paths) |
91f4b31f | 971 | arg = sanitize_path(NULL, arg, NULL, 0, NULL); |
7842418b | 972 | if (server_filter_list.head) { |
d3ef9859 WD |
973 | char *cp = strdup(arg); |
974 | if (!cp) | |
975 | out_of_memory("parse_arguments"); | |
3671987f WD |
976 | if (!*cp) |
977 | goto options_rejected; | |
ba3db479 | 978 | clean_fname(cp, 1); |
7842418b | 979 | if (check_filter(&server_filter_list, cp, 0) < 0) |
ba3db479 | 980 | goto options_rejected; |
d3ef9859 | 981 | free(cp); |
ba3db479 | 982 | } |
3a5e9224 WD |
983 | parse_filter_file(&filter_list, arg, |
984 | opt == OPT_INCLUDE_FROM ? MATCHFLG_INCLUDE : 0, | |
985 | XFLG_FATAL_ERRORS | XFLG_OLD_PREFIXES); | |
93695764 DD |
986 | break; |
987 | ||
b6164938 WD |
988 | case 'a': |
989 | if (refused_archive_part) { | |
990 | create_refuse_error(refused_archive_part); | |
991 | return 0; | |
992 | } | |
993 | if (!recurse) /* preserve recurse == 2 */ | |
994 | recurse = 1; | |
995 | #ifdef SUPPORT_LINKS | |
996 | preserve_links = 1; | |
997 | #endif | |
998 | preserve_perms = 1; | |
999 | preserve_times = 1; | |
1000 | preserve_gid = 1; | |
1001 | preserve_uid = 1; | |
1002 | preserve_devices = 1; | |
b5c6a6ae WD |
1003 | preserve_specials = 1; |
1004 | break; | |
1005 | ||
1006 | case 'D': | |
1007 | preserve_devices = preserve_specials = 1; | |
1008 | break; | |
1009 | ||
1010 | case OPT_NO_D: | |
1011 | preserve_devices = preserve_specials = 0; | |
b6164938 WD |
1012 | break; |
1013 | ||
3ca9e5d8 WD |
1014 | case 'h': |
1015 | human_readable++; | |
1016 | break; | |
1017 | ||
e0e32031 WD |
1018 | case 'H': |
1019 | preserve_hard_links++; | |
1020 | break; | |
1021 | ||
487094a0 WD |
1022 | case 'i': |
1023 | itemize_changes++; | |
1024 | break; | |
1025 | ||
d853783f AT |
1026 | case 'v': |
1027 | verbose++; | |
1028 | break; | |
7a6421fa | 1029 | |
b86f0cef | 1030 | case 'q': |
f98c60bf WD |
1031 | if (frommain) |
1032 | quiet++; | |
b86f0cef DD |
1033 | break; |
1034 | ||
243c995f WD |
1035 | case 'x': |
1036 | one_file_system++; | |
1037 | break; | |
1038 | ||
aa4d3b4c WD |
1039 | case 'F': |
1040 | switch (++F_option_cnt) { | |
1041 | case 1: | |
3a5e9224 | 1042 | parse_rule(&filter_list,": /.rsync-filter",0,0); |
aa4d3b4c WD |
1043 | break; |
1044 | case 2: | |
3a5e9224 | 1045 | parse_rule(&filter_list,"- .rsync-filter",0,0); |
aa4d3b4c WD |
1046 | break; |
1047 | } | |
1048 | break; | |
1049 | ||
d9fcc198 | 1050 | case 'P': |
3671987f WD |
1051 | if (refused_partial || refused_progress) { |
1052 | create_refuse_error(refused_partial | |
1053 | ? refused_partial : refused_progress); | |
1054 | return 0; | |
1055 | } | |
d9fcc198 AT |
1056 | do_progress = 1; |
1057 | keep_partial = 1; | |
1058 | break; | |
1059 | ||
854a1aad WD |
1060 | case 'z': |
1061 | if (def_compress_level < Z_DEFAULT_COMPRESSION | |
1062 | || def_compress_level > Z_BEST_COMPRESSION) { | |
1063 | snprintf(err_buf, sizeof err_buf, | |
1064 | "--compress-level value is invalid: %d\n", | |
1065 | def_compress_level); | |
1066 | return 0; | |
1067 | } | |
1068 | do_compression = def_compress_level != Z_NO_COMPRESSION; | |
1069 | if (do_compression && refused_compress) { | |
1070 | create_refuse_error(refused_compress); | |
1071 | return 0; | |
1072 | } | |
1073 | break; | |
1074 | ||
088aac85 | 1075 | case OPT_WRITE_BATCH: |
9b3318b0 | 1076 | /* batch_name is already set */ |
088aac85 DD |
1077 | write_batch = 1; |
1078 | break; | |
1079 | ||
11e758a4 WD |
1080 | case OPT_ONLY_WRITE_BATCH: |
1081 | /* batch_name is already set */ | |
1082 | write_batch = -1; | |
1083 | break; | |
1084 | ||
76f79ba7 | 1085 | case OPT_READ_BATCH: |
9b3318b0 | 1086 | /* batch_name is already set */ |
6902ed17 MP |
1087 | read_batch = 1; |
1088 | break; | |
ea5164d1 | 1089 | |
7d5acf1d | 1090 | case OPT_MAX_SIZE: |
837d01dd | 1091 | if ((max_size = parse_size_arg(&max_size_arg, 'b')) <= 0) { |
e012f858 | 1092 | snprintf(err_buf, sizeof err_buf, |
7d5acf1d WD |
1093 | "--max-size value is invalid: %s\n", |
1094 | max_size_arg); | |
e012f858 | 1095 | return 0; |
7d5acf1d WD |
1096 | } |
1097 | break; | |
1098 | ||
74de13d1 WD |
1099 | case OPT_MIN_SIZE: |
1100 | if ((min_size = parse_size_arg(&min_size_arg, 'b')) <= 0) { | |
1101 | snprintf(err_buf, sizeof err_buf, | |
1102 | "--min-size value is invalid: %s\n", | |
1103 | min_size_arg); | |
1104 | return 0; | |
1105 | } | |
1106 | break; | |
1107 | ||
59c95e42 | 1108 | case OPT_LINK_DEST: |
fcecb70b | 1109 | #ifdef SUPPORT_HARD_LINKS |
59c95e42 | 1110 | link_dest = 1; |
e012f858 WD |
1111 | dest_option = "--link-dest"; |
1112 | goto set_dest_dir; | |
59c95e42 | 1113 | #else |
d175d7e1 | 1114 | snprintf(err_buf, sizeof err_buf, |
dfa32483 | 1115 | "hard links are not supported on this %s\n", |
59c95e42 | 1116 | am_server ? "server" : "client"); |
59c95e42 DD |
1117 | return 0; |
1118 | #endif | |
1119 | ||
1de3e99b WD |
1120 | case OPT_COPY_DEST: |
1121 | copy_dest = 1; | |
1122 | dest_option = "--copy-dest"; | |
1123 | goto set_dest_dir; | |
1124 | ||
e012f858 WD |
1125 | case OPT_COMPARE_DEST: |
1126 | compare_dest = 1; | |
1127 | dest_option = "--compare-dest"; | |
1128 | set_dest_dir: | |
3b26bba0 | 1129 | if (basis_dir_cnt >= MAX_BASIS_DIRS) { |
e012f858 WD |
1130 | snprintf(err_buf, sizeof err_buf, |
1131 | "ERROR: at most %d %s args may be specified\n", | |
1132 | MAX_BASIS_DIRS, dest_option); | |
1133 | return 0; | |
1134 | } | |
ad77db8b WD |
1135 | /* We defer sanitizing this arg until we know what |
1136 | * our destination directory is going to be. */ | |
1137 | basis_dir[basis_dir_cnt++] = (char *)poptGetOptArg(pc); | |
e012f858 WD |
1138 | break; |
1139 | ||
e16adcdf WD |
1140 | case OPT_CHMOD: |
1141 | arg = poptGetOptArg(pc); | |
bbe42182 | 1142 | if (!parse_chmod(arg, &chmod_modes)) { |
e16adcdf WD |
1143 | snprintf(err_buf, sizeof err_buf, |
1144 | "Invalid argument passed to --chmod (%s)\n", | |
1145 | arg); | |
1146 | return 0; | |
1147 | } | |
1148 | break; | |
1149 | ||
f5a910dd WD |
1150 | case OPT_HELP: |
1151 | usage(FINFO); | |
1152 | exit_cleanup(0); | |
1153 | ||
1c3344a1 WD |
1154 | case 'A': |
1155 | #ifdef SUPPORT_ACLS | |
1156 | preserve_acls = 1; | |
1157 | preserve_perms = 1; | |
1158 | break; | |
1159 | #else | |
1160 | /* FIXME: this should probably be ignored with a | |
1161 | * warning and then countermeasures taken to | |
1162 | * restrict group and other access in the presence | |
1163 | * of any more restrictive ACLs, but this is safe | |
1164 | * for now */ | |
1165 | snprintf(err_buf,sizeof(err_buf), | |
1166 | "ACLs are not supported on this %s\n", | |
1167 | am_server ? "server" : "client"); | |
1168 | return 0; | |
1169 | #endif | |
1170 | ||
16edf865 WD |
1171 | case 'X': |
1172 | #ifdef SUPPORT_XATTRS | |
1173 | preserve_xattrs = 1; | |
1174 | preserve_perms = 1; | |
1175 | break; | |
1176 | #else | |
1177 | snprintf(err_buf,sizeof(err_buf), | |
1178 | "extended attributes are not supported on this %s\n", | |
1179 | am_server ? "server" : "client"); | |
1180 | return 0; | |
1181 | #endif | |
1c3344a1 | 1182 | |
d853783f | 1183 | default: |
55afbb52 | 1184 | /* A large opt value means that set_refuse_options() |
3671987f | 1185 | * turned this option off. */ |
c67d1386 | 1186 | if (opt >= OPT_REFUSED_BASE) { |
3671987f WD |
1187 | create_refuse_error(opt); |
1188 | return 0; | |
27ed20f7 | 1189 | } |
3671987f WD |
1190 | snprintf(err_buf, sizeof err_buf, "%s%s: %s\n", |
1191 | am_server ? "on remote machine: " : "", | |
1192 | poptBadOption(pc, POPT_BADOPTION_NOALIAS), | |
1193 | poptStrerror(opt)); | |
dfa32483 | 1194 | return 0; |
d853783f | 1195 | } |
7a6421fa | 1196 | } |
2855f61f | 1197 | |
05724c07 | 1198 | if (human_readable && *argc == 2) { |
3ca9e5d8 | 1199 | /* Allow the old meaning of 'h' (--help) on its own. */ |
05724c07 WD |
1200 | usage(FINFO); |
1201 | exit_cleanup(0); | |
1202 | } | |
1203 | ||
332cf6df WD |
1204 | #ifdef ICONV_OPTION |
1205 | if (iconv_opt) { | |
1206 | if (!am_server && strcmp(iconv_opt, "-") == 0) | |
1207 | iconv_opt = NULL; | |
1208 | else | |
1209 | need_unsorted_flist = 1; | |
1210 | } | |
1211 | #endif | |
1212 | ||
4f5b0756 | 1213 | #ifndef SUPPORT_LINKS |
54e87b4b | 1214 | if (preserve_links && !am_sender) { |
e1add893 WD |
1215 | snprintf(err_buf, sizeof err_buf, |
1216 | "symlinks are not supported on this %s\n", | |
1217 | am_server ? "server" : "client"); | |
e1add893 WD |
1218 | return 0; |
1219 | } | |
1220 | #endif | |
1221 | ||
4f5b0756 | 1222 | #ifndef SUPPORT_HARD_LINKS |
e1add893 WD |
1223 | if (preserve_hard_links) { |
1224 | snprintf(err_buf, sizeof err_buf, | |
1225 | "hard links are not supported on this %s\n", | |
1226 | am_server ? "server" : "client"); | |
e1add893 WD |
1227 | return 0; |
1228 | } | |
1229 | #endif | |
1230 | ||
9439c0cb WD |
1231 | #ifndef SUPPORT_XATTRS |
1232 | if (am_root < 0) { | |
1233 | snprintf(err_buf, sizeof err_buf, | |
1234 | "--fake-super requires an rsync with extended attributes enabled\n"); | |
1235 | return 0; | |
1236 | } | |
1237 | #endif | |
1238 | ||
088aac85 | 1239 | if (write_batch && read_batch) { |
c3ea0990 | 1240 | snprintf(err_buf, sizeof err_buf, |
36119893 | 1241 | "--write-batch and --read-batch can not be used together\n"); |
c3ea0990 | 1242 | return 0; |
088aac85 | 1243 | } |
11e758a4 | 1244 | if (write_batch > 0 || read_batch) { |
94327ff0 WD |
1245 | if (am_server) { |
1246 | rprintf(FINFO, | |
1247 | "ignoring --%s-batch option sent to server\n", | |
1248 | write_batch ? "write" : "read"); | |
1249 | /* We don't actually exit_cleanup(), so that we can | |
1250 | * still service older version clients that still send | |
1251 | * batch args to server. */ | |
1252 | read_batch = write_batch = 0; | |
1253 | batch_name = NULL; | |
254ee3ba WD |
1254 | } else if (dry_run) |
1255 | write_batch = 0; | |
b9f592fb | 1256 | } |
36119893 | 1257 | if (read_batch && files_from) { |
c3ea0990 | 1258 | snprintf(err_buf, sizeof err_buf, |
36119893 | 1259 | "--read-batch cannot be used with --files-from\n"); |
c3ea0990 | 1260 | return 0; |
36119893 | 1261 | } |
9b3318b0 | 1262 | if (batch_name && strlen(batch_name) > MAX_BATCH_NAME_LEN) { |
c3ea0990 | 1263 | snprintf(err_buf, sizeof err_buf, |
9b3318b0 WD |
1264 | "the batch-file name must be %d characters or less.\n", |
1265 | MAX_BATCH_NAME_LEN); | |
c3ea0990 | 1266 | return 0; |
beb93684 | 1267 | } |
088aac85 | 1268 | |
ce58b1b4 | 1269 | if (tmpdir && strlen(tmpdir) >= MAXPATHLEN - 10) { |
c3ea0990 WD |
1270 | snprintf(err_buf, sizeof err_buf, |
1271 | "the --temp-dir path is WAY too long.\n"); | |
1272 | return 0; | |
ce58b1b4 WD |
1273 | } |
1274 | ||
1de3e99b | 1275 | if (compare_dest + copy_dest + link_dest > 1) { |
e012f858 | 1276 | snprintf(err_buf, sizeof err_buf, |
1de3e99b | 1277 | "You may not mix --compare-dest, --copy-dest, and --link-dest.\n"); |
e012f858 WD |
1278 | return 0; |
1279 | } | |
1280 | ||
b6164938 WD |
1281 | if (files_from) { |
1282 | if (recurse == 1) /* preserve recurse == 2 */ | |
1283 | recurse = 0; | |
550d4e23 | 1284 | if (xfer_dirs < 0) |
b6164938 | 1285 | xfer_dirs = 1; |
dfa32483 | 1286 | } |
51d48398 | 1287 | |
b6164938 WD |
1288 | if (xfer_dirs < 1) |
1289 | xfer_dirs = recurse || list_only; | |
dfa32483 | 1290 | |
ea5164d1 WD |
1291 | if (relative_paths < 0) |
1292 | relative_paths = files_from? 1 : 0; | |
89f2a4c2 WD |
1293 | if (!relative_paths) |
1294 | implied_dirs = 0; | |
ea5164d1 | 1295 | |
e0e32031 | 1296 | if (delete_before + !!delete_during + delete_after > 1) { |
3359acb8 | 1297 | snprintf(err_buf, sizeof err_buf, |
c6eb7fad | 1298 | "You may not combine multiple --delete-WHEN options.\n"); |
3359acb8 WD |
1299 | return 0; |
1300 | } | |
f5a910dd | 1301 | if (delete_before || delete_during || delete_after) |
51d48398 | 1302 | delete_mode = 1; |
3296f91b | 1303 | else if (delete_mode || delete_excluded) { |
e0e32031 | 1304 | /* Only choose now between before & during if one is refused. */ |
3296f91b | 1305 | if (refused_delete_before) { |
e0e32031 WD |
1306 | if (!refused_delete_during) |
1307 | delete_during = 1; | |
1308 | else { | |
1309 | create_refuse_error(refused_delete_before); | |
1310 | return 0; | |
1311 | } | |
1312 | } else if (refused_delete_during) | |
1313 | delete_before = 1; | |
1314 | delete_mode = 1; | |
3296f91b | 1315 | } |
89fb5026 WD |
1316 | if (!xfer_dirs && delete_mode) { |
1317 | snprintf(err_buf, sizeof err_buf, | |
1318 | "--delete does not work without -r or -d.\n"); | |
1319 | return 0; | |
f5a910dd | 1320 | } |
51d48398 | 1321 | |
3671987f WD |
1322 | if (delete_mode && refused_delete) { |
1323 | create_refuse_error(refused_delete); | |
1324 | return 0; | |
1325 | } | |
1326 | ||
47c11975 WD |
1327 | if (remove_source_files) { |
1328 | /* We only want to infer this refusal of --remove-source-files | |
07c6ae7d WD |
1329 | * via the refusal of "delete", not any of the "delete-FOO" |
1330 | * options. */ | |
1331 | if (refused_delete && am_sender) { | |
1332 | create_refuse_error(refused_delete); | |
1333 | return 0; | |
1334 | } | |
1335 | need_messages_from_generator = 1; | |
1336 | } | |
1337 | ||
7be73df4 | 1338 | *argv = poptGetArgs(pc); |
8db7cc2c | 1339 | *argc = count_args(*argv); |
7be73df4 WD |
1340 | |
1341 | if (sanitize_paths) { | |
1342 | int i; | |
1343 | for (i = *argc; i-- > 0; ) | |
91f4b31f | 1344 | (*argv)[i] = sanitize_path(NULL, (*argv)[i], "", 0, NULL); |
1a7f3d99 | 1345 | if (tmpdir) |
91f4b31f | 1346 | tmpdir = sanitize_path(NULL, tmpdir, NULL, 0, NULL); |
1a7f3d99 | 1347 | if (backup_dir) |
91f4b31f | 1348 | backup_dir = sanitize_path(NULL, backup_dir, NULL, 0, NULL); |
7be73df4 | 1349 | } |
7842418b WD |
1350 | if (server_filter_list.head && !am_sender) { |
1351 | struct filter_list_struct *elp = &server_filter_list; | |
c3ea0990 | 1352 | if (tmpdir) { |
3671987f WD |
1353 | if (!*tmpdir) |
1354 | goto options_rejected; | |
58b1999e | 1355 | clean_fname(tmpdir, 1); |
7842418b | 1356 | if (check_filter(elp, tmpdir, 1) < 0) |
c3ea0990 WD |
1357 | goto options_rejected; |
1358 | } | |
c3ea0990 | 1359 | if (backup_dir) { |
3671987f WD |
1360 | if (!*backup_dir) |
1361 | goto options_rejected; | |
58b1999e | 1362 | clean_fname(backup_dir, 1); |
f0fa8c6d WD |
1363 | if (check_filter(elp, backup_dir, 1) < 0) |
1364 | goto options_rejected; | |
c3ea0990 WD |
1365 | } |
1366 | } | |
7be73df4 | 1367 | |
d175d7e1 | 1368 | if (!backup_suffix) |
e0391f81 | 1369 | backup_suffix = backup_dir ? "" : BACKUP_SUFFIX; |
d175d7e1 | 1370 | backup_suffix_len = strlen(backup_suffix); |
80ddadb7 | 1371 | if (strchr(backup_suffix, '/') != NULL) { |
c3ea0990 WD |
1372 | snprintf(err_buf, sizeof err_buf, |
1373 | "--suffix cannot contain slashes: %s\n", | |
80ddadb7 | 1374 | backup_suffix); |
c3ea0990 | 1375 | return 0; |
80ddadb7 | 1376 | } |
e0391f81 WD |
1377 | if (backup_dir) { |
1378 | backup_dir_len = strlcpy(backup_dir_buf, backup_dir, sizeof backup_dir_buf); | |
1379 | backup_dir_remainder = sizeof backup_dir_buf - backup_dir_len; | |
1380 | if (backup_dir_remainder < 32) { | |
c3ea0990 WD |
1381 | snprintf(err_buf, sizeof err_buf, |
1382 | "the --backup-dir path is WAY too long.\n"); | |
1383 | return 0; | |
e0391f81 WD |
1384 | } |
1385 | if (backup_dir_buf[backup_dir_len - 1] != '/') { | |
1386 | backup_dir_buf[backup_dir_len++] = '/'; | |
1387 | backup_dir_buf[backup_dir_len] = '\0'; | |
1388 | } | |
0ee6ca98 WD |
1389 | if (verbose > 1 && !am_sender) |
1390 | rprintf(FINFO, "backup_dir is %s\n", backup_dir_buf); | |
8dcf9335 | 1391 | } else if (!backup_suffix_len && (!am_server || !am_sender)) { |
c3ea0990 | 1392 | snprintf(err_buf, sizeof err_buf, |
d175d7e1 | 1393 | "--suffix cannot be a null string without --backup-dir\n"); |
c3ea0990 | 1394 | return 0; |
f41152d3 WD |
1395 | } else if (make_backups && delete_mode && !delete_excluded && !am_server) { |
1396 | snprintf(backup_dir_buf, sizeof backup_dir_buf, | |
1397 | "P *%s", backup_suffix); | |
1398 | parse_rule(&filter_list, backup_dir_buf, 0, 0); | |
d175d7e1 | 1399 | } |
d4021b6d WD |
1400 | if (make_backups && !backup_dir) |
1401 | omit_dir_times = 1; | |
d175d7e1 | 1402 | |
b3e4e7ef WD |
1403 | if (stdout_format) { |
1404 | if (am_server && log_format_has(stdout_format, 'I')) | |
1405 | stdout_format_has_i = 2; | |
1406 | else if (log_format_has(stdout_format, 'i')) | |
1407 | stdout_format_has_i = itemize_changes | 1; | |
1408 | if (!log_format_has(stdout_format, 'b') | |
1409 | && !log_format_has(stdout_format, 'c')) | |
e7651884 WD |
1410 | log_before_transfer = !am_server; |
1411 | } else if (itemize_changes) { | |
b3e4e7ef WD |
1412 | stdout_format = "%i %n%L"; |
1413 | stdout_format_has_i = itemize_changes; | |
e7651884 WD |
1414 | log_before_transfer = !am_server; |
1415 | } | |
87383697 | 1416 | |
a892d905 | 1417 | if (do_progress && !verbose && !log_before_transfer && !am_server) |
e2559dbe | 1418 | verbose = 1; |
87383697 | 1419 | |
11e758a4 WD |
1420 | if (dry_run) |
1421 | do_xfers = 0; | |
1422 | ||
9ac756c6 WD |
1423 | set_io_timeout(io_timeout); |
1424 | ||
b3e4e7ef WD |
1425 | if (verbose && !stdout_format) { |
1426 | stdout_format = "%n%L"; | |
87383697 | 1427 | log_before_transfer = !am_server; |
3671987f | 1428 | } |
b3e4e7ef WD |
1429 | if (stdout_format_has_i || log_format_has(stdout_format, 'o')) |
1430 | stdout_format_has_o_or_i = 1; | |
e2559dbe | 1431 | |
232658d9 | 1432 | if (logfile_name && !am_daemon) { |
b3e4e7ef | 1433 | if (!logfile_format) { |
232658d9 | 1434 | logfile_format = "%i %n%L"; |
87c0f9d6 | 1435 | logfile_format_has_i = logfile_format_has_o_or_i = 1; |
b3e4e7ef WD |
1436 | } else { |
1437 | if (log_format_has(logfile_format, 'i')) | |
19b85876 | 1438 | logfile_format_has_i = 1; |
b3e4e7ef WD |
1439 | if (logfile_format_has_i || log_format_has(logfile_format, 'o')) |
1440 | logfile_format_has_o_or_i = 1; | |
87c0f9d6 | 1441 | } |
6dc9b74b | 1442 | log_init(0); |
2873603a WD |
1443 | } else if (!am_daemon) |
1444 | logfile_format = NULL; | |
87c0f9d6 | 1445 | |
9fb08441 WD |
1446 | if (daemon_bwlimit && (!bwlimit || bwlimit > daemon_bwlimit)) |
1447 | bwlimit = daemon_bwlimit; | |
3c74c3a3 WD |
1448 | if (bwlimit) { |
1449 | bwlimit_writemax = (size_t)bwlimit * 128; | |
1450 | if (bwlimit_writemax < 512) | |
1451 | bwlimit_writemax = 512; | |
1452 | } | |
1453 | ||
cfce9f6d | 1454 | if (sparse_files && inplace) { |
c3851185 | 1455 | /* Note: we don't check for this below, because --append is |
cfce9f6d WD |
1456 | * OK with --sparse (as long as redos are handled right). */ |
1457 | snprintf(err_buf, sizeof err_buf, | |
1458 | "--sparse cannot be used with --inplace\n"); | |
1459 | return 0; | |
1460 | } | |
1461 | ||
a015788d WD |
1462 | if (append_mode) { |
1463 | if (whole_file > 0) { | |
1464 | snprintf(err_buf, sizeof err_buf, | |
1465 | "--append cannot be used with --whole-file\n"); | |
1466 | return 0; | |
1467 | } | |
1468 | if (refused_inplace) { | |
1469 | create_refuse_error(refused_inplace); | |
1470 | return 0; | |
1471 | } | |
1472 | inplace = 1; | |
1473 | } | |
1474 | ||
f06e7082 | 1475 | if (delay_updates && !partial_dir) |
77860bac | 1476 | partial_dir = tmp_partialdir; |
f06e7082 | 1477 | |
a3221d2a | 1478 | if (inplace) { |
4f5b0756 | 1479 | #ifdef HAVE_FTRUNCATE |
a7260c40 WD |
1480 | if (partial_dir) { |
1481 | snprintf(err_buf, sizeof err_buf, | |
a015788d WD |
1482 | "--%s cannot be used with --%s\n", |
1483 | append_mode ? "append" : "inplace", | |
f06e7082 | 1484 | delay_updates ? "delay-updates" : "partial-dir"); |
a7260c40 WD |
1485 | return 0; |
1486 | } | |
3671987f WD |
1487 | /* --inplace implies --partial for refusal purposes, but we |
1488 | * clear the keep_partial flag for internal logic purposes. */ | |
1489 | if (refused_partial) { | |
1490 | create_refuse_error(refused_partial); | |
1491 | return 0; | |
1492 | } | |
a3221d2a | 1493 | keep_partial = 0; |
ded4daf0 WD |
1494 | #else |
1495 | snprintf(err_buf, sizeof err_buf, | |
a015788d WD |
1496 | "--%s is not supported on this %s\n", |
1497 | append_mode ? "append" : "inplace", | |
ded4daf0 WD |
1498 | am_server ? "server" : "client"); |
1499 | return 0; | |
1500 | #endif | |
075aa18f | 1501 | } else { |
bc880cb8 | 1502 | if (keep_partial && !partial_dir && !am_server) { |
3671987f WD |
1503 | if ((arg = getenv("RSYNC_PARTIAL_DIR")) != NULL && *arg) |
1504 | partial_dir = strdup(arg); | |
1505 | } | |
075aa18f | 1506 | if (partial_dir) { |
3671987f WD |
1507 | if (*partial_dir) |
1508 | clean_fname(partial_dir, 1); | |
075aa18f WD |
1509 | if (!*partial_dir || strcmp(partial_dir, ".") == 0) |
1510 | partial_dir = NULL; | |
3671987f WD |
1511 | if (!partial_dir && refused_partial) { |
1512 | create_refuse_error(refused_partial); | |
1513 | return 0; | |
1514 | } | |
075aa18f WD |
1515 | keep_partial = 1; |
1516 | } | |
a3221d2a WD |
1517 | } |
1518 | ||
ea5164d1 | 1519 | if (files_from) { |
305666bf WD |
1520 | char *h, *p; |
1521 | int q; | |
c3ea0990 | 1522 | if (*argc > 2 || (!am_daemon && *argc == 1)) { |
ea5164d1 WD |
1523 | usage(FERROR); |
1524 | exit_cleanup(RERR_SYNTAX); | |
1525 | } | |
63596e1c | 1526 | if (strcmp(files_from, "-") == 0) { |
ea5164d1 | 1527 | filesfrom_fd = 0; |
63596e1c | 1528 | if (am_server) |
305666bf WD |
1529 | filesfrom_host = ""; /* reading from socket */ |
1530 | } else if ((p = check_for_hostspec(files_from, &h, &q)) != 0) { | |
ea5164d1 | 1531 | if (am_server) { |
305666bf WD |
1532 | snprintf(err_buf, sizeof err_buf, |
1533 | "The --files-from sent to the server cannot specify a host.\n"); | |
1534 | return 0; | |
ea5164d1 | 1535 | } |
305666bf WD |
1536 | files_from = p; |
1537 | filesfrom_host = h; | |
1538 | if (strcmp(files_from, "-") == 0) { | |
c3ea0990 WD |
1539 | snprintf(err_buf, sizeof err_buf, |
1540 | "Invalid --files-from remote filename\n"); | |
1541 | return 0; | |
ea5164d1 WD |
1542 | } |
1543 | } else { | |
305666bf | 1544 | if (sanitize_paths) |
91f4b31f | 1545 | files_from = sanitize_path(NULL, files_from, NULL, 0, NULL); |
305666bf WD |
1546 | if (server_filter_list.head) { |
1547 | if (!*files_from) | |
1548 | goto options_rejected; | |
1549 | clean_fname(files_from, 1); | |
1550 | if (check_filter(&server_filter_list, files_from, 0) < 0) | |
1551 | goto options_rejected; | |
1552 | } | |
ea5164d1 WD |
1553 | filesfrom_fd = open(files_from, O_RDONLY|O_BINARY); |
1554 | if (filesfrom_fd < 0) { | |
c3ea0990 WD |
1555 | snprintf(err_buf, sizeof err_buf, |
1556 | "failed to open files-from file %s: %s\n", | |
1557 | files_from, strerror(errno)); | |
1558 | return 0; | |
ea5164d1 WD |
1559 | } |
1560 | } | |
1561 | } | |
1562 | ||
7f2a1f65 WD |
1563 | am_starting_up = 0; |
1564 | ||
b11ed3b1 | 1565 | return 1; |
f0fa8c6d WD |
1566 | |
1567 | options_rejected: | |
1568 | snprintf(err_buf, sizeof err_buf, | |
1569 | "Your options have been rejected by the server.\n"); | |
1570 | return 0; | |
7a6421fa AT |
1571 | } |
1572 | ||
1573 | ||
dafe63ca MP |
1574 | /** |
1575 | * Construct a filtered list of options to pass through from the | |
1576 | * client to the server. | |
1577 | * | |
1578 | * This involves setting options that will tell the server how to | |
1579 | * behave, and also filtering out options that are processed only | |
1580 | * locally. | |
1581 | **/ | |
7a6421fa AT |
1582 | void server_options(char **args,int *argc) |
1583 | { | |
74ba98a5 | 1584 | static char argstr[64]; |
d853783f | 1585 | int ac = *argc; |
f98c60bf | 1586 | char *arg; |
ef5d23eb | 1587 | |
d853783f AT |
1588 | int i, x; |
1589 | ||
93689aa5 DD |
1590 | if (blocking_io == -1) |
1591 | blocking_io = 0; | |
1592 | ||
def97ff9 | 1593 | /* This should always remain first on the server's command-line. */ |
d853783f AT |
1594 | args[ac++] = "--server"; |
1595 | ||
1312d9fc WD |
1596 | if (daemon_over_rsh) { |
1597 | args[ac++] = "--daemon"; | |
1598 | *argc = ac; | |
1599 | /* if we're passing --daemon, we're done */ | |
1600 | return; | |
1601 | } | |
1602 | ||
d853783f AT |
1603 | if (!am_sender) |
1604 | args[ac++] = "--sender"; | |
1605 | ||
1606 | x = 1; | |
1607 | argstr[0] = '-'; | |
f98c60bf | 1608 | for (i = 0; i < verbose; i++) |
d853783f | 1609 | argstr[x++] = 'v'; |
f0b36a48 | 1610 | |
b86f0cef | 1611 | /* the -q option is intentionally left out */ |
d853783f AT |
1612 | if (make_backups) |
1613 | argstr[x++] = 'b'; | |
1614 | if (update_only) | |
1615 | argstr[x++] = 'u'; | |
2dbf36ef | 1616 | if (!do_xfers) /* Note: NOT "dry_run"! */ |
d853783f AT |
1617 | argstr[x++] = 'n'; |
1618 | if (preserve_links) | |
1619 | argstr[x++] = 'l'; | |
4d51f0db | 1620 | if (xfer_dirs > (recurse || !delete_mode || !am_sender ? 1 : 0)) |
5454d22a | 1621 | argstr[x++] = 'd'; |
35bf8fa0 WD |
1622 | if (am_sender) { |
1623 | if (keep_dirlinks) | |
1624 | argstr[x++] = 'K'; | |
876c9936 WD |
1625 | if (prune_empty_dirs) |
1626 | argstr[x++] = 'm'; | |
35bf8fa0 WD |
1627 | if (omit_dir_times == 2) |
1628 | argstr[x++] = 'O'; | |
2dbf36ef WD |
1629 | } else { |
1630 | if (copy_links) | |
1631 | argstr[x++] = 'L'; | |
1632 | if (copy_dirlinks) | |
1633 | argstr[x++] = 'k'; | |
35bf8fa0 | 1634 | } |
1bfbf40b | 1635 | |
dfa32483 | 1636 | if (whole_file > 0) |
d853783f | 1637 | argstr[x++] = 'W'; |
bceec82f MP |
1638 | /* We don't need to send --no-whole-file, because it's the |
1639 | * default for remote transfers, and in any case old versions | |
1640 | * of rsync will not understand it. */ | |
dfa32483 | 1641 | |
e0e32031 | 1642 | if (preserve_hard_links) { |
d853783f | 1643 | argstr[x++] = 'H'; |
e0e32031 WD |
1644 | if (preserve_hard_links > 1) |
1645 | argstr[x++] = 'H'; | |
1646 | } | |
d853783f AT |
1647 | if (preserve_uid) |
1648 | argstr[x++] = 'o'; | |
1649 | if (preserve_gid) | |
1650 | argstr[x++] = 'g'; | |
b5c6a6ae | 1651 | if (preserve_devices) /* ignore preserve_specials here */ |
d853783f AT |
1652 | argstr[x++] = 'D'; |
1653 | if (preserve_times) | |
1654 | argstr[x++] = 't'; | |
1655 | if (preserve_perms) | |
1656 | argstr[x++] = 'p'; | |
344f9ba7 WD |
1657 | else if (preserve_executability && am_sender) |
1658 | argstr[x++] = 'E'; | |
1c3344a1 WD |
1659 | #ifdef SUPPORT_ACLS |
1660 | if (preserve_acls) | |
1661 | argstr[x++] = 'A'; | |
16edf865 WD |
1662 | #endif |
1663 | #ifdef SUPPORT_XATTRS | |
1664 | if (preserve_xattrs) | |
1665 | argstr[x++] = 'X'; | |
1c3344a1 | 1666 | #endif |
aa7a6e87 | 1667 | if (recurse) |
d853783f AT |
1668 | argstr[x++] = 'r'; |
1669 | if (always_checksum) | |
1670 | argstr[x++] = 'c'; | |
1671 | if (cvs_exclude) | |
1672 | argstr[x++] = 'C'; | |
1673 | if (ignore_times) | |
1674 | argstr[x++] = 'I'; | |
1675 | if (relative_paths) | |
1676 | argstr[x++] = 'R'; | |
243c995f | 1677 | if (one_file_system) { |
d853783f | 1678 | argstr[x++] = 'x'; |
243c995f WD |
1679 | if (one_file_system > 1) |
1680 | argstr[x++] = 'x'; | |
1681 | } | |
d853783f AT |
1682 | if (sparse_files) |
1683 | argstr[x++] = 'S'; | |
1684 | if (do_compression) | |
1685 | argstr[x++] = 'z'; | |
f0b36a48 | 1686 | |
51d48398 WD |
1687 | /* This is a complete hack - blame Rusty. FIXME! |
1688 | * This hack is only needed for older rsync versions that | |
1689 | * don't understand the --list-only option. */ | |
da2a6c1f | 1690 | if (list_only == 1 && !recurse) |
f0b36a48 AT |
1691 | argstr[x++] = 'r'; |
1692 | ||
2ed790f3 | 1693 | #if SUBPROTOCOL_VERSION != 0 |
486f8cd1 WD |
1694 | /* If we're speaking a pre-release version of a protocol, we tell |
1695 | * the server about this by (ab)using the -e option. */ | |
2ed790f3 | 1696 | if (protocol_version == PROTOCOL_VERSION) { |
486f8cd1 WD |
1697 | x += snprintf(argstr+x, sizeof argstr - x, |
1698 | "e%d.%d", PROTOCOL_VERSION, SUBPROTOCOL_VERSION); | |
1699 | } | |
2ed790f3 | 1700 | #endif |
486f8cd1 | 1701 | |
332cf6df WD |
1702 | argstr[x] = '\0'; |
1703 | ||
f98c60bf WD |
1704 | if (x != 1) |
1705 | args[ac++] = argstr; | |
d853783f | 1706 | |
51d48398 WD |
1707 | if (list_only > 1) |
1708 | args[ac++] = "--list-only"; | |
1709 | ||
f5a910dd WD |
1710 | /* This makes sure that the remote rsync can handle deleting with -d |
1711 | * sans -r because the --no-r option was added at the same time. */ | |
1712 | if (xfer_dirs && !recurse && delete_mode && am_sender) | |
1713 | args[ac++] = "--no-r"; | |
1714 | ||
854a1aad WD |
1715 | if (do_compression && def_compress_level != Z_DEFAULT_COMPRESSION) { |
1716 | if (asprintf(&arg, "--compress-level=%d", def_compress_level) < 0) | |
1717 | goto oom; | |
1718 | args[ac++] = arg; | |
1719 | } | |
1720 | ||
b5c6a6ae WD |
1721 | if (preserve_devices) { |
1722 | /* Note: sending "--devices" would not be backward-compatible. */ | |
1723 | if (!preserve_specials) | |
1724 | args[ac++] = "--no-specials"; /* -D is already set. */ | |
1725 | } else if (preserve_specials) | |
1726 | args[ac++] = "--specials"; | |
1727 | ||
5c5e1598 WD |
1728 | /* The server side doesn't use our log-format, but in certain |
1729 | * circumstances they need to know a little about the option. */ | |
b3e4e7ef WD |
1730 | if (stdout_format && am_sender) { |
1731 | /* Use --log-format, not --out-format, for compatibility. */ | |
1732 | if (stdout_format_has_i > 1) | |
487094a0 | 1733 | args[ac++] = "--log-format=%i%I"; |
b3e4e7ef | 1734 | else if (stdout_format_has_i) |
684d7582 | 1735 | args[ac++] = "--log-format=%i"; |
b3e4e7ef | 1736 | else if (stdout_format_has_o_or_i) |
5c5e1598 WD |
1737 | args[ac++] = "--log-format=%o"; |
1738 | else if (!verbose) | |
1739 | args[ac++] = "--log-format=X"; | |
1740 | } | |
1f30a674 | 1741 | |
332cf6df WD |
1742 | #ifdef ICONV_OPTION |
1743 | if (iconv_opt) { | |
1744 | char *set = strchr(iconv_opt, ','); | |
1745 | if (set) | |
1746 | set++; | |
1747 | else | |
1748 | set = iconv_opt; | |
1749 | if (asprintf(&arg, "--iconv=%s", set) < 0) | |
1750 | goto oom; | |
1751 | args[ac++] = arg; | |
1752 | } | |
1753 | #endif | |
1754 | ||
195bd906 | 1755 | if (block_size) { |
a06b419d | 1756 | if (asprintf(&arg, "-B%lu", block_size) < 0) |
f98c60bf WD |
1757 | goto oom; |
1758 | args[ac++] = arg; | |
dfa32483 | 1759 | } |
d853783f | 1760 | |
e5e85283 | 1761 | if (max_delete >= 0 && am_sender) { |
f98c60bf WD |
1762 | if (asprintf(&arg, "--max-delete=%d", max_delete) < 0) |
1763 | goto oom; | |
1764 | args[ac++] = arg; | |
dfa32483 WD |
1765 | } |
1766 | ||
74de13d1 WD |
1767 | if (min_size && am_sender) { |
1768 | args[ac++] = "--min-size"; | |
1769 | args[ac++] = min_size_arg; | |
1770 | } | |
1771 | ||
7d5acf1d WD |
1772 | if (max_size && am_sender) { |
1773 | args[ac++] = "--max-size"; | |
1774 | args[ac++] = max_size_arg; | |
1775 | } | |
1776 | ||
d853783f | 1777 | if (io_timeout) { |
f98c60bf WD |
1778 | if (asprintf(&arg, "--timeout=%d", io_timeout) < 0) |
1779 | goto oom; | |
1780 | args[ac++] = arg; | |
dfa32483 | 1781 | } |
d853783f | 1782 | |
ef5d23eb | 1783 | if (bwlimit) { |
f98c60bf WD |
1784 | if (asprintf(&arg, "--bwlimit=%d", bwlimit) < 0) |
1785 | goto oom; | |
1786 | args[ac++] = arg; | |
ef5d23eb DD |
1787 | } |
1788 | ||
d175d7e1 WD |
1789 | if (backup_dir) { |
1790 | args[ac++] = "--backup-dir"; | |
1791 | args[ac++] = backup_dir; | |
1792 | } | |
1793 | ||
1794 | /* Only send --suffix if it specifies a non-default value. */ | |
f98c60bf | 1795 | if (strcmp(backup_suffix, backup_dir ? "" : BACKUP_SUFFIX) != 0) { |
191e40da | 1796 | /* We use the following syntax to avoid weirdness with '~'. */ |
f98c60bf WD |
1797 | if (asprintf(&arg, "--suffix=%s", backup_suffix) < 0) |
1798 | goto oom; | |
1799 | args[ac++] = arg; | |
d853783f AT |
1800 | } |
1801 | ||
06a50542 | 1802 | if (am_sender) { |
e0e32031 | 1803 | if (delete_before) |
c6eb7fad | 1804 | args[ac++] = "--delete-before"; |
0d152437 WD |
1805 | else if (delete_during == 2) |
1806 | args[ac++] = "--delete-delay"; | |
1807 | else if (delete_during) | |
1808 | args[ac++] = "--delete-during"; | |
1809 | else if (delete_after) | |
06a50542 | 1810 | args[ac++] = "--delete-after"; |
e0e32031 WD |
1811 | else if (delete_mode && !delete_excluded) |
1812 | args[ac++] = "--delete"; | |
1813 | if (delete_excluded) | |
1814 | args[ac++] = "--delete-excluded"; | |
06a50542 WD |
1815 | if (force_delete) |
1816 | args[ac++] = "--force"; | |
11e758a4 WD |
1817 | if (write_batch < 0) |
1818 | args[ac++] = "--only-write-batch=X"; | |
def97ff9 WD |
1819 | if (am_root > 1) |
1820 | args[ac++] = "--super"; | |
f17e769e WD |
1821 | if (size_only) |
1822 | args[ac++] = "--size-only"; | |
06a50542 | 1823 | } |
b33b791e | 1824 | |
5b56cc19 | 1825 | if (modify_window_set) { |
f98c60bf WD |
1826 | if (asprintf(&arg, "--modify-window=%d", modify_window) < 0) |
1827 | goto oom; | |
1828 | args[ac++] = arg; | |
5b56cc19 AT |
1829 | } |
1830 | ||
c8d895de | 1831 | if (checksum_seed) { |
221ddb94 | 1832 | if (asprintf(&arg, "--checksum-seed=%d", checksum_seed) < 0) |
c8d895de WD |
1833 | goto oom; |
1834 | args[ac++] = arg; | |
1835 | } | |
1836 | ||
a7260c40 | 1837 | if (partial_dir && am_sender) { |
77860bac | 1838 | if (partial_dir != tmp_partialdir) { |
3671987f WD |
1839 | args[ac++] = "--partial-dir"; |
1840 | args[ac++] = partial_dir; | |
1841 | } | |
f06e7082 WD |
1842 | if (delay_updates) |
1843 | args[ac++] = "--delay-updates"; | |
77860bac | 1844 | } else if (keep_partial && am_sender) |
d853783f AT |
1845 | args[ac++] = "--partial"; |
1846 | ||
ef55c686 AT |
1847 | if (ignore_errors) |
1848 | args[ac++] = "--ignore-errors"; | |
1849 | ||
b5313607 DD |
1850 | if (copy_unsafe_links) |
1851 | args[ac++] = "--copy-unsafe-links"; | |
1852 | ||
d853783f AT |
1853 | if (safe_symlinks) |
1854 | args[ac++] = "--safe-links"; | |
1855 | ||
1856 | if (numeric_ids) | |
1857 | args[ac++] = "--numeric-ids"; | |
1858 | ||
e90aab49 | 1859 | if (ignore_existing && am_sender) |
3d6feada MP |
1860 | args[ac++] = "--ignore-existing"; |
1861 | ||
e90aab49 WD |
1862 | /* Backward compatibility: send --existing, not --ignore-non-existing. */ |
1863 | if (ignore_non_existing && am_sender) | |
1864 | args[ac++] = "--existing"; | |
1865 | ||
a015788d WD |
1866 | if (append_mode) |
1867 | args[ac++] = "--append"; | |
1868 | else if (inplace) | |
a3221d2a WD |
1869 | args[ac++] = "--inplace"; |
1870 | ||
120cde95 | 1871 | if (tmpdir && am_sender) { |
d853783f AT |
1872 | args[ac++] = "--temp-dir"; |
1873 | args[ac++] = tmpdir; | |
1874 | } | |
1875 | ||
e012f858 | 1876 | if (basis_dir[0] && am_sender) { |
375a4556 DD |
1877 | /* the server only needs this option if it is not the sender, |
1878 | * and it may be an older version that doesn't know this | |
1879 | * option, so don't send it if client is the sender. | |
1880 | */ | |
e012f858 WD |
1881 | int i; |
1882 | for (i = 0; i < basis_dir_cnt; i++) { | |
1883 | args[ac++] = dest_option; | |
1884 | args[ac++] = basis_dir[i]; | |
1885 | } | |
375a4556 DD |
1886 | } |
1887 | ||
305666bf WD |
1888 | if (files_from && (!am_sender || filesfrom_host)) { |
1889 | if (filesfrom_host) { | |
ea5164d1 | 1890 | args[ac++] = "--files-from"; |
305666bf | 1891 | args[ac++] = files_from; |
ea5164d1 WD |
1892 | if (eol_nulls) |
1893 | args[ac++] = "--from0"; | |
1894 | } else { | |
1895 | args[ac++] = "--files-from=-"; | |
1896 | args[ac++] = "--from0"; | |
1897 | } | |
c0ab28d1 WD |
1898 | if (!relative_paths) |
1899 | args[ac++] = "--no-relative"; | |
ea5164d1 | 1900 | } |
89f2a4c2 | 1901 | if (relative_paths && !implied_dirs && !am_sender) |
3a90ea0a | 1902 | args[ac++] = "--no-implied-dirs"; |
ea5164d1 | 1903 | |
c4ed1487 WD |
1904 | if (fuzzy_basis && am_sender) |
1905 | args[ac++] = "--fuzzy"; | |
1906 | ||
47c11975 WD |
1907 | if (remove_source_files == 1) |
1908 | args[ac++] = "--remove-source-files"; | |
1909 | else if (remove_source_files) | |
07c6ae7d WD |
1910 | args[ac++] = "--remove-sent-files"; |
1911 | ||
d853783f | 1912 | *argc = ac; |
f98c60bf WD |
1913 | return; |
1914 | ||
1915 | oom: | |
1916 | out_of_memory("server_options"); | |
7a6421fa AT |
1917 | } |
1918 | ||
305666bf WD |
1919 | /* Look for a HOST specfication of the form "HOST:PATH", "HOST::PATH", or |
1920 | * "rsync://HOST:PORT/PATH". If found, *host_ptr will be set to some allocated | |
1921 | * memory with the HOST. If a daemon-accessing spec was specified, the value | |
1922 | * of *port_ptr will contain a non-0 port number, otherwise it will be set to | |
1923 | * 0. The return value is a pointer to the PATH. Note that the HOST spec can | |
1924 | * be an IPv6 literal address enclosed in '[' and ']' (such as "[::1]" or | |
1925 | * "[::ffff:127.0.0.1]") which is returned without the '[' and ']'. */ | |
1926 | char *check_for_hostspec(char *s, char **host_ptr, int *port_ptr) | |
ea5164d1 | 1927 | { |
305666bf WD |
1928 | char *p; |
1929 | int not_host; | |
8f4ae68c | 1930 | int hostlen; |
305666bf WD |
1931 | |
1932 | if (port_ptr && strncasecmp(URL_PREFIX, s, strlen(URL_PREFIX)) == 0) { | |
1933 | char *path; | |
305666bf WD |
1934 | s += strlen(URL_PREFIX); |
1935 | if ((p = strchr(s, '/')) != NULL) { | |
1936 | hostlen = p - s; | |
1937 | path = p + 1; | |
1938 | } else { | |
1939 | hostlen = strlen(s); | |
1940 | path = ""; | |
1941 | } | |
1942 | if (*s == '[' && (p = strchr(s, ']')) != NULL) { | |
1943 | s++; | |
1944 | hostlen = p - s; | |
c60b7056 WD |
1945 | if (p[1] == ':') |
1946 | *port_ptr = atoi(p+2); | |
305666bf WD |
1947 | } else { |
1948 | if ((p = strchr(s, ':')) != NULL) { | |
1949 | hostlen = p - s; | |
1950 | *port_ptr = atoi(p+1); | |
c60b7056 | 1951 | } |
305666bf | 1952 | } |
c60b7056 WD |
1953 | if (!*port_ptr) |
1954 | *port_ptr = RSYNC_PORT; | |
305666bf WD |
1955 | *host_ptr = new_array(char, hostlen + 1); |
1956 | strlcpy(*host_ptr, s, hostlen + 1); | |
1957 | return path; | |
1958 | } | |
ea5164d1 | 1959 | |
305666bf | 1960 | if (*s == '[' && (p = strchr(s, ']')) != NULL && p[1] == ':') { |
8f4ae68c WD |
1961 | s++; |
1962 | hostlen = p - s; | |
305666bf WD |
1963 | *p = '\0'; |
1964 | not_host = strchr(s, '/') || !strchr(s, ':'); | |
1965 | *p = ']'; | |
1966 | if (not_host) | |
1967 | return NULL; | |
c60b7056 | 1968 | p++; |
305666bf WD |
1969 | } else { |
1970 | if (!(p = strchr(s, ':'))) | |
1971 | return NULL; | |
8f4ae68c | 1972 | hostlen = p - s; |
305666bf WD |
1973 | *p = '\0'; |
1974 | not_host = strchr(s, '/') != NULL; | |
1975 | *p = ':'; | |
1976 | if (not_host) | |
1977 | return NULL; | |
1978 | } | |
1979 | ||
8f4ae68c WD |
1980 | *host_ptr = new_array(char, hostlen + 1); |
1981 | strlcpy(*host_ptr, s, hostlen + 1); | |
ea5164d1 | 1982 | |
305666bf WD |
1983 | if (p[1] == ':') { |
1984 | if (port_ptr && !*port_ptr) | |
1985 | *port_ptr = RSYNC_PORT; | |
1986 | return p + 2; | |
1987 | } | |
1988 | if (port_ptr) | |
1989 | *port_ptr = 0; | |
ea5164d1 | 1990 | |
305666bf | 1991 | return p + 1; |
ea5164d1 | 1992 | } |