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