From 7afab20603fffa3a8ea00f4c0f069ec6cb18e574 Mon Sep 17 00:00:00 2001 From: Hyunwoo Kim Date: Tue, 26 Mar 2013 22:30:23 +0900 Subject: [PATCH] Add Check logic Change-Id: I003c44eb8becf7c68557a6cf0b1576bdfb86c0a5 Signed-off-by: Hyunwoo Kim --- CMakeLists.txt | 1 + client/CMakeLists.txt | 5 +- client/inc/PrivacyChecker.h | 20 +- .../{PrivacyManager.h => PrivacyManagerClient.h} | 10 +- client/inc/privacy_checker_client.h | 15 +- client/inc/privacy_manager_client.h | 1 + client/src/PrivacyChecker.cpp | 263 +++++++++++++++------ client/src/PrivacyManager.cpp | 149 ------------ client/src/PrivacyManagerClient.cpp | 190 +++++++++++++++ client/src/privacy_checker_client.cpp | 37 ++- client/src/privacy_info_client.cpp | 2 +- client/src/privacy_manager_client.cpp | 33 ++- common/inc/PrivacyIdInfo.h | 2 +- common/inc/PrivacyManagerTypes.h | 2 + common/inc/Utils.h | 8 +- common/inc/privacy_manager_client_types.h | 1 + common/src/PrivacyIdInfo.cpp | 131 +++++----- .../TestService.cpp => common/src/Utils.cpp | 17 +- packaging/priavcy-manager.manifest | 12 - packaging/privacy-manager-server.manifest | 17 +- packaging/privacy-manager.spec | 31 +-- pkgmgr_plugin/CMakeLists.txt | 57 +++++ pkgmgr_plugin/privileges.cpp | 118 +++++++++ privacy-manager-test.pc.in | 9 - res/opt/dbspace/.privacylist.db | Bin 0 -> 9216 bytes res/usr/bin/privacy_db.sql | 17 +- server/CMakeLists.txt | 11 +- server/inc/PrivacyManagerServer.h | 21 +- server/inc/TestService.h | 39 --- server/src/PrivacyManagerDaemon.cpp | 2 - server/src/PrivacyManagerServer.cpp | 153 +++--------- server/src/service/PrivacyInfoService.cpp | 2 +- 32 files changed, 793 insertions(+), 583 deletions(-) rename client/inc/{PrivacyManager.h => PrivacyManagerClient.h} (85%) delete mode 100644 client/src/PrivacyManager.cpp create mode 100644 client/src/PrivacyManagerClient.cpp rename server/src/service/TestService.cpp => common/src/Utils.cpp (61%) delete mode 100644 packaging/priavcy-manager.manifest create mode 100644 pkgmgr_plugin/CMakeLists.txt create mode 100644 pkgmgr_plugin/privileges.cpp delete mode 100644 privacy-manager-test.pc.in create mode 100644 res/opt/dbspace/.privacylist.db delete mode 100644 server/inc/TestService.h diff --git a/CMakeLists.txt b/CMakeLists.txt index e335471..15fa6d8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,3 +15,4 @@ ADD_SUBDIRECTORY(server) ADD_SUBDIRECTORY(client) #ADD_SUBDIRECTORY(test) ADD_SUBDIRECTORY(capi) +ADD_SUBDIRECTORY(pkgmgr_plugin) diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 80c4c9e..1e7024f 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -49,15 +49,14 @@ SET(PRIVACY_MANAGER_CLIENT_SOURCES ${common_src_dir}/SocketStream.cpp ${common_src_dir}/PrivacyIdInfo.cpp ${client_src_dir}/SocketClient.cpp - ${client_src_dir}/PrivacyManager.cpp + ${client_src_dir}/PrivacyManagerClient.cpp ${client_src_dir}/PrivacyChecker.cpp ${client_src_dir}/privacy_checker_client.cpp ${client_src_dir}/privacy_info_client.cpp ${client_src_dir}/privacy_manager_client.cpp ) SET(PRIVACY_MANAGER_CLIENT_HEADERS - ${client_include_dir}/PrivacyManager.h - ${client_include_dir}/PrivacyChecker.h + ${client_include_dir}/PrivacyManagerClient.h ${client_include_dir}/PrivacyChecker.h ${client_include_dir}/privacy_info_client.h ${client_include_dir}/privacy_manager_client.h diff --git a/client/inc/PrivacyChecker.h b/client/inc/PrivacyChecker.h index 96d86b3..4438a40 100644 --- a/client/inc/PrivacyChecker.h +++ b/client/inc/PrivacyChecker.h @@ -32,8 +32,8 @@ struct sqlite3; class EXTERN_API PrivacyChecker { private: - static const std::string DB_PATH; static std::map < std::string, bool > m_privacyCache; + static std::map < std::string, std::map < std::string, bool > > m_privacyInfoCache; static std::string m_pkgId; static bool m_isInitialized; static std::mutex m_cacheMutex; @@ -43,16 +43,28 @@ private: private: static int initializeDbus(void); static int finalizeDbus(void); - static int getUniqueIdFromPackageId(const std::string pkgId, int& uniqueId); - static int updateCache(void); - static int updateCache(const std::string privacyId); + static int updateCache(const std::string pkgId, std::string privacyId, std::map < std::string, bool >& pkgCacheMap); + static int updateCache(const std::string privacyId, std::map < std::string, bool >& pkgCacheMap); + static int updateCache(std::map < std::string, bool >& pkgCacheMap); static void printCache(void); static void* runSignalListenerThread(void* pData); static int getCurrentPkgId(std::string& pkgId); + static int check(const std::string privacyId, std::map < std::string, bool >& privacyMap); public: + // for Checking in App Process static int initialize(const std::string pkgId); + static int check(const std::string pkgId, const std::string privacyId); + static int checkWithPrivilege(const std::string pkgId, const std::string privilegeId); + static int checkWithDeviceCap(const std::string pkgId, const std::string deviceCap); + + // for Checking in Server Process + static int initialize(void); static int check(const std::string privacyId); + static int checkWithPrivilege(const std::string privilegeId); + static int checkWithDeviceCap(const std::string deviceCap); + + // common static int finalize(void); static DBusHandlerResult handleNotification(DBusConnection* connection, DBusMessage* message, void* user_data); }; diff --git a/client/inc/PrivacyManager.h b/client/inc/PrivacyManagerClient.h similarity index 85% rename from client/inc/PrivacyManager.h rename to client/inc/PrivacyManagerClient.h index a9c054d..e5ae684 100644 --- a/client/inc/PrivacyManager.h +++ b/client/inc/PrivacyManagerClient.h @@ -26,21 +26,21 @@ class SocketClient; -class EXTERN_API PrivacyManager +class EXTERN_API PrivacyManagerClient { private: - static PrivacyManager* m_pInstance; + static PrivacyManagerClient* m_pInstance; static const std::string INTERFACE_NAME; std::unique_ptr< SocketClient > m_pSocketClient; static std::mutex m_singletonMutex; - PrivacyManager(); - ~PrivacyManager(); + PrivacyManagerClient(); + ~PrivacyManagerClient(); public: - static PrivacyManager* getInstance(void); + static PrivacyManagerClient* getInstance(void); int addAppPackagePrivacyInfo(const std::string pkgId, const std::list < std::string >& list); diff --git a/client/inc/privacy_checker_client.h b/client/inc/privacy_checker_client.h index aa453f6..318b738 100644 --- a/client/inc/privacy_checker_client.h +++ b/client/inc/privacy_checker_client.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef _PRIVACY_INFO_CLIENT_H -#define _PRIVACY_INFO_CLIENT_H +#ifndef _PRIVACY_CHECKER_CLIENT_H +#define _PRIVACY_CHECKER_CLIENT_H #include @@ -25,8 +25,13 @@ extern "C" { EXTERN_API int privacy_checker_initialize(const char *package_id); EXTERN_API int privacy_checker_check_privacy(const char *privacy_id); -EXTERN_API int privacy_checker_check_privacy_by_privilege(const char *privilege_id); -EXTERN_API int privacy_checker_check_privacy_by_device_cap(const char *device_cap); +EXTERN_API int privacy_checker_check_by_privilege(const char *privilege_id); +EXTERN_API int privacy_checker_check_by_device_cap(const char *device_cap); +EXTERN_API int privacy_checker_finalize(void); + +EXTERN_API int privacy_checker_check_package_by_privilege(const char* package_id, const char *privilege_id); +EXTERN_API int privacy_checker_check_package_by_device_cap(const char* package_id, const char *device_cap); + EXTERN_API int privacy_checker_finalize(void); #ifdef __cplusplus @@ -34,4 +39,4 @@ EXTERN_API int privacy_checker_finalize(void); #endif -#endif //_PRIVACY_INFO_CLIENT_H +#endif //_PRIVACY_CHECKER_CLIENT_H diff --git a/client/inc/privacy_manager_client.h b/client/inc/privacy_manager_client.h index a67f6c5..4d407a6 100644 --- a/client/inc/privacy_manager_client.h +++ b/client/inc/privacy_manager_client.h @@ -33,6 +33,7 @@ EXTERN_API int privacy_manager_client_foreach_privacy_packages(privacy_manager_c EXTERN_API int privacy_manager_client_foreach_get_privacy_info(const char *package_id, privacy_manager_client_privacy_info_cb callback, void* user_data); EXTERN_API int privacy_manager_client_set_package_privacy(const char *package_id, const char *privacy_id, bool enable); +EXTERN_API int privacy_manager_client_check_user_consented(const char *package_id, bool consented); #ifdef __cplusplus } diff --git a/client/src/PrivacyChecker.cpp b/client/src/PrivacyChecker.cpp index 8688f7e..c4bb5fc 100644 --- a/client/src/PrivacyChecker.cpp +++ b/client/src/PrivacyChecker.cpp @@ -15,7 +15,8 @@ */ #include -#include +#include +#include #include #include #include @@ -27,8 +28,8 @@ #include bool PrivacyChecker::m_isInitialized = false; -const std::string PrivacyChecker::DB_PATH("/opt/dbspace/.privacy.db"); std::map < std::string, bool >PrivacyChecker::m_privacyCache; +std::map < std::string, std::map < std::string, bool > > PrivacyChecker::m_privacyInfoCache; std::mutex PrivacyChecker::m_cacheMutex; std::string PrivacyChecker::m_pkgId; DBusConnection* PrivacyChecker::m_pDBusConnection; @@ -37,30 +38,28 @@ GMainLoop* PrivacyChecker::m_pLoop = NULL; const int MAX_LOCAL_BUF_SIZE = 128; int -PrivacyChecker::getUniqueIdFromPackageId(const std::string pkgId, int& uniqueId) +PrivacyChecker::initialize(const std::string pkgId) { LOGI("enter"); - std::string PkgIdQuery = std::string("SELECT UNIQUE_ID from PackageInfo where PKG_ID=?"); - int res; - openDb(DB_PATH.c_str(), pDbH, SQLITE_OPEN_READONLY); - prepareDb(pDbH, PkgIdQuery.c_str(), pStmt); + if (m_isInitialized) + return PRIV_MGR_ERROR_SUCCESS; - res = sqlite3_bind_text(pStmt.get(), 1, pkgId.c_str(), -1, SQLITE_TRANSIENT); - TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_IO_ERROR, , "sqlite3_bind_text : %d", res); + m_pkgId = pkgId; - res = sqlite3_step(pStmt.get()); - TryReturn( res == SQLITE_ROW, PRIV_MGR_ERROR_IO_ERROR, , "sqlite3_step : %d", res); + std::lock_guard < std::mutex > guard(m_cacheMutex); + + int res = updateCache(m_privacyCache); + TryReturn(res == 0, res, m_pkgId.clear(), "Failed to update cache : %d", res); - uniqueId = sqlite3_column_int(pStmt.get(), 0); - LOGI("%s : %d", pkgId.c_str(), uniqueId); + res = initialize(); + TryReturn(res == 0, res, m_pkgId.clear(), "Failed to initialize() : %d", res); - LOGI("leave"); return PRIV_MGR_ERROR_SUCCESS; } int -PrivacyChecker::initialize(const std::string pkgId) +PrivacyChecker::initialize(void) { LOGI("enter"); @@ -72,10 +71,6 @@ PrivacyChecker::initialize(const std::string pkgId) res = pthread_create(&signalThread, NULL, &runSignalListenerThread, NULL); TryReturn(res >= 0, PRIV_MGR_ERROR_SYSTEM_ERROR, errno = res;, "Failed to create listener thread :%s", strerror(res)); - m_pkgId = pkgId; - res = updateCache(); - TryReturn(res == 0, res, m_pkgId.clear(), "Failed to update cache : %d", res); - m_isInitialized = true; LOGI("leave"); @@ -151,6 +146,8 @@ PrivacyChecker::handleNotification(DBusConnection* connection, DBusMessage* mess char* pPkgId; char* pPrivacyId; + LOGI("enter"); + if (dbus_message_is_signal(message, DBUS_SIGNAL_INTERFACE.c_str(), DBUS_SIGNAL_NAME.c_str())) { r = dbus_message_get_args(message, &error, @@ -159,12 +156,22 @@ PrivacyChecker::handleNotification(DBusConnection* connection, DBusMessage* mess DBUS_TYPE_INVALID); TryReturn(r, DBUS_HANDLER_RESULT_NOT_YET_HANDLED, , "Fail to get data : %s", error.message); + std::lock_guard < std::mutex > guard(m_cacheMutex); + if (std::string(pPkgId) == m_pkgId) { LOGI("Current app pkg privacy information updated"); - updateCache(pPrivacyId); + updateCache(pPrivacyId, m_privacyCache); printCache(); } + + std::map < std::string, std::map < std::string, bool > > :: iterator iter = m_privacyInfoCache.find(std::string(pPkgId)); + if (iter != m_privacyInfoCache.end()) + { + LOGI("Current pkg privacy is in cache"); + updateCache(std::string(pPkgId), pPrivacyId, iter->second); + } + } else { @@ -175,24 +182,22 @@ PrivacyChecker::handleNotification(DBusConnection* connection, DBusMessage* mess } int -PrivacyChecker::check(const std::string privacyId) +PrivacyChecker::check(const std::string privacyId, std::map < std::string, bool >& privacyMap) { LOGI("enter"); - std::lock_guard < std::mutex > guard(m_cacheMutex); + TryReturn(m_isInitialized, PRIV_MGR_ERROR_NOT_INITIALIZED, , "Not initialized"); - TryReturn(m_isInitialized, -1, , "Not initialized"); - - std::map < std::string, bool >::const_iterator iter = m_privacyCache.find(privacyId); - if (iter == m_privacyCache.end() ) + std::map < std::string, bool >::const_iterator iter = privacyMap.find(privacyId); + if (iter == privacyMap.end() ) { LOGD("NO matcheded"); - return -1; + return PRIV_MGR_ERROR_USER_NOT_CONSENTED; } else if (!iter->second) { LOGD("NOT allowed"); - return -1; + return PRIV_MGR_ERROR_USER_NOT_CONSENTED; } LOGD("OK"); @@ -200,55 +205,134 @@ PrivacyChecker::check(const std::string privacyId) } int -PrivacyChecker::finalize(void) +PrivacyChecker::check(const std::string privacyId) { - std::lock_guard guard (m_cacheMutex); - m_privacyCache.clear(); - - if (m_pLoop != NULL) + LOGI("enter"); + + if (!m_isInitialized) + return PRIV_MGR_ERROR_NOT_INITIALIZED; + + std::lock_guard < std::mutex > guard(m_cacheMutex); + + int res = check(privacyId, m_privacyCache); + + LOGI("leave"); + + return res; +} + +int +PrivacyChecker::check(const std::string pkgId, const std::string privacyId) +{ + LOGI("enter"); + + if (!m_isInitialized) + initialize(); + std::lock_guard < std::mutex > guard(m_cacheMutex); + int res; + + std::map < std::string, std::map < std::string, bool > >::iterator iter = m_privacyInfoCache.find(pkgId); + if (iter == m_privacyInfoCache.end() ) { - g_main_loop_quit(m_pLoop); - m_pLoop = NULL; + std::map < std::string, bool > pkgCacheMap; + res = updateCache(pkgCacheMap); + TryReturn( res == PRIV_MGR_ERROR_SUCCESS, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_text : %d", res); + + m_privacyInfoCache.insert( std::map < std::string, std::map < std::string, bool > >::value_type(std::string(pkgId), pkgCacheMap)); + iter = m_privacyInfoCache.find(pkgId); } + if (iter->second.size() == 0) + return PRIV_MGR_ERROR_USER_NOT_CONSENTED; - m_isInitialized = false; + res = check(privacyId, iter->second); - return PRIV_MGR_ERROR_SUCCESS; + LOGI("leave"); + + return res; } int -PrivacyChecker::updateCache(void) +PrivacyChecker::checkWithPrivilege(const std::string pkgId, const std::string privilege) { LOGI("enter"); - static const std::string PrivacyQuery = "SELECT PRIVACY_ID, IS_ENABLED from Privacy where ID=?"; - - std::lock_guard < std::mutex > guard(m_cacheMutex); - int res; - int id; - res = getUniqueIdFromPackageId(m_pkgId, id); - TryReturn( res == 0, -1, , "getUniqueIdFromPackageId : %d", res); - LOGD("id : %d" ,id); - - openDb(DB_PATH.c_str(), pDbH, SQLITE_OPEN_READONLY); - prepareDb(pDbH, PrivacyQuery.c_str(), pPrivacyStmt); - res = sqlite3_bind_int(pPrivacyStmt.get(), 1, id); - TryReturn( res == 0, -1, , "sqlite3_bind_int : %d", res); + std::string privacyId; + int res = PrivacyIdInfo::getPrivacyIdFromPrivilege(privilege, privacyId); + if (res == PRIV_MGR_ERROR_NO_DATA) + return PRIV_MGR_ERROR_USER_NOT_CONSENTED; + TryReturn( res == PRIV_MGR_ERROR_SUCCESS, res, , "getPrivacyIdFromPrivilege : %d", res); + LOGI("leave"); - while ( sqlite3_step(pPrivacyStmt.get()) == SQLITE_ROW ) - { - LOGI("start"); - const char* privacyId = reinterpret_cast < const char* > (sqlite3_column_text(pPrivacyStmt.get(), 0)); - bool privacyEnabled = sqlite3_column_int(pPrivacyStmt.get(), 1) > 0 ? true : false; + return check(pkgId, privacyId); +} + +int +PrivacyChecker::checkWithPrivilege(const std::string privilege) +{ + LOGI("enter"); - m_privacyCache.insert(std::map < std::string, bool >::value_type(std::string(privacyId), privacyEnabled)); + std::string privacyId; + int res = PrivacyIdInfo::getPrivacyIdFromPrivilege(privilege, privacyId); + if (res == PRIV_MGR_ERROR_NO_DATA) + return PRIV_MGR_ERROR_USER_NOT_CONSENTED; + TryReturn( res == PRIV_MGR_ERROR_SUCCESS, res, , "getPrivacyIdFromPrivilege : %d", res); + + LOGI("leave"); + + return check(privacyId); +} + +int +PrivacyChecker::checkWithDeviceCap(const std::string pkgId, const std::string deviceCap) +{ + LOGI("enter"); + + std::string privacyId; + int res = PrivacyIdInfo::getPrivacyIdFromDeviceCap(deviceCap, privacyId); + if (res == PRIV_MGR_ERROR_NO_DATA) + return PRIV_MGR_ERROR_USER_NOT_CONSENTED; + TryReturn( res == PRIV_MGR_ERROR_SUCCESS, res, , "getPrivacyIdFromPrivilege : %d", res); - LOGD("Privacy found : %s %d", privacyId, privacyEnabled); - } LOGI("leave"); + + return check(pkgId ,privacyId); +} + +int +PrivacyChecker::checkWithDeviceCap(const std::string deviceCap) +{ + LOGI("enter"); + + std::string privacyId; + int res = PrivacyIdInfo::getPrivacyIdFromDeviceCap(deviceCap, privacyId); + if (res == PRIV_MGR_ERROR_NO_DATA) + return PRIV_MGR_ERROR_USER_NOT_CONSENTED; + TryReturn( res == PRIV_MGR_ERROR_SUCCESS, res, , "getPrivacyIdFromPrivilege : %d", res); + + LOGI("leave"); + + return check(privacyId); +} + +int +PrivacyChecker::finalize(void) +{ + std::lock_guard guard (m_cacheMutex); + m_privacyCache.clear(); + m_privacyInfoCache.clear(); + + if (m_pLoop != NULL) + { + g_main_loop_quit(m_pLoop); + m_pLoop = NULL; + } + + m_isInitialized = false; + return PRIV_MGR_ERROR_SUCCESS; } + void PrivacyChecker::printCache(void) { @@ -258,37 +342,66 @@ PrivacyChecker::printCache(void) LOGD(" %s : %d", iter->first.c_str(), iter->second); } } + int -PrivacyChecker::updateCache(const std::string privacyId) +PrivacyChecker::updateCache(const std::string privacyId, std::map < std::string, bool >& pkgCacheMap) { - LOGI("enter"); - static const std::string PrivacyQuery = "SELECT IS_ENABLED from Privacy where ID=? and PRIVACY_ID=?"; - - int res; - int id; - res = getUniqueIdFromPackageId(m_pkgId, id); - TryReturn( res == 0, -1, , "getUniqueIdFromPackageId : %d", res); + return updateCache(m_pkgId, privacyId, pkgCacheMap); +} - LOGD("id : %d" ,id); +int +PrivacyChecker::updateCache(const std::string pkgId, std::string privacyId, std::map < std::string, bool >& pkgCacheMap) +{ + LOGI("enter"); + static const std::string PrivacyQuery = "SELECT IS_ENABLED from PrivacyInfo where PKG_ID=? and PRIVACY_ID=?"; - openDb(DB_PATH.c_str(), pDbH, SQLITE_OPEN_READONLY); + openDb(PRIVACY_DB_PATH.c_str(), pDbH, SQLITE_OPEN_READONLY); prepareDb(pDbH, PrivacyQuery.c_str(), pPrivacyStmt); - res = sqlite3_bind_int(pPrivacyStmt.get(), 1, id); - TryReturn( res == 0, -1, , "sqlite3_bind_int : %d", res); + int res = sqlite3_bind_text(pPrivacyStmt.get(), 1, pkgId.c_str(), -1, SQLITE_TRANSIENT); + TryReturn( res == 0, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_text : %d", res); res = sqlite3_bind_text(pPrivacyStmt.get(), 2, privacyId.c_str(), -1, SQLITE_TRANSIENT); - TryReturn( res == 0, -1, , "sqlite3_bind_text : %d", res); + TryReturn( res == 0, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_text : %d", res); + LOGI(" %s -- %s", pkgId.c_str(), privacyId.c_str()); while ( sqlite3_step(pPrivacyStmt.get()) == SQLITE_ROW ) { bool privacyEnabled = sqlite3_column_int(pPrivacyStmt.get(), 0) > 0 ? true : false; - std::lock_guard < std::mutex > guard(m_cacheMutex); - m_privacyCache.erase(privacyId); - m_privacyCache.insert(std::map < std::string, bool >::value_type(privacyId, privacyEnabled)); + LOGI("Set result : %s : %d", privacyId.c_str(), privacyEnabled ); + pkgCacheMap.erase(privacyId); + pkgCacheMap.insert(std::map < std::string, bool >::value_type(privacyId, privacyEnabled)); } LOGI("leave"); return PRIV_MGR_ERROR_SUCCESS; +} + + +int +PrivacyChecker::updateCache(std::map < std::string, bool >& pkgCacheMap) +{ + LOGI("enter"); + static const std::string PrivacyQuery = "SELECT PRIVACY_ID, IS_ENABLED from PrivacyInfo where PKG_ID=?"; + + pkgCacheMap.clear(); + + openDb(PRIVACY_DB_PATH.c_str(), pDbH, SQLITE_OPEN_READONLY); + prepareDb(pDbH, PrivacyQuery.c_str(), pPrivacyStmt); + int res = sqlite3_bind_text(pPrivacyStmt.get(), 1, m_pkgId.c_str(), -1, SQLITE_TRANSIENT); + TryReturn( res == 0, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_text : %d", res); + + while ( sqlite3_step(pPrivacyStmt.get()) == SQLITE_ROW ) + { + LOGI("start"); + const char* privacyId = reinterpret_cast < const char* > (sqlite3_column_text(pPrivacyStmt.get(), 0)); + bool privacyEnabled = sqlite3_column_int(pPrivacyStmt.get(), 1) > 0 ? true : false; + + pkgCacheMap.insert(std::map < std::string, bool >::value_type(std::string(privacyId), privacyEnabled)); + + LOGD("Privacy found : %s %d", privacyId, privacyEnabled); + } + LOGI("leave"); + return PRIV_MGR_ERROR_SUCCESS; } \ No newline at end of file diff --git a/client/src/PrivacyManager.cpp b/client/src/PrivacyManager.cpp deleted file mode 100644 index fca7d71..0000000 --- a/client/src/PrivacyManager.cpp +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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. - */ - -#include -#include -#include -#include -#include -#include - -std::mutex PrivacyManager::m_singletonMutex; -PrivacyManager* PrivacyManager::m_pInstance = NULL; -const std::string PrivacyManager::INTERFACE_NAME("PrivacyInfoService"); - -PrivacyManager::PrivacyManager(void) -{ - std::unique_ptr pSocketClient(new SocketClient(INTERFACE_NAME)); - m_pSocketClient = std::move(pSocketClient); -} - -PrivacyManager* -PrivacyManager::getInstance(void) -{ - std::lock_guard guard(m_singletonMutex); - if (m_pInstance == NULL) - m_pInstance = new PrivacyManager(); - return m_pInstance; -} - -int -PrivacyManager::addAppPackagePrivacyInfo(const std::string pkgId, const std::list < std::string >& pList) -{ - int result; - - std::list < std::string > privacyList; - - result = PrivacyIdInfo::getPrivacyIdListFromPrivilegeList(pList, privacyList); - if (result != PRIV_MGR_ERROR_SUCCESS ) - return result; - - if (privacyList.size() == 0) - return PRIV_MGR_ERROR_SUCCESS; - - m_pSocketClient->connect(); - m_pSocketClient->call("addPrivacyInfo", pkgId, privacyList, &result); - m_pSocketClient->disconnect(); - - return result; -} - -int -PrivacyManager::removeAppPackagePrivacyInfo(const std::string pkgId) -{ - int result; - m_pSocketClient->connect(); - m_pSocketClient->call("removePrivacyInfo", pkgId, pkgId, &result); - m_pSocketClient->disconnect(); - - return result; -} - -int -PrivacyManager::setPrivacySetting(const std::string pkgId, const std::string privacyId, bool isEnabled) -{ - int result; - m_pSocketClient->connect(); - m_pSocketClient->call("setPrivacySetting", pkgId, privacyId, isEnabled, &result); - m_pSocketClient->disconnect(); - - return result; -} - -int -PrivacyManager::getPrivacyAppPackages(std::list < std::string >& pList) -{ - int result, size; - std::string temp1; - SocketClient* p = new SocketClient(INTERFACE_NAME); - p->connect(); - p->call("getPrivacyAppPackages", &result, &size, &pList); - p->disconnect(); - - return result; -} - -int -PrivacyManager::getAppPackagePrivacyInfo(const std::string pkgId, std::list < std::pair > & list) -{ - - std::unique_ptr pSocketClient (new SocketClient(INTERFACE_NAME)); - - int result; - pSocketClient->connect(); - pSocketClient->call("getAppPackagePrivacyInfo", pkgId, &result, &list); - - pSocketClient->disconnect(); - - for (std::list < std::pair >::const_iterator iter = list.begin(); iter != list.end(); ++iter){ - LOGD(" %s : %d", iter->first.c_str(), iter->second); - } - - return result; -} - -int -PrivacyManager::isUserPrompted(const std::string pkgId, bool& isPrompted) -{ - LOGI("enter"); - - std::unique_ptr pSocketClient (new SocketClient(INTERFACE_NAME)); - - int result; - pSocketClient->connect(); - pSocketClient->call("isUserPrompted", pkgId, &result, &isPrompted); - pSocketClient->disconnect(); - - LOGI("leave"); - - return result; -} - -int -PrivacyManager::setUserPrompted(const std::string pkgId, bool prompted) -{ - LOGI("enter"); - - std::unique_ptr pSocketClient (new SocketClient(INTERFACE_NAME)); - - int result; - pSocketClient->connect(); - pSocketClient->call("setUserPrompted", pkgId, prompted, &result); - pSocketClient->disconnect(); - LOGI("leave"); - - return result; -} \ No newline at end of file diff --git a/client/src/PrivacyManagerClient.cpp b/client/src/PrivacyManagerClient.cpp new file mode 100644 index 0000000..cbdbc09 --- /dev/null +++ b/client/src/PrivacyManagerClient.cpp @@ -0,0 +1,190 @@ +/* + * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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. + */ + +#include +#include +#include +#include +#include +#include + +std::mutex PrivacyManagerClient::m_singletonMutex; +PrivacyManagerClient* PrivacyManagerClient::m_pInstance = NULL; +const std::string PrivacyManagerClient::INTERFACE_NAME("PrivacyInfoService"); + +PrivacyManagerClient::PrivacyManagerClient(void) +{ + std::unique_ptr pSocketClient(new SocketClient(INTERFACE_NAME)); + m_pSocketClient = std::move(pSocketClient); +} + +PrivacyManagerClient* +PrivacyManagerClient::getInstance(void) +{ + std::lock_guard guard(m_singletonMutex); + if (m_pInstance == NULL) + m_pInstance = new PrivacyManagerClient(); + return m_pInstance; +} + +int +PrivacyManagerClient::addAppPackagePrivacyInfo(const std::string pkgId, const std::list < std::string >& pList) +{ + + std::list < std::string > privacyList; + + int res = PrivacyIdInfo::getPrivacyIdListFromPrivilegeList(pList, privacyList); + if (res != PRIV_MGR_ERROR_SUCCESS ) + return res; + + if (privacyList.size() == 0) + return PRIV_MGR_ERROR_SUCCESS; + +#ifdef __READ_DB_IPC__ + m_pSocketClient->connect(); + m_pSocketClient->call("addPrivacyInfo", pkgId, privacyList, &result); + m_pSocketClient->disconnect(); + + return result; +#else + LOGI("enter"); + + static const std::string pkgInfoQuery("INSERT INTO PackageInfo(PKG_ID, IS_SET) VALUES(?, ?)"); + static const std::string privacyQuery("INSERT INTO PrivacyInfo(PKG_ID, PRIVACY_ID, IS_ENABLED) VALUES(?, ?, ?)"); + + openDb(PRIVACY_DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READWRITE); + prepareDb(pDbHandler, pkgInfoQuery.c_str(), pPkgInfoStmt); + + res = sqlite3_bind_text(pPkgInfoStmt.get(), 1, pkgId.c_str(), -1, SQLITE_TRANSIENT); + TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_text : %d", res); + + res = sqlite3_bind_int(pPkgInfoStmt.get(), 2, 0); + TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_int : %d", res); + + res = sqlite3_step(pPkgInfoStmt.get()); + TryReturn( res == SQLITE_DONE || res == SQLITE_CONSTRAINT, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_step : %d", res); + + prepareDb(pDbHandler, privacyQuery.c_str(), pPrivacyStmt); + for ( std::list ::const_iterator iter = privacyList.begin(); iter != privacyList.end(); ++iter) + { + LOGD(" install privacy: %s", iter->c_str()); + + res = sqlite3_bind_text(pPrivacyStmt.get(), 1, pkgId.c_str(), -1, SQLITE_TRANSIENT); + TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_int : %d", res); + + res = sqlite3_bind_text(pPrivacyStmt.get(), 2, iter->c_str(), -1, SQLITE_TRANSIENT); + TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_text : %d", res); + + // Before setting app and popup is ready, default value is true + res = sqlite3_bind_int(pPrivacyStmt.get(), 3, 1); + TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_int : %d", res); + + res = sqlite3_step(pPrivacyStmt.get()); + TryReturn( res == SQLITE_DONE || res == SQLITE_CONSTRAINT, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_step : %d", res); + + sqlite3_reset(pPrivacyStmt.get()); + } + + return 0; +#endif +} + +int +PrivacyManagerClient::removeAppPackagePrivacyInfo(const std::string pkgId) +{ + int result; + m_pSocketClient->connect(); + m_pSocketClient->call("removePrivacyInfo", pkgId, &result); + m_pSocketClient->disconnect(); + + return result; +} + +int +PrivacyManagerClient::setPrivacySetting(const std::string pkgId, const std::string privacyId, bool isEnabled) +{ + int result; + m_pSocketClient->connect(); + m_pSocketClient->call("setPrivacySetting", pkgId, privacyId, isEnabled, &result); + m_pSocketClient->disconnect(); + + return result; +} + +int +PrivacyManagerClient::getPrivacyAppPackages(std::list < std::string >& pList) +{ + int result, size; + std::string temp1; + SocketClient* p = new SocketClient(INTERFACE_NAME); + p->connect(); + p->call("getPrivacyAppPackages", &result, &size, &pList); + p->disconnect(); + + return result; +} + +int +PrivacyManagerClient::getAppPackagePrivacyInfo(const std::string pkgId, std::list < std::pair > & list) +{ + + std::unique_ptr pSocketClient (new SocketClient(INTERFACE_NAME)); + + int result; + pSocketClient->connect(); + pSocketClient->call("getAppPackagePrivacyInfo", pkgId, &result, &list); + + pSocketClient->disconnect(); + + for (std::list < std::pair >::const_iterator iter = list.begin(); iter != list.end(); ++iter){ + LOGD(" %s : %d", iter->first.c_str(), iter->second); + } + + return result; +} + +int +PrivacyManagerClient::isUserPrompted(const std::string pkgId, bool& isPrompted) +{ + LOGI("enter"); + + std::unique_ptr pSocketClient (new SocketClient(INTERFACE_NAME)); + + int result; + pSocketClient->connect(); + pSocketClient->call("isUserPrompted", pkgId, &result, &isPrompted); + pSocketClient->disconnect(); + + LOGI("leave"); + + return result; +} + +int +PrivacyManagerClient::setUserPrompted(const std::string pkgId, bool prompted) +{ + LOGI("enter"); + + std::unique_ptr pSocketClient (new SocketClient(INTERFACE_NAME)); + + int result; + pSocketClient->connect(); + pSocketClient->call("setUserPrompted", pkgId, prompted, &result); + pSocketClient->disconnect(); + LOGI("leave"); + + return result; +} \ No newline at end of file diff --git a/client/src/privacy_checker_client.cpp b/client/src/privacy_checker_client.cpp index 87a01e8..55159ff 100644 --- a/client/src/privacy_checker_client.cpp +++ b/client/src/privacy_checker_client.cpp @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include #include "privacy_manager_client_internal_types.h" @@ -35,33 +35,28 @@ int privacy_checker_check_privacy(const char *privacy_id) { return PrivacyChecker::check(std::string(privacy_id)); } -int privacy_checker_check_privacy_by_privilege(const char *privilege_id) -{ - int res; - std::string privacyId; - - res = PrivacyIdInfo::getPrivacyIdFromPrivilege(std::string(privilege_id), privacyId); - if (res != PRIV_MGR_ERROR_SUCCESS) - return res; - - return PrivacyChecker::check(privacyId); +int privacy_checker_check_by_privilege(const char *privilege_id) +{ + return PrivacyChecker::checkWithPrivilege(privilege_id); } -int privacy_checker_check_privacy_by_device_cap(const char *device_cap) +int privacy_checker_check_by_device_cap(const char *device_cap) { - int res; - std::string privacyId; - - res = PrivacyIdInfo::getPrivacyIdFromDeviceCap(std::string(device_cap), privacyId); - if (res != PRIV_MGR_ERROR_SUCCESS) - return res; - - return PrivacyChecker::check(privacyId); - + return PrivacyChecker::checkWithPrivilege(device_cap); } int privacy_checker_finalize(void) { return PrivacyChecker::finalize(); } + +int privacy_checker_check_package_by_privilege(const char* package_id, const char *privilege_id) +{ + return PrivacyChecker::checkWithPrivilege(package_id,privilege_id); +} + +int privacy_checker_check_package_by_device_cap(const char* package_id, const char *device_cap) +{ + return PrivacyChecker::checkWithDeviceCap(package_id, device_cap); +} \ No newline at end of file diff --git a/client/src/privacy_info_client.cpp b/client/src/privacy_info_client.cpp index 691c69c..d4d9e99 100644 --- a/client/src/privacy_info_client.cpp +++ b/client/src/privacy_info_client.cpp @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include #include "privacy_manager_client_internal_types.h" diff --git a/client/src/privacy_manager_client.cpp b/client/src/privacy_manager_client.cpp index eb9c155..24c0cb1 100644 --- a/client/src/privacy_manager_client.cpp +++ b/client/src/privacy_manager_client.cpp @@ -17,7 +17,8 @@ #include #include #include -#include +#include +#include #include #include "privacy_manager_client_internal_types.h" @@ -45,14 +46,17 @@ int create_privacy_info_client_s(const char* package_id, bool enabled, privacy_i int privacy_manager_client_install_privacy(const char *package_id, const char** privacy_list) { - int retval; - PrivacyManager* pInst = PrivacyManager::getInstance(); + LOGI("enter"); + + PrivacyManagerClient* pInst = PrivacyManagerClient::getInstance(); std::list < std::string > privacyList; - while (*privacy_list != NULL) - privacyList.push_back(std::string(*privacy_list ++)); + while (*privacy_list[0] != '\0') + privacyList.push_back(std::string(*privacy_list++)); + + int retval = pInst->addAppPackagePrivacyInfo(std::string(package_id), privacyList); - retval = pInst->addAppPackagePrivacyInfo(std::string(package_id), privacyList); + LOGI("leave"); return retval; } @@ -61,13 +65,13 @@ int privacy_manager_client_uninstall_privacy(const char *package_id) { if (package_id == NULL) return PRIV_MGR_ERROR_INVALID_PARAMETER; - return PrivacyManager::getInstance()->removeAppPackagePrivacyInfo(std::string(package_id)); + return PrivacyManagerClient::getInstance()->removeAppPackagePrivacyInfo(std::string(package_id)); } int privacy_manager_client_foreach_privacy_packages(privacy_manager_client_privacy_packages_cb callback, void *user_data) { int retval; - PrivacyManager* pInst = PrivacyManager::getInstance(); + PrivacyManagerClient* pInst = PrivacyManagerClient::getInstance(); std::list < std::string > list; retval = pInst->getPrivacyAppPackages(list); @@ -88,11 +92,11 @@ int privacy_manager_client_foreach_get_privacy_info(const char *package_id, priv { int retval; bool res; - PrivacyManager* pInst = PrivacyManager::getInstance(); + PrivacyManagerClient* pInst = PrivacyManagerClient::getInstance(); std::list < std::pair > list; - retval = pInst->getAppPackagePrivacyInfo(package_id, list); + retval = pInst->getAppPackagePrivacyInfo(std::string(package_id), list); if (retval != PRIV_MGR_ERROR_SUCCESS) return retval; if (list.size() == 0) @@ -112,7 +116,14 @@ int privacy_manager_client_foreach_get_privacy_info(const char *package_id, priv } int privacy_manager_client_set_package_privacy(const char *package_id, const char *privacy_id, bool enable) { - PrivacyManager* pInst = PrivacyManager::getInstance(); + PrivacyManagerClient* pInst = PrivacyManagerClient::getInstance(); return pInst->setPrivacySetting(package_id, privacy_id, enable); } + +int privacy_manager_client_check_user_consented(const char *package_id, bool consented) +{ + PrivacyManagerClient* pInst = PrivacyManagerClient::getInstance(); + + return pInst->isUserPrompted(std::string(package_id), consented); +} \ No newline at end of file diff --git a/common/inc/PrivacyIdInfo.h b/common/inc/PrivacyIdInfo.h index 6e75092..3756369 100644 --- a/common/inc/PrivacyIdInfo.h +++ b/common/inc/PrivacyIdInfo.h @@ -29,7 +29,7 @@ private: static bool m_isInitialized; public: - static void initialize(void); + static int initialize(void); static int getPrivacyIdFromPrivilege(const std::string privilege, std::string& privacyId); static int getPrivacyIdFromDeviceCap(const std::string deviceCap, std::string& privacyId); diff --git a/common/inc/PrivacyManagerTypes.h b/common/inc/PrivacyManagerTypes.h index 6b42115..5f7e128 100644 --- a/common/inc/PrivacyManagerTypes.h +++ b/common/inc/PrivacyManagerTypes.h @@ -20,6 +20,8 @@ #include #include +static const std::string PRIVACY_DB_PATH("/opt/dbspace/.privacy.db"); +static const std::string PRIVACY_INFO_DB_PATH("/opt/dbspace/.privacylist.db"); static const std::string SERVER_ADDRESS ("/tmp/privacy_manager_server"); static const std::string DBUS_PATH("/privacy_manager/dbus_notification"); static const std::string DBUS_SIGNAL_INTERFACE("org.tizen.privacy_manager.signal"); diff --git a/common/inc/Utils.h b/common/inc/Utils.h index d499231..0589924 100644 --- a/common/inc/Utils.h +++ b/common/inc/Utils.h @@ -22,7 +22,8 @@ #include #include #include - +#include +#include #define TryCatchLogReturn(condition, expr, r, logFormat) if (!(condition)) { \ LOGE(logFormat); \ @@ -66,4 +67,9 @@ auto DbDeleter = [&](sqlite3* pPtr) { LOGI("sqlite3_close"); sqlite3_close(pPtr) }\ setStmtToUniquePtr(pStmt, pStmt##Temp); +class Utils +{ +public: + static std::string toHash (std::string src); +}; #endif //_UTILS_H_ diff --git a/common/inc/privacy_manager_client_types.h b/common/inc/privacy_manager_client_types.h index a368742..e3da8ab 100644 --- a/common/inc/privacy_manager_client_types.h +++ b/common/inc/privacy_manager_client_types.h @@ -37,6 +37,7 @@ enum { PRIV_MGR_ERROR_IPC_ERROR = -16, PRIV_MGR_ERROR_INVALID_STATE = -17, PRIV_MGR_ERROR_SYSTEM_ERROR = -18, + PRIV_MGR_ERROR_USER_NOT_CONSENTED = -19, PRIV_MGR_ERROR_UNKNOWN = -(0x99), }; diff --git a/common/src/PrivacyIdInfo.cpp b/common/src/PrivacyIdInfo.cpp index ef8b260..080420b 100644 --- a/common/src/PrivacyIdInfo.cpp +++ b/common/src/PrivacyIdInfo.cpp @@ -16,8 +16,10 @@ #include #include +#include #include #include +#include std::map PrivacyIdInfo::m_privilegeToPrivacyMap; @@ -36,90 +38,103 @@ struct PrivacyDeviceCapPair char DeviceCap[128]; char privacy[128]; }; - +/* static struct PrivacyPrivilegePair DeviceCapToPrivacyTable[] = { - {"bluetooth.admin", "bluetooth"}, - {"bluetooth.gap", "bluetooth"}, - {"bluetooth.spp", "bluetooth"}, - {"bluetoothmanager", "bluetooth"}, + {"bluetooth.admin", "http://tizen.org/privacy/bluetooth"}, + {"bluetooth.gap", "http://tizen.org/privacy/bluetooth"}, + {"bluetooth.spp", "http://tizen.org/privacy/bluetooth"}, + {"bluetoothmanager", "http://tizen.org/privacy/bluetooth"}, - {"calendar.read", "calender"}, - {"calendar.write", "calender"}, + {"calendar.read", "http://tizen.org/privacy/calender"}, + {"calendar.write", "http://tizen.org/privacy/calender"}, - {"contact.read", "contact"}, - {"contact.write", "contact"}, + {"contact.read", "http://tizen.org/privacy/contact"}, + {"contact.write", "http://tizen.org/privacy/contact"}, - {"messaging.read", "messaging"}, - {"messaging.write", "messaging"}, - {"messaging.send", "messaging"}, + {"messaging.read", "http://tizen.org/privacy/messaging"}, + {"messaging.write", "http://tizen.org/privacy/messaging"}, + {"messaging.send", "http://tizen.org/privacy/messaging"}, - {"nfc.admin", "nfc"}, - {"nfcmanager.cardemulation", "nfc"}, - {"nfc.common", "nfc"}, - {"nfc.p2p", "nfc"}, - {"nfc.tag", "nfc"}, + {"nfc.admin", "http://tizen.org/privacy/nfc"}, + {"nfcmanager.cardemulation", "http://tizen.org/privacy/nfc"}, + {"nfc.common", "http://tizen.org/privacy/nfc"}, + {"nfc.p2p", "http://tizen.org/privacy/nfc"}, + {"nfc.tag", "http://tizen.org/privacy/nfc"}, - {"XMLHttpRequest", "internet"}, - {"externalNetworkAccess", "internet"}, + {"XMLHttpRequest", "http://tizen.org/privacy/internet"}, + {"externalNetworkAccess", "http://tizen.org/privacy/internet"}, {"\0", "\0"} }; static struct PrivacyPrivilegePair PrivilegeToPrivacyTable[] = { - {"http://tizen.org/privilege/bluetooth.admin", "bluetooth"}, - {"http://tizen.org/privilege/bluetooth.gap", "bluetooth"}, - {"http://tizen.org/privilege/bluetooth.health", "bluetooth"}, - {"http://tizen.org/privilege/bluetooth.opp", "bluetooth"}, - {"http://tizen.org/privilege/bluetooth.spp", "bluetooth"}, - {"http://tizen.org/privilege/bluetoothmanager", "bluetooth"}, + {"http://tizen.org/privilege/bluetooth.admin", "http://tizen.org/privacy/bluetooth"}, + {"http://tizen.org/privilege/bluetooth.gap", "http://tizen.org/privacy/bluetooth"}, + {"http://tizen.org/privilege/bluetooth.health", "http://tizen.org/privacy/bluetooth"}, + {"http://tizen.org/privilege/bluetooth.opp", "http://tizen.org/privacy/bluetooth"}, + {"http://tizen.org/privilege/bluetooth.spp", "http://tizen.org/privacy/bluetooth"}, + {"http://tizen.org/privilege/bluetoothmanager", "http://tizen.org/privacy/bluetooth"}, - {"http://tizen.org/privilege/calendar.read", "calender"}, - {"http://tizen.org/privilege/calendar.write", "calender"}, + {"http://tizen.org/privilege/calendar.read", "http://tizen.org/privacy/calender"}, + {"http://tizen.org/privilege/calendar.write", "http://tizen.org/privacy/calender"}, - {"http://tizen.org/privilege/contact.read", "contact"}, - {"http://tizen.org/privilege/contact.write", "contact"}, + {"http://tizen.org/privilege/contact.read", "http://tizen.org/privacy/contact"}, + {"http://tizen.org/privilege/contact.write", "http://tizen.org/privacy/contact"}, - {"http://tizen.org/privilege/contextmanager.privacy", "context"}, - {"http://tizen.org/privilege/contextmanager.upload", "context"}, + {"http://tizen.org/privilege/contextmanager.privacy", "http://tizen.org/privacy/context"}, + {"http://tizen.org/privilege/contextmanager.upload", "http://tizen.org/privacy/context"}, - {"http://tizen.org/privilege/location", "location"}, + {"http://tizen.org/privilege/location", "http://tizen.org/privacy/location"}, - {"http://tizen.org/privilege/messaging.read", "messaging"}, - {"http://tizen.org/privilege/messaging.write", "messaging"}, + {"http://tizen.org/privilege/messaging.read", "http://tizen.org/privacy/messaging"}, + {"http://tizen.org/privilege/messaging.write", "http://tizen.org/privacy/messaging"}, - {"http://tizen.org/privilege/nfc.admin", "nfc"}, - {"http://tizen.org/privilege/nfcmanager.cardemulation", "nfc"}, - {"http://tizen.org/privilege/nfc.common", "nfc"}, - {"http://tizen.org/privilege/nfc.p2p", "nfc"}, - {"http://tizen.org/privilege/nfc.tag", "nfc"}, + {"http://tizen.org/privilege/nfc.admin", "http://tizen.org/privacy/nfc"}, + {"http://tizen.org/privilege/nfcmanager.cardemulation", "http://tizen.org/privacy/nfc"}, + {"http://tizen.org/privilege/nfc.common", "http://tizen.org/privacy/nfc"}, + {"http://tizen.org/privilege/nfc.p2p", "http://tizen.org/privacy/nfc"}, + {"http://tizen.org/privilege/nfc.tag", "http://tizen.org/privacy/nfc"}, - {"http://tizen.org/privilege/http", "internet"}, - {"http://tizen.org/privilege/socket", "internet"}, - {"http://tizen.org/privilege/web.service", "internet"}, + {"http://tizen.org/privilege/http", "http://tizen.org/privacy/internet"}, + {"http://tizen.org/privilege/socket", "http://tizen.org/privacy/internet"}, + {"http://tizen.org/privilege/web.service", "http://tizen.org/privacy/internet"}, {"\0", "\0"} }; +*/ - -void +int PrivacyIdInfo::initialize(void) { - int i = 0; - while (PrivilegeToPrivacyTable[i].privilege[0] != '\0') - { - m_privilegeToPrivacyMap.insert(std::map < std::string, std::string >::value_type(std::string(PrivilegeToPrivacyTable[i].privilege), std::string(PrivilegeToPrivacyTable[i].privacy))); - ++i; - } - - i = 0; - while (DeviceCapToPrivacyTable[i].privilege[0] != '\0') - { - m_deviceCapToPrivacyMap.insert(std::map < std::string, std::string >::value_type(std::string(DeviceCapToPrivacyTable[i].privilege), std::string(DeviceCapToPrivacyTable[i].privacy))); - ++i; - } - m_isInitialized = true; + static const std::string sqlPrivilege("SELECT PRIVILEGE_ID, PRIVACY_ID from PrivilegeToPrivacyTable"); + static const std::string sqlDeviceCap("SELECT DEVICE_CAP, PRIVACY_ID from DeviceCapToPrivacyTable"); + + LOGI("enter"); + + openDb(PRIVACY_INFO_DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READONLY); + prepareDb(pDbHandler, sqlPrivilege.c_str(), pStmtPrivilege); + + int res; + while ( (res = sqlite3_step(pStmtPrivilege.get())) == SQLITE_ROW ) + { + const char* privilegeId = reinterpret_cast < const char* > (sqlite3_column_text(pStmtPrivilege.get(), 0)); + const char* privacyId = reinterpret_cast < const char* > (sqlite3_column_text(pStmtPrivilege.get(), 1)); + m_privilegeToPrivacyMap.insert(std::map < std::string, std::string >::value_type(std::string(privilegeId), std::string(privacyId))); + LOGD(" %s : %s", privilegeId, privacyId); + } + + prepareDb(pDbHandler, sqlDeviceCap.c_str(), pStmtDeviceCap); + while ( (res = sqlite3_step(pStmtDeviceCap.get())) == SQLITE_ROW ) + { + const char* DeviceCap = reinterpret_cast < const char* > (sqlite3_column_text(pStmtDeviceCap.get(), 0)); + const char* privacyId = reinterpret_cast < const char* > (sqlite3_column_text(pStmtDeviceCap.get(), 1)); + m_deviceCapToPrivacyMap.insert(std::map < std::string, std::string >::value_type(std::string(DeviceCap), std::string(privacyId))); + } + m_isInitialized = true; + + return PRIV_MGR_ERROR_SUCCESS; } int diff --git a/server/src/service/TestService.cpp b/common/src/Utils.cpp similarity index 61% rename from server/src/service/TestService.cpp rename to common/src/Utils.cpp index d9e77cc..b94e4af 100644 --- a/server/src/service/TestService.cpp +++ b/common/src/Utils.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,16 +14,9 @@ * limitations under the License. */ +#include -#include - -void -TestService::test(SocketConnection* pConnector) +std::string Utils::toHash(std::string src) { - std::string res1, res2; - pConnector->read(&res1, &res2); - LOGD("TEST received: %s %s", res1.c_str(),res2.c_str()); - - pConnector->write(std::string("-test OK-")); - pConnector->write(std::string("-byebye-")); -} + return src; +} \ No newline at end of file diff --git a/packaging/priavcy-manager.manifest b/packaging/priavcy-manager.manifest deleted file mode 100644 index 05112a1..0000000 --- a/packaging/priavcy-manager.manifest +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - diff --git a/packaging/privacy-manager-server.manifest b/packaging/privacy-manager-server.manifest index 05112a1..cb3db80 100644 --- a/packaging/privacy-manager-server.manifest +++ b/packaging/privacy-manager-server.manifest @@ -1,12 +1,21 @@ - + - - + + + + + + + + + + diff --git a/packaging/privacy-manager.spec b/packaging/privacy-manager.spec index 80a6d04..87e72b5 100644 --- a/packaging/privacy-manager.spec +++ b/packaging/privacy-manager.spec @@ -20,8 +20,6 @@ BuildRequires: pkgconfig(dbus-glib-1) Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig -provides: privacy-manager-server - %description Privacy Management @@ -38,14 +36,13 @@ summary: privacy-manager client Group: Development/Libraries Requires: privacy-manager-server = %{version}-%{release} -provides: libprivacy-manager-client.so.1 - %description -n privacy-manager-client privacy-manager client %package -n privacy-manager-client-devel Summary: privacy-manager client devel Group: Development/Libraries +BuildRequires: pkgconfig(libxml-2.0) Requires: privacy-manager-client = %{version}-%{release} %description -n privacy-manager-client-devel @@ -63,6 +60,7 @@ BuildRequires: pkgconfig(capi-base-common) BuildRequires: pkgconfig(glib-2.0) Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig +Requires: privacy-manager-client = %{version}-%{release} %description -n capi-security-privacy-manager The Privacy Manager API provides functions to get/set information about privacy information of installed packages. @@ -70,7 +68,7 @@ The Privacy Manager API provides functions to get/set information about privacy %package -n capi-security-privacy-manager-devel Summary: Privacy Manager API (Development) Group: TO_BE/FILLED_IN -Requires: %{name} = %{version}-%{release} +Requires: privacy-manager-client = %{version}-%{release} %description -n capi-security-privacy-manager-devel The Privacy Manager API provides functions to get/set information about privacy information of installed packages.(DEV) @@ -95,18 +93,20 @@ make %{?jobs:-j%jobs} %install rm -rf %{buildroot} mkdir -p %{buildroot}/usr/share/license -cp LICENSE.APLv2 %{buildroot}/usr/share/license/%{name} +cp LICENSE.APLv2 %{buildroot}/usr/share/license/privacy-manager-server mkdir -p %{buildroot}/usr/share/license cp LICENSE.APLv2 %{buildroot}/usr/share/license/privacy-manager-client mkdir -p %{buildroot}/usr/bin cp res/usr/bin/* %{buildroot}/usr/bin/ +mkdir -p %{buildroot}/opt/dbspace +cp res/opt/dbspace/.privacylist.db /%{buildroot}/opt/dbspace/ #mkdir -p %{buildroot}/etc/rc.d/init.d #cp res/etc/rc.d/init.d/* %{buildroot}/etc/rc.d/init.d/ %make_install -n privacy-manager-client install -D %{SOURCE2} %{buildroot}%{_datadir}/privacy-manager-client.manifest -%make_install -n privacy-manager-server +%make_install -n privacy-manager install -D %{SOURCE1} %{buildroot}%{_datadir}/privacy-manager-server.manifest %make_install -n capi-security-privacy-manager @@ -114,8 +114,8 @@ install -D %{SOURCE4} %{buildroot}%{_datadir}/capi-security-privacy-manager.mani #mkdir -p %{buildroot}/etc/rc.d/rc3.d #mkdir -p %{buildroot}/etc/rc.d/rc5.d -#ln -sf /etc/rc.d/init.d/wrt-security-daemon.sh %{buildroot}/etc/rc.d/rc3.d/S10privacy-manager-server.sh -#ln -sf /etc/rc.d/init.d/wrt-security-daemon.sh %{buildroot}/etc/rc.d/rc5.d/S10privacy-manager-server.sh +#ln -sf res/etc/rc.d/init.d/privacy-manager-server.sh %{buildroot}/etc/rc.d/rc3.d/S10privacy-manager-server.sh +#ln -sf res/etc/rc.d/init.d/privacy-manager-server.sh %{buildroot}/etc/rc.d/rc5.d/S10privacy-manager-server.sh mkdir -p %{buildroot}%{_libdir}/systemd/system/multi-user.target.wants install -m 0644 %{SOURCE3} %{buildroot}%{_libdir}/systemd/system/privacy-manager-server.service @@ -124,11 +124,13 @@ ln -sf /usr/lib/systemd/system/privacy-manager-server.service %{buildroot}%{_lib %clean rm -rf %{buildroot} -%post +%post -n privacy-manager-server /sbin/ldconfig +echo "Check privacy DB" if [ ! -f /opt/dbspace/.privacy.db ] then + echo "Create privacy DB" /usr/bin/privacy_manager_create_clean_db.sh fi @@ -137,10 +139,10 @@ fi %files -n privacy-manager-server %defattr(-,root,root,-) -%manifest %{_datadir}/%{name}.manifest +%manifest %{_datadir}/privacy-manager-server.manifest %{_bindir}/* %{_libdir}/systemd/* -#%{_libdir}/etc/rc.d/init.d/privacy-manager-server.sh +#/etc/rc.d/init.d/privacy-manager-server.sh #%attr(755,root,root) /etc/rc.d/init.d/privacy-manager-server.sh #/etc/rc.d/rc3.d/S10privacy-manager-server.sh #/etc/rc.d/rc5.d/S10privacy-manager-server.sh @@ -152,8 +154,10 @@ fi %files -n privacy-manager-client %defattr(-,root,root,-) %manifest %{_datadir}/privacy-manager-client.manifest -%{_libdir}/*.so* +%{_libdir}/libprivacy-manager-client.so* /usr/share/license/privacy-manager-client +/usr/etc/package-manager/parserlib/libprivileges.so +/opt/dbspace/.privacylist.db %files -n privacy-manager-client-devel %defattr(-,root,root,-) @@ -168,4 +172,3 @@ fi %{_includedir}/privacymgr/*.h %{_libdir}/libcapi-security-privacy-manager.so %{_libdir}/pkgconfig/capi-security-privacy-manager.pc - diff --git a/pkgmgr_plugin/CMakeLists.txt b/pkgmgr_plugin/CMakeLists.txt new file mode 100644 index 0000000..c3898b6 --- /dev/null +++ b/pkgmgr_plugin/CMakeLists.txt @@ -0,0 +1,57 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) + +SET (this_target privileges) + +SET(LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/cmake_build_tmp/output) + +INCLUDE(FindPkgConfig) +pkg_check_modules(bin_pkgs REQUIRED dlog libxml-2.0) + +INCLUDE_DIRECTORIES( + /usr/include + /usr/include/glib-2.0 + /usr/lib/glib-2.0/include + /usr/include/libxml2 + /usr/include/package_manager + /usr/include/dlog + "${CMAKE_SOURCE_DIR}/client/inc/" + "${CMAKE_SOURCE_DIR}/common/inc/" + ) + +SET (${this_target}_SOURCE_FILES + privileges.cpp + ) + +ADD_DEFINITIONS("-DDLOG_ERROR_ENABLED") +ADD_DEFINITIONS("-DLOG_TAG=\"PRIVILEGE_PLUGIN\"") +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wall" ) + +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") + +## Create Library +ADD_LIBRARY (${this_target} SHARED ${${this_target}_SOURCE_FILES} ) +ADD_DEPENDENCIES(${this_target} privacy-manager-client) +## SET LINKER FLAGS +SET(CMAKE_SHARED_LINKER_FLAGS -Wl,--no-undefined) + +TARGET_LINK_LIBRARIES(${this_target} "-lxml2" ) +TARGET_LINK_LIBRARIES(${this_target} "-lglib-2.0" ) +TARGET_LINK_LIBRARIES(${this_target} "-ldlog" ) +TARGET_LINK_LIBRARIES(${this_target} "-lprivacy-manager-client" "-L../client" ) + +ADD_CUSTOM_COMMAND(TARGET ${this_target} + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy ${LIBRARY_OUTPUT_PATH}/${CMAKE_SHARED_LIBRARY_PREFIX}${this_target}${CMAKE_SHARED_LIBRARY_SUFFIX} ${LIBRARY_OUTPUT_PATH}/debug/${CMAKE_SHARED_LIBRARY_PREFIX}${this_target}${CMAKE_SHARED_LIBRARY_SUFFIX} + COMMAND ${CMAKE_STRIP} --strip-unneeded ${LIBRARY_OUTPUT_PATH}/${CMAKE_SHARED_LIBRARY_PREFIX}${this_target}${CMAKE_SHARED_LIBRARY_SUFFIX} + COMMENT "strip ${this_target}" + ) + +INSTALL(TARGETS ${this_target} DESTINATION "../etc/package-manager/parserlib") + diff --git a/pkgmgr_plugin/privileges.cpp b/pkgmgr_plugin/privileges.cpp new file mode 100644 index 0000000..494306e --- /dev/null +++ b/pkgmgr_plugin/privileges.cpp @@ -0,0 +1,118 @@ +// +// Open Service Platform +// Copyright (c) 2013 Samsung Electronics Co., Ltd. +// +// 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. +// + +#include +#include +#include +#include +#include +#include +#include + +static const xmlChar _NODE_PRIVILEGES[] = "privileges"; +static const xmlChar _NODE_PRIVILEGE[] = "privilege"; + + +void destroy_char_list(char** ppList, int size) +{ + int i; + for (i = 0; i < size; ++i) + { + if (ppList[i]) + free(ppList[i]); + } + free(ppList); +} + +extern "C" +__attribute__ ((visibility("default"))) +int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr docPtr, const char* packageId) +{ + int ret; + LOGI("enter"); + + // Node: + xmlNodePtr curPtr = xmlFirstElementChild(xmlDocGetRootElement(docPtr)); + LOGD("Node: %s", curPtr->name); + + curPtr = curPtr->xmlChildrenNode; + if (curPtr == NULL) + { + LOGD("No privileges"); + return 0; + } + + std::list privilegeList; + while (curPtr != NULL) + { + LOGD("Node: %s", curPtr->name); + + if (xmlStrcmp(curPtr->name, _NODE_PRIVILEGE) == 0) + { + xmlChar* pPrivilege = xmlNodeListGetString(docPtr, curPtr->xmlChildrenNode, 1); + LOGD(" value= %s", reinterpret_cast(pPrivilege)); + if (pPrivilege == NULL) + { + LOGE("Failed to get value"); + return -EINVAL; + } + privilegeList.push_back(std::string( reinterpret_cast (pPrivilege))); + } + curPtr = curPtr->next; + } + + char** ppPrivilegeList = (char**) calloc(1, privilegeList.size() + 1); + std::list ::iterator iter = privilegeList.begin(); + for (int i = 0; i < privilegeList.size(); ++i) + { + ppPrivilegeList[i] = (char*)calloc (1, strlen(iter->c_str() + 1)); + if (ppPrivilegeList[i] == NULL) + { + destroy_char_list(ppPrivilegeList, privilegeList.size() + 1); + return -ENOMEM; + } + memcpy(ppPrivilegeList[i], iter->c_str(), strlen(iter->c_str())); + ++iter; + } + for (int i = 0; i < privilegeList.size(); ++i) + LOGD(" values : %s", ppPrivilegeList[i]); + + ppPrivilegeList[privilegeList.size()] = (char*)calloc (1, sizeof(char) + 1 ); + memcpy(ppPrivilegeList[privilegeList.size()], "\0", 1); + + ret = privacy_manager_client_install_privacy(packageId, (const char**) ppPrivilegeList); + destroy_char_list(ppPrivilegeList, privilegeList.size() + 1); + if (ret != PRIV_MGR_ERROR_SUCCESS) + { + LOGD("Failed to install privacy : %d", ret); + return -EINVAL; + } + + LOGI("leave"); +} + +extern "C" +__attribute__ ((visibility("default"))) +int PKGMGR_PARSER_PLUGIN_UNINSTALL(xmlDocPtr docPtr, const char* packageId) +{ + LOGI("enter"); + + privacy_manager_client_uninstall_privacy(packageId); + + return 0; + LOGI("leave"); +} \ No newline at end of file diff --git a/privacy-manager-test.pc.in b/privacy-manager-test.pc.in deleted file mode 100644 index 0bba87a..0000000 --- a/privacy-manager-test.pc.in +++ /dev/null @@ -1,9 +0,0 @@ -prefix=@PREFIX@ -exec_prefix=@EXEC_PREFIX@ -libdir=@LIBDIR@ -includedir=@INCLUDEDIR@ - -Name: privacy-manager-server -Description: Privacy Manager Server -Version: @VERSION@ -Requires: diff --git a/res/opt/dbspace/.privacylist.db b/res/opt/dbspace/.privacylist.db new file mode 100644 index 0000000000000000000000000000000000000000..26eeff582c583d3d35a46bb155eed011cae59bf3 GIT binary patch literal 9216 zcmeHN&1)M+6rY)=k65wd$W5crLRrTjvWP9!c1%f9XjN%R6-$;SD``wI>UuqvRZCh$ zTH9%%2Z0YgwTD9ggF>N)(&pStAeWwUD1=^n3KV=QDYPzhR?=>?K|8yG9)i0AE9T?P z`}ob9H*W^5=Q9+vsh1hi4Et=# zGZI-4rc3 z>uKoxd5DSz1bhQnQaV329QnE7$b-X?j}Art<{5}&d&#biPxPqbewa39@Yl9`jb0it zxe#}X0s5kkdAQ+1d}q~tXxRhv&wZ#S)ul3RS}wNXMvGu_y;j44>s`fcGZ`FW(sr#< zx0j^l|9<=!;m2fxG{{2;!AJ0;wF|o=FE;`?3{rmJvUgtg<3l@0mcXVnhK>T{8i4GK z-7b}?>h3^O*n|6XL$V&H3Mx*vQP%5}ougg3=5uJTaN; zj?gGdAou|&Tp|xijZEQR@DY9o{f@q214lOgp11&ck)sYfjAD&N>-fdSnS=?hl+-Km zft?IlsnrzgfXBoX#-U}yrMCz%S!!<6+J041D}0{G5Zt!mX%mT=Vyow&#M=|b3B*74 z4YJj-|CZm)bFj|yxT+%afzk=qN1>MG_=f%{YhG5!z>K~|u z7FT*YtOQ`wjw^eQcb1>r8i5a;FyrsoZt9Xf10~*K7~9`jf)a$ck%xST;3x7Y9I%R8 zTm)WD1a4h|4W8#8(ydsFHnsm$Snh89I+eT#D?DBr16w8xrt6NN(yrR3B8DNy6W>zg VJ!*e{PP}S=_Nr3Z(hzp`{0m6PeGmWu literal 0 HcmV?d00001 diff --git a/res/usr/bin/privacy_db.sql b/res/usr/bin/privacy_db.sql index 5b16806..49a0557 100644 --- a/res/usr/bin/privacy_db.sql +++ b/res/usr/bin/privacy_db.sql @@ -1,25 +1,18 @@ PRAGMA foreign_keys = ON; BEGIN TRANSACTION; CREATE TABLE PackageInfo( - UNIQUE_ID INTEGER PRIMARY KEY AUTOINCREMENT, - PKG_ID TEXT not null, + PKG_ID TEXT not null PRIMARY KEY UNIQUE, IS_SET BOOL not null, CHECK(1) ); -CREATE TABLE Privacy( - ID INTEGER not null, +CREATE TABLE PrivacyInfo( + PKG_ID TEXT not null , PRIVACY_ID TEXT not null, IS_ENABLED INTEGER not null, - FOREIGN KEY(ID) REFERENCES PackageInfo(UNQUE_ID), + FOREIGN KEY(PKG_ID) REFERENCES PackageInfo(PKG_ID), + CONSTRAINT PKG_PRIVACY UNIQUE (PKG_ID, PRIVACY_ID) CHECK(1) ); -CREATE VIEW PrivacyView as SELECT - PackageInfo.UNIQUE_ID, - PackageInfo.PKG_ID, - Privacy.PRIVACY_ID, - Privacy.IS_ENABLED - FROM PackageInfo, Privacy - WHERE PackageInfo.UNIQUE_ID = Privacy.ID; COMMIT; BEGIN TRANSACTION; CREATE TABLE DB_VERSION_0_1 (version INT); COMMIT; diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index a0f2d39..2dc6f84 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -54,16 +54,15 @@ SET(PRIVACY_MANAGER_SERVER_SOURCES ${server_src_dir}/SocketService.cpp ${server_src_dir}/PrivacyManagerDaemon.cpp ${server_src_dir}/service/PrivacyInfoService.cpp - ${server_src_dir}/service/TestService.cpp ${server_src_dir}/PrivacyManagerServer.cpp ${server_src_dir}/NotificationServer.cpp ) SET(PRIVACY_MANAGER_SERVER_HEADERS - ${server_include_dir}/SocketService.h - ${server_include_dir}/PrivacyManagerDaemon.h - ${common_include_dir}/SocketConnection.h - ${common_include_dir}/SocketConnection.h + # ${server_include_dir}/SocketService.h + # ${server_include_dir}/PrivacyManagerDaemon.h + # ${common_include_dir}/SocketConnection.h + # ${common_include_dir}/SocketConnection.h ) SET(PRIVACY_MANAGER_SERVER_LDFLAGS " -module -avoid-version ") SET(PRIVACY_MANAGER_SERVER_CFLAGS " ${CFLAGS} -fPIC ") @@ -81,4 +80,4 @@ CONFIGURE_FILE(../privacy-manager-server.pc.in privacy-manager-server.pc @ONLY) INSTALL(TARGETS privacy-manager-server DESTINATION ../bin COMPONENT RuntimeLibraries) INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/privacy-manager-server.pc DESTINATION ../lib/pkgconfig) -INSTALL(FILES ${PRIVACY_MANAGER_SERVER_HEADERS} DESTINATION ../include/privacy_manager/server) \ No newline at end of file +INSTALL(FILES ${PRIVACY_MANAGER_SERVER_HEADERS} DESTINATION ../include/privacy_manager/server) diff --git a/server/inc/PrivacyManagerServer.h b/server/inc/PrivacyManagerServer.h index c9a7689..ec75620 100644 --- a/server/inc/PrivacyManagerServer.h +++ b/server/inc/PrivacyManagerServer.h @@ -14,34 +14,25 @@ * limitations under the License. */ -#ifndef _PRIVACY_DB_H_ -#define _PRIVACY_DB_H_ +#ifndef _PRIVACY_MANAGER_SERVER_H_ +#define _PRIVACY_MANAGER_SERVER_H_ #include #include #include #include -#include #include class NotificationServer; -struct sqlite3; -class a; class PrivacyManagerServer { private: static std::mutex m_singletonMutex; - static const std::string DB_PATH; static PrivacyManagerServer* m_pInstance; - sqlite3* m_pDBHandler; NotificationServer m_notificationServer; - const static std::string CREATE_PACKAGE_INFO_TABLE; - const static std::string CREATE_PRIVACY_TABLE; - private: void createDB(void); - int isPackageIdAreadyExisted(const std::string pkgId, bool& isExisted); public: @@ -49,13 +40,9 @@ public: static PrivacyManagerServer* getInstance(void); - sqlite3* getDBHandler(void); - - int getUniqueIdFromPackageId(const std::string pkgId, int& id); - int getPrivacyAppPackages(std::list & list); - int getAppPackagePrivacyInfo(const std::string pkgId, std::list < std::pair < std::string, bool > > *pList); + int getAppPackagePrivacyInfo(const std::string pkgId, std::list < std::pair < std::string, bool > > & list); int setPrivacySetting(const std::string pkgId, const std::string privacyId, bool enabled); @@ -69,4 +56,4 @@ public: }; -#endif // _PRIVACY_DB_H_ \ No newline at end of file +#endif // _PRIVACY_MANAGER_SERVER_H_ \ No newline at end of file diff --git a/server/inc/TestService.h b/server/inc/TestService.h deleted file mode 100644 index 1498ce5..0000000 --- a/server/inc/TestService.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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. - */ - -#ifndef _TEST_SERVICE_H_ -#define _TEST_SERVICE_H_ - -#include -#include - -class TestService { -private: - inline static std::string getInterfaceName(void) - { - return "TestService"; - } - -public: - static void registerCallbacks(SocketService* pSocketService) - { - pSocketService->registerServiceCallback(getInterfaceName(), std::string("test"), test); - } - - static void test(SocketConnection* pConnector); - -}; -#endif // _TEST_SERVICE_H_ \ No newline at end of file diff --git a/server/src/PrivacyManagerDaemon.cpp b/server/src/PrivacyManagerDaemon.cpp index 44c9674..b448e0a 100644 --- a/server/src/PrivacyManagerDaemon.cpp +++ b/server/src/PrivacyManagerDaemon.cpp @@ -17,7 +17,6 @@ #include #include #include -#include #include PrivacyManagerDaemon* PrivacyManagerDaemon::pInstance = NULL; @@ -51,7 +50,6 @@ PrivacyManagerDaemon::inialize(void) pSocketService->initialize(); PrivacyInfoService::registerCallbacks(pSocketService); - TestService::registerCallbacks(pSocketService); return 0; } diff --git a/server/src/PrivacyManagerServer.cpp b/server/src/PrivacyManagerServer.cpp index c54d87b..7a729dd 100644 --- a/server/src/PrivacyManagerServer.cpp +++ b/server/src/PrivacyManagerServer.cpp @@ -19,9 +19,9 @@ #include #include #include +#include std::mutex PrivacyManagerServer::m_singletonMutex; -const std::string PrivacyManagerServer::DB_PATH("/opt/dbspace/.privacy.db"); PrivacyManagerServer* PrivacyManagerServer::m_pInstance = NULL; void @@ -31,82 +31,19 @@ PrivacyManagerServer::createDB(void) } int -PrivacyManagerServer::isPackageIdAreadyExisted(const std::string pkgId, bool& isExisted) -{ - LOGI("enter"); - - isExisted = false; - - static const std::string query = std::string("SELECT UNIQUE_ID from PackageInfo where PKG_ID=?"); - - int res; - - openDb(DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READWRITE); - prepareDb(pDbHandler, query.c_str(), pStmt); - - res = sqlite3_bind_text(pStmt.get(), 1, pkgId.c_str(), -1, SQLITE_TRANSIENT); - TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_prepare_v2 : %d", res); - - res = sqlite3_step(pStmt.get()); - if (res == SQLITE_DONE) - { - isExisted = true; - return 0; - } - - LOGI("leave"); - - return 0; -} - -int -PrivacyManagerServer::getUniqueIdFromPackageId(const std::string pkgId, int& uniqueId) -{ - LOGI("enter"); - - static const std::string query = std::string("SELECT UNIQUE_ID from PackageInfo where PKG_ID=?"); - - int res; - - openDb(DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READWRITE); - prepareDb(pDbHandler, query.c_str(), pStmt); - - res = sqlite3_bind_text(pStmt.get(), 1, pkgId.c_str(), -1, SQLITE_TRANSIENT); - TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_prepare_v2 : %d", res); - - res = sqlite3_step(pStmt.get()); - TryReturn( res == SQLITE_ROW, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_step : %d", res); - - - int cnt = sqlite3_data_count(pStmt.get()); - TryReturn(cnt != 0, PRIV_MGR_ERROR_NO_DATA, , "Failed to find data"); - - uniqueId = sqlite3_column_int(pStmt.get(), 0); - - LOGI("%s : %d", pkgId.c_str(), uniqueId); - - LOGI("leave"); - - return 0; -} -int PrivacyManagerServer::setPrivacySetting(const std::string pkgId, const std::string privacyId, bool enabled) { LOGI("enter"); - static const std::string query = std::string("UPDATE Privacy set IS_ENABLED =? where ID=? and PRIVACY_ID=?"); - - int uniqueId; - int res = getUniqueIdFromPackageId(pkgId, uniqueId); - TryReturn(res == 0, PRIV_MGR_ERROR_NO_DATA, , "getUniqueIdFromPackageId : %d", res); + static const std::string query = std::string("UPDATE PrivacyInfo set IS_ENABLED =? where PKG_ID=? and PRIVACY_ID=?"); - openDb(DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READWRITE); + openDb(PRIVACY_DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READWRITE); prepareDb(pDbHandler, query.c_str(), pStmt); - res = sqlite3_bind_int(pStmt.get(), 1, enabled); + int res = sqlite3_bind_int(pStmt.get(), 1, enabled); TryReturn(res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_int : %d", res); - res = sqlite3_bind_int(pStmt.get(), 2, uniqueId); + res = sqlite3_bind_text(pStmt.get(), 2, pkgId.c_str(), -1, SQLITE_TRANSIENT); TryReturn(res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_int : %d", res); res = sqlite3_bind_text(pStmt.get(), 3, privacyId.c_str(), -1, SQLITE_TRANSIENT); @@ -128,9 +65,9 @@ PrivacyManagerServer::getPrivacyAppPackages(std::list & list) { LOGI("enter"); - std::string query = "SELECT pkg_id from PackageInfo"; + std::string query = "SELECT PKG_ID from PackageInfo"; - openDb(DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READWRITE); + openDb(PRIVACY_DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READWRITE); prepareDb(pDbHandler, query.c_str(), pStmt); while ( sqlite3_step(pStmt.get()) == SQLITE_ROW ) @@ -147,35 +84,29 @@ PrivacyManagerServer::getPrivacyAppPackages(std::list & list) } int -PrivacyManagerServer::getAppPackagePrivacyInfo(const std::string pkgId, std::list < std::pair < std::string, bool > >* pPrivacyInfoList) +PrivacyManagerServer::getAppPackagePrivacyInfo(const std::string pkgId, std::list < std::pair < std::string, bool > >& privacyInfoList) { LOGI("enter"); - static const std::string query = "SELECT PRIVACY_ID, IS_ENABLED from Privacy where ID=?"; - - int uniqueId; - int res = getUniqueIdFromPackageId(pkgId, uniqueId); - TryReturn( res == 0, -1, , "getUniqueIdFromPackageId : %d", res); + static const std::string query = "SELECT PRIVACY_ID, IS_ENABLED from PrivacyInfo where PKG_ID=?"; - openDb(DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READWRITE); + openDb(PRIVACY_DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READWRITE); prepareDb(pDbHandler, query.c_str(), pStmt); - res = sqlite3_bind_int(pStmt.get(), 1, uniqueId); + int res = sqlite3_bind_text(pStmt.get(), 1, pkgId.c_str(), -1, SQLITE_TRANSIENT); TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_int : %d", res); - std::unique_ptr < std::list < std::pair < std:: string, bool > > > pList ( new std::list < std::pair < std:: string, bool > >); - LOGI("start"); - while ((res= sqlite3_step(pStmt.get())) == SQLITE_ROW ) + + while ( (res= sqlite3_step(pStmt.get())) == SQLITE_ROW ) { const char* privacyId = reinterpret_cast < const char* > (sqlite3_column_text(pStmt.get(), 0)); bool privacyEnabled = sqlite3_column_int(pStmt.get(), 1) > 0 ? true : false; - pList->push_back( std::pair (std::string(privacyId), privacyEnabled) ); + privacyInfoList.push_back( std::pair (std::string(privacyId), privacyEnabled) ); LOGD("Privacy found : %s %d", privacyId, privacyEnabled); } - *pPrivacyInfoList = *pList.release(); LOGI("leave"); @@ -189,18 +120,12 @@ PrivacyManagerServer::addAppPackagePrivacyInfo(const std::string pkgId, const st LOGI("enter"); static const std::string pkgInfoQuery("INSERT INTO PackageInfo(PKG_ID, IS_SET) VALUES(?, ?)"); - static const std::string privacyQuery("INSERT INTO Privacy(ID, PRIVACY_ID, IS_ENABLED) VALUES(?, ?, ?)"); - - int res; - int uniqueId; - bool check; - res = isPackageIdAreadyExisted(pkgId, check); - TryReturn(check, PRIV_MGR_ERROR_INVALID_STATE, ,"The pkg ID %s is alreay added : %d", pkgId.c_str(), res); + static const std::string privacyQuery("INSERT INTO PrivacyInfo(PKG_ID, PRIVACY_ID, IS_ENABLED) VALUES(?, ?, ?)"); - openDb(DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READWRITE); + openDb(PRIVACY_DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READWRITE); prepareDb(pDbHandler, pkgInfoQuery.c_str(), pPkgInfoStmt); - res = sqlite3_bind_text(pPkgInfoStmt.get(), 1, pkgId.c_str(), -1, SQLITE_TRANSIENT); + int res = sqlite3_bind_text(pPkgInfoStmt.get(), 1, pkgId.c_str(), -1, SQLITE_TRANSIENT); TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_text : %d", res); res = sqlite3_bind_int(pPkgInfoStmt.get(), 2, 0); @@ -208,16 +133,13 @@ PrivacyManagerServer::addAppPackagePrivacyInfo(const std::string pkgId, const st res = sqlite3_step(pPkgInfoStmt.get()); TryReturn( res == SQLITE_DONE, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_step : %d", res); - - - res = getUniqueIdFromPackageId(pkgId, uniqueId); - TryReturn( res == PRIV_MGR_ERROR_SUCCESS, res, , "getUniqueIdFromPackageId : %d", res); for ( std::list ::const_iterator iter = privilegeList.begin(); iter != privilegeList.end(); ++iter) { + LOGD(" install privacy: %s", iter->c_str()); prepareDb(pDbHandler, privacyQuery.c_str(), pPrivacyStmt); - res = sqlite3_bind_int(pPrivacyStmt.get(), 1, uniqueId); + res = sqlite3_bind_text(pPrivacyStmt.get(), 1, pkgId.c_str(), -1, SQLITE_TRANSIENT); TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_int : %d", res); res = sqlite3_bind_text(pPrivacyStmt.get(), 2, iter->c_str(), -1, SQLITE_TRANSIENT); @@ -228,7 +150,9 @@ PrivacyManagerServer::addAppPackagePrivacyInfo(const std::string pkgId, const st TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_int : %d", res); res = sqlite3_step(pPrivacyStmt.get()); - TryReturn( res == SQLITE_DONE, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_step : %d", res); + TryReturn( res == SQLITE_DONE || res == SQLITE_CONSTRAINT, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_step : %d", res); + + sqlite3_reset(pPrivacyStmt.get()); } return 0; @@ -240,14 +164,11 @@ PrivacyManagerServer::removeAppPackagePrivacyInfo(const std::string pkgId) LOGI("enter"); static const std::string pkgInfoQuery("DELETE FROM PackageInfo WHERE PKG_ID=?"); - static const std::string privacyQuery("DELETE FROM Privacy WHERE ID=?"); + static const std::string privacyQuery("DELETE FROM PrivacyInfo WHERE PKG_ID=?"); int res; - int uniqueId; - res = getUniqueIdFromPackageId(pkgId, uniqueId); - TryReturn( res == 0, res, , "getUniqueIdFromPackageId : %d", res); - openDb(DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READWRITE); + openDb(PRIVACY_DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READWRITE); prepareDb(pDbHandler, pkgInfoQuery.c_str(), pPkgInfoStmt); res = sqlite3_bind_text(pPkgInfoStmt.get(), 1, pkgId.c_str(), -1, SQLITE_TRANSIENT); @@ -258,8 +179,8 @@ PrivacyManagerServer::removeAppPackagePrivacyInfo(const std::string pkgId) prepareDb(pDbHandler, privacyQuery.c_str(), pPrivacyStmt); - res = sqlite3_bind_int(pPrivacyStmt.get(), 1, uniqueId); - TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_int : %d", res); + res = sqlite3_bind_text(pPrivacyStmt.get(), 1, pkgId.c_str(), -1, SQLITE_TRANSIENT); + TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_text : %d", res); res = sqlite3_step(pPrivacyStmt.get()); TryReturn( res == SQLITE_DONE, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_step : %d", res); @@ -274,14 +195,12 @@ PrivacyManagerServer::isUserPrompted(const std::string pkgId, bool& isPrompted) static const std::string query = "SELECT IS_SET from PackageInfo where PKG_ID=?"; - int uniqueId; - int res = getUniqueIdFromPackageId(pkgId, uniqueId); - TryReturn( res == 0, res, , "getUniqueIdFromPackageId : %d", res); + isPrompted = true; - openDb(DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READWRITE); + openDb(PRIVACY_DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READWRITE); prepareDb(pDbHandler, query.c_str(), pStmt); - res = sqlite3_bind_text(pStmt.get(), 1, pkgId.c_str(), -1, SQLITE_TRANSIENT); + int res = sqlite3_bind_text(pStmt.get(), 1, pkgId.c_str(), -1, SQLITE_TRANSIENT); TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_text : %d", res); std::unique_ptr < std::list < std::pair < std:: string, bool > > > pList ( new std::list < std::pair < std:: string, bool > >); @@ -292,12 +211,10 @@ PrivacyManagerServer::isUserPrompted(const std::string pkgId, bool& isPrompted) } else { - LOGE("Fail to get data : %d", res); + LOGE("The package[%s] doesnt access privacy", pkgId.c_str()); return PRIV_MGR_ERROR_DB_ERROR; } - LOGI("leave"); - return 0; } @@ -310,7 +227,7 @@ PrivacyManagerServer::setUserPrompted(const std::string pkgId, bool prompted) int res; - openDb(DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READWRITE); + openDb(PRIVACY_DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READWRITE); prepareDb(pDbHandler, query.c_str(), pStmt); res = sqlite3_bind_int(pStmt.get(), 1, prompted? 1 : 0); @@ -344,10 +261,4 @@ PrivacyManagerServer::getInstance(void) } LOGI("leave"); return m_pInstance; -} - -sqlite3* -PrivacyManagerServer::getDBHandler(void) -{ - return m_pDBHandler; -} +} \ No newline at end of file diff --git a/server/src/service/PrivacyInfoService.cpp b/server/src/service/PrivacyInfoService.cpp index 664da44..d822e13 100644 --- a/server/src/service/PrivacyInfoService.cpp +++ b/server/src/service/PrivacyInfoService.cpp @@ -90,7 +90,7 @@ PrivacyInfoService::getAppPackagePrivacyInfo(SocketConnection* pConnector) std::list < std::pair < std::string, bool > > infoList; - int res = pPrivacyManagerServer->getAppPackagePrivacyInfo(pkgId, &infoList); + int res = pPrivacyManagerServer->getAppPackagePrivacyInfo(pkgId, infoList); pConnector->write( res ); pConnector->write( infoList ); -- 2.7.4