Skip to content

Commit 707220f

Browse files
committed
Add enriched record test
This test is to ensure that when auditd is configured to create enriched events, that it does so correctly. Correct is defined as: enriched length > raw length AUDIT_INTERP_SEPARATOR is found in the record A capitalized AUID field is found in the record The actual test is not being enabled just yet.
1 parent b6b8594 commit 707220f

File tree

2 files changed

+106
-2
lines changed

2 files changed

+106
-2
lines changed

src/test/Makefile.am

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,28 @@
1919
# Steve Grubb <[email protected]>
2020
#
2121

22-
AM_CPPFLAGS = -I${top_srcdir} -I${top_srcdir}/lib -I${top_srcdir}/src
23-
check_PROGRAMS = ilist_test slist_test
22+
AM_CPPFLAGS = -I${top_srcdir} -I${top_srcdir}/lib -I${top_srcdir}/src -I${top_srcdir}/common -I${top_srcdir}/auparse
23+
check_PROGRAMS = ilist_test slist_test # format_event_test
2424
TESTS = $(check_PROGRAMS)
2525
ilist_test_LDADD = ${top_builddir}/src/ausearch-int.o
2626
ilist_test_DEPENDENCIES = ${top_builddir}/src/ausearch-int.o
2727
slist_test_LDADD = ${top_builddir}/src/ausearch-string.o
2828
slist_test_DEPENDENCIES = ${top_builddir}/src/ausearch-string.o
29+
format_event_test_LDADD = ${top_builddir}/src/auditd-event.o \
30+
${top_builddir}/src/auditd-config.o \
31+
${top_builddir}/src/auditd-auditd-sendmail.o \
32+
${top_builddir}/src/auditd-auditd-dispatch.o \
33+
${top_builddir}/src/auditd-auditd-listen.o \
34+
${top_builddir}/lib/libaudit.la ${top_builddir}/auparse/libauparse.la \
35+
${top_builddir}/audisp/libdisp.la \
36+
${top_builddir}/src/libev/libev.la \
37+
${top_builddir}/common/libaucommon.la -lpthread -lm $(gss_libs)
38+
format_event_test_DEPENDENCIES = ${top_builddir}/src/auditd-event.o \
39+
${top_builddir}/src/auditd-config.o \
40+
${top_builddir}/src/auditd-auditd-sendmail.o \
41+
${top_builddir}/src/auditd-auditd-dispatch.o \
42+
${top_builddir}/src/auditd-auditd-listen.o \
43+
${top_builddir}/lib/libaudit.la ${top_builddir}/auparse/libauparse.la \
44+
${top_builddir}/common/libaucommon.la ${top_builddir}/audisp/libdisp.la\
45+
${top_builddir}/src/libev/libev.la
46+

src/test/format_event_test.c

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#include "config.h"
2+
#include <stdio.h>
3+
#include <string.h>
4+
#include "auditd-event.h"
5+
#include "auditd-config.h"
6+
#include "common.h"
7+
8+
#ifdef HAVE_ATOMIC
9+
ATOMIC_INT stop = 0;
10+
#else
11+
volatile ATOMIC_INT stop = 0;
12+
#endif
13+
14+
void update_report_timer(unsigned int interval){}
15+
16+
int main(void)
17+
{
18+
unsigned len_raw, len_enriched;
19+
struct daemon_conf conf;
20+
memset(&conf, 0, sizeof(conf));
21+
conf.daemonize = D_FOREGROUND;
22+
conf.log_format = LF_RAW;
23+
conf.node_name_format = N_NONE;
24+
conf.node_name = "testnode";
25+
conf.end_of_event_timeout = 1;
26+
27+
if (init_event(&conf)) {
28+
fprintf(stderr, "init_event failed\n");
29+
return 1;
30+
}
31+
32+
const char *msg = "audit(0.0:1): op=test auid=-1 uid=2 gid=2 ses=-1";
33+
struct auditd_event *e;
34+
35+
e = create_event(NULL, NULL, NULL, 0);
36+
if (!e)
37+
return 1;
38+
e->reply.type = AUDIT_TRUSTED_APP;
39+
e->reply.message = strdup(msg);
40+
e->reply.len = strlen(msg);
41+
format_event(e);
42+
len_raw = strlen(e->reply.message);
43+
printf("RAW: %s\n", e->reply.message);
44+
cleanup_event(e);
45+
46+
conf.log_format = LF_ENRICHED;
47+
e = create_event(NULL, NULL, NULL, 0);
48+
if (!e)
49+
return 1;
50+
e->reply.type = AUDIT_TRUSTED_APP;
51+
e->reply.message = strdup(msg);
52+
e->reply.len = strlen(msg);
53+
format_event(e);
54+
len_enriched = strlen(e->reply.message);
55+
printf("ENRICHED: %s\n", e->reply.message);
56+
cleanup_event(e);
57+
58+
//shutdown_events();
59+
if (len_enriched <= len_raw) {
60+
printf("enriched length should be larger that raw length\n"
61+
" raw length = %u, enriched length = %u\n", len_raw,
62+
len_enriched);
63+
return 1;
64+
}
65+
if (!strchr(e->reply.message, AUDIT_INTERP_SEPARATOR)) {
66+
puts("missing AUDIT_INTERP_SEPARATOR");
67+
return 1;
68+
}
69+
if (!strstr(e->reply.message, "AUID")) {
70+
puts("missing AUID interpretation");
71+
return 1;
72+
}
73+
return 0;
74+
}
75+
76+
// Needed only for linking
77+
int send_audit_event(int type, const char *str)
78+
{
79+
return 0;
80+
}
81+
82+
// Needed only for linking
83+
void distribute_event(struct auditd_event *e)
84+
{
85+
}
86+

0 commit comments

Comments
 (0)