blob: 181920e381133af652d71ce15a168316e7808456 [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
Tom Cherry64e90162020-05-07 14:44:43 -070017#pragma once
William Roberts29d238d2013-02-08 09:45:26 +090018
Max Bires4214d132017-08-15 11:07:49 -070019#include <map>
Mark Salyzyn247d6822017-01-03 14:00:19 -080020
William Roberts29d238d2013-02-08 09:45:26 +090021#include <sysutils/SocketListener.h>
Mark Salyzyn317bfb92016-02-23 08:55:43 -080022
23#include "LogBuffer.h"
Tom Cherry64e90162020-05-07 14:44:43 -070024#include "LogStatistics.h"
Mark Salyzyn317bfb92016-02-23 08:55:43 -080025
William Roberts29d238d2013-02-08 09:45:26 +090026class LogAudit : public SocketListener {
Mark Salyzyn501c3732017-03-10 14:31:54 -080027 LogBuffer* logbuf;
Mark Salyzyn501c3732017-03-10 14:31:54 -080028 int fdDmesg; // fdDmesg >= 0 is functionally bool dmesg
Mark Salyzynce80da32016-12-29 15:16:06 -080029 bool main;
30 bool events;
Mark Salyzyneb06de72014-10-13 09:59:37 -070031 bool initialized;
William Roberts29d238d2013-02-08 09:45:26 +090032
Tom Cherry64e90162020-05-07 14:44:43 -070033 public:
Tom Cherry68630a02020-05-11 16:29:29 -070034 LogAudit(LogBuffer* buf, int fdDmesg, LogStatistics* stats);
Mark Salyzyn501c3732017-03-10 14:31:54 -080035 int log(char* buf, size_t len);
William Roberts29d238d2013-02-08 09:45:26 +090036
Tom Cherry64e90162020-05-07 14:44:43 -070037 protected:
Mark Salyzyn501c3732017-03-10 14:31:54 -080038 virtual bool onDataAvailable(SocketClient* cli);
William Roberts29d238d2013-02-08 09:45:26 +090039
Tom Cherry64e90162020-05-07 14:44:43 -070040 private:
William Roberts29d238d2013-02-08 09:45:26 +090041 static int getLogSocket();
Max Bires4214d132017-08-15 11:07:49 -070042 std::map<std::string, std::string> populateDenialMap();
43 std::string denialParse(const std::string& denial, char terminator,
44 const std::string& search_term);
Jeff Vander Stoepd8858902018-05-03 14:57:39 -070045 void auditParse(const std::string& string, uid_t uid, std::string* bug_num);
Mark Salyzyn501c3732017-03-10 14:31:54 -080046 int logPrint(const char* fmt, ...)
47 __attribute__((__format__(__printf__, 2, 3)));
William Roberts29d238d2013-02-08 09:45:26 +090048
Tom Cherry64e90162020-05-07 14:44:43 -070049 LogStatistics* stats_;
50};