98fdc15fe5a91c9971726bd4ddab81e4897387fc
[platform/core/security/security-manager.git] / src / server / dpl / log / include / dpl / log / audit-smack-log.h
1 /*
2  *  Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *  Contact: Bumjin Im <bj.im@samsung.com>
5  *
6  *  Licensed under the Apache License, Version 2.0 (the "License");
7  *  you may not use this file except in compliance with the License.
8  *  You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License
17  */
18 /*
19  * @file        audit-smack-log.h
20  * @author      Marek Smolinski (m.smolinski@samsung.com)
21  * @version     1.0
22  * @brief       AuditSmackLog loging SMACK access deny sequentially into files
23  */
24
25 #ifndef _AUDIT_SMACK_LOG_
26 #define _AUDIT_SMACK_LOG_
27
28 #include <dpl/log/abstract_log_provider.h>
29
30 #include <map>
31 #include <fstream>
32 #include <mutex>
33 #include <memory>
34 #include <functional>
35
36 namespace SecurityManager {
37 namespace Log {
38
39 class AuditSmackLog :
40     public AbstractLogProvider
41 {
42 public:
43     AuditSmackLog();
44     virtual ~AuditSmackLog();
45
46     bool Fail() const;
47
48     virtual void Debug(const char *message,
49                        const char *fileName,
50                        int line,
51                        const char *function);
52     virtual void Info(const char *message,
53                       const char *fileName,
54                       int line,
55                       const char *function);
56     virtual void Warning(const char *message,
57                          const char *fileName,
58                          int line,
59                          const char *function);
60     virtual void Error(const char *message,
61                        const char *fileName,
62                        int line,
63                        const char *function);
64     virtual void Pedantic(const char *message,
65                           const char *fileName,
66                           int line,
67                           const char *function);
68     virtual void SecureDebug(const char *message,
69                              const char *fileName,
70                              int line,
71                              const char *function);
72     virtual void SecureInfo(const char *message,
73                             const char *fileName,
74                             int line,
75                             const char *function);
76     virtual void SecureWarning(const char *message,
77                               const char *fileName,
78                               int line,
79                               const char *function);
80     virtual void SecureError(const char *message,
81                              const char *fileName,
82                              int line,
83                              const char *function);
84
85     virtual void SmackAudit(const char *message,
86                             const char *fileName,
87                             int line,
88                             const char *function);
89
90 private:
91     void HandleWrite(const char *message,
92                      const char *fileName,
93                      int line,
94                      const char *function);
95
96     int CreateLogFile();
97     int RemoveOldestLogFile();
98     int ParseConfig();
99     int ProcessLogDir();
100     bool IsFileFull(std::ofstream &fs) const;
101
102     bool m_state;
103     unsigned int m_filesCount;
104     unsigned int m_fileMaxBytesSize;
105
106     std::map<time_t, std::string> m_fileNameMap;
107     std::ofstream m_outputStream;
108
109     std::mutex m_writeMtx;
110 };
111
112 }  // namespace Log
113 }  // namespace SecurityManager
114 #endif  // _AUDIT_SMACK_LOG_