26RCSID(
"$Id: 139649ce6fd5eb75ad1d1c6c2c50105ec8fefff8 $")
28#include <freeradius-devel/server/regex.h>
29#include <freeradius-devel/server/request_data.h>
30#include <freeradius-devel/util/debug.h>
34#define REQUEST_DATA_REGEX (0xadbeef00)
37#if defined(HAVE_REGEX_PCRE) || defined(HAVE_REGEX_PCRE2)
40 fr_regmatch_t *regmatch;
63 fr_regcapture_t *old_rc, *new_rc;
70 DEBUG4(
"Clearing %zu matches", old_rc->regmatch->used);
76 if (!regmatch || ((*regmatch)->used == 0))
return;
82 DEBUG4(
"Adding %zu matches", (*regmatch)->used);
87 MEM(new_rc = talloc(request, fr_regcapture_t));
92#if defined(HAVE_REGEX_PCRE) || defined(HAVE_REGEX_PCRE2)
93 if (!(*preg)->precompiled) {
94 new_rc->preg = talloc_steal(new_rc, *preg);
104 new_rc->regmatch = talloc_steal(new_rc, *regmatch);
105 new_rc->safe_for =
in->safe_for;
106 new_rc->secret =
in->secret;
112# if defined(HAVE_REGEX_PCRE2)
131 pcre2_match_data *match_data;
135 RDEBUG4(
"No subcapture data found");
138 match_data = talloc_get_type_abort(rc->regmatch->match_data, pcre2_match_data);
140 ret = pcre2_substring_length_bynumber(match_data, num, &len);
142 case PCRE2_ERROR_NOMEMORY:
149 case PCRE2_ERROR_NOSUBSTRING:
150 RDEBUG4(
"%i/%zu Not found", num + 1, rc->regmatch->used);
158 MEM(
buff = talloc_array(ctx,
char, ++len));
159 pcre2_substring_copy_bynumber(match_data, num, (PCRE2_UCHAR *)
buff, &len);
166 RDEBUG4(
"%i/%zu Found: %pV (%zu)", num + 1, rc->regmatch->used,
out,
out->vb_length);
191 pcre2_match_data *match_data;
195 RDEBUG4(
"No subcapture data found");
198 match_data = rc->regmatch->match_data;
200 ret = pcre2_substring_length_byname(match_data, (PCRE2_UCHAR
const *)
name, &len);
202 case PCRE2_ERROR_NOMEMORY:
209 case PCRE2_ERROR_NOSUBSTRING:
214 if (ret < 0)
return -1;
216 MEM(
buff = talloc_array(ctx,
char, ++len));
217 pcre2_substring_copy_byname(match_data, (PCRE2_UCHAR
const *)
name, (PCRE2_UCHAR *)
buff, &len);
230# elif defined(HAVE_REGEX_PCRE)
251 RDEBUG4(
"No subcapture data found");
255 ret = pcre_get_substring(rc->regmatch->subject,
256 (
int *)rc->regmatch->match_data, (
int)rc->regmatch->used, num, &p);
258 case PCRE_ERROR_NOMEMORY:
265 case PCRE_ERROR_NOSUBSTRING:
266 RDEBUG4(
"%i/%zu Not found", num + 1, rc->regmatch->used);
270 if (ret < 0)
return -1;
272 talloc_set_type(p,
char);
273 talloc_steal(ctx, p);
280 RDEBUG4(
"%i/%zu Found: %pV (%zu)", num + 1, rc->regmatch->used,
out,
out->vb_length);
308 RDEBUG4(
"No subcapture data found");
312 rc = talloc_get_type_abort(rd, fr_regcapture_t);
313 ret = pcre_get_named_substring(rc->preg->compiled, rc->regmatch->subject,
314 (
int *)rc->regmatch->match_data, (
int)rc->regmatch->used,
name, &p);
316 case PCRE_ERROR_NOMEMORY:
323 case PCRE_ERROR_NOSUBSTRING:
328 if (ret < 0)
return -1;
330 talloc_set_type(p,
char);
331 talloc_steal(ctx, p);
364 regmatch_t *match_data;
368 RDEBUG4(
"No subcapture data found");
371 match_data = rc->regmatch->match_data;
378 if ((num >= rc->regmatch->used) || (match_data[num].rm_eo == -1) || (match_data[num].rm_so == -1)) {
379 RDEBUG4(
"%i/%zu Not found", num + 1, rc->regmatch->used);
386 fr_assert(match_data[num].rm_eo <= (regoff_t)talloc_array_length(rc->regmatch->subject));
387 fr_assert(match_data[num].rm_so <= (regoff_t)talloc_array_length(rc->regmatch->subject));
389 start = rc->regmatch->subject + match_data[num].rm_so;
390 len = match_data[num].rm_eo - match_data[num].rm_so;
399 RDEBUG4(
"%i/%zu Found: %pV (%zu)", num + 1, rc->regmatch->used,
out,
out->vb_length);
@ FR_TYPE_STRING
String of printable characters.
void * request_data_reference(request_t *request, void const *unique_ptr, int unique_int)
Get opaque data from a request without removing it.
void * request_data_get(request_t *request, void const *unique_ptr, int unique_int)
Get opaque data from a request.
#define request_data_talloc_add(_request, _unique_ptr, _unique_int, _type, _opaque, _free_on_replace, _free_on_parent, _persist)
Add opaque data to a request_t.
static char buff[sizeof("18446744073709551615")+3]
char * talloc_bstrndup(TALLOC_CTX *ctx, char const *in, size_t inlen)
Binary safe strndup function.
void fr_value_box_bstrndup_shallow(fr_value_box_t *dst, fr_dict_attr_t const *enumv, char const *src, size_t len, bool tainted)
Assign a string to to a fr_value_box_t.
#define fr_value_box_mark_safe_for(_box, _safe_for)
static void fr_value_box_set_secret(fr_value_box_t *box, bool secret)
uintptr_t fr_value_box_safe_for_t
Escaping that's been applied to a value box.
#define fr_value_box_init(_vb, _type, _enumv, _tainted)
Initialise a fr_value_box_t.
static size_t char ** out