Skip to content
Snippets Groups Projects
Commit b2a96e2b authored by Robert Anderson's avatar Robert Anderson
Browse files

Reject connection if no realms are found

parent c8bdc576
No related branches found
No related tags found
No related merge requests found
...@@ -161,15 +161,16 @@ sub getConfig ...@@ -161,15 +161,16 @@ sub getConfig
# Default realm... # Default realm...
my $realmName = '<DEFAULT>'; my $realmName = '<DEFAULT>';
my $realmID;
# Get default realm ID # Get default realm ID
my $sth = DBSelect($config->{'get_config_realm_id_query'},$realmName); my $sth = DBSelect($config->{'get_config_realm_id_query'},$realmName);
if (!$sth) { if (!$sth) {
$server->log(LOG_ERR,"Failed to get default config attributes: ".awitpt::db::dblayer::Error()); $server->log(LOG_ERR,"Failed to get default realm ID: ".awitpt::db::dblayer::Error());
return MOD_RES_NACK; return MOD_RES_NACK;
} }
# Set realm ID # Set realm ID
my ($row,$realmID); my $row;
if ($sth->rows == 1) { if ($sth->rows == 1) {
$row = hashifyLCtoMC($sth->fetchrow_hashref(),qw(ID)); $row = hashifyLCtoMC($sth->fetchrow_hashref(),qw(ID));
$realmID = $row->{'ID'}; $realmID = $row->{'ID'};
...@@ -180,7 +181,7 @@ sub getConfig ...@@ -180,7 +181,7 @@ sub getConfig
if (defined($realmID)) { if (defined($realmID)) {
$sth = DBSelect($config->{'get_config_realm_attributes_query'},$realmID); $sth = DBSelect($config->{'get_config_realm_attributes_query'},$realmID);
if (!$sth) { if (!$sth) {
$server->log(LOG_ERR,"Failed to get default config attributes: ".awitpt::db::dblayer::Error()); $server->log(LOG_ERR,"Failed to get default realm config attributes: ".awitpt::db::dblayer::Error());
return MOD_RES_NACK; return MOD_RES_NACK;
} }
# Add any default realm attributes to config attributes # Add any default realm attributes to config attributes
...@@ -191,7 +192,6 @@ sub getConfig ...@@ -191,7 +192,6 @@ sub getConfig
} }
# Extract realm from username # Extract realm from username
my $userRealmID;
if (defined($user->{'Username'}) && $user->{'Username'} =~ /^\S+@(\S+)$/) { if (defined($user->{'Username'}) && $user->{'Username'} =~ /^\S+@(\S+)$/) {
$realmName = $1; $realmName = $1;
...@@ -203,11 +203,11 @@ sub getConfig ...@@ -203,11 +203,11 @@ sub getConfig
# Fetch realm ID # Fetch realm ID
if ($sth->rows == 1) { if ($sth->rows == 1) {
$row = hashifyLCtoMC($sth->fetchrow_hashref(),qw(ID)); $row = hashifyLCtoMC($sth->fetchrow_hashref(),qw(ID));
$userRealmID = $row->{'ID'}; $realmID = $row->{'ID'};
DBFreeRes($sth); DBFreeRes($sth);
# User realm attributes # User realm attributes
$sth = DBSelect($config->{'get_config_realm_attributes_query'},$userRealmID); $sth = DBSelect($config->{'get_config_realm_attributes_query'},$realmID);
if (!$sth) { if (!$sth) {
$server->log(LOG_ERR,"Failed to get user realm config attributes: ".awitpt::db::dblayer::Error()); $server->log(LOG_ERR,"Failed to get user realm config attributes: ".awitpt::db::dblayer::Error());
return MOD_RES_NACK; return MOD_RES_NACK;
...@@ -220,34 +220,38 @@ sub getConfig ...@@ -220,34 +220,38 @@ sub getConfig
} }
} }
# Reject if there is no realm
if (!defined($realmID)) {
$server->log(LOG_DEBUG,"No realm found, rejecting");
return MOD_RES_NACK;
}
# Get client name # Get client name
my ($clientID,$res); my ($clientID,$res);
if (defined($userRealmID)) { $sth = DBSelect($config->{'get_config_accesslist_query'},$realmID);
$sth = DBSelect($config->{'get_config_accesslist_query'},$userRealmID); if (!$sth) {
if (!$sth) { $server->log(LOG_ERR,"Failed to get config attributes: ".awitpt::db::dblayer::Error());
$server->log(LOG_ERR,"Failed to get config attributes: ".awitpt::db::dblayer::Error()); return MOD_RES_NACK;
return MOD_RES_NACK; }
} # Check if we know this client
# Check if we know this client my @accessList;
my @accessList; while (my $row = $sth->fetchrow_hashref()) {
while (my $row = $sth->fetchrow_hashref()) { $res = hashifyLCtoMC($row,qw(AccessList ID));
$res = hashifyLCtoMC($row,qw(AccessList ID)); # Split off allowed sources, comma separated
# Split off allowed sources, comma separated @accessList = ();
@accessList = (); @accessList = split(',',$res->{'AccessList'});
@accessList = split(',',$res->{'AccessList'}); # Loop with what we get and check if we have match
# Loop with what we get and check if we have match foreach my $ip (@accessList) {
foreach my $ip (@accessList) { if ($server->{'server'}{'peeraddr'} eq $ip) {
if ($server->{'server'}{'peeraddr'} eq $ip) { $clientID = $res->{'ID'};
$clientID = $res->{'ID'}; last;
last;
}
} }
} }
DBFreeRes($sth); }
if (!defined($clientID)) { DBFreeRes($sth);
$server->log(LOG_ERR,"Peer Address '".$server->{'server'}{'peeraddr'}."' not found in access list"); if (!defined($clientID)) {
return MOD_RES_NACK; $server->log(LOG_ERR,"Peer Address '".$server->{'server'}{'peeraddr'}."' not found in access list");
} return MOD_RES_NACK;
} }
# Get client attributes # Get client attributes
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment