Subversion Repositories ALCASAR

Rev

Rev 2438 | Go to most recent revision | 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
	#
49
	default_user_profile = "ldap"
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.
102
	group_membership_query = "SELECT groupname \
103
         FROM ${usergroup_table} \
104
         WHERE username = BINARY '%{SQL-User-Name}' \
105
         ORDER BY priority"
106
 
107
#	group_membership_query = "SELECT groupname \
108
#          FROM ${usergroup_table} \
109
#          WHERE username = '%{SQL-User-Name}' \
110
#          ORDER BY priority"
111
 
112
	authorize_group_check_query = "SELECT id, groupname, attribute, \
113
          Value, op \
114
          FROM ${groupcheck_table} \
115
          WHERE groupname = '%{Sql-Group}' \
116
          ORDER BY id"
117
	authorize_group_reply_query = "SELECT id, groupname, attribute, \
118
          value, op \
119
          FROM ${groupreply_table} \
120
          WHERE groupname = '%{Sql-Group}' \
121
          ORDER BY id"
122
 
123
	#######################################################################
124
	#  Accounting Queries
125
	#######################################################################
126
	# accounting_onoff_query	- query for Accounting On/Off packets
127
	# accounting_update_query	- query for Accounting update packets
128
	# accounting_update_query_alt	- query for Accounting update packets
129
	#                               (alternate in case first query fails)
130
	# accounting_start_query	- query for Accounting start packets
131
	# accounting_start_query_alt	- query for Accounting start packets
132
	#                               (alternate in case first query fails)
133
	# accounting_stop_query		- query for Accounting stop packets
134
	# accounting_stop_query_alt	- query for Accounting start packets
135
	#                               (alternate in case first query doesn't
136
	#                                affect any existing rows in the table)
137
	#######################################################################
138
	accounting_onoff_query = "\
139
          UPDATE ${acct_table1} \
140
          SET \
141
             acctstoptime       =  '%S', \
142
             acctsessiontime    =  unix_timestamp('%S') - \
143
                                   unix_timestamp(acctstarttime), \
144
             acctterminatecause =  '%{Acct-Terminate-Cause}', \
145
             acctstopdelay      =  %{%{Acct-Delay-Time}:-0} \
146
          WHERE acctstoptime IS NULL \
147
          AND nasipaddress      =  '%{NAS-IP-Address}' \
148
          AND acctstarttime     <= '%S'"
149
 
150
	accounting_update_query = " \
151
          UPDATE ${acct_table1} \
152
          SET \
153
             framedipaddress = '%{Framed-IP-Address}', \
154
             acctsessiontime     = '%{Acct-Session-Time}', \
155
             acctinputoctets     = '%{%{Acct-Input-Gigawords}:-0}'  << 32 | \
156
                                   '%{%{Acct-Input-Octets}:-0}', \
157
             acctoutputoctets    = '%{%{Acct-Output-Gigawords}:-0}' << 32 | \
158
                                   '%{%{Acct-Output-Octets}:-0}' \
159
          WHERE acctsessionid = '%{Acct-Session-Id}' \
2476 tom.houday 160
          AND username        = BINARY '%{SQL-User-Name}' \
1279 richard 161
          AND nasipaddress    = '%{NAS-IP-Address}'"
162
 
163
        accounting_update_query_alt = " \
164
          INSERT INTO ${acct_table1} \
165
            (acctsessionid,    acctuniqueid,      username, \
166
             realm,            nasipaddress,      nasportid, \
167
             nasporttype,      acctstarttime,     acctsessiontime, \
168
             acctauthentic,    connectinfo_start, acctinputoctets, \
169
             acctoutputoctets, calledstationid,   callingstationid, \
170
             servicetype,      framedprotocol,    framedipaddress, \
171
             acctstartdelay,   xascendsessionsvrkey) \
172
          VALUES \
173
            ('%{Acct-Session-Id}', '%{Acct-Unique-Session-Id}', \
2476 tom.houday 174
             BINARY '%{SQL-User-Name}', \
1279 richard 175
             '%{Realm}', '%{NAS-IP-Address}', '%{NAS-Port}', \
176
             '%{NAS-Port-Type}', \
177
             DATE_SUB('%S', \
178
                      INTERVAL (%{%{Acct-Session-Time}:-0} + \
179
                                %{%{Acct-Delay-Time}:-0}) SECOND), \
180
                      '%{Acct-Session-Time}', \
181
             '%{Acct-Authentic}', '', \
182
             '%{%{Acct-Input-Gigawords}:-0}' << 32 | \
183
             '%{%{Acct-Input-Octets}:-0}', \
184
             '%{%{Acct-Output-Gigawords}:-0}' << 32 | \
185
             '%{%{Acct-Output-Octets}:-0}', \
186
             '%{Called-Station-Id}', '%{Calling-Station-Id}', \
187
             '%{Service-Type}', '%{Framed-Protocol}', \
188
             '%{Framed-IP-Address}', \
189
             '0', '%{X-Ascend-Session-Svr-Key}')"
190
 
191
	accounting_start_query = " \
192
          INSERT INTO ${acct_table1} \
193
            (acctsessionid,    acctuniqueid,     username, \
194
             realm,            nasipaddress,     nasportid, \
195
             nasporttype,      acctstarttime,    acctstoptime, \
196
             acctsessiontime,  acctauthentic,    connectinfo_start, \
197
             connectinfo_stop, acctinputoctets,  acctoutputoctets, \
198
             calledstationid,  callingstationid, acctterminatecause, \
199
             servicetype,      framedprotocol,   framedipaddress, \
200
             acctstartdelay,   acctstopdelay,    xascendsessionsvrkey) \
201
          VALUES \
202
            ('%{Acct-Session-Id}', '%{Acct-Unique-Session-Id}', \
2476 tom.houday 203
             BINARY '%{SQL-User-Name}', \
1279 richard 204
             '%{Realm}', '%{NAS-IP-Address}', '%{NAS-Port}', \
205
             '%{NAS-Port-Type}', '%S', NULL, \
206
             '0', '%{Acct-Authentic}', '%{Connect-Info}', \
207
             '', '0', '0', \
208
             '%{Called-Station-Id}', '%{Calling-Station-Id}', '', \
209
             '%{Service-Type}', '%{Framed-Protocol}', '%{Framed-IP-Address}', \
210
             '%{%{Acct-Delay-Time}:-0}', '0', '%{X-Ascend-Session-Svr-Key}')"
211
 
212
	accounting_start_query_alt  = " \
213
          UPDATE ${acct_table1} SET \
214
             acctstarttime     = '%S', \
215
             acctstartdelay    = '%{%{Acct-Delay-Time}:-0}', \
216
             connectinfo_start = '%{Connect-Info}' \
217
          WHERE acctsessionid  = '%{Acct-Session-Id}' \
2476 tom.houday 218
          AND username         = BINARY '%{SQL-User-Name}' \
1279 richard 219
          AND nasipaddress     = '%{NAS-IP-Address}'"
220
 
221
	accounting_stop_query = " \
222
          UPDATE ${acct_table2} SET \
223
             acctstoptime       = '%S', \
224
             acctsessiontime    = '%{Acct-Session-Time}', \
225
             acctinputoctets    = '%{%{Acct-Input-Gigawords}:-0}' << 32 | \
226
                                  '%{%{Acct-Input-Octets}:-0}', \
227
             acctoutputoctets   = '%{%{Acct-Output-Gigawords}:-0}' << 32 | \
228
                                  '%{%{Acct-Output-Octets}:-0}', \
229
             acctterminatecause = '%{Acct-Terminate-Cause}', \
230
             acctstopdelay      = '%{%{Acct-Delay-Time}:-0}', \
231
             connectinfo_stop   = '%{Connect-Info}' \
232
          WHERE acctsessionid   = '%{Acct-Session-Id}' \
2476 tom.houday 233
          AND username          = BINARY '%{SQL-User-Name}' \
1279 richard 234
          AND nasipaddress      = '%{NAS-IP-Address}'"
235
 
236
	accounting_stop_query_alt = " \
237
          INSERT INTO ${acct_table2} \
238
            (acctsessionid, acctuniqueid, username, \
239
             realm, nasipaddress, nasportid, \
240
             nasporttype, acctstarttime, acctstoptime, \
241
             acctsessiontime, acctauthentic, connectinfo_start, \
242
             connectinfo_stop, acctinputoctets, acctoutputoctets, \
243
             calledstationid, callingstationid, acctterminatecause, \
244
             servicetype, framedprotocol, framedipaddress, \
245
             acctstartdelay, acctstopdelay) \
246
          VALUES \
247
            ('%{Acct-Session-Id}', '%{Acct-Unique-Session-Id}', \
2476 tom.houday 248
             BINARY '%{SQL-User-Name}', \
1279 richard 249
             '%{Realm}', '%{NAS-IP-Address}', '%{NAS-Port}', \
250
             '%{NAS-Port-Type}', \
251
             DATE_SUB('%S', \
252
                 INTERVAL (%{%{Acct-Session-Time}:-0} + \
253
                 %{%{Acct-Delay-Time}:-0}) SECOND), \
254
             '%S', '%{Acct-Session-Time}', '%{Acct-Authentic}', '', \
255
             '%{Connect-Info}', \
256
             '%{%{Acct-Input-Gigawords}:-0}' << 32 | \
257
             '%{%{Acct-Input-Octets}:-0}', \
258
             '%{%{Acct-Output-Gigawords}:-0}' << 32 | \
259
             '%{%{Acct-Output-Octets}:-0}', \
260
             '%{Called-Station-Id}', '%{Calling-Station-Id}', \
261
             '%{Acct-Terminate-Cause}', \
262
             '%{Service-Type}', '%{Framed-Protocol}', '%{Framed-IP-Address}', \
263
             '0', '%{%{Acct-Delay-Time}:-0}')"
2438 richard 264
# We add the following patch (freeradius V2 to V3) in order ALCASAR works
265
# be carefull : 'tolower' need now the 'expr' module
266
accounting {
267
	reference = "%{tolower:type.%{Acct-Status-Type}.query}"
268
	type {
269
		accounting-on {
270
			query = "${....accounting_onoff_query}"
271
		}
272
		accounting-off {
273
			query = "${....accounting_onoff_query}"
274
		}
275
		start {
276
			query = "${....accounting_start_query}"
277
			query = "${....accounting_start_query_alt}"
278
		}
279
		interim-update {
280
			query = "${....accounting_update_query}"
281
			query = "${....accounting_update_query_alt}"
282
		}
283
		stop {
284
			query = "${....accounting_stop_query}"
285
			query = "${....accounting_stop_query_alt}"
286
		}
287
	}
288
}
1279 richard 289
	#######################################################################
290
	# Simultaneous Use Checking Queries
291
	#######################################################################
292
	# simul_count_query	- query for the number of current connections
293
	#			- If this is not defined, no simultaneouls use checking
294
	#			- will be performed by this module instance
295
	# simul_verify_query	- query to return details of current connections for verification
296
	#			- Leave blank or commented out to disable verification step
297
	#			- Note that the returned field order should not be changed.
298
	#######################################################################
299
 
300
	# Uncomment simul_count_query to enable simultaneous use checking
301
	simul_count_query = "SELECT COUNT(*) \
302
                             FROM ${acct_table1} \
2476 tom.houday 303
                             WHERE username = BINARY '%{SQL-User-Name}' \
1279 richard 304
                             AND acctstoptime IS NULL"
305
 
306
	#simul_verify_query  = "SELECT radacctid, acctsessionid, username, \
307
                               #nasipaddress, nasportid, framedipaddress, \
308
                               #callingstationid, framedprotocol \
309
                               #FROM ${acct_table1} \
310
                               #WHERE username = '%{SQL-User-Name}' \
311
                               #AND acctstoptime IS NULL"
312
 
313
	#######################################################################
314
	# Authentication Logging Queries
315
	#######################################################################
316
	# postauth_query		- Insert some info after authentication
317
	#######################################################################
318
#                          (username, pass, reply, authdate) \
319
#                          '%{%{User-Password}:-%{Chap-Password}}', \
320
 
321
	postauth_query = "INSERT INTO ${postauth_table} \
322
                          (username, reply, authdate) \
323
                          VALUES ( \
2476 tom.houday 324
                          BINARY '%{User-Name}', \
1279 richard 325
                          '%{reply:Packet-Type}', '%S')"
2438 richard 326
# We add the following patch (freeradius V2 to V3) in order ALCASAR works
327
post-auth {
328
	query = "${..postauth_query}"
329
}