journald-audit.c revision cd556b6ca8aec8dd371806afedec45f852f8f724
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering This file is part of systemd.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Copyright 2014 Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering systemd is free software; you can redistribute it and/or modify it
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering under the terms of the GNU Lesser General Public License as published by
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering (at your option) any later version.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering systemd is distributed in the hope that it will be useful, but
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Lesser General Public License for more details.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering You should have received a copy of the GNU Lesser General Public License
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringtypedef struct MapField {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering int (*map)(const char *field, const char **p, struct iovec **iov, size_t *n_iov_allocated, unsigned *n_iov);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poetteringstatic int map_simple_field(const char *field, const char **p, struct iovec **iov, size_t *n_iov_allocated, unsigned *n_iov) {
39d8db043b599a7382f94bfc904d5e108af438bdLennart Poettering const char *e;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering for (e = *p; *e != ' ' && *e != 0; e++) {
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering if (!GREEDY_REALLOC(*iov, *n_iov_allocated, *n_iov + 1))
ad867662936a4c7ab2c7116d804c272338801231Lennart Poetteringstatic int map_string_field_internal(const char *field, const char **p, struct iovec **iov, size_t *n_iov_allocated, unsigned *n_iov, bool filter_printable) {
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering const char *s, *e;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering /* The kernel formats string fields in one of two formats. */
dc4d47e2c79aafa3ef646e32ff3422c4ce935c1bLennart Poettering if (**p == '"') {
return -ENOMEM;
} else if (unhexchar(**p) >= 0) {
return -ENOMEM;
uint8_t x;
a = unhexchar(e[0]);
return -ENOMEM;
return -ENOMEM;
(*n_iov) ++;
c = NULL;
static int map_string_field(const char *field, const char **p, struct iovec **iov, size_t *n_iov_allocated, unsigned *n_iov) {
static int map_string_field_printable(const char *field, const char **p, struct iovec **iov, size_t *n_iov_allocated, unsigned *n_iov) {
static int map_generic_field(const char *prefix, const char **p, struct iovec **iov, size_t *n_iov_allocated, unsigned *n_iov) {
static int map_all_fields(
const char *prefix,
bool handle_msg,
unsigned *n_iov) {
assert(p);
bool mapped = false;
const MapField *m;
if (handle_msg) {
c = strndupa(v, e - v);
mapped = true;
if (!mapped) {
unsigned n_iov = 0, k;
assert(s);
if (size <= 0)
if (!data)
&seconds,
&msec,
&id,
if (isempty(p))
if (!iov) {
log_oom();
z = n_iov;
log_oom();
goto finish;
for (; z < n_iov; z++)
Server *s,
const void *buffer,
assert(s);
if (!sa ||
process_audit_string(s, nl->nlmsg_type, NLMSG_DATA(nl), nl->nlmsg_len - ALIGN(sizeof(struct nlmsghdr)));
ssize_t n;
return -errno;
return -EIO;
if (s->audit_fd < 0) {
if (s->audit_fd < 0) {
r = sd_event_add_io(s->event, &s->audit_event_source, s->audit_fd, EPOLLIN, server_process_datagram, s);