]> git.stg.codes - stg.git/blobdiff - projects/rlm_stg/rlm_stg.c
Merge branch 'stg-2.409-radius'
[stg.git] / projects / rlm_stg / rlm_stg.c
index 0333fadc55304795cbf2b3475895d6e5979a88ae..84df4e7b7cbf683d2a44b4e0e129f2431fedf8d9 100644 (file)
 #include "iface.h"
 #include "stgpair.h"
 
-#ifndef NDEBUG
-#define NDEBUG
 #include <freeradius/ident.h>
 #include <freeradius/radiusd.h>
 #include <freeradius/modules.h>
-#undef NDEBUG
-#endif
 
 #include <stddef.h> // size_t
 
@@ -54,17 +50,18 @@ static void deletePairs(STG_PAIR* pairs)
     free(pairs);
 }
 
-static size_t toVPS(const STG_PAIR* pairs, VALUE_PAIR* vps)
+static size_t toVPS(const STG_PAIR* pairs, VALUE_PAIR** vps)
 {
     const STG_PAIR* pair = pairs;
     size_t count = 0;
 
     while (!emptyPair(pair)) {
         VALUE_PAIR* vp = pairmake(pair->key, pair->value, T_OP_SET);
-        pairadd(&vps, vp);
-        DEBUG("Adding pair '%s': '%s'", pair->key, pair->value);
+        if (vp != NULL) {
+            pairadd(vps, vp);
+            ++count;
+        }
         ++pair;
-        ++count;
     }
 
     return count;
@@ -74,8 +71,9 @@ static size_t toReply(STG_RESULT result, REQUEST* request)
 {
     size_t count = 0;
 
-    count += toVPS(result.modify, request->config_items);
-    count += toVPS(result.reply, request->reply->vps);
+    count += toVPS(result.modify, &request->config_items);
+    pairfree(&request->reply->vps);
+    count += toVPS(result.reply, &request->reply->vps);
 
     deletePairs(result.modify);
     deletePairs(result.reply);
@@ -102,7 +100,7 @@ static STG_PAIR* fromVPS(const VALUE_PAIR* pairs)
         bzero(res[pos].key, sizeof(res[0].key));
         bzero(res[pos].value, sizeof(res[0].value));
         strncpy(res[pos].key, pairs->name, sizeof(res[0].key));
-        strncpy(res[pos].value, pairs->data.strvalue, sizeof(res[0].value));
+        vp_prints_value(res[pos].value, sizeof(res[0].value), (VALUE_PAIR*)pairs, 0);
         ++pos;
         pairs = pairs->next;
     }
@@ -111,6 +109,23 @@ static STG_PAIR* fromVPS(const VALUE_PAIR* pairs)
     return res;
 }
 
+static int toRLMCode(int code)
+{
+    switch (code)
+    {
+        case STG_REJECT:   return RLM_MODULE_REJECT;
+        case STG_FAIL:     return RLM_MODULE_FAIL;
+        case STG_OK:       return RLM_MODULE_OK;
+        case STG_HANDLED:  return RLM_MODULE_HANDLED;
+        case STG_INVALID:  return RLM_MODULE_INVALID;
+        case STG_USERLOCK: return RLM_MODULE_USERLOCK;
+        case STG_NOTFOUND: return RLM_MODULE_NOTFOUND;
+        case STG_NOOP:     return RLM_MODULE_NOOP;
+        case STG_UPDATED:  return RLM_MODULE_UPDATED;
+    }
+    return RLM_MODULE_REJECT;
+}
+
 /*
  *    Do any per-module initialization that is separate to each
  *    configured instance of the module.  e.g. set up connections
@@ -194,7 +209,7 @@ static int stg_authorize(void* instance, REQUEST* request)
     if (count)
         return RLM_MODULE_UPDATED;
 
-    return RLM_MODULE_NOOP;
+    return toRLMCode(result.returnCode);
 }
 
 /*
@@ -235,7 +250,7 @@ static int stg_authenticate(void* instance, REQUEST* request)
     if (count)
         return RLM_MODULE_UPDATED;
 
-    return RLM_MODULE_NOOP;
+    return toRLMCode(result.returnCode);
 }
 
 /*
@@ -276,7 +291,7 @@ static int stg_preacct(void* instance, REQUEST* request)
     if (count)
         return RLM_MODULE_UPDATED;
 
-    return RLM_MODULE_NOOP;
+    return toRLMCode(result.returnCode);
 }
 
 /*
@@ -317,7 +332,7 @@ static int stg_accounting(void* instance, REQUEST* request)
     if (count)
         return RLM_MODULE_UPDATED;
 
-    return RLM_MODULE_OK;
+    return toRLMCode(result.returnCode);
 }
 
 /*
@@ -376,7 +391,7 @@ static int stg_postauth(void* instance, REQUEST* request)
     if (count)
         return RLM_MODULE_UPDATED;
 
-    return RLM_MODULE_NOOP;
+    return toRLMCode(result.returnCode);
 }
 
 static int stg_detach(void* instance)
@@ -386,19 +401,10 @@ static int stg_detach(void* instance)
     return 0;
 }
 
-/*
- *    The module name should be the only globally exported symbol.
- *    That is, everything else should be 'static'.
- *
- *    If the module needs to temporarily modify it's instantiation
- *    data, the type should be changed to RLM_TYPE_THREAD_UNSAFE.
- *    The server will then take care of ensuring that the module
- *    is single-threaded.
- */
 module_t rlm_stg = {
     RLM_MODULE_INIT,
     "stg",
-    RLM_TYPE_THREAD_SAFE, /* type */
+    RLM_TYPE_THREAD_UNSAFE, /* type */
     stg_instantiate,      /* instantiation */
     stg_detach,           /* detach */
     {