2
* Copyright (c) 1999-2008 NOVELL (All rights reserved)
3
* Copyright 2009-2010 Canonical Ltd.
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of version 2.1 of the GNU Lesser General
7
* Public License published by the Free Software Foundation.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU Lesser General Public License for more details.
14
* You should have received a copy of the GNU Lesser General Public License
15
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19
* @author Matt Barringer <mbarringer@suse.de>
25
* - Convert the text permission mask into a bitmask
26
* - Clean up parser grammar
33
#include <netinet/in.h>
34
#include "aalogparse.h"
37
/* This is mostly just a wrapper around the code in grammar.y */
38
aa_log_record *parse_record(char *str)
43
return _parse_yacc(str);
46
void free_record(aa_log_record *record)
50
if (record->operation != NULL)
51
free(record->operation);
52
if (record->requested_mask != NULL)
53
free(record->requested_mask);
54
if (record->denied_mask != NULL)
55
free(record->denied_mask);
56
if (record->profile != NULL)
57
free(record->profile);
58
if (record->comm != NULL)
60
if (record->name != NULL)
62
if (record->name2 != NULL)
64
if (record->namespace != NULL)
65
free(record->namespace);
66
if (record->attribute != NULL)
67
free(record->attribute);
68
if (record->info != NULL)
70
if (record->active_hat != NULL)
71
free(record->active_hat);
72
if (record->audit_id != NULL)
73
free(record->audit_id);
74
if (record->net_family != NULL)
75
free(record->net_family);
76
if (record->net_protocol != NULL)
77
free(record->net_protocol);
78
if (record->net_sock_type != NULL)
79
free(record->net_sock_type);
86
/* Set all of the fields to appropriate values */
87
void _init_log_record(aa_log_record *record)
92
memset(record, 0, sizeof(aa_log_record));
94
record->version = AA_RECORD_SYNTAX_UNKNOWN;
95
record->event = AA_RECORD_INVALID;
96
record->fsuid = (unsigned long) -1;
97
record->ouid = (unsigned long) -1;
102
/* convert a hex-encoded string to its char* version */
103
char *hex_to_string(char *hexstring)
106
char buf[3], *endptr;
113
len = strlen(hexstring) / 2;
114
ret = malloc(len + 1);
118
for (i = 0; i < len; i++) {
119
sprintf(buf, "%.2s", hexstring);
121
ret[i] = (unsigned char) strtoul(buf, &endptr, 16);
129
struct ipproto_pairs {
130
unsigned int protocol;
134
#define AA_GEN_PROTO_ENT(name, IP) {name, IP},
136
static struct ipproto_pairs ipproto_mappings[] = {
137
#include "af_protos.h"
142
/* convert an ip protocol number to a string */
143
char *ipproto_to_string(unsigned int proto)
146
struct ipproto_pairs *current = ipproto_mappings;
148
while (current->protocol != proto && current->protocol_name != NULL) {
152
if (current->protocol_name) {
153
ret = strdup(current->protocol_name);
155
if (!asprintf(&ret, "unknown(%u)", proto))