From: Alan T. DeKok Date: Fri, 4 May 2012 15:14:08 +0000 (+0200) Subject: Added %{hex:...} X-Git-Tag: release_3_0_0_beta0~198 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5cc3821e794fa0c57e7eca9348818e885e352f9e;p=thirdparty%2Ffreeradius-server.git Added %{hex:...} Will print the hex version of the contents of the attribute. Mainly useful for integers, IPaddresses, etc. --- diff --git a/src/main/xlat.c b/src/main/xlat.c index 522bcf27ae1..7f4932e90ef 100644 --- a/src/main/xlat.c +++ b/src/main/xlat.c @@ -524,6 +524,40 @@ static size_t xlat_integer(UNUSED void *instance, REQUEST *request, return snprintf(out, outlen, "%u", vp->vp_integer); } +/** + * @brief Print data as hex, not as VALUE. + */ +static size_t xlat_hex(UNUSED void *instance, REQUEST *request, + char *fmt, char *out, size_t outlen, + UNUSED RADIUS_ESCAPE_STRING func) +{ + size_t i; + uint8_t *p; + VALUE_PAIR *vp; + + while (isspace((int) *fmt)) fmt++; + + if (!radius_get_vp(request, fmt, &vp) || !vp) { + *out = '\0'; + return 0; + } + + /* + * Don't truncate the data. + */ + if (outlen < (vp->length * 2)) { + *out = 0; + return 0; + } + + p = &vp->vp_octets[0]; + for (i = 0; i < vp->length; i++) { + snprintf(out + 2*i, 3, "%02x", p[i]); + } + + return vp->length * 2; +} + #ifdef WITH_UNLANG /** @@ -842,6 +876,11 @@ int xlat_register(const char *module, RAD_XLAT_FUNC func, void *instance) rad_assert(c != NULL); c->internal = TRUE; + xlat_register("hex", xlat_hex, NULL); + c = xlat_find("hex"); + rad_assert(c != NULL); + c->internal = TRUE; + xlat_register("string", xlat_string, NULL); c = xlat_find("string"); rad_assert(c != NULL);