From: Arran Cudbard-Bell Date: Fri, 5 Sep 2014 23:02:26 +0000 (-0400) Subject: Fix building without regex support X-Git-Tag: release_3_0_5~612 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5646f52a5bf21c54faf1c759c7bb8a4e0a2a4429;p=thirdparty%2Ffreeradius-server.git Fix building without regex support --- diff --git a/.travis.yml b/.travis.yml index fc0a677e59f..f7fb30b1e84 100644 --- a/.travis.yml +++ b/.travis.yml @@ -69,6 +69,6 @@ before_install: libyubikey-dev - sudo apt-get install -qq -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" libmysqlclient-dev before_script: - - CFLAGS="${BUILD_CFLAGS}" ./configure -C --enable-werror --prefix=$HOME/freeradius --with-shared-libs=$LIBS_SHARED --with-threads=$LIBS_OPTIONAL --with-udpfromto=$LIBS_OPTIONAL --with-openssl=$LIBS_OPTIONAL + - CFLAGS="${BUILD_CFLAGS}" ./configure -C --enable-werror --prefix=$HOME/freeradius --with-shared-libs=$LIBS_SHARED --with-threads=$LIBS_OPTIONAL --with-udpfromto=$LIBS_OPTIONAL --with-openssl=$LIBS_OPTIONAL --with-regex=$LIBS_OPTIONAL - make script: if [ ${COVERITY_SCAN_BRANCH} != 1 ]; then make travis-test; fi diff --git a/configure b/configure index 35048e90044..f15072dafc4 100755 --- a/configure +++ b/configure @@ -764,6 +764,7 @@ with_execinfo_lib_dir with_execinfo_include_dir with_pcre_lib_dir with_pcre_include_dir +with_regex ' ac_precious_vars='build_alias host_alias @@ -1450,6 +1451,8 @@ Optional Packages: --with-pcre-lib-dir=DIR directory in which to look for pcre library files --with-pcre-include-dir=DIR directory in which to look for pcre include files + --with-regex Whether to build with regular expressions + (default=yes) Some influential environment variables: CC C compiler command @@ -10670,8 +10673,23 @@ if test "${with_pcre_include_dir+set}" = set; then : fi -REGEX=no -smart_try_dir=$pcre_include_dir +REGEX= + +# Check whether --with-regex was given. +if test "${with_regex+set}" = set; then : + withval=$with_regex; case "$withval" in + no) + REGEX=no + ;; + *) + ;; + esac + +fi + + +if test "x$REGEX" = "x"; then + smart_try_dir=$pcre_include_dir ac_safe=`echo "pcreposix.h" | sed 'y%./+-%__pm%'` @@ -10898,8 +10916,8 @@ fi smart_prefix= -if test "x$ac_cv_header_pcreposix_h" = "xyes"; then - smart_try_dir=$pcre_lib_dir + if test "x$ac_cv_header_pcreposix_h" = "xyes"; then + smart_try_dir=$pcre_lib_dir sm_lib_safe=`echo "pcre" | sed 'y%./+-%__p_%'` @@ -11074,18 +11092,20 @@ if test "x$smart_lib" != "x"; then SMART_LIBS="$smart_ldflags $smart_lib $SMART_LIBS" fi - if test "x$ac_cv_lib_pcre_pcre_compile" = "xyes"; then - REGEX=yes + if test "x$ac_cv_lib_pcre_pcre_compile" = "xyes"; then + REGEX=yes - smart_try_dir=$pcre_lib_dir + smart_try_dir=$pcre_lib_dir $as_echo "#define HAVE_PCRE 1" >>confdefs.h - LIBS=$(echo "$LIBS" | sed -e 's/-lpcre/-lpcre -lpcreposix/') + LIBS=$(echo "$LIBS" | sed -e 's/-lpcre/-lpcre -lpcreposix/') + fi fi fi -if test "x$REGEX" != "xyes"; then + +if test "x$REGEX" = "x"; then smart_try_dir= @@ -11331,7 +11351,6 @@ if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } - REGEX_EXTENDED=yes $as_echo "#define HAVE_REG_EXTENDED 1" >>confdefs.h diff --git a/configure.ac b/configure.ac index 8a95bbbccf1..76466ecc45a 100644 --- a/configure.ac +++ b/configure.ac @@ -1636,7 +1636,7 @@ AC_ARG_WITH(pcre-lib-dir, esac ] ) -dnl extra argument: --with-pcre-include--dir +dnl extra argument: --with-pcre-include-dir pcre_include_dir= AC_ARG_WITH(pcre-include-dir, [AS_HELP_STRING([--with-pcre-include-dir=DIR], @@ -1653,32 +1653,48 @@ AC_ARG_WITH(pcre-include-dir, esac ] ) -REGEX=no +dnl extra argument: --with-regex +REGEX= +AC_ARG_WITH(regex, +[AS_HELP_STRING([--with-regex], +[Whether to build with regular expressions (default=yes)])], +[ case "$withval" in + no) + REGEX=no + ;; + *) + ;; + esac ] +) + dnl # dnl # First look for PCRE dnl # -smart_try_dir=$pcre_include_dir -FR_SMART_CHECK_INCLUDE(pcreposix.h) -if test "x$ac_cv_header_pcreposix_h" = "xyes"; then - smart_try_dir=$pcre_lib_dir - FR_SMART_CHECK_LIB(pcre, pcre_compile) - if test "x$ac_cv_lib_pcre_pcre_compile" = "xyes"; then - REGEX=yes - +if test "x$REGEX" = "x"; then + smart_try_dir=$pcre_include_dir + FR_SMART_CHECK_INCLUDE(pcreposix.h) + if test "x$ac_cv_header_pcreposix_h" = "xyes"; then smart_try_dir=$pcre_lib_dir - AC_DEFINE(HAVE_PCRE, [1], [define this if we have libpcre]) - - dnl # - dnl # Hack to get -L and -lpcreposix at the start - dnl # of the linker arguments. - dnl # - LIBS=$(echo "$LIBS" | sed -e 's/-lpcre/-lpcre -lpcreposix/') + FR_SMART_CHECK_LIB(pcre, pcre_compile) + if test "x$ac_cv_lib_pcre_pcre_compile" = "xyes"; then + REGEX=yes + + smart_try_dir=$pcre_lib_dir + AC_DEFINE(HAVE_PCRE, [1], [define this if we have libpcre]) + + dnl # + dnl # Hack to get -L and -lpcreposix at the start + dnl # of the linker arguments. + dnl # + LIBS=$(echo "$LIBS" | sed -e 's/-lpcre/-lpcre -lpcreposix/') + fi fi fi + dnl # dnl # If no PCRE, fallback to POSIX regular expressions dnl # -if test "x$REGEX" != "xyes"; then +if test "x$REGEX" = "x"; then smart_try_dir= FR_SMART_CHECK_INCLUDE(regex.h) if test "x$ac_cv_header_regex_h" = "xyes"; then @@ -1693,7 +1709,6 @@ if test "x$REGEX" != "xyes"; then ], [ AC_MSG_RESULT(yes) - REGEX_EXTENDED=yes AC_DEFINE(HAVE_REG_EXTENDED, [1], [define this if we have REG_EXTENDED (from )]) ], [ diff --git a/src/include/radiusd.h b/src/include/radiusd.h index ff252f21cc6..024bc6e8eb5 100644 --- a/src/include/radiusd.h +++ b/src/include/radiusd.h @@ -552,8 +552,11 @@ uint32_t rad_pps(uint32_t *past, uint32_t *present, time_t *then, struct timeval int rad_expand_xlat(REQUEST *request, char const *cmd, int max_argc, char *argv[], bool can_fail, size_t argv_buflen, char *argv_buf); +#ifdef HAVE_REGEX void rad_regcapture(REQUEST *request, int compare, char const *value, regmatch_t rxmatch[]); +#endif + void verify_request(char const *file, int line, REQUEST *request); /* only for special debug builds */ #ifdef HAVE_GRP_H bool fr_getgid(char const *name, gid_t *gid); diff --git a/src/include/tmpl.h b/src/include/tmpl.h index b920168319c..d607720458e 100644 --- a/src/include/tmpl.h +++ b/src/include/tmpl.h @@ -135,10 +135,12 @@ typedef struct value_pair_tmpl_t { size_t length; //!< of the vpd data } literal; xlat_exp_t *xlat; //!< pre-parsed xlat_exp_t +#ifdef HAVE_REGEX struct { regex_t *comp; //!< pre-parsed regex_t bool iflag; //!< Case insensitive } preg; +#endif } data; } value_pair_tmpl_t; @@ -150,8 +152,10 @@ typedef struct value_pair_tmpl_t { #define tmpl_xlat data.xlat -#define tmpl_preg data.preg.comp -#define tmpl_iflag data.preg.iflag +#ifdef HAVE_REGEX +# define tmpl_preg data.preg.comp +# define tmpl_iflag data.preg.iflag +#endif #define tmpl_value data.literal.value #define tmpl_length data.literal.length diff --git a/src/lib/valuepair.c b/src/lib/valuepair.c index 2e7fa235717..0ea02f5b35c 100644 --- a/src/lib/valuepair.c +++ b/src/lib/valuepair.c @@ -1835,14 +1835,12 @@ VALUE_PAIR *pairmake(TALLOC_CTX *ctx, VALUE_PAIR **vps, case T_OP_REG_EQ: /* =~ */ case T_OP_REG_NE: /* !~ */ { - - int compare; - regex_t reg; #ifndef WITH_REGEX fr_strerror_printf("Regular expressions are not supported"); return NULL; - #else + int compare; + regex_t reg; /* * Someone else will fill in the value. diff --git a/src/main/parser.c b/src/main/parser.c index 34f4dd73a3a..15608054b23 100644 --- a/src/main/parser.c +++ b/src/main/parser.c @@ -640,8 +640,8 @@ static ssize_t condition_tokenize(TALLOC_CTX *ctx, CONF_ITEM *ci, char const *st } c->data.map = map_from_str(c, lhs, lhs_type, op, rhs, rhs_type, - REQUEST_CURRENT, PAIR_LIST_REQUEST, - REQUEST_CURRENT, PAIR_LIST_REQUEST); + REQUEST_CURRENT, PAIR_LIST_REQUEST, + REQUEST_CURRENT, PAIR_LIST_REQUEST); if (!c->data.map) { /* * If strings are T_BARE_WORD and they start with '&', @@ -665,7 +665,11 @@ static ssize_t condition_tokenize(TALLOC_CTX *ctx, CONF_ITEM *ci, char const *st } if (c->data.map->src->type == TMPL_TYPE_REGEX) { +#ifdef HAVE_REGEX c->data.map->src->tmpl_iflag = i_flag; +#else + return_0("Server was built without support for regular expressions"); +#endif } /* diff --git a/src/main/realms.c b/src/main/realms.c index e14a6513893..a09fcf0eb62 100644 --- a/src/main/realms.c +++ b/src/main/realms.c @@ -1807,8 +1807,11 @@ static int realm_add(realm_config_t *rc, CONF_SECTION *cs) return 0; } - +#ifdef HAVE_REGEX int realm_realm_add(REALM *r, CONF_SECTION *cs) +#else +int realm_realm_add(REALM *r, UNUSED CONF_SECTION *cs) +#endif { /* * The structs aren't mutex protected. Refuse to destroy diff --git a/src/main/util.c b/src/main/util.c index ef5998c8a5f..2e8b307a187 100644 --- a/src/main/util.c +++ b/src/main/util.c @@ -784,6 +784,7 @@ int rad_expand_xlat(REQUEST *request, char const *cmd, return argc; } +#ifdef HAVE_REGEX /** Adds subcapture values to request data * * Allows use of %{n} expansions. @@ -844,6 +845,7 @@ void rad_regcapture(REQUEST *request, int compare, char const *value, regmatch_t request_data_add(request, request, REQUEST_DATA_REGEX | i, p, true); } } +#endif #ifndef NDEBUG /* diff --git a/src/main/valuepair.c b/src/main/valuepair.c index b37cfa5b7e5..eeed7ad6158 100644 --- a/src/main/valuepair.c +++ b/src/main/valuepair.c @@ -65,7 +65,11 @@ static struct cmp *cmp; * @return 0 if check and vp are equal, -1 if vp value is less than check value, 1 is vp value is more than check * value, -2 on error. */ +#ifdef HAVE_REGEX int radius_compare_vps(REQUEST *request, VALUE_PAIR *check, VALUE_PAIR *vp) +#else +int radius_compare_vps(UNUSED REQUEST *request, VALUE_PAIR *check, VALUE_PAIR *vp) +#endif { int ret = 0; diff --git a/src/main/version.c b/src/main/version.c index 948de9a9152..0aba383d641 100644 --- a/src/main/version.c +++ b/src/main/version.c @@ -234,9 +234,13 @@ void version(void) #ifdef HAVE_PCRE DEBUG3(" regex-pcre"); #else -#ifdef HAVE_REGEX +# ifdef HAVE_REGEX +# ifdef HAVE_REG_EXTENDED + DEBUG3(" regex-posix-extended"); +# else DEBUG3(" regex-posix"); -#endif +# endif +# endif #endif #ifdef WITH_SESSION_MGMT