[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r25736 - gnunet/src/testbed
From: |
gnunet |
Subject: |
[GNUnet-SVN] r25736 - gnunet/src/testbed |
Date: |
Thu, 10 Jan 2013 00:53:37 +0100 |
Author: harsha
Date: 2013-01-10 00:53:37 +0100 (Thu, 10 Jan 2013)
New Revision: 25736
Modified:
gnunet/src/testbed/testbed_api.c
Log:
allow customizing remote shell command and the program started by it
Modified: gnunet/src/testbed/testbed_api.c
===================================================================
--- gnunet/src/testbed/testbed_api.c 2013-01-09 20:30:49 UTC (rev 25735)
+++ gnunet/src/testbed/testbed_api.c 2013-01-09 23:53:37 UTC (rev 25736)
@@ -1512,6 +1512,38 @@
/**
+ * Function to join NULL terminated list of arguments
+ *
+ * @param argv1 the NULL terminated list of arguments. Cannot be NULL.
+ * @param argv2 the NULL terminated list of arguments. Cannot be NULL.
+ * @return the joined NULL terminated arguments
+ */
+static char **
+join_argv (const char *const *argv1, const char *const *argv2)
+{
+ char **argvj;
+ char *argv;
+ unsigned int carg;
+ unsigned int cnt;
+
+ carg = 0;
+ argvj = NULL;
+ for (cnt = 0; NULL != argv1[cnt]; cnt++)
+ {
+ argv = GNUNET_strdup (argv1[cnt]);
+ GNUNET_array_append (argvj, carg, argv);
+ }
+ for (cnt = 0; NULL != argv2[cnt]; cnt++)
+ {
+ argv = GNUNET_strdup (argv2[cnt]);
+ GNUNET_array_append (argvj, carg, argv);
+ }
+ GNUNET_array_append (argvj, carg, NULL);
+ return argvj;
+}
+
+
+/**
* Frees the given NULL terminated arguments
*
* @param argv the NULL terminated list of arguments
@@ -1528,6 +1560,96 @@
/**
+ * Generates arguments for opening a remote shell. Builds up the arguments
+ * from the environment variable GNUNET_TESTBED_RSH_CMD. The variable
+ * should not mention `-p' (port) option and destination address as these will
+ * be set locally in the function from its parameteres. If the environmental
+ * variable is not found then it defaults to `ssh -o BatchMode=yes -o
+ * NoHostAuthenticationForLocalhost=yes'
+ *
+ * @param port the destination port number
+ * @param dst the destination address
+ * @return NULL terminated list of arguments
+ */
+static char **
+gen_rsh_args (const char *port, const char *dst)
+{
+ static const char *default_ssh_args[] = {
+ "ssh",
+ "-o",
+ "BatchMode=yes",
+ "-o",
+ "NoHostAuthenticationForLocalhost=yes",
+ NULL
+ };
+ char **ssh_args;
+ char *ssh_cmd;
+ char *ssh_cmd_cp;
+ char *arg;
+ unsigned int cnt;
+
+ ssh_args = NULL;
+ if (NULL != (ssh_cmd = getenv ("GNUNET_TESTBED_RSH_CMD")))
+ {
+ ssh_cmd = GNUNET_strdup (ssh_cmd);
+ ssh_cmd_cp = ssh_cmd;
+ for (cnt = 0;
+ NULL != (arg = strtok (ssh_cmd, " "));
+ ssh_cmd = NULL)
+ GNUNET_array_append (ssh_args, cnt, GNUNET_strdup (arg));
+ GNUNET_free (ssh_cmd_cp);
+ }
+ else
+ {
+ ssh_args = copy_argv (default_ssh_args);
+ cnt = (sizeof (default_ssh_args)) / (sizeof (const char *));
+ GNUNET_array_grow (ssh_args, cnt, cnt - 1);
+ }
+ GNUNET_array_append (ssh_args, cnt, GNUNET_strdup ("-p"));
+ GNUNET_array_append (ssh_args, cnt, GNUNET_strdup (port));
+ GNUNET_array_append (ssh_args, cnt, GNUNET_strdup (dst));
+ GNUNET_array_append (ssh_args, cnt, NULL);
+ return ssh_args;
+}
+
+
+/**
+ * Generates the arguments needed for executing the given binary in a remote
+ * shell. Builds the arguments from the environmental variable
+ * GNUNET_TETSBED_RSH_CMD_SUFFIX. If the environmental variable is not found,
+ * only the given binary name will be present in the returned arguments
+ *
+ * @param helper_binary_path the path of the binary to execute
+ * @return NULL-terminated args
+ */
+static char **
+gen_rsh_suffix_args (const char *helper_binary_path)
+{
+ char **rshell_args;
+ char *rshell_cmd;
+ char *rshell_cmd_cp;
+ char *arg;
+ unsigned int cnt;
+
+ rshell_args = NULL;
+ cnt = 0;
+ if (NULL != (rshell_cmd = getenv ("GNUNET_TESTBED_RSH_CMD_SUFFIX")))
+ {
+ rshell_cmd = GNUNET_strdup (rshell_cmd);
+ rshell_cmd_cp = rshell_cmd;
+ for (;
+ NULL != (arg = strtok (rshell_cmd, " "));
+ rshell_cmd = NULL)
+ GNUNET_array_append (rshell_args, cnt, GNUNET_strdup (arg));
+ GNUNET_free (rshell_cmd_cp);
+ }
+ GNUNET_array_append (rshell_args, cnt, GNUNET_strdup (helper_binary_path));
+ GNUNET_array_append (rshell_args, cnt, NULL);
+ return rshell_args;
+}
+
+
+/**
* Starts a controller process at the given host
*
* @param trusted_ip the ip address of the controller which will be set as
TRUSTED
@@ -1574,12 +1696,11 @@
else
{
char *helper_binary_path;
-#define NUM_REMOTE_ARGS 12
- const char *remote_args[NUM_REMOTE_ARGS];
+ char **ssh_args;
+ char **rshell_args;
const char *username;
char *port;
char *dst;
- unsigned int argp;
username = GNUNET_TESTBED_host_get_username_ (host);
hostname = GNUNET_TESTBED_host_get_hostname (host);
@@ -1589,25 +1710,18 @@
else
GNUNET_asprintf (&dst, "address@hidden", username, hostname);
LOG_DEBUG ("Starting SSH to destination %s\n", dst);
- argp = 0;
- remote_args[argp++] = "ssh";
- remote_args[argp++] = "-p";
- remote_args[argp++] = port;
- remote_args[argp++] = "-o";
- remote_args[argp++] = "BatchMode=yes";
- remote_args[argp++] = "-o";
- remote_args[argp++] = "NoHostAuthenticationForLocalhost=yes";
- remote_args[argp++] = dst;
+
if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "testbed",
"HELPER_BINARY_PATH",
&helper_binary_path))
- helper_binary_path = GNUNET_OS_get_libexec_binary_path
(HELPER_TESTBED_BINARY);
- remote_args[argp++] = "sh";
- remote_args[argp++] = "-lc";
- remote_args[argp++] = helper_binary_path;
- remote_args[argp++] = NULL;
- GNUNET_assert (NUM_REMOTE_ARGS == argp);
- cp->helper_argv = copy_argv (remote_args);
+ helper_binary_path = GNUNET_OS_get_libexec_binary_path
+ (HELPER_TESTBED_BINARY);
+ ssh_args = gen_rsh_args (port, dst);
+ rshell_args = gen_rsh_suffix_args (helper_binary_path);
+ cp->helper_argv = join_argv ((const char **) ssh_args,
+ (const char **)rshell_args);
+ free_argv (ssh_args);
+ free_argv (rshell_args);
GNUNET_free (port);
GNUNET_free (dst);
cp->helper =
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r25736 - gnunet/src/testbed,
gnunet <=