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