-# Enable the interaction module for FreeRADIUS "mod_radius.so"
+# Enable the interaction module for RADIUS "mod_radius.so"
<Module radius>
- # FreeRADIUS password
+ # RADIUS shared secret
# Parameter: required
- # Values: any, supported by software
- # Default: 123456
- Password = 123456
+ # Values: any
+ Secret = sec
- # FreeRADIUS server
- # Parameter: required
- # Values: IP address or DNS name
- # Default: 127.0.0.1
- ServerIP = 127.0.0.1
+ # Path to RADIUS dictionaries file
+ # Parameter: optional
+ # Values: file path
+ # Default: /usr/share/freeradius/dictionary
+ # Dictionaries = /usr/share/freeradius/dictionary
- # FreeRADIUS port
- # Parameter: required
+ # RADIUS port number
+ # Parameter: optional
# Value: 1 ... 65535
- # Default: 6666
- Port = 6666
+ # Default: 1812
+ # Port = 1812
- # List of services for which will be carried out FreeRADIUS authentication
- # Note: Parameter can be blank
- # Parameter: required
- # Value: any, supported by software
- # Default: Login-User
- AuthServices = Login-User
-
- # List of services for which will be carried out FreeRADIUS Accounting
- # Note: Parameter can be blank
- # Parameter: required
- # Value: any, supported by software
- # Default: Framed-User
- AcctServices = Framed-User
-</Module>
\ No newline at end of file
+</Module>
#include <boost/asio.hpp>
#include <string>
+#include <iterator>
#include <iostream>
-#include <cstdint> //uint8_t, uint32_t
using STG::RADIUS;
+using STG::RAD_SETTINGS;
extern "C" STG::Plugin* GetPlugin()
{
return &plugin;
}
-std::string RADIUS::GetVersion() const
+RAD_SETTINGS::RAD_SETTINGS()
+ : m_port(1812),
+ m_dictionaries("/usr/share/freeradius/dictionary")
+{}
+
+int RAD_SETTINGS::ParseSettings(const ModuleSettings & s)
{
- return "Radius v.1.0";
+ 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_logger(PluginLogger::get("radius")),
- m_running(false)
+ : m_running(false),
+ m_logger(PluginLogger::get("radius"))
+{
+}
+
+int RADIUS::Run(std::stop_token token)
+{
+ SetRunning(true);
+
+ try
+ {
+ boost::asio::io_service ioService;
+ Server server(ioService, m_radSettings.GetSecret(), m_radSettings.GetPort(), m_radSettings.GetDictionaries());
+ ioService.run();
+ }
+ catch (const std::exception& e)
+ {
+ m_errorStr = "Exception in RADIUS::Run(): " + std::string(e.what());
+ m_logger("Exception in RADIUS:: Run(): %s", e.what());
+ printfd(__FILE__, "Exception in RADIUS:: Run(). Message: '%s'\n", e.what());
+ }
+
+ SetRunning(false);
+ return 0;
+}
+
+int RADIUS::ParseSettings()
{
+ auto ret = m_radSettings.ParseSettings(m_settings);
+ if (ret != 0)
+ m_errorStr = m_radSettings.GetStrError();
+
+ return ret;
+}
+
+std::string RADIUS::GetVersion() const
+{
+ return "Radius v.1.0";
}
int RADIUS::Start()
return 0;
}
-void RADIUS::SetRunning(bool val)
-{
- const std::lock_guard lock(m_mutex);
- m_running = val;
-}
-
bool RADIUS::IsRunning()
{
const std::lock_guard lock(m_mutex);
return m_running;
}
-int RADIUS::Run(std::stop_token token)
+void RADIUS::SetRunning(bool val)
{
- SetRunning(true);
-
- try
- {
- boost::asio::io_service ioService;
- Server server(ioService, "secret", 1812, "/usr/share/freeradius/dictionary");
- ioService.run();
- }
- catch (const std::exception& e)
- {
- m_errorStr = "Exception in RADIUS::Run(): " + std::string(e.what());
- m_logger("Exception in RADIUS:: Run(): %s", e.what());
- printfd(__FILE__, "Exception in RADIUS:: Run(). Message: '%s'\n", e.what());
- }
-
- SetRunning(false);
- return 0;
+ const std::lock_guard lock(m_mutex);
+ m_running = val;
}
#pragma once
#include "stg/auth.h"
+#include "stg/plugin.h"
+#include "stg/module_settings.h"
+#include "stg/subscriptions.h"
#include "stg/logger.h"
#include <string>
#include <mutex>
#include <jthread.hpp>
+#include <cstdint> //uint8_t, uint32_t
namespace STG
{
+ struct Settings;
+
+ class RAD_SETTINGS
+ {
+ public:
+ RAD_SETTINGS();
+ virtual ~RAD_SETTINGS() {}
+ const std::string & GetStrError() const { return m_errorStr; }
+ int ParseSettings(const ModuleSettings & s);
+
+ uint16_t GetPort() const { return m_port; }
+ const std::string & GetDictionaries() const { return m_dictionaries; }
+ const std::string & GetSecret() const { return m_secret; }
+
+ private:
+ std::string m_errorStr;
+ uint16_t m_port;
+ std::string m_dictionaries;
+ std::string m_secret;
+ };
+
class RADIUS : public Auth
{
public:
RADIUS();
+ RADIUS(const RADIUS&) = delete;
+ RADIUS& operator=(const RADIUS&) = delete;
+
+ void SetSettings(const ModuleSettings & s) override { m_settings = s; }
+ int ParseSettings() override;
int Start() override;
int Stop() override;
int Reload(const ModuleSettings & /*ms*/) override { return 0; }
bool IsRunning() override;
void SetRunning(bool val);
- int ParseSettings() override { return 0; }
+
const std::string & GetStrError() const override { return m_errorStr; }
std::string GetVersion() const override;
+
uint16_t GetStartPosition() const override { return 0; }
uint16_t GetStopPosition() const override { return 0; }
private:
std::mutex m_mutex;
+
+ int Run(std::stop_token token);
+
mutable std::string m_errorStr;
- std::jthread m_thread;
+ RAD_SETTINGS m_radSettings;
+ ModuleSettings m_settings;
+
bool m_running;
- PluginLogger m_logger;
- int Run(std::stop_token token);
+ std::jthread m_thread;
+
+ PluginLogger m_logger;
};
}