Pulled fix from branch_1_1
[freeradius.git] / raddb / sql / postgresql / dialup.conf
1 #
2 #  $Id$
3 #
4 #  Configuration for the SQL module, when using Postgresql.
5 #
6 #  The database schema is available at:
7 #
8 #       doc/examples/postgresql.sql
9 #
10
11
12         # Safe characters list for sql queries. Everything else is replaced
13         # with their mime-encoded equivalents.
14         # The default list should be ok
15 #       safe-characters = "@abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-_: /"
16
17         #######################################################################
18         #  Query config:  Username
19         #######################################################################
20         # This is the username that will get substituted, escaped, and added
21         # as attribute 'SQL-User-Name'.  '%{SQL-User-Name}' should be used
22         # below everywhere a username substitution is needed so you you can
23         # be sure the username passed from the client is escaped properly.
24         #
25         # Uncomment the next line, if you want the sql_user_name to mean:
26         #
27         #    Use Stripped-User-Name, if it's there.
28         #    Else use User-Name, if it's there,
29         #    Else use hard-coded string "none" as the user name.
30         #
31         #sql_user_name = "%{%{Stripped-User-Name}:-%{%{User-Name}:-none}}"
32         #
33         sql_user_name = "%{User-Name}"
34
35         #######################################################################
36         #  Default profile
37         #######################################################################
38         # This is the default profile. It is found in SQL by group membership.
39         # That means that this profile must be a member of at least one group
40         # which will contain the corresponding check and reply items.
41         # This profile will be queried in the authorize section for every user.
42         # The point is to assign all users a default profile without having to
43         # manually add each one to a group that will contain the profile.
44         # The SQL module will also honor the User-Profile attribute. This
45         # attribute can be set anywhere in the authorize section (ie the users
46         # file). It is found exactly as the default profile is found.
47         # If it is set then it will *overwrite* the default profile setting.
48         # The idea is to select profiles based on checks on the incoming
49         # packets, not on user group membership. For example:
50         # -- users file --
51         # DEFAULT       Service-Type == Outbound-User, User-Profile := "outbound"
52         # DEFAULT       Service-Type == Framed-User, User-Profile := "framed"
53         #
54         # By default the default_user_profile is not set
55         #
56 #       default_user_profile = "DEFAULT"
57
58         #######################################################################
59         #  NAS Query
60         #######################################################################
61         #  This query retrieves the radius clients
62         #
63         #  0. Row ID (currently unused)
64         #  1. Name (or IP address)
65         #  2. Shortname
66         #  3. Type
67         #  4. Secret
68         #######################################################################
69
70         nas_query = "SELECT id, nasname, shortname, type, secret FROM ${nas_table}"
71
72         #######################################################################
73         #  Authorization Queries
74         #######################################################################
75         #  These queries compare the check items for the user
76         #  in ${authcheck_table} and setup the reply items in
77         #  ${authreply_table}.  You can use any query/tables
78         #  you want, but the return data for each row MUST
79         #  be in the  following order:
80         #
81         #  0. Row ID (currently unused)
82         #  1. UserName/GroupName
83         #  2. Item Attr Name
84         #  3. Item Attr Value
85         #  4. Item Attr Operation
86         #######################################################################
87
88         # Use these for case insensitive usernames. WARNING: Slower queries!
89 # authorize_check_query = "SELECT id, UserName, Attribute, Value, Op \
90 #   FROM ${authcheck_table} \
91 #   WHERE LOWER(UserName) = LOWER('%{SQL-User-Name}') \
92 #   ORDER BY id"
93 # authorize_reply_query = "SELECT id, UserName, Attribute, Value, Op \
94 #   FROM ${authreply_table} \
95 #   WHERE LOWER(UserName) = LOWER('%{SQL-User-Name}') \
96 #   ORDER BY id"
97
98         authorize_check_query = "SELECT id, UserName, Attribute, Value, Op \
99                 FROM ${authcheck_table} \
100                 WHERE Username = '%{SQL-User-Name}' \
101                 ORDER BY id"
102
103         authorize_reply_query = "SELECT id, UserName, Attribute, Value, Op \
104                 FROM ${authreply_table} \
105                 WHERE Username = '%{SQL-User-Name}' \
106                 ORDER BY id"
107
108         # Use these for case insensitive usernames. WARNING: Slower queries!
109 # authorize_group_check_query = "SELECT ${groupcheck_table}.id, ${groupcheck_table}.GroupName, \
110 #   ${groupcheck_table}.Attribute, ${groupcheck_table}.Value, ${groupcheck_table}.Op \
111 #   FROM ${groupcheck_table}, ${usergroup_table} \
112 #   WHERE LOWER(${usergroup_table}.UserName) = LOWER('%{SQL-User-Name}') AND ${usergroup_table}.GroupName = ${groupcheck_table}.GroupName \
113 #   ORDER BY ${groupcheck_table}.id"
114 # authorize_group_reply_query = "SELECT ${groupreply_table}.id, ${groupreply_table}.GroupName, \
115 #   ${groupreply_table}.Attribute, ${groupreply_table}.Value, ${groupreply_table}.Op \
116 #   FROM ${groupreply_table}, ${usergroup_table} \
117 #   WHERE LOWER(${usergroup_table}.UserName) = LOWER('%{SQL-User-Name}') AND ${usergroup_table}.GroupName = ${groupreply_table}.GroupName \
118 #   ORDER BY ${groupreply_table}.id"
119
120   authorize_group_check_query = "SELECT id, GroupName, Attribute, Value, op \
121     FROM ${groupcheck_table} \
122     WHERE GroupName = '%{Sql-Group}' \
123     ORDER BY id"
124
125   authorize_group_reply_query = "SELECT id, GroupName, Attribute, Value, op \
126     FROM ${groupreply_table} \
127     WHERE GroupName = '%{Sql-Group}' \
128     ORDER BY id"
129
130         #######################################################################
131         # Simultaneous Use Checking Queries
132         #######################################################################
133         # simul_count_query     - query for the number of current connections
134         #                       - If this is not defined, no simultaneous use checking
135         #                       - will be performed by this module instance
136         # simul_verify_query    - query to return details of current connections for verification
137         #                       - Leave blank or commented out to disable verification step
138         #                       - Note that the returned field order should not be changed.
139         #######################################################################
140
141         # Uncomment simul_count_query to enable simultaneous use checking
142         # simul_count_query = "SELECT COUNT(*) FROM ${acct_table1} WHERE UserName='%{SQL-User-Name}' AND AcctStopTime IS NULL"
143         # simul_verify_query = "SELECT RadAcctId, AcctSessionId, UserName, NASIPAddress, NASPortId, FramedIPAddress, CallingStationId, FramedProtocol FROM ${acct_table1} WHERE UserName='%{SQL-User-Name}' AND AcctStopTime IS NULL"
144
145
146
147         #######################################################################
148         #  Accounting Queries
149         #######################################################################
150         # accounting_onoff_query        - query for Accounting On/Off packets
151         # accounting_update_query       - query for Accounting update packets
152         # accounting_update_query_alt   - query for Accounting update packets
153         #                               (alternate in case first query fails)
154         # accounting_start_query        - query for Accounting start packets
155         # accounting_start_query_alt    - query for Accounting start packets
156         #                               (alternate in case first query fails)
157         # accounting_stop_query         - query for Accounting stop packets
158         # accounting_stop_query_alt     - query for Accounting start packets
159         #                               (alternate in case first query doesn't
160         #                                affect any existing rows in the table)
161         #######################################################################
162
163   accounting_onoff_query = "UPDATE ${acct_table1} \
164     SET AcctStopTime = ('%S'::timestamp - '%{%{Acct-Delay-Time}:-0}'::interval), \
165     AcctSessionTime = (EXTRACT(EPOCH FROM ('%S'::timestamp with time zone - AcctStartTime::timestamp with time zone \
166     - '%{%{Acct-Delay-Time}:-0}'::interval)))::BIGINT, \
167     AcctTerminateCause='%{Acct-Terminate-Cause}', AcctStopDelay = 0 \
168     WHERE AcctSessionTime IS NULL AND AcctStopTime IS NULL AND NASIPAddress= '%{NAS-IP-Address}' AND AcctStartTime <= '%S'::timestamp"
169
170   accounting_update_query = "UPDATE ${acct_table1} \
171     SET FramedIPAddress = NULLIF('%{Framed-IP-Address}', '')::inet, \
172     AcctSessionTime = '%{Acct-Session-Time}', \
173     AcctInputOctets = (('%{%{Acct-Input-Gigawords}:-0}'::bigint << 32) + '%{%{Acct-Input-Octets}:-0}'::bigint), \
174     AcctOutputOctets = (('%{%{Acct-Output-Gigawords}:-0}'::bigint << 32) + '%{%{Acct-Output-Octets}:-0}'::bigint) \
175     WHERE AcctSessionId = '%{Acct-Session-Id}' AND UserName = '%{SQL-User-Name}' \
176     AND NASIPAddress= '%{NAS-IP-Address}' AND AcctStopTime IS NULL"
177
178   accounting_update_query_alt = "INSERT INTO ${acct_table1} \
179     (AcctSessionId, AcctUniqueId, UserName, Realm, NASIPAddress, \
180     NASPortId, NASPortType, AcctStartTime, \
181     AcctSessionTime, AcctAuthentic, AcctInputOctets, \
182     AcctOutputOctets, CalledStationId, CallingStationId, \
183     ServiceType, FramedProtocol, FramedIPAddress, XAscendSessionSvrKey) \
184     VALUES('%{Acct-Session-Id}', '%{Acct-Unique-Session-Id}', \
185     '%{SQL-User-Name}', '%{Realm}', '%{NAS-IP-Address}', \
186     %{%{NAS-Port}:-NULL}::integer, '%{NAS-Port-Type}', \
187     ('%S'::timestamp - '%{%{Acct-Delay-Time}:-0}'::interval - '%{%{Acct-Session-Time}:-0}'::interval), \
188     '%{Acct-Session-Time}', '%{Acct-Authentic}', \
189     (('%{%{Acct-Input-Gigawords}:-0}'::bigint << 32) + '%{%{Acct-Input-Octets}:-0}'::bigint), \
190     (('%{%{Acct-Output-Gigawords}:-0}'::bigint << 32) + '%{%{Acct-Output-Octets}:-0}'::bigint), \
191     '%{Called-Station-Id}', \
192     '%{Calling-Station-Id}', '%{Service-Type}', '%{Framed-Protocol}', \
193     NULLIF('%{Framed-IP-Address}', '')::inet, '%{X-Ascend-Session-Svr-Key}')"
194
195   accounting_start_query = "INSERT INTO ${acct_table1} \
196     (AcctSessionId, AcctUniqueId, UserName, Realm, NASIPAddress, \
197      NASPortId, NASPortType, AcctStartTime, AcctAuthentic, \
198     ConnectInfo_start, CalledStationId, CallingStationId, ServiceType, \
199     FramedProtocol, FramedIPAddress, AcctStartDelay, XAscendSessionSvrKey) \
200     VALUES('%{Acct-Session-Id}', \
201     '%{Acct-Unique-Session-Id}', \
202     '%{SQL-User-Name}', '%{Realm}', \
203     '%{NAS-IP-Address}', \
204     %{%{NAS-Port}:-NULL}::integer, \
205     '%{NAS-Port-Type}', \
206     ('%S'::timestamp - '%{%{Acct-Delay-Time}:-0}'::interval), \
207     '%{Acct-Authentic}', \
208     '%{Connect-Info}', \
209     '%{Called-Station-Id}', \
210     '%{Calling-Station-Id}', \
211     '%{Service-Type}', \
212     '%{Framed-Protocol}', \
213     NULLIF('%{Framed-IP-Address}', '')::inet, \
214     0, \
215     '%{X-Ascend-Session-Svr-Key}')"
216
217   accounting_start_query_alt  = "UPDATE ${acct_table1} \
218     SET AcctStartTime = ('%S'::timestamp - '%{%{Acct-Delay-Time}:-0}'::interval), \
219     AcctStartDelay = 0, \
220     ConnectInfo_start = '%{Connect-Info}' WHERE AcctSessionId = '%{Acct-Session-Id}' AND UserName = '%{SQL-User-Name}' \
221     AND NASIPAddress = '%{NAS-IP-Address}' AND AcctStopTime IS NULL"
222
223   accounting_stop_query = "UPDATE ${acct_table2} \
224     SET AcctStopTime = ('%S'::timestamp - '%{%{Acct-Delay-Time}:-0}'::interval), \
225     AcctSessionTime = CASE WHEN '%{Acct-Session-Time}' = '' THEN \
226     (EXTRACT(EPOCH FROM ('%S'::TIMESTAMP WITH TIME ZONE - AcctStartTime::TIMESTAMP WITH TIME ZONE \
227     - '%{%{Acct-Delay-Time}:-0}'::INTERVAL)))::BIGINT ELSE '%{Acct-Session-Time}' END, \
228     AcctInputOctets = (('%{%{Acct-Input-Gigawords}:-0}'::bigint << 32) + '%{%{Acct-Input-Octets}:-0}'::bigint), \
229     AcctOutputOctets = (('%{%{Acct-Output-Gigawords}:-0}'::bigint << 32) + '%{%{Acct-Output-Octets}:-0}'::bigint), \
230     AcctTerminateCause = '%{Acct-Terminate-Cause}', AcctStopDelay = 0, \
231     FramedIPAddress = NULLIF('%{Framed-IP-Address}', '')::inet, ConnectInfo_stop = '%{Connect-Info}' \
232     WHERE AcctSessionId = '%{Acct-Session-Id}' AND UserName = '%{SQL-User-Name}' \
233     AND NASIPAddress = '%{NAS-IP-Address}' AND AcctStopTime IS NULL"
234
235   accounting_stop_query_alt = "INSERT INTO ${acct_table2} \
236     (AcctSessionId, AcctUniqueId, UserName, Realm, NASIPAddress, NASPortId, NASPortType, AcctStartTime, AcctStopTime, \
237     AcctSessionTime, AcctAuthentic, ConnectInfo_stop, AcctInputOctets, AcctOutputOctets, CalledStationId, \
238     CallingStationId, AcctTerminateCause, ServiceType, FramedProtocol, FramedIPAddress, AcctStopDelay) \
239     values('%{Acct-Session-Id}', '%{Acct-Unique-Session-Id}', '%{SQL-User-Name}', '%{Realm}', '%{NAS-IP-Address}', \
240     %{%{NAS-Port}:-NULL}::integer, '%{NAS-Port-Type}', ('%S'::timestamp - '%{%{Acct-Delay-Time}:-0}'::interval - '%{%{Acct-Session-Time}:-0}'::interval), \
241     ('%S'::timestamp - '%{%{Acct-Delay-Time}:-0}'::interval), NULLIF('%{Acct-Session-Time}', '')::bigint, '%{Acct-Authentic}', \
242     '%{Connect-Info}', (('%{%{Acct-Input-Gigawords}:-0}'::bigint << 32) + '%{%{Acct-Input-Octets}:-0}'::bigint), \
243     (('%{%{Acct-Output-Gigawords}:-0}'::bigint << 32) + '%{%{Acct-Output-Octets}:-0}'::bigint), '%{Called-Station-Id}', \
244     '%{Calling-Station-Id}', '%{Acct-Terminate-Cause}', '%{Service-Type}', '%{Framed-Protocol}', \
245     NULLIF('%{Framed-IP-Address}', '')::inet, 0)"
246
247         #######################################################################
248         # Group Membership Queries
249         #######################################################################
250         # group_membership_query        - Check user group membership
251         #######################################################################
252
253         # Use these for case insensitive usernames. WARNING: Slower queries!
254 # group_membership_query = "SELECT GroupName FROM ${usergroup_table} WHERE LOWER(UserName) = LOWER('%{SQL-User-Name}') ORDER BY priority"
255
256   group_membership_query = "SELECT GroupName FROM ${usergroup_table} WHERE UserName='%{SQL-User-Name}' ORDER BY priority"
257
258         #######################################################################
259         # Authentication Logging Queries
260         #######################################################################
261         # postauth_query                - Insert some info after authentication
262         #######################################################################
263   postauth_query = "INSERT INTO ${postauth_table} (username, pass, reply, authdate) \
264     VALUES ('%{User-Name}', '%{%{User-Password}:-Chap-Password}', '%{reply:Packet-Type}', NOW())"
265