]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
use UTC for date to string, too.
authorAlan T. DeKok <aland@freeradius.org>
Mon, 23 Nov 2020 21:00:22 +0000 (16:00 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 23 Nov 2020 21:17:14 +0000 (16:17 -0500)
Manual port of 7ea17db2d2 from v3.0.x

src/modules/rlm_date/rlm_date.c

index 0ffe83a3fa410666ffd8ffcf5ce5c8b4cc6eeea8..0bade1014eff3a89ca2acf61786825d00d410821 100644 (file)
@@ -43,17 +43,21 @@ static const CONF_PARSER module_config[] = {
 
 DIAG_OFF(format-nonliteral)
 static ssize_t date_convert_string(request_t *request, char **out, size_t outlen,
-                                  const char *str, const char *fmt)
+                                  const char *str, rlm_date_t const *inst)
 {
        struct tm tminfo;
        time_t date = 0;
 
-       if (strptime(str, fmt, &tminfo) == NULL) {
-               REDEBUG("Failed to parse time string \"%s\" as format '%s'", str, fmt);
+       if (strptime(str, inst->fmt, &tminfo) == NULL) {
+               REDEBUG("Failed to parse time string \"%s\" as format '%s'", str, inst->fmt);
                return -1;
        }
 
-       date = mktime(&tminfo);
+       if (inst->utc) {
+               date = timegm(&tminfo);
+       } else {
+               date = mktime(&tminfo);
+       }
        if (date < 0) {
                REDEBUG("Failed converting parsed time into unix time");
                return -1;
@@ -151,7 +155,7 @@ static ssize_t xlat_date_convert(UNUSED TALLOC_CTX *ctx, char **out, size_t outl
         *      unix timestamp.
         */
        case FR_TYPE_STRING:
-               return date_convert_string(request, out, outlen, vp->vp_strvalue, inst->fmt);
+               return date_convert_string(request, out, outlen, vp->vp_strvalue, inst);
 
        default:
                REDEBUG("Can't convert type %s into date", fr_table_str_by_value(fr_value_box_type_table, vp->da->type, "<INVALID>"));