[systemd-devel] [PATCH 1/3] journal: add int↔audit type name mapping

Zbigniew Jędrzejewski-Szmek zbyszek at in.waw.pl
Tue Apr 14 18:58:32 PDT 2015


---
 Makefile.am              | 23 +++++++++++++++++++++--
 src/journal/.gitignore   |  4 ++++
 src/journal/audit-type.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 src/journal/audit-type.h | 26 ++++++++++++++++++++++++++
 4 files changed, 93 insertions(+), 2 deletions(-)
 create mode 100644 src/journal/audit-type.c
 create mode 100644 src/journal/audit-type.h

diff --git Makefile.am Makefile.am
index 72a2c3c220..4c8812bba0 100644
--- Makefile.am
+++ Makefile.am
@@ -215,6 +215,7 @@ AM_CPPFLAGS = \
 	-I $(top_srcdir)/src/network \
 	-I $(top_srcdir)/src/login \
 	-I $(top_srcdir)/src/journal \
+	-I $(top_builddir)/src/journal \
 	-I $(top_srcdir)/src/timedate \
 	-I $(top_srcdir)/src/timesync \
 	-I $(top_srcdir)/src/resolve \
@@ -1311,12 +1312,23 @@ src/shared/cap-from-name.h: src/shared/cap-from-name.gperf
 	$(AM_V_GPERF)$(GPERF) -L ANSI-C -t --ignore-case -N lookup_capability -H hash_capability_name -p -C <$< >$@
 
 
+src/journal/audit_type-list.txt:
+	$(AM_V_at)$(MKDIR_P) $(dir $@)
+	$(AM_V_GEN)$(CPP) $(CFLAGS) $(AM_CPPFLAGS) $(CPPFLAGS) -dM -include linux/audit.h - </dev/null | grep -vE 'AUDIT_(FIRST|LAST)_.*MSG' | $(SED) -r -n 's/^#define\s+AUDIT_(\w+)\s+([0-9]{4})\s*$$/\1\t\2/p' | sort -k2 >$@
+
+src/journal/audit_type-to-name.h: src/journal/audit_type-list.txt
+	$(AM_V_GEN)$(AWK) 'BEGIN{ print "const char *audit_type_to_string(int type) {\n\tswitch(type) {" } {printf "        case AUDIT_%s: return \"%s\";\n", $$1, $$1 } END{ print "        default: return NULL;\n\t}\n}\n" }' <$< >$@
+
+src/journal/audit_type-from-name.gperf: src/journal/audit_type-list.txt
+	$(AM_V_GEN)$(AWK) 'BEGIN{ print "struct audit_type_name { const char* name; int id; };"; print "%null-strings"; print "%%";} { s=$$1; sub(/_/, "-", s); printf "%s, ", $$s; printf "AUDIT_%s\n", $$1 }' <$< >$@
+
+
 src/resolve/dns_type-list.txt: src/resolve/dns-type.h
 	$(AM_V_at)$(MKDIR_P) $(dir $@)
 	$(AM_V_GEN)$(SED) -n -r 's/.* DNS_TYPE_(\w+).*/\1/p' <$< >$@
 
 src/resolve/dns_type-to-name.h: src/resolve/dns_type-list.txt
-	$(AM_V_GEN)$(AWK) 'BEGIN{ print "const char *dns_type_to_string(int type) {\n\tswitch(type) {" } {printf "        case DNS_TYPE_%s: return ", $$1; sub(/_/, "-"); printf "\"%s\";\n", $$1 } END{ print "\ndefault: return NULL;\n\t}\n}\n" }' <$< >$@
+	$(AM_V_GEN)$(AWK) 'BEGIN{ print "const char *dns_type_to_string(int type) {\n\tswitch(type) {" } {printf "        case DNS_TYPE_%s: return ", $$1; sub(/_/, "-"); printf "\"%s\";\n", $$1 } END{ print "        default: return NULL;\n\t}\n}\n" }' <$< >$@
 
 src/resolve/dns_type-from-name.gperf: src/resolve/dns_type-list.txt
 	$(AM_V_GEN)$(AWK) 'BEGIN{ print "struct dns_type_name { const char* name; int id; };"; print "%null-strings"; print "%%";} { s=$$1; sub(/_/, "-", s); printf "%s, ", $$s; printf "DNS_TYPE_%s\n", $$1 }' <$< >$@
@@ -4629,7 +4641,14 @@ libsystemd_journal_internal_la_SOURCES = \
 	src/journal/catalog.h \
 	src/journal/mmap-cache.c \
 	src/journal/mmap-cache.h \
-	src/journal/compress.c
+	src/journal/compress.c \
+	src/journal/audit-type.h \
+	src/journal/audit-type.c \
+	src/journal/audit_type-from-name.h \
+	src/journal/audit_type-to-name.h
+
+gperf_txt_sources += \
+	src/journal/audit_type-list.txt
 
 # using _CFLAGS = in the conditional below would suppress AM_CFLAGS
 libsystemd_journal_internal_la_CFLAGS = \
diff --git src/journal/.gitignore src/journal/.gitignore
index d6a79460cd..9488fcd0ff 100644
--- src/journal/.gitignore
+++ src/journal/.gitignore
@@ -1,2 +1,6 @@
 /journald-gperf.c
 /libsystemd-journal.pc
+/audit_type-list.txt
+/audit_type-from-name.h
+/audit_type-from-name.gperf
+/audit_type-to-name.h
diff --git src/journal/audit-type.c src/journal/audit-type.c
new file mode 100644
index 0000000000..9e6d4cb76b
--- /dev/null
+++ src/journal/audit-type.c
@@ -0,0 +1,42 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+  This file is part of systemd.
+
+  Copyright 2015 Zbigniew Jędrzejewski-Szmek
+
+  systemd is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Lesser General Public License as published by
+  the Free Software Foundation; either version 2.1 of the License, or
+  (at your option) any later version.
+
+  systemd is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include <linux/audit.h>
+
+#include "audit-type.h"
+
+static const struct audit_type_name *
+lookup_audit_type(register const char *str, register unsigned int len);
+
+#include "audit_type-from-name.h"
+#include "audit_type-to-name.h"
+
+int audit_type_from_string(const char *s) {
+        const struct audit_type_name *sc;
+
+        assert(s);
+
+        sc = lookup_audit_type(s, strlen(s));
+        if (!sc)
+                return -EINVAL;
+
+        return sc->id;
+}
diff --git src/journal/audit-type.h src/journal/audit-type.h
new file mode 100644
index 0000000000..9f37716cd6
--- /dev/null
+++ src/journal/audit-type.h
@@ -0,0 +1,26 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+#pragma once
+
+/***
+  This file is part of systemd.
+
+  Copyright 2015 Zbigniew Jędrzejewski-Szmek
+
+  systemd is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Lesser General Public License as published by
+  the Free Software Foundation; either version 2.1 of the License, or
+  (at your option) any later version.
+
+  systemd is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+
+const char *audit_type_to_string(int type);
+int audit_type_from_string(const char *s);
-- 
2.3.5



More information about the systemd-devel mailing list