]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add reply message attribute to sqlcounter call_env
authorNick Porter <nick@portercomputing.co.uk>
Tue, 13 Feb 2024 16:45:30 +0000 (16:45 +0000)
committerNick Porter <nick@portercomputing.co.uk>
Thu, 15 Feb 2024 16:32:33 +0000 (16:32 +0000)
raddb/mods-available/sqlcounter
src/modules/rlm_sqlcounter/rlm_sqlcounter.c

index 3eb5cf24cb0dfa28218b0d10d6009f804e125085..eec50ee9e91c6ab923b7908646c20cf88581d16c 100644 (file)
@@ -98,6 +98,9 @@
 #  reply_name:: Name of the attribute to populate with the remaining session time.
 #  e.g. `&reply.Session-Timeout`.  If the attribute already exists and contains
 #  a lower value, then it will not be updated.
+#
+#  reply_message_name:: Name of the attribute into which a message should be placed
+#  if the limit has been exeeded for the counter.
 
 #
 #  ## Configuration Settings
@@ -116,6 +119,7 @@ sqlcounter dailycounter {
        check_name = &control.Max-Daily-Session
        reply_name = &reply.Session-Timeout
        key = "%{&Stripped-User-Name || &User-Name}"
+       reply_message_name = &Reply-Message
 
        reset = daily
 
index 5527417c803af27b66b0e231399a31355c827569..ed483e5393be540a1c3f1ff3b28c9ea03c029f33 100644 (file)
@@ -98,6 +98,7 @@ static const conf_parser_t module_config[] = {
 
 typedef struct {
        tmpl_t          *reply_attr;            //!< Attribute to write timeout to.
+       tmpl_t          *reply_msg_attr;        //!< Attribute to write reply message to.
 } sqlcounter_call_env_t;
 
 static fr_dict_t const *dict_freeradius;
@@ -110,12 +111,10 @@ fr_dict_autoload_t rlm_sqlcounter_dict[] = {
        { NULL }
 };
 
-static fr_dict_attr_t const *attr_reply_message;
 static fr_dict_attr_t const *attr_session_timeout;
 
 extern fr_dict_attr_autoload_t rlm_sqlcounter_dict_attr[];
 fr_dict_attr_autoload_t rlm_sqlcounter_dict_attr[] = {
-       { .out = &attr_reply_message, .name = "Reply-Message", .type = FR_TYPE_STRING, .dict = &dict_radius },
        { .out = &attr_session_timeout, .name = "Session-Timeout", .type = FR_TYPE_UINT32, .dict = &dict_radius },
        { NULL }
 };
@@ -319,11 +318,13 @@ static unlang_action_t CC_HINT(nonnull) mod_authorize(rlm_rcode_t *p_result, mod
         *      Check if check item > counter
         */
        if (limit->vp_uint64 <= counter) {
-               /* User is denied access, send back a reply message */
-               snprintf(msg, sizeof(msg), "Your maximum %s usage time has been reached", inst->reset);
+               if (env->reply_msg_attr) {
+                       /* User is denied access, send back a reply message */
+                       snprintf(msg, sizeof(msg), "Your maximum %s usage time has been reached", inst->reset);
 
-               MEM(pair_update_reply(&vp, attr_reply_message) >= 0);
-               fr_pair_value_strdup(vp, msg, false);
+                       MEM(pair_update_reply(&vp, tmpl_attr_tail_da(env->reply_msg_attr)) >= 0);
+                       fr_pair_value_strdup(vp, msg, false);
+               }
 
                REDEBUG2("Maximum %s usage time reached", inst->reset);
                REDEBUG2("Rejecting user, %s value (%" PRIu64 ") is less than counter value (%" PRIu64 ")",
@@ -496,6 +497,7 @@ static const call_env_method_t sqlcounter_call_env = {
        FR_CALL_ENV_METHOD_OUT(sqlcounter_call_env_t),
        .env = (call_env_parser_t[]){
                { FR_CALL_ENV_PARSE_ONLY_OFFSET("reply_name", FR_TYPE_VOID, CALL_ENV_FLAG_PARSE_ONLY, sqlcounter_call_env_t, reply_attr) },
+               { FR_CALL_ENV_PARSE_ONLY_OFFSET("reply_message_name", FR_TYPE_VOID, CALL_ENV_FLAG_PARSE_ONLY, sqlcounter_call_env_t, reply_msg_attr) },
                CALL_ENV_TERMINATOR
        }
 };