aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/testbed_api_hosts.c
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2013-08-21 14:35:24 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2013-08-21 14:35:24 +0000
commitb4fe9e8eec012efb981f90a4d751bb23507aa2c5 (patch)
tree303623bd722a31d766a017267c89e2ece8c04b25 /src/testbed/testbed_api_hosts.c
parent4f6e5912d16f9b15cc5b9af963b5e0e8cb6d234c (diff)
downloadgnunet-b4fe9e8eec012efb981f90a4d751bb23507aa2c5.tar.gz
gnunet-b4fe9e8eec012efb981f90a4d751bb23507aa2c5.zip
- enable substitions
Diffstat (limited to 'src/testbed/testbed_api_hosts.c')
-rw-r--r--src/testbed/testbed_api_hosts.c74
1 files changed, 44 insertions, 30 deletions
diff --git a/src/testbed/testbed_api_hosts.c b/src/testbed/testbed_api_hosts.c
index c0b64cf8f..6060810a4 100644
--- a/src/testbed/testbed_api_hosts.c
+++ b/src/testbed/testbed_api_hosts.c
@@ -945,11 +945,12 @@ free_argv (char **argv)
945 * NoHostAuthenticationForLocalhost=yes' 945 * NoHostAuthenticationForLocalhost=yes'
946 * 946 *
947 * @param port the destination port number 947 * @param port the destination port number
948 * @param dst the destination address 948 * @param hostname the hostname of the target host
949 * @param username the username to use while connecting to target host
949 * @return NULL terminated list of arguments 950 * @return NULL terminated list of arguments
950 */ 951 */
951static char ** 952static char **
952gen_rsh_args (const char *port, const char *dst) 953gen_rsh_args (const char *port, const char *hostname, const char *username)
953{ 954{
954 static const char *default_ssh_args[] = { 955 static const char *default_ssh_args[] = {
955 "ssh", 956 "ssh",
@@ -957,12 +958,15 @@ gen_rsh_args (const char *port, const char *dst)
957 "BatchMode=yes", 958 "BatchMode=yes",
958 "-o", 959 "-o",
959 "NoHostAuthenticationForLocalhost=yes", 960 "NoHostAuthenticationForLocalhost=yes",
961 "%h",
960 NULL 962 NULL
961 }; 963 };
962 char **ssh_args; 964 char **ssh_args;
963 char *ssh_cmd; 965 char *ssh_cmd;
964 char *ssh_cmd_cp; 966 char *ssh_cmd_cp;
965 char *arg; 967 char *arg;
968 const char *new_arg;
969 unsigned int size;
966 unsigned int cnt; 970 unsigned int cnt;
967 971
968 ssh_args = NULL; 972 ssh_args = NULL;
@@ -970,20 +974,44 @@ gen_rsh_args (const char *port, const char *dst)
970 { 974 {
971 ssh_cmd = GNUNET_strdup (ssh_cmd); 975 ssh_cmd = GNUNET_strdup (ssh_cmd);
972 ssh_cmd_cp = ssh_cmd; 976 ssh_cmd_cp = ssh_cmd;
973 for (cnt = 0; NULL != (arg = strtok (ssh_cmd, " ")); ssh_cmd = NULL) 977 for (size = 0; NULL != (arg = strtok (ssh_cmd, " ")); ssh_cmd = NULL)
974 GNUNET_array_append (ssh_args, cnt, GNUNET_strdup (arg)); 978 GNUNET_array_append (ssh_args, size, GNUNET_strdup (arg));
975 GNUNET_free (ssh_cmd_cp); 979 GNUNET_free (ssh_cmd_cp);
976 } 980 }
977 else 981 else
978 { 982 {
979 ssh_args = copy_argv (default_ssh_args); 983 ssh_args = copy_argv (default_ssh_args);
980 cnt = (sizeof (default_ssh_args)) / (sizeof (const char *)); 984 size = (sizeof (default_ssh_args)) / (sizeof (const char *));
981 GNUNET_array_grow (ssh_args, cnt, cnt - 1); 985 GNUNET_array_grow (ssh_args, size, size - 1);
982 } 986 }
983 GNUNET_array_append (ssh_args, cnt, GNUNET_strdup ("-p")); 987 for (cnt = 0; cnt < size; cnt++)
984 GNUNET_array_append (ssh_args, cnt, GNUNET_strdup (port)); 988 {
985 GNUNET_array_append (ssh_args, cnt, GNUNET_strdup (dst)); 989 arg = ssh_args[cnt];
986 GNUNET_array_append (ssh_args, cnt, NULL); 990 if ('%' != arg[0])
991 continue;
992 switch (arg[1])
993 {
994 case 'p':
995 new_arg = port;
996 break;
997
998 case 'u':
999 new_arg = username;
1000 break;
1001
1002 case 'h':
1003 new_arg = hostname;
1004 break;
1005
1006 default:
1007 continue;
1008 }
1009 if (NULL == new_arg)
1010 continue;
1011 GNUNET_free (arg);
1012 ssh_args[cnt] = GNUNET_strdup (new_arg);
1013 }
1014 GNUNET_array_append (ssh_args, size, NULL);
987 return ssh_args; 1015 return ssh_args;
988} 1016}
989 1017
@@ -1182,17 +1210,11 @@ GNUNET_TESTBED_controller_start (const char *trusted_ip,
1182 char **rsh_suffix_args; 1210 char **rsh_suffix_args;
1183 const char *username; 1211 const char *username;
1184 char *port; 1212 char *port;
1185 char *dst;
1186
1187 username = GNUNET_TESTBED_host_get_username_ (host);
1188 hostname = GNUNET_TESTBED_host_get_hostname (host);
1189 GNUNET_asprintf (&port, "%u", GNUNET_TESTBED_host_get_ssh_port_ (host));
1190 if (NULL == username)
1191 GNUNET_asprintf (&dst, "%s", hostname);
1192 else
1193 GNUNET_asprintf (&dst, "%s@%s", username, hostname);
1194 LOG_DEBUG ("Starting SSH to destination %s\n", dst);
1195 1213
1214 username = host->username;
1215 hostname = host->hostname;
1216 GNUNET_asprintf (&port, "%u", host->port);
1217 LOG_DEBUG ("Starting remote connection to destination %s\n", hostname);
1196 if (GNUNET_OK != 1218 if (GNUNET_OK !=
1197 GNUNET_CONFIGURATION_get_value_string (cfg, "testbed", 1219 GNUNET_CONFIGURATION_get_value_string (cfg, "testbed",
1198 "HELPER_BINARY_PATH", 1220 "HELPER_BINARY_PATH",
@@ -1200,14 +1222,13 @@ GNUNET_TESTBED_controller_start (const char *trusted_ip,
1200 helper_binary_path_args[0] = 1222 helper_binary_path_args[0] =
1201 GNUNET_OS_get_libexec_binary_path (HELPER_TESTBED_BINARY); 1223 GNUNET_OS_get_libexec_binary_path (HELPER_TESTBED_BINARY);
1202 helper_binary_path_args[1] = NULL; 1224 helper_binary_path_args[1] = NULL;
1203 rsh_args = gen_rsh_args (port, dst); 1225 rsh_args = gen_rsh_args (port, hostname, username);
1204 rsh_suffix_args = gen_rsh_suffix_args ((const char **) helper_binary_path_args); 1226 rsh_suffix_args = gen_rsh_suffix_args ((const char **) helper_binary_path_args);
1205 cp->helper_argv = 1227 cp->helper_argv =
1206 join_argv ((const char **) rsh_args, (const char **) rsh_suffix_args); 1228 join_argv ((const char **) rsh_args, (const char **) rsh_suffix_args);
1207 free_argv (rsh_args); 1229 free_argv (rsh_args);
1208 free_argv (rsh_suffix_args); 1230 free_argv (rsh_suffix_args);
1209 GNUNET_free (port); 1231 GNUNET_free (port);
1210 GNUNET_free (dst);
1211 cp->helper = 1232 cp->helper =
1212 GNUNET_HELPER_start (GNUNET_NO, cp->helper_argv[0], cp->helper_argv, &helper_mst, 1233 GNUNET_HELPER_start (GNUNET_NO, cp->helper_argv[0], cp->helper_argv, &helper_mst,
1213 &helper_exp_cb, cp); 1234 &helper_exp_cb, cp);
@@ -1406,17 +1427,12 @@ GNUNET_TESTBED_is_host_habitable (const struct GNUNET_TESTBED_Host *host,
1406 char *stat_args[3]; 1427 char *stat_args[3];
1407 const char *hostname; 1428 const char *hostname;
1408 char *port; 1429 char *port;
1409 char *dst;
1410 1430
1411 h = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_HostHabitableCheckHandle)); 1431 h = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_HostHabitableCheckHandle));
1412 h->cb = cb; 1432 h->cb = cb;
1413 h->cb_cls = cb_cls; 1433 h->cb_cls = cb_cls;
1414 h->host = host; 1434 h->host = host;
1415 hostname = (NULL == host->hostname) ? "127.0.0.1" : host->hostname; 1435 hostname = (NULL == host->hostname) ? "127.0.0.1" : host->hostname;
1416 if (NULL == host->username)
1417 dst = GNUNET_strdup (hostname);
1418 else
1419 GNUNET_asprintf (&dst, "%s@%s", host->username, hostname);
1420 if (GNUNET_OK != 1436 if (GNUNET_OK !=
1421 GNUNET_CONFIGURATION_get_value_string (config, "testbed", 1437 GNUNET_CONFIGURATION_get_value_string (config, "testbed",
1422 "HELPER_BINARY_PATH", 1438 "HELPER_BINARY_PATH",
@@ -1424,11 +1440,9 @@ GNUNET_TESTBED_is_host_habitable (const struct GNUNET_TESTBED_Host *host,
1424 stat_args[1] = 1440 stat_args[1] =
1425 GNUNET_OS_get_libexec_binary_path (HELPER_TESTBED_BINARY); 1441 GNUNET_OS_get_libexec_binary_path (HELPER_TESTBED_BINARY);
1426 GNUNET_asprintf (&port, "%u", host->port); 1442 GNUNET_asprintf (&port, "%u", host->port);
1427 rsh_args = gen_rsh_args (port, dst); 1443 rsh_args = gen_rsh_args (port, hostname, host->username);
1428 GNUNET_free (port); 1444 GNUNET_free (port);
1429 GNUNET_free (dst);
1430 port = NULL; 1445 port = NULL;
1431 dst = NULL;
1432 stat_args[0] = "stat"; 1446 stat_args[0] = "stat";
1433 stat_args[2] = NULL; 1447 stat_args[2] = NULL;
1434 rsh_suffix_args = gen_rsh_suffix_args ((const char **) stat_args); 1448 rsh_suffix_args = gen_rsh_suffix_args ((const char **) stat_args);