]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add utc option to rlm_date
authorMatthew Newton <matthew-git@newtoncomputing.co.uk>
Tue, 20 Mar 2018 18:53:54 +0000 (13:53 -0500)
committerMatthew Newton <matthew-git@newtoncomputing.co.uk>
Tue, 20 Mar 2018 19:06:38 +0000 (19:06 +0000)
raddb/mods-available/date
src/modules/rlm_date/rlm_date.c

index bd4737d13d92749ab34d96610cea04d13ade4aa4..a6e00fb619a78e09c845381fe8fd3814aa8faff0 100644 (file)
 #
 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
 }
index b257abf7062e584ea2ac9af424538182a610adac..f6633e6fb66d9e6afdd4dfdc497d0e2bdf3a539c 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[] = {
        { 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);