Fix boot-time smack rule loading
[platform/core/security/libprivilege-control.git] / include / rules-db.h
1 /*
2  * libprivilege control, rules database
3  *
4  * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved
5  *
6  * Contact: Jan Olszak <j.olszak@samsung.com>
7  *
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
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
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.
19  *
20  */
21
22
23 /*
24  * @file        rules-db.h
25  * @author      Jan Olszak (j.olszak@samsung.com)
26  * @version     1.0
27  * @brief       This file contains definition of rules database API.
28  */
29
30 #ifndef _RULES_DB_H_
31 #define _RULES_DB_H_
32
33 #include "privilege-control.h" // For error codes
34 #include "common.h"
35
36 #define RDB_PATH "/opt/dbspace/.rules-db.db3"
37
38 /**
39  * Starts a session with the database.
40  * Begins transaction.
41  *
42  * @ingroup RDB API functions
43  *
44  * @return  PC_OPERATION_SUCCESS on success,
45  *          error code otherwise
46  */
47 int rdb_modification_start(void);
48
49
50 /**
51  * Finishes the session with the database.
52  * Commits or rollbacks.
53  *
54  * @ingroup RDB API functions
55  * @return  PC_OPERATION_SUCCESS on success,
56  *          error code of the session otherwise
57  */
58 int rdb_modification_finish(void);
59
60
61 /**
62  * Rollbacks last transaction and finishes session
63  * with the database.
64  *
65  * @ingroup RDB API functions
66  * @return  PC_OPERATION_SUCCESS on success,
67  *          error code otherwise
68  */
69 int rdb_modification_rollback(void);
70
71
72 /**
73  * Add application label to the database.
74  * If label present: do nothing.
75  *
76  * @ingroup RDB API functions
77  *
78  * @param  s_label_name s_label_name application label
79  * @return              PC_OPERATION_SUCCESS on success,
80  *                      error code otherwise
81  */
82 int rdb_add_application(const char *const s_label_name);
83
84
85 /**
86  * Remove application label from the table.
87  * Used during uninstalling application.
88  *
89  * @ingroup RDB API functions
90  *
91  * @param  s_label_name application's label name
92  * @return              PC_OPERATION_SUCCESS on success,
93  *                      error code otherwise
94  */
95 int rdb_remove_application(const char *const s_label_name);
96
97
98 /**
99  * Add a path to the database.
100  *
101  * @ingroup RDB API functions
102  *
103  * @param  s_owner_label_name owner application's label name
104  * @param  s_path_label_name  path's label name
105  * @param  s_path             the path
106  * @param  s_access           owner to path label access rights
107  * @param  s_access_reverse   path label to owner access rights
108  * @param  s_type             type of path
109  * @return                    PC_OPERATION_SUCCESS on success,
110  *                            error code otherwise
111  */
112 int rdb_add_path(const char *const s_owner_label_name,
113                  const char *const s_path_label_name,
114                  const char *const s_path,
115                  const char *const s_access,
116                  const char *const s_access_reverse,
117                  const char *const s_type);
118
119
120 /**
121  * Add permission with the given name and type and add smack rules.
122  *
123  * @ingroup RDB API functions
124  *
125  * @param  s_permission_name      new permission's name
126  * @param  s_permission_type_name new permission's type
127  * @param  pp_smack_rules         a table of smack accesses to apply
128  * @return                        PC_OPERATION_SUCCESS on success,
129  *                                error code otherwise
130  */
131 int rdb_add_permission_rules(const char  *const s_permission_name,
132                              const char  *const s_permission_type_name,
133                              const char *const *const pp_smack_rules);
134
135
136 /**
137  * Enable permissions from the list.
138  * If there were no such permissions, we adds them.
139  * One can't change permissions from non volatile to volatile,
140  * One can change permissions from volatile to non volatile,
141  * but it's suspicious...
142  *
143  * @ingroup RDB API functions
144  *
145  * @param  s_app_label_name       application's label name
146  * @param  i_permission_type      permission's type id
147  * @param  pp_permissions_list    array of permissions to parse
148  * @param  b_is_volatile          are the new permissions volatile
149  * @return                        PC_OPERATION_SUCCESS on success,
150  *                                error code otherwise
151  */
152 int rdb_enable_app_permissions(const char  *const s_app_label_name,
153                                const app_type_t i_permission_type,
154                                const char *const *const pp_permissions_list,
155                                const bool b_is_volatile);
156
157
158 /**
159  * Disable permissions from the list.
160  *
161  * @ingroup RDB API functions
162  *
163  * @param  s_app_label_name       application's label name
164  * @param  i_permission_type      permission's type id
165  * @param  pp_permissions_list    array of permissions to parse
166  * @return                        PC_OPERATION_SUCCESS on success,
167  *                                error code otherwise
168  */
169 int rdb_disable_app_permissions(const char  *const s_app_label_name,
170                                 const app_type_t i_permission_type,
171                                 const char *const *const pp_permissions_list);
172
173
174 /**
175  * Revokes all permissions from the application by.
176  * deleting all permissions from app_permission table.
177  *
178  * @ingroup RDB API functions
179  *
180  * @param  s_app_label_name application's label name
181  * @return                  PC_OPERATION_SUCCESS on success,
182  *                          error code otherwise
183  */
184 int rdb_revoke_app_permissions(const char *const s_app_label_name);
185
186
187 /**
188  * Revokes all volatile permissions from the application by.
189  * deleting all permissions from app_permission table.
190  *
191  * @ingroup RDB API functions
192  *
193  * @param  s_app_label_name application's label name
194  * @return                  PC_OPERATION_SUCCESS on success,
195  *                          error code otherwise
196  */
197 int rdb_reset_app_permissions(const char *const s_app_label_name);
198
199
200 #endif /*_RULES_DB_H_*/