diff options
author | Paul Wolfenbarger <prwolfe@sandia.gov> | 2016-08-12 09:19:43 -0600 |
---|---|---|
committer | Paul Wolfenbarger <prwolfe@sandia.gov> | 2016-08-12 09:33:14 -0600 |
commit | da14374f8556cdcde2ffa50efaacf0a50db2dd04 (patch) | |
tree | 6079b2880f6916c04907c63449a8ae46deb589de | |
parent | c8eac974fd3057bd8cff1a66898d1899f27bf998 (diff) | |
download | distcc-git-da14374f8556cdcde2ffa50efaacf0a50db2dd04.tar.gz |
ssh.c: tokenize the ssh command retrieved from DISTCC_SSH
We have a large and ever-changing user community
to support and cannot rely on corporate to put ssh options
into the machine configurations. This allows us to place
-o ErrorLevel=ERROR in the DISTCC varable and have distcc
properly interpret that for passing on to execvp. Includes
changes from previous review by TafThorne
-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; |