summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
46d0fa3)
* Radius. Header file <mutex>, <jthread.hpp> added. Functions start, stop
declaration changed. Class members m_thread, m_mutex added. Function Run
declaration added.
* Radius. Header files added. Functions Start, Stop, Run definition added.
* Radius. New files server.h, server.cpp added.
* Radius. Definition of functions startReceive, makeResponse, handleSend,
handleReceive added.
* The Run function name fixed. Definition of secret variable sdded.
* The file server.cpp added to add_library command, command
find_package(OpenSSL 1.0.0 Required) added, OpenSSL::Crypto added to
target_link_libraries command in the block if(BUILD_MOD_RADIUS).
* Parameter token added to function Run() declaration.
* Radius. Method Start: variable isRunning=true removed, m_thread
definition changed. Method Stop: variable isRunning=false removed,
m_thread.joinable check added, isRunning check added, request_stop call added.
Method Run: parameter token added, variables secret, port removed,
object lock and isRunning=true added before cycle while,
cycle while added, isRunning=false added after cycle while.
* Radius. Hold the mutex removed,extra conditions
for m_thread.join() removed in the Stop function.
* Radius. Cycle while removed in function Run.
* Radius. The variables isRunning, errorStr replaced by m_running,
m_errorStr in class Radius.
* Radius. The variable isRunning replaced by m_running in function Run.
* Radius. Object name io_service changed to ioService in the function Run.
* Method SetRunning declaration added to the class RADIUS.
* Method SetRunning definition added. Method SetRunning call added to
function Run.
* Radius. Namespace STG added.
* Radius. Declaration using STG::Server added.
* Radius. Header file "stg/logger.h" added. RADIUS class member m_loger added.
* Radius. Header file "stg/common.h" added. Initialization of m_logger
added to constructor RADIUS. Output cerr replaced by logger and
printfd().
* Radius. Variable except added, messages fixed in the function Run.
* Radius. Thread join logic fixed in the function Stop.
* Keyword const added to std::lock_guard in the function SetRunning.
* Radius. Class member m_mutex moved to the top of list.
* Radius. Class member m_logger put after the m_running.
* Radius. Unnecessary variable except removed in the function Run.
* Radius. Extra whitespace removed in the function Stop. Function
IsRunning definition added.
* Radius. Function IsRunning declaration changed.
* Radius. Formatting fixed.
* Radius. Extra symbols '//' removed.
* Radius. Class member m_running initialization added to constructor
RADIUS.
* Radius.Header file "stg/module_settings.h" added. Class members variable
m_settings and method SetSettings added to class RADIUS.
* Radius. The parameters Secret, Dictionaries added, parameter Port
changed, other parameters removed.
* Radius. Header files added. Class RAD_SETTINGS added. Methods
SetSettings, copy constructor RADIUS, assignment operator added. Method
ParseSettings changed. Formatting fixed.
* Radius. Parameter default changed to optional and parameters value
commented out for the parameters dictionaries, port.
* Radius. Description of parameters secret, port, dictionaries changed.
* Radius. Copy constructor RADIUS and assignment operator declaration
changed and moved to public section.
* Radius. Class member m_mutex moved to the top of section private.
* Radius. The m_port variable value initialization changed to 1812,
m_dictionaries variable initialization added to constructor RAD_SETTINGS.
* Radius. Check for missing parameters port and dictionaries removed in function ParseSettings.
-# Enable the interaction module for FreeRADIUS "mod_radius.so"
+# Enable the interaction module for RADIUS "mod_radius.so"
- # 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
- # 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
#include <boost/asio.hpp>
#include <string>
#include <boost/asio.hpp>
#include <string>
-#include <cstdint> //uint8_t, uint32_t
+using STG::RAD_SETTINGS;
extern "C" STG::Plugin* GetPlugin()
{
extern "C" STG::Plugin* GetPlugin()
{
-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)
+ 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;
- : 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";
-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;
}
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"
#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 "stg/logger.h"
#include <string>
#include <mutex>
#include <jthread.hpp>
+#include <cstdint> //uint8_t, uint32_t
+ 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();
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 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;
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; }
uint16_t GetStartPosition() const override { return 0; }
uint16_t GetStopPosition() const override { return 0; }
private:
std::mutex m_mutex;
private:
std::mutex m_mutex;
+
+ int Run(std::stop_token token);
+
mutable std::string m_errorStr;
mutable std::string m_errorStr;
+ RAD_SETTINGS m_radSettings;
+ ModuleSettings m_settings;
+
- int Run(std::stop_token token);
+ std::jthread m_thread;
+
+ PluginLogger m_logger;