2
2
* xlat.c Translate strings. This is the first version of xlat
3
3
* incorporated to RADIUS
5
* Version: $Id: xlat.c,v 1.135 2008/03/16 17:59:29 aland Exp $
7
7
* This program is free software; you can redistribute it and/or modify
8
8
* it under the terms of the GNU General Public License as published by
25
25
#include <freeradius-devel/ident.h>
26
RCSID("$Id: xlat.c,v 1.135 2008/03/16 17:59:29 aland Exp $")
28
28
#include <freeradius-devel/radiusd.h>
29
#include <freeradius-devel/md5.h>
29
30
#include <freeradius-devel/rad_assert.h>
178
183
vp = pairfind(vp->next, da->attr)) {
181
snprintf(out, outlen, "%d", count);
186
snprintf(out, outlen, "%d", (int) count);
182
187
return strlen(out);
214
219
p += 1 + strspn(p + 1, "0123456789");
216
DEBUG2("xlat: Invalid array reference in string at %s %s",
221
RDEBUG2("xlat: Invalid array reference in string at %s %s",
418
* Change the debugging level.
420
static size_t xlat_debug(UNUSED void *instance, REQUEST *request,
421
char *fmt, char *out, size_t outlen,
422
UNUSED RADIUS_ESCAPE_STRING func)
426
if (*fmt) level = atoi(fmt);
429
request->options = RAD_REQUEST_OPTION_NONE;
430
request->radlog = NULL;
432
if (level > 4) level = 4;
434
request->options = level;
435
request->radlog = radlog_request;
438
snprintf(out, outlen, "%d", level);
444
* Calculate the MD5 hash of a string.
446
static size_t xlat_md5(UNUSED void *instance, REQUEST *request,
447
char *fmt, char *out, size_t outlen,
448
UNUSED RADIUS_ESCAPE_STRING func)
455
if (!radius_xlat(buffer, sizeof(buffer), fmt, request, func)) {
461
fr_MD5Update(&ctx, (void *) buffer, strlen(buffer));
462
fr_MD5Final(digest, &ctx);
465
snprintf(out, outlen, "md5_overflow");
469
for (i = 0; i < 16; i++) {
470
snprintf(out + i * 2, 3, "%02x", digest[i]);
413
477
* Compare two xlat_t structs, based ONLY on the module name.
415
479
static int xlat_cmp(const void *a, const void *b)
508
572
c->internal = TRUE;
510
574
#endif /* HAVE_REGEX_H */
577
xlat_register("debug", xlat_debug, &xlat_inst[0]);
578
c = xlat_find("debug");
579
rad_assert(c != NULL);
582
xlat_register("md5", xlat_md5, &xlat_inst[0]);
583
c = xlat_find("md5");
584
rad_assert(c != NULL);
626
701
size_t mylen = strlen(p);
627
char *first = rad_malloc(mylen);
628
char *second = rad_malloc(mylen);
702
char *first = rad_malloc(mylen + 1);
703
char *second = rad_malloc(mylen + 1);
629
704
int expand2 = FALSE;
631
706
len1 = rad_copy_variable(first, p);
633
DEBUG2("Badly formatted variable: %s", p);
708
RDEBUG2("Badly formatted variable: %s", p);
634
709
goto free_and_done;
637
712
if ((p[len1] != ':') || (p[len1 + 1] != '-')) {
638
DEBUG2("No trailing :- after variable at %s", p);
713
RDEBUG2("No trailing :- after variable at %s", p);
639
714
goto free_and_done;
718
DEBUG("xlat: Invalid syntax in %s", *from);
793
RDEBUG("xlat: Invalid syntax in %s", *from);
721
796
* %{name} is a simple attribute reference,
833
908
if ((c = xlat_find(xlat_name)) != NULL) {
834
if (!c->internal) DEBUG3("radius_xlat: Running registered xlat function of module %s for string \'%s\'",
909
if (!c->internal) RDEBUG3("radius_xlat: Running registered xlat function of module %s for string \'%s\'",
835
910
c->module, xlat_string);
836
911
retlen = c->do_xlat(c->instance, request, xlat_string,
837
912
q, freespace, func);
838
913
/* If retlen is 0, treat it as not found */
839
914
if (retlen > 0) found = 1;
844
919
* No attribute by that name, return an error.
846
DEBUG2("WARNING: Unknown module \"%s\" in string expansion \"%%%s\"", xlat_name, *from);
921
RDEBUG2("WARNING: Unknown module \"%s\" in string expansion \"%%%s\"", xlat_name, *from);
1042
1117
case 'l': /* request timestamp */
1043
1118
snprintf(tmpdt, sizeof(tmpdt), "%lu",
1044
(unsigned long) request->received.tv_sec);
1119
(unsigned long) request->timestamp);
1045
1120
strlcpy(q,tmpdt,freespace);
1046
1121
q += strlen(q);