diff options
author | jk7744.park <jk7744.park@samsung.com> | 2016-02-24 18:58:10 +0900 |
---|---|---|
committer | jk7744.park <jk7744.park@samsung.com> | 2016-02-24 18:58:10 +0900 |
commit | 4a599b7918a66c837e3bfd848242688ba4ac2099 (patch) | |
tree | 6abb179d430eee16dca1f64a3fefa196cd7de58c | |
parent | 1fe1fed0cd28f6e024edff903558528c545f7019 (diff) | |
download | privilege-checker-tizen_2.4.tar.gz privilege-checker-tizen_2.4.tar.bz2 privilege-checker-tizen_2.4.zip |
Tizen 2.4.0 rev3 SDK Public Releasetizen_2.4
-rwxr-xr-x | capi/include/privilege_info.h | 16 | ||||
-rwxr-xr-x | capi/include/privilege_info_types.h | 45 | ||||
-rwxr-xr-x | capi/include/privilege_manager.h | 2 | ||||
-rwxr-xr-x | capi/src/privilege_info.c | 30 | ||||
-rw-r--r-- | checker/CMakeLists.txt | 26 | ||||
-rwxr-xr-x | checker/include/privilege_checker.h | 102 | ||||
-rwxr-xr-x | checker/include/privilege_checker_extension.h | 44 | ||||
-rwxr-xr-x | checker/security-privilege-checker.pc.in | 3 | ||||
-rwxr-xr-x | checker/src/privilege_checker.c | 125 | ||||
-rw-r--r-- | checker/src/test_framework.c | 31 | ||||
-rw-r--r-- | packaging/privilege-checker.spec | 44 | ||||
-rw-r--r-- | packaging/security-privilege-checker.manifest | 5 | ||||
-rwxr-xr-x | test/CMakeLists.txt | 2 |
13 files changed, 275 insertions, 200 deletions
diff --git a/capi/include/privilege_info.h b/capi/include/privilege_info.h index 6d177db..365c2d0 100755 --- a/capi/include/privilege_info.h +++ b/capi/include/privilege_info.h @@ -28,7 +28,7 @@ extern "C" { * @brief Called to get a privilege group once for specific package. * @param[in] privilege_group The privilege group * @param[in] user_data The user data passed from the foreach function - * @return 0 if success, nonzero value(>0) if fail. Callback is not called if return value is nonzero. + * @return 0 if success, negative value(<0) if fail. Callback is not called if return value is negative. * @pre privilege_info_foreach_privilege_group_list_by_pkgid() will invoke this callback. * @see privilege_info_foreach_privilege_group_list_by_pkgid() */ @@ -38,7 +38,7 @@ typedef int (*privilege_info_privilege_groups_cb) (const char *privilege_group, * @brief Called to get a privilege in the privilege group once for specific package. * @param[in] privilege The privilege * @param[in] user_data The user data passed from the foreach function - * @return 0 if success, nonzero value(>0) if fail. Callback is not called if return value is nonzero. + * @return 0 if success, negative value(<0) if fail. Callback is not called if return value is negative. * @pre privilege_info_foreach_privilege_list_by_pkgid_and_privilege_group() will invoke this callback. * @see privilege_info_foreach_privilege_list_by_pkgid_and_privilege_group() */ @@ -49,7 +49,7 @@ typedef int (*privilege_info_privileges_cb) (const char *privilege, void* user_d * @param [in] package_id The package id * @param [in] callback The callback function to invoke * @param [in] user_data The user data to be passed to the callback function - * @return 0 on success, otherwise a nonzero error value. + * @return 0 on success, otherwise a negative error value. * @retval #PRVMGR_ERR_NONE Successful * @retval #PRVMGR_ERR_INTERNAL_ERROR Internal error * @retval #PRVMGR_ERR_INVALID_PARAMETER Invalid parameter @@ -63,7 +63,7 @@ EXPORT_API int privilege_info_foreach_privilege_group_list_by_pkgid(const char * * @param [in] package_id The package id * @param [in] callback The callback function to invoke * @param [in] user_data The user data to be passed to the callback function - * @return 0 on success, otherwise a nonzero error value. + * @return 0 on success, otherwise a negative error value. * @retval #PRVMGR_ERR_NONE Successful * @retval #PRVMGR_ERR_INTERNAL_ERROR Internal error * @retval #PRVMGR_ERR_INVALID_PARAMETER Invalid parameter @@ -76,7 +76,7 @@ EXPORT_API int privilege_info_foreach_privilege_list_by_pkgid_and_privilege_grou * @remarks @a name must be released with free() by you. * @param [in] privilege_group The privilege group * @param [out] name The display name of the privilege group - * @return 0 on success, otherwise a nonzero error value. + * @return 0 on success, otherwise a negative error value. * @retval #PRVMGR_ERR_NONE Successful * @retval #PRVMGR_ERR_OUT_OF_MEMORY Out of memory * @retval #PRVMGR_ERR_INVALID_PARAMETER Invalid parameter @@ -88,7 +88,7 @@ EXPORT_API int privilege_info_get_privilege_group_display_name(const char *privi * @remarks @a name must be released with free() by you. * @param [in] privilege The privilege * @param [out] name The display name of the privilege - * @return 0 on success, otherwise a nonzero error value. + * @return 0 on success, otherwise a negative error value. * @retval #PRVMGR_ERR_NONE Successful * @retval #PRVMGR_ERR_OUT_OF_MEMORY Out of memory * @retval #PRVMGR_ERR_INVALID_PARAMETER Invalid parameter @@ -100,7 +100,7 @@ EXPORT_API int privilege_info_get_privilege_display_name(const char *privilege, * @remarks @a description must be released with free() by you. * @param [in] privilege The privilege * @param [out] description The description of the privilege - * @return 0 on success, otherwise a nonzero error value. + * @return 0 on success, otherwise a negative error value. * @retval #PRVMGR_ERR_NONE Successful * @retval #PRVMGR_ERR_OUT_OF_MEMORY Out of memory * @retval #PRVMGR_ERR_INVALID_PARAMETER Invalid parameter @@ -112,7 +112,7 @@ EXPORT_API int privilege_info_get_privilege_description(const char *privilege, c * @remarks @a privilege_level must be released with free() by you. * @param [in] privilege The privilege * @param [out] privilege_level The privilege_level of the external privilege - * @return 0 on success, otherwise a nonzero error value. + * @return 0 on success, otherwise a negative error value. * @retval #PRVMGR_ERR_NONE Successful * @retval #PRVMGR_ERR_OUT_OF_MEMORY Out of memory * @retval #PRVMGR_ERR_INVALID_PARAMETER Invalid parameter diff --git a/capi/include/privilege_info_types.h b/capi/include/privilege_info_types.h index 081c5f4..f5aeb27 100755 --- a/capi/include/privilege_info_types.h +++ b/capi/include/privilege_info_types.h @@ -49,6 +49,16 @@ typedef struct typedef struct { const char* privilege; + const char* name_string_id; + const char* description_string_id; + const char* privilege_level; + privilegeGroup privilege_group_enum; + +} external_privilege_info_s; + +typedef struct +{ + const char* privilege; const char* privilege_level; } core_privilege_info_s; @@ -212,6 +222,41 @@ const static privilege_info_s const privilege_info_table[PRIVILEGE_NUM] = {"http://tizen.org/privilege/maps", "IDS_TPLATFORM_BODY_MANAGING_SAMSUNG_MAPS", "IDS_TPLATFORM_BODY_ALLOWS_THE_APPLICATION_TO_CONTROL_SAMSUNG_MAPS", _PRV_GROUP_1}, }; +#define EXTERNAL_PRIVILEGE_NUM 28 + +const static external_privilege_info_s const external_privilege_info_table[EXTERNAL_PRIVILEGE_NUM] = +{ + // {"http://privilege", "IDS_PRIVILEGE_NAME_ID", "IDS_PRIVILEGE_DESC_ID", "platform", _PRV_GROUP_ENUM}, + {"http://developer.samsung.com/tizen/privilege/allshare", "IDS_TPLATFORM_BODY_MANAGING_ALLSHARE_SERVICES_M_NOUN", "IDS_TPLATFORM_BODY_ALLOWS_THE_APPLICATION_TO_USE_ALLSHARE_SERVICES_TO_SHARE_MULTIMEDIA_CONTROL_YOUR_TV_AND_TRANSFER_FILES_BETWEEN_DEVICES", "platform", _PRV_GROUP_5}, + {"http://developer.samsung.com/tizen/privilege/audiomanager.session", "IDS_TPLATFORM_BODY_MANAGING_AUDIO_SESSIONS", "IDS_TPLATFORM_BODY_ALLOWS_THE_APPLICATION_TO_MANAGE_THE_AUDIO_SESSION_POLICY_BETWEEN_APPLICATIONS", "platform", _PRV_GROUP_5}, + {"http://developer.samsung.com/tizen/privilege/audiomanager.voipsession", "IDS_TPLATFORM_BODY_MANAGING_VOIP_AUDIO_SESSIONS", "IDS_TPLATFORM_BODY_ALLOWS_THE_APPLICATION_TO_MANAGE_AUDIO_SESSIONS_WITH_VOIP_CALLS", "platform", _PRV_GROUP_5}, + {"http://developer.samsung.com/tizen/privilege/audiomanager.volume", "IDS_TPLATFORM_BODY_MANAGING_VOLUMES", "IDS_TPLATFORM_BODY_ALLOWS_THE_APPLICATION_TO_MANAGE_THE_AUDIO_VOLUMES_OF_VARIOUS_AUDIO_STREAM_TYPES", "platform", _PRV_GROUP_5}, + {"http://developer.samsung.com/tizen/privilege/chord", "IDS_TPLATFORM_BODY_MANAGING_CHORD_M_NOUN", "IDS_TPLATFORM_BODY_ALLOWS_THE_APPLICATION_TO_USE_CHORD_TO_SEND_AND_RECEIVE_MESSAGES_OR_FILES_BETWEEN_DEVICES", "platform", _PRV_GROUP_5}, + {"http://developer.samsung.com/tizen/privilege/deviceadmin.read", "IDS_TPLATFORM_BODY_DETECTING_DEVICE_ADMIN_ACCESS_M_NOUN", "IDS_TPLATFORM_BODY_ALLOWS_THE_APPLICATION_TO_DETECT_WHEN_ACCESS_TO_ADMIN_FUNCTIONS_HAS_BEEN_GAINED", "platform", _PRV_GROUP_5}, + {"http://developer.samsung.com/tizen/privilege/mdm", "IDS_TPLATFORM_BODY_MANAGING_MDM_SERVICE", "IDS_TPLATFORM_BODY_ALLOWS_THE_APPLICATION_TO_MANAGE_THE_DEVICE", "platform", _PRV_GROUP_0}, + {"http://developer.samsung.com/tizen/privilege/mobilecare", "IDS_TPLATFORM_BODY_MANAGING_SAMSUNG_MOBILECARE", "IDS_TPLATFORM_BODY_ALLOWS_THE_APPLICATION_TO_CONTROL_SAMSUNG_MOBILECARE", "platform", _PRV_GROUP_5}, + {"http://developer.samsung.com/tizen/privilege/nfc.cardemulation", "IDS_TPLATFORM_BODY_MANAGING_NFC_CARD_EMULATION_SETTINGS", "IDS_TPLATFORM_BODY_ALLOWS_THE_APPLICATION_TO_CHANGE_NFC_CARD_EMULATION_MODE_SETTINGS_SUCH_AS_CHANGING_THE_ACTIVE_SECURE_ELEMENT_AND_ACCESSING_EMBEDDED_SECURE_ELEMENTS_HESE", "public", _PRV_GROUP_0}, + {"http://developer.samsung.com/tizen/privilege/nservice", "IDS_TPLATFORM_BODY_MANAGING_N_SERVICE_M_NOUN", "IDS_TPLATFORM_BODY_ALLOWS_THE_APPLICATION_TO_USE_N_SERVICE_TO_SEND_AND_RECEIVE_MESSAGES_OR_FILES_BETWEEN_DEVICES_AND_TV", "platform", _PRV_GROUP_5}, + {"http://developer.samsung.com/tizen/privilege/samsungmaps", "IDS_TPLATFORM_BODY_MANAGING_SAMSUNG_MAPS", "IDS_TPLATFORM_BODY_ALLOWS_THE_APPLICATION_TO_CONTROL_SAMSUNG_MAPS", "platform", _PRV_GROUP_1}, + {"http://developer.samsung.com/tizen/privilege/secureelement", "IDS_TPLATFORM_BODY_ACCESSING_SECURE_ELEMENTS", "IDS_TPLATFORM_BODY_ALLOWS_THE_APPLICATION_TO_ACCESS_TO_SECURE_SMART_CARD_CHIP_SUCH_AS_UICC_SIM_EMBEDDED_SECURE_ELEMENT_OR_SECURE_SD_CARD", "platform", _PRV_GROUP_0}, + {"http://developer.samsung.com/tizen/privilege/applifecycleevent", "IDS_TPLATFORM_BODY_RECOGNISING_APPLICATION_EVENTS_AND_ACTIONS_M_NOUN", "IDS_TPLATFORM_BODY_ALLOWS_THE_APPLICATION_TO_RECOGNISE_EVENTS_AND_ACTIVITY_IN_OTHER_APPLICATIONS", "platform", _PRV_GROUP_5}, + {"http://developer.samsung.com/tizen/privilege/callhistory.read", "IDS_TPLATFORM_BODY_READING_CALL_LOGS", "IDS_TPLATFORM_BODY_ALLOWS_THE_APPLICATION_TO_READ_CALL_LOGS", "platform", _PRV_GROUP_4}, + {"http://developer.samsung.com/tizen/privilege/callhistory.write", "IDS_TPLATFORM_BODY_MANAGING_CALL_LOGS", "IDS_TPLATFORM_BODY_ALLOWS_THE_APPLICATION_TO_CREATE_UPDATE_AND_DELETE_CALL_LOGS", "platform", _PRV_GROUP_4}, + {"http://developer.samsung.com/tizen/privilege/smartswitch.alarminfomanager", "IDS_TPLATFORM_BODY_MANAGING_ALARM_INFORMATION", "IDS_TPLATFORM_BODY_ALLOWS_THE_APPLICATION_TO_MANAGE_ALARM_INFORMATION", "platform", _PRV_GROUP_5}, + {"http://developer.samsung.com/tizen/privilege/wifidirectmanager", "IDS_TPLATFORM_BODY_MANAGING_WI_FI_DIRECT_SETTINGS_M_NOUN", "IDS_TPLATFORM_BODY_ALLOW_THE_APPLICATION_TO_MANAGE_WI_FI_DIRECT_SETTINGS_INCLUDING_TURNING_ON_AUTO_CONNECT", "platform", _PRV_GROUP_0}, + {"http://developer.samsung.com/tizen/privilege/accessoryprotocol", "IDS_TPLATFORM_BODY_USE_OPEN_ACCESSORY_PROTOCOL_TO_DETECT_AND_CONNECT_TO_OTHER_DEVICES", "IDS_TPLATFORM_BODY_ALLOWS_THE_APPLICATION_TO_USE_OPEN_ACCESSORY_PROTOCOL_MSG", "public", _PRV_GROUP_0}, + {"http://developer.samsung.com/tizen/privilege/gamepad.read", "IDS_TPLATFORM_BODY_READING_GAME_CONTROLLER_INPUT_DATA_M_NOUN", "IDS_TPLATFORM_BODY_ALLOW_THE_APP_TO_READ_GAME_CONTROLLER_INPUT_DATA_SUCH_AS_THE_PRESSING_AND_RELEASING_OF_BUTTONS_AND_THE_MOVEMENT_OF_ANALOGUE_STICKS", "public", _PRV_GROUP_0}, + {"http://developer.samsung.com/tizen/privilege/healthinfo", "IDS_TPLATFORM_HEADER_READING_HEALTH_INFORMATION", "IDS_TPLATFORM_BODY_ALLOW_THE_APPLICATION_TO_READ_YOUR_HEALTH_INFORMATION", "public", _PRV_GROUP_4}, + {"http://developer.samsung.com/tizen/privilege/personalinfo", "IDS_TPLATFORM_HEADER_CHANGING_PROFILE_INFORMATION", "IDS_TPLATFORM_BODY_ALLOW_THE_APPLICATION_TO_CHANGE_YOUR_PROFILE_INFORMATION", "partner", _PRV_GROUP_4}, + {"http://developer.samsung.com/tizen/privilege/pass.identify", "IDS_TPLATFORM_HEADER_RECOGNISING_FINGERPRINTS", "IDS_TPLATFORM_BODY_ALLOW_THE_APPLICATION_TO_RECOGNISE_FINGERPRINTS", "public", _PRV_GROUP_0}, + {"http://developer.samsung.com/tizen/privilege/fido", "IDS_TPLATFORM_HEADER_MAKING_PAYMENTS_WITH_FIDO_DATA", "IDS_TPLATFORM_BODY_ALLOW_THE_APPLICATION_TO_PROCESS_FAST_IDENTITY_ONLINE_HFIDO_DATA_TO_MAKE_PAYMENTS", "partner", _PRV_GROUP_0}, + {"http://developer.samsung.com/tizen/privilege/irled", "IDS_TPLATFORM_BODY_USING_INFRARED_TRANSMITTER_M_NOUN", "IDS_TPLATFORM_BODY_ALLOW_THE_APPLICATION_TO_USE_THE_INFRARED_TRANSMITTER", "public", _PRV_GROUP_0}, + {"http://developer.samsung.com/tizen/privilege/messaging.setting", "IDS_TPLATFORM_HEADER_CHANGING_MESSAGES_SETTINGS", "IDS_TPLATFORM_BODY_ALLOW_THE_APPLICATION_TO_CHANGE_SETTINGS_IN_THE_MESSAGES_APP", "platform", _PRV_GROUP_4}, + {"http://developer.samsung.com/tizen/privilege/core/systeminfo.admin", "IDS_TPLATFORM_BODY_ACCESSING_SYSTEM_INFORMATION", "IDS_TPLATFORM_BODY_ALLOWS_THE_APPLICATION_TO_RETRIEVE_SYSTEM_INFORMATION_SUCH_AS_NETWORK_SIM_AND_CALL_DETAILS", "plagtform", _PRV_GROUP_5}, + {"http://developer.samsung.com/tizen/privilege/core/context.admin", "IDS_TPLATFORM_BODY_MANAGING_ACTIVITY_LOG_M_NOUN", "IDS_TPLATFORM_BODY_ALLOWS_THE_APPLICATION_TO_COLLECT_AND_USE_ACTIVITY_LOG_DATA_AND_READ_YOUR_CONTEXTUAL_INFORMATION", "platform", _PRV_GROUP_5}, + {"http://developer.samsung.com/tizen/privilege/core/application.admin", "IDS_TPLATFORM_BODY_RETRIEVING_APPLICATION_INFORMATION_M_NOUN", "IDS_TPLATFORM_BODY_ALLOWS_THE_APPLICATION_TO_RETRIEVE_INFORMATION_RELATED_TO_OTHER_APPLICATIONS", "platform", _PRV_GROUP_5}, +}; + #ifdef __cplusplus } #endif diff --git a/capi/include/privilege_manager.h b/capi/include/privilege_manager.h index e3a9690..27aabee 100755 --- a/capi/include/privilege_manager.h +++ b/capi/include/privilege_manager.h @@ -65,7 +65,7 @@ typedef enum * @param [in] privilege_list The privilege_list * @param [in] privilege_manager_visibility_e The privilege_manager_visibility_e * @param [out] error_message The error_message's value is assigned when the return value isn't PRVMGR_ERR_NONE, otherwise null is assigned. - * @return 0 on success, otherwise a nonzero error value. + * @return 0 on success, otherwise a negative error value. * @retval #PRVMGR_ERR_NONE Successful * @retval #PRVMGR_ERR_OUT_OF_MEMORY Out of memory * @retvak #PRVMGR_ERR_INVALID_PRIVILEGE The privilege_list contains invalid privilege(s). diff --git a/capi/src/privilege_info.c b/capi/src/privilege_info.c index b510eec..a7037cb 100755 --- a/capi/src/privilege_info.c +++ b/capi/src/privilege_info.c @@ -743,4 +743,34 @@ int privilege_info_get_privilege_description(const char *privilege, char **descr return PRVMGR_ERR_NONE; } +int privilege_info_get_external_privilege_level(const char *privilege, char **privilege_level) +{ + int index = 0; + bool matchedFlag = false; + char* public_level = "public"; + TryReturn(privilege != NULL, , PRVMGR_ERR_INVALID_PARAMETER, "[PRVMGR_ERR_INVALID_PARAMETER] privilege is NULL"); + + for (index = 0; index < EXTERNAL_PRIVILEGE_NUM; index++) + { + if (strcmp(external_privilege_info_table[index].privilege, privilege) == 0) + { + matchedFlag = true; + *privilege_level = (char*)calloc(strlen(external_privilege_info_table[index].privilege_level) + 1, sizeof(char)); + TryReturn(*privilege_level != NULL, , PRVMGR_ERR_OUT_OF_MEMORY, "[PRVMGR_ERR_OUT_OF_MEMORY] Memory allocation failed."); + + memcpy(*privilege_level, external_privilege_info_table[index].privilege_level, strlen(external_privilege_info_table[index].privilege_level)); + break; + } + } + + if (matchedFlag == false) + { + *privilege_level = (char*)calloc(strlen(public_level) + 1, sizeof(char)); + TryReturn(*privilege_level != NULL, , PRVMGR_ERR_OUT_OF_MEMORY, "[PRVMGR_ERR_OUT_OF_MEMORY] Memory allocation failed."); + + memcpy(*privilege_level, public_level, strlen(public_level)); + } + + return PRVMGR_ERR_NONE; +} diff --git a/checker/CMakeLists.txt b/checker/CMakeLists.txt index 654e74c..d06bbaa 100644 --- a/checker/CMakeLists.txt +++ b/checker/CMakeLists.txt @@ -5,20 +5,7 @@ SET(VERSION ${VERSION_MAJOR}.0.1) INCLUDE(FindPkgConfig) PROJECT(${fw_name}) -IF("${PROFILE_TYPE}" STREQUAL "WEARABLE") - ADD_DEFINITIONS("-DPROFILE_TYPE_WEARABLE") -ELSEIF("${PROFILE_TYPE}" STREQUAL "MOBILE") - ADD_DEFINITIONS("-DPROFILE_TYPE_MOBILE") -ELSEIF("${PROFILE_TYPE}" STREQUAL "TV") - ADD_DEFINITIONS("-DPROFILE_TYPE_TV") -ENDIF() - -IF("${PROFILE_TYPE}" STREQUAL "TV") - pkg_check_modules(${fw_name} REQUIRED dlog libsmack capi-base-common) -ELSE() - pkg_check_modules(${fw_name} REQUIRED dlog libsmack capi-base-common privacy-manager-client) -ENDIF() - +pkg_check_modules(${fw_name} REQUIRED dlog libsmack capi-base-common) FOREACH(flag ${${fw_name}_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") ENDFOREACH(flag) @@ -34,7 +21,7 @@ SET(${fw_name}_framework_src src/test_framework.c ) -ADD_LIBRARY(${fw_name} SHARED src/privilege_checker.c) +ADD_LIBRARY(${fw_name} SHARED src/test_framework.c) TARGET_LINK_LIBRARIES(${fw_name} ${${fw_name}_LDFLAGS}) @@ -46,18 +33,15 @@ SET_TARGET_PROPERTIES(${fw_name} ) INSTALL(TARGETS ${fw_name} DESTINATION ../lib) -IF("${PROFILE_TYPE}" STREQUAL "TV") - SET(pc_requires "libsmack") -ELSE() - SET(pc_requires "libsmack privacy-manager-client") -ENDIF() +SET(pc_requires "libsmack") SET(PC_NAME ${fw_name}) SET(PC_REQUIRED ${pc_requires}) -SET(PC_LDFLAGS "-l${fw_name}") +SET(PC_LDFLAGS "") SET(PC_CFLAGS "") CONFIGURE_FILE(${fw_name}.pc.in ${fw_name}.pc @ONLY) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/privilege_checker.h DESTINATION /usr/include) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/privilege_checker_extension.h DESTINATION /usr/include) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc DESTINATION ../lib/pkgconfig) diff --git a/checker/include/privilege_checker.h b/checker/include/privilege_checker.h index f7d1ad5..eefc79c 100755 --- a/checker/include/privilege_checker.h +++ b/checker/include/privilege_checker.h @@ -17,6 +17,8 @@ #ifndef __TIZEN_SECURITY_PRIVILEGE_CHECKER_H #define __TIZEN_SECURITY_PRIVILEGE_CHECKER_H +#include <tizen.h> + #ifdef __cplusplus extern "C" { #endif @@ -36,12 +38,12 @@ extern "C" { #include <stdlib.h> #include <dlog.h> #include <sys/smack.h> +#include "privilege_checker_extension.h" typedef enum { PRIVILEGE_CHECKER_ERR_NONE = TIZEN_ERROR_NONE, PRIVILEGE_CHECKER_ERR_UNDECLARED_PRIVILEGE = TIZEN_ERROR_PERMISSION_DENIED, - PRIVILEGE_CHECKER_ERR_UNCONSENTED = TIZEN_ERROR_PERMISSION_DENIED, PRIVILEGE_CHECKER_ERR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, PRIVILEGE_CHECKER_ERR_INTERNAL_ERROR = TIZEN_ERROR_UNKNOWN, } privilege_checker_error_e; @@ -55,17 +57,95 @@ typedef enum #define PRIVILEGE_CHECKER_GET_PRIVILEGE_NAME(name, len) (char *)(name + len) #define PRIVILEGE_CHECKER_RESERVED_PERMISSION "rw" +#define privilege_checker_check_privilege(name) __privilege_checker_check_privilege(name, __func__, __FILE__, __LINE__) -/** - * @brief check the privilege is declared or not for current application - * @param [in] privilege_name Privilege name such as "http://tizen.org/privilege/$name" - * @retval #PRIVILEGE_CHECKER_ERR_NONE Success. Privilege is declared in current application - * @retval #PRIVILEGE_CHECKER_ERR_UNDECLARED_PRIVILEGE Privilege is not declared in current application - * @retval #PRIVILEGE_CHECKER_ERR_INVALID_PARAMETER Invalid privilege name - * @retval #PRIVILEGE_CHECKER_ERR_INTERNAL_ERROR Internal I/O Error - * int privilege_checker_check_privilege(const char* privilege_name) - */ -EXPORT_API int privilege_checker_check_privilege(const char* privilege_name); +#define TryReturn(condition, expr, returnValue, ...) \ + if (!(condition)) { \ + LOGE(__VA_ARGS__); \ + expr; \ + return returnValue; \ + } \ + else {;} + +static int __privilege_checker_check_privilege(const char* privilege_name, const char* caller_function, char* caller_file, int caller_line) +{ +#ifdef LOG_TAG +#define BACKUP_TAG LOG_TAG +#undef LOG_TAG +#endif + +#define LOG_TAG "PRIVILEGE_CHECKER" + +#define VALUE(x) #x + + int ret; + char *subject, *object = NULL; + char *privilege_key_name = NULL; + + LOGD("_ENTER_"); + + if ( privilege_name == NULL ) + { + LOGE("Invalid privilege name : %s", privilege_name); + return PRIVILEGE_CHECKER_ERR_INVALID_PARAMETER; + } + + if (smack_new_label_from_self(&subject) == -1) + { + LOGE("smack_new_label_from_self failed : %d", errno); + return PRIVILEGE_CHECKER_ERR_INTERNAL_ERROR; + } + + if ( PRIVILEGE_CHECKER_IS_TIZEN_PRIVILEGE(privilege_name) ) + { + privilege_key_name = PRIVILEGE_CHECKER_GET_PRIVILEGE_NAME(privilege_name, PRIVILEGE_CHECKER_TIZEN_PRIVILEGE_LEN); + object = (char*)malloc( PRIVILEGE_CHECKER_TIZEN_PREFIX_LABEL_LEN + strlen(privilege_key_name) + 1); + TryReturn( object != NULL,, PRIVILEGE_CHECKER_ERR_INTERNAL_ERROR, "[PRIVILEGE_CHECKER_ERR_INTERNAL_ERROR] object's malloc failed"); + snprintf(object, PRIVILEGE_CHECKER_TIZEN_PREFIX_LABEL_LEN + strlen(privilege_key_name) + 1, "%s%s", PRIVILEGE_CHECKER_TIZEN_PREFIX_LABEL, privilege_key_name); + } + else if ( PRIVILEGE_CHECKER_IS_EXTENSION_PRIVILEGE(privilege_name) ) + { + privilege_key_name = PRIVILEGE_CHECKER_GET_PRIVILEGE_NAME(privilege_name, PRIVILEGE_CHECKER_EXTENSION_PRIVILEGE_LEN); + object = (char*)malloc( PRIVILEGE_CHECKER_EXTENSION_PREFIX_LABEL_LEN + strlen(privilege_key_name) + 1); + TryReturn( object != NULL,, PRIVILEGE_CHECKER_ERR_INTERNAL_ERROR, "[PRIVILEGE_CHECKER_ERR_INTERNAL_ERROR] object's malloc failed"); + snprintf(object, PRIVILEGE_CHECKER_EXTENSION_PREFIX_LABEL_LEN + strlen(privilege_key_name) + 1, "%s%s", PRIVILEGE_CHECKER_EXTENSION_PREFIX_LABEL, privilege_key_name); + } + else + { + LOGE("Invalid privilege name : %s", privilege_name); + return PRIVILEGE_CHECKER_ERR_INVALID_PARAMETER; + } + + switch ( ret = smack_have_access (subject, object, PRIVILEGE_CHECKER_RESERVED_PERMISSION) ) + { + case 1: + ret = PRIVILEGE_CHECKER_ERR_NONE; + break; + case 0: + LOGE("Please declare %s in tizen-manifest.xml", privilege_name); + ret = PRIVILEGE_CHECKER_ERR_UNDECLARED_PRIVILEGE; + break; + case -1: + LOGE("Internal error[%d]: %s, %s, %s", ret, privilege_name, subject, object); + ret = PRIVILEGE_CHECKER_ERR_INTERNAL_ERROR; + break; + default: + LOGE("Internal error[%d]: %s, %s, %s", ret, privilege_name, subject, object); + ret = PRIVILEGE_CHECKER_ERR_INTERNAL_ERROR; + } + + if (object != NULL) + { + free (object); + object = NULL; + } +#ifdef BACKUP_TAG +#undef LOG_TAG +#define LOG_TAG VALUE(BACKUP_TAG) +#undef BACKUP_TAG +#endif + return ret; +} #ifdef __cplusplus } diff --git a/checker/include/privilege_checker_extension.h b/checker/include/privilege_checker_extension.h new file mode 100755 index 0000000..1e190ae --- /dev/null +++ b/checker/include/privilege_checker_extension.h @@ -0,0 +1,44 @@ +/* + * 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 __TIZEN_SECURITY_PRIVILEGE_CHECKER_EXTENSION_H +#define __TIZEN_SECURITY_PRIVILEGE_CHECKER_EXTENSION_H + +#include <tizen.h> + +#ifdef __cplusplus +extern "C" { +#endif + +#include <tizen.h> +#include <stdio.h> +#include <stdlib.h> +#include <dlog.h> + +#define PRIVILEGE_CHECKER_EXTENSION_PRIVILEGE "http://developer.samsung.com/tizen/privilege/" +#define PRIVILEGE_CHECKER_EXTENSION_PRIVILEGE_LEN strlen(PRIVILEGE_CHECKER_EXTENSION_PRIVILEGE) +#define PRIVILEGE_CHECKER_EXTENSION_PREFIX_LABEL "privilege::samsung::" +#define PRIVILEGE_CHECKER_EXTENSION_PREFIX_LABEL_LEN strlen(PRIVILEGE_CHECKER_EXTENSION_PREFIX_LABEL) +#define PRIVILEGE_CHECKER_IS_EXTENSION_PRIVILEGE(name) \ + ( (strlen (name) < PRIVILEGE_CHECKER_EXTENSION_PRIVILEGE_LEN) ? \ + 0 : \ + !strncmp(PRIVILEGE_CHECKER_EXTENSION_PRIVILEGE, name, PRIVILEGE_CHECKER_EXTENSION_PRIVILEGE_LEN) ) + +#ifdef __cplusplus +} +#endif + +#endif // __TIZEN_SECURITY_PRIVILEGE_CHECKER_EXTENSION_H diff --git a/checker/security-privilege-checker.pc.in b/checker/security-privilege-checker.pc.in index 50e38ad..8d12dfc 100755 --- a/checker/security-privilege-checker.pc.in +++ b/checker/security-privilege-checker.pc.in @@ -4,11 +4,12 @@ prefix=@PREFIX@ exec_prefix=/usr libdir=/usr/lib +includedir=/usr/include/privilegemgr Name: @PC_NAME@ Description: @PACKAGE_DESCRIPTION@ Version: @VERSION@ Requires: @PC_REQUIRED@ Libs: -L${libdir} @PC_LDFLAGS@ -Cflags: @PC_CFLAGS@ +Cflags: -I${includedir} @PC_CFLAGS@ diff --git a/checker/src/privilege_checker.c b/checker/src/privilege_checker.c deleted file mode 100755 index 6ec2168..0000000 --- a/checker/src/privilege_checker.c +++ /dev/null @@ -1,125 +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. - */ - -#include <unistd.h> -#include <stdlib.h> -#include <dlog.h> -#include <privilege_checker.h> - -#if defined PROFILE_TYPE_MOBILE || defined PROFILE_TYPE_WEARABLE -#include <privacy_checker_client.h> -#endif - -#ifdef LOG_TAG -#undef LOG_TAG -#define LOG_TAG "PRIVILEGE_CHECKER" -#endif - -#define TryReturn(condition, expr, returnValue, ...) \ - if (!(condition)) { \ - LOGE(__VA_ARGS__); \ - expr; \ - return returnValue; \ - } \ - else {;} - -static int __privilege_checker_check_privilege(const char* privilege_name, const char* caller_function, char* caller_file, int caller_line) -{ - int ret; - char *subject, *object = NULL; - char *privilege_key_name = NULL; - - LOGD("_ENTER_"); - - if ( privilege_name == NULL ) - { - LOGE("Invalid privilege name : %s", privilege_name); - return PRIVILEGE_CHECKER_ERR_INVALID_PARAMETER; - } - - if (smack_new_label_from_self(&subject) == -1) - { - LOGE("smack_new_label_from_self failed : %d", errno); - return PRIVILEGE_CHECKER_ERR_INTERNAL_ERROR; - } - - if ( PRIVILEGE_CHECKER_IS_TIZEN_PRIVILEGE(privilege_name) ) - { - privilege_key_name = PRIVILEGE_CHECKER_GET_PRIVILEGE_NAME(privilege_name, PRIVILEGE_CHECKER_TIZEN_PRIVILEGE_LEN); - object = (char*)malloc( PRIVILEGE_CHECKER_TIZEN_PREFIX_LABEL_LEN + strlen(privilege_key_name) + 1); - TryReturn(object != NULL, free(object), PRIVILEGE_CHECKER_ERR_INTERNAL_ERROR, "[PRIVILEGE_CHECKER_ERR_INTERNAL_ERROR] object's malloc is failed."); - snprintf(object, PRIVILEGE_CHECKER_TIZEN_PREFIX_LABEL_LEN + strlen(privilege_key_name) + 1, "%s%s", PRIVILEGE_CHECKER_TIZEN_PREFIX_LABEL, privilege_key_name); - } - else - { - LOGE("Invalid privilege name : %s", privilege_name); - return PRIVILEGE_CHECKER_ERR_INVALID_PARAMETER; - } - - switch ( ret = smack_have_access (subject, object, PRIVILEGE_CHECKER_RESERVED_PERMISSION) ) - { - case 1: - ret = PRIVILEGE_CHECKER_ERR_NONE; - break; - case 0: - LOGE("Please declare %s in tizen-manifest.xml or config.xml", privilege_name); - ret = PRIVILEGE_CHECKER_ERR_UNDECLARED_PRIVILEGE; - break; - case -1: - LOGE("Internal error[%d]: %s, %s, %s", ret, privilege_name, subject, object); - ret = PRIVILEGE_CHECKER_ERR_INTERNAL_ERROR; - break; - default: - LOGE("Internal error[%d]: %s, %s, %s", ret, privilege_name, subject, object); - ret = PRIVILEGE_CHECKER_ERR_INTERNAL_ERROR; - } - - if (object != NULL) - { - free (object); - object = NULL; - } - - if (subject != NULL) - { - free (subject); - } - - return ret; -} - -int privilege_checker_check_privilege(const char* privilege_name) -{ - int ret = __privilege_checker_check_privilege(privilege_name, __func__, __FILE__, __LINE__); -#if defined PROFILE_TYPE_MOBILE || defined PROFILE_TYPE_WEARABLE - if (ret == PRIVILEGE_CHECKER_ERR_NONE) { - switch ( ret = privacy_checker_check_by_privilege(privilege_name)) - { - case 0: - ret = PRIVILEGE_CHECKER_ERR_NONE; - break; - case -19: - ret = PRIVILEGE_CHECKER_ERR_UNDECLARED_PRIVILEGE; - break; - default: - ret = PRIVILEGE_CHECKER_ERR_INTERNAL_ERROR; - } - return ret; - } -#endif - return ret; -} - diff --git a/checker/src/test_framework.c b/checker/src/test_framework.c new file mode 100644 index 0000000..836c766 --- /dev/null +++ b/checker/src/test_framework.c @@ -0,0 +1,31 @@ +#include <privilege_checker.h> +#include <dlog.h> + +void show(char* privilege_name, int ret) +{ + switch (ret) + { + case PRIVILEGE_CHECKER_ERR_NONE: + LOGD("%s is declared in current application", privilege_name); + break; + case PRIVILEGE_CHECKER_ERR_UNDECLARED_PRIVILEGE: + LOGD("%s is not declared in current application", privilege_name); + break; + case PRIVILEGE_CHECKER_ERR_INVALID_PARAMETER: + LOGD("%s is invalid name", privilege_name); + break; + case PRIVILEGE_CHECKER_ERR_INTERNAL_ERROR: + default: + LOGD("Internal error"); + break; + } + +} + +int privilege_api_account_read() +{ + char* privilege_name = "http://tizen.org/privilege/account.read"; + int ret = privilege_checker_check_privilege(privilege_name); + show(privilege_name, ret); + return ret; +} diff --git a/packaging/privilege-checker.spec b/packaging/privilege-checker.spec index 3a70471..9345988 100644 --- a/packaging/privilege-checker.spec +++ b/packaging/privilege-checker.spec @@ -1,3 +1,5 @@ +%define core_privilege_checker security-privilege-checker + Name: privilege-checker Summary: Privilege Management Version: 0.0.4 @@ -10,32 +12,21 @@ BuildRequires: cmake %description Privilege Management -%package -n privilege-checker-devel -summary: privilege-checker server -Group: Development/Libraries -Requires: privilege-checker = %{version}-%{release} -%description -n privilege-checker-devel -privilege-checker devel - - -%package -n security-privilege-checker +%package -n %{core_privilege_checker}-devel Summary: Privilege Checker API(Core) Group: TO_BE/FILLED_IN -BuildRequires: pkgconfig(libsmack) -%if "%{?tizen_profile_name}" != "tv" -BuildRequires: pkgconfig(privacy-manager-client) -%endif +BuildRequires: pkgconfig(libsmack) -%description -n security-privilege-checker +%description -n %{core_privilege_checker}-devel The Privilege Checker API provides functions to check given privilege is declared current application or not. -%package -n security-privilege-checker-devel -Summary: Privilege Checker API(Core) -Group: TO_BE/FILLED_IN -BuildRequires: pkgconfig(libsmack) +%package -n privilege-checker-devel +summary: privilege-checker server +Group: Development/Libraries +Requires: privilege-checker = %{version}-%{release} -%description -n security-privilege-checker-devel -The Privilege Checker API provides functions to check given privilege is declared current application or not. +%description -n privilege-checker-devel +privilege-checker devel %package -n capi-security-privilege-manager Summary: Privilege Manager API @@ -49,6 +40,7 @@ BuildRequires: pkgconfig(pkgmgr-info) BuildRequires: pkgconfig(cert-svc) BuildRequires: pkgconfig(sqlite3) BuildRequires: pkgconfig(glib-2.0) +BuildRequires: pkgconfig(libsmack) %description -n capi-security-privilege-manager The Privilege Manager API provides functions to get information about privilege information of installed packages. @@ -132,14 +124,10 @@ sqlite3 /%{buildroot}/usr/share/privilege-manager/.wrt_privilege_info.db "select /usr/share/license/privilege-checker %manifest packaging/privilege-checker.manifest -%files -n security-privilege-checker -%{_libdir}/libsecurity-privilege-checker.so* -%manifest packaging/security-privilege-checker.manifest - -%files -n security-privilege-checker-devel +%files -n %{core_privilege_checker}-devel %{_includedir}/privilege_checker.h -%{_libdir}/pkgconfig/security-privilege-checker.pc -%{_libdir}/libsecurity-privilege-checker.so +%{_includedir}/privilege_checker_extension.h +%{_libdir}/pkgconfig/%{core_privilege_checker}.pc %files -n capi-security-privilege-manager %{_libdir}/libcapi-security-privilege-manager.so* @@ -160,7 +148,9 @@ sqlite3 /%{buildroot}/usr/share/privilege-manager/.wrt_privilege_info.db "select /usr/share/packages/org.tizen.test-privilege-checker.xml %{_bindir}/tc-privilege-db-manager %{_bindir}/tc-privilege-manager +#%{_bindir}/tc-privilege-checker %{_bindir}/tc-privilege-info +%{_libdir}/lib%{core_privilege_checker}.so* %clean rm -rf %{buildroot} diff --git a/packaging/security-privilege-checker.manifest b/packaging/security-privilege-checker.manifest deleted file mode 100644 index 75b0fa5..0000000 --- a/packaging/security-privilege-checker.manifest +++ /dev/null @@ -1,5 +0,0 @@ -<manifest> - <request> - <domain name="_"/> - </request> -</manifest> diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 047dc45..4bd210a 100755 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -35,7 +35,7 @@ ADD_EXECUTABLE(${TC4_NAME} ${TC4_SRCS}) TARGET_LINK_LIBRARIES(${TC1_NAME} "capi-security-privilege-manager") TARGET_LINK_LIBRARIES(${TC2_NAME} "capi-security-privilege-manager") -TARGET_LINK_LIBRARIES(${TC3_NAME} "security-privilege-checker") +TARGET_LINK_LIBRARIES(${TC3_NAME} "capi-security-privilege-manager") TARGET_LINK_LIBRARIES(${TC4_NAME} "capi-security-privilege-manager") INSTALL(TARGETS ${TC1_NAME} DESTINATION /usr/bin) |