Update source from tizen 2.3
[platform/core/base/rpm-installer.git] / backend / src / rpm / rpm-installer-privilege.c
1 /*
2  * rpm-installer
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
7  * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
8  *
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
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
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.
20  *
21  */
22
23 #ifndef _GNU_SOURCE
24 #define _GNU_SOURCE
25 #endif
26 #define __USE_GNU
27 #include <unistd.h>
28 #include <stdio.h>
29 #include <errno.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <privilege-control.h>
33 #include "sys/smack.h"
34
35 #include "rpm-installer.h"
36
37
38
39 static int __ri_privilege_perm_begin(void)
40 {
41         int ret = 0;
42
43         ret = perm_begin();
44         _LOGD("[smack] perm_begin, result=[%d]",ret);
45
46         return ret;
47 }
48
49 static int __ri_privilege_perm_end(void)
50 {
51         int ret = 0;
52
53         ret = perm_end();
54         _LOGD("[smack] perm_end, result=[%d]",ret);
55
56         return ret;
57 }
58
59 int _ri_privilege_register_package(const char *pkgid)
60 {
61         int ret = 0;
62
63         ret = perm_app_install(pkgid);
64         _LOGD("[smack] app_install(%s), result=[%d]", pkgid, ret);
65
66         return ret;
67 }
68
69 int _ri_privilege_unregister_package(const char *pkgid)
70 {
71         int ret = 0;
72
73         ret = perm_app_uninstall(pkgid);
74         _LOGD("[smack] app_uninstall(%s), result=[%d]", pkgid, ret);
75
76         return ret;
77 }
78
79 int _ri_privilege_revoke_permissions(const char *pkgid)
80 {
81         int ret = 0;
82
83         ret = perm_app_revoke_permissions(pkgid);
84         _LOGD("[smack] app_revoke_permissions(%s), result=[%d]", pkgid, ret);
85
86         return ret;
87 }
88
89 int _ri_privilege_enable_permissions(const char *pkgid, int apptype,
90                                                 const char **perms, int persistent)
91 {
92         int ret = 0;
93
94         __ri_privilege_perm_begin();
95
96         ret = perm_app_enable_permissions(pkgid, apptype, perms, persistent);
97         _LOGD("[smack] app_enable_permissions(%s, %d), result=[%d]", pkgid, apptype, ret);
98
99         __ri_privilege_perm_end();
100
101         return ret;
102 }
103
104 int _ri_privilege_setup_path(const char *pkgid, const char *dirpath, int apppathtype, const char *groupid)
105 {
106         int ret = 0;
107
108         if (groupid == NULL) {
109                 ret = perm_app_setup_path(pkgid, dirpath, apppathtype);
110                 _LOGD("[smack] app_setup_path(%s, %s, %d), result=[%d]", pkgid, dirpath, apppathtype, ret);
111         } else {
112                 ret = perm_app_setup_path(pkgid, dirpath, apppathtype, groupid);
113                 _LOGD("[smack] app_setup_path(%s, %s, %d, %s), result=[%d]", pkgid, dirpath, apppathtype, groupid, ret);
114         }
115
116         return ret;
117 }
118
119 int _ri_privilege_add_friend(const char *pkgid1, const char *pkgid2)
120 {
121         int ret = 0;
122
123         ret = perm_app_add_friend(pkgid1, pkgid2);
124         _LOGD("[smack] app_add_friend(%s, %s), result=[%d]", pkgid1, pkgid2, ret);
125
126         return ret;
127 }
128
129 int _ri_privilege_change_smack_label(const char *path, const char *label,
130                                                 int label_type)
131 {
132         if (path == NULL || label == NULL)
133                 return -1;
134         int ret = 0;
135
136         ret = smack_lsetlabel(path, label, label_type);
137         _LOGD("[smack] smack_lsetlabel(%s, %s, %d), result=[%d]", path, label, label_type, ret);
138
139         return ret;
140 }