3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 # Copyright 2002 The FreeRADIUS server project
18 # Copyright 2002 Boian Jordanov <bjordanov@orbitel.bg>
22 # Example code for use with rlm_perl
24 # You can use every module that comes with your perl distribution!
26 # If you are using DBI and do some queries to DB, please be sure to
27 # use the CLONE function to initialize the DBI connection to DB.
36 # Bring the global hashes into the package scope
37 our (%RAD_REQUEST, %RAD_REPLY, %RAD_CHECK);
39 # This is hash wich hold original request from radius
41 # In this hash you add values that will be returned to NAS.
43 #This is for check items
45 # This is configuration items from "config" perl module configuration section
48 # Multi-value attributes are mapped to perl arrayrefs.
55 # This results to the following entry in %RAD_REQUEST:
57 # $RAD_REQUEST{'Filter-Id'} = [ 'foo', 'bar' ];
59 # Likewise, you can assign an arrayref to return multi-value attributes
62 # This the remapping of return values
65 RLM_MODULE_REJECT => 0, # immediately reject the request
66 RLM_MODULE_OK => 2, # the module is OK, continue
67 RLM_MODULE_HANDLED => 3, # the module handled the request, so stop
68 RLM_MODULE_INVALID => 4, # the module considers the request invalid
69 RLM_MODULE_USERLOCK => 5, # reject the request (user is locked out)
70 RLM_MODULE_NOTFOUND => 6, # user not found
71 RLM_MODULE_NOOP => 7, # module succeeded without doing anything
72 RLM_MODULE_UPDATED => 8, # OK (pairs modified)
73 RLM_MODULE_NUMCODES => 9 # How many return codes there are
76 # Same as src/include/radiusd.h
77 use constant L_DBG=> 1;
78 use constant L_AUTH=> 2;
79 use constant L_INFO=> 3;
80 use constant L_ERR=> 4;
81 use constant L_PROXY=> 5;
82 use constant L_ACCT=> 6;
84 # Global variables can persist across different calls to the module.
88 # my %static_global_hash = ();
97 # Function to handle authorize
99 # For debugging purposes only
100 # &log_request_attributes;
102 # Here's where your authorization code comes
103 # You can call another function from here:
106 return RLM_MODULE_OK;
109 # Function to handle authenticate
111 # For debugging purposes only
112 # &log_request_attributes;
114 if ($RAD_REQUEST{'User-Name'} =~ /^baduser/i) {
115 # Reject user and tell him why
116 $RAD_REPLY{'Reply-Message'} = "Denied access by rlm_perl function";
117 return RLM_MODULE_REJECT;
119 # Accept user and set some attribute
120 $RAD_REPLY{'h323-credit-amount'} = "100";
121 return RLM_MODULE_OK;
125 # Function to handle preacct
127 # For debugging purposes only
128 # &log_request_attributes;
130 return RLM_MODULE_OK;
133 # Function to handle accounting
135 # For debugging purposes only
136 # &log_request_attributes;
138 # You can call another subroutine from here
141 return RLM_MODULE_OK;
144 # Function to handle checksimul
146 # For debugging purposes only
147 # &log_request_attributes;
149 return RLM_MODULE_OK;
152 # Function to handle pre_proxy
154 # For debugging purposes only
155 # &log_request_attributes;
157 return RLM_MODULE_OK;
160 # Function to handle post_proxy
162 # For debugging purposes only
163 # &log_request_attributes;
165 return RLM_MODULE_OK;
168 # Function to handle post_auth
170 # For debugging purposes only
171 # &log_request_attributes;
173 return RLM_MODULE_OK;
176 # Function to handle xlat
178 # For debugging purposes only
179 # &log_request_attributes;
181 # Loads some external perl and evaluate it
182 my ($filename,$a,$b,$c,$d) = @_;
183 &radiusd::radlog(L_DBG, "From xlat $filename ");
184 &radiusd::radlog(L_DBG,"From xlat $a $b $c $d ");
186 open FH, $filename or die "open '$filename' $!";
190 my $eval = qq{ sub handler{ $sub;} };
192 eval {main->handler;};
195 # Function to handle detach
197 # For debugging purposes only
198 # &log_request_attributes;
202 # Some functions that can be called from other functions
206 # Some code goes here
209 sub log_request_attributes {
210 # This shouldn't be done in production environments!
211 # This is only meant for debugging!
212 for (keys %RAD_REQUEST) {
213 &radiusd::radlog(L_DBG, "RAD_REQUEST: $_ = $RAD_REQUEST{$_}");