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