From dff097e2dd1cae019c15b830b0365ff9644a6cec Mon Sep 17 00:00:00 2001 From: sooyeon Date: Thu, 22 Sep 2022 13:46:47 +0900 Subject: [PATCH] Add permission denied error and descriptions Change-Id: Iaf1b54300feb01f789cac0af799982a3d6492a3b Signed-off-by: sooyeon --- common/vc_defs.h | 2 ++ include/vce.h | 37 +++++++++++++++---------- server/vce.c | 71 +++++++++++++++++++++++++++++------------------- 3 files changed, 67 insertions(+), 43 deletions(-) diff --git a/common/vc_defs.h b/common/vc_defs.h index 0e12f46..1fb53d3 100644 --- a/common/vc_defs.h +++ b/common/vc_defs.h @@ -282,6 +282,8 @@ extern "C" { #define VC_MIC_FEATURE_PATH "tizen.org/feature/microphone" #define VC_PRIVILEGE_RECORDER "http://tizen.org/privilege/recorder" +#define VC_PRIVILEGE_APPMGR_LAUNCH "http://tizen.org/privilege/appmanager.launch" +#define VC_PRIVILEGE_DATASHARING "http://tizen.org/privilege/datasharing" #define VC_MGR_PRIVILEGE "http://tizen.org/privilege/voicecontrol.manager" /****************************************************************************************** diff --git a/include/vce.h b/include/vce.h index 4509c32..ae54abc 100644 --- a/include/vce.h +++ b/include/vce.h @@ -685,8 +685,8 @@ typedef struct { * @details This function is the main function for operating VC engine. * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @privlevel public - * @privilege %http://tizen.org/privilege/recorder - * %http://tizen.org/privilege/appmanager.launch (Since 7.0) + * @privilege %http://tizen.org/privilege/recorder \n + * %http://tizen.org/privilege/appmanager.launch (Since 7.0) \n * %http://tizen.org/privilege/datasharing (Since 7.0) * @remarks To use this function, privileges of appmanager.launch and datasharing should be included since 7.0. \n * The service_app_main() should be used for working the engine after this function. @@ -798,7 +798,7 @@ int vce_main(int argc, char** argv, vce_request_callback_s* callback); * @brief Sends the results to the engine service user. * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @privlevel public - * @privilege %http://tizen.org/privilege/appmanager.launch (Since 7.0) + * @privilege %http://tizen.org/privilege/appmanager.launch (Since 7.0) \n * %http://tizen.org/privilege/datasharing (Since 7.0) * @remarks To use this function, privileges of appmanager.launch and datasharing should be included since 7.0. * @@ -813,6 +813,7 @@ int vce_main(int argc, char** argv, vce_request_callback_s* callback); * @param[in] user_data The user data passed from set callback function * @return @c 0 on success, otherwise a negative error value * @retval #VCE_ERROR_NONE Successful + * @retval #VCE_ERROR_PERMISSION_DENIED Permission denied * @retval #VCE_ERROR_INVALID_PARAMETER Invalid parameter * @retval #VCE_ERROR_OUT_OF_MEMORY Out of Memory * @retval #VCE_ERROR_INVALID_STATE Invalid state @@ -827,7 +828,7 @@ int vce_send_result(vce_result_event_e event, int* result_id, int count, const c * @brief Sends the ASR result to the engine service user. * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @privlevel public - * @privilege %http://tizen.org/privilege/appmanager.launch (Since 7.0) + * @privilege %http://tizen.org/privilege/appmanager.launch (Since 7.0) \n * %http://tizen.org/privilege/datasharing (Since 7.0) * @remarks To use this function, privileges of appmanager.launch and datasharing should be included since 7.0. * @@ -836,6 +837,7 @@ int vce_send_result(vce_result_event_e event, int* result_id, int count, const c * @param[in] user_data The user data passed from the start * @return @c 0 on success, otherwise a negative error value * @retval #VCE_ERROR_NONE Successful + * @retval #VCE_ERROR_PERMISSION_DENIED Permission denied * @retval #VCE_ERROR_INVALID_PARAMETER Invalid parameter * @retval #VCE_ERROR_OUT_OF_MEMORY Out of Memory * @retval #VCE_ERROR_OPERATION_FAILED Operation failure @@ -848,7 +850,7 @@ int vce_send_asr_result(vce_asr_result_event_e event, const char* asr_result, vo * @brief Sends the NLG (Natural Language Generation) result to the engine service user. * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @privlevel public - * @privilege %http://tizen.org/privilege/appmanager.launch (Since 7.0) + * @privilege %http://tizen.org/privilege/appmanager.launch (Since 7.0) \n * %http://tizen.org/privilege/datasharing (Since 7.0) * @remarks To use this function, privileges of appmanager.launch and datasharing should be included since 7.0. * @@ -856,6 +858,7 @@ int vce_send_asr_result(vce_asr_result_event_e event, const char* asr_result, vo * @param[in] user_data The user data passed from the start * @return @c 0 on success, otherwise a negative error value * @retval #VCE_ERROR_NONE Successful + * @retval #VCE_ERROR_PERMISSION_DENIED Permission denied * @retval #VCE_ERROR_INVALID_PARAMETER Invalid parameter * @retval #VCE_ERROR_OUT_OF_MEMORY Out of Memory * @retval #VCE_ERROR_OPERATION_FAILED Operation failure @@ -868,7 +871,7 @@ int vce_send_nlg_result(const char* nlg_result, void* user_data); * @brief Sends the specific engine result to the engine service user. * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @privlevel public - * @privilege %http://tizen.org/privilege/appmanager.launch (Since 7.0) + * @privilege %http://tizen.org/privilege/appmanager.launch (Since 7.0) \n * %http://tizen.org/privilege/datasharing (Since 7.0) * @remarks To use this function, privileges of appmanager.launch and datasharing should be included since 7.0. * @@ -879,6 +882,7 @@ int vce_send_nlg_result(const char* nlg_result, void* user_data); * * @return 0 on success, otherwise a negative error value * @retval #VCE_ERROR_NONE Successful + * @retval #VCE_ERROR_PERMISSION_DENIED Permission denied * @retval #VCE_ERROR_INVALID_PARAMETER Invalid parameter * @retval #VCE_ERROR_OUT_OF_MEMORY Out of Memory * @retval #VCE_ERROR_OPERATION_FAILED Operation failure @@ -904,7 +908,7 @@ int vce_send_specific_engine_result(const char* engine_app_id, const char* event * #VCE_ERROR_TTS_FAILED. * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @privlevel public - * @privilege %http://tizen.org/privilege/appmanager.launch (Since 7.0) + * @privilege %http://tizen.org/privilege/appmanager.launch (Since 7.0) \n * %http://tizen.org/privilege/datasharing (Since 7.0) * @remarks To use this function, privileges of appmanager.launch and datasharing should be included since 7.0. * @@ -913,6 +917,7 @@ int vce_send_specific_engine_result(const char* engine_app_id, const char* event * @param[in] user_data The user data passed from set callback function * @return @c 0 on success, otherwise a negative error value * @retval #VCE_ERROR_NONE Successful + * @retval #VCE_ERROR_PERMISSION_DENIED Permission denied * @retval #VCE_ERROR_INVALID_PARAMETER Invalid parameter * @retval #VCE_ERROR_OUT_OF_MEMORY Out of Memory * @retval #VCE_ERROR_OPERATION_FAILED Operation failure @@ -1053,8 +1058,8 @@ int vce_get_audio_type(char** audio_type); * @brief Sets private data to a voice manager client. * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @privlevel public - * @privilege %http://tizen.org/privilege/recorder - * %http://tizen.org/privilege/appmanager.launch (Since 7.0) + * @privilege %http://tizen.org/privilege/recorder \n + * %http://tizen.org/privilege/appmanager.launch (Since 7.0) \n * %http://tizen.org/privilege/datasharing (Since 7.0) * @remarks To use this function, privileges of appmanager.launch and datasharing should be included since 7.0. * @@ -1075,8 +1080,8 @@ int vce_set_private_data(const char* key, const char* data); * @brief Gets private data from a voice manager client. * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @privlevel public - * @privilege %http://tizen.org/privilege/recorder - * %http://tizen.org/privilege/appmanager.launch (Since 7.0) + * @privilege %http://tizen.org/privilege/recorder \n + * %http://tizen.org/privilege/appmanager.launch (Since 7.0) \n * %http://tizen.org/privilege/datasharing (Since 7.0) * @remarks To use this function, privileges of appmanager.launch and datasharing should be included since 7.0. \n * The @a data must be released using free() when it is no longer required. @@ -1098,8 +1103,8 @@ int vce_get_private_data(const char* key, char** data); * @brief Starts recording voice. * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @privlevel public - * @privilege %http://tizen.org/privilege/recorder - * %http://tizen.org/privilege/appmanager.launch (Since 7.0) + * @privilege %http://tizen.org/privilege/recorder \n + * %http://tizen.org/privilege/appmanager.launch (Since 7.0) \n * %http://tizen.org/privilege/datasharing (Since 7.0) * @remarks To use this function, privileges of appmanager.launch and datasharing should be included since 7.0. * @@ -1130,7 +1135,7 @@ int vce_stop_recording(void); * @brief Sends audio formats necessary for playing TTS feedback. * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @privlevel public - * @privilege %http://tizen.org/privilege/appmanager.launch (Since 7.0) + * @privilege %http://tizen.org/privilege/appmanager.launch (Since 7.0) \n * %http://tizen.org/privilege/datasharing (Since 7.0) * @remarks To use this function, privileges of appmanager.launch and datasharing should be included since 7.0. * @@ -1141,6 +1146,7 @@ int vce_stop_recording(void); * @return 0 on success, otherwise a negative error value. * @retval #VCE_ERROR_NONE Successful * @retval #VCE_ERROR_NOT_SUPPORTED Not supported + * @retval #VCE_ERROR_PERMISSION_DENIED Permission denied * @retval #VCE_ERROR_INVALID_PARAMETER Invalid parameter * @retval #VCE_ERROR_OPERATION_FAILED Operation failure * @retval #VCE_ERROR_OUT_OF_MEMORY Out of Memory @@ -1151,7 +1157,7 @@ int vce_send_feedback_audio_format(int rate, vce_audio_channel_e channel, vce_au * @brief Sends audio streaming necessary for playing TTS feedback. * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @privlevel public - * @privilege %http://tizen.org/privilege/appmanager.launch (Since 7.0) + * @privilege %http://tizen.org/privilege/appmanager.launch (Since 7.0) \n * %http://tizen.org/privilege/datasharing (Since 7.0) * @remarks To use this function, privileges of appmanager.launch and datasharing should be included since 7.0. * @@ -1162,6 +1168,7 @@ int vce_send_feedback_audio_format(int rate, vce_audio_channel_e channel, vce_au * @return 0 on success, otherwise a negative error value. * @retval #VCE_ERROR_NONE Successful * @retval #VCE_ERROR_NOT_SUPPORTED Not supported + * @retval #VCE_ERROR_PERMISSION_DENIED Permission denied * @retval #VCE_ERROR_INVALID_PARAMETER Invalid parameter * @retval #VCE_ERROR_OPERATION_FAILED Operation failure * @retval #VCE_ERROR_OUT_OF_MEMORY Out of Memory diff --git a/server/vce.c b/server/vce.c index 98826b5..7daff10 100644 --- a/server/vce.c +++ b/server/vce.c @@ -141,6 +141,28 @@ static int __vce_check_privilege() //LCOV_EXCL_STOP } + ret = __check_privilege(uid, VC_PRIVILEGE_APPMGR_LAUNCH); + if (false == ret) { + //LCOV_EXCL_START + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Permission is denied(%s)(%s)", VC_PRIVILEGE_APPMGR_LAUNCH, uid); + __check_privilege_deinitialize(); + g_privilege_allowed = false; + pthread_mutex_unlock(&g_cynara_mutex); + return VCE_ERROR_PERMISSION_DENIED; + //LCOV_EXCL_STOP + } + + ret = __check_privilege(uid, VC_PRIVILEGE_DATASHARING); + if (false == ret) { + //LCOV_EXCL_START + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Permission is denied(%s)(%s)", VC_PRIVILEGE_DATASHARING, uid); + __check_privilege_deinitialize(); + g_privilege_allowed = false; + pthread_mutex_unlock(&g_cynara_mutex); + return VCE_ERROR_PERMISSION_DENIED; + //LCOV_EXCL_STOP + } + __check_privilege_deinitialize(); } @@ -198,11 +220,10 @@ int vce_main(int argc, char** argv, vce_request_callback_s *callback) int vce_send_result(vce_result_event_e event, int* result_id, int count, const char* all_result, const char* non_fixed_result, const char* nlu_result, const char* msg, int* user_info, void *user_data) { - if (0 != __vce_get_feature_enabled()) { - return VCE_ERROR_NOT_SUPPORTED; - } - int ret = VCE_ERROR_NONE; + ret = __check_engine_feature_privilege(); + if (VCE_ERROR_NONE != ret) + return ret; if (event < VCE_RESULT_EVENT_SUCCESS || event > VCE_RESULT_EVENT_ERROR) { SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Invalid parameter"); @@ -226,11 +247,10 @@ int vce_send_result(vce_result_event_e event, int* result_id, int count, const c int vce_send_asr_result(vce_asr_result_event_e event, const char* asr_result, void *user_data) { - if (0 != __vce_get_feature_enabled()) { - return VCE_ERROR_NOT_SUPPORTED; - } - int ret = VCE_ERROR_NONE; + ret = __check_engine_feature_privilege(); + if (VCE_ERROR_NONE != ret) + return ret; if (event < VCE_ASR_RESULT_EVENT_FINAL_RESULT || event > VCE_ASR_RESULT_EVENT_ERROR) { SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Invalid parameter"); @@ -253,11 +273,10 @@ int vce_send_asr_result(vce_asr_result_event_e event, const char* asr_result, vo int vce_send_specific_engine_result(const char* engine_app_id, const char* event, const char* result, void *user_info) { - if (0 != __vce_get_feature_enabled()) { - return VCE_ERROR_NOT_SUPPORTED; - } - int ret = VCE_ERROR_NONE; + ret = __check_engine_feature_privilege(); + if (VCE_ERROR_NONE != ret) + return ret; if (NULL == engine_app_id || NULL == event) { SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Invalid parameter"); @@ -280,11 +299,10 @@ int vce_send_specific_engine_result(const char* engine_app_id, const char* event int vce_send_nlg_result(const char* nlg_result, void *user_data) { - if (0 != __vce_get_feature_enabled()) { - return VCE_ERROR_NOT_SUPPORTED; - } - int ret = VCE_ERROR_NONE; + ret = __check_engine_feature_privilege(); + if (VCE_ERROR_NONE != ret) + return ret; if (NULL == nlg_result) { SLOG(LOG_ERROR, TAG_VCD, "[INFO] Input parameter is NULL. (no result)"); @@ -302,11 +320,10 @@ int vce_send_nlg_result(const char* nlg_result, void *user_data) int vce_send_error(vce_error_e error, const char* msg, void *user_data) { - if (0 != __vce_get_feature_enabled()) { - return VCE_ERROR_NOT_SUPPORTED; - } - int ret = VCE_ERROR_NONE; + ret = __check_engine_feature_privilege(); + if (VCE_ERROR_NONE != ret) + return ret; if (NULL == msg) { SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Input parameter is NULL. (no error message)"); @@ -566,11 +583,10 @@ int vce_unset_specific_engine_request_cb(void) /* for TTS feedback */ int vce_send_feedback_audio_format(int rate, vce_audio_channel_e channel, vce_audio_type_e audio_type) { - if (0 != __vce_get_feature_enabled()) { - return VCE_ERROR_NOT_SUPPORTED; - } - int ret = VCE_ERROR_NONE; + ret = __check_engine_feature_privilege(); + if (VCE_ERROR_NONE != ret) + return ret; if (channel < VCE_AUDIO_CHANNEL_MONO || channel > VCE_AUDIO_CHANNEL_STEREO) { SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Invalid parameter"); @@ -592,11 +608,10 @@ int vce_send_feedback_audio_format(int rate, vce_audio_channel_e channel, vce_au int vce_send_feedback_streaming(vce_feedback_event_e event, char* buffer, int len) { - if (0 != __vce_get_feature_enabled()) { - return VCE_ERROR_NOT_SUPPORTED; - } - int ret = VCE_ERROR_NONE; + ret = __check_engine_feature_privilege(); + if (VCE_ERROR_NONE != ret) + return ret; if (NULL == buffer) { SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Input parameter is NULL"); -- 2.34.1