summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.c9
-rw-r--r--src/pymscp.c8
-rw-r--r--src/ssh.c12
3 files changed, 22 insertions, 7 deletions
diff --git a/src/main.c b/src/main.c
index 7c8efb6..7035215 100644
--- a/src/main.c
+++ b/src/main.c
@@ -26,7 +26,7 @@ void usage(bool print_help) {
"\n"
"Usage: mscp [vqDHdNh] [-n nr_conns] [-m coremask] [-u max_startups]\n"
" [-s min_chunk_sz] [-S max_chunk_sz] [-a nr_ahead] [-b buf_sz]\n"
- " [-l login_name] [-p port] [-i identity_file]\n"
+ " [-l login_name] [-p port] [-F ssh_config] [-i identity_file]\n"
" [-c cipher_spec] [-M hmac_spec] [-C compress] source ... target\n"
"\n");
@@ -51,6 +51,8 @@ void usage(bool print_help) {
"\n"
" -l LOGIN_NAME login name\n"
" -p PORT port number\n"
+ " -F CONFIG path to user ssh config (default ~/.ssh/config)\n"
+ " if set to 'none', no config files will be read.\n"
" -i IDENTITY identity file for public key authentication\n"
" -c CIPHER cipher spec\n"
" -M HMAC hmac spec\n"
@@ -207,7 +209,7 @@ int main(int argc, char **argv)
memset(&o, 0, sizeof(o));
o.severity = MSCP_SEVERITY_WARN;
- while ((ch = getopt(argc, argv, "n:m:u:s:S:a:b:vqDrl:p:i:c:M:C:HdNh")) != -1) {
+ while ((ch = getopt(argc, argv, "n:m:u:s:S:a:b:vqDrl:p:i:F:c:M:C:HdNh")) != -1) {
switch (ch) {
case 'n':
o.nr_threads = atoi(optarg);
@@ -261,6 +263,9 @@ int main(int argc, char **argv)
}
strncpy(s.port, optarg, MSCP_SSH_MAX_PORT_STR);
break;
+ case 'F':
+ strncpy(s.config, optarg, PATH_MAX - 1);
+ break;
case 'i':
if (strlen(optarg) > MSCP_SSH_MAX_IDENTITY_PATH - 1) {
fprintf(stderr, "long identity path: %s\n", optarg);
diff --git a/src/pymscp.c b/src/pymscp.c
index 1a55a3d..0d92df4 100644
--- a/src/pymscp.c
+++ b/src/pymscp.c
@@ -103,6 +103,7 @@ static PyObject *wrap_mscp_init(PyObject *self, PyObject *args, PyObject *kw)
/* mscp_ssh_opts */
"login_name", /* const char * */
"port", /* const char * */
+ "config", /* const char * */
"identity", /* const char * */
"cipher", /* const char * */
@@ -116,9 +117,9 @@ static PyObject *wrap_mscp_init(PyObject *self, PyObject *args, PyObject *kw)
"enable_nagle", /* bool */
NULL,
};
- const char *fmt = "si" "|" "ii" "kkk" "s" "iii" "sss" "sssss" "ipp";
+ const char *fmt = "si" "|" "ii" "kkk" "s" "iii" "ssss" "sssss" "ipp";
char *coremask = NULL;
- char *login_name = NULL, *port = NULL, *identity = NULL;
+ char *login_name = NULL, *port = NULL, *config = NULL, *identity = NULL;
char *cipher = NULL, *hmac = NULL, *compress = NULL;
char *password = NULL, *passphrase = NULL;
@@ -148,6 +149,7 @@ static PyObject *wrap_mscp_init(PyObject *self, PyObject *args, PyObject *kw)
&i->mo.msg_fd,
&login_name,
&port,
+ &config,
&identity,
&cipher,
&hmac,
@@ -167,6 +169,8 @@ static PyObject *wrap_mscp_init(PyObject *self, PyObject *args, PyObject *kw)
strncpy(i->so.login_name, login_name, MSCP_SSH_MAX_LOGIN_NAME - 1);
if (port)
strncpy(i->so.port, port, MSCP_SSH_MAX_PORT_STR - 1);
+ if (config)
+ strncpy(i->so.config, config, PATH_MAX - 1);
if (identity)
strncpy(i->so.identity, identity, MSCP_SSH_MAX_IDENTITY_PATH - 1);
if (cipher)
diff --git a/src/ssh.c b/src/ssh.c
index e4d0d75..29f9623 100644
--- a/src/ssh.c
+++ b/src/ssh.c
@@ -73,6 +73,12 @@ static int ssh_set_opts(ssh_session ssh, struct mscp_ssh_opts *opts)
}
}
+ if (is_specified(opts->config) &&
+ ssh_options_parse_config(ssh, opts->config) < 0) {
+ mscp_set_error("failed to parse ssh_config: %s", opts->config);
+ return -1;
+ }
+
return 0;
}
@@ -149,14 +155,14 @@ static ssh_session ssh_init_session(const char *sshdst, struct mscp_ssh_opts *op
cb.userdata = opts;
ssh_set_callbacks(ssh, &cb);
- if (ssh_set_opts(ssh, opts) != 0)
- goto free_out;
-
if (ssh_options_set(ssh, SSH_OPTIONS_HOST, sshdst) != SSH_OK) {
mscp_set_error("failed to set destination host");
goto free_out;
}
+ if (ssh_set_opts(ssh, opts) != 0)
+ goto free_out;
+
if (ssh_connect(ssh) != SSH_OK) {
mscp_set_error("failed to connect ssh server: %s", ssh_get_error(ssh));
goto free_out;