blob: ee6e5793969d7e44d297ea0327ab21faa27a1160 [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
26class LogReader;
William Roberts29d238d2013-02-08 09:45:26 +090027
28class LogAudit : public SocketListener {
Mark Salyzyn501c3732017-03-10 14:31:54 -080029 LogBuffer* logbuf;
30 LogReader* reader;
31 int fdDmesg; // fdDmesg >= 0 is functionally bool dmesg
Mark Salyzynce80da32016-12-29 15:16:06 -080032 bool main;
33 bool events;
Mark Salyzyneb06de72014-10-13 09:59:37 -070034 bool initialized;
William Roberts29d238d2013-02-08 09:45:26 +090035
Tom Cherry64e90162020-05-07 14:44:43 -070036 public:
37 LogAudit(LogBuffer* buf, LogReader* reader, int fdDmesg, LogStatistics* stats);
Mark Salyzyn501c3732017-03-10 14:31:54 -080038 int log(char* buf, size_t len);
William Roberts29d238d2013-02-08 09:45:26 +090039
Tom Cherry64e90162020-05-07 14:44:43 -070040 protected:
Mark Salyzyn501c3732017-03-10 14:31:54 -080041 virtual bool onDataAvailable(SocketClient* cli);
William Roberts29d238d2013-02-08 09:45:26 +090042
Tom Cherry64e90162020-05-07 14:44:43 -070043 private:
William Roberts29d238d2013-02-08 09:45:26 +090044 static int getLogSocket();
Max Bires4214d132017-08-15 11:07:49 -070045 std::map<std::string, std::string> populateDenialMap();
46 std::string denialParse(const std::string& denial, char terminator,
47 const std::string& search_term);
Jeff Vander Stoepd8858902018-05-03 14:57:39 -070048 void auditParse(const std::string& string, uid_t uid, std::string* bug_num);
Mark Salyzyn501c3732017-03-10 14:31:54 -080049 int logPrint(const char* fmt, ...)
50 __attribute__((__format__(__printf__, 2, 3)));
William Roberts29d238d2013-02-08 09:45:26 +090051
Tom Cherry64e90162020-05-07 14:44:43 -070052 LogStatistics* stats_;
53};