diff options
author | Dave Davenport <qball@gmpclient.org> | 2018-09-22 16:16:25 +0200 |
---|---|---|
committer | Dave Davenport <qball@gmpclient.org> | 2018-09-22 16:16:25 +0200 |
commit | 114b2cf2fd05b17566cf635e02c4979731c20f52 (patch) | |
tree | a1c051cf9b7eedcd3360b120c6706fc64653b064 /source | |
parent | f888805ccd3c4bdc67311a547c4d72aa453d80a5 (diff) |
[SSH] Improve parser for known_hosts a bit.
Issue: #820
Diffstat (limited to 'source')
-rw-r--r-- | source/dialogs/ssh.c | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/source/dialogs/ssh.c b/source/dialogs/ssh.c index a3d2f84e..486cced1 100644 --- a/source/dialogs/ssh.c +++ b/source/dialogs/ssh.c @@ -148,15 +148,38 @@ static char **read_known_hosts_file ( char ** retv, unsigned int *length ) size_t buffer_length = 0; // Reading one line per time. while ( getline ( &buffer, &buffer_length, fd ) > 0 ) { - char *sep = strstr ( buffer, "," ); - - if ( sep != NULL ) { - *sep = '\0'; + // Strip whitespace. + char *start = g_strstrip(&(buffer[0])); + // Find start. + if ( *start == '#' || *start == '@' ){ + // skip comments or cert-authority or revoked items. + printf("Comment.\n"); + continue; + } + if ( *start == '|' ) { + // Skip hashed hostnames. + continue; + } + if ( *start == '[' ) { + // Don't support port versions yet, TODO + continue; + } + // Find end of hostname set. + char *end = strstr ( start, " " ); + if ( end == NULL ) { + // Something is wrong. + continue; + } + *end = '\0'; + char *sep = start; + start = strsep(&sep,", " ); + while ( start ) + { // Is this host name already in the list? // We often get duplicates in hosts file, so lets check this. int found = 0; for ( unsigned int j = 0; j < ( *length ); j++ ) { - if ( !g_ascii_strcasecmp ( buffer, retv[j] ) ) { + if ( !g_ascii_strcasecmp ( start, retv[j] ) ) { found = 1; break; } @@ -165,10 +188,11 @@ static char **read_known_hosts_file ( char ** retv, unsigned int *length ) if ( !found ) { // Add this host name to the list. retv = g_realloc ( retv, ( ( *length ) + 2 ) * sizeof ( char* ) ); - retv[( *length )] = g_strdup ( buffer ); + retv[( *length )] = g_strdup ( start ); retv[( *length ) + 1] = NULL; ( *length )++; } + start = strsep(&sep,", " ); } } if ( buffer != NULL ) { |