2 # Configuration for the SQL module, when using MySQL.
4 # The database schema is available at:
6 # src/radiusd/src/modules/rlm_sql/drivers/rlm_sql_mysql/db_mysql.sql
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.
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"
25 # Database table configuration
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"
35 # Allow for storing data after authentication
36 postauth_table = "radpostauth"
38 authcheck_table = "radcheck"
39 authreply_table = "radreply"
41 groupcheck_table = "radgroupcheck"
42 groupreply_table = "radgroupreply"
44 usergroup_table = "usergroup"
46 # Table to keep radius client info
49 # Remove stale session if checkrad does not see a double login
50 deletestalesessions = yes
52 # Print all SQL statements when in debug mode (-x)
54 sqltracefile = ${logdir}/sqltrace.sql
56 # number of sql connections to make to server
59 # number of seconds to dely retrying on a failed database
60 # connection (per_socket)
61 connect_failure_retry_delay = 60
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.-_: /"
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.
76 # Uncomment the next line, if you want the sql_user_name to mean:
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}}"
83 sql_user_name = "%{User-Name}"
85 #######################################################################
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:
101 # DEFAULT Service-Type == Outbound-User, User-Profile := "outbound"
102 # DEFAULT Service-Type == Framed-User, User-Profile := "framed"
104 # By default the default_user_profile is not set
106 #default_user_profile = "DEFAULT"
108 #######################################################################
110 #######################################################################
111 # This query retrieves the radius clients
113 # 0. Row ID (currently unused)
114 # 1. Name (or IP address)
118 #######################################################################
120 nas_query = "SELECT id, nasname, shortname, type, secret FROM ${nas_table}"
122 #######################################################################
123 # Authorization Queries
124 #######################################################################
125 # These queries compare the check items for the user
126 # in ${authcheck_table} and setup the reply items in
127 # ${authreply_table}. You can use any query/tables
128 # you want, but the return data for each row MUST
129 # be in the following order:
131 # 0. Row ID (currently unused)
132 # 1. UserName/GroupName
135 # 4. Item Attr Operation
136 #######################################################################
137 # Use these for case insensitive usernames. WARNING: Slower queries!
138 # authorize_check_query = "SELECT id, UserName, Attribute, Value, op \
139 # FROM ${authcheck_table} \
140 # WHERE LOWER(Username) = LOWER('%{SQL-User-Name}') \
142 # authorize_reply_query = "SELECT id, UserName, Attribute, Value, op \
143 # FROM ${authreply_table} \
144 # WHERE LOWER(Username) = LOWER('%{SQL-User-Name}') \
147 authorize_check_query = "SELECT id, UserName, Attribute, Value, op \
148 FROM ${authcheck_table} \
149 WHERE Username = '%{SQL-User-Name}' \
151 authorize_reply_query = "SELECT id, UserName, Attribute, Value, op \
152 FROM ${authreply_table} \
153 WHERE Username = '%{SQL-User-Name}' \
156 # Use these for case insensitive usernames. WARNING: Slower queries!
157 # authorize_group_check_query = "SELECT id, GroupName, Attribute, Value, op \
158 # FROM ${groupcheck_table} \
159 # WHERE LOWER(GroupName) = LOWER('%{Sql-Group}') \
161 # authorize_group_reply_query = "SELECT id, GroupName, Attribute, Value, op \
162 # FROM ${groupreply_table} \
163 # WHERE LOWER(GroupName) = LOWER('%{Sql-Group}') \
166 authorize_group_check_query = "SELECT id, GroupName, Attribute, Value, op \
167 FROM ${groupcheck_table} \
168 WHERE GroupName = '%{Sql-Group}' \
170 authorize_group_reply_query = "SELECT id, GroupName, Attribute, Value, op \
171 FROM ${groupreply_table} \
172 WHERE GroupName = '%{Sql-Group}' \
175 #######################################################################
177 #######################################################################
178 # accounting_onoff_query - query for Accounting On/Off packets
179 # accounting_update_query - query for Accounting update packets
180 # accounting_update_query_alt - query for Accounting update packets
181 # (alternate in case first query fails)
182 # accounting_start_query - query for Accounting start packets
183 # accounting_start_query_alt - query for Accounting start packets
184 # (alternate in case first query fails)
185 # accounting_stop_query - query for Accounting stop packets
186 # accounting_stop_query_alt - query for Accounting start packets
187 # (alternate in case first query doesn't
188 # affect any existing rows in the table)
189 #######################################################################
190 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'"
192 accounting_update_query = "UPDATE ${acct_table1} \
193 SET FramedIPAddress = '%{Framed-IP-Address}', \
194 AcctSessionTime = '%{Acct-Session-Time}', \
195 AcctInputOctets = '%{Acct-Input-Octets}', \
196 AcctOutputOctets = '%{Acct-Output-Octets}' \
197 WHERE AcctSessionId = '%{Acct-Session-Id}' \
198 AND UserName = '%{SQL-User-Name}' \
199 AND NASIPAddress= '%{NAS-IP-Address}'"
201 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')"
203 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')"
205 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}'"
207 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}'"
209 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}')"
211 #######################################################################
212 # Simultaneous Use Checking Queries
213 #######################################################################
214 # simul_count_query - query for the number of current connections
215 # - If this is not defined, no simultaneouls use checking
216 # - will be performed by this module instance
217 # simul_verify_query - query to return details of current connections for verification
218 # - Leave blank or commented out to disable verification step
219 # - Note that the returned field order should not be changed.
220 #######################################################################
222 # Uncomment simul_count_query to enable simultaneous use checking
223 # simul_count_query = "SELECT COUNT(*) FROM ${acct_table1} WHERE UserName='%{SQL-User-Name}' AND AcctStopTime = 0"
224 simul_verify_query = "SELECT RadAcctId, AcctSessionId, UserName, NASIPAddress, NASPortId, FramedIPAddress, CallingStationId, FramedProtocol FROM ${acct_table1} WHERE UserName='%{SQL-User-Name}' AND AcctStopTime = 0"
226 #######################################################################
227 # Group Membership Queries
228 #######################################################################
229 # group_membership_query - Check user group membership
230 #######################################################################
232 group_membership_query = "SELECT GroupName FROM ${usergroup_table} WHERE UserName='%{SQL-User-Name}' ORDER BY priority"
235 # If set to 'yes' (default) we read the group tables
236 # If set to 'no' the user MUST have Fall-Through = Yes in the radreply table
239 #######################################################################
240 # Authentication Logging Queries
241 #######################################################################
242 # postauth_query - Insert some info after authentication
243 #######################################################################
245 postauth_query = "INSERT into ${postauth_table} (id, user, pass, reply, date) values ('', '%{User-Name}', '%{User-Password:-Chap-Password}', '%{reply:Packet-Type}', '%S')"
248 # Set to 'yes' to read radius clients from the database ('nas' table)