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