-#include <deque>
-#include <set>
-
-#include <pthread.h>
-#include <unistd.h>
-#include <sys/select.h>
-#include <sys/types.h>
-
-extern "C" PLUGIN * GetPlugin();
-
-class STORE;
-class USERS;
-
-class RADIUS : public AUTH {
-public:
- RADIUS();
- virtual ~RADIUS() {}
-
- void SetUsers(USERS* u) { m_users = u; }
- void SetStore(STORE* s) { m_store = s; }
- void SetStgSettings(const SETTINGS*) {}
- void SetSettings(const MODULE_SETTINGS& s) { m_settings = s; }
- int ParseSettings();
-
- int Start();
- int Stop();
- int Reload() { return 0; }
- bool IsRunning() { return m_running; }
-
- const std::string& GetStrError() const { return m_error; }
- std::string GetVersion() const { return "RADIUS data access plugin v. 2.0"; }
- uint16_t GetStartPosition() const { return 30; }
- uint16_t GetStopPosition() const { return 30; }
-
- int SendMessage(const STG_MSG&, uint32_t) const { return 0; }
-
- void authorize(const USER& user);
- void unauthorize(const std::string& login, const std::string& reason);
-
-private:
- RADIUS(const RADIUS & rvalue);
- RADIUS & operator=(const RADIUS & rvalue);
-
- static void* run(void*);
-
- bool reconnect();
- int createUNIX() const;
- int createTCP() const;
- void runImpl();
- int maxFD() const;
- void buildFDSet(fd_set & fds) const;
- void cleanupConns();
- void handleEvents(const fd_set & fds);
- void acceptConnection();
- void acceptUNIX();
- void acceptTCP();
-
- mutable std::string m_error;
- STG::Config m_config;
-
- MODULE_SETTINGS m_settings;
-
- bool m_running;
- bool m_stopped;
-
- USERS* m_users;
- const STORE* m_store;
-
- int m_listenSocket;
- std::deque<STG::Conn*> m_conns;
- std::set<std::string> m_logins;
-
- pthread_t m_thread;
-
- PLUGIN_LOGGER m_logger;
-};
-
-#endif
+#include <memory>
+#include <mutex>
+#include <jthread.hpp>
+#include <cstdint> //uint8_t, uint32_t
+
+namespace STG
+{
+ struct Settings;
+
+ class Users;
+
+ class RAD_SETTINGS
+ {
+ public:
+ RAD_SETTINGS();
+ virtual ~RAD_SETTINGS() {}
+
+ struct AttrValue
+ {
+ enum class Type
+ {
+ PARAM_NAME,
+ VALUE
+ };
+ std::string value;
+ Type type;
+ };
+
+ struct ASection
+ {
+ using Pairs = std::vector<std::pair<std::string, AttrValue>>;
+ Pairs match;
+ Pairs send;
+ };
+
+ 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; }
+ const ASection& getAuth() const { return m_auth; }
+ const ASection& getAutz() const { return m_autz; }
+
+ private:
+ std::vector<std::pair<std::string, AttrValue>> ParseRules(const std::string& value, const std::string& paramName);
+ ASection parseASection(const std::vector<ParamValue>& conf);
+
+ std::string m_errorStr;
+ uint16_t m_port;
+ std::string m_dictionaries;
+ std::string m_secret;
+
+ ASection m_auth;
+ ASection m_autz;
+
+ PluginLogger m_logger;
+ };
+
+ class RADIUS : public Auth
+ {
+ public:
+ RADIUS();
+ RADIUS(const RADIUS&) = delete;
+ RADIUS& operator=(const RADIUS&) = delete;
+
+ void SetUsers(Users* u) override { m_users = u; }
+ 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);
+
+ 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; }
+
+ int SendMessage(const Message& /*msg*/, uint32_t /*ip*/) const override { return 0; }
+
+ private:
+ std::mutex m_mutex;
+
+ boost::asio::io_context m_ioContext;
+ int Run(std::stop_token token);
+
+ mutable std::string m_errorStr;
+ RAD_SETTINGS m_radSettings;
+ ModuleSettings m_settings;
+
+ bool m_running;
+
+ std::jthread m_thread;
+ Users* m_users;
+ PluginLogger m_logger;
+
+ std::unique_ptr<Server> m_server;
+ };
+}