* limitations under the License.
*/
+#include <cynara-client.h>
+#include <cynara-error.h>
+#include <cynara-session.h>
#include <system_info.h>
#include "vc_elm_main.h"
#include <voice_control_elm.h>
static int g_feature_enabled = -1;
+static int g_privilege_allowed = -1;
+static cynara *p_cynara = NULL;
+
static int __vc_elm_get_feature_enabled()
{
if (0 == g_feature_enabled) {
return 0;
}
+static int __check_privilege_initialize()
+{
+ int ret = cynara_initialize(&p_cynara, NULL);
+ if (CYNARA_API_SUCCESS != ret)
+ VC_ELM_LOG_ERR("[ERROR] fail to initialize");
+
+ return ret == CYNARA_API_SUCCESS;
+}
+
+static int __check_privilege(const char* uid, const char * privilege)
+{
+ FILE *fp = NULL;
+ char smack_label[1024] = "/proc/self/attr/current";
+
+ if (!p_cynara) {
+ return false;
+ }
+
+ fp = fopen(smack_label, "r");
+ if (fp != NULL) {
+ if (fread(smack_label, 1, sizeof(smack_label), fp) <= 0)
+ VC_ELM_LOG_ERR("[ERROR] fail to fread");
+
+ fclose(fp);
+ }
+
+ pid_t pid = getpid();
+ char *session = cynara_session_from_pid(pid);
+ int ret = cynara_check(p_cynara, smack_label, session, uid, privilege);
+ VC_ELM_LOG_DBG("[Client]cynara_check returned %d(%s)", ret, (CYNARA_API_ACCESS_ALLOWED == ret) ? "Allowed" : "Denied");
+ if (session)
+ free(session);
+
+ if (ret != CYNARA_API_ACCESS_ALLOWED)
+ return false;
+ return true;
+}
+
+static void __check_privilege_deinitialize()
+{
+ if (p_cynara)
+ cynara_finish(p_cynara);
+ p_cynara = NULL;
+}
+
+static int __vc_elm_check_privilege()
+{
+ char uid[16];
+
+ if (0 == g_privilege_allowed) {
+ VC_ELM_LOG_ERR("[ERROR] Permission is denied");
+ return VC_ELM_ERROR_PERMISSION_DENIED;
+ } else if (-1 == g_privilege_allowed) {
+ if (false == __check_privilege_initialize()){
+ VC_ELM_LOG_ERR("[ERROR] privilege initialize is failed");
+ return VC_ELM_ERROR_PERMISSION_DENIED;
+ }
+ snprintf(uid, 16, "%d", getuid());
+ if (false == __check_privilege(uid, VC_ELM_PRIVILEGE)) {
+ VC_ELM_LOG_ERR("[ERROR] Permission is denied");
+ g_privilege_allowed = 0;
+ __check_privilege_deinitialize();
+ return VC_ELM_ERROR_PERMISSION_DENIED;
+ }
+ __check_privilege_deinitialize();
+ }
+
+ g_privilege_allowed = 1;
+ return VC_ELM_ERROR_NONE;
+}
+
int vc_elm_initialize()
{
if (0 != __vc_elm_get_feature_enabled()) {
- return VC_ERROR_NOT_SUPPORTED;
+ return VC_ELM_ERROR_NOT_SUPPORTED;
+ }
+ if (0 != __vc_elm_check_privilege()) {
+ return VC_ELM_ERROR_PERMISSION_DENIED;
}
if (true == is_vc_elm_initialized) {
vc_elm_h handler = NULL;
if (0 != __vc_elm_get_feature_enabled()) {
- return VC_ERROR_NOT_SUPPORTED;
+ return VC_ELM_ERROR_NOT_SUPPORTED;
+ }
+ if (0 != __vc_elm_check_privilege()) {
+ return VC_ELM_ERROR_PERMISSION_DENIED;
}
if (false == is_vc_elm_initialized) {
{
int ret;
if (0 != __vc_elm_get_feature_enabled()) {
- return VC_ERROR_NOT_SUPPORTED;
+ return VC_ELM_ERROR_NOT_SUPPORTED;
+ }
+ if (0 != __vc_elm_check_privilege()) {
+ return VC_ELM_ERROR_PERMISSION_DENIED;
}
ret = vc_widget_foreach_supported_languages(callback, user_data);
{
int ret;
if (0 != __vc_elm_get_feature_enabled()) {
- return VC_ERROR_NOT_SUPPORTED;
+ return VC_ELM_ERROR_NOT_SUPPORTED;
+ }
+ if (0 != __vc_elm_check_privilege()) {
+ return VC_ELM_ERROR_PERMISSION_DENIED;
}
ret = vc_widget_get_current_language(language);
const Eina_Hash *hash = NULL;
if (0 != __vc_elm_get_feature_enabled()) {
- return VC_ERROR_NOT_SUPPORTED;
+ return VC_ELM_ERROR_NOT_SUPPORTED;
+ }
+ if (0 != __vc_elm_check_privilege()) {
+ return VC_ELM_ERROR_PERMISSION_DENIED;
}
+
if (NULL == callback) {
VC_ELM_LOG_ERR("Invalid parameters detected!");
return VC_ELM_ERROR_INVALID_PARAMETER;
const char *action_tag = NULL;
if (0 != __vc_elm_get_feature_enabled()) {
- return VC_ERROR_NOT_SUPPORTED;
+ return VC_ELM_ERROR_NOT_SUPPORTED;
+ }
+ if (0 != __vc_elm_check_privilege()) {
+ return VC_ELM_ERROR_PERMISSION_DENIED;
}
+
if ((NULL == widget) || (NULL == callback)) {
VC_ELM_LOG_ERR("Invalid parameters detected!");
return VC_ELM_ERROR_INVALID_PARAMETER;
size_t len = 0;
if (0 != __vc_elm_get_feature_enabled()) {
- return VC_ERROR_NOT_SUPPORTED;
+ return VC_ELM_ERROR_NOT_SUPPORTED;
}
+ if (0 != __vc_elm_check_privilege()) {
+ return VC_ELM_ERROR_PERMISSION_DENIED;
+ }
+
if ((NULL == action) || (NULL == command)) {
VC_ELM_LOG_ERR("Invalid parameters detected!");
return VC_ELM_ERROR_INVALID_PARAMETER;
{
vc_elm_s *handler = NULL;
if (0 != __vc_elm_get_feature_enabled()) {
- return VC_ERROR_NOT_SUPPORTED;
+ return VC_ELM_ERROR_NOT_SUPPORTED;
+ }
+ if (0 != __vc_elm_check_privilege()) {
+ return VC_ELM_ERROR_PERMISSION_DENIED;
}
if (NULL == vc_elm) {
{
vc_elm_s *handler = NULL;
if (0 != __vc_elm_get_feature_enabled()) {
- return VC_ERROR_NOT_SUPPORTED;
+ return VC_ELM_ERROR_NOT_SUPPORTED;
+ }
+ if (0 != __vc_elm_check_privilege()) {
+ return VC_ELM_ERROR_PERMISSION_DENIED;
}
if (NULL == vc_elm) {
Eina_List *list = NULL;
int type = 0;
if (0 != __vc_elm_get_feature_enabled()) {
- return VC_ERROR_NOT_SUPPORTED;
+ return VC_ELM_ERROR_NOT_SUPPORTED;
+ }
+ if (0 != __vc_elm_check_privilege()) {
+ return VC_ELM_ERROR_PERMISSION_DENIED;
}
+
if (NULL == vc_elm) {
VC_ELM_LOG_ERR("Invalid vc_elm parameter detected!");
return VC_ELM_ERROR_INVALID_PARAMETER;
vc_elm_s *handler = (vc_elm_s *)vc_elm;
int type = 0;
if (0 != __vc_elm_get_feature_enabled()) {
- return VC_ERROR_NOT_SUPPORTED;
+ return VC_ELM_ERROR_NOT_SUPPORTED;
}
+ if (0 != __vc_elm_check_privilege()) {
+ return VC_ELM_ERROR_PERMISSION_DENIED;
+ }
+
if (NULL == vc_elm) {
VC_ELM_LOG_ERR("Invalid vc_elm parameter detected!");
return VC_ELM_ERROR_INVALID_PARAMETER;
vc_elm_s *handler = (vc_elm_s *)vc_elm;
int type = 0;
if (0 != __vc_elm_get_feature_enabled()) {
- return VC_ERROR_NOT_SUPPORTED;
+ return VC_ELM_ERROR_NOT_SUPPORTED;
}
+ if (0 != __vc_elm_check_privilege()) {
+ return VC_ELM_ERROR_PERMISSION_DENIED;
+ }
+
if (NULL == vc_elm) {
VC_ELM_LOG_ERR("Invalid vc_elm parameter detected!");
return VC_ELM_ERROR_INVALID_PARAMETER;
vc_elm_s *handler = (vc_elm_s *)vc_elm;
int type = 0;
if (0 != __vc_elm_get_feature_enabled()) {
- return VC_ERROR_NOT_SUPPORTED;
+ return VC_ELM_ERROR_NOT_SUPPORTED;
+ }
+ if (0 != __vc_elm_check_privilege()) {
+ return VC_ELM_ERROR_PERMISSION_DENIED;
}
+
if (NULL == vc_elm) {
VC_ELM_LOG_ERR("Invalid vc_elm parameter detected!");
return VC_ELM_ERROR_INVALID_PARAMETER;
vc_elm_s *handler = (vc_elm_s *)vc_elm;
int type = 0;
if (0 != __vc_elm_get_feature_enabled()) {
- return VC_ERROR_NOT_SUPPORTED;
+ return VC_ELM_ERROR_NOT_SUPPORTED;
+ }
+ if (0 != __vc_elm_check_privilege()) {
+ return VC_ELM_ERROR_PERMISSION_DENIED;
}
+
if (NULL == vc_elm) {
VC_ELM_LOG_ERR("Invalid vc_elm parameter detected!");
return VC_ELM_ERROR_INVALID_PARAMETER;
vc_elm_s *handler = (vc_elm_s *)vc_elm;
int type = 0;
if (0 != __vc_elm_get_feature_enabled()) {
- return VC_ERROR_NOT_SUPPORTED;
+ return VC_ELM_ERROR_NOT_SUPPORTED;
+ }
+ if (0 != __vc_elm_check_privilege()) {
+ return VC_ELM_ERROR_PERMISSION_DENIED;
}
+
if (NULL == vc_elm) {
VC_ELM_LOG_ERR("Invalid vc_elm parameter detected!");
return VC_ELM_ERROR_INVALID_PARAMETER;
vc_elm_s *handler = (vc_elm_s *)vc_elm;
int type = 0;
if (0 != __vc_elm_get_feature_enabled()) {
- return VC_ERROR_NOT_SUPPORTED;
+ return VC_ELM_ERROR_NOT_SUPPORTED;
}
+ if (0 != __vc_elm_check_privilege()) {
+ return VC_ELM_ERROR_PERMISSION_DENIED;
+ }
+
if (NULL == vc_elm) {
VC_ELM_LOG_ERR("Invalid vc_elm parameter detected!");
return VC_ELM_ERROR_INVALID_PARAMETER;
vc_elm_s *handler = (vc_elm_s *)vc_elm;
int type = 0;
if (0 != __vc_elm_get_feature_enabled()) {
- return VC_ERROR_NOT_SUPPORTED;
+ return VC_ELM_ERROR_NOT_SUPPORTED;
}
+ if (0 != __vc_elm_check_privilege()) {
+ return VC_ELM_ERROR_PERMISSION_DENIED;
+ }
+
if (NULL == vc_elm) {
VC_ELM_LOG_ERR("Invalid vc_elm parameter detected!");
return VC_ELM_ERROR_INVALID_PARAMETER;
const char *path = NULL;
int type = 0;
if (0 != __vc_elm_get_feature_enabled()) {
- return VC_ERROR_NOT_SUPPORTED;
+ return VC_ELM_ERROR_NOT_SUPPORTED;
+ }
+ if (0 != __vc_elm_check_privilege()) {
+ return VC_ELM_ERROR_PERMISSION_DENIED;
}
+
if (NULL == vc_elm) {
VC_ELM_LOG_ERR("Invalid vc_elm parameter detected!");
return VC_ELM_ERROR_INVALID_PARAMETER;
int ret = VC_ELM_ERROR_NONE;
if (0 != __vc_elm_get_feature_enabled()) {
- return VC_ERROR_NOT_SUPPORTED;
+ return VC_ELM_ERROR_NOT_SUPPORTED;
+ }
+ if (0 != __vc_elm_check_privilege()) {
+ return VC_ELM_ERROR_PERMISSION_DENIED;
}
+
if (false == is_vc_elm_initialized) {
VC_ELM_LOG_ERR("Invalid state detected! Library not initialized!");
return VC_ELM_ERROR_INVALID_STATE;
int ret = VC_ELM_ERROR_NONE;
if (0 != __vc_elm_get_feature_enabled()) {
- return VC_ERROR_NOT_SUPPORTED;
+ return VC_ELM_ERROR_NOT_SUPPORTED;
}
+ if (0 != __vc_elm_check_privilege()) {
+ return VC_ELM_ERROR_PERMISSION_DENIED;
+ }
+
if (false == is_vc_elm_initialized) {
VC_ELM_LOG_ERR("Invalid state detected! Library not initialized!");
return VC_ELM_ERROR_INVALID_STATE;