4 |
- |
1 |
#
|
|
|
2 |
# This program is free software; you can redistribute it and/or modify
|
|
|
3 |
# it under the terms of the GNU General Public License as published by
|
|
|
4 |
# the Free Software Foundation; either version 2 of the License, or
|
|
|
5 |
# (at your option) any later version.
|
|
|
6 |
#
|
|
|
7 |
# This program is distributed in the hope that it will be useful,
|
|
|
8 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
9 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
10 |
# GNU General Public License for more details.
|
|
|
11 |
#
|
|
|
12 |
# You should have received a copy of the GNU General Public License
|
|
|
13 |
# along with this program; if not, write to the Free Software
|
|
|
14 |
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
15 |
#
|
|
|
16 |
# Copyright 2002 The FreeRADIUS server project
|
|
|
17 |
# Copyright 2002 Boian Jordanov <bjordanov@orbitel.bg>
|
|
|
18 |
#
|
|
|
19 |
|
|
|
20 |
#
|
|
|
21 |
# Example code for use with rlm_perl
|
|
|
22 |
#
|
|
|
23 |
# You can use every module that comes with your perl distribution!
|
|
|
24 |
#
|
|
|
25 |
# If you are using DBI and do some queries to DB, please be sure to
|
|
|
26 |
# use the CLONE function to initialize the DBI connection to DB.
|
|
|
27 |
#
|
|
|
28 |
|
|
|
29 |
use strict;
|
|
|
30 |
# use ...
|
|
|
31 |
# This is very important ! Without this script will not get the filled hashesh from main.
|
|
|
32 |
use vars qw(%RAD_REQUEST %RAD_REPLY %RAD_CHECK);
|
|
|
33 |
use Data::Dumper;
|
|
|
34 |
|
|
|
35 |
# This is hash wich hold original request from radius
|
|
|
36 |
#my %RAD_REQUEST;
|
|
|
37 |
# In this hash you add values that will be returned to NAS.
|
|
|
38 |
#my %RAD_REPLY;
|
|
|
39 |
#This is for check items
|
|
|
40 |
#my %RAD_CHECK;
|
|
|
41 |
|
|
|
42 |
#
|
|
|
43 |
# This the remapping of return values
|
|
|
44 |
#
|
|
|
45 |
use constant RLM_MODULE_REJECT=> 0;# /* immediately reject the request */
|
|
|
46 |
use constant RLM_MODULE_FAIL=> 1;# /* module failed, don't reply */
|
|
|
47 |
use constant RLM_MODULE_OK=> 2;# /* the module is OK, continue */
|
|
|
48 |
use constant RLM_MODULE_HANDLED=> 3;# /* the module handled the request, so stop. */
|
|
|
49 |
use constant RLM_MODULE_INVALID=> 4;# /* the module considers the request invalid. */
|
|
|
50 |
use constant RLM_MODULE_USERLOCK=> 5;# /* reject the request (user is locked out) */
|
|
|
51 |
use constant RLM_MODULE_NOTFOUND=> 6;# /* user not found */
|
|
|
52 |
use constant RLM_MODULE_NOOP=> 7;# /* module succeeded without doing anything */
|
|
|
53 |
use constant RLM_MODULE_UPDATED=> 8;# /* OK (pairs modified) */
|
|
|
54 |
use constant RLM_MODULE_NUMCODES=> 9;# /* How many return codes there are */
|
|
|
55 |
|
|
|
56 |
# Global variables can persist across different calls to the module.
|
|
|
57 |
#
|
|
|
58 |
#
|
|
|
59 |
# {
|
|
|
60 |
# my %static_global_hash = ();
|
|
|
61 |
#
|
|
|
62 |
# sub post_auth {
|
|
|
63 |
# ...
|
|
|
64 |
# }
|
|
|
65 |
# ...
|
|
|
66 |
# }
|
|
|
67 |
|
|
|
68 |
|
|
|
69 |
# Function to handle authorize
|
|
|
70 |
sub authorize {
|
|
|
71 |
# For debugging purposes only
|
|
|
72 |
# &log_request_attributes;
|
|
|
73 |
|
|
|
74 |
# Here's where your authorization code comes
|
|
|
75 |
# You can call another function from here:
|
|
|
76 |
&test_call;
|
|
|
77 |
|
|
|
78 |
return RLM_MODULE_OK;
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
# Function to handle authenticate
|
|
|
82 |
sub authenticate {
|
|
|
83 |
# For debugging purposes only
|
|
|
84 |
# &log_request_attributes;
|
|
|
85 |
|
|
|
86 |
if ($RAD_REQUEST{'User-Name'} =~ /^baduser/i) {
|
|
|
87 |
# Reject user and tell him why
|
|
|
88 |
$RAD_REPLY{'Reply-Message'} = "Denied access by rlm_perl function";
|
|
|
89 |
return RLM_MODULE_REJECT;
|
|
|
90 |
} else {
|
|
|
91 |
# Accept user and set some attribute
|
|
|
92 |
$RAD_REPLY{'h323-credit-amount'} = "100";
|
|
|
93 |
return RLM_MODULE_OK;
|
|
|
94 |
}
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
# Function to handle preacct
|
|
|
98 |
sub preacct {
|
|
|
99 |
# For debugging purposes only
|
|
|
100 |
# &log_request_attributes;
|
|
|
101 |
|
|
|
102 |
return RLM_MODULE_OK;
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
# Function to handle accounting
|
|
|
106 |
sub accounting {
|
|
|
107 |
# For debugging purposes only
|
|
|
108 |
# &log_request_attributes;
|
|
|
109 |
|
|
|
110 |
# You can call another subroutine from here
|
|
|
111 |
&test_call;
|
|
|
112 |
|
|
|
113 |
return RLM_MODULE_OK;
|
|
|
114 |
}
|
|
|
115 |
|
|
|
116 |
# Function to handle checksimul
|
|
|
117 |
sub checksimul {
|
|
|
118 |
# For debugging purposes only
|
|
|
119 |
# &log_request_attributes;
|
|
|
120 |
|
|
|
121 |
return RLM_MODULE_OK;
|
|
|
122 |
}
|
|
|
123 |
|
|
|
124 |
# Function to handle pre_proxy
|
|
|
125 |
sub pre_proxy {
|
|
|
126 |
# For debugging purposes only
|
|
|
127 |
# &log_request_attributes;
|
|
|
128 |
|
|
|
129 |
return RLM_MODULE_OK;
|
|
|
130 |
}
|
|
|
131 |
|
|
|
132 |
# Function to handle post_proxy
|
|
|
133 |
sub post_proxy {
|
|
|
134 |
# For debugging purposes only
|
|
|
135 |
# &log_request_attributes;
|
|
|
136 |
|
|
|
137 |
return RLM_MODULE_OK;
|
|
|
138 |
}
|
|
|
139 |
|
|
|
140 |
# Function to handle post_auth
|
|
|
141 |
sub post_auth {
|
|
|
142 |
# For debugging purposes only
|
|
|
143 |
# &log_request_attributes;
|
|
|
144 |
|
|
|
145 |
return RLM_MODULE_OK;
|
|
|
146 |
}
|
|
|
147 |
|
|
|
148 |
# Function to handle xlat
|
|
|
149 |
sub xlat {
|
|
|
150 |
# For debugging purposes only
|
|
|
151 |
# &log_request_attributes;
|
|
|
152 |
|
|
|
153 |
# Loads some external perl and evaluate it
|
|
|
154 |
my ($filename,$a,$b,$c,$d) = @_;
|
|
|
155 |
&radiusd::radlog(1, "From xlat $filename ");
|
|
|
156 |
&radiusd::radlog(1,"From xlat $a $b $c $d ");
|
|
|
157 |
local *FH;
|
|
|
158 |
open FH, $filename or die "open '$filename' $!";
|
|
|
159 |
local($/) = undef;
|
|
|
160 |
my $sub = <FH>;
|
|
|
161 |
close FH;
|
|
|
162 |
my $eval = qq{ sub handler{ $sub;} };
|
|
|
163 |
eval $eval;
|
|
|
164 |
eval {main->handler;};
|
|
|
165 |
}
|
|
|
166 |
|
|
|
167 |
# Function to handle detach
|
|
|
168 |
sub detach {
|
|
|
169 |
# For debugging purposes only
|
|
|
170 |
# &log_request_attributes;
|
|
|
171 |
|
|
|
172 |
# Do some logging.
|
|
|
173 |
&radiusd::radlog(0,"rlm_perl::Detaching. Reloading. Done.");
|
|
|
174 |
}
|
|
|
175 |
|
|
|
176 |
#
|
|
|
177 |
# Some functions that can be called from other functions
|
|
|
178 |
#
|
|
|
179 |
|
|
|
180 |
sub test_call {
|
|
|
181 |
# Some code goes here
|
|
|
182 |
}
|
|
|
183 |
|
|
|
184 |
sub log_request_attributes {
|
|
|
185 |
# This shouldn't be done in production environments!
|
|
|
186 |
# This is only meant for debugging!
|
|
|
187 |
for (keys %RAD_REQUEST) {
|
|
|
188 |
&radiusd::radlog(1, "RAD_REQUEST: $_ = $RAD_REQUEST{$_}");
|
|
|
189 |
}
|
|
|
190 |
}
|
|
|
191 |
|