[Qemu-devel] [PATCH 3/4] configure: Improve checking libssh version is 0.8

Philippe Mathieu-Daudé posted 4 patches 5 weeks ago
Maintainers: Kevin Wolf <kwolf@redhat.com>, Max Reitz <mreitz@redhat.com>, "Richard W.M. Jones" <rjones@redhat.com>

[Qemu-devel] [PATCH 3/4] configure: Improve checking libssh version is 0.8

Posted by Philippe Mathieu-Daudé 5 weeks ago
To figure out which libssh version is installed, checking for
ssh_get_server_publickey() is not sufficient.

ssh_get_server_publickey() has been introduced in libssh
commit bbd052202 (predating 0.8) but distributions also
backported other pre-0.8 patches, such libssh commit
963c46e4f which introduce the ssh_known_hosts_e enum.

Check the enum is available to assume the version is 0.8.

This fixes build failure on Ubuntu 18.04:

    CC      block/ssh.o
  block/ssh.c: In function 'check_host_key_knownhosts':
  block/ssh.c:281:28: error: storage size of 'state' isn't known
       enum ssh_known_hosts_e state;
                              ^~~~~
  rules.mak:69: recipe for target 'block/ssh.o' failed
  make: *** [block/ssh.o] Error 1

Reported-by: 周文青 <1151451036@qq.com>
Fixes: https://bugs.launchpad.net/qemu/+bug/1838763
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 configure | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/configure b/configure
index fe3fef9309..040aa8eb6c 100755
--- a/configure
+++ b/configure
@@ -3949,18 +3949,24 @@ fi
 if test "$libssh" = "yes"; then
   cat > $TMPC <<EOF
 #include <libssh/libssh.h>
+#ifdef HAVE_LIBSSH_0_8
+static const enum ssh_known_hosts_e val = SSH_KNOWN_HOSTS_OK;
+#endif
 #ifdef HAVE_SSH_GET_SERVER_PUBLICKEY
 int main(void) { return ssh_get_server_publickey(NULL, NULL); }
 #else
 int main(void) { return ssh_get_publickey(NULL, NULL); }
 #endif
 EOF
-  if compile_object "$libssh_cflags"; then
+  if compile_object "$libssh_cflags -DHAVE_LIBSSH_0_8"; then
     libssh_cflags="-DHAVE_LIBSSH_0_8 $libssh_cflags"
   fi
   if compile_object "$libssh_cflags -DHAVE_SSH_GET_SERVER_PUBLICKEY"; then
     libssh_cflags="-DHAVE_SSH_GET_SERVER_PUBLICKEY $libssh_cflags"
   fi
+  if ! compile_object "$libssh_cflags"; then
+    error_exit "cannot use with libssh (is it broken?)"
+  fi
 fi
 
 ##########################################
-- 
2.20.1


Re: [Qemu-devel] [PATCH 3/4] configure: Improve checking libssh version is 0.8

Posted by Pino Toscano 5 weeks ago
On Wednesday, 14 August 2019 14:15:26 CEST Philippe Mathieu-Daudé wrote:
> To figure out which libssh version is installed, checking for
> ssh_get_server_publickey() is not sufficient.
> 
> ssh_get_server_publickey() has been introduced in libssh
> commit bbd052202 (predating 0.8) but distributions also
> backported other pre-0.8 patches, such libssh commit
> 963c46e4f which introduce the ssh_known_hosts_e enum.
> 
> Check the enum is available to assume the version is 0.8.
> 
> This fixes build failure on Ubuntu 18.04:
> 
>     CC      block/ssh.o
>   block/ssh.c: In function 'check_host_key_knownhosts':
>   block/ssh.c:281:28: error: storage size of 'state' isn't known
>        enum ssh_known_hosts_e state;
>                               ^~~~~
>   rules.mak:69: recipe for target 'block/ssh.o' failed
>   make: *** [block/ssh.o] Error 1
> 
> Reported-by: 周文青 <1151451036@qq.com>
> Fixes: https://bugs.launchpad.net/qemu/+bug/1838763
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
>  configure | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/configure b/configure
> index fe3fef9309..040aa8eb6c 100755
> --- a/configure
> +++ b/configure
> @@ -3949,18 +3949,24 @@ fi
>  if test "$libssh" = "yes"; then
>    cat > $TMPC <<EOF
>  #include <libssh/libssh.h>
> +#ifdef HAVE_LIBSSH_0_8
> +static const enum ssh_known_hosts_e val = SSH_KNOWN_HOSTS_OK;
> +#endif
>  #ifdef HAVE_SSH_GET_SERVER_PUBLICKEY
>  int main(void) { return ssh_get_server_publickey(NULL, NULL); }
>  #else
>  int main(void) { return ssh_get_publickey(NULL, NULL); }
>  #endif
>  EOF
> -  if compile_object "$libssh_cflags"; then
> +  if compile_object "$libssh_cflags -DHAVE_LIBSSH_0_8"; then
>      libssh_cflags="-DHAVE_LIBSSH_0_8 $libssh_cflags"
>    fi
>    if compile_object "$libssh_cflags -DHAVE_SSH_GET_SERVER_PUBLICKEY"; then
>      libssh_cflags="-DHAVE_SSH_GET_SERVER_PUBLICKEY $libssh_cflags"
>    fi
> +  if ! compile_object "$libssh_cflags"; then
> +    error_exit "cannot use with libssh (is it broken?)"
> +  fi

Ugh no, this is way more twisted and complex than really needed.

Instead, just add another build time check for
ssh_session_is_known_server, and change check_host_key_knownhosts to
use it only when found.

-- 
Pino Toscano