blob: 5a375ec1c985f8d411f2dcd0d83c98c621579079 [file] [log] [blame]
William Roberts29d238d2013-02-08 09:45:26 +09001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <ctype.h>
Mark Salyzyn29eb5702015-03-03 16:21:27 -080018#include <endian.h>
William Roberts29d238d2013-02-08 09:45:26 +090019#include <errno.h>
Mark Salyzyne0fa2912014-04-28 16:39:04 -070020#include <limits.h>
William Roberts29d238d2013-02-08 09:45:26 +090021#include <stdarg.h>
Chih-Hung Hsieh08d470b2018-08-13 14:22:56 -070022#include <stdint.h>
William Roberts29d238d2013-02-08 09:45:26 +090023#include <stdlib.h>
Mark Salyzyn317bfb92016-02-23 08:55:43 -080024#include <string.h>
Mark Salyzyn8daa9af2014-04-28 14:07:23 -070025#include <sys/prctl.h>
Mark Salyzyne9bebd02014-04-03 09:55:26 -070026#include <sys/uio.h>
Mark Salyzyn7ee2aef2014-09-28 14:41:50 -070027#include <syslog.h>
William Roberts29d238d2013-02-08 09:45:26 +090028
Max Bires4214d132017-08-15 11:07:49 -070029#include <fstream>
30#include <sstream>
31
Mark Salyzync8d31942016-11-03 10:29:23 -070032#include <android-base/macros.h>
Max Bires4214d132017-08-15 11:07:49 -070033#include <log/log_properties.h>
Mark Salyzyne3aeeee2015-03-17 07:56:32 -070034#include <private/android_filesystem_config.h>
Mark Salyzyn29eb5702015-03-03 16:21:27 -080035#include <private/android_logger.h>
36
William Roberts29d238d2013-02-08 09:45:26 +090037#include "LogAudit.h"
Mark Salyzyn317bfb92016-02-23 08:55:43 -080038#include "LogBuffer.h"
Mark Salyzynae4d9282014-10-15 08:49:39 -070039#include "LogKlog.h"
Mark Salyzyn317bfb92016-02-23 08:55:43 -080040#include "LogReader.h"
Mark Salyzyna2c02222016-12-13 10:31:29 -080041#include "LogUtils.h"
Mark Salyzyn501c3732017-03-10 14:31:54 -080042#include "libaudit.h"
William Roberts29d238d2013-02-08 09:45:26 +090043
Mark Salyzyn501c3732017-03-10 14:31:54 -080044#define KMSG_PRIORITY(PRI) \
45 '<', '0' + LOG_MAKEPRI(LOG_AUTH, LOG_PRI(PRI)) / 10, \
46 '0' + LOG_MAKEPRI(LOG_AUTH, LOG_PRI(PRI)) % 10, '>'
Mark Salyzyn7ee2aef2014-09-28 14:41:50 -070047
Mark Salyzyn501c3732017-03-10 14:31:54 -080048LogAudit::LogAudit(LogBuffer* buf, LogReader* reader, int fdDmesg)
Jeff Vander Stoep54c7a5f2018-01-03 11:04:26 -080049 : SocketListener(getLogSocket(), false),
Mark Salyzyn501c3732017-03-10 14:31:54 -080050 logbuf(buf),
51 reader(reader),
52 fdDmesg(fdDmesg),
53 main(__android_logger_property_get_bool("ro.logd.auditd.main",
54 BOOL_DEFAULT_TRUE)),
55 events(__android_logger_property_get_bool("ro.logd.auditd.events",
Mark Salyzynce80da32016-12-29 15:16:06 -080056 BOOL_DEFAULT_TRUE)),
Jeff Vander Stoep54c7a5f2018-01-03 11:04:26 -080057 initialized(false) {
Sami Tolvanena742d102016-06-14 18:04:43 +000058 static const char auditd_message[] = { KMSG_PRIORITY(LOG_INFO),
Mark Salyzyn501c3732017-03-10 14:31:54 -080059 'l',
60 'o',
61 'g',
62 'd',
63 '.',
64 'a',
65 'u',
66 'd',
67 'i',
68 't',
69 'd',
70 ':',
71 ' ',
72 's',
73 't',
74 'a',
75 'r',
76 't',
77 '\n' };
Sami Tolvanena742d102016-06-14 18:04:43 +000078 write(fdDmesg, auditd_message, sizeof(auditd_message));
William Roberts29d238d2013-02-08 09:45:26 +090079}
80
Mark Salyzyn501c3732017-03-10 14:31:54 -080081bool LogAudit::onDataAvailable(SocketClient* cli) {
Mark Salyzyneb06de72014-10-13 09:59:37 -070082 if (!initialized) {
83 prctl(PR_SET_NAME, "logd.auditd");
84 initialized = true;
85 }
Mark Salyzyn8daa9af2014-04-28 14:07:23 -070086
William Roberts29d238d2013-02-08 09:45:26 +090087 struct audit_message rep;
88
Mark Salyzyne0fa2912014-04-28 16:39:04 -070089 rep.nlh.nlmsg_type = 0;
90 rep.nlh.nlmsg_len = 0;
91 rep.data[0] = '\0';
92
William Roberts29d238d2013-02-08 09:45:26 +090093 if (audit_get_reply(cli->getSocket(), &rep, GET_REPLY_BLOCKING, 0) < 0) {
94 SLOGE("Failed on audit_get_reply with error: %s", strerror(errno));
95 return false;
96 }
97
Mark Salyzyn247d6822017-01-03 14:00:19 -080098 logPrint("type=%d %.*s", rep.nlh.nlmsg_type, rep.nlh.nlmsg_len, rep.data);
William Roberts29d238d2013-02-08 09:45:26 +090099
100 return true;
101}
102
Max Bires4214d132017-08-15 11:07:49 -0700103static inline bool hasMetadata(char* str, int str_len) {
104 // need to check and see if str already contains bug metadata from
105 // possibility of stuttering if log audit crashes and then reloads kernel
106 // messages. Kernel denials that contain metadata will either end in
107 // "b/[0-9]+$" or "b/[0-9]+ duplicate messages suppressed$" which will put
108 // a '/' character at either 9 or 39 indices away from the end of the str.
109 return str_len >= 39 &&
110 (str[str_len - 9] == '/' || str[str_len - 39] == '/');
111}
112
113std::map<std::string, std::string> LogAudit::populateDenialMap() {
Tri Vo57b2e8c2019-01-23 09:58:35 -0800114 std::ifstream bug_file("/vendor/etc/selinux/selinux_denial_metadata");
Max Bires4214d132017-08-15 11:07:49 -0700115 std::string line;
Jeff Vander Stoepd8858902018-05-03 14:57:39 -0700116 // allocate a map for the static map pointer in auditParse to keep track of,
Max Bires4214d132017-08-15 11:07:49 -0700117 // this function only runs once
118 std::map<std::string, std::string> denial_to_bug;
119 if (bug_file.good()) {
120 std::string scontext;
121 std::string tcontext;
122 std::string tclass;
123 std::string bug_num;
124 while (std::getline(bug_file, line)) {
125 std::stringstream split_line(line);
126 split_line >> scontext >> tcontext >> tclass >> bug_num;
127 denial_to_bug.emplace(scontext + tcontext + tclass, bug_num);
128 }
129 }
130 return denial_to_bug;
131}
132
133std::string LogAudit::denialParse(const std::string& denial, char terminator,
134 const std::string& search_term) {
135 size_t start_index = denial.find(search_term);
136 if (start_index != std::string::npos) {
137 start_index += search_term.length();
138 return denial.substr(
139 start_index, denial.find(terminator, start_index) - start_index);
140 }
141 return "";
142}
143
Jeff Vander Stoepd8858902018-05-03 14:57:39 -0700144void LogAudit::auditParse(const std::string& string, uid_t uid,
145 std::string* bug_num) {
Max Bires4214d132017-08-15 11:07:49 -0700146 if (!__android_log_is_debuggable()) {
147 bug_num->assign("");
148 return;
149 }
150 static std::map<std::string, std::string> denial_to_bug =
151 populateDenialMap();
152 std::string scontext = denialParse(string, ':', "scontext=u:object_r:");
153 std::string tcontext = denialParse(string, ':', "tcontext=u:object_r:");
154 std::string tclass = denialParse(string, ' ', "tclass=");
155 if (scontext.empty()) {
156 scontext = denialParse(string, ':', "scontext=u:r:");
157 }
158 if (tcontext.empty()) {
159 tcontext = denialParse(string, ':', "tcontext=u:r:");
160 }
161 auto search = denial_to_bug.find(scontext + tcontext + tclass);
162 if (search != denial_to_bug.end()) {
163 bug_num->assign(" b/" + search->second);
164 } else {
165 bug_num->assign("");
166 }
Jeff Vander Stoepd8858902018-05-03 14:57:39 -0700167
Dan Austinb43eb942018-11-27 07:30:11 -0800168 // Ensure the uid name is not null before passing it to the bug string.
Jeff Vander Stoepd8858902018-05-03 14:57:39 -0700169 if (uid >= AID_APP_START && uid <= AID_APP_END) {
Dan Austinb43eb942018-11-27 07:30:11 -0800170 char* uidname = android::uidToName(uid);
171 if (uidname) {
172 bug_num->append(" app=");
173 bug_num->append(uidname);
174 free(uidname);
175 }
Jeff Vander Stoepd8858902018-05-03 14:57:39 -0700176 }
Max Bires4214d132017-08-15 11:07:49 -0700177}
178
Mark Salyzyn501c3732017-03-10 14:31:54 -0800179int LogAudit::logPrint(const char* fmt, ...) {
Yi Kongc8d09dd2018-07-13 17:39:22 -0700180 if (fmt == nullptr) {
William Roberts29d238d2013-02-08 09:45:26 +0900181 return -EINVAL;
182 }
183
184 va_list args;
185
Yi Kongc8d09dd2018-07-13 17:39:22 -0700186 char* str = nullptr;
William Roberts29d238d2013-02-08 09:45:26 +0900187 va_start(args, fmt);
188 int rc = vasprintf(&str, fmt, args);
189 va_end(args);
190
191 if (rc < 0) {
192 return rc;
193 }
Mark Salyzyn501c3732017-03-10 14:31:54 -0800194 char* cp;
Nick Kralevich2e588672017-01-03 10:35:34 -0800195 // Work around kernels missing
196 // https://github.com/torvalds/linux/commit/b8f89caafeb55fba75b74bea25adc4e4cd91be67
197 // Such kernels improperly add newlines inside audit messages.
198 while ((cp = strchr(str, '\n'))) {
199 *cp = ' ';
200 }
201
Mark Salyzyne4369d62014-05-27 10:06:34 -0700202 while ((cp = strstr(str, " "))) {
203 memmove(cp, cp + 1, strlen(cp + 1) + 1);
204 }
Jeff Vander Stoepd8858902018-05-03 14:57:39 -0700205 pid_t pid = getpid();
206 pid_t tid = gettid();
207 uid_t uid = AID_LOGD;
208 static const char pid_str[] = " pid=";
209 char* pidptr = strstr(str, pid_str);
210 if (pidptr && isdigit(pidptr[sizeof(pid_str) - 1])) {
211 cp = pidptr + sizeof(pid_str) - 1;
212 pid = 0;
213 while (isdigit(*cp)) {
214 pid = (pid * 10) + (*cp - '0');
215 ++cp;
216 }
217 tid = pid;
218 logbuf->wrlock();
219 uid = logbuf->pidToUid(pid);
220 logbuf->unlock();
221 memmove(pidptr, cp, strlen(cp) + 1);
222 }
223
Sami Tolvanena742d102016-06-14 18:04:43 +0000224 bool info = strstr(str, " permissive=1") || strstr(str, " policy loaded ");
Jeff Vander Stoepd8858902018-05-03 14:57:39 -0700225 static std::string denial_metadata;
Mark Salyzyneb06de72014-10-13 09:59:37 -0700226 if ((fdDmesg >= 0) && initialized) {
Max Bires4214d132017-08-15 11:07:49 -0700227 struct iovec iov[4];
Mark Salyzyn7ee2aef2014-09-28 14:41:50 -0700228 static const char log_info[] = { KMSG_PRIORITY(LOG_INFO) };
229 static const char log_warning[] = { KMSG_PRIORITY(LOG_WARNING) };
Mark Salyzyn4d205f82016-07-15 15:45:58 -0700230 static const char newline[] = "\n";
Mark Salyzyne9bebd02014-04-03 09:55:26 -0700231
Nick Kralevich512a7bf2019-04-24 13:29:35 -0700232 auditParse(str, uid, &denial_metadata);
233 iov[0].iov_base = info ? const_cast<char*>(log_info) : const_cast<char*>(log_warning);
234 iov[0].iov_len = info ? sizeof(log_info) : sizeof(log_warning);
235 iov[1].iov_base = str;
236 iov[1].iov_len = strlen(str);
237 iov[2].iov_base = const_cast<char*>(denial_metadata.c_str());
238 iov[2].iov_len = denial_metadata.length();
239 iov[3].iov_base = const_cast<char*>(newline);
240 iov[3].iov_len = strlen(newline);
Mark Salyzyne9bebd02014-04-03 09:55:26 -0700241
Nick Kralevich512a7bf2019-04-24 13:29:35 -0700242 writev(fdDmesg, iov, arraysize(iov));
Mark Salyzyne9bebd02014-04-03 09:55:26 -0700243 }
244
Mark Salyzynce80da32016-12-29 15:16:06 -0800245 if (!main && !events) {
246 free(str);
247 return 0;
248 }
249
Bernie Innocenti804e7d82019-01-16 15:25:18 +0900250 log_time now(log_time::EPOCH);
William Roberts29d238d2013-02-08 09:45:26 +0900251
252 static const char audit_str[] = " audit(";
Mark Salyzyn501c3732017-03-10 14:31:54 -0800253 char* timeptr = strstr(str, audit_str);
254 if (timeptr &&
255 ((cp = now.strptime(timeptr + sizeof(audit_str) - 1, "%s.%q"))) &&
256 (*cp == ':')) {
William Roberts29d238d2013-02-08 09:45:26 +0900257 memcpy(timeptr + sizeof(audit_str) - 1, "0.0", 3);
Mark Salyzyne4369d62014-05-27 10:06:34 -0700258 memmove(timeptr + sizeof(audit_str) - 1 + 3, cp, strlen(cp) + 1);
Mark Salyzynb6bee332015-09-08 08:56:32 -0700259 if (!isMonotonic()) {
260 if (android::isMonotonic(now)) {
261 LogKlog::convertMonotonicToReal(now);
262 }
263 } else {
264 if (!android::isMonotonic(now)) {
265 LogKlog::convertRealToMonotonic(now);
266 }
Mark Salyzynae4d9282014-10-15 08:49:39 -0700267 }
Mark Salyzynb6bee332015-09-08 08:56:32 -0700268 } else if (isMonotonic()) {
269 now = log_time(CLOCK_MONOTONIC);
William Roberts29d238d2013-02-08 09:45:26 +0900270 } else {
Mark Salyzynb6bee332015-09-08 08:56:32 -0700271 now = log_time(CLOCK_REALTIME);
William Roberts29d238d2013-02-08 09:45:26 +0900272 }
273
Mark Salyzyne4369d62014-05-27 10:06:34 -0700274 // log to events
275
Max Bires4214d132017-08-15 11:07:49 -0700276 size_t str_len = strnlen(str, LOGGER_ENTRY_MAX_PAYLOAD);
277 if (((fdDmesg < 0) || !initialized) && !hasMetadata(str, str_len))
Jeff Vander Stoepd8858902018-05-03 14:57:39 -0700278 auditParse(str, uid, &denial_metadata);
279 str_len = (str_len + denial_metadata.length() <= LOGGER_ENTRY_MAX_PAYLOAD)
280 ? str_len + denial_metadata.length()
Max Bires4214d132017-08-15 11:07:49 -0700281 : LOGGER_ENTRY_MAX_PAYLOAD;
282 size_t message_len = str_len + sizeof(android_log_event_string_t);
Mark Salyzyne4369d62014-05-27 10:06:34 -0700283
Hao Wangf6e22962017-12-04 14:10:40 +0800284 log_mask_t notify = 0;
William Roberts29d238d2013-02-08 09:45:26 +0900285
Mark Salyzyn501c3732017-03-10 14:31:54 -0800286 if (events) { // begin scope for event buffer
Max Bires4214d132017-08-15 11:07:49 -0700287 uint32_t buffer[(message_len + sizeof(uint32_t) - 1) / sizeof(uint32_t)];
Mark Salyzynddda2122015-10-02 09:22:52 -0700288
Mark Salyzyn501c3732017-03-10 14:31:54 -0800289 android_log_event_string_t* event =
290 reinterpret_cast<android_log_event_string_t*>(buffer);
Mark Salyzyn29eb5702015-03-03 16:21:27 -0800291 event->header.tag = htole32(AUDITD_LOG_TAG);
Nick Kralevich58ba58a2015-04-07 01:25:43 -0700292 event->type = EVENT_TYPE_STRING;
Max Biresb8716682017-09-14 13:01:28 -0700293 event->length = htole32(str_len);
Jeff Vander Stoepd8858902018-05-03 14:57:39 -0700294 memcpy(event->data, str, str_len - denial_metadata.length());
295 memcpy(event->data + str_len - denial_metadata.length(),
296 denial_metadata.c_str(), denial_metadata.length());
Mark Salyzyne4369d62014-05-27 10:06:34 -0700297
Max Bires4214d132017-08-15 11:07:49 -0700298 rc = logbuf->log(
299 LOG_ID_EVENTS, now, uid, pid, tid, reinterpret_cast<char*>(event),
Chih-Hung Hsieh08d470b2018-08-13 14:22:56 -0700300 (message_len <= UINT16_MAX) ? (uint16_t)message_len : UINT16_MAX);
Mark Salyzyn202e1532015-02-09 08:21:05 -0800301 if (rc >= 0) {
Hao Wangf6e22962017-12-04 14:10:40 +0800302 notify |= 1 << LOG_ID_EVENTS;
Mark Salyzyn202e1532015-02-09 08:21:05 -0800303 }
Mark Salyzynddda2122015-10-02 09:22:52 -0700304 // end scope for event buffer
William Roberts29d238d2013-02-08 09:45:26 +0900305 }
306
Mark Salyzyne4369d62014-05-27 10:06:34 -0700307 // log to main
308
309 static const char comm_str[] = " comm=\"";
Mark Salyzyn501c3732017-03-10 14:31:54 -0800310 const char* comm = strstr(str, comm_str);
311 const char* estr = str + strlen(str);
Yi Kongc8d09dd2018-07-13 17:39:22 -0700312 const char* commfree = nullptr;
Mark Salyzyne4369d62014-05-27 10:06:34 -0700313 if (comm) {
314 estr = comm;
315 comm += sizeof(comm_str) - 1;
316 } else if (pid == getpid()) {
317 pid = tid;
318 comm = "auditd";
Mark Salyzyned777e92015-06-24 16:22:54 -0700319 } else {
Mark Salyzyn3c501b52017-04-18 14:09:45 -0700320 logbuf->wrlock();
Mark Salyzyned777e92015-06-24 16:22:54 -0700321 comm = commfree = logbuf->pidToName(pid);
322 logbuf->unlock();
323 if (!comm) {
324 comm = "unknown";
325 }
Mark Salyzyne4369d62014-05-27 10:06:34 -0700326 }
327
Mark Salyzyn501c3732017-03-10 14:31:54 -0800328 const char* ecomm = strchr(comm, '"');
Mark Salyzyne4369d62014-05-27 10:06:34 -0700329 if (ecomm) {
330 ++ecomm;
Max Bires4214d132017-08-15 11:07:49 -0700331 str_len = ecomm - comm;
Mark Salyzyne4369d62014-05-27 10:06:34 -0700332 } else {
Max Bires4214d132017-08-15 11:07:49 -0700333 str_len = strlen(comm) + 1;
Mark Salyzyne4369d62014-05-27 10:06:34 -0700334 ecomm = "";
335 }
Max Bires4214d132017-08-15 11:07:49 -0700336 size_t prefix_len = estr - str;
337 if (prefix_len > LOGGER_ENTRY_MAX_PAYLOAD) {
338 prefix_len = LOGGER_ENTRY_MAX_PAYLOAD;
Mark Salyzynddda2122015-10-02 09:22:52 -0700339 }
Max Bires4214d132017-08-15 11:07:49 -0700340 size_t suffix_len = strnlen(ecomm, LOGGER_ENTRY_MAX_PAYLOAD - prefix_len);
Jeff Vander Stoepd8858902018-05-03 14:57:39 -0700341 message_len =
342 str_len + prefix_len + suffix_len + denial_metadata.length() + 2;
Mark Salyzyne4369d62014-05-27 10:06:34 -0700343
Mark Salyzyn501c3732017-03-10 14:31:54 -0800344 if (main) { // begin scope for main buffer
Max Bires4214d132017-08-15 11:07:49 -0700345 char newstr[message_len];
Mark Salyzynddda2122015-10-02 09:22:52 -0700346
Mark Salyzyn6bdeee02014-09-19 11:59:42 -0700347 *newstr = info ? ANDROID_LOG_INFO : ANDROID_LOG_WARN;
Max Bires4214d132017-08-15 11:07:49 -0700348 strlcpy(newstr + 1, comm, str_len);
349 strncpy(newstr + 1 + str_len, str, prefix_len);
350 strncpy(newstr + 1 + str_len + prefix_len, ecomm, suffix_len);
351 strncpy(newstr + 1 + str_len + prefix_len + suffix_len,
Jeff Vander Stoepd8858902018-05-03 14:57:39 -0700352 denial_metadata.c_str(), denial_metadata.length());
Mark Salyzyne4369d62014-05-27 10:06:34 -0700353
Chih-Hung Hsieh08d470b2018-08-13 14:22:56 -0700354 rc = logbuf->log(
355 LOG_ID_MAIN, now, uid, pid, tid, newstr,
356 (message_len <= UINT16_MAX) ? (uint16_t)message_len : UINT16_MAX);
Mark Salyzyne4369d62014-05-27 10:06:34 -0700357
Mark Salyzyn202e1532015-02-09 08:21:05 -0800358 if (rc >= 0) {
Hao Wangf6e22962017-12-04 14:10:40 +0800359 notify |= 1 << LOG_ID_MAIN;
Mark Salyzyn202e1532015-02-09 08:21:05 -0800360 }
Mark Salyzynddda2122015-10-02 09:22:52 -0700361 // end scope for main buffer
Mark Salyzyne4369d62014-05-27 10:06:34 -0700362 }
363
Mark Salyzyn501c3732017-03-10 14:31:54 -0800364 free(const_cast<char*>(commfree));
William Roberts29d238d2013-02-08 09:45:26 +0900365 free(str);
366
Mark Salyzyne4369d62014-05-27 10:06:34 -0700367 if (notify) {
Hao Wangf6e22962017-12-04 14:10:40 +0800368 reader->notifyNewLog(notify);
Mark Salyzyn202e1532015-02-09 08:21:05 -0800369 if (rc < 0) {
Max Bires4214d132017-08-15 11:07:49 -0700370 rc = message_len;
Mark Salyzyn202e1532015-02-09 08:21:05 -0800371 }
Mark Salyzyne4369d62014-05-27 10:06:34 -0700372 }
William Roberts29d238d2013-02-08 09:45:26 +0900373
374 return rc;
375}
376
Mark Salyzyn501c3732017-03-10 14:31:54 -0800377int LogAudit::log(char* buf, size_t len) {
378 char* audit = strstr(buf, " audit(");
Mark Salyzyn151beac2015-09-04 11:37:42 -0700379 if (!audit || (audit >= &buf[len])) {
Mark Salyzynae4d9282014-10-15 08:49:39 -0700380 return 0;
William Roberts29d238d2013-02-08 09:45:26 +0900381 }
382
Mark Salyzyneb06de72014-10-13 09:59:37 -0700383 *audit = '\0';
William Roberts29d238d2013-02-08 09:45:26 +0900384
Mark Salyzyneb06de72014-10-13 09:59:37 -0700385 int rc;
Mark Salyzyn501c3732017-03-10 14:31:54 -0800386 char* type = strstr(buf, "type=");
Mark Salyzyn151beac2015-09-04 11:37:42 -0700387 if (type && (type < &buf[len])) {
Mark Salyzyneb06de72014-10-13 09:59:37 -0700388 rc = logPrint("%s %s", type, audit + 1);
389 } else {
390 rc = logPrint("%s", audit + 1);
William Roberts29d238d2013-02-08 09:45:26 +0900391 }
Mark Salyzyneb06de72014-10-13 09:59:37 -0700392 *audit = ' ';
393 return rc;
William Roberts29d238d2013-02-08 09:45:26 +0900394}
395
396int LogAudit::getLogSocket() {
397 int fd = audit_open();
398 if (fd < 0) {
399 return fd;
400 }
Nick Kralevichc234a1b2014-11-19 13:33:22 -0800401 if (audit_setup(fd, getpid()) < 0) {
William Roberts29d238d2013-02-08 09:45:26 +0900402 audit_close(fd);
403 fd = -1;
404 }
William Roberts29d238d2013-02-08 09:45:26 +0900405 return fd;
406}