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