int *f_in, int *f_out)
{
int i, argc = 0;
- char *args[100];
+ char *args[MAX_ARGS];
pid_t ret;
char *tok, *dir = NULL;
int dash_l_set = 0;
if (!cmd)
goto oom;
- for (tok = strtok(cmd, " "); tok; tok = strtok(NULL, " "))
+ for (tok = strtok(cmd, " "); tok; tok = strtok(NULL, " ")) {
+ if (argc >= MAX_ARGS) {
+ rprintf(FERROR, "Command is too long\n");
+ exit_cleanup(RERR_SYNTAX);
+ }
args[argc++] = tok;
+ }
/* check to see if we've already been given '-l user' in
* the remote-shell command */
ret = piped_child(args,f_in,f_out);
}
- if (dir) free(dir);
+ if (dir)
+ free(dir);
return ret;
if ((pid=do_fork()) == 0) {
close(error_pipe[0]);
- if (f_in != f_out) close(f_out);
+ if (f_in != f_out)
+ close(f_out);
/* we can't let two processes write to the socket at one time */
io_multiplexing_close();
am_generator = 1;
close(error_pipe[1]);
- if (f_in != f_out) close(f_in);
+ if (f_in != f_out)
+ close(f_in);
io_start_buffering_out(f_out);
if (argc > 0) {
if (strcmp(dir,".")) {
argv[0] += strlen(dir);
- if (argv[0][0] == '/') argv[0]++;
+ if (argv[0][0] == '/')
+ argv[0]++;
}
local_name = get_local_name(flist,argv[0]);
}
return start_socket_client(host, path, argc-1, argv+1);
}
- if (!read_batch) {
+ if (!read_batch) { /* for read_batch, NO source is specified */
p = find_colon(argv[0]);
- if (p) {
+ if (p) { /* source is remote */
if (remote_filesfrom_file
&& remote_filesfrom_file != files_from + 1
&& strncmp(files_from, argv[0], p-argv[0]+1) != 0) {
daemon_over_rsh = 1;
}
- if (argc < 1) {
+ if (argc < 1) { /* destination required */
usage(FERROR);
exit_cleanup(RERR_SYNTAX);
}
*p = 0;
shell_machine = argv[0];
shell_path = p+1;
- argc--;
argv++;
- } else {
+ } else { /* source is local */
am_sender = 1;
/* rsync:// destination uses rsync server over direct socket */
return start_socket_client(host, path, argc-1, argv);
}
- p = find_colon(argv[argc-1]);
+ p = find_colon(argv[argc-1]); /* look in dest arg */
if (p && remote_filesfrom_file
&& remote_filesfrom_file != files_from + 1
&& strncmp(files_from, argv[argc-1], p-argv[argc-1]+1) != 0) {
"--files-from hostname is not transfer hostname\n");
exit_cleanup(RERR_SYNTAX);
}
- if (!p) {
+ if (!p) { /* no colon found, so src & dest are local */
local_server = 1;
if (remote_filesfrom_file) {
rprintf(FERROR,
shell_machine = argv[argc-1];
shell_path = p+1;
}
- argc--;
}
- } else {
+ argc--;
+ } else { /* read_batch */
am_sender = 1;
local_server = 1;
shell_path = argv[argc-1];
shell_path?shell_path:"");
}
+ /* for remote source, only single dest arg can remain ... */
if (!am_sender && argc > 1) {
usage(FERROR);
exit_cleanup(RERR_SYNTAX);
}
- if (argc == 0 && !am_sender) {
+ /* ... or no dest at all */
+ if (!am_sender && argc == 0) {
list_only = 1;
}