00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "rsync.h"
00022 #include <popt.h>
00023 #include "zlib/zlib.h"
00024
00025 extern int module_id;
00026 extern int sanitize_paths;
00027 extern struct filter_list_struct filter_list;
00028 extern struct filter_list_struct server_filter_list;
00029
00030 int make_backups = 0;
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 int whole_file = -1;
00041
00042 int append_mode = 0;
00043 int keep_dirlinks = 0;
00044 int copy_dirlinks = 0;
00045 int copy_links = 0;
00046 int preserve_links = 0;
00047 int preserve_hard_links = 0;
00048 int preserve_acls = 0;
00049 int preserve_xattrs = 0;
00050 int preserve_perms = 0;
00051 int preserve_executability = 0;
00052 int preserve_devices = 0;
00053 int preserve_specials = 0;
00054 int preserve_uid = 0;
00055 int preserve_gid = 0;
00056 int preserve_times = 0;
00057 int omit_dir_times = 0;
00058 int update_only = 0;
00059 int cvs_exclude = 0;
00060 int dry_run = 0;
00061 int do_xfers = 1;
00062 int ignore_times = 0;
00063 int delete_mode = 0;
00064 int delete_during = 0;
00065 int delete_before = 0;
00066 int delete_after = 0;
00067 int delete_excluded = 0;
00068 int remove_sent_files = 0;
00069 int one_file_system = 0;
00070 int protocol_version = PROTOCOL_VERSION;
00071 int sparse_files = 0;
00072 int do_compression = 0;
00073 int def_compress_level = Z_DEFAULT_COMPRESSION;
00074 int am_root = 0;
00075 int am_server = 0;
00076 int am_sender = 0;
00077 int am_generator = 0;
00078 int am_starting_up = 1;
00079 int relative_paths = -1;
00080 int implied_dirs = 1;
00081 int numeric_ids = 0;
00082 int allow_8bit_chars = 0;
00083 int force_delete = 0;
00084 int io_timeout = 0;
00085 int allowed_lull = 0;
00086 int prune_empty_dirs = 0;
00087 char *files_from = NULL;
00088 int filesfrom_fd = -1;
00089 char *filesfrom_host = NULL;
00090 int eol_nulls = 0;
00091 int human_readable = 0;
00092 int recurse = 0;
00093 int xfer_dirs = -1;
00094 int am_daemon = 0;
00095 int daemon_over_rsh = 0;
00096 int do_stats = 0;
00097 int do_progress = 0;
00098 int keep_partial = 0;
00099 int safe_symlinks = 0;
00100 int copy_unsafe_links = 0;
00101 int size_only = 0;
00102 int daemon_bwlimit = 0;
00103 int bwlimit = 0;
00104 int fuzzy_basis = 0;
00105 size_t bwlimit_writemax = 0;
00106 int ignore_existing = 0;
00107 int ignore_non_existing = 0;
00108 int need_messages_from_generator = 0;
00109 int max_delete = 0;
00110 OFF_T max_size = 0;
00111 OFF_T min_size = 0;
00112 int ignore_errors = 0;
00113 int modify_window = 0;
00114 int blocking_io = -1;
00115 int checksum_seed = 0;
00116 int inplace = 0;
00117 int delay_updates = 0;
00118 long block_size = 0;
00119
00120
00121
00122 #ifdef INET6
00123 int default_af_hint = 0;
00124 #else
00125 int default_af_hint = AF_INET;
00126 #endif
00127
00128
00129
00130
00131 int no_detach
00132 #if defined _WIN32 || defined __WIN32__
00133 = 1;
00134 #else
00135 = 0;
00136 #endif
00137
00138 int write_batch = 0;
00139 int read_batch = 0;
00140 int backup_dir_len = 0;
00141 int backup_suffix_len;
00142 unsigned int backup_dir_remainder;
00143
00144 char *backup_suffix = NULL;
00145 char *tmpdir = NULL;
00146 char *partial_dir = NULL;
00147 char *basis_dir[MAX_BASIS_DIRS+1];
00148 char *config_file = NULL;
00149 char *shell_cmd = NULL;
00150 char *log_format = NULL;
00151 char *password_file = NULL;
00152 char *rsync_path = RSYNC_PATH;
00153 char *backup_dir = NULL;
00154 char backup_dir_buf[MAXPATHLEN];
00155 char *sockopts = NULL;
00156 int rsync_port = 0;
00157 int compare_dest = 0;
00158 int copy_dest = 0;
00159 int link_dest = 0;
00160 int basis_dir_cnt = 0;
00161 char *dest_option = NULL;
00162
00163 int verbose = 0;
00164 int quiet = 0;
00165 int log_before_transfer = 0;
00166 int log_format_has_i = 0;
00167 int log_format_has_o_or_i = 0;
00168 int always_checksum = 0;
00169 int list_only = 0;
00170
00171 #define MAX_BATCH_NAME_LEN 256
00172 char *batch_name = NULL;
00173
00174 struct chmod_mode_struct *chmod_modes = NULL;
00175
00176 static int daemon_opt;
00177 static int F_option_cnt = 0;
00178 static int modify_window_set;
00179 static int itemize_changes = 0;
00180 static int refused_delete, refused_archive_part, refused_compress;
00181 static int refused_partial, refused_progress, refused_delete_before;
00182 static int refused_inplace;
00183 static char *max_size_arg, *min_size_arg;
00184 static char tmp_partialdir[] = ".~tmp~";
00185
00186
00187
00188
00189 char *bind_address;
00190
00191
00192 static void print_rsync_version(enum logcode f)
00193 {
00194 char const *got_socketpair = "no ";
00195 char const *have_inplace = "no ";
00196 char const *hardlinks = "no ";
00197 char const *acls = "no ";
00198 char const *xattrs = "no ";
00199 char const *links = "no ";
00200 char const *ipv6 = "no ";
00201 STRUCT_STAT *dumstat;
00202
00203 #ifdef HAVE_SOCKETPAIR
00204 got_socketpair = "";
00205 #endif
00206
00207 #ifdef HAVE_FTRUNCATE
00208 have_inplace = "";
00209 #endif
00210
00211 #ifdef SUPPORT_HARD_LINKS
00212 hardlinks = "";
00213 #endif
00214
00215 #ifdef SUPPORT_ACLS
00216 acls = "";
00217 #endif
00218 #ifdef SUPPORT_XATTRS
00219 xattrs = "";
00220 #endif
00221 #ifdef SUPPORT_LINKS
00222 links = "";
00223 #endif
00224
00225 #ifdef INET6
00226 ipv6 = "";
00227 #endif
00228
00229 rprintf(f, "%s version %s protocol version %d\n",
00230 RSYNC_NAME, RSYNC_VERSION, PROTOCOL_VERSION);
00231 rprintf(f, "Copyright (C) 1996-2006 by Andrew Tridgell, Wayne Davison, and others.\n");
00232 rprintf(f, "<http://rsync.samba.org/>\n");
00233 rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, "
00234 "%shard links, %sACLs, %sxattrs, %ssymlinks, batchfiles,\n",
00235 (int) (sizeof (OFF_T) * 8),
00236 got_socketpair, hardlinks, acls, xattrs, links);
00237
00238
00239
00240
00241 rprintf(f, " %sinplace, %sIPv6, "
00242 "%d-bit system inums, %d-bit internal inums\n",
00243 have_inplace, ipv6,
00244 (int) (sizeof dumstat->st_ino * 8),
00245 (int) (sizeof (int64) * 8));
00246 #ifdef MAINTAINER_MODE
00247 rprintf(f, "Panic Action: \"%s\"\n", get_panic_action());
00248 #endif
00249
00250 #if SIZEOF_INT64 < 8
00251 rprintf(f, "WARNING: no 64-bit integers on this platform!\n");
00252 #endif
00253 if (sizeof (int64) != SIZEOF_INT64) {
00254 rprintf(f,
00255 "WARNING: size mismatch in SIZEOF_INT64 define (%d != %d)\n",
00256 (int) SIZEOF_INT64, (int) sizeof (int64));
00257 }
00258
00259 rprintf(f,"\nrsync comes with ABSOLUTELY NO WARRANTY. This is free software, and you\n");
00260 rprintf(f,"are welcome to redistribute it under certain conditions. See the GNU\n");
00261 rprintf(f,"General Public Licence for details.\n");
00262 }
00263
00264
00265 void usage(enum logcode F)
00266 {
00267 print_rsync_version(F);
00268
00269 rprintf(F,"\nrsync is a file transfer program capable of efficient remote update\n");
00270 rprintf(F,"via a fast differencing algorithm.\n");
00271
00272 rprintf(F,"\nUsage: rsync [OPTION]... SRC [SRC]... DEST\n");
00273 rprintf(F," or rsync [OPTION]... SRC [SRC]... [USER@]HOST:DEST\n");
00274 rprintf(F," or rsync [OPTION]... SRC [SRC]... [USER@]HOST::DEST\n");
00275 rprintf(F," or rsync [OPTION]... SRC [SRC]... rsync://[USER@]HOST[:PORT]/DEST\n");
00276 rprintf(F," or rsync [OPTION]... [USER@]HOST:SRC [DEST]\n");
00277 rprintf(F," or rsync [OPTION]... [USER@]HOST::SRC [DEST]\n");
00278 rprintf(F," or rsync [OPTION]... rsync://[USER@]HOST[:PORT]/SRC [DEST]\n");
00279 rprintf(F,"The ':' usages connect via remote shell, while '::' & 'rsync://' usages connect\n");
00280 rprintf(F,"to an rsync daemon, and require SRC or DEST to start with a module name.\n");
00281 rprintf(F,"\nOptions\n");
00282 rprintf(F," -v, --verbose increase verbosity\n");
00283 rprintf(F," -q, --quiet suppress non-error messages\n");
00284 rprintf(F," -c, --checksum skip based on checksum, not mod-time & size\n");
00285 rprintf(F," -a, --archive archive mode; same as -rlptgoD (no -H)\n");
00286 rprintf(F," --no-OPTION turn off an implied OPTION (e.g. --no-D)\n");
00287 rprintf(F," -r, --recursive recurse into directories\n");
00288 rprintf(F," -R, --relative use relative path names\n");
00289 rprintf(F," --no-implied-dirs don't send implied dirs with --relative\n");
00290 rprintf(F," -b, --backup make backups (see --suffix & --backup-dir)\n");
00291 rprintf(F," --backup-dir=DIR make backups into hierarchy based in DIR\n");
00292 rprintf(F," --suffix=SUFFIX set backup suffix (default %s w/o --backup-dir)\n",BACKUP_SUFFIX);
00293 rprintf(F," -u, --update skip files that are newer on the receiver\n");
00294 rprintf(F," --inplace update destination files in-place (SEE MAN PAGE)\n");
00295 rprintf(F," --append append data onto shorter files\n");
00296 rprintf(F," -d, --dirs transfer directories without recursing\n");
00297 rprintf(F," -l, --links copy symlinks as symlinks\n");
00298 rprintf(F," -L, --copy-links transform symlink into referent file/dir\n");
00299 rprintf(F," --copy-unsafe-links only \"unsafe\" symlinks are transformed\n");
00300 rprintf(F," --safe-links ignore symlinks that point outside the source tree\n");
00301 rprintf(F," -k, --copy-dirlinks transform symlink to a dir into referent dir\n");
00302 rprintf(F," -K, --keep-dirlinks treat symlinked dir on receiver as dir\n");
00303 rprintf(F," -H, --hard-links preserve hard links\n");
00304 rprintf(F," -p, --perms preserve permissions\n");
00305 rprintf(F," -E, --executability preserve the file's executability\n");
00306 #ifdef SUPPORT_ACLS
00307 rprintf(F," -A, --acls preserve ACLs (implies --perms)\n");
00308 #endif
00309 #ifdef SUPPORT_XATTRS
00310 rprintf(F," -X, --xattrs preserve extended attributes (implies --perms)\n");
00311 #endif
00312 rprintf(F," --chmod=CHMOD change destination permissions\n");
00313 rprintf(F," -o, --owner preserve owner (super-user only)\n");
00314 rprintf(F," -g, --group preserve group\n");
00315 rprintf(F," --devices preserve device files (super-user only)\n");
00316 rprintf(F," --specials preserve special files\n");
00317 rprintf(F," -D same as --devices --specials\n");
00318 rprintf(F," -t, --times preserve times\n");
00319 rprintf(F," -O, --omit-dir-times omit directories when preserving times\n");
00320 rprintf(F," --super receiver attempts super-user activities\n");
00321 rprintf(F," -S, --sparse handle sparse files efficiently\n");
00322 rprintf(F," -n, --dry-run show what would have been transferred\n");
00323 rprintf(F," -W, --whole-file copy files whole (without rsync algorithm)\n");
00324 rprintf(F," -x, --one-file-system don't cross filesystem boundaries\n");
00325 rprintf(F," -B, --block-size=SIZE force a fixed checksum block-size\n");
00326 rprintf(F," -e, --rsh=COMMAND specify the remote shell to use\n");
00327 rprintf(F," --rsync-path=PROGRAM specify the rsync to run on the remote machine\n");
00328 rprintf(F," --existing ignore non-existing files on receiving side\n");
00329 rprintf(F," --ignore-existing ignore files that already exist on receiving side\n");
00330 rprintf(F," --remove-sent-files sent files/symlinks are removed from sending side\n");
00331 rprintf(F," --del an alias for --delete-during\n");
00332 rprintf(F," --delete delete files that don't exist on the sending side\n");
00333 rprintf(F," --delete-before receiver deletes before transfer (default)\n");
00334 rprintf(F," --delete-during receiver deletes during transfer, not before\n");
00335 rprintf(F," --delete-after receiver deletes after transfer, not before\n");
00336 rprintf(F," --delete-excluded also delete excluded files on the receiving side\n");
00337 rprintf(F," --ignore-errors delete even if there are I/O errors\n");
00338 rprintf(F," --force force deletion of directories even if not empty\n");
00339 rprintf(F," --max-delete=NUM don't delete more than NUM files\n");
00340 rprintf(F," --max-size=SIZE don't transfer any file larger than SIZE\n");
00341 rprintf(F," --min-size=SIZE don't transfer any file smaller than SIZE\n");
00342 rprintf(F," --partial keep partially transferred files\n");
00343 rprintf(F," --partial-dir=DIR put a partially transferred file into DIR\n");
00344 rprintf(F," --delay-updates put all updated files into place at transfer's end\n");
00345 rprintf(F," -m, --prune-empty-dirs prune empty directory chains from the file-list\n");
00346 rprintf(F," --numeric-ids don't map uid/gid values by user/group name\n");
00347 rprintf(F," --timeout=TIME set I/O timeout in seconds\n");
00348 rprintf(F," -I, --ignore-times don't skip files that match in size and mod-time\n");
00349 rprintf(F," --size-only skip files that match in size\n");
00350 rprintf(F," --modify-window=NUM compare mod-times with reduced accuracy\n");
00351 rprintf(F," -T, --temp-dir=DIR create temporary files in directory DIR\n");
00352 rprintf(F," -y, --fuzzy find similar file for basis if no dest file\n");
00353 rprintf(F," --compare-dest=DIR also compare destination files relative to DIR\n");
00354 rprintf(F," --copy-dest=DIR ... and include copies of unchanged files\n");
00355 rprintf(F," --link-dest=DIR hardlink to files in DIR when unchanged\n");
00356 rprintf(F," -z, --compress compress file data during the transfer\n");
00357 rprintf(F," --compress-level=NUM explicitly set compression level\n");
00358 rprintf(F," -C, --cvs-exclude auto-ignore files the same way CVS does\n");
00359 rprintf(F," -f, --filter=RULE add a file-filtering RULE\n");
00360 rprintf(F," -F same as --filter='dir-merge /.rsync-filter'\n");
00361 rprintf(F," repeated: --filter='- .rsync-filter'\n");
00362 rprintf(F," --exclude=PATTERN exclude files matching PATTERN\n");
00363 rprintf(F," --exclude-from=FILE read exclude patterns from FILE\n");
00364 rprintf(F," --include=PATTERN don't exclude files matching PATTERN\n");
00365 rprintf(F," --include-from=FILE read include patterns from FILE\n");
00366 rprintf(F," --files-from=FILE read list of source-file names from FILE\n");
00367 rprintf(F," -0, --from0 all *-from/filter files are delimited by 0s\n");
00368 rprintf(F," --address=ADDRESS bind address for outgoing socket to daemon\n");
00369 rprintf(F," --port=PORT specify double-colon alternate port number\n");
00370 rprintf(F," --sockopts=OPTIONS specify custom TCP options\n");
00371 rprintf(F," --blocking-io use blocking I/O for the remote shell\n");
00372 rprintf(F," --stats give some file-transfer stats\n");
00373 rprintf(F," -8, --8-bit-output leave high-bit chars unescaped in output\n");
00374 rprintf(F," -h, --human-readable output numbers in a human-readable format\n");
00375 rprintf(F," --progress show progress during transfer\n");
00376 rprintf(F," -P same as --partial --progress\n");
00377 rprintf(F," -i, --itemize-changes output a change-summary for all updates\n");
00378 rprintf(F," --log-format=FORMAT output filenames using the specified format\n");
00379 rprintf(F," --password-file=FILE read password from FILE\n");
00380 rprintf(F," --list-only list the files instead of copying them\n");
00381 rprintf(F," --bwlimit=KBPS limit I/O bandwidth; KBytes per second\n");
00382 rprintf(F," --write-batch=FILE write a batched update to FILE\n");
00383 rprintf(F," --only-write-batch=FILE like --write-batch but w/o updating destination\n");
00384 rprintf(F," --read-batch=FILE read a batched update from FILE\n");
00385 rprintf(F," --protocol=NUM force an older protocol version to be used\n");
00386 #ifdef INET6
00387 rprintf(F," -4, --ipv4 prefer IPv4\n");
00388 rprintf(F," -6, --ipv6 prefer IPv6\n");
00389 #endif
00390 rprintf(F," --version print version number\n");
00391 rprintf(F,"(-h) --help show this help (-h works with no other options)\n");
00392
00393 rprintf(F,"\nUse \"rsync --daemon --help\" to see the daemon-mode command-line options.\n");
00394 rprintf(F,"Please see the rsync(1) and rsyncd.conf(5) man pages for full documentation.\n");
00395 rprintf(F,"See http://rsync.samba.org/ for updates, bug reports, and answers\n");
00396 }
00397
00398 enum {OPT_VERSION = 1000, OPT_DAEMON, OPT_SENDER, OPT_EXCLUDE, OPT_EXCLUDE_FROM,
00399 OPT_FILTER, OPT_COMPARE_DEST, OPT_COPY_DEST, OPT_LINK_DEST, OPT_HELP,
00400 OPT_INCLUDE, OPT_INCLUDE_FROM, OPT_MODIFY_WINDOW, OPT_MIN_SIZE, OPT_CHMOD,
00401 OPT_READ_BATCH, OPT_WRITE_BATCH, OPT_ONLY_WRITE_BATCH, OPT_MAX_SIZE,
00402 OPT_NO_D,
00403 OPT_SERVER, OPT_REFUSED_BASE = 9000};
00404
00405 static struct poptOption long_options[] = {
00406
00407 {"help", 0, POPT_ARG_NONE, 0, OPT_HELP, 0, 0 },
00408 {"version", 0, POPT_ARG_NONE, 0, OPT_VERSION, 0, 0},
00409 {"verbose", 'v', POPT_ARG_NONE, 0, 'v', 0, 0 },
00410 {"no-verbose", 0, POPT_ARG_VAL, &verbose, 0, 0, 0 },
00411 {"no-v", 0, POPT_ARG_VAL, &verbose, 0, 0, 0 },
00412 {"quiet", 'q', POPT_ARG_NONE, 0, 'q', 0, 0 },
00413 {"stats", 0, POPT_ARG_NONE, &do_stats, 0, 0, 0 },
00414 {"human-readable", 'h', POPT_ARG_NONE, 0, 'h', 0, 0},
00415 {"dry-run", 'n', POPT_ARG_NONE, &dry_run, 0, 0, 0 },
00416 {"archive", 'a', POPT_ARG_NONE, 0, 'a', 0, 0 },
00417 {"recursive", 'r', POPT_ARG_VAL, &recurse, 2, 0, 0 },
00418 {"no-recursive", 0, POPT_ARG_VAL, &recurse, 0, 0, 0 },
00419 {"no-r", 0, POPT_ARG_VAL, &recurse, 0, 0, 0 },
00420 {"dirs", 'd', POPT_ARG_VAL, &xfer_dirs, 2, 0, 0 },
00421 {"no-dirs", 0, POPT_ARG_VAL, &xfer_dirs, 0, 0, 0 },
00422 {"no-d", 0, POPT_ARG_VAL, &xfer_dirs, 0, 0, 0 },
00423 {"perms", 'p', POPT_ARG_VAL, &preserve_perms, 1, 0, 0 },
00424 {"no-perms", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
00425 {"no-p", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
00426 {"executability", 'E', POPT_ARG_NONE, &preserve_executability, 0, 0, 0 },
00427 {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 },
00428 {"no-acls", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
00429 {"no-A", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
00430 {"xattrs", 'X', POPT_ARG_NONE, 0, 'X', 0, 0 },
00431 {"no-xattrs", 0, POPT_ARG_VAL, &preserve_xattrs, 0, 0, 0 },
00432 {"no-X", 0, POPT_ARG_VAL, &preserve_xattrs, 0, 0, 0 },
00433 {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
00434 {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
00435 {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
00436 {"omit-dir-times", 'O', POPT_ARG_VAL, &omit_dir_times, 2, 0, 0 },
00437 {"modify-window", 0, POPT_ARG_INT, &modify_window, OPT_MODIFY_WINDOW, 0, 0 },
00438 {"super", 0, POPT_ARG_VAL, &am_root, 2, 0, 0 },
00439 {"no-super", 0, POPT_ARG_VAL, &am_root, 0, 0, 0 },
00440 {"owner", 'o', POPT_ARG_VAL, &preserve_uid, 1, 0, 0 },
00441 {"no-owner", 0, POPT_ARG_VAL, &preserve_uid, 0, 0, 0 },
00442 {"no-o", 0, POPT_ARG_VAL, &preserve_uid, 0, 0, 0 },
00443 {"group", 'g', POPT_ARG_VAL, &preserve_gid, 1, 0, 0 },
00444 {"no-group", 0, POPT_ARG_VAL, &preserve_gid, 0, 0, 0 },
00445 {"no-g", 0, POPT_ARG_VAL, &preserve_gid, 0, 0, 0 },
00446 {0, 'D', POPT_ARG_NONE, 0, 'D', 0, 0 },
00447 {"no-D", 0, POPT_ARG_NONE, 0, OPT_NO_D, 0, 0 },
00448 {"devices", 0, POPT_ARG_VAL, &preserve_devices, 1, 0, 0 },
00449 {"no-devices", 0, POPT_ARG_VAL, &preserve_devices, 0, 0, 0 },
00450 {"specials", 0, POPT_ARG_VAL, &preserve_specials, 1, 0, 0 },
00451 {"no-specials", 0, POPT_ARG_VAL, &preserve_specials, 0, 0, 0 },
00452 {"links", 'l', POPT_ARG_VAL, &preserve_links, 1, 0, 0 },
00453 {"no-links", 0, POPT_ARG_VAL, &preserve_links, 0, 0, 0 },
00454 {"no-l", 0, POPT_ARG_VAL, &preserve_links, 0, 0, 0 },
00455 {"copy-links", 'L', POPT_ARG_NONE, ©_links, 0, 0, 0 },
00456 {"copy-unsafe-links",0, POPT_ARG_NONE, ©_unsafe_links, 0, 0, 0 },
00457 {"safe-links", 0, POPT_ARG_NONE, &safe_symlinks, 0, 0, 0 },
00458 {"copy-dirlinks", 'k', POPT_ARG_NONE, ©_dirlinks, 0, 0, 0 },
00459 {"keep-dirlinks", 'K', POPT_ARG_NONE, &keep_dirlinks, 0, 0, 0 },
00460 {"hard-links", 'H', POPT_ARG_VAL, &preserve_hard_links, 1, 0, 0 },
00461 {"no-hard-links", 0, POPT_ARG_VAL, &preserve_hard_links, 0, 0, 0 },
00462 {"no-H", 0, POPT_ARG_VAL, &preserve_hard_links, 0, 0, 0 },
00463 {"relative", 'R', POPT_ARG_VAL, &relative_paths, 1, 0, 0 },
00464 {"no-relative", 0, POPT_ARG_VAL, &relative_paths, 0, 0, 0 },
00465 {"no-R", 0, POPT_ARG_VAL, &relative_paths, 0, 0, 0 },
00466 {"implied-dirs", 0, POPT_ARG_VAL, &implied_dirs, 1, 0, 0 },
00467 {"no-implied-dirs", 0, POPT_ARG_VAL, &implied_dirs, 0, 0, 0 },
00468 {"chmod", 0, POPT_ARG_STRING, 0, OPT_CHMOD, 0, 0 },
00469 {"ignore-times", 'I', POPT_ARG_NONE, &ignore_times, 0, 0, 0 },
00470 {"size-only", 0, POPT_ARG_NONE, &size_only, 0, 0, 0 },
00471 {"one-file-system", 'x', POPT_ARG_NONE, 0, 'x', 0, 0 },
00472 {"update", 'u', POPT_ARG_NONE, &update_only, 0, 0, 0 },
00473 {"existing", 0, POPT_ARG_NONE, &ignore_non_existing, 0, 0, 0 },
00474 {"ignore-non-existing",0,POPT_ARG_NONE, &ignore_non_existing, 0, 0, 0 },
00475 {"ignore-existing", 0, POPT_ARG_NONE, &ignore_existing, 0, 0, 0 },
00476 {"max-size", 0, POPT_ARG_STRING, &max_size_arg, OPT_MAX_SIZE, 0, 0 },
00477 {"min-size", 0, POPT_ARG_STRING, &min_size_arg, OPT_MIN_SIZE, 0, 0 },
00478 {"sparse", 'S', POPT_ARG_NONE, &sparse_files, 0, 0, 0 },
00479 {"inplace", 0, POPT_ARG_NONE, &inplace, 0, 0, 0 },
00480 {"append", 0, POPT_ARG_VAL, &append_mode, 1, 0, 0 },
00481 {"del", 0, POPT_ARG_NONE, &delete_during, 0, 0, 0 },
00482 {"delete", 0, POPT_ARG_NONE, &delete_mode, 0, 0, 0 },
00483 {"delete-before", 0, POPT_ARG_VAL, &delete_before, 2, 0, 0 },
00484 {"delete-during", 0, POPT_ARG_NONE, &delete_during, 0, 0, 0 },
00485 {"delete-after", 0, POPT_ARG_NONE, &delete_after, 0, 0, 0 },
00486 {"delete-excluded", 0, POPT_ARG_NONE, &delete_excluded, 0, 0, 0 },
00487 {"remove-sent-files",0, POPT_ARG_NONE, &remove_sent_files, 0, 0, 0 },
00488 {"force", 0, POPT_ARG_NONE, &force_delete, 0, 0, 0 },
00489 {"ignore-errors", 0, POPT_ARG_NONE, &ignore_errors, 0, 0, 0 },
00490 {"max-delete", 0, POPT_ARG_INT, &max_delete, 0, 0, 0 },
00491 {0, 'F', POPT_ARG_NONE, 0, 'F', 0, 0 },
00492 {"filter", 'f', POPT_ARG_STRING, 0, OPT_FILTER, 0, 0 },
00493 {"exclude", 0, POPT_ARG_STRING, 0, OPT_EXCLUDE, 0, 0 },
00494 {"include", 0, POPT_ARG_STRING, 0, OPT_INCLUDE, 0, 0 },
00495 {"exclude-from", 0, POPT_ARG_STRING, 0, OPT_EXCLUDE_FROM, 0, 0 },
00496 {"include-from", 0, POPT_ARG_STRING, 0, OPT_INCLUDE_FROM, 0, 0 },
00497 {"cvs-exclude", 'C', POPT_ARG_NONE, &cvs_exclude, 0, 0, 0 },
00498 {"whole-file", 'W', POPT_ARG_VAL, &whole_file, 1, 0, 0 },
00499 {"no-whole-file", 0, POPT_ARG_VAL, &whole_file, 0, 0, 0 },
00500 {"no-W", 0, POPT_ARG_VAL, &whole_file, 0, 0, 0 },
00501 {"checksum", 'c', POPT_ARG_NONE, &always_checksum, 0, 0, 0 },
00502 {"block-size", 'B', POPT_ARG_LONG, &block_size, 0, 0, 0 },
00503 {"compare-dest", 0, POPT_ARG_STRING, 0, OPT_COMPARE_DEST, 0, 0 },
00504 {"copy-dest", 0, POPT_ARG_STRING, 0, OPT_COPY_DEST, 0, 0 },
00505 {"link-dest", 0, POPT_ARG_STRING, 0, OPT_LINK_DEST, 0, 0 },
00506 {"fuzzy", 'y', POPT_ARG_NONE, &fuzzy_basis, 0, 0, 0 },
00507 {"compress", 'z', POPT_ARG_NONE, 0, 'z', 0, 0 },
00508 {"compress-level", 0, POPT_ARG_INT, &def_compress_level, 'z', 0, 0 },
00509 {0, 'P', POPT_ARG_NONE, 0, 'P', 0, 0 },
00510 {"progress", 0, POPT_ARG_VAL, &do_progress, 1, 0, 0 },
00511 {"no-progress", 0, POPT_ARG_VAL, &do_progress, 0, 0, 0 },
00512 {"partial", 0, POPT_ARG_VAL, &keep_partial, 1, 0, 0 },
00513 {"no-partial", 0, POPT_ARG_VAL, &keep_partial, 0, 0, 0 },
00514 {"partial-dir", 0, POPT_ARG_STRING, &partial_dir, 0, 0, 0 },
00515 {"delay-updates", 0, POPT_ARG_NONE, &delay_updates, 0, 0, 0 },
00516 {"prune-empty-dirs",'m', POPT_ARG_NONE, &prune_empty_dirs, 0, 0, 0 },
00517 {"log-format", 0, POPT_ARG_STRING, &log_format, 0, 0, 0 },
00518 {"itemize-changes", 'i', POPT_ARG_NONE, 0, 'i', 0, 0 },
00519 {"bwlimit", 0, POPT_ARG_INT, &bwlimit, 0, 0, 0 },
00520 {"backup", 'b', POPT_ARG_NONE, &make_backups, 0, 0, 0 },
00521 {"backup-dir", 0, POPT_ARG_STRING, &backup_dir, 0, 0, 0 },
00522 {"suffix", 0, POPT_ARG_STRING, &backup_suffix, 0, 0, 0 },
00523 {"list-only", 0, POPT_ARG_VAL, &list_only, 2, 0, 0 },
00524 {"read-batch", 0, POPT_ARG_STRING, &batch_name, OPT_READ_BATCH, 0, 0 },
00525 {"write-batch", 0, POPT_ARG_STRING, &batch_name, OPT_WRITE_BATCH, 0, 0 },
00526 {"only-write-batch", 0, POPT_ARG_STRING, &batch_name, OPT_ONLY_WRITE_BATCH, 0, 0 },
00527 {"files-from", 0, POPT_ARG_STRING, &files_from, 0, 0, 0 },
00528 {"from0", '0', POPT_ARG_NONE, &eol_nulls, 0, 0, 0},
00529 {"numeric-ids", 0, POPT_ARG_NONE, &numeric_ids, 0, 0, 0 },
00530 {"timeout", 0, POPT_ARG_INT, &io_timeout, 0, 0, 0 },
00531 {"rsh", 'e', POPT_ARG_STRING, &shell_cmd, 0, 0, 0 },
00532 {"rsync-path", 0, POPT_ARG_STRING, &rsync_path, 0, 0, 0 },
00533 {"temp-dir", 'T', POPT_ARG_STRING, &tmpdir, 0, 0, 0 },
00534 #ifdef INET6
00535 {"ipv4", '4', POPT_ARG_VAL, &default_af_hint, AF_INET, 0, 0 },
00536 {"ipv6", '6', POPT_ARG_VAL, &default_af_hint, AF_INET6, 0, 0 },
00537 #endif
00538 {"8-bit-output", '8', POPT_ARG_NONE, &allow_8bit_chars, 0, 0, 0 },
00539 {"address", 0, POPT_ARG_STRING, &bind_address, 0, 0, 0 },
00540 {"port", 0, POPT_ARG_INT, &rsync_port, 0, 0, 0 },
00541 {"sockopts", 0, POPT_ARG_STRING, &sockopts, 0, 0, 0 },
00542 {"password-file", 0, POPT_ARG_STRING, &password_file, 0, 0, 0 },
00543 {"blocking-io", 0, POPT_ARG_VAL, &blocking_io, 1, 0, 0 },
00544 {"no-blocking-io", 0, POPT_ARG_VAL, &blocking_io, 0, 0, 0 },
00545 {"protocol", 0, POPT_ARG_INT, &protocol_version, 0, 0, 0 },
00546 {"checksum-seed", 0, POPT_ARG_INT, &checksum_seed, 0, 0, 0 },
00547 {"server", 0, POPT_ARG_NONE, 0, OPT_SERVER, 0, 0 },
00548 {"sender", 0, POPT_ARG_NONE, 0, OPT_SENDER, 0, 0 },
00549
00550 {"config", 0, POPT_ARG_STRING, 0, OPT_DAEMON, 0, 0 },
00551 {"daemon", 0, POPT_ARG_NONE, 0, OPT_DAEMON, 0, 0 },
00552 {"detach", 0, POPT_ARG_NONE, 0, OPT_DAEMON, 0, 0 },
00553 {"no-detach", 0, POPT_ARG_NONE, 0, OPT_DAEMON, 0, 0 },
00554 {0,0,0,0, 0, 0, 0}
00555 };
00556
00557 static void daemon_usage(enum logcode F)
00558 {
00559 print_rsync_version(F);
00560
00561 rprintf(F,"\nUsage: rsync --daemon [OPTION]...\n");
00562 rprintf(F," --address=ADDRESS bind to the specified address\n");
00563 rprintf(F," --bwlimit=KBPS limit I/O bandwidth; KBytes per second\n");
00564 rprintf(F," --config=FILE specify alternate rsyncd.conf file\n");
00565 rprintf(F," --no-detach do not detach from the parent\n");
00566 rprintf(F," --port=PORT listen on alternate port number\n");
00567 rprintf(F," --sockopts=OPTIONS specify custom TCP options\n");
00568 rprintf(F," -v, --verbose increase verbosity\n");
00569 #ifdef INET6
00570 rprintf(F," -4, --ipv4 prefer IPv4\n");
00571 rprintf(F," -6, --ipv6 prefer IPv6\n");
00572 #endif
00573 rprintf(F," --help show this help screen\n");
00574
00575 rprintf(F,"\nIf you were not trying to invoke rsync as a daemon, avoid using any of the\n");
00576 rprintf(F,"daemon-specific rsync options. See also the rsyncd.conf(5) man page.\n");
00577 }
00578
00579 static struct poptOption long_daemon_options[] = {
00580
00581 {"address", 0, POPT_ARG_STRING, &bind_address, 0, 0, 0 },
00582 {"bwlimit", 0, POPT_ARG_INT, &daemon_bwlimit, 0, 0, 0 },
00583 {"config", 0, POPT_ARG_STRING, &config_file, 0, 0, 0 },
00584 {"daemon", 0, POPT_ARG_NONE, &daemon_opt, 0, 0, 0 },
00585 #ifdef INET6
00586 {"ipv4", '4', POPT_ARG_VAL, &default_af_hint, AF_INET, 0, 0 },
00587 {"ipv6", '6', POPT_ARG_VAL, &default_af_hint, AF_INET6, 0, 0 },
00588 #endif
00589 {"detach", 0, POPT_ARG_VAL, &no_detach, 0, 0, 0 },
00590 {"no-detach", 0, POPT_ARG_VAL, &no_detach, 1, 0, 0 },
00591 {"port", 0, POPT_ARG_INT, &rsync_port, 0, 0, 0 },
00592 {"sockopts", 0, POPT_ARG_STRING, &sockopts, 0, 0, 0 },
00593 {"protocol", 0, POPT_ARG_INT, &protocol_version, 0, 0, 0 },
00594 {"server", 0, POPT_ARG_NONE, &am_server, 0, 0, 0 },
00595 {"temp-dir", 'T', POPT_ARG_STRING, &tmpdir, 0, 0, 0 },
00596 {"verbose", 'v', POPT_ARG_NONE, 0, 'v', 0, 0 },
00597 {"no-verbose", 0, POPT_ARG_VAL, &verbose, 0, 0, 0 },
00598 {"no-v", 0, POPT_ARG_VAL, &verbose, 0, 0, 0 },
00599 {"help", 'h', POPT_ARG_NONE, 0, 'h', 0, 0 },
00600 {0,0,0,0, 0, 0, 0}
00601 };
00602
00603
00604 static char err_buf[200];
00605
00606
00607
00608
00609
00610
00611
00612 void option_error(void)
00613 {
00614 if (!err_buf[0]) {
00615 strcpy(err_buf, "Error parsing options: "
00616 "option may be supported on client but not on server?\n");
00617 }
00618
00619 rprintf(FERROR, RSYNC_NAME ": %s", err_buf);
00620 msleep(20);
00621 }
00622
00623
00624
00625
00626
00627
00628 static void set_refuse_options(char *bp)
00629 {
00630 struct poptOption *op;
00631 char *cp, shortname[2];
00632 int is_wild, found_match;
00633
00634 shortname[1] = '\0';
00635
00636 while (1) {
00637 while (*bp == ' ') bp++;
00638 if (!*bp)
00639 break;
00640 if ((cp = strchr(bp, ' ')) != NULL)
00641 *cp= '\0';
00642 is_wild = strpbrk(bp, "*?[") != NULL;
00643 found_match = 0;
00644 for (op = long_options; ; op++) {
00645 *shortname = op->shortName;
00646 if (!op->longName && !*shortname)
00647 break;
00648 if ((op->longName && wildmatch(bp, op->longName))
00649 || (*shortname && wildmatch(bp, shortname))) {
00650 if (op->argInfo == POPT_ARG_VAL)
00651 op->argInfo = POPT_ARG_NONE;
00652 op->val = (op - long_options) + OPT_REFUSED_BASE;
00653 found_match = 1;
00654
00655
00656 switch (*shortname) {
00657 case 'r': case 'd': case 'l': case 'p':
00658 case 't': case 'g': case 'o': case 'D':
00659 refused_archive_part = op->val;
00660 break;
00661 case 'z':
00662 refused_compress = op->val;
00663 break;
00664 case '\0':
00665 if (wildmatch("delete", op->longName))
00666 refused_delete = op->val;
00667 else if (wildmatch("delete-before", op->longName))
00668 refused_delete_before = op->val;
00669 else if (wildmatch("partial", op->longName))
00670 refused_partial = op->val;
00671 else if (wildmatch("progress", op->longName))
00672 refused_progress = op->val;
00673 else if (wildmatch("inplace", op->longName))
00674 refused_inplace = op->val;
00675 break;
00676 }
00677 if (!is_wild)
00678 break;
00679 }
00680 }
00681 if (!found_match) {
00682 rprintf(FLOG, "No match for refuse-options string \"%s\"\n",
00683 bp);
00684 }
00685 if (!cp)
00686 break;
00687 *cp = ' ';
00688 bp = cp + 1;
00689 }
00690
00691 for (op = long_options; ; op++) {
00692 *shortname = op->shortName;
00693 if (!op->longName && !*shortname)
00694 break;
00695 if (op->val == OPT_DAEMON) {
00696 if (op->argInfo == POPT_ARG_VAL)
00697 op->argInfo = POPT_ARG_NONE;
00698 op->val = (op - long_options) + OPT_REFUSED_BASE;
00699 }
00700 }
00701 }
00702
00703
00704 static int count_args(const char **argv)
00705 {
00706 int i = 0;
00707
00708 if (argv) {
00709 while (argv[i] != NULL)
00710 i++;
00711 }
00712
00713 return i;
00714 }
00715
00716
00717 static OFF_T parse_size_arg(char **size_arg, char def_suf)
00718 {
00719 int reps, mult, make_compatible = 0;
00720 const char *arg;
00721 OFF_T size = 1;
00722
00723 for (arg = *size_arg; isdigit(*(uchar*)arg); arg++) {}
00724 if (*arg == '.')
00725 for (arg++; isdigit(*(uchar*)arg); arg++) {}
00726 switch (*arg && *arg != '+' && *arg != '-' ? *arg++ : def_suf) {
00727 case 'b': case 'B':
00728 reps = 0;
00729 break;
00730 case 'k': case 'K':
00731 reps = 1;
00732 break;
00733 case 'm': case 'M':
00734 reps = 2;
00735 break;
00736 case 'g': case 'G':
00737 reps = 3;
00738 break;
00739 default:
00740 return -1;
00741 }
00742 if (*arg == 'b' || *arg == 'B')
00743 mult = 1000, make_compatible = 1, arg++;
00744 else if (!*arg || *arg == '+' || *arg == '-')
00745 mult = 1024;
00746 else if (strncasecmp(arg, "ib", 2) == 0)
00747 mult = 1024, arg += 2;
00748 else
00749 return -1;
00750 while (reps--)
00751 size *= mult;
00752 size *= atof(*size_arg);
00753 if ((*arg == '+' || *arg == '-') && arg[1] == '1')
00754 size += atoi(arg), make_compatible = 1, arg += 2;
00755 if (*arg)
00756 return -1;
00757 if (size > 0 && make_compatible) {
00758
00759
00760 char buf[128], *s = buf + sizeof buf - 1;
00761 OFF_T num = size;
00762 *s = '\0';
00763 while (num) {
00764 *--s = (num % 10) + '0';
00765 num /= 10;
00766 }
00767 if (!(*size_arg = strdup(s)))
00768 out_of_memory("parse_size_arg");
00769 }
00770 return size;
00771 }
00772
00773
00774 static void create_refuse_error(int which)
00775 {
00776
00777 struct poptOption *op = &long_options[which - OPT_REFUSED_BASE];
00778 int n = snprintf(err_buf, sizeof err_buf,
00779 "The server is configured to refuse --%s\n",
00780 op->longName) - 1;
00781 if (op->shortName) {
00782 snprintf(err_buf + n, sizeof err_buf - n,
00783 " (-%c)\n", op->shortName);
00784 }
00785 }
00786
00787
00788
00789
00790
00791
00792
00793
00794
00795
00796 int parse_arguments(int *argc, const char ***argv, int frommain)
00797 {
00798 int opt;
00799 char *ref = lp_refuse_options(module_id);
00800 const char *arg;
00801 poptContext pc;
00802
00803 if (ref && *ref)
00804 set_refuse_options(ref);
00805
00806
00807
00808
00809
00810 pc = poptGetContext(RSYNC_NAME, *argc, *argv, long_options, 0);
00811 poptReadDefaultConfig(pc, 0);
00812
00813 while ((opt = poptGetNextOpt(pc)) != -1) {
00814
00815
00816
00817 switch (opt) {
00818 case OPT_VERSION:
00819 print_rsync_version(FINFO);
00820 exit_cleanup(0);
00821
00822 case OPT_SERVER:
00823 if (!am_server) {
00824
00825
00826 poptFreeContext(pc);
00827 pc = poptGetContext(RSYNC_NAME, *argc, *argv,
00828 long_options, 0);
00829 am_server = 1;
00830 }
00831 break;
00832
00833 case OPT_SENDER:
00834 if (!am_server) {
00835 usage(FERROR);
00836 exit_cleanup(RERR_SYNTAX);
00837 }
00838 am_sender = 1;
00839 break;
00840
00841 case OPT_DAEMON:
00842 if (am_daemon) {
00843 strcpy(err_buf, "Attempt to hack rsync thwarted!\n");
00844 return 0;
00845 }
00846 poptFreeContext(pc);
00847 pc = poptGetContext(RSYNC_NAME, *argc, *argv,
00848 long_daemon_options, 0);
00849 while ((opt = poptGetNextOpt(pc)) != -1) {
00850 switch (opt) {
00851 case 'h':
00852 daemon_usage(FINFO);
00853 exit_cleanup(0);
00854
00855 case 'v':
00856 verbose++;
00857 break;
00858
00859 default:
00860 rprintf(FERROR,
00861 "rsync: %s: %s (in daemon mode)\n",
00862 poptBadOption(pc, POPT_BADOPTION_NOALIAS),
00863 poptStrerror(opt));
00864 goto daemon_error;
00865 }
00866 }
00867
00868 if (tmpdir && strlen(tmpdir) >= MAXPATHLEN - 10) {
00869 snprintf(err_buf, sizeof err_buf,
00870 "the --temp-dir path is WAY too long.\n");
00871 return 0;
00872 }
00873
00874 if (!daemon_opt) {
00875 rprintf(FERROR, "Daemon option(s) used without --daemon.\n");
00876 daemon_error:
00877 rprintf(FERROR,
00878 "(Type \"rsync --daemon --help\" for assistance with daemon mode.)\n");
00879 exit_cleanup(RERR_SYNTAX);
00880 }
00881
00882 *argv = poptGetArgs(pc);
00883 *argc = count_args(*argv);
00884 am_starting_up = 0;
00885 daemon_opt = 0;
00886 am_daemon = 1;
00887 return 1;
00888
00889 case OPT_MODIFY_WINDOW:
00890
00891
00892
00893 modify_window_set = 1;
00894 break;
00895
00896 case OPT_FILTER:
00897 parse_rule(&filter_list, poptGetOptArg(pc), 0, 0);
00898 break;
00899
00900 case OPT_EXCLUDE:
00901 parse_rule(&filter_list, poptGetOptArg(pc),
00902 0, XFLG_OLD_PREFIXES);
00903 break;
00904
00905 case OPT_INCLUDE:
00906 parse_rule(&filter_list, poptGetOptArg(pc),
00907 MATCHFLG_INCLUDE, XFLG_OLD_PREFIXES);
00908 break;
00909
00910 case OPT_EXCLUDE_FROM:
00911 case OPT_INCLUDE_FROM:
00912 arg = poptGetOptArg(pc);
00913 if (sanitize_paths)
00914 arg = sanitize_path(NULL, arg, NULL, 0);
00915 if (server_filter_list.head) {
00916 char *cp = (char *)arg;
00917 if (!*cp)
00918 goto options_rejected;
00919 clean_fname(cp, 1);
00920 if (check_filter(&server_filter_list, cp, 0) < 0)
00921 goto options_rejected;
00922 }
00923 parse_filter_file(&filter_list, arg,
00924 opt == OPT_INCLUDE_FROM ? MATCHFLG_INCLUDE : 0,
00925 XFLG_FATAL_ERRORS | XFLG_OLD_PREFIXES);
00926 break;
00927
00928 case 'a':
00929 if (refused_archive_part) {
00930 create_refuse_error(refused_archive_part);
00931 return 0;
00932 }
00933 if (!recurse)
00934 recurse = 1;
00935 #ifdef SUPPORT_LINKS
00936 preserve_links = 1;
00937 #endif
00938 preserve_perms = 1;
00939 preserve_times = 1;
00940 preserve_gid = 1;
00941 preserve_uid = 1;
00942 preserve_devices = 1;
00943 preserve_specials = 1;
00944 break;
00945
00946 case 'D':
00947 preserve_devices = preserve_specials = 1;
00948 break;
00949
00950 case OPT_NO_D:
00951 preserve_devices = preserve_specials = 0;
00952 break;
00953
00954 case 'h':
00955 human_readable++;
00956 break;
00957
00958 case 'i':
00959 itemize_changes++;
00960 break;
00961
00962 case 'v':
00963 verbose++;
00964 break;
00965
00966 case 'q':
00967 if (frommain)
00968 quiet++;
00969 break;
00970
00971 case 'x':
00972 one_file_system++;
00973 break;
00974
00975 case 'F':
00976 switch (++F_option_cnt) {
00977 case 1:
00978 parse_rule(&filter_list,": /.rsync-filter",0,0);
00979 break;
00980 case 2:
00981 parse_rule(&filter_list,"- .rsync-filter",0,0);
00982 break;
00983 }
00984 break;
00985
00986 case 'P':
00987 if (refused_partial || refused_progress) {
00988 create_refuse_error(refused_partial
00989 ? refused_partial : refused_progress);
00990 return 0;
00991 }
00992 do_progress = 1;
00993 keep_partial = 1;
00994 break;
00995
00996 case 'z':
00997 if (def_compress_level < Z_DEFAULT_COMPRESSION
00998 || def_compress_level > Z_BEST_COMPRESSION) {
00999 snprintf(err_buf, sizeof err_buf,
01000 "--compress-level value is invalid: %d\n",
01001 def_compress_level);
01002 return 0;
01003 }
01004 do_compression = def_compress_level != Z_NO_COMPRESSION;
01005 if (do_compression && refused_compress) {
01006 create_refuse_error(refused_compress);
01007 return 0;
01008 }
01009 break;
01010
01011 case OPT_WRITE_BATCH:
01012
01013 write_batch = 1;
01014 break;
01015
01016 case OPT_ONLY_WRITE_BATCH:
01017
01018 write_batch = -1;
01019 break;
01020
01021 case OPT_READ_BATCH:
01022
01023 read_batch = 1;
01024 break;
01025
01026 case OPT_MAX_SIZE:
01027 if ((max_size = parse_size_arg(&max_size_arg, 'b')) <= 0) {
01028 snprintf(err_buf, sizeof err_buf,
01029 "--max-size value is invalid: %s\n",
01030 max_size_arg);
01031 return 0;
01032 }
01033 break;
01034
01035 case OPT_MIN_SIZE:
01036 if ((min_size = parse_size_arg(&min_size_arg, 'b')) <= 0) {
01037 snprintf(err_buf, sizeof err_buf,
01038 "--min-size value is invalid: %s\n",
01039 min_size_arg);
01040 return 0;
01041 }
01042 break;
01043
01044 case OPT_LINK_DEST:
01045 #ifdef HAVE_LINK
01046 link_dest = 1;
01047 dest_option = "--link-dest";
01048 goto set_dest_dir;
01049 #else
01050 snprintf(err_buf, sizeof err_buf,
01051 "hard links are not supported on this %s\n",
01052 am_server ? "server" : "client");
01053 return 0;
01054 #endif
01055
01056 case OPT_COPY_DEST:
01057 copy_dest = 1;
01058 dest_option = "--copy-dest";
01059 goto set_dest_dir;
01060
01061 case OPT_COMPARE_DEST:
01062 compare_dest = 1;
01063 dest_option = "--compare-dest";
01064 set_dest_dir:
01065 if (basis_dir_cnt >= MAX_BASIS_DIRS) {
01066 snprintf(err_buf, sizeof err_buf,
01067 "ERROR: at most %d %s args may be specified\n",
01068 MAX_BASIS_DIRS, dest_option);
01069 return 0;
01070 }
01071 arg = poptGetOptArg(pc);
01072 if (sanitize_paths)
01073 arg = sanitize_path(NULL, arg, NULL, 0);
01074 basis_dir[basis_dir_cnt++] = (char *)arg;
01075 break;
01076
01077 case OPT_CHMOD:
01078 arg = poptGetOptArg(pc);
01079 if (!parse_chmod(arg, &chmod_modes)) {
01080 snprintf(err_buf, sizeof err_buf,
01081 "Invalid argument passed to --chmod (%s)\n",
01082 arg);
01083 return 0;
01084 }
01085 break;
01086
01087 case OPT_HELP:
01088 usage(FINFO);
01089 exit_cleanup(0);
01090
01091 case 'A':
01092 #ifdef SUPPORT_ACLS
01093 preserve_acls++;
01094 preserve_perms = 1;
01095 break;
01096 #else
01097
01098
01099
01100
01101
01102 snprintf(err_buf,sizeof(err_buf),
01103 "ACLs are not supported on this %s\n",
01104 am_server ? "server" : "client");
01105 return 0;
01106 #endif
01107
01108 case 'X':
01109 #ifdef SUPPORT_XATTRS
01110 preserve_xattrs = 1;
01111 preserve_perms = 1;
01112 break;
01113 #else
01114 snprintf(err_buf,sizeof(err_buf),
01115 "extended attributes are not supported on this %s\n",
01116 am_server ? "server" : "client");
01117 return 0;
01118 #endif
01119
01120 default:
01121
01122
01123 if (opt >= OPT_REFUSED_BASE) {
01124 create_refuse_error(opt);
01125 return 0;
01126 }
01127 snprintf(err_buf, sizeof err_buf, "%s%s: %s\n",
01128 am_server ? "on remote machine: " : "",
01129 poptBadOption(pc, POPT_BADOPTION_NOALIAS),
01130 poptStrerror(opt));
01131 return 0;
01132 }
01133 }
01134
01135 if (human_readable && *argc == 2) {
01136
01137 usage(FINFO);
01138 exit_cleanup(0);
01139 }
01140
01141 #ifndef SUPPORT_LINKS
01142 if (preserve_links && !am_sender) {
01143 snprintf(err_buf, sizeof err_buf,
01144 "symlinks are not supported on this %s\n",
01145 am_server ? "server" : "client");
01146 return 0;
01147 }
01148 #endif
01149
01150 #ifndef SUPPORT_HARD_LINKS
01151 if (preserve_hard_links) {
01152 snprintf(err_buf, sizeof err_buf,
01153 "hard links are not supported on this %s\n",
01154 am_server ? "server" : "client");
01155 return 0;
01156 }
01157 #endif
01158
01159 if (write_batch && read_batch) {
01160 snprintf(err_buf, sizeof err_buf,
01161 "--write-batch and --read-batch can not be used together\n");
01162 return 0;
01163 }
01164 if (write_batch > 0 || read_batch) {
01165 if (am_server) {
01166 rprintf(FINFO,
01167 "ignoring --%s-batch option sent to server\n",
01168 write_batch ? "write" : "read");
01169
01170
01171
01172 read_batch = write_batch = 0;
01173 batch_name = NULL;
01174 } else if (dry_run)
01175 write_batch = 0;
01176 }
01177 if (read_batch && files_from) {
01178 snprintf(err_buf, sizeof err_buf,
01179 "--read-batch cannot be used with --files-from\n");
01180 return 0;
01181 }
01182 if (batch_name && strlen(batch_name) > MAX_BATCH_NAME_LEN) {
01183 snprintf(err_buf, sizeof err_buf,
01184 "the batch-file name must be %d characters or less.\n",
01185 MAX_BATCH_NAME_LEN);
01186 return 0;
01187 }
01188
01189 if (tmpdir && strlen(tmpdir) >= MAXPATHLEN - 10) {
01190 snprintf(err_buf, sizeof err_buf,
01191 "the --temp-dir path is WAY too long.\n");
01192 return 0;
01193 }
01194
01195 if (compare_dest + copy_dest + link_dest > 1) {
01196 snprintf(err_buf, sizeof err_buf,
01197 "You may not mix --compare-dest, --copy-dest, and --link-dest.\n");
01198 return 0;
01199 }
01200
01201 if (files_from) {
01202 if (recurse == 1)
01203 recurse = 0;
01204 if (xfer_dirs < 0)
01205 xfer_dirs = 1;
01206 }
01207
01208 if (xfer_dirs < 1)
01209 xfer_dirs = recurse || list_only;
01210
01211 if (relative_paths < 0)
01212 relative_paths = files_from? 1 : 0;
01213 if (!relative_paths)
01214 implied_dirs = 0;
01215
01216 if (!!delete_before + delete_during + delete_after > 1) {
01217 snprintf(err_buf, sizeof err_buf,
01218 "You may not combine multiple --delete-WHEN options.\n");
01219 return 0;
01220 }
01221 if (delete_before || delete_during || delete_after)
01222 delete_mode = 1;
01223 else if (delete_mode || delete_excluded) {
01224 if (refused_delete_before) {
01225 create_refuse_error(refused_delete_before);
01226 return 0;
01227 }
01228 delete_mode = delete_before = 1;
01229 }
01230 if (!xfer_dirs && delete_mode) {
01231 snprintf(err_buf, sizeof err_buf,
01232 "--delete does not work without -r or -d.\n");
01233 return 0;
01234 }
01235
01236 if (delete_mode && refused_delete) {
01237 create_refuse_error(refused_delete);
01238 return 0;
01239 }
01240
01241 if (remove_sent_files) {
01242
01243
01244
01245 if (refused_delete && am_sender) {
01246 create_refuse_error(refused_delete);
01247 return 0;
01248 }
01249 need_messages_from_generator = 1;
01250 }
01251
01252 *argv = poptGetArgs(pc);
01253 *argc = count_args(*argv);
01254
01255 if (sanitize_paths) {
01256 int i;
01257 for (i = *argc; i-- > 0; )
01258 (*argv)[i] = sanitize_path(NULL, (*argv)[i], "", 0);
01259 if (tmpdir)
01260 tmpdir = sanitize_path(NULL, tmpdir, NULL, 0);
01261 if (partial_dir)
01262 partial_dir = sanitize_path(NULL, partial_dir, NULL, 0);
01263 if (backup_dir)
01264 backup_dir = sanitize_path(NULL, backup_dir, NULL, 0);
01265 }
01266 if (server_filter_list.head && !am_sender) {
01267 struct filter_list_struct *elp = &server_filter_list;
01268 int i;
01269 if (tmpdir) {
01270 if (!*tmpdir)
01271 goto options_rejected;
01272 clean_fname(tmpdir, 1);
01273 if (check_filter(elp, tmpdir, 1) < 0)
01274 goto options_rejected;
01275 }
01276 if (partial_dir && *partial_dir) {
01277 clean_fname(partial_dir, 1);
01278 if (check_filter(elp, partial_dir, 1) < 0)
01279 goto options_rejected;
01280 }
01281 for (i = 0; i < basis_dir_cnt; i++) {
01282 if (!*basis_dir[i])
01283 goto options_rejected;
01284 clean_fname(basis_dir[i], 1);
01285 if (check_filter(elp, basis_dir[i], 1) < 0)
01286 goto options_rejected;
01287 }
01288 if (backup_dir) {
01289 if (!*backup_dir)
01290 goto options_rejected;
01291 clean_fname(backup_dir, 1);
01292 if (check_filter(elp, backup_dir, 1) < 0) {
01293 options_rejected:
01294 snprintf(err_buf, sizeof err_buf,
01295 "Your options have been rejected by the server.\n");
01296 return 0;
01297 }
01298 }
01299 }
01300
01301 if (!backup_suffix)
01302 backup_suffix = backup_dir ? "" : BACKUP_SUFFIX;
01303 backup_suffix_len = strlen(backup_suffix);
01304 if (strchr(backup_suffix, '/') != NULL) {
01305 snprintf(err_buf, sizeof err_buf,
01306 "--suffix cannot contain slashes: %s\n",
01307 backup_suffix);
01308 return 0;
01309 }
01310 if (backup_dir) {
01311 backup_dir_len = strlcpy(backup_dir_buf, backup_dir, sizeof backup_dir_buf);
01312 backup_dir_remainder = sizeof backup_dir_buf - backup_dir_len;
01313 if (backup_dir_remainder < 32) {
01314 snprintf(err_buf, sizeof err_buf,
01315 "the --backup-dir path is WAY too long.\n");
01316 return 0;
01317 }
01318 if (backup_dir_buf[backup_dir_len - 1] != '/') {
01319 backup_dir_buf[backup_dir_len++] = '/';
01320 backup_dir_buf[backup_dir_len] = '\0';
01321 }
01322 if (verbose > 1 && !am_sender)
01323 rprintf(FINFO, "backup_dir is %s\n", backup_dir_buf);
01324 } else if (!backup_suffix_len && (!am_server || !am_sender)) {
01325 snprintf(err_buf, sizeof err_buf,
01326 "--suffix cannot be a null string without --backup-dir\n");
01327 return 0;
01328 } else if (make_backups && delete_mode && !delete_excluded) {
01329 snprintf(backup_dir_buf, sizeof backup_dir_buf,
01330 "P *%s", backup_suffix);
01331 parse_rule(&filter_list, backup_dir_buf, 0, 0);
01332 }
01333 if (make_backups && !backup_dir)
01334 omit_dir_times = 1;
01335
01336 if (log_format) {
01337 if (am_server && log_format_has(log_format, 'I'))
01338 log_format_has_i = 2;
01339 else if (log_format_has(log_format, 'i'))
01340 log_format_has_i = itemize_changes | 1;
01341 if (!log_format_has(log_format, 'b')
01342 && !log_format_has(log_format, 'c'))
01343 log_before_transfer = !am_server;
01344 } else if (itemize_changes) {
01345 log_format = "%i %n%L";
01346 log_format_has_i = itemize_changes;
01347 log_before_transfer = !am_server;
01348 }
01349
01350 if (do_progress && !verbose && !log_before_transfer && !am_server)
01351 verbose = 1;
01352
01353 if (dry_run)
01354 do_xfers = 0;
01355
01356 set_io_timeout(io_timeout);
01357
01358 if (verbose && !log_format) {
01359 log_format = "%n%L";
01360 log_before_transfer = !am_server;
01361 }
01362 if (log_format_has_i || log_format_has(log_format, 'o'))
01363 log_format_has_o_or_i = 1;
01364
01365 if (daemon_bwlimit && (!bwlimit || bwlimit > daemon_bwlimit))
01366 bwlimit = daemon_bwlimit;
01367 if (bwlimit) {
01368 bwlimit_writemax = (size_t)bwlimit * 128;
01369 if (bwlimit_writemax < 512)
01370 bwlimit_writemax = 512;
01371 }
01372
01373 if (sparse_files && inplace) {
01374
01375
01376 snprintf(err_buf, sizeof err_buf,
01377 "--sparse cannot be used with --inplace\n");
01378 return 0;
01379 }
01380
01381 if (append_mode) {
01382 if (whole_file > 0) {
01383 snprintf(err_buf, sizeof err_buf,
01384 "--append cannot be used with --whole-file\n");
01385 return 0;
01386 }
01387 if (refused_inplace) {
01388 create_refuse_error(refused_inplace);
01389 return 0;
01390 }
01391 inplace = 1;
01392 }
01393
01394 if (delay_updates && !partial_dir)
01395 partial_dir = tmp_partialdir;
01396
01397 if (inplace) {
01398 #ifdef HAVE_FTRUNCATE
01399 if (partial_dir) {
01400 snprintf(err_buf, sizeof err_buf,
01401 "--%s cannot be used with --%s\n",
01402 append_mode ? "append" : "inplace",
01403 delay_updates ? "delay-updates" : "partial-dir");
01404 return 0;
01405 }
01406
01407
01408 if (refused_partial) {
01409 create_refuse_error(refused_partial);
01410 return 0;
01411 }
01412 keep_partial = 0;
01413 #else
01414 snprintf(err_buf, sizeof err_buf,
01415 "--%s is not supported on this %s\n",
01416 append_mode ? "append" : "inplace",
01417 am_server ? "server" : "client");
01418 return 0;
01419 #endif
01420 } else {
01421 if (keep_partial && !partial_dir && !am_server) {
01422 if ((arg = getenv("RSYNC_PARTIAL_DIR")) != NULL && *arg)
01423 partial_dir = strdup(arg);
01424 }
01425 if (partial_dir) {
01426 if (*partial_dir)
01427 clean_fname(partial_dir, 1);
01428 if (!*partial_dir || strcmp(partial_dir, ".") == 0)
01429 partial_dir = NULL;
01430 else if (*partial_dir != '/') {
01431 parse_rule(&filter_list, partial_dir,
01432 MATCHFLG_NO_PREFIXES|MATCHFLG_DIRECTORY, 0);
01433 }
01434 if (!partial_dir && refused_partial) {
01435 create_refuse_error(refused_partial);
01436 return 0;
01437 }
01438 keep_partial = 1;
01439 }
01440 }
01441
01442 if (files_from) {
01443 char *h, *p;
01444 int q;
01445 if (*argc > 2 || (!am_daemon && *argc == 1)) {
01446 usage(FERROR);
01447 exit_cleanup(RERR_SYNTAX);
01448 }
01449 if (strcmp(files_from, "-") == 0) {
01450 filesfrom_fd = 0;
01451 if (am_server)
01452 filesfrom_host = "";
01453 } else if ((p = check_for_hostspec(files_from, &h, &q)) != 0) {
01454 if (am_server) {
01455 snprintf(err_buf, sizeof err_buf,
01456 "The --files-from sent to the server cannot specify a host.\n");
01457 return 0;
01458 }
01459 files_from = p;
01460 filesfrom_host = h;
01461 if (strcmp(files_from, "-") == 0) {
01462 snprintf(err_buf, sizeof err_buf,
01463 "Invalid --files-from remote filename\n");
01464 return 0;
01465 }
01466 } else {
01467 if (sanitize_paths)
01468 files_from = sanitize_path(NULL, files_from, NULL, 0);
01469 if (server_filter_list.head) {
01470 if (!*files_from)
01471 goto options_rejected;
01472 clean_fname(files_from, 1);
01473 if (check_filter(&server_filter_list, files_from, 0) < 0)
01474 goto options_rejected;
01475 }
01476 filesfrom_fd = open(files_from, O_RDONLY|O_BINARY);
01477 if (filesfrom_fd < 0) {
01478 snprintf(err_buf, sizeof err_buf,
01479 "failed to open files-from file %s: %s\n",
01480 files_from, strerror(errno));
01481 return 0;
01482 }
01483 }
01484 }
01485
01486 am_starting_up = 0;
01487
01488 return 1;
01489 }
01490
01491
01492
01493
01494
01495
01496
01497
01498
01499
01500 void server_options(char **args,int *argc)
01501 {
01502 static char argstr[64];
01503 int ac = *argc;
01504 char *arg;
01505
01506 int i, x;
01507
01508 if (blocking_io == -1)
01509 blocking_io = 0;
01510
01511
01512 args[ac++] = "--server";
01513
01514 if (daemon_over_rsh) {
01515 args[ac++] = "--daemon";
01516 *argc = ac;
01517
01518 return;
01519 }
01520
01521 if (!am_sender)
01522 args[ac++] = "--sender";
01523
01524 x = 1;
01525 argstr[0] = '-';
01526 for (i = 0; i < verbose; i++)
01527 argstr[x++] = 'v';
01528
01529
01530 if (make_backups)
01531 argstr[x++] = 'b';
01532 if (update_only)
01533 argstr[x++] = 'u';
01534 if (!do_xfers)
01535 argstr[x++] = 'n';
01536 if (preserve_links)
01537 argstr[x++] = 'l';
01538 if (xfer_dirs > (recurse || !delete_mode || !am_sender))
01539 argstr[x++] = 'd';
01540 if (am_sender) {
01541 if (keep_dirlinks)
01542 argstr[x++] = 'K';
01543 if (prune_empty_dirs)
01544 argstr[x++] = 'm';
01545 if (omit_dir_times == 2)
01546 argstr[x++] = 'O';
01547 } else {
01548 if (copy_links)
01549 argstr[x++] = 'L';
01550 if (copy_dirlinks)
01551 argstr[x++] = 'k';
01552 }
01553
01554 if (whole_file > 0)
01555 argstr[x++] = 'W';
01556
01557
01558
01559
01560 if (preserve_hard_links)
01561 argstr[x++] = 'H';
01562 #ifdef SUPPORT_ACLS
01563 if (preserve_acls)
01564 argstr[x++] = 'A';
01565 #endif
01566 #ifdef SUPPORT_XATTRS
01567 if (preserve_xattrs)
01568 argstr[x++] = 'X';
01569 #endif
01570 if (preserve_uid)
01571 argstr[x++] = 'o';
01572 if (preserve_gid)
01573 argstr[x++] = 'g';
01574 if (preserve_devices)
01575 argstr[x++] = 'D';
01576 if (preserve_times)
01577 argstr[x++] = 't';
01578 if (preserve_perms)
01579 argstr[x++] = 'p';
01580 else if (preserve_executability && am_sender)
01581 argstr[x++] = 'E';
01582 if (recurse)
01583 argstr[x++] = 'r';
01584 if (always_checksum)
01585 argstr[x++] = 'c';
01586 if (cvs_exclude)
01587 argstr[x++] = 'C';
01588 if (ignore_times)
01589 argstr[x++] = 'I';
01590 if (relative_paths)
01591 argstr[x++] = 'R';
01592 if (one_file_system) {
01593 argstr[x++] = 'x';
01594 if (one_file_system > 1)
01595 argstr[x++] = 'x';
01596 }
01597 if (sparse_files)
01598 argstr[x++] = 'S';
01599 if (do_compression)
01600 argstr[x++] = 'z';
01601
01602
01603
01604
01605 if (list_only == 1 && !recurse)
01606 argstr[x++] = 'r';
01607
01608 argstr[x] = '\0';
01609
01610 if (x != 1)
01611 args[ac++] = argstr;
01612
01613 if (list_only > 1)
01614 args[ac++] = "--list-only";
01615
01616
01617
01618 if (xfer_dirs && !recurse && delete_mode && am_sender)
01619 args[ac++] = "--no-r";
01620
01621 if (do_compression && def_compress_level != Z_DEFAULT_COMPRESSION) {
01622 if (asprintf(&arg, "--compress-level=%d", def_compress_level) < 0)
01623 goto oom;
01624 args[ac++] = arg;
01625 }
01626
01627 if (preserve_devices) {
01628
01629 if (!preserve_specials)
01630 args[ac++] = "--no-specials";
01631 } else if (preserve_specials)
01632 args[ac++] = "--specials";
01633
01634
01635
01636 if (log_format && am_sender) {
01637 if (log_format_has_i > 1)
01638 args[ac++] = "--log-format=%i%I";
01639 else if (log_format_has_i)
01640 args[ac++] = "--log-format=%i";
01641 else if (log_format_has_o_or_i)
01642 args[ac++] = "--log-format=%o";
01643 else if (!verbose)
01644 args[ac++] = "--log-format=X";
01645 }
01646
01647 if (block_size) {
01648 if (asprintf(&arg, "-B%lu", block_size) < 0)
01649 goto oom;
01650 args[ac++] = arg;
01651 }
01652
01653 if (max_delete && am_sender) {
01654 if (asprintf(&arg, "--max-delete=%d", max_delete) < 0)
01655 goto oom;
01656 args[ac++] = arg;
01657 }
01658
01659 if (min_size && am_sender) {
01660 args[ac++] = "--min-size";
01661 args[ac++] = min_size_arg;
01662 }
01663
01664 if (max_size && am_sender) {
01665 args[ac++] = "--max-size";
01666 args[ac++] = max_size_arg;
01667 }
01668
01669 if (io_timeout) {
01670 if (asprintf(&arg, "--timeout=%d", io_timeout) < 0)
01671 goto oom;
01672 args[ac++] = arg;
01673 }
01674
01675 if (bwlimit) {
01676 if (asprintf(&arg, "--bwlimit=%d", bwlimit) < 0)
01677 goto oom;
01678 args[ac++] = arg;
01679 }
01680
01681 if (backup_dir) {
01682 args[ac++] = "--backup-dir";
01683 args[ac++] = backup_dir;
01684 }
01685
01686
01687 if (strcmp(backup_suffix, backup_dir ? "" : BACKUP_SUFFIX) != 0) {
01688
01689 if (asprintf(&arg, "--suffix=%s", backup_suffix) < 0)
01690 goto oom;
01691 args[ac++] = arg;
01692 }
01693
01694 if (am_sender) {
01695 if (delete_excluded)
01696 args[ac++] = "--delete-excluded";
01697 else if (delete_before == 1 || delete_after)
01698 args[ac++] = "--delete";
01699 if (delete_before > 1)
01700 args[ac++] = "--delete-before";
01701 if (delete_during)
01702 args[ac++] = "--delete-during";
01703 if (delete_after)
01704 args[ac++] = "--delete-after";
01705 if (force_delete)
01706 args[ac++] = "--force";
01707 if (write_batch < 0)
01708 args[ac++] = "--only-write-batch=X";
01709 if (am_root > 1)
01710 args[ac++] = "--super";
01711 if (size_only)
01712 args[ac++] = "--size-only";
01713 }
01714
01715 if (modify_window_set) {
01716 if (asprintf(&arg, "--modify-window=%d", modify_window) < 0)
01717 goto oom;
01718 args[ac++] = arg;
01719 }
01720
01721 if (checksum_seed) {
01722 if (asprintf(&arg, "--checksum-seed=%d", checksum_seed) < 0)
01723 goto oom;
01724 args[ac++] = arg;
01725 }
01726
01727 if (partial_dir && am_sender) {
01728 if (partial_dir != tmp_partialdir) {
01729 args[ac++] = "--partial-dir";
01730 args[ac++] = partial_dir;
01731 }
01732 if (delay_updates)
01733 args[ac++] = "--delay-updates";
01734 } else if (keep_partial && am_sender)
01735 args[ac++] = "--partial";
01736
01737 if (ignore_errors)
01738 args[ac++] = "--ignore-errors";
01739
01740 if (copy_unsafe_links)
01741 args[ac++] = "--copy-unsafe-links";
01742
01743 if (safe_symlinks)
01744 args[ac++] = "--safe-links";
01745
01746 if (numeric_ids)
01747 args[ac++] = "--numeric-ids";
01748
01749 if (ignore_existing && am_sender)
01750 args[ac++] = "--ignore-existing";
01751
01752
01753 if (ignore_non_existing && am_sender)
01754 args[ac++] = "--existing";
01755
01756 if (append_mode)
01757 args[ac++] = "--append";
01758 else if (inplace)
01759 args[ac++] = "--inplace";
01760
01761 if (tmpdir && am_sender) {
01762 args[ac++] = "--temp-dir";
01763 args[ac++] = tmpdir;
01764 }
01765
01766 if (basis_dir[0] && am_sender) {
01767
01768
01769
01770
01771 int i;
01772 for (i = 0; i < basis_dir_cnt; i++) {
01773 args[ac++] = dest_option;
01774 args[ac++] = basis_dir[i];
01775 }
01776 }
01777
01778 if (files_from && (!am_sender || filesfrom_host)) {
01779 if (filesfrom_host) {
01780 args[ac++] = "--files-from";
01781 args[ac++] = files_from;
01782 if (eol_nulls)
01783 args[ac++] = "--from0";
01784 } else {
01785 args[ac++] = "--files-from=-";
01786 args[ac++] = "--from0";
01787 }
01788 if (!relative_paths)
01789 args[ac++] = "--no-relative";
01790 }
01791 if (relative_paths && !implied_dirs && !am_sender)
01792 args[ac++] = "--no-implied-dirs";
01793
01794 if (fuzzy_basis && am_sender)
01795 args[ac++] = "--fuzzy";
01796
01797 if (remove_sent_files)
01798 args[ac++] = "--remove-sent-files";
01799
01800 *argc = ac;
01801 return;
01802
01803 oom:
01804 out_of_memory("server_options");
01805 }
01806
01807
01808
01809
01810
01811
01812
01813
01814 char *check_for_hostspec(char *s, char **host_ptr, int *port_ptr)
01815 {
01816 char *p;
01817 int not_host;
01818
01819 if (port_ptr && strncasecmp(URL_PREFIX, s, strlen(URL_PREFIX)) == 0) {
01820 char *path;
01821 int hostlen;
01822 s += strlen(URL_PREFIX);
01823 if ((p = strchr(s, '/')) != NULL) {
01824 hostlen = p - s;
01825 path = p + 1;
01826 } else {
01827 hostlen = strlen(s);
01828 path = "";
01829 }
01830 if (*s == '[' && (p = strchr(s, ']')) != NULL) {
01831 s++;
01832 hostlen = p - s;
01833 if (p[1] == ':')
01834 *port_ptr = atoi(p+2);
01835 } else {
01836 if ((p = strchr(s, ':')) != NULL) {
01837 hostlen = p - s;
01838 *port_ptr = atoi(p+1);
01839 }
01840 }
01841 if (!*port_ptr)
01842 *port_ptr = RSYNC_PORT;
01843 *host_ptr = new_array(char, hostlen + 1);
01844 strlcpy(*host_ptr, s, hostlen + 1);
01845 return path;
01846 }
01847
01848 if (*s == '[' && (p = strchr(s, ']')) != NULL && p[1] == ':') {
01849 s++;
01850 *p = '\0';
01851 not_host = strchr(s, '/') || !strchr(s, ':');
01852 *p = ']';
01853 if (not_host)
01854 return NULL;
01855 p++;
01856 } else {
01857 if (!(p = strchr(s, ':')))
01858 return NULL;
01859 *p = '\0';
01860 not_host = strchr(s, '/') != NULL;
01861 *p = ':';
01862 if (not_host)
01863 return NULL;
01864 }
01865
01866 *host_ptr = new_array(char, p - s + 1);
01867 strlcpy(*host_ptr, s, p - s + 1);
01868
01869 if (p[1] == ':') {
01870 if (port_ptr && !*port_ptr)
01871 *port_ptr = RSYNC_PORT;
01872 return p + 2;
01873 }
01874 if (port_ptr)
01875 *port_ptr = 0;
01876
01877 return p + 1;
01878 }