Port patch from branch_1_1 to the HEAD
[freeradius.git] / raddb / sql.conf
1 #
2 #  Configuration for the SQL module, when using MySQL.
3 #
4 #  The database schema is available at:
5 #
6 #   src/radiusd/src/modules/rlm_sql/drivers/rlm_sql_mysql/db_mysql.sql
7 #
8 #  If you are using PostgreSQL, please use 'postgresql.conf', instead.
9 #  If you are using Oracle, please use 'oracle.conf', instead.
10 #  If you are using MS-SQL, please use 'mssql.conf', instead.
11 #
12 #       $Id$
13 #
14
15 sql {
16
17         # Database type
18         # Current supported are: rlm_sql_mysql, rlm_sql_postgresql,
19         # rlm_sql_iodbc, rlm_sql_oracle, rlm_sql_unixodbc, rlm_sql_freetds
20         driver = "rlm_sql_mysql"
21
22         # Connect info
23         server = "localhost"
24         login = "root"
25         password = "rootpass"
26
27         # Database table configuration
28         radius_db = "radius"
29
30         # If you want both stop and start records logged to the
31         # same SQL table, leave this as is.  If you want them in
32         # different tables, put the start table in acct_table1
33         # and stop table in acct_table2
34         acct_table1 = "radacct"
35         acct_table2 = "radacct"
36
37         # Allow for storing data after authentication
38         postauth_table = "radpostauth"
39
40         authcheck_table = "radcheck"
41         authreply_table = "radreply"
42
43         groupcheck_table = "radgroupcheck"
44         groupreply_table = "radgroupreply"
45
46         # Table to keep group info
47         usergroup_table = "usergroup"
48
49         # If set to 'yes' (default) we read the group tables
50         # If set to 'no' the user MUST have Fall-Through = Yes in the radreply table
51         #read_groups = yes
52
53         # Table to keep radius client info
54         nas_table = "nas"
55
56         # Set to 'yes' to read radius clients from the database ('nas' table)
57         #readclients = yes
58
59         # Remove stale session if checkrad does not see a double login
60         deletestalesessions = yes
61
62         # Print all SQL statements when in debug mode (-x)
63         sqltrace = no
64         sqltracefile = ${logdir}/sqltrace.sql
65
66         # number of sql connections to make to server
67         num_sql_socks = 5
68
69         # number of seconds to dely retrying on a failed database
70         # connection (per_socket)
71         connect_failure_retry_delay = 60
72
73         # Safe characters list for sql queries. Everything else is replaced
74         # with their mime-encoded equivalents.
75         # The default list should be ok
76         #safe-characters = "@abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-_: /"
77
78         #######################################################################
79         #  Query config:  Username
80         #######################################################################
81         # This is the username that will get substituted, escaped, and added
82         # as attribute 'SQL-User-Name'.  '%{SQL-User-Name}' should be used below
83         # everywhere a username substitution is needed so you you can be sure
84         # the username passed from the client is escaped properly.
85         #
86         #  Uncomment the next line, if you want the sql_user_name to mean:
87         #
88         #    Use Stripped-User-Name, if it's there.
89         #    Else use User-Name, if it's there,
90         #    Else use hard-coded string "DEFAULT" as the user name.
91         #sql_user_name = "%{Stripped-User-Name:-%{User-Name:-DEFAULT}}"
92         #
93         sql_user_name = "%{User-Name}"
94
95         #######################################################################
96         #  Default profile
97         #######################################################################
98         # This is the default profile. It is found in SQL by group membership.
99         # That means that this profile must be a member of at least one group
100         # which will contain the corresponding check and reply items.
101         # This profile will be queried in the authorize section for every user.
102         # The point is to assign all users a default profile without having to
103         # manually add each one to a group that will contain the profile.
104         # The SQL module will also honor the User-Profile attribute. This
105         # attribute can be set anywhere in the authorize section (ie the users
106         # file). It is found exactly as the default profile is found.
107         # If it is set then it will *overwrite* the default profile setting.
108         # The idea is to select profiles based on checks on the incoming packets,
109         # not on user group membership. For example:
110         # -- users file --
111         # DEFAULT       Service-Type == Outbound-User, User-Profile := "outbound"
112         # DEFAULT       Service-Type == Framed-User, User-Profile := "framed"
113         #
114         # By default the default_user_profile is not set
115         #
116         #default_user_profile = "DEFAULT"
117
118         #######################################################################
119         #  NAS Query
120         #######################################################################
121         #  This query retrieves the radius clients
122         #
123         #  0. Row ID (currently unused)
124         #  1. Name (or IP address)
125         #  2. Shortname
126         #  3. Type
127         #  4. Secret
128         #######################################################################
129
130         nas_query = "SELECT id, nasname, shortname, type, secret FROM ${nas_table}"
131
132         #######################################################################
133         #  Authorization Queries
134         #######################################################################
135         #  These queries compare the check items for the user
136         #  in ${authcheck_table} and setup the reply items in
137         #  ${authreply_table}.  You can use any query/tables
138         #  you want, but the return data for each row MUST
139         #  be in the  following order:
140         #
141         #  0. Row ID (currently unused)
142         #  1. UserName/GroupName
143         #  2. Item Attr Name
144         #  3. Item Attr Value
145         #  4. Item Attr Operation
146         #######################################################################
147         # Use these for case sensitive usernames.
148 #       authorize_check_query = "SELECT id, UserName, Attribute, Value, op \
149 #         FROM ${authcheck_table} \
150 #         WHERE Username = BINARY '%{SQL-User-Name}' \
151 #         ORDER BY id"
152 #       authorize_reply_query = "SELECT id, UserName, Attribute, Value, op \
153 #         FROM ${authreply_table} \
154 #         WHERE Username = BINARY '%{SQL-User-Name}' \
155 #         ORDER BY id"
156
157         # The default queries are case insensitive. (for compatibility with
158         # older versions of FreeRADIUS)
159         authorize_check_query = "SELECT id, UserName, Attribute, Value, op \
160           FROM ${authcheck_table} \
161           WHERE Username = '%{SQL-User-Name}' \
162           ORDER BY id"
163         authorize_reply_query = "SELECT id, UserName, Attribute, Value, op \
164           FROM ${authreply_table} \
165           WHERE Username = '%{SQL-User-Name}' \
166           ORDER BY id"
167
168         # Use these for case sensitive usernames.
169 #       group_membership_query = "SELECT GroupName \
170 #         FROM ${usergroup_table} \
171 #         WHERE UserName = BINARY '%{SQL-User-Name}' \
172 #         ORDER BY priority"
173
174         group_membership_query = "SELECT GroupName \
175           FROM ${usergroup_table} \
176           WHERE UserName = '%{SQL-User-Name}' \
177           ORDER BY priority"
178
179         authorize_group_check_query = "SELECT id, GroupName, Attribute, Value, op \
180           FROM ${groupcheck_table} \
181           WHERE GroupName = '%{Sql-Group}' \
182           ORDER BY id"
183         authorize_group_reply_query = "SELECT id, GroupName, Attribute, Value, op \
184           FROM ${groupreply_table} \
185           WHERE GroupName = '%{Sql-Group}' \
186           ORDER BY id"
187
188         #######################################################################
189         #  Accounting Queries
190         #######################################################################
191         # accounting_onoff_query        - query for Accounting On/Off packets
192         # accounting_update_query       - query for Accounting update packets
193         # accounting_update_query_alt   - query for Accounting update packets
194         #                               (alternate in case first query fails)
195         # accounting_start_query        - query for Accounting start packets
196         # accounting_start_query_alt    - query for Accounting start packets
197         #                               (alternate in case first query fails)
198         # accounting_stop_query         - query for Accounting stop packets
199         # accounting_stop_query_alt     - query for Accounting start packets
200         #                               (alternate in case first query doesn't
201         #                                affect any existing rows in the table)
202         #######################################################################
203         accounting_onoff_query = "UPDATE ${acct_table1} SET AcctStopTime='%S', AcctSessionTime=unix_timestamp('%S') - unix_timestamp(AcctStartTime), AcctTerminateCause='%{Acct-Terminate-Cause}', AcctStopDelay = %{Acct-Delay-Time} WHERE AcctSessionTime=0 AND AcctStopTime=0 AND NASIPAddress= '%{NAS-IP-Address}' AND AcctStartTime <= '%S'"
204
205         accounting_update_query = "UPDATE ${acct_table1} \
206           SET FramedIPAddress = '%{Framed-IP-Address}', \
207           AcctSessionTime = '%{Acct-Session-Time}', \
208           AcctInputOctets = '%{Acct-Input-Octets}', \
209           AcctOutputOctets = '%{Acct-Output-Octets}' \
210           WHERE AcctSessionId = '%{Acct-Session-Id}' \
211           AND UserName = '%{SQL-User-Name}' \
212           AND NASIPAddress= '%{NAS-IP-Address}'"
213
214         accounting_update_query_alt = "INSERT into ${acct_table1} (AcctSessionId, AcctUniqueId, UserName, Realm, NASIPAddress, NASPortId, NASPortType, AcctStartTime, AcctSessionTime, AcctAuthentic, ConnectInfo_start, AcctInputOctets, AcctOutputOctets, CalledStationId, CallingStationId, ServiceType, FramedProtocol, FramedIPAddress, AcctStartDelay) values('%{Acct-Session-Id}', '%{Acct-Unique-Session-Id}', '%{SQL-User-Name}', '%{Realm}', '%{NAS-IP-Address}', '%{NAS-Port}', '%{NAS-Port-Type}', DATE_SUB('%S',INTERVAL (%{Acct-Session-Time:-0} + %{Acct-Delay-Time:-0}) SECOND), '%{Acct-Session-Time}', '%{Acct-Authentic}', '', '%{Acct-Input-Octets}', '%{Acct-Output-Octets}', '%{Called-Station-Id}', '%{Calling-Station-Id}', '%{Service-Type}', '%{Framed-Protocol}', '%{Framed-IP-Address}', '0')"
215
216         accounting_start_query = "INSERT into ${acct_table1} (AcctSessionId, AcctUniqueId, UserName, Realm, NASIPAddress, NASPortId, NASPortType, AcctStartTime, AcctStopTime, AcctSessionTime, AcctAuthentic, ConnectInfo_start, ConnectInfo_stop, AcctInputOctets, AcctOutputOctets, CalledStationId, CallingStationId, AcctTerminateCause, ServiceType, FramedProtocol, FramedIPAddress, AcctStartDelay, AcctStopDelay) values('%{Acct-Session-Id}', '%{Acct-Unique-Session-Id}', '%{SQL-User-Name}', '%{Realm}', '%{NAS-IP-Address}', '%{NAS-Port}', '%{NAS-Port-Type}', '%S', '0', '0', '%{Acct-Authentic}', '%{Connect-Info}', '', '0', '0', '%{Called-Station-Id}', '%{Calling-Station-Id}', '', '%{Service-Type}', '%{Framed-Protocol}', '%{Framed-IP-Address}', '%{Acct-Delay-Time}', '0')"
217
218         accounting_start_query_alt  = "UPDATE ${acct_table1} SET AcctStartTime = '%S', AcctStartDelay = '%{Acct-Delay-Time}', ConnectInfo_start = '%{Connect-Info}' WHERE AcctSessionId = '%{Acct-Session-Id}' AND UserName = '%{SQL-User-Name}' AND NASIPAddress = '%{NAS-IP-Address}'"
219
220         accounting_stop_query = "UPDATE ${acct_table2} SET AcctStopTime = '%S', AcctSessionTime = '%{Acct-Session-Time}', AcctInputOctets = '%{Acct-Input-Octets}', AcctOutputOctets = '%{Acct-Output-Octets}', AcctTerminateCause = '%{Acct-Terminate-Cause}', AcctStopDelay = '%{Acct-Delay-Time}', ConnectInfo_stop = '%{Connect-Info}' WHERE AcctSessionId = '%{Acct-Session-Id}' AND UserName = '%{SQL-User-Name}' AND NASIPAddress = '%{NAS-IP-Address}'"
221
222         accounting_stop_query_alt = "INSERT into ${acct_table2} (AcctSessionId, AcctUniqueId, UserName, Realm, NASIPAddress, NASPortId, NASPortType, AcctStartTime, AcctStopTime, AcctSessionTime, AcctAuthentic, ConnectInfo_start, ConnectInfo_stop, AcctInputOctets, AcctOutputOctets, CalledStationId, CallingStationId, AcctTerminateCause, ServiceType, FramedProtocol, FramedIPAddress, AcctStartDelay, AcctStopDelay) values('%{Acct-Session-Id}', '%{Acct-Unique-Session-Id}', '%{SQL-User-Name}', '%{Realm}', '%{NAS-IP-Address}', '%{NAS-Port}', '%{NAS-Port-Type}', DATE_SUB('%S', INTERVAL (%{Acct-Session-Time:-0} + %{Acct-Delay-Time:-0}) SECOND), '%S', '%{Acct-Session-Time}', '%{Acct-Authentic}', '', '%{Connect-Info}', '%{Acct-Input-Octets}', '%{Acct-Output-Octets}', '%{Called-Station-Id}', '%{Calling-Station-Id}', '%{Acct-Terminate-Cause}', '%{Service-Type}', '%{Framed-Protocol}', '%{Framed-IP-Address}', '0', '%{Acct-Delay-Time}')"
223
224         #######################################################################
225         # Simultaneous Use Checking Queries
226         #######################################################################
227         # simul_count_query     - query for the number of current connections
228         #                       - If this is not defined, no simultaneouls use checking
229         #                       - will be performed by this module instance
230         # simul_verify_query    - query to return details of current connections for verification
231         #                       - Leave blank or commented out to disable verification step
232         #                       - Note that the returned field order should not be changed.
233         #######################################################################
234
235         # Uncomment simul_count_query to enable simultaneous use checking
236         # simul_count_query = "SELECT COUNT(*) FROM ${acct_table1} WHERE UserName='%{SQL-User-Name}' AND AcctStopTime = 0"
237         simul_verify_query = "SELECT RadAcctId, AcctSessionId, UserName, NASIPAddress, NASPortId, FramedIPAddress, CallingStationId, FramedProtocol FROM ${acct_table1} WHERE UserName='%{SQL-User-Name}' AND AcctStopTime = 0"
238
239         #######################################################################
240         # Authentication Logging Queries
241         #######################################################################
242         # postauth_query                - Insert some info after authentication
243         #######################################################################
244
245         postauth_query = "INSERT into ${postauth_table} (id, user, pass, reply, date) values ('', '%{User-Name}', '%{User-Password:-Chap-Password}', '%{reply:Packet-Type}', '%S')"
246
247 }