Improve and document ssh_get_banner().
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@483 7dcaeef0-15fb-0310-b436-a5af3365683c
Этот коммит содержится в:
родитель
1f1e9dc15b
Коммит
160f6a08d0
@ -33,36 +33,51 @@
|
|||||||
if (opt->connect_status_function) \
|
if (opt->connect_status_function) \
|
||||||
opt->connect_status_function(opt->connect_status_arg, status); \
|
opt->connect_status_function(opt->connect_status_arg, status); \
|
||||||
} while (0)
|
} while (0)
|
||||||
/* simply gets a banner from a socket */
|
|
||||||
|
|
||||||
char *ssh_get_banner(SSH_SESSION *session){
|
/**
|
||||||
char buffer[128];
|
* @internal
|
||||||
int i = 0;
|
*
|
||||||
char *ret;
|
* @brief Get a banner from a socket.
|
||||||
enter_function();
|
*
|
||||||
while (i < 127) {
|
* The caller has to free memroy.
|
||||||
if(ssh_socket_read(session->socket, &buffer[i], 1)!= SSH_OK){
|
*
|
||||||
ssh_set_error(session,SSH_FATAL,"Remote host closed connection");
|
* @param session The session to get the banner from.
|
||||||
leave_function();
|
*
|
||||||
return NULL;
|
* @return A newly allocated string with the banner or NULL on error.
|
||||||
}
|
*/
|
||||||
if (buffer[i] == '\r')
|
char *ssh_get_banner(SSH_SESSION *session) {
|
||||||
buffer[i] = 0;
|
char buffer[128] = {0};
|
||||||
if (buffer[i] == '\n') {
|
char *str = NULL;
|
||||||
buffer[i] = 0;
|
int i;
|
||||||
ret = strdup(buffer);
|
|
||||||
if (ret == NULL) {
|
enter_function();
|
||||||
leave_function();
|
|
||||||
return NULL;
|
for (i = 0; i < 127; i++) {
|
||||||
}
|
if (ssh_socket_read(session->socket, &buffer[i], 1) != SSH_OK) {
|
||||||
leave_function();
|
ssh_set_error(session, SSH_FATAL, "Remote host closed connection");
|
||||||
return ret;
|
leave_function();
|
||||||
}
|
return NULL;
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
ssh_set_error(session,SSH_FATAL,"Too large banner");
|
|
||||||
leave_function();
|
if (buffer[i] == '\r') {
|
||||||
return NULL;
|
buffer[i] = '\0';
|
||||||
|
}
|
||||||
|
if (buffer[i] == '\n') {
|
||||||
|
buffer[i] = '\0';
|
||||||
|
str = strdup(buffer);
|
||||||
|
if (str == NULL) {
|
||||||
|
leave_function();
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
leave_function();
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ssh_set_error(session, SSH_FATAL, "Too large banner");
|
||||||
|
|
||||||
|
leave_function();
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ssh_analyze_banner(SSH_SESSION *session, int *ssh1, int *ssh2){
|
static int ssh_analyze_banner(SSH_SESSION *session, int *ssh1, int *ssh2){
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user