diff --git a/smradius/attributes.pm b/smradius/attributes.pm index 64985dd3b8258fcabc76d55a92e0e7e977efe7e9..31bcf36f9bcad1d45aeb6f6287564ab0c412cae7 100644 --- a/smradius/attributes.pm +++ b/smradius/attributes.pm @@ -32,6 +32,7 @@ our (@ISA,@EXPORT); addAttribute checkAttributeAuth getReplyAttribute + checkAttributeConfig ); @@ -408,6 +409,80 @@ sub getReplyAttribute +## @fn checkAttributeConfig($server,$packetAttributes,$attribute) +# Function to check an attribute in the configuration stage +# +# @param server Server instance +# @param packetAttributes Hashref of attributes provided, eg. Those from the packet +# @param attribute Attribute to check, eg. One of the ones from the database +sub checkAttributeConfig +{ + my ($server,$configAttributes,$attribute) = @_; + + + # Matched & ok? + my $matched = 0; + + # Figure out our attr values + my @attrValues; + if (ref($attribute->{'Value'}) eq "ARRAY") { + @attrValues = @{$attribute->{'Value'}}; + } else { + @attrValues = ( $attribute->{'Value'} ); + } + + $server->log(LOG_DEBUG,"[ATTRIBUTES] Processing CONFIG attribute value ".niceUndef($attrVal)." against: '". + $attribute->{'Name'}."' ".$attribute->{'Operator'}." '".join("','",@attrValues)."'"); + + # Loop with all the test attribute values + foreach my $tattrVal (@attrValues) { + + # FIXME + # Operator: += + # + # Use: Attribute += Value + # Always matches as a check item, and adds the current + # attribute with value to the list of configuration items. + # + # As a reply item, it has an itendtical meaning, but the + # attribute is added to the reply items. + + if ($attribute->{'Operator'} eq '+=') { + $server->log(LOG_DEBUG,"[ATTRIBUTES] Operator '+=' triggered: Adding item to configuration items."); + $matched = 1; + + # FIXME + # Operator: := + # + # Use: Attribute := Value + # Always matches as a check item, and replaces in the configuration items any attribute of the same name. + # If no attribute of that name appears in the request, then this attribute is added. + # + # As a reply item, it has an itendtical meaning, but for the reply items, instead of the request items. + + } elsif ($attribute->{'Operator'} eq ':=') { + $server->log(LOG_DEBUG,"[ATTRIBUTES] Operator ':=' triggered: Adding or replacing item in configuration items."); + $matched = 1; + + # Attributes that are not defined + } else { + # Ignore + $matched = 2; + last; + } + } + + # Some debugging info + if ($matched == 1) { + $server->log(LOG_DEBUG,"[ATTRIBUTES] - Attribute '".$attribute->{'Name'}."' matched"); + } elsif ($matched == 2) { + $server->log(LOG_DEBUG,"[ATTRIBUTES] - Attribute '".$attribute->{'Name'}."' ignored"); + } else { + $server->log(LOG_DEBUG,"[ATTRIBUTES] - Attribute '".$attribute->{'Name'}."' not matched"); + } + + return $matched; +} diff --git a/smradius/modules/accounting/mod_accounting_sql.pm b/smradius/modules/accounting/mod_accounting_sql.pm index 3e7b515069d215df9a8cb03bd57dc13938f61230..27ebeaa1d6b2490c090adbf8bfe6a048b2840ee0 100644 --- a/smradius/modules/accounting/mod_accounting_sql.pm +++ b/smradius/modules/accounting/mod_accounting_sql.pm @@ -30,7 +30,6 @@ use smradius::util; use DateTime; use POSIX qw(ceil); -use Data::Dumper; # Exporter stuff require Exporter; diff --git a/smradius/modules/config/mod_config_sql.pm b/smradius/modules/config/mod_config_sql.pm index a1706d502303d27cdec95f4654120410b083b0bb..a14600fa4640fe5c9751a9a1062cf1573f398dcf 100644 --- a/smradius/modules/config/mod_config_sql.pm +++ b/smradius/modules/config/mod_config_sql.pm @@ -71,8 +71,6 @@ sub init Name, Operator, Value FROM @TP@realm_attributes - WHERE - RealmID = %{realms.ID} '; diff --git a/smradiusd b/smradiusd index f002e323957bb0dc909ae00020e630fa4a893c30..be0b34356ce478a1d115a13377a85bbc9711f811 100755 --- a/smradiusd +++ b/smradiusd @@ -547,8 +547,6 @@ sub process_request { # Main user hash with everything in my $user; - - # # GRAB CONFIG FIXME # @@ -563,13 +561,35 @@ sub process_request { if ($configData) { # Add what we have received to the user hash $user->{'ConfigData'} = $configData; - $self->log(LOG_NOTICE,"[SMRADIUS] ConfigData: ".Dumper($user->{'ConfigData'})); last; } } } + # + # FIXME USER + # + + # Build a list of our attributes in the packet + my $configAttributes; + foreach my $attr ($pkt->attributes) { + $configAttributes->{$attr} = $pkt->rawattr($attr); + } + # Loop with attributes we got from the user + foreach my $attribute (@{$user->{'ConfigData'}->{'ConfigAttributes'}}) { + # Check attribute against authorization attributes + my $res = checkAttributeConfig($self,$configAttributes,$attribute); + if ($res == 0) { + $self->log(LOG_DEBUG,"[SMRADIUS] Failed checkAttributeConfig(): Do something here"); + last; + } + } + + # We don't want to process everyting if something doesn't match + # last if (!$authorized); + #} + # UserDB module if we using/need it my $userdb; diff --git a/smradiusd.conf b/smradiusd.conf index 0b57e2e0cb598f0af9f32e423db38705a8f96f96..384f4ab6b1a6045c405e3791a35f3f75e3a99385 100644 --- a/smradiusd.conf +++ b/smradiusd.conf @@ -103,15 +103,13 @@ mod_auth_mschap EOT users=<<EOT -mod_userdb_test mod_userdb_sql EOT [system] plugins=<<EOT -mod_config_test -mod_config_sql +mod_userdb_sql EOT @@ -124,7 +122,7 @@ EOT [accounting] plugins=<<EOT -mod_accounting_test +mod_accounting_sql EOT