mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-09 09:54:25 +09:00
Enable conditional compiling for IP regex code.
This commit is contained in:
@@ -34,6 +34,7 @@ else (WIN32)
|
|||||||
check_function_exists(gethostbyname HAVE_GETHOSTBYNAME)
|
check_function_exists(gethostbyname HAVE_GETHOSTBYNAME)
|
||||||
check_function_exists(poll HAVE_POLL)
|
check_function_exists(poll HAVE_POLL)
|
||||||
check_function_exists(select HAVE_SELECT)
|
check_function_exists(select HAVE_SELECT)
|
||||||
|
check_function_exists(regcomp HAVE_REGCOMP)
|
||||||
endif (WIN32)
|
endif (WIN32)
|
||||||
|
|
||||||
# LIBRARIES
|
# LIBRARIES
|
||||||
|
|||||||
@@ -46,6 +46,9 @@
|
|||||||
/* Define to 1 if you have the `select' function. */
|
/* Define to 1 if you have the `select' function. */
|
||||||
#cmakedefine HAVE_SELECT 1
|
#cmakedefine HAVE_SELECT 1
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `regcomp' function. */
|
||||||
|
#cmakedefine HAVE_REGCOMP 1
|
||||||
|
|
||||||
/*************************** LIBRARIES ***************************/
|
/*************************** LIBRARIES ***************************/
|
||||||
|
|
||||||
/* Define to 1 if you have the `crypto' library (-lcrypto). */
|
/* Define to 1 if you have the `crypto' library (-lcrypto). */
|
||||||
|
|||||||
@@ -56,12 +56,13 @@
|
|||||||
#error "Your system must have getaddrinfo()"
|
#error "Your system must have getaddrinfo()"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_REGCOMP
|
||||||
/* don't declare gnu extended regexp's */
|
/* don't declare gnu extended regexp's */
|
||||||
#ifndef _POSIX_C_SOURCE
|
#ifndef _POSIX_C_SOURCE
|
||||||
#define _POSIX_C_SOURCE
|
#define _POSIX_C_SOURCE
|
||||||
#endif
|
#endif
|
||||||
#include <regex.h>
|
#include <regex.h>
|
||||||
|
#endif /* HAVE_REGCOMP */
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
static void sock_set_nonblocking(socket_t sock) {
|
static void sock_set_nonblocking(socket_t sock) {
|
||||||
@@ -94,7 +95,7 @@ static void sock_set_blocking(socket_t sock) {
|
|||||||
}
|
}
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
|
#ifdef HAVE_REGCOMP
|
||||||
static regex_t *ip_regex = NULL;
|
static regex_t *ip_regex = NULL;
|
||||||
|
|
||||||
/** @internal
|
/** @internal
|
||||||
@@ -130,6 +131,14 @@ void ssh_regex_finalize(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#else /* HAVE_REGCOMP */
|
||||||
|
int ssh_regex_init(){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
void ssh_regex_finalize(){
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static int getai(SSH_SESSION *session, const char *host, int port, struct addrinfo **ai) {
|
static int getai(SSH_SESSION *session, const char *host, int port, struct addrinfo **ai) {
|
||||||
const char *service = NULL;
|
const char *service = NULL;
|
||||||
struct addrinfo hints;
|
struct addrinfo hints;
|
||||||
@@ -148,11 +157,13 @@ static int getai(SSH_SESSION *session, const char *host, int port, struct addrin
|
|||||||
service = s_port;
|
service = s_port;
|
||||||
hints.ai_flags=AI_NUMERICSERV;
|
hints.ai_flags=AI_NUMERICSERV;
|
||||||
}
|
}
|
||||||
|
#ifdef HAVE_REGCOMP
|
||||||
if(regexec(ip_regex,host,0,NULL,0) == 0){
|
if(regexec(ip_regex,host,0,NULL,0) == 0){
|
||||||
/* this is an IP address */
|
/* this is an IP address */
|
||||||
ssh_log(session,SSH_LOG_PACKET,"host %s matches an IP address",host);
|
ssh_log(session,SSH_LOG_PACKET,"host %s matches an IP address",host);
|
||||||
hints.ai_flags |= AI_NUMERICHOST;
|
hints.ai_flags |= AI_NUMERICHOST;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
return getaddrinfo(host, service, &hints, ai);
|
return getaddrinfo(host, service, &hints, ai);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user