Allow utc. Patch from Peter Lambrechtsen
authorAlan T. DeKok <aland@freeradius.org>
Wed, 29 Mar 2017 14:54:07 +0000 (10:54 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 29 Mar 2017 14:54:07 +0000 (10:54 -0400)
raddb/mods-available/date
src/modules/rlm_date/rlm_date.c

index bd4737d..2438b81 100644 (file)
@@ -11,4 +11,9 @@
 #
 date {
        format = "%b %e %Y %H:%M:%S %Z"
+
+       # Use UTC instead of local time.
+       #
+       #  default = no
+#      utc = yes
 }
index d8278cc..86a7d62 100644 (file)
 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
 };
 
@@ -69,9 +71,16 @@ static ssize_t xlat_date_convert(void *instance, REQUEST *request, char const *f
                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 (localtime_r(&date, &tminfo) == NULL) {
+                               REDEBUG("Failed converting time string to localtime");
+                               goto error;
+                       }
+               } else {
+                       if (gmtime_r(&date, &tminfo) == NULL) {
+                               REDEBUG("Failed converting time string to gmtime");
+                               goto error;
+                       }
                }
                return strftime(out, outlen, inst->fmt, &tminfo);