Modify for avoid deprecated functions of libssh
ssh_get_publickey() becomes deprecated function from libssh 0.8.0.
ssh_get_publickey() and ssh_write_knownhost() become deprecated
functions from libssh 0.9.0.
diff --git a/src/session_client_ssh.c b/src/session_client_ssh.c
index f5bd61f..6bad75d 100644
--- a/src/session_client_ssh.c
+++ b/src/session_client_ssh.c
@@ -273,7 +273,12 @@
sshauth_hostkey_check(const char *hostname, ssh_session session, void *UNUSED(priv))
{
char *hexa = NULL;
+#if (LIBSSH_VERSION_INT >= SSH_VERSION_INT(0, 9, 0))
+ int c, ret;
+ enum ssh_known_hosts_e state;
+#else
int c, state, ret;
+#endif
ssh_key srv_pubkey;
unsigned char *hash_sha1 = NULL;
size_t hlen;
@@ -281,9 +286,17 @@
char answer[5];
FILE *out = NULL, *in = NULL;
+#if (LIBSSH_VERSION_INT >= SSH_VERSION_INT(0, 9, 0))
+ state = ssh_session_is_known_server(session);
+#else
state = ssh_is_server_known(session);
+#endif
+#if (LIBSSH_VERSION_INT >= SSH_VERSION_INT(0, 8, 0))
+ ret = ssh_get_server_publickey(session, &srv_pubkey);
+#else
ret = ssh_get_publickey(session, &srv_pubkey);
+#endif
if (ret < 0) {
ERR("Unable to get server public key.");
return -1;
@@ -300,22 +313,42 @@
hexa = ssh_get_hexa(hash_sha1, hlen);
switch (state) {
+#if (LIBSSH_VERSION_INT >= SSH_VERSION_INT(0, 9, 0))
+ case SSH_KNOWN_HOSTS_OK:
+#else
case SSH_SERVER_KNOWN_OK:
+#endif
break; /* ok */
+#if (LIBSSH_VERSION_INT >= SSH_VERSION_INT(0, 9, 0))
+ case SSH_KNOWN_HOSTS_CHANGED:
+#else
case SSH_SERVER_KNOWN_CHANGED:
+#endif
ERR("Remote host key changed, the connection will be terminated!");
goto error;
+#if (LIBSSH_VERSION_INT >= SSH_VERSION_INT(0, 9, 0))
+ case SSH_KNOWN_HOSTS_OTHER:
+#else
case SSH_SERVER_FOUND_OTHER:
+#endif
WRN("Remote host key is not known, but a key of another type for this host is known. Continue with caution.");
goto hostkey_not_known;
+#if (LIBSSH_VERSION_INT >= SSH_VERSION_INT(0, 9, 0))
+ case SSH_KNOWN_HOSTS_NOT_FOUND:
+#else
case SSH_SERVER_FILE_NOT_FOUND:
+#endif
WRN("Could not find the known hosts file.");
goto hostkey_not_known;
+#if (LIBSSH_VERSION_INT >= SSH_VERSION_INT(0, 9, 0))
+ case SSH_KNOWN_HOSTS_UNKNOWN:
+#else
case SSH_SERVER_NOT_KNOWN:
+#endif
hostkey_not_known:
#ifdef ENABLE_DNSSEC
if ((srv_pubkey_type != SSH_KEYTYPE_UNKNOWN) || (srv_pubkey_type != SSH_KEYTYPE_RSA1)) {
@@ -330,7 +363,11 @@
/* DNSSEC SSHFP check successful, that's enough */
if (!ret) {
VRB("DNSSEC SSHFP check successful.");
+#if (LIBSSH_VERSION_INT >= SSH_VERSION_INT(0, 9, 0))
+ ssh_session_update_known_hosts(session);
+#else
ssh_write_knownhost(session);
+#endif
ssh_clean_pubkey_hash(&hash_sha1);
ssh_string_free_char(hexa);
return 0;
@@ -385,7 +422,11 @@
fflush(in);
if (!strcmp("yes", answer)) {
/* store the key into the host file */
+#if (LIBSSH_VERSION_INT >= SSH_VERSION_INT(0, 9, 0))
+ ret = ssh_session_update_known_hosts(session);
+#else
ret = ssh_write_knownhost(session);
+#endif
if (ret != SSH_OK) {
WRN("Adding the known host \"%s\" failed (%s).", hostname, ssh_get_error(session));
}
@@ -401,7 +442,11 @@
break;
+#if (LIBSSH_VERSION_INT >= SSH_VERSION_INT(0, 9, 0))
+ case SSH_KNOWN_HOSTS_ERROR:
+#else
case SSH_SERVER_ERROR:
+#endif
ERR("SSH error: %s", ssh_get_error(session));
goto error;
}