misc: Move ssh_analyze_banner to a common location.
Don't duplicate functions!
Этот коммит содержится в:
родитель
72b62d3064
Коммит
8b719e51cf
@ -30,6 +30,7 @@ int ssh_file_readaccess_ok(const char *file);
|
|||||||
|
|
||||||
char *ssh_path_expand_tilde(const char *d);
|
char *ssh_path_expand_tilde(const char *d);
|
||||||
char *ssh_path_expand_escape(ssh_session session, const char *s);
|
char *ssh_path_expand_escape(ssh_session session, const char *s);
|
||||||
|
int ssh_analyze_banner(ssh_session session, int *ssh1, int *ssh2);
|
||||||
|
|
||||||
/* macro for byte ordering */
|
/* macro for byte ordering */
|
||||||
uint64_t ntohll(uint64_t);
|
uint64_t ntohll(uint64_t);
|
||||||
|
65
src/client.c
65
src/client.c
@ -37,6 +37,8 @@
|
|||||||
#include "libssh/session.h"
|
#include "libssh/session.h"
|
||||||
#include "libssh/dh.h"
|
#include "libssh/dh.h"
|
||||||
#include "libssh/threads.h"
|
#include "libssh/threads.h"
|
||||||
|
#include "libssh/misc.h"
|
||||||
|
|
||||||
#define set_status(session, status) do {\
|
#define set_status(session, status) do {\
|
||||||
if (session->callbacks && session->callbacks->connect_status_function) \
|
if (session->callbacks && session->callbacks->connect_status_function) \
|
||||||
session->callbacks->connect_status_function(session->callbacks->userdata, status); \
|
session->callbacks->connect_status_function(session->callbacks->userdata, status); \
|
||||||
@ -114,69 +116,6 @@ static int callback_receive_banner(const void *data, size_t len, void *user) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @internal
|
|
||||||
*
|
|
||||||
* @brief Analyze the SSH banner to find out if we have a SSHv1 or SSHv2
|
|
||||||
* server.
|
|
||||||
*
|
|
||||||
* @param session The session to analyze the banner from.
|
|
||||||
* @param ssh1 The variable which is set if it is a SSHv1 server.
|
|
||||||
* @param ssh2 The variable which is set if it is a SSHv2 server.
|
|
||||||
*
|
|
||||||
* @return 0 on success, < 0 on error.
|
|
||||||
*
|
|
||||||
* @see ssh_get_banner()
|
|
||||||
*/
|
|
||||||
static int ssh_analyze_banner(ssh_session session, int *ssh1, int *ssh2) {
|
|
||||||
const char *banner = session->serverbanner;
|
|
||||||
const char *openssh;
|
|
||||||
|
|
||||||
ssh_log(session, SSH_LOG_RARE, "Analyzing banner: %s", banner);
|
|
||||||
|
|
||||||
if (strncmp(banner, "SSH-", 4) != 0) {
|
|
||||||
ssh_set_error(session, SSH_FATAL, "Protocol mismatch: %s", banner);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Typical banners e.g. are:
|
|
||||||
* SSH-1.5-blah
|
|
||||||
* SSH-1.99-blah
|
|
||||||
* SSH-2.0-blah
|
|
||||||
*/
|
|
||||||
switch(banner[4]) {
|
|
||||||
case '1':
|
|
||||||
*ssh1 = 1;
|
|
||||||
if (banner[6] == '9') {
|
|
||||||
*ssh2 = 1;
|
|
||||||
} else {
|
|
||||||
*ssh2 = 0;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case '2':
|
|
||||||
*ssh1 = 0;
|
|
||||||
*ssh2 = 1;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
ssh_set_error(session, SSH_FATAL, "Protocol mismatch: %s", banner);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
openssh = strstr(banner, "OpenSSH");
|
|
||||||
if (openssh != NULL) {
|
|
||||||
int major, minor;
|
|
||||||
major = strtol(openssh + 8, (char **) NULL, 10);
|
|
||||||
minor = strtol(openssh + 10, (char **) NULL, 10);
|
|
||||||
session->openssh = SSH_VERSION_INT(major, minor, 0);
|
|
||||||
ssh_log(session, SSH_LOG_RARE,
|
|
||||||
"We are talking to an OpenSSH server version: %d.%d (%x)",
|
|
||||||
major, minor, session->openssh);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @internal
|
/** @internal
|
||||||
* @brief Sends a SSH banner to the server.
|
* @brief Sends a SSH banner to the server.
|
||||||
*
|
*
|
||||||
|
63
src/misc.c
63
src/misc.c
@ -681,6 +681,69 @@ char *ssh_path_expand_escape(ssh_session session, const char *s) {
|
|||||||
#undef MAX_BUF_SIZE
|
#undef MAX_BUF_SIZE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*
|
||||||
|
* @brief Analyze the SSH banner to find out if we have a SSHv1 or SSHv2
|
||||||
|
* server.
|
||||||
|
*
|
||||||
|
* @param session The session to analyze the banner from.
|
||||||
|
* @param ssh1 The variable which is set if it is a SSHv1 server.
|
||||||
|
* @param ssh2 The variable which is set if it is a SSHv2 server.
|
||||||
|
*
|
||||||
|
* @return 0 on success, < 0 on error.
|
||||||
|
*
|
||||||
|
* @see ssh_get_banner()
|
||||||
|
*/
|
||||||
|
int ssh_analyze_banner(ssh_session session, int *ssh1, int *ssh2) {
|
||||||
|
const char *banner = session->clientbanner;
|
||||||
|
const char *openssh;
|
||||||
|
|
||||||
|
ssh_log(session, SSH_LOG_RARE, "Analyzing banner: %s", banner);
|
||||||
|
|
||||||
|
if (strncmp(banner, "SSH-", 4) != 0) {
|
||||||
|
ssh_set_error(session, SSH_FATAL, "Protocol mismatch: %s", banner);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Typical banners e.g. are:
|
||||||
|
* SSH-1.5-blah
|
||||||
|
* SSH-1.99-blah
|
||||||
|
* SSH-2.0-blah
|
||||||
|
*/
|
||||||
|
switch(banner[4]) {
|
||||||
|
case '1':
|
||||||
|
*ssh1 = 1;
|
||||||
|
if (banner[6] == '9') {
|
||||||
|
*ssh2 = 1;
|
||||||
|
} else {
|
||||||
|
*ssh2 = 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case '2':
|
||||||
|
*ssh1 = 0;
|
||||||
|
*ssh2 = 1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ssh_set_error(session, SSH_FATAL, "Protocol mismatch: %s", banner);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
openssh = strstr(banner, "OpenSSH");
|
||||||
|
if (openssh != NULL) {
|
||||||
|
int major, minor;
|
||||||
|
major = strtol(openssh + 8, (char **) NULL, 10);
|
||||||
|
minor = strtol(openssh + 10, (char **) NULL, 10);
|
||||||
|
session->openssh = SSH_VERSION_INT(major, minor, 0);
|
||||||
|
ssh_log(session, SSH_LOG_RARE,
|
||||||
|
"We are talking to an OpenSSH client version: %d.%d (%x)",
|
||||||
|
major, minor, session->openssh);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
/* vim: set ts=4 sw=4 et cindent: */
|
/* vim: set ts=4 sw=4 et cindent: */
|
||||||
|
64
src/server.c
64
src/server.c
@ -43,6 +43,7 @@
|
|||||||
#include "libssh/keys.h"
|
#include "libssh/keys.h"
|
||||||
#include "libssh/dh.h"
|
#include "libssh/dh.h"
|
||||||
#include "libssh/messages.h"
|
#include "libssh/messages.h"
|
||||||
|
#include "libssh/misc.h"
|
||||||
|
|
||||||
#define set_status(session, status) do {\
|
#define set_status(session, status) do {\
|
||||||
if (session->callbacks && session->callbacks->connect_status_function) \
|
if (session->callbacks && session->callbacks->connect_status_function) \
|
||||||
@ -411,69 +412,6 @@ static int dh_handshake_server(ssh_session session) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @internal
|
|
||||||
*
|
|
||||||
* @brief Analyze the SSH banner to find out if we have a SSHv1 or SSHv2
|
|
||||||
* server.
|
|
||||||
*
|
|
||||||
* @param session The session to analyze the banner from.
|
|
||||||
* @param ssh1 The variable which is set if it is a SSHv1 server.
|
|
||||||
* @param ssh2 The variable which is set if it is a SSHv2 server.
|
|
||||||
*
|
|
||||||
* @return 0 on success, < 0 on error.
|
|
||||||
*
|
|
||||||
* @see ssh_get_banner()
|
|
||||||
*/
|
|
||||||
static int ssh_analyze_banner(ssh_session session, int *ssh1, int *ssh2) {
|
|
||||||
const char *banner = session->clientbanner;
|
|
||||||
const char *openssh;
|
|
||||||
|
|
||||||
ssh_log(session, SSH_LOG_RARE, "Analyzing banner: %s", banner);
|
|
||||||
|
|
||||||
if (strncmp(banner, "SSH-", 4) != 0) {
|
|
||||||
ssh_set_error(session, SSH_FATAL, "Protocol mismatch: %s", banner);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Typical banners e.g. are:
|
|
||||||
* SSH-1.5-blah
|
|
||||||
* SSH-1.99-blah
|
|
||||||
* SSH-2.0-blah
|
|
||||||
*/
|
|
||||||
switch(banner[4]) {
|
|
||||||
case '1':
|
|
||||||
*ssh1 = 1;
|
|
||||||
if (banner[6] == '9') {
|
|
||||||
*ssh2 = 1;
|
|
||||||
} else {
|
|
||||||
*ssh2 = 0;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case '2':
|
|
||||||
*ssh1 = 0;
|
|
||||||
*ssh2 = 1;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
ssh_set_error(session, SSH_FATAL, "Protocol mismatch: %s", banner);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
openssh = strstr(banner, "OpenSSH");
|
|
||||||
if (openssh != NULL) {
|
|
||||||
int major, minor;
|
|
||||||
major = strtol(openssh + 8, (char **) NULL, 10);
|
|
||||||
minor = strtol(openssh + 10, (char **) NULL, 10);
|
|
||||||
session->openssh = SSH_VERSION_INT(major, minor, 0);
|
|
||||||
ssh_log(session, SSH_LOG_RARE,
|
|
||||||
"We are talking to an OpenSSH client version: %d.%d (%x)",
|
|
||||||
major, minor, session->openssh);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*
|
*
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user