William Roberts | 29d238d | 2013-02-08 09:45:26 +0900 | [diff] [blame] | 1 | /* |
| 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 Salyzyn | 29eb570 | 2015-03-03 16:21:27 -0800 | [diff] [blame] | 18 | #include <endian.h> |
William Roberts | 29d238d | 2013-02-08 09:45:26 +0900 | [diff] [blame] | 19 | #include <errno.h> |
Mark Salyzyn | e0fa291 | 2014-04-28 16:39:04 -0700 | [diff] [blame] | 20 | #include <limits.h> |
William Roberts | 29d238d | 2013-02-08 09:45:26 +0900 | [diff] [blame] | 21 | #include <stdarg.h> |
| 22 | #include <stdlib.h> |
Mark Salyzyn | 2ad0bd0 | 2016-02-23 08:55:43 -0800 | [diff] [blame] | 23 | #include <string.h> |
Mark Salyzyn | 8daa9af | 2014-04-28 14:07:23 -0700 | [diff] [blame] | 24 | #include <sys/prctl.h> |
Mark Salyzyn | e9bebd0 | 2014-04-03 09:55:26 -0700 | [diff] [blame] | 25 | #include <sys/uio.h> |
Mark Salyzyn | 7ee2aef | 2014-09-28 14:41:50 -0700 | [diff] [blame] | 26 | #include <syslog.h> |
William Roberts | 29d238d | 2013-02-08 09:45:26 +0900 | [diff] [blame] | 27 | |
Mark Salyzyn | 2ad0bd0 | 2016-02-23 08:55:43 -0800 | [diff] [blame] | 28 | #include <string> |
| 29 | |
Sami Tolvanen | d122ee6 | 2016-02-05 14:27:52 -0800 | [diff] [blame] | 30 | #include <cutils/properties.h> |
Mark Salyzyn | ddda212 | 2015-10-02 09:22:52 -0700 | [diff] [blame] | 31 | #include <log/logger.h> |
Mark Salyzyn | e3aeeee | 2015-03-17 07:56:32 -0700 | [diff] [blame] | 32 | #include <private/android_filesystem_config.h> |
Mark Salyzyn | 29eb570 | 2015-03-03 16:21:27 -0800 | [diff] [blame] | 33 | #include <private/android_logger.h> |
| 34 | |
William Roberts | 29d238d | 2013-02-08 09:45:26 +0900 | [diff] [blame] | 35 | #include "libaudit.h" |
| 36 | #include "LogAudit.h" |
Mark Salyzyn | 2ad0bd0 | 2016-02-23 08:55:43 -0800 | [diff] [blame] | 37 | #include "LogBuffer.h" |
Mark Salyzyn | ae4d928 | 2014-10-15 08:49:39 -0700 | [diff] [blame] | 38 | #include "LogKlog.h" |
Mark Salyzyn | 2ad0bd0 | 2016-02-23 08:55:43 -0800 | [diff] [blame] | 39 | #include "LogReader.h" |
William Roberts | 29d238d | 2013-02-08 09:45:26 +0900 | [diff] [blame] | 40 | |
Sami Tolvanen | d122ee6 | 2016-02-05 14:27:52 -0800 | [diff] [blame] | 41 | #ifndef AUDITD_ENFORCE_INTEGRITY |
| 42 | #define AUDITD_ENFORCE_INTEGRITY false |
| 43 | #endif |
| 44 | |
Mark Salyzyn | ccbadc6 | 2015-03-12 12:25:35 -0700 | [diff] [blame] | 45 | #define KMSG_PRIORITY(PRI) \ |
| 46 | '<', \ |
| 47 | '0' + LOG_MAKEPRI(LOG_AUTH, LOG_PRI(PRI)) / 10, \ |
| 48 | '0' + LOG_MAKEPRI(LOG_AUTH, LOG_PRI(PRI)) % 10, \ |
Mark Salyzyn | 7ee2aef | 2014-09-28 14:41:50 -0700 | [diff] [blame] | 49 | '>' |
| 50 | |
Mark Salyzyn | 7718778 | 2015-05-12 15:21:31 -0700 | [diff] [blame] | 51 | LogAudit::LogAudit(LogBuffer *buf, LogReader *reader, int fdDmesg) : |
| 52 | SocketListener(getLogSocket(), false), |
| 53 | logbuf(buf), |
| 54 | reader(reader), |
| 55 | fdDmesg(fdDmesg), |
Sami Tolvanen | d122ee6 | 2016-02-05 14:27:52 -0800 | [diff] [blame] | 56 | policyLoaded(false), |
| 57 | rebootToSafeMode(false), |
Mark Salyzyn | 7718778 | 2015-05-12 15:21:31 -0700 | [diff] [blame] | 58 | initialized(false) { |
Sami Tolvanen | d122ee6 | 2016-02-05 14:27:52 -0800 | [diff] [blame] | 59 | logToDmesg("start"); |
William Roberts | 29d238d | 2013-02-08 09:45:26 +0900 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | bool LogAudit::onDataAvailable(SocketClient *cli) { |
Mark Salyzyn | eb06de7 | 2014-10-13 09:59:37 -0700 | [diff] [blame] | 63 | if (!initialized) { |
| 64 | prctl(PR_SET_NAME, "logd.auditd"); |
| 65 | initialized = true; |
| 66 | } |
Mark Salyzyn | 8daa9af | 2014-04-28 14:07:23 -0700 | [diff] [blame] | 67 | |
William Roberts | 29d238d | 2013-02-08 09:45:26 +0900 | [diff] [blame] | 68 | struct audit_message rep; |
| 69 | |
Mark Salyzyn | e0fa291 | 2014-04-28 16:39:04 -0700 | [diff] [blame] | 70 | rep.nlh.nlmsg_type = 0; |
| 71 | rep.nlh.nlmsg_len = 0; |
| 72 | rep.data[0] = '\0'; |
| 73 | |
William Roberts | 29d238d | 2013-02-08 09:45:26 +0900 | [diff] [blame] | 74 | if (audit_get_reply(cli->getSocket(), &rep, GET_REPLY_BLOCKING, 0) < 0) { |
| 75 | SLOGE("Failed on audit_get_reply with error: %s", strerror(errno)); |
| 76 | return false; |
| 77 | } |
| 78 | |
Mark Salyzyn | eb06de7 | 2014-10-13 09:59:37 -0700 | [diff] [blame] | 79 | logPrint("type=%d %.*s", |
| 80 | rep.nlh.nlmsg_type, rep.nlh.nlmsg_len, rep.data); |
William Roberts | 29d238d | 2013-02-08 09:45:26 +0900 | [diff] [blame] | 81 | |
| 82 | return true; |
| 83 | } |
| 84 | |
Sami Tolvanen | d122ee6 | 2016-02-05 14:27:52 -0800 | [diff] [blame] | 85 | void LogAudit::logToDmesg(const std::string& str) |
| 86 | { |
| 87 | static const char prefix[] = { KMSG_PRIORITY(LOG_INFO), |
| 88 | 'l', 'o', 'g', 'd', '.', 'a', 'u', 'd', 'i', 't', 'd', ':', |
| 89 | ' ', '\0' }; |
| 90 | std::string message = prefix + str + "\n"; |
| 91 | write(fdDmesg, message.c_str(), message.length()); |
| 92 | } |
| 93 | |
| 94 | std::string LogAudit::getProperty(const std::string& name) |
| 95 | { |
| 96 | char value[PROP_VALUE_MAX] = {0}; |
| 97 | property_get(name.c_str(), value, ""); |
| 98 | return value; |
| 99 | } |
| 100 | |
| 101 | void LogAudit::enforceIntegrity() { |
Sami Tolvanen | abda934 | 2016-02-29 09:07:46 -0800 | [diff] [blame] | 102 | static bool loggedOnce; |
| 103 | bool once = loggedOnce; |
| 104 | |
| 105 | loggedOnce = true; |
| 106 | |
Sami Tolvanen | d122ee6 | 2016-02-05 14:27:52 -0800 | [diff] [blame] | 107 | if (!AUDITD_ENFORCE_INTEGRITY) { |
Sami Tolvanen | abda934 | 2016-02-29 09:07:46 -0800 | [diff] [blame] | 108 | if (!once) { |
| 109 | logToDmesg("integrity enforcement suppressed; not rebooting"); |
| 110 | } |
Sami Tolvanen | d122ee6 | 2016-02-05 14:27:52 -0800 | [diff] [blame] | 111 | } else if (rebootToSafeMode) { |
| 112 | if (getProperty("persist.sys.safemode") == "1") { |
Sami Tolvanen | abda934 | 2016-02-29 09:07:46 -0800 | [diff] [blame] | 113 | if (!once) { |
| 114 | logToDmesg("integrity enforcement suppressed; in safe mode"); |
| 115 | } |
Sami Tolvanen | d122ee6 | 2016-02-05 14:27:52 -0800 | [diff] [blame] | 116 | return; |
| 117 | } |
| 118 | |
| 119 | logToDmesg("enforcing integrity; rebooting to safe mode"); |
| 120 | property_set("persist.sys.safemode", "1"); |
| 121 | |
| 122 | std::string buildDate = getProperty("ro.build.date.utc"); |
| 123 | if (!buildDate.empty()) { |
| 124 | property_set("persist.sys.audit_safemode", buildDate.c_str()); |
| 125 | } |
| 126 | |
| 127 | property_set("sys.powerctl", "reboot"); |
| 128 | } else { |
| 129 | logToDmesg("enforcing integrity: rebooting to recovery"); |
| 130 | property_set("sys.powerctl", "reboot,recovery"); |
| 131 | } |
| 132 | } |
| 133 | |
William Roberts | 29d238d | 2013-02-08 09:45:26 +0900 | [diff] [blame] | 134 | int LogAudit::logPrint(const char *fmt, ...) { |
| 135 | if (fmt == NULL) { |
| 136 | return -EINVAL; |
| 137 | } |
| 138 | |
| 139 | va_list args; |
| 140 | |
| 141 | char *str = NULL; |
| 142 | va_start(args, fmt); |
| 143 | int rc = vasprintf(&str, fmt, args); |
| 144 | va_end(args); |
| 145 | |
| 146 | if (rc < 0) { |
| 147 | return rc; |
| 148 | } |
| 149 | |
Mark Salyzyn | e4369d6 | 2014-05-27 10:06:34 -0700 | [diff] [blame] | 150 | char *cp; |
| 151 | while ((cp = strstr(str, " "))) { |
| 152 | memmove(cp, cp + 1, strlen(cp + 1) + 1); |
| 153 | } |
| 154 | |
Sami Tolvanen | d122ee6 | 2016-02-05 14:27:52 -0800 | [diff] [blame] | 155 | bool loaded = strstr(str, " policy loaded "); |
| 156 | |
| 157 | if (loaded) { |
| 158 | if (policyLoaded) { |
| 159 | // SELinux policy changes are not allowed |
| 160 | enforceIntegrity(); |
| 161 | } else { |
| 162 | logToDmesg("policy loaded"); |
| 163 | policyLoaded = true; |
| 164 | } |
| 165 | } |
| 166 | |
Sami Tolvanen | 2060a83 | 2016-02-29 14:10:59 -0800 | [diff] [blame] | 167 | // Note: The audit log can include untrusted strings, but those containing |
| 168 | // "a control character, unprintable character, double quote mark, or a |
| 169 | // space" are hex encoded. The space character before the search term is |
| 170 | // therefore needed to prevent denial of service. Do not remove the space. |
Sami Tolvanen | d122ee6 | 2016-02-05 14:27:52 -0800 | [diff] [blame] | 171 | bool permissive = strstr(str, " enforcing=0") || |
| 172 | strstr(str, " permissive=1"); |
| 173 | |
| 174 | if (permissive) { |
| 175 | // SELinux in permissive mode is not allowed |
| 176 | enforceIntegrity(); |
| 177 | } |
| 178 | |
| 179 | bool info = loaded || permissive; |
Mark Salyzyn | eb06de7 | 2014-10-13 09:59:37 -0700 | [diff] [blame] | 180 | if ((fdDmesg >= 0) && initialized) { |
Mark Salyzyn | 6bdeee0 | 2014-09-19 11:59:42 -0700 | [diff] [blame] | 181 | struct iovec iov[3]; |
Mark Salyzyn | 7ee2aef | 2014-09-28 14:41:50 -0700 | [diff] [blame] | 182 | static const char log_info[] = { KMSG_PRIORITY(LOG_INFO) }; |
| 183 | static const char log_warning[] = { KMSG_PRIORITY(LOG_WARNING) }; |
Mark Salyzyn | e9bebd0 | 2014-04-03 09:55:26 -0700 | [diff] [blame] | 184 | |
Mark Salyzyn | 7ee2aef | 2014-09-28 14:41:50 -0700 | [diff] [blame] | 185 | iov[0].iov_base = info ? const_cast<char *>(log_info) |
| 186 | : const_cast<char *>(log_warning); |
| 187 | iov[0].iov_len = info ? sizeof(log_info) : sizeof(log_warning); |
Mark Salyzyn | 6bdeee0 | 2014-09-19 11:59:42 -0700 | [diff] [blame] | 188 | iov[1].iov_base = str; |
| 189 | iov[1].iov_len = strlen(str); |
| 190 | iov[2].iov_base = const_cast<char *>("\n"); |
| 191 | iov[2].iov_len = 1; |
Mark Salyzyn | e9bebd0 | 2014-04-03 09:55:26 -0700 | [diff] [blame] | 192 | |
| 193 | writev(fdDmesg, iov, sizeof(iov) / sizeof(iov[0])); |
| 194 | } |
| 195 | |
William Roberts | 29d238d | 2013-02-08 09:45:26 +0900 | [diff] [blame] | 196 | pid_t pid = getpid(); |
| 197 | pid_t tid = gettid(); |
Mark Salyzyn | e3aeeee | 2015-03-17 07:56:32 -0700 | [diff] [blame] | 198 | uid_t uid = AID_LOGD; |
William Roberts | 29d238d | 2013-02-08 09:45:26 +0900 | [diff] [blame] | 199 | log_time now; |
| 200 | |
| 201 | static const char audit_str[] = " audit("; |
| 202 | char *timeptr = strstr(str, audit_str); |
William Roberts | 29d238d | 2013-02-08 09:45:26 +0900 | [diff] [blame] | 203 | if (timeptr |
| 204 | && ((cp = now.strptime(timeptr + sizeof(audit_str) - 1, "%s.%q"))) |
| 205 | && (*cp == ':')) { |
| 206 | memcpy(timeptr + sizeof(audit_str) - 1, "0.0", 3); |
Mark Salyzyn | e4369d6 | 2014-05-27 10:06:34 -0700 | [diff] [blame] | 207 | memmove(timeptr + sizeof(audit_str) - 1 + 3, cp, strlen(cp) + 1); |
Mark Salyzyn | b6bee33 | 2015-09-08 08:56:32 -0700 | [diff] [blame] | 208 | if (!isMonotonic()) { |
| 209 | if (android::isMonotonic(now)) { |
| 210 | LogKlog::convertMonotonicToReal(now); |
| 211 | } |
| 212 | } else { |
| 213 | if (!android::isMonotonic(now)) { |
| 214 | LogKlog::convertRealToMonotonic(now); |
| 215 | } |
Mark Salyzyn | ae4d928 | 2014-10-15 08:49:39 -0700 | [diff] [blame] | 216 | } |
Mark Salyzyn | b6bee33 | 2015-09-08 08:56:32 -0700 | [diff] [blame] | 217 | } else if (isMonotonic()) { |
| 218 | now = log_time(CLOCK_MONOTONIC); |
William Roberts | 29d238d | 2013-02-08 09:45:26 +0900 | [diff] [blame] | 219 | } else { |
Mark Salyzyn | b6bee33 | 2015-09-08 08:56:32 -0700 | [diff] [blame] | 220 | now = log_time(CLOCK_REALTIME); |
William Roberts | 29d238d | 2013-02-08 09:45:26 +0900 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | static const char pid_str[] = " pid="; |
| 224 | char *pidptr = strstr(str, pid_str); |
| 225 | if (pidptr && isdigit(pidptr[sizeof(pid_str) - 1])) { |
| 226 | cp = pidptr + sizeof(pid_str) - 1; |
| 227 | pid = 0; |
| 228 | while (isdigit(*cp)) { |
| 229 | pid = (pid * 10) + (*cp - '0'); |
| 230 | ++cp; |
| 231 | } |
| 232 | tid = pid; |
Mark Salyzyn | ed777e9 | 2015-06-24 16:22:54 -0700 | [diff] [blame] | 233 | logbuf->lock(); |
William Roberts | 29d238d | 2013-02-08 09:45:26 +0900 | [diff] [blame] | 234 | uid = logbuf->pidToUid(pid); |
Mark Salyzyn | ed777e9 | 2015-06-24 16:22:54 -0700 | [diff] [blame] | 235 | logbuf->unlock(); |
Mark Salyzyn | e4369d6 | 2014-05-27 10:06:34 -0700 | [diff] [blame] | 236 | memmove(pidptr, cp, strlen(cp) + 1); |
William Roberts | 29d238d | 2013-02-08 09:45:26 +0900 | [diff] [blame] | 237 | } |
| 238 | |
Mark Salyzyn | e4369d6 | 2014-05-27 10:06:34 -0700 | [diff] [blame] | 239 | // log to events |
| 240 | |
Mark Salyzyn | ddda212 | 2015-10-02 09:22:52 -0700 | [diff] [blame] | 241 | size_t l = strnlen(str, LOGGER_ENTRY_MAX_PAYLOAD); |
Mark Salyzyn | 29eb570 | 2015-03-03 16:21:27 -0800 | [diff] [blame] | 242 | size_t n = l + sizeof(android_log_event_string_t); |
Mark Salyzyn | e4369d6 | 2014-05-27 10:06:34 -0700 | [diff] [blame] | 243 | |
| 244 | bool notify = false; |
William Roberts | 29d238d | 2013-02-08 09:45:26 +0900 | [diff] [blame] | 245 | |
Mark Salyzyn | ddda212 | 2015-10-02 09:22:52 -0700 | [diff] [blame] | 246 | { // begin scope for event buffer |
| 247 | uint32_t buffer[(n + sizeof(uint32_t) - 1) / sizeof(uint32_t)]; |
| 248 | |
| 249 | android_log_event_string_t *event |
| 250 | = reinterpret_cast<android_log_event_string_t *>(buffer); |
Mark Salyzyn | 29eb570 | 2015-03-03 16:21:27 -0800 | [diff] [blame] | 251 | event->header.tag = htole32(AUDITD_LOG_TAG); |
Nick Kralevich | 58ba58a | 2015-04-07 01:25:43 -0700 | [diff] [blame] | 252 | event->type = EVENT_TYPE_STRING; |
| 253 | event->length = htole32(l); |
| 254 | memcpy(event->data, str, l); |
Mark Salyzyn | e4369d6 | 2014-05-27 10:06:34 -0700 | [diff] [blame] | 255 | |
Mark Salyzyn | 202e153 | 2015-02-09 08:21:05 -0800 | [diff] [blame] | 256 | rc = logbuf->log(LOG_ID_EVENTS, now, uid, pid, tid, |
| 257 | reinterpret_cast<char *>(event), |
| 258 | (n <= USHRT_MAX) ? (unsigned short) n : USHRT_MAX); |
Mark Salyzyn | 202e153 | 2015-02-09 08:21:05 -0800 | [diff] [blame] | 259 | if (rc >= 0) { |
| 260 | notify = true; |
| 261 | } |
Mark Salyzyn | ddda212 | 2015-10-02 09:22:52 -0700 | [diff] [blame] | 262 | // end scope for event buffer |
William Roberts | 29d238d | 2013-02-08 09:45:26 +0900 | [diff] [blame] | 263 | } |
| 264 | |
Mark Salyzyn | e4369d6 | 2014-05-27 10:06:34 -0700 | [diff] [blame] | 265 | // log to main |
| 266 | |
| 267 | static const char comm_str[] = " comm=\""; |
| 268 | const char *comm = strstr(str, comm_str); |
| 269 | const char *estr = str + strlen(str); |
Mark Salyzyn | 758058f | 2015-08-21 16:44:30 -0700 | [diff] [blame] | 270 | const char *commfree = NULL; |
Mark Salyzyn | e4369d6 | 2014-05-27 10:06:34 -0700 | [diff] [blame] | 271 | if (comm) { |
| 272 | estr = comm; |
| 273 | comm += sizeof(comm_str) - 1; |
| 274 | } else if (pid == getpid()) { |
| 275 | pid = tid; |
| 276 | comm = "auditd"; |
Mark Salyzyn | ed777e9 | 2015-06-24 16:22:54 -0700 | [diff] [blame] | 277 | } else { |
| 278 | logbuf->lock(); |
| 279 | comm = commfree = logbuf->pidToName(pid); |
| 280 | logbuf->unlock(); |
| 281 | if (!comm) { |
| 282 | comm = "unknown"; |
| 283 | } |
Mark Salyzyn | e4369d6 | 2014-05-27 10:06:34 -0700 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | const char *ecomm = strchr(comm, '"'); |
| 287 | if (ecomm) { |
| 288 | ++ecomm; |
| 289 | l = ecomm - comm; |
| 290 | } else { |
| 291 | l = strlen(comm) + 1; |
| 292 | ecomm = ""; |
| 293 | } |
Mark Salyzyn | ddda212 | 2015-10-02 09:22:52 -0700 | [diff] [blame] | 294 | size_t b = estr - str; |
| 295 | if (b > LOGGER_ENTRY_MAX_PAYLOAD) { |
| 296 | b = LOGGER_ENTRY_MAX_PAYLOAD; |
| 297 | } |
| 298 | size_t e = strnlen(ecomm, LOGGER_ENTRY_MAX_PAYLOAD - b); |
| 299 | n = b + e + l + 2; |
Mark Salyzyn | e4369d6 | 2014-05-27 10:06:34 -0700 | [diff] [blame] | 300 | |
Mark Salyzyn | ddda212 | 2015-10-02 09:22:52 -0700 | [diff] [blame] | 301 | { // begin scope for main buffer |
| 302 | char newstr[n]; |
| 303 | |
Mark Salyzyn | 6bdeee0 | 2014-09-19 11:59:42 -0700 | [diff] [blame] | 304 | *newstr = info ? ANDROID_LOG_INFO : ANDROID_LOG_WARN; |
Mark Salyzyn | e4369d6 | 2014-05-27 10:06:34 -0700 | [diff] [blame] | 305 | strlcpy(newstr + 1, comm, l); |
Mark Salyzyn | ddda212 | 2015-10-02 09:22:52 -0700 | [diff] [blame] | 306 | strncpy(newstr + 1 + l, str, b); |
| 307 | strncpy(newstr + 1 + l + b, ecomm, e); |
Mark Salyzyn | e4369d6 | 2014-05-27 10:06:34 -0700 | [diff] [blame] | 308 | |
Mark Salyzyn | 202e153 | 2015-02-09 08:21:05 -0800 | [diff] [blame] | 309 | rc = logbuf->log(LOG_ID_MAIN, now, uid, pid, tid, newstr, |
| 310 | (n <= USHRT_MAX) ? (unsigned short) n : USHRT_MAX); |
Mark Salyzyn | e4369d6 | 2014-05-27 10:06:34 -0700 | [diff] [blame] | 311 | |
Mark Salyzyn | 202e153 | 2015-02-09 08:21:05 -0800 | [diff] [blame] | 312 | if (rc >= 0) { |
| 313 | notify = true; |
| 314 | } |
Mark Salyzyn | ddda212 | 2015-10-02 09:22:52 -0700 | [diff] [blame] | 315 | // end scope for main buffer |
Mark Salyzyn | e4369d6 | 2014-05-27 10:06:34 -0700 | [diff] [blame] | 316 | } |
| 317 | |
Mark Salyzyn | 758058f | 2015-08-21 16:44:30 -0700 | [diff] [blame] | 318 | free(const_cast<char *>(commfree)); |
William Roberts | 29d238d | 2013-02-08 09:45:26 +0900 | [diff] [blame] | 319 | free(str); |
| 320 | |
Mark Salyzyn | e4369d6 | 2014-05-27 10:06:34 -0700 | [diff] [blame] | 321 | if (notify) { |
| 322 | reader->notifyNewLog(); |
Mark Salyzyn | 202e153 | 2015-02-09 08:21:05 -0800 | [diff] [blame] | 323 | if (rc < 0) { |
| 324 | rc = n; |
| 325 | } |
Mark Salyzyn | e4369d6 | 2014-05-27 10:06:34 -0700 | [diff] [blame] | 326 | } |
William Roberts | 29d238d | 2013-02-08 09:45:26 +0900 | [diff] [blame] | 327 | |
| 328 | return rc; |
| 329 | } |
| 330 | |
Mark Salyzyn | 151beac | 2015-09-04 11:37:42 -0700 | [diff] [blame] | 331 | int LogAudit::log(char *buf, size_t len) { |
Mark Salyzyn | eb06de7 | 2014-10-13 09:59:37 -0700 | [diff] [blame] | 332 | char *audit = strstr(buf, " audit("); |
Mark Salyzyn | 151beac | 2015-09-04 11:37:42 -0700 | [diff] [blame] | 333 | if (!audit || (audit >= &buf[len])) { |
Mark Salyzyn | ae4d928 | 2014-10-15 08:49:39 -0700 | [diff] [blame] | 334 | return 0; |
William Roberts | 29d238d | 2013-02-08 09:45:26 +0900 | [diff] [blame] | 335 | } |
| 336 | |
Mark Salyzyn | eb06de7 | 2014-10-13 09:59:37 -0700 | [diff] [blame] | 337 | *audit = '\0'; |
William Roberts | 29d238d | 2013-02-08 09:45:26 +0900 | [diff] [blame] | 338 | |
Mark Salyzyn | eb06de7 | 2014-10-13 09:59:37 -0700 | [diff] [blame] | 339 | int rc; |
| 340 | char *type = strstr(buf, "type="); |
Mark Salyzyn | 151beac | 2015-09-04 11:37:42 -0700 | [diff] [blame] | 341 | if (type && (type < &buf[len])) { |
Mark Salyzyn | eb06de7 | 2014-10-13 09:59:37 -0700 | [diff] [blame] | 342 | rc = logPrint("%s %s", type, audit + 1); |
| 343 | } else { |
| 344 | rc = logPrint("%s", audit + 1); |
William Roberts | 29d238d | 2013-02-08 09:45:26 +0900 | [diff] [blame] | 345 | } |
Mark Salyzyn | eb06de7 | 2014-10-13 09:59:37 -0700 | [diff] [blame] | 346 | *audit = ' '; |
| 347 | return rc; |
William Roberts | 29d238d | 2013-02-08 09:45:26 +0900 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | int LogAudit::getLogSocket() { |
| 351 | int fd = audit_open(); |
| 352 | if (fd < 0) { |
| 353 | return fd; |
| 354 | } |
Nick Kralevich | c234a1b | 2014-11-19 13:33:22 -0800 | [diff] [blame] | 355 | if (audit_setup(fd, getpid()) < 0) { |
William Roberts | 29d238d | 2013-02-08 09:45:26 +0900 | [diff] [blame] | 356 | audit_close(fd); |
| 357 | fd = -1; |
| 358 | } |
| 359 | return fd; |
| 360 | } |