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