diff options
author | Daehyeon Jung <darrenh.jung@samsung.com> | 2016-03-24 23:15:39 +0900 |
---|---|---|
committer | Daehyeon Jung <darrenh.jung@samsung.com> | 2016-03-24 23:15:39 +0900 |
commit | 8de1418f50f98e61668b0154a4d386b60bae45a9 (patch) | |
tree | c4b1c3cf4781fb8f820e8b3ae5e0dbc029b211a5 | |
parent | dbbc459b76db26824fa7cfefed755bf992e26f8e (diff) | |
download | widget-service-accepted/tizen/mobile/20160325.032255.tar.gz widget-service-accepted/tizen/mobile/20160325.032255.tar.bz2 widget-service-accepted/tizen/mobile/20160325.032255.zip |
Add pirivilege checksubmit/tizen/20160324.150057accepted/tizen/wearable/20160325.032332accepted/tizen/tv/20160325.032313accepted/tizen/mobile/20160325.032255accepted/tizen/ivi/20160325.032351accepted/tizen/common/20160324.173503
Change-Id: I9d55acde45eb02a9568e7ed3997d9bcface3abaa
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | packaging/libwidget_service.spec | 1 | ||||
-rw-r--r-- | src/widget_service.c | 59 |
3 files changed, 61 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 7ff419b..215c621 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,6 +28,7 @@ pkg_check_modules(pkgs REQUIRED aul libtzplatform-config uuid + cynara-client ) FOREACH(flag ${pkgs_CFLAGS}) diff --git a/packaging/libwidget_service.spec b/packaging/libwidget_service.spec index aaf5bf5..43c30f8 100644 --- a/packaging/libwidget_service.spec +++ b/packaging/libwidget_service.spec @@ -24,6 +24,7 @@ BuildRequires: pkgconfig(capi-system-info) BuildRequires: pkgconfig(libtzplatform-config) BuildRequires: pkgconfig(libxml-2.0) BuildRequires: pkgconfig(aul) +BuildRequires: pkgconfig(cynara-client) %if "%{model_build_feature_widget}" == "0" ExclusiveArch: diff --git a/src/widget_service.c b/src/widget_service.c index 60681a6..3897bee 100644 --- a/src/widget_service.c +++ b/src/widget_service.c @@ -28,6 +28,9 @@ #include <pkgmgr-info.h> #include <system_info.h> #include <dlog.h> +#include <cynara-client.h> +#include <stdio.h> +#include <fcntl.h> #include "widget_errno.h" #include "debug.h" @@ -36,6 +39,7 @@ #include "widget_service.h" #define MAX_BUF_SIZE 4096 +#define SMACK_LABEL_LEN 255 static GList *lifecycle_cbs; @@ -60,6 +64,58 @@ static inline bool _is_widget_feature_enabled(void) return feature; } +static int check_privilege(const char *privilege) +{ + cynara *p_cynara; + + int fd = 0; + int ret = 0; + + char subject_label[SMACK_LABEL_LEN + 1] = ""; + char uid[10] = {0,}; + char *client_session = ""; + + ret = cynara_initialize(&p_cynara, NULL); + if (ret != CYNARA_API_SUCCESS) { + LOGE("cannot init cynara [%d] failed!", ret); + ret = -1; + goto out; + } + + fd = open("/proc/self/attr/current", O_RDONLY); + if (fd < 0) { + LOGE("open [%d] failed!", errno); + ret = -1; + goto out; + } + + ret = read(fd, subject_label, SMACK_LABEL_LEN); + if (ret < 0) { + LOGE("read [%d] failed!", errno); + close(fd); + ret = -1; + goto out; + } + close(fd); + + snprintf(uid, 10, "%d", getuid()); + + ret = cynara_check(p_cynara, subject_label, client_session, uid, + privilege); + if (ret != CYNARA_API_ACCESS_ALLOWED) { + LOGE("cynara access check [%d] failed!", ret); + ret = -1; + goto out; + } + + ret = 0; +out: + if (p_cynara) + cynara_finish(p_cynara); + + return ret; +} + #define ROOT_USER 0 #define GLOBALAPP_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER) static int _is_global(uid_t uid) @@ -423,6 +479,9 @@ EAPI int widget_service_get_widget_list(widget_list_cb cb, void *data) return WIDGET_ERROR_INVALID_PARAMETER; } + if (check_privilege("http://tizen.org/privilege/widget.viewer") < 0) + return WIDGET_ERROR_PERMISSION_DENIED; + ret = _get_widget_list(NULL, getuid(), &list); if (ret == WIDGET_ERROR_NONE) ret = _get_widget_list(NULL, GLOBALAPP_USER, &list); |