config: Add CMake check for glob()

This commit is contained in:
Jakub Jelen
2017-12-11 15:37:02 +01:00
committed by Andreas Schneider
parent 99c5160cb5
commit b8e301ade3
4 changed files with 25 additions and 2 deletions

View File

@@ -63,6 +63,7 @@ check_include_file(sys/utime.h HAVE_SYS_UTIME_H)
check_include_file(sys/param.h HAVE_SYS_PARAM_H) check_include_file(sys/param.h HAVE_SYS_PARAM_H)
check_include_file(arpa/inet.h HAVE_ARPA_INET_H) 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)
if (WIN32) if (WIN32)
check_include_file(io.h HAVE_IO_H) check_include_file(io.h HAVE_IO_H)
@@ -140,6 +141,10 @@ check_function_exists(isblank HAVE_ISBLANK)
check_function_exists(strncpy HAVE_STRNCPY) check_function_exists(strncpy HAVE_STRNCPY)
check_function_exists(strtoull HAVE_STRTOULL) check_function_exists(strtoull HAVE_STRTOULL)
if (HAVE_GLOB_H)
check_function_exists(glob HAVE_GLOB)
endif (HAVE_GLOB_H)
if (NOT WIN32) if (NOT WIN32)
check_function_exists(vsnprintf HAVE_VSNPRINTF) check_function_exists(vsnprintf HAVE_VSNPRINTF)
check_function_exists(snprintf HAVE_SNPRINTF) check_function_exists(snprintf HAVE_SNPRINTF)

View File

@@ -20,6 +20,9 @@
/* Define to 1 if you have the <aprpa/inet.h> header file. */ /* Define to 1 if you have the <aprpa/inet.h> header file. */
#cmakedefine HAVE_ARPA_INET_H 1 #cmakedefine HAVE_ARPA_INET_H 1
/* Define to 1 if you have the <glob.h> header file. */
#cmakedefine HAVE_GLOB_H 1
/* Define to 1 if you have the <pty.h> header file. */ /* Define to 1 if you have the <pty.h> header file. */
#cmakedefine HAVE_PTY_H 1 #cmakedefine HAVE_PTY_H 1
@@ -151,6 +154,9 @@
/* Define to 1 if you have the `_strtoui64' function. */ /* Define to 1 if you have the `_strtoui64' function. */
#cmakedefine HAVE__STRTOUI64 1 #cmakedefine HAVE__STRTOUI64 1
/* Define to 1 if you have the `glob' function. */
#cmakedefine HAVE_GLOB 1
/*************************** LIBRARIES ***************************/ /*************************** LIBRARIES ***************************/
/* Define to 1 if you have the `crypto' library (-lcrypto). */ /* Define to 1 if you have the `crypto' library (-lcrypto). */

View File

@@ -27,7 +27,9 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <glob.h> #ifdef HAVE_GLOB_H
# include <glob.h>
#endif
#include "libssh/priv.h" #include "libssh/priv.h"
#include "libssh/session.h" #include "libssh/session.h"
@@ -317,6 +319,7 @@ static void local_parse_file(ssh_session session, const char *filename, int *par
return; return;
} }
#ifdef HAVE_GLOB
static void local_parse_glob(ssh_session session, static void local_parse_glob(ssh_session session,
const char *fileglob, const char *fileglob,
int *parsing, int *parsing,
@@ -343,6 +346,7 @@ static void local_parse_glob(ssh_session session,
globfree(&globbuf); globfree(&globbuf);
} }
#endif /* HAVE_GLOB */
static int ssh_config_parse_line(ssh_session session, const char *line, static int ssh_config_parse_line(ssh_session session, const char *line,
unsigned int count, int *parsing, int seen[]) { unsigned int count, int *parsing, int seen[]) {
@@ -389,7 +393,11 @@ static int ssh_config_parse_line(ssh_session session, const char *line,
p = ssh_config_get_str_tok(&s, NULL); p = ssh_config_get_str_tok(&s, NULL);
if (p && *parsing) { if (p && *parsing) {
#ifdef HAVE_GLOB
local_parse_glob(session, p, parsing, seen); local_parse_glob(session, p, parsing, seen);
#else
local_parse_file(session, p, parsing, seen);
#endif /* HAVE_GLOB */
} }
break; break;
case SOC_HOST: { case SOC_HOST: {

View File

@@ -122,13 +122,16 @@ static void torture_config_double_ports(void **state) {
static void torture_config_glob(void **state) { static void torture_config_glob(void **state) {
ssh_session session = *state; ssh_session session = *state;
int ret; int ret;
#ifdef HAVE_GLOB
char *v; char *v;
#endif
ret = ssh_config_parse_file(session, LIBSSH_TESTCONFIG5); ret = ssh_config_parse_file(session, LIBSSH_TESTCONFIG5);
assert_true(ret == 0); assert_true(ret == 0); /* non-existing files should not error */
/* Test the variable presence */ /* Test the variable presence */
#ifdef HAVE_GLOB
ret = ssh_options_get(session, SSH_OPTIONS_PROXYCOMMAND, &v); ret = ssh_options_get(session, SSH_OPTIONS_PROXYCOMMAND, &v);
assert_true(ret == 0); assert_true(ret == 0);
@@ -140,6 +143,7 @@ static void torture_config_glob(void **state) {
assert_string_equal(v, ID_FILE); assert_string_equal(v, ID_FILE);
ssh_string_free_char(v); ssh_string_free_char(v);
#endif /* HAVE_GLOB */
} }
int torture_run_tests(void) { int torture_run_tests(void) {