rlm_date and utc time
Peter Lambrechtsen
peter at crypt.nz
Wed Mar 29 11:12:25 CEST 2017
Hi Alan & Arran
Using the rlm_date function it only returns time in local time.
Sometimes it would be useful if you can manipulate time in UTC rather than
local time, and depending on how far to take it allowing any time zone
might be useful. Here is a quick patch that I wrote to the module to store
time in utc and update the mods-available to include utc=yes commented out.
--- freeradius-server-3.0.x.old/src/modules/rlm_date/rlm_date.c 2016-03-09
05:20:18.000000000 +1300
+++ freeradius-server-3.0.x/src/modules/rlm_date/rlm_date.c 2017-03-29
13:08:24.293850788 +1300
@@ -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[] = {
{ "format", FR_CONF_OFFSET(PW_TYPE_STRING, rlm_date_t, fmt), "%b %e
%Y %H:%M:%S %Z" },
+ { "utc", FR_CONF_OFFSET(PW_TYPE_BOOLEAN, rlm_date_t, utc), "no" },
CONF_PARSER_TERMINATOR
};
@@ -67,9 +69,16 @@
date = (time_t) vp->vp_integer;
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
localtime");
+ 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);
--- freeradius-server-3.0.x.old/raddb/mods-available/date 2016-03-09
05:20:18.000000000 +1300
+++ freeradius-server-3.0.x/raddb/mods-available/date 2017-03-12
21:01:37.915195157 +1300
@@ -11,4 +11,6 @@
#
date {
format = "%b %e %Y %H:%M:%S %Z"
+ #Use UTC rather than localtime.
+ #utc = yes
}
Thoughts / comments??
Cheers
Peter
More information about the Freeradius-Devel
mailing list