File: test_multi.c

package info (click to toggle)
apparmor 3.0.8-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 29,932 kB
  • sloc: ansic: 21,504; python: 20,695; sh: 10,935; cpp: 5,729; yacc: 2,064; makefile: 1,759; perl: 1,254; lex: 1,140; pascal: 1,098; ruby: 365; exp: 250; java: 212; xml: 159
file content (140 lines) | stat: -rw-r--r-- 3,759 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#define _GNU_SOURCE /* for glibc's basename version */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>

#include <aalogparse.h>

int print_results(aa_log_record *record);

int main(int argc, char **argv)
{
	FILE *testcase;
	char log_line[1024];
	aa_log_record *test = NULL;
	size_t size;
	int ret = -1;

	if (argc != 2)
	{
		fprintf(stderr, "Usage: test_multi.multi <filename>\n");
		return(1);
	}

	printf("START\n");
	printf("File: %s\n", basename(argv[1]));

	testcase = fopen(argv[1], "r");
	if (testcase == NULL)
	{
		perror("Could not open testcase: ");
		return(1);
	}

	size = fread(log_line, 1, 1023, testcase);
	if (ferror(testcase)) {
		fprintf(stderr, "Could not read testcase.\n");
		fclose(testcase);
		return(1);
	}
	fclose(testcase);
	log_line[size] = 0;

	test = parse_record(log_line);

	if (test == NULL)
	{
		fprintf(stderr,"Parsing failed.\n");
		return(1);
	}
	ret = print_results(test);
	free_record(test);
	return ret;
}

#define print_string(description, var) \
	if ((var) != NULL) { \
		printf("%s: %s\n", (description), (var)); \
	}

/* unset is the value that the library sets to the var to indicate
   that it is unset */
#define print_long(description, var, unset) \
	if ((var) != (unsigned long) (unset)) { \
		printf("%s: %ld\n", (description), (var)); \
	}

#define event_case(event) \
	case event: { \
		print_string("Event type", #event ); \
		break; \
	}

int print_results(aa_log_record *record)
{
		switch(record->event)
		{
			event_case(AA_RECORD_ERROR);
			event_case(AA_RECORD_INVALID);
			event_case(AA_RECORD_AUDIT);
			event_case(AA_RECORD_ALLOWED);
			event_case(AA_RECORD_DENIED);
			event_case(AA_RECORD_HINT);
			event_case(AA_RECORD_STATUS);
			default: {
				print_string("Event type", "UNKNOWN EVENT TYPE");
				break;
			}
		}

		print_string("Audit ID", record->audit_id);
		print_string("Operation", record->operation);
		print_string("Mask", record->requested_mask);
		print_string("Denied Mask", record->denied_mask);

		print_long("fsuid", record->fsuid, (unsigned long) -1);
		print_long("ouid", record->ouid, (unsigned long) -1)

		print_string("Profile", record->profile);
		print_string("Peer profile", record->peer_profile);
		print_string("Peer", record->peer);
		print_string("Name", record->name);
		print_string("Command", record->comm);
		print_string("Name2", record->name2);
		print_string("Namespace", record->namespace);
		print_string("Attribute", record->attribute);
		print_long("Task", record->task, 0);
		print_long("Parent", record->parent, 0);
		print_long("Token", record->magic_token, 0);
		print_string("Info", record->info);
		print_string("Peer info", record->peer_info);
		print_long("ErrorCode", (long) record->error_code, 0);
		print_long("PID", record->pid, 0);
		print_long("Peer PID", record->peer_pid, 0);
		print_string("Active hat", record->active_hat);

		print_string("Network family", record->net_family);
		print_string("Socket type", record->net_sock_type);
		print_string("Protocol", record->net_protocol);
		print_string("Local addr", record->net_local_addr);
		print_string("Foreign addr", record->net_foreign_addr);
		print_long("Local port", record->net_local_port, 0);
		print_long("Foreign port", record->net_foreign_port, 0);

		print_string("DBus bus", record->dbus_bus);
		print_string("DBus path", record->dbus_path);
		print_string("DBus interface", record->dbus_interface);
		print_string("DBus member", record->dbus_member);

		print_string("Signal", record->signal);

		print_string("FS Type", record->fs_type);
		print_string("Flags", record->flags);
		print_string("Src name", record->src_name);

		print_long("Epoch", record->epoch, 0);
		print_long("Audit subid", (long) record->audit_sub_id, 0);
	return(0);
}