From 1e0e67cbe4018656b916cf9762018ca4ca0ca4ec Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Fri, 27 Dec 2024 15:15:20 +0200 Subject: [PATCH 001/186] Radius. Header file , added. Functions start, stop declaration changed. Class members m_thread, m_mutex added. Function Run declaration added. --- projects/stargazer/plugins/other/radius/radius.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.h b/projects/stargazer/plugins/other/radius/radius.h index 4cc84e26..0eb251bf 100644 --- a/projects/stargazer/plugins/other/radius/radius.h +++ b/projects/stargazer/plugins/other/radius/radius.h @@ -2,6 +2,8 @@ #include "stg/auth.h" #include +#include +#include namespace STG { @@ -10,8 +12,8 @@ namespace STG public: RADIUS(); - int Start() override { return 0; } - int Stop() override { return 0; } + int Start() override; + int Stop() override; int Reload(const ModuleSettings & /*ms*/) override { return 0; } bool IsRunning() override { return isRunning; } int ParseSettings() override { return 0; } @@ -24,7 +26,10 @@ namespace STG private: mutable std::string errorStr; + std::jthread m_thread; + std::mutex m_mutex; bool isRunning; + int Run(); }; } From 2f28e0760a1b58d0784458f3a0d9020491017187 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Fri, 27 Dec 2024 15:22:50 +0200 Subject: [PATCH 002/186] Radius. Header files added. Functions Start, Stop, Run definition added. --- .../stargazer/plugins/other/radius/radius.cpp | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 3ec0f705..24c9f600 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -1,4 +1,10 @@ #include "radius.h" +#include "server.h" +#include "radproto/error.h" +#include +#include +#include +#include //uint8_t, uint32_t using STG::RADIUS; @@ -17,3 +23,34 @@ RADIUS::RADIUS() { } +int RADIUS::Start() +{ + isRunning = true; + m_thread = std::jthread([this](){ Run(); }); + return 0; +} + +int RADIUS::Stop() +{ + std::lock_guard lock(m_mutex); + isRunning = false; + return 0; +} + +int Run() +{ + std::string secret; + uint16_t port = 1812; + + try + { + boost::asio::io_service io_service; + Server server(io_service, secret, port, "/usr/share/freeradius/dictionary"); + io_service.run(); + } + catch (const std::exception& e) + { + std::cerr << "Exception: " << e.what() <<"\n"; + } + return 0; +} From 3818eac30492c2772bf415a26aab061eae19b6f1 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Fri, 27 Dec 2024 15:33:31 +0200 Subject: [PATCH 003/186] Radius. New files server.h, server.cpp added. --- .../stargazer/plugins/other/radius/server.cpp | 13 +++++++++++ .../stargazer/plugins/other/radius/server.h | 23 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 projects/stargazer/plugins/other/radius/server.cpp create mode 100644 projects/stargazer/plugins/other/radius/server.h diff --git a/projects/stargazer/plugins/other/radius/server.cpp b/projects/stargazer/plugins/other/radius/server.cpp new file mode 100644 index 00000000..2c729553 --- /dev/null +++ b/projects/stargazer/plugins/other/radius/server.cpp @@ -0,0 +1,13 @@ +#include "server.h" +#include "radproto/packet_codes.h" +#include +#include + +using boost::system::error_code; + +Server::Server(boost::asio::io_service& io_service, const std::string& secret, uint16_t port, const std::string& filePath) + : m_radius(io_service, secret, port), + m_dictionaries(filePath) +{ + startReceive(); +} diff --git a/projects/stargazer/plugins/other/radius/server.h b/projects/stargazer/plugins/other/radius/server.h new file mode 100644 index 00000000..fe06ace9 --- /dev/null +++ b/projects/stargazer/plugins/other/radius/server.h @@ -0,0 +1,23 @@ +#pragma once + +#include "radproto/socket.h" +#include "radproto/packet.h" +#include "radproto/dictionaries.h" +#include +#include +#include //uint8_t, uint32_t + +class Server +{ + public: + Server(boost::asio::io_service& io_service, const std::string& secret, uint16_t port, const std::string& filePath); + + private: + RadProto::Packet makeResponse(const RadProto::Packet& request); + void handleReceive(const boost::system::error_code& error, const std::optional& packet, const boost::asio::ip::udp::endpoint& source); + void handleSend(const boost::system::error_code& ec); + void startReceive(); + + RadProto::Socket m_radius; + RadProto::Dictionaries m_dictionaries; +}; From 4bd343904b8a0ccf51135444654ea56786bf0811 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Thu, 2 Jan 2025 15:58:16 +0200 Subject: [PATCH 004/186] Radius. Definition of functions startReceive, makeResponse, handleSend, handleReceive added. --- .../stargazer/plugins/other/radius/server.cpp | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/projects/stargazer/plugins/other/radius/server.cpp b/projects/stargazer/plugins/other/radius/server.cpp index 2c729553..f02659d9 100644 --- a/projects/stargazer/plugins/other/radius/server.cpp +++ b/projects/stargazer/plugins/other/radius/server.cpp @@ -11,3 +11,57 @@ Server::Server(boost::asio::io_service& io_service, const std::string& secret, u { startReceive(); } + +void Server::startReceive() +{ + m_radius.asyncReceive([this](const auto& error, const auto& packet, const boost::asio::ip::udp::endpoint& source){ handleReceive(error, packet, source); }); +} + +RadProto::Packet Server::makeResponse(const RadProto::Packet& request) +{ + std::vector attributes; + attributes.push_back(new RadProto::String(m_dictionaries.attributeCode("User-Name"), "test")); + attributes.push_back(new RadProto::Integer(m_dictionaries.attributeCode("NAS-Port"), 20)); + std::array address {127, 104, 22, 17}; + attributes.push_back(new RadProto::IpAddress(m_dictionaries.attributeCode("NAS-IP-Address"), address)); + std::vector bytes {'1', '2', '3', 'a', 'b', 'c'}; + attributes.push_back(new RadProto::Bytes(m_dictionaries.attributeCode("Callback-Number"), bytes)); + std::vector chapPassword {'1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g' }; + attributes.push_back(new RadProto::ChapPassword(m_dictionaries.attributeCode("CHAP-Password"), 1, chapPassword)); + + std::vector vendorSpecific; + std::vector vendorValue {0, 0, 0, 3}; + vendorSpecific.push_back(RadProto::VendorSpecific(m_dictionaries.vendorCode("Dlink"), m_dictionaries.vendorAttributeCode("Dlink", "Dlink-User-Level"), vendorValue)); + + if (request.type() == RadProto::ACCESS_REQUEST) + return RadProto::Packet(RadProto::ACCESS_ACCEPT, request.id(), request.auth(), attributes, vendorSpecific); + + return RadProto::Packet(RadProto::ACCESS_REJECT, request.id(), request.auth(), attributes, vendorSpecific); +} + +void Server::handleSend(const error_code& ec) +{ + if (ec) + std::cout << "Error asyncSend: " << ec.message() << "\n"; + + startReceive(); +} + +void Server::handleReceive(const error_code& error, const std::optional& packet, const boost::asio::ip::udp::endpoint& source) +{ + if (error) + { + std::cout << "Error asyncReceive: " << error.message() << "\n"; + return; + } + + if (packet == std::nullopt) + { + std::cout << "Error asyncReceive: the request packet is missing\n"; + return; + } + else + { + m_radius.asyncSend(makeResponse(*packet), source, [this](const auto& ec){ handleSend(ec); }); + } +} From 69c2f837f9acfaa80008c1620f3a2d2f334b30e8 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Thu, 2 Jan 2025 16:48:14 +0200 Subject: [PATCH 005/186] The Run function name fixed. Definition of secret variable sdded. --- projects/stargazer/plugins/other/radius/radius.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 24c9f600..18eff0be 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -37,9 +37,9 @@ int RADIUS::Stop() return 0; } -int Run() +int RADIUS::Run() { - std::string secret; + std::string secret("secret"); uint16_t port = 1812; try From dca0d951794a6bb34f5d6c0d6b6be0164cdb3507 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Thu, 2 Jan 2025 17:01:10 +0200 Subject: [PATCH 006/186] 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). --- projects/stargazer/plugins/CMakeLists.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/projects/stargazer/plugins/CMakeLists.txt b/projects/stargazer/plugins/CMakeLists.txt index a53349ea..b6e4d326 100644 --- a/projects/stargazer/plugins/CMakeLists.txt +++ b/projects/stargazer/plugins/CMakeLists.txt @@ -14,7 +14,8 @@ endif ( BUILD_MOD_AO ) if ( BUILD_MOD_RADIUS ) find_package ( Boost REQUIRED ) - add_library ( mod_radius MODULE other/radius/radius.cpp ) + add_library ( mod_radius MODULE other/radius/radius.cpp + other/radius/server.cpp) target_link_libraries ( mod_radius PRIVATE scriptexecuter logger common ) set_target_properties ( mod_radius PROPERTIES PREFIX "" ) @@ -34,7 +35,8 @@ if ( BUILD_MOD_RADIUS ) add_dependencies ( mod_radius async-radius ) - target_link_libraries ( mod_radius PRIVATE radproto Boost::boost ) + find_package ( OpenSSL 1.0.0 REQUIRED ) + target_link_libraries ( mod_radius PRIVATE radproto Boost::boost OpenSSL::Crypto) if ( CLANG_TIDY_EXE ) set_target_properties ( mod_radius PROPERTIES CXX_CLANG_TIDY "${DO_CLANG_TIDY}" ) From 6a7ea1edb7d70ae620327a380719e4a3a1f85e52 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Wed, 8 Jan 2025 16:43:18 +0200 Subject: [PATCH 007/186] Parameter token added to function Run() declaration. --- projects/stargazer/plugins/other/radius/radius.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/stargazer/plugins/other/radius/radius.h b/projects/stargazer/plugins/other/radius/radius.h index 0eb251bf..409eb610 100644 --- a/projects/stargazer/plugins/other/radius/radius.h +++ b/projects/stargazer/plugins/other/radius/radius.h @@ -30,6 +30,6 @@ namespace STG std::mutex m_mutex; bool isRunning; - int Run(); + int Run(std::stop_token token); }; } From 85a5b66ffea36f6df85a76fd7da92e10f4af918c Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Wed, 8 Jan 2025 16:55:27 +0200 Subject: [PATCH 008/186] 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. --- .../stargazer/plugins/other/radius/radius.cpp | 42 ++++++++++++------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 18eff0be..d7883d75 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -25,32 +25,46 @@ RADIUS::RADIUS() int RADIUS::Start() { - isRunning = true; - m_thread = std::jthread([this](){ Run(); }); + m_thread = std::jthread([this](auto token){ Run(std::move(token)); }); return 0; } int RADIUS::Stop() { std::lock_guard lock(m_mutex); - isRunning = false; + + if (!m_thread.joinable()) + return 0; + + m_thread.request_stop(); + + + if (isRunning) + m_thread.detach(); + else + m_thread.join(); + return 0; } -int RADIUS::Run() +int RADIUS::Run(std::stop_token token) { - std::string secret("secret"); - uint16_t port = 1812; + std::lock_guard lock(m_mutex); + isRunning = true; - try + while (!token.stop_requested()) { - boost::asio::io_service io_service; - Server server(io_service, secret, port, "/usr/share/freeradius/dictionary"); - io_service.run(); - } - catch (const std::exception& e) - { - std::cerr << "Exception: " << e.what() <<"\n"; + try + { + boost::asio::io_service io_service; + Server server(io_service, "secret", 1812, "/usr/share/freeradius/dictionary"); + io_service.run(); + } + catch (const std::exception& e) + { + std::cerr << "Exception: " << e.what() <<"\n"; + } } + isRunning = false; return 0; } From 713a4cebbc3b5263c88f88c9d7f455e31acf2538 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Mon, 13 Jan 2025 15:39:01 +0200 Subject: [PATCH 009/186] Radius. Hold the mutex removed,extra conditions for m_thread.join() removed in the Stop function. --- projects/stargazer/plugins/other/radius/radius.cpp | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index d7883d75..e249ca02 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -31,19 +31,10 @@ int RADIUS::Start() int RADIUS::Stop() { - std::lock_guard lock(m_mutex); - - if (!m_thread.joinable()) - return 0; - - m_thread.request_stop(); - - - if (isRunning) - m_thread.detach(); - else + if (m_thread.joinable()) m_thread.join(); + m_thread.request_stop(); return 0; } From c8ee14f17950d6b76f673d1eb597442b46dd9849 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Mon, 13 Jan 2025 16:42:39 +0200 Subject: [PATCH 010/186] Radius. Cycle while removed in function Run. --- .../stargazer/plugins/other/radius/radius.cpp | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index e249ca02..87e40a7d 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -43,19 +43,17 @@ int RADIUS::Run(std::stop_token token) std::lock_guard lock(m_mutex); isRunning = true; - while (!token.stop_requested()) + try { - try - { - boost::asio::io_service io_service; - Server server(io_service, "secret", 1812, "/usr/share/freeradius/dictionary"); - io_service.run(); - } - catch (const std::exception& e) - { - std::cerr << "Exception: " << e.what() <<"\n"; - } + boost::asio::io_service io_service; + Server server(io_service, "secret", 1812, "/usr/share/freeradius/dictionary"); + io_service.run(); } + catch (const std::exception& e) + { + std::cerr << "Exception: " << e.what() <<"\n"; + } + isRunning = false; return 0; } From f366de044c7dd6992e1ca84bc691a5a241be99a4 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Mon, 13 Jan 2025 16:58:54 +0200 Subject: [PATCH 011/186] Radius. The variables isRunning, errorStr replaced by m_running, m_errorStr in class Radius. --- projects/stargazer/plugins/other/radius/radius.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.h b/projects/stargazer/plugins/other/radius/radius.h index 409eb610..c3b971d7 100644 --- a/projects/stargazer/plugins/other/radius/radius.h +++ b/projects/stargazer/plugins/other/radius/radius.h @@ -15,9 +15,9 @@ namespace STG int Start() override; int Stop() override; int Reload(const ModuleSettings & /*ms*/) override { return 0; } - bool IsRunning() override { return isRunning; } + bool IsRunning() override { return m_running; } int ParseSettings() override { return 0; } - const std::string & GetStrError() const override { return errorStr; } + 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; } @@ -25,10 +25,10 @@ namespace STG int SendMessage(const Message & msg, uint32_t ip) const override { return 0; } private: - mutable std::string errorStr; + mutable std::string m_errorStr; std::jthread m_thread; std::mutex m_mutex; - bool isRunning; + bool m_running; int Run(std::stop_token token); }; From 98fdb4b53cca11d3d805f6cffb1e381d9d3bb21f Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Mon, 13 Jan 2025 17:04:09 +0200 Subject: [PATCH 012/186] Radius. The variable isRunning replaced by m_running in function Run. --- projects/stargazer/plugins/other/radius/radius.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 87e40a7d..79ba7c09 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -41,7 +41,7 @@ int RADIUS::Stop() int RADIUS::Run(std::stop_token token) { std::lock_guard lock(m_mutex); - isRunning = true; + m_running = true; try { @@ -54,6 +54,6 @@ int RADIUS::Run(std::stop_token token) std::cerr << "Exception: " << e.what() <<"\n"; } - isRunning = false; + m_running = false; return 0; } From 6623d7eac72bd0737f5acb948cb737f71d52ffbd Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Mon, 13 Jan 2025 18:32:02 +0200 Subject: [PATCH 013/186] Radius. Object name io_service changed to ioService in the function Run. --- projects/stargazer/plugins/other/radius/radius.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 79ba7c09..4cc74a1b 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -45,9 +45,9 @@ int RADIUS::Run(std::stop_token token) try { - boost::asio::io_service io_service; - Server server(io_service, "secret", 1812, "/usr/share/freeradius/dictionary"); - io_service.run(); + boost::asio::io_service ioService; + Server server(ioService, "secret", 1812, "/usr/share/freeradius/dictionary"); + ioService.run(); } catch (const std::exception& e) { From c940134e56c1781e1f18dee479d735d433ae5888 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Tue, 14 Jan 2025 16:02:24 +0200 Subject: [PATCH 014/186] Method SetRunning declaration added to the class RADIUS. --- projects/stargazer/plugins/other/radius/radius.h | 1 + 1 file changed, 1 insertion(+) diff --git a/projects/stargazer/plugins/other/radius/radius.h b/projects/stargazer/plugins/other/radius/radius.h index c3b971d7..d3642f79 100644 --- a/projects/stargazer/plugins/other/radius/radius.h +++ b/projects/stargazer/plugins/other/radius/radius.h @@ -16,6 +16,7 @@ namespace STG int Stop() override; int Reload(const ModuleSettings & /*ms*/) override { return 0; } bool IsRunning() override { return m_running; } + void SetRunning(bool val); int ParseSettings() override { return 0; } const std::string & GetStrError() const override { return m_errorStr; } std::string GetVersion() const override; From 759e5f2639702a1e2f506aef68fa14dd2f9935b6 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Tue, 14 Jan 2025 16:07:17 +0200 Subject: [PATCH 015/186] Method SetRunning definition added. Method SetRunning call added to function Run. --- projects/stargazer/plugins/other/radius/radius.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 4cc74a1b..feb2b5e6 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -38,10 +38,15 @@ int RADIUS::Stop() return 0; } -int RADIUS::Run(std::stop_token token) +void RADIUS::SetRunning(bool val) { std::lock_guard lock(m_mutex); - m_running = true; + m_running = val; +} + +int RADIUS::Run(std::stop_token token) +{ + SetRunning(true); try { @@ -54,6 +59,6 @@ int RADIUS::Run(std::stop_token token) std::cerr << "Exception: " << e.what() <<"\n"; } - m_running = false; + SetRunning(false); return 0; } From dbd8db4baf237a24050cacc17df313efb880a079 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Tue, 14 Jan 2025 16:16:38 +0200 Subject: [PATCH 016/186] Radius. Namespace STG added. --- .../stargazer/plugins/other/radius/server.h | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/server.h b/projects/stargazer/plugins/other/radius/server.h index fe06ace9..6c207c83 100644 --- a/projects/stargazer/plugins/other/radius/server.h +++ b/projects/stargazer/plugins/other/radius/server.h @@ -6,18 +6,21 @@ #include #include #include //uint8_t, uint32_t - -class Server + // +namespace STG { - public: - Server(boost::asio::io_service& io_service, const std::string& secret, uint16_t port, const std::string& filePath); + class Server + { + public: + Server(boost::asio::io_service& io_service, const std::string& secret, uint16_t port, const std::string& filePath); - private: - RadProto::Packet makeResponse(const RadProto::Packet& request); - void handleReceive(const boost::system::error_code& error, const std::optional& packet, const boost::asio::ip::udp::endpoint& source); - void handleSend(const boost::system::error_code& ec); - void startReceive(); + private: + RadProto::Packet makeResponse(const RadProto::Packet& request); + void handleReceive(const boost::system::error_code& error, const std::optional& packet, const boost::asio::ip::udp::endpoint& source); + void handleSend(const boost::system::error_code& ec); + void startReceive(); - RadProto::Socket m_radius; - RadProto::Dictionaries m_dictionaries; -}; + RadProto::Socket m_radius; + RadProto::Dictionaries m_dictionaries; + }; +} From d3491dba2cc3fd4bbf61f45484d998afe21fd2c8 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Tue, 14 Jan 2025 16:17:46 +0200 Subject: [PATCH 017/186] Radius. Declaration using STG::Server added. --- projects/stargazer/plugins/other/radius/server.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/projects/stargazer/plugins/other/radius/server.cpp b/projects/stargazer/plugins/other/radius/server.cpp index f02659d9..4d16b6cb 100644 --- a/projects/stargazer/plugins/other/radius/server.cpp +++ b/projects/stargazer/plugins/other/radius/server.cpp @@ -3,6 +3,7 @@ #include #include +using STG::Server; using boost::system::error_code; Server::Server(boost::asio::io_service& io_service, const std::string& secret, uint16_t port, const std::string& filePath) From 6db11a35ba950f139d4e86eca704c90eaf2950ac Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Wed, 15 Jan 2025 16:57:37 +0200 Subject: [PATCH 018/186] Radius. Header file "stg/logger.h" added. RADIUS class member m_loger added. --- projects/stargazer/plugins/other/radius/radius.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/projects/stargazer/plugins/other/radius/radius.h b/projects/stargazer/plugins/other/radius/radius.h index d3642f79..611e8ae7 100644 --- a/projects/stargazer/plugins/other/radius/radius.h +++ b/projects/stargazer/plugins/other/radius/radius.h @@ -1,6 +1,8 @@ #pragma once #include "stg/auth.h" +#include "stg/logger.h" + #include #include #include @@ -32,5 +34,6 @@ namespace STG bool m_running; int Run(std::stop_token token); + PluginLogger m_logger; }; } From fdb78112c328b54d0d8d7dbce1442a174bbbcab1 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Wed, 15 Jan 2025 17:10:04 +0200 Subject: [PATCH 019/186] Radius. Header file "stg/common.h" added. Initialization of m_logger added to constructor RADIUS. Output cerr replaced by logger and printfd(). --- projects/stargazer/plugins/other/radius/radius.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index feb2b5e6..548cd430 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -1,6 +1,9 @@ #include "radius.h" #include "server.h" #include "radproto/error.h" + +#include "stg/common.h" + #include #include #include @@ -20,6 +23,7 @@ std::string RADIUS::GetVersion() const } RADIUS::RADIUS() + : m_logger(PluginLogger::get("radius")) { } @@ -56,7 +60,9 @@ int RADIUS::Run(std::stop_token token) } catch (const std::exception& e) { - std::cerr << "Exception: " << e.what() <<"\n"; + m_errorStr = "Exceptoin by Run()"; + m_logger("Exception by Run: %s", e.what()); + printfd(__FILE__, "Exception by Run. Message: '%s'\n", e.what()); } SetRunning(false); From d43fcafc45433884b51bde97b3fb7a062cdf4ec1 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Fri, 17 Jan 2025 16:17:11 +0200 Subject: [PATCH 020/186] Radius. Variable except added, messages fixed in the function Run. --- projects/stargazer/plugins/other/radius/radius.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 548cd430..7801e75b 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -60,9 +60,10 @@ int RADIUS::Run(std::stop_token token) } catch (const std::exception& e) { - m_errorStr = "Exceptoin by Run()"; - m_logger("Exception by Run: %s", e.what()); - printfd(__FILE__, "Exception by Run. Message: '%s'\n", e.what()); + std::string except(e.what()); + m_errorStr = "Exception in RADIUS::Run(): " + except; + m_logger("Exception in RADIUS:: Run(): %s", e.what()); + printfd(__FILE__, "Exception in RADIUS:: Run(). Message: '%s'\n", e.what()); } SetRunning(false); From 8284ccc2acfd74229c98c6d5f548dc4af3652dfd Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Fri, 17 Jan 2025 17:09:41 +0200 Subject: [PATCH 021/186] Radius. Thread join logic fixed in the function Stop. --- projects/stargazer/plugins/other/radius/radius.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 7801e75b..4a9127f6 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -35,10 +35,12 @@ int RADIUS::Start() int RADIUS::Stop() { - if (m_thread.joinable()) - m_thread.join(); + if (!m_thread.joinable()) + return 0; m_thread.request_stop(); + + m_thread. join(); return 0; } From 65caf3ddfda7457d78d5603cf393fa33a0aea60d Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Fri, 17 Jan 2025 19:20:13 +0200 Subject: [PATCH 022/186] Keyword const added to std::lock_guard in the function SetRunning. --- projects/stargazer/plugins/other/radius/radius.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 4a9127f6..5473e722 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -46,7 +46,7 @@ int RADIUS::Stop() void RADIUS::SetRunning(bool val) { - std::lock_guard lock(m_mutex); + const std::lock_guard lock(m_mutex); m_running = val; } From 74a20130c83d0d3ed3c02ed855d7c640e856dd29 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Mon, 20 Jan 2025 15:01:05 +0200 Subject: [PATCH 023/186] Radius. Class member m_mutex moved to the top of list. --- projects/stargazer/plugins/other/radius/radius.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/stargazer/plugins/other/radius/radius.h b/projects/stargazer/plugins/other/radius/radius.h index 611e8ae7..be1df754 100644 --- a/projects/stargazer/plugins/other/radius/radius.h +++ b/projects/stargazer/plugins/other/radius/radius.h @@ -28,9 +28,9 @@ namespace STG int SendMessage(const Message & msg, uint32_t ip) const override { return 0; } private: + std::mutex m_mutex; mutable std::string m_errorStr; std::jthread m_thread; - std::mutex m_mutex; bool m_running; int Run(std::stop_token token); From 9d2b564b24370b71a184f79df541d14a140aafed Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Mon, 20 Jan 2025 15:08:16 +0200 Subject: [PATCH 024/186] Radius. Class member m_logger put after the m_running. --- projects/stargazer/plugins/other/radius/radius.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/stargazer/plugins/other/radius/radius.h b/projects/stargazer/plugins/other/radius/radius.h index be1df754..c0c36709 100644 --- a/projects/stargazer/plugins/other/radius/radius.h +++ b/projects/stargazer/plugins/other/radius/radius.h @@ -32,8 +32,8 @@ namespace STG mutable std::string m_errorStr; std::jthread m_thread; bool m_running; + PluginLogger m_logger; int Run(std::stop_token token); - PluginLogger m_logger; }; } From fd6655c455c394345a6273140f1a8b59570b112e Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Sun, 26 Jan 2025 16:52:44 +0200 Subject: [PATCH 025/186] Radius. Unnecessary variable except removed in the function Run. --- projects/stargazer/plugins/other/radius/radius.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 5473e722..741c4a00 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -62,8 +62,7 @@ int RADIUS::Run(std::stop_token token) } catch (const std::exception& e) { - std::string except(e.what()); - m_errorStr = "Exception in RADIUS::Run(): " + except; + 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()); } From 8e041bed6b145b3565f2e247af3380bdf6000d54 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Mon, 27 Jan 2025 15:24:55 +0200 Subject: [PATCH 026/186] Radius. Extra whitespace removed in the function Stop. Function IsRunning definition added. --- projects/stargazer/plugins/other/radius/radius.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 741c4a00..8230aec0 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -40,7 +40,7 @@ int RADIUS::Stop() m_thread.request_stop(); - m_thread. join(); + m_thread.join(); return 0; } @@ -50,6 +50,12 @@ void RADIUS::SetRunning(bool val) m_running = val; } +bool RADIUS::IsRunning() + { + const std::lock_guard lock(m_mutex); + return m_running; + } + int RADIUS::Run(std::stop_token token) { SetRunning(true); From aef4a9491bde11e8ac1bb9b504612d860ac2ebae Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Mon, 27 Jan 2025 15:30:57 +0200 Subject: [PATCH 027/186] Radius. Function IsRunning declaration changed. --- projects/stargazer/plugins/other/radius/radius.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/stargazer/plugins/other/radius/radius.h b/projects/stargazer/plugins/other/radius/radius.h index c0c36709..4e06e463 100644 --- a/projects/stargazer/plugins/other/radius/radius.h +++ b/projects/stargazer/plugins/other/radius/radius.h @@ -17,7 +17,7 @@ namespace STG int Start() override; int Stop() override; int Reload(const ModuleSettings & /*ms*/) override { return 0; } - bool IsRunning() override { return m_running; } + bool IsRunning() override; void SetRunning(bool val); int ParseSettings() override { return 0; } const std::string & GetStrError() const override { return m_errorStr; } From 2692423fe1fe2e0b5881cf879bd68e7025decc16 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Mon, 27 Jan 2025 15:41:52 +0200 Subject: [PATCH 028/186] Radius. Formatting fixed. --- projects/stargazer/plugins/other/radius/radius.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 8230aec0..3b815df9 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -51,10 +51,10 @@ void RADIUS::SetRunning(bool val) } bool RADIUS::IsRunning() - { - const std::lock_guard lock(m_mutex); - return m_running; - } +{ + const std::lock_guard lock(m_mutex); + return m_running; +} int RADIUS::Run(std::stop_token token) { From fc12e516b7f87669ba72cf77b21ae489e7c652f8 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Mon, 27 Jan 2025 15:48:44 +0200 Subject: [PATCH 029/186] Radius. Extra symbols '//' removed. --- projects/stargazer/plugins/other/radius/server.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/stargazer/plugins/other/radius/server.h b/projects/stargazer/plugins/other/radius/server.h index 6c207c83..b88889be 100644 --- a/projects/stargazer/plugins/other/radius/server.h +++ b/projects/stargazer/plugins/other/radius/server.h @@ -6,7 +6,7 @@ #include #include #include //uint8_t, uint32_t - // + namespace STG { class Server From b96915598e84eae79419abdc8130c5a9db304660 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Mon, 27 Jan 2025 16:12:28 +0200 Subject: [PATCH 030/186] Radius. Class member m_running initialization added to constructor RADIUS. --- projects/stargazer/plugins/other/radius/radius.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 3b815df9..78c80b4d 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -23,7 +23,8 @@ std::string RADIUS::GetVersion() const } RADIUS::RADIUS() - : m_logger(PluginLogger::get("radius")) + : m_logger(PluginLogger::get("radius")), + m_running(false) { } From d430e665ab989301b1679f1d619be62e48c683f8 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Wed, 29 Jan 2025 13:36:13 +0200 Subject: [PATCH 031/186] Radius.Header file "stg/module_settings.h" added. Class members variable m_settings and method SetSettings added to class RADIUS. --- projects/stargazer/plugins/other/radius/radius.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/projects/stargazer/plugins/other/radius/radius.h b/projects/stargazer/plugins/other/radius/radius.h index 4e06e463..a1680f63 100644 --- a/projects/stargazer/plugins/other/radius/radius.h +++ b/projects/stargazer/plugins/other/radius/radius.h @@ -2,6 +2,7 @@ #include "stg/auth.h" #include "stg/logger.h" +#include "stg/module_settings.h" #include #include @@ -14,6 +15,7 @@ namespace STG public: RADIUS(); + void SetSettings(const ModuleSettings & s) override { m_settings = s; } int Start() override; int Stop() override; int Reload(const ModuleSettings & /*ms*/) override { return 0; } @@ -33,6 +35,7 @@ namespace STG std::jthread m_thread; bool m_running; PluginLogger m_logger; + ModuleSettings m_settings; int Run(std::stop_token token); }; From 2c11cad7809477a095aabb88e42ff7cd1bef551c Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Wed, 29 Jan 2025 14:02:30 +0200 Subject: [PATCH 032/186] Radius. The parameters Secret, Dictionaries added, parameter Port changed, other parameters removed. --- .../conf-available.d/mod_radius.conf | 38 ++++++------------- 1 file changed, 12 insertions(+), 26 deletions(-) diff --git a/projects/stargazer/inst/linux/etc/stargazer/conf-available.d/mod_radius.conf b/projects/stargazer/inst/linux/etc/stargazer/conf-available.d/mod_radius.conf index edc94d50..a77332c9 100644 --- a/projects/stargazer/inst/linux/etc/stargazer/conf-available.d/mod_radius.conf +++ b/projects/stargazer/inst/linux/etc/stargazer/conf-available.d/mod_radius.conf @@ -1,34 +1,20 @@ -# Enable the interaction module for FreeRADIUS "mod_radius.so" +# Enable the interaction module for RADIUS "mod_radius.so" - # FreeRADIUS password + # RADIUS shared secret for password encryption by client and server # Parameter: required - # Values: any, supported by software - # Default: 123456 - Password = 123456 + # Values: any + Secret = secret - # FreeRADIUS server + # RADIUS path to dictionary file # Parameter: required - # Values: IP address or DNS name - # Default: 127.0.0.1 - ServerIP = 127.0.0.1 + # Values: file path + # Default: /usr/share/freeradius/dictionary + Dictionaries = /usr/share/freeradius/dictionary - # FreeRADIUS port + # RADIUS port number for the socket # Parameter: required # 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 - \ No newline at end of file + From a79c030876386f4c460bffbf456189d789deb32a Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Tue, 4 Feb 2025 14:36:44 +0200 Subject: [PATCH 033/186] Radius. Header files added. Class RAD_SETTINGS added. Methods SetSettings, copy constructor RADIUS, assignment operator added. Method ParseSettings changed. Formatting fixed. --- .../conf-available.d/mod_radius.conf | 2 +- .../stargazer/plugins/other/radius/radius.cpp | 121 +++++++++++++----- 2 files changed, 93 insertions(+), 30 deletions(-) diff --git a/projects/stargazer/inst/linux/etc/stargazer/conf-available.d/mod_radius.conf b/projects/stargazer/inst/linux/etc/stargazer/conf-available.d/mod_radius.conf index a77332c9..f84bfed8 100644 --- a/projects/stargazer/inst/linux/etc/stargazer/conf-available.d/mod_radius.conf +++ b/projects/stargazer/inst/linux/etc/stargazer/conf-available.d/mod_radius.conf @@ -3,7 +3,7 @@ # RADIUS shared secret for password encryption by client and server # Parameter: required # Values: any - Secret = secret + Secret = sec # RADIUS path to dictionary file # Parameter: required diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 78c80b4d..a41eda16 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -6,10 +6,11 @@ #include #include +#include #include -#include //uint8_t, uint32_t using STG::RADIUS; +using STG::RAD_SETTINGS; extern "C" STG::Plugin* GetPlugin() { @@ -17,15 +18,98 @@ extern "C" STG::Plugin* GetPlugin() return &plugin; } -std::string RADIUS::GetVersion() const +RAD_SETTINGS::RAD_SETTINGS() + : m_port(0) +{} + +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()) + { + m_errorStr = "Parameter \'Port\' not found."; + printfd(__FILE__, "Parameter 'Port' not found\n"); + return -1; + } + 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(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_errorStr = "Parameter \'Dictionaries\' not found."; + printfd(__FILE__, "Parameter 'Dictionaries' not found\n"); + m_dictionaries = ""; + } + else + { + 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() @@ -45,35 +129,14 @@ int RADIUS::Stop() 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; } From 014c78dff1d3c50a4ce49e5a7ecdafeb5382979f Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Thu, 6 Feb 2025 14:30:05 +0200 Subject: [PATCH 034/186] Radius. Parameter default changed to optional and parameters value commented out for the parameters dictionaries, port. --- .../linux/etc/stargazer/conf-available.d/mod_radius.conf | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/projects/stargazer/inst/linux/etc/stargazer/conf-available.d/mod_radius.conf b/projects/stargazer/inst/linux/etc/stargazer/conf-available.d/mod_radius.conf index f84bfed8..477b1a1c 100644 --- a/projects/stargazer/inst/linux/etc/stargazer/conf-available.d/mod_radius.conf +++ b/projects/stargazer/inst/linux/etc/stargazer/conf-available.d/mod_radius.conf @@ -6,15 +6,15 @@ Secret = sec # RADIUS path to dictionary file - # Parameter: required + # Parameter: optional # Values: file path # Default: /usr/share/freeradius/dictionary - Dictionaries = /usr/share/freeradius/dictionary + # Dictionaries = /usr/share/freeradius/dictionary # RADIUS port number for the socket - # Parameter: required + # Parameter: optional # Value: 1 ... 65535 # Default: 1812 - Port = 1812 + # Port = 1812 From 1ff4563114e6b488e918b2c1666f0ead0404e920 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Thu, 6 Feb 2025 14:38:41 +0200 Subject: [PATCH 035/186] Radius. Description of parameters secret, port, dictionaries changed. --- .../linux/etc/stargazer/conf-available.d/mod_radius.conf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/projects/stargazer/inst/linux/etc/stargazer/conf-available.d/mod_radius.conf b/projects/stargazer/inst/linux/etc/stargazer/conf-available.d/mod_radius.conf index 477b1a1c..d4cf6c4c 100644 --- a/projects/stargazer/inst/linux/etc/stargazer/conf-available.d/mod_radius.conf +++ b/projects/stargazer/inst/linux/etc/stargazer/conf-available.d/mod_radius.conf @@ -1,17 +1,17 @@ # Enable the interaction module for RADIUS "mod_radius.so" - # RADIUS shared secret for password encryption by client and server + # RADIUS shared secret # Parameter: required # Values: any Secret = sec - # RADIUS path to dictionary file + # Path to RADIUS dictionaries file # Parameter: optional # Values: file path # Default: /usr/share/freeradius/dictionary # Dictionaries = /usr/share/freeradius/dictionary - # RADIUS port number for the socket + # RADIUS port number # Parameter: optional # Value: 1 ... 65535 # Default: 1812 From b2264e8adbfc8943bbc3bf0333f2178a1ada48f6 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Thu, 6 Feb 2025 14:58:00 +0200 Subject: [PATCH 036/186] Radius. Copy constructor RADIUS and assignment operator declaration changed and moved to public section. --- projects/stargazer/plugins/other/radius/radius.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.h b/projects/stargazer/plugins/other/radius/radius.h index c0152785..c171efdf 100644 --- a/projects/stargazer/plugins/other/radius/radius.h +++ b/projects/stargazer/plugins/other/radius/radius.h @@ -38,6 +38,8 @@ namespace STG { public: RADIUS(); + RADIUS(const RADIUS&) = delete; + RADIUS& operator=(const RADIUS&) = delete; void SetSettings(const ModuleSettings & s) override { m_settings = s; } int ParseSettings() override; @@ -57,9 +59,6 @@ namespace STG int SendMessage(const Message & msg, uint32_t ip) const override { return 0; } private: - RADIUS(const RADIUS & rhs); - RADIUS & operator=(const RADIUS & rhs); - int Run(std::stop_token token); mutable std::string m_errorStr; From a4ff4c91e3091a461e9ffc8f1d403a7abedf348d Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Thu, 6 Feb 2025 15:21:05 +0200 Subject: [PATCH 037/186] Radius. Class member m_mutex moved to the top of section private. --- projects/stargazer/plugins/other/radius/radius.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/projects/stargazer/plugins/other/radius/radius.h b/projects/stargazer/plugins/other/radius/radius.h index c171efdf..8eedace1 100644 --- a/projects/stargazer/plugins/other/radius/radius.h +++ b/projects/stargazer/plugins/other/radius/radius.h @@ -59,6 +59,8 @@ namespace STG int SendMessage(const Message & msg, uint32_t ip) const override { return 0; } private: + std::mutex m_mutex; + int Run(std::stop_token token); mutable std::string m_errorStr; @@ -68,7 +70,6 @@ namespace STG bool m_running; std::jthread m_thread; - std::mutex m_mutex; PluginLogger m_logger; }; From f35612b9d1950a0078f049a5c9692cb67f9df09f Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Thu, 6 Feb 2025 15:27:28 +0200 Subject: [PATCH 038/186] Radius. The m_port variable value initialization changed to 1812, m_dictionaries variable initialization added to constructor RAD_SETTINGS. --- projects/stargazer/plugins/other/radius/radius.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index a41eda16..0ff6bbf8 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -19,7 +19,8 @@ extern "C" STG::Plugin* GetPlugin() } RAD_SETTINGS::RAD_SETTINGS() - : m_port(0) + : m_port(1812), + m_dictionaries("/usr/share/freeradius/dictionary") {} int RAD_SETTINGS::ParseSettings(const ModuleSettings & s) From 4c782bc8ecc39d0a5a684e4cd35a74f49243f4fe Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Fri, 7 Feb 2025 17:08:26 +0200 Subject: [PATCH 039/186] Radius. Check for missing parameters port and dictionaries removed in function ParseSettings. --- .../stargazer/plugins/other/radius/radius.cpp | 29 ++++++------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 0ff6bbf8..e517c959 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -30,19 +30,16 @@ int RAD_SETTINGS::ParseSettings(const ModuleSettings & s) pv.param = "Port"; auto pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv); - if (pvi == s.moduleParams.end() || pvi->value.empty()) - { - m_errorStr = "Parameter \'Port\' not found."; - printfd(__FILE__, "Parameter 'Port' not found\n"); - return -1; - } - if (ParseIntInRange(pvi->value[0], 2, 65535, &p) != 0) + if (pvi != s.moduleParams.end() && !pvi->value.empty()) { - m_errorStr = "Cannot parse parameter \'Port\': " + m_errorStr; - printfd(__FILE__, "Cannot parse parameter 'Port'\n"); - return -1; + 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(p); } - m_port = static_cast(p); pv.param = "Secret"; pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv); @@ -59,16 +56,8 @@ int RAD_SETTINGS::ParseSettings(const ModuleSettings & s) pv.param = "Dictionaries"; pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv); - if (pvi == s.moduleParams.end() || pvi->value.empty()) - { - m_errorStr = "Parameter \'Dictionaries\' not found."; - printfd(__FILE__, "Parameter 'Dictionaries' not found\n"); - m_dictionaries = ""; - } - else - { + if (pvi != s.moduleParams.end() && !pvi->value.empty()) m_dictionaries = pvi->value[0]; - } return 0; } From b4a5568f1c24665d0d27bc8d83c61f5007d07d10 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Fri, 28 Feb 2025 14:20:06 +0200 Subject: [PATCH 040/186] Radius. The dist directory added. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index ba791f70..9fe21c8f 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ CVS* doc/xmlrpc-doc/book doc/help/book doc/help/help.pdf +dist From f85212837364c04595d5cf9cd6ef201aaaea366a Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Fri, 28 Feb 2025 14:37:05 +0200 Subject: [PATCH 041/186] Radius. The methods declaration stop and start added. --- projects/stargazer/plugins/other/radius/server.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/projects/stargazer/plugins/other/radius/server.h b/projects/stargazer/plugins/other/radius/server.h index b88889be..7769fa95 100644 --- a/projects/stargazer/plugins/other/radius/server.h +++ b/projects/stargazer/plugins/other/radius/server.h @@ -13,11 +13,12 @@ namespace STG { public: Server(boost::asio::io_service& io_service, const std::string& secret, uint16_t port, const std::string& filePath); - + void stop(); private: RadProto::Packet makeResponse(const RadProto::Packet& request); void handleReceive(const boost::system::error_code& error, const std::optional& packet, const boost::asio::ip::udp::endpoint& source); void handleSend(const boost::system::error_code& ec); + void start(); void startReceive(); RadProto::Socket m_radius; From d89cd5eaa4e2c629cfd2c8f6ed54f0d66c7310b9 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Fri, 28 Feb 2025 14:42:36 +0200 Subject: [PATCH 042/186] Radius. The methods stop, start definition added. Method start call added to Server constructor. --- projects/stargazer/plugins/other/radius/server.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/projects/stargazer/plugins/other/radius/server.cpp b/projects/stargazer/plugins/other/radius/server.cpp index 4d16b6cb..e4b28876 100644 --- a/projects/stargazer/plugins/other/radius/server.cpp +++ b/projects/stargazer/plugins/other/radius/server.cpp @@ -9,10 +9,21 @@ using boost::system::error_code; Server::Server(boost::asio::io_service& io_service, const std::string& secret, uint16_t port, const std::string& filePath) : m_radius(io_service, secret, port), m_dictionaries(filePath) +{ + start(); +} + +void Server::start() { startReceive(); } +void Server::stop() +{ + error_code ec; + m_radius.close(ec); +} + void Server::startReceive() { m_radius.asyncReceive([this](const auto& error, const auto& packet, const boost::asio::ip::udp::endpoint& source){ handleReceive(error, packet, source); }); From 22b6a97a8e97808164689836a70595d6419504fa Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Fri, 28 Feb 2025 15:08:43 +0200 Subject: [PATCH 043/186] Radius. The header files "server.h", , added. The class members m_ioService, m_server added. --- projects/stargazer/plugins/other/radius/radius.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/projects/stargazer/plugins/other/radius/radius.h b/projects/stargazer/plugins/other/radius/radius.h index 8eedace1..bc38e3a6 100644 --- a/projects/stargazer/plugins/other/radius/radius.h +++ b/projects/stargazer/plugins/other/radius/radius.h @@ -5,8 +5,11 @@ #include "stg/module_settings.h" #include "stg/subscriptions.h" #include "stg/logger.h" +#include "server.h" +#include #include +#include #include #include #include //uint8_t, uint32_t @@ -61,6 +64,7 @@ namespace STG private: std::mutex m_mutex; + boost::asio::io_service m_ioService; int Run(std::stop_token token); mutable std::string m_errorStr; @@ -72,5 +76,7 @@ namespace STG std::jthread m_thread; PluginLogger m_logger; + + std::unique_ptr m_server{}; }; } From b137bad73d1072ff7376749c5bcbc80ecd4f28c9 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Fri, 28 Feb 2025 15:21:19 +0200 Subject: [PATCH 044/186] Radius. The header files "server", , removed. The method m_server->stop() call added to method Stop. --- .../stargazer/plugins/other/radius/radius.cpp | 47 +++++++++---------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index e517c959..27d13fb9 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -1,11 +1,7 @@ #include "radius.h" -#include "server.h" #include "radproto/error.h" - #include "stg/common.h" -#include -#include #include #include @@ -67,27 +63,6 @@ RADIUS::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); @@ -113,6 +88,7 @@ int RADIUS::Stop() if (!m_thread.joinable()) return 0; + m_server->stop(); m_thread.request_stop(); m_thread.join(); @@ -130,3 +106,24 @@ void RADIUS::SetRunning(bool val) const std::lock_guard lock(m_mutex); m_running = val; } + +int RADIUS::Run(std::stop_token token) +{ + SetRunning(true); + + try + { + if (!m_server) + m_server = std::make_unique (m_ioService, m_radSettings.GetSecret(), m_radSettings.GetPort(), m_radSettings.GetDictionaries()); + m_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; +} From d8332789a5b4c294719fb16af6102b150fbe6f6b Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Fri, 7 Mar 2025 14:41:04 +0200 Subject: [PATCH 045/186] Radius. Header files and added. Parameter token added to constructor Server. Class member m_token added. --- projects/stargazer/plugins/other/radius/server.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/projects/stargazer/plugins/other/radius/server.h b/projects/stargazer/plugins/other/radius/server.h index 7769fa95..df4278ac 100644 --- a/projects/stargazer/plugins/other/radius/server.h +++ b/projects/stargazer/plugins/other/radius/server.h @@ -4,6 +4,8 @@ #include "radproto/packet.h" #include "radproto/dictionaries.h" #include +#include +#include #include #include //uint8_t, uint32_t @@ -12,7 +14,7 @@ namespace STG class Server { public: - Server(boost::asio::io_service& io_service, const std::string& secret, uint16_t port, const std::string& filePath); + Server(boost::asio::io_service& io_service, const std::string& secret, uint16_t port, const std::string& filePath, std::stop_token token); void stop(); private: RadProto::Packet makeResponse(const RadProto::Packet& request); @@ -23,5 +25,6 @@ namespace STG RadProto::Socket m_radius; RadProto::Dictionaries m_dictionaries; + std::stop_token m_token; }; } From af7b211f1df2041b020fd4a5ef4f68a1b339456e Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Fri, 7 Mar 2025 14:47:41 +0200 Subject: [PATCH 046/186] Radius. Parameter token and m_token class member initialization added to Server constructor definition. The check m_token.stop_requested() added to method handleSend before startReceive method call. --- projects/stargazer/plugins/other/radius/server.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/server.cpp b/projects/stargazer/plugins/other/radius/server.cpp index e4b28876..923c4d7a 100644 --- a/projects/stargazer/plugins/other/radius/server.cpp +++ b/projects/stargazer/plugins/other/radius/server.cpp @@ -6,9 +6,10 @@ using STG::Server; using boost::system::error_code; -Server::Server(boost::asio::io_service& io_service, const std::string& secret, uint16_t port, const std::string& filePath) +Server::Server(boost::asio::io_service& io_service, const std::string& secret, uint16_t port, const std::string& filePath, std::stop_token token) : m_radius(io_service, secret, port), - m_dictionaries(filePath) + m_dictionaries(filePath), + m_token(token) { start(); } @@ -56,7 +57,8 @@ void Server::handleSend(const error_code& ec) if (ec) std::cout << "Error asyncSend: " << ec.message() << "\n"; - startReceive(); + if (!m_token.stop_requested()) + startReceive(); } void Server::handleReceive(const error_code& error, const std::optional& packet, const boost::asio::ip::udp::endpoint& source) From d1f81bac256d07b8a8c028a009e7acbd253bc371 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Fri, 7 Mar 2025 14:55:27 +0200 Subject: [PATCH 047/186] Radius. The m_server class member initialization removed. --- projects/stargazer/plugins/other/radius/radius.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/stargazer/plugins/other/radius/radius.h b/projects/stargazer/plugins/other/radius/radius.h index bc38e3a6..6b742de5 100644 --- a/projects/stargazer/plugins/other/radius/radius.h +++ b/projects/stargazer/plugins/other/radius/radius.h @@ -77,6 +77,6 @@ namespace STG PluginLogger m_logger; - std::unique_ptr m_server{}; + std::unique_ptr m_server; }; } From 2961aecf7b9067e899f8c602913ffc4672ab005e Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Fri, 7 Mar 2025 15:19:40 +0200 Subject: [PATCH 048/186] Radius. The m_server->stop() call adnd m_thread.request_stop() call reodered, the m_server check added before m_server->stop call in the method Stop. Parameter token added to constructor Server in the function Run. --- projects/stargazer/plugins/other/radius/radius.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 27d13fb9..612af22f 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -88,9 +88,11 @@ int RADIUS::Stop() if (!m_thread.joinable()) return 0; - m_server->stop(); m_thread.request_stop(); + if (m_server) + m_server->stop(); + m_thread.join(); return 0; } @@ -114,7 +116,7 @@ int RADIUS::Run(std::stop_token token) try { if (!m_server) - m_server = std::make_unique (m_ioService, m_radSettings.GetSecret(), m_radSettings.GetPort(), m_radSettings.GetDictionaries()); + m_server = std::make_unique (m_ioService, m_radSettings.GetSecret(), m_radSettings.GetPort(), m_radSettings.GetDictionaries(), token); m_ioService.run(); } catch (const std::exception& e) From 881c2fd6ef518acc66f7862c0d28d0ba6ffa9a9c Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Mon, 10 Mar 2025 14:52:31 +0200 Subject: [PATCH 049/186] Radius. Header file "stg/logger.h" added. Class member m_logger added to class Server. --- projects/stargazer/plugins/other/radius/server.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/projects/stargazer/plugins/other/radius/server.h b/projects/stargazer/plugins/other/radius/server.h index df4278ac..4a5f718c 100644 --- a/projects/stargazer/plugins/other/radius/server.h +++ b/projects/stargazer/plugins/other/radius/server.h @@ -3,6 +3,7 @@ #include "radproto/socket.h" #include "radproto/packet.h" #include "radproto/dictionaries.h" +#include "stg/logger.h" #include #include #include @@ -26,5 +27,7 @@ namespace STG RadProto::Socket m_radius; RadProto::Dictionaries m_dictionaries; std::stop_token m_token; + + PluginLogger m_logger; }; } From 7e273c9e8a5c4122bce6ec75ca4cb59f42113dfd Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Mon, 10 Mar 2025 15:59:30 +0200 Subject: [PATCH 050/186] Radius. Header file "stg/common.h" added, header file removed. Class member m_logger initialization added to constructor Server. Object std::cout replaced by function printfd and m_logger. --- .../stargazer/plugins/other/radius/server.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/server.cpp b/projects/stargazer/plugins/other/radius/server.cpp index 923c4d7a..5dea22ef 100644 --- a/projects/stargazer/plugins/other/radius/server.cpp +++ b/projects/stargazer/plugins/other/radius/server.cpp @@ -1,7 +1,7 @@ #include "server.h" #include "radproto/packet_codes.h" +#include "stg/common.h" #include -#include using STG::Server; using boost::system::error_code; @@ -9,7 +9,8 @@ using boost::system::error_code; Server::Server(boost::asio::io_service& io_service, const std::string& secret, uint16_t port, const std::string& filePath, std::stop_token token) : m_radius(io_service, secret, port), m_dictionaries(filePath), - m_token(token) + m_token(token), + m_logger(PluginLogger::get("radius")) { start(); } @@ -55,7 +56,10 @@ RadProto::Packet Server::makeResponse(const RadProto::Packet& request) void Server::handleSend(const error_code& ec) { if (ec) - std::cout << "Error asyncSend: " << ec.message() << "\n"; + { + m_logger("Error asyncSend: %s", ec.message()); + printfd(__FILE__, "Error asyncSend: '%s'\n", ec.message()); + } if (!m_token.stop_requested()) startReceive(); @@ -65,13 +69,15 @@ void Server::handleReceive(const error_code& error, const std::optional Date: Wed, 12 Mar 2025 14:08:04 +0200 Subject: [PATCH 051/186] Radius. Class member m_logger initialization changed in the constructor Server. Check token moved before checking the error code in the handleSend method. --- projects/stargazer/plugins/other/radius/server.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/server.cpp b/projects/stargazer/plugins/other/radius/server.cpp index 5dea22ef..ca03d927 100644 --- a/projects/stargazer/plugins/other/radius/server.cpp +++ b/projects/stargazer/plugins/other/radius/server.cpp @@ -10,7 +10,7 @@ Server::Server(boost::asio::io_service& io_service, const std::string& secret, u : m_radius(io_service, secret, port), m_dictionaries(filePath), m_token(token), - m_logger(PluginLogger::get("radius")) + m_logger(PluginLogger::get("RADIUS")) { start(); } @@ -55,14 +55,14 @@ RadProto::Packet Server::makeResponse(const RadProto::Packet& request) void Server::handleSend(const error_code& ec) { + if (!m_token.stop_requested()) + startReceive(); + if (ec) { m_logger("Error asyncSend: %s", ec.message()); printfd(__FILE__, "Error asyncSend: '%s'\n", ec.message()); } - - if (!m_token.stop_requested()) - startReceive(); } void Server::handleReceive(const error_code& error, const std::optional& packet, const boost::asio::ip::udp::endpoint& source) From b29a9180413301585fc51aab1acb6bbff0b8ea1b Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Wed, 12 Mar 2025 14:49:32 +0200 Subject: [PATCH 052/186] Radius. Check token added to handleReceive method. --- .../stargazer/plugins/other/radius/server.cpp | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/server.cpp b/projects/stargazer/plugins/other/radius/server.cpp index ca03d927..e5a9a40f 100644 --- a/projects/stargazer/plugins/other/radius/server.cpp +++ b/projects/stargazer/plugins/other/radius/server.cpp @@ -67,21 +67,24 @@ void Server::handleSend(const error_code& ec) void Server::handleReceive(const error_code& error, const std::optional& packet, const boost::asio::ip::udp::endpoint& source) { - if (error) + if (!m_token.stop_requested()) { - m_logger("Error asyncReceive: %s", error.message()); - printfd(__FILE__, "Error asyncReceive: '%s'\n", error.message()); - return; - } + if (error) + { + m_logger("Error asyncReceive: %s", error.message()); + printfd(__FILE__, "Error asyncReceive: '%s'\n", error.message()); + return; + } - if (packet == std::nullopt) - { - m_logger("Error asyncReceive: the request packet is missing\n"); - printfd(__FILE__, "Error asyncReceive: the request packet is missing\n"); - return; - } - else - { - m_radius.asyncSend(makeResponse(*packet), source, [this](const auto& ec){ handleSend(ec); }); + if (packet == std::nullopt) + { + m_logger("Error asyncReceive: the request packet is missing\n"); + printfd(__FILE__, "Error asyncReceive: the request packet is missing\n"); + return; + } + else + { + m_radius.asyncSend(makeResponse(*packet), source, [this](const auto& ec){ handleSend(ec); }); + } } } From a69f043ac47655f2c1f51f6acad7aff4f3e3dee4 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Wed, 12 Mar 2025 15:06:38 +0200 Subject: [PATCH 053/186] Radius. Header file replaced by , header file removed. --- projects/stargazer/plugins/other/radius/server.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/server.h b/projects/stargazer/plugins/other/radius/server.h index 4a5f718c..dd1f6f63 100644 --- a/projects/stargazer/plugins/other/radius/server.h +++ b/projects/stargazer/plugins/other/radius/server.h @@ -5,8 +5,7 @@ #include "radproto/dictionaries.h" #include "stg/logger.h" #include -#include -#include +#include #include #include //uint8_t, uint32_t From 46c4133fc5e40c27face56f81922f6ca0f84f9c6 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Fri, 14 Mar 2025 15:08:33 +0200 Subject: [PATCH 054/186] Radius. Parameter m_logger added to constructor Server call in the method Run. --- projects/stargazer/plugins/other/radius/radius.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 612af22f..4be0e241 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -116,7 +116,7 @@ int RADIUS::Run(std::stop_token token) try { if (!m_server) - m_server = std::make_unique (m_ioService, m_radSettings.GetSecret(), m_radSettings.GetPort(), m_radSettings.GetDictionaries(), token); + m_server = std::make_unique (m_ioService, m_radSettings.GetSecret(), m_radSettings.GetPort(), m_radSettings.GetDictionaries(), token, m_logger); m_ioService.run(); } catch (const std::exception& e) From 095f460b33fa2639ef12d6bd7d664b12d567bb9e Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Fri, 14 Mar 2025 15:14:46 +0200 Subject: [PATCH 055/186] Radius. Parameter logger added to constructor Server declaration. Class member m_logger added to class Server. --- projects/stargazer/plugins/other/radius/server.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/server.h b/projects/stargazer/plugins/other/radius/server.h index dd1f6f63..e33a23b3 100644 --- a/projects/stargazer/plugins/other/radius/server.h +++ b/projects/stargazer/plugins/other/radius/server.h @@ -14,7 +14,7 @@ namespace STG class Server { public: - Server(boost::asio::io_service& io_service, const std::string& secret, uint16_t port, const std::string& filePath, std::stop_token token); + Server(boost::asio::io_service& io_service, const std::string& secret, uint16_t port, const std::string& filePath, std::stop_token token, PluginLogger& logger); void stop(); private: RadProto::Packet makeResponse(const RadProto::Packet& request); @@ -27,6 +27,6 @@ namespace STG RadProto::Dictionaries m_dictionaries; std::stop_token m_token; - PluginLogger m_logger; + PluginLogger& m_logger; }; } From db47a07b0243d5d44e747ab94318c154e38dbb34 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Fri, 14 Mar 2025 15:18:44 +0200 Subject: [PATCH 056/186] Radius. Parameter logger added to constructor Server definition. Class member m_logger initialization changed in the constructor Server. --- projects/stargazer/plugins/other/radius/server.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/server.cpp b/projects/stargazer/plugins/other/radius/server.cpp index e5a9a40f..28e932e7 100644 --- a/projects/stargazer/plugins/other/radius/server.cpp +++ b/projects/stargazer/plugins/other/radius/server.cpp @@ -6,11 +6,11 @@ using STG::Server; using boost::system::error_code; -Server::Server(boost::asio::io_service& io_service, const std::string& secret, uint16_t port, const std::string& filePath, std::stop_token token) +Server::Server(boost::asio::io_service& io_service, const std::string& secret, uint16_t port, const std::string& filePath, std::stop_token token, PluginLogger& logger) : m_radius(io_service, secret, port), m_dictionaries(filePath), m_token(token), - m_logger(PluginLogger::get("RADIUS")) + m_logger(logger) { start(); } From 2f1a11cd18e5980581a0c9c35ac26ba32b85118e Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Mon, 17 Mar 2025 15:45:30 +0200 Subject: [PATCH 057/186] Radius. Extra whitespace removed ib the method Run. --- projects/stargazer/plugins/other/radius/radius.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 4be0e241..bd78096b 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -116,7 +116,7 @@ int RADIUS::Run(std::stop_token token) try { if (!m_server) - m_server = std::make_unique (m_ioService, m_radSettings.GetSecret(), m_radSettings.GetPort(), m_radSettings.GetDictionaries(), token, m_logger); + m_server = std::make_unique(m_ioService, m_radSettings.GetSecret(), m_radSettings.GetPort(), m_radSettings.GetDictionaries(), token, m_logger); m_ioService.run(); } catch (const std::exception& e) From a110cf66b4b1a4606adeef04707ceea4789df4d9 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Mon, 17 Mar 2025 16:24:14 +0200 Subject: [PATCH 058/186] Radius. The order of operations changed in the method handleSend. --- projects/stargazer/plugins/other/radius/server.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/server.cpp b/projects/stargazer/plugins/other/radius/server.cpp index 28e932e7..f1f80727 100644 --- a/projects/stargazer/plugins/other/radius/server.cpp +++ b/projects/stargazer/plugins/other/radius/server.cpp @@ -55,14 +55,15 @@ RadProto::Packet Server::makeResponse(const RadProto::Packet& request) void Server::handleSend(const error_code& ec) { - if (!m_token.stop_requested()) - startReceive(); + if (m_token.stop_requested()) + return; if (ec) { m_logger("Error asyncSend: %s", ec.message()); printfd(__FILE__, "Error asyncSend: '%s'\n", ec.message()); } + startReceive(); } void Server::handleReceive(const error_code& error, const std::optional& packet, const boost::asio::ip::udp::endpoint& source) From 4b86c90ba312a519132fabc43b99d176550a866d Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Mon, 17 Mar 2025 16:39:32 +0200 Subject: [PATCH 059/186] Radius. The order of operations changed in the method handleReceive. --- .../stargazer/plugins/other/radius/server.cpp | 32 +++++++++---------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/server.cpp b/projects/stargazer/plugins/other/radius/server.cpp index f1f80727..334256d5 100644 --- a/projects/stargazer/plugins/other/radius/server.cpp +++ b/projects/stargazer/plugins/other/radius/server.cpp @@ -68,24 +68,22 @@ void Server::handleSend(const error_code& ec) void Server::handleReceive(const error_code& error, const std::optional& packet, const boost::asio::ip::udp::endpoint& source) { - if (!m_token.stop_requested()) + if (m_token.stop_requested()) + return; + + if (error) { - if (error) - { - m_logger("Error asyncReceive: %s", error.message()); - printfd(__FILE__, "Error asyncReceive: '%s'\n", error.message()); - return; - } + m_logger("Error asyncReceive: %s", error.message()); + printfd(__FILE__, "Error asyncReceive: '%s'\n", error.message()); + return; + } - if (packet == std::nullopt) - { - m_logger("Error asyncReceive: the request packet is missing\n"); - printfd(__FILE__, "Error asyncReceive: the request packet is missing\n"); - return; - } - else - { - m_radius.asyncSend(makeResponse(*packet), source, [this](const auto& ec){ handleSend(ec); }); - } + if (packet == std::nullopt) + { + m_logger("Error asyncReceive: the request packet is missing\n"); + printfd(__FILE__, "Error asyncReceive: the request packet is missing\n"); + return; } + else + m_radius.asyncSend(makeResponse(*packet), source, [this](const auto& ec){ handleSend(ec); }); } From 01225c4742f10fad3994147b49a0112a94b242bf Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Tue, 18 Mar 2025 14:52:05 +0200 Subject: [PATCH 060/186] Radius. Operator return removed when checking ec, operator else removed when checking packet in the handleReceive method. --- projects/stargazer/plugins/other/radius/server.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/server.cpp b/projects/stargazer/plugins/other/radius/server.cpp index 334256d5..595bc8de 100644 --- a/projects/stargazer/plugins/other/radius/server.cpp +++ b/projects/stargazer/plugins/other/radius/server.cpp @@ -75,7 +75,6 @@ void Server::handleReceive(const error_code& error, const std::optional Date: Tue, 18 Mar 2025 16:03:33 +0200 Subject: [PATCH 061/186] Radius. Parameter token replaced by std::move(token) in the constructor Server in method Run. --- projects/stargazer/plugins/other/radius/radius.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index bd78096b..8e5b37a8 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -116,7 +116,7 @@ int RADIUS::Run(std::stop_token token) try { if (!m_server) - m_server = std::make_unique(m_ioService, m_radSettings.GetSecret(), m_radSettings.GetPort(), m_radSettings.GetDictionaries(), token, m_logger); + m_server = std::make_unique(m_ioService, m_radSettings.GetSecret(), m_radSettings.GetPort(), m_radSettings.GetDictionaries(), std::move(token), m_logger); m_ioService.run(); } catch (const std::exception& e) From bb7155111912b3a77cbc4d4403c4c94239d1441f Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Tue, 18 Mar 2025 16:08:54 +0200 Subject: [PATCH 062/186] Radius. Class member m_token initialization value changed to std::move(token) in the constructor Server. --- projects/stargazer/plugins/other/radius/server.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/stargazer/plugins/other/radius/server.cpp b/projects/stargazer/plugins/other/radius/server.cpp index 595bc8de..f3687bcb 100644 --- a/projects/stargazer/plugins/other/radius/server.cpp +++ b/projects/stargazer/plugins/other/radius/server.cpp @@ -9,7 +9,7 @@ using boost::system::error_code; Server::Server(boost::asio::io_service& io_service, const std::string& secret, uint16_t port, const std::string& filePath, std::stop_token token, PluginLogger& logger) : m_radius(io_service, secret, port), m_dictionaries(filePath), - m_token(token), + m_token(std::move(token)), m_logger(logger) { start(); From 129fc5c29c5f6078584d96d84dce5557cd2a3e6d Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Tue, 18 Mar 2025 16:22:04 +0200 Subject: [PATCH 063/186] Radius. The c_str() function added to message when checking error in the handleSend and handleReceive methods. --- projects/stargazer/plugins/other/radius/server.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/server.cpp b/projects/stargazer/plugins/other/radius/server.cpp index f3687bcb..e4aeb8b1 100644 --- a/projects/stargazer/plugins/other/radius/server.cpp +++ b/projects/stargazer/plugins/other/radius/server.cpp @@ -60,8 +60,8 @@ void Server::handleSend(const error_code& ec) if (ec) { - m_logger("Error asyncSend: %s", ec.message()); - printfd(__FILE__, "Error asyncSend: '%s'\n", ec.message()); + m_logger("Error asyncSend: %s", ec.message().c_str()); + printfd(__FILE__, "Error asyncSend: '%s'\n", ec.message().c_str()); } startReceive(); } @@ -73,8 +73,8 @@ void Server::handleReceive(const error_code& error, const std::optional Date: Tue, 18 Mar 2025 16:28:26 +0200 Subject: [PATCH 064/186] Radius. Header file added. --- projects/stargazer/plugins/other/radius/server.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/projects/stargazer/plugins/other/radius/server.cpp b/projects/stargazer/plugins/other/radius/server.cpp index e4aeb8b1..850847fa 100644 --- a/projects/stargazer/plugins/other/radius/server.cpp +++ b/projects/stargazer/plugins/other/radius/server.cpp @@ -1,6 +1,7 @@ #include "server.h" #include "radproto/packet_codes.h" #include "stg/common.h" +#include #include using STG::Server; From 5d9d30ed26fb86c35cf29fab99bb34a0dd440d6f Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Fri, 28 Mar 2025 16:26:48 +0200 Subject: [PATCH 065/186] Radius. Header files "stg/users.h", "stg/user.h", "stg/user_property.h" added. The using statements added. The findUser, SetUsers functions declaration added. Class member m_users added. --- projects/stargazer/plugins/other/radius/server.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/projects/stargazer/plugins/other/radius/server.h b/projects/stargazer/plugins/other/radius/server.h index e33a23b3..b89d7168 100644 --- a/projects/stargazer/plugins/other/radius/server.h +++ b/projects/stargazer/plugins/other/radius/server.h @@ -3,6 +3,9 @@ #include "radproto/socket.h" #include "radproto/packet.h" #include "radproto/dictionaries.h" +#include "stg/users.h" +#include "stg/user.h" +#include "stg/user_property.h" #include "stg/logger.h" #include #include @@ -11,10 +14,17 @@ namespace STG { + class Users; + + using UserPtr = STG::User*; + using ConstUserPtr = const User*; + class Server { public: Server(boost::asio::io_service& io_service, const std::string& secret, uint16_t port, const std::string& filePath, std::stop_token token, PluginLogger& logger); + int findUser(const RadProto::Packet& packet); + void SetUsers(STG::Users* u) { m_users = u; } void stop(); private: RadProto::Packet makeResponse(const RadProto::Packet& request); @@ -25,6 +35,7 @@ namespace STG RadProto::Socket m_radius; RadProto::Dictionaries m_dictionaries; + STG::Users* m_users; std::stop_token m_token; PluginLogger& m_logger; From 9cce8e2950fe7a27e91e02894a3ae7c7342c2e92 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Fri, 28 Mar 2025 16:48:02 +0200 Subject: [PATCH 066/186] Radius. Header files "radproto/attribute_types.h", added. The m_users class member initialization added to constructor Server. The findUser function definition added. The findUser function call added to makeResponse function. --- .../stargazer/plugins/other/radius/server.cpp | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/projects/stargazer/plugins/other/radius/server.cpp b/projects/stargazer/plugins/other/radius/server.cpp index 850847fa..81d98e3a 100644 --- a/projects/stargazer/plugins/other/radius/server.cpp +++ b/projects/stargazer/plugins/other/radius/server.cpp @@ -1,8 +1,10 @@ #include "server.h" #include "radproto/packet_codes.h" +#include "radproto/attribute_types.h" #include "stg/common.h" #include #include +#include //uint8_t, uint32_t using STG::Server; using boost::system::error_code; @@ -10,6 +12,7 @@ using boost::system::error_code; Server::Server(boost::asio::io_service& io_service, const std::string& secret, uint16_t port, const std::string& filePath, std::stop_token token, PluginLogger& logger) : m_radius(io_service, secret, port), m_dictionaries(filePath), + m_users(NULL), m_token(std::move(token)), m_logger(logger) { @@ -48,6 +51,13 @@ RadProto::Packet Server::makeResponse(const RadProto::Packet& request) std::vector vendorValue {0, 0, 0, 3}; vendorSpecific.push_back(RadProto::VendorSpecific(m_dictionaries.vendorCode("Dlink"), m_dictionaries.vendorAttributeCode("Dlink", "Dlink-User-Level"), vendorValue)); + if (findUser(request)) + { + m_logger("Error findUser\n"); + printfd(__FILE__, "Error findUser\n"); + return RadProto::Packet(RadProto::ACCESS_REJECT, request.id(), request.auth(), attributes, vendorSpecific); + } + if (request.type() == RadProto::ACCESS_REQUEST) return RadProto::Packet(RadProto::ACCESS_ACCEPT, request.id(), request.auth(), attributes, vendorSpecific); @@ -84,5 +94,41 @@ void Server::handleReceive(const error_code& error, const std::optionaltype() == RadProto::USER_NAME) + login = m_dictionaries.attributeValueName(m_dictionaries.attributeName(RadProto::USER_NAME), RadProto::USER_NAME); + + if (a->type() == RadProto::USER_PASSWORD) + password = m_dictionaries.attributeValueName(m_dictionaries.attributeName(RadProto::USER_PASSWORD), RadProto::USER_PASSWORD); + } + + if (m_users->FindByName(login, &user)) + { + m_logger("User's connect failed: user '%s' not found. %s", login); + printfd(__FILE__, "User '%s' NOT found!\n", login); + return -1; + } + + printfd(__FILE__, "User '%s' FOUND!\n", user->GetLogin().c_str()); + + if (password != user->GetProperties().password.Get()) + { + m_logger("Password user is incorrect. %s", password); + printfd(__FILE__, "Password user is incorrect.\n", password); + return -1; + } + + printfd(__FILE__, "User FOUND!\n"); + + return 0; +} From 0ff99e1e5e40f1a84573be22fdbdfb7b35556249 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Tue, 1 Apr 2025 15:49:43 +0300 Subject: [PATCH 067/186] Radius. Getting the values of login and password fixed in the function findUser. Extra functions printfd call added. --- .../stargazer/plugins/other/radius/server.cpp | 37 ++++++++++++++++--- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/server.cpp b/projects/stargazer/plugins/other/radius/server.cpp index 81d98e3a..12484cd5 100644 --- a/projects/stargazer/plugins/other/radius/server.cpp +++ b/projects/stargazer/plugins/other/radius/server.cpp @@ -51,13 +51,21 @@ RadProto::Packet Server::makeResponse(const RadProto::Packet& request) std::vector vendorValue {0, 0, 0, 3}; vendorSpecific.push_back(RadProto::VendorSpecific(m_dictionaries.vendorCode("Dlink"), m_dictionaries.vendorAttributeCode("Dlink", "Dlink-User-Level"), vendorValue)); + printfd(__FILE__, "MakeResponse before findUser\n"); if (findUser(request)) { + printfd(__FILE__, "MakeResponse reject findUser\n"); + + m_logger("Error findUser\n"); printfd(__FILE__, "Error findUser\n"); return RadProto::Packet(RadProto::ACCESS_REJECT, request.id(), request.auth(), attributes, vendorSpecific); } + + printfd(__FILE__, "MakeResponse accept findUser\n"); + + if (request.type() == RadProto::ACCESS_REQUEST) return RadProto::Packet(RadProto::ACCESS_ACCEPT, request.id(), request.auth(), attributes, vendorSpecific); @@ -100,18 +108,37 @@ void Server::handleReceive(const error_code& error, const std::optionaltype() == RadProto::USER_NAME) - login = m_dictionaries.attributeValueName(m_dictionaries.attributeName(RadProto::USER_NAME), RadProto::USER_NAME); + printfd(__FILE__, "findUser cycle start\n"); - if (a->type() == RadProto::USER_PASSWORD) - password = m_dictionaries.attributeValueName(m_dictionaries.attributeName(RadProto::USER_PASSWORD), RadProto::USER_PASSWORD); + if (attribute->type() == RadProto::USER_NAME) + { + + printfd(__FILE__, "findUser cycle start if\n"); + login = attribute->toString(); + + printfd(__FILE__, "findUser login '%s'\n", login.c_str()); + } + + if (attribute->type() == RadProto::USER_PASSWORD) + { + password = attribute->toString(); + + + printfd(__FILE__, "findUser password '%s'\n", password.c_str()); + } } + + printfd(__FILE__, "findUser after cycle\n"); + if (m_users->FindByName(login, &user)) { m_logger("User's connect failed: user '%s' not found. %s", login); From 6d03d729a612561905f15d1c2b6b35937589d5d3 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Thu, 3 Apr 2025 15:37:25 +0300 Subject: [PATCH 068/186] Radius. Using statements added. Method SetUsers added, variable class member m_users added to class RADIUS. --- projects/stargazer/plugins/other/radius/radius.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/projects/stargazer/plugins/other/radius/radius.h b/projects/stargazer/plugins/other/radius/radius.h index 6b742de5..0ecd655a 100644 --- a/projects/stargazer/plugins/other/radius/radius.h +++ b/projects/stargazer/plugins/other/radius/radius.h @@ -18,6 +18,12 @@ namespace STG { struct Settings; + class Users; + + using UserPtr = STG::User*; + using ConstUserPtr = const User*; + + class RAD_SETTINGS { public: @@ -44,6 +50,7 @@ namespace STG RADIUS(const RADIUS&) = delete; RADIUS& operator=(const RADIUS&) = delete; + void SetUsers(STG::Users* u) { m_users = u; } void SetSettings(const ModuleSettings & s) override { m_settings = s; } int ParseSettings() override; @@ -74,7 +81,7 @@ namespace STG bool m_running; std::jthread m_thread; - + STG::Users* m_users; PluginLogger m_logger; std::unique_ptr m_server; From 24cf9ce38c70af8b783419f44d86768ef01d1cd7 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Thu, 3 Apr 2025 15:48:10 +0300 Subject: [PATCH 069/186] Radius. The class member variable m_users initialization added to constructor Radius. Parameter m_users added to constructor Server call in the method Run. --- projects/stargazer/plugins/other/radius/radius.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 8e5b37a8..c93c4ddf 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -59,6 +59,7 @@ int RAD_SETTINGS::ParseSettings(const ModuleSettings & s) RADIUS::RADIUS() : m_running(false), + m_users(NULL), m_logger(PluginLogger::get("radius")) { } @@ -116,7 +117,7 @@ int RADIUS::Run(std::stop_token token) try { if (!m_server) - m_server = std::make_unique(m_ioService, m_radSettings.GetSecret(), m_radSettings.GetPort(), m_radSettings.GetDictionaries(), std::move(token), m_logger); + m_server = std::make_unique(m_ioService, m_radSettings.GetSecret(), m_radSettings.GetPort(), m_radSettings.GetDictionaries(), std::move(token), m_logger, m_users); m_ioService.run(); } catch (const std::exception& e) From e0d0c901481b8750f245fa9b8a81789460ac6e68 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Thu, 3 Apr 2025 15:57:25 +0300 Subject: [PATCH 070/186] Radius. Parameter users added to constructir Server declaration. Function SetUsers removed fron class Server. --- projects/stargazer/plugins/other/radius/server.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/server.h b/projects/stargazer/plugins/other/radius/server.h index b89d7168..5bc0fcbd 100644 --- a/projects/stargazer/plugins/other/radius/server.h +++ b/projects/stargazer/plugins/other/radius/server.h @@ -22,9 +22,8 @@ namespace STG class Server { public: - Server(boost::asio::io_service& io_service, const std::string& secret, uint16_t port, const std::string& filePath, std::stop_token token, PluginLogger& logger); + Server(boost::asio::io_service& io_service, const std::string& secret, uint16_t port, const std::string& filePath, std::stop_token token, PluginLogger& logger, STG::Users* users); int findUser(const RadProto::Packet& packet); - void SetUsers(STG::Users* u) { m_users = u; } void stop(); private: RadProto::Packet makeResponse(const RadProto::Packet& request); From 2c18f404898b8a4204dfc9527b2e385c5b8ed7e0 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Thu, 3 Apr 2025 16:02:27 +0300 Subject: [PATCH 071/186] Radius. Parameter users added to constructor Server definition. Variable class member m_users initialization added to constructor Server. --- .../stargazer/plugins/other/radius/server.cpp | 27 +++---------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/server.cpp b/projects/stargazer/plugins/other/radius/server.cpp index 12484cd5..907fa973 100644 --- a/projects/stargazer/plugins/other/radius/server.cpp +++ b/projects/stargazer/plugins/other/radius/server.cpp @@ -9,10 +9,10 @@ using STG::Server; using boost::system::error_code; -Server::Server(boost::asio::io_service& io_service, const std::string& secret, uint16_t port, const std::string& filePath, std::stop_token token, PluginLogger& logger) +Server::Server(boost::asio::io_service& io_service, const std::string& secret, uint16_t port, const std::string& filePath, std::stop_token token, PluginLogger& logger, STG::Users* users) : m_radius(io_service, secret, port), m_dictionaries(filePath), - m_users(NULL), + m_users(users), m_token(std::move(token)), m_logger(logger) { @@ -51,21 +51,13 @@ RadProto::Packet Server::makeResponse(const RadProto::Packet& request) std::vector vendorValue {0, 0, 0, 3}; vendorSpecific.push_back(RadProto::VendorSpecific(m_dictionaries.vendorCode("Dlink"), m_dictionaries.vendorAttributeCode("Dlink", "Dlink-User-Level"), vendorValue)); - printfd(__FILE__, "MakeResponse before findUser\n"); if (findUser(request)) { - printfd(__FILE__, "MakeResponse reject findUser\n"); - - m_logger("Error findUser\n"); printfd(__FILE__, "Error findUser\n"); return RadProto::Packet(RadProto::ACCESS_REJECT, request.id(), request.auth(), attributes, vendorSpecific); } - - printfd(__FILE__, "MakeResponse accept findUser\n"); - - if (request.type() == RadProto::ACCESS_REQUEST) return RadProto::Packet(RadProto::ACCESS_ACCEPT, request.id(), request.auth(), attributes, vendorSpecific); @@ -108,37 +100,24 @@ void Server::handleReceive(const error_code& error, const std::optionaltype() == RadProto::USER_NAME) { - - printfd(__FILE__, "findUser cycle start if\n"); login = attribute->toString(); - printfd(__FILE__, "findUser login '%s'\n", login.c_str()); } if (attribute->type() == RadProto::USER_PASSWORD) { password = attribute->toString(); - - printfd(__FILE__, "findUser password '%s'\n", password.c_str()); } } - - printfd(__FILE__, "findUser after cycle\n"); - if (m_users->FindByName(login, &user)) { m_logger("User's connect failed: user '%s' not found. %s", login); @@ -146,6 +125,8 @@ int Server::findUser(const RadProto::Packet& packet) return -1; } + printfd(__FILE__, "findUser FindByName yes\n"); + printfd(__FILE__, "User '%s' FOUND!\n", user->GetLogin().c_str()); if (password != user->GetProperties().password.Get()) From 2ab70c755638c453b19f3bda278abfea1c42f7ca Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Fri, 4 Apr 2025 16:49:38 +0300 Subject: [PATCH 072/186] Radius. Function c_str added to login and password in m_logger and printfd function in the function findUser. --- projects/stargazer/plugins/other/radius/server.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/server.cpp b/projects/stargazer/plugins/other/radius/server.cpp index 907fa973..75dff161 100644 --- a/projects/stargazer/plugins/other/radius/server.cpp +++ b/projects/stargazer/plugins/other/radius/server.cpp @@ -120,8 +120,8 @@ int Server::findUser(const RadProto::Packet& packet) if (m_users->FindByName(login, &user)) { - m_logger("User's connect failed: user '%s' not found. %s", login); - printfd(__FILE__, "User '%s' NOT found!\n", login); + m_logger("User's connect failed: user '%s' not found. %s", login.c_str()); + printfd(__FILE__, "User '%s' NOT found!\n", login.c_str()); return -1; } @@ -131,8 +131,8 @@ int Server::findUser(const RadProto::Packet& packet) if (password != user->GetProperties().password.Get()) { - m_logger("Password user is incorrect. %s", password); - printfd(__FILE__, "Password user is incorrect.\n", password); + m_logger("Password user is incorrect. %s", password.c_str()); + printfd(__FILE__, "Password user is incorrect.\n", password.c_str()); return -1; } From 86af31d76103b43789ab2dd897faa8df394cdfe6 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Tue, 15 Apr 2025 14:32:05 +0300 Subject: [PATCH 073/186] Radius. Extra functions printfd removed. --- projects/stargazer/plugins/other/radius/server.cpp | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/server.cpp b/projects/stargazer/plugins/other/radius/server.cpp index 75dff161..1025b9fc 100644 --- a/projects/stargazer/plugins/other/radius/server.cpp +++ b/projects/stargazer/plugins/other/radius/server.cpp @@ -106,27 +106,19 @@ int Server::findUser(const RadProto::Packet& packet) for (const auto& attribute : packet.attributes()) { if (attribute->type() == RadProto::USER_NAME) - { login = attribute->toString(); - printfd(__FILE__, "findUser login '%s'\n", login.c_str()); - } if (attribute->type() == RadProto::USER_PASSWORD) - { password = attribute->toString(); - printfd(__FILE__, "findUser password '%s'\n", password.c_str()); - } } if (m_users->FindByName(login, &user)) { - m_logger("User's connect failed: user '%s' not found. %s", login.c_str()); + m_logger("User's connect failed: user '%s' not found.", login.c_str()); printfd(__FILE__, "User '%s' NOT found!\n", login.c_str()); return -1; } - printfd(__FILE__, "findUser FindByName yes\n"); - printfd(__FILE__, "User '%s' FOUND!\n", user->GetLogin().c_str()); if (password != user->GetProperties().password.Get()) From 42c0748c30f31086f6c8ad8f44f707d63d58ce5c Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Wed, 16 Apr 2025 14:51:03 +0300 Subject: [PATCH 074/186] Radius. The using declaration for UserPtr, ConstUserPtr removed. --- projects/stargazer/plugins/other/radius/radius.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.h b/projects/stargazer/plugins/other/radius/radius.h index 0ecd655a..c6ba4297 100644 --- a/projects/stargazer/plugins/other/radius/radius.h +++ b/projects/stargazer/plugins/other/radius/radius.h @@ -20,10 +20,6 @@ namespace STG class Users; - using UserPtr = STG::User*; - using ConstUserPtr = const User*; - - class RAD_SETTINGS { public: From 0173c0b575d4308213245e26fe5baa87a87df149 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Wed, 16 Apr 2025 15:32:44 +0300 Subject: [PATCH 075/186] Radius. Looking for user moved after check request type in the makeResponse function. --- .../stargazer/plugins/other/radius/server.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/server.cpp b/projects/stargazer/plugins/other/radius/server.cpp index 1025b9fc..3e3f635f 100644 --- a/projects/stargazer/plugins/other/radius/server.cpp +++ b/projects/stargazer/plugins/other/radius/server.cpp @@ -51,16 +51,17 @@ RadProto::Packet Server::makeResponse(const RadProto::Packet& request) std::vector vendorValue {0, 0, 0, 3}; vendorSpecific.push_back(RadProto::VendorSpecific(m_dictionaries.vendorCode("Dlink"), m_dictionaries.vendorAttributeCode("Dlink", "Dlink-User-Level"), vendorValue)); - if (findUser(request)) + if (request.type() == RadProto::ACCESS_REQUEST) { - m_logger("Error findUser\n"); - printfd(__FILE__, "Error findUser\n"); - return RadProto::Packet(RadProto::ACCESS_REJECT, request.id(), request.auth(), attributes, vendorSpecific); + if (!findUser(request)) + return RadProto::Packet(RadProto::ACCESS_ACCEPT, request.id(), request.auth(), attributes, vendorSpecific); + else + { + m_logger("Error findUser\n"); + printfd(__FILE__, "Error findUser\n"); + return RadProto::Packet(RadProto::ACCESS_REJECT, request.id(), request.auth(), attributes, vendorSpecific); + } } - - if (request.type() == RadProto::ACCESS_REQUEST) - return RadProto::Packet(RadProto::ACCESS_ACCEPT, request.id(), request.auth(), attributes, vendorSpecific); - return RadProto::Packet(RadProto::ACCESS_REJECT, request.id(), request.auth(), attributes, vendorSpecific); } From 8422222952c17972e693793c2063aa4566c16b79 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Wed, 16 Apr 2025 16:03:45 +0300 Subject: [PATCH 076/186] Radius. The using declaration for UserPtr, ConstUserPtr removed. Header files "stg/user.h", "stg/users.h", "stg/user.property.h" removed. --- projects/stargazer/plugins/other/radius/server.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/server.h b/projects/stargazer/plugins/other/radius/server.h index 5bc0fcbd..e5e5d7c4 100644 --- a/projects/stargazer/plugins/other/radius/server.h +++ b/projects/stargazer/plugins/other/radius/server.h @@ -3,9 +3,6 @@ #include "radproto/socket.h" #include "radproto/packet.h" #include "radproto/dictionaries.h" -#include "stg/users.h" -#include "stg/user.h" -#include "stg/user_property.h" #include "stg/logger.h" #include #include @@ -16,9 +13,6 @@ namespace STG { class Users; - using UserPtr = STG::User*; - using ConstUserPtr = const User*; - class Server { public: From dc8573622876fc9f609673d1118b8b09b7a29d03 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Wed, 16 Apr 2025 16:09:05 +0300 Subject: [PATCH 077/186] Radius. Header files "stg/user.h", "stg/users.h" added. --- projects/stargazer/plugins/other/radius/server.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/projects/stargazer/plugins/other/radius/server.cpp b/projects/stargazer/plugins/other/radius/server.cpp index 3e3f635f..5f00a94b 100644 --- a/projects/stargazer/plugins/other/radius/server.cpp +++ b/projects/stargazer/plugins/other/radius/server.cpp @@ -1,6 +1,8 @@ #include "server.h" #include "radproto/packet_codes.h" #include "radproto/attribute_types.h" +#include "stg/user.h" +#include "stg/users.h" #include "stg/common.h" #include #include From 5ae59eee8fbe36bdaa3dcd91f10db925fede5129 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Wed, 16 Apr 2025 16:17:20 +0300 Subject: [PATCH 078/186] Radius. Function findUser moved to private. --- projects/stargazer/plugins/other/radius/server.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/stargazer/plugins/other/radius/server.h b/projects/stargazer/plugins/other/radius/server.h index e5e5d7c4..7f3da1c7 100644 --- a/projects/stargazer/plugins/other/radius/server.h +++ b/projects/stargazer/plugins/other/radius/server.h @@ -17,10 +17,10 @@ namespace STG { public: Server(boost::asio::io_service& io_service, const std::string& secret, uint16_t port, const std::string& filePath, std::stop_token token, PluginLogger& logger, STG::Users* users); - int findUser(const RadProto::Packet& packet); void stop(); private: RadProto::Packet makeResponse(const RadProto::Packet& request); + int findUser(const RadProto::Packet& packet); void handleReceive(const boost::system::error_code& error, const std::optional& packet, const boost::asio::ip::udp::endpoint& source); void handleSend(const boost::system::error_code& ec); void start(); From cf4f88ccc51a3936c6067526928f0e2645309b27 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Wed, 16 Apr 2025 16:44:14 +0300 Subject: [PATCH 079/186] Radius. Return type of function findUser changed to bool. --- projects/stargazer/plugins/other/radius/server.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/stargazer/plugins/other/radius/server.h b/projects/stargazer/plugins/other/radius/server.h index 7f3da1c7..ad5c5786 100644 --- a/projects/stargazer/plugins/other/radius/server.h +++ b/projects/stargazer/plugins/other/radius/server.h @@ -20,7 +20,7 @@ namespace STG void stop(); private: RadProto::Packet makeResponse(const RadProto::Packet& request); - int findUser(const RadProto::Packet& packet); + bool findUser(const RadProto::Packet& packet); void handleReceive(const boost::system::error_code& error, const std::optional& packet, const boost::asio::ip::udp::endpoint& source); void handleSend(const boost::system::error_code& ec); void start(); From 52714c2da51842aebfdbcaa914064b83696e3089 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Wed, 16 Apr 2025 16:48:02 +0300 Subject: [PATCH 080/186] Radius. Return type of function findUser definition and call changed to bool. --- projects/stargazer/plugins/other/radius/server.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/server.cpp b/projects/stargazer/plugins/other/radius/server.cpp index 5f00a94b..8047470d 100644 --- a/projects/stargazer/plugins/other/radius/server.cpp +++ b/projects/stargazer/plugins/other/radius/server.cpp @@ -55,7 +55,7 @@ RadProto::Packet Server::makeResponse(const RadProto::Packet& request) if (request.type() == RadProto::ACCESS_REQUEST) { - if (!findUser(request)) + if (findUser(request)) return RadProto::Packet(RadProto::ACCESS_ACCEPT, request.id(), request.auth(), attributes, vendorSpecific); else { @@ -101,7 +101,7 @@ void Server::handleReceive(const error_code& error, const std::optionalGetLogin().c_str()); @@ -128,10 +128,10 @@ int Server::findUser(const RadProto::Packet& packet) { m_logger("Password user is incorrect. %s", password.c_str()); printfd(__FILE__, "Password user is incorrect.\n", password.c_str()); - return -1; + return false; } printfd(__FILE__, "User FOUND!\n"); - return 0; + return true; } From e047e611e16d78297655a0a5533a00ddb08293ad Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Thu, 17 Apr 2025 16:51:55 +0300 Subject: [PATCH 081/186] Radius. Variables attributesEmpty, vendorSpecificEmpty added for packet ACCESS_REJECT in the function makeResponse. --- projects/stargazer/plugins/other/radius/server.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/server.cpp b/projects/stargazer/plugins/other/radius/server.cpp index 8047470d..6504f351 100644 --- a/projects/stargazer/plugins/other/radius/server.cpp +++ b/projects/stargazer/plugins/other/radius/server.cpp @@ -53,6 +53,9 @@ RadProto::Packet Server::makeResponse(const RadProto::Packet& request) std::vector vendorValue {0, 0, 0, 3}; vendorSpecific.push_back(RadProto::VendorSpecific(m_dictionaries.vendorCode("Dlink"), m_dictionaries.vendorAttributeCode("Dlink", "Dlink-User-Level"), vendorValue)); + std::vector attributesEmpty; + std::vector vendorSpecificEmpty; + if (request.type() == RadProto::ACCESS_REQUEST) { if (findUser(request)) @@ -61,10 +64,10 @@ RadProto::Packet Server::makeResponse(const RadProto::Packet& request) { m_logger("Error findUser\n"); printfd(__FILE__, "Error findUser\n"); - return RadProto::Packet(RadProto::ACCESS_REJECT, request.id(), request.auth(), attributes, vendorSpecific); + return RadProto::Packet(RadProto::ACCESS_REJECT, request.id(), request.auth(), attributesEmpty, vendorSpecificEmpty); } } - return RadProto::Packet(RadProto::ACCESS_REJECT, request.id(), request.auth(), attributes, vendorSpecific); + return RadProto::Packet(RadProto::ACCESS_REJECT, request.id(), request.auth(), attributesEmpty, vendorSpecificEmpty); } void Server::handleSend(const error_code& ec) From 84ac11e8b71ec3b90733c9a5cbbb50b43da1f5ac Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Mon, 21 Apr 2025 14:44:58 +0300 Subject: [PATCH 082/186] Radius. Type STG::Users* replaced by Users* in parameter users in the constructor Server definition. --- projects/stargazer/plugins/other/radius/server.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/stargazer/plugins/other/radius/server.cpp b/projects/stargazer/plugins/other/radius/server.cpp index 6504f351..9dc37fdf 100644 --- a/projects/stargazer/plugins/other/radius/server.cpp +++ b/projects/stargazer/plugins/other/radius/server.cpp @@ -11,7 +11,7 @@ using STG::Server; using boost::system::error_code; -Server::Server(boost::asio::io_service& io_service, const std::string& secret, uint16_t port, const std::string& filePath, std::stop_token token, PluginLogger& logger, STG::Users* users) +Server::Server(boost::asio::io_service& io_service, const std::string& secret, uint16_t port, const std::string& filePath, std::stop_token token, PluginLogger& logger, Users* users) : m_radius(io_service, secret, port), m_dictionaries(filePath), m_users(users), From 37b47b29f767680f27fd3850506cddff7d597a8b Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Mon, 21 Apr 2025 15:15:30 +0300 Subject: [PATCH 083/186] Radius. Condition and code order changed when packet is returned in makeResponse function. --- .../stargazer/plugins/other/radius/server.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/server.cpp b/projects/stargazer/plugins/other/radius/server.cpp index 9dc37fdf..ebf0c25f 100644 --- a/projects/stargazer/plugins/other/radius/server.cpp +++ b/projects/stargazer/plugins/other/radius/server.cpp @@ -56,17 +56,14 @@ RadProto::Packet Server::makeResponse(const RadProto::Packet& request) std::vector attributesEmpty; std::vector vendorSpecificEmpty; - if (request.type() == RadProto::ACCESS_REQUEST) - { - if (findUser(request)) - return RadProto::Packet(RadProto::ACCESS_ACCEPT, request.id(), request.auth(), attributes, vendorSpecific); - else - { - m_logger("Error findUser\n"); - printfd(__FILE__, "Error findUser\n"); - return RadProto::Packet(RadProto::ACCESS_REJECT, request.id(), request.auth(), attributesEmpty, vendorSpecificEmpty); - } - } + if (request.type() != RadProto::ACCESS_REQUEST) + return RadProto::Packet(RadProto::ACCESS_REJECT, request.id(), request.auth(), attributesEmpty, vendorSpecificEmpty); + + if (findUser(request)) + return RadProto::Packet(RadProto::ACCESS_ACCEPT, request.id(), request.auth(), attributes, vendorSpecific); + + m_logger("Error findUser\n"); + printfd(__FILE__, "Error findUser\n"); return RadProto::Packet(RadProto::ACCESS_REJECT, request.id(), request.auth(), attributesEmpty, vendorSpecificEmpty); } From da54173f1e43f14e713df77eedc26b2a1b7cbc70 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Mon, 21 Apr 2025 15:29:50 +0300 Subject: [PATCH 084/186] Radius. Unnecessary variables attributeEmpty, vendorSpecificEmpty replaced by {} when ACCESS_REJECT packet is returned in makeResponse function. --- projects/stargazer/plugins/other/radius/server.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/server.cpp b/projects/stargazer/plugins/other/radius/server.cpp index ebf0c25f..d0629201 100644 --- a/projects/stargazer/plugins/other/radius/server.cpp +++ b/projects/stargazer/plugins/other/radius/server.cpp @@ -53,18 +53,15 @@ RadProto::Packet Server::makeResponse(const RadProto::Packet& request) std::vector vendorValue {0, 0, 0, 3}; vendorSpecific.push_back(RadProto::VendorSpecific(m_dictionaries.vendorCode("Dlink"), m_dictionaries.vendorAttributeCode("Dlink", "Dlink-User-Level"), vendorValue)); - std::vector attributesEmpty; - std::vector vendorSpecificEmpty; - if (request.type() != RadProto::ACCESS_REQUEST) - return RadProto::Packet(RadProto::ACCESS_REJECT, request.id(), request.auth(), attributesEmpty, vendorSpecificEmpty); + return RadProto::Packet(RadProto::ACCESS_REJECT, request.id(), request.auth(), {}, {}); if (findUser(request)) return RadProto::Packet(RadProto::ACCESS_ACCEPT, request.id(), request.auth(), attributes, vendorSpecific); m_logger("Error findUser\n"); printfd(__FILE__, "Error findUser\n"); - return RadProto::Packet(RadProto::ACCESS_REJECT, request.id(), request.auth(), attributesEmpty, vendorSpecificEmpty); + return RadProto::Packet(RadProto::ACCESS_REJECT, request.id(), request.auth(), {}, {}); } void Server::handleSend(const error_code& ec) From 5e03dd0e7112b15935caa55a80f855eb5da15ab1 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Mon, 21 Apr 2025 16:00:58 +0300 Subject: [PATCH 085/186] Radius. Prefix STG of user object removed, user is initialized by nullptr and moved to the point before call FindByName function in the findUser function. --- projects/stargazer/plugins/other/radius/server.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/stargazer/plugins/other/radius/server.cpp b/projects/stargazer/plugins/other/radius/server.cpp index d0629201..a6379ec3 100644 --- a/projects/stargazer/plugins/other/radius/server.cpp +++ b/projects/stargazer/plugins/other/radius/server.cpp @@ -100,7 +100,6 @@ void Server::handleReceive(const error_code& error, const std::optionaltoString(); } + User* user(nullptr); if (m_users->FindByName(login, &user)) { m_logger("User's connect failed: user '%s' not found.", login.c_str()); From a12adbdc652325a07a150a0fb72572c60136521b Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Mon, 21 Apr 2025 16:08:39 +0300 Subject: [PATCH 086/186] Radius. Extra printfd function call removed in the function findUser. --- projects/stargazer/plugins/other/radius/server.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/server.cpp b/projects/stargazer/plugins/other/radius/server.cpp index a6379ec3..ce7ae81a 100644 --- a/projects/stargazer/plugins/other/radius/server.cpp +++ b/projects/stargazer/plugins/other/radius/server.cpp @@ -127,8 +127,5 @@ bool Server::findUser(const RadProto::Packet& packet) printfd(__FILE__, "Password user is incorrect.\n", password.c_str()); return false; } - - printfd(__FILE__, "User FOUND!\n"); - return true; } From 15ff9374ab9dc792d9f849be95abb11f86d44bf9 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Tue, 22 Apr 2025 14:30:12 +0300 Subject: [PATCH 087/186] Radius. The way of initializing the object user changed in the findUser function. Error log removed in the makeResponse function. --- projects/stargazer/plugins/other/radius/server.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/server.cpp b/projects/stargazer/plugins/other/radius/server.cpp index ce7ae81a..43768713 100644 --- a/projects/stargazer/plugins/other/radius/server.cpp +++ b/projects/stargazer/plugins/other/radius/server.cpp @@ -59,7 +59,6 @@ RadProto::Packet Server::makeResponse(const RadProto::Packet& request) if (findUser(request)) return RadProto::Packet(RadProto::ACCESS_ACCEPT, request.id(), request.auth(), attributes, vendorSpecific); - m_logger("Error findUser\n"); printfd(__FILE__, "Error findUser\n"); return RadProto::Packet(RadProto::ACCESS_REJECT, request.id(), request.auth(), {}, {}); } @@ -111,7 +110,7 @@ bool Server::findUser(const RadProto::Packet& packet) password = attribute->toString(); } - User* user(nullptr); + User* user = nullptr; if (m_users->FindByName(login, &user)) { m_logger("User's connect failed: user '%s' not found.", login.c_str()); From 92e202f683534cc5a125ef381f31601e6af3b082 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Tue, 22 Apr 2025 14:39:40 +0300 Subject: [PATCH 088/186] Radius. Prefix STG of class member m_users and of parameter u in SetUsers function removed. --- projects/stargazer/plugins/other/radius/radius.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.h b/projects/stargazer/plugins/other/radius/radius.h index c6ba4297..17f8ea4e 100644 --- a/projects/stargazer/plugins/other/radius/radius.h +++ b/projects/stargazer/plugins/other/radius/radius.h @@ -46,7 +46,7 @@ namespace STG RADIUS(const RADIUS&) = delete; RADIUS& operator=(const RADIUS&) = delete; - void SetUsers(STG::Users* u) { m_users = u; } + void SetUsers(Users* u) { m_users = u; } void SetSettings(const ModuleSettings & s) override { m_settings = s; } int ParseSettings() override; @@ -77,7 +77,7 @@ namespace STG bool m_running; std::jthread m_thread; - STG::Users* m_users; + Users* m_users; PluginLogger m_logger; std::unique_ptr m_server; From f6eb048062d1c153b01d03a9a0576fc6d318d668 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Tue, 22 Apr 2025 14:55:56 +0300 Subject: [PATCH 089/186] Radius. Prefix STG of class member m_users and of parameter users in the constructor Server declaration removed. --- projects/stargazer/plugins/other/radius/server.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/server.h b/projects/stargazer/plugins/other/radius/server.h index ad5c5786..7abcff3d 100644 --- a/projects/stargazer/plugins/other/radius/server.h +++ b/projects/stargazer/plugins/other/radius/server.h @@ -16,7 +16,7 @@ namespace STG class Server { public: - Server(boost::asio::io_service& io_service, const std::string& secret, uint16_t port, const std::string& filePath, std::stop_token token, PluginLogger& logger, STG::Users* users); + Server(boost::asio::io_service& io_service, const std::string& secret, uint16_t port, const std::string& filePath, std::stop_token token, PluginLogger& logger, Users* users); void stop(); private: RadProto::Packet makeResponse(const RadProto::Packet& request); @@ -28,7 +28,7 @@ namespace STG RadProto::Socket m_radius; RadProto::Dictionaries m_dictionaries; - STG::Users* m_users; + Users* m_users; std::stop_token m_token; PluginLogger& m_logger; From ba3ad7b9bfe963a5833e7625ec6ef8144024d8fe Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Tue, 22 Apr 2025 15:33:46 +0300 Subject: [PATCH 090/186] Radius. The messages of m_logger and printfd changed in function findUser. --- projects/stargazer/plugins/other/radius/server.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/server.cpp b/projects/stargazer/plugins/other/radius/server.cpp index 43768713..375fcd69 100644 --- a/projects/stargazer/plugins/other/radius/server.cpp +++ b/projects/stargazer/plugins/other/radius/server.cpp @@ -113,7 +113,7 @@ bool Server::findUser(const RadProto::Packet& packet) User* user = nullptr; if (m_users->FindByName(login, &user)) { - m_logger("User's connect failed: user '%s' not found.", login.c_str()); + m_logger("User '%s' not found.", login.c_str()); printfd(__FILE__, "User '%s' NOT found!\n", login.c_str()); return false; } @@ -122,8 +122,8 @@ bool Server::findUser(const RadProto::Packet& packet) if (password != user->GetProperties().password.Get()) { - m_logger("Password user is incorrect. %s", password.c_str()); - printfd(__FILE__, "Password user is incorrect.\n", password.c_str()); + m_logger("User's password is incorrect. %s", password.c_str()); + printfd(__FILE__, "User's password is incorrect.\n", password.c_str()); return false; } return true; From 3ea9d0a14ee6b479ce0ddf70c8f9a470bba7b30d Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Wed, 30 Apr 2025 16:11:28 +0300 Subject: [PATCH 091/186] Radius. Search for parameters auth and send added to the ParseSettings function. --- .../stargazer/plugins/other/radius/radius.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index c93c4ddf..3c87aaa1 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -46,14 +46,27 @@ int RAD_SETTINGS::ParseSettings(const ModuleSettings & s) 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]; + + pv.param = "auth"; + pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv); + if (pvi != s.moduleParams.end() ) + { + pv.param = "send"; + std::string sendValue; + std::vector sectionsParams = pvi->sections; + auto pva = std::find(sectionsParams.begin(), sectionsParams.end(), pv); + if (pva != sectionsParams.end() && !pva->value.empty()) + { + sendValue = pva->value[0]; + printfd(__FILE__, "ParseSettings Value of send: '%s'\n", sendValue.c_str()); + } + } return 0; } From 0db49003f4bdd387e356df25bc93ec45285258ad Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Fri, 2 May 2025 16:27:30 +0300 Subject: [PATCH 092/186] Radius. Extra whitespace removed, unnecessary variables sendValue and sectionsParams removed in ParseSettings function. --- projects/stargazer/plugins/other/radius/radius.cpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 3c87aaa1..61e1d375 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -55,17 +55,12 @@ int RAD_SETTINGS::ParseSettings(const ModuleSettings & s) pv.param = "auth"; pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv); - if (pvi != s.moduleParams.end() ) + if (pvi != s.moduleParams.end()) { pv.param = "send"; - std::string sendValue; - std::vector sectionsParams = pvi->sections; - auto pva = std::find(sectionsParams.begin(), sectionsParams.end(), pv); - if (pva != sectionsParams.end() && !pva->value.empty()) - { - sendValue = pva->value[0]; - printfd(__FILE__, "ParseSettings Value of send: '%s'\n", sendValue.c_str()); - } + auto pva = std::find(pvi->sections.begin(), pvi->sections.end(), pv); + if (pva != pvi->sections.end() && !pva->value.empty()) + printfd(__FILE__, "ParseSettings Value of send: '%s'\n", pva->value[0].c_str()); } return 0; } From e2c502788423441ee3dcfb4d5e5fcc97a4178636 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Wed, 14 May 2025 18:03:50 +0300 Subject: [PATCH 093/186] Radius. The struct AttrValue added. --- projects/stargazer/plugins/other/radius/radius.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/projects/stargazer/plugins/other/radius/radius.h b/projects/stargazer/plugins/other/radius/radius.h index 17f8ea4e..fb9a23eb 100644 --- a/projects/stargazer/plugins/other/radius/radius.h +++ b/projects/stargazer/plugins/other/radius/radius.h @@ -20,11 +20,23 @@ namespace STG class Users; + struct AttrValue + { + enum class Sign + { + NO, + IS + }; + std::string value; + Sign sign; + }; + class RAD_SETTINGS { public: RAD_SETTINGS(); virtual ~RAD_SETTINGS() {} + const std::string & GetStrError() const { return m_errorStr; } int ParseSettings(const ModuleSettings & s); From ae2a0683dbb8390f77e269859cd042ae34c18d69 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Wed, 14 May 2025 18:15:47 +0300 Subject: [PATCH 094/186] Radius. Header files , , added. Parsing attributes of field send in section auth of mod_radius.conf added to the function ParseSettings. --- .../stargazer/plugins/other/radius/radius.cpp | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 61e1d375..a0ec2c00 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -1,7 +1,10 @@ #include "radius.h" #include "radproto/error.h" #include "stg/common.h" +#include +#include +#include #include #include @@ -61,6 +64,62 @@ int RAD_SETTINGS::ParseSettings(const ModuleSettings & s) auto pva = std::find(pvi->sections.begin(), pvi->sections.end(), pv); if (pva != pvi->sections.end() && !pva->value.empty()) printfd(__FILE__, "ParseSettings Value of send: '%s'\n", pva->value[0].c_str()); + + using tokenizer = boost::tokenizer>; + boost::char_separator sep(","); + + tokenizer tokens(pva->value[0], sep); + + for (const auto& token : tokens) + { + printfd(__FILE__, "Tok: '%s'\n", token.c_str()); + boost::char_separator sp(" ="); + tokenizer tok(token, sp); + + std::vector attribute; + for (const auto& t : tok) + { + printfd(__FILE__, "T: '%s'\n", t.c_str()); + attribute.push_back(t); + } + + if (!attribute.empty()) + { + std::string key = attribute[0]; + printfd(__FILE__, "T attr key: '%s'\n", attribute[0].c_str()); + + std::string valueName = attribute[1]; + printfd(__FILE__, "T attr value: '%s'\n", attribute[1].c_str()); + + AttrValue attrValue; + std::vector> attrSend; + + if (valueName[0] == '\'') + { + valueName.erase(0, 1); + valueName.erase(valueName.length() - 1, 1); + + attrValue.value = valueName; + attrValue.sign = AttrValue::Sign::IS; + + attrSend.emplace_back(key, attrValue); + + printfd(__FILE__, "Key: '%s'\n", key.c_str()); + printfd(__FILE__, "Value: '%s'\n", valueName.c_str()); + } + else + { + attrValue.value = valueName; + attrValue.sign = AttrValue::Sign::NO; + + attrSend.emplace_back(key, attrValue); + + printfd(__FILE__, "No \'\n"); + printfd(__FILE__, "Key: '%s'\n", key.c_str()); + printfd(__FILE__, "Value: '%s'\n", valueName.c_str()); + } + } + } } return 0; } From 967321f921c42faf0730c047ed68ec0c58d15cbc Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Thu, 15 May 2025 16:01:02 +0300 Subject: [PATCH 095/186] Radius. Filling vector of pairs attrSend added. Extra printfd function removed. --- .../stargazer/plugins/other/radius/radius.cpp | 78 ++++++++----------- 1 file changed, 33 insertions(+), 45 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index a0ec2c00..9feb964e 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -63,62 +63,50 @@ int RAD_SETTINGS::ParseSettings(const ModuleSettings & s) pv.param = "send"; auto pva = std::find(pvi->sections.begin(), pvi->sections.end(), pv); if (pva != pvi->sections.end() && !pva->value.empty()) + { printfd(__FILE__, "ParseSettings Value of send: '%s'\n", pva->value[0].c_str()); - using tokenizer = boost::tokenizer>; - boost::char_separator sep(","); + using tokenizer = boost::tokenizer>; + boost::char_separator sep(","); - tokenizer tokens(pva->value[0], sep); + tokenizer tokens(pva->value[0], sep); - for (const auto& token : tokens) - { - printfd(__FILE__, "Tok: '%s'\n", token.c_str()); - boost::char_separator sp(" ="); - tokenizer tok(token, sp); + AttrValue attrValue; + std::vector> attrSend; - std::vector attribute; - for (const auto& t : tok) + for (const auto& token : tokens) { - printfd(__FILE__, "T: '%s'\n", t.c_str()); - attribute.push_back(t); - } + boost::char_separator sp(" ="); + tokenizer tok(token, sp); - if (!attribute.empty()) - { - std::string key = attribute[0]; - printfd(__FILE__, "T attr key: '%s'\n", attribute[0].c_str()); + std::vector attribute; + for (const auto& t : tok) + attribute.push_back(t); - std::string valueName = attribute[1]; - printfd(__FILE__, "T attr value: '%s'\n", attribute[1].c_str()); - - AttrValue attrValue; - std::vector> attrSend; - - if (valueName[0] == '\'') + if (!attribute.empty()) { - valueName.erase(0, 1); - valueName.erase(valueName.length() - 1, 1); - - attrValue.value = valueName; - attrValue.sign = AttrValue::Sign::IS; - - attrSend.emplace_back(key, attrValue); - - printfd(__FILE__, "Key: '%s'\n", key.c_str()); - printfd(__FILE__, "Value: '%s'\n", valueName.c_str()); - } - else - { - attrValue.value = valueName; - attrValue.sign = AttrValue::Sign::NO; - - attrSend.emplace_back(key, attrValue); - - printfd(__FILE__, "No \'\n"); - printfd(__FILE__, "Key: '%s'\n", key.c_str()); - printfd(__FILE__, "Value: '%s'\n", valueName.c_str()); + std::string key = attribute[0]; + std::string valueName = attribute[1]; + + if (valueName[0] == '\'') + { + valueName.erase(0, 1); + valueName.erase(valueName.length() - 1, 1); + + attrValue.value = valueName; + attrValue.sign = AttrValue::Sign::IS; + attrSend.emplace_back(key, attrValue); + } + else + { + attrValue.value = valueName; + attrValue.sign = AttrValue::Sign::NO; + attrSend.emplace_back(key, attrValue); + } } } + for (const auto& at : attrSend) + printfd(__FILE__, "Key: '%s', Value: '%s', Sign: %d\n", at.first.c_str(), at.second.value.c_str(), at.second.sign); } } return 0; From cd918e522cc17e3de5de405dd9d8f094cfe7756e Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Mon, 19 May 2025 19:17:12 +0300 Subject: [PATCH 096/186] Radius. The Sign enumeration elements names changed in the struct AttrValue. --- projects/stargazer/plugins/other/radius/radius.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.h b/projects/stargazer/plugins/other/radius/radius.h index fb9a23eb..b75dab15 100644 --- a/projects/stargazer/plugins/other/radius/radius.h +++ b/projects/stargazer/plugins/other/radius/radius.h @@ -24,8 +24,8 @@ namespace STG { enum class Sign { - NO, - IS + NOT_VALUE, + IS_VALUE }; std::string value; Sign sign; From 43d4001308d0a9ae776362f7a13d78cdda9e1f03 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Mon, 19 May 2025 19:24:41 +0300 Subject: [PATCH 097/186] Radius. Using declaration for struct AttrValue added. Function ParseSendAttr definition added and call in the function ParseSettings added. --- .../stargazer/plugins/other/radius/radius.cpp | 85 ++++++++++--------- 1 file changed, 45 insertions(+), 40 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 9feb964e..a92a3431 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -10,6 +10,7 @@ using STG::RADIUS; using STG::RAD_SETTINGS; +using STG::AttrValue; extern "C" STG::Plugin* GetPlugin() { @@ -17,6 +18,47 @@ extern "C" STG::Plugin* GetPlugin() return &plugin; } +std::vector> ParseSendAttr(std::string fieldSendAttr) +{ + using tokenizer = boost::tokenizer>; + boost::char_separator sep(","); + + tokenizer tokens(fieldSendAttr, sep); + + AttrValue attrValue; + std::vector> keyValuePairs; + + for (const auto& token : tokens) + { + boost::char_separator sp(" ="); + tokenizer tok(token, sp); + + std::vector parsedSendAttr; + for (const auto& t : tok) + parsedSendAttr.push_back(t); + + std::string key = parsedSendAttr[0]; + std::string valueName = parsedSendAttr[1]; + + if (valueName[0] == '\'') + { + valueName.erase(0, 1); + valueName.erase(valueName.length() - 1, 1); + + attrValue.value = valueName; + attrValue.sign = AttrValue::Sign::IS_VALUE; + keyValuePairs.emplace_back(key, attrValue); + } + else + { + attrValue.value = valueName; + attrValue.sign = AttrValue::Sign::NOT_VALUE; + keyValuePairs.emplace_back(key, attrValue); + } + } + return keyValuePairs; +} + RAD_SETTINGS::RAD_SETTINGS() : m_port(1812), m_dictionaries("/usr/share/freeradius/dictionary") @@ -66,46 +108,9 @@ int RAD_SETTINGS::ParseSettings(const ModuleSettings & s) { printfd(__FILE__, "ParseSettings Value of send: '%s'\n", pva->value[0].c_str()); - using tokenizer = boost::tokenizer>; - boost::char_separator sep(","); - - tokenizer tokens(pva->value[0], sep); - - AttrValue attrValue; - std::vector> attrSend; - - for (const auto& token : tokens) - { - boost::char_separator sp(" ="); - tokenizer tok(token, sp); - - std::vector attribute; - for (const auto& t : tok) - attribute.push_back(t); - - if (!attribute.empty()) - { - std::string key = attribute[0]; - std::string valueName = attribute[1]; - - if (valueName[0] == '\'') - { - valueName.erase(0, 1); - valueName.erase(valueName.length() - 1, 1); - - attrValue.value = valueName; - attrValue.sign = AttrValue::Sign::IS; - attrSend.emplace_back(key, attrValue); - } - else - { - attrValue.value = valueName; - attrValue.sign = AttrValue::Sign::NO; - attrSend.emplace_back(key, attrValue); - } - } - } - for (const auto& at : attrSend) + std::vector> keyValuePairs = ParseSendAttr(pva->value[0]); + + for (const auto& at : keyValuePairs) printfd(__FILE__, "Key: '%s', Value: '%s', Sign: %d\n", at.first.c_str(), at.second.value.c_str(), at.second.sign); } } From 023dbb416c744b3fbfd0cffcd0fcd2a9123a6a12 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Tue, 20 May 2025 15:24:22 +0300 Subject: [PATCH 098/186] Radius. The enum class Sign renamed to Type, object sign renamed to type. --- projects/stargazer/plugins/other/radius/radius.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.h b/projects/stargazer/plugins/other/radius/radius.h index b75dab15..12c9f12c 100644 --- a/projects/stargazer/plugins/other/radius/radius.h +++ b/projects/stargazer/plugins/other/radius/radius.h @@ -22,13 +22,13 @@ namespace STG struct AttrValue { - enum class Sign + enum class Type { NOT_VALUE, IS_VALUE }; std::string value; - Sign sign; + Type type; }; class RAD_SETTINGS From c8bd692309f9337394ab0e04c9b94bc2711edd49 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Tue, 20 May 2025 15:25:50 +0300 Subject: [PATCH 099/186] Radius. The enum class Sign renamed to Type, object sign renamed to type in ParseSendAttr function and ParseSettings function. --- projects/stargazer/plugins/other/radius/radius.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index a92a3431..9f80d380 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -46,13 +46,13 @@ std::vector> ParseSendAttr(std::string fieldSe valueName.erase(valueName.length() - 1, 1); attrValue.value = valueName; - attrValue.sign = AttrValue::Sign::IS_VALUE; + attrValue.type = AttrValue::Type::IS_VALUE; keyValuePairs.emplace_back(key, attrValue); } else { attrValue.value = valueName; - attrValue.sign = AttrValue::Sign::NOT_VALUE; + attrValue.type = AttrValue::Type::NOT_VALUE; keyValuePairs.emplace_back(key, attrValue); } } @@ -111,7 +111,7 @@ int RAD_SETTINGS::ParseSettings(const ModuleSettings & s) std::vector> keyValuePairs = ParseSendAttr(pva->value[0]); for (const auto& at : keyValuePairs) - printfd(__FILE__, "Key: '%s', Value: '%s', Sign: %d\n", at.first.c_str(), at.second.value.c_str(), at.second.sign); + printfd(__FILE__, "Key: '%s', Value: '%s', Type: %d\n", at.first.c_str(), at.second.value.c_str(), at.second.type); } } return 0; From 0e1f6fe112feef4cdcc463682fd410c956844432 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Tue, 20 May 2025 15:52:00 +0300 Subject: [PATCH 100/186] Radius. The enumerator names NOT_VALUE changed to PARAN_NAME, IS_VALUE changed to VALUE in enum Type. --- projects/stargazer/plugins/other/radius/radius.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.h b/projects/stargazer/plugins/other/radius/radius.h index 12c9f12c..4c7bc1f2 100644 --- a/projects/stargazer/plugins/other/radius/radius.h +++ b/projects/stargazer/plugins/other/radius/radius.h @@ -24,8 +24,8 @@ namespace STG { enum class Type { - NOT_VALUE, - IS_VALUE + PARAM_NAME, + VALUE }; std::string value; Type type; From 218b6d74b20dc6976d751058792cd0af95b22633 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Tue, 20 May 2025 15:55:08 +0300 Subject: [PATCH 101/186] Radius. Radius. The enumerator names NOT_VALUE changed to PARAM_NAME, IS_VALUE changed to VALUE in ParseSendAttr function. --- projects/stargazer/plugins/other/radius/radius.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 9f80d380..9fc780e7 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -46,13 +46,13 @@ std::vector> ParseSendAttr(std::string fieldSe valueName.erase(valueName.length() - 1, 1); attrValue.value = valueName; - attrValue.type = AttrValue::Type::IS_VALUE; + attrValue.type = AttrValue::Type::VALUE; keyValuePairs.emplace_back(key, attrValue); } else { attrValue.value = valueName; - attrValue.type = AttrValue::Type::NOT_VALUE; + attrValue.type = AttrValue::Type::PARAM_NAME; keyValuePairs.emplace_back(key, attrValue); } } From 534d79ba42f7569eb9903cf754861b2e991248d1 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Tue, 20 May 2025 18:17:55 +0300 Subject: [PATCH 102/186] Radius. The AttrValue struct moved into the RAD_SETTINGS class. --- .../stargazer/plugins/other/radius/radius.h | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.h b/projects/stargazer/plugins/other/radius/radius.h index 4c7bc1f2..88ef9bda 100644 --- a/projects/stargazer/plugins/other/radius/radius.h +++ b/projects/stargazer/plugins/other/radius/radius.h @@ -20,23 +20,23 @@ namespace STG class Users; - struct AttrValue - { - enum class Type - { - PARAM_NAME, - VALUE - }; - std::string value; - Type type; - }; - class RAD_SETTINGS { public: RAD_SETTINGS(); virtual ~RAD_SETTINGS() {} + struct AttrValue + { + enum class Type + { + PARAM_NAME, + VALUE + }; + std::string value; + Type type; + }; + const std::string & GetStrError() const { return m_errorStr; } int ParseSettings(const ModuleSettings & s); From 322595260429c4521a0fd2095630bee387e5fe3f Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Tue, 20 May 2025 18:22:10 +0300 Subject: [PATCH 103/186] Radius. The using statement for struct AttrValue removed. The using alias for struct AttrValue added. --- projects/stargazer/plugins/other/radius/radius.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 9fc780e7..30a13fbb 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -10,7 +10,7 @@ using STG::RADIUS; using STG::RAD_SETTINGS; -using STG::AttrValue; +using AttrValue = RAD_SETTINGS::AttrValue; extern "C" STG::Plugin* GetPlugin() { From ce267835388256039fc6179b8f14ea5dfe0b688f Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Wed, 21 May 2025 15:34:36 +0300 Subject: [PATCH 104/186] Radius. The vector parsedSendAttr check added to the function ParseSendAttr. --- .../stargazer/plugins/other/radius/radius.cpp | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 30a13fbb..77b1bac5 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -37,23 +37,26 @@ std::vector> ParseSendAttr(std::string fieldSe for (const auto& t : tok) parsedSendAttr.push_back(t); - std::string key = parsedSendAttr[0]; - std::string valueName = parsedSendAttr[1]; - - if (valueName[0] == '\'') - { - valueName.erase(0, 1); - valueName.erase(valueName.length() - 1, 1); - - attrValue.value = valueName; - attrValue.type = AttrValue::Type::VALUE; - keyValuePairs.emplace_back(key, attrValue); - } - else + if (!parsedSendAttr.empty()) { - attrValue.value = valueName; - attrValue.type = AttrValue::Type::PARAM_NAME; - keyValuePairs.emplace_back(key, attrValue); + std::string key = parsedSendAttr[0]; + std::string valueName = parsedSendAttr[1]; + + if (valueName[0] == '\'') + { + valueName.erase(0, 1); + valueName.erase(valueName.length() - 1, 1); + + attrValue.value = valueName; + attrValue.type = AttrValue::Type::VALUE; + keyValuePairs.emplace_back(key, attrValue); + } + else + { + attrValue.value = valueName; + attrValue.type = AttrValue::Type::PARAM_NAME; + keyValuePairs.emplace_back(key, attrValue); + } } } return keyValuePairs; From 7b1bbb5b28c7304b520d49e2952c01f550069140 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Thu, 22 May 2025 18:25:54 +0300 Subject: [PATCH 105/186] Radius. The ParseSendAttr method added, m_logger variable class member added to RAD_SETTINGS class. --- projects/stargazer/plugins/other/radius/radius.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/projects/stargazer/plugins/other/radius/radius.h b/projects/stargazer/plugins/other/radius/radius.h index 88ef9bda..1dfeba04 100644 --- a/projects/stargazer/plugins/other/radius/radius.h +++ b/projects/stargazer/plugins/other/radius/radius.h @@ -39,6 +39,7 @@ namespace STG const std::string & GetStrError() const { return m_errorStr; } int ParseSettings(const ModuleSettings & s); + std::vector> ParseSendAttr(std::string fieldSendAttr); uint16_t GetPort() const { return m_port; } const std::string & GetDictionaries() const { return m_dictionaries; } @@ -49,6 +50,7 @@ namespace STG uint16_t m_port; std::string m_dictionaries; std::string m_secret; + PluginLogger m_logger; }; class RADIUS : public Auth From 15c5a1ff3dfdb745316f22338888fe170aaf4cb4 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Thu, 22 May 2025 18:36:04 +0300 Subject: [PATCH 106/186] Radius. ParseSendAttr function changed to method of RAD_SETTINGS class. Vector parsedSendAttr check for emptiness and check vector size added to the ParseSendAttr method. Class member m_logger initialization added to initialization list to RAD_SETTINGS constructor. --- .../stargazer/plugins/other/radius/radius.cpp | 54 +++++++++++-------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 77b1bac5..9942231d 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -18,7 +18,7 @@ extern "C" STG::Plugin* GetPlugin() return &plugin; } -std::vector> ParseSendAttr(std::string fieldSendAttr) +std::vector> RAD_SETTINGS::ParseSendAttr(std::string fieldSendAttr) { using tokenizer = boost::tokenizer>; boost::char_separator sep(","); @@ -37,26 +37,37 @@ std::vector> ParseSendAttr(std::string fieldSe for (const auto& t : tok) parsedSendAttr.push_back(t); - if (!parsedSendAttr.empty()) + if (parsedSendAttr.empty()) { - std::string key = parsedSendAttr[0]; - std::string valueName = parsedSendAttr[1]; - - if (valueName[0] == '\'') - { - valueName.erase(0, 1); - valueName.erase(valueName.length() - 1, 1); - - attrValue.value = valueName; - attrValue.type = AttrValue::Type::VALUE; - keyValuePairs.emplace_back(key, attrValue); - } - else - { - attrValue.value = valueName; - attrValue.type = AttrValue::Type::PARAM_NAME; - keyValuePairs.emplace_back(key, attrValue); - } + m_logger("Error ParseSendAttr: send parameter attribute is missing.\n"); + printfd(__FILE__, "Error ParseSendAttr: send parameter attribute is missing.\n"); + return keyValuePairs; + } + + if (parsedSendAttr.size() < 2) + { + m_logger("Error ParseSendAttr: send parameter attribute is invalid.\n"); + printfd(__FILE__, "Error ParseSendAttr: send parameter attribute is invalid.\n"); + return keyValuePairs; + } + + std::string key = parsedSendAttr[0]; + std::string valueName = parsedSendAttr[1]; + + if (valueName[0] == '\'') + { + valueName.erase(0, 1); + valueName.erase(valueName.length() - 1, 1); + + attrValue.value = valueName; + attrValue.type = AttrValue::Type::VALUE; + keyValuePairs.emplace_back(key, attrValue); + } + else + { + attrValue.value = valueName; + attrValue.type = AttrValue::Type::PARAM_NAME; + keyValuePairs.emplace_back(key, attrValue); } } return keyValuePairs; @@ -64,7 +75,8 @@ std::vector> ParseSendAttr(std::string fieldSe RAD_SETTINGS::RAD_SETTINGS() : m_port(1812), - m_dictionaries("/usr/share/freeradius/dictionary") + m_dictionaries("/usr/share/freeradius/dictionary"), + m_logger(PluginLogger::get("radius")) {} int RAD_SETTINGS::ParseSettings(const ModuleSettings & s) From 154edc341c69a20dc0e7cc42c61ede7453ba06f2 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Fri, 23 May 2025 18:04:00 +0300 Subject: [PATCH 107/186] Radius. Quotes check for the ValueName added to the ParseSendAttr method. --- projects/stargazer/plugins/other/radius/radius.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 9942231d..f311f168 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -54,7 +54,7 @@ std::vector> RAD_SETTINGS::ParseSendAttr(std:: std::string key = parsedSendAttr[0]; std::string valueName = parsedSendAttr[1]; - if (valueName[0] == '\'') + if (valueName[0] == '\'' && valueName[valueName.length() - 1] == '\'') { valueName.erase(0, 1); valueName.erase(valueName.length() - 1, 1); @@ -63,12 +63,18 @@ std::vector> RAD_SETTINGS::ParseSendAttr(std:: attrValue.type = AttrValue::Type::VALUE; keyValuePairs.emplace_back(key, attrValue); } - else + else if (valueName[0] != '\'' && valueName[valueName.length() - 1] != '\'') { attrValue.value = valueName; attrValue.type = AttrValue::Type::PARAM_NAME; keyValuePairs.emplace_back(key, attrValue); } + else + { + m_logger("Error ParseSendAttr: send parameter attribute value is invalid.\n"); + printfd(__FILE__, "Error ParseSendAttr: send parameter attribute value is invalid.\n"); + return keyValuePairs; + } } return keyValuePairs; } From b5e9b4f10600679d1d9dbbca35cde2569b59970f Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Fri, 23 May 2025 18:33:57 +0300 Subject: [PATCH 108/186] Radius. Extra variables attrValue.value and attrValue.type removed in the ParseSendAttr method. --- projects/stargazer/plugins/other/radius/radius.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index f311f168..7657c7d3 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -59,16 +59,10 @@ std::vector> RAD_SETTINGS::ParseSendAttr(std:: valueName.erase(0, 1); valueName.erase(valueName.length() - 1, 1); - attrValue.value = valueName; - attrValue.type = AttrValue::Type::VALUE; - keyValuePairs.emplace_back(key, attrValue); + keyValuePairs.emplace_back(key, AttrValue{valueName, AttrValue::Type::VALUE}); } else if (valueName[0] != '\'' && valueName[valueName.length() - 1] != '\'') - { - attrValue.value = valueName; - attrValue.type = AttrValue::Type::PARAM_NAME; - keyValuePairs.emplace_back(key, attrValue); - } + keyValuePairs.emplace_back(key, AttrValue{valueName, AttrValue::Type::PARAM_NAME}); else { m_logger("Error ParseSendAttr: send parameter attribute value is invalid.\n"); From 233bd641f91627788d40e7f209d8cf8bb02fe2ab Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Mon, 26 May 2025 14:40:06 +0300 Subject: [PATCH 109/186] Radius. Extra variable attrValue removed in ParseSendAttr method. --- projects/stargazer/plugins/other/radius/radius.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 7657c7d3..22720ce3 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -25,7 +25,6 @@ std::vector> RAD_SETTINGS::ParseSendAttr(std:: tokenizer tokens(fieldSendAttr, sep); - AttrValue attrValue; std::vector> keyValuePairs; for (const auto& token : tokens) From f24d0628aff81b2b22709cb11eeb70c2c2b9c6fa Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Mon, 26 May 2025 17:00:05 +0300 Subject: [PATCH 110/186] Radius. Send attributes parsing changed in method ParseSendAttr. --- .../stargazer/plugins/other/radius/radius.cpp | 34 +++++++------------ 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 22720ce3..5814549f 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -36,38 +36,28 @@ std::vector> RAD_SETTINGS::ParseSendAttr(std:: for (const auto& t : tok) parsedSendAttr.push_back(t); - if (parsedSendAttr.empty()) + if (parsedSendAttr.size() != 2) { - m_logger("Error ParseSendAttr: send parameter attribute is missing.\n"); - printfd(__FILE__, "Error ParseSendAttr: send parameter attribute is missing.\n"); - return keyValuePairs; + m_logger("Send attribute specification has an incorrect format: '%s'.", token.c_str()); + printfd(__FILE__, "Send attribute specification has an incorrect format: '%s'.", token.c_str()); + return {}; } - if (parsedSendAttr.size() < 2) - { - m_logger("Error ParseSendAttr: send parameter attribute is invalid.\n"); - printfd(__FILE__, "Error ParseSendAttr: send parameter attribute is invalid.\n"); - return keyValuePairs; - } - - std::string key = parsedSendAttr[0]; + auto type = AttrValue::Type::PARAM_NAME; std::string valueName = parsedSendAttr[1]; - - if (valueName[0] == '\'' && valueName[valueName.length() - 1] == '\'') + if (valueName[0] == '\'' && valueName[valueName.length() - 1] == '\'') { + type = AttrValue::Type::VALUE; valueName.erase(0, 1); valueName.erase(valueName.length() - 1, 1); - - keyValuePairs.emplace_back(key, AttrValue{valueName, AttrValue::Type::VALUE}); } - else if (valueName[0] != '\'' && valueName[valueName.length() - 1] != '\'') - keyValuePairs.emplace_back(key, AttrValue{valueName, AttrValue::Type::PARAM_NAME}); - else + else if ((valueName[0] == '\'' && valueName[valueName.length() - 1] != '\'') || (valueName[0] != '\'' && valueName[valueName.length() - 1] == '\'')) { - m_logger("Error ParseSendAttr: send parameter attribute value is invalid.\n"); - printfd(__FILE__, "Error ParseSendAttr: send parameter attribute value is invalid.\n"); - return keyValuePairs; + m_logger("Error ParseSendAttr: send attribute parameter value is invalid.\n"); + printfd(__FILE__, "Error ParseSendAttr: send attribute parameter value is invalid.\n"); + return {}; } + keyValuePairs.emplace_back(parsedSendAttr[0], AttrValue{valueName, type}); } return keyValuePairs; } From bd30450fa823b64ba7faada238340eca2e4fcd7d Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Tue, 27 May 2025 14:38:47 +0300 Subject: [PATCH 111/186] Radius. Argument fieldSendAttr name changed to value and argument type changed to const std::string& in ParseSendAttr method. Vector keyValuePairs name changed to res. --- projects/stargazer/plugins/other/radius/radius.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 5814549f..96229df8 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -18,14 +18,14 @@ extern "C" STG::Plugin* GetPlugin() return &plugin; } -std::vector> RAD_SETTINGS::ParseSendAttr(std::string fieldSendAttr) +std::vector> RAD_SETTINGS::ParseSendAttr(const std::string& value) { using tokenizer = boost::tokenizer>; boost::char_separator sep(","); - tokenizer tokens(fieldSendAttr, sep); + tokenizer tokens(value, sep); - std::vector> keyValuePairs; + std::vector> res; for (const auto& token : tokens) { @@ -57,9 +57,9 @@ std::vector> RAD_SETTINGS::ParseSendAttr(std:: printfd(__FILE__, "Error ParseSendAttr: send attribute parameter value is invalid.\n"); return {}; } - keyValuePairs.emplace_back(parsedSendAttr[0], AttrValue{valueName, type}); + res.emplace_back(parsedSendAttr[0], AttrValue{valueName, type}); } - return keyValuePairs; + return res; } RAD_SETTINGS::RAD_SETTINGS() @@ -112,9 +112,9 @@ int RAD_SETTINGS::ParseSettings(const ModuleSettings & s) { printfd(__FILE__, "ParseSettings Value of send: '%s'\n", pva->value[0].c_str()); - std::vector> keyValuePairs = ParseSendAttr(pva->value[0]); + std::vector> res = ParseSendAttr(pva->value[0]); - for (const auto& at : keyValuePairs) + for (const auto& at : res) printfd(__FILE__, "Key: '%s', Value: '%s', Type: %d\n", at.first.c_str(), at.second.value.c_str(), at.second.type); } } From c07c0a7a9572a01bfae278295af4990cd87f391e Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Tue, 27 May 2025 14:46:15 +0300 Subject: [PATCH 112/186] Radius. Argument fieldSendAttr name changed to value and argument type changed to const std::string& in ParseSendAttr method. --- projects/stargazer/plugins/other/radius/radius.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/stargazer/plugins/other/radius/radius.h b/projects/stargazer/plugins/other/radius/radius.h index 1dfeba04..5437d1dd 100644 --- a/projects/stargazer/plugins/other/radius/radius.h +++ b/projects/stargazer/plugins/other/radius/radius.h @@ -39,7 +39,7 @@ namespace STG const std::string & GetStrError() const { return m_errorStr; } int ParseSettings(const ModuleSettings & s); - std::vector> ParseSendAttr(std::string fieldSendAttr); + std::vector> ParseSendAttr(const std::string& value); uint16_t GetPort() const { return m_port; } const std::string & GetDictionaries() const { return m_dictionaries; } From c1f4bd77551d4a26b68a375b02f678b81a39aede Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Tue, 27 May 2025 14:55:44 +0300 Subject: [PATCH 113/186] Radius. Vector name parsedSendAttr changed to keyValue in ParseSendAttr method. --- projects/stargazer/plugins/other/radius/radius.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 96229df8..f16e1c62 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -32,11 +32,11 @@ std::vector> RAD_SETTINGS::ParseSendAttr(const boost::char_separator sp(" ="); tokenizer tok(token, sp); - std::vector parsedSendAttr; + std::vector keyValue; for (const auto& t : tok) - parsedSendAttr.push_back(t); + keyValue.push_back(t); - if (parsedSendAttr.size() != 2) + if (keyValue.size() != 2) { m_logger("Send attribute specification has an incorrect format: '%s'.", token.c_str()); printfd(__FILE__, "Send attribute specification has an incorrect format: '%s'.", token.c_str()); @@ -44,7 +44,7 @@ std::vector> RAD_SETTINGS::ParseSendAttr(const } auto type = AttrValue::Type::PARAM_NAME; - std::string valueName = parsedSendAttr[1]; + std::string valueName = keyValue[1]; if (valueName[0] == '\'' && valueName[valueName.length() - 1] == '\'') { type = AttrValue::Type::VALUE; @@ -57,7 +57,7 @@ std::vector> RAD_SETTINGS::ParseSendAttr(const printfd(__FILE__, "Error ParseSendAttr: send attribute parameter value is invalid.\n"); return {}; } - res.emplace_back(parsedSendAttr[0], AttrValue{valueName, type}); + res.emplace_back(keyValue[0], AttrValue{valueName, type}); } return res; } From bfcb2987940c96a90b19b581545c3b597a9f92c0 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Tue, 27 May 2025 15:18:39 +0300 Subject: [PATCH 114/186] Radius. Functions front() and back() are used to get the first and last characters of string valueName in ParseSendAttr method. --- projects/stargazer/plugins/other/radius/radius.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index f16e1c62..83db8c50 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -45,13 +45,13 @@ std::vector> RAD_SETTINGS::ParseSendAttr(const auto type = AttrValue::Type::PARAM_NAME; std::string valueName = keyValue[1]; - if (valueName[0] == '\'' && valueName[valueName.length() - 1] == '\'') + if (valueName.front() == '\'' && valueName.back() == '\'') { type = AttrValue::Type::VALUE; valueName.erase(0, 1); valueName.erase(valueName.length() - 1, 1); } - else if ((valueName[0] == '\'' && valueName[valueName.length() - 1] != '\'') || (valueName[0] != '\'' && valueName[valueName.length() - 1] == '\'')) + else if ((valueName.front() == '\'' && valueName.back() != '\'') || (valueName.front() != '\'' && valueName.back() == '\'')) { m_logger("Error ParseSendAttr: send attribute parameter value is invalid.\n"); printfd(__FILE__, "Error ParseSendAttr: send attribute parameter value is invalid.\n"); From e87368db1b114500a36103a6b00908e3384c257e Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Tue, 27 May 2025 15:27:48 +0300 Subject: [PATCH 115/186] Radius. Method declaration ParseSendAttr moved to private in class RAD_SETTINGS. --- projects/stargazer/plugins/other/radius/radius.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/projects/stargazer/plugins/other/radius/radius.h b/projects/stargazer/plugins/other/radius/radius.h index 5437d1dd..22baa4c8 100644 --- a/projects/stargazer/plugins/other/radius/radius.h +++ b/projects/stargazer/plugins/other/radius/radius.h @@ -39,13 +39,14 @@ namespace STG const std::string & GetStrError() const { return m_errorStr; } int ParseSettings(const ModuleSettings & s); - std::vector> ParseSendAttr(const std::string& value); 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::vector> ParseSendAttr(const std::string& value); + std::string m_errorStr; uint16_t m_port; std::string m_dictionaries; From 8baf9e04a39540c38d5cbe771ff6d6ce9380bcfc Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Tue, 27 May 2025 16:00:50 +0300 Subject: [PATCH 116/186] Radius. Formatting fixed. Class member m_res and public function GetRes added to class RAD_SETTINGS. --- .../stargazer/plugins/other/radius/radius.h | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.h b/projects/stargazer/plugins/other/radius/radius.h index 22baa4c8..9a238fa5 100644 --- a/projects/stargazer/plugins/other/radius/radius.h +++ b/projects/stargazer/plugins/other/radius/radius.h @@ -37,12 +37,13 @@ namespace STG Type type; }; - const std::string & GetStrError() const { return m_errorStr; } - int ParseSettings(const ModuleSettings & s); + 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 std::string& GetDictionaries() const { return m_dictionaries; } + const std::string& GetSecret() const { return m_secret; } + const std::vector>& GetRes() const { return m_res; } private: std::vector> ParseSendAttr(const std::string& value); @@ -51,6 +52,7 @@ namespace STG uint16_t m_port; std::string m_dictionaries; std::string m_secret; + std::vector> m_res; PluginLogger m_logger; }; @@ -62,22 +64,22 @@ namespace STG RADIUS& operator=(const RADIUS&) = delete; void SetUsers(Users* u) { m_users = u; } - void SetSettings(const ModuleSettings & s) override { m_settings = s; } + 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; } + int Reload(const ModuleSettings& /*ms*/) override { return 0; } bool IsRunning() override; void SetRunning(bool val); - const std::string & GetStrError() const override { return m_errorStr; } + 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; } + int SendMessage(const Message& msg, uint32_t ip) const override { return 0; } private: std::mutex m_mutex; From 9367195701c392e8dd7b0e5d07354a46c3f25e48 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Tue, 27 May 2025 16:09:45 +0300 Subject: [PATCH 117/186] Radius. Extra variable res removed. Class member m_res definition added to ParseSendAttr function and ParseSettings function. --- projects/stargazer/plugins/other/radius/radius.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 83db8c50..9330a114 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -25,8 +25,6 @@ std::vector> RAD_SETTINGS::ParseSendAttr(const tokenizer tokens(value, sep); - std::vector> res; - for (const auto& token : tokens) { boost::char_separator sp(" ="); @@ -57,9 +55,9 @@ std::vector> RAD_SETTINGS::ParseSendAttr(const printfd(__FILE__, "Error ParseSendAttr: send attribute parameter value is invalid.\n"); return {}; } - res.emplace_back(keyValue[0], AttrValue{valueName, type}); + m_res.emplace_back(keyValue[0], AttrValue{valueName, type}); } - return res; + return m_res; } RAD_SETTINGS::RAD_SETTINGS() @@ -112,9 +110,9 @@ int RAD_SETTINGS::ParseSettings(const ModuleSettings & s) { printfd(__FILE__, "ParseSettings Value of send: '%s'\n", pva->value[0].c_str()); - std::vector> res = ParseSendAttr(pva->value[0]); + m_res = ParseSendAttr(pva->value[0]); - for (const auto& at : res) + for (const auto& at : m_res) printfd(__FILE__, "Key: '%s', Value: '%s', Type: %d\n", at.first.c_str(), at.second.value.c_str(), at.second.type); } } From 3d628274c469473801b925b24b817a978a55c4e8 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Wed, 28 May 2025 14:33:00 +0300 Subject: [PATCH 118/186] Radius. Vector res added, variable m_res replaced by res in ParseSendAttr function. --- projects/stargazer/plugins/other/radius/radius.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 9330a114..4e5631b6 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -25,6 +25,7 @@ std::vector> RAD_SETTINGS::ParseSendAttr(const tokenizer tokens(value, sep); + std::vector> res; for (const auto& token : tokens) { boost::char_separator sp(" ="); @@ -55,9 +56,9 @@ std::vector> RAD_SETTINGS::ParseSendAttr(const printfd(__FILE__, "Error ParseSendAttr: send attribute parameter value is invalid.\n"); return {}; } - m_res.emplace_back(keyValue[0], AttrValue{valueName, type}); + res.emplace_back(keyValue[0], AttrValue{valueName, type}); } - return m_res; + return res; } RAD_SETTINGS::RAD_SETTINGS() From 85b9f0d966690ff4d70b3a5fa37df2a9dc953058 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Wed, 28 May 2025 14:44:44 +0300 Subject: [PATCH 119/186] Radius. Function name GetRes changed to GetSendPairs, class member vaiable name m_res changed to m_sendPairs in class RAD_SETTINGS. --- projects/stargazer/plugins/other/radius/radius.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.h b/projects/stargazer/plugins/other/radius/radius.h index 9a238fa5..2f93dbf6 100644 --- a/projects/stargazer/plugins/other/radius/radius.h +++ b/projects/stargazer/plugins/other/radius/radius.h @@ -43,7 +43,7 @@ namespace STG 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::vector>& GetRes() const { return m_res; } + const std::vector>& GetSendPairs() const { return m_sendPairs; } private: std::vector> ParseSendAttr(const std::string& value); @@ -52,7 +52,7 @@ namespace STG uint16_t m_port; std::string m_dictionaries; std::string m_secret; - std::vector> m_res; + std::vector> m_sendPairs; PluginLogger m_logger; }; From 44844ce39ca44597a7ce13dc0230be13aa98ab4d Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Wed, 28 May 2025 14:52:01 +0300 Subject: [PATCH 120/186] Radius. Class member vaiable name m_res changed to m_sendPairs in the ParseSettings function. --- projects/stargazer/plugins/other/radius/radius.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 4e5631b6..20accfdf 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -111,9 +111,9 @@ int RAD_SETTINGS::ParseSettings(const ModuleSettings & s) { printfd(__FILE__, "ParseSettings Value of send: '%s'\n", pva->value[0].c_str()); - m_res = ParseSendAttr(pva->value[0]); + m_sendPairs = ParseSendAttr(pva->value[0]); - for (const auto& at : m_res) + for (const auto& at : m_sendPairs) printfd(__FILE__, "Key: '%s', Value: '%s', Type: %d\n", at.first.c_str(), at.second.value.c_str(), at.second.type); } } From ccfecf2ae6314b04c4288983d28d2ffb30b5691a Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Wed, 4 Jun 2025 15:31:48 +0300 Subject: [PATCH 121/186] Radius. Parameter auth added to mod_radius.conf. --- .../inst/linux/etc/stargazer/conf-available.d/mod_radius.conf | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/projects/stargazer/inst/linux/etc/stargazer/conf-available.d/mod_radius.conf b/projects/stargazer/inst/linux/etc/stargazer/conf-available.d/mod_radius.conf index d4cf6c4c..a7a90ba5 100644 --- a/projects/stargazer/inst/linux/etc/stargazer/conf-available.d/mod_radius.conf +++ b/projects/stargazer/inst/linux/etc/stargazer/conf-available.d/mod_radius.conf @@ -17,4 +17,8 @@ # Default: 1812 # Port = 1812 + + send = "Framed-IP-Address = currip, Framed-Protocol = \'PPP\'" + match = "Framed-IP-Address = currip, Framed-Protocol = \'PPP\'" + From 9c6ee365ce986c072e97d26b9b0d947bf77dbce7 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Wed, 4 Jun 2025 15:52:38 +0300 Subject: [PATCH 122/186] Radius. The ParseMatchAttr method declaration and m_matchPairs class member added to RAD_SETTINGS class. --- projects/stargazer/plugins/other/radius/radius.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/projects/stargazer/plugins/other/radius/radius.h b/projects/stargazer/plugins/other/radius/radius.h index 2f93dbf6..f1f735a6 100644 --- a/projects/stargazer/plugins/other/radius/radius.h +++ b/projects/stargazer/plugins/other/radius/radius.h @@ -47,12 +47,14 @@ namespace STG private: std::vector> ParseSendAttr(const std::string& value); + std::vector> ParseMatchAttr(const std::string& value); std::string m_errorStr; uint16_t m_port; std::string m_dictionaries; std::string m_secret; std::vector> m_sendPairs; + std::vector> m_matchPairs; PluginLogger m_logger; }; From b2304cac18326074df483c6b76be21be938bd81f Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Wed, 4 Jun 2025 16:05:48 +0300 Subject: [PATCH 123/186] Radius. The ParseMatchAttr function definition added. Match attributes parsing added to ParseSetting function. --- .../stargazer/plugins/other/radius/radius.cpp | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 20accfdf..184c80a7 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -61,6 +61,49 @@ std::vector> RAD_SETTINGS::ParseSendAttr(const return res; } +std::vector> RAD_SETTINGS::ParseMatchAttr(const std::string& value) +{ + using tokenizer = boost::tokenizer>; + boost::char_separator sep(","); + + tokenizer tokens(value, sep); + + std::vector> res; + for (const auto& token : tokens) + { + boost::char_separator sp(" ="); + tokenizer tok(token, sp); + + std::vector keyValue; + for (const auto& t : tok) + keyValue.push_back(t); + + if (keyValue.size() != 2) + { + m_logger("Match attribute specification has an incorrect format: '%s'.", token.c_str()); + printfd(__FILE__, "Match attribute specification has an incorrect format: '%s'.", token.c_str()); + return {}; + } + + auto type = AttrValue::Type::PARAM_NAME; + std::string valueName = keyValue[1]; + if (valueName.front() == '\'' && valueName.back() == '\'') + { + type = AttrValue::Type::VALUE; + valueName.erase(0, 1); + valueName.erase(valueName.length() - 1, 1); + } + else if ((valueName.front() == '\'' && valueName.back() != '\'') || (valueName.front() != '\'' && valueName.back() == '\'')) + { + m_logger("Error ParseMatchAttr: match attribute parameter value is invalid.\n"); + printfd(__FILE__, "Error ParseMatchAttr: match attribute parameter value is invalid.\n"); + return {}; + } + res.emplace_back(keyValue[0], AttrValue{valueName, type}); + } + return res; +} + RAD_SETTINGS::RAD_SETTINGS() : m_port(1812), m_dictionaries("/usr/share/freeradius/dictionary"), @@ -116,6 +159,18 @@ int RAD_SETTINGS::ParseSettings(const ModuleSettings & s) for (const auto& at : m_sendPairs) printfd(__FILE__, "Key: '%s', Value: '%s', Type: %d\n", at.first.c_str(), at.second.value.c_str(), at.second.type); } + + pv.param = "match"; + pva = std::find(pvi->sections.begin(), pvi->sections.end(), pv); + if (pva != pvi->sections.end() && !pva->value.empty()) + { + printfd(__FILE__, "ParseSettings Value of match: '%s'\n", pva->value[0].c_str()); + + m_matchPairs = ParseMatchAttr(pva->value[0]); + + for (const auto& at : m_matchPairs) + printfd(__FILE__, "Key: '%s', Value: '%s', Type: %d\n", at.first.c_str(), at.second.value.c_str(), at.second.type); + } } return 0; } From 4d6fcb7cfa878a2b046c0fd221563e9aa9a71a20 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Thu, 5 Jun 2025 15:48:36 +0300 Subject: [PATCH 124/186] Radius. The ParseMatchAttr method removed, the ParseSendAttr method renamed to ParseAuthAttr in the class RAD_SETTINGS. --- projects/stargazer/plugins/other/radius/radius.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.h b/projects/stargazer/plugins/other/radius/radius.h index f1f735a6..2b7bd28b 100644 --- a/projects/stargazer/plugins/other/radius/radius.h +++ b/projects/stargazer/plugins/other/radius/radius.h @@ -46,8 +46,7 @@ namespace STG const std::vector>& GetSendPairs() const { return m_sendPairs; } private: - std::vector> ParseSendAttr(const std::string& value); - std::vector> ParseMatchAttr(const std::string& value); + std::vector> ParseAuthAttr(const std::string& value, const std::string& paramName); std::string m_errorStr; uint16_t m_port; From 083c78b988725be93ff08e6919ff0ed5f467bb86 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Thu, 5 Jun 2025 15:55:38 +0300 Subject: [PATCH 125/186] Radius. The ParseSendAttr method definition and call renamed to ParseAuthAttr. Parameter paramName added to ParseAuthAttr method. The ParseMatchAttr method definition removed. ParseMatchAttr method call replaced by ParseAuthAttr. --- .../stargazer/plugins/other/radius/radius.cpp | 57 +++---------------- 1 file changed, 7 insertions(+), 50 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 184c80a7..743aa6c4 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -18,7 +18,7 @@ extern "C" STG::Plugin* GetPlugin() return &plugin; } -std::vector> RAD_SETTINGS::ParseSendAttr(const std::string& value) +std::vector> RAD_SETTINGS::ParseAuthAttr(const std::string& value, const std::string& paramName) { using tokenizer = boost::tokenizer>; boost::char_separator sep(","); @@ -37,8 +37,8 @@ std::vector> RAD_SETTINGS::ParseSendAttr(const if (keyValue.size() != 2) { - m_logger("Send attribute specification has an incorrect format: '%s'.", token.c_str()); - printfd(__FILE__, "Send attribute specification has an incorrect format: '%s'.", token.c_str()); + m_logger("The '%s' attribute specification has an incorrect format: '%s'.", paramName.c_str(), token.c_str()); + printfd(__FILE__, "The '%s' attribute specification has an incorrect format: '%s'.", paramName.c_str(), token.c_str()); return {}; } @@ -52,51 +52,8 @@ std::vector> RAD_SETTINGS::ParseSendAttr(const } else if ((valueName.front() == '\'' && valueName.back() != '\'') || (valueName.front() != '\'' && valueName.back() == '\'')) { - m_logger("Error ParseSendAttr: send attribute parameter value is invalid.\n"); - printfd(__FILE__, "Error ParseSendAttr: send attribute parameter value is invalid.\n"); - return {}; - } - res.emplace_back(keyValue[0], AttrValue{valueName, type}); - } - return res; -} - -std::vector> RAD_SETTINGS::ParseMatchAttr(const std::string& value) -{ - using tokenizer = boost::tokenizer>; - boost::char_separator sep(","); - - tokenizer tokens(value, sep); - - std::vector> res; - for (const auto& token : tokens) - { - boost::char_separator sp(" ="); - tokenizer tok(token, sp); - - std::vector keyValue; - for (const auto& t : tok) - keyValue.push_back(t); - - if (keyValue.size() != 2) - { - m_logger("Match attribute specification has an incorrect format: '%s'.", token.c_str()); - printfd(__FILE__, "Match attribute specification has an incorrect format: '%s'.", token.c_str()); - return {}; - } - - auto type = AttrValue::Type::PARAM_NAME; - std::string valueName = keyValue[1]; - if (valueName.front() == '\'' && valueName.back() == '\'') - { - type = AttrValue::Type::VALUE; - valueName.erase(0, 1); - valueName.erase(valueName.length() - 1, 1); - } - else if ((valueName.front() == '\'' && valueName.back() != '\'') || (valueName.front() != '\'' && valueName.back() == '\'')) - { - m_logger("Error ParseMatchAttr: match attribute parameter value is invalid.\n"); - printfd(__FILE__, "Error ParseMatchAttr: match attribute parameter value is invalid.\n"); + m_logger("Error ParseAuthAttr: '%s' attribute parameter value is invalid.\n", paramName.c_str()); + printfd(__FILE__, "Error ParseAuthAttr: '%s' attribute parameter value is invalid.\n", paramName.c_str()); return {}; } res.emplace_back(keyValue[0], AttrValue{valueName, type}); @@ -154,7 +111,7 @@ int RAD_SETTINGS::ParseSettings(const ModuleSettings & s) { printfd(__FILE__, "ParseSettings Value of send: '%s'\n", pva->value[0].c_str()); - m_sendPairs = ParseSendAttr(pva->value[0]); + m_sendPairs = ParseAuthAttr(pva->value[0], pv.param); for (const auto& at : m_sendPairs) printfd(__FILE__, "Key: '%s', Value: '%s', Type: %d\n", at.first.c_str(), at.second.value.c_str(), at.second.type); @@ -166,7 +123,7 @@ int RAD_SETTINGS::ParseSettings(const ModuleSettings & s) { printfd(__FILE__, "ParseSettings Value of match: '%s'\n", pva->value[0].c_str()); - m_matchPairs = ParseMatchAttr(pva->value[0]); + m_matchPairs = ParseAuthAttr(pva->value[0], pv.param.c_str()); for (const auto& at : m_matchPairs) printfd(__FILE__, "Key: '%s', Value: '%s', Type: %d\n", at.first.c_str(), at.second.value.c_str(), at.second.type); From 850915293d61ba2f6cd3ccd92a68216d96e49d35 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Fri, 6 Jun 2025 15:35:24 +0300 Subject: [PATCH 126/186] Radius. Attribute for parameter auth/match changed. --- .../inst/linux/etc/stargazer/conf-available.d/mod_radius.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/stargazer/inst/linux/etc/stargazer/conf-available.d/mod_radius.conf b/projects/stargazer/inst/linux/etc/stargazer/conf-available.d/mod_radius.conf index a7a90ba5..ee74f23d 100644 --- a/projects/stargazer/inst/linux/etc/stargazer/conf-available.d/mod_radius.conf +++ b/projects/stargazer/inst/linux/etc/stargazer/conf-available.d/mod_radius.conf @@ -19,6 +19,6 @@ send = "Framed-IP-Address = currip, Framed-Protocol = \'PPP\'" - match = "Framed-IP-Address = currip, Framed-Protocol = \'PPP\'" + match = "Calling-Station-Id = userdata0" From ee9496a9a3dee23f149364e859b71a38012d4fb8 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Fri, 6 Jun 2025 16:16:59 +0300 Subject: [PATCH 127/186] Radius. Parameter autz added. --- .../linux/etc/stargazer/conf-available.d/mod_radius.conf | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/projects/stargazer/inst/linux/etc/stargazer/conf-available.d/mod_radius.conf b/projects/stargazer/inst/linux/etc/stargazer/conf-available.d/mod_radius.conf index ee74f23d..adae7a54 100644 --- a/projects/stargazer/inst/linux/etc/stargazer/conf-available.d/mod_radius.conf +++ b/projects/stargazer/inst/linux/etc/stargazer/conf-available.d/mod_radius.conf @@ -21,4 +21,9 @@ send = "Framed-IP-Address = currip, Framed-Protocol = \'PPP\'" match = "Calling-Station-Id = userdata0" + + + send = "Framed-IP-Address = currip, Framed-Protocol = \'PPP\'" + match = "Calling-Station-Id = userdata0" + From 97235bb4cf6f5719e70364ad0a140b69662c1ef6 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Fri, 6 Jun 2025 19:21:52 +0300 Subject: [PATCH 128/186] Radius. ParseAuthAttr function renamed to ParseAuthAutzAttr. --- projects/stargazer/plugins/other/radius/radius.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/stargazer/plugins/other/radius/radius.h b/projects/stargazer/plugins/other/radius/radius.h index 2b7bd28b..74c739ea 100644 --- a/projects/stargazer/plugins/other/radius/radius.h +++ b/projects/stargazer/plugins/other/radius/radius.h @@ -46,7 +46,7 @@ namespace STG const std::vector>& GetSendPairs() const { return m_sendPairs; } private: - std::vector> ParseAuthAttr(const std::string& value, const std::string& paramName); + std::vector> ParseAuthAutzAttr(const std::string& value, const std::string& paramName); std::string m_errorStr; uint16_t m_port; From a5b0dbdcad37efe621a909dc97cf7e4678c14e3c Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Fri, 6 Jun 2025 19:23:46 +0300 Subject: [PATCH 129/186] Radius. ParseAuthAttr function renamed to ParseAuthAutzAttr. The autz attributes parsing added, m_logger and printfd messages changed in the ParseAuthAutzAttr function. --- .../stargazer/plugins/other/radius/radius.cpp | 43 ++++++++++++++++--- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 743aa6c4..5c8393a5 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -18,7 +18,7 @@ extern "C" STG::Plugin* GetPlugin() return &plugin; } -std::vector> RAD_SETTINGS::ParseAuthAttr(const std::string& value, const std::string& paramName) +std::vector> RAD_SETTINGS::ParseAuthAutzAttr(const std::string& value, const std::string& paramName) { using tokenizer = boost::tokenizer>; boost::char_separator sep(","); @@ -52,8 +52,8 @@ std::vector> RAD_SETTINGS::ParseAuthAttr(const } else if ((valueName.front() == '\'' && valueName.back() != '\'') || (valueName.front() != '\'' && valueName.back() == '\'')) { - m_logger("Error ParseAuthAttr: '%s' attribute parameter value is invalid.\n", paramName.c_str()); - printfd(__FILE__, "Error ParseAuthAttr: '%s' attribute parameter value is invalid.\n", paramName.c_str()); + m_logger("Error ParseAuthAutzAttr: '%s' attribute parameter value is invalid.\n", paramName.c_str()); + printfd(__FILE__, "Error ParseAuthAutzAttr: '%s' attribute parameter value is invalid.\n", paramName.c_str()); return {}; } res.emplace_back(keyValue[0], AttrValue{valueName, type}); @@ -109,9 +109,9 @@ int RAD_SETTINGS::ParseSettings(const ModuleSettings & s) auto pva = std::find(pvi->sections.begin(), pvi->sections.end(), pv); if (pva != pvi->sections.end() && !pva->value.empty()) { - printfd(__FILE__, "ParseSettings Value of send: '%s'\n", pva->value[0].c_str()); + printfd(__FILE__, "ParseSettings Value of auth/send: '%s'\n", pva->value[0].c_str()); - m_sendPairs = ParseAuthAttr(pva->value[0], pv.param); + m_sendPairs = ParseAuthAutzAttr(pva->value[0], pv.param); for (const auto& at : m_sendPairs) printfd(__FILE__, "Key: '%s', Value: '%s', Type: %d\n", at.first.c_str(), at.second.value.c_str(), at.second.type); @@ -121,9 +121,38 @@ int RAD_SETTINGS::ParseSettings(const ModuleSettings & s) pva = std::find(pvi->sections.begin(), pvi->sections.end(), pv); if (pva != pvi->sections.end() && !pva->value.empty()) { - printfd(__FILE__, "ParseSettings Value of match: '%s'\n", pva->value[0].c_str()); + printfd(__FILE__, "ParseSettings Value of auth/match: '%s'\n", pva->value[0].c_str()); - m_matchPairs = ParseAuthAttr(pva->value[0], pv.param.c_str()); + m_matchPairs = ParseAuthAutzAttr(pva->value[0], pv.param.c_str()); + + for (const auto& at : m_matchPairs) + printfd(__FILE__, "Key: '%s', Value: '%s', Type: %d\n", at.first.c_str(), at.second.value.c_str(), at.second.type); + } + } + + pv.param = "autz"; + pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv); + if (pvi != s.moduleParams.end()) + { + pv.param = "send"; + auto pva = std::find(pvi->sections.begin(), pvi->sections.end(), pv); + if (pva != pvi->sections.end() && !pva->value.empty()) + { + printfd(__FILE__, "ParseSettings Value of autz/send: '%s'\n", pva->value[0].c_str()); + + m_sendPairs = ParseAuthAutzAttr(pva->value[0], pv.param); + + for (const auto& at : m_sendPairs) + printfd(__FILE__, "Key: '%s', Value: '%s', Type: %d\n", at.first.c_str(), at.second.value.c_str(), at.second.type); + } + + pv.param = "match"; + pva = std::find(pvi->sections.begin(), pvi->sections.end(), pv); + if (pva != pvi->sections.end() && !pva->value.empty()) + { + printfd(__FILE__, "ParseSettings Value of autz/match: '%s'\n", pva->value[0].c_str()); + + m_matchPairs = ParseAuthAutzAttr(pva->value[0], pv.param.c_str()); for (const auto& at : m_matchPairs) printfd(__FILE__, "Key: '%s', Value: '%s', Type: %d\n", at.first.c_str(), at.second.value.c_str(), at.second.type); From a13248458a79ac73028ea2e6351c006fabf71585 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Wed, 11 Jun 2025 16:21:17 +0300 Subject: [PATCH 130/186] Radius. ParseAuthAutzAttr function renamed to ParseSectionsAttr. The MakeKeyValuePairs function definition added. --- projects/stargazer/plugins/other/radius/radius.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/projects/stargazer/plugins/other/radius/radius.h b/projects/stargazer/plugins/other/radius/radius.h index 74c739ea..3807d699 100644 --- a/projects/stargazer/plugins/other/radius/radius.h +++ b/projects/stargazer/plugins/other/radius/radius.h @@ -46,7 +46,8 @@ namespace STG const std::vector>& GetSendPairs() const { return m_sendPairs; } private: - std::vector> ParseAuthAutzAttr(const std::string& value, const std::string& paramName); + std::vector> ParseSectionsAttr(const std::string& value, const std::string& paramName); + void MakeKeyValuePairs(const ModuleSettings & s, ParamValue pv, const std::string& paramName); std::string m_errorStr; uint16_t m_port; From e6090216eac6cec208a9b58870f44116e0332e3f Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Wed, 11 Jun 2025 16:28:21 +0300 Subject: [PATCH 131/186] Radius. ParseAuthAutzAttr function renamed to ParseSectionsAttr. The messages of m_logger and printfd changed in the ParseSectionsAttr function. The MakeKeyValuePairs function definition and call added. --- .../stargazer/plugins/other/radius/radius.cpp | 92 ++++++++----------- 1 file changed, 36 insertions(+), 56 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 5c8393a5..f98a8fdc 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -18,7 +18,7 @@ extern "C" STG::Plugin* GetPlugin() return &plugin; } -std::vector> RAD_SETTINGS::ParseAuthAutzAttr(const std::string& value, const std::string& paramName) +std::vector> RAD_SETTINGS::ParseSectionsAttr(const std::string& value, const std::string& paramName) { using tokenizer = boost::tokenizer>; boost::char_separator sep(","); @@ -52,8 +52,8 @@ std::vector> RAD_SETTINGS::ParseAuthAutzAttr(c } else if ((valueName.front() == '\'' && valueName.back() != '\'') || (valueName.front() != '\'' && valueName.back() == '\'')) { - m_logger("Error ParseAuthAutzAttr: '%s' attribute parameter value is invalid.\n", paramName.c_str()); - printfd(__FILE__, "Error ParseAuthAutzAttr: '%s' attribute parameter value is invalid.\n", paramName.c_str()); + m_logger("Error ParseSectionsAttr: '%s' attribute parameter value is invalid.\n", paramName.c_str()); + printfd(__FILE__, "Error ParseSectionsAttr: '%s' attribute parameter value is invalid.\n", paramName.c_str()); return {}; } res.emplace_back(keyValue[0], AttrValue{valueName, type}); @@ -61,6 +61,37 @@ std::vector> RAD_SETTINGS::ParseAuthAutzAttr(c return res; } +void RAD_SETTINGS::MakeKeyValuePairs(const ModuleSettings & s, ParamValue pv, const std::string& paramName) +{ + auto pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv); + if (pvi != s.moduleParams.end()) + { + pv.param = "send"; + auto pva = std::find(pvi->sections.begin(), pvi->sections.end(), pv); + if (pva != pvi->sections.end() && !pva->value.empty()) + { + printfd(__FILE__, "ParseSettings: The send value of param '%s': '%s'\n", paramName.c_str(), pva->value[0].c_str()); + + m_sendPairs = ParseSectionsAttr(pva->value[0], pv.param); + + for (const auto& at : m_sendPairs) + printfd(__FILE__, "Key: '%s', Value: '%s', Type: %d\n", at.first.c_str(), at.second.value.c_str(), at.second.type); + } + + pv.param = "match"; + pva = std::find(pvi->sections.begin(), pvi->sections.end(), pv); + if (pva != pvi->sections.end() && !pva->value.empty()) + { + printfd(__FILE__, "ParseSettings: The match value of param '%s': '%s'\n", paramName.c_str(), pva->value[0].c_str()); + + m_matchPairs = ParseSectionsAttr(pva->value[0], pv.param.c_str()); + + for (const auto& at : m_matchPairs) + printfd(__FILE__, "Key: '%s', Value: '%s', Type: %d\n", at.first.c_str(), at.second.value.c_str(), at.second.type); + } + } +} + RAD_SETTINGS::RAD_SETTINGS() : m_port(1812), m_dictionaries("/usr/share/freeradius/dictionary"), @@ -102,62 +133,11 @@ int RAD_SETTINGS::ParseSettings(const ModuleSettings & s) m_dictionaries = pvi->value[0]; pv.param = "auth"; - pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv); - if (pvi != s.moduleParams.end()) - { - pv.param = "send"; - auto pva = std::find(pvi->sections.begin(), pvi->sections.end(), pv); - if (pva != pvi->sections.end() && !pva->value.empty()) - { - printfd(__FILE__, "ParseSettings Value of auth/send: '%s'\n", pva->value[0].c_str()); - - m_sendPairs = ParseAuthAutzAttr(pva->value[0], pv.param); - - for (const auto& at : m_sendPairs) - printfd(__FILE__, "Key: '%s', Value: '%s', Type: %d\n", at.first.c_str(), at.second.value.c_str(), at.second.type); - } - - pv.param = "match"; - pva = std::find(pvi->sections.begin(), pvi->sections.end(), pv); - if (pva != pvi->sections.end() && !pva->value.empty()) - { - printfd(__FILE__, "ParseSettings Value of auth/match: '%s'\n", pva->value[0].c_str()); - - m_matchPairs = ParseAuthAutzAttr(pva->value[0], pv.param.c_str()); - - for (const auto& at : m_matchPairs) - printfd(__FILE__, "Key: '%s', Value: '%s', Type: %d\n", at.first.c_str(), at.second.value.c_str(), at.second.type); - } - } + MakeKeyValuePairs(s, pv, pv.param); pv.param = "autz"; - pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv); - if (pvi != s.moduleParams.end()) - { - pv.param = "send"; - auto pva = std::find(pvi->sections.begin(), pvi->sections.end(), pv); - if (pva != pvi->sections.end() && !pva->value.empty()) - { - printfd(__FILE__, "ParseSettings Value of autz/send: '%s'\n", pva->value[0].c_str()); - - m_sendPairs = ParseAuthAutzAttr(pva->value[0], pv.param); + MakeKeyValuePairs(s, pv, pv.param); - for (const auto& at : m_sendPairs) - printfd(__FILE__, "Key: '%s', Value: '%s', Type: %d\n", at.first.c_str(), at.second.value.c_str(), at.second.type); - } - - pv.param = "match"; - pva = std::find(pvi->sections.begin(), pvi->sections.end(), pv); - if (pva != pvi->sections.end() && !pva->value.empty()) - { - printfd(__FILE__, "ParseSettings Value of autz/match: '%s'\n", pva->value[0].c_str()); - - m_matchPairs = ParseAuthAutzAttr(pva->value[0], pv.param.c_str()); - - for (const auto& at : m_matchPairs) - printfd(__FILE__, "Key: '%s', Value: '%s', Type: %d\n", at.first.c_str(), at.second.value.c_str(), at.second.type); - } - } return 0; } From 91b514a7c4e1151959f8a527bb3b369d5856e50b Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Thu, 12 Jun 2025 17:06:15 +0300 Subject: [PATCH 132/186] Radius. Attributes of auth/send, autz/send, autz/match changed. --- .../linux/etc/stargazer/conf-available.d/mod_radius.conf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/projects/stargazer/inst/linux/etc/stargazer/conf-available.d/mod_radius.conf b/projects/stargazer/inst/linux/etc/stargazer/conf-available.d/mod_radius.conf index adae7a54..7373af21 100644 --- a/projects/stargazer/inst/linux/etc/stargazer/conf-available.d/mod_radius.conf +++ b/projects/stargazer/inst/linux/etc/stargazer/conf-available.d/mod_radius.conf @@ -18,12 +18,12 @@ # Port = 1812 - send = "Framed-IP-Address = currip, Framed-Protocol = \'PPP\'" + send = "Framed-IP-Address = currip, Service-Type = \'Framed-User\'" match = "Calling-Station-Id = userdata0" - send = "Framed-IP-Address = currip, Framed-Protocol = \'PPP\'" - match = "Calling-Station-Id = userdata0" + send = "Framed-IP-Address = currip, Service-Type = \'Login-User\'" + match = "User-Name = login, User-Password = password" From 63ba77a5863f799015ecef7781f72fbd2ef49488 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Thu, 12 Jun 2025 18:08:48 +0300 Subject: [PATCH 133/186] Radius. ParseSectionsAttr function name changed to ParseRyles. --- projects/stargazer/plugins/other/radius/radius.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/stargazer/plugins/other/radius/radius.h b/projects/stargazer/plugins/other/radius/radius.h index 3807d699..7bc6de14 100644 --- a/projects/stargazer/plugins/other/radius/radius.h +++ b/projects/stargazer/plugins/other/radius/radius.h @@ -46,7 +46,7 @@ namespace STG const std::vector>& GetSendPairs() const { return m_sendPairs; } private: - std::vector> ParseSectionsAttr(const std::string& value, const std::string& paramName); + std::vector> ParseRules(const std::string& value, const std::string& paramName); void MakeKeyValuePairs(const ModuleSettings & s, ParamValue pv, const std::string& paramName); std::string m_errorStr; From c79b7c10159a76a35f2c1763e58d26cccf2a0b71 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Thu, 12 Jun 2025 18:16:59 +0300 Subject: [PATCH 134/186] Radius. ParseSectionsAttr function name definition and call changed to ParseRyles. --- projects/stargazer/plugins/other/radius/radius.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index f98a8fdc..152ec441 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -18,7 +18,7 @@ extern "C" STG::Plugin* GetPlugin() return &plugin; } -std::vector> RAD_SETTINGS::ParseSectionsAttr(const std::string& value, const std::string& paramName) +std::vector> RAD_SETTINGS::ParseRules(const std::string& value, const std::string& paramName) { using tokenizer = boost::tokenizer>; boost::char_separator sep(","); @@ -52,8 +52,8 @@ std::vector> RAD_SETTINGS::ParseSectionsAttr(c } else if ((valueName.front() == '\'' && valueName.back() != '\'') || (valueName.front() != '\'' && valueName.back() == '\'')) { - m_logger("Error ParseSectionsAttr: '%s' attribute parameter value is invalid.\n", paramName.c_str()); - printfd(__FILE__, "Error ParseSectionsAttr: '%s' attribute parameter value is invalid.\n", paramName.c_str()); + m_logger("Error ParseRules: '%s' attribute parameter value is invalid.\n", paramName.c_str()); + printfd(__FILE__, "Error ParseRules: '%s' attribute parameter value is invalid.\n", paramName.c_str()); return {}; } res.emplace_back(keyValue[0], AttrValue{valueName, type}); @@ -72,7 +72,7 @@ void RAD_SETTINGS::MakeKeyValuePairs(const ModuleSettings & s, ParamValue pv, co { printfd(__FILE__, "ParseSettings: The send value of param '%s': '%s'\n", paramName.c_str(), pva->value[0].c_str()); - m_sendPairs = ParseSectionsAttr(pva->value[0], pv.param); + m_sendPairs = ParseRules(pva->value[0], pv.param); for (const auto& at : m_sendPairs) printfd(__FILE__, "Key: '%s', Value: '%s', Type: %d\n", at.first.c_str(), at.second.value.c_str(), at.second.type); @@ -84,7 +84,7 @@ void RAD_SETTINGS::MakeKeyValuePairs(const ModuleSettings & s, ParamValue pv, co { printfd(__FILE__, "ParseSettings: The match value of param '%s': '%s'\n", paramName.c_str(), pva->value[0].c_str()); - m_matchPairs = ParseSectionsAttr(pva->value[0], pv.param.c_str()); + m_matchPairs = ParseRules(pva->value[0], pv.param.c_str()); for (const auto& at : m_matchPairs) printfd(__FILE__, "Key: '%s', Value: '%s', Type: %d\n", at.first.c_str(), at.second.value.c_str(), at.second.type); From 92eff021ae36206e2919b928059139ef293d6cc1 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Fri, 13 Jun 2025 18:19:04 +0300 Subject: [PATCH 135/186] Radius. Extra printfd function call removed in MakeKeyValuePairs functions. --- projects/stargazer/plugins/other/radius/radius.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 152ec441..17619ad9 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -70,8 +70,6 @@ void RAD_SETTINGS::MakeKeyValuePairs(const ModuleSettings & s, ParamValue pv, co auto pva = std::find(pvi->sections.begin(), pvi->sections.end(), pv); if (pva != pvi->sections.end() && !pva->value.empty()) { - printfd(__FILE__, "ParseSettings: The send value of param '%s': '%s'\n", paramName.c_str(), pva->value[0].c_str()); - m_sendPairs = ParseRules(pva->value[0], pv.param); for (const auto& at : m_sendPairs) @@ -82,8 +80,6 @@ void RAD_SETTINGS::MakeKeyValuePairs(const ModuleSettings & s, ParamValue pv, co pva = std::find(pvi->sections.begin(), pvi->sections.end(), pv); if (pva != pvi->sections.end() && !pva->value.empty()) { - printfd(__FILE__, "ParseSettings: The match value of param '%s': '%s'\n", paramName.c_str(), pva->value[0].c_str()); - m_matchPairs = ParseRules(pva->value[0], pv.param.c_str()); for (const auto& at : m_matchPairs) From 9f96684c10aca9134b4179ce25a18936ff37b2af Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Thu, 19 Jun 2025 15:38:43 +0300 Subject: [PATCH 136/186] Radius. The ShowRules, GetSendPairsAuth, GetMatchPairsAuth, GetSendPairsAutz, GetMatchPairsAutz functions declaration added. The m_sendPairs, m_matchPairs class members removed. The m_sendPairsAuth, m_matchPairsAuth, m_sendPairsAutz, m_matchPairsAutz class members added. --- projects/stargazer/plugins/other/radius/radius.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.h b/projects/stargazer/plugins/other/radius/radius.h index 7bc6de14..378cba5b 100644 --- a/projects/stargazer/plugins/other/radius/radius.h +++ b/projects/stargazer/plugins/other/radius/radius.h @@ -43,18 +43,24 @@ namespace STG 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::vector>& GetSendPairs() const { return m_sendPairs; } + const std::vector>& GetSendPairsAuth() const { return m_sendPairsAuth; } + const std::vector>& GetMatchPairsAuth() const { return m_matchPairsAuth; } + const std::vector>& GetSendPairsAutz() const { return m_sendPairsAutz; } + const std::vector>& GetMatchPairsAutz() const { return m_matchPairsAuth; } private: std::vector> ParseRules(const std::string& value, const std::string& paramName); + std::string ShowRules(const std::vector> mvector); void MakeKeyValuePairs(const ModuleSettings & s, ParamValue pv, const std::string& paramName); std::string m_errorStr; uint16_t m_port; std::string m_dictionaries; std::string m_secret; - std::vector> m_sendPairs; - std::vector> m_matchPairs; + std::vector> m_sendPairsAuth; + std::vector> m_matchPairsAuth; + std::vector> m_sendPairsAutz; + std::vector> m_matchPairsAutz; PluginLogger m_logger; }; From ddcaf6fa3ce8c62a6418fa89dd3b0f82360dce0e Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Thu, 19 Jun 2025 15:50:10 +0300 Subject: [PATCH 137/186] Radius. The ShowRules function definition added and its call in MakeKeyValuePairs function added. --- .../stargazer/plugins/other/radius/radius.cpp | 46 +++++++++++++++---- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 17619ad9..559399d9 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -61,6 +61,24 @@ std::vector> RAD_SETTINGS::ParseRules(const st return res; } +std::string RAD_SETTINGS::ShowRules(const std::vector> mvector) +{ + std::string strRules; + size_t i = 0; + for (const auto& at : mvector) + { + if (at.second.type == AttrValue::Type::PARAM_NAME) + strRules.append(at.first + " = " + at.second.value); + else + strRules.append(at.first + " = " + "'" + at.second.value + "'"); + + if (i != mvector.size() - 1) + strRules.append(", "); + ++i; + } + return strRules; +} + void RAD_SETTINGS::MakeKeyValuePairs(const ModuleSettings & s, ParamValue pv, const std::string& paramName) { auto pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv); @@ -70,20 +88,32 @@ void RAD_SETTINGS::MakeKeyValuePairs(const ModuleSettings & s, ParamValue pv, co auto pva = std::find(pvi->sections.begin(), pvi->sections.end(), pv); if (pva != pvi->sections.end() && !pva->value.empty()) { - m_sendPairs = ParseRules(pva->value[0], pv.param); - - for (const auto& at : m_sendPairs) - printfd(__FILE__, "Key: '%s', Value: '%s', Type: %d\n", at.first.c_str(), at.second.value.c_str(), at.second.type); + if (paramName == "auth") + { + m_sendPairsAuth = ParseRules(pva->value[0], pv.param); + printfd(__FILE__," auth.send = \"%s\"\n", ShowRules(m_sendPairsAuth).c_str()); + } + else if (paramName == "autz") + { + m_sendPairsAutz = ParseRules(pva->value[0], pv.param); + printfd(__FILE__," autz.send = \"%s\"\n", ShowRules(m_sendPairsAutz).c_str()); + } } pv.param = "match"; pva = std::find(pvi->sections.begin(), pvi->sections.end(), pv); if (pva != pvi->sections.end() && !pva->value.empty()) { - m_matchPairs = ParseRules(pva->value[0], pv.param.c_str()); - - for (const auto& at : m_matchPairs) - printfd(__FILE__, "Key: '%s', Value: '%s', Type: %d\n", at.first.c_str(), at.second.value.c_str(), at.second.type); + if (paramName == "auth") + { + m_matchPairsAuth = ParseRules(pva->value[0], pv.param); + printfd(__FILE__," auth.match = \"%s\"\n", ShowRules(m_matchPairsAuth).c_str()); + } + else if (paramName == "autz") + { + m_matchPairsAutz = ParseRules(pva->value[0], pv.param); + printfd(__FILE__," autz.match = \"%s\"\n", ShowRules(m_matchPairsAutz).c_str()); + } } } } From 3a559a6a7f5ddbfa789c2838281e8193a82131cf Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Fri, 20 Jun 2025 14:13:56 +0300 Subject: [PATCH 138/186] Radius. The strRules string creating fixed and strRules string renamed to result in the ShowRules function. --- projects/stargazer/plugins/other/radius/radius.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 559399d9..5589ed70 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -63,20 +63,20 @@ std::vector> RAD_SETTINGS::ParseRules(const st std::string RAD_SETTINGS::ShowRules(const std::vector> mvector) { - std::string strRules; + std::string result; size_t i = 0; for (const auto& at : mvector) { if (at.second.type == AttrValue::Type::PARAM_NAME) - strRules.append(at.first + " = " + at.second.value); + result.append(at.first + " = " + at.second.value); else - strRules.append(at.first + " = " + "'" + at.second.value + "'"); + result.append(at.first + " = '" + at.second.value + "'"); if (i != mvector.size() - 1) - strRules.append(", "); + result.append(", "); ++i; } - return strRules; + return result; } void RAD_SETTINGS::MakeKeyValuePairs(const ModuleSettings & s, ParamValue pv, const std::string& paramName) From 646790b7e04733280d1a84aa3a9c6bad51450000 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Fri, 20 Jun 2025 17:01:28 +0300 Subject: [PATCH 139/186] Radius. Parameter name changed to attributes and & added to parameter in the ParseRules function. --- projects/stargazer/plugins/other/radius/radius.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/stargazer/plugins/other/radius/radius.h b/projects/stargazer/plugins/other/radius/radius.h index 378cba5b..50a02247 100644 --- a/projects/stargazer/plugins/other/radius/radius.h +++ b/projects/stargazer/plugins/other/radius/radius.h @@ -50,7 +50,7 @@ namespace STG private: std::vector> ParseRules(const std::string& value, const std::string& paramName); - std::string ShowRules(const std::vector> mvector); + std::string ShowRules(const std::vector>& attributes); void MakeKeyValuePairs(const ModuleSettings & s, ParamValue pv, const std::string& paramName); std::string m_errorStr; From dab9c61057f7820bb72f07209692c67ec4bda468 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Fri, 20 Jun 2025 17:07:16 +0300 Subject: [PATCH 140/186] Radius. The ShowRules function definition changed. Parameter name changed to attributes and & added to parameter in the ShowRules function. --- .../stargazer/plugins/other/radius/radius.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 5589ed70..43734a24 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -61,20 +61,21 @@ std::vector> RAD_SETTINGS::ParseRules(const st return res; } -std::string RAD_SETTINGS::ShowRules(const std::vector> mvector) +std::string RAD_SETTINGS::ShowRules(const std::vector>& attributes) { std::string result; - size_t i = 0; - for (const auto& at : mvector) + bool first = true; + for (const auto& at : attributes) { + if (first) + first = false; + else + result += ", "; + if (at.second.type == AttrValue::Type::PARAM_NAME) result.append(at.first + " = " + at.second.value); else result.append(at.first + " = '" + at.second.value + "'"); - - if (i != mvector.size() - 1) - result.append(", "); - ++i; } return result; } From 3b7bc48406a94a8d049fe48ec4a5c6ac9585cd52 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Wed, 25 Jun 2025 17:15:54 +0300 Subject: [PATCH 141/186] Radius. The struct ASection added. The getAuth, getAutz, parseASection function declaration added. Class member m_auth, m_autz added. Unnecessary code removed. --- .../stargazer/plugins/other/radius/radius.h | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.h b/projects/stargazer/plugins/other/radius/radius.h index 50a02247..61fc50d0 100644 --- a/projects/stargazer/plugins/other/radius/radius.h +++ b/projects/stargazer/plugins/other/radius/radius.h @@ -37,30 +37,35 @@ namespace STG Type type; }; + struct ASection + { + using Pairs = std::vector>; + 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 std::vector>& GetSendPairsAuth() const { return m_sendPairsAuth; } - const std::vector>& GetMatchPairsAuth() const { return m_matchPairsAuth; } - const std::vector>& GetSendPairsAutz() const { return m_sendPairsAutz; } - const std::vector>& GetMatchPairsAutz() const { return m_matchPairsAuth; } + const ASection& getAuth() const { return m_auth; } + const ASection& getAutz() const { return m_autz; } private: std::vector> ParseRules(const std::string& value, const std::string& paramName); std::string ShowRules(const std::vector>& attributes); - void MakeKeyValuePairs(const ModuleSettings & s, ParamValue pv, const std::string& paramName); + ASection parseASection(const std::vector& conf); std::string m_errorStr; uint16_t m_port; std::string m_dictionaries; std::string m_secret; - std::vector> m_sendPairsAuth; - std::vector> m_matchPairsAuth; - std::vector> m_sendPairsAutz; - std::vector> m_matchPairsAutz; + + ASection m_auth; + ASection m_autz; + PluginLogger m_logger; }; From 4078c176f1824f0e4ee8e4630c17f71909aef56f Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Wed, 25 Jun 2025 17:35:18 +0300 Subject: [PATCH 142/186] Radius. The using ASection for alias added. The parseASection function definition and call added, MakeKeyValuePairs function removed, ParseSettings function changed. Extra printfd function added. --- .../stargazer/plugins/other/radius/radius.cpp | 73 +++++++++---------- 1 file changed, 35 insertions(+), 38 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 43734a24..adb8aa15 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -11,6 +11,7 @@ using STG::RADIUS; using STG::RAD_SETTINGS; using AttrValue = RAD_SETTINGS::AttrValue; +using ASection = RAD_SETTINGS::ASection; extern "C" STG::Plugin* GetPlugin() { @@ -58,6 +59,7 @@ std::vector> RAD_SETTINGS::ParseRules(const st } res.emplace_back(keyValue[0], AttrValue{valueName, type}); } + printfd(__FILE__, "Extra. parseRules end\n"); return res; } @@ -80,43 +82,26 @@ std::string RAD_SETTINGS::ShowRules(const std::vector& conf) { - auto pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv); - if (pvi != s.moduleParams.end()) + printfd(__FILE__, "Extra. parseASection start\n"); + ASection res; + const auto mit = std::find(conf.begin(), conf.end(), ParamValue("match", {})); + if (mit != conf.end()) { - pv.param = "send"; - auto pva = std::find(pvi->sections.begin(), pvi->sections.end(), pv); - if (pva != pvi->sections.end() && !pva->value.empty()) - { - if (paramName == "auth") - { - m_sendPairsAuth = ParseRules(pva->value[0], pv.param); - printfd(__FILE__," auth.send = \"%s\"\n", ShowRules(m_sendPairsAuth).c_str()); - } - else if (paramName == "autz") - { - m_sendPairsAutz = ParseRules(pva->value[0], pv.param); - printfd(__FILE__," autz.send = \"%s\"\n", ShowRules(m_sendPairsAutz).c_str()); - } - } - - pv.param = "match"; - pva = std::find(pvi->sections.begin(), pvi->sections.end(), pv); - if (pva != pvi->sections.end() && !pva->value.empty()) - { - if (paramName == "auth") - { - m_matchPairsAuth = ParseRules(pva->value[0], pv.param); - printfd(__FILE__," auth.match = \"%s\"\n", ShowRules(m_matchPairsAuth).c_str()); - } - else if (paramName == "autz") - { - m_matchPairsAutz = ParseRules(pva->value[0], pv.param); - printfd(__FILE__," autz.match = \"%s\"\n", ShowRules(m_matchPairsAutz).c_str()); - } - } + printfd(__FILE__, "Extra. parseASection into if for match before\n"); + res.match = ParseRules(mit->value[0], mit->param); + printfd(__FILE__, "Extra. parseASection into if for match after\n"); + printfd(__FILE__, "Extra. parseASection into if mit->param: '%s'\n", mit->param.c_str()); + printfd(__FILE__, "Extra. parseASection into if mit->value[0]: '%s'\n", mit->value[0].c_str()); } + + printfd(__FILE__, "Extra. parseASection after match\n"); + const auto sit = std::find(conf.begin(), conf.end(), ParamValue("send", {})); + if (sit != conf.end()) + res.send = ParseRules(sit->value[0], sit->param); + + printfd(__FILE__, "Extra. parseASection end\n"); } RAD_SETTINGS::RAD_SETTINGS() @@ -159,11 +144,23 @@ int RAD_SETTINGS::ParseSettings(const ModuleSettings & s) if (pvi != s.moduleParams.end() && !pvi->value.empty()) m_dictionaries = pvi->value[0]; - pv.param = "auth"; - MakeKeyValuePairs(s, pv, pv.param); + const auto authIt = std::find(s.moduleParams.begin(), s.moduleParams.end(), ParamValue("auth", {})); + printfd(__FILE__, "Extra. ParseSettings before parseASection call for m_ayth\n"); + if (authIt != s.moduleParams.end()) + { + printfd(__FILE__, "Extra. ParseSettings into if before parseASection call for m_ayth\n"); + m_auth = parseASection(authIt->sections); - pv.param = "autz"; - MakeKeyValuePairs(s, pv, pv.param); + printfd(__FILE__, "Extra. ParseSettings into if after parseASection call for m_ayth\n"); + } + printfd(__FILE__, "Extra. ParseSettings after parseASection call for m_ayth\n"); + const auto autzIt = std::find(s.moduleParams.begin(), s.moduleParams.end(), ParamValue("autz", {})); + if (autzIt != s.moduleParams.end()) + m_autz = parseASection(autzIt->sections); + printfd(__FILE__, " auth.match = \"%s\"\n", ShowRules(m_auth.match).c_str()); + printfd(__FILE__, " auth.send = \"%s\"\n", ShowRules(m_auth.send).c_str()); + printfd(__FILE__, " autz.match = \"%s\"\n", ShowRules(m_autz.match).c_str()); + printfd(__FILE__, " autz.send = \"%s\"\n", ShowRules(m_autz.send).c_str()); return 0; } From d1d90e133800a1ab0a9b07dcc874beba6144b88d Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Thu, 26 Jun 2025 15:33:19 +0300 Subject: [PATCH 143/186] Radius. The return added to parseASection function. Extra printfd functions removed. --- .../stargazer/plugins/other/radius/radius.cpp | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index adb8aa15..ecf6534d 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -59,7 +59,6 @@ std::vector> RAD_SETTINGS::ParseRules(const st } res.emplace_back(keyValue[0], AttrValue{valueName, type}); } - printfd(__FILE__, "Extra. parseRules end\n"); return res; } @@ -84,24 +83,16 @@ std::string RAD_SETTINGS::ShowRules(const std::vector& conf) { - printfd(__FILE__, "Extra. parseASection start\n"); ASection res; const auto mit = std::find(conf.begin(), conf.end(), ParamValue("match", {})); if (mit != conf.end()) - { - printfd(__FILE__, "Extra. parseASection into if for match before\n"); res.match = ParseRules(mit->value[0], mit->param); - printfd(__FILE__, "Extra. parseASection into if for match after\n"); - printfd(__FILE__, "Extra. parseASection into if mit->param: '%s'\n", mit->param.c_str()); - printfd(__FILE__, "Extra. parseASection into if mit->value[0]: '%s'\n", mit->value[0].c_str()); - } - printfd(__FILE__, "Extra. parseASection after match\n"); const auto sit = std::find(conf.begin(), conf.end(), ParamValue("send", {})); if (sit != conf.end()) res.send = ParseRules(sit->value[0], sit->param); - printfd(__FILE__, "Extra. parseASection end\n"); + return res; } RAD_SETTINGS::RAD_SETTINGS() @@ -145,18 +136,13 @@ int RAD_SETTINGS::ParseSettings(const ModuleSettings & s) m_dictionaries = pvi->value[0]; const auto authIt = std::find(s.moduleParams.begin(), s.moduleParams.end(), ParamValue("auth", {})); - printfd(__FILE__, "Extra. ParseSettings before parseASection call for m_ayth\n"); if (authIt != s.moduleParams.end()) - { - printfd(__FILE__, "Extra. ParseSettings into if before parseASection call for m_ayth\n"); m_auth = parseASection(authIt->sections); - printfd(__FILE__, "Extra. ParseSettings into if after parseASection call for m_ayth\n"); - } - printfd(__FILE__, "Extra. ParseSettings after parseASection call for m_ayth\n"); const auto autzIt = std::find(s.moduleParams.begin(), s.moduleParams.end(), ParamValue("autz", {})); if (autzIt != s.moduleParams.end()) m_autz = parseASection(autzIt->sections); + printfd(__FILE__, " auth.match = \"%s\"\n", ShowRules(m_auth.match).c_str()); printfd(__FILE__, " auth.send = \"%s\"\n", ShowRules(m_auth.send).c_str()); printfd(__FILE__, " autz.match = \"%s\"\n", ShowRules(m_autz.match).c_str()); From a744e3020a0c6d1c54b22c70683797cf33e6b425 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Mon, 7 Jul 2025 16:24:12 +0300 Subject: [PATCH 144/186] Radius. GIT_TAG changed to 1.1.3 in the ExternalProject_Add for async-radius. --- projects/stargazer/plugins/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/stargazer/plugins/CMakeLists.txt b/projects/stargazer/plugins/CMakeLists.txt index c8dd8f50..fc030b67 100644 --- a/projects/stargazer/plugins/CMakeLists.txt +++ b/projects/stargazer/plugins/CMakeLists.txt @@ -23,7 +23,7 @@ if ( BUILD_MOD_RADIUS ) ExternalProject_Add ( async-radius GIT_REPOSITORY https://github.com/madf/async-radius.git - GIT_TAG 1.1.2 + GIT_TAG 1.1.3 GIT_SHALLOW true INSTALL_COMMAND "" CMAKE_ARGS -DCMAKE_CXX_FLAGS=-fPIC ) From fccd8cd7e6360bf03cb0d1b32f6ca616f894bc3c Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Tue, 8 Jul 2025 15:20:16 +0300 Subject: [PATCH 145/186] Radius. The m_ioService class member replaced by m_ioContext in class Radius. --- projects/stargazer/plugins/other/radius/radius.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/stargazer/plugins/other/radius/radius.h b/projects/stargazer/plugins/other/radius/radius.h index 61fc50d0..84ffc8f0 100644 --- a/projects/stargazer/plugins/other/radius/radius.h +++ b/projects/stargazer/plugins/other/radius/radius.h @@ -97,7 +97,7 @@ namespace STG private: std::mutex m_mutex; - boost::asio::io_service m_ioService; + boost::asio::io_context m_ioContext; int Run(std::stop_token token); mutable std::string m_errorStr; From b5b82999f3cce4eed6902a9a75cf996bb2c594a0 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Tue, 8 Jul 2025 15:26:03 +0300 Subject: [PATCH 146/186] Radius. The m_ioService class member replaced by m_ioContext in the function Run. --- projects/stargazer/plugins/other/radius/radius.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index ecf6534d..3254b8c4 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -211,8 +211,8 @@ int RADIUS::Run(std::stop_token token) try { if (!m_server) - m_server = std::make_unique(m_ioService, m_radSettings.GetSecret(), m_radSettings.GetPort(), m_radSettings.GetDictionaries(), std::move(token), m_logger, m_users); - m_ioService.run(); + m_server = std::make_unique(m_ioContext, m_radSettings.GetSecret(), m_radSettings.GetPort(), m_radSettings.GetDictionaries(), std::move(token), m_logger, m_users); + m_ioContext.run(); } catch (const std::exception& e) { From 49f93695df14a1067eb0a7a7da12a7a816860618 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Tue, 8 Jul 2025 15:30:45 +0300 Subject: [PATCH 147/186] Radius. Parameter io_service replaced by io_context in the constructor Server. --- projects/stargazer/plugins/other/radius/server.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/stargazer/plugins/other/radius/server.h b/projects/stargazer/plugins/other/radius/server.h index 7abcff3d..d4efef98 100644 --- a/projects/stargazer/plugins/other/radius/server.h +++ b/projects/stargazer/plugins/other/radius/server.h @@ -16,7 +16,7 @@ namespace STG class Server { public: - Server(boost::asio::io_service& io_service, const std::string& secret, uint16_t port, const std::string& filePath, std::stop_token token, PluginLogger& logger, Users* users); + Server(boost::asio::io_context& io_context, const std::string& secret, uint16_t port, const std::string& filePath, std::stop_token token, PluginLogger& logger, Users* users); void stop(); private: RadProto::Packet makeResponse(const RadProto::Packet& request); From 0d97b85f81443cd6e93cf615b70a8358770dca47 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Tue, 8 Jul 2025 15:36:14 +0300 Subject: [PATCH 148/186] Radius. Parameter io_service replaced by io_context in the constructor Server definition. --- projects/stargazer/plugins/other/radius/server.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/server.cpp b/projects/stargazer/plugins/other/radius/server.cpp index 375fcd69..9e6766d5 100644 --- a/projects/stargazer/plugins/other/radius/server.cpp +++ b/projects/stargazer/plugins/other/radius/server.cpp @@ -11,8 +11,8 @@ using STG::Server; using boost::system::error_code; -Server::Server(boost::asio::io_service& io_service, const std::string& secret, uint16_t port, const std::string& filePath, std::stop_token token, PluginLogger& logger, Users* users) - : m_radius(io_service, secret, port), +Server::Server(boost::asio::io_context& io_context, const std::string& secret, uint16_t port, const std::string& filePath, std::stop_token token, PluginLogger& logger, Users* users) + : m_radius(io_context, secret, port), m_dictionaries(filePath), m_users(users), m_token(std::move(token)), From e51985c446fb109349b16c7ccfb49389051a3c54 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Wed, 9 Jul 2025 14:12:07 +0300 Subject: [PATCH 149/186] Radius. Parameters msg, ip commented out in the SendMessage function. --- projects/stargazer/plugins/other/radius/radius.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/stargazer/plugins/other/radius/radius.h b/projects/stargazer/plugins/other/radius/radius.h index 84ffc8f0..f9d4f628 100644 --- a/projects/stargazer/plugins/other/radius/radius.h +++ b/projects/stargazer/plugins/other/radius/radius.h @@ -92,7 +92,7 @@ namespace STG 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; } + int SendMessage(const Message& /*msg*/, uint32_t /*ip*/) const override { return 0; } private: std::mutex m_mutex; From 5fdde108cf2d9a7b8e61a098a693e80bbfc129aa Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Wed, 9 Jul 2025 14:26:03 +0300 Subject: [PATCH 150/186] Radius. Variable 'sep' declared 'const' in ParseRules function. --- projects/stargazer/plugins/other/radius/radius.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 3254b8c4..0aeb2d4c 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -22,7 +22,7 @@ extern "C" STG::Plugin* GetPlugin() std::vector> RAD_SETTINGS::ParseRules(const std::string& value, const std::string& paramName) { using tokenizer = boost::tokenizer>; - boost::char_separator sep(","); + const boost::char_separator sep(","); tokenizer tokens(value, sep); From 2981417aa70b4dfd4ab3c0c10eefdf9db1a9b478 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Wed, 9 Jul 2025 14:35:20 +0300 Subject: [PATCH 151/186] Radius. Variables 'tokens', 'sp', 'tok' declared 'const' in ParseRules function. --- projects/stargazer/plugins/other/radius/radius.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 0aeb2d4c..db3f3009 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -24,13 +24,13 @@ std::vector> RAD_SETTINGS::ParseRules(const st using tokenizer = boost::tokenizer>; const boost::char_separator sep(","); - tokenizer tokens(value, sep); + const tokenizer tokens(value, sep); std::vector> res; for (const auto& token : tokens) { - boost::char_separator sp(" ="); - tokenizer tok(token, sp); + const boost::char_separator sp(" ="); + const tokenizer tok(token, sp); std::vector keyValue; for (const auto& t : tok) From a650b2aa97e8f9d018cddaec5bc82ea0173c5a43 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Wed, 9 Jul 2025 14:45:17 +0300 Subject: [PATCH 152/186] Radius. ShowRules function declaration removed from class RAD_SETTINGS. --- projects/stargazer/plugins/other/radius/radius.h | 1 - 1 file changed, 1 deletion(-) diff --git a/projects/stargazer/plugins/other/radius/radius.h b/projects/stargazer/plugins/other/radius/radius.h index f9d4f628..8ff7e6e6 100644 --- a/projects/stargazer/plugins/other/radius/radius.h +++ b/projects/stargazer/plugins/other/radius/radius.h @@ -55,7 +55,6 @@ namespace STG private: std::vector> ParseRules(const std::string& value, const std::string& paramName); - std::string ShowRules(const std::vector>& attributes); ASection parseASection(const std::vector& conf); std::string m_errorStr; From 72e22dc9626fcab34e48565de3fbead1667f962b Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Wed, 9 Jul 2025 14:48:27 +0300 Subject: [PATCH 153/186] Radius. ShowRules function definition is made as a free function. --- .../stargazer/plugins/other/radius/radius.cpp | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index db3f3009..76040fef 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -19,6 +19,25 @@ extern "C" STG::Plugin* GetPlugin() return &plugin; } +std::string ShowRules(const std::vector>& attributes) +{ + std::string result; + bool first = true; + for (const auto& at : attributes) + { + if (first) + first = false; + else + result += ", "; + + if (at.second.type == AttrValue::Type::PARAM_NAME) + result.append(at.first + " = " + at.second.value); + else + result.append(at.first + " = '" + at.second.value + "'"); + } + return result; +} + std::vector> RAD_SETTINGS::ParseRules(const std::string& value, const std::string& paramName) { using tokenizer = boost::tokenizer>; @@ -62,25 +81,6 @@ std::vector> RAD_SETTINGS::ParseRules(const st return res; } -std::string RAD_SETTINGS::ShowRules(const std::vector>& attributes) -{ - std::string result; - bool first = true; - for (const auto& at : attributes) - { - if (first) - first = false; - else - result += ", "; - - if (at.second.type == AttrValue::Type::PARAM_NAME) - result.append(at.first + " = " + at.second.value); - else - result.append(at.first + " = '" + at.second.value + "'"); - } - return result; -} - ASection RAD_SETTINGS::parseASection(const std::vector& conf) { ASection res; From f26626c093b641ab4931ccd67596626d6d46a95e Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Thu, 10 Jul 2025 15:25:10 +0300 Subject: [PATCH 154/186] Radius. ShowRules function definition is placed in the anonymous namespace. --- .../stargazer/plugins/other/radius/radius.cpp | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 76040fef..705cd448 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -19,23 +19,26 @@ extern "C" STG::Plugin* GetPlugin() return &plugin; } -std::string ShowRules(const std::vector>& attributes) +namespace { - std::string result; - bool first = true; - for (const auto& at : attributes) + std::string ShowRules(const std::vector>& attributes) { - if (first) - first = false; - else - result += ", "; - - if (at.second.type == AttrValue::Type::PARAM_NAME) - result.append(at.first + " = " + at.second.value); - else - result.append(at.first + " = '" + at.second.value + "'"); + std::string result; + bool first = true; + for (const auto& at : attributes) + { + if (first) + first = false; + else + result += ", "; + + if (at.second.type == AttrValue::Type::PARAM_NAME) + result.append(at.first + " = " + at.second.value); + else + result.append(at.first + " = '" + at.second.value + "'"); + } + return result; } - return result; } std::vector> RAD_SETTINGS::ParseRules(const std::string& value, const std::string& paramName) From d31ccb3da97357087910e98ef3a603586cc9b160 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Thu, 10 Jul 2025 15:40:40 +0300 Subject: [PATCH 155/186] Radius. The code for determining the first element of vector changed in the function ShowRules. --- projects/stargazer/plugins/other/radius/radius.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 705cd448..0b8ab1e5 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -24,12 +24,9 @@ namespace std::string ShowRules(const std::vector>& attributes) { std::string result; - bool first = true; for (const auto& at : attributes) { - if (first) - first = false; - else + if (!result.empty()) result += ", "; if (at.second.type == AttrValue::Type::PARAM_NAME) From 0128fa275f518fe0255fbc5ba10f1b0f01864c3b Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Thu, 10 Jul 2025 15:50:17 +0300 Subject: [PATCH 156/186] Radius. Function SetUsers declaration is made as override in the class Radius. --- projects/stargazer/plugins/other/radius/radius.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/stargazer/plugins/other/radius/radius.h b/projects/stargazer/plugins/other/radius/radius.h index 8ff7e6e6..80e032a8 100644 --- a/projects/stargazer/plugins/other/radius/radius.h +++ b/projects/stargazer/plugins/other/radius/radius.h @@ -75,7 +75,7 @@ namespace STG RADIUS(const RADIUS&) = delete; RADIUS& operator=(const RADIUS&) = delete; - void SetUsers(Users* u) { m_users = u; } + void SetUsers(Users* u) override { m_users = u; } void SetSettings(const ModuleSettings& s) override { m_settings = s; } int ParseSettings() override; From 498c75af8e5278fdbab8fdeca82372cf28745f0f Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Thu, 10 Jul 2025 15:58:56 +0300 Subject: [PATCH 157/186] Radius. Header file added. --- projects/stargazer/plugins/other/radius/radius.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 0b8ab1e5..68291dcf 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include using STG::RADIUS; From 8d1f71586c15e8860dfe1451bc95d34f70070292 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Mon, 21 Jul 2025 14:58:57 +0300 Subject: [PATCH 158/186] Radius. The rad_settings.cpp file name added to add_library for MODULE radius. --- projects/stargazer/plugins/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/projects/stargazer/plugins/CMakeLists.txt b/projects/stargazer/plugins/CMakeLists.txt index fc030b67..ba4a6d14 100644 --- a/projects/stargazer/plugins/CMakeLists.txt +++ b/projects/stargazer/plugins/CMakeLists.txt @@ -15,7 +15,8 @@ if ( BUILD_MOD_RADIUS ) find_package ( Boost REQUIRED ) add_library ( mod_radius MODULE other/radius/radius.cpp - other/radius/server.cpp) + other/radius/server.cpp + other/radius/rad_settings.cpp) target_link_libraries ( mod_radius PRIVATE scriptexecuter logger common ) set_target_properties ( mod_radius PROPERTIES PREFIX "" ) From ae4014b5f4b9a302c9bdcbf34cad2553869b0854 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Mon, 21 Jul 2025 15:17:41 +0300 Subject: [PATCH 159/186] Radius. Header file "rad_settings.h" added. RAD_SETTINGS class declaration removed, struct Settings forward declaration removed. --- .../stargazer/plugins/other/radius/radius.h | 51 +------------------ 1 file changed, 1 insertion(+), 50 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.h b/projects/stargazer/plugins/other/radius/radius.h index 80e032a8..583eb94f 100644 --- a/projects/stargazer/plugins/other/radius/radius.h +++ b/projects/stargazer/plugins/other/radius/radius.h @@ -2,6 +2,7 @@ #include "stg/auth.h" #include "stg/plugin.h" +#include "rad_settings.h" #include "stg/module_settings.h" #include "stg/subscriptions.h" #include "stg/logger.h" @@ -16,58 +17,8 @@ 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>; - 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> ParseRules(const std::string& value, const std::string& paramName); - ASection parseASection(const std::vector& 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: From fa8aca994701eff96bdd58370bc7b0927ba92f91 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Mon, 21 Jul 2025 15:42:39 +0300 Subject: [PATCH 160/186] Radius. Header files , , , , removed. Extra using declaration removed. Functions definition of class RAD_SETTINGS removed. Parameter m_radSettings added to Server constructor call. --- .../stargazer/plugins/other/radius/radius.cpp | 142 +----------------- 1 file changed, 1 insertion(+), 141 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 68291dcf..b12efe1c 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -1,18 +1,10 @@ #include "radius.h" #include "radproto/error.h" #include "stg/common.h" -#include -#include #include -#include -#include -#include using STG::RADIUS; -using STG::RAD_SETTINGS; -using AttrValue = RAD_SETTINGS::AttrValue; -using ASection = RAD_SETTINGS::ASection; extern "C" STG::Plugin* GetPlugin() { @@ -20,138 +12,6 @@ extern "C" STG::Plugin* GetPlugin() return &plugin; } -namespace -{ - std::string ShowRules(const std::vector>& attributes) - { - std::string result; - for (const auto& at : attributes) - { - if (!result.empty()) - result += ", "; - - if (at.second.type == AttrValue::Type::PARAM_NAME) - result.append(at.first + " = " + at.second.value); - else - result.append(at.first + " = '" + at.second.value + "'"); - } - return result; - } -} - -std::vector> RAD_SETTINGS::ParseRules(const std::string& value, const std::string& paramName) -{ - using tokenizer = boost::tokenizer>; - const boost::char_separator sep(","); - - const tokenizer tokens(value, sep); - - std::vector> res; - for (const auto& token : tokens) - { - const boost::char_separator sp(" ="); - const tokenizer tok(token, sp); - - std::vector keyValue; - for (const auto& t : tok) - keyValue.push_back(t); - - if (keyValue.size() != 2) - { - m_logger("The '%s' attribute specification has an incorrect format: '%s'.", paramName.c_str(), token.c_str()); - printfd(__FILE__, "The '%s' attribute specification has an incorrect format: '%s'.", paramName.c_str(), token.c_str()); - return {}; - } - - auto type = AttrValue::Type::PARAM_NAME; - std::string valueName = keyValue[1]; - if (valueName.front() == '\'' && valueName.back() == '\'') - { - type = AttrValue::Type::VALUE; - valueName.erase(0, 1); - valueName.erase(valueName.length() - 1, 1); - } - else if ((valueName.front() == '\'' && valueName.back() != '\'') || (valueName.front() != '\'' && valueName.back() == '\'')) - { - m_logger("Error ParseRules: '%s' attribute parameter value is invalid.\n", paramName.c_str()); - printfd(__FILE__, "Error ParseRules: '%s' attribute parameter value is invalid.\n", paramName.c_str()); - return {}; - } - res.emplace_back(keyValue[0], AttrValue{valueName, type}); - } - return res; -} - -ASection RAD_SETTINGS::parseASection(const std::vector& conf) -{ - ASection res; - const auto mit = std::find(conf.begin(), conf.end(), ParamValue("match", {})); - if (mit != conf.end()) - res.match = ParseRules(mit->value[0], mit->param); - - const auto sit = std::find(conf.begin(), conf.end(), ParamValue("send", {})); - if (sit != conf.end()) - res.send = ParseRules(sit->value[0], sit->param); - - return res; -} - -RAD_SETTINGS::RAD_SETTINGS() - : m_port(1812), - m_dictionaries("/usr/share/freeradius/dictionary"), - m_logger(PluginLogger::get("radius")) -{} - -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(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]; - - const auto authIt = std::find(s.moduleParams.begin(), s.moduleParams.end(), ParamValue("auth", {})); - if (authIt != s.moduleParams.end()) - m_auth = parseASection(authIt->sections); - - const auto autzIt = std::find(s.moduleParams.begin(), s.moduleParams.end(), ParamValue("autz", {})); - if (autzIt != s.moduleParams.end()) - m_autz = parseASection(autzIt->sections); - - printfd(__FILE__, " auth.match = \"%s\"\n", ShowRules(m_auth.match).c_str()); - printfd(__FILE__, " auth.send = \"%s\"\n", ShowRules(m_auth.send).c_str()); - printfd(__FILE__, " autz.match = \"%s\"\n", ShowRules(m_autz.match).c_str()); - printfd(__FILE__, " autz.send = \"%s\"\n", ShowRules(m_autz.send).c_str()); - - return 0; -} - RADIUS::RADIUS() : m_running(false), m_users(NULL), @@ -212,7 +72,7 @@ int RADIUS::Run(std::stop_token token) try { if (!m_server) - m_server = std::make_unique(m_ioContext, m_radSettings.GetSecret(), m_radSettings.GetPort(), m_radSettings.GetDictionaries(), std::move(token), m_logger, m_users); + m_server = std::make_unique(m_ioContext, m_radSettings.GetSecret(), m_radSettings.GetPort(), m_radSettings.GetDictionaries(), std::move(token), m_logger, m_users, m_radSettings); m_ioContext.run(); } catch (const std::exception& e) From d74bb0b62bfbe1b55937c61b6434c21115e69cb2 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Mon, 21 Jul 2025 16:22:57 +0300 Subject: [PATCH 161/186] Radius. The new file rad_settings.h added. --- .../plugins/other/radius/rad_settings.h | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 projects/stargazer/plugins/other/radius/rad_settings.h diff --git a/projects/stargazer/plugins/other/radius/rad_settings.h b/projects/stargazer/plugins/other/radius/rad_settings.h new file mode 100644 index 00000000..4cd1a86f --- /dev/null +++ b/projects/stargazer/plugins/other/radius/rad_settings.h @@ -0,0 +1,60 @@ +#pragma once + +#include "stg/module_settings.h" +#include "stg/subscriptions.h" +#include "stg/logger.h" + +#include +#include //uint8_t, uint32_t + +namespace STG +{ + struct Settings; + + class RAD_SETTINGS + { + public: + RAD_SETTINGS(); + + struct AttrValue + { + enum class Type + { + PARAM_NAME, + VALUE + }; + std::string value; + Type type; + }; + + struct ASection + { + using Pairs = std::vector>; + 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> ParseRules(const std::string& value, const std::string& paramName); + ASection parseASection(const std::vector& 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; + }; +} From 5909001c9009a7943c7fe6b8fd6f5ae660df4538 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Mon, 21 Jul 2025 16:25:56 +0300 Subject: [PATCH 162/186] Radius. The new file rad_settings.cpp added. --- .../plugins/other/radius/rad_settings.cpp | 147 ++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 projects/stargazer/plugins/other/radius/rad_settings.cpp diff --git a/projects/stargazer/plugins/other/radius/rad_settings.cpp b/projects/stargazer/plugins/other/radius/rad_settings.cpp new file mode 100644 index 00000000..07b896f6 --- /dev/null +++ b/projects/stargazer/plugins/other/radius/rad_settings.cpp @@ -0,0 +1,147 @@ +#include "rad_settings.h" +#include "radproto/error.h" +#include "stg/common.h" +#include + +#include +#include +#include +#include +#include + +using STG::RAD_SETTINGS; +using AttrValue = RAD_SETTINGS::AttrValue; +using ASection = RAD_SETTINGS::ASection; + +namespace +{ + std::string ShowRules(const std::vector>& attributes) + { + std::string result; + for (const auto& at : attributes) + { + if (!result.empty()) + result += ", "; + + if (at.second.type == AttrValue::Type::PARAM_NAME) + result.append(at.first + " = " + at.second.value); + else + result.append(at.first + " = '" + at.second.value + "'"); + } + return result; + } +} + +std::vector> RAD_SETTINGS::ParseRules(const std::string& value, const std::string& paramName) +{ + using tokenizer = boost::tokenizer>; + const boost::char_separator sep(","); + + const tokenizer tokens(value, sep); + + std::vector> res; + for (const auto& token : tokens) + { + const boost::char_separator sp(" ="); + const tokenizer tok(token, sp); + + std::vector keyValue; + for (const auto& t : tok) + keyValue.push_back(t); + + if (keyValue.size() != 2) + { + m_logger("The '%s' attribute specification has an incorrect format: '%s'.", paramName.c_str(), token.c_str()); + printfd(__FILE__, "The '%s' attribute specification has an incorrect format: '%s'.", paramName.c_str(), token.c_str()); + return {}; + } + + auto type = AttrValue::Type::PARAM_NAME; + std::string valueName = keyValue[1]; + if (valueName.front() == '\'' && valueName.back() == '\'') + { + type = AttrValue::Type::VALUE; + valueName.erase(0, 1); + valueName.erase(valueName.length() - 1, 1); + } + else if ((valueName.front() == '\'' && valueName.back() != '\'') || (valueName.front() != '\'' && valueName.back() == '\'')) + { + m_logger("Error ParseRules: '%s' attribute parameter value is invalid.\n", paramName.c_str()); + printfd(__FILE__, "Error ParseRules: '%s' attribute parameter value is invalid.\n", paramName.c_str()); + return {}; + } + res.emplace_back(keyValue[0], AttrValue{valueName, type}); + } + return res; +} + +ASection RAD_SETTINGS::parseASection(const std::vector& conf) +{ + ASection res; + const auto mit = std::find(conf.begin(), conf.end(), ParamValue("match", {})); + if (mit != conf.end()) + res.match = ParseRules(mit->value[0], mit->param); + + const auto sit = std::find(conf.begin(), conf.end(), ParamValue("send", {})); + if (sit != conf.end()) + res.send = ParseRules(sit->value[0], sit->param); + + return res; +} + +RAD_SETTINGS::RAD_SETTINGS() + : m_port(1812), + m_dictionaries("/usr/share/freeradius/dictionary"), + m_logger(PluginLogger::get("radius")) +{} + +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(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]; + + const auto authIt = std::find(s.moduleParams.begin(), s.moduleParams.end(), ParamValue("auth", {})); + if (authIt != s.moduleParams.end()) + m_auth = parseASection(authIt->sections); + + const auto autzIt = std::find(s.moduleParams.begin(), s.moduleParams.end(), ParamValue("autz", {})); + if (autzIt != s.moduleParams.end()) + m_autz = parseASection(autzIt->sections); + + printfd(__FILE__, " auth.match = \"%s\"\n", ShowRules(m_auth.match).c_str()); + printfd(__FILE__, " auth.send = \"%s\"\n", ShowRules(m_auth.send).c_str()); + printfd(__FILE__, " autz.match = \"%s\"\n", ShowRules(m_autz.match).c_str()); + printfd(__FILE__, " autz.send = \"%s\"\n", ShowRules(m_autz.send).c_str()); + + return 0; +} + From fbd5b1ceca7aa07cfe437d1f6883fb83e6bd8fb7 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Mon, 21 Jul 2025 16:42:33 +0300 Subject: [PATCH 163/186] Radius. Header file "rad_settings.h" added. Parameter radSettings added to constructor Server declaration. Class memberm_radSettings added. --- projects/stargazer/plugins/other/radius/server.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/projects/stargazer/plugins/other/radius/server.h b/projects/stargazer/plugins/other/radius/server.h index d4efef98..3f9862c3 100644 --- a/projects/stargazer/plugins/other/radius/server.h +++ b/projects/stargazer/plugins/other/radius/server.h @@ -2,6 +2,7 @@ #include "radproto/socket.h" #include "radproto/packet.h" +#include "rad_settings.h" #include "radproto/dictionaries.h" #include "stg/logger.h" #include @@ -16,7 +17,7 @@ namespace STG class Server { public: - Server(boost::asio::io_context& io_context, const std::string& secret, uint16_t port, const std::string& filePath, std::stop_token token, PluginLogger& logger, Users* users); + Server(boost::asio::io_context& io_context, const std::string& secret, uint16_t port, const std::string& filePath, std::stop_token token, PluginLogger& logger, Users* users, RAD_SETTINGS& radSettings); void stop(); private: RadProto::Packet makeResponse(const RadProto::Packet& request); @@ -29,6 +30,7 @@ namespace STG RadProto::Socket m_radius; RadProto::Dictionaries m_dictionaries; Users* m_users; + const RAD_SETTINGS& m_radSettings; std::stop_token m_token; PluginLogger& m_logger; From b5819adde7fc9f58cad3bf20986dd546d4b0b62c Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Mon, 21 Jul 2025 16:47:58 +0300 Subject: [PATCH 164/186] Radius. Parameter radSettings added to constructor Server definition. Class member m_radSettings initialization added in the constructor Server. --- projects/stargazer/plugins/other/radius/server.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/projects/stargazer/plugins/other/radius/server.cpp b/projects/stargazer/plugins/other/radius/server.cpp index 9e6766d5..cd5f8036 100644 --- a/projects/stargazer/plugins/other/radius/server.cpp +++ b/projects/stargazer/plugins/other/radius/server.cpp @@ -11,10 +11,11 @@ using STG::Server; using boost::system::error_code; -Server::Server(boost::asio::io_context& io_context, const std::string& secret, uint16_t port, const std::string& filePath, std::stop_token token, PluginLogger& logger, Users* users) +Server::Server(boost::asio::io_context& io_context, const std::string& secret, uint16_t port, const std::string& filePath, std::stop_token token, PluginLogger& logger, Users* users, RAD_SETTINGS& radSettings) : m_radius(io_context, secret, port), m_dictionaries(filePath), m_users(users), + m_radSettings(radSettings), m_token(std::move(token)), m_logger(logger) { From 3ec586ec636d6927f33707a0fa660cde69be333b Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Wed, 27 Aug 2025 15:32:16 +0300 Subject: [PATCH 165/186] Radius. The attributes User-Name, Cacllback-Number added to section /send. --- .../inst/linux/etc/stargazer/conf-available.d/mod_radius.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/stargazer/inst/linux/etc/stargazer/conf-available.d/mod_radius.conf b/projects/stargazer/inst/linux/etc/stargazer/conf-available.d/mod_radius.conf index 7373af21..459f1a54 100644 --- a/projects/stargazer/inst/linux/etc/stargazer/conf-available.d/mod_radius.conf +++ b/projects/stargazer/inst/linux/etc/stargazer/conf-available.d/mod_radius.conf @@ -18,7 +18,7 @@ # Port = 1812 - send = "Framed-IP-Address = currip, Service-Type = \'Framed-User\'" + send = "User-Name = login, Framed-IP-Address = currip, Service-Type = \'Framed-User\', Callback-Number = \'987654abc\'" match = "Calling-Station-Id = userdata0" From 694212fc6c78e5364ed33e4773d2205462ea2e95 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Wed, 27 Aug 2025 15:57:46 +0300 Subject: [PATCH 166/186] Radius. Class User forward declaration added. Parameter radSettings changed to const in constructor Server declaration. The bool findUser function declaration replaced by const User* findUser. --- projects/stargazer/plugins/other/radius/server.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/server.h b/projects/stargazer/plugins/other/radius/server.h index 3f9862c3..010e0f45 100644 --- a/projects/stargazer/plugins/other/radius/server.h +++ b/projects/stargazer/plugins/other/radius/server.h @@ -13,15 +13,17 @@ namespace STG { class Users; + class User; class Server { public: - Server(boost::asio::io_context& io_context, const std::string& secret, uint16_t port, const std::string& filePath, std::stop_token token, PluginLogger& logger, Users* users, RAD_SETTINGS& radSettings); + Server(boost::asio::io_context& io_context, const std::string& secret, uint16_t port, const std::string& filePath, std::stop_token token, PluginLogger& logger, Users* users, const RAD_SETTINGS& radSettings); void stop(); private: + std::vector makeAttributes(const User* user); RadProto::Packet makeResponse(const RadProto::Packet& request); - bool findUser(const RadProto::Packet& packet); + const User* findUser(const RadProto::Packet& packet); void handleReceive(const boost::system::error_code& error, const std::optional& packet, const boost::asio::ip::udp::endpoint& source); void handleSend(const boost::system::error_code& ec); void start(); From b7ce5c44d58a916bf53033f730e5d93db6b44bd9 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Wed, 27 Aug 2025 16:17:39 +0300 Subject: [PATCH 167/186] Radius. Header files added. The using statement for STG User added. Parameter radSettings changed to const in constructor Server definition. The bool findUser function definition replaced by const User* findUser. The makeAttributes function definition added. Function makeResponse definition changed. --- .../stargazer/plugins/other/radius/server.cpp | 96 +++++++++++++++---- 1 file changed, 76 insertions(+), 20 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/server.cpp b/projects/stargazer/plugins/other/radius/server.cpp index cd5f8036..6c3ec4b9 100644 --- a/projects/stargazer/plugins/other/radius/server.cpp +++ b/projects/stargazer/plugins/other/radius/server.cpp @@ -4,14 +4,19 @@ #include "stg/user.h" #include "stg/users.h" #include "stg/common.h" +#include +#include +#include +#include // для std::replace #include #include #include //uint8_t, uint32_t using STG::Server; +using STG::User; using boost::system::error_code; -Server::Server(boost::asio::io_context& io_context, const std::string& secret, uint16_t port, const std::string& filePath, std::stop_token token, PluginLogger& logger, Users* users, RAD_SETTINGS& radSettings) +Server::Server(boost::asio::io_context& io_context, const std::string& secret, uint16_t port, const std::string& filePath, std::stop_token token, PluginLogger& logger, Users* users, const RAD_SETTINGS& radSettings) : m_radius(io_context, secret, port), m_dictionaries(filePath), m_users(users), @@ -38,27 +43,78 @@ void Server::startReceive() m_radius.asyncReceive([this](const auto& error, const auto& packet, const boost::asio::ip::udp::endpoint& source){ handleReceive(error, packet, source); }); } -RadProto::Packet Server::makeResponse(const RadProto::Packet& request) +std::vector Server::makeAttributes(const User* user) { std::vector attributes; - attributes.push_back(new RadProto::String(m_dictionaries.attributeCode("User-Name"), "test")); - attributes.push_back(new RadProto::Integer(m_dictionaries.attributeCode("NAS-Port"), 20)); - std::array address {127, 104, 22, 17}; - attributes.push_back(new RadProto::IpAddress(m_dictionaries.attributeCode("NAS-IP-Address"), address)); - std::vector bytes {'1', '2', '3', 'a', 'b', 'c'}; - attributes.push_back(new RadProto::Bytes(m_dictionaries.attributeCode("Callback-Number"), bytes)); - std::vector chapPassword {'1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g' }; - attributes.push_back(new RadProto::ChapPassword(m_dictionaries.attributeCode("CHAP-Password"), 1, chapPassword)); - - std::vector vendorSpecific; - std::vector vendorValue {0, 0, 0, 3}; - vendorSpecific.push_back(RadProto::VendorSpecific(m_dictionaries.vendorCode("Dlink"), m_dictionaries.vendorAttributeCode("Dlink", "Dlink-User-Level"), vendorValue)); + std::string attrName; + std::string attrValue; + uint8_t attrCode; + + for (const auto& at : m_radSettings.getAuth().send) + { + attrName = at.first; + attrCode = m_dictionaries.attributeCode(attrName); + if (at.second.type == RAD_SETTINGS::AttrValue::Type::PARAM_NAME) + attrValue = user->GetParamValue(at.second.value); + else + attrValue = at.second.value; + + if (attrCode == 1 || attrCode == 11 || attrCode == 18 || attrCode == 22 || attrCode == 34 || attrCode == 35 || attrCode == 60 || attrCode == 63) + { + attributes.push_back(new RadProto::String(attrCode, attrValue)); + } + else if (attrCode == 4 || attrCode == 8 || attrCode == 9 || attrCode == 14) + { + std::array attrValueIP; + if (attrValue == "0") + attrValueIP = {0}; + else + { + std::replace(attrValue.begin(), attrValue.end(), '.', ' '); + + std::stringstream ss(attrValue); + int temp_num; + + for (size_t i = 0; i < 4; ++i) + { + ss >> temp_num; + attrValueIP[i] = temp_num; + } + } + attributes.push_back(new RadProto::IpAddress(attrCode, attrValueIP)); + } + else if (attrCode == 5 || attrCode == 6 || attrCode == 7 || attrCode == 10 || attrCode == 12 || attrCode == 13 || attrCode == 15 || attrCode == 16 || attrCode == 27 || attrCode == 28 || attrCode == 29 || attrCode == 37 || attrCode == 38 || attrCode == 61 || attrCode == 62) + { + uint32_t attrValueInt; + if (attrCode == 6 || attrCode == 7 || attrCode == 10 || attrCode == 13 || attrCode == 15 || attrCode == 16 || attrCode == 29 || attrCode == 61) + attrValueInt = m_dictionaries.attributeValueCode(attrName, attrValue); + else + attrValueInt = std::stoi(attrValue); + attributes.push_back(new RadProto::Integer(attrCode, attrValueInt)); + } + else if (attrCode == 19 || attrCode == 20 || attrCode == 24 || attrCode == 25 || attrCode == 30 || attrCode == 31 || attrCode == 32 || attrCode == 33 || attrCode == 36 || attrCode == 39 || attrCode == 79 || attrCode == 80) + { + std::vector attrValueBytes; + if (!attrValue.empty()) + for (char c : attrValue) + attrValueBytes.push_back(static_cast(c)); + attributes.push_back(new RadProto::Bytes(attrCode, attrValueBytes)); + } + } + return attributes; +} + +RadProto::Packet Server::makeResponse(const RadProto::Packet& request) +{ + const User* user; + + user = findUser(request); if (request.type() != RadProto::ACCESS_REQUEST) return RadProto::Packet(RadProto::ACCESS_REJECT, request.id(), request.auth(), {}, {}); - if (findUser(request)) - return RadProto::Packet(RadProto::ACCESS_ACCEPT, request.id(), request.auth(), attributes, vendorSpecific); + if (user != nullptr) + return RadProto::Packet(RadProto::ACCESS_ACCEPT, request.id(), request.auth(), makeAttributes(user), {}); printfd(__FILE__, "Error findUser\n"); return RadProto::Packet(RadProto::ACCESS_REJECT, request.id(), request.auth(), {}, {}); @@ -98,7 +154,7 @@ void Server::handleReceive(const error_code& error, const std::optionalGetLogin().c_str()); @@ -125,7 +181,7 @@ bool Server::findUser(const RadProto::Packet& packet) { m_logger("User's password is incorrect. %s", password.c_str()); printfd(__FILE__, "User's password is incorrect.\n", password.c_str()); - return false; + return nullptr; } - return true; + return user; } From 8cbb40186c57a4d98a3998812834e439530929fc Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Mon, 1 Sep 2025 15:20:36 +0300 Subject: [PATCH 168/186] Radius. Unnecessary attributes removed from /send section. --- .../inst/linux/etc/stargazer/conf-available.d/mod_radius.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/stargazer/inst/linux/etc/stargazer/conf-available.d/mod_radius.conf b/projects/stargazer/inst/linux/etc/stargazer/conf-available.d/mod_radius.conf index 459f1a54..7373af21 100644 --- a/projects/stargazer/inst/linux/etc/stargazer/conf-available.d/mod_radius.conf +++ b/projects/stargazer/inst/linux/etc/stargazer/conf-available.d/mod_radius.conf @@ -18,7 +18,7 @@ # Port = 1812 - send = "User-Name = login, Framed-IP-Address = currip, Service-Type = \'Framed-User\', Callback-Number = \'987654abc\'" + send = "Framed-IP-Address = currip, Service-Type = \'Framed-User\'" match = "Calling-Station-Id = userdata0" From 2fab1f488c3ffbb17f35b0f69e5248a192c2d33b Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Mon, 1 Sep 2025 15:49:58 +0300 Subject: [PATCH 169/186] Radius. The rad_settings.h header file changed to settings.h. --- .../plugins/other/radius/{rad_settings.cpp => settings.cpp} | 2 +- .../plugins/other/radius/{rad_settings.h => settings.h} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename projects/stargazer/plugins/other/radius/{rad_settings.cpp => settings.cpp} (99%) rename projects/stargazer/plugins/other/radius/{rad_settings.h => settings.h} (100%) diff --git a/projects/stargazer/plugins/other/radius/rad_settings.cpp b/projects/stargazer/plugins/other/radius/settings.cpp similarity index 99% rename from projects/stargazer/plugins/other/radius/rad_settings.cpp rename to projects/stargazer/plugins/other/radius/settings.cpp index 07b896f6..e765f608 100644 --- a/projects/stargazer/plugins/other/radius/rad_settings.cpp +++ b/projects/stargazer/plugins/other/radius/settings.cpp @@ -1,4 +1,4 @@ -#include "rad_settings.h" +#include "settings.h" #include "radproto/error.h" #include "stg/common.h" #include diff --git a/projects/stargazer/plugins/other/radius/rad_settings.h b/projects/stargazer/plugins/other/radius/settings.h similarity index 100% rename from projects/stargazer/plugins/other/radius/rad_settings.h rename to projects/stargazer/plugins/other/radius/settings.h From 835a7bfb8c46fed1aba478a4fd071900bcca47a3 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Mon, 1 Sep 2025 15:56:42 +0300 Subject: [PATCH 170/186] Radius. The rad_settings.h header file changed to settings.h. --- projects/stargazer/plugins/other/radius/server.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/stargazer/plugins/other/radius/server.h b/projects/stargazer/plugins/other/radius/server.h index 010e0f45..dab76f81 100644 --- a/projects/stargazer/plugins/other/radius/server.h +++ b/projects/stargazer/plugins/other/radius/server.h @@ -2,7 +2,7 @@ #include "radproto/socket.h" #include "radproto/packet.h" -#include "rad_settings.h" +#include "settings.h" #include "radproto/dictionaries.h" #include "stg/logger.h" #include From b4373ff4bf5a8bd84f7df4e06fe07dbbe06360fd Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Mon, 1 Sep 2025 15:57:49 +0300 Subject: [PATCH 171/186] Radius. The rad_settings.h header file changed to settings.h. --- projects/stargazer/plugins/other/radius/radius.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/stargazer/plugins/other/radius/radius.h b/projects/stargazer/plugins/other/radius/radius.h index 583eb94f..4f9e7360 100644 --- a/projects/stargazer/plugins/other/radius/radius.h +++ b/projects/stargazer/plugins/other/radius/radius.h @@ -2,7 +2,7 @@ #include "stg/auth.h" #include "stg/plugin.h" -#include "rad_settings.h" +#include "settings.h" #include "stg/module_settings.h" #include "stg/subscriptions.h" #include "stg/logger.h" From f67141295aa50f005f9d37761a40418f24c86f5a Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Mon, 1 Sep 2025 15:59:08 +0300 Subject: [PATCH 172/186] Radius. The rad_settings.cpp filename changed to settings.cpp in add_library for BUILD_MOD_RADIUS. --- projects/stargazer/plugins/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/stargazer/plugins/CMakeLists.txt b/projects/stargazer/plugins/CMakeLists.txt index ba4a6d14..bf63dbfd 100644 --- a/projects/stargazer/plugins/CMakeLists.txt +++ b/projects/stargazer/plugins/CMakeLists.txt @@ -16,7 +16,7 @@ if ( BUILD_MOD_RADIUS ) add_library ( mod_radius MODULE other/radius/radius.cpp other/radius/server.cpp - other/radius/rad_settings.cpp) + other/radius/settings.cpp) target_link_libraries ( mod_radius PRIVATE scriptexecuter logger common ) set_target_properties ( mod_radius PROPERTIES PREFIX "" ) From 0a1cd1b92fd4962cc48c53c70a8e9e55d9f5eb39 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Tue, 2 Sep 2025 14:17:35 +0300 Subject: [PATCH 173/186] Radius. The settings.cpp filename changed to config.cpp in add_library for BUILD_MOD_RADIUS. --- projects/stargazer/plugins/CMakeLists.txt | 2 +- .../stargazer/plugins/other/radius/{settings.cpp => config.cpp} | 0 .../stargazer/plugins/other/radius/{settings.h => config.h} | 0 3 files changed, 1 insertion(+), 1 deletion(-) rename projects/stargazer/plugins/other/radius/{settings.cpp => config.cpp} (100%) rename projects/stargazer/plugins/other/radius/{settings.h => config.h} (100%) diff --git a/projects/stargazer/plugins/CMakeLists.txt b/projects/stargazer/plugins/CMakeLists.txt index bf63dbfd..df4ef4c0 100644 --- a/projects/stargazer/plugins/CMakeLists.txt +++ b/projects/stargazer/plugins/CMakeLists.txt @@ -16,7 +16,7 @@ if ( BUILD_MOD_RADIUS ) add_library ( mod_radius MODULE other/radius/radius.cpp other/radius/server.cpp - other/radius/settings.cpp) + other/radius/config.cpp) target_link_libraries ( mod_radius PRIVATE scriptexecuter logger common ) set_target_properties ( mod_radius PROPERTIES PREFIX "" ) diff --git a/projects/stargazer/plugins/other/radius/settings.cpp b/projects/stargazer/plugins/other/radius/config.cpp similarity index 100% rename from projects/stargazer/plugins/other/radius/settings.cpp rename to projects/stargazer/plugins/other/radius/config.cpp diff --git a/projects/stargazer/plugins/other/radius/settings.h b/projects/stargazer/plugins/other/radius/config.h similarity index 100% rename from projects/stargazer/plugins/other/radius/settings.h rename to projects/stargazer/plugins/other/radius/config.h From b34d90bce0862a5484fbc56c6ef8f1146eeb4607 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Tue, 2 Sep 2025 14:23:03 +0300 Subject: [PATCH 174/186] Radius. The settings.h header file changed to config.h. --- projects/stargazer/plugins/other/radius/radius.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/stargazer/plugins/other/radius/radius.h b/projects/stargazer/plugins/other/radius/radius.h index 4f9e7360..3c3bc5f2 100644 --- a/projects/stargazer/plugins/other/radius/radius.h +++ b/projects/stargazer/plugins/other/radius/radius.h @@ -2,7 +2,7 @@ #include "stg/auth.h" #include "stg/plugin.h" -#include "settings.h" +#include "config.h" #include "stg/module_settings.h" #include "stg/subscriptions.h" #include "stg/logger.h" From eb0110004ab3a620894397bde6745cad7c82e63f Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Tue, 2 Sep 2025 14:28:37 +0300 Subject: [PATCH 175/186] Radius. The settings.h header file changed to config.h. --- projects/stargazer/plugins/other/radius/server.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/stargazer/plugins/other/radius/server.h b/projects/stargazer/plugins/other/radius/server.h index dab76f81..e192a74f 100644 --- a/projects/stargazer/plugins/other/radius/server.h +++ b/projects/stargazer/plugins/other/radius/server.h @@ -2,7 +2,7 @@ #include "radproto/socket.h" #include "radproto/packet.h" -#include "settings.h" +#include "config.h" #include "radproto/dictionaries.h" #include "stg/logger.h" #include From ba581369cd56e37d2ad260358766b11c28a23b96 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Tue, 2 Sep 2025 14:31:25 +0300 Subject: [PATCH 176/186] Radius. The settings.h header file changed to config.h. --- projects/stargazer/plugins/other/radius/config.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/stargazer/plugins/other/radius/config.cpp b/projects/stargazer/plugins/other/radius/config.cpp index e765f608..93cf5ea3 100644 --- a/projects/stargazer/plugins/other/radius/config.cpp +++ b/projects/stargazer/plugins/other/radius/config.cpp @@ -1,4 +1,4 @@ -#include "settings.h" +#include "config.h" #include "radproto/error.h" #include "stg/common.h" #include From 3aed01c80538fb3bc8235ddfc4c408505bb7c051 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Tue, 2 Sep 2025 14:41:42 +0300 Subject: [PATCH 177/186] Radius. The RAD_SETTINGS class name changed to Config. --- projects/stargazer/plugins/other/radius/config.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/config.h b/projects/stargazer/plugins/other/radius/config.h index 4cd1a86f..74e483a5 100644 --- a/projects/stargazer/plugins/other/radius/config.h +++ b/projects/stargazer/plugins/other/radius/config.h @@ -11,10 +11,10 @@ namespace STG { struct Settings; - class RAD_SETTINGS + class Config { public: - RAD_SETTINGS(); + Config(); struct AttrValue { From 4e2a5f96341a84e93c7833a07ae315f7ed9f074a Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Tue, 2 Sep 2025 14:46:31 +0300 Subject: [PATCH 178/186] Radius. The RAD_SETTINGS class name changed to Config. --- projects/stargazer/plugins/other/radius/config.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/config.cpp b/projects/stargazer/plugins/other/radius/config.cpp index 93cf5ea3..c273761f 100644 --- a/projects/stargazer/plugins/other/radius/config.cpp +++ b/projects/stargazer/plugins/other/radius/config.cpp @@ -9,9 +9,9 @@ #include #include -using STG::RAD_SETTINGS; -using AttrValue = RAD_SETTINGS::AttrValue; -using ASection = RAD_SETTINGS::ASection; +using STG::Config; +using AttrValue = Config::AttrValue; +using ASection = Config::ASection; namespace { @@ -32,7 +32,7 @@ namespace } } -std::vector> RAD_SETTINGS::ParseRules(const std::string& value, const std::string& paramName) +std::vector> Config::ParseRules(const std::string& value, const std::string& paramName) { using tokenizer = boost::tokenizer>; const boost::char_separator sep(","); @@ -75,7 +75,7 @@ std::vector> RAD_SETTINGS::ParseRules(const st return res; } -ASection RAD_SETTINGS::parseASection(const std::vector& conf) +ASection Config::parseASection(const std::vector& conf) { ASection res; const auto mit = std::find(conf.begin(), conf.end(), ParamValue("match", {})); @@ -89,13 +89,13 @@ ASection RAD_SETTINGS::parseASection(const std::vector& conf) return res; } -RAD_SETTINGS::RAD_SETTINGS() +Config::Config() : m_port(1812), m_dictionaries("/usr/share/freeradius/dictionary"), m_logger(PluginLogger::get("radius")) {} -int RAD_SETTINGS::ParseSettings(const ModuleSettings & s) +int Config::ParseSettings(const ModuleSettings & s) { ParamValue pv; int p; From 46c44148bd0bc082d0ba197f6f189a49c27af058 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Tue, 2 Sep 2025 14:57:08 +0300 Subject: [PATCH 179/186] Radius. The RAD_SETTINGS class name changed to Config. The m_radSettings variable class member changed to m_config. --- projects/stargazer/plugins/other/radius/radius.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/stargazer/plugins/other/radius/radius.h b/projects/stargazer/plugins/other/radius/radius.h index 3c3bc5f2..87136d83 100644 --- a/projects/stargazer/plugins/other/radius/radius.h +++ b/projects/stargazer/plugins/other/radius/radius.h @@ -51,7 +51,7 @@ namespace STG int Run(std::stop_token token); mutable std::string m_errorStr; - RAD_SETTINGS m_radSettings; + Config m_config; ModuleSettings m_settings; bool m_running; From c836bfceebac0be9be98ae073c1430e01ae9eb04 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Tue, 2 Sep 2025 15:06:56 +0300 Subject: [PATCH 180/186] Radius. The m_radSettings variable class member changed to m_config. --- projects/stargazer/plugins/other/radius/radius.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 14b5d746..e3c8ad4e 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -22,9 +22,9 @@ RADIUS::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; } @@ -73,7 +73,7 @@ int RADIUS::Run(std::stop_token token) try { if (!m_server) - m_server = std::make_unique(m_ioContext, m_radSettings.GetSecret(), m_radSettings.GetPort(), m_radSettings.GetDictionaries(), std::move(token), m_logger, m_users, m_radSettings); + m_server = std::make_unique(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) From 58b9b78b24047f7cc4cce3545c802a85ba4d62b0 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Tue, 2 Sep 2025 15:15:50 +0300 Subject: [PATCH 181/186] Radius. The RAD_SETTINGS class name changed to Config. The m_radSettings variable class member changed to m_config. The radSettings parameter name changed to config. --- projects/stargazer/plugins/other/radius/server.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/server.h b/projects/stargazer/plugins/other/radius/server.h index e192a74f..1523179e 100644 --- a/projects/stargazer/plugins/other/radius/server.h +++ b/projects/stargazer/plugins/other/radius/server.h @@ -18,7 +18,7 @@ namespace STG class Server { public: - Server(boost::asio::io_context& io_context, const std::string& secret, uint16_t port, const std::string& filePath, std::stop_token token, PluginLogger& logger, Users* users, const RAD_SETTINGS& radSettings); + Server(boost::asio::io_context& io_context, const std::string& secret, uint16_t port, const std::string& filePath, std::stop_token token, PluginLogger& logger, Users* users, const Config& config); void stop(); private: std::vector makeAttributes(const User* user); @@ -32,7 +32,7 @@ namespace STG RadProto::Socket m_radius; RadProto::Dictionaries m_dictionaries; Users* m_users; - const RAD_SETTINGS& m_radSettings; + const Config& m_config; std::stop_token m_token; PluginLogger& m_logger; From 7c54a627f2a8edcaa889c88eedc938707e8d8733 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Tue, 2 Sep 2025 15:22:34 +0300 Subject: [PATCH 182/186] Radius. The RAD_SETTINGS class name changed to Config. The m_radSettings variable class member changed to m_config. The radSettings parameter name changed to config in constructor Server. --- projects/stargazer/plugins/other/radius/server.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/server.cpp b/projects/stargazer/plugins/other/radius/server.cpp index 6c3ec4b9..3e16f2bd 100644 --- a/projects/stargazer/plugins/other/radius/server.cpp +++ b/projects/stargazer/plugins/other/radius/server.cpp @@ -16,11 +16,11 @@ using STG::Server; using STG::User; using boost::system::error_code; -Server::Server(boost::asio::io_context& io_context, const std::string& secret, uint16_t port, const std::string& filePath, std::stop_token token, PluginLogger& logger, Users* users, const RAD_SETTINGS& radSettings) +Server::Server(boost::asio::io_context& io_context, const std::string& secret, uint16_t port, const std::string& filePath, std::stop_token token, PluginLogger& logger, Users* users, const Config& config) : m_radius(io_context, secret, port), m_dictionaries(filePath), m_users(users), - m_radSettings(radSettings), + m_config(config), m_token(std::move(token)), m_logger(logger) { @@ -50,11 +50,11 @@ std::vector Server::makeAttributes(const User* user) std::string attrValue; uint8_t attrCode; - for (const auto& at : m_radSettings.getAuth().send) + for (const auto& at : m_config.getAuth().send) { attrName = at.first; attrCode = m_dictionaries.attributeCode(attrName); - if (at.second.type == RAD_SETTINGS::AttrValue::Type::PARAM_NAME) + if (at.second.type == Config::AttrValue::Type::PARAM_NAME) attrValue = user->GetParamValue(at.second.value); else attrValue = at.second.value; From 677a77fca757b4ec1b7d016165c0ebd22dd0c31c Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Tue, 10 Feb 2026 13:58:54 +0200 Subject: [PATCH 183/186] GIT_TAG changed to 1.2.0. --- projects/stargazer/plugins/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/stargazer/plugins/CMakeLists.txt b/projects/stargazer/plugins/CMakeLists.txt index df4ef4c0..78d1b94f 100644 --- a/projects/stargazer/plugins/CMakeLists.txt +++ b/projects/stargazer/plugins/CMakeLists.txt @@ -24,7 +24,7 @@ if ( BUILD_MOD_RADIUS ) ExternalProject_Add ( async-radius GIT_REPOSITORY https://github.com/madf/async-radius.git - GIT_TAG 1.1.3 + GIT_TAG 1.2.0 GIT_SHALLOW true INSTALL_COMMAND "" CMAKE_ARGS -DCMAKE_CXX_FLAGS=-fPIC ) From a53e4be5d4fbf0bbce666e5d450a6ee84a04588c Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Tue, 10 Feb 2026 14:00:55 +0200 Subject: [PATCH 184/186] GIT_TAG changed to 1.3.0. --- projects/stargazer/plugins/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/stargazer/plugins/CMakeLists.txt b/projects/stargazer/plugins/CMakeLists.txt index 78d1b94f..7d0e02e6 100644 --- a/projects/stargazer/plugins/CMakeLists.txt +++ b/projects/stargazer/plugins/CMakeLists.txt @@ -24,7 +24,7 @@ if ( BUILD_MOD_RADIUS ) ExternalProject_Add ( async-radius GIT_REPOSITORY https://github.com/madf/async-radius.git - GIT_TAG 1.2.0 + GIT_TAG 1.3.0 GIT_SHALLOW true INSTALL_COMMAND "" CMAKE_ARGS -DCMAKE_CXX_FLAGS=-fPIC ) From c920bf2419aab6a39814afab438ec6eb3ac667ad Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Tue, 10 Feb 2026 14:04:57 +0200 Subject: [PATCH 185/186] Header file "rsdproto/attribute.h" added. Server class member variable m_attribute added. --- projects/stargazer/plugins/other/radius/server.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/projects/stargazer/plugins/other/radius/server.h b/projects/stargazer/plugins/other/radius/server.h index 1523179e..c6ba9354 100644 --- a/projects/stargazer/plugins/other/radius/server.h +++ b/projects/stargazer/plugins/other/radius/server.h @@ -4,6 +4,7 @@ #include "radproto/packet.h" #include "config.h" #include "radproto/dictionaries.h" +#include "radproto/attribute.h" #include "stg/logger.h" #include #include @@ -31,6 +32,7 @@ namespace STG RadProto::Socket m_radius; RadProto::Dictionaries m_dictionaries; + RadProto::Attribute* m_attribute; Users* m_users; const Config& m_config; std::stop_token m_token; From 70179e9c81f08f922840df55f2146305b5d1ad41 Mon Sep 17 00:00:00 2001 From: Elena Mamontova Date: Wed, 11 Feb 2026 14:57:16 +0200 Subject: [PATCH 186/186] Header file "radproto/attribute_types.h" replaced by "radproto/attribute_codes.h". The class member m_attribute initialization added to constructor Server. The attrType variable added. The function type() replaced by code(). The function call make() added to function makeAttributes instead of attributes vector fill code. --- .../stargazer/plugins/other/radius/server.cpp | 56 +++++-------------- 1 file changed, 13 insertions(+), 43 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/server.cpp b/projects/stargazer/plugins/other/radius/server.cpp index 3e16f2bd..c60c18c8 100644 --- a/projects/stargazer/plugins/other/radius/server.cpp +++ b/projects/stargazer/plugins/other/radius/server.cpp @@ -1,6 +1,6 @@ #include "server.h" #include "radproto/packet_codes.h" -#include "radproto/attribute_types.h" +#include "radproto/attribute_codes.h" #include "stg/user.h" #include "stg/users.h" #include "stg/common.h" @@ -19,6 +19,7 @@ using boost::system::error_code; Server::Server(boost::asio::io_context& io_context, const std::string& secret, uint16_t port, const std::string& filePath, std::stop_token token, PluginLogger& logger, Users* users, const Config& config) : m_radius(io_context, secret, port), m_dictionaries(filePath), + m_attribute(0), m_users(users), m_config(config), m_token(std::move(token)), @@ -48,58 +49,27 @@ std::vector Server::makeAttributes(const User* user) std::vector attributes; std::string attrName; std::string attrValue; + std::string attrType; uint8_t attrCode; for (const auto& at : m_config.getAuth().send) { attrName = at.first; attrCode = m_dictionaries.attributeCode(attrName); + attrType = m_dictionaries.attributeType(attrCode); + if (at.second.type == Config::AttrValue::Type::PARAM_NAME) attrValue = user->GetParamValue(at.second.value); else attrValue = at.second.value; - if (attrCode == 1 || attrCode == 11 || attrCode == 18 || attrCode == 22 || attrCode == 34 || attrCode == 35 || attrCode == 60 || attrCode == 63) - { - attributes.push_back(new RadProto::String(attrCode, attrValue)); - } - else if (attrCode == 4 || attrCode == 8 || attrCode == 9 || attrCode == 14) - { - std::array attrValueIP; - if (attrValue == "0") - attrValueIP = {0}; - else - { - std::replace(attrValue.begin(), attrValue.end(), '.', ' '); - - std::stringstream ss(attrValue); - int temp_num; - - for (size_t i = 0; i < 4; ++i) - { - ss >> temp_num; - attrValueIP[i] = temp_num; - } - } - attributes.push_back(new RadProto::IpAddress(attrCode, attrValueIP)); - } - else if (attrCode == 5 || attrCode == 6 || attrCode == 7 || attrCode == 10 || attrCode == 12 || attrCode == 13 || attrCode == 15 || attrCode == 16 || attrCode == 27 || attrCode == 28 || attrCode == 29 || attrCode == 37 || attrCode == 38 || attrCode == 61 || attrCode == 62) - { - uint32_t attrValueInt; - if (attrCode == 6 || attrCode == 7 || attrCode == 10 || attrCode == 13 || attrCode == 15 || attrCode == 16 || attrCode == 29 || attrCode == 61) - attrValueInt = m_dictionaries.attributeValueCode(attrName, attrValue); - else - attrValueInt = std::stoi(attrValue); - attributes.push_back(new RadProto::Integer(attrCode, attrValueInt)); - } - else if (attrCode == 19 || attrCode == 20 || attrCode == 24 || attrCode == 25 || attrCode == 30 || attrCode == 31 || attrCode == 32 || attrCode == 33 || attrCode == 36 || attrCode == 39 || attrCode == 79 || attrCode == 80) + if (attrType == "integer") { - std::vector attrValueBytes; - if (!attrValue.empty()) - for (char c : attrValue) - attrValueBytes.push_back(static_cast(c)); - attributes.push_back(new RadProto::Bytes(attrCode, attrValueBytes)); + if (m_dictionaries.attributeValueFindByName(attrName, attrValue)) + attributes.push_back(m_attribute->make(attrCode, attrType, std::to_string(m_dictionaries.attributeValueCode(attrName, attrValue)))); } + else + attributes.push_back(m_attribute->make(attrCode, attrType, attrValue)); } return attributes; } @@ -110,7 +80,7 @@ RadProto::Packet Server::makeResponse(const RadProto::Packet& request) user = findUser(request); - if (request.type() != RadProto::ACCESS_REQUEST) + if (request.code() != RadProto::ACCESS_REQUEST) return RadProto::Packet(RadProto::ACCESS_REJECT, request.id(), request.auth(), {}, {}); if (user != nullptr) @@ -160,10 +130,10 @@ const User* Server::findUser(const RadProto::Packet& packet) std::string password; for (const auto& attribute : packet.attributes()) { - if (attribute->type() == RadProto::USER_NAME) + if (attribute->code() == RadProto::USER_NAME) login = attribute->toString(); - if (attribute->type() == RadProto::USER_PASSWORD) + if (attribute->code() == RadProto::USER_PASSWORD) password = attribute->toString(); }