/*
- * Copyright(c) 2013-2017 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright(c) 2013-2018 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0(the License);
* you may not use this file except in compliance with the License.
int privilege_db_manager_get_privacy_by_privilege(const char* privilege, char** privacy_name);
/**
+ * @brief Get privilege list of the same privacy group that the given privilege is included in.
+ * @param [in] privilege The privilege
+ * @param [out] privilege_list The privilege list of the same privacy group.
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #PRIVILEGE_DB_MANAGER_ERR_NONE Successful.
+ * @retval #PRIVILEGE_DB_MANAGER_ERR_INVALID_QUERY Failed to prepare sql query.
+ * @retval #PRIVILEGE_DB_MANAGER_ERR_DB_NOENTRY DB not exist.
+ * @retval #PRIVILEGE_DB_MANAGER_ERR_CONNECTION_FAIL DB exist but failed to open DB.
+ * @retval #PRIVILEGE_DB_MANAGER_ERR_NO_EXIST_RESULT No data selected by given qeury.
+ */
+int privilege_db_manager_get_same_privacy_grouped_privileges(const char* privilege, GList **privilege_list);
+
+
+/**
* @brief Get privacy ID that the given privilege is included in.
* @param [in] privilege The privilege
* @param [out] privacy_id The privacy ID
/*
- * Copyright (c) 2013-2017 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2013-2018 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
*/
EXPORT_API int privilege_info_get_mdm_black_list(uid_t uid, GList **privilege_list);
+/**
+ * @brief Get privilege list of the same privacy group that the given privilege is included in.
+ * @remarks @a privilege_list must be released with g_list_free() by you.
+ * @remarks @a privilege_list is NULL when the given privilege is not a privacy privilege.
+ * @param [in] privilege privilege
+ * @param [out] privilege_list The privilege list of the same privacy group
+ * @return 0 on success, otherwise a nonzero error value.
+ * @retval #PRVMGR_ERR_NONE Successful
+ * @retval #PRVMGR_ERR_INTERNAL_ERROR Internal error
+ * @retval #PRVMGR_ERR_INVALID_PARAMETER Invalid parameter
+ */
+EXPORT_API int privilege_info_get_same_privacy_grouped_privileges(const char* privilege, GList **privilege_list);
+
#ifdef __cplusplus
}
#endif
/*
- * Copyright(c) 2013-2017 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright(c) 2013-2018 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0(the License);
* you may not use this file except in compliance with the License.
return ret;
}
+int privilege_db_manager_get_same_privacy_grouped_privileges(const char* privilege, GList** privilege_list)
+{
+ sqlite3 *db = NULL;
+ sqlite3_stmt *stmt = NULL;
+ int ret = __initialize_db(PRIVILEGE_DB_TYPE_INFO, &db);
+ if (ret != PRIVILEGE_DB_MANAGER_ERR_NONE)
+ return ret;
+
+ char *sql = sqlite3_mprintf("select distinct privilege_name from privilege_info where privacy_name=(select distinct privacy_name from privilege_info where privilege_name=%Q and is_privacy=1)", privilege);
+ TryReturn(sql != NULL, __finalize_db(db, stmt, sql), PRIVILEGE_DB_MANAGER_ERR_INVALID_QUERY, "[DB_FAIL] sqlite3_mprintf failed");
+ ret = sqlite3_prepare_v2(db, sql, strlen(sql), &stmt, NULL);
+ TryReturn(ret == SQLITE_OK, __finalize_db(db, stmt, sql), PRIVILEGE_DB_MANAGER_ERR_INVALID_QUERY, "[DB_FAIL] fail to prepare database: %s", sqlite3_errmsg(db));
+
+ GList* temp_privilege_list = NULL;
+ do {
+ ret = sqlite3_step(stmt);
+ if (ret == SQLITE_ROW) {
+ char *privilege_name = strdup((char *)sqlite3_column_text(stmt, 0));
+ TryReturn(privilege_name != NULL, __finalize_db(db, stmt, sql); g_list_free_full(temp_privilege_list, free), PRIVILEGE_DB_MANAGER_ERR_OUT_OF_MEMORY, "strdup failed");
+ temp_privilege_list = g_list_append(temp_privilege_list, privilege_name);
+ }
+ } while (ret == SQLITE_ROW);
+
+ __finalize_db(db, stmt, sql);
+
+ if (temp_privilege_list == NULL)
+ return PRIVILEGE_DB_MANAGER_ERR_NO_EXIST_RESULT;
+
+ *privilege_list = temp_privilege_list;
+
+ return PRIVILEGE_DB_MANAGER_ERR_NONE;
+
+}
+
int privilege_db_manager_get_privacy_id_by_privilege(const char* privilege, int *privacy_id)
{
sqlite3 *db = NULL;
/*
- * Copyright(c) 2013-2017 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright(c) 2013-2018 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0(the License);
* you may not use this file except in compliance with the License.
ret = PRVMGR_ERR_INTERNAL_ERROR;
return ret;
}
+
+int privilege_info_get_same_privacy_grouped_privileges(const char* privilege, GList **privilege_list)
+{
+ TryReturn(privilege != NULL, , PRVMGR_ERR_INVALID_PARAMETER, "[PRVMGR_ERR_INVALID_PARAMETER] privilege is null");
+ int ret = privilege_db_manager_get_same_privacy_grouped_privileges(privilege, privilege_list);
+ if (ret == PRIVILEGE_DB_MANAGER_ERR_NONE || ret == PRIVILEGE_DB_MANAGER_ERR_NO_EXIST_RESULT)
+ return PRVMGR_ERR_NONE;
+ else
+ return PRVMGR_ERR_INTERNAL_ERROR;
+}
__print_line();
}
+void __test_privilege_db_manager_get_same_privacy_grouped_privileges()
+{
+ int ret = 0;
+ GList *privilege_list = NULL;
+
+ __print_line();
+ printf("privilege = http://tizen.org/privilege/account.read\n");
+ ret = privilege_db_manager_get_same_privacy_grouped_privileges("http://tizen.org/privilege/account.read", &privilege_list);
+
+ if (ENABLE_ASKUSER) {
+ printf("privacy = account\n");
+ if (ret == PRIVILEGE_DB_MANAGER_ERR_NONE && privilege_list != NULL) {
+ success_cnt++;
+ __color_to_green();
+ printf("success\n");
+ __color_to_origin();
+ } else {
+ fail_cnt++;
+ __color_to_red();
+ printf("failed. ret = %s\n", __get_result_string('m', ret));
+ __color_to_origin();
+ }
+ } else {
+ printf("not privacy\n");
+ if (ret == PRIVILEGE_DB_MANAGER_ERR_NO_EXIST_RESULT && privilege_list == NULL) {
+ success_cnt++;
+ __color_to_green();
+ printf("success\n");
+ __color_to_origin();
+ } else {
+ fail_cnt++;
+ __color_to_red();
+ printf("failed. ret = %s\n", __get_result_string('d', ret));
+ __color_to_origin();
+ }
+ }
+
+ if (privilege_list != NULL) {
+ __print_glist(privilege_list);
+ g_list_free_full(privilege_list, free);
+ privilege_list = NULL;
+ }
+
+ __print_line();
+ printf("privilege = http://tizen.org/privilege/internet\n");
+ printf("not privacy\n");
+
+ ret = privilege_db_manager_get_same_privacy_grouped_privileges("http://tizen.org/privilege/internet", &privilege_list);
+ if (ret == PRIVILEGE_DB_MANAGER_ERR_NO_EXIST_RESULT && privilege_list == NULL) {
+ success_cnt++;
+ __color_to_green();
+ printf("success\n");
+ __color_to_origin();
+ } else {
+ fail_cnt++;
+ __color_to_red();
+ printf("failed. internet privilege is not privacy. ret = %s\n", __get_result_string('d', ret));
+ __color_to_origin();
+ }
+
+ if (privilege_list != NULL) {
+ __print_glist(privilege_list);
+ g_list_free_full(privilege_list, free);
+ privilege_list = NULL;
+ }
+ __print_line();
+ printf("privilege = http://tizen.org/privilege/internal/buxton/message.read\n");
+ printf("not privacy\n");
+
+ ret = privilege_db_manager_get_same_privacy_grouped_privileges("http://tizen.org/privilege/internal/buxton/message.read", &privilege_list);
+ if (ret == PRIVILEGE_DB_MANAGER_ERR_NO_EXIST_RESULT && privilege_list == NULL) {
+ success_cnt++;
+ __color_to_green();
+ printf("success\n");
+ __color_to_origin();
+ } else {
+ fail_cnt++;
+ __color_to_red();
+ printf("failed. internal/buxton/message.read privilege is not privacy. ret = %s\n", __get_result_string('d', ret));
+ __color_to_origin();
+ }
+
+ if (privilege_list != NULL) {
+ __print_glist(privilege_list);
+ g_list_free_full(privilege_list, free);
+ }
+}
+
int main()
{
__tcinfo(function, "privilege_db_manager_get_privilege_list");
__tcinfo(function, "privilege_db_manager_is_user_settable");
__test_privilege_db_manager_is_user_settable();
+ __tcinfo(function, "privilege_db_manager_get_same_privacy_grouped_privileges");
+ __test_privilege_db_manager_get_same_privacy_grouped_privileges();
+
__color_to_green();
printf("Test Complete\n");
printf("success : %d, ", success_cnt);
__print_line();
}
+void __test_privilege_info_get_same_privacy_grouped_privileges()
+{
+ int ret = 0;
+ GList *privilege_list = NULL;
+
+ __print_line();
+ printf("privilege = http://tizen.org/privilege/account.read\n");
+ ret = privilege_info_get_same_privacy_grouped_privileges("http://tizen.org/privilege/account.read", &privilege_list);
+
+ if (ENABLE_ASKUSER) {
+ printf("privacy = account\n");
+ if (ret == PRVMGR_ERR_NONE && privilege_list != NULL) {
+ success_cnt++;
+ __color_to_green();
+ printf("success\n");
+ __color_to_origin();
+ } else {
+ fail_cnt++;
+ __color_to_red();
+ printf("failed. ret = %s\n", __get_result_string('m', ret));
+ __color_to_origin();
+ }
+ } else {
+ printf("not privacy\n");
+ if (ret == PRVMGR_ERR_NONE && privilege_list == NULL) {
+ success_cnt++;
+ __color_to_green();
+ printf("success\n");
+ __color_to_origin();
+ } else {
+ fail_cnt++;
+ __color_to_red();
+ printf("failed. ret = %s\n", __get_result_string('m', ret));
+ __color_to_origin();
+ }
+ }
+
+ if (privilege_list != NULL) {
+ __print_glist(privilege_list);
+ g_list_free_full(privilege_list, free);
+ privilege_list = NULL;
+ }
+
+ __print_line();
+ printf("privilege = http://tizen.org/privilege/internet\n");
+ printf("not privacy\n");
+
+ ret = privilege_info_get_same_privacy_grouped_privileges("http://tizen.org/privilege/internet", &privilege_list);
+ if (ret == PRVMGR_ERR_NONE && privilege_list == NULL) {
+ success_cnt++;
+ __color_to_green();
+ printf("success\n");
+ __color_to_origin();
+ } else {
+ fail_cnt++;
+ __color_to_red();
+ printf("failed. internet privilege is not privacy. ret = %s\n", __get_result_string('m', ret));
+ __color_to_origin();
+ }
+
+ if (privilege_list != NULL) {
+ __print_glist(privilege_list);
+ g_list_free_full(privilege_list, free);
+ privilege_list = NULL;
+ }
+
+ __print_line();
+ printf("privilege = http://tizen.org/privilege/internal/buxton/message.read\n");
+ printf("not privacy\n");
+
+ ret = privilege_info_get_same_privacy_grouped_privileges("http://tizen.org/privilege/internal/buxton/message.read", &privilege_list);
+ if (ret == PRVMGR_ERR_NONE && privilege_list == NULL) {
+ success_cnt++;
+ __color_to_green();
+ printf("success\n");
+ __color_to_origin();
+ } else {
+ fail_cnt++;
+ __color_to_red();
+ printf("failed. internal/buxton/message.read privilege is not privacy. ret = %s\n", __get_result_string('m', ret));
+ __color_to_origin();
+ }
+
+ if (privilege_list != NULL) {
+ __print_glist(privilege_list);
+ g_list_free_full(privilege_list, free);
+ }
+}
+
int main()
{
__tcinfo(function, "privilege_info_is_privacy");
__tcinfo(function, "privilege_info_is_user_settable");
__test_privilege_info_is_user_settable();
+ __tcinfo(function, "privilege_info_get_same_privacy_grouped_privileges");
+ __test_privilege_info_get_same_privacy_grouped_privileges();
+
__color_to_green();
printf("Test Complete\n");
printf("success : %d, ", success_cnt);