mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-09 09:54:25 +09:00
First implementation of known_hosts with port read
This commit is contained in:
@@ -51,6 +51,7 @@ int ssh_list_append(struct ssh_list *list, const void *data);
|
|||||||
int ssh_list_prepend(struct ssh_list *list, const void *data);
|
int ssh_list_prepend(struct ssh_list *list, const void *data);
|
||||||
void ssh_list_remove(struct ssh_list *list, struct ssh_iterator *iterator);
|
void ssh_list_remove(struct ssh_list *list, struct ssh_iterator *iterator);
|
||||||
char *ssh_lowercase(const char* str);
|
char *ssh_lowercase(const char* str);
|
||||||
|
char *ssh_hostport(const char *host, int port);
|
||||||
|
|
||||||
const void *_ssh_list_pop_head(struct ssh_list *list);
|
const void *_ssh_list_pop_head(struct ssh_list *list);
|
||||||
|
|
||||||
|
|||||||
@@ -1594,6 +1594,7 @@ int ssh_is_server_known(ssh_session session) {
|
|||||||
FILE *file = NULL;
|
FILE *file = NULL;
|
||||||
char **tokens;
|
char **tokens;
|
||||||
char *host;
|
char *host;
|
||||||
|
char *hostport;
|
||||||
const char *type;
|
const char *type;
|
||||||
int match;
|
int match;
|
||||||
int ret = SSH_SERVER_NOT_KNOWN;
|
int ret = SSH_SERVER_NOT_KNOWN;
|
||||||
@@ -1617,8 +1618,11 @@ int ssh_is_server_known(ssh_session session) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
host = ssh_lowercase(session->host);
|
host = ssh_lowercase(session->host);
|
||||||
if (host == NULL) {
|
hostport = ssh_hostport(host,session->port);
|
||||||
ssh_set_error(session, SSH_FATAL, "Not enough space!");
|
if (host == NULL || hostport == NULL) {
|
||||||
|
ssh_set_error_oom(session);
|
||||||
|
SAFE_FREE(host);
|
||||||
|
SAFE_FREE(hostport);
|
||||||
leave_function();
|
leave_function();
|
||||||
return SSH_SERVER_ERROR;
|
return SSH_SERVER_ERROR;
|
||||||
}
|
}
|
||||||
@@ -1632,10 +1636,12 @@ int ssh_is_server_known(ssh_session session) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
match = match_hashed_host(session, host, tokens[0]);
|
match = match_hashed_host(session, host, tokens[0]);
|
||||||
|
if (match == 0){
|
||||||
|
match = match_hostname(hostport, tokens[0], strlen(tokens[0]));
|
||||||
|
}
|
||||||
if (match == 0) {
|
if (match == 0) {
|
||||||
match = match_hostname(host, tokens[0], strlen(tokens[0]));
|
match = match_hostname(host, tokens[0], strlen(tokens[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (match) {
|
if (match) {
|
||||||
/* We got a match. Now check the key type */
|
/* We got a match. Now check the key type */
|
||||||
if (strcmp(session->current_crypto->server_pubkey_type, type) != 0) {
|
if (strcmp(session->current_crypto->server_pubkey_type, type) != 0) {
|
||||||
@@ -1671,6 +1677,7 @@ int ssh_is_server_known(ssh_session session) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SAFE_FREE(host);
|
SAFE_FREE(host);
|
||||||
|
SAFE_FREE(hostport);
|
||||||
if (file != NULL) {
|
if (file != NULL) {
|
||||||
fclose(file);
|
fclose(file);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -140,6 +140,20 @@ char *ssh_lowercase(const char* str) {
|
|||||||
return new;
|
return new;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *ssh_hostport(const char *host, int port){
|
||||||
|
char *dest;
|
||||||
|
size_t len;
|
||||||
|
if(host==NULL)
|
||||||
|
return NULL;
|
||||||
|
/* 3 for []:, 5 for 65536 and 1 for nul */
|
||||||
|
len=strlen(host) + 3 + 5 + 1;
|
||||||
|
dest=malloc(len);
|
||||||
|
if(dest==NULL)
|
||||||
|
return NULL;
|
||||||
|
snprintf(dest,len,"[%s]:%d",host,port);
|
||||||
|
return dest;
|
||||||
|
}
|
||||||
|
|
||||||
char *ssh_get_user_home_dir(void) {
|
char *ssh_get_user_home_dir(void) {
|
||||||
char *szPath = NULL;
|
char *szPath = NULL;
|
||||||
struct passwd pwd;
|
struct passwd pwd;
|
||||||
|
|||||||
Reference in New Issue
Block a user