X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fjournal%2Fjournald-audit.c;h=341d74815d5826116ef16b355e00a3695c375c62;hp=520d1cbb31186be895bb60c06b5f9618ef6de6ab;hb=124aff6251c095367ce1323a21fa23235cbb0490;hpb=5034c7bcdfc4493ed3c30722e9d897c8da78fede diff --git a/src/journal/journald-audit.c b/src/journal/journald-audit.c index 520d1cbb3..341d74815 100644 --- a/src/journal/journald-audit.c +++ b/src/journal/journald-audit.c @@ -172,7 +172,7 @@ static int map_generic_field(const char *prefix, const char **p, struct iovec ** if (!((*e >= 'a' && *e <= 'z') || (*e >= 'A' && *e <= 'Z') || (*e >= '0' && *e <= '9') || - (*e == '_'))) + *e == '_' || *e == '-')) return 0; } @@ -182,8 +182,18 @@ static int map_generic_field(const char *prefix, const char **p, struct iovec ** c = alloca(strlen(prefix) + (e - *p) + 2); t = stpcpy(c, prefix); - for (f = *p; f < e; f++) - *(t++) = *f >= 'a' && *f <= 'z' ? ((*f - 'a') + 'A') : *f; + for (f = *p; f < e; f++) { + char x; + + if (*f >= 'a' && *f <= 'z') + x = (*f - 'a') + 'A'; /* uppercase */ + else if (*f == '-') + x = '_'; /* dashes → underscores */ + else + x = *f; + + *(t++) = x; + } strcpy(t, "="); e ++; @@ -325,7 +335,7 @@ static int map_all_fields( } } -static void process_audit_string(Server *s, int type, const char *data, size_t size, const struct timeval *tv) { +static void process_audit_string(Server *s, int type, const char *data, size_t size) { _cleanup_free_ struct iovec *iov = NULL; size_t n_iov_allocated = 0; unsigned n_iov = 0, k; @@ -335,7 +345,7 @@ static void process_audit_string(Server *s, int type, const char *data, size_t s char id_field[sizeof("_AUDIT_ID=") + DECIMAL_STR_MAX(uint64_t)], type_field[sizeof("_AUDIT_TYPE=") + DECIMAL_STR_MAX(int)], source_time_field[sizeof("_SOURCE_REALTIME_TIMESTAMP=") + DECIMAL_STR_MAX(usec_t)]; - const char *m; + char *m; assert(s); @@ -386,7 +396,8 @@ static void process_audit_string(Server *s, int type, const char *data, size_t s sprintf(id_field, "_AUDIT_ID=%" PRIu64, id); IOVEC_SET_STRING(iov[n_iov++], id_field); - m = strappenda("MESSAGE=audit: ", p); + m = alloca(strlen("MESSAGE= ") + strlen(p) + 1); + sprintf(m, "MESSAGE= %s", type, p); IOVEC_SET_STRING(iov[n_iov++], m); z = n_iov; @@ -398,7 +409,7 @@ static void process_audit_string(Server *s, int type, const char *data, size_t s goto finish; } - server_dispatch_message(s, iov, n_iov, n_iov_allocated, NULL, tv, NULL, 0, NULL, LOG_NOTICE, 0); + server_dispatch_message(s, iov, n_iov, n_iov_allocated, NULL, NULL, NULL, 0, NULL, LOG_NOTICE, 0); finish: /* free() all entries that map_all_fields() added. All others @@ -413,7 +424,6 @@ void server_process_audit_message( const void *buffer, size_t buffer_size, const struct ucred *ucred, - const struct timeval *tv, const union sockaddr_union *sa, socklen_t salen) { @@ -453,7 +463,7 @@ void server_process_audit_message( if (nl->nlmsg_type < AUDIT_FIRST_USER_MSG) return; - process_audit_string(s, nl->nlmsg_type, NLMSG_DATA(nl), nl->nlmsg_len - ALIGN(sizeof(struct nlmsghdr)), tv); + process_audit_string(s, nl->nlmsg_type, NLMSG_DATA(nl), nl->nlmsg_len - ALIGN(sizeof(struct nlmsghdr))); } static int enable_audit(int fd, bool b) {