Commit | Line | Data |
---|---|---|
7a24c346 MP |
1 | /* -*- c-file-style: "linux" -*- |
2 | ||
2855f61f | 3 | Copyright (C) 1998-2001 by Andrew Tridgell <tridge@samba.org> |
736a6a29 | 4 | Copyright (C) 2000, 2001, 2002 by Martin Pool <mbp@samba.org> |
7a6421fa AT |
5 | |
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. | |
10 | ||
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. | |
15 | ||
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 | */ | |
20 | ||
7a6421fa | 21 | #include "rsync.h" |
2855f61f | 22 | #include "popt.h" |
7a6421fa AT |
23 | |
24 | int make_backups = 0; | |
1bfbf40b MP |
25 | |
26 | /** | |
27 | * Should we send the whole file as literal data rather than trying to | |
28 | * create an incremental diff? This is on by default when both source | |
29 | * and destination are local and we're not doing a batch delta, | |
30 | * because there it's no cheaper to read the whole basis file than to | |
31 | * just rewrite it. | |
32 | * | |
33 | * -1 means "unspecified", i.e. depend on is_local; 0 means off; 1 means on. | |
34 | **/ | |
93689aa5 | 35 | int whole_file = -1; |
1bfbf40b | 36 | |
7a6421fa AT |
37 | int copy_links = 0; |
38 | int preserve_links = 0; | |
39 | int preserve_hard_links = 0; | |
40 | int preserve_perms = 0; | |
41 | int preserve_devices = 0; | |
42 | int preserve_uid = 0; | |
43 | int preserve_gid = 0; | |
44 | int preserve_times = 0; | |
45 | int update_only = 0; | |
46 | int cvs_exclude = 0; | |
47 | int dry_run=0; | |
48 | int local_server=0; | |
49 | int ignore_times=0; | |
50 | int delete_mode=0; | |
b33b791e | 51 | int delete_excluded=0; |
7a6421fa AT |
52 | int one_file_system=0; |
53 | int remote_version=0; | |
54 | int sparse_files=0; | |
55 | int do_compression=0; | |
56 | int am_root=0; | |
57 | int orig_umask=0; | |
58 | int relative_paths=0; | |
59 | int numeric_ids = 0; | |
60 | int force_delete = 0; | |
61 | int io_timeout = 0; | |
62 | int io_error = 0; | |
63 | int read_only = 0; | |
64 | int module_id = -1; | |
65 | int am_server = 0; | |
30ce7e8a | 66 | int am_sender = 0; |
7a6421fa AT |
67 | int recurse = 0; |
68 | int am_daemon=0; | |
a800434a | 69 | int do_stats=0; |
eb86d661 | 70 | int do_progress=0; |
c95da96a | 71 | int keep_partial=0; |
d853783f | 72 | int safe_symlinks=0; |
b5313607 | 73 | int copy_unsafe_links=0; |
7a6421fa | 74 | int block_size=BLOCK_SIZE; |
f83f0548 | 75 | int size_only=0; |
ef5d23eb | 76 | int bwlimit=0; |
57df171b | 77 | int delete_after=0; |
1347d512 | 78 | int only_existing=0; |
3d6feada | 79 | int opt_ignore_existing=0; |
0b73ca12 | 80 | int max_delete=0; |
ef55c686 | 81 | int ignore_errors=0; |
5b56cc19 AT |
82 | #ifdef _WIN32 |
83 | int modify_window=2; | |
84 | #else | |
85 | int modify_window=0; | |
86 | #endif | |
93689aa5 | 87 | int blocking_io=-1; |
7a6421fa | 88 | |
13e29995 | 89 | /** Network address family. **/ |
6ab6d4bf | 90 | #ifdef INET6 |
13e29995 | 91 | int default_af_hint = 0; /* Any protocol */ |
6ab6d4bf | 92 | #else |
13e29995 | 93 | int default_af_hint = AF_INET; /* Must use IPv4 */ |
6ab6d4bf | 94 | #endif |
06963d0f | 95 | |
13e29995 MP |
96 | /** Do not go into the background when run as --daemon. Good |
97 | * for debugging and required for running as a service on W32, | |
98 | * or under Unix process-monitors. **/ | |
99 | int no_detach = 0; | |
100 | ||
088aac85 DD |
101 | int write_batch = 0; |
102 | int read_batch = 0; | |
6902ed17 | 103 | |
7a6421fa AT |
104 | char *backup_suffix = BACKUP_SUFFIX; |
105 | char *tmpdir = NULL; | |
375a4556 | 106 | char *compare_dest = NULL; |
7a6421fa AT |
107 | char *config_file = RSYNCD_CONF; |
108 | char *shell_cmd = NULL; | |
b6062654 | 109 | char *log_format = NULL; |
65575e96 | 110 | char *password_file = NULL; |
41bd28fe | 111 | char *rsync_path = RSYNC_PATH; |
66203a98 | 112 | char *backup_dir = NULL; |
7a6421fa AT |
113 | int rsync_port = RSYNC_PORT; |
114 | ||
115 | int verbose = 0; | |
b86f0cef | 116 | int quiet = 0; |
7a6421fa | 117 | int always_checksum = 0; |
f7632fc6 | 118 | int list_only = 0; |
7a6421fa | 119 | |
088aac85 | 120 | char *batch_prefix = NULL; |
6902ed17 | 121 | |
5b56cc19 AT |
122 | static int modify_window_set; |
123 | ||
06963d0f MP |
124 | /** Local address to bind. As a character string because it's |
125 | * interpreted by the IPv6 layer: should be a numeric IP4 or ip6 | |
126 | * address, or a hostname. **/ | |
127 | char *bind_address; | |
5c9730a4 | 128 | |
7a24c346 | 129 | |
27a12348 | 130 | static void print_rsync_version(enum logcode f) |
7a24c346 | 131 | { |
0c80cd8e | 132 | char const *got_socketpair = "no "; |
2855f61f MP |
133 | char const *hardlinks = "no "; |
134 | char const *links = "no "; | |
a358449a | 135 | char const *ipv6 = "no "; |
736a6a29 | 136 | STRUCT_STAT *dumstat; |
0c80cd8e MP |
137 | |
138 | #ifdef HAVE_SOCKETPAIR | |
139 | got_socketpair = ""; | |
140 | #endif | |
2855f61f MP |
141 | |
142 | #if SUPPORT_HARD_LINKS | |
143 | hardlinks = ""; | |
144 | #endif | |
145 | ||
146 | #if SUPPORT_LINKS | |
147 | links = ""; | |
148 | #endif | |
149 | ||
a358449a MP |
150 | #if INET6 |
151 | ipv6 = ""; | |
152 | #endif | |
153 | ||
2855f61f | 154 | rprintf(f, "%s version %s protocol version %d\n", |
a358449a | 155 | RSYNC_NAME, RSYNC_VERSION, PROTOCOL_VERSION); |
2855f61f | 156 | rprintf(f, |
0413e160 | 157 | "Copyright (C) 1996-2002 by Andrew Tridgell and others\n"); |
3b4b1984 | 158 | rprintf(f, "<http://rsync.samba.org/>\n"); |
2855f61f | 159 | rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, " |
736a6a29 | 160 | "%shard links, %ssymlinks, batchfiles, %sIPv6,\n", |
30ce7e8a | 161 | (int) (sizeof(OFF_T) * 8), |
a358449a | 162 | got_socketpair, hardlinks, links, ipv6); |
2855f61f | 163 | |
736a6a29 MP |
164 | /* Note that this field may not have type ino_t. It depends |
165 | * on the complicated interaction between largefile feature | |
166 | * macros. */ | |
6abd193f | 167 | rprintf(f, " %d-bit system inums, %d-bit internal inums\n", |
736a6a29 | 168 | (int) (sizeof(dumstat->st_ino) * 8), |
6abd193f | 169 | (int) (sizeof(INO64_T) * 8)); |
736a6a29 | 170 | |
7a24c346 | 171 | #ifdef NO_INT64 |
4db41492 | 172 | rprintf(f, "WARNING: no 64-bit integers on this platform!\n"); |
7a24c346 MP |
173 | #endif |
174 | } | |
175 | ||
176 | ||
0f3203c3 | 177 | void usage(enum logcode F) |
7a6421fa | 178 | { |
2855f61f | 179 | print_rsync_version(F); |
704f908e AT |
180 | |
181 | rprintf(F,"rsync is a file transfer program capable of efficient remote update\nvia a fast differencing algorithm.\n\n"); | |
182 | ||
9ef53907 | 183 | rprintf(F,"Usage: rsync [OPTION]... SRC [SRC]... [USER@]HOST:DEST\n"); |
704f908e | 184 | rprintf(F," or rsync [OPTION]... [USER@]HOST:SRC DEST\n"); |
9ef53907 | 185 | rprintf(F," or rsync [OPTION]... SRC [SRC]... DEST\n"); |
14d43f1f | 186 | rprintf(F," or rsync [OPTION]... [USER@]HOST::SRC [DEST]\n"); |
9ef53907 | 187 | rprintf(F," or rsync [OPTION]... SRC [SRC]... [USER@]HOST::DEST\n"); |
14d43f1f | 188 | rprintf(F," or rsync [OPTION]... rsync://[USER@]HOST[:PORT]/SRC [DEST]\n"); |
9ef53907 DD |
189 | rprintf(F,"SRC on single-colon remote HOST will be expanded by remote shell\n"); |
190 | rprintf(F,"SRC on server remote HOST may contain shell wildcards or multiple\n"); | |
191 | rprintf(F," sources separated by space as long as they have same top-level\n"); | |
704f908e AT |
192 | rprintf(F,"\nOptions\n"); |
193 | rprintf(F," -v, --verbose increase verbosity\n"); | |
b86f0cef | 194 | rprintf(F," -q, --quiet decrease verbosity\n"); |
704f908e AT |
195 | rprintf(F," -c, --checksum always checksum\n"); |
196 | rprintf(F," -a, --archive archive mode\n"); | |
197 | rprintf(F," -r, --recursive recurse into directories\n"); | |
198 | rprintf(F," -R, --relative use relative path names\n"); | |
9ef53907 | 199 | rprintf(F," -b, --backup make backups (default %s suffix)\n",BACKUP_SUFFIX); |
e20c5e95 | 200 | rprintf(F," --backup-dir make backups into this directory\n"); |
9ef53907 | 201 | rprintf(F," --suffix=SUFFIX override backup suffix\n"); |
704f908e | 202 | rprintf(F," -u, --update update only (don't overwrite newer files)\n"); |
13e29995 MP |
203 | rprintf(F," -l, --links copy symlinks as symlinks\n"); |
204 | rprintf(F," -L, --copy-links copy the referent of symlinks\n"); | |
b5313607 | 205 | rprintf(F," --copy-unsafe-links copy links outside the source tree\n"); |
d853783f | 206 | rprintf(F," --safe-links ignore links outside the destination tree\n"); |
704f908e AT |
207 | rprintf(F," -H, --hard-links preserve hard links\n"); |
208 | rprintf(F," -p, --perms preserve permissions\n"); | |
209 | rprintf(F," -o, --owner preserve owner (root only)\n"); | |
210 | rprintf(F," -g, --group preserve group\n"); | |
211 | rprintf(F," -D, --devices preserve devices (root only)\n"); | |
212 | rprintf(F," -t, --times preserve times\n"); | |
213 | rprintf(F," -S, --sparse handle sparse files efficiently\n"); | |
214 | rprintf(F," -n, --dry-run show what would have been transferred\n"); | |
215 | rprintf(F," -W, --whole-file copy whole files, no incremental checks\n"); | |
93689aa5 | 216 | rprintf(F," --no-whole-file turn off --whole-file\n"); |
704f908e | 217 | rprintf(F," -x, --one-file-system don't cross filesystem boundaries\n"); |
9ef53907 | 218 | rprintf(F," -B, --block-size=SIZE checksum blocking size (default %d)\n",BLOCK_SIZE); |
704f908e AT |
219 | rprintf(F," -e, --rsh=COMMAND specify rsh replacement\n"); |
220 | rprintf(F," --rsync-path=PATH specify path to rsync on the remote machine\n"); | |
221 | rprintf(F," -C, --cvs-exclude auto ignore files in the same way CVS does\n"); | |
1347d512 | 222 | rprintf(F," --existing only update files that already exist\n"); |
3d6feada | 223 | rprintf(F," --ignore-existing ignore files that already exist on the receiving side\n"); |
704f908e | 224 | rprintf(F," --delete delete files that don't exist on the sending side\n"); |
b33b791e | 225 | rprintf(F," --delete-excluded also delete excluded files on the receiving side\n"); |
57df171b | 226 | rprintf(F," --delete-after delete after transferring, not before\n"); |
ef55c686 | 227 | rprintf(F," --ignore-errors delete even if there are IO errors\n"); |
0b73ca12 | 228 | rprintf(F," --max-delete=NUM don't delete more than NUM files\n"); |
c95da96a | 229 | rprintf(F," --partial keep partially transferred files\n"); |
704f908e AT |
230 | rprintf(F," --force force deletion of directories even if not empty\n"); |
231 | rprintf(F," --numeric-ids don't map uid/gid values by user/group name\n"); | |
232 | rprintf(F," --timeout=TIME set IO timeout in seconds\n"); | |
233 | rprintf(F," -I, --ignore-times don't exclude files that match length and time\n"); | |
f83f0548 | 234 | rprintf(F," --size-only only use file size when determining if a file should be transferred\n"); |
5b56cc19 | 235 | rprintf(F," --modify-window=NUM Timestamp window (seconds) for file match (default=%d)\n",modify_window); |
704f908e | 236 | rprintf(F," -T --temp-dir=DIR create temporary files in directory DIR\n"); |
375a4556 | 237 | rprintf(F," --compare-dest=DIR also compare destination files relative to DIR\n"); |
d9fcc198 | 238 | rprintf(F," -P equivalent to --partial --progress\n"); |
704f908e | 239 | rprintf(F," -z, --compress compress file data\n"); |
2acf81eb | 240 | rprintf(F," --exclude=PATTERN exclude files matching PATTERN\n"); |
858fb9eb | 241 | rprintf(F," --exclude-from=FILE exclude patterns listed in FILE\n"); |
2acf81eb | 242 | rprintf(F," --include=PATTERN don't exclude files matching PATTERN\n"); |
858fb9eb | 243 | rprintf(F," --include-from=FILE don't exclude patterns listed in FILE\n"); |
704f908e AT |
244 | rprintf(F," --version print version number\n"); |
245 | rprintf(F," --daemon run as a rsync daemon\n"); | |
a538066d | 246 | rprintf(F," --no-detach do not detach from the parent\n"); |
2a951cd2 | 247 | rprintf(F," --address=ADDRESS bind to the specified address\n"); |
704f908e AT |
248 | rprintf(F," --config=FILE specify alternate rsyncd.conf file\n"); |
249 | rprintf(F," --port=PORT specify alternate rsyncd port number\n"); | |
c80ccabb | 250 | rprintf(F," --blocking-io use blocking IO for the remote shell\n"); |
93689aa5 | 251 | rprintf(F," --no-blocking-io turn off --blocking-io\n"); |
704f908e | 252 | rprintf(F," --stats give some file transfer stats\n"); |
eb86d661 | 253 | rprintf(F," --progress show progress during transfer\n"); |
b6062654 | 254 | rprintf(F," --log-format=FORMAT log file transfers using specified format\n"); |
65575e96 | 255 | rprintf(F," --password-file=FILE get password from FILE\n"); |
ef5d23eb | 256 | rprintf(F," --bwlimit=KBPS limit I/O bandwidth, KBytes per second\n"); |
088aac85 DD |
257 | rprintf(F," --write-batch=PREFIX write batch fileset starting with PREFIX\n"); |
258 | rprintf(F," --read-batch=PREFIX read batch fileset starting with PREFIX\n"); | |
704f908e | 259 | rprintf(F," -h, --help show this help screen\n"); |
06963d0f MP |
260 | #ifdef INET6 |
261 | rprintf(F," -4 prefer IPv4\n"); | |
262 | rprintf(F," -6 prefer IPv6\n"); | |
263 | #endif | |
7a6421fa AT |
264 | |
265 | rprintf(F,"\n"); | |
b72f24c7 AT |
266 | |
267 | rprintf(F,"\nPlease see the rsync(1) and rsyncd.conf(5) man pages for full documentation\n"); | |
2855f61f | 268 | rprintf(F,"See http://rsync.samba.org/ for updates, bug reports, and answers\n"); |
7a6421fa AT |
269 | } |
270 | ||
2855f61f | 271 | enum {OPT_VERSION = 1000, OPT_SUFFIX, OPT_SENDER, OPT_SERVER, OPT_EXCLUDE, |
b33b791e DD |
272 | OPT_EXCLUDE_FROM, OPT_DELETE, OPT_DELETE_EXCLUDED, OPT_NUMERIC_IDS, |
273 | OPT_RSYNC_PATH, OPT_FORCE, OPT_TIMEOUT, OPT_DAEMON, OPT_CONFIG, OPT_PORT, | |
d853783f | 274 | OPT_INCLUDE, OPT_INCLUDE_FROM, OPT_STATS, OPT_PARTIAL, OPT_PROGRESS, |
b5313607 | 275 | OPT_COPY_UNSAFE_LINKS, OPT_SAFE_LINKS, OPT_COMPARE_DEST, |
57df171b | 276 | OPT_LOG_FORMAT, OPT_PASSWORD_FILE, OPT_SIZE_ONLY, OPT_ADDRESS, |
ef55c686 | 277 | OPT_DELETE_AFTER, OPT_EXISTING, OPT_MAX_DELETE, OPT_BACKUP_DIR, |
5b56cc19 | 278 | OPT_IGNORE_ERRORS, OPT_BWLIMIT, OPT_BLOCKING_IO, |
93689aa5 | 279 | OPT_NO_BLOCKING_IO, OPT_NO_WHOLE_FILE, |
3d6feada | 280 | OPT_MODIFY_WINDOW, OPT_READ_BATCH, OPT_WRITE_BATCH, OPT_IGNORE_EXISTING}; |
7a6421fa | 281 | |
2855f61f MP |
282 | static struct poptOption long_options[] = { |
283 | /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */ | |
284 | {"version", 0, POPT_ARG_NONE, 0, OPT_VERSION}, | |
285 | {"suffix", 0, POPT_ARG_STRING, &backup_suffix}, | |
286 | {"rsync-path", 0, POPT_ARG_STRING, &rsync_path}, | |
287 | {"password-file", 0, POPT_ARG_STRING, &password_file}, | |
288 | {"ignore-times", 'I', POPT_ARG_NONE, &ignore_times}, | |
289 | {"size-only", 0, POPT_ARG_NONE, &size_only}, | |
290 | {"modify-window", 0, POPT_ARG_INT, &modify_window, OPT_MODIFY_WINDOW}, | |
291 | {"one-file-system", 'x', POPT_ARG_NONE, &one_file_system}, | |
292 | {"delete", 0, POPT_ARG_NONE, &delete_mode}, | |
293 | {"existing", 0, POPT_ARG_NONE, &only_existing}, | |
3d6feada | 294 | {"ignore-existing", 0, POPT_ARG_NONE, &opt_ignore_existing}, |
2855f61f MP |
295 | {"delete-after", 0, POPT_ARG_NONE, &delete_after}, |
296 | {"delete-excluded", 0, POPT_ARG_NONE, 0, OPT_DELETE_EXCLUDED}, | |
297 | {"force", 0, POPT_ARG_NONE, &force_delete}, | |
298 | {"numeric-ids", 0, POPT_ARG_NONE, &numeric_ids}, | |
299 | {"exclude", 0, POPT_ARG_STRING, 0, OPT_EXCLUDE}, | |
300 | {"include", 0, POPT_ARG_STRING, 0, OPT_INCLUDE}, | |
301 | {"exclude-from", 0, POPT_ARG_STRING, 0, OPT_EXCLUDE_FROM}, | |
302 | {"include-from", 0, POPT_ARG_STRING, 0, OPT_INCLUDE_FROM}, | |
303 | {"safe-links", 0, POPT_ARG_NONE, &safe_symlinks}, | |
304 | {"help", 'h', POPT_ARG_NONE, 0, 'h'}, | |
305 | {"backup", 'b', POPT_ARG_NONE, &make_backups}, | |
306 | {"dry-run", 'n', POPT_ARG_NONE, &dry_run}, | |
307 | {"sparse", 'S', POPT_ARG_NONE, &sparse_files}, | |
308 | {"cvs-exclude", 'C', POPT_ARG_NONE, &cvs_exclude}, | |
309 | {"update", 'u', POPT_ARG_NONE, &update_only}, | |
310 | {"links", 'l', POPT_ARG_NONE, &preserve_links}, | |
311 | {"copy-links", 'L', POPT_ARG_NONE, ©_links}, | |
759c0627 | 312 | {"whole-file", 'W', POPT_ARG_NONE, &whole_file}, |
93689aa5 | 313 | {"no-whole-file", 0, POPT_ARG_NONE, 0, OPT_NO_WHOLE_FILE}, |
2855f61f MP |
314 | {"copy-unsafe-links", 0, POPT_ARG_NONE, ©_unsafe_links}, |
315 | {"perms", 'p', POPT_ARG_NONE, &preserve_perms}, | |
316 | {"owner", 'o', POPT_ARG_NONE, &preserve_uid}, | |
317 | {"group", 'g', POPT_ARG_NONE, &preserve_gid}, | |
318 | {"devices", 'D', POPT_ARG_NONE, &preserve_devices}, | |
319 | {"times", 't', POPT_ARG_NONE, &preserve_times}, | |
320 | {"checksum", 'c', POPT_ARG_NONE, &always_checksum}, | |
321 | {"verbose", 'v', POPT_ARG_NONE, 0, 'v'}, | |
322 | {"quiet", 'q', POPT_ARG_NONE, 0, 'q'}, | |
323 | {"archive", 'a', POPT_ARG_NONE, 0, 'a'}, | |
324 | {"server", 0, POPT_ARG_NONE, &am_server}, | |
325 | {"sender", 0, POPT_ARG_NONE, 0, OPT_SENDER}, | |
f6e09367 | 326 | {"recursive", 'r', POPT_ARG_NONE, &recurse}, |
2855f61f MP |
327 | {"relative", 'R', POPT_ARG_NONE, &relative_paths}, |
328 | {"rsh", 'e', POPT_ARG_STRING, &shell_cmd}, | |
329 | {"block-size", 'B', POPT_ARG_INT, &block_size}, | |
330 | {"max-delete", 0, POPT_ARG_INT, &max_delete}, | |
331 | {"timeout", 0, POPT_ARG_INT, &io_timeout}, | |
332 | {"temp-dir", 'T', POPT_ARG_STRING, &tmpdir}, | |
7c06e407 | 333 | {"compare-dest", 0, POPT_ARG_STRING, &compare_dest}, |
2855f61f MP |
334 | /* TODO: Should this take an optional int giving the compression level? */ |
335 | {"compress", 'z', POPT_ARG_NONE, &do_compression}, | |
336 | {"daemon", 0, POPT_ARG_NONE, &am_daemon}, | |
13e29995 | 337 | {"no-detach", 0, POPT_ARG_NONE, &no_detach}, |
2855f61f MP |
338 | {"stats", 0, POPT_ARG_NONE, &do_stats}, |
339 | {"progress", 0, POPT_ARG_NONE, &do_progress}, | |
340 | {"partial", 0, POPT_ARG_NONE, &keep_partial}, | |
341 | {"ignore-errors", 0, POPT_ARG_NONE, &ignore_errors}, | |
342 | {"blocking-io", 0, POPT_ARG_NONE, &blocking_io}, | |
93689aa5 | 343 | {"no-blocking-io", 0, POPT_ARG_NONE, 0, OPT_NO_BLOCKING_IO}, |
2855f61f MP |
344 | {0, 'P', POPT_ARG_NONE, 0, 'P'}, |
345 | {"config", 0, POPT_ARG_STRING, &config_file}, | |
346 | {"port", 0, POPT_ARG_INT, &rsync_port}, | |
347 | {"log-format", 0, POPT_ARG_STRING, &log_format}, | |
348 | {"bwlimit", 0, POPT_ARG_INT, &bwlimit}, | |
06963d0f | 349 | {"address", 0, POPT_ARG_STRING, &bind_address, 0}, |
2855f61f MP |
350 | {"backup-dir", 0, POPT_ARG_STRING, &backup_dir}, |
351 | {"hard-links", 'H', POPT_ARG_NONE, &preserve_hard_links}, | |
088aac85 DD |
352 | {"read-batch", 0, POPT_ARG_STRING, &batch_prefix, OPT_READ_BATCH}, |
353 | {"write-batch", 0, POPT_ARG_STRING, &batch_prefix, OPT_WRITE_BATCH}, | |
06963d0f | 354 | #ifdef INET6 |
13e29995 MP |
355 | {0, '4', POPT_ARG_VAL, &default_af_hint, AF_INET }, |
356 | {0, '6', POPT_ARG_VAL, &default_af_hint, AF_INET6 }, | |
06963d0f | 357 | #endif |
2855f61f MP |
358 | {0,0,0,0} |
359 | }; | |
7a6421fa | 360 | |
06963d0f | 361 | |
cd8185f2 AT |
362 | static char err_buf[100]; |
363 | ||
2855f61f | 364 | |
add7e8fb MP |
365 | /* We store the option error message, if any, so that we can log the |
366 | connection attempt (which requires parsing the options), and then | |
367 | show the error later on. */ | |
cd8185f2 AT |
368 | void option_error(void) |
369 | { | |
370 | if (err_buf[0]) { | |
2855f61f MP |
371 | rprintf(FLOG, "%s", err_buf); |
372 | rprintf(FERROR, "%s: %s", RSYNC_NAME, err_buf); | |
cd8185f2 | 373 | } else { |
add7e8fb MP |
374 | rprintf (FERROR, "Error parsing options: " |
375 | "option may be supported on client but not on server?\n"); | |
376 | rprintf (FERROR, RSYNC_NAME ": Error parsing options: " | |
377 | "option may be supported on client but not on server?\n"); | |
cd8185f2 | 378 | } |
cd8185f2 AT |
379 | } |
380 | ||
381 | /* check to see if we should refuse this option */ | |
382 | static int check_refuse_options(char *ref, int opt) | |
383 | { | |
384 | int i, len; | |
385 | char *p; | |
386 | const char *name; | |
387 | ||
2855f61f | 388 | for (i=0; long_options[i].longName; i++) { |
cd8185f2 AT |
389 | if (long_options[i].val == opt) break; |
390 | } | |
391 | ||
2855f61f | 392 | if (!long_options[i].longName) return 0; |
cd8185f2 | 393 | |
2855f61f | 394 | name = long_options[i].longName; |
cd8185f2 AT |
395 | len = strlen(name); |
396 | ||
397 | while ((p = strstr(ref,name))) { | |
055af776 AT |
398 | if ((p==ref || p[-1]==' ') && |
399 | (p[len] == ' ' || p[len] == 0)) { | |
8950ac03 | 400 | snprintf(err_buf,sizeof(err_buf), |
cd8185f2 AT |
401 | "The '%s' option is not supported by this server\n", name); |
402 | return 1; | |
403 | } | |
404 | ref += len; | |
405 | } | |
406 | return 0; | |
407 | } | |
408 | ||
409 | ||
2855f61f MP |
410 | static int count_args(char const **argv) |
411 | { | |
412 | int i = 0; | |
413 | ||
414 | while (argv[i] != NULL) | |
415 | i++; | |
416 | ||
417 | return i; | |
418 | } | |
419 | ||
420 | ||
421 | /* Process command line arguments. Called on both local and remote. | |
422 | * Returns if all options are OK, otherwise fills in err_buf and | |
423 | * returns 0. */ | |
424 | int parse_arguments(int *argc, const char ***argv, int frommain) | |
7a6421fa | 425 | { |
d853783f | 426 | int opt; |
cd8185f2 | 427 | char *ref = lp_refuse_options(module_id); |
2855f61f | 428 | poptContext pc; |
d853783f | 429 | |
2855f61f | 430 | /* TODO: Call poptReadDefaultConfig; handle errors. */ |
cd8185f2 | 431 | |
2855f61f MP |
432 | /* The context leaks in case of an error, but if there's a |
433 | * problem we always exit anyhow. */ | |
4db41492 | 434 | pc = poptGetContext(RSYNC_NAME, *argc, *argv, long_options, 0); |
2855f61f MP |
435 | |
436 | while ((opt = poptGetNextOpt(pc)) != -1) { | |
cd8185f2 AT |
437 | if (ref) { |
438 | if (check_refuse_options(ref, opt)) return 0; | |
439 | } | |
440 | ||
2855f61f MP |
441 | /* most options are handled automatically by popt; |
442 | * only special cases are returned and listed here. */ | |
443 | ||
d853783f AT |
444 | switch (opt) { |
445 | case OPT_VERSION: | |
2855f61f | 446 | print_rsync_version(FINFO); |
d853783f AT |
447 | exit_cleanup(0); |
448 | ||
5b56cc19 | 449 | case OPT_MODIFY_WINDOW: |
2855f61f MP |
450 | /* The value has already been set by popt, but |
451 | * we need to remember that we're using a | |
452 | * non-default setting. */ | |
5b56cc19 AT |
453 | modify_window_set = 1; |
454 | break; | |
455 | ||
b33b791e DD |
456 | case OPT_DELETE_EXCLUDED: |
457 | delete_excluded = 1; | |
458 | delete_mode = 1; | |
459 | break; | |
460 | ||
d853783f | 461 | case OPT_EXCLUDE: |
2855f61f | 462 | add_exclude(poptGetOptArg(pc), 0); |
d853783f AT |
463 | break; |
464 | ||
465 | case OPT_INCLUDE: | |
2855f61f | 466 | add_exclude(poptGetOptArg(pc), 1); |
d853783f AT |
467 | break; |
468 | ||
469 | case OPT_EXCLUDE_FROM: | |
2855f61f | 470 | add_exclude_file(poptGetOptArg(pc), 1, 0); |
d853783f AT |
471 | break; |
472 | ||
93695764 DD |
473 | case OPT_INCLUDE_FROM: |
474 | add_exclude_file(poptGetOptArg(pc), 1, 1); | |
475 | break; | |
476 | ||
93689aa5 DD |
477 | case OPT_NO_WHOLE_FILE: |
478 | whole_file = 0; | |
479 | break; | |
480 | ||
481 | case OPT_NO_BLOCKING_IO: | |
482 | blocking_io = 0; | |
d853783f AT |
483 | break; |
484 | ||
485 | case 'h': | |
486 | usage(FINFO); | |
487 | exit_cleanup(0); | |
488 | ||
d853783f | 489 | case 'H': |
7a6421fa | 490 | #if SUPPORT_HARD_LINKS |
d853783f | 491 | preserve_hard_links=1; |
2855f61f MP |
492 | #else |
493 | /* FIXME: Don't say "server" if this is | |
494 | * happening on the client. */ | |
495 | /* FIXME: Why do we have the duplicated | |
496 | * rprintf? Everybody who gets this message | |
497 | * ought to send it to the client and also to | |
498 | * the logs. */ | |
8950ac03 | 499 | snprintf(err_buf,sizeof(err_buf), |
2855f61f MP |
500 | "hard links are not supported on this %s\n", |
501 | am_server ? "server" : "client"); | |
d853783f | 502 | rprintf(FERROR,"ERROR: hard links not supported on this platform\n"); |
b11ed3b1 | 503 | return 0; |
2855f61f | 504 | #endif /* SUPPORT_HARD_LINKS */ |
d853783f | 505 | break; |
7a6421fa | 506 | |
d853783f AT |
507 | case 'v': |
508 | verbose++; | |
509 | break; | |
7a6421fa | 510 | |
b86f0cef DD |
511 | case 'q': |
512 | if (frommain) quiet++; | |
513 | break; | |
514 | ||
d853783f AT |
515 | case 'a': |
516 | recurse=1; | |
7a6421fa | 517 | #if SUPPORT_LINKS |
d853783f | 518 | preserve_links=1; |
7a6421fa | 519 | #endif |
d853783f AT |
520 | preserve_perms=1; |
521 | preserve_times=1; | |
522 | preserve_gid=1; | |
e20c5e95 AT |
523 | preserve_uid=1; |
524 | preserve_devices=1; | |
d853783f AT |
525 | break; |
526 | ||
d853783f AT |
527 | case OPT_SENDER: |
528 | if (!am_server) { | |
529 | usage(FERROR); | |
65417579 | 530 | exit_cleanup(RERR_SYNTAX); |
d853783f AT |
531 | } |
532 | am_sender = 1; | |
533 | break; | |
534 | ||
d9fcc198 AT |
535 | case 'P': |
536 | do_progress = 1; | |
537 | keep_partial = 1; | |
538 | break; | |
539 | ||
088aac85 DD |
540 | case OPT_WRITE_BATCH: |
541 | /* popt stores the filename in batch_prefix for us */ | |
542 | write_batch = 1; | |
543 | break; | |
544 | ||
76f79ba7 | 545 | case OPT_READ_BATCH: |
088aac85 | 546 | /* popt stores the filename in batch_prefix for us */ |
6902ed17 MP |
547 | read_batch = 1; |
548 | break; | |
549 | ||
d853783f | 550 | default: |
2855f61f MP |
551 | /* FIXME: If --daemon is specified, then errors for later |
552 | * parameters seem to disappear. */ | |
8950ac03 | 553 | snprintf(err_buf, sizeof(err_buf), |
2855f61f MP |
554 | "%s%s: %s\n", |
555 | am_server ? "on remote machine: " : "", | |
556 | poptBadOption(pc, POPT_BADOPTION_NOALIAS), | |
557 | poptStrerror(opt)); | |
558 | return 0; | |
d853783f | 559 | } |
7a6421fa | 560 | } |
2855f61f | 561 | |
088aac85 DD |
562 | if (write_batch && read_batch) { |
563 | snprintf(err_buf,sizeof(err_buf), | |
564 | "write-batch and read-batch can not be used together\n"); | |
565 | rprintf(FERROR,"ERROR: write-batch and read-batch" | |
566 | " can not be used together\n"); | |
567 | return 0; | |
568 | } | |
569 | ||
570 | if (do_compression && (write_batch || read_batch)) { | |
571 | snprintf(err_buf,sizeof(err_buf), | |
572 | "compress can not be used with write-batch or read-batch\n"); | |
573 | rprintf(FERROR,"ERROR: compress can not be used with" | |
574 | " write-batch or read-batch\n"); | |
575 | return 0; | |
576 | } | |
577 | ||
2855f61f MP |
578 | *argv = poptGetArgs(pc); |
579 | if (*argv) | |
580 | *argc = count_args(*argv); | |
581 | else | |
582 | *argc = 0; | |
583 | ||
b11ed3b1 | 584 | return 1; |
7a6421fa AT |
585 | } |
586 | ||
587 | ||
2855f61f MP |
588 | /* Construct a filtered list of options to pass through from the |
589 | * client to the server */ | |
7a6421fa AT |
590 | void server_options(char **args,int *argc) |
591 | { | |
d853783f AT |
592 | int ac = *argc; |
593 | static char argstr[50]; | |
594 | static char bsize[30]; | |
595 | static char iotime[30]; | |
0b73ca12 | 596 | static char mdelete[30]; |
5b56cc19 | 597 | static char mwindow[30]; |
ef5d23eb | 598 | static char bw[50]; |
088aac85 DD |
599 | /* Leave room for ``--(write|read)-batch='' */ |
600 | static char fext[MAXPATHLEN + 15]; | |
ef5d23eb | 601 | |
d853783f AT |
602 | int i, x; |
603 | ||
93689aa5 DD |
604 | if (whole_file == -1) |
605 | whole_file = 0; | |
606 | if (blocking_io == -1) | |
607 | blocking_io = 0; | |
608 | ||
d853783f AT |
609 | args[ac++] = "--server"; |
610 | ||
611 | if (!am_sender) | |
612 | args[ac++] = "--sender"; | |
613 | ||
614 | x = 1; | |
615 | argstr[0] = '-'; | |
616 | for (i=0;i<verbose;i++) | |
617 | argstr[x++] = 'v'; | |
f0b36a48 | 618 | |
b86f0cef | 619 | /* the -q option is intentionally left out */ |
d853783f AT |
620 | if (make_backups) |
621 | argstr[x++] = 'b'; | |
622 | if (update_only) | |
623 | argstr[x++] = 'u'; | |
624 | if (dry_run) | |
625 | argstr[x++] = 'n'; | |
626 | if (preserve_links) | |
627 | argstr[x++] = 'l'; | |
628 | if (copy_links) | |
629 | argstr[x++] = 'L'; | |
1bfbf40b MP |
630 | |
631 | assert(whole_file == 0 || whole_file == -1); | |
d853783f AT |
632 | if (whole_file) |
633 | argstr[x++] = 'W'; | |
1bfbf40b | 634 | |
d853783f AT |
635 | if (preserve_hard_links) |
636 | argstr[x++] = 'H'; | |
637 | if (preserve_uid) | |
638 | argstr[x++] = 'o'; | |
639 | if (preserve_gid) | |
640 | argstr[x++] = 'g'; | |
641 | if (preserve_devices) | |
642 | argstr[x++] = 'D'; | |
643 | if (preserve_times) | |
644 | argstr[x++] = 't'; | |
645 | if (preserve_perms) | |
646 | argstr[x++] = 'p'; | |
647 | if (recurse) | |
648 | argstr[x++] = 'r'; | |
649 | if (always_checksum) | |
650 | argstr[x++] = 'c'; | |
651 | if (cvs_exclude) | |
652 | argstr[x++] = 'C'; | |
653 | if (ignore_times) | |
654 | argstr[x++] = 'I'; | |
655 | if (relative_paths) | |
656 | argstr[x++] = 'R'; | |
657 | if (one_file_system) | |
658 | argstr[x++] = 'x'; | |
659 | if (sparse_files) | |
660 | argstr[x++] = 'S'; | |
661 | if (do_compression) | |
662 | argstr[x++] = 'z'; | |
f0b36a48 AT |
663 | |
664 | /* this is a complete hack - blame Rusty | |
665 | ||
666 | this is a hack to make the list_only (remote file list) | |
667 | more useful */ | |
668 | if (list_only && !recurse) | |
669 | argstr[x++] = 'r'; | |
670 | ||
d853783f AT |
671 | argstr[x] = 0; |
672 | ||
673 | if (x != 1) args[ac++] = argstr; | |
674 | ||
675 | if (block_size != BLOCK_SIZE) { | |
8950ac03 | 676 | snprintf(bsize,sizeof(bsize),"-B%d",block_size); |
d853783f AT |
677 | args[ac++] = bsize; |
678 | } | |
679 | ||
0b73ca12 | 680 | if (max_delete && am_sender) { |
8950ac03 | 681 | snprintf(mdelete,sizeof(mdelete),"--max-delete=%d",max_delete); |
0b73ca12 AT |
682 | args[ac++] = mdelete; |
683 | } | |
6902ed17 | 684 | |
088aac85 DD |
685 | if (batch_prefix != NULL) { |
686 | char *fmt = ""; | |
687 | if (write_batch) | |
688 | fmt = "--write-batch=%s"; | |
689 | else | |
690 | if (read_batch) | |
691 | fmt = "--read-batch=%s"; | |
692 | snprintf(fext,sizeof(fext),fmt,batch_prefix); | |
6902ed17 MP |
693 | args[ac++] = fext; |
694 | } | |
0b73ca12 | 695 | |
d853783f | 696 | if (io_timeout) { |
8950ac03 | 697 | snprintf(iotime,sizeof(iotime),"--timeout=%d",io_timeout); |
d853783f AT |
698 | args[ac++] = iotime; |
699 | } | |
700 | ||
ef5d23eb | 701 | if (bwlimit) { |
8950ac03 | 702 | snprintf(bw,sizeof(bw),"--bwlimit=%d",bwlimit); |
ef5d23eb DD |
703 | args[ac++] = bw; |
704 | } | |
705 | ||
d853783f AT |
706 | if (strcmp(backup_suffix, BACKUP_SUFFIX)) { |
707 | args[ac++] = "--suffix"; | |
708 | args[ac++] = backup_suffix; | |
709 | } | |
710 | ||
b33b791e | 711 | if (delete_mode && !delete_excluded) |
d853783f AT |
712 | args[ac++] = "--delete"; |
713 | ||
b33b791e DD |
714 | if (delete_excluded) |
715 | args[ac++] = "--delete-excluded"; | |
716 | ||
f83f0548 AT |
717 | if (size_only) |
718 | args[ac++] = "--size-only"; | |
719 | ||
5b56cc19 | 720 | if (modify_window_set) { |
8950ac03 | 721 | snprintf(mwindow,sizeof(mwindow),"--modify-window=%d", |
5b56cc19 AT |
722 | modify_window); |
723 | args[ac++] = mwindow; | |
724 | } | |
725 | ||
d853783f AT |
726 | if (keep_partial) |
727 | args[ac++] = "--partial"; | |
728 | ||
729 | if (force_delete) | |
730 | args[ac++] = "--force"; | |
731 | ||
57df171b AT |
732 | if (delete_after) |
733 | args[ac++] = "--delete-after"; | |
734 | ||
ef55c686 AT |
735 | if (ignore_errors) |
736 | args[ac++] = "--ignore-errors"; | |
737 | ||
b5313607 DD |
738 | if (copy_unsafe_links) |
739 | args[ac++] = "--copy-unsafe-links"; | |
740 | ||
d853783f AT |
741 | if (safe_symlinks) |
742 | args[ac++] = "--safe-links"; | |
743 | ||
744 | if (numeric_ids) | |
745 | args[ac++] = "--numeric-ids"; | |
746 | ||
0b73ca12 | 747 | if (only_existing && am_sender) |
1347d512 AT |
748 | args[ac++] = "--existing"; |
749 | ||
3d6feada MP |
750 | if (opt_ignore_existing && am_sender) |
751 | args[ac++] = "--ignore-existing"; | |
752 | ||
d853783f AT |
753 | if (tmpdir) { |
754 | args[ac++] = "--temp-dir"; | |
755 | args[ac++] = tmpdir; | |
756 | } | |
757 | ||
66203a98 AT |
758 | if (backup_dir && am_sender) { |
759 | /* only the receiver needs this option, if we are the sender | |
760 | * then we need to send it to the receiver. | |
761 | */ | |
762 | args[ac++] = "--backup-dir"; | |
763 | args[ac++] = backup_dir; | |
764 | } | |
765 | ||
375a4556 DD |
766 | if (compare_dest && am_sender) { |
767 | /* the server only needs this option if it is not the sender, | |
768 | * and it may be an older version that doesn't know this | |
769 | * option, so don't send it if client is the sender. | |
770 | */ | |
771 | args[ac++] = "--compare-dest"; | |
772 | args[ac++] = compare_dest; | |
773 | } | |
774 | ||
d853783f | 775 | *argc = ac; |
7a6421fa AT |
776 | } |
777 |