]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
update mssql for Class queries
authorAlan T. DeKok <aland@freeradius.org>
Tue, 25 May 2021 13:39:32 +0000 (09:39 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 25 May 2021 13:39:32 +0000 (09:39 -0400)
raddb/mods-config/sql/main/mssql/queries.conf
raddb/mods-config/sql/main/mssql/schema.sql

index ee21f740e5a385071560e48fd3b9c57e11be09d1..a69e6022a9d8fae1eab8004f25d6057401a0147e 100644 (file)
@@ -45,6 +45,40 @@ event_timestamp_epoch = "%{%{integer:Event-Timestamp}:-%l}"
 
 event_timestamp = "DATEADD(SS, ${event_timestamp_epoch}, '19700101')"
 
+#######################################################################
+#  Query config:  Class attribute
+#######################################################################
+#
+#  3.0.22 and later have a "class" column in the accounting table.
+#
+#  However, we do NOT want to break existing configurations by adding
+#  the Class attribute to the default queries.  If we did that, then
+#  systems using newer versions of the server would fail, because
+#  there is no "class" column in their accounting tables.
+#
+#  The solution to that is the following "class" subsection.  If your
+#  database has a "class" column for the various tables, then you can
+#  uncomment the configuration items here.  The queries below will
+#  then automatically insert the Class attribute into radacct,
+#  radpostauth, etc.
+#
+class {
+       #
+       #  Delete the '#' character from each of the configuration
+       #  items in this section.  This change puts the Class
+       #  attribute into the various tables.  Leave the double-quoted
+       #  string there, as the value for the configuration item.
+       #
+       #  See also policy.d/accounting, and the "insert_acct_class"
+       #  policy.  You will need to list (or uncomment)
+       #  "insert_acct_class" in the "post-auth" section in order to
+       #  create a Class attribute.
+       #
+       column_name =   # ", class"
+       packet_xlat =   # ", '%{Class}'"
+       reply_xlat =    # ", '%{Reply:Class}'"
+}
+
 #######################################################################
 #  Authorization Queries
 #######################################################################
@@ -174,7 +208,8 @@ accounting {
                                        FramedIPv6Address, \
                                        FramedIPv6Prefix, \
                                        FramedInterfaceId, \
-                                       DelegatedIPv6Prefix) \
+                                       DelegatedIPv6Prefix \
+                                       ${..class.column_name}) \
                        VALUES(\
                                '%{Acct-Session-Id}', \
                                '%{Acct-Unique-Session-Id}', \
@@ -199,7 +234,8 @@ accounting {
                                '', \
                                '', \
                                '', \
-                               '')"
+                               '' \
+                               ${....class.packet_xlat})"
 
                        query = "\
                                UPDATE ${....acct_table1} SET \
@@ -242,7 +278,8 @@ accounting {
                                        DelegatedIPv6Prefix, \
                                        AcctStartDelay, \
                                        AcctStopDelay, \
-                                       XAscendSessionSvrKey) \
+                                       XAscendSessionSvrKey \
+                                       ${..class.column_name}) \
                                VALUES(\
                                        '%{Acct-Session-Id}', \
                                        '%{Acct-Unique-Session-Id}', \
@@ -270,7 +307,8 @@ accounting {
                                        '%{Delegated-IPv6-Prefix}', \
                                        '%{Acct-Delay-Time}', \
                                        '0', \
-                                       '%{X-Ascend-Session-Svr-Key}')"
+                                       '%{X-Ascend-Session-Svr-Key}' \
+                                       ${....class.packet_xlat})"
 
                        #
                        #  When using "sql_session_start", you should comment out
@@ -348,7 +386,8 @@ accounting {
                                        FramedInterfaceId, \
                                        DelegatedIPv6Prefix, \
                                        AcctStartDelay, \
-                                       XAscendSessionSvrKey) \
+                                       XAscendSessionSvrKey \
+                                       ${..class.column_name}) \
                                VALUES(\
                                        '%{Acct-Session-Id}', \
                                        '%{Acct-Unique-Session-Id}', \
@@ -372,7 +411,8 @@ accounting {
                                        '%{Framed-Interface-Id}', \
                                        '%{Delegated-IPv6-Prefix}', \
                                        '0', \
-                                       '%{X-Ascend-Session-Svr-Key}')"
+                                       '%{X-Ascend-Session-Svr-Key}' \
+                                       ${....class.packet_xlat})"
 
                        #
                        #  When using "sql_session_start", you should comment out
@@ -447,7 +487,8 @@ accounting {
                                        FramedInterfaceId, \
                                        DelegatedIPv6Prefix, \
                                        AcctStartDelay, \
-                                       AcctStopDelay) \
+                                       AcctStopDelay \
+                                       ${..class.column_name}) \
                                VALUES(\
                                        '%{Acct-Session-Id}', \
                                        '%{Acct-Unique-Session-Id}', \
@@ -475,7 +516,8 @@ accounting {
                                        '%{Framed-Interface-Id}', \
                                        '%{Delegated-IPv6-Prefix}', \
                                        '0', \
-                                       '%{%{Acct-Delay-Time}:-0}')"
+                                       '%{%{Acct-Delay-Time}:-0}' \
+                                       ${....class.packet_xlat})"
 
                        #
                        #  When using "sql_session_start", you should comment out
@@ -529,10 +571,11 @@ post-auth {
 
        query = "\
                INSERT INTO ${..postauth_table} \
-                       (userName, pass, reply, authdate) \
+                       (userName, pass, reply, authdate ${..class.column_name}) \
                VALUES(\
                        '%{User-Name}', \
                        '%{%{User-Password}:-CHAP-PASSWORD}', \
                        '%{reply:Packet-Type}', \
-                       '%S.%{expr:%M / 1000}')"
+                       '%S.%{expr:%M / 1000}' \
+                       ${..class.reply_xlat})"
 }
index 5e23d33fc710d4b160b01b6f55ca5a1310f8397a..6338c1d1744078cabac25a9768725d4e71863a60 100644 (file)
@@ -276,10 +276,17 @@ CREATE TABLE [radpostauth] (
        [userName] [varchar] (64) NOT NULL ,
        [pass] [varchar] (64) NOT NULL ,
        [reply] [varchar] (32) NOT NULL ,
-       [authdate] [datetime] NOT NULL
+       [authdate] [datetime] NOT NULL,
+       [Class] [varchar] (64) NULL
 )
 GO
 
+CREATE INDEX [userName] ON [radpostauth]([userName]) ON [PRIMARY]
+GO
+
+CREATE INDEX [Class] ON [radpostauth]([Class]) ON [PRIMARY]
+GO
+
 ALTER TABLE [radpostauth] WITH NOCHECK ADD
        CONSTRAINT [DF_radpostauth_userName] DEFAULT ('') FOR [userName],
        CONSTRAINT [DF_radpostauth_pass] DEFAULT ('') FOR [pass],