Skip to content

Commit 066a204

Browse files
committed
informix audit code for trigger
1 parent 11c889a commit 066a204

19 files changed

+1683
-0
lines changed

informix_auditing/README.txt

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
Fine-Grained Auditing testing function
2+
3+
IDS 9.50.xC4 has added functionality for trigger introspection. This allows
4+
us to write a generic trigger function that can record the changes made
5+
to any table in the database.
6+
7+
This directory implement three versions of this UDR. One version (do_auditing1)
8+
uses a table to log the changes. The other versions (do_auditing2, do_auditing3) uses
9+
SESSION memory to keep track of the rows and a callback writes the
10+
result to files if the transaction was successful.
11+
12+
Both versions should implement more testing on buffer usage. The current
13+
buffer has a max length of 29900 bytes. If the result is larger, we will get
14+
a stack trace due to memory problems.
15+
16+
This directory contains:
17+
18+
README : This file
19+
WinNT.mak : Makefile for Windows
20+
do_auditing1.c : do_auditing1 UDR source code
21+
do_auditing1.sql : register the do_auditing1 functions
22+
do_auditing1_d.sql: deregister the do_auditing1 functions
23+
do_auditing2.c : do_auditing2 UDR source code
24+
do_auditing2.sql : register the do_auditing2 functions
25+
do_auditing2_d.sql: deregister the do_auditing2 functions
26+
do_auditing3.c : do_auditing3 UDR source code
27+
do_auditing3.sql : register the do_auditing3 functions
28+
do_auditing3_d.sql: deregister the do_auditing3 functions
29+
RecordAudit.java : Java procedure used by do_auditing3
30+
tryit.sql : test the functionality for do_auditing1
31+
(writing to table auditTable)
32+
tryit2.sql : test the functionality for do_auditing2
33+
(writing to files in /tmp, names: audit_xx.xml)
34+
tryit2.sql : test the functionality for do_auditing2
35+
(writing to files in /tmp, names: audit_xx.xml)
36+
UNIX.mak : Generic makefile for Unix platforms
37+
38+
You register do_auditing1, do_auditing2, or do_auditing3 as follows:
39+
40+
- Execute the Makefile: nmake -f winnt.mak
41+
- Create $INFORMIX/extend/auditing
42+
- Execute the Makefile for install: nmake -f winnt.mak install
43+
- Register do_auditing1, do_auditing2, or do_auditing3:
44+
. dbaccess -e <dbname> do_auditing1
45+
. dbaccess -e <dbname> do_auditing2
46+
. dbaccess -e <dbname> do_auditing3
47+
- Execute the test script:
48+
. dbaccess -e <dbname> tryit
49+
. dbaccess -e <dbname> tryit2
50+
. dbaccess -e <dbname> tryit3
51+
- De-register the UDR:
52+
. dbaccess -e <dbname> do_auditing1_d
53+
. dbaccess -e <dbname> do_auditing2_d
54+
. dbaccess -e <dbname> do_auditing3_d
55+
56+
By default, tracing is turned off. you can turn it on in the testit,
57+
testit2, and testit3 scripts. You also need to change the make file to remove
58+
the definition of -DMITRACE_OFF=1 from the compilation.
59+
60+
If you are trying this code on a Unix platform, uncomment and modify line 32 of
61+
the Unix.mak file: uncomment and use your platform-specific include file.

informix_auditing/RecordAudit.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// (c) Copyright IBM Corp. 2004 All rights reserved. */
2+
// */
3+
// This sample program is owned by International Business Machines */
4+
// Corporation or one of its subsidiaries ("IBM") and is copyrighted */
5+
// and licensed, not sold. */
6+
// */
7+
// You may copy, modify, and distribute this sample program in any */
8+
// form without payment to IBM, for any purpose including developing,*/
9+
// using, marketing or distributing programs that include or are */
10+
// derivative works of the sample program. */
11+
// */
12+
// The sample program is provided to you on an "AS IS" basis, without */
13+
// warranty of any kind. IBM HEREBY EXPRESSLY DISCLAIMS ALL */
14+
// WARRANTIES EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO*/
15+
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTIC-*/
16+
// ULAR PURPOSE. Some jurisdictions do not allow for the exclusion or */
17+
// limitation of implied warranties, so the above limitations or */
18+
// exclusions may not apply to you. IBM shall not be liable for any */
19+
// damages you suffer as a result of using, modifying or distributing */
20+
// the sample program or its derivatives. */
21+
// */
22+
// Each copy of any portion of this sample program or any derivative */
23+
// work, must include a the above copyright notice and disclaimer of */
24+
// warranty. */
25+
// */
26+
// ********************************************************************/
27+
28+
import java.io.*;
29+
30+
public class RecordAudit {
31+
public static void writeFile(String fname, String content) throws IOException
32+
{
33+
BufferedWriter fout;
34+
35+
fout = new BufferedWriter(new FileWriter(fname) );
36+
fout.write(content);
37+
fout.newLine();
38+
fout.close();
39+
return;
40+
}
41+
}

informix_auditing/UNIX.mak

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# (c) Copyright IBM Corp. 2004 All rights reserved. */
2+
# */
3+
# This sample program is owned by International Business Machines */
4+
# Corporation or one of its subsidiaries ("IBM") and is copyrighted */
5+
# and licensed, not sold. */
6+
# */
7+
# You may copy, modify, and distribute this sample program in any */
8+
# form without payment to IBM, for any purpose including developing,*/
9+
# using, marketing or distributing programs that include or are */
10+
# derivative works of the sample program. */
11+
# */
12+
# The sample program is provided to you on an "AS IS" basis, without */
13+
# warranty of any kind. IBM HEREBY EXPRESSLY DISCLAIMS ALL */
14+
# WARRANTIES EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO*/
15+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTIC-*/
16+
# ULAR PURPOSE. Some jurisdictions do not allow for the exclusion or */
17+
# limitation of implied warranties, so the above limitations or */
18+
# exclusions may not apply to you. IBM shall not be liable for any */
19+
# damages you suffer as a result of using, modifying or distributing */
20+
# the sample program or its derivatives. */
21+
# */
22+
# Each copy of any portion of this sample program or any derivative */
23+
# work, must include a the above copyright notice and disclaimer of */
24+
# warranty. */
25+
# */
26+
# ********************************************************************/
27+
28+
# This Makefile builds the logger libraries
29+
# TARGET must be set to the location/filename
30+
# of the platform-specific make include file.
31+
32+
TARGET=$(INFORMIXDIR)/incl/dbdk/makeinc.linux
33+
include $(TARGET)
34+
# ===============================================================
35+
# This is the project title.
36+
PROJECT_TITLE = auditing
37+
38+
BINDIR = $(OS_NAME)-$(PLATFORM)
39+
40+
# Platform independent code goes here.
41+
# The following code was generated by BladeSmith.
42+
43+
MI_INCL = $(INFORMIXDIR)/incl
44+
COPTS=-O -DMI_SERVBUILD -DMITRACE_OFF=1
45+
CFLAGS =$(COPTS) $(CC_PIC) -I$(MI_INCL)/public -I$(MI_INCL)
46+
LINKFLAGS = $(SHLIBLFLAG) $(SYMFLAG)
47+
LIBS =
48+
49+
PROJECT_OBJS= $(BINDIR)/auditing1.$(OBJSUFF) $(BINDIR)/auditing2.$(OBJSUFF) $(BINDIR)/auditing3.$(OBJSUFF) $(BINDIR)/audit_util.$(OBJSUFF)
50+
51+
PROJECT_LIBS=$(BINDIR)/$(PROJECT_TITLE).$(BLDLIB_SUFF)
52+
53+
all: $(BINDIR) RecordAudit.jar
54+
$(MAKE) $(MAKEFLAGS) -f UNIX.mak server
55+
56+
# Construct the object file.
57+
58+
$(BINDIR)/auditing1.$(OBJSUFF) : auditing1.c
59+
$(CC) $(CFLAGS) -o $@ -c $?
60+
61+
$(BINDIR)/auditing2.$(OBJSUFF) : auditing2.c
62+
$(CC) $(CFLAGS) -o $@ -c $?
63+
64+
$(BINDIR)/auditing3.$(OBJSUFF) : auditing3.c
65+
$(CC) $(CFLAGS) -o $@ -c $?
66+
67+
$(BINDIR)/audit_util.$(OBJSUFF) : audit_util.c
68+
$(CC) $(CFLAGS) -o $@ -c $?
69+
70+
RecordAudit.class: RecordAudit.java
71+
javac RecordAudit.java
72+
73+
RecordAudit.jar: RecordAudit.class
74+
jar cf RecordAudit.jar RecordAudit.class
75+
76+
# Construct the shared library.
77+
# Do *NOT* link with client side libraries.
78+
# You will see many undefined symbols during linking. This is
79+
# normal since those symbols are resolved when the server loads
80+
# your shared object.
81+
#
82+
# ATTENTION:
83+
# The ld "Symbol referencing errors" warning is normal.
84+
# These unresolved symbols are resolved when the server
85+
# loads the shared object. This list should be examined, however,
86+
# for symbol names that may have been inadvertently misspelled.
87+
# Misspelled symbol names will not be resolved here or at load time.
88+
#
89+
$(PROJECT_LIBS) : $(PROJECT_OBJS)
90+
$(SHLIBLOD) $(LINKFLAGS) -o $(PROJECT_LIBS) \
91+
$(PROJECT_OBJS) $(LIBS) $(DATABLADE_LIBS) 2> link.errs
92+
93+
server: $(PROJECT_LIBS)
94+
95+
clean:
96+
$(RM) $(RMFLAGS) $(PROJECT_LIBS) $(PROJECT_OBJS) RecordAudit.class RecordAudit.jar
97+
98+
$(BINDIR):
99+
-mkdir $(BINDIR)
100+
101+
INSTALL:
102+
cp $(PROJECT_TITLE).bld $(INFORMIXDIR)/extend/auditing/$(PROJECT_TITLE).bld
103+
cp RecordAudit.jar $(INFORMIXDIR)/extend/auditing/RecordAudit.jar

informix_auditing/WinNT.mak

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# This Makefile builds the shared library
2+
# (c) Copyright IBM Corp. 2004 All rights reserved. */
3+
# */
4+
# This sample program is owned by International Business Machines */
5+
# Corporation or one of its subsidiaries ("IBM") and is copyrighted */
6+
# and licensed, not sold. */
7+
# */
8+
# You may copy, modify, and distribute this sample program in any */
9+
# form without payment to IBM, for any purpose including developing,*/
10+
# using, marketing or distributing programs that include or are */
11+
# derivative works of the sample program. */
12+
# */
13+
# The sample program is provided to you on an "AS IS" basis, without */
14+
# warranty of any kind. IBM HEREBY EXPRESSLY DISCLAIMS ALL */
15+
# WARRANTIES EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO*/
16+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTIC-*/
17+
# ULAR PURPOSE. Some jurisdictions do not allow for the exclusion or */
18+
# limitation of implied warranties, so the above limitations or */
19+
# exclusions may not apply to you. IBM shall not be liable for any */
20+
# damages you suffer as a result of using, modifying or distributing */
21+
# the sample program or its derivatives. */
22+
# */
23+
# Each copy of any portion of this sample program or any derivative */
24+
# work, must include a the above copyright notice and disclaimer of */
25+
# warranty. */
26+
# */
27+
# ********************************************************************/
28+
29+
# This is the project title.
30+
PROJECT_TITLE = auditing
31+
32+
# Insure that INFORMIXDIR is set.
33+
!IF "$(INFORMIXDIR)" == ""
34+
!MESSAGE
35+
!MESSAGE The INFORMIXDIR environment variable is not set.
36+
!MESSAGE This variable must be be set to the location of
37+
!MESSAGE the Informix installation. This is typically
38+
!MESSAGE X:\informix where "X" is the drive letter.
39+
!MESSAGE Use "set INFORMIXDIR X:\informix" to set this
40+
!MESSAGE variable from a DOS command prompt or the System
41+
!MESSAGE entry in the Control Panel to set it permanently.
42+
!MESSAGE
43+
!MESSAGE INFORMIXDIR has defaulted to $(HOMEDRIVE)\informix.
44+
!MESSAGE
45+
INFORMIXDIR=$(HOMEDRIVE)\informix
46+
!ENDIF
47+
48+
# NT-specific code goes here.
49+
MI_INCLUDE="$(INFORMIXDIR)"\incl
50+
RM= del
51+
RMFLAGS= /q
52+
CC= cl
53+
CSRVRFLAGS= -DNT -DMI_SERVBUILD -DGL_NT_STATIC -DNT_MI_SAPI
54+
COPTS= -O -DMITRACE_OFF=1
55+
# COPTS= -O
56+
CFLAGS=$(CSRVRFLAGS) -DWIN32 -I$(MI_INCLUDE)\public -I$(MI_INCLUDE) $(COPTS)
57+
LINK= link
58+
LINKFLAGS= /DLL /nologo $(LOPTS)
59+
LIBS= "$(INFORMIXDIR)"\lib\sapi.lib
60+
BINDIR= WinNT-i386
61+
PRODDIR= .
62+
63+
# Platform independent code goes here.
64+
# The following code was generated by BladeSmith.
65+
66+
all: $(BINDIR) RecordAudit.jar
67+
$(MAKE) -$(MAKEFLAGS) -f WinNT.mak server
68+
69+
.c.obj:
70+
$(CC) $(CFLAGS) /Fo$*.obj /c $?
71+
72+
# List all object files.
73+
OBJ1=$(BINDIR)/auditing1.obj $(BINDIR)/auditing2.obj $(BINDIR)/audit_util.obj
74+
OBJ2=$(BINDIR)/auditing3.obj
75+
76+
OBJS_ALL=$(OBJ1) $(OBJ2)
77+
78+
# Construct the object file.
79+
$(BINDIR)/auditing1.obj: auditing1.c
80+
$(CC) $(CFLAGS) /Fo$*.obj /c $?
81+
82+
$(BINDIR)/auditing2.obj: auditing2.c
83+
$(CC) $(CFLAGS) /Fo$*.obj /c $?
84+
85+
$(BINDIR)/auditing3.obj: auditing3.c
86+
$(CC) $(CFLAGS) /Fo$*.obj /c $?
87+
88+
$(BINDIR)/audit_util.obj: audit_util.c
89+
$(CC) $(CFLAGS) /Fo$*.obj /c $?
90+
91+
RecordAudit.class: RecordAudit.java
92+
javac RecordAudit.java
93+
94+
RecordAudit.jar: RecordAudit.class
95+
jar cf RecordAudit.jar RecordAudit.class
96+
97+
# Construct the DLL library.
98+
$(PRODDIR)\\$(PROJECT_TITLE).bld: $(OBJS_ALL)
99+
attrib -R $(PRODDIR)\\$(PROJECT_TITLE).bld > nul
100+
$(LINK) $(LINKFLAGS) /out:$(PRODDIR)\\$(PROJECT_TITLE).bld /def:$(PROJECT_TITLE).def $(OBJS_ALL) $(LIBS)
101+
attrib +R $(PRODDIR)\\$(PROJECT_TITLE).bld
102+
103+
server: $(PRODDIR)\\$(PROJECT_TITLE).bld
104+
105+
clean:
106+
attrib -R $(PRODDIR)\\$(PROJECT_TITLE).bld > nul
107+
$(RM) $(RMFLAGS) $(PRODDIR)\\$(PROJECT_TITLE).bld
108+
$(RM) $(RMFLAGS) $(PRODDIR)\\$(PROJECT_TITLE).exp
109+
$(RM) $(RMFLAGS) $(PRODDIR)\\$(PROJECT_TITLE).lib
110+
$(RM) $(RMFLAGS) $(BINDIR)\\*.obj
111+
112+
$(BINDIR):
113+
-mkdir $(BINDIR)
114+
115+
INSTALL:
116+
attrib -R "$(INFORMIXDIR)"\extend\auditing\$(PROJECT_TITLE).bld
117+
COPY $(PROJECT_TITLE).bld "$(INFORMIXDIR)"\extend\$(PROJECT_TITLE)
118+
attrib +R "$(INFORMIXDIR)"\extend\auditing\$(PROJECT_TITLE).bld
119+
COPY RecordAudit.jar "$(INFORMIXDIR)"\extend\auditing\RecordAudit.jar

0 commit comments

Comments
 (0)