From 5a65b2a580dcefc621b30e6b6572cb23f3a643d6 Mon Sep 17 00:00:00 2001
From: Robert Anderson <randerson@lbsd.net>
Date: Sun, 26 Apr 2009 18:33:52 +0000
Subject: [PATCH] * Commit of work of config attributes

---
 smradius/attributes.pm                        | 75 +++++++++++++++++++
 .../modules/accounting/mod_accounting_sql.pm  |  1 -
 smradius/modules/config/mod_config_sql.pm     |  2 -
 smradiusd                                     | 26 ++++++-
 smradiusd.conf                                |  6 +-
 5 files changed, 100 insertions(+), 10 deletions(-)

diff --git a/smradius/attributes.pm b/smradius/attributes.pm
index 64985dd3..31bcf36f 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 3e7b5150..27ebeaa1 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 a1706d50..a14600fa 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 f002e323..be0b3435 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 0b57e2e0..384f4ab6 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
 
 
-- 
GitLab