Remove SmackAudit() from logging facility 58/23158/6
authorRafal Krypa <r.krypa@samsung.com>
Wed, 18 Jun 2014 13:09:46 +0000 (15:09 +0200)
committerRafal Krypa <r.krypa@samsung.com>
Mon, 23 Jun 2014 18:00:15 +0000 (20:00 +0200)
This functionality was needed in security-server to log user space Smack
checks consistently with logs generated by kernel.
Security-manager will never perform such checks.

Change-Id: Ifcc67228b85dedba33330710d1e763dbdfadd996
Signed-off-by: Rafal Krypa <r.krypa@samsung.com>
13 files changed:
packaging/security-manager.spec
security-manager-audit.conf [deleted file]
src/server/CMakeLists.txt
src/server/dpl/log/include/dpl/log/abstract_log_provider.h
src/server/dpl/log/include/dpl/log/audit-smack-log.h [deleted file]
src/server/dpl/log/include/dpl/log/dlog_log_provider.h
src/server/dpl/log/include/dpl/log/log.h
src/server/dpl/log/include/dpl/log/old_style_log_provider.h
src/server/dpl/log/src/audit-smack-log.cpp [deleted file]
src/server/dpl/log/src/dlog_log_provider.cpp
src/server/dpl/log/src/log.cpp
src/server/dpl/log/src/old_style_log_provider.cpp
src/server/main/server2-main.cpp

index 302bc23..b4b44ac 100644 (file)
@@ -62,8 +62,6 @@ rm -rf %{buildroot}
 mkdir -p %{buildroot}/usr/share/license
 cp LICENSE %{buildroot}/usr/share/license/%{name}
 cp LICENSE %{buildroot}/usr/share/license/libsecurity-manager-client
-mkdir -p %{buildroot}/etc/security/
-cp security-manager-audit.conf %{buildroot}/etc/security/
 mkdir -p %{buildroot}/etc/smack/
 cp app-rules-template.smack %{buildroot}/etc/smack/
 %make_install
@@ -114,7 +112,6 @@ fi
 %attr(-,root,root) /usr/lib/systemd/system/security-manager.target
 %attr(-,root,root) /usr/lib/systemd/system/sockets.target.wants/security-manager-installer.socket
 %attr(-,root,root) /usr/lib/systemd/system/security-manager-installer.socket
-%attr(-,root,root) /etc/security/security-manager-audit.conf
 %attr(-,root,root) /etc/smack/app-rules-template.smack
 %{_datadir}/license/%{name}
 
diff --git a/security-manager-audit.conf b/security-manager-audit.conf
deleted file mode 100644 (file)
index c977fda..0000000
+++ /dev/null
@@ -1 +0,0 @@
-10 524288
index c52f61b..73e3c00 100644 (file)
@@ -13,7 +13,6 @@ SET(COMMON_SOURCES
     ${COMMON_PATH}/dpl/log/src/dlog_log_provider.cpp
     ${COMMON_PATH}/dpl/log/src/log.cpp
     ${COMMON_PATH}/dpl/log/src/old_style_log_provider.cpp
-    ${COMMON_PATH}/dpl/log/src/audit-smack-log.cpp
     ${COMMON_PATH}/dpl/core/src/assert.cpp
     ${COMMON_PATH}/dpl/core/src/binary_queue.cpp
     ${COMMON_PATH}/dpl/core/src/colors.cpp
index cfe9679..a3ad299 100644 (file)
@@ -67,10 +67,6 @@ class AbstractLogProvider
                        const char *fileName,
                        int line,
                        const char *function) = 0;
-    virtual void SmackAudit(const char *message,
-                       const char *fileName,
-                       int line,
-                       const char *function) = 0;
 
   protected:
     static const char *LocateSourceFileName(const char *filename);
diff --git a/src/server/dpl/log/include/dpl/log/audit-smack-log.h b/src/server/dpl/log/include/dpl/log/audit-smack-log.h
deleted file mode 100644 (file)
index 98fdc15..0000000
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- *  Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved
- *
- *  Contact: Bumjin Im <bj.im@samsung.com>
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License
- */
-/*
- * @file        audit-smack-log.h
- * @author      Marek Smolinski (m.smolinski@samsung.com)
- * @version     1.0
- * @brief       AuditSmackLog loging SMACK access deny sequentially into files
- */
-
-#ifndef _AUDIT_SMACK_LOG_
-#define _AUDIT_SMACK_LOG_
-
-#include <dpl/log/abstract_log_provider.h>
-
-#include <map>
-#include <fstream>
-#include <mutex>
-#include <memory>
-#include <functional>
-
-namespace SecurityManager {
-namespace Log {
-
-class AuditSmackLog :
-    public AbstractLogProvider
-{
-public:
-    AuditSmackLog();
-    virtual ~AuditSmackLog();
-
-    bool Fail() const;
-
-    virtual void Debug(const char *message,
-                       const char *fileName,
-                       int line,
-                       const char *function);
-    virtual void Info(const char *message,
-                      const char *fileName,
-                      int line,
-                      const char *function);
-    virtual void Warning(const char *message,
-                         const char *fileName,
-                         int line,
-                         const char *function);
-    virtual void Error(const char *message,
-                       const char *fileName,
-                       int line,
-                       const char *function);
-    virtual void Pedantic(const char *message,
-                          const char *fileName,
-                          int line,
-                          const char *function);
-    virtual void SecureDebug(const char *message,
-                             const char *fileName,
-                             int line,
-                             const char *function);
-    virtual void SecureInfo(const char *message,
-                            const char *fileName,
-                            int line,
-                            const char *function);
-    virtual void SecureWarning(const char *message,
-                              const char *fileName,
-                              int line,
-                              const char *function);
-    virtual void SecureError(const char *message,
-                             const char *fileName,
-                             int line,
-                             const char *function);
-
-    virtual void SmackAudit(const char *message,
-                            const char *fileName,
-                            int line,
-                            const char *function);
-
-private:
-    void HandleWrite(const char *message,
-                     const char *fileName,
-                     int line,
-                     const char *function);
-
-    int CreateLogFile();
-    int RemoveOldestLogFile();
-    int ParseConfig();
-    int ProcessLogDir();
-    bool IsFileFull(std::ofstream &fs) const;
-
-    bool m_state;
-    unsigned int m_filesCount;
-    unsigned int m_fileMaxBytesSize;
-
-    std::map<time_t, std::string> m_fileNameMap;
-    std::ofstream m_outputStream;
-
-    std::mutex m_writeMtx;
-};
-
-}  // namespace Log
-}  // namespace SecurityManager
-#endif  // _AUDIT_SMACK_LOG_
index 6fe0d97..6b19e09 100644 (file)
@@ -79,10 +79,6 @@ class DLOGLogProvider :
                        const char *fileName,
                        int line,
                        const char *function);
-    virtual void SmackAudit(const char *message,
-                       const char *fileName,
-                       int line,
-                       const char *function);
 
     // Set global Tag according to DLOG
     void SetTag(const char *tag);
index 2594ace..74792cc 100644 (file)
@@ -123,14 +123,6 @@ class LogSystem :
                const char *function);
 
     /**
-     * Log SS_SMACK into files
-     */
-     void SmackAudit(const char *message,
-                      const char *fileName,
-                      int line,
-                      const char *function);
-
-    /**
      * Set default's DLOG provider Tag
      */
     void SetTag(const char *tag);
@@ -199,8 +191,6 @@ do                                                                         \
 #define  LogError(message) DPL_MACRO_FOR_LOGGING(message, Error)
 #define  LogSecureError(message) DPL_MACRO_FOR_LOGGING(message, SecureError)
 
-#define  LogSmackAudit(message) DPL_MACRO_FOR_LOGGING(message, SmackAudit)
-
 #ifdef BUILD_TYPE_DEBUG
     #define LogDebug(message) DPL_MACRO_FOR_LOGGING(message, Debug)
     #define LogInfo(message) DPL_MACRO_FOR_LOGGING(message, Info)
index 8ca2068..da1117a 100644 (file)
@@ -93,10 +93,6 @@ class OldStyleLogProvider :
                        const char *fileName,
                        int line,
                        const char *function);
-    virtual void SmackAudit(const char *message,
-                      const char *fileName,
-                      int line,
-                      const char *function);
 };
 }
 } // namespace SecurityManager
diff --git a/src/server/dpl/log/src/audit-smack-log.cpp b/src/server/dpl/log/src/audit-smack-log.cpp
deleted file mode 100644 (file)
index 1d03b6f..0000000
+++ /dev/null
@@ -1,310 +0,0 @@
-/*
- *  Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved
- *
- *  Contact: Bumjin Im <bj.im@samsung.com>
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License
- */
-/*
- * @file        audit-smack-log.cpp
- * @author      Marek Smolinski (m.smolinski@samsung.com)
- * @version     1.0
- * @brief       AuditSmackLog loging SMACK access deny sequentially into files
- */
-
-#include <iostream>
-#include <fstream>
-#include <map>
-#include <cstring>
-#include <mutex>
-
-#include <dirent.h>
-#include <time.h>
-#include <errno.h>
-#include <unistd.h>
-#include <cassert>
-
-#include <sys/smack.h>
-#include <sys/stat.h>
-
-#include <dpl/log/audit-smack-log.h>
-#include <dpl/log/log.h>
-#include <dpl/fstream_accessors.h>
-
-#define UNUSED __attribute__((unused))
-
-namespace {
-
-const std::string AUDIT_CONFIG_LOG_PATH = "/etc/security/";
-const std::string AUDIT_CONFIG_FILENAME = "security-manager-audit.conf";
-const std::string AUDIT_LOG_DIRECTORY = "/var/log/audit/";
-const std::string AUDIT_LOG_FILENAME_PREFIX = "audit-smack";
-const std::string AUDIT_LOG_SMACK_LABEL = "security-manager::audit-files";
-
-} // namespace anonymous
-
-namespace SecurityManager {
-namespace Log {
-
-AuditSmackLog::AuditSmackLog()
-    : m_state(true), m_filesCount(0), m_fileMaxBytesSize(0)
-{
-    if (ParseConfig() != 0) {
-        goto error;
-    }
-
-    if (ProcessLogDir() != 0) {
-        goto error;
-    }
-
-    if (m_state) {
-
-        // reduce existing files count in log dir if config file was changed
-        while (m_fileNameMap.size() > m_filesCount) {
-            if (RemoveOldestLogFile() != 0) {
-                goto error;
-            }
-        }
-
-        if (m_fileNameMap.size() == 0) {
-            if (CreateLogFile() != 0) {
-                goto error;
-            }
-        } else {
-            std::string filename(AUDIT_LOG_DIRECTORY);
-            filename += m_fileNameMap.rbegin()->second;
-            m_outputStream.open(filename, std::ios_base::app);
-        }
-    }
-
-    return;
-
-error:
-    m_state = false;
-
-}
-
-AuditSmackLog::~AuditSmackLog(){}
-
-bool AuditSmackLog::Fail() const
-{
-    return !m_state;
-}
-
-void AuditSmackLog::SmackAudit(const char *message,
-                               const char *fileName,
-                               int line,
-                               const char *function)
-{
-    if (m_state) {
-        HandleWrite(message, fileName, line, function);
-    }
-}
-
-void AuditSmackLog::HandleWrite(const char *message,
-                                const char *filename,
-                                int line,
-                                const char *function)
-{
-    std::lock_guard<std::mutex> lock(m_writeMtx);
-    if (IsFileFull(m_outputStream)) {
-        if (CreateLogFile() != 0) {
-            m_state = false;
-            return;
-        }
-
-        if (m_fileNameMap.size() > m_filesCount) {
-            if (RemoveOldestLogFile() != 0) {
-                m_state = false;
-                return;
-            }
-        }
-    }
-
-    m_outputStream << std::string("[") <<
-        LocateSourceFileName(filename) << std::string(":") << line <<
-        std::string("] ") << function << std::string("(): ") <<
-        message << std::endl;
-}
-
-int AuditSmackLog::CreateLogFile()
-{
-    time_t sec = time(NULL);
-    std::string fname(AUDIT_LOG_FILENAME_PREFIX);
-    std::string pathname(AUDIT_LOG_DIRECTORY);
-
-    fname += std::to_string(sec);
-    fname += ".log";
-    pathname += fname;
-
-    if (m_outputStream.is_open())
-        m_outputStream.close();
-
-    m_outputStream.open(pathname.c_str());
-
-    if (!m_outputStream) {
-        return -1;
-    }
-
-    if (smack_setlabel(pathname.c_str(),
-                       AUDIT_LOG_SMACK_LABEL.c_str(),
-                       SMACK_LABEL_ACCESS) != 0)  {
-        return -1;
-    }
-
-    m_fileNameMap.insert(std::make_pair(sec, fname));
-    return 0;
-}
-
-int AuditSmackLog::RemoveOldestLogFile()
-{
-    assert(m_fileNameMap.size() > 0);
-
-    auto it = m_fileNameMap.begin();
-    std::string filename(AUDIT_LOG_DIRECTORY);
-    filename += it->second;
-
-    if (unlink(filename.c_str()) == 0) {
-        m_fileNameMap.erase(it);
-        return 0;
-    }
-
-    return -1;
-}
-
-int AuditSmackLog::ParseConfig()
-{
-    struct stat sb;
-    if (stat(AUDIT_CONFIG_LOG_PATH.c_str(), &sb) != 0) {
-        return -1;
-    }
-
-    std::ifstream in(AUDIT_CONFIG_LOG_PATH + AUDIT_CONFIG_FILENAME,
-                     std::ios_base::in);
-    if (!in) {
-        return -1;
-    }
-
-    in >> m_filesCount >> m_fileMaxBytesSize;
-
-    if (in.fail()) {
-        return -1;
-    }
-
-    return (m_filesCount > 0 && m_fileMaxBytesSize > 0) ? 0 : -1;
-}
-
-int AuditSmackLog::ProcessLogDir()
-{
-    DIR *dir;
-    dirent *dp;
-
-    if ((dir = opendir(AUDIT_LOG_DIRECTORY.c_str())) == NULL) {
-        return -1;
-    }
-
-    while ((dp = readdir(dir)) != NULL) {
-        if (AUDIT_LOG_FILENAME_PREFIX.compare(0, std::string::npos,
-                                      dp->d_name,
-                                      AUDIT_LOG_FILENAME_PREFIX.size()) == 0) {
-            errno = 0;
-            char *pEnd;
-            time_t fUnxTime = static_cast<time_t>(
-                    strtoull(dp->d_name + AUDIT_LOG_FILENAME_PREFIX.size(),
-                             &pEnd, 10));
-
-            if (errno != 0) {
-                closedir(dir);
-                return -1;
-            }
-
-            m_fileNameMap.insert(
-                    std::make_pair(fUnxTime, std::string(dp->d_name)));
-        }
-    }
-
-    closedir(dir);
-
-    return 0;
-}
-
-bool AuditSmackLog::IsFileFull(std::ofstream &fs) const
-{
-    return fs.tellp() > m_fileMaxBytesSize;
-}
-
-void AuditSmackLog::Debug(const char *message UNUSED,
-                          const char *filename UNUSED,
-                          int line UNUSED,
-                          const char *function UNUSED)
-{
-}
-
-void AuditSmackLog::Info(const char *message UNUSED,
-                         const char *filename UNUSED,
-                         int line UNUSED,
-                         const char *function UNUSED)
-{
-}
-
-void AuditSmackLog::Warning(const char *message UNUSED,
-                            const char *filename UNUSED,
-                            int line UNUSED,
-                            const char *function UNUSED)
-{
-}
-
-void AuditSmackLog::Error(const char *message UNUSED,
-                          const char *filename UNUSED,
-                          int line UNUSED,
-                          const char *function UNUSED)
-{
-}
-
-void AuditSmackLog::Pedantic(const char *message UNUSED,
-                             const char *filename UNUSED,
-                             int line UNUSED,
-                             const char *function UNUSED)
-{
-}
-
-void AuditSmackLog::SecureDebug(const char *message UNUSED,
-                                const char *filename UNUSED,
-                                int line UNUSED,
-                                const char *function UNUSED)
-{
-}
-
-void AuditSmackLog::SecureInfo(const char *message UNUSED,
-                               const char *filename  UNUSED,
-                               int line  UNUSED,
-                               const char *function UNUSED)
-{
-}
-
-void AuditSmackLog::SecureWarning(const char *message UNUSED,
-                                  const char *filename UNUSED,
-                                  int line UNUSED,
-                                  const char *function UNUSED)
-{
-}
-
-void AuditSmackLog::SecureError(const char *message UNUSED,
-                                const char *filename UNUSED,
-                                int line UNUSED,
-                                const char *function UNUSED)
-{
-}
-
-} // namespace Log
-} // namespace SecurityManager
index c96dfd0..b2a59f9 100644 (file)
@@ -141,12 +141,5 @@ void DLOGLogProvider::SecureError(const char *message UNUSED,
         FormatMessage(message, filename, line, function).c_str());
 }
 
-void DLOGLogProvider::SmackAudit(const char *message UNUSED,
-                           const char *filename UNUSED,
-                           int line UNUSED,
-                           const char *function UNUSED)
-{
-}
-
 } // nemespace Log
 } // namespace SecurityManager
index 9ac65c0..a237fdb 100644 (file)
@@ -26,7 +26,6 @@
 #include <dpl/singleton_impl.h>
 #include <dpl/log/dlog_log_provider.h>
 #include <dpl/log/old_style_log_provider.h>
-#include <dpl/log/audit-smack-log.h>
 
 IMPLEMENT_SINGLETON(SecurityManager::Log::LogSystem)
 
@@ -277,18 +276,5 @@ void LogSystem::SecureWarning(const char *message,
     }
 }
 
-void LogSystem::SmackAudit(const char *message,
-                     const char *fileName,
-                     int line,
-                     const char *function)
-{
-    for (AbstractLogProviderPtrList::iterator iterator = m_providers.begin();
-         iterator != m_providers.end();
-         ++iterator)
-    {
-        (*iterator)->SmackAudit(message, fileName, line, function);
-    }
-}
-
 }
 } // namespace SecurityManager
index b3ea65a..0317862 100644 (file)
@@ -298,16 +298,5 @@ void OldStyleLogProvider::SecureError(const char *message,
 #endif
 }
 
-void OldStyleLogProvider::SmackAudit(const char *message,
-                               const char *fileName,
-                               int line,
-                               const char *function)
-{
-    (void)message;
-    (void)fileName;
-    (void)line;
-    (void)function;
-}
-
 }
 } // namespace SecurityManager
index 213f749..11a3f04 100644 (file)
@@ -25,7 +25,6 @@
 #include <signal.h>
 
 #include <dpl/log/log.h>
-#include <dpl/log/audit-smack-log.h>
 #include <dpl/singleton.h>
 #include <dpl/singleton_safe_impl.h>
 
@@ -67,15 +66,6 @@ int main(void) {
     {
         SecurityManager::Singleton<SecurityManager::Log::LogSystem>::Instance().SetTag("SECURITY_MANAGER");
 
-        // This provider may be used in security-manager only.
-        // If we add it inside LogSystem constructor it also
-        // will be used by security-manager-client library.
-        SecurityManager::Log::AuditSmackLog *smackLog = new SecurityManager::Log::AuditSmackLog;
-        if (smackLog->Fail())
-            delete smackLog;
-        else
-            SecurityManager::Singleton<SecurityManager::Log::LogSystem>::Instance().AddProvider(smackLog);
-
         sigset_t mask;
         sigemptyset(&mask);
         sigaddset(&mask, SIGTERM);