Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
smradius
smradius
Commits
01dd85b5
Commit
01dd85b5
authored
May 15, 2019
by
Nigel Kukard
Browse files
Move the processing of reply attributes into its own internal function
parent
4e729270
Changes
1
Hide whitespace changes
Inline
Side-by-side
lib/smradius/daemon.pm
View file @
01dd85b5
...
...
@@ -1166,133 +1166,8 @@ sub process_request {
$resp
->
set_identifier
(
$pkt
->
identifier
);
$resp
->
set_authenticator
(
$pkt
->
authenticator
);
# Loop with attributes we got from the getReplyAttributes function, its a hash of arrays which are the values
my
%replyAttributes
=
%
{
$user
->
{'
ReplyAttributes
'}
};
foreach
my
$attrName
(
keys
%
{
$user
->
{'
Attributes
'}})
{
# Loop with operators
foreach
my
$attrOp
(
keys
%
{
$user
->
{'
Attributes
'}
->
{
$attrName
}})
{
# Grab attribute
my
$attr
=
$user
->
{'
Attributes
'}
->
{
$attrName
}
->
{
$attrOp
};
# Add this to the reply attribute?
setReplyAttribute
(
$self
,
\
%replyAttributes
,
$attr
);
}
}
# Loop with reply attributes
$request
->
addLogLine
("
. RFILTER =>
");
foreach
my
$attrName
(
keys
%replyAttributes
)
{
# Loop with values
foreach
my
$value
(
@
{
$replyAttributes
{
$attrName
}})
{
# Check for filter matches
my
$excluded
=
0
;
foreach
my
$item
(
@
{
$user
->
{'
ConfigAttributes
'}
->
{'
SMRadius-Config-Filter-Reply-Attribute
'}})
{
my
@attrList
=
split
(
/[;,]/
,
$item
);
foreach
my
$aItem
(
@attrList
)
{
$excluded
=
1
if
(
lc
(
$attrName
)
eq
lc
(
$aItem
));
}
}
# If we must be filtered, just exclude it then
if
(
!
$excluded
)
{
# Add each value
$resp
->
set_attr
(
$attrName
,
$value
);
}
else
{
$request
->
addLogLine
("
%s
",
$attrName
);
}
}
}
# Loop with vendor reply attributes
$request
->
addLogLine
("
. RVFILTER =>
");
my
%replyVAttributes
=
();
# Process reply vattributes already added
foreach
my
$vendor
(
keys
%
{
$user
->
{'
ReplyVAttributes
'}
})
{
# Loop with operators
foreach
my
$attrName
(
keys
%
{
$user
->
{'
ReplyVAttributes
'}
->
{
$vendor
}})
{
# Add each value
foreach
my
$value
(
@
{
$user
->
{'
ReplyVAttributes
'}{
$vendor
}
->
{
$attrName
}})
{
# Check for filter matches
my
$excluded
=
0
;
foreach
my
$item
(
@
{
$user
->
{'
ConfigAttributes
'}
->
{'
SMRadius-Config-Filter-Reply-VAttribute
'}})
{
my
@attrList
=
split
(
/[;,]/
,
$item
);
foreach
my
$aItem
(
@attrList
)
{
$excluded
=
1
if
(
lc
(
$attrName
)
eq
lc
(
$aItem
));
}
}
# If we must be filtered, just exclude it then
if
(
!
$excluded
)
{
# This attribute is not excluded, so its ok
$replyVAttributes
{
$vendor
}
->
{
$attrName
}
=
$user
->
{'
ReplyVAttributes
'}
->
{
$vendor
}
->
{
$attrName
};
}
else
{
$request
->
addLogLine
("
%s
",
$attrName
);
}
}
}
}
# Process VAttributes
foreach
my
$attrName
(
keys
%
{
$user
->
{'
VAttributes
'}})
{
# Loop with operators
foreach
my
$attrOp
(
keys
%
{
$user
->
{'
VAttributes
'}
->
{
$attrName
}})
{
# Check for filter matches
my
$excluded
=
0
;
foreach
my
$item
(
@
{
$user
->
{'
ConfigAttributes
'}
->
{'
SMRadius-Config-Filter-Reply-VAttribute
'}})
{
my
@attrList
=
split
(
/[;,]/
,
$item
);
foreach
my
$aItem
(
@attrList
)
{
$excluded
=
1
if
(
lc
(
$attrName
)
eq
lc
(
$aItem
));
}
}
# If we must be filtered, just exclude it then
if
(
!
$excluded
)
{
# Grab attribute
my
$attr
=
$user
->
{'
VAttributes
'}
->
{
$attrName
}
->
{
$attrOp
};
# Add this to the reply attribute?
setReplyVAttribute
(
$self
,
\
%replyVAttributes
,
$attr
);
}
else
{
$request
->
addLogLine
("
%s
",
$attrName
);
}
}
}
foreach
my
$vendor
(
keys
%replyVAttributes
)
{
# Loop with operators
foreach
my
$attrName
(
keys
%
{
$replyVAttributes
{
$vendor
}})
{
# Add each value
foreach
my
$value
(
@
{
$replyVAttributes
{
$vendor
}
->
{
$attrName
}})
{
$resp
->
set_vsattr
(
$vendor
,
$attrName
,
$value
);
}
}
}
# Add attributes onto logline
$request
->
addLogLine
("
. REPLY =>
");
foreach
my
$attrName
(
$resp
->
attributes
)
{
$request
->
addLogLine
(
"
%s: '%s
",
$attrName
,
$resp
->
rawattr
(
$attrName
)
);
}
# Add vattributes onto logline
$request
->
addLogLine
("
. VREPLY =>
");
# Loop with vendors
foreach
my
$vendor
(
$resp
->
vendors
())
{
# Loop with attributes
foreach
my
$attrName
(
$resp
->
vsattributes
(
$vendor
))
{
# Grab the value
my
@attrRawVal
=
(
$resp
->
vsattr
(
$vendor
,
$attrName
)
);
my
$attrVal
=
$attrRawVal
[
0
][
0
];
# Sanatize it a bit
if
(
$attrVal
=~
/[[:cntrl:]]/
)
{
$attrVal
=
"
-nonprint-
";
}
else
{
$attrVal
=
"
'
$attrVal
'
";
}
$request
->
addLogLine
(
"
%s/%s: %s
",
$vendor
,
$attrName
,
$attrVal
);
}
}
# Process the reply attributes
$self
->
_processReplyAttributes
(
$request
,
$user
,
$resp
);
$server
->
{'
client
'}
->
send
(
auth_resp
(
$resp
->
pack
,
getAttributeValue
(
$user
->
{'
ConfigAttributes
'},"
SMRadius-Config-Secret
"))
...
...
@@ -1424,6 +1299,127 @@ EOF
#
# Internal functions
#
# Process reply attributes
sub _processReplyAttributes
{
my ($self,$request,$user,$pkt) = @_;
# Add attributes we got from plugins and process attributes attached to the user
my %replyAttributes = %{ $user->{
'
ReplyAttributes
'
} };
foreach my $attrName (keys %{$user->{
'
Attributes
'
}}) {
# Loop with operators
foreach my $attrOp (keys %{$user->{
'
Attributes
'
}->{$attrName}}) {
# Grab attribute
my $attr = $user->{
'
Attributes
'
}->{$attrName}->{$attrOp};
# Add this to the reply attribute?
setReplyAttribute($self,\%replyAttributes,$attr);
}
}
# Add vendor attributes we got from plugins and process attributes attached to the user
my %replyVAttributes = %{ $user->{
'
ReplyVAttributes
'
} };
foreach my $attrName (keys %{$user->{
'
VAttributes
'
}}) {
# Loop with operators
foreach my $attrOp (keys %{$user->{
'
VAttributes
'
}->{$attrName}}) {
# Grab attribute
my $attr = $user->{
'
VAttributes
'
}->{$attrName}->{$attrOp};
# Add this to the reply attribute?
setReplyVAttribute($self,\%replyVAttributes,$attr);
}
}
# Loop with reply attributes add them to our response, or output them to log if they were excluded
$request->addLogLine("RFILTER => ");
foreach my $attrName (keys %replyAttributes) {
# Loop with values
foreach my $value (@{$replyAttributes{$attrName}}) {
# Check for filter matches
my $excluded = 0;
foreach my $item (@{$user->{
'
ConfigAttributes
'
}->{
'
SMRadius
-
Config
-
Filter
-
Reply
-
Attribute
'
}}) {
my @attrList = split(/[;,]/,$item);
foreach my $aItem (@attrList) {
$excluded = 1 if (lc($attrName) eq lc($aItem));
}
}
# If we must be filtered, just exclude it then
if (!$excluded) {
# Add each value
$pkt->set_attr($attrName,$value);
} else {
$request->addLogLine("%s ",$attrName);
}
}
}
# Loop with reply vendor attributes add them to our response, or output them to log if they were excluded
$request->addLogLine(". RVFILTER => ");
# Process reply vattributes already added
foreach my $vendor (keys %replyVAttributes) {
# Loop with operators
foreach my $attrName (keys %{$replyVAttributes{$vendor}}) {
# Add each value
foreach my $value (@{$replyVAttributes{$vendor}->{$attrName}}) {
# Check for filter matches
my $excluded = 0;
foreach my $item (@{$user->{
'
ConfigAttributes
'
}->{
'
SMRadius
-
Config
-
Filter
-
Reply
-
VAttribute
'
}}) {
my @attrList = split(/[;,]/,$item);
foreach my $aItem (@attrList) {
$excluded = 1 if (lc($attrName) eq lc($aItem));
}
}
# If we must be filtered, just exclude it then
if (!$excluded) {
# This attribute is not excluded, so its ok
$pkt->set_vsattr($vendor,$attrName,$value);
} else {
$request->addLogLine("%s ",$attrName);
}
}
}
}
# Add attributes onto logline
$request->addLogLine(". REPLY => ");
foreach my $attrName ($pkt->attributes) {
$request->addLogLine(
"%s:
'
%s
"
,
$attrName
,
$pkt
->rawattr(
$attrName
)
);
}
# Add vattributes onto logline
$request
->addLogLine(
"
.
VREPLY
=>
"
);
# Loop with vendors
foreach my
$vendor
(
$pkt
->vendors()) {
# Loop with attributes
foreach my
$attrName
(
$pkt
->vsattributes(
$vendor
)) {
# Grab the value
my
@attrRawVal
= (
$pkt
->vsattr(
$vendor
,
$attrName
) );
my
$attrVal
=
$attrRawVal
[0][0];
# Sanatize it a bit
if (
$attrVal
=~ /[[:cntrl:]]/) {
$attrVal
=
"
-
nonprint
-
"
;
} else {
$attrVal
=
"'
$attrVal
'"
;
}
$request
->addLogLine(
"
%s
/
%s:
%s
"
,
$vendor
,
$attrName
,
$attrVal
);
}
}
return
$self
;
};
1;
# vim: ts=4
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment