Subversion Repositories ALCASAR

Rev

Rev 2706 | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
1279 richard 1
# -*- text -*-
2
##
2438 richard 3
## query.conf -- MySQL configuration for default schema (schema.sql)
1279 richard 4
##
5
 
6
	# Safe characters list for sql queries. Everything else is replaced
7
	# with their mime-encoded equivalents.
2438 richard 8
	# The default list should be ok (define in 'expr' module
1279 richard 9
	#safe-characters = "@abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-_: /"
10
 
11
	#######################################################################
12
	#  Query config:  Username
13
	#######################################################################
14
	# This is the username that will get substituted, escaped, and added
15
	# as attribute 'SQL-User-Name'.  '%{SQL-User-Name}' should be used below
16
	# everywhere a username substitution is needed so you you can be sure
17
	# the username passed from the client is escaped properly.
18
	#
19
	#  Uncomment the next line, if you want the sql_user_name to mean:
20
	#
21
	#    Use Stripped-User-Name, if it's there.
22
	#    Else use User-Name, if it's there,
23
	#    Else use hard-coded string "DEFAULT" as the user name.
24
	#sql_user_name = "%{%{Stripped-User-Name}:-%{%{User-Name}:-DEFAULT}}"
25
	#
26
	sql_user_name = "%{User-Name}"
27
 
28
	#######################################################################
29
	#  Default profile
30
	#######################################################################
31
	# This is the default profile. It is found in SQL by group membership.
32
	# That means that this profile must be a member of at least one group
33
	# which will contain the corresponding check and reply items.
34
	# This profile will be queried in the authorize section for every user.
35
	# The point is to assign all users a default profile without having to
36
	# manually add each one to a group that will contain the profile.
37
	# The SQL module will also honor the User-Profile attribute. This
38
	# attribute can be set anywhere in the authorize section (ie the users
39
	# file). It is found exactly as the default profile is found.
40
	# If it is set then it will *overwrite* the default profile setting.
41
	# The idea is to select profiles based on checks on the incoming packets,
42
	# not on user group membership. For example:
43
	# -- users file --
44
	# DEFAULT	Service-Type == Outbound-User, User-Profile := "outbound"
45
	# DEFAULT	Service-Type == Framed-User, User-Profile := "framed"
46
	#
47
	# By default the default_user_profile is not set
48
	#
2706 tom.houday 49
	#default_user_profile = "DEFAULT"
1279 richard 50
 
51
	#######################################################################
52
	#  NAS Query
53
	#######################################################################
54
	#  This query retrieves the radius clients
55
	#
56
	#  0. Row ID (currently unused)
57
	#  1. Name (or IP address)
58
	#  2. Shortname
59
	#  3. Type
60
	#  4. Secret
61
	#######################################################################
62
 
2422 richard 63
	# nas_query = "SELECT id, nasname, shortname, type, secret FROM ${nas_table}"
1279 richard 64
 
65
	#######################################################################
66
	#  Authorization Queries
67
	#######################################################################
68
	#  These queries compare the check items for the user
69
	#  in ${authcheck_table} and setup the reply items in
70
	#  ${authreply_table}.  You can use any query/tables
71
	#  you want, but the return data for each row MUST
72
	#  be in the  following order:
73
	#
74
	#  0. Row ID (currently unused)
75
	#  1. UserName/GroupName
76
	#  2. Item Attr Name
77
	#  3. Item Attr Value
78
	#  4. Item Attr Operation
79
	#######################################################################
80
	# Use these for case sensitive usernames.
81
	authorize_check_query = "SELECT id, username, attribute, value, op \
82
         FROM ${authcheck_table} \
83
         WHERE username = BINARY '%{SQL-User-Name}' \
84
         ORDER BY id"
85
	authorize_reply_query = "SELECT id, username, attribute, value, op \
86
         FROM ${authreply_table} \
87
         WHERE username = BINARY '%{SQL-User-Name}' \
88
         ORDER BY id"
89
 
90
	# The default queries are case insensitive. (for compatibility with
91
	# older versions of FreeRADIUS)
92
#	authorize_check_query = "SELECT id, username, attribute, value, op \
93
#          FROM ${authcheck_table} \
94
#          WHERE username = '%{SQL-User-Name}' \
95
#          ORDER BY id"
96
#	authorize_reply_query = "SELECT id, username, attribute, value, op \
97
#          FROM ${authreply_table} \
98
#          WHERE username = '%{SQL-User-Name}' \
99
#          ORDER BY id"
100
 
101
	# Use these for case sensitive usernames.
2706 tom.houday 102
#	group_membership_query = "SELECT groupname \
103
#         FROM ${usergroup_table} \
104
#         WHERE username = BINARY '%{SQL-User-Name}' \
105
#         ORDER BY priority"
1279 richard 106
 
107
#	group_membership_query = "SELECT groupname \
108
#          FROM ${usergroup_table} \
109
#          WHERE username = '%{SQL-User-Name}' \
110
#          ORDER BY priority"
111
 
2706 tom.houday 112
	group_membership_query = "SELECT '%{SQL-User-Name}'"
1279 richard 113
 
2706 tom.houday 114
#	authorize_group_check_query = "SELECT id, groupname, attribute, \
115
#          Value, op \
116
#          FROM ${groupcheck_table} \
117
#          WHERE groupname = '%{Sql-Group}' \
118
#          ORDER BY id"
119
#	authorize_group_reply_query = "SELECT id, groupname, attribute, \
120
#          value, op \
121
#          FROM ${groupreply_table} \
122
#          WHERE groupname = '%{Sql-Group}' \
123
#          ORDER BY id"
124
	authorize_group_check_query = "SELECT id, '%{SQL-User-Name}', attribute, value, op FROM ( \
125
           ( SELECT id, attribute, value, op FROM ${groupcheck_table} gr LEFT JOIN radusergroup ug ON gr.groupname = ug.groupname WHERE username = '%{SQL-User-Name}' ORDER BY ug.priority) UNION \
126
           ( SELECT id, attribute, value, op FROM ${groupcheck_table} WHERE groupname = '%{control:Tmp-String-0}') UNION \
127
           ( SELECT id, attribute, value, op FROM ${groupcheck_table} WHERE groupname = 'default') \
128
         ) attrs GROUP BY attribute"
129
	authorize_group_reply_query = "SELECT id, '%{SQL-User-Name}', attribute, value, op FROM ( \
130
           ( SELECT id, attribute, value, op FROM ${groupreply_table} gr LEFT JOIN radusergroup ug ON gr.groupname = ug.groupname WHERE username = '%{SQL-User-Name}' ORDER BY ug.priority) UNION \
131
           ( SELECT id, attribute, value, op FROM ${groupreply_table} WHERE groupname = '%{control:Tmp-String-0}') UNION \
132
           ( SELECT id, attribute, value, op FROM ${groupreply_table} WHERE groupname = 'default') \
133
         ) attrs GROUP BY attribute"
134
 
1279 richard 135
	#######################################################################
136
	#  Accounting Queries
137
	#######################################################################
138
	# accounting_onoff_query	- query for Accounting On/Off packets
139
	# accounting_update_query	- query for Accounting update packets
140
	# accounting_update_query_alt	- query for Accounting update packets
141
	#                               (alternate in case first query fails)
142
	# accounting_start_query	- query for Accounting start packets
143
	# accounting_start_query_alt	- query for Accounting start packets
144
	#                               (alternate in case first query fails)
145
	# accounting_stop_query		- query for Accounting stop packets
146
	# accounting_stop_query_alt	- query for Accounting start packets
147
	#                               (alternate in case first query doesn't
148
	#                                affect any existing rows in the table)
149
	#######################################################################
150
	accounting_onoff_query = "\
151
          UPDATE ${acct_table1} \
152
          SET \
153
             acctstoptime       =  '%S', \
154
             acctsessiontime    =  unix_timestamp('%S') - \
155
                                   unix_timestamp(acctstarttime), \
156
             acctterminatecause =  '%{Acct-Terminate-Cause}', \
157
          WHERE acctstoptime IS NULL \
158
          AND nasipaddress      =  '%{NAS-IP-Address}' \
159
          AND acctstarttime     <= '%S'"
160
 
161
	accounting_update_query = " \
162
          UPDATE ${acct_table1} \
163
          SET \
164
             framedipaddress = '%{Framed-IP-Address}', \
165
             acctsessiontime     = '%{Acct-Session-Time}', \
166
             acctinputoctets     = '%{%{Acct-Input-Gigawords}:-0}'  << 32 | \
167
                                   '%{%{Acct-Input-Octets}:-0}', \
168
             acctoutputoctets    = '%{%{Acct-Output-Gigawords}:-0}' << 32 | \
169
                                   '%{%{Acct-Output-Octets}:-0}' \
170
          WHERE acctsessionid = '%{Acct-Session-Id}' \
2476 tom.houday 171
          AND username        = BINARY '%{SQL-User-Name}' \
1279 richard 172
          AND nasipaddress    = '%{NAS-IP-Address}'"
173
 
174
        accounting_update_query_alt = " \
175
          INSERT INTO ${acct_table1} \
176
            (acctsessionid,    acctuniqueid,      username, \
177
             realm,            nasipaddress,      nasportid, \
178
             nasporttype,      acctstarttime,     acctsessiontime, \
179
             acctauthentic,    connectinfo_start, acctinputoctets, \
180
             acctoutputoctets, calledstationid,   callingstationid, \
3278 rexy 181
             servicetype,      framedprotocol,    framedipaddress) \
1279 richard 182
          VALUES \
183
            ('%{Acct-Session-Id}', '%{Acct-Unique-Session-Id}', \
2476 tom.houday 184
             BINARY '%{SQL-User-Name}', \
1279 richard 185
             '%{Realm}', '%{NAS-IP-Address}', '%{NAS-Port}', \
186
             '%{NAS-Port-Type}', \
187
             DATE_SUB('%S', \
188
                      INTERVAL (%{%{Acct-Session-Time}:-0} + \
189
                                %{%{Acct-Delay-Time}:-0}) SECOND), \
190
                      '%{Acct-Session-Time}', \
191
             '%{Acct-Authentic}', '', \
192
             '%{%{Acct-Input-Gigawords}:-0}' << 32 | \
193
             '%{%{Acct-Input-Octets}:-0}', \
194
             '%{%{Acct-Output-Gigawords}:-0}' << 32 | \
195
             '%{%{Acct-Output-Octets}:-0}', \
196
             '%{Called-Station-Id}', '%{Calling-Station-Id}', \
197
             '%{Service-Type}', '%{Framed-Protocol}', \
3278 rexy 198
             '%{Framed-IP-Address}')"
1279 richard 199
 
200
	accounting_start_query = " \
201
          INSERT INTO ${acct_table1} \
202
            (acctsessionid,    acctuniqueid,     username, \
203
             realm,            nasipaddress,     nasportid, \
204
             nasporttype,      acctstarttime,    acctstoptime, \
205
             acctsessiontime,  acctauthentic,    connectinfo_start, \
206
             connectinfo_stop, acctinputoctets,  acctoutputoctets, \
207
             calledstationid,  callingstationid, acctterminatecause, \
3278 rexy 208
             servicetype,      framedprotocol,   framedipaddress) \
1279 richard 209
          VALUES \
210
            ('%{Acct-Session-Id}', '%{Acct-Unique-Session-Id}', \
2476 tom.houday 211
             BINARY '%{SQL-User-Name}', \
1279 richard 212
             '%{Realm}', '%{NAS-IP-Address}', '%{NAS-Port}', \
213
             '%{NAS-Port-Type}', '%S', NULL, \
214
             '0', '%{Acct-Authentic}', '%{Connect-Info}', \
215
             '', '0', '0', \
216
             '%{Called-Station-Id}', '%{Calling-Station-Id}', '', \
3278 rexy 217
             '%{Service-Type}', '%{Framed-Protocol}', '%{Framed-IP-Address}')"
1279 richard 218
 
219
	accounting_start_query_alt  = " \
220
          UPDATE ${acct_table1} SET \
221
             acctstarttime     = '%S', \
222
             connectinfo_start = '%{Connect-Info}' \
223
          WHERE acctsessionid  = '%{Acct-Session-Id}' \
2476 tom.houday 224
          AND username         = BINARY '%{SQL-User-Name}' \
1279 richard 225
          AND nasipaddress     = '%{NAS-IP-Address}'"
226
 
227
	accounting_stop_query = " \
228
          UPDATE ${acct_table2} SET \
229
             acctstoptime       = '%S', \
230
             acctsessiontime    = '%{Acct-Session-Time}', \
231
             acctinputoctets    = '%{%{Acct-Input-Gigawords}:-0}' << 32 | \
232
                                  '%{%{Acct-Input-Octets}:-0}', \
233
             acctoutputoctets   = '%{%{Acct-Output-Gigawords}:-0}' << 32 | \
234
                                  '%{%{Acct-Output-Octets}:-0}', \
235
             acctterminatecause = '%{Acct-Terminate-Cause}', \
236
             connectinfo_stop   = '%{Connect-Info}' \
237
          WHERE acctsessionid   = '%{Acct-Session-Id}' \
2476 tom.houday 238
          AND username          = BINARY '%{SQL-User-Name}' \
1279 richard 239
          AND nasipaddress      = '%{NAS-IP-Address}'"
240
 
241
	accounting_stop_query_alt = " \
242
          INSERT INTO ${acct_table2} \
243
            (acctsessionid, acctuniqueid, username, \
244
             realm, nasipaddress, nasportid, \
245
             nasporttype, acctstarttime, acctstoptime, \
246
             acctsessiontime, acctauthentic, connectinfo_start, \
247
             connectinfo_stop, acctinputoctets, acctoutputoctets, \
248
             calledstationid, callingstationid, acctterminatecause, \
3278 rexy 249
             servicetype, framedprotocol, framedipaddress) \
1279 richard 250
          VALUES \
251
            ('%{Acct-Session-Id}', '%{Acct-Unique-Session-Id}', \
2476 tom.houday 252
             BINARY '%{SQL-User-Name}', \
1279 richard 253
             '%{Realm}', '%{NAS-IP-Address}', '%{NAS-Port}', \
254
             '%{NAS-Port-Type}', \
255
             DATE_SUB('%S', \
256
                 INTERVAL (%{%{Acct-Session-Time}:-0} + \
257
                 %{%{Acct-Delay-Time}:-0}) SECOND), \
258
             '%S', '%{Acct-Session-Time}', '%{Acct-Authentic}', '', \
259
             '%{Connect-Info}', \
260
             '%{%{Acct-Input-Gigawords}:-0}' << 32 | \
261
             '%{%{Acct-Input-Octets}:-0}', \
262
             '%{%{Acct-Output-Gigawords}:-0}' << 32 | \
263
             '%{%{Acct-Output-Octets}:-0}', \
264
             '%{Called-Station-Id}', '%{Calling-Station-Id}', \
265
             '%{Acct-Terminate-Cause}', \
3278 rexy 266
             '%{Service-Type}', '%{Framed-Protocol}', '%{Framed-IP-Address}')"
2438 richard 267
# We add the following patch (freeradius V2 to V3) in order ALCASAR works
268
# be carefull : 'tolower' need now the 'expr' module
269
accounting {
270
	reference = "%{tolower:type.%{Acct-Status-Type}.query}"
271
	type {
272
		accounting-on {
273
			query = "${....accounting_onoff_query}"
274
		}
275
		accounting-off {
276
			query = "${....accounting_onoff_query}"
277
		}
278
		start {
279
			query = "${....accounting_start_query}"
280
			query = "${....accounting_start_query_alt}"
281
		}
282
		interim-update {
283
			query = "${....accounting_update_query}"
284
			query = "${....accounting_update_query_alt}"
285
		}
286
		stop {
287
			query = "${....accounting_stop_query}"
288
			query = "${....accounting_stop_query_alt}"
289
		}
290
	}
291
}
1279 richard 292
	#######################################################################
293
	# Simultaneous Use Checking Queries
294
	#######################################################################
295
	# simul_count_query	- query for the number of current connections
296
	#			- If this is not defined, no simultaneouls use checking
297
	#			- will be performed by this module instance
298
	# simul_verify_query	- query to return details of current connections for verification
299
	#			- Leave blank or commented out to disable verification step
300
	#			- Note that the returned field order should not be changed.
301
	#######################################################################
302
 
303
	# Uncomment simul_count_query to enable simultaneous use checking
304
	simul_count_query = "SELECT COUNT(*) \
305
                             FROM ${acct_table1} \
2476 tom.houday 306
                             WHERE username = BINARY '%{SQL-User-Name}' \
1279 richard 307
                             AND acctstoptime IS NULL"
308
 
309
	#simul_verify_query  = "SELECT radacctid, acctsessionid, username, \
310
                               #nasipaddress, nasportid, framedipaddress, \
311
                               #callingstationid, framedprotocol \
312
                               #FROM ${acct_table1} \
313
                               #WHERE username = '%{SQL-User-Name}' \
314
                               #AND acctstoptime IS NULL"
315
 
316
	#######################################################################
317
	# Authentication Logging Queries
318
	#######################################################################
319
	# postauth_query		- Insert some info after authentication
320
	#######################################################################
321
#                          (username, pass, reply, authdate) \
322
#                          '%{%{User-Password}:-%{Chap-Password}}', \
323
 
324
	postauth_query = "INSERT INTO ${postauth_table} \
325
                          (username, reply, authdate) \
326
                          VALUES ( \
2476 tom.houday 327
                          BINARY '%{User-Name}', \
1279 richard 328
                          '%{reply:Packet-Type}', '%S')"
2438 richard 329
# We add the following patch (freeradius V2 to V3) in order ALCASAR works
330
post-auth {
331
	query = "${..postauth_query}"
332
}