diff options
author | Thomas Thorne <TafThorne@GoogleMail.com> | 2016-08-15 15:37:51 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-15 15:37:51 +0100 |
commit | 83c78dd7c5bf15f7653229f96d3f4b424818ed6d (patch) | |
tree | 6079b2880f6916c04907c63449a8ae46deb589de | |
parent | c8eac974fd3057bd8cff1a66898d1899f27bf998 (diff) | |
parent | da14374f8556cdcde2ffa50efaacf0a50db2dd04 (diff) | |
download | distcc-git-83c78dd7c5bf15f7653229f96d3f4b424818ed6d.tar.gz |
Merge pull request #192 from prwolfe/improve_ssh_handling
ssh.c: tokenize the ssh command retrieved from DISTCC_SSH
-rw-r--r-- | src/ssh.c | 30 |
1 files changed, 26 insertions, 4 deletions
@@ -178,6 +178,12 @@ static int dcc_run_piped_cmd(char **argv, * nice for us to parse it into an argv[] string by splitting on * wildcards/quotes, but at the moment this seems redundant. It can be done * adequately using .ssh/config I think. + * + * @note the ssh command does need to be tokenized as we have hundreds of + * users and a corporate requirement that keeps us from modifying the + * system ssh config files. We can at the same time set command-line options + * through the tool in use one level above this. - prw 08/09/2016 + * **/ int dcc_ssh_connect(char *ssh_cmd, char *user, @@ -187,14 +193,26 @@ int dcc_ssh_connect(char *ssh_cmd, pid_t *ssh_pid) { pid_t ret; - char *child_argv[10]; - int i; + const int max_ssh_args = 12; + char *ssh_args[max_ssh_args]; + char *child_argv[10+max_ssh_args]; + int i,j; + int num_ssh_args = 0; /* We need to cast away constness. I promise the strings in the argv[] * will not be modified. */ - if (!ssh_cmd) - ssh_cmd = getenv("DISTCC_SSH"); + if (!ssh_cmd) { + char *ssh_cmd_in = getenv("DISTCC_SSH"); + ssh_cmd = strtok(ssh_cmd_in, " "); + char *token = strtok(NULL, " "); + while (token != NULL) { + ssh_args[num_ssh_args++] = token; + token = strtok(NULL, " "); + if (num_ssh_args == max_ssh_args) + break; + } + } if (!ssh_cmd) ssh_cmd = (char *) dcc_default_ssh; @@ -207,6 +225,10 @@ int dcc_ssh_connect(char *ssh_cmd, i = 0; child_argv[i++] = ssh_cmd; + for (j=0; j<num_ssh_args; ) { + child_argv[i++] = ssh_args[j++]; + } + if (user) { child_argv[i++] = (char *) "-l"; child_argv[i++] = user; |