+ if (sanitize_paths) {
+ int i;
+ for (i = *argc; i-- > 0; )
+ (*argv)[i] = sanitize_path(NULL, (*argv)[i], NULL);
+ if (tmpdir)
+ tmpdir = sanitize_path(NULL, tmpdir, "");
+ if (partial_dir)
+ partial_dir = sanitize_path(NULL, partial_dir, "");
+ if (compare_dest)
+ compare_dest = sanitize_path(NULL, compare_dest, "");
+ if (backup_dir)
+ backup_dir = sanitize_path(NULL, backup_dir, "");
+ if (files_from)
+ files_from = sanitize_path(NULL, files_from, "");
+ }
+ if (server_exclude_list.head && !am_sender) {
+ struct exclude_list_struct *elp = &server_exclude_list;
+ if (tmpdir) {
+ clean_fname(tmpdir);
+ if (check_exclude(elp, tmpdir, 1) < 0)
+ goto options_rejected;
+ }
+ if (partial_dir) {
+ clean_fname(partial_dir);
+ if (check_exclude(elp, partial_dir, 1) < 0)
+ goto options_rejected;
+ }
+ if (compare_dest) {
+ clean_fname(compare_dest);
+ if (check_exclude(elp, compare_dest, 1) < 0)
+ goto options_rejected;
+ }
+ if (backup_dir) {
+ clean_fname(backup_dir);
+ if (check_exclude(elp, backup_dir, 1) < 0)
+ goto options_rejected;
+ }
+ }
+ if (server_exclude_list.head && files_from) {
+ clean_fname(files_from);
+ if (check_exclude(&server_exclude_list, files_from, 0) < 0) {
+ options_rejected:
+ snprintf(err_buf, sizeof err_buf,
+ "Your options have been rejected by the server.\n");
+ return 0;
+ }
+ }
+
+ if (daemon_opt) {
+ daemon_opt = 0;
+ am_daemon = 1;
+ return 1;
+ }
+
+ 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", 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 (do_progress && !verbose)
+ verbose = 1;
+
+ if (bwlimit) {
+ bwlimit_writemax = (size_t)bwlimit * 128;
+ if (bwlimit_writemax < 512)
+ bwlimit_writemax = 512;
+ }
+
+ if (inplace) {
+#if HAVE_FTRUNCATE
+ if (partial_dir) {
+ snprintf(err_buf, sizeof err_buf,
+ "--inplace cannot be used with --partial-dir\n");
+ 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 (partial_dir) {
+ if (strcmp(partial_dir, ".") == 0)
+ partial_dir = NULL;
+ keep_partial = 1;
+ }
+
+ if (files_from) {
+ char *colon;
+ if (*argc > 2 || (!am_daemon && *argc == 1)) {
+ usage(FERROR);
+ exit_cleanup(RERR_SYNTAX);
+ }
+ if (strcmp(files_from, "-") == 0) {
+ filesfrom_fd = 0;
+ if (am_server)
+ remote_filesfrom_file = "-";
+ }
+ else if ((colon = find_colon(files_from)) != 0) {
+ if (am_server) {
+ usage(FERROR);
+ exit_cleanup(RERR_SYNTAX);
+ }
+ remote_filesfrom_file = colon+1 + (colon[1] == ':');
+ if (strcmp(remote_filesfrom_file, "-") == 0) {
+ snprintf(err_buf, sizeof err_buf,
+ "Invalid --files-from remote filename\n");
+ return 0;
+ }
+ } else {
+ 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;
+ }
+ }
+ }
+