Add LogSecure* macros.
authorBartlomiej Grzelewski <b.grzelewski@samsung.com>
Fri, 19 Jul 2013 09:11:12 +0000 (11:11 +0200)
committerBartlomiej Grzelewski <b.grzelewski@samsung.com>
Thu, 6 Feb 2014 16:13:21 +0000 (17:13 +0100)
[Issue#]   SSDWSSP-392
[Bug]      N/A
[Cause]    N/A
[Problem]  Some security-server logs must marked as "secure".
[Solution] Add support for SECURE_SLOG macro in the project.

[Verification] Run tests.

Change-Id: Ic5b4058a39ff0c1acb191871b27bafaf25f3cad7

src/server2/client/client-socket-privilege.cpp
src/server2/dpl/log/include/dpl/log/abstract_log_provider.h
src/server2/dpl/log/include/dpl/log/dlog_log_provider.h
src/server2/dpl/log/include/dpl/log/log.h
src/server2/dpl/log/include/dpl/log/old_style_log_provider.h
src/server2/dpl/log/src/dlog_log_provider.cpp
src/server2/dpl/log/src/log.cpp
src/server2/dpl/log/src/old_style_log_provider.cpp

index 2ac617e..bae2b58 100644 (file)
@@ -110,7 +110,7 @@ int security_server_check_privilege_by_sockfd(int sockfd,
 
     ret = security_server_check_privilege_by_pid(cr.pid, object, access_rights);
 
-    SECURE_LOGD("security_server_check_privilege_by_pid returned %d", ret);
+    LogSecureDebug("security_server_check_privilege_by_pid returned " << ret);
 
 exit:
     //Getting path for logs
@@ -118,11 +118,15 @@ exit:
         //If this is only for logs, do we want to log it as error?
         LogError("Failed to read executable path for process " << cr.pid);
     if (ret == SECURITY_SERVER_API_SUCCESS)
-        SECURE_LOGD("SS_SMACK: caller_pid=%d, subject=%s, object=%s, access=%s, result=%d, caller_path=%s",
-                cr.pid, subject_p.get() ? subject_p.get() : "NULL", object, access_rights, ret, path.c_str());
+        LogSecureDebug("SS_SMACK: caller_pid=" << cr.pid << ", subject=" <<
+            (subject_p.get() ? subject_p.get() : "NULL") << ", object=" <<
+            object << ", access=" << access_rights << ", result=" <<
+            ret << ", caller_path=" << path.c_str());
     else
-        SECURE_LOGW("SS_SMACK: caller_pid=%d, subject=%s, object=%s, access=%s, result=%d, caller_path=%s",
-                cr.pid, subject_p.get() ? subject_p.get() : "NULL", object, access_rights, ret, path.c_str());
+        LogSecureWarning("SS_SMACK: caller_pid=" << cr.pid << ", subject=" <<
+            (subject_p.get() ? subject_p.get() : "NULL") << ", object=" <<
+            object << ", access=" << access_rights << ", result=" <<
+            ret << ", caller_path=" << path.c_str());
 
     return ret;
 }
index 6a32169..312d416 100644 (file)
@@ -49,6 +49,22 @@ class AbstractLogProvider
                           const char *fileName,
                           int line,
                           const char *function) = 0;
+    virtual void SecureDebug(const char *message,
+                       const char *fileName,
+                       int line,
+                       const char *function) = 0;
+    virtual void SecureInfo(const char *message,
+                      const char *fileName,
+                      int line,
+                      const char *function) = 0;
+    virtual void SecureWarning(const char *message,
+                         const char *fileName,
+                         int line,
+                         const char *function) = 0;
+    virtual void SecureError(const char *message,
+                       const char *fileName,
+                       int line,
+                       const char *function) = 0;
 
   protected:
     static const char *LocateSourceFileName(const char *filename);
index db0f0b9..e569bf7 100644 (file)
@@ -63,6 +63,22 @@ class DLOGLogProvider :
                           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);
 
     // Set global Tag according to DLOG
     void SetTag(const char *tag);
index d3a3009..2478d1f 100644 (file)
@@ -96,6 +96,38 @@ class LogSystem :
                   const char *function);
 
     /**
+     * Log pedantic message with secure macro
+     */
+    void SecureDebug(const char *message,
+               const char *filename,
+               int line,
+               const char *function);
+
+    /**
+     * Log info message with secure macro
+     */
+    void SecureInfo(const char *message,
+              const char *filename,
+              int line,
+              const char *function);
+
+    /**
+     * Log warning message with secure macro
+     */
+    void SecureWarning(const char *message,
+                 const char *filename,
+                 int line,
+                 const char *function);
+
+    /**
+     * Log error message with secure macro
+     */
+    void SecureError(const char *message,
+               const char *filename,
+               int line,
+               const char *function);
+
+    /**
      * Set default's DLOG provider Tag
      */
     void SetTag(const char *tag);
@@ -167,5 +199,9 @@ typedef Singleton<LogSystem> LogSystemSingleton;
 #define  LogWarning(message) DPL_MACRO_FOR_LOGGING(message, Warning)
 #define  LogError(message) DPL_MACRO_FOR_LOGGING(message, Error)
 #define  LogPedantic(message) DPL_MACRO_FOR_LOGGING(message, Pedantic)
+#define  LogSecureDebug(message) DPL_MACRO_FOR_LOGGING(message, SecureDebug)
+#define  LogSecureInfo(message) DPL_MACRO_FOR_LOGGING(message, SecureInfo)
+#define  LogSecureWarning(message) DPL_MACRO_FOR_LOGGING(message, SecureWarning)
+#define  LogSecureError(message) DPL_MACRO_FOR_LOGGING(message, SecureError)
 
 #endif // SECURITYSERVER_LOG_H
index a3b9784..42673a4 100644 (file)
@@ -77,6 +77,22 @@ class OldStyleLogProvider :
                           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);
 };
 }
 } // namespace SecurityServer
index 5a26d24..2b79f84 100644 (file)
@@ -102,5 +102,42 @@ void DLOGLogProvider::Pedantic(const char *message,
                                               line,
                                               function).c_str());
 }
+
+void DLOGLogProvider::SecureDebug(const char *message,
+                            const char *filename,
+                            int line,
+                            const char *function)
+{
+    SECURE_SLOG(LOG_DEBUG, m_tag.get(), "%s",
+        FormatMessage(message, filename, line, function).c_str());
+}
+
+void DLOGLogProvider::SecureInfo(const char *message,
+                           const char *filename,
+                           int line,
+                           const char *function)
+{
+    SECURE_SLOG(LOG_INFO, m_tag.get(), "%s",
+        FormatMessage(message, filename, line, function).c_str());
+}
+
+void DLOGLogProvider::SecureWarning(const char *message,
+                              const char *filename,
+                              int line,
+                              const char *function)
+{
+    SECURE_SLOG(LOG_WARN, m_tag.get(), "%s",
+        FormatMessage(message, filename, line, function).c_str());
+}
+
+void DLOGLogProvider::SecureError(const char *message,
+                            const char *filename,
+                            int line,
+                            const char *function)
+{
+    SECURE_SLOG(LOG_ERROR, m_tag.get(), "%s",
+        FormatMessage(message, filename, line, function).c_str());
+}
+
 }
 } // namespace SecurityServer
index f066bcd..13330b8 100644 (file)
@@ -35,7 +35,7 @@ const char *OLD_STYLE_LOGS_ENV_NAME = "DPL_USE_OLD_STYLE_LOGS";
 const char *OLD_STYLE_PEDANTIC_LOGS_ENV_NAME =
     "DPL_USE_OLD_STYLE_PEDANTIC_LOGS";
 const char *OLD_STYLE_LOGS_MASK_ENV_NAME = "DPL_USE_OLD_STYLE_LOGS_MASK";
-const char *SecurityServer_LOG_OFF = "DPL_LOG_OFF";
+const char *SECURITY_SERVER_LOG_OFF = "DPL_LOG_OFF";
 } // namespace anonymous
 
 bool LogSystem::IsLoggingEnabled() const
@@ -46,7 +46,7 @@ bool LogSystem::IsLoggingEnabled() const
 LogSystem::LogSystem() :
     m_dlogProvider(NULL),
     m_oldStyleProvider(NULL),
-    m_isLoggingEnabled(!getenv(SecurityServer_LOG_OFF))
+    m_isLoggingEnabled(!getenv(SECURITY_SERVER_LOG_OFF))
 {
     bool oldStyleLogs = false;
     bool oldStyleDebugLogs = true;
@@ -220,5 +220,57 @@ void LogSystem::Pedantic(const char *message,
         (*iterator)->Pedantic(message, filename, line, function);
     }
 }
+
+void LogSystem::SecureInfo(const char *message,
+                         const char *filename,
+                         int line,
+                         const char *function)
+{
+    for (AbstractLogProviderPtrList::iterator iterator = m_providers.begin();
+         iterator != m_providers.end();
+         ++iterator)
+    {
+        (*iterator)->SecureInfo(message, filename, line, function);
+    }
+}
+
+void LogSystem::SecureDebug(const char *message,
+                         const char *filename,
+                         int line,
+                         const char *function)
+{
+    for (AbstractLogProviderPtrList::iterator iterator = m_providers.begin();
+         iterator != m_providers.end();
+         ++iterator)
+    {
+        (*iterator)->SecureDebug(message, filename, line, function);
+    }
+}
+
+void LogSystem::SecureError(const char *message,
+                         const char *filename,
+                         int line,
+                         const char *function)
+{
+    for (AbstractLogProviderPtrList::iterator iterator = m_providers.begin();
+         iterator != m_providers.end();
+         ++iterator)
+    {
+        (*iterator)->SecureError(message, filename, line, function);
+    }
+}
+
+void LogSystem::SecureWarning(const char *message,
+                         const char *filename,
+                         int line,
+                         const char *function)
+{
+    for (AbstractLogProviderPtrList::iterator iterator = m_providers.begin();
+         iterator != m_providers.end();
+         ++iterator)
+    {
+        (*iterator)->SecureWarning(message, filename, line, function);
+    }
+}
 }
 } // namespace SecurityServer
index 34a73cc..f59f40e 100644 (file)
@@ -27,6 +27,7 @@
 #include <sstream>
 #include <sys/time.h>
 #include <unistd.h>
+#include <dlog.h>
 
 namespace SecurityServer {
 namespace Log {
@@ -196,5 +197,106 @@ void OldStyleLogProvider::Pedantic(const char *message,
         }
     }
 }
+
+void OldStyleLogProvider::SecureDebug(const char *message,
+                                const char *filename,
+                                int line,
+                                const char *function)
+{
+#ifdef _SECURE_LOG
+    if (m_showDebug) {
+        if (m_printStdErr) {
+            fprintf(stderr, "%s%s%s\n", DEBUG_BEGIN,
+                    FormatMessage(message, filename, line,
+                        function).c_str(), DEBUG_END);
+        } else {
+            fprintf(stdout, "%s%s%s\n", DEBUG_BEGIN,
+                    FormatMessage(message, filename, line,
+                        function).c_str(), DEBUG_END);
+        }
+    }
+#else
+    (void)message;
+    (void)filename;
+    (void)line;
+    (void)function;
+#endif
+}
+
+void OldStyleLogProvider::SecureInfo(const char *message,
+                               const char *filename,
+                               int line,
+                               const char *function)
+{
+#ifdef _SECURE_LOG
+    if (m_showInfo) {
+        if (m_printStdErr) {
+            fprintf(stderr, "%s%s%s\n", INFO_BEGIN,
+                    FormatMessage(message, filename, line,
+                        function).c_str(), INFO_END);
+        } else {
+            fprintf(stdout, "%s%s%s\n", INFO_BEGIN,
+                    FormatMessage(message, filename, line,
+                        function).c_str(), INFO_END);
+        }
+    }
+#else
+    (void)message;
+    (void)filename;
+    (void)line;
+    (void)function;
+#endif
+}
+
+void OldStyleLogProvider::SecureWarning(const char *message,
+                                  const char *filename,
+                                  int line,
+                                  const char *function)
+{
+#ifdef _SECURE_LOG
+    if (m_showWarning) {
+        if (m_printStdErr) {
+            fprintf(stderr, "%s%s%s\n", WARNING_BEGIN,
+                    FormatMessage(message, filename, line,
+                        function).c_str(), WARNING_END);
+        } else {
+            fprintf(stdout, "%s%s%s\n", WARNING_BEGIN,
+                    FormatMessage(message, filename, line,
+                        function).c_str(), WARNING_END);
+        }
+    }
+#else
+    (void)message;
+    (void)filename;
+    (void)line;
+    (void)function;
+#endif
+}
+
+void OldStyleLogProvider::SecureError(const char *message,
+                                const char *filename,
+                                int line,
+                                const char *function)
+{
+#ifdef _SECURE_LOG
+    if (m_showError) {
+        if (m_printStdErr) {
+            fprintf(stderr, "%s%s%s\n", ERROR_BEGIN,
+                    FormatMessage(message, filename, line,
+                        function).c_str(), ERROR_END);
+        } else {
+            fprintf(stdout, "%s%s%s\n", ERROR_BEGIN,
+                    FormatMessage(message, filename, line,
+                        function).c_str(), ERROR_END);
+        }
+    }
+#else
+    (void)message;
+    (void)filename;
+    (void)line;
+    (void)function;
+#endif
+}
+
 }
 } // namespace SecurityServer