Add permission denied error and descriptions 24/282324/1
authorsooyeon <sooyeon.kim@samsung.com>
Thu, 22 Sep 2022 04:46:47 +0000 (13:46 +0900)
committerTizen AI <ai.tzn.sec@samsung.com>
Fri, 30 Sep 2022 01:50:14 +0000 (10:50 +0900)
Change-Id: Iaf1b54300feb01f789cac0af799982a3d6492a3b
Signed-off-by: sooyeon <sooyeon.kim@samsung.com>
common/vc_defs.h
include/vce.h
server/vce.c

index 0e12f460161e4248484447ecfb4b451977f6389d..1fb53d340a9c716b73d73a1c791fab607c9cb5dd 100644 (file)
@@ -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"
 
 /******************************************************************************************
index 4509c32fc5a24ab02ffcaaac2ca807ba3124b5f6..ae54abc8ca4eee232a67bcf1c9e26f2f7723db8a 100644 (file)
@@ -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
index 98826b57bc3580223380d321e6f4705581d1ad00..7daff10ba2337b4eff039ba7ef86e89541a5c7f8 100644 (file)
@@ -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");