From c7fd53b224b1486712c16598139063e7da495032 Mon Sep 17 00:00:00 2001 From: Robert Anderson <randerson@lbsd.net> Date: Thu, 26 Feb 2009 15:10:12 +0000 Subject: [PATCH] * Fixed up mod_auth_pap a bit * Added mod_userdb_test for testing of radius server --- .../modules/authentication/mod_auth_pap.pm | 25 +--- smradius/modules/userdb/mod_userdb_test.pm | 115 ++++++++++++++++++ 2 files changed, 120 insertions(+), 20 deletions(-) create mode 100644 smradius/modules/userdb/mod_userdb_test.pm diff --git a/smradius/modules/authentication/mod_auth_pap.pm b/smradius/modules/authentication/mod_auth_pap.pm index 07e1eb66..1419f969 100644 --- a/smradius/modules/authentication/mod_auth_pap.pm +++ b/smradius/modules/authentication/mod_auth_pap.pm @@ -37,7 +37,6 @@ require Exporter; our (@ISA,@EXPORT,@EXPORT_OK); @ISA = qw(Exporter); @EXPORT = qw( - encode_chap ); @EXPORT_OK = qw( ); @@ -92,29 +91,15 @@ sub authenticate print(STDERR "CALC\n"); print(STDERR "Result : len = ".length($clearPassword).", hex = ".unpack("H*",$clearPassword).", password = $clearPassword\n"); - return MOD_RES_NACK; -} - - -# Encode CHAP password from ID, Challenge and Password -sub encode_chap -{ - my ($id,$challenge,$password) = @_; + # Compare passwords + if ($user->{'ClearPassword'} eq $clearPassword) { + return MOD_RES_ACK; + } - # Build MD5 - my $md5 = Digest::MD5->new(); - $md5->add($id); - $md5->add($password); - $md5->add($challenge); - - # Create encoded - my $encoded = $id . $md5->digest(); - - return $encoded; + return MOD_RES_NACK; } - 1; diff --git a/smradius/modules/userdb/mod_userdb_test.pm b/smradius/modules/userdb/mod_userdb_test.pm new file mode 100644 index 00000000..71269a18 --- /dev/null +++ b/smradius/modules/userdb/mod_userdb_test.pm @@ -0,0 +1,115 @@ +# Test user database +# +# Copyright (C) 2008, AllWorldIT +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +package mod_userdb_test; + +use strict; +use warnings; + +# Modules we need +use smradius::constants; + + +# Exporter stuff +require Exporter; +our (@ISA,@EXPORT,@EXPORT_OK); +@ISA = qw(Exporter); +@EXPORT = qw( +); +@EXPORT_OK = qw( +); + + + +# Plugin info +our $pluginInfo = { + Name => "Test User Database", + Init => \&init, + + # User database + User_find => \&find, + User_get => \&get, +}; + + + +## @internal +# Initialize module +sub init +{ + my $server = shift; +} + + + +## @find +# Try find a user +# +# @param server Server object +# @param user User +# @param packet Radius packet +# +# @return Result +sub find +{ + my ($server,$user,$packet) = @_; + + + # Test username + if ($user->{'Username'} eq "testuser") { + return MOD_RES_ACK; + } + + + return MOD_RES_SKIP; +} + + +## @get +# Try to get a user +# +# @param server Server object +# @param user User +# @param packet Radius packet +# +# @return Result +sub get +{ + my ($server,$user,$packet) = @_; + + + my $userDetails = { + 'ClearPassword' => 'doap', + 'Attributes' => [ + { + 'Name' => 'Framed-IP-Address', + 'Value' => '192.168.0.233' + }, + { + 'Name' => 'Session-Timeout', + 'Value' => '60' + } + ] + }; + + + return $userDetails; +} + + +1; -- GitLab