+ *argc = count_args(*argv);
+
+ if (sanitize_paths) {
+ int i;
+ for (i = *argc; i-- > 0; )
+ (*argv)[i] = sanitize_path(NULL, (*argv)[i], "", 0);
+ if (tmpdir)
+ tmpdir = sanitize_path(NULL, tmpdir, NULL, 0);
+ if (partial_dir)
+ partial_dir = sanitize_path(NULL, partial_dir, NULL, 0);
+ if (backup_dir)
+ backup_dir = sanitize_path(NULL, backup_dir, NULL, 0);
+ }
+ if (server_filter_list.head && !am_sender) {
+ struct filter_list_struct *elp = &server_filter_list;
+ int i;
+ if (tmpdir) {
+ if (!*tmpdir)
+ goto options_rejected;
+ clean_fname(tmpdir, 1);
+ if (check_filter(elp, tmpdir, 1) < 0)
+ goto options_rejected;
+ }
+ if (partial_dir && *partial_dir) {
+ clean_fname(partial_dir, 1);
+ if (check_filter(elp, partial_dir, 1) < 0)
+ goto options_rejected;
+ }
+ for (i = 0; i < basis_dir_cnt; i++) {
+ if (!*basis_dir[i])
+ goto options_rejected;
+ clean_fname(basis_dir[i], 1);
+ if (check_filter(elp, basis_dir[i], 1) < 0)
+ goto options_rejected;
+ }
+ if (backup_dir) {
+ if (!*backup_dir)
+ goto options_rejected;
+ clean_fname(backup_dir, 1);
+ if (check_filter(elp, backup_dir, 1) < 0) {
+ options_rejected:
+ snprintf(err_buf, sizeof err_buf,
+ "Your options have been rejected by the server.\n");
+ return 0;
+ }
+ }
+ }
+
+ if (!backup_suffix)
+ backup_suffix = backup_dir ? "" : BACKUP_SUFFIX;
+ backup_suffix_len = strlen(backup_suffix);
+ if (strchr(backup_suffix, '/') != NULL) {
+ snprintf(err_buf, sizeof err_buf,
+ "--suffix cannot contain slashes: %s\n",
+ backup_suffix);
+ return 0;
+ }
+ if (backup_dir) {
+ backup_dir_len = strlcpy(backup_dir_buf, backup_dir, sizeof backup_dir_buf);
+ backup_dir_remainder = sizeof backup_dir_buf - backup_dir_len;
+ if (backup_dir_remainder < 32) {
+ snprintf(err_buf, sizeof err_buf,
+ "the --backup-dir path is WAY too long.\n");
+ return 0;
+ }
+ if (backup_dir_buf[backup_dir_len - 1] != '/') {
+ backup_dir_buf[backup_dir_len++] = '/';
+ backup_dir_buf[backup_dir_len] = '\0';
+ }
+ if (verbose > 1 && !am_sender) {
+ rprintf(FINFO, "backup_dir is %s\n",
+ safe_fname(backup_dir_buf));
+ }
+ } else if (!backup_suffix_len && (!am_server || !am_sender)) {
+ snprintf(err_buf, sizeof err_buf,
+ "--suffix cannot be a null string without --backup-dir\n");
+ return 0;
+ }
+ if (make_backups && !backup_dir)
+ omit_dir_times = 1;
+
+ if (log_format) {
+ if (log_format_has(log_format, 'i'))
+ log_format_has_i = 1;
+ if (!log_format_has(log_format, 'b')
+ && !log_format_has(log_format, 'c'))
+ log_before_transfer = !am_server;
+ } else if (itemize_changes) {
+ log_format = "%i %n%L";
+ log_format_has_i = 1;
+ log_before_transfer = !am_server;
+ }
+
+ if ((do_progress || dry_run) && !verbose && !log_before_transfer
+ && !am_server)
+ verbose = 1;
+
+ if (dry_run)
+ do_xfers = 0;
+
+ if (verbose && !log_format) {
+ log_format = "%n%L";
+ log_before_transfer = !am_server;
+ }
+ if (log_format_has_i || log_format_has(log_format, 'o'))
+ log_format_has_o_or_i = 1;
+
+ if (daemon_bwlimit && (!bwlimit || bwlimit > daemon_bwlimit))
+ bwlimit = daemon_bwlimit;
+ if (bwlimit) {
+ bwlimit_writemax = (size_t)bwlimit * 128;
+ if (bwlimit_writemax < 512)
+ bwlimit_writemax = 512;
+ }
+
+ if (delay_updates && !partial_dir)
+ partial_dir = partialdir_for_delayupdate;
+
+ if (inplace) {
+#ifdef HAVE_FTRUNCATE
+ if (partial_dir) {
+ snprintf(err_buf, sizeof err_buf,
+ "--inplace cannot be used with --%s\n",
+ delay_updates ? "delay-updates" : "partial-dir");
+ return 0;
+ }
+ /* --inplace implies --partial for refusal purposes, but we
+ * clear the keep_partial flag for internal logic purposes. */
+ if (refused_partial) {
+ create_refuse_error(refused_partial);
+ return 0;
+ }
+ keep_partial = 0;
+#else
+ snprintf(err_buf, sizeof err_buf,
+ "--inplace is not supported on this %s\n",
+ am_server ? "server" : "client");
+ return 0;
+#endif
+ } else {
+ if (keep_partial && !partial_dir) {
+ if ((arg = getenv("RSYNC_PARTIAL_DIR")) != NULL && *arg)
+ partial_dir = strdup(arg);
+ }
+ if (partial_dir) {
+ if (*partial_dir)
+ clean_fname(partial_dir, 1);
+ if (!*partial_dir || strcmp(partial_dir, ".") == 0)
+ partial_dir = NULL;
+ else if (*partial_dir != '/') {
+ parse_rule(&filter_list, partial_dir,
+ MATCHFLG_NO_PREFIXES|MATCHFLG_DIRECTORY, 0);
+ }
+ if (!partial_dir && refused_partial) {
+ create_refuse_error(refused_partial);
+ return 0;
+ }
+ keep_partial = 1;
+ }
+ }
+
+ if (files_from) {
+ char *h, *p;
+ int q;
+ if (*argc > 2 || (!am_daemon && *argc == 1)) {
+ usage(FERROR);
+ exit_cleanup(RERR_SYNTAX);
+ }
+ if (strcmp(files_from, "-") == 0) {
+ filesfrom_fd = 0;
+ if (am_server)
+ filesfrom_host = ""; /* reading from socket */
+ } else if ((p = check_for_hostspec(files_from, &h, &q)) != 0) {
+ if (am_server) {
+ snprintf(err_buf, sizeof err_buf,
+ "The --files-from sent to the server cannot specify a host.\n");
+ return 0;
+ }
+ files_from = p;
+ filesfrom_host = h;
+ if (strcmp(files_from, "-") == 0) {
+ snprintf(err_buf, sizeof err_buf,
+ "Invalid --files-from remote filename\n");
+ return 0;
+ }
+ } else {
+ if (sanitize_paths)
+ files_from = sanitize_path(NULL, files_from, NULL, 0);
+ if (server_filter_list.head) {
+ if (!*files_from)
+ goto options_rejected;
+ clean_fname(files_from, 1);
+ if (check_filter(&server_filter_list, files_from, 0) < 0)
+ goto options_rejected;
+ }
+ filesfrom_fd = open(files_from, O_RDONLY|O_BINARY);
+ if (filesfrom_fd < 0) {
+ snprintf(err_buf, sizeof err_buf,
+ "failed to open files-from file %s: %s\n",
+ files_from, strerror(errno));
+ return 0;
+ }
+ }
+ }
+
+ am_starting_up = 0;