From: Krzysztof Sasiak Date: Sat, 31 Jan 2015 10:11:18 +0000 (+0100) Subject: Add API stub for getting policy entries X-Git-Tag: accepted/tizen/tv/20150217.004257~11 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F90%2F34690%2F11;p=platform%2Fcore%2Fsecurity%2Fsecurity-manager.git Add API stub for getting policy entries Change-Id: I4eaa9642b81d6524038ec18bcfe7ad55dc61b697 Signed-off-by: Jan Cybulski Signed-off-by: Krzysztof Sasiak --- diff --git a/src/client/client-security-manager.cpp b/src/client/client-security-manager.cpp index c2a3fd7..c7fe2a7 100644 --- a/src/client/client-security-manager.cpp +++ b/src/client/client-security-manager.cpp @@ -667,6 +667,41 @@ int security_manager_policy_update_send(policy_update_req *p_req) return SECURITY_MANAGER_ERROR_UNKNOWN; } +SECURITY_MANAGER_API +int security_manager_get_configured_policy_for_admin( + policy_entry *p_filter, + policy_entry **pp_privs_policy, + size_t *p_size) +{ + (void)p_filter; + (void)pp_privs_policy; + (void)p_size; + return SECURITY_MANAGER_ERROR_UNKNOWN; +} + +SECURITY_MANAGER_API +int security_manager_get_configured_policy_for_self( + policy_entry *p_filter, + policy_entry **pp_privs_policy, + size_t *p_size) +{ + (void)p_filter; + (void)pp_privs_policy; + (void)p_size; + return SECURITY_MANAGER_ERROR_UNKNOWN; +} + + +int security_manager_get_policy( + policy_entry *p_filter, + policy_entry **pp_privs_policy, + size_t *p_size) +{ + (void)p_filter; + (void)pp_privs_policy; + (void)p_size; + return SECURITY_MANAGER_ERROR_UNKNOWN; +} SECURITY_MANAGER_API int security_manager_policy_entry_new(policy_entry **p_entry) @@ -743,3 +778,55 @@ int security_manager_policy_update_req_add_entry(policy_update_req *p_req, const return SECURITY_MANAGER_SUCCESS; } + +SECURITY_MANAGER_API +const char *security_manager_policy_entry_get_user(policy_entry *p_entry) +{ + if (p_entry) + return strdup(p_entry->user.c_str()); + else + return nullptr; +} + +SECURITY_MANAGER_API +const char *security_manager_policy_entry_get_application(policy_entry *p_entry) +{ + if (p_entry) + return strdup(p_entry->appId.c_str()); + else + return nullptr; +} +SECURITY_MANAGER_API +const char *security_manager_policy_entry_get_privilege(policy_entry *p_entry) +{ + if (p_entry) + return strdup(p_entry->privilege.c_str()); + else + return nullptr; +} +SECURITY_MANAGER_API +const char *security_manager_policy_entry_get_level(policy_entry *p_entry) +{ + if (p_entry) + return strdup(p_entry->currentLevel.c_str()); + else + return nullptr; +} + +SECURITY_MANAGER_API +const char *security_manager_policy_entry_get_max_level(policy_entry *p_entry) +{ + if (p_entry) + return strdup(p_entry->maxLevel.c_str()); + else + return nullptr; +} + +SECURITY_MANAGER_API +void security_manager_policy_entries_free(policy_entry *p_entries, const size_t size) +{ + for (size_t i = 0; i < size; i++) { + delete &p_entries[i]; + } + delete [] p_entries; +} diff --git a/src/include/security-manager.h b/src/include/security-manager.h index 0dd5378..9e8a536 100644 --- a/src/include/security-manager.h +++ b/src/include/security-manager.h @@ -480,7 +480,58 @@ int security_manager_policy_entry_admin_set_level(policy_entry *p_entry, const c int security_manager_policy_update_req_add_entry(policy_update_req *p_req, const policy_entry *p_entry); /** - * \brief This function is used to send the prepared policy update request to scurity-manager daemon. + * This function is used to obtain user ID from p_entry structure + * + * \param[in] p_entry Pointer handling policy_entry structure + * \attention Warning: memory pointed to by value written to policy_level needs to be freed + * + * \return user uid + */ + +const char *security_manager_policy_entry_get_user(policy_entry *p_entry); +/** + * This function is used to obtain application name from p_entry structure + * + * \param[in] p_entry Pointer handling policy_entry structure + * \attention Warning: memory pointed to by value written to policy_level needs to be freed + * + * \return application name + */ + +const char *security_manager_policy_entry_get_application(policy_entry *p_entry); +/** + * This function is used to obtain privilege name from p_entry structure + * + * \param[in] p_entry Pointer handling policy_entry structure + * \attention Warning: memory pointed to by value written to policy_level needs to be freed + * + * \return privilege name + */ +const char *security_manager_policy_entry_get_privilege(policy_entry *p_entry); +/** + * This function is used to obtain current policy level from p_entry structure + * + * \param[in] p_entry Pointer handling policy_entry structure + * \attention Warning: memory pointed to by value written to policy_level needs to be freed + * + * \return Current policy level + */ +const char *security_manager_policy_entry_get_level(policy_entry *p_entry); + +/** + * This function is used to obtain maximal policy level from p_entry structure + * + * \param[in] p_entry Pointer handling policy_entry structure. + * \attention Warning: memory pointed to by value written to policy_level needs to be freed + * + * \return Maximal policy level + */ +const char *security_manager_policy_entry_get_max_level(policy_entry *p_entry); + +/** + * \brief This function is used to send the prepared policy update request using privacy manager + * entry point. The request should contain at least one policy update unit, otherwise + * the SECURITY_MANAGER_ERROR_INPUT_PARAM is returned. * * \param[in] p_req Pointer handling allocated policy_update_req structure * \return API return code or error code @@ -568,6 +619,72 @@ int security_manager_policy_update_req_add_entry(policy_update_req *p_req, const */ int security_manager_policy_update_send(policy_update_req *p_req); +/** + * \brief Function fetches all privileges enforced by admin user. + * The result is stored in the policy_entry structures array. + * + * \note It should be called by user with http://tizen.org/privilege/systemsettings.admin privilege. + * Normal users may list their personal policy entries using + * security_manager_get_configured_policy_for_self() API function. + * + * \attention Developer is responsible for calling security_manager_policy_entries_free() + * for freeing allocated resources. + * + * \param[in] p_filter Pointer to filter struct + * \param[out] pp_privs_policy Pointer handling allocated policy_entry structures array + * \param[out] p_size Pointer where the size of allocated array will be stored + * \return API return code or error code + */ +int security_manager_get_configured_policy_for_admin( + policy_entry *p_filter, + policy_entry **pp_privs_policy, size_t *p_size); + +/** + * \brief Function fetches all privileges that are configured by user in his/her + * privacy manager. The result is stored in the policy_entry structures array. + * User may only fetch privileges for his/her own UID. + * + * \attention Developer is responsible for calling security_manager_policy_entries_free() + * for freeing allocated resources. + * + * \param[in] p_filter Pointer to filter struct + * \param[out] pp_privs_policy Pointer handling allocated policy_entry structures array + * \param[out] p_size Pointer where the size of allocated array will be stored + * \return API return code or error code + */ +int security_manager_get_configured_policy_for_self( + policy_entry *p_filter, + policy_entry **pp_privs_policy, + size_t *p_size); + +/** + * \brief Function gets the whole policy for all users, their applications and privileges + * based on the provided filter. The result is stored in the policy_entry array. + * + * \note If this call is performed by user with http://tizen.org/privilege/systemsettings.admin + * privilege, then it's possible to list policies for all users. + * Normal users may only list privileges for their own UID. + * + * \attention Developer is responsible for calling security_manager_policy_entries_free() + * for freeing allocated resources. + * + * \param[in] p_filter Pointer to filter struct + * \param[out] pp_privs_policy Pointer handling allocated policy_entry structures array + * \param[out] p_size Pointer where the size of allocated array will be stored + * \return API return code or error code + */ +int security_manager_get_policy( + policy_entry *p_filter, + policy_entry **pp_privs_policy, + size_t *p_size); + +/** + * \brief This function is used to free resources allocated in policy_entry structures array. + * \param[in] p_entries Pointer handling allocated policy status array + * \param[in] size Size of the array + */ +void security_manager_policy_entries_free(policy_entry *p_entries, const size_t size); + #ifdef __cplusplus } #endif