integrate privacy-guard with cynara-monitor 56/70056/3
authorKyoungyong Lee <bluevox@naver.com>
Wed, 18 May 2016 01:55:44 +0000 (10:55 +0900)
committerKyoungyong Lee <bluevox@naver.com>
Wed, 18 May 2016 08:15:14 +0000 (17:15 +0900)
Change-Id: I89292e186dc8a7d35308e8bcad0677a04eb56459

16 files changed:
client/src/privacy_guard_client.cpp
common/inc/PrivacyGuardTypes.h
packaging/privacy-guard-server.service
packaging/privacy-guard-server.socket
packaging/privacy-guard.spec
res/usr/bin/privacy_guard_create_clean_db.sh
server/CMakeLists.txt
server/inc/CynaraService.h
server/inc/PrivacyGuardDaemon.h
server/inc/PrivacyGuardDb.h
server/src/CMakeLists.txt [deleted file]
server/src/CynaraService.cpp
server/src/PrivacyGuardDaemon.cpp
server/src/PrivacyGuardDb.cpp
server/src/SocketService.cpp
server/src/main.cpp

index e347226..cb3ef83 100755 (executable)
@@ -118,7 +118,7 @@ int privacy_guard_client_foreach_total_privacy_count_of_package(const int user_i
                const time_t end_date, privacy_guard_client_privacy_count_of_package_cb callback, void *user_data)
 {
        if (user_id < 0 || start_date > end_date || start_date <= 0) {
-               PG_LOGE("Invalid parameters.");
+               PG_LOGE("Invalid parameters. user id: [%d], start date: [%d], end date: [%d]", user_id, start_date, end_date);
                return PRIV_GUARD_ERROR_INVALID_PARAMETER;
        }
 
index c241987..bf72ff6 100755 (executable)
@@ -23,6 +23,9 @@
 
 #define PRIVACY_DB_PATH         tzplatform_mkpath(TZ_SYS_DB,".privacy_guard.db")
 
+//#define CYNARA_BUFFER_SIZE 1024
+#define CYNARA_BUFFER_SIZE 10
+
 typedef struct _privacy_data_s {
        char *privacy_id;
        int monitor_policy;
@@ -34,7 +37,6 @@ typedef struct _package_data_s {
        int monitor_policy;
 } package_data_s;
 
-
 static const std::string SERVER_ADDRESS ("/tmp/privacy_guard_server");
 static const std::string DBUS_PATH("/privacy_guard/dbus_notification");
 static const std::string DBUS_SIGNAL_INTERFACE("org.tizen.privacy_guard.signal");
index 3d6b105..60806f6 100755 (executable)
@@ -2,8 +2,8 @@
 Description=Privacy Guard Server
 
 [Service]
-User=system
-Group=system
+User=security_fw
+Group=security_fw
 Type=simple
 ExecStart=/usr/bin/privacy-guard-server
 Sockets=privacy-guard-server.socket
index 9d165a2..88c9086 100755 (executable)
@@ -2,8 +2,8 @@
 Description=Privacy Guard Socket
 
 [Socket]
-SocketUser=system
-SocketGroup=system
+SocketUser=security_fw
+SocketGroup=security_fw
 ListenStream=/tmp/privacy_guard_server
 SocketMode=0777
 
index 30a23d9..525bf06 100755 (executable)
@@ -1,5 +1,5 @@
 Name:           privacy-guard-server
-Version:        0.0.1
+Version:        0.0.5
 Release:        1
 License:        Apache-2.0
 Summary:        Privacy Management
index 648e21d..84faa11 100755 (executable)
@@ -23,8 +23,8 @@ do
     SQL=".read ${TZ_SYS_BIN}/"$name"_db.sql"
     sqlite3 ${TZ_SYS_DB}/.$name.db "$SQL"
     touch ${TZ_SYS_DB}/.$name.db-journal
-    chown system:system ${TZ_SYS_DB}/.$name.db
-    chown system:system ${TZ_SYS_DB}/.$name.db-journal
+    chown security_fw:security_fw ${TZ_SYS_DB}/.$name.db
+    chown security_fw:security_fw ${TZ_SYS_DB}/.$name.db-journal
     chmod 666 ${TZ_SYS_DB}/.$name.db
     chmod 666 ${TZ_SYS_DB}/.$name.db-journal
 done
index 20c9d64..2d3e54d 100755 (executable)
@@ -8,6 +8,7 @@ SET(INCLUDEDIR "\${prefix}/include")
 
 INCLUDE(FindPkgConfig)
 pkg_check_modules(pkgs REQUIRED dlog sqlite3 dbus-1 dbus-glib-1 db-util pkgmgr-info capi-system-info libtzplatform-config security-privilege-manager cynara-monitor)
+#pkg_check_modules(pkgs REQUIRED dlog sqlite3 dbus-1 dbus-glib-1 db-util pkgmgr-info capi-system-info libtzplatform-config security-privilege-manager)
 
 FOREACH(flag ${pkgs_CFLAGS})
        SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
@@ -50,14 +51,14 @@ INCLUDE_DIRECTORIES(
        ${dbus_include_dir}
        )
 
-SET(PRIVACY_GUARD_SERVER_SOURCES 
+SET(PRIVACY_GUARD_SERVER_SOURCES
        ${common_src_dir}/SocketConnection.cpp
        ${common_src_dir}/SocketStream.cpp
-       ${common_src_dir}/PrivacyIdInfo.cpp     
+       ${common_src_dir}/PrivacyIdInfo.cpp
        ${server_src_dir}/PrivacyGuardDb.cpp
        ${server_src_dir}/main.cpp
        ${server_src_dir}/SocketService.cpp
-#      ${server_src_dir}/CynaraService.cpp
+       ${server_src_dir}/CynaraService.cpp
        ${server_src_dir}/PrivacyGuardDaemon.cpp
        ${server_src_dir}/service/PrivacyInfoService.cpp
        ${server_src_dir}/NotificationServer.cpp
index aced859..f9c6a6b 100755 (executable)
@@ -14,8 +14,8 @@
  *    limitations under the License.
  */
 
-#ifndef _CYNARASERVICE_H_
-#define _CYNARASERVICE_H_
+#ifndef _CYNARA_SERVICE_H_
+#define _CYNARA_SERVICE_H_
 
 #include <string>
 #include <mutex>
@@ -33,7 +33,7 @@ private:
 
 private:
        static void* getEntriesThread(void* );
-       static void* flushThread(void* );
+//     static void* flushThread(void* );
 public:
        CynaraService(void);
        ~CynaraService(void);
@@ -44,4 +44,4 @@ public:
        static int updateDb(cynara_monitor_entry** monitor_entries);
 };
 
-#endif //_CYNARASERVICE_H_
+#endif //_CYNARA_SERVICE_H_
\ No newline at end of file
index 281bdea..be0d1ce 100755 (executable)
 #include "privacy_guard_client_types.h"
 
 class SocketService;
-#if 0
 // [CYNARA]
 class CynaraService;
-#endif
 
 class EXTERN_API PrivacyGuardDaemon
 {
 private:
        static PrivacyGuardDaemon* pInstance;
        SocketService* pSocketService;
-#if 0
-       // [CYNARA]     
+       // [CYNARA]
        CynaraService* pCynaraService;
-#endif
 
 private:
        PrivacyGuardDaemon(void);
index c3e6b9f..a8a63c9 100755 (executable)
@@ -14,8 +14,8 @@
  *    limitations under the License.
  */
 
-#ifndef _PRIVACYGUARDDB_H_
-#define _PRIVACYGUARDDB_H_
+#ifndef _PRIVACY_GUARD_DB_H_
+#define _PRIVACY_GUARD_DB_H_
 
 #include <string>
 #include <memory>
@@ -46,7 +46,7 @@ public:
 
        int PgAddPrivacyAccessLog(const int userId, std::list < std::pair < std::string, std::string > > logInfoList);
 
-       int PgAddPrivacyAccessLogForCynara(const int userId, const std::string packageId, const std::string privilege, const timespec *timestamp);
+       int PgAddPrivacyAccessLogForCynara(const int userId, const std::string packageId, const std::string privilege, const time_t timestamp);
 
        int PgAddPrivacyAccessLogTest(const int userId, const std::string packageId, const std::string privacyId);
 
@@ -94,4 +94,4 @@ public:
 };
 
 
-#endif // _PRIVACYGUARDDB_H_
+#endif // _PRIVACY_GUARD_DB_H_
\ No newline at end of file
diff --git a/server/src/CMakeLists.txt b/server/src/CMakeLists.txt
deleted file mode 100755 (executable)
index b496320..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
-#PROJECT(privacy-guard-server)
-
-SET(CMAKE_INSTALL_PREFIX /usr)
-SET(PREFIX ${CMAKE_INSTALL_PREFIX})
-SET(EXEC_PREFIX "\${prefix}")
-SET(LIBDIR ${LIB_INSTALL_DIR})
-SET(INCLUDEDIR ${INCLUDE_INSTALL_DIR})
-SET(VERSION 0.0)
-
-SET(VERSION_MAJOR 0)
-SET(VERSION "${VERSION_MAJOR}.0.1")
-
-INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
-
-INCLUDE(FindPkgConfig)
-#pkg_check_modules(pkgs REQUIRED dlog pkgmgr-info cynara-monitor)
-pkg_check_modules(pkgs REQUIRED dlog pkgmgr-info)
-
-FOREACH(flag ${pkgs_CFLAGS})
-       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
-ENDFOREACH(flag)
-
-SET(CMAKE_C_FLAGS_PROFILING    " -g -pg")
-SET(CMAKE_CXX_FLAGS_PROFILING  " -std=c++0x -g -pg")
-SET(CMAKE_C_FLAGS_DEBUG        " -g")
-SET(CMAKE_CXX_FLAGS_DEBUG      " -std=c++0x -g")
-SET(CMAKE_C_FLAGS_RELEASE      " -g")
-SET(CMAKE_CXX_FLAGS_RELEASE    " -std=c++0x -g")
-SET(CMAKE_C_FLAGS_CCOV         " -g --coverage")
-SET(CMAKE_CXX_FLAGS_CCOV       " -std=c++0x -g --coverage")
-
-SET(src_dir "./")
-SET(include_dir "./../inc/")
-SET(common_src_dir "./../../common/src/")
-SET(common_include_dir "./../../common/inc/")
-
-## Additional flag
-ADD_DEFINITIONS("-fvisibility=hidden")
-ADD_DEFINITIONS("-Wall -Werror")
-ADD_DEFINITIONS("-DDLOG_ERROR_ENABLED")
-
-###################################################################################################
-## for libprivacy-guard-server.so (library)
-INCLUDE_DIRECTORIES(${pkgs_INCLUDE_DIRS})
-SET(PRIVACY_GUARD_SERVER_SOURCES 
-       ${src_dir}/main.cpp
-       ${src_dir}/SocketService.cpp
-#      ${src_dir}/CynaraService.cpp
-       ${src_dir}/PrivacyGuardDaemon.cpp
-       ${common_src_dir}/SocketConnection.cpp
-       ${common_src_dir}/SocketStream.cpp
-       )
-SET(PRIVACY_GUARD_SERVER_HEADERS
-       ${include_dir}/SocketService.h
-#      ${include_dir}/CynaraService.h  
-       ${include_dir}/PrivacyGuardDaemon.h
-       ${common_include_dir}/SocketConnection.h
-)
-SET(PRIVACY_GUARD_SERVER_LDFLAGS " -module -avoid-version ")
-SET(PRIVACY_GUARD_SERVER_CFLAGS  " ${CFLAGS} -fPIC -I${include_dir}" -I${common_include_dir})
-#SET(PRIVACY_GUARD_SERVER_LIBADD " ")
-
-ADD_EXECUTABLE(privacy-guard-server ${PRIVACY_GUARD_SERVER_SOURCES})
-TARGET_LINK_LIBRARIES(privacy-guard-server ${pkgs_LDFLAGS} ${pkgs_LIBRARIES})
-SET_TARGET_PROPERTIES(privacy-guard-server PROPERTIES COMPILE_FLAGS "${PRIVACY_GUARD_SERVER_CFLAGS}")
-SET_TARGET_PROPERTIES(privacy-guard-server PROPERTIES SOVERSION ${VERSION_MAJOR})
-SET_TARGET_PROPERTIES(privacy-guard-server PROPERTIES VERSION ${VERSION})
-###################################################################################################
-
-CONFIGURE_FILE(../../privacy-guard-server.pc.in privacy-guard-server.pc @ONLY)
-
-INSTALL(TARGETS privacy-guard-server DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries)
-INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/privacy-guard-server.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
-INSTALL(FILES ${PRIVACY_GUARD_SERVER_HEADERS} DESTINATION ${INCLUDE_INSTALL_DIR})
index e1c4d6d..4b8428b 100755 (executable)
@@ -38,29 +38,32 @@ CynaraService::CynaraService(void)
        : m_signalToClose(-1)
        , m_cynaraThread(-1)
 {
-
 }
 
 CynaraService::~CynaraService(void)
 {
-
 }
 
 int
 CynaraService::initialize(void)
 {
-       PG_LOGI("CynaraService initializing");
+       PG_LOGD("[cynara_service] CynaraService initializing");
 
        int res = cynara_monitor_configuration_create(&p_conf);
        if(res != CYNARA_API_SUCCESS){
-               PG_LOGE("cynara_monitor_configuration_create FAIL");
+               PG_LOGE("cynara_monitor_configuration_create() is failed.");
                return PRIV_GUARD_ERROR_SYSTEM_ERROR;
        }
-//     cynara_monitor_configuration_set_buffer_size(p_conf, buffer_size);
-//     res = cynara_monitor_initialize(&p_cynara_monitor, p_conf);
-       res = cynara_monitor_initialize(&p_cynara_monitor, nullptr);
+
+       res = cynara_monitor_configuration_set_buffer_size(p_conf, CYNARA_BUFFER_SIZE);
+       if(res != CYNARA_API_SUCCESS){
+               PG_LOGE("cynara_monitor_configuration_set_buffer_size() is failed.");
+               return PRIV_GUARD_ERROR_SYSTEM_ERROR;
+       }
+
+       res = cynara_monitor_initialize(&p_cynara_monitor, p_conf);
        if(res != CYNARA_API_SUCCESS){
-               PG_LOGE("cynara_monitor_initialize FAIL");
+               PG_LOGE("cynara_monitor_initialize() is failed.");
                return PRIV_GUARD_ERROR_SYSTEM_ERROR;
        }
 
@@ -74,7 +77,7 @@ CynaraService::initialize(void)
 int
 CynaraService::start(void)
 {
-       PG_LOGI("CynaraService starting");
+       PG_LOGI("[cynara_service] CynaraService starting");
 
        int res = 0;
        char buf[256];
@@ -99,43 +102,41 @@ void*
 CynaraService::getEntriesThread(void* pData)
 {
        pthread_detach(pthread_self());
-       PG_LOGI("Running get entries thread");
+       PG_LOGD("[cynara_service] Running get entries thread");
 
-       pthread_t testThread;
-       int result = pthread_create(&testThread, NULL, &flushThread, NULL);
-       if(result){
-               PG_LOGE("pthread_create FAIL");
+//     pthread_t testThread;
+//     int result = pthread_create(&testThread, NULL, &flushThread, NULL);
+//     if(result){
+//             PG_LOGE("pthread_create FAIL");
+//             return (void*) PRIV_GUARD_ERROR_SYSTEM_ERROR;
+//     }
+
+       // cynara_monitor_entries_get
+       // returned when the cynara buffer is full or cynara_monitor_entries_flush() is called from another thread
+       int res = cynara_monitor_entries_get(p_cynara_monitor, &monitor_entries);
+       if(res != CYNARA_API_SUCCESS){
+               PG_LOGE("cynara_monitor_entries_get FAIL");
                return (void*) PRIV_GUARD_ERROR_SYSTEM_ERROR;
        }
 
-//     while(1)
-//     {
-               // cynara_monitor_entries_get
-               int res = cynara_monitor_entries_get(p_cynara_monitor, &monitor_entries);
-               if(res != CYNARA_API_SUCCESS){
-                       PG_LOGE("cynara_monitor_entries_get FAIL");
-                       return (void*) PRIV_GUARD_ERROR_SYSTEM_ERROR;
-               }
-
-               res = CynaraService::updateDb(monitor_entries);
-               if(res != PRIV_GUARD_ERROR_SUCCESS){
-                       PG_LOGE("updateDb FAIL");
-                       return (void*) res;
-               }
-//     }
+       res = CynaraService::updateDb(monitor_entries);
+       if(res != PRIV_GUARD_ERROR_SUCCESS){
+               PG_LOGE("updateDb FAIL");
+               return (void*) res;
+       }
 
-       pthread_join(testThread, NULL);
+//     pthread_join(testThread, NULL);
 
        cynara_monitor_entries_free(monitor_entries);
 
        return (void*) 0;
 }
 
-void*
+/*void*
 CynaraService::flushThread(void* pData)
 {
        pthread_detach(pthread_self());
-       PG_LOGI("Running get flush thread");
+       PG_LOGD("Running get flush thread");
 
        for(int i = 0; i < 1000000000;i++);
 
@@ -145,37 +146,50 @@ CynaraService::flushThread(void* pData)
                return (void*) PRIV_GUARD_ERROR_SYSTEM_ERROR;
        }
        else{
-               PG_LOGI("cynara_monitor_entries_flush SUCCESS");
+               PG_LOGD("cynara_monitor_entries_flush SUCCESS");
        }
 
        return (void*) 0;
-}
+}*/
 
 int
-CynaraService::updateDb(cynara_monitor_entry** monitor_entries)
+CynaraService::updateDb(cynara_monitor_entry **monitor_entries)
 {
+       PG_LOGD("[cynara_service]");
+
        cynara_monitor_entry **entryIter = monitor_entries;
 
-       PG_LOGI("entryIter = %x", entryIter);
+       PG_LOGD("entryIter = %x", entryIter);
 
-// DB update
-               int userId = 0;
-               std::string packageId;
-       std::string privilege;
-       const timespec *timestamp = { 0 };;
+       // DB update
+       const char *user = NULL, *client = NULL, *privilege = NULL;
+       const timespec *timestamp = NULL;
+       int userId;
+       std::string packageId, privilegeId;
+       time_t date;
 
        while (*entryIter != nullptr) {
-               packageId = cynara_monitor_entry_get_client(*entryIter);
-               userId = (int)*cynara_monitor_entry_get_user(*entryIter);
+               user = cynara_monitor_entry_get_user(*entryIter);
+               TryReturn(user != NULL, PRIV_GUARD_ERROR_SYSTEM_ERROR, , "User Id in the entry is NULL");
+               client = cynara_monitor_entry_get_client(*entryIter);
+               TryReturn(user != NULL, PRIV_GUARD_ERROR_SYSTEM_ERROR, , "Package Id in the entry is NULL");
                privilege = cynara_monitor_entry_get_privilege(*entryIter);
+               TryReturn(user != NULL, PRIV_GUARD_ERROR_SYSTEM_ERROR, , "Privilege Id in the entry is NULL");
                timestamp = cynara_monitor_entry_get_timestamp(*entryIter);
+               TryReturn(user != NULL, PRIV_GUARD_ERROR_SYSTEM_ERROR, , "timestamp in the entry is NULL");
 
-               int ret = PrivacyGuardDb::getInstance()->PgAddPrivacyAccessLogForCynara(userId, packageId, privilege, timestamp);
+               userId = atoi(user);
+               packageId = client;
+               privilegeId = privilege;
+               date = timestamp->tv_sec;
+
+               // add access log
+               int ret = PrivacyGuardDb::getInstance()->PgAddPrivacyAccessLogForCynara(userId, packageId, privilegeId, date);
                if(ret != PRIV_GUARD_ERROR_SUCCESS){
                        PG_LOGE("PgAddPrivacyAccessLogForCynara FAIL");
                }
                else{
-                       PG_LOGI("PgAddPrivacyAccessLogForCynara SUCCESS");
+                       PG_LOGD("PgAddPrivacyAccessLogForCynara SUCCESS");
                }
 
                ++entryIter;
@@ -188,24 +202,38 @@ CynaraService::updateDb(cynara_monitor_entry** monitor_entries)
 int
 CynaraService::stop(void)
 {
-       PG_LOGI("Stopping");
+       PG_LOGD("begin");
 
        char buf[BUF_SIZE];
-       int returned_value;
-       if((returned_value = pthread_kill(m_cynaraThread, m_signalToClose)) < 0)
+       int ret;
+
+       if((ret = pthread_kill(m_cynaraThread, m_signalToClose)) < 0)
        {
-               errno = returned_value;
-               PG_LOGE("pthread_kill() : %s", strerror_r(errno, buf, sizeof(buf)));
+               //errno = ret;
+               //PG_LOGE("pthread_kill() : %s", strerror_r(errno, buf, sizeof(buf)));
+               PG_LOGE("pthread_kill() : %s", strerror_r(ret, buf, sizeof(buf)));
                return PRIV_GUARD_ERROR_IPC_ERROR;
        }
        pthread_join(m_cynaraThread, NULL);
 
-       PG_LOGI("Stopped");
+       ret = cynara_monitor_finish(p_cynara_monitor);
+       if(ret != CYNARA_API_SUCCESS){
+               PG_LOGE("cynara_monitor_finish() is failed. [%d]", ret);
+               return PRIV_GUARD_ERROR_SYSTEM_ERROR;
+       }
+
+       PG_LOGD("end");
        return PRIV_GUARD_ERROR_SUCCESS;
 }
 
 int
 CynaraService::shutdown(void)
 {
+       PG_LOGD("begin");
+
+       cynara_monitor_configuration_destroy(p_conf);
+
+       PG_LOGD("end");
+
        return PRIV_GUARD_ERROR_SUCCESS;
 }
index 9277098..525a539 100755 (executable)
 #include "PrivacyGuardDaemon.h"
 #include "PrivacyInfoService.h"
 #include "SocketService.h"
-#if 0
 // [CYNARA]
 #include <CynaraService.h>
-#endif
 
 PrivacyGuardDaemon* PrivacyGuardDaemon::pInstance = NULL;
 
@@ -37,6 +35,8 @@ PrivacyGuardDaemon::~PrivacyGuardDaemon(void)
 PrivacyGuardDaemon*
 PrivacyGuardDaemon::getInstance(void)
 {
+       PG_LOGD("called");
+
        if (pInstance == NULL)
                pInstance = new PrivacyGuardDaemon();
        return pInstance;
@@ -45,20 +45,23 @@ PrivacyGuardDaemon::getInstance(void)
 int
 PrivacyGuardDaemon::initialize(void)
 {
+       PG_LOGD("called");
+
        if (pSocketService == NULL)
                pSocketService = new SocketService();
-#if 0
+
+       PG_LOGD("calling pSocketService->initialize()");
+       pSocketService->initialize();
+
+       PG_LOGD("calling PrivacyInfoService::registerCallbacks(pSocketService)");
+       PrivacyInfoService::registerCallbacks(pSocketService);
+
        // [CYNARA]
        if (pCynaraService == NULL)
                pCynaraService = new CynaraService();
-#endif
-       pSocketService->initialize();
-#if 0
-       // [CYNARA]
-       pCynaraService->initialize();
-#endif
 
-       PrivacyInfoService::registerCallbacks(pSocketService);
+       PG_LOGD("calling pCynaraService->initialize()");
+       pCynaraService->initialize();
 
        return 0;
 }
@@ -68,32 +71,34 @@ PrivacyGuardDaemon::start(void)
 {
        int res = 0;
 
+       PG_LOGD("calling pSocketService->start()");
        if (pSocketService == NULL)
                return PRIV_GUARD_ERROR_NOT_INITIALIZED;
        res = pSocketService->start();
        if(res != PRIV_GUARD_ERROR_SUCCESS){
                PG_LOGE("FAIL");
        }
-#if 0
+
        // [CYNARA]
+/*     PG_LOGD("calling pCynaraService->start()");
        if (pCynaraService == NULL)
                return PRIV_GUARD_ERROR_NOT_INITIALIZED;
        res = pCynaraService->start();
        if(res != PRIV_GUARD_ERROR_SUCCESS){
                PG_LOGE("FAIL");
        }
-#endif
+*/
        return res;
 }
 
 int
 PrivacyGuardDaemon::stop(void)
 {
+       PG_LOGD("calling pSocketService->stop()");
        pSocketService->stop();
-#if 0
-       // [CYNARA]
-       pCynaraService->stop();
-#endif
+
+//     PG_LOGD("calling pCynaraService->stop()");
+//     pCynaraService->stop();
 
        return 0;
 }
@@ -101,6 +106,10 @@ PrivacyGuardDaemon::stop(void)
 int
 PrivacyGuardDaemon::shutdown(void)
 {
+       PG_LOGD("calling pSocketService->shutdown()");
        pSocketService->shutdown();
+//     PG_LOGD("calling pCynaraService->shutdown()");
+//     pCynaraService->shutdown();
+
        return 0;
 }
index 5d6fe5c..90108ad 100755 (executable)
 #include <pkgmgr-info.h>
 #include <time.h>
 #include <privilege_info.h>
+#include <cynara-monitor.h>
 #include "Utils.h"
 #include "PrivacyGuardDb.h"
 #include "PrivacyIdInfo.h"
 
+
 #define PRIVACY_GUARD_DAYS 7
 #define UNIX_TIME_ONE_DAY (24 * 60 * 60) // 86400 secs
 
-#if 0
-// [CYNARA]
-#include "CynaraService.h"
-
-//static cynara_monitor_configuration *p_conf;
-static cynara_monitor *p_cynara_monitor;
-static cynara_monitor_entry **monitor_entries;
-#endif
-
 std::mutex PrivacyGuardDb::m_singletonMutex;
 PrivacyGuardDb* PrivacyGuardDb::m_pInstance = NULL;
 GList *PrivacyGuardDb::m_privacy_list = NULL;
 
+static cynara_monitor_configuration *p_conf;
+static cynara_monitor *p_cynara_monitor;
+
 void
 PrivacyGuardDb::initialize(void)
 {
+       m_bInitialized = false;
+
+       // get privacy list
        int res = privilege_info_get_privacy_list(&m_privacy_list);
        if (res != PRVMGR_ERR_NONE) {
                PG_LOGE("Failed to get privacy list from security-privilege-manager [%d].", res);
+               //return PRIV_GUARD_ERROR_SYSTEM_ERROR;
+               return;
+       }
+
+       // cynara initialize
+       res = cynara_monitor_configuration_create(&p_conf);
+       if(res != CYNARA_API_SUCCESS){
+               PG_LOGE("cynara_monitor_configuration_create() is failed.");
+               //return PRIV_GUARD_ERROR_SYSTEM_ERROR;
+               return;
+       }
+
+       res = cynara_monitor_initialize(&p_cynara_monitor, p_conf);
+       if(res != CYNARA_API_SUCCESS){
+               PG_LOGE("cynara_monitor_initialize() is failed.");
+               //return PRIV_GUARD_ERROR_SYSTEM_ERROR;
                return;
        }
 
@@ -129,29 +144,32 @@ PrivacyGuardDb::PgAddPrivacyAccessLog(const int userId, std::list < std::pair <
 }
 
 int
-PrivacyGuardDb::PgAddPrivacyAccessLogForCynara(const int userId, const std::string packageId, const std::string privilege, const timespec* timestamp)
+PrivacyGuardDb::PgAddPrivacyAccessLogForCynara(const int userId, const std::string packageId, const std::string privilegeId, const time_t date)
 {
-       ////////////////////////////////////////////////
-       // check userId, packageId, privilege here..
-       ////////////////////////////////////////////////
-       if(timestamp->tv_sec <= 0) {
-               PG_LOGE("Invalid timestamp value: [%d]", timestamp->tv_sec);
+       if(userId < 0 || date <= 0) {
+               PG_LOGE("Invalid parameter: userId: [%d], date: [%d]", userId, date);
                return PRIV_GUARD_ERROR_INVALID_PARAMETER;
        }
 
-       int res = SQLITE_OK;
+       int res = -1;
+       std::string privacyId;
 
        // change from privilege to privacy
-       std::string privacyId;
-       res = PrivacyIdInfo::getPrivacyIdFromPrivilege(privilege, privacyId);
+       res = PrivacyIdInfo::getPrivacyIdFromPrivilege(privilegeId, privacyId);
        if (res == PRIV_GUARD_ERROR_NO_DATA) {
+               PG_LOGD("Input privilege[%s] is not related to any privacy. So skip it.", privilegeId.c_str());
                return PRIV_GUARD_ERROR_SUCCESS;
        }
-       TryReturn( res == PRIV_GUARD_ERROR_SUCCESS, res, , "getPrivacyIdFromPrivilege : %d", res);
+       TryReturn(res == PRIV_GUARD_ERROR_SUCCESS, res, , "getPrivacyIdFromPrivilege is failed: [%d]", res);
 
-       // change from timespec to time_t
-       time_t logging_date;
-       logging_date = timestamp->tv_sec;
+       // check monitor policy using userId, packageId, privacyId
+       int monitorPolicy;
+       res = PgGetMonitorPolicy(userId, packageId, privacyId, monitorPolicy);
+       TryReturn(res == PRIV_GUARD_ERROR_SUCCESS, res, , "PgGetMonitorPolicy is failed: [%d]", res);
+       if (monitorPolicy == 0) {
+               PG_LOGD("Monitor Policy is 0. So skip it. UserId:[%d], PrivacyId:[%s], PackageId:[%s], Policy:[%d]", userId, privacyId.c_str(), packageId.c_str(), monitorPolicy);
+               return PRIV_GUARD_ERROR_SUCCESS;
+       }
 
        static const std::string QUERY_INSERT = std::string("INSERT INTO StatisticsMonitorInfo(USER_ID, PKG_ID, PRIVACY_ID, USE_DATE) VALUES(?, ?, ?, ?)");
 
@@ -169,8 +187,6 @@ PrivacyGuardDb::PgAddPrivacyAccessLogForCynara(const int userId, const std::stri
        }
        TryCatchResLogReturn(m_bDBOpen == true, m_dbMutex.unlock(), PRIV_GUARD_ERROR_IO_ERROR, "openSqliteDB : %d", res);
 
-       PG_LOGD("addlogToDb m_sqlHandler : %p", m_sqlHandler);
-
        // prepare
        res = sqlite3_prepare_v2(m_sqlHandler, QUERY_INSERT.c_str(), -1, &m_stmt, NULL);
        TryCatchResLogReturn(res == SQLITE_OK, m_dbMutex.unlock(), PRIV_GUARD_ERROR_DB_ERROR, "sqlite3_prepare_v2 : %d", res);
@@ -185,7 +201,7 @@ PrivacyGuardDb::PgAddPrivacyAccessLogForCynara(const int userId, const std::stri
        res = sqlite3_bind_text(m_stmt, 3, privacyId.c_str(), -1, SQLITE_TRANSIENT);
        TryCatchResLogReturn(res == SQLITE_OK, m_dbMutex.unlock(), PRIV_GUARD_ERROR_DB_ERROR, "sqlite3_bind_text : %d", res);
 
-       res = sqlite3_bind_int(m_stmt, 4, logging_date);
+       res = sqlite3_bind_int(m_stmt, 4, date);
        TryCatchResLogReturn(res == SQLITE_OK, m_dbMutex.unlock(), PRIV_GUARD_ERROR_DB_ERROR, "sqlite3_bind_int : %d", res);
 
        res = sqlite3_step(m_stmt);
@@ -488,7 +504,6 @@ PrivacyGuardDb::PgForeachTotalPrivacyCountOfPackage(const int userId, const int
 {
        int res = -1;
 
-#if 0
        // [CYNARA] Fluch Entries
        int ret= cynara_monitor_entries_flush(p_cynara_monitor);
        if(ret != CYNARA_API_SUCCESS){
@@ -496,7 +511,7 @@ PrivacyGuardDb::PgForeachTotalPrivacyCountOfPackage(const int userId, const int
                return PRIV_GUARD_ERROR_SYSTEM_ERROR;
        }
 
-       // [CYNARA] Get Entries
+/*     // [CYNARA] Get Entries
        ret = cynara_monitor_entries_get(p_cynara_monitor, &monitor_entries);
        if(ret != CYNARA_API_SUCCESS){
                PG_LOGE("cynara_monitor_entries_get FAIL");
@@ -509,8 +524,7 @@ PrivacyGuardDb::PgForeachTotalPrivacyCountOfPackage(const int userId, const int
                PG_LOGE("updateDb FAIL");
                return ret;
        }
-#endif
-
+*/
        static const std::string PKGID_SELECT = std::string("SELECT DISTINCT PKG_ID FROM StatisticsMonitorInfo WHERE USER_ID=? AND USE_DATE>=? AND USE_DATE<=?");
        static const std::string PKGINFO_SELECT = std::string("SELECT COUNT(*) FROM StatisticsMonitorInfo WHERE USER_ID=? AND PKG_ID=? AND USE_DATE>=? AND USE_DATE<=?");
        sqlite3_stmt* infoStmt;
@@ -582,7 +596,6 @@ PrivacyGuardDb::PgForeachTotalPrivacyCountOfPrivacy(const int userId, const int
 {
        int res = -1;
 
-#if 0
        // [CYNARA] Fluch Entries
        int ret= cynara_monitor_entries_flush(p_cynara_monitor);
        if(ret != CYNARA_API_SUCCESS){
@@ -590,7 +603,7 @@ PrivacyGuardDb::PgForeachTotalPrivacyCountOfPrivacy(const int userId, const int
                return PRIV_GUARD_ERROR_SYSTEM_ERROR;
        }
 
-       // [CYNARA] Get Entries
+/*     // [CYNARA] Get Entries
        ret = cynara_monitor_entries_get(p_cynara_monitor, &monitor_entries);
        if(ret != CYNARA_API_SUCCESS){
                PG_LOGE("cynara_monitor_entries_get FAIL");
@@ -603,8 +616,7 @@ PrivacyGuardDb::PgForeachTotalPrivacyCountOfPrivacy(const int userId, const int
                PG_LOGE("updateDb FAIL");
                return ret;
        }
-#endif
-
+*/
        static const std::string PRIVACY_SELECT = std::string("SELECT COUNT(*) FROM StatisticsMonitorInfo WHERE USER_ID=? AND PRIVACY_ID=? AND USE_DATE>=? AND USE_DATE<=?");
 
        m_dbMutex.lock();
@@ -663,7 +675,6 @@ PrivacyGuardDb::PgForeachPrivacyCountByPrivacyId(const int userId, const int sta
 {
        int res = -1;
 
-#if 0
        // [CYNARA] Fluch Entries
        int ret= cynara_monitor_entries_flush(p_cynara_monitor);
        if(ret != CYNARA_API_SUCCESS){
@@ -671,7 +682,7 @@ PrivacyGuardDb::PgForeachPrivacyCountByPrivacyId(const int userId, const int sta
                return PRIV_GUARD_ERROR_SYSTEM_ERROR;
        }
 
-       // [CYNARA] Get Entries
+/*     // [CYNARA] Get Entries
        ret = cynara_monitor_entries_get(p_cynara_monitor, &monitor_entries);
        if(ret != CYNARA_API_SUCCESS){
                PG_LOGE("cynara_monitor_entries_get FAIL");
@@ -684,7 +695,7 @@ PrivacyGuardDb::PgForeachPrivacyCountByPrivacyId(const int userId, const int sta
                PG_LOGE("updateDb FAIL");
                return ret;
        }
-#endif
+*/
 
        static const std::string PKGID_SELECT = std::string("SELECT DISTINCT PKG_ID FROM StatisticsMonitorInfo WHERE USER_ID=? AND PRIVACY_ID=? AND USE_DATE>=? AND USE_DATE<=?");
        static const std::string PKGINFO_SELECT = std::string("SELECT COUNT(*) FROM StatisticsMonitorInfo WHERE USER_ID=? AND PKG_ID=? AND PRIVACY_ID=? AND USE_DATE>=? AND USE_DATE<=?");
@@ -765,7 +776,6 @@ PrivacyGuardDb::PgForeachPrivacyCountByPackageId(const int userId, const int sta
 {
        int res = -1;
 
-#if 0
        // [CYNARA] Fluch Entries
        int ret= cynara_monitor_entries_flush(p_cynara_monitor);
        if(ret != CYNARA_API_SUCCESS){
@@ -773,7 +783,7 @@ PrivacyGuardDb::PgForeachPrivacyCountByPackageId(const int userId, const int sta
                return PRIV_GUARD_ERROR_SYSTEM_ERROR;
        }
 
-       // [CYNARA] Get Entries
+/*     // [CYNARA] Get Entries
        ret = cynara_monitor_entries_get(p_cynara_monitor, &monitor_entries);
        if(ret != CYNARA_API_SUCCESS){
                PG_LOGE("cynara_monitor_entries_get FAIL");
@@ -786,7 +796,7 @@ PrivacyGuardDb::PgForeachPrivacyCountByPackageId(const int userId, const int sta
                PG_LOGE("updateDb FAIL");
                return ret;
        }
-#endif
+*/
 
        static const std::string PRIVACY_SELECT = std::string("SELECT COUNT(*) FROM StatisticsMonitorInfo WHERE USER_ID=? AND PKG_ID=? AND PRIVACY_ID=? AND USE_DATE>=? AND USE_DATE<=?");
 
@@ -1119,7 +1129,6 @@ PrivacyGuardDb::PgForeachPackageInfoByPrivacyId(const int userId, const std::str
                }
                sqlite3_reset(infoStmt);
        }
-
        m_dbMutex.unlock();
 
        return PRIV_GUARD_ERROR_SUCCESS;
@@ -1364,6 +1373,7 @@ PrivacyGuardDb::~PrivacyGuardDb(void)
        if (m_bInitialized == true) {
                m_dbMutex.lock();
                g_list_free(m_privacy_list);
+               cynara_monitor_configuration_destroy(p_conf);
                m_bInitialized = false;
                m_dbMutex.unlock();
        }
index 2ce1d08..471f92d 100755 (executable)
@@ -39,18 +39,18 @@ SocketService::SocketService(void)
        , m_signalToClose(-1)
        , m_mainThread(-1)
 {
-
+       PG_LOGD("SocketService() called.");
 }
 
 SocketService::~SocketService(void)
 {
-
+       PG_LOGD("~SocketService() called.");
 }
 
 int
 SocketService::initialize(void)
 {
-       PG_LOGI("SocketService initializing");
+       PG_LOGD("SocketService initializing");
 
        char buf[BUF_SIZE];
        m_listenFd = socket(AF_UNIX, SOCK_STREAM, 0);
@@ -115,21 +115,26 @@ SocketService::start(void)
 void*
 SocketService::serverThread(void* pData)
 {
+       PG_LOGD("serverThread() called.");
        pthread_detach(pthread_self());
        SocketService &t = *static_cast< SocketService* > (pData);
-       PG_LOGI("Running main thread");
+
+       PG_LOGD("Running main thread");
        int ret = t.mainloop();
-       if (ret < 0)
-       {
+       if (ret < 0) {
                return (void*) 1;
        }
+
        return (void*) 0;
 }
 
 int
 SocketService::mainloop(void)
 {
+       PG_LOGD("mainloop() called.");
+
        char buf[BUF_SIZE];
+
        if( listen(m_listenFd, MAX_LISTEN) == -1 ){
                PG_LOGE("listen : %s", strerror_r(errno, buf, sizeof(buf)));
                return PRIV_GUARD_ERROR_IPC_ERROR;
@@ -221,6 +226,7 @@ SocketService::mainloop(void)
 void*
 SocketService::connectionThread(void* pData)
 {
+       PG_LOGD("connectionThread() called.");
        pthread_detach(pthread_self());
        std::unique_ptr<ConnectionInfo> connectionInfo (static_cast<ConnectionInfo *>(pData));
        SocketService &t = *static_cast<SocketService *>(connectionInfo->pData);
@@ -240,6 +246,7 @@ SocketService::connectionThread(void* pData)
 int
 SocketService::connectionService(int fd)
 {
+       PG_LOGD("connectionService() called.");
 
        SocketConnection connector = SocketConnection(fd);
        std::string interfaceName, methodName;
@@ -288,8 +295,10 @@ SocketService::connectionService(int fd)
 int
 SocketService::stop(void)
 {
-       PG_LOGI("Stopping");
+       PG_LOGD("Stopping");
+
        char buf[BUF_SIZE];
+
        if(close(m_listenFd) == -1)
                if(errno != ENOTCONN)
                {
@@ -306,19 +315,23 @@ SocketService::stop(void)
        }
        pthread_join(m_mainThread, NULL);
 
-       PG_LOGI("Stopped");
+       PG_LOGD("Stopped");
+
        return PRIV_GUARD_ERROR_SUCCESS;
 }
 
 int
 SocketService::shutdown(void)
 {
+       PG_LOGD("called");
        return PRIV_GUARD_ERROR_SUCCESS;
 }
 
 int
 SocketService::registerServiceCallback(const std::string &interfaceName,  const std::string &methodName, socketServiceCallback callbackMethod)
 {
+       PG_LOGD("called");
+
        if(NULL == callbackMethod)
        {
                PG_LOGE("Null callback");
@@ -339,6 +352,8 @@ SocketService::registerServiceCallback(const std::string &interfaceName,  const
 void
 SocketService::addClientSocket(int clientSocket)
 {
+       PG_LOGD("called");
+
        std::lock_guard<std::mutex> guard(m_clientSocketListMutex);
        m_clientSocketList.push_back(clientSocket);
 }
@@ -346,6 +361,8 @@ SocketService::addClientSocket(int clientSocket)
 void
 SocketService::removeClientSocket(int clientSocket)
 {
+       PG_LOGD("called");
+
        std::lock_guard<std::mutex> guard(m_clientSocketListMutex);
        m_clientSocketList.remove(clientSocket);
 }
@@ -353,6 +370,8 @@ SocketService::removeClientSocket(int clientSocket)
 bool
 SocketService::popClientSocket(int * pClientSocket)
 {
+       PG_LOGD("called");
+
        std::lock_guard<std::mutex> guard(m_clientSocketListMutex);
        if(m_clientSocketList.empty())
                return false;
@@ -365,6 +384,8 @@ SocketService::popClientSocket(int * pClientSocket)
 void
 SocketService::closeConnections(void)
 {
+       PG_LOGD("called");
+
        int clientSocket;
        char buf[BUF_SIZE];
        PG_LOGI("Closing client sockets");
@@ -376,5 +397,5 @@ SocketService::closeConnections(void)
                }
        }
 
-       PG_LOGI("Connections closed");
+       PG_LOGD("Connections closed");
 }
index 528355b..6050163 100755 (executable)
 #include <glib.h>
 #include "PrivacyGuardDaemon.h"
 
+// [kylee76]temp
+#include "Utils.h"
+
 int
 main(int argc, char* argv[])
 {
+       PG_LOGD("called");
        PrivacyGuardDaemon* pDaemon = PrivacyGuardDaemon::getInstance();
 
+       PG_LOGD("pDaemon->initialize()");
        pDaemon->initialize();
+       PG_LOGD("pDaemon->start()");
        pDaemon->start();
 
        GMainLoop* pLoop;
        pLoop = g_main_new(TRUE);
 
+       PG_LOGD("g_main_loop_run(pLoop)");
        g_main_loop_run(pLoop);
 
+       PG_LOGD("pDaemon->stop()");
        pDaemon->stop();
+       PG_LOGD("pDaemon->shutdown()");
        pDaemon->shutdown();
 
        return 0;