removed wrong contacts, added authors
[platform/core/location/lbs-location.git] / location / manager / location-privacy.c
1 /*
2  * libslp-location
3  *
4  * Copyright (c) 2010-2013 Samsung Electronics Co., Ltd. All rights reserved.
5  *
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
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  */
18
19 #include <sys/types.h>
20 #include <unistd.h>
21 #include <glib.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24
25 #include <app_manager.h>
26 #include <cynara-client.h>
27 #include <cynara-session.h>
28
29 #include "location-common-util.h"
30 #include "location-types.h"
31 #include "location-log.h"
32 #include "location-privacy.h"
33
34 int location_check_cynara(const char *privilege_name)
35 {
36         cynara *cynara = NULL;
37         int ret = LOCATION_ERROR_NONE;
38         FILE *fp = NULL;
39         char uid[16];
40         char *session = NULL;
41         char smack_label[100] = {0, };
42
43         if (cynara_initialize(&cynara, NULL) != CYNARA_API_SUCCESS) {
44                 LOCATION_LOGE("cynara initialize failed");
45                 cynara = NULL;
46                 return LOCATION_ERROR_NOT_ALLOWED;
47         }
48
49         fp = fopen("/proc/self/attr/current", "r");
50         if (fp != NULL) {
51                 int ch = 0;
52                 int idx = 0;
53                 while (EOF != (ch = fgetc(fp))) {
54                         smack_label[idx] = ch;
55                         idx++;
56                 }
57                 fclose(fp);
58         }
59
60         pid_t pid = getpid();
61         session = cynara_session_from_pid(pid);
62         snprintf(uid, 16, "%d", getuid());
63         ret = cynara_check(cynara, smack_label, session, uid, privilege_name);
64
65         if (session)
66                 free(session);
67
68         if (cynara)
69                 cynara_finish(cynara);
70
71         LOC_COND_RET(ret != CYNARA_API_ACCESS_ALLOWED, LOCATION_ERROR_NOT_ALLOWED, _E, "Cynara_check failed [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
72
73         return LOCATION_ERROR_NONE;
74 }