mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-11-29 01:03:57 +03:00
misc: reindent ssh_analyze_banner, update docs
No changes to code, only whitespace indentation and an update to the function docs. Signed-off-by: Jon Simons <jon@jonsimons.org> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
committed by
Andreas Schneider
parent
14d8e940e6
commit
a97db12f4f
158
src/misc.c
158
src/misc.c
@@ -780,8 +780,7 @@ char *ssh_path_expand_escape(ssh_session session, const char *s) {
|
|||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*
|
*
|
||||||
* @brief Analyze the SSH banner to find out if we have a SSHv1 or SSHv2
|
* @brief Analyze the SSH banner to extract version information.
|
||||||
* server.
|
|
||||||
*
|
*
|
||||||
* @param session The session to analyze the banner from.
|
* @param session The session to analyze the banner from.
|
||||||
* @param server 0 means we are a client, 1 a server.
|
* @param server 0 means we are a client, 1 a server.
|
||||||
@@ -790,95 +789,94 @@ char *ssh_path_expand_escape(ssh_session session, const char *s) {
|
|||||||
*
|
*
|
||||||
* @return 0 on success, < 0 on error.
|
* @return 0 on success, < 0 on error.
|
||||||
*
|
*
|
||||||
* @see ssh_get_banner()
|
* @see ssh_get_issue_banner()
|
||||||
*/
|
*/
|
||||||
int ssh_analyze_banner(ssh_session session, int server, int *ssh1, int *ssh2) {
|
int ssh_analyze_banner(ssh_session session, int server, int *ssh1, int *ssh2) {
|
||||||
const char *banner;
|
const char *banner;
|
||||||
const char *openssh;
|
const char *openssh;
|
||||||
|
|
||||||
if (server) {
|
if (server) {
|
||||||
banner = session->clientbanner;
|
banner = session->clientbanner;
|
||||||
} else {
|
} else {
|
||||||
banner = session->serverbanner;
|
banner = session->serverbanner;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (banner == NULL) {
|
if (banner == NULL) {
|
||||||
ssh_set_error(session, SSH_FATAL, "Invalid banner");
|
ssh_set_error(session, SSH_FATAL, "Invalid banner");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Typical banners e.g. are:
|
* Typical banners e.g. are:
|
||||||
*
|
*
|
||||||
* SSH-1.5-openSSH_5.4
|
* SSH-1.5-openSSH_5.4
|
||||||
* SSH-1.99-openSSH_3.0
|
* SSH-1.99-openSSH_3.0
|
||||||
*
|
*
|
||||||
* SSH-2.0-something
|
* SSH-2.0-something
|
||||||
* 012345678901234567890
|
* 012345678901234567890
|
||||||
*/
|
*/
|
||||||
if (strlen(banner) < 6 ||
|
if (strlen(banner) < 6 ||
|
||||||
strncmp(banner, "SSH-", 4) != 0) {
|
strncmp(banner, "SSH-", 4) != 0) {
|
||||||
ssh_set_error(session, SSH_FATAL, "Protocol mismatch: %s", banner);
|
ssh_set_error(session, SSH_FATAL, "Protocol mismatch: %s", banner);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSH_LOG(SSH_LOG_RARE, "Analyzing banner: %s", banner);
|
SSH_LOG(SSH_LOG_RARE, "Analyzing banner: %s", banner);
|
||||||
|
|
||||||
switch(banner[4]) {
|
switch (banner[4]) {
|
||||||
case '1':
|
case '1':
|
||||||
*ssh1 = 1;
|
*ssh1 = 1;
|
||||||
if (strlen(banner) > 6) {
|
if (strlen(banner) > 6) {
|
||||||
if (banner[6] == '9') {
|
if (banner[6] == '9') {
|
||||||
|
*ssh2 = 1;
|
||||||
|
} else {
|
||||||
|
*ssh2 = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case '2':
|
||||||
|
*ssh1 = 0;
|
||||||
*ssh2 = 1;
|
*ssh2 = 1;
|
||||||
} else {
|
break;
|
||||||
*ssh2 = 0;
|
default:
|
||||||
}
|
ssh_set_error(session, SSH_FATAL, "Protocol mismatch: %s", banner);
|
||||||
}
|
return -1;
|
||||||
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");
|
openssh = strstr(banner, "OpenSSH");
|
||||||
if (openssh != NULL) {
|
if (openssh != NULL) {
|
||||||
unsigned int major, minor;
|
unsigned int major, minor;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The banner is typical:
|
* The banner is typical:
|
||||||
* OpenSSH_5.4
|
* OpenSSH_5.4
|
||||||
* 012345678901234567890
|
* 012345678901234567890
|
||||||
*/
|
*/
|
||||||
if (strlen(openssh) > 9) {
|
if (strlen(openssh) > 9) {
|
||||||
major = strtoul(openssh + 8, (char **) NULL, 10);
|
major = strtoul(openssh + 8, (char **) NULL, 10);
|
||||||
if (major < 1 || major > 100) {
|
if (major < 1 || major > 100) {
|
||||||
ssh_set_error(session,
|
ssh_set_error(session,
|
||||||
SSH_FATAL,
|
SSH_FATAL,
|
||||||
"Invalid major version number: %s",
|
"Invalid major version number: %s",
|
||||||
banner);
|
banner);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
minor = strtoul(openssh + 10, (char **) NULL, 10);
|
minor = strtoul(openssh + 10, (char **) NULL, 10);
|
||||||
if (minor > 100) {
|
if (minor > 100) {
|
||||||
ssh_set_error(session,
|
ssh_set_error(session,
|
||||||
SSH_FATAL,
|
SSH_FATAL,
|
||||||
"Invalid minor version number: %s",
|
"Invalid minor version number: %s",
|
||||||
banner);
|
banner);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
session->openssh = SSH_VERSION_INT(major, minor, 0);
|
session->openssh = SSH_VERSION_INT(major, minor, 0);
|
||||||
SSH_LOG(SSH_LOG_RARE,
|
SSH_LOG(SSH_LOG_RARE,
|
||||||
"We are talking to an OpenSSH client version: %d.%d (%x)",
|
"We are talking to an OpenSSH client version: %d.%d (%x)",
|
||||||
major, minor, session->openssh);
|
major, minor, session->openssh);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* try the Monotonic clock if possible for perfs reasons */
|
/* try the Monotonic clock if possible for perfs reasons */
|
||||||
|
|||||||
Reference in New Issue
Block a user