4 * Copyright (c) 2010-2013 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 #include <sys/types.h>
25 #include <app_manager.h>
26 #include <cynara-client.h>
27 #include <cynara-session.h>
29 #include "location-common-util.h"
30 #include "location-types.h"
31 #include "location-log.h"
32 #include "location-privacy.h"
34 int location_check_cynara(const char *privilege_name)
36 cynara *cynara = NULL;
37 int ret = LOCATION_ERROR_NONE;
41 char smack_label[100] = {0, };
43 if (cynara_initialize(&cynara, NULL) != CYNARA_API_SUCCESS) {
44 LOCATION_LOGE("cynara initialize failed");
46 return LOCATION_ERROR_NOT_ALLOWED;
49 fp = fopen("/proc/self/attr/current", "r");
53 while (EOF != (ch = fgetc(fp))) {
54 smack_label[idx] = ch;
61 session = cynara_session_from_pid(pid);
62 snprintf(uid, 16, "%d", getuid());
63 ret = cynara_check(cynara, smack_label, session, uid, privilege_name);
69 cynara_finish(cynara);
71 LOC_COND_RET(ret != CYNARA_API_ACCESS_ALLOWED, LOCATION_ERROR_NOT_ALLOWED, _E, "Cynara_check failed [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
73 return LOCATION_ERROR_NONE;