aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/samplesshd-cb.c11
-rw-r--r--examples/ssh_client.c21
2 files changed, 27 insertions, 5 deletions
diff --git a/examples/samplesshd-cb.c b/examples/samplesshd-cb.c
index f93ab4b4..d2eef216 100644
--- a/examples/samplesshd-cb.c
+++ b/examples/samplesshd-cb.c
@@ -165,6 +165,14 @@ static struct argp_option options[] = {
.doc = "Get verbose output.",
.group = 0
},
+ {
+ .name = "config",
+ .key = 'f',
+ .arg = "FILE",
+ .flags = 0,
+ .doc = "Configuration file to use.",
+ .group = 0
+ },
{NULL, 0, NULL, 0, NULL, 0}
};
@@ -191,6 +199,9 @@ static error_t parse_opt (int key, char *arg, struct argp_state *state) {
case 'v':
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_LOG_VERBOSITY_STR, "3");
break;
+ case 'f':
+ ssh_bind_options_parse_config(sshbind, arg);
+ break;
case ARGP_KEY_ARG:
if (state->arg_num >= 1) {
/* Too many arguments. */
diff --git a/examples/ssh_client.c b/examples/ssh_client.c
index 54ecd30b..7304da85 100644
--- a/examples/ssh_client.c
+++ b/examples/ssh_client.c
@@ -44,9 +44,10 @@
#include "examples_common.h"
#define MAXCMD 10
-static char *host;
-static char *user;
+static char *host = NULL;
+static char *user = NULL;
static char *cmds[MAXCMD];
+static char *config_file = NULL;
static struct termios terminal;
static char *pcap_file = NULL;
@@ -94,6 +95,7 @@ static void usage(void)
" -p port : connect to port\n"
" -d : use DSS to verify host public key\n"
" -r : use RSA to verify host public key\n"
+ " -F file : parse configuration file instead of default one\n"
#ifdef WITH_PCAP
" -P file : create a pcap debugging file\n"
#endif
@@ -110,11 +112,14 @@ static int opts(int argc, char **argv)
{
int i;
- while((i = getopt(argc,argv,"T:P:")) != -1) {
+ while((i = getopt(argc,argv,"T:P:F:")) != -1) {
switch(i){
case 'P':
pcap_file = optarg;
break;
+ case 'F':
+ config_file = optarg;
+ break;
#ifndef _WIN32
case 'T':
proxycommand = optarg;
@@ -326,7 +331,7 @@ static int client(ssh_session session)
return -1;
}
}
- if (ssh_options_set(session, SSH_OPTIONS_HOST ,host) < 0) {
+ if (ssh_options_set(session, SSH_OPTIONS_HOST, host) < 0) {
return -1;
}
if (proxycommand != NULL) {
@@ -334,7 +339,13 @@ static int client(ssh_session session)
return -1;
}
}
- ssh_options_parse_config(session, NULL);
+ /* Parse configuration file if specified: The command-line options will
+ * overwrite items loaded from configuration file */
+ if (config_file != NULL) {
+ ssh_options_parse_config(session, config_file);
+ } else {
+ ssh_options_parse_config(session, NULL);
+ }
if (ssh_connect(session)) {
fprintf(stderr, "Connection failed : %s\n", ssh_get_error(session));