Conditional compilation of localnetwork matching

Some architectures (esp32) might not have this API.

Fixes: #263

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit 9634668258)
This commit is contained in:
Jakub Jelen
2024-08-02 09:56:43 +02:00
parent 894e07aede
commit 7beb580aab
5 changed files with 29 additions and 9 deletions

View File

@@ -64,6 +64,7 @@ check_include_file(arpa/inet.h HAVE_ARPA_INET_H)
check_include_file(byteswap.h HAVE_BYTESWAP_H) check_include_file(byteswap.h HAVE_BYTESWAP_H)
check_include_file(glob.h HAVE_GLOB_H) check_include_file(glob.h HAVE_GLOB_H)
check_include_file(valgrind/valgrind.h HAVE_VALGRIND_VALGRIND_H) check_include_file(valgrind/valgrind.h HAVE_VALGRIND_VALGRIND_H)
check_include_file(ifaddrs.h HAVE_IFADDRS_H)
if (WIN32) if (WIN32)
check_include_file(io.h HAVE_IO_H) check_include_file(io.h HAVE_IO_H)

View File

@@ -58,6 +58,9 @@
/* Define to 1 if you have the <stdint.h> header file. */ /* Define to 1 if you have the <stdint.h> header file. */
#cmakedefine HAVE_STDINT_H 1 #cmakedefine HAVE_STDINT_H 1
/* Define to 1 if you have the <ifaddrs.h> header file. */
#cmakedefine HAVE_IFADDRS_H 1
/* Define to 1 if you have the <openssl/aes.h> header file. */ /* Define to 1 if you have the <openssl/aes.h> header file. */
#cmakedefine HAVE_OPENSSL_AES_H 1 #cmakedefine HAVE_OPENSSL_AES_H 1

View File

@@ -39,10 +39,12 @@
# include <errno.h> # include <errno.h>
# include <signal.h> # include <signal.h>
# include <sys/wait.h> # include <sys/wait.h>
# include <ifaddrs.h>
# include <net/if.h> # include <net/if.h>
# include <netinet/in.h> # include <netinet/in.h>
#endif #endif
#ifdef HAVE_IFADDRS_H
#include <ifaddrs.h>
#endif
#include "libssh/config_parser.h" #include "libssh/config_parser.h"
#include "libssh/config.h" #include "libssh/config.h"
@@ -639,7 +641,7 @@ ssh_config_make_absolute(ssh_session session,
return out; return out;
} }
#ifndef _WIN32 #ifdef HAVE_IFADDRS_H
/** /**
* @brief Checks if host address matches the local network specified. * @brief Checks if host address matches the local network specified.
* *
@@ -730,7 +732,7 @@ ssh_match_localnetwork(const char *addrlist, bool negate)
return (found == (negate ? 0 : 1)); return (found == (negate ? 0 : 1));
} }
#endif #endif /* HAVE_IFADDRS_H */
static int static int
ssh_config_parse_line(ssh_session session, ssh_config_parse_line(ssh_session session,
@@ -955,7 +957,6 @@ ssh_config_parse_line(ssh_session session,
args++; args++;
break; break;
#ifndef _WIN32
case MATCH_LOCALNETWORK: case MATCH_LOCALNETWORK:
/* Here we match only one argument */ /* Here we match only one argument */
p = ssh_config_get_str_tok(&s, NULL); p = ssh_config_get_str_tok(&s, NULL);
@@ -968,6 +969,7 @@ ssh_config_parse_line(ssh_session session,
SAFE_FREE(x); SAFE_FREE(x);
return -1; return -1;
} }
#ifdef HAVE_IFADDRS_H
rv = match_cidr_address_list(NULL, p, -1); rv = match_cidr_address_list(NULL, p, -1);
if (rv == -1) { if (rv == -1) {
ssh_set_error(session, ssh_set_error(session,
@@ -992,9 +994,17 @@ ssh_config_parse_line(ssh_session session,
} }
result &= rv; result &= rv;
#else /* HAVE_IFADDRS_H */
ssh_set_error(session,
SSH_FATAL,
"line %d: ERROR - match localnetwork "
"not supported on this platform",
count);
SAFE_FREE(x);
return -1;
#endif /* HAVE_IFADDRS_H */
args++; args++;
break; break;
#endif
case MATCH_UNKNOWN: case MATCH_UNKNOWN:
default: default:

View File

@@ -48,11 +48,15 @@ if (UNIX AND NOT WIN32)
torture_pki_ed25519 torture_pki_ed25519
# requires /dev/null # requires /dev/null
torture_channel torture_channel
# requires some non-standard API from netdb.h, in.h
# and arpa/inet.h for handling IP addresses
torture_config_match_localnetwork
) )
if (HAVE_IFADDRS_H)
set(LIBSSH_UNIT_TESTS
${LIBSSH_UNIT_TESTS}
# requires some non-standard API from netdb.h, in.h
# and arpa/inet.h for handling IP addresses
torture_config_match_localnetwork
)
endif (HAVE_IFADDRS_H)
if (WITH_SERVER) if (WITH_SERVER)
set(LIBSSH_UNIT_TESTS set(LIBSSH_UNIT_TESTS
${LIBSSH_UNIT_TESTS} ${LIBSSH_UNIT_TESTS}

View File

@@ -3,7 +3,9 @@
#include "libssh/options.h" #include "libssh/options.h"
#include "libssh/session.h" #include "libssh/session.h"
#include "match.c" #include "match.c"
#ifdef HAVE_IFADDRS_H
#include <ifaddrs.h> #include <ifaddrs.h>
#endif
#include <net/if.h> #include <net/if.h>
#include <stdbool.h> #include <stdbool.h>