diff --git a/smradius/attributes.pm b/smradius/attributes.pm index b5ebb4e194f17adfd008235422a6be923e9adc0e..397257187d5bd17cc88db0623720983e78d37afd 100644 --- a/smradius/attributes.pm +++ b/smradius/attributes.pm @@ -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; } } diff --git a/smradius/modules/userdb/mod_userdb_sql.pm b/smradius/modules/userdb/mod_userdb_sql.pm index 4362971803b0ebf857bd7086e1a697eb20d83186..8d3b764cd2c1b744a548310bff008ff659d7fe5e 100644 --- a/smradius/modules/userdb/mod_userdb_sql.pm +++ b/smradius/modules/userdb/mod_userdb_sql.pm @@ -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; } diff --git a/smradius/modules/userdb/mod_userdb_test.pm b/smradius/modules/userdb/mod_userdb_test.pm index 217b328d28e8462599393b7a1518e3b5bef9e102..ff4e50920ff15531e42958427dc93e8012d0dc36 100644 --- a/smradius/modules/userdb/mod_userdb_test.pm +++ b/smradius/modules/userdb/mod_userdb_test.pm @@ -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; } diff --git a/smradiusd b/smradiusd index 9f44cca82e9537c76553a96a777577e400fad6aa..f3c216a091bbc991ca14511e5e06677f6603619f 100755 --- a/smradiusd +++ b/smradiusd @@ -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}}) {