~ubuntu-branches/ubuntu/wily/apparmor/wily

« back to all changes in this revision

Viewing changes to libraries/libapparmor/testsuite/test_multi.c

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2011-04-27 10:38:07 UTC
  • mfrom: (5.1.118 natty)
  • Revision ID: james.westby@ubuntu.com-20110427103807-ym3rhwys6o84ith0
Tags: 2.6.1-2
debian/copyright: clarify for some full organization names.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include <stdlib.h>
 
3
#include <string.h>
 
4
#include <errno.h>
 
5
 
 
6
#include "aalogparse.h"
 
7
 
 
8
int print_results(aa_log_record *record);
 
9
 
 
10
int main(int argc, char **argv)
 
11
{
 
12
        FILE *testcase;
 
13
        char log_line[1024];
 
14
        aa_log_record *test = NULL;
 
15
        int ret = -1;
 
16
 
 
17
        if (argc != 2)
 
18
        {
 
19
                fprintf(stderr, "Usage: test_multi.multi <filename>\n");
 
20
                return(1);
 
21
        }
 
22
 
 
23
        printf("START\n");
 
24
        printf("File: %s\n", argv[1]);
 
25
 
 
26
        testcase = fopen(argv[1], "r");
 
27
        if (testcase == NULL)
 
28
        {
 
29
                perror("Could not open testcase: ");
 
30
                return(1);
 
31
        }
 
32
 
 
33
        if (fgets(log_line, 1023, testcase) == NULL)
 
34
        {
 
35
                fprintf(stderr, "Could not read testcase.\n");
 
36
                fclose(testcase);
 
37
                return(1);
 
38
        }
 
39
 
 
40
        fclose(testcase);
 
41
 
 
42
        test = parse_record(log_line);
 
43
 
 
44
        if (test == NULL)
 
45
        {
 
46
                fprintf(stderr,"Parsing failed.\n");
 
47
                return(1);
 
48
        }
 
49
        ret = print_results(test);
 
50
        free_record(test);
 
51
        return ret;
 
52
}
 
53
 
 
54
int print_results(aa_log_record *record)
 
55
{
 
56
                printf("Event type: ");
 
57
                switch(record->event)
 
58
                {
 
59
                        case AA_RECORD_ERROR:
 
60
                        {
 
61
                                printf("AA_RECORD_ERROR\n");
 
62
                                break;
 
63
                        }
 
64
                        case AA_RECORD_INVALID:
 
65
                        {
 
66
                                printf("AA_RECORD_INVALID\n");
 
67
                                break;
 
68
                        }
 
69
                        case AA_RECORD_AUDIT:
 
70
                        {
 
71
                                printf("AA_RECORD_AUDIT\n");
 
72
                                break;
 
73
                        }
 
74
                        case AA_RECORD_ALLOWED:
 
75
                        {
 
76
                                printf("AA_RECORD_ALLOWED\n");
 
77
                                break;
 
78
                        }
 
79
                        case AA_RECORD_DENIED:
 
80
                        {
 
81
                                printf("AA_RECORD_DENIED\n");
 
82
                                break;
 
83
                        }
 
84
                        case AA_RECORD_HINT:
 
85
                        {
 
86
                                printf("AA_RECORD_HINT\n");
 
87
                                break;
 
88
                        }
 
89
                        case AA_RECORD_STATUS:
 
90
                        {
 
91
                                printf("AA_RECORD_STATUS\n");
 
92
                                break;
 
93
                        }
 
94
                        default:
 
95
                        {
 
96
                                printf("UNKNOWN EVENT TYPE\n");
 
97
                                break;
 
98
                        }
 
99
                }
 
100
                if (record->audit_id != NULL)
 
101
                {
 
102
                        printf("Audit ID: %s\n", record->audit_id);
 
103
                }
 
104
                if (record->operation != NULL)
 
105
                {
 
106
                        printf("Operation: %s\n", record->operation);
 
107
                }
 
108
                if (record->requested_mask != NULL)
 
109
                {
 
110
                        printf("Mask: %s\n", record->requested_mask);
 
111
                }
 
112
                if (record->denied_mask != NULL)
 
113
                {
 
114
                        printf("Denied Mask: %s\n", record->denied_mask);
 
115
                }
 
116
                if (record->fsuid != (unsigned long) -1)
 
117
                {
 
118
                        printf("fsuid: %ld\n", record->fsuid);
 
119
                }
 
120
                if (record->ouid != (unsigned long) -1)
 
121
                {
 
122
                        printf("ouid: %ld\n", record->ouid);
 
123
                }
 
124
                if (record->profile != NULL)
 
125
                {
 
126
                        printf("Profile: %s\n", record->profile);
 
127
                }
 
128
                if (record->name != NULL)
 
129
                {
 
130
                        printf("Name: %s\n", record->name);
 
131
                }
 
132
                if (record->comm != NULL)
 
133
                {
 
134
                        printf("Command: %s\n", record->comm);
 
135
                }
 
136
                if (record->name2 != NULL)
 
137
                {
 
138
                        printf("Name2: %s\n", record->name2);
 
139
                }
 
140
                if (record->namespace != NULL)
 
141
                {
 
142
                        printf("Namespace: %s\n", record->namespace);
 
143
                }
 
144
                if (record->attribute != NULL)
 
145
                {
 
146
                        printf("Attribute: %s\n", record->attribute);
 
147
                }
 
148
                if (record->task != 0)
 
149
                {
 
150
                        printf("Task: %ld\n", record->task);
 
151
                }
 
152
                if (record->parent != 0)
 
153
                {
 
154
                        printf("Parent: %ld\n", record->parent);
 
155
                }
 
156
                if (record->magic_token != 0)
 
157
                {
 
158
                        printf("Token: %lu\n", record->magic_token);
 
159
                }
 
160
                if (record->info != NULL)
 
161
                {
 
162
                        printf("Info: %s\n", record->info);
 
163
                }
 
164
                if (record->error_code)
 
165
                {
 
166
                        printf("ErrorCode: %d\n", record->error_code);
 
167
                }
 
168
                if (record->pid != 0)
 
169
                {
 
170
                        printf("PID: %ld\n", record->pid);
 
171
                }
 
172
                if (record->active_hat != NULL)
 
173
                {
 
174
                        printf("Active hat: %s\n", record->active_hat);
 
175
                }
 
176
                if (record->net_family != NULL)
 
177
                {
 
178
                        printf("Network family: %s\n", record->net_family);
 
179
                }
 
180
                if (record->net_sock_type != NULL)
 
181
                {
 
182
                        printf("Socket type: %s\n", record->net_sock_type);
 
183
                }
 
184
                if (record->net_protocol != NULL)
 
185
                {
 
186
                        printf("Protocol: %s\n", record->net_protocol);
 
187
                }
 
188
                printf("Epoch: %lu\n", record->epoch);
 
189
                printf("Audit subid: %u\n", record->audit_sub_id);
 
190
        return(0);
 
191
}