commit:     6283f9180d0c4b97ebafe3676c0a23be23889391
Author:     Andreas Sturmlechner <asturm <AT> gentoo <DOT> org>
AuthorDate: Fri Jun  7 18:03:58 2024 +0000
Commit:     Andreas Sturmlechner <asturm <AT> gentoo <DOT> org>
CommitDate: Fri Jun  7 18:10:38 2024 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=6283f918

net-libs/libssh: Fix build w/ modern C, fix IPv6 regression

Closes: https://bugs.gentoo.org/932715
Signed-off-by: Andreas Sturmlechner <asturm <AT> gentoo.org>

 .../libssh-0.10.6-ipv6-hostname-parsing.patch      | 135 ++++++++++++++++++++
 .../libssh-0.10.6-libgcrypt-type-mismatches.patch  |  60 +++++++++
 net-libs/libssh/libssh-0.10.6-r1.ebuild            | 140 +++++++++++++++++++++
 3 files changed, 335 insertions(+)

diff --git a/net-libs/libssh/files/libssh-0.10.6-ipv6-hostname-parsing.patch 
b/net-libs/libssh/files/libssh-0.10.6-ipv6-hostname-parsing.patch
new file mode 100644
index 000000000000..4d62ca5e9459
--- /dev/null
+++ b/net-libs/libssh/files/libssh-0.10.6-ipv6-hostname-parsing.patch
@@ -0,0 +1,135 @@
+From 4f997aee7c7d7ea346b3e8ba505da0b7601ff318 Mon Sep 17 00:00:00 2001
+From: Jakub Jelen <[email protected]>
+Date: Fri, 22 Dec 2023 10:32:40 +0100
+Subject: [PATCH] Fix regression in IPv6 addresses in hostname parsing
+
+Signed-off-by: Jakub Jelen <[email protected]>
+Reviewed-by: Andreas Schneider <[email protected]>
+---
+ include/libssh/config_parser.h | 11 ++++++++---
+ src/config.c                   |  4 ++--
+ src/config_parser.c            | 16 +++++++++++-----
+ src/options.c                  | 10 ++--------
+ 4 files changed, 23 insertions(+), 18 deletions(-)
+
+diff --git a/include/libssh/config_parser.h b/include/libssh/config_parser.h
+index a7dd42a2c..ca353432b 100644
+--- a/include/libssh/config_parser.h
++++ b/include/libssh/config_parser.h
+@@ -30,6 +30,8 @@
+ extern "C" {
+ #endif
+ 
++#include <stdbool.h>
++
+ char *ssh_config_get_cmd(char **str);
+ 
+ char *ssh_config_get_token(char **str);
+@@ -49,14 +51,17 @@ int ssh_config_get_yesno(char **str, int notfound);
+  *                       be stored or NULL if we do not care about the result.
+  * @param[out]  port     Pointer to the location, where the new port will
+  *                       be stored or NULL if we do not care about the result.
++ * @param[in]   ignore_port Set to true if the we should not attempt to parse
++ *                       port number.
+  *
+  * @returns     SSH_OK if the provided string is in format of SSH URI,
+  *              SSH_ERROR on failure
+  */
+ int ssh_config_parse_uri(const char *tok,
+-        char **username,
+-        char **hostname,
+-        char **port);
++                         char **username,
++                         char **hostname,
++                         char **port,
++                         bool ignore_port);
+ 
+ #ifdef __cplusplus
+ }
+diff --git a/src/config.c b/src/config.c
+index 5eedbce96..7135c3b19 100644
+--- a/src/config.c
++++ b/src/config.c
+@@ -464,7 +464,7 @@ ssh_config_parse_proxy_jump(ssh_session session, const 
char *s, bool do_parsing)
+         }
+         if (parse_entry) {
+             /* We actually care only about the first item */
+-            rv = ssh_config_parse_uri(cp, &username, &hostname, &port);
++            rv = ssh_config_parse_uri(cp, &username, &hostname, &port, false);
+             /* The rest of the list needs to be passed on */
+             if (endp != NULL) {
+                 next = strdup(endp + 1);
+@@ -475,7 +475,7 @@ ssh_config_parse_proxy_jump(ssh_session session, const 
char *s, bool do_parsing)
+             }
+         } else {
+             /* The rest is just sanity-checked to avoid failures later */
+-            rv = ssh_config_parse_uri(cp, NULL, NULL, NULL);
++            rv = ssh_config_parse_uri(cp, NULL, NULL, NULL, false);
+         }
+         if (rv != SSH_OK) {
+             goto out;
+diff --git a/src/config_parser.c b/src/config_parser.c
+index 9ffc8b8b0..5f30cd3e1 100644
+--- a/src/config_parser.c
++++ b/src/config_parser.c
+@@ -162,9 +162,10 @@ int ssh_config_get_yesno(char **str, int notfound)
+ }
+ 
+ int ssh_config_parse_uri(const char *tok,
+-        char **username,
+-        char **hostname,
+-        char **port)
++                         char **username,
++                         char **hostname,
++                         char **port,
++                         bool ignore_port)
+ {
+     char *endp = NULL;
+     long port_n;
+@@ -210,12 +211,17 @@ int ssh_config_parse_uri(const char *tok,
+         if (endp == NULL) {
+             goto error;
+         }
+-    } else {
+-        /* Hostnames or aliases expand to the last colon or to the end */
++    } else if (!ignore_port) {
++        /* Hostnames or aliases expand to the last colon (if port is 
requested)
++         * or to the end */
+         endp = strrchr(tok, ':');
+         if (endp == NULL) {
+             endp = strchr(tok, '\0');
+         }
++    } else {
++        /* If no port is requested, expand to the end of line
++         * (to accommodate the IPv6 addresses) */
++        endp = strchr(tok, '\0');
+     }
+     if (tok == endp) {
+         /* Zero-length hostnames are not valid */
+diff --git a/src/options.c b/src/options.c
+index 2e73be462..676c49e7a 100644
+--- a/src/options.c
++++ b/src/options.c
+@@ -634,17 +634,11 @@ int ssh_options_set(ssh_session session, enum 
ssh_options_e type,
+                 ssh_set_error_invalid(session);
+                 return -1;
+             } else {
+-                char *username = NULL, *hostname = NULL, *port = NULL;
+-                rc = ssh_config_parse_uri(value, &username, &hostname, &port);
++                char *username = NULL, *hostname = NULL;
++                rc = ssh_config_parse_uri(value, &username, &hostname, NULL, 
true);
+                 if (rc != SSH_OK) {
+                     return -1;
+                 }
+-                if (port != NULL) {
+-                    SAFE_FREE(username);
+-                    SAFE_FREE(hostname);
+-                    SAFE_FREE(port);
+-                    return -1;
+-                }
+                 if (username != NULL) {
+                     SAFE_FREE(session->opts.username);
+                     session->opts.username = username;
+-- 
+GitLab
+

diff --git 
a/net-libs/libssh/files/libssh-0.10.6-libgcrypt-type-mismatches.patch 
b/net-libs/libssh/files/libssh-0.10.6-libgcrypt-type-mismatches.patch
new file mode 100644
index 000000000000..89e6d012240e
--- /dev/null
+++ b/net-libs/libssh/files/libssh-0.10.6-libgcrypt-type-mismatches.patch
@@ -0,0 +1,60 @@
+From c01377081fc60132fd3e256ad56eab6b329f5493 Mon Sep 17 00:00:00 2001
+From: Gerald Combs <[email protected]>
+Date: Thu, 1 Jun 2023 12:42:50 -0700
+Subject: [PATCH] libgcrypt.c: Fix type mismatches
+
+Fix
+
+    /build/libssh-0.10.5/src/libgcrypt.c:903:20: error: incompatible function 
pointer types initializing 'void (*)(struct ssh_cipher_struct *, void *, void 
*, size_t)' (aka 'void (*)(struct ssh_cipher_struct *, void *, void *, unsigned 
long long)') with an expression of type 'void (struct ssh_cipher_struct *, void 
*, void *, unsigned long)' [-Wincompatible-function-pointer-types]
+        .encrypt     = des3_encrypt,
+                       ^~~~~~~~~~~~
+    /build/libssh-0.10.5/src/libgcrypt.c:904:20: error: incompatible function 
pointer types initializing 'void (*)(struct ssh_cipher_struct *, void *, void 
*, size_t)' (aka 'void (*)(struct ssh_cipher_struct *, void *, void *, unsigned 
long long)') with an expression of type 'void (struct ssh_cipher_struct *, void 
*, void *, unsigned long)' [-Wincompatible-function-pointer-types]
+        .decrypt     = des3_decrypt
+                       ^~~~~~~~~~~~
+
+Fixes: #196
+
+Signed-off-by: Gerald Combs <[email protected]>
+Reviewed-by: Jakub Jelen <[email protected]>
+Reviewed-by: Norbert Pocs <[email protected]>
+---
+ src/libgcrypt.c | 8 ++++----
+ 1 file changed, 4 insertions(+), 4 deletions(-)
+
+diff --git a/src/libgcrypt.c b/src/libgcrypt.c
+index cea20370b..58f510954 100644
+--- a/src/libgcrypt.c
++++ b/src/libgcrypt.c
+@@ -198,12 +198,12 @@ static int blowfish_set_key(struct ssh_cipher_struct 
*cipher, void *key, void *I
+ }
+ 
+ static void blowfish_encrypt(struct ssh_cipher_struct *cipher, void *in,
+-    void *out, unsigned long len) {
++    void *out, size_t len) {
+   gcry_cipher_encrypt(cipher->key[0], out, len, in, len);
+ }
+ 
+ static void blowfish_decrypt(struct ssh_cipher_struct *cipher, void *in,
+-    void *out, unsigned long len) {
++    void *out, size_t len) {
+   gcry_cipher_decrypt(cipher->key[0], out, len, in, len);
+ }
+ #endif /* WITH_BLOWFISH_CIPHER */
+@@ -469,12 +469,12 @@ static int des3_set_key(struct ssh_cipher_struct 
*cipher, void *key, void *IV) {
+ }
+ 
+ static void des3_encrypt(struct ssh_cipher_struct *cipher, void *in,
+-    void *out, unsigned long len) {
++    void *out, size_t len) {
+   gcry_cipher_encrypt(cipher->key[0], out, len, in, len);
+ }
+ 
+ static void des3_decrypt(struct ssh_cipher_struct *cipher, void *in,
+-    void *out, unsigned long len) {
++    void *out, size_t len) {
+   gcry_cipher_decrypt(cipher->key[0], out, len, in, len);
+ }
+ 
+-- 
+GitLab
+

diff --git a/net-libs/libssh/libssh-0.10.6-r1.ebuild 
b/net-libs/libssh/libssh-0.10.6-r1.ebuild
new file mode 100644
index 000000000000..fcdd767eddc4
--- /dev/null
+++ b/net-libs/libssh/libssh-0.10.6-r1.ebuild
@@ -0,0 +1,140 @@
+# Copyright 1999-2024 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+
+inherit cmake-multilib
+
+DESCRIPTION="Access a working SSH implementation by means of a library"
+HOMEPAGE="https://www.libssh.org/";
+
+if [[ ${PV} == *9999* ]] ; then
+       inherit git-r3
+       EGIT_REPO_URI="https://git.libssh.org/projects/libssh.git";
+else
+       SRC_URI="https://www.libssh.org/files/$(ver_cut 1-2)/${P}.tar.xz"
+       KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~loong ~mips ~ppc 
~ppc64 ~riscv ~s390 ~sparc ~x86 ~amd64-linux ~x86-linux"
+fi
+
+LICENSE="LGPL-2.1"
+SLOT="0/4" # subslot = soname major version
+IUSE="debug doc examples gcrypt gssapi mbedtls pcap server +sftp static-libs 
test zlib"
+# Maintainer: check IUSE-defaults at DefineOptions.cmake
+
+REQUIRED_USE="?? ( gcrypt mbedtls )"
+RESTRICT="!test? ( test )"
+
+RDEPEND="
+       !gcrypt? (
+               !mbedtls? (
+                       >=dev-libs/openssl-1.0.1h-r2:0=[${MULTILIB_USEDEP}]
+               )
+       )
+       gcrypt? ( >=dev-libs/libgcrypt-1.5.3:0[${MULTILIB_USEDEP}] )
+       gssapi? ( >=virtual/krb5-0-r1[${MULTILIB_USEDEP}] )
+       mbedtls? ( net-libs/mbedtls:=[${MULTILIB_USEDEP}] )
+       zlib? ( >=sys-libs/zlib-1.2.8-r1[${MULTILIB_USEDEP}] )
+"
+DEPEND="${RDEPEND}
+       test? (
+               >=dev-util/cmocka-0.3.1[${MULTILIB_USEDEP}]
+               elibc_musl? ( sys-libs/argp-standalone )
+       )
+"
+BDEPEND="doc? ( app-text/doxygen[dot] )"
+
+DOCS=( AUTHORS CHANGELOG README )
+
+PATCHES=(
+       "${FILESDIR}/${P}-libgcrypt-type-mismatches.patch" # bug 932715
+       "${FILESDIR}/${P}-ipv6-hostname-parsing.patch"
+)
+
+src_prepare() {
+       cmake_src_prepare
+
+       # just install the examples, do not compile them
+       cmake_comment_add_subdirectory examples
+
+       sed -e "/^check_include_file.*HAVE_VALGRIND_VALGRIND_H/s/^/#DONT /" \
+               -i ConfigureChecks.cmake || die
+
+       if use test; then
+               local skip_tests=(
+                       # keyfile torture test is currently broken
+                       -e "/torture_keyfiles/d"
+
+                       # Tries to expand ~ which fails w/ portage homedir
+                       # (torture_path_expand_tilde_unix and 
torture_config_make_absolute_no_sshdir)
+                       -e "/torture_misc/d"
+                       -e "/torture_config/d"
+               )
+
+               # Disable tests that take too long (bug #677006)
+               if use sparc; then
+                       skip_tests+=(
+                               -e "/torture_threads_pki_rsa/d"
+                               -e "/torture_pki_dsa/d"
+                       )
+               fi
+
+               if (( ${#skip_tests[@]} )) ; then
+                       sed -i "${skip_tests[@]}" 
tests/unittests/CMakeLists.txt || die
+               fi
+
+               if use elibc_musl; then
+                       sed -e "/SOLARIS/d" \
+                               -i tests/CMakeLists.txt || die
+               fi
+       fi
+}
+
+multilib_src_configure() {
+       local mycmakeargs=(
+               -DWITH_NACL=OFF
+               -DWITH_STACK_PROTECTOR=OFF
+               -DWITH_STACK_PROTECTOR_STRONG=OFF
+               -DWITH_DEBUG_CALLTRACE=$(usex debug)
+               -DWITH_DEBUG_CRYPTO=$(usex debug)
+               -DWITH_GCRYPT=$(usex gcrypt)
+               -DWITH_GSSAPI=$(usex gssapi)
+               -DWITH_MBEDTLS=$(usex mbedtls)
+               -DWITH_PCAP=$(usex pcap)
+               -DWITH_SERVER=$(usex server)
+               -DWITH_SFTP=$(usex sftp)
+               -DBUILD_STATIC_LIB=$(usex static-libs)
+               # TODO: try enabling {CLIENT,SERVER}_TESTING
+               -DUNIT_TESTING=$(usex test)
+               -DWITH_ZLIB=$(usex zlib)
+       )
+
+       multilib_is_native_abi || mycmakeargs+=( 
-DCMAKE_DISABLE_FIND_PACKAGE_Doxygen=ON )
+
+       cmake_src_configure
+}
+
+multilib_src_compile() {
+       cmake_src_compile
+       multilib_is_native_abi && use doc && cmake_src_compile docs
+}
+
+multilib_src_install() {
+       cmake_src_install
+       multilib_is_native_abi && use doc && local HTML_DOCS=( 
"${BUILD_DIR}"/doc/html/. )
+
+       use static-libs && dolib.a src/libssh.a
+
+       # compatibility symlink until all consumers have been updated
+       # to no longer use libssh_threads.so
+       dosym libssh.so /usr/$(get_libdir)/libssh_threads.so
+}
+
+multilib_src_install_all() {
+       use mbedtls && DOCS+=( README.mbedtls )
+       einstalldocs
+
+       if use examples; then
+               docinto examples
+               dodoc examples/*.{c,h,cpp}
+       fi
+}

Reply via email to