Apply new API to get package id 12/90412/2 accepted/tizen/common/20160930.174704 accepted/tizen/mobile/20160930.232452 submit/tizen/20160930.022920
authorSEUNGTAEK HAN <s.t.han@samsung.com>
Fri, 30 Sep 2016 02:22:05 +0000 (11:22 +0900)
committerSEUNGTAEK HAN <s.t.han@samsung.com>
Fri, 30 Sep 2016 02:24:24 +0000 (11:24 +0900)
Change-Id: I8579483d25220f49a492e3b15c0eec64cb0e7ade

common/inc/PrivacyGuardTypes.h
packaging/privacy-guard.spec
pkgmgr_plugin/CMakeLists.txt
server/CMakeLists.txt
server/src/CynaraService.cpp

index 8f1809f..cb42e05 100755 (executable)
 #define USER_APP_PREFIX "User::App::"
 #define USER_APP_PREFIX_LEN 11
 #define GLOBAL_APP_USER_ID 0
+#define USER_PKG_PREFIX "User::Pkg::"
+#define USER_PKG_PREFIX_LEN 11
+#define ROOT_USER_ID 0
+#define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
 
 typedef struct _privacy_data_s {
        char *privacy_id;
index 8fcd619..8edf16b 100755 (executable)
@@ -27,6 +27,7 @@ BuildRequires:        pkgconfig(libtzplatform-config)
 BuildRequires: pkgconfig(security-privilege-manager)
 BuildRequires: pkgconfig(cynara-monitor)
 BuildRequires:  pkgconfig(pkgmgr-installer)
+BuildRequires:  pkgconfig(security-manager)
 
 Requires(post):   /sbin/ldconfig
 Requires(postun): /sbin/ldconfig
index 814127e..d1591e5 100755 (executable)
@@ -5,7 +5,7 @@ SET (this_target privileges)
 SET(LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/cmake_build_tmp/output)
 
 INCLUDE(FindPkgConfig)
-pkg_check_modules(pkg REQUIRED glib-2.0 dlog libxml-2.0 pkgmgr-installer)
+pkg_check_modules(pkg REQUIRED glib-2.0 dlog libxml-2.0 libtzplatform-config pkgmgr-installer)
 
 FOREACH(flag ${privileges_CFLAGS})
     SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
index 2d3e54d..7ff76f0 100755 (executable)
@@ -7,7 +7,7 @@ SET(EXEC_PREFIX "\${prefix}")
 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 cynara-monitor security-manager)
 #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})
index f649180..12601c1 100755 (executable)
@@ -32,6 +32,7 @@
 #include "CynaraService.h"
 #include "PrivacyGuardDb.h"
 #include "PrivacyIdInfo.h"
+#include "security-manager.h"
 
 #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
 
@@ -180,6 +181,7 @@ CynaraService::updateDb(cynara_monitor_entry **monitor_entries)
 
        // DB update
        const char *user = NULL, *client = NULL, *privilege = NULL;
+#if 0
        char *package_id = NULL, *package_id_dup = NULL;
        const timespec *timestamp = NULL;
        uid_t userId;
@@ -243,7 +245,53 @@ CynaraService::updateDb(cynara_monitor_entry **monitor_entries)
                                packageId = package_id_dup;
                                pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo);
                        }
+#else
+                               const timespec *timestamp = NULL;
+                               uid_t userId;
+                               std::string appId, privacyId, packageId;
+                               time_t date;
+                               int res = -1;
+                               pkgmgrinfo_pkginfo_h pkg_handle;
+                               bool is_global = false;
+                               char *pkg_name = NULL, *app_name = NULL;
+
+                               while (*entryIter != nullptr) {
+                                       privilege = cynara_monitor_entry_get_privilege(*entryIter);
+                                       TryReturn(privilege != NULL, PRIV_GUARD_ERROR_SYSTEM_ERROR, , "Privilege Id in the entry is NULL");
+
+                                       // change from privilege to privacy
+                                       res = PrivacyIdInfo::getPrivacyIdFromPrivilege(privilege, privacyId);
+                                       if (res != PRIV_GUARD_ERROR_NO_DATA) {
+                                               // User ID - string
+                                               user = cynara_monitor_entry_get_user(*entryIter);
+                                               TryReturn(user != NULL, PRIV_GUARD_ERROR_SYSTEM_ERROR, , "User Id in the entry is NULL");
+
+                                               // App ID - string
+                                               client = cynara_monitor_entry_get_client(*entryIter);
+                                               TryReturn(client != NULL, PRIV_GUARD_ERROR_SYSTEM_ERROR, , "App Id in the entry is NULL");
+
+                                               // timestamp
+                                               timestamp = cynara_monitor_entry_get_timestamp(*entryIter);
+                                               TryReturn(timestamp != NULL, PRIV_GUARD_ERROR_SYSTEM_ERROR, , "timestamp in the entry is NULL");
+
+                                               // convert string to integer
+                                               userId = atoi(user);
+
+                       res = security_manager_identify_app_from_cynara_client(client, &pkg_name, &app_name);
+                       if (res != PRIV_GUARD_ERROR_NO_DATA) {
+                               PG_LOGE("Failed to security_manager_identify_app_from_cynara_client()");
+                       }
 
+                       // check pkg ID
+                       std::string tempPkgId = pkg_name;
+                       if (tempPkgId.substr(0, USER_PKG_PREFIX_LEN).compare(USER_PKG_PREFIX) == 0) {
+                               packageId = tempPkgId.substr(USER_PKG_PREFIX_LEN, tempPkgId.length() - USER_PKG_PREFIX_LEN);
+                               PG_LOGD("Pkg ID: [%s]", packageId.c_str());
+                       } else {
+                               packageId = pkg_name;
+                               PG_LOGD("Pkg ID: [%s]", pkg_name);
+                       }
+#endif
                        // check this package is global app
                        if (userId == GLOBAL_USER) {
                                res = pkgmgrinfo_pkginfo_get_pkginfo(packageId.c_str(), &pkg_handle);