2013-02-08 01:45:26 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <ctype.h>
|
2015-03-04 01:21:27 +01:00
|
|
|
#include <endian.h>
|
2013-02-08 01:45:26 +01:00
|
|
|
#include <errno.h>
|
2014-04-29 01:39:04 +02:00
|
|
|
#include <limits.h>
|
2013-02-08 01:45:26 +01:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdlib.h>
|
2016-02-23 17:55:43 +01:00
|
|
|
#include <string.h>
|
2014-04-28 23:07:23 +02:00
|
|
|
#include <sys/prctl.h>
|
2014-04-03 18:55:26 +02:00
|
|
|
#include <sys/uio.h>
|
2014-09-28 23:41:50 +02:00
|
|
|
#include <syslog.h>
|
2013-02-08 01:45:26 +01:00
|
|
|
|
2016-11-03 18:29:23 +01:00
|
|
|
#include <android-base/macros.h>
|
2015-03-17 15:56:32 +01:00
|
|
|
#include <private/android_filesystem_config.h>
|
2015-03-04 01:21:27 +01:00
|
|
|
#include <private/android_logger.h>
|
|
|
|
|
2013-02-08 01:45:26 +01:00
|
|
|
#include "LogAudit.h"
|
2016-02-23 17:55:43 +01:00
|
|
|
#include "LogBuffer.h"
|
2014-10-15 17:49:39 +02:00
|
|
|
#include "LogKlog.h"
|
2016-02-23 17:55:43 +01:00
|
|
|
#include "LogReader.h"
|
2016-12-13 19:31:29 +01:00
|
|
|
#include "LogUtils.h"
|
2017-03-10 23:31:54 +01:00
|
|
|
#include "libaudit.h"
|
2013-02-08 01:45:26 +01:00
|
|
|
|
2017-03-10 23:31:54 +01:00
|
|
|
#define KMSG_PRIORITY(PRI) \
|
|
|
|
'<', '0' + LOG_MAKEPRI(LOG_AUTH, LOG_PRI(PRI)) / 10, \
|
|
|
|
'0' + LOG_MAKEPRI(LOG_AUTH, LOG_PRI(PRI)) % 10, '>'
|
|
|
|
|
|
|
|
LogAudit::LogAudit(LogBuffer* buf, LogReader* reader, int fdDmesg)
|
|
|
|
: SocketListener(mSock = getLogSocket(), false),
|
|
|
|
logbuf(buf),
|
|
|
|
reader(reader),
|
|
|
|
fdDmesg(fdDmesg),
|
|
|
|
main(__android_logger_property_get_bool("ro.logd.auditd.main",
|
|
|
|
BOOL_DEFAULT_TRUE)),
|
|
|
|
events(__android_logger_property_get_bool("ro.logd.auditd.events",
|
2016-12-30 00:16:06 +01:00
|
|
|
BOOL_DEFAULT_TRUE)),
|
2017-03-10 23:31:54 +01:00
|
|
|
initialized(false),
|
|
|
|
tooFast(false) {
|
2016-06-14 20:04:43 +02:00
|
|
|
static const char auditd_message[] = { KMSG_PRIORITY(LOG_INFO),
|
2017-03-10 23:31:54 +01:00
|
|
|
'l',
|
|
|
|
'o',
|
|
|
|
'g',
|
|
|
|
'd',
|
|
|
|
'.',
|
|
|
|
'a',
|
|
|
|
'u',
|
|
|
|
'd',
|
|
|
|
'i',
|
|
|
|
't',
|
|
|
|
'd',
|
|
|
|
':',
|
|
|
|
' ',
|
|
|
|
's',
|
|
|
|
't',
|
|
|
|
'a',
|
|
|
|
'r',
|
|
|
|
't',
|
|
|
|
'\n' };
|
2016-06-14 20:04:43 +02:00
|
|
|
write(fdDmesg, auditd_message, sizeof(auditd_message));
|
2013-02-08 01:45:26 +01:00
|
|
|
}
|
|
|
|
|
2017-01-03 23:00:19 +01:00
|
|
|
void LogAudit::checkRateLimit() {
|
|
|
|
// trim list for AUDIT_RATE_LIMIT_BURST_DURATION of history
|
|
|
|
log_time oldest(AUDIT_RATE_LIMIT_BURST_DURATION, 0);
|
|
|
|
bucket.emplace(android_log_clockid());
|
|
|
|
oldest = bucket.back() - oldest;
|
|
|
|
while (bucket.front() < oldest) bucket.pop();
|
|
|
|
|
|
|
|
static const size_t upperThreshold =
|
|
|
|
((AUDIT_RATE_LIMIT_BURST_DURATION *
|
2017-03-10 23:31:54 +01:00
|
|
|
(AUDIT_RATE_LIMIT_DEFAULT + AUDIT_RATE_LIMIT_MAX)) +
|
|
|
|
1) /
|
|
|
|
2;
|
2017-01-03 23:00:19 +01:00
|
|
|
if (bucket.size() >= upperThreshold) {
|
|
|
|
// Hit peak, slow down source
|
|
|
|
if (!tooFast) {
|
|
|
|
tooFast = true;
|
|
|
|
audit_rate_limit(mSock, AUDIT_RATE_LIMIT_MAX);
|
|
|
|
}
|
|
|
|
|
|
|
|
// We do not need to hold on to the full set of timing data history,
|
|
|
|
// let's ensure it does not grow without bounds. This also ensures
|
|
|
|
// that std::dequeue underneath behaves almost like a ring buffer.
|
|
|
|
do {
|
|
|
|
bucket.pop();
|
|
|
|
} while (bucket.size() >= upperThreshold);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!tooFast) return;
|
|
|
|
|
2017-03-10 23:31:54 +01:00
|
|
|
static const size_t lowerThreshold =
|
|
|
|
AUDIT_RATE_LIMIT_BURST_DURATION * AUDIT_RATE_LIMIT_MAX;
|
2017-01-03 23:00:19 +01:00
|
|
|
|
|
|
|
if (bucket.size() >= lowerThreshold) return;
|
|
|
|
|
|
|
|
tooFast = false;
|
|
|
|
// Went below max sustained rate, allow source to speed up
|
|
|
|
audit_rate_limit(mSock, AUDIT_RATE_LIMIT_DEFAULT);
|
|
|
|
}
|
|
|
|
|
2017-03-10 23:31:54 +01:00
|
|
|
bool LogAudit::onDataAvailable(SocketClient* cli) {
|
2014-10-13 18:59:37 +02:00
|
|
|
if (!initialized) {
|
|
|
|
prctl(PR_SET_NAME, "logd.auditd");
|
|
|
|
initialized = true;
|
|
|
|
}
|
2014-04-28 23:07:23 +02:00
|
|
|
|
2017-01-03 23:00:19 +01:00
|
|
|
checkRateLimit();
|
|
|
|
|
2013-02-08 01:45:26 +01:00
|
|
|
struct audit_message rep;
|
|
|
|
|
2014-04-29 01:39:04 +02:00
|
|
|
rep.nlh.nlmsg_type = 0;
|
|
|
|
rep.nlh.nlmsg_len = 0;
|
|
|
|
rep.data[0] = '\0';
|
|
|
|
|
2013-02-08 01:45:26 +01:00
|
|
|
if (audit_get_reply(cli->getSocket(), &rep, GET_REPLY_BLOCKING, 0) < 0) {
|
|
|
|
SLOGE("Failed on audit_get_reply with error: %s", strerror(errno));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-01-03 23:00:19 +01:00
|
|
|
logPrint("type=%d %.*s", rep.nlh.nlmsg_type, rep.nlh.nlmsg_len, rep.data);
|
2013-02-08 01:45:26 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-10 23:31:54 +01:00
|
|
|
int LogAudit::logPrint(const char* fmt, ...) {
|
2013-02-08 01:45:26 +01:00
|
|
|
if (fmt == NULL) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
va_list args;
|
|
|
|
|
2017-03-10 23:31:54 +01:00
|
|
|
char* str = NULL;
|
2013-02-08 01:45:26 +01:00
|
|
|
va_start(args, fmt);
|
|
|
|
int rc = vasprintf(&str, fmt, args);
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
if (rc < 0) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2017-03-10 23:31:54 +01:00
|
|
|
char* cp;
|
2017-01-03 19:35:34 +01:00
|
|
|
// Work around kernels missing
|
|
|
|
// https://github.com/torvalds/linux/commit/b8f89caafeb55fba75b74bea25adc4e4cd91be67
|
|
|
|
// Such kernels improperly add newlines inside audit messages.
|
|
|
|
while ((cp = strchr(str, '\n'))) {
|
|
|
|
*cp = ' ';
|
|
|
|
}
|
|
|
|
|
2014-05-27 19:06:34 +02:00
|
|
|
while ((cp = strstr(str, " "))) {
|
|
|
|
memmove(cp, cp + 1, strlen(cp + 1) + 1);
|
|
|
|
}
|
|
|
|
|
2016-06-14 20:04:43 +02:00
|
|
|
bool info = strstr(str, " permissive=1") || strstr(str, " policy loaded ");
|
2014-10-13 18:59:37 +02:00
|
|
|
if ((fdDmesg >= 0) && initialized) {
|
2014-09-19 20:59:42 +02:00
|
|
|
struct iovec iov[3];
|
2014-09-28 23:41:50 +02:00
|
|
|
static const char log_info[] = { KMSG_PRIORITY(LOG_INFO) };
|
|
|
|
static const char log_warning[] = { KMSG_PRIORITY(LOG_WARNING) };
|
2016-07-16 00:45:58 +02:00
|
|
|
static const char newline[] = "\n";
|
|
|
|
|
|
|
|
// Dedupe messages, checking for identical messages starting with avc:
|
|
|
|
static unsigned count;
|
2017-03-10 23:31:54 +01:00
|
|
|
static char* last_str;
|
2016-07-16 00:45:58 +02:00
|
|
|
static bool last_info;
|
|
|
|
|
|
|
|
if (last_str != NULL) {
|
|
|
|
static const char avc[] = "): avc: ";
|
2017-03-10 23:31:54 +01:00
|
|
|
char* avcl = strstr(last_str, avc);
|
2016-07-16 00:45:58 +02:00
|
|
|
bool skip = false;
|
|
|
|
|
|
|
|
if (avcl) {
|
2017-03-10 23:31:54 +01:00
|
|
|
char* avcr = strstr(str, avc);
|
2016-07-16 00:45:58 +02:00
|
|
|
|
2017-03-10 23:31:54 +01:00
|
|
|
skip = avcr &&
|
|
|
|
!fastcmp<strcmp>(avcl + strlen(avc), avcr + strlen(avc));
|
2016-07-16 00:45:58 +02:00
|
|
|
if (skip) {
|
|
|
|
++count;
|
|
|
|
free(last_str);
|
|
|
|
last_str = strdup(str);
|
|
|
|
last_info = info;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!skip) {
|
|
|
|
static const char resume[] = " duplicate messages suppressed\n";
|
|
|
|
|
2017-03-10 23:31:54 +01:00
|
|
|
iov[0].iov_base = last_info ? const_cast<char*>(log_info)
|
|
|
|
: const_cast<char*>(log_warning);
|
|
|
|
iov[0].iov_len =
|
|
|
|
last_info ? sizeof(log_info) : sizeof(log_warning);
|
2016-07-16 00:45:58 +02:00
|
|
|
iov[1].iov_base = last_str;
|
|
|
|
iov[1].iov_len = strlen(last_str);
|
|
|
|
if (count > 1) {
|
2017-03-10 23:31:54 +01:00
|
|
|
iov[2].iov_base = const_cast<char*>(resume);
|
2016-07-16 00:45:58 +02:00
|
|
|
iov[2].iov_len = strlen(resume);
|
|
|
|
} else {
|
2017-03-10 23:31:54 +01:00
|
|
|
iov[2].iov_base = const_cast<char*>(newline);
|
2016-07-16 00:45:58 +02:00
|
|
|
iov[2].iov_len = strlen(newline);
|
|
|
|
}
|
|
|
|
|
2016-11-03 18:29:23 +01:00
|
|
|
writev(fdDmesg, iov, arraysize(iov));
|
2016-07-16 00:45:58 +02:00
|
|
|
free(last_str);
|
|
|
|
last_str = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (last_str == NULL) {
|
|
|
|
count = 0;
|
|
|
|
last_str = strdup(str);
|
|
|
|
last_info = info;
|
|
|
|
}
|
|
|
|
if (count == 0) {
|
2017-03-10 23:31:54 +01:00
|
|
|
iov[0].iov_base = info ? const_cast<char*>(log_info)
|
|
|
|
: const_cast<char*>(log_warning);
|
|
|
|
iov[0].iov_len = info ? sizeof(log_info) : sizeof(log_warning);
|
2016-07-16 00:45:58 +02:00
|
|
|
iov[1].iov_base = str;
|
|
|
|
iov[1].iov_len = strlen(str);
|
2017-03-10 23:31:54 +01:00
|
|
|
iov[2].iov_base = const_cast<char*>(newline);
|
2016-07-16 00:45:58 +02:00
|
|
|
iov[2].iov_len = strlen(newline);
|
|
|
|
|
2016-11-03 18:29:23 +01:00
|
|
|
writev(fdDmesg, iov, arraysize(iov));
|
2016-07-16 00:45:58 +02:00
|
|
|
}
|
2014-04-03 18:55:26 +02:00
|
|
|
}
|
|
|
|
|
2016-12-30 00:16:06 +01:00
|
|
|
if (!main && !events) {
|
|
|
|
free(str);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-02-08 01:45:26 +01:00
|
|
|
pid_t pid = getpid();
|
|
|
|
pid_t tid = gettid();
|
2015-03-17 15:56:32 +01:00
|
|
|
uid_t uid = AID_LOGD;
|
2013-02-08 01:45:26 +01:00
|
|
|
log_time now;
|
|
|
|
|
|
|
|
static const char audit_str[] = " audit(";
|
2017-03-10 23:31:54 +01:00
|
|
|
char* timeptr = strstr(str, audit_str);
|
|
|
|
if (timeptr &&
|
|
|
|
((cp = now.strptime(timeptr + sizeof(audit_str) - 1, "%s.%q"))) &&
|
|
|
|
(*cp == ':')) {
|
2013-02-08 01:45:26 +01:00
|
|
|
memcpy(timeptr + sizeof(audit_str) - 1, "0.0", 3);
|
2014-05-27 19:06:34 +02:00
|
|
|
memmove(timeptr + sizeof(audit_str) - 1 + 3, cp, strlen(cp) + 1);
|
2015-09-08 17:56:32 +02:00
|
|
|
if (!isMonotonic()) {
|
|
|
|
if (android::isMonotonic(now)) {
|
|
|
|
LogKlog::convertMonotonicToReal(now);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!android::isMonotonic(now)) {
|
|
|
|
LogKlog::convertRealToMonotonic(now);
|
|
|
|
}
|
2014-10-15 17:49:39 +02:00
|
|
|
}
|
2015-09-08 17:56:32 +02:00
|
|
|
} else if (isMonotonic()) {
|
|
|
|
now = log_time(CLOCK_MONOTONIC);
|
2013-02-08 01:45:26 +01:00
|
|
|
} else {
|
2015-09-08 17:56:32 +02:00
|
|
|
now = log_time(CLOCK_REALTIME);
|
2013-02-08 01:45:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static const char pid_str[] = " pid=";
|
2017-03-10 23:31:54 +01:00
|
|
|
char* pidptr = strstr(str, pid_str);
|
2013-02-08 01:45:26 +01:00
|
|
|
if (pidptr && isdigit(pidptr[sizeof(pid_str) - 1])) {
|
|
|
|
cp = pidptr + sizeof(pid_str) - 1;
|
|
|
|
pid = 0;
|
|
|
|
while (isdigit(*cp)) {
|
|
|
|
pid = (pid * 10) + (*cp - '0');
|
|
|
|
++cp;
|
|
|
|
}
|
|
|
|
tid = pid;
|
2015-06-25 01:22:54 +02:00
|
|
|
logbuf->lock();
|
2013-02-08 01:45:26 +01:00
|
|
|
uid = logbuf->pidToUid(pid);
|
2015-06-25 01:22:54 +02:00
|
|
|
logbuf->unlock();
|
2014-05-27 19:06:34 +02:00
|
|
|
memmove(pidptr, cp, strlen(cp) + 1);
|
2013-02-08 01:45:26 +01:00
|
|
|
}
|
|
|
|
|
2014-05-27 19:06:34 +02:00
|
|
|
// log to events
|
|
|
|
|
2015-10-02 18:22:52 +02:00
|
|
|
size_t l = strnlen(str, LOGGER_ENTRY_MAX_PAYLOAD);
|
2015-03-04 01:21:27 +01:00
|
|
|
size_t n = l + sizeof(android_log_event_string_t);
|
2014-05-27 19:06:34 +02:00
|
|
|
|
|
|
|
bool notify = false;
|
2013-02-08 01:45:26 +01:00
|
|
|
|
2017-03-10 23:31:54 +01:00
|
|
|
if (events) { // begin scope for event buffer
|
2015-10-02 18:22:52 +02:00
|
|
|
uint32_t buffer[(n + sizeof(uint32_t) - 1) / sizeof(uint32_t)];
|
|
|
|
|
2017-03-10 23:31:54 +01:00
|
|
|
android_log_event_string_t* event =
|
|
|
|
reinterpret_cast<android_log_event_string_t*>(buffer);
|
2015-03-04 01:21:27 +01:00
|
|
|
event->header.tag = htole32(AUDITD_LOG_TAG);
|
logd: Don't embed a flexible array member within another struct
C (but not C++) has a concept of a flexible array member, which
is documented at https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html .
Using a flexible array member indicates that the structure is
really a header for a variable length object.
In logd's case, the variable length structure android_event_string_t
was embedded within another structure called
android_log_event_string_t. This makes gcc's __builtin_object_size()
function really confused. When compiling with C++,
__builtin_object_size(android_log_event_string_t.payload.data, 1)
would return 0, whereas if you compiled the code with C, the same
call would (properly) return -1.
Code which does automatic bounds checking, such as the proposed
patch at https://android-review.googlesource.com/145411 , will
cause problems for logd if this syntax is used.
Don't try to embed a variable length structure within another
structure. This doesn't appear to be valid C nor C++, and
while it's worked, it seems problematic.
Instead, inline the structure so it's one big happy structure.
Change-Id: I8ac02b7142a4f6560f5f80df2effcf720f9896fc
2015-04-07 10:25:43 +02:00
|
|
|
event->type = EVENT_TYPE_STRING;
|
|
|
|
event->length = htole32(l);
|
|
|
|
memcpy(event->data, str, l);
|
2015-03-04 01:21:27 +01:00
|
|
|
|
2015-02-09 17:21:05 +01:00
|
|
|
rc = logbuf->log(LOG_ID_EVENTS, now, uid, pid, tid,
|
2017-03-10 23:31:54 +01:00
|
|
|
reinterpret_cast<char*>(event),
|
|
|
|
(n <= USHRT_MAX) ? (unsigned short)n : USHRT_MAX);
|
2015-02-09 17:21:05 +01:00
|
|
|
if (rc >= 0) {
|
|
|
|
notify = true;
|
|
|
|
}
|
2015-10-02 18:22:52 +02:00
|
|
|
// end scope for event buffer
|
2014-05-27 19:06:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// log to main
|
|
|
|
|
|
|
|
static const char comm_str[] = " comm=\"";
|
2017-03-10 23:31:54 +01:00
|
|
|
const char* comm = strstr(str, comm_str);
|
|
|
|
const char* estr = str + strlen(str);
|
|
|
|
const char* commfree = NULL;
|
2014-05-27 19:06:34 +02:00
|
|
|
if (comm) {
|
|
|
|
estr = comm;
|
|
|
|
comm += sizeof(comm_str) - 1;
|
|
|
|
} else if (pid == getpid()) {
|
|
|
|
pid = tid;
|
|
|
|
comm = "auditd";
|
2015-06-25 01:22:54 +02:00
|
|
|
} else {
|
|
|
|
logbuf->lock();
|
|
|
|
comm = commfree = logbuf->pidToName(pid);
|
|
|
|
logbuf->unlock();
|
|
|
|
if (!comm) {
|
|
|
|
comm = "unknown";
|
|
|
|
}
|
2014-05-27 19:06:34 +02:00
|
|
|
}
|
|
|
|
|
2017-03-10 23:31:54 +01:00
|
|
|
const char* ecomm = strchr(comm, '"');
|
2014-05-27 19:06:34 +02:00
|
|
|
if (ecomm) {
|
|
|
|
++ecomm;
|
|
|
|
l = ecomm - comm;
|
|
|
|
} else {
|
|
|
|
l = strlen(comm) + 1;
|
|
|
|
ecomm = "";
|
|
|
|
}
|
2015-10-02 18:22:52 +02:00
|
|
|
size_t b = estr - str;
|
|
|
|
if (b > LOGGER_ENTRY_MAX_PAYLOAD) {
|
|
|
|
b = LOGGER_ENTRY_MAX_PAYLOAD;
|
|
|
|
}
|
|
|
|
size_t e = strnlen(ecomm, LOGGER_ENTRY_MAX_PAYLOAD - b);
|
|
|
|
n = b + e + l + 2;
|
|
|
|
|
2017-03-10 23:31:54 +01:00
|
|
|
if (main) { // begin scope for main buffer
|
2015-10-02 18:22:52 +02:00
|
|
|
char newstr[n];
|
2014-05-27 19:06:34 +02:00
|
|
|
|
2014-09-19 20:59:42 +02:00
|
|
|
*newstr = info ? ANDROID_LOG_INFO : ANDROID_LOG_WARN;
|
2014-05-27 19:06:34 +02:00
|
|
|
strlcpy(newstr + 1, comm, l);
|
2015-10-02 18:22:52 +02:00
|
|
|
strncpy(newstr + 1 + l, str, b);
|
|
|
|
strncpy(newstr + 1 + l + b, ecomm, e);
|
2014-05-27 19:06:34 +02:00
|
|
|
|
2015-02-09 17:21:05 +01:00
|
|
|
rc = logbuf->log(LOG_ID_MAIN, now, uid, pid, tid, newstr,
|
2017-03-10 23:31:54 +01:00
|
|
|
(n <= USHRT_MAX) ? (unsigned short)n : USHRT_MAX);
|
2014-05-27 19:06:34 +02:00
|
|
|
|
2015-02-09 17:21:05 +01:00
|
|
|
if (rc >= 0) {
|
|
|
|
notify = true;
|
|
|
|
}
|
2015-10-02 18:22:52 +02:00
|
|
|
// end scope for main buffer
|
2014-05-27 19:06:34 +02:00
|
|
|
}
|
2013-02-08 01:45:26 +01:00
|
|
|
|
2017-03-10 23:31:54 +01:00
|
|
|
free(const_cast<char*>(commfree));
|
2014-05-27 19:06:34 +02:00
|
|
|
free(str);
|
2013-02-08 01:45:26 +01:00
|
|
|
|
2014-05-27 19:06:34 +02:00
|
|
|
if (notify) {
|
|
|
|
reader->notifyNewLog();
|
2015-02-09 17:21:05 +01:00
|
|
|
if (rc < 0) {
|
|
|
|
rc = n;
|
|
|
|
}
|
2014-05-27 19:06:34 +02:00
|
|
|
}
|
2013-02-08 01:45:26 +01:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2017-03-10 23:31:54 +01:00
|
|
|
int LogAudit::log(char* buf, size_t len) {
|
|
|
|
char* audit = strstr(buf, " audit(");
|
2015-09-04 20:37:42 +02:00
|
|
|
if (!audit || (audit >= &buf[len])) {
|
2014-10-15 17:49:39 +02:00
|
|
|
return 0;
|
2013-02-08 01:45:26 +01:00
|
|
|
}
|
|
|
|
|
2014-10-13 18:59:37 +02:00
|
|
|
*audit = '\0';
|
2013-02-08 01:45:26 +01:00
|
|
|
|
2014-10-13 18:59:37 +02:00
|
|
|
int rc;
|
2017-03-10 23:31:54 +01:00
|
|
|
char* type = strstr(buf, "type=");
|
2015-09-04 20:37:42 +02:00
|
|
|
if (type && (type < &buf[len])) {
|
2014-10-13 18:59:37 +02:00
|
|
|
rc = logPrint("%s %s", type, audit + 1);
|
|
|
|
} else {
|
|
|
|
rc = logPrint("%s", audit + 1);
|
2013-02-08 01:45:26 +01:00
|
|
|
}
|
2014-10-13 18:59:37 +02:00
|
|
|
*audit = ' ';
|
|
|
|
return rc;
|
2013-02-08 01:45:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int LogAudit::getLogSocket() {
|
|
|
|
int fd = audit_open();
|
|
|
|
if (fd < 0) {
|
|
|
|
return fd;
|
|
|
|
}
|
2014-11-19 22:33:22 +01:00
|
|
|
if (audit_setup(fd, getpid()) < 0) {
|
2013-02-08 01:45:26 +01:00
|
|
|
audit_close(fd);
|
|
|
|
fd = -1;
|
|
|
|
}
|
2017-01-03 23:00:19 +01:00
|
|
|
(void)audit_rate_limit(fd, AUDIT_RATE_LIMIT_DEFAULT);
|
2013-02-08 01:45:26 +01:00
|
|
|
return fd;
|
|
|
|
}
|