2 * xlat.c Translate strings. This is the first version of xlat
3 * incorporated to RADIUS
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 * Copyright 2000,2006 The FreeRADIUS server project
22 * Copyright 2000 Alan DeKok <aland@ox.org>
25 #include <freeradius-devel/ident.h>
28 #include <freeradius-devel/radiusd.h>
29 #include <freeradius-devel/md5.h>
30 #include <freeradius-devel/rad_assert.h>
34 typedef struct xlat_t {
35 char module[MAX_STRING_LEN];
38 RAD_XLAT_FUNC do_xlat;
39 int internal; /* not allowed to re-define these */
42 static rbtree_t *xlat_root = NULL;
45 * Define all xlat's in the structure.
47 static const char * const internal_xlat[] = {"check",
57 #if REQUEST_MAX_REGEX > 8
58 #error Please fix the following line
60 static int xlat_inst[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 }; /* up to 8 for regex */
64 * Convert the value on a VALUE_PAIR to string
66 static int valuepair2str(char * out,int outlen,VALUE_PAIR * pair,
67 int type, RADIUS_ESCAPE_STRING func)
69 char buffer[MAX_STRING_LEN * 4];
72 vp_prints_value(buffer, sizeof(buffer), pair, -1);
73 return func(out, outlen, buffer);
78 strlcpy(out,"_",outlen);
80 case PW_TYPE_INTEGER :
81 strlcpy(out,"0",outlen);
84 strlcpy(out,"?.?.?.?",outlen);
86 case PW_TYPE_IPV6ADDR :
87 strlcpy(out,":?:",outlen);
90 strlcpy(out,"0",outlen);
93 strlcpy(out,"unknown_type",outlen);
100 * Dynamically translate for check:, request:, reply:, etc.
102 static size_t xlat_packet(void *instance, REQUEST *request,
103 char *fmt, char *out, size_t outlen,
104 RADIUS_ESCAPE_STRING func)
108 VALUE_PAIR *vps = NULL;
109 RADIUS_PACKET *packet = NULL;
111 switch (*(int*) instance) {
113 vps = request->config_items;
117 vps = request->packet->vps;
118 packet = request->packet;
122 vps = request->reply->vps;
123 packet = request->reply;
128 if (request->proxy) vps = request->proxy->vps;
129 packet = request->proxy;
135 if (request->proxy_reply) vps = request->proxy_reply->vps;
136 packet = request->proxy_reply;
141 if (request->parent) {
142 vps = request->parent->packet->vps;
143 packet = request->parent->packet;
148 if (request->parent && request->parent->reply) {
149 vps = request->parent->reply->vps;
150 packet = request->parent->reply;
155 if (request->parent) {
156 vps = request->parent->config_items;
165 * The "format" string is the attribute name.
167 da = dict_attrbyname(fmt);
169 int do_number = FALSE;
174 if (strlen(fmt) > sizeof(buffer)) return 0;
176 p = strchr(fmt, '[');
178 p = strchr(fmt, '#');
183 strlcpy(buffer, fmt, p - fmt + 1);
185 da = dict_attrbyname(buffer);
189 vp = pairfind(vps, da->attr, 0);
196 case PW_TYPE_INTEGER:
200 snprintf(out, outlen, "%u", vp->lvalue);
208 * %{Attribute-Name[#]} returns the count of
209 * attributes of that name in the list.
211 if ((p[1] == '#') && (p[2] == ']')) {
214 for (vp = pairfind(vps, da->attr, da->vendor);
216 vp = pairfind(vp->next, da->attr, da->vendor)) {
219 snprintf(out, outlen, "%d", (int) count);
224 * %{Attribute-Name[*]} returns ALL of the
225 * the attributes, separated by a newline.
227 if ((p[1] == '*') && (p[2] == ']')) {
230 for (vp = pairfind(vps, da->attr, da->vendor);
232 vp = pairfind(vp->next, da->attr, da->vendor)) {
233 count = valuepair2str(out, outlen - 1, vp, da->type, func);
234 rad_assert(count <= outlen);
236 outlen -= (count + 1);
241 if (outlen <= 1) break;
253 p += 1 + strspn(p + 1, "0123456789");
255 RDEBUG2("xlat: Invalid array reference in string at %s %s",
261 * Find the N'th value.
263 for (vp = pairfind(vps, da->attr, da->vendor);
265 vp = pairfind(vp->next, da->attr, da->vendor)) {
266 if (count == 0) break;
271 * Non-existent array reference.
275 return valuepair2str(out, outlen, vp, da->type, func);
278 vp = pairfind(vps, da->attr, da->vendor);
281 * Some "magic" handlers, which are never in VP's, but
282 * which are in the packet.
284 * FIXME: We should really do this in a more
290 memset(&localvp, 0, sizeof(localvp));
297 dval = dict_valbyattr(da->attr, da->vendor, packet->code);
299 snprintf(out, outlen, "%s", dval->name);
301 snprintf(out, outlen, "%d", packet->code);
307 case PW_CLIENT_SHORTNAME:
308 if (request->client && request->client->shortname) {
309 strlcpy(out, request->client->shortname, outlen);
311 strlcpy(out, "<UNKNOWN-CLIENT>", outlen);
315 case PW_CLIENT_IP_ADDRESS: /* the same as below */
316 case PW_PACKET_SRC_IP_ADDRESS:
317 if (packet->src_ipaddr.af != AF_INET) {
320 localvp.attribute = da->attr;
321 localvp.vp_ipaddr = packet->src_ipaddr.ipaddr.ip4addr.s_addr;
324 case PW_PACKET_DST_IP_ADDRESS:
325 if (packet->dst_ipaddr.af != AF_INET) {
328 localvp.attribute = da->attr;
329 localvp.vp_ipaddr = packet->dst_ipaddr.ipaddr.ip4addr.s_addr;
332 case PW_PACKET_SRC_PORT:
333 localvp.attribute = da->attr;
334 localvp.vp_integer = packet->src_port;
337 case PW_PACKET_DST_PORT:
338 localvp.attribute = da->attr;
339 localvp.vp_integer = packet->dst_port;
342 case PW_PACKET_AUTHENTICATION_VECTOR:
343 localvp.attribute = da->attr;
344 memcpy(localvp.vp_strvalue, packet->vector,
345 sizeof(packet->vector));
346 localvp.length = sizeof(packet->vector);
350 * Authorization, accounting, etc.
352 case PW_REQUEST_PROCESSING_STAGE:
353 if (request->component) {
354 strlcpy(out, request->component, outlen);
356 strlcpy(out, "server_core", outlen);
360 case PW_PACKET_SRC_IPV6_ADDRESS:
361 if (packet->src_ipaddr.af != AF_INET6) {
364 localvp.attribute = da->attr;
365 memcpy(localvp.vp_strvalue,
366 &packet->src_ipaddr.ipaddr.ip6addr,
367 sizeof(packet->src_ipaddr.ipaddr.ip6addr));
370 case PW_PACKET_DST_IPV6_ADDRESS:
371 if (packet->dst_ipaddr.af != AF_INET6) {
374 localvp.attribute = da->attr;
375 memcpy(localvp.vp_strvalue,
376 &packet->dst_ipaddr.ipaddr.ip6addr,
377 sizeof(packet->dst_ipaddr.ipaddr.ip6addr));
380 case PW_VIRTUAL_SERVER:
381 if (!request->server) return 0;
383 snprintf(out, outlen, "%s", request->server);
387 case PW_MODULE_RETURN_CODE:
388 localvp.attribute = da->attr;
391 * See modcall.c for a bit of a hack.
393 localvp.vp_integer = request->simul_max;
397 return 0; /* not found */
401 localvp.type = da->type;
402 return valuepair2str(out, outlen, &localvp,
412 if (!vps) return 0; /* silently fail */
415 * Convert the VP to a string, and return it.
417 return valuepair2str(out, outlen, vp, da->type, func);
421 * Print data as integer, not as VALUE.
423 static size_t xlat_integer(UNUSED void *instance, REQUEST *request,
424 char *fmt, char *out, size_t outlen,
425 UNUSED RADIUS_ESCAPE_STRING func)
429 while (isspace((int) *fmt)) fmt++;
431 if (!radius_get_vp(request, fmt, &vp) || !vp) {
436 if ((vp->type != PW_TYPE_IPADDR) &&
437 (vp->type != PW_TYPE_INTEGER) &&
438 (vp->type != PW_TYPE_SHORT) &&
439 (vp->type != PW_TYPE_BYTE) &&
440 (vp->type != PW_TYPE_DATE)) {
445 return snprintf(out, outlen, "%u", vp->vp_integer);
449 * Print data as string, if possible.
451 static size_t xlat_string(UNUSED void *instance, REQUEST *request,
452 char *fmt, char *out, size_t outlen,
453 UNUSED RADIUS_ESCAPE_STRING func)
458 while (isspace((int) *fmt)) fmt++;
466 if (!radius_get_vp(request, fmt, &vp)) goto nothing;
468 if (!vp) goto nothing;
470 if (vp->type != PW_TYPE_OCTETS) goto nothing;
473 len = fr_print_string(vp->vp_strvalue, vp->length, out + 1, outlen - 3);
482 * Pull %{0} to %{8} out of the packet.
484 static size_t xlat_regex(void *instance, REQUEST *request,
485 char *fmt, char *out, size_t outlen,
486 RADIUS_ESCAPE_STRING func)
491 * We cheat: fmt is "0" to "8", but those numbers
492 * are already in the "instance".
494 fmt = fmt; /* -Wunused */
495 func = func; /* -Wunused FIXME: do escaping? */
497 regex = request_data_reference(request, request,
498 REQUEST_DATA_REGEX | *(int *)instance);
499 if (!regex) return 0;
502 * Copy UP TO "freespace" bytes, including
505 strlcpy(out, regex, outlen);
508 #endif /* HAVE_REGEX_H */
512 * Change the debugging level.
514 static size_t xlat_debug(UNUSED void *instance, REQUEST *request,
515 char *fmt, char *out, size_t outlen,
516 UNUSED RADIUS_ESCAPE_STRING func)
520 if (*fmt) level = atoi(fmt);
523 request->options = RAD_REQUEST_OPTION_NONE;
524 request->radlog = NULL;
526 if (level > 4) level = 4;
528 request->options = level;
529 request->radlog = radlog_request;
532 snprintf(out, outlen, "%d", level);
538 * Calculate the MD5 hash of a string.
540 static size_t xlat_md5(UNUSED void *instance, REQUEST *request,
541 char *fmt, char *out, size_t outlen,
542 UNUSED RADIUS_ESCAPE_STRING func)
549 if (!radius_xlat(buffer, sizeof(buffer), fmt, request, func)) {
555 fr_MD5Update(&ctx, (void *) buffer, strlen(buffer));
556 fr_MD5Final(digest, &ctx);
559 snprintf(out, outlen, "md5_overflow");
563 for (i = 0; i < 16; i++) {
564 snprintf(out + i * 2, 3, "%02x", digest[i]);
572 * Convert a string to lowercase
574 static size_t xlat_lc(UNUSED void *instance, REQUEST *request,
575 char *fmt, char *out, size_t outlen,
576 UNUSED RADIUS_ESCAPE_STRING func)
581 if (outlen <= 1) return 0;
583 if (!radius_xlat(buffer, sizeof(buffer), fmt, request, func)) {
588 for (p = buffer, q = out; *p != '\0'; p++, outlen--) {
589 if (outlen <= 1) break;
591 *(q++) = tolower((int) *p);
601 * Convert a string to uppercase
603 static size_t xlat_uc(UNUSED void *instance, REQUEST *request,
604 char *fmt, char *out, size_t outlen,
605 UNUSED RADIUS_ESCAPE_STRING func)
610 if (outlen <= 1) return 0;
612 if (!radius_xlat(buffer, sizeof(buffer), fmt, request, func)) {
617 for (p = buffer, q = out; *p != '\0'; p++, outlen--) {
618 if (outlen <= 1) break;
620 *(q++) = toupper((int) *p);
630 * Compare two xlat_t structs, based ONLY on the module name.
632 static int xlat_cmp(const void *a, const void *b)
634 if (((const xlat_t *)a)->length != ((const xlat_t *)b)->length) {
635 return ((const xlat_t *)a)->length - ((const xlat_t *)b)->length;
638 return memcmp(((const xlat_t *)a)->module,
639 ((const xlat_t *)b)->module,
640 ((const xlat_t *)a)->length);
644 * find the appropriate registered xlat function.
646 static xlat_t *xlat_find(const char *module)
651 * Look for dictionary attributes first.
653 if ((dict_attrbyname(module) != NULL) ||
654 (strchr(module, '[') != NULL) ||
655 (strchr(module, '#') != NULL)) {
659 strlcpy(my_xlat.module, module, sizeof(my_xlat.module));
660 my_xlat.length = strlen(my_xlat.module);
662 return rbtree_finddata(xlat_root, &my_xlat);
667 * Register an xlat function.
669 int xlat_register(const char *module, RAD_XLAT_FUNC func, void *instance)
674 if ((module == NULL) || (strlen(module) == 0)) {
675 DEBUG("xlat_register: Invalid module name");
680 * First time around, build up the tree...
682 * FIXME: This code should be hoisted out of this function,
683 * and into a global "initialization". But it isn't critical...
691 xlat_root = rbtree_create(xlat_cmp, free, 0);
693 DEBUG("xlat_register: Failed to create tree.");
698 * Register the internal packet xlat's.
700 for (i = 0; internal_xlat[i] != NULL; i++) {
701 xlat_register(internal_xlat[i], xlat_packet, &xlat_inst[i]);
702 c = xlat_find(internal_xlat[i]);
703 rad_assert(c != NULL);
708 * New name: "control"
710 xlat_register("control", xlat_packet, &xlat_inst[0]);
711 c = xlat_find("control");
712 rad_assert(c != NULL);
715 xlat_register("integer", xlat_integer, "");
716 c = xlat_find("integer");
717 rad_assert(c != NULL);
720 xlat_register("string", xlat_string, "");
721 c = xlat_find("string");
722 rad_assert(c != NULL);
727 * Register xlat's for regexes.
730 for (i = 0; i <= REQUEST_MAX_REGEX; i++) {
732 xlat_register(buffer, xlat_regex, &xlat_inst[i]);
733 c = xlat_find(buffer);
734 rad_assert(c != NULL);
737 #endif /* HAVE_REGEX_H */
740 xlat_register("debug", xlat_debug, &xlat_inst[0]);
741 c = xlat_find("debug");
742 rad_assert(c != NULL);
745 xlat_register("md5", xlat_md5, &xlat_inst[0]);
746 c = xlat_find("md5");
747 rad_assert(c != NULL);
750 xlat_register("tolower", xlat_lc, &xlat_inst[0]);
751 c = xlat_find("tolower");
752 rad_assert(c != NULL);
755 xlat_register("toupper", xlat_uc, &xlat_inst[0]);
756 c = xlat_find("toupper");
757 rad_assert(c != NULL);
762 * If it already exists, replace the instance.
764 strlcpy(my_xlat.module, module, sizeof(my_xlat.module));
765 my_xlat.length = strlen(my_xlat.module);
766 c = rbtree_finddata(xlat_root, &my_xlat);
769 DEBUG("xlat_register: Cannot re-define internal xlat");
774 c->instance = instance;
779 * Doesn't exist. Create it.
781 c = rad_malloc(sizeof(*c));
782 memset(c, 0, sizeof(*c));
785 strlcpy(c->module, module, sizeof(c->module));
786 c->length = strlen(c->module);
787 c->instance = instance;
789 rbtree_insert(xlat_root, c);
795 * Unregister an xlat function.
797 * We can only have one function to call per name, so the
798 * passing of "func" here is extraneous.
800 void xlat_unregister(const char *module, RAD_XLAT_FUNC func)
805 func = func; /* -Wunused */
809 strlcpy(my_xlat.module, module, sizeof(my_xlat.module));
810 my_xlat.length = strlen(my_xlat.module);
812 node = rbtree_find(xlat_root, &my_xlat);
815 rbtree_delete(xlat_root, node);
819 * De-register all xlat functions,
820 * used mainly for debugging.
824 rbtree_free(xlat_root);
829 * Decode an attribute name into a string.
831 static int decode_attribute(const char **from, char **to, int freespace,
833 RADIUS_ESCAPE_STRING func)
836 char *xlat_name, *xlat_str;
837 char *p, *q, *l, *next = NULL;
848 * Copy the input string to an intermediate buffer where
851 varlen = rad_copy_variable(buffer, *from);
853 RDEBUG2("ERROR: Badly formatted variable: %s", *from);
859 * Kill the %{} around the data we are looking for.
862 p[varlen - 1] = '\0'; /* */
870 * Handle %{%{foo}:-%{bar}}, which is useful, too.
872 * Did I mention that this parser is garbage?
874 if ((p[0] == '%') && (p[1] == '{')) {
879 * 'p' is after the start of 'buffer', so we can
882 len1 = rad_copy_variable(buffer, p);
884 RDEBUG2("ERROR: Badly formatted variable: %s", p);
889 * They did %{%{foo}}, which is stupid, but allowed.
892 RDEBUG2("Improperly nested variable; %%{%s}", p);
897 * It SHOULD be %{%{foo}:-%{bar}}. If not, it's
900 if ((p[len1] != ':') || (p[len1 + 1] != '-')) {
901 RDEBUG2("No trailing :- after variable at %s", p);
906 * Parse the second bit. The second bit can be
907 * either %{foo}, or a string "foo", or a string
908 * 'foo', or just a bare word: foo
911 l = buffer + len1 + 1;
913 if ((p[0] == '%') && (p[1] == '{')) {
914 len2 = rad_copy_variable(l, p);
917 RDEBUG2("ERROR: Invalid text after :- at %s", p);
923 } else if ((p[0] == '"') || p[0] == '\'') {
924 getstring((const char **) &p, l, strlen(l));
931 * Expand the first one. If we did, exit the
934 retlen = radius_xlat(q, freespace, buffer, request, func);
940 RDEBUG2("\t... expanding second conditional");
942 * Expand / copy the second string if required.
945 retlen = radius_xlat(q, freespace, l,
951 strlcpy(q, l, freespace);
956 * Else the output is an empty string.
962 * See if we're supposed to expand a module name.
965 for (l = p; *l != '\0'; l++) {
972 xlat_name = p; /* start of name */
979 * Module names can't have spaces.
981 if ((*l == ' ') || (*l == '\t')) break;
985 * %{name} is a simple attribute reference,
986 * or regex reference.
989 xlat_name = xlat_str = p;
994 * Maybe it's the old-style %{foo:-bar}
997 RDEBUG2("WARNING: Deprecated conditional expansion \":-\". See \"man unlang\" for details");
1000 xlat_str = xlat_name;
1006 * FIXME: For backwards "WTF" compatibility, check for
1007 * {...}, (after the :), and copy that, too.
1010 /* module name, followed by (possibly) per-module string */
1014 if ((c = xlat_find(xlat_name)) != NULL) {
1015 if (!c->internal) RDEBUG3("radius_xlat: Running registered xlat function of module %s for string \'%s\'",
1016 c->module, xlat_str);
1017 retlen = c->do_xlat(c->instance, request, xlat_str,
1018 q, freespace, func);
1021 snprintf(q, freespace, "%d", retlen);
1027 * Expand the second bit.
1029 RDEBUG2("\t... expanding second conditional");
1030 retlen = radius_xlat(q, freespace, next, request, func);
1036 * No attribute by that name, return an error.
1038 RDEBUG2("WARNING: Unknown module \"%s\" in string expansion \"%%%s\"", xlat_name, *from);
1048 * If the caller doesn't pass xlat an escape function, then
1049 * we use this one. It simplifies the coding, as the check for
1050 * func == NULL only happens once.
1052 static size_t xlat_copy(char *out, size_t outlen, const char *in)
1054 int freespace = outlen;
1056 if (outlen < 1) return 0;
1058 while ((*in) && (freespace > 1)) {
1062 * FIXME: Do escaping of bad stuff!
1070 return (outlen - freespace); /* count does not include NUL */
1074 * Replace %<whatever> in a string.
1076 * See 'doc/variables.txt' for more information.
1078 int radius_xlat(char *out, int outlen, const char *fmt,
1079 REQUEST *request, RADIUS_ESCAPE_STRING func)
1081 int c, len, freespace;
1086 struct tm *TM, s_TM;
1087 char tmpdt[40]; /* For temporary storing of dates */
1091 * Catch bad modules.
1093 if (!fmt || !out || !request) return 0;
1096 * Ensure that we always have an escaping function.
1105 /* Calculate freespace in output */
1106 freespace = outlen - (q - out);
1111 if ((c != '%') && (c != '$') && (c != '\\')) {
1113 * We check if we're inside an open brace. If we are
1114 * then we assume this brace is NOT literal, but is
1115 * a closing brace and apply it
1117 if ((c == '}') && openbraces) {
1127 * There's nothing after this character, copy
1128 * the last '%' or "$' or '\\' over to the output
1154 } else if (c == '%') switch(*p) {
1157 if (decode_attribute(&p, &q, freespace, request, func) < 0) return 0;
1163 case 'a': /* Protocol: */
1164 q += valuepair2str(q,freespace,pairfind(request->reply->vps,PW_FRAMED_PROTOCOL, 0),PW_TYPE_INTEGER, func);
1167 case 'c': /* Callback-Number */
1168 q += valuepair2str(q,freespace,pairfind(request->reply->vps,PW_CALLBACK_NUMBER, 0),PW_TYPE_STRING, func);
1171 case 'd': /* request day */
1172 TM = localtime_r(&request->timestamp, &s_TM);
1173 len = strftime(tmpdt, sizeof(tmpdt), "%d", TM);
1175 strlcpy(q, tmpdt, freespace);
1180 case 'f': /* Framed IP address */
1181 q += valuepair2str(q,freespace,pairfind(request->reply->vps,PW_FRAMED_IP_ADDRESS, 0),PW_TYPE_IPADDR, func);
1184 case 'i': /* Calling station ID */
1185 q += valuepair2str(q,freespace,pairfind(request->packet->vps,PW_CALLING_STATION_ID, 0),PW_TYPE_STRING, func);
1188 case 'l': /* request timestamp */
1189 snprintf(tmpdt, sizeof(tmpdt), "%lu",
1190 (unsigned long) request->timestamp);
1191 strlcpy(q,tmpdt,freespace);
1195 case 'm': /* request month */
1196 TM = localtime_r(&request->timestamp, &s_TM);
1197 len = strftime(tmpdt, sizeof(tmpdt), "%m", TM);
1199 strlcpy(q, tmpdt, freespace);
1204 case 'n': /* NAS IP address */
1205 q += valuepair2str(q,freespace,pairfind(request->packet->vps,PW_NAS_IP_ADDRESS, 0),PW_TYPE_IPADDR, func);
1208 case 'p': /* Port number */
1209 q += valuepair2str(q,freespace,pairfind(request->packet->vps,PW_NAS_PORT, 0),PW_TYPE_INTEGER, func);
1212 case 's': /* Speed */
1213 q += valuepair2str(q,freespace,pairfind(request->packet->vps,PW_CONNECT_INFO, 0),PW_TYPE_STRING, func);
1216 case 't': /* request timestamp */
1217 CTIME_R(&request->timestamp, tmpdt, sizeof(tmpdt));
1218 nl = strchr(tmpdt, '\n');
1220 strlcpy(q, tmpdt, freespace);
1224 case 'u': /* User name */
1225 q += valuepair2str(q,freespace,pairfind(request->packet->vps,PW_USER_NAME, 0),PW_TYPE_STRING, func);
1228 case 'A': /* radacct_dir */
1229 strlcpy(q,radacct_dir,freespace);
1233 case 'C': /* ClientName */
1234 strlcpy(q,request->client->shortname,freespace);
1238 case 'D': /* request date */
1239 TM = localtime_r(&request->timestamp, &s_TM);
1240 len = strftime(tmpdt, sizeof(tmpdt), "%Y%m%d", TM);
1242 strlcpy(q, tmpdt, freespace);
1247 case 'H': /* request hour */
1248 TM = localtime_r(&request->timestamp, &s_TM);
1249 len = strftime(tmpdt, sizeof(tmpdt), "%H", TM);
1251 strlcpy(q, tmpdt, freespace);
1256 case 'L': /* radlog_dir */
1257 strlcpy(q,radlog_dir,freespace);
1262 q += valuepair2str(q,freespace,pairfind(request->reply->vps,PW_FRAMED_MTU, 0),PW_TYPE_INTEGER, func);
1265 case 'R': /* radius_dir */
1266 strlcpy(q,radius_dir,freespace);
1270 case 'S': /* request timestamp in SQL format*/
1271 TM = localtime_r(&request->timestamp, &s_TM);
1272 len = strftime(tmpdt, sizeof(tmpdt), "%Y-%m-%d %H:%M:%S", TM);
1274 strlcpy(q, tmpdt, freespace);
1279 case 'T': /* request timestamp */
1280 TM = localtime_r(&request->timestamp, &s_TM);
1281 len = strftime(tmpdt, sizeof(tmpdt), "%Y-%m-%d-%H.%M.%S.000000", TM);
1283 strlcpy(q, tmpdt, freespace);
1288 case 'U': /* Stripped User name */
1289 q += valuepair2str(q,freespace,pairfind(request->packet->vps,PW_STRIPPED_USER_NAME, 0),PW_TYPE_STRING, func);
1292 case 'V': /* Request-Authenticator */
1293 strlcpy(q,"Verified",freespace);
1297 case 'Y': /* request year */
1298 TM = localtime_r(&request->timestamp, &s_TM);
1299 len = strftime(tmpdt, sizeof(tmpdt), "%Y", TM);
1301 strlcpy(q, tmpdt, freespace);
1306 case 'Z': /* Full request pairs except password */
1307 tmp = request->packet->vps;
1308 while (tmp && (freespace > 3)) {
1309 if (tmp->attribute != PW_USER_PASSWORD) {
1311 len = vp_prints(q, freespace - 2, tmp);
1313 freespace -= (len + 2);
1321 RDEBUG2("WARNING: Unknown variable '%%%c': See 'doc/variables.txt'", *p);
1322 if (freespace > 2) {
1331 RDEBUG2("\texpand: %s -> %s", fmt, out);