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