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