- char *p;
- char *shell_machine = NULL;
- char *shell_path = NULL;
- char *shell_user = NULL;
- int pid, ret;
- int f_in,f_out;
- extern int local_server;
- extern int am_sender;
- extern char *shell_cmd;
- extern int rsync_port;
-
- if (strncasecmp(URL_PREFIX, argv[0], strlen(URL_PREFIX)) == 0) {
- char *host, *path;
-
- host = argv[0] + strlen(URL_PREFIX);
- p = strchr(host,'/');
- if (p) {
- *p = 0;
- path = p+1;
- } else {
- path="";
+ char *p, *shell_machine = NULL, *shell_user = NULL;
+ char **remote_argv;
+ int remote_argc;
+ int f_in, f_out;
+ int ret;
+ pid_t pid;
+
+ /* Don't clobber argv[] so that ps(1) can still show the right
+ * command line. */
+ if ((ret = copy_argv(argv)) != 0)
+ return ret;
+
+ if (!read_batch) { /* for read_batch, NO source is specified */
+ char *path = check_for_hostspec(argv[0], &shell_machine, &rsync_port);
+ if (path) { /* source is remote */
+ char *dummy1;
+ int dummy2;
+ *argv = path;
+ remote_argv = argv;
+ remote_argc = argc;
+ argv += argc - 1;
+ if (argc == 1 || **argv == ':')
+ argc = 0; /* no dest arg */
+ else if (check_for_hostspec(*argv, &dummy1, &dummy2)) {
+ rprintf(FERROR,
+ "The source and destination cannot both be remote.\n");
+ exit_cleanup(RERR_SYNTAX);
+ } else {
+ remote_argc--; /* don't count dest */
+ argc = 1;
+ }
+ if (filesfrom_host && *filesfrom_host
+ && strcmp(filesfrom_host, shell_machine) != 0) {
+ rprintf(FERROR,
+ "--files-from hostname is not the same as the transfer hostname\n");
+ exit_cleanup(RERR_SYNTAX);
+ }
+ am_sender = 0;
+ if (rsync_port)
+ daemon_over_rsh = shell_cmd ? 1 : -1;
+ } else { /* source is local, check dest arg */
+ am_sender = 1;
+
+ if (argc > 1) {
+ p = argv[--argc];
+ remote_argv = argv + argc;
+ } else {
+ static char *dotarg[1] = { "." };
+ p = dotarg[0];
+ remote_argv = dotarg;
+ list_only = 1;
+ }
+ remote_argc = 1;
+
+ path = check_for_hostspec(p, &shell_machine, &rsync_port);
+ if (path && filesfrom_host && *filesfrom_host
+ && strcmp(filesfrom_host, shell_machine) != 0) {
+ rprintf(FERROR,
+ "--files-from hostname is not the same as the transfer hostname\n");
+ exit_cleanup(RERR_SYNTAX);
+ }
+ if (!path) { /* no hostspec found, so src & dest are local */
+ local_server = 1;
+ if (filesfrom_host) {
+ rprintf(FERROR,
+ "--files-from cannot be remote when the transfer is local\n");
+ exit_cleanup(RERR_SYNTAX);
+ }
+ shell_machine = NULL;
+ } else { /* hostspec was found, so dest is remote */
+ argv[argc] = path;
+ if (rsync_port)
+ daemon_over_rsh = shell_cmd ? 1 : -1;
+ }