Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
174 commits
Select commit Hold shift + click to select a range
1e0e67c
Radius. Header file <mutex>, <jthread.hpp> added. Functions start, stop
HelenMamontova Dec 27, 2024
2f28e07
Radius. Header files added. Functions Start, Stop, Run definition added.
HelenMamontova Dec 27, 2024
3818eac
Radius. New files server.h, server.cpp added.
HelenMamontova Dec 27, 2024
4bd3439
Radius. Definition of functions startReceive, makeResponse, handleSend,
HelenMamontova Jan 2, 2025
69c2f83
The Run function name fixed. Definition of secret variable sdded.
HelenMamontova Jan 2, 2025
dca0d95
The file server.cpp added to add_library command, command
HelenMamontova Jan 2, 2025
6a7ea1e
Parameter token added to function Run() declaration.
HelenMamontova Jan 8, 2025
85a5b66
Radius. Method Start: variable isRunning=true removed, m_thread
HelenMamontova Jan 8, 2025
713a4ce
Radius. Hold the mutex removed,extra conditions
HelenMamontova Jan 13, 2025
c8ee14f
Radius. Cycle while removed in function Run.
HelenMamontova Jan 13, 2025
f366de0
Radius. The variables isRunning, errorStr replaced by m_running,
HelenMamontova Jan 13, 2025
98fdb4b
Radius. The variable isRunning replaced by m_running in function Run.
HelenMamontova Jan 13, 2025
6623d7e
Radius. Object name io_service changed to ioService in the function Run.
HelenMamontova Jan 13, 2025
c940134
Method SetRunning declaration added to the class RADIUS.
HelenMamontova Jan 14, 2025
759e5f2
Method SetRunning definition added. Method SetRunning call added to
HelenMamontova Jan 14, 2025
dbd8db4
Radius. Namespace STG added.
HelenMamontova Jan 14, 2025
d3491db
Radius. Declaration using STG::Server added.
HelenMamontova Jan 14, 2025
6db11a3
Radius. Header file "stg/logger.h" added. RADIUS class member m_loger…
HelenMamontova Jan 15, 2025
fdb7811
Radius. Header file "stg/common.h" added. Initialization of m_logger
HelenMamontova Jan 15, 2025
d43fcaf
Radius. Variable except added, messages fixed in the function Run.
HelenMamontova Jan 17, 2025
8284ccc
Radius. Thread join logic fixed in the function Stop.
HelenMamontova Jan 17, 2025
65caf3d
Keyword const added to std::lock_guard in the function SetRunning.
HelenMamontova Jan 17, 2025
74a2013
Radius. Class member m_mutex moved to the top of list.
HelenMamontova Jan 20, 2025
9d2b564
Radius. Class member m_logger put after the m_running.
HelenMamontova Jan 20, 2025
fd6655c
Radius. Unnecessary variable except removed in the function Run.
HelenMamontova Jan 26, 2025
8e041be
Radius. Extra whitespace removed in the function Stop. Function
HelenMamontova Jan 27, 2025
aef4a94
Radius. Function IsRunning declaration changed.
HelenMamontova Jan 27, 2025
2692423
Radius. Formatting fixed.
HelenMamontova Jan 27, 2025
fc12e51
Radius. Extra symbols '//' removed.
HelenMamontova Jan 27, 2025
b969155
Radius. Class member m_running initialization added to constructor
HelenMamontova Jan 27, 2025
d430e66
Radius.Header file "stg/module_settings.h" added. Class members variable
HelenMamontova Jan 29, 2025
2c11cad
Radius. The parameters Secret, Dictionaries added, parameter Port
HelenMamontova Jan 29, 2025
0caf1b8
Merge remote-tracking branch 'madf/master' into radius
HelenMamontova Feb 4, 2025
a79c030
Radius. Header files added. Class RAD_SETTINGS added. Methods
HelenMamontova Feb 4, 2025
014c78d
Radius. Parameter default changed to optional and parameters value
HelenMamontova Feb 6, 2025
1ff4563
Radius. Description of parameters secret, port, dictionaries changed.
HelenMamontova Feb 6, 2025
b2264e8
Radius. Copy constructor RADIUS and assignment operator declaration
HelenMamontova Feb 6, 2025
a4ff4c9
Radius. Class member m_mutex moved to the top of section private.
HelenMamontova Feb 6, 2025
f35612b
Radius. The m_port variable value initialization changed to 1812,
HelenMamontova Feb 6, 2025
4c782bc
Radius. Check for missing parameters port and dictionaries removed in…
HelenMamontova Feb 7, 2025
7505bfc
Merge remote-tracking branch 'madf/master' into radius
HelenMamontova Feb 12, 2025
0889076
Merge remote-tracking branch 'madf/master' into radius
HelenMamontova Feb 19, 2025
b4a5568
Radius. The dist directory added.
HelenMamontova Feb 28, 2025
f852128
Radius. The methods declaration stop and start added.
HelenMamontova Feb 28, 2025
d89cd5e
Radius. The methods stop, start definition added. Method start call
HelenMamontova Feb 28, 2025
22b6a97
Radius. The header files "server.h", <boost/asio.hpp>, <memory> added.
HelenMamontova Feb 28, 2025
b137bad
Radius. The header files "server", <boost/asio.hpp>, <string> removed.
HelenMamontova Feb 28, 2025
d833278
Radius. Header files <stop_token> and <jthread.hpp> added. Parameter
HelenMamontova Mar 7, 2025
af7b211
Radius. Parameter token and m_token class member initialization added…
HelenMamontova Mar 7, 2025
d1f81ba
Radius. The m_server class member initialization removed.
HelenMamontova Mar 7, 2025
2961aec
Radius. The m_server->stop() call adnd m_thread.request_stop() call
HelenMamontova Mar 7, 2025
881c2fd
Radius. Header file "stg/logger.h" added. Class member m_logger added to
HelenMamontova Mar 10, 2025
7e273c9
Radius. Header file "stg/common.h" added, header file <iostream>
HelenMamontova Mar 10, 2025
dc45849
Radius. Class member m_logger initialization changed in the constructor
HelenMamontova Mar 12, 2025
b29a918
Radius. Check token added to handleReceive method.
HelenMamontova Mar 12, 2025
a69f043
Radius. Header file <stop_token> replaced by <stop_token.hpp>, header
HelenMamontova Mar 12, 2025
46c4133
Radius. Parameter m_logger added to constructor Server call in the
HelenMamontova Mar 14, 2025
095f460
Radius. Parameter logger added to constructor Server declaration. Class
HelenMamontova Mar 14, 2025
db47a07
Radius. Parameter logger added to constructor Server definition. Class
HelenMamontova Mar 14, 2025
2f1a11c
Radius. Extra whitespace removed ib the method Run.
HelenMamontova Mar 17, 2025
a110cf6
Radius. The order of operations changed in the method handleSend.
HelenMamontova Mar 17, 2025
4b86c90
Radius. The order of operations changed in the method handleReceive.
HelenMamontova Mar 17, 2025
01225c4
Radius. Operator return removed when checking ec, operator else removed
HelenMamontova Mar 18, 2025
c2aaf5e
Radius. Parameter token replaced by std::move(token) in the construct…
HelenMamontova Mar 18, 2025
bb71551
Radius. Class member m_token initialization value changed to
HelenMamontova Mar 18, 2025
129fc5c
Radius. The c_str() function added to message when checking error in the
HelenMamontova Mar 18, 2025
7c1cc07
Radius. Header file <cstring> added.
HelenMamontova Mar 18, 2025
627c306
Merge remote-tracking branch 'madf/master' into radius
HelenMamontova Mar 19, 2025
5d9d30e
Radius. Header files "stg/users.h", "stg/user.h", "stg/user_property.h"
HelenMamontova Mar 28, 2025
9cce8e2
Radius. Header files "radproto/attribute_types.h", <cstdint> added.
HelenMamontova Mar 28, 2025
0ff99e1
Radius. Getting the values of login and password fixed in the function
HelenMamontova Apr 1, 2025
6d03d72
Radius. Using statements added. Method SetUsers added, variable class
HelenMamontova Apr 3, 2025
24cf9ce
Radius. The class member variable m_users initialization added to
HelenMamontova Apr 3, 2025
e0d0c90
Radius. Parameter users added to constructir Server declaration.
HelenMamontova Apr 3, 2025
2c18f40
Radius. Parameter users added to constructor Server definition. Variable
HelenMamontova Apr 3, 2025
2ab70c7
Radius. Function c_str added to login and password in m_logger and
HelenMamontova Apr 4, 2025
6f03749
Merge remote-tracking branch 'madf/master' into radius
HelenMamontova Apr 14, 2025
86af31d
Radius. Extra functions printfd removed.
HelenMamontova Apr 15, 2025
42c0748
Radius. The using declaration for UserPtr, ConstUserPtr removed.
HelenMamontova Apr 16, 2025
0173c0b
Radius. Looking for user moved after check request type in the
HelenMamontova Apr 16, 2025
8422222
Radius. The using declaration for UserPtr, ConstUserPtr removed. Header
HelenMamontova Apr 16, 2025
dc85736
Radius. Header files "stg/user.h", "stg/users.h" added.
HelenMamontova Apr 16, 2025
5ae59ee
Radius. Function findUser moved to private.
HelenMamontova Apr 16, 2025
cf4f88c
Radius. Return type of function findUser changed to bool.
HelenMamontova Apr 16, 2025
52714c2
Radius. Return type of function findUser definition and call changed …
HelenMamontova Apr 16, 2025
e047e61
Radius. Variables attributesEmpty, vendorSpecificEmpty added for packet
HelenMamontova Apr 17, 2025
84ac11e
Radius. Type STG::Users* replaced by Users* in parameter users in the
HelenMamontova Apr 21, 2025
37b47b2
Radius. Condition and code order changed when packet is returned in
HelenMamontova Apr 21, 2025
da54173
Radius. Unnecessary variables attributeEmpty, vendorSpecificEmpty
HelenMamontova Apr 21, 2025
5e03dd0
Radius. Prefix STG of user object removed, user is initialized by
HelenMamontova Apr 21, 2025
a12adbd
Radius. Extra printfd function call removed in the function findUser.
HelenMamontova Apr 21, 2025
15ff937
Radius. The way of initializing the object user changed in the findUser
HelenMamontova Apr 22, 2025
92e202f
Radius. Prefix STG of class member m_users and of parameter u in
HelenMamontova Apr 22, 2025
f6eb048
Radius. Prefix STG of class member m_users and of parameter users
HelenMamontova Apr 22, 2025
ba3ad7b
Radius. The messages of m_logger and printfd changed in function
HelenMamontova Apr 22, 2025
36ecbb6
Merge remote-tracking branch 'madf/master' into radius
HelenMamontova Apr 23, 2025
3ea9d0a
Radius. Search for parameters auth and send added to the ParseSetting…
HelenMamontova Apr 30, 2025
0db4900
Radius. Extra whitespace removed, unnecessary variables sendValue and
HelenMamontova May 2, 2025
e2c5027
Radius. The struct AttrValue added.
HelenMamontova May 14, 2025
ae2a068
Radius. Header files <boost/tokenizer.hpp>, <vector>, <utility> added.
HelenMamontova May 14, 2025
967321f
Radius. Filling vector of pairs attrSend added. Extra printfd function
HelenMamontova May 15, 2025
cd918e5
Radius. The Sign enumeration elements names changed in the struct
HelenMamontova May 19, 2025
43d4001
Radius. Using declaration for struct AttrValue added. Function ParseS…
HelenMamontova May 19, 2025
023dbb4
Radius. The enum class Sign renamed to Type, object sign renamed to
HelenMamontova May 20, 2025
c8bd692
Radius. The enum class Sign renamed to Type, object sign renamed to type
HelenMamontova May 20, 2025
0e1f6fe
Radius. The enumerator names NOT_VALUE changed to PARAN_NAME, IS_VALUE
HelenMamontova May 20, 2025
218b6d7
Radius. Radius. The enumerator names NOT_VALUE changed to PARAM_NAME,…
HelenMamontova May 20, 2025
534d79b
Radius. The AttrValue struct moved into the RAD_SETTINGS class.
HelenMamontova May 20, 2025
3225952
Radius. The using statement for struct AttrValue removed. The using a…
HelenMamontova May 20, 2025
ce26783
Radius. The vector parsedSendAttr check added to the function
HelenMamontova May 21, 2025
7b1bbb5
Radius. The ParseSendAttr method added, m_logger variable class member
HelenMamontova May 22, 2025
15c5a1f
Radius. ParseSendAttr function changed to method of RAD_SETTINGS class.
HelenMamontova May 22, 2025
154edc3
Radius. Quotes check for the ValueName added to the ParseSendAttr
HelenMamontova May 23, 2025
b5e9b4f
Radius. Extra variables attrValue.value and attrValue.type removed in
HelenMamontova May 23, 2025
233bd64
Radius. Extra variable attrValue removed in ParseSendAttr method.
HelenMamontova May 26, 2025
f24d062
Radius. Send attributes parsing changed in method ParseSendAttr.
HelenMamontova May 26, 2025
bd30450
Radius. Argument fieldSendAttr name changed to value and argument type
HelenMamontova May 27, 2025
c07c0a7
Radius. Argument fieldSendAttr name changed to value and argument type
HelenMamontova May 27, 2025
c1f4bd7
Radius. Vector name parsedSendAttr changed to keyValue in ParseSendAttr
HelenMamontova May 27, 2025
bfcb298
Radius. Functions front() and back() are used to get the first and last
HelenMamontova May 27, 2025
e87368d
Radius. Method declaration ParseSendAttr moved to private in class
HelenMamontova May 27, 2025
8baf9e0
Radius. Formatting fixed. Class member m_res and public function
HelenMamontova May 27, 2025
9367195
Radius. Extra variable res removed. Class member m_res definition added
HelenMamontova May 27, 2025
3d62827
Radius. Vector res added, variable m_res replaced by res in
HelenMamontova May 28, 2025
85b9f0d
Radius. Function name GetRes changed to GetSendPairs, class member
HelenMamontova May 28, 2025
44844ce
Radius. Class member vaiable name m_res changed to m_sendPairs in the
HelenMamontova May 28, 2025
ccfecf2
Radius. Parameter auth added to mod_radius.conf.
HelenMamontova Jun 4, 2025
9c6ee36
Radius. The ParseMatchAttr method declaration and m_matchPairs class
HelenMamontova Jun 4, 2025
b2304ca
Radius. The ParseMatchAttr function definition added. Match attributes
HelenMamontova Jun 4, 2025
4d6fcb7
Radius. The ParseMatchAttr method removed, the ParseSendAttr method
HelenMamontova Jun 5, 2025
083c78b
Radius. The ParseSendAttr method definition and call renamed to
HelenMamontova Jun 5, 2025
8509152
Radius. Attribute for parameter auth/match changed.
HelenMamontova Jun 6, 2025
ee9496a
Radius. Parameter autz added.
HelenMamontova Jun 6, 2025
97235bb
Radius. ParseAuthAttr function renamed to ParseAuthAutzAttr.
HelenMamontova Jun 6, 2025
a5b0dbd
Radius. ParseAuthAttr function renamed to ParseAuthAutzAttr. The autz
HelenMamontova Jun 6, 2025
a132484
Radius. ParseAuthAutzAttr function renamed to ParseSectionsAttr. The …
HelenMamontova Jun 11, 2025
e609021
Radius. ParseAuthAutzAttr function renamed to ParseSectionsAttr. The …
HelenMamontova Jun 11, 2025
91b514a
Radius. Attributes of auth/send, autz/send, autz/match changed.
HelenMamontova Jun 12, 2025
63ba77a
Radius. ParseSectionsAttr function name changed to ParseRyles.
HelenMamontova Jun 12, 2025
c79b7c1
Radius. ParseSectionsAttr function name definition and call changed t…
HelenMamontova Jun 12, 2025
92eff02
Radius. Extra printfd function call removed in MakeKeyValuePairs
HelenMamontova Jun 13, 2025
9f96684
Radius. The ShowRules, GetSendPairsAuth, GetMatchPairsAuth, GetSendPa…
HelenMamontova Jun 19, 2025
ddcaf6f
Radius. The ShowRules function definition added and its call in
HelenMamontova Jun 19, 2025
3a559a6
Radius. The strRules string creating fixed and strRules string rename…
HelenMamontova Jun 20, 2025
646790b
Radius. Parameter name changed to attributes and & added to parameter in
HelenMamontova Jun 20, 2025
dab9c61
Radius. The ShowRules function definition changed. Parameter name cha…
HelenMamontova Jun 20, 2025
3b7bc48
Radius. The struct ASection added. The getAuth, getAutz, parseASection
HelenMamontova Jun 25, 2025
4078c17
Radius. The using ASection for alias added. The parseASection function
HelenMamontova Jun 25, 2025
d1d90e1
Radius. The return added to parseASection function. Extra printfd
HelenMamontova Jun 26, 2025
a744e30
Radius. GIT_TAG changed to 1.1.3 in the ExternalProject_Add for
HelenMamontova Jul 7, 2025
fccd8cd
Radius. The m_ioService class member replaced by m_ioContext in class
HelenMamontova Jul 8, 2025
b5b8299
Radius. The m_ioService class member replaced by m_ioContext in the
HelenMamontova Jul 8, 2025
49f9369
Radius. Parameter io_service replaced by io_context in the constructo…
HelenMamontova Jul 8, 2025
0d97b85
Radius. Parameter io_service replaced by io_context in the constructo…
HelenMamontova Jul 8, 2025
e51985c
Radius. Parameters msg, ip commented out in the SendMessage function.
HelenMamontova Jul 9, 2025
5fdde10
Radius. Variable 'sep' declared 'const' in ParseRules function.
HelenMamontova Jul 9, 2025
2981417
Radius. Variables 'tokens', 'sp', 'tok' declared 'const' in ParseRule…
HelenMamontova Jul 9, 2025
a650b2a
Radius. ShowRules function declaration removed from class RAD_SETTINGS.
HelenMamontova Jul 9, 2025
72e22dc
Radius. ShowRules function definition is made as a free function.
HelenMamontova Jul 9, 2025
f26626c
Radius. ShowRules function definition is placed in the anonymous name…
HelenMamontova Jul 10, 2025
d31ccb3
Radius. The code for determining the first element of vector changed …
HelenMamontova Jul 10, 2025
0128fa2
Radius. Function SetUsers declaration is made as override in the class
HelenMamontova Jul 10, 2025
498c75a
Radius. Header file <algorithm> added.
HelenMamontova Jul 10, 2025
8d1f715
Radius. The rad_settings.cpp file name added to add_library for MODULE
HelenMamontova Jul 21, 2025
ae4014b
Radius. Header file "rad_settings.h" added. RAD_SETTINGS class
HelenMamontova Jul 21, 2025
fa8aca9
Radius. Header files <boost/tokenizer.hpp>, <vector>, <iterator>,
HelenMamontova Jul 21, 2025
d74bb0b
Radius. The new file rad_settings.h added.
HelenMamontova Jul 21, 2025
5909001
Radius. The new file rad_settings.cpp added.
HelenMamontova Jul 21, 2025
fbd5b1c
Radius. Header file "rad_settings.h" added. Parameter radSettings add…
HelenMamontova Jul 21, 2025
b5819ad
Radius. Parameter radSettings added to constructor Server definition.…
HelenMamontova Jul 21, 2025
3ec586e
Radius. The attributes User-Name, Cacllback-Number added to section <…
HelenMamontova Aug 27, 2025
694212f
Radius. Class User forward declaration added. Parameter radSettings
HelenMamontova Aug 27, 2025
b7ce5c4
Radius. Header files added. The using statement for STG User added. P…
HelenMamontova Aug 27, 2025
16884a3
Merge remote-tracking branch 'madf/master' into radius
HelenMamontova Aug 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# Port = 1812

<auth>
send = "Framed-IP-Address = currip, Service-Type = \'Framed-User\'"
send = "User-Name = login, Framed-IP-Address = currip, Service-Type = \'Framed-User\', Callback-Number = \'987654abc\'"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep the original value. It makes more sense.

match = "Calling-Station-Id = userdata0"
</auth>

Expand Down
3 changes: 2 additions & 1 deletion projects/stargazer/plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about just settings.cpp?

target_link_libraries ( mod_radius PRIVATE scriptexecuter logger common )
set_target_properties ( mod_radius PROPERTIES PREFIX "" )

Expand Down
147 changes: 147 additions & 0 deletions projects/stargazer/plugins/other/radius/rad_settings.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
#include "rad_settings.h"
#include "radproto/error.h"
#include "stg/common.h"
#include <boost/tokenizer.hpp>

#include <vector>
#include <utility>
#include <iterator>
#include <algorithm>
#include <iostream>

using STG::RAD_SETTINGS;
using AttrValue = RAD_SETTINGS::AttrValue;
using ASection = RAD_SETTINGS::ASection;

namespace
{
std::string ShowRules(const std::vector<std::pair<std::string, AttrValue>>& 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<std::pair<std::string, AttrValue>> RAD_SETTINGS::ParseRules(const std::string& value, const std::string& paramName)
{
using tokenizer = boost::tokenizer<boost::char_separator<char>>;
const boost::char_separator<char> sep(",");

const tokenizer tokens(value, sep);

std::vector<std::pair<std::string, AttrValue>> res;
for (const auto& token : tokens)
{
const boost::char_separator<char> sp(" =");
const tokenizer tok(token, sp);

std::vector<std::string> 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<ParamValue>& 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<uint16_t>(p);
}

pv.param = "Secret";
pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv);
if (pvi == s.moduleParams.end() || pvi->value.empty())
{
m_errorStr = "Parameter \'Secret\' not found.";
printfd(__FILE__, "Parameter 'Secret' not found\n");
m_secret = "";
}
else
m_secret = pvi->value[0];

pv.param = "Dictionaries";
pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv);
if (pvi != s.moduleParams.end() && !pvi->value.empty())
m_dictionaries = pvi->value[0];

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;
}

60 changes: 60 additions & 0 deletions projects/stargazer/plugins/other/radius/rad_settings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#pragma once

#include "stg/module_settings.h"
#include "stg/subscriptions.h"
#include "stg/logger.h"

#include <string>
#include <cstdint> //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<std::pair<std::string, AttrValue>>;
Pairs match;
Pairs send;
};

const std::string& GetStrError() const { return m_errorStr; }
int ParseSettings(const ModuleSettings& s);

uint16_t GetPort() const { return m_port; }
const std::string& GetDictionaries() const { return m_dictionaries; }
const std::string& GetSecret() const { return m_secret; }
const ASection& getAuth() const { return m_auth; }
const ASection& getAutz() const { return m_autz; }

private:
std::vector<std::pair<std::string, AttrValue>> ParseRules(const std::string& value, const std::string& paramName);
ASection parseASection(const std::vector<ParamValue>& conf);

std::string m_errorStr;
uint16_t m_port;
std::string m_dictionaries;
std::string m_secret;

ASection m_auth;
ASection m_autz;

PluginLogger m_logger;
};
}
141 changes: 1 addition & 140 deletions projects/stargazer/plugins/other/radius/radius.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,155 +3,16 @@
#include "stg/common.h"
#include <boost/tokenizer.hpp>

#include <vector>
#include <utility>
#include <iterator>
#include <algorithm>
#include <iostream>

using STG::RADIUS;
using STG::RAD_SETTINGS;
using AttrValue = RAD_SETTINGS::AttrValue;
using ASection = RAD_SETTINGS::ASection;

extern "C" STG::Plugin* GetPlugin()
{
static RADIUS plugin;
return &plugin;
}

namespace
{
std::string ShowRules(const std::vector<std::pair<std::string, AttrValue>>& 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<std::pair<std::string, AttrValue>> RAD_SETTINGS::ParseRules(const std::string& value, const std::string& paramName)
{
using tokenizer = boost::tokenizer<boost::char_separator<char>>;
const boost::char_separator<char> sep(",");

const tokenizer tokens(value, sep);

std::vector<std::pair<std::string, AttrValue>> res;
for (const auto& token : tokens)
{
const boost::char_separator<char> sp(" =");
const tokenizer tok(token, sp);

std::vector<std::string> 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<ParamValue>& 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<uint16_t>(p);
}

pv.param = "Secret";
pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv);
if (pvi == s.moduleParams.end() || pvi->value.empty())
{
m_errorStr = "Parameter \'Secret\' not found.";
printfd(__FILE__, "Parameter 'Secret' not found\n");
m_secret = "";
}
else
m_secret = pvi->value[0];

pv.param = "Dictionaries";
pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv);
if (pvi != s.moduleParams.end() && !pvi->value.empty())
m_dictionaries = pvi->value[0];

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),
Expand Down Expand Up @@ -212,7 +73,7 @@ int RADIUS::Run(std::stop_token token)
try
{
if (!m_server)
m_server = std::make_unique<Server>(m_ioContext, m_radSettings.GetSecret(), m_radSettings.GetPort(), m_radSettings.GetDictionaries(), std::move(token), m_logger, m_users);
m_server = std::make_unique<Server>(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)
Expand Down
Loading