From 798a808a2bddec9a64dd29df9f03de8e81ea6d95 Mon Sep 17 00:00:00 2001 From: Alexander Lamaison Date: Fri, 21 May 2010 00:01:57 +0100 Subject: [PATCH] Change magic port number for generic knownhost check. libssh2_knownhost_checkp took 0 as a magic port number that indicated a 'generic' check should be performed. However, 0 is a valid port number in its own right so this commit changes the magic value to any negative int. --- docs/libssh2_knownhost_checkp.3 | 8 ++++---- src/knownhost.c | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/libssh2_knownhost_checkp.3 b/docs/libssh2_knownhost_checkp.3 index 45b0a1f2..b348e9d8 100644 --- a/docs/libssh2_knownhost_checkp.3 +++ b/docs/libssh2_knownhost_checkp.3 @@ -19,10 +19,10 @@ and returns info back about the (partially) matched entry. \fIhost\fP is a pointer the host name in plain text. The host name can be the IP numerical address of the host or the full name. -\fIport\fP is the port number used by the host (or 0 to check the generic -host). If the port number is given, libssh2 will check the key for the -specific host + port number combination in addition to the plain host name -only check. +\fIport\fP is the port number used by the host (or a negative number +to check the generic host). If the port number is given, libssh2 will +check the key for the specific host + port number combination in +addition to the plain host name only check. \fIkey\fP is a pointer to the key for the given host. diff --git a/src/knownhost.c b/src/knownhost.c index d3eba673..29f1a1d0 100644 --- a/src/knownhost.c +++ b/src/knownhost.c @@ -366,7 +366,7 @@ knownhost_check(LIBSSH2_KNOWNHOSTS *hosts, /* if a port number is given, check for a '[host]:port' first before the plain 'host' */ - if(port) { + if(port >= 0) { snprintf(hostbuff, sizeof(hostbuff), "[%s]:%d", hostp, port); host = hostbuff; numcheck = 2; /* check both combos, start with this */ @@ -475,7 +475,7 @@ libssh2_knownhost_check(LIBSSH2_KNOWNHOSTS *hosts, int typemask, struct libssh2_knownhost **ext) { - return knownhost_check(hosts, hostp, 0, key, keylen, + return knownhost_check(hosts, hostp, -1, key, keylen, typemask, ext); } @@ -485,9 +485,9 @@ libssh2_knownhost_check(LIBSSH2_KNOWNHOSTS *hosts, * Check a host+port and its associated key against the collection of known * hosts. * - * Note that if 'port' is specified as non-zero, the check function will be - * able to check for a dedicated key for this particular host+port combo, and - * if 'port' is set to zero it only checks for the generic host key. + * Note that if 'port' is specified as greater than zero, the check function + * will be able to check for a dedicated key for this particular host+port + * combo, and if 'port' is negative it only checks for the generic host key. * * The typemask is the type/format of the given host name and key *