4 * Copyright (c) 2010-2013 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Youngae Kang <youngae.kang@samsung.com>, Minjune Kim <sena06.kim@samsung.com>
7 * Genie Kim <daejins.kim@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
22 #include <sys/types.h>
28 #include <app_manager.h>
29 #include <cynara-client.h>
30 #include <cynara-session.h>
32 #include "location-common-util.h"
33 #include "location-types.h"
34 #include "location-log.h"
35 #include "location-privacy.h"
37 int location_check_cynara(const char *privilege_name)
39 cynara *cynara = NULL;
40 int ret = LOCATION_ERROR_NONE;
44 char smack_label[100] = "/proc/self/attr/current";
46 if (cynara_initialize(&cynara, NULL) != CYNARA_API_SUCCESS)
48 LOCATION_LOGE("cynara initialize failed");
50 return LOCATION_ERROR_NOT_ALLOWED;
53 fp = fopen("/proc/self/attr/current", "r");
55 if (fread(smack_label, 1, sizeof(smack_label), fp) <= 0) {
56 LOCATION_LOGE("fread failed");
62 session = cynara_session_from_pid(pid);
63 snprintf(uid, 16, "%d", getuid());
64 ret = cynara_check(cynara, smack_label, session, uid, privilege_name);
71 cynara_finish(cynara);
74 if (ret != CYNARA_API_ACCESS_ALLOWED) {
75 LOCATION_LOGE("cynara_check failed [%d]", ret);
76 return LOCATION_ERROR_NOT_ALLOWED;
79 return LOCATION_ERROR_NONE;