On Tue, May 01, 2018 at 13:21:15 -0300, Julio Faracco wrote:
After 0.7.5 release, libssh deprecated ssh_get_publickey() method to
introduce ssh_get_server_publickey(). This commit check the current
version of libssh and use the proper method during the compilation.
See the error:
make[3]: Entering directory '/home/julio/Desktop/virt/libvirt/src'
CC rpc/libvirt_net_rpc_la-virnetlibsshsession.lo
rpc/virnetlibsshsession.c:217:9: error: 'ssh_get_publickey' is deprecated
[-Werror,-Wdeprecated-declarations]
if (ssh_get_publickey(sess->session, &key) != SSH_OK) {
^
/usr/include/libssh/libssh.h:489:1: note: 'ssh_get_publickey' has been explicitly
marked deprecated here
SSH_DEPRECATED LIBSSH_API int ssh_get_publickey(ssh_session session, ssh_key *key);
^
/usr/include/libssh/libssh.h:99:40: note: expanded from macro 'SSH_DEPRECATED'
^
1 error generated.
Makefile:8604: recipe for target 'rpc/libvirt_net_rpc_la-virnetlibsshsession.lo'
failed
Signed-off-by: Julio Faracco <jcfaracco(a)gmail.com>
---
src/rpc/virnetlibsshsession.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/rpc/virnetlibsshsession.c b/src/rpc/virnetlibsshsession.c
index 309e8a9340..96c5bc0882 100644
--- a/src/rpc/virnetlibsshsession.c
+++ b/src/rpc/virnetlibsshsession.c
@@ -214,7 +214,11 @@ virLibsshServerKeyAsString(virNetLibsshSessionPtr sess)
size_t keyhashlen;
char *str;
+#if LIBSSH_VERSION_INT > 0x0705 /* 0.7.5 */
+ if (ssh_get_server_publickey(sess->session, &key) != SSH_OK) {
+#else
if (ssh_get_publickey(sess->session, &key) != SSH_OK) {
+#endif
virReportError(VIR_ERR_LIBSSH, "%s",
_("failed to get the key of the current "
"session"));
How about making it easier to read and harder to mess up:
#if LIBSSH_VERSION_INT > 0x0705 /* 0.7.5 */
rc = ssh_get_server_publickey(sess->session, &key);
#else
rc = ssh_get_publickey(sess->session, &key);
#endif
if (rc != SSH_OK) {
...
}
Jirka