modify to filter privilege 17/72617/4
authorSEUNGTAEK HAN <s.t.han@samsung.com>
Thu, 2 Jun 2016 00:36:09 +0000 (09:36 +0900)
committerSEUNGTAEK HAN <s.t.han@samsung.com>
Thu, 2 Jun 2016 00:54:15 +0000 (09:54 +0900)
Change-Id: Ibd228a3e224c9a6999c4a22aa903ff0dc5299ef7

common/inc/PrivacyGuardTypes.h
server/inc/PrivacyGuardDb.h
server/src/CynaraService.cpp
server/src/PrivacyGuardDb.cpp

index ea5b703929d614d664172593fd3c519fa12047b6..e3f935971611166edca8367a313e7f6f35be2c75 100755 (executable)
@@ -25,6 +25,8 @@
 
 //#define CYNARA_BUFFER_SIZE 1024
 #define CYNARA_BUFFER_SIZE 100
+#define USER_APP_PREFIX "User::App::"
+#define USER_APP_PREFIX_LEN 11
 
 typedef struct _privacy_data_s {
        char *privacy_id;
index a8a63c98f52c560ca35bf4cde731538ec05eee69..37edad591e5408bd00114d1710ff182a1433b349 100755 (executable)
@@ -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 time_t timestamp);
+       int PgAddPrivacyAccessLogForCynara(const int userId, const std::string packageId, const std::string privacyId, const time_t timestamp);
 
        int PgAddPrivacyAccessLogTest(const int userId, const std::string packageId, const std::string privacyId);
 
index 17589c32d7ee40a250c5320cc9bb8821e6495b76..9d0b0b5d603509c42b21aa37a73362c2710bdcda 100755 (executable)
@@ -27,6 +27,7 @@
 #include "Utils.h"
 #include "CynaraService.h"
 #include "PrivacyGuardDb.h"
+#include "PrivacyIdInfo.h"
 
 #define BUF_SIZE 256
 
@@ -171,42 +172,55 @@ CynaraService::updateDb(cynara_monitor_entry **monitor_entries)
        const char *user = NULL, *client = NULL, *privilege = NULL;
        const timespec *timestamp = NULL;
        int userId;
-       std::string packageId, privilegeId;
+       std::string packageId, privacyId;
        time_t date;
+       int res = -1;
 
        while (*entryIter != nullptr) {
-               user = cynara_monitor_entry_get_user(*entryIter);
-               TryReturn(user != NULL, PRIV_GUARD_ERROR_SYSTEM_ERROR, , "User Id in the entry is NULL");
-               PG_LOGD("@@ userid: [%s]", user);
-               client = cynara_monitor_entry_get_client(*entryIter);
-               TryReturn(user != NULL, PRIV_GUARD_ERROR_SYSTEM_ERROR, , "Package Id in the entry is NULL");
-               PG_LOGD("@@ client: [%s]", client);
                privilege = cynara_monitor_entry_get_privilege(*entryIter);
-               TryReturn(user != NULL, PRIV_GUARD_ERROR_SYSTEM_ERROR, , "Privilege Id in the entry is NULL");
+               TryReturn(privilege != NULL, PRIV_GUARD_ERROR_SYSTEM_ERROR, , "Privilege Id in the entry is NULL");
                PG_LOGD("@@ privilege: [%s]", privilege);
-               timestamp = cynara_monitor_entry_get_timestamp(*entryIter);
-               TryReturn(user != NULL, PRIV_GUARD_ERROR_SYSTEM_ERROR, , "timestamp in the entry is NULL");
-
-               userId = atoi(user);
-               PG_LOGD("## userId: [%d]", userId);
-               std::string tempPackageId = client;
-               if (tempPackageId.substr(0, 11).compare("User::App::") == 0) {
-                       packageId = tempPackageId.substr(11, tempPackageId.length() - 11);
-               } else {
-                       packageId = client;
-               }
-               PG_LOGD("## packageId: [%s]", packageId.c_str());
-               privilegeId = privilege;
-               PG_LOGD("## privilegeId: [%s]", privilegeId.c_str());
-               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");
+
+               PG_LOGD("getting privacy id from privilege [%s]", privilege);
+
+               // change from privilege to privacy
+               res = PrivacyIdInfo::getPrivacyIdFromPrivilege(privilege, privacyId);
+               if (res == PRIV_GUARD_ERROR_NO_DATA) {
+                       PG_LOGD("Input privilege[%s] is not related to any privacy. So skip it.", privilege);
                }
-               else{
-                       PG_LOGD("PgAddPrivacyAccessLogForCynara SUCCESS");
+               else {
+                       PG_LOGD("@@ privacyId: [%s]", privacyId.c_str());
+
+                       user = cynara_monitor_entry_get_user(*entryIter);
+                       TryReturn(user != NULL, PRIV_GUARD_ERROR_SYSTEM_ERROR, , "User Id in the entry is NULL");
+                       PG_LOGD("@@ userid: [%s]", user);
+
+                       client = cynara_monitor_entry_get_client(*entryIter);
+                       TryReturn(client != NULL, PRIV_GUARD_ERROR_SYSTEM_ERROR, , "Package Id in the entry is NULL");
+                       PG_LOGD("@@ client: [%s]", client);
+
+                       timestamp = cynara_monitor_entry_get_timestamp(*entryIter);
+                       TryReturn(timestamp != NULL, PRIV_GUARD_ERROR_SYSTEM_ERROR, , "timestamp in the entry is NULL");
+
+                       userId = atoi(user);
+                       PG_LOGD("## userId: [%d]", userId);
+                       std::string tempPackageId = client;
+                       if (tempPackageId.substr(0, USER_APP_PREFIX_LEN).compare(USER_APP_PREFIX) == 0) {
+                               packageId = tempPackageId.substr(USER_APP_PREFIX_LEN, tempPackageId.length() - USER_APP_PREFIX_LEN);
+                       } else {
+                               packageId = client;
+                       }
+                       PG_LOGD("## packageId: [%s]", packageId.c_str());
+                       date = timestamp->tv_sec;
+
+                       // add access log
+                       int ret = PrivacyGuardDb::getInstance()->PgAddPrivacyAccessLogForCynara(userId, packageId, privacyId, date);
+                       if(ret != PRIV_GUARD_ERROR_SUCCESS){
+                               PG_LOGE("PgAddPrivacyAccessLogForCynara FAIL");
+                       }
+                       else{
+                               PG_LOGD("PgAddPrivacyAccessLogForCynara SUCCESS");
+                       }
                }
 
                ++entryIter;
index 819c1c95cd884ffa3664c77acb30552a764b5f9e..89188a71683633724e504f5c23213113c036e058 100755 (executable)
@@ -144,7 +144,7 @@ PrivacyGuardDb::PgAddPrivacyAccessLog(const int userId, std::list < std::pair <
 }
 
 int
-PrivacyGuardDb::PgAddPrivacyAccessLogForCynara(const int userId, const std::string packageId, const std::string privilegeId, const time_t date)
+PrivacyGuardDb::PgAddPrivacyAccessLogForCynara(const int userId, const std::string packageId, const std::string privacyId, const time_t date)
 {
        PG_LOGD("start.");
 
@@ -154,17 +154,6 @@ PrivacyGuardDb::PgAddPrivacyAccessLogForCynara(const int userId, const std::stri
        }
 
        int res = -1;
-       std::string privacyId;
-
-       PG_LOGD("getting privacy id from privilege [%s]", privilegeId.c_str());
-
-       // change from privilege to privacy
-       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 is failed: [%d]", res);
 
        PG_LOGD("getting monitor policy");