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