mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-11 18:50:28 +09:00
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:
@@ -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(glob.h HAVE_GLOB_H)
|
||||
check_include_file(valgrind/valgrind.h HAVE_VALGRIND_VALGRIND_H)
|
||||
check_include_file(ifaddrs.h HAVE_IFADDRS_H)
|
||||
|
||||
if (WIN32)
|
||||
check_include_file(io.h HAVE_IO_H)
|
||||
|
||||
@@ -58,6 +58,9 @@
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#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. */
|
||||
#cmakedefine HAVE_OPENSSL_AES_H 1
|
||||
|
||||
|
||||
20
src/config.c
20
src/config.c
@@ -39,10 +39,12 @@
|
||||
# include <errno.h>
|
||||
# include <signal.h>
|
||||
# include <sys/wait.h>
|
||||
# include <ifaddrs.h>
|
||||
# include <net/if.h>
|
||||
# include <netinet/in.h>
|
||||
#endif
|
||||
#ifdef HAVE_IFADDRS_H
|
||||
#include <ifaddrs.h>
|
||||
#endif
|
||||
|
||||
#include "libssh/config_parser.h"
|
||||
#include "libssh/config.h"
|
||||
@@ -639,7 +641,7 @@ ssh_config_make_absolute(ssh_session session,
|
||||
return out;
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
#ifdef HAVE_IFADDRS_H
|
||||
/**
|
||||
* @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));
|
||||
}
|
||||
#endif
|
||||
#endif /* HAVE_IFADDRS_H */
|
||||
|
||||
static int
|
||||
ssh_config_parse_line(ssh_session session,
|
||||
@@ -955,7 +957,6 @@ ssh_config_parse_line(ssh_session session,
|
||||
args++;
|
||||
break;
|
||||
|
||||
#ifndef _WIN32
|
||||
case MATCH_LOCALNETWORK:
|
||||
/* Here we match only one argument */
|
||||
p = ssh_config_get_str_tok(&s, NULL);
|
||||
@@ -968,6 +969,7 @@ ssh_config_parse_line(ssh_session session,
|
||||
SAFE_FREE(x);
|
||||
return -1;
|
||||
}
|
||||
#ifdef HAVE_IFADDRS_H
|
||||
rv = match_cidr_address_list(NULL, p, -1);
|
||||
if (rv == -1) {
|
||||
ssh_set_error(session,
|
||||
@@ -992,9 +994,17 @@ ssh_config_parse_line(ssh_session session,
|
||||
}
|
||||
|
||||
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++;
|
||||
break;
|
||||
#endif
|
||||
|
||||
case MATCH_UNKNOWN:
|
||||
default:
|
||||
|
||||
@@ -48,11 +48,15 @@ if (UNIX AND NOT WIN32)
|
||||
torture_pki_ed25519
|
||||
# requires /dev/null
|
||||
torture_channel
|
||||
)
|
||||
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)
|
||||
set(LIBSSH_UNIT_TESTS
|
||||
${LIBSSH_UNIT_TESTS}
|
||||
|
||||
@@ -3,7 +3,9 @@
|
||||
#include "libssh/options.h"
|
||||
#include "libssh/session.h"
|
||||
#include "match.c"
|
||||
#ifdef HAVE_IFADDRS_H
|
||||
#include <ifaddrs.h>
|
||||
#endif
|
||||
#include <net/if.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user