X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/e39f173d25ae650ee843e3d1c311abe9c1cb5ee9..refs/heads/master:/projects/stargazer/plugins/other/radius/radius.h diff --git a/projects/stargazer/plugins/other/radius/radius.h b/projects/stargazer/plugins/other/radius/radius.h index 52da138e..6b742de5 100644 --- a/projects/stargazer/plugins/other/radius/radius.h +++ b/projects/stargazer/plugins/other/radius/radius.h @@ -1,110 +1,82 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* - * Author : Maxim Mamontov - */ - -#ifndef __STG_RADIUS_H__ -#define __STG_RADIUS_H__ - -#include "stg/os_int.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 "server.h" -#include "config.h" -#include "conn.h" - +#include #include -#include -#include - -#include -#include -#include -#include - -extern "C" PLUGIN * GetPlugin(); - -class STORE; -class USERS; +#include +#include +#include +#include //uint8_t, uint32_t -class RADIUS : public AUTH { -public: - RADIUS(); - virtual ~RADIUS() {} +namespace STG +{ + struct Settings; - 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(); + class RAD_SETTINGS + { + public: + RAD_SETTINGS(); + virtual ~RAD_SETTINGS() {} + const std::string & GetStrError() const { return m_errorStr; } + int ParseSettings(const ModuleSettings & s); - int Start(); - int Stop(); - int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; } - bool IsRunning() { return m_running; } + uint16_t GetPort() const { return m_port; } + const std::string & GetDictionaries() const { return m_dictionaries; } + const std::string & GetSecret() const { return m_secret; } - 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; } + private: + std::string m_errorStr; + uint16_t m_port; + std::string m_dictionaries; + std::string m_secret; + }; - int SendMessage(const STG_MSG&, uint32_t) const { return 0; } + class RADIUS : public Auth + { + public: + RADIUS(); + RADIUS(const RADIUS&) = delete; + RADIUS& operator=(const RADIUS&) = delete; - void authorize(const USER& user); - void unauthorize(const std::string& login, const std::string& reason); + void SetSettings(const ModuleSettings & s) override { m_settings = s; } + int ParseSettings() override; -private: - RADIUS(const RADIUS & rvalue); - RADIUS & operator=(const RADIUS & rvalue); + int Start() override; + int Stop() override; + int Reload(const ModuleSettings & /*ms*/) override { return 0; } + bool IsRunning() override; + void SetRunning(bool val); - static void* run(void*); + const std::string & GetStrError() const override { return m_errorStr; } + std::string GetVersion() const override; - 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(); + uint16_t GetStartPosition() const override { return 0; } + uint16_t GetStopPosition() const override { return 0; } - mutable std::string m_error; - STG::Config m_config; + int SendMessage(const Message & msg, uint32_t ip) const override { return 0; } - MODULE_SETTINGS m_settings; + private: + std::mutex m_mutex; - bool m_running; - bool m_stopped; + boost::asio::io_service m_ioService; + int Run(std::stop_token token); - USERS* m_users; - const STORE* m_store; + mutable std::string m_errorStr; + RAD_SETTINGS m_radSettings; + ModuleSettings m_settings; - int m_listenSocket; - std::deque m_conns; - std::set m_logins; + bool m_running; - pthread_t m_thread; + std::jthread m_thread; - PLUGIN_LOGGER m_logger; -}; + PluginLogger m_logger; -#endif + std::unique_ptr m_server; + }; +}