Permalink
Browse files

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
  • Loading branch information...
1 parent c8eac97 commit da14374f8556cdcde2ffa50efaacf0a50db2dd04 @prwolfe prwolfe committed Aug 12, 2016
Showing with 26 additions and 4 deletions.
  1. +26 −4 src/ssh.c
View
@@ -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;

0 comments on commit da14374

Please sign in to comment.