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
On Wed, Mar 29, 2017 at 10:12:25PM +1300, Peter Lambrechtsen wrote:
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");
typo: localtime -> UTC
+ 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); ...
Thoughts / comments??
Seems like a good idea to me. UTC/Localtime is always a pain, so as flexible as possible makes sense. Matthew -- Matthew Newton, Ph.D. <mcn4@leicester.ac.uk> Systems Specialist, Infrastructure Services, I.T. Services, University of Leicester, Leicester LE1 7RH, United Kingdom For IT help contact helpdesk extn. 2253, <ithelp@le.ac.uk>
Seems like a good idea to me. UTC/Localtime is always a pain, so as flexible as possible makes sense.
+1 :-) Stefan Paetow Moonshot Industry & Research Liaison Coordinator t: +44 (0)1235 822 125 gpg: 0x3FCE5142 xmpp: stefanp@jabber.dev.ja.net skype: stefan.paetow.janet jisc.ac.uk Jisc is a registered charity (number 1149740) and a company limited by guarantee which is registered in England under Company No. 5747339, VAT No. GB 197 0632 86. Jisc’s registered office is: One Castlepark, Tower Hill, Bristol, BS2 0JA. T 0203 697 5800.
On Mar 29, 2017, at 5:12 AM, Peter Lambrechtsen <peter@crypt.nz> wrote:
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.
Looks good. I've added the patch. Alan DeKok.
participants (4)
-
Alan DeKok -
Matthew Newton -
Peter Lambrechtsen -
Stefan Paetow