30RCSID(
"$Id: 303ab9215abe8e72b9f714e774080048496eb154 $")
32#include <freeradius-devel/server/paircmp.h>
33#include <freeradius-devel/server/regex.h>
34#include <freeradius-devel/unlang/xlat.h>
65 REDEBUG(
"Non-Unary operations require two operands");
74 fr_regmatch_t *regmatch;
76 char *expr = NULL, *
value = NULL;
77 char const *expr_p, *value_p;
80 expr_p =
check->vp_strvalue;
87 value_p =
vp->vp_strvalue;
93 if (!expr_p || !value_p) {
94 REDEBUG(
"Error stringifying operand for regular expression");
106 slen = regex_compile(request, &preg, expr_p,
talloc_strlen(expr_p),
114 subcaptures = regex_subcapture_count(preg);
115 if (!subcaptures) subcaptures = REQUEST_MAX_REGEX + 1;
116 MEM(regmatch = regex_match_data_alloc(NULL, subcaptures));
121 slen = regex_exec(preg, value_p,
talloc_strlen(value_p), regmatch);
132 regex_sub_to_request(request, &preg, ®match, &
vp->data);
133 ret = (slen == 1) ? 0 : -1;
135 ret = (slen != 1) ? 0 : -1;
155 if (
vp->vp_type !=
check->vp_type)
return -1;
160 switch (
check->vp_type) {
169 return CMP(strcmp(
vp->vp_strvalue,
check->vp_strvalue), 0);
190 return CMP(ntohl(
vp->vp_ipv4addr), ntohl(
check->vp_ipv4addr));
193 return CMP(memcmp(
vp->vp_ip.addr.v6.s6_addr,
check->vp_ip.addr.v6.s6_addr,
194 sizeof(
vp->vp_ip.addr.v6.s6_addr)), 0);
199 if (ret == -1)
return -2;
201 ret = (ret == 1) ? -1 : 1;
203 ret = (ret == 1) ? 1 : -1;
205 ret = (ret == 1) ? 0 : -1;
209 return CMP(memcmp(
vp->vp_ifid,
check->vp_ifid,
sizeof(
vp->vp_ifid)), 0);
216 if (ret > 0)
return 1;
217 if (ret < 0)
return -1;
#define CMP(_a, _b)
Same as CMP_PREFER_SMALLER use when you don't really care about ordering, you just want an ordering.
#define MEMCMP_FIELDS(_a, _b, _field, _len_field)
Return the comparison of two opaque fields of a structure.
#define REMARKER(_str, _marker_idx, _marker,...)
Output string with error marker, showing where format error occurred.
@ FR_TYPE_IPV4_ADDR
32 Bit IPv4 Address.
@ FR_TYPE_IPV6_PREFIX
IPv6 Prefix.
@ FR_TYPE_STRING
String of printable characters.
@ FR_TYPE_UINT16
16 Bit unsigned integer.
@ FR_TYPE_DATE
Unix time stamp, always has value >2^31.
@ FR_TYPE_UINT8
8 Bit unsigned integer.
@ FR_TYPE_UINT32
32 Bit unsigned integer.
@ FR_TYPE_INT32
32 Bit signed integer.
@ FR_TYPE_UINT64
64 Bit unsigned integer.
@ FR_TYPE_IPV6_ADDR
128 Bit IPv6 Address.
@ FR_TYPE_IPV4_PREFIX
IPv4 Prefix.
@ FR_TYPE_IFID
Interface ID.
@ FR_TYPE_OCTETS
Raw octets.
int paircmp_pairs(UNUSED request_t *request, fr_pair_t const *check, fr_pair_t *vp)
Compares check and vp by value.
Stores an attribute, a value and various bits of other data.
static size_t talloc_strlen(char const *s)
Returns the length of a talloc array containing a string.
void check(const char *name, int index, const struct info *all, int want_lineno, const char *want_function, const char *want_file, int *failed)
static int8_t fr_unix_time_cmp(fr_unix_time_t a, fr_unix_time_t b)
Compare two fr_unix_time_t values.
#define fr_pair_cmp_op(_op, _a, _b)
Compare two attributes using and operator.
char const * fr_strerror(void)
Get the last library error.
static fr_slen_t fr_value_box_aprint(TALLOC_CTX *ctx, char **out, fr_value_box_t const *data, fr_sbuff_escape_rules_t const *e_rules) 1(fr_value_box_print