summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYunhee Seo <yuni.seo@samsung.com>2023-08-18 12:58:40 +0900
committerYunhee Seo <yuni.seo@samsung.com>2023-08-21 14:30:57 +0900
commit8721411b5fff98bf3c4487175fafabfb714ddee7 (patch)
treed4ebcc9ea3fbed427b7b6d2f4acb8ec0db794e35
parenta3a75b5c5c6f67a6d2868021a67681ed29c79c82 (diff)
downloadlibsvi-8721411b5fff98bf3c4487175fafabfb714ddee7.tar.gz
libsvi-8721411b5fff98bf3c4487175fafabfb714ddee7.tar.bz2
libsvi-8721411b5fff98bf3c4487175fafabfb714ddee7.zip
feedback: Add checking privilege for multi-theme support funcs
Setting feedback theme index is required "http://tizen.org/privilege/systemsettings.admin" privilege. Getting feedback theme is required "http://tizen.org/privilege/internal/default/public". If application has above privilege, setting/getting theme index is successful. Change-Id: I5aad3f3138e0fe0d0211832300929d78a4d7d47b Signed-off-by: Yunhee Seo <yuni.seo@samsung.com>
-rw-r--r--CMakeLists.txt9
-rwxr-xr-xinclude/feedback-internal.h9
-rw-r--r--include/util/feedback-privilege.h26
-rw-r--r--packaging/libfeedback.spec2
-rw-r--r--src/feedback.c12
-rw-r--r--src/util/feedback-privilege.c75
6 files changed, 131 insertions, 2 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e83e7e9..a0eceb9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -16,19 +16,22 @@ SET(SRCS
src/devices.c
src/feedback-config.c
src/feedback.c
- src/check.c)
+ src/check.c
+ src/util/feedback-privilege.c)
SET(HEADERS
include/feedback.h
include/feedback-ids.h
include/feedback-internal.h
include/feedback-ids-internal.h
- include/feedback-ids-product.h)
+ include/feedback-ids-product.h
+ include/util/feedback-privilege.h)
ADD_DEFINITIONS("-DFEEDBACK_SYS_SHARE=\"${TZ_SYS_SHARE}\"")
ADD_DEFINITIONS("-DFEEDBACK_SYS_RO_SHARE=\"${TZ_SYS_RO_SHARE}\"")
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include/util)
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src)
INCLUDE(FindPkgConfig)
@@ -42,6 +45,8 @@ pkg_check_modules(pkgs REQUIRED
capi-media-sound-manager
capi-media-wav-player
libsyscommon
+ cynara-client
+ cynara-session
)
FOREACH(flag ${pkgs_CFLAGS})
diff --git a/include/feedback-internal.h b/include/feedback-internal.h
index c7b03da..17b254c 100755
--- a/include/feedback-internal.h
+++ b/include/feedback-internal.h
@@ -161,6 +161,8 @@ int feedback_play_type_soundpath_internal(feedback_type_e type, feedback_pattern
* @brief Gets the number of theme supported.
* @details This function gets the number of theme described in the config file.
* @since_tizen 8.0
+ * @remarks For reading count of feedback theme by feedback type, the privilege should be set to, %http://tizen.org/privilege/internal/default/public.
+ * If app doesn't have the privilege, it returns FEEDBACK_ERROR_PERMISSION_DENIED error.
* @param[in] type The feedback type
* @param[out] count_of_theme The number of theme supported
* @return @c 0 on success,
@@ -170,6 +172,7 @@ int feedback_play_type_soundpath_internal(feedback_type_e type, feedback_pattern
* @retval #FEEDBACK_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #FEEDBACK_ERROR_NOT_SUPPORTED Not supported device
* @retval #FEEDBACK_ERROR_NOT_INITIALIZED Not initialized
+ * @retval #FEEDBACK_ERROR_PERMISSION_DENIED Permission denied
* @pre feedback_initialize()
*/
int feedback_get_count_of_theme_internal(feedback_type_e feedback_type, unsigned int *count_of_theme);
@@ -178,6 +181,8 @@ int feedback_get_count_of_theme_internal(feedback_type_e feedback_type, unsigned
* @brief Gets the current index of theme selected.
* @details This function gets the current index of theme selected.
* @since_tizen 8.0
+ * @remarks For reading feedback theme index, the privilege should be set to, %http://tizen.org/privilege/internal/default/public.
+ * If app doesn't have the privilege, it returns FEEDBACK_ERROR_PERMISSION_DENIED error.
* @param[in] type The feedback type
* @param[out] index_of_theme The current index of theme selected
* @return @c 0 on success,
@@ -186,6 +191,7 @@ int feedback_get_count_of_theme_internal(feedback_type_e feedback_type, unsigned
* @retval #FEEDBACK_ERROR_OPERATION_FAILED Operation not permitted
* @retval #FEEDBACK_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #FEEDBACK_ERROR_NOT_SUPPORTED Not supported device
+ * @retval #FEEDBACK_ERROR_PERMISSION_DENIED Permission denied
*/
int feedback_get_theme_index_internal(feedback_type_e feedback_type, unsigned int *index_of_theme);
@@ -195,6 +201,8 @@ int feedback_get_theme_index_internal(feedback_type_e feedback_type, unsigned in
* The range of theme index will be 1~N according to conf file.
* Please put the accurate index_of_theme value.
* @since_tizen 8.0
+ * @remarks For setting feedback theme index, the privilege should be set to, %http://tizen.org/privilege/systemsettings.admin.
+ * If app doesn't have the privilege, it returns FEEDBACK_ERROR_PERMISSION_DENIED error.
* @param[in] type The feedback type
* @param[in] index_of_theme The index of theme will be selected
* @return @c 0 on success,
@@ -203,6 +211,7 @@ int feedback_get_theme_index_internal(feedback_type_e feedback_type, unsigned in
* @retval #FEEDBACK_ERROR_OPERATION_FAILED Operation not permitted
* @retval #FEEDBACK_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #FEEDBACK_ERROR_NOT_SUPPORTED Not supported device
+ * @retval #FEEDBACK_ERROR_PERMISSION_DENIED Permission denied
*/
int feedback_set_theme_index_internal(feedback_type_e feedback_type, unsigned int index_of_theme);
diff --git a/include/util/feedback-privilege.h b/include/util/feedback-privilege.h
new file mode 100644
index 0000000..bdd1852
--- /dev/null
+++ b/include/util/feedback-privilege.h
@@ -0,0 +1,26 @@
+
+/*
+ * libfeedback
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __FEEDBACK_PRIVILEGE_H__
+#define __FEEDBACK_PRIVILEGE_H__
+
+#include <stdbool.h>
+
+bool is_privilege_supported(const char *privilege_name);
+
+#endif //__FEEDBACK_PRIVILEGE_H__ \ No newline at end of file
diff --git a/packaging/libfeedback.spec b/packaging/libfeedback.spec
index 71a6985..a088c13 100644
--- a/packaging/libfeedback.spec
+++ b/packaging/libfeedback.spec
@@ -21,6 +21,8 @@ BuildRequires: pkgconfig(capi-media-wav-player)
BuildRequires: pkgconfig(libtzplatform-config)
BuildRequires: pkgconfig(capi-system-info)
BuildRequires: pkgconfig(libsyscommon)
+BuildRequires: pkgconfig(cynara-client)
+BuildRequires: pkgconfig(cynara-session)
%if 0%{?gcov:1}
BuildRequires: lcov
diff --git a/src/feedback.c b/src/feedback.c
index dd5d254..6f0d0db 100644
--- a/src/feedback.c
+++ b/src/feedback.c
@@ -22,6 +22,7 @@
#include <limits.h>
#include <libsyscommon/libgdbus.h>
+#include "util/feedback-privilege.h"
#include "feedback.h"
#include "feedback-internal.h"
#include "profiles.h"
@@ -37,6 +38,8 @@ static pthread_mutex_t fmutex = PTHREAD_MUTEX_INITIALIZER;
static guint signal_id = 0;
#define SIGNAL_VIBRATOR_INITIATED "InitiateVibrator"
+#define PRIVILEGE_FEEDBACK_SET_THEME "http://tizen.org/privilege/systemsettings.admin"
+#define PRIVILEGE_FEEDBACK_GET_THEME "http://tizen.org/privilege/internal/default/public"
//LCOV_EXCL_START Not called Callback
static void restart_callback(GDBusConnection *conn,
@@ -529,6 +532,9 @@ API int feedback_get_count_of_theme_internal(feedback_type_e feedback_type, unsi
const struct device_ops *dev = NULL;
int ret = 0;
+ if (!is_privilege_supported(PRIVILEGE_FEEDBACK_GET_THEME))
+ return FEEDBACK_ERROR_PERMISSION_DENIED;
+
pthread_mutex_lock(&fmutex);
if (!init_cnt) {
_E("Not initialized"); //LCOV_EXCL_LINE
@@ -563,6 +569,9 @@ API int feedback_get_theme_index_internal(feedback_type_e feedback_type, unsigne
const struct device_ops *dev = NULL;
int ret = 0;
+ if (!is_privilege_supported(PRIVILEGE_FEEDBACK_GET_THEME))
+ return FEEDBACK_ERROR_PERMISSION_DENIED;
+
if (feedback_type <= FEEDBACK_TYPE_NONE || feedback_type >= profile->max_type || !index_of_theme) {
_E("Invalid parameter : type(%d)", feedback_type);
return FEEDBACK_ERROR_INVALID_PARAMETER;
@@ -591,6 +600,9 @@ API int feedback_set_theme_index_internal(feedback_type_e feedback_type, unsigne
const struct device_ops *dev = NULL;
int ret = 0;
+ if (!is_privilege_supported(PRIVILEGE_FEEDBACK_SET_THEME))
+ return FEEDBACK_ERROR_PERMISSION_DENIED;
+
if (feedback_type <= FEEDBACK_TYPE_NONE || feedback_type >= profile->max_type) {
_E("Invalid parameter : type(%d)", feedback_type);
return FEEDBACK_ERROR_INVALID_PARAMETER;
diff --git a/src/util/feedback-privilege.c b/src/util/feedback-privilege.c
new file mode 100644
index 0000000..f47dc84
--- /dev/null
+++ b/src/util/feedback-privilege.c
@@ -0,0 +1,75 @@
+/*
+ * libfeedback
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <unistd.h>
+#include <glib.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <cynara-client.h>
+#include <cynara-session.h>
+
+#include "util/feedback-privilege.h"
+#include "log.h"
+
+#define BUFF_MAX 255
+
+extern char *program_invocation_name;
+
+bool is_privilege_supported(const char *privilege_name)
+{
+ cynara *cynara = NULL;
+ FILE *fp = NULL;
+ char uid[16];
+ char *session = NULL;
+ char smack_label[BUFF_MAX] = {0, };
+ int ret;
+
+ if (cynara_initialize(&cynara, NULL) != CYNARA_API_SUCCESS) {
+ _E("failed to initialize cynara");
+ return false;
+ }
+
+ fp = fopen("/proc/self/attr/current", "r");
+ if (fp != NULL) {
+ int ch = 0;
+ int idx = 0;
+ while (EOF != (ch = fgetc(fp))) {
+ smack_label[idx] = ch;
+ idx++;
+ }
+ fclose(fp);
+ }
+
+ pid_t pid = getpid();
+ session = cynara_session_from_pid(pid);
+ snprintf(uid, 16, "%d", getuid());
+ uid[15] = '\0';
+
+ ret = cynara_check(cynara, smack_label, session, uid, privilege_name);
+ if (session)
+ free(session);
+ if (cynara)
+ cynara_finish(cynara);
+ if (ret != CYNARA_API_ACCESS_ALLOWED) {
+ _E("'%s' privilege is not supported on %s",
+ privilege_name, program_invocation_name);
+ return false;
+ }
+
+ return true;
+}