こんにちは(^-^*)/
予告通り、RADIUSについて書こうと思います☆今回は、認証時の外部プログラムの呼び出しについてです♪
では早速!
まず、必要なパッケージをインストールします。
# yum install freeradius-perl |
次にperlプログラムを呼び出すように設定を変更します。
# cp -p /etc/raddb/sites-available/default /etc/raddb/sites-available/default.org
# vi /etc/raddb/sites-available/default
~
authorize {
perl
update control {
Auth-Type := perl
}
・・・
authenticate {
perl
・・・
}
|
perlのモジュールを呼ぶように設定します。
# cd /etc/raddb/mods-enabled # ln -s ../mods-available/perl perl # cp -p /etc/raddb/mods-available/perl /etc/raddb/mods-available/perl.org |
プログラムのパスを変更します。
# vi /etc/raddb/mods-available/perl
以下のように変更
filename = ${modconfdir}/${.:instance}/example.pl
↓
filename = ${modconfdir}/${.:instance}/test.pl
|
プログラムを作成します。example.plを例に作るといいかと思います♪
perlプログラムの中では、認証のデータをファイルに書き出すようにしています。また、RLM_MODULE_OKを返り値にすることで、全て認証OKにしています(>▽<;;
# touch /etc/raddb/mods-config/perl/test.pl
# chown root:radiusd /etc/raddb/mods-config/perl/kome.pl
# vi /etc/raddb/mods-config/perl/test.pl
~
use strict;
use warnings;
use Data::Dumper;
our (%RAD_REQUEST, %RAD_REPLY, %RAD_CHECK);
use constant {
RLM_MODULE_REJECT => 0, # immediately reject the request
RLM_MODULE_OK => 2, # the module is OK, continue
RLM_MODULE_HANDLED => 3, # the module handled the request, so stop
RLM_MODULE_INVALID => 4, # the module considers the request invalid
RLM_MODULE_USERLOCK => 5, # reject the request (user is locked out)
RLM_MODULE_NOTFOUND => 6, # user not found
RLM_MODULE_NOOP => 7, # module succeeded without doing anything
RLM_MODULE_UPDATED => 8, # OK (pairs modified)
RLM_MODULE_NUMCODES => 9 # How many return codes there are
};
use constant L_DBG=> 1;
use constant L_AUTH=> 2;
use constant L_INFO=> 3;
use constant L_ERR=> 4;
use constant L_PROXY=> 5;
use constant L_ACCT=> 6;
sub authorize {
my $val;
open OFP,">>/tmp/test.log";
print OFP Dumper(\%RAD_REQUEST);
close OFP;
return RLM_MODULE_OK;
}
sub authenticate {
return RLM_MODULE_OK;
}
|
設定を反映させます!
# systemctl restart radiusd |
実際に試してみましょうー(=⌒▽⌒=)
# radtest test pass localhost:1812 0 testing123
~
Sending Access-Request Id 216 from 0.0.0.0:60941 to 127.0.0.1:1812
User-Name = 'test'
User-Password = 'pass'
NAS-IP-Address = 192.168.8.8
NAS-Port = 0
Message-Authenticator = 0x00
Received Access-Accept Id 216 from 127.0.0.1:1812 to 127.0.0.1:60941 length 20
|
ファイルを見てみましょう☆
# cat /tmp/test.log
~
$VAR1 = {
'User-Name' => 'test',
'User-Password' => 'pass',
'NAS-Port' => '0',
'NAS-IP-Address' => '192.168.8.8',
'Message-Authenticator' => '0xde3f40c1c067bc9c0e17311e1ef79e16'
};
|
おお書かれていますね!w(*゚o゚*)w
freeradius-pythonをインストールすることで、pythonも使うことができます。