3 ## policy.conf -- FreeRADIUS server configuration file.
5 ## http://www.freeradius.org/
10 # Policies are virtual modules, similar to those defined in the
11 # "instantate" section of radiusd.conf.
13 # Defining a policy here means that it can be referenced in multiple
14 # places as a *name*, rather than as a series of conditions to match,
15 # and actions to take.
17 # Policies are something like subroutines in a normal language, but
18 # they cannot be called recursively. They MUST be defined in order.
19 # If policy A calls policy B, then B MUST be defined before A.
23 # Overload the default acct_unique module, it's not smart enough
27 # If we have a class attribute, it'll have a local value (defined by populate_class),
28 # this ensures uniqueness and suitability.
29 # We could just use the Class attribute as Acct-Unique-Session-Id, but this may cause
30 # problems with NAS that carry Class values across between multiple linked sessions.
31 # So we rehash class with Acct-Session-ID to provide a truely unique session identifier.
33 # Using a Class/Session-ID combination is more robust than using elements in the
34 # Accounting-Request, which may be subject to change, such as NAS-IP-Address
35 # or Client-IP-Address and NAS-Port-ID/NAS-Port.
36 # So should ensure that session data is not affected if NAS IP addresses change, or
37 # the client roams to a different 'port' whilst maintaining its initial authentication
38 # session (Common in a wireless environment).
42 Acct-Unique-Session-Id := "%{md5:%{Class}%{Acct-Session-ID}}"
46 # Not All devices respect RFC 2865 when dealing with the class attribute,
47 # so be prepared to use the older style of hashing scheme if a class attribute is not included
51 Acct-Unique-Session-Id := "%{md5:%{User-Name}%{Acct-Session-ID}%{NAS-IP-Address}%{NAS-Port-ID:}%{NAS-Port}}"
57 # Insert a (hopefully unique) value into class
61 Class = "%{md5:%t%{request:NAS-Identifier}%{NAS-Port-ID}%{NAS-Port}%{Calling-Station-ID}%{reply:User-Name}}"
66 # Forbid all EAP types.
75 # Forbid all non-EAP types outside of an EAP tunnel.
79 # We MAY be inside of a TTLS tunnel.
80 # PEAP and EAP-FAST require EAP inside of
81 # the tunnel, so this check is OK.
82 # If so, then there MUST be an outer EAP message.
83 if (!"%{outer.request:EAP-Message}") {
90 # Forbid all attempts to login via realms.
93 if (User-Name =~ /@|\\/) {
99 # If you want the server to pretend that it is dead,
100 # then use the "do_not_respond" policy.
104 Response-Packet-Type := Do-Not-Respond
111 # Filter the username
113 # Force some sanity on User-Name.This helps to avoid issues
114 # issues where the back-end database is "forgiving" about
115 # what constitutes a user name.
118 # spaces at the start: reject
119 if (User-Name =~ /^ /) {
123 # spaces at the end: reject
124 if (User-Name =~ / $$/) {
129 if (User-Name != "%{tolower:%{User-Name}}") {
136 # The following policies are for the Chargeable-User-Identity
137 # (CUI) configuration.
140 # The policies below can be called as just 'cui' (not cui.authorize etc..)
141 # from the various config sections.
145 # The client indicates it can do CUI by sending a CUI attribute
146 # containing one zero byte
150 Chargeable-User-Identity:='\\000'
155 # Add a CUI attribute based on the User-Name, and a secret key
156 # known only to this server.
159 if (FreeRadius-Proxied-To == 127.0.0.1) {
160 if (outer.request:Chargeable-User-Identity) {
162 Chargeable-User-Identity:="%{md5:%{config:cui_hash_key}%{User-Name}}"
167 if (Chargeable-User-Identity) {
169 Chargeable-User-Identity="%{md5:%{config:cui_hash_key}%{User-Name}}"
177 # If we had stored a CUI for the User, add it to the request.
181 # If the CUI isn't in the packet, see if we can find it
184 if (!Chargeable-User-Identity) {
186 Chargable-User-Identity := "%{cui: SELECT cui FROM cui WHERE clientipaddress = '%{Client-IP-Address}' AND callingstationid = '%{Calling-Station-Id}' AND username = '%{User-Name}'}"
191 # If it exists now, then write out when we last saw
194 if (Chargeable-User-Identity && (Chargeable-User-Identity != "")) {
200 # If there is a CUI attribute in the reply, add it to the DB.
203 if (reply:Chargeable-User-Identity) {
209 # Normalize the MAC Addresses in the Calling/Called-Station-Id
211 mac-addr-regexp = ([0-9a-f]{2})[^0-9a-f]?([0-9a-f]{2})[^0-9a-f]?([0-9a-f]{2})[^0-9a-f]?([0-9a-f]{2})[^0-9a-f]?([0-9a-f]{2})[^0-9a-f]?([0-9a-f]{2})
213 # Add "rewrite_called_station_id" in the "authorize" and "preacct"
215 rewrite_called_station_id {
216 if(Called-Station-Id =~ /^%{config:policy.mac-addr-regexp}(:(.+))?$/i) {
218 Called-Station-Id := "%{tolower:%{1}-%{2}-%{3}-%{4}-%{5}-%{6}}"
224 Called-Station-SSID := "%{7}"
234 # Add "rewrite_calling_station_id" in the "authorize" and "preacct"
236 rewrite_calling_station_id {
237 if(Calling-Station-Id =~ /^%{config:policy.mac-addr-regexp}$/i) {
239 Calling-Station-Id := "%{tolower:%{1}-%{2}-%{3}-%{4}-%{5}-%{6}}"