Skip to content

Commit 50ef75c

Browse files
authored
Improve handling of raw audit data (#462)
* Add new log * auparse_test: optionally interpret field value Do not interpret all the values within the test suite, especially in places where RAW audit format is used. * auparse_test: optionally interpret field value in callback Do not interpret all the values within the test suite, especially in places where RAW audit format is used. * Adjust reference output * Rename new test suite file * Enable test suite for all currently available distros * auparse_test.py: Disable interpretation in RAW audit logs
1 parent 03f1ead commit 50ef75c

File tree

5 files changed

+2040
-2018
lines changed

5 files changed

+2040
-2018
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,4 @@ jobs:
6060
make -j$(nproc)
6161
6262
- name: Run tests
63-
# Temporarily disable for Ubuntu
64-
if: matrix.container != 'ubuntu:latest'
6563
run: make check

auparse/test/auparse_test.c

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ static const char *buf[] = {
2020
unsigned int walked_fields = 0;
2121
#define FIELDS_EXPECTED 403
2222

23-
static void walk_test(auparse_state_t *au)
23+
static void walk_test(auparse_state_t *au, int interpret)
2424
{
2525
int event_cnt = 1, record_cnt;
2626

@@ -53,10 +53,16 @@ static void walk_test(auparse_state_t *au)
5353
e->milli, e->serial, e->host ? e->host : "?");
5454
auparse_first_field(au);
5555
do {
56-
printf(" %s=%s (%s)\n",
57-
auparse_get_field_name(au),
58-
auparse_get_field_str(au),
59-
auparse_interpret_field(au));
56+
if (interpret) {
57+
printf(" %s=%s (%s)\n",
58+
auparse_get_field_name(au),
59+
auparse_get_field_str(au),
60+
auparse_interpret_field(au));
61+
} else {
62+
printf(" %s=%s\n",
63+
auparse_get_field_name(au),
64+
auparse_get_field_str(au));
65+
}
6066
walked_fields++;
6167
} while (auparse_next_field(au) > 0);
6268
printf("\n");
@@ -221,17 +227,22 @@ void regex_search(const char *expr)
221227
auparse_destroy(au);
222228
}
223229

230+
typedef struct {
231+
int *event_cnt;
232+
int interpret;
233+
} callback_data_t;
234+
224235
static void auparse_callback(auparse_state_t *au, auparse_cb_event_t cb_event_type, void *user_data)
225236
{
226-
int *event_cnt = (int *)user_data;
237+
callback_data_t *data = (callback_data_t *)user_data;
227238
int record_cnt;
228239

229240
if (cb_event_type == AUPARSE_CB_EVENT_READY) {
230241
if (auparse_first_record(au) <= 0) {
231242
printf("can't get first record\n");
232243
return;
233244
}
234-
printf("event %d has %u records\n", *event_cnt,
245+
printf("event %d has %u records\n", *(data->event_cnt),
235246
auparse_get_num_records(au));
236247
record_cnt = 1;
237248
do {
@@ -254,15 +265,21 @@ static void auparse_callback(auparse_state_t *au, auparse_cb_event_t cb_event_ty
254265
e->host ? e->host : "?");
255266
auparse_first_field(au);
256267
do {
257-
printf(" %s=%s (%s)\n",
258-
auparse_get_field_name(au),
259-
auparse_get_field_str(au),
260-
auparse_interpret_field(au));
268+
if (data->interpret) {
269+
printf(" %s=%s (%s)\n",
270+
auparse_get_field_name(au),
271+
auparse_get_field_str(au),
272+
auparse_interpret_field(au));
273+
} else {
274+
printf(" %s=%s\n",
275+
auparse_get_field_name(au),
276+
auparse_get_field_str(au));
277+
}
261278
} while (auparse_next_field(au) > 0);
262279
printf("\n");
263280
record_cnt++;
264281
} while(auparse_next_record(au) > 0);
265-
(*event_cnt)++;
282+
(*(data->event_cnt))++;
266283
}
267284
}
268285

@@ -304,7 +321,7 @@ int main(void)
304321
/* Reset, now lets go to beginning and walk the list manually */
305322
printf("Starting Test 2, walk events, records, and fields...\n");
306323
auparse_reset(au);
307-
walk_test(au);
324+
walk_test(au, 1);
308325
auparse_destroy(au);
309326
printf("Test 2 Done\n\n");
310327

@@ -325,7 +342,7 @@ int main(void)
325342
printf("Error - %s\n", strerror(errno));
326343
return 1;
327344
}
328-
walk_test(au);
345+
walk_test(au, 0);
329346
auparse_destroy(au);
330347
printf("Test 4 Done\n\n");
331348

@@ -335,7 +352,7 @@ int main(void)
335352
printf("Error - %s\n", strerror(errno));
336353
return 1;
337354
}
338-
walk_test(au);
355+
walk_test(au, 0);
339356
auparse_destroy(au);
340357
printf("Test 5 Done\n\n");
341358

@@ -409,12 +426,13 @@ int main(void)
409426
printf("Starting Test 9, buffer feed...\n");
410427
{
411428
int event_cnt = 1;
429+
callback_data_t cb_data = { &event_cnt, 1 };
412430
size_t len, chunk_len = 3;
413431
const char **cur_buf, *p_beg, *p_end, *p_chunk_beg,
414432
*p_chunk_end;
415433

416434
au = auparse_init(AUSOURCE_FEED, 0);
417-
auparse_add_callback(au, auparse_callback, &event_cnt, NULL);
435+
auparse_add_callback(au, auparse_callback, &cb_data, NULL);
418436
for (cur_buf = buf, p_beg = *cur_buf; *cur_buf;
419437
cur_buf++, p_beg = *cur_buf) {
420438
len = strlen(p_beg);
@@ -441,15 +459,15 @@ int main(void)
441459
/* Note: this should match Test 4 exactly */
442460
printf("Starting Test 10, file feed...\n");
443461
{
444-
int *event_cnt = malloc(sizeof(int));
462+
int event_cnt = 1;
463+
callback_data_t cb_data = { &event_cnt, 0 };
445464
size_t len;
446465
char filename[] = "./test.log";
447466
char buf[4];
448467
FILE *fp;
449468

450-
*event_cnt = 1;
451469
au = auparse_init(AUSOURCE_FEED, 0);
452-
auparse_add_callback(au, auparse_callback, event_cnt, free);
470+
auparse_add_callback(au, auparse_callback, &cb_data, NULL);
453471
if ((fp = fopen(filename, "r")) == NULL) {
454472
fprintf(stderr, "could not open '%s', %s\n",
455473
filename, strerror(errno));
@@ -473,7 +491,7 @@ int main(void)
473491
}
474492

475493
walked_fields = 0;
476-
walk_test(au);
494+
walk_test(au, 0);
477495
auparse_destroy(au);
478496

479497
if (walked_fields != FIELDS_EXPECTED) {

auparse/test/auparse_test.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def none_to_null(s):
2626
walked_fields = 0
2727
FIELDS_EXPECTED = 403
2828

29-
def walk_test(au):
29+
def walk_test(au, interpret=False):
3030
global walked_fields
3131
event_cnt = 1
3232

@@ -53,7 +53,10 @@ def walk_test(au):
5353
print(" event time: %d.%d:%d, host=%s" % (event.sec, event.milli, event.serial, none_to_null(event.host)))
5454
au.first_field()
5555
while True:
56-
print(" %s=%s (%s)" % (au.get_field_name(), au.get_field_str(), au.interpret_field()))
56+
if interpret:
57+
print(" %s=%s (%s)" % (au.get_field_name(), au.get_field_str(), au.interpret_field()))
58+
else:
59+
print(" %s=%s" % (au.get_field_name(), au.get_field_str()))
5760
walked_fields += 1
5861
if not au.next_field(): break
5962
print("")
@@ -123,7 +126,7 @@ def compound_search(au, how):
123126
else:
124127
print("Found %s = %s" % (au.get_field_name(), au.get_field_str()))
125128

126-
def feed_callback(au, cb_event_type, event_cnt):
129+
def feed_callback(au, cb_event_type, event_cnt, interpret=False):
127130
if cb_event_type == auparse.AUPARSE_CB_EVENT_READY:
128131
if not au.first_record():
129132
print("Error getting first record")
@@ -146,7 +149,10 @@ def feed_callback(au, cb_event_type, event_cnt):
146149
print(" event time: %d.%d:%d, host=%s" % (event.sec, event.milli, event.serial, none_to_null(event.host)))
147150
au.first_field()
148151
while True:
149-
print(" %s=%s (%s)" % (au.get_field_name(), au.get_field_str(), au.interpret_field()))
152+
if interpret:
153+
print(" %s=%s (%s)" % (au.get_field_name(), au.get_field_str(), au.interpret_field()))
154+
else:
155+
print(" %s=%s" % (au.get_field_name(), au.get_field_str()))
150156
if not au.next_field(): break
151157
print("")
152158
record_cnt += 1
@@ -166,7 +172,7 @@ def feed_callback(au, cb_event_type, event_cnt):
166172

167173
# Reset, now lets go to beginning and walk the list manually */
168174
print("Starting Test 2, walk events, records, and fields...")
169-
walk_test(au)
175+
walk_test(au, interpret=True)
170176
print("Test 2 Done\n")
171177

172178
# Reset, now lets go to beginning and walk the list manually */
@@ -234,7 +240,7 @@ def feed_callback(au, cb_event_type, event_cnt):
234240
print("Starting Test 9, buffer feed...")
235241
au = auparse.AuParser(auparse.AUSOURCE_FEED);
236242
event_cnt = 1
237-
au.add_callback(feed_callback, [event_cnt])
243+
au.add_callback(lambda au, cb_event_type, event_cnt: feed_callback(au, cb_event_type, event_cnt, interpret=False), [event_cnt])
238244
chunk_len = 3
239245
for s in buf:
240246
s_len = len(s)
@@ -251,7 +257,7 @@ def feed_callback(au, cb_event_type, event_cnt):
251257
print("Starting Test 10, file feed...")
252258
au = auparse.AuParser(auparse.AUSOURCE_FEED);
253259
event_cnt = 1
254-
au.add_callback(feed_callback, [event_cnt])
260+
au.add_callback(lambda au, cb_event_type, event_cnt: feed_callback(au, cb_event_type, event_cnt, interpret=False), [event_cnt])
255261
f = open(srcdir + "/test.log");
256262
while True:
257263
data = f.read(4)

0 commit comments

Comments
 (0)