]> git.stg.codes - stg.git/blobdiff - projects/stargazer/plugins/other/radius/radius.cpp
Sending attributes from <auth>/send section. (#13)
[stg.git] / projects / stargazer / plugins / other / radius / radius.cpp
index 8e5b37a895edc3f5b2cdb195087faf5787276721..11fbcf7be132d9547732c0ad16b8f5b126d74b48 100644 (file)
@@ -1,12 +1,11 @@
 #include "radius.h"
 #include "radproto/error.h"
 #include "stg/common.h"
+#include <boost/tokenizer.hpp>
 
-#include <iterator>
-#include <iostream>
+#include <utility>
 
 using STG::RADIUS;
-using STG::RAD_SETTINGS;
 
 extern "C" STG::Plugin* GetPlugin()
 {
@@ -14,60 +13,18 @@ extern "C" STG::Plugin* GetPlugin()
     return &plugin;
 }
 
-RAD_SETTINGS::RAD_SETTINGS()
-    : m_port(1812),
-      m_dictionaries("/usr/share/freeradius/dictionary")
-{}
-
-int RAD_SETTINGS::ParseSettings(const ModuleSettings & s)
-{
-    ParamValue pv;
-    int p;
-
-    pv.param = "Port";
-    auto pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv);
-    if (pvi != s.moduleParams.end() && !pvi->value.empty())
-    {
-        if (ParseIntInRange(pvi->value[0], 2, 65535, &p) != 0)
-        {
-            m_errorStr = "Cannot parse parameter \'Port\': " + m_errorStr;
-            printfd(__FILE__, "Cannot parse parameter 'Port'\n");
-            return -1;
-        }
-        m_port = static_cast<uint16_t>(p);
-    }
-
-    pv.param = "Secret";
-    pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv);
-    if (pvi == s.moduleParams.end() || pvi->value.empty())
-    {
-        m_errorStr = "Parameter \'Secret\' not found.";
-        printfd(__FILE__, "Parameter 'Secret' not found\n");
-        m_secret = "";
-    }
-    else
-    {
-        m_secret = pvi->value[0];
-    }
-
-    pv.param = "Dictionaries";
-    pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv);
-    if (pvi != s.moduleParams.end() && !pvi->value.empty())
-        m_dictionaries = pvi->value[0];
-    return 0;
-}
-
 RADIUS::RADIUS()
     : m_running(false),
+      m_users(nullptr),
       m_logger(PluginLogger::get("radius"))
 {
 }
 
 int RADIUS::ParseSettings()
 {
-    auto ret = m_radSettings.ParseSettings(m_settings);
+    auto ret = m_config.ParseSettings(m_settings);
     if (ret != 0)
-        m_errorStr = m_radSettings.GetStrError();
+        m_errorStr = m_config.GetStrError();
 
     return ret;
 }
@@ -116,8 +73,8 @@ int RADIUS::Run(std::stop_token token)
     try
     {
         if (!m_server)
-           m_server = std::make_unique<Server>(m_ioService, m_radSettings.GetSecret(), m_radSettings.GetPort(), m_radSettings.GetDictionaries(), std::move(token), m_logger);
-        m_ioService.run();
+           m_server = std::make_unique<Server>(m_ioContext, m_config.GetSecret(), m_config.GetPort(), m_config.GetDictionaries(), std::move(token), m_logger, m_users, m_config);
+        m_ioContext.run();
     }
     catch (const std::exception& e)
     {