]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add utc option to sqlcounter
authorNick Porter <nick@portercomputing.co.uk>
Sun, 18 Feb 2024 16:16:49 +0000 (16:16 +0000)
committerNick Porter <nick@portercomputing.co.uk>
Sun, 18 Feb 2024 16:16:49 +0000 (16:16 +0000)
raddb/mods-available/sqlcounter
src/modules/rlm_sqlcounter/rlm_sqlcounter.c

index 752b36d4cf80b8039bc61a3c2160325447ca303e..21d35a9f914345443c880e0fd65f95d5dce4cfac 100644 (file)
 #  `Session-Timeout` is the `reply_name` attribute.  If there is sufficient allocation
 #  left for the session to get to the next counter period, the user will not have
 #  to re-authenticate before they have used their allocation for the next counter period.
+#
+#  utc:: Use UTC for calculating the period start and end values.
 
 #
 #  ## Configuration Settings
index fee8783fff89e06c1a2690403d63a0267a079902..63b2f94ea5b5c22401f560f92538255ef7a5e589 100644 (file)
@@ -72,6 +72,7 @@ typedef struct {
        char const      *reset;         //!< Daily, weekly, monthly, never or user defined.
        bool            auto_extend;    //!< If the remaining allowance is sufficient to reach the next
                                        ///< period allow for that in setting the reply attribute.
+       bool            utc;            //!< Use UTC time.
 
        fr_time_t       reset_time;
        fr_time_t       last_reset;
@@ -84,6 +85,7 @@ static const conf_parser_t module_config[] = {
        { FR_CONF_OFFSET_FLAGS("query", CONF_FLAG_XLAT | CONF_FLAG_REQUIRED, rlm_sqlcounter_t, query) },
        { FR_CONF_OFFSET_FLAGS("reset", CONF_FLAG_REQUIRED, rlm_sqlcounter_t, reset) },
        { FR_CONF_OFFSET_FLAGS("auto_extend", CONF_FLAG_OK_MISSING, rlm_sqlcounter_t, auto_extend) },
+       { FR_CONF_OFFSET_FLAGS("utc", CONF_FLAG_OK_MISSING, rlm_sqlcounter_t, utc) },
 
        { FR_CONF_OFFSET_FLAGS("key", CONF_FLAG_NOT_EMPTY, rlm_sqlcounter_t, key), .dflt = "%{%{Stripped-User-Name} || %{User-Name}}", .quote = T_DOUBLE_QUOTED_STRING },
 
@@ -122,7 +124,11 @@ static int find_next_reset(rlm_sqlcounter_t *inst, fr_time_t now)
        struct tm       *tm, s_tm;
        time_t          time_s = fr_time_to_sec(now);
 
-       tm = localtime_r(&time_s, &s_tm);
+       if (inst->utc) {
+               tm = gmtime_r(&time_s, &s_tm);
+       } else {
+               tm = localtime_r(&time_s, &s_tm);
+       }
        tm->tm_sec = tm->tm_min = 0;
 
        fr_assert(inst->reset != NULL);
@@ -186,7 +192,11 @@ static int find_prev_reset(rlm_sqlcounter_t *inst, fr_time_t now)
        struct          tm *tm, s_tm;
        time_t          time_s = fr_time_to_sec(now);
 
-       tm = localtime_r(&time_s, &s_tm);
+       if (inst->utc) {
+               tm = gmtime_r(&time_s, &s_tm);
+       } else {
+               tm = localtime_r(&time_s, &s_tm);
+       }
        tm->tm_sec = tm->tm_min = 0;
 
        fr_assert(inst->reset != NULL);