Skip to content

Commit

Permalink
Fix building without regex support
Browse files Browse the repository at this point in the history
  • Loading branch information
arr2036 committed Sep 5, 2014
1 parent fc38acc commit 794fed5
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -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
39 changes: 29 additions & 10 deletions configure
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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%'`
Expand Down Expand Up @@ -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_%'`
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -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
Expand Down
53 changes: 34 additions & 19 deletions configure.ac
Expand Up @@ -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],
Expand All @@ -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<path> 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<path> 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
Expand All @@ -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 <regex.h>)])
],
[
Expand Down
3 changes: 3 additions & 0 deletions src/include/radiusd.h
Expand Up @@ -538,15 +538,18 @@ 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

char const *rad_default_log_dir(void);
char const *rad_default_lib_dir(void);
char const *rad_default_raddb_dir(void);
char const *rad_default_run_dir(void);
char const *rad_default_sbin_dir(void);
char const *rad_radacct_dir(void);

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);
Expand Down
8 changes: 6 additions & 2 deletions src/include/tmpl.h
Expand Up @@ -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;

Expand All @@ -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
Expand Down
6 changes: 2 additions & 4 deletions src/lib/valuepair.c
Expand Up @@ -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.
Expand Down
8 changes: 6 additions & 2 deletions src/main/parser.c
Expand Up @@ -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 '&',
Expand All @@ -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
}

/*
Expand Down
5 changes: 4 additions & 1 deletion src/main/realms.c
Expand Up @@ -1808,8 +1808,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
Expand Down
2 changes: 2 additions & 0 deletions src/main/util.c
Expand Up @@ -814,6 +814,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.
Expand Down Expand Up @@ -874,6 +875,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

/** Return the default log dir
*
Expand Down
4 changes: 4 additions & 0 deletions src/main/valuepair.c
Expand Up @@ -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;

Expand Down
8 changes: 6 additions & 2 deletions src/main/version.c
Expand Up @@ -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
Expand Down

0 comments on commit 794fed5

Please sign in to comment.