mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-07-29 13:01:13 +03:00
Allow example client and server to process different configuration files
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
committed by
Andreas Schneider
parent
08a70bb474
commit
b88aa98550
@ -165,6 +165,14 @@ static struct argp_option options[] = {
|
|||||||
.doc = "Get verbose output.",
|
.doc = "Get verbose output.",
|
||||||
.group = 0
|
.group = 0
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
.name = "config",
|
||||||
|
.key = 'f',
|
||||||
|
.arg = "FILE",
|
||||||
|
.flags = 0,
|
||||||
|
.doc = "Configuration file to use.",
|
||||||
|
.group = 0
|
||||||
|
},
|
||||||
{NULL, 0, NULL, 0, NULL, 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':
|
case 'v':
|
||||||
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_LOG_VERBOSITY_STR, "3");
|
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_LOG_VERBOSITY_STR, "3");
|
||||||
break;
|
break;
|
||||||
|
case 'f':
|
||||||
|
ssh_bind_options_parse_config(sshbind, arg);
|
||||||
|
break;
|
||||||
case ARGP_KEY_ARG:
|
case ARGP_KEY_ARG:
|
||||||
if (state->arg_num >= 1) {
|
if (state->arg_num >= 1) {
|
||||||
/* Too many arguments. */
|
/* Too many arguments. */
|
||||||
|
@ -44,9 +44,10 @@
|
|||||||
#include "examples_common.h"
|
#include "examples_common.h"
|
||||||
#define MAXCMD 10
|
#define MAXCMD 10
|
||||||
|
|
||||||
static char *host;
|
static char *host = NULL;
|
||||||
static char *user;
|
static char *user = NULL;
|
||||||
static char *cmds[MAXCMD];
|
static char *cmds[MAXCMD];
|
||||||
|
static char *config_file = NULL;
|
||||||
static struct termios terminal;
|
static struct termios terminal;
|
||||||
|
|
||||||
static char *pcap_file = NULL;
|
static char *pcap_file = NULL;
|
||||||
@ -94,6 +95,7 @@ static void usage(void)
|
|||||||
" -p port : connect to port\n"
|
" -p port : connect to port\n"
|
||||||
" -d : use DSS to verify host public key\n"
|
" -d : use DSS to verify host public key\n"
|
||||||
" -r : use RSA 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
|
#ifdef WITH_PCAP
|
||||||
" -P file : create a pcap debugging file\n"
|
" -P file : create a pcap debugging file\n"
|
||||||
#endif
|
#endif
|
||||||
@ -110,11 +112,14 @@ static int opts(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
while((i = getopt(argc,argv,"T:P:")) != -1) {
|
while((i = getopt(argc,argv,"T:P:F:")) != -1) {
|
||||||
switch(i){
|
switch(i){
|
||||||
case 'P':
|
case 'P':
|
||||||
pcap_file = optarg;
|
pcap_file = optarg;
|
||||||
break;
|
break;
|
||||||
|
case 'F':
|
||||||
|
config_file = optarg;
|
||||||
|
break;
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
case 'T':
|
case 'T':
|
||||||
proxycommand = optarg;
|
proxycommand = optarg;
|
||||||
@ -326,7 +331,7 @@ static int client(ssh_session session)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ssh_options_set(session, SSH_OPTIONS_HOST ,host) < 0) {
|
if (ssh_options_set(session, SSH_OPTIONS_HOST, host) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (proxycommand != NULL) {
|
if (proxycommand != NULL) {
|
||||||
@ -334,7 +339,13 @@ static int client(ssh_session session)
|
|||||||
return -1;
|
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)) {
|
if (ssh_connect(session)) {
|
||||||
fprintf(stderr, "Connection failed : %s\n", ssh_get_error(session));
|
fprintf(stderr, "Connection failed : %s\n", ssh_get_error(session));
|
||||||
|
Reference in New Issue
Block a user