From: Matthew Newton Date: Tue, 20 Mar 2018 18:53:54 +0000 (-0500) Subject: add utc option to rlm_date X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2777b98b31240efdb158e4ae33af3c632b8ebcdb;p=thirdparty%2Ffreeradius-server.git add utc option to rlm_date --- diff --git a/raddb/mods-available/date b/raddb/mods-available/date index bd4737d13d9..a6e00fb619a 100644 --- a/raddb/mods-available/date +++ b/raddb/mods-available/date @@ -11,4 +11,10 @@ # date { format = "%b %e %Y %H:%M:%S %Z" + + # If "utc" is enabled then any conversions from a date + # attribute to a string will be made as UTC, not localtime. + # Default is to use localtime. + # + #utc = no } diff --git a/src/modules/rlm_date/rlm_date.c b/src/modules/rlm_date/rlm_date.c index b257abf7062..f6633e6fb66 100644 --- a/src/modules/rlm_date/rlm_date.c +++ b/src/modules/rlm_date/rlm_date.c @@ -32,10 +32,12 @@ typedef struct rlm_date_t { char const *xlat_name; char const *fmt; + bool utc; } rlm_date_t; static const CONF_PARSER module_config[] = { { FR_CONF_OFFSET("format", FR_TYPE_STRING, rlm_date_t, fmt), .dflt = "%b %e %Y %H:%M:%S %Z" }, + { FR_CONF_OFFSET("utc", FR_TYPE_BOOL, rlm_date_t, utc), .dflt = "no" }, CONF_PARSER_TERMINATOR }; @@ -68,9 +70,16 @@ static ssize_t xlat_date_convert(UNUSED TALLOC_CTX *ctx, char **out, size_t outl date = (time_t) vp->vp_uint32; encode: - if (localtime_r(&date, &tminfo) == NULL) { - REDEBUG("Failed converting time string to localtime"); - goto error; + if (inst->utc) { + if (gmtime_r(&date, &tminfo) == NULL) { + REDEBUG("Failed converting time string to gmtime"); + goto error; + } + } else { + if (localtime_r(&date, &tminfo) == NULL) { + REDEBUG("Failed converting time string to localtime"); + goto error; + } } return strftime(*out, outlen, inst->fmt, &tminfo);