Before enabling auditing, establish a threshold procedure to automatically switch auditing tables when the current table is full.
The threshold procedure for the audit device segments should:
Make the next empty audit table current using sp_configure.
Archive the audit table that is almost full using the insert and select commands.
The current audit table configuration parameter establishes the table where Adaptive Server writes audit rows. As a System Security Officer, you can change the current audit table with sp_configure, using the following syntax, where n is an integer that determines the new current audit table:
sp_configure "current audit table", n [, "with truncate"]
The valid values for n are:
1 means sysaudits_01, 2 means sysaudits_02, and so forth.
0 tells Adaptive Server to automatically set the current audit table to the next table. For example, if your installation has three audit tables, sysaudits_01, sysaudits_02, and sysaudits_03, Adaptive Server sets the current audit table to:
2 if the current audit table is sysaudits_01
3 if the current audit table is sysaudits_02
1 if the current audit table is sysaudits_03
The with truncate option specifies that Adaptive Server should truncate the new table if it is not already empty. If you do not specify this option and the table is not empty, sp_configure fails.
If Adaptive Server truncates the current audit table and you have not archived the data, the table’s audit records are lost. Archive the audit data before you use the with truncate option.
To execute sp_configure to change the current audit table, you must have the sso_role active. You can write a threshold procedure to automatically change the current audit table.
You can use insert with select to copy the audit data into an existing table having the same columns as the audit tables in sybsecurity.
Be sure that the threshold procedure can successfully copy data into the archive table in another database:
Create the archive database on a separate device from the one containing audit tables in sybsecurity.
Create an archive table with columns identical to those in the sybsecurity audit tables. If such a table does not already exist, you can use select into to create an empty one by having a false condition in the where clause. For example:
use aud_db go select * into audit_data from sybsecurity.dbo.sysaudits_01 where 1 = 2
The where condition is always false, so an empty duplicate of sysaudits_01 is created.
The select into/bulk copy database option must be turned on in the archive database (using sp_dboption) before you can use select into.
The threshold procedure, after using sp_configure to change the audit table, can use insert and select to copy data to the archive table in the archive database. The procedure can execute commands similar to these:
insert aud_db.sso_user.audit_data select * from sybsecurity.dbo.sysaudits_01
This sample threshold procedure assumes that three tables are configured for auditing:
declare @audit_table_number int /* ** Select the value of the current audit table */ select @audit_table_number = scc.value from master.dbo.syscurconfigs scc, master.dbo.sysconfigures sc where sc.config=scc.config and sc.name = “current audit table” /* ** Set the next audit table to be current. ** When the next audit table is specified as 0, ** the value is automatically set to the next one. */ exec sp_configure “current audit table”, 0, “with truncate” /* ** Copy the audit records from the audit table ** that became full into another table. */ if @audit_table_number = 1 begin insert aud_db.sso_user.sysaudits select * from sysaudits_01 truncate table sysaudits_01 end else if @audit_table_number = 2 begin insert aud_db.sso_user.sysaudits select * from sysaudits_02 truncate table sysaudits_02 end return(0)
To attach the threshold procedure to each audit table segment, use the sp_addthreshold.
Before executing sp_addthreshold:
Determine the number of audit tables configured for your installation and the names of their device segments
Have the permissions and roles you need for sp_addthreshold for all the commands in the threshold procedure
WARNING! sp_addthreshold and sp_modifythreshold check to ensure that only a user with sa_role directly granted can add or modify a threshold. All system-defined roles that are active when you add or modify a threshold are inserted as valid roles for your login in the systhresholds table. However, only directly granted roles are activated when the threshold procedure fires.
When you install auditing, auditinit displays the name of each audit table and its segment. The segment names are “aud_seg1” for sysaudits_01, “aud_seg2” for sysaudits_02, and so forth. You can find information about the segments in the sybsecurity database if you execute sp_helpsegment with sybsecurity as your current database. One way to find the number of audit tables for your installation is to execute the following SQL commands:
use sybsecurity go select count(*) from sysobjects where name like "sysaudit%" go
In addition, you can get information about the audit tables and the sybsecurity database by executing the following SQL commands:
sp_helpdb sybsecurity go use sybsecurity go sp_help sysaudits_01 go sp_help sysaudits_02 go ...
To execute sp_addthreshold, you must be either the Database Owner or a System Administrator. A System Security Officer should be the owner of the sybsecurity database and, therefore, should be able to execute sp_addthreshold. In addition to being able to execute sp_addthreshold, you must have permission to execute all the commands in your threshold procedure. For example, to execute sp_configure for current audit table, the sso_role must be active. When the threshold procedure fires, Adaptive Server attempts to turn on all the roles and permissions that were in effect when you executed sp_addthreshold.
To attach the threshold procedure audit_thresh to three device segments:
use sybsecurity go sp_addthreshold sybsecurity, aud_seg_01, 250, audit_thresh sp_addthreshold sybsecurity, aud_seg_02, 250, audit_thresh sp_addthreshold sybsecurity, aud_seg_03, 250, audit_thresh go
The sample threshold procedure audit_thresh receives control when fewer than 250 free pages remain in the current audit table.
For more information about adding threshold procedures, see Chapter 29, “Managing Free Space with Thresholds.”
After you enable auditing, Adaptive Server writes all audit data to the initial current audit table, sysaudits_01. When sysaudits_01 is within 250 pages of being full, the threshold procedure audit_thresh fires. The procedure switches the current audit table to sysaudits_02, and, immediately, Adaptive Server starts writing new audit records to sysaudits_02. The procedure also copies all audit data from sysaudits_01 to the audit_data archive table in the audit_db database. The rotation of the audit tables continues in this fashion without manual intervention.