Commit d06e927b authored by Nigel Kukard's avatar Nigel Kukard
Browse files

* Added support for vendor attributes in the form of [vendor_id:attribute_name]

parent 996466c6
......@@ -57,35 +57,57 @@ my @attributeVReplyIgnoreList = (
);
## @fn addAttribute($server,$attributes,$attribute)
## @fn addAttribute($server,$nattributes,$vattributes,$attribute)
# Function to add an attribute to $attributes
#
# @param server Server instance
# @param attributes Hashref of attributes we already have and / or must add to
# @param nattributes Hashref of normal attributes we already have and/or must add to
# @param vattributes Hashref of vendor attributes we already have and/or must add to
# @param attribute Attribute to add, eg. Those from a database
sub addAttribute
{
my ($server,$attributes,$attribute) = @_;
my ($server,$nattributes,$vattributes,$attribute) = @_;
# Clean them up a bit
$attribute->{'Name'} =~ s/\s*(\S+)\s*/$1/;
$attribute->{'Operator'} =~ s/\s*(\S+)\s*/$1/;
# Grab attribue name, operator and value
my $name = $attribute->{'Name'};
my $operator = $attribute->{'Operator'};
my $value = $attribute->{'Value'};
# Default attribute to add is normal
my $attributes = $nattributes;
# Check where we must add this attribute, maybe to the vendor attributes?
if ($name =~ /^\[(\d+):(\S+)\]$/) {
my $vendor = $1; $name = $2;
# Set vendor
$attribute->{'Vendor'} = $vendor;
# Reset attribute name
$attribute->{'Name'} = $name;
# Set the attributes to use to the vendor
$attributes = $vattributes;
}
# Check if this is an array
if ($attribute->{'Operator'} =~ s/^\|\|//) {
if ($operator =~ s/^\|\|//) {
# Check if we've seen this before
if (defined($attributes->{$attribute->{'Name'}}->{$attribute->{'Operator'}}) &&
ref($attributes->{$attribute->{'Name'}}->{$attribute->{'Operator'}}->{'Value'}) eq "ARRAY" ) {
if (defined($attributes->{$name}->{$operator}) &&
ref($attributes->{$name}->{$operator}->{'Value'}) eq "ARRAY" ) {
# Then add value to end of array
push(@{$attributes->{$attribute->{'Name'}}->{$attribute->{'Operator'}}->{'Value'}}, $attribute->{'Value'});
push(@{$attributes->{$name}->{$operator}->{'Value'}}, $value);
# If we have not seen it before, initialize it
} else {
# Assign attribute
$attributes->{$attribute->{'Name'}}->{$attribute->{'Operator'}} = $attribute;
$attributes->{$name}->{$operator} = $attribute;
# Override type ... else we must create a custom attribute hash, this is dirty, but faster
$attributes->{$attribute->{'Name'}}->{$attribute->{'Operator'}}->{'Value'} = [ $attribute->{'Value'} ];
$attributes->{$name}->{$operator}->{'Value'} = [ $value ];
}
# If its not an array, just add it normally
} else {
$attributes->{$attribute->{'Name'}}->{$attribute->{'Operator'}} = $attribute;
$attributes->{$name}->{$operator} = $attribute;
}
}
......
......@@ -202,6 +202,7 @@ sub get
# Attributes to return
my %attributes = ();
my %vattributes = ();
# Replace template entries
my @dbDoParams = templateReplace($config->{'userdb_get_group_attributes_query'},$template);
......@@ -215,7 +216,7 @@ sub get
# Loop with group attributes
while (my $row = $sth->fetchrow_hashref()) {
addAttribute($server,\%attributes,hashifyLCtoMC($row,qw(Name Operator Value)));
addAttribute($server,\%attributes,\%vattributes,hashifyLCtoMC($row,qw(Name Operator Value)));
}
DBFreeRes($sth);
......@@ -233,12 +234,16 @@ sub get
# Loop with group attributes
while (my $row = $sth->fetchrow_hashref()) {
addAttribute($server,\%attributes,hashifyLCtoMC($row,qw(Name Operator Value)));
addAttribute($server,\%attributes,\%vattributes,hashifyLCtoMC($row,qw(Name Operator Value)));
}
DBFreeRes($sth);
return \%attributes;
my $ret;
$ret->{'Attributes'} = \%attributes;
$ret->{'VAttributes'} = \%vattributes;
return $ret;
}
......
......@@ -91,8 +91,8 @@ sub get
{
my ($server,$user,$packet) = @_;
my $userDetails = {
# Attributes to return
my $attributes = {
'ClearPassword' => 'doap',
'Attributes' => [
{
......@@ -113,7 +113,13 @@ sub get
]
};
my %vattributes = ();
my $ret;
$ret->{'Attributes'} = $attributes;
$ret->{'VAttributes'} = \%vattributes;
return $ret;
return $userDetails;
}
......
......@@ -606,7 +606,8 @@ sub process_request {
# Check result
if (defined($res) && ref($res) eq "HASH") {
# We're only after the attributes here
$user->{'Attributes'} = $res;
$user->{'Attributes'} = $res->{'Attributes'};
$user->{'VAttributes'} = $res->{'VAttributes'};
}
}
......@@ -755,7 +756,8 @@ sub process_request {
goto CHECK_RESULT;
}
# Setup user dataw
$user->{'Attributes'} = $res;
$user->{'Attributes'} = $res->{'Attributes'};
$user->{'VAttributes'} = $res->{'VAttributes'};
} else {
$self->log(LOG_INFO,"[SMRADIUS] GET: No 'User_get' function available for module '".$userdb->{'Name'}."'");
......@@ -885,9 +887,19 @@ sub process_request {
$resp->set_attr($attrName,$value);
}
}
use Data::Dumper; print Dumper($user->{'ReplyVAttributes'});
use Data::Dumper; print Dumper($user->{'VAttributes'});
# Loop with vendor reply attributes
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);
}
}
foreach my $vendor (keys %replyVAttributes) {
# Loop with operators
foreach my $attrName (keys %{$replyVAttributes{$vendor}}) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment