4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Seungtaek Chung <seungtaek.chung@samsung.com>, Mi-Ju Lee <miju52.lee@samsung.com>, Xi Zhichan <zhichan.xi@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
27 #include <notification.h>
28 #include <notification_db.h>
29 #include <notification_noti.h>
30 #include <notification_debug.h>
31 #include <notification_ipc.h>
32 #include <notification_private.h>
33 #include <notification_permission.h>
34 #include <cynara-client.h>
36 #define NOTIFICATION_DB_ACCESS_READ 0
37 #define NOTIFICATION_DB_ACCESS_WRITE 1
38 #define SMACK_LABEL_LEN 255
40 int notification_check_permission()
46 char subject_label[SMACK_LABEL_LEN + 1] = "";
48 char *client_session = "";
50 static bool checked_privilege = FALSE;
52 if (checked_privilege)
53 return NOTIFICATION_ERROR_NONE;
55 ret = cynara_initialize(&p_cynara, NULL);
56 if (ret != CYNARA_API_SUCCESS) {
57 LOGE("cannot init cynara [%d] failed!", ret);
58 ret = NOTIFICATION_ERROR_IO_ERROR;
62 fd = open("/proc/self/attr/current", O_RDONLY);
64 LOGE("open [%d] failed!", errno);
65 ret = NOTIFICATION_ERROR_IO_ERROR;
69 ret = read(fd, subject_label, SMACK_LABEL_LEN);
71 LOGE("read [%d] failed!", errno);
73 ret = NOTIFICATION_ERROR_IO_ERROR;
78 snprintf(uid, 10, "%d", getuid());
79 ret = cynara_check(p_cynara, subject_label, client_session, uid,
80 "http://tizen.org/privilege/notification");
81 if (ret != CYNARA_API_ACCESS_ALLOWED) {
82 LOGE("cynara access check [%d] failed!", ret);
83 ret = NOTIFICATION_ERROR_PERMISSION_DENIED;
86 ret = NOTIFICATION_ERROR_NONE;
87 checked_privilege = TRUE;
91 cynara_finish(p_cynara);