Add missing information about APP_PATH_ANY_LABEL in header
[platform/core/security/libprivilege-control.git] / include / privilege-control.h
1 /*
2  * libprivilege control
3  *
4  * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd All Rights Reserved
5  *
6  * Contact: Kidong Kim <kd0228.kim@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 #include <stdbool.h>
23 #include <sys/types.h>
24 #include <sys/smack.h>
25
26 #ifndef _PRIVILEGE_CONTROL_H_
27 #define _PRIVILEGE_CONTROL_H_
28
29 /* Macros for converting preprocessor token to string */
30 #define STRINGIFY(x) #x
31 #define TOSTRING(x) STRINGIFY(x)
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif // __cplusplus
36
37 #ifndef API
38 #define API __attribute__((visibility("default")))
39 #endif // API
40
41 #define DEPRECATED __attribute__((deprecated));
42
43 /* error codes */
44 #define PC_OPERATION_SUCCESS            ((int)0)
45 #define PC_ERR_FILE_OPERATION           -1
46 #define PC_ERR_MEM_OPERATION            -2
47 #define PC_ERR_NOT_PERMITTED            -3
48 #define PC_ERR_INVALID_PARAM            -4
49 #define PC_ERR_INVALID_OPERATION        -5
50 #define PC_ERR_DB_OPERATION                     -6
51
52 typedef enum {
53        APP_TYPE_WGT,
54        APP_TYPE_OSP,
55        APP_TYPE_OTHER,
56        APP_TYPE_WGT_PARTNER,
57        APP_TYPE_WGT_PLATFORM,
58        APP_TYPE_OSP_PARTNER,
59        APP_TYPE_OSP_PLATFORM,
60        APP_TYPE_EFL,
61 } app_type_t;
62
63 typedef enum {
64         APP_PATH_PRIVATE,
65         APP_PATH_GROUP_RW,
66         APP_PATH_PUBLIC_RO,
67         APP_PATH_SETTINGS_RW,
68         APP_PATH_ANY_LABEL,
69 } app_path_type_t;
70
71 /* APIs - used by applications */
72 int control_privilege(void) DEPRECATED;
73
74 int set_privilege(const char* pkg_name) DEPRECATED;
75
76 /**
77  * Function getting process smack label based on pid.
78  * @param in:  pid of process
79  * @param out: label of process
80  * @return PC_OPERATION_SUCCESS on success PC_ERR_* on error.
81  */
82 int get_smack_label_from_process(pid_t pid, char smack_label[SMACK_LABEL_LEN + 1]);
83
84 /**
85  * Check if process with pid has access to object.
86  * This function checks if subject has access to object via smack_have_access() function.
87  * If YES then returns access granted. In NO then function checks if process with pid has
88  * CAP_MAC_OVERRIDE capability. If YES then returns access granted.
89  * If NO then returns access denied.
90  *
91  * @param pid of process
92  * @param label of object to access
93  * @param access_type
94  * @return 0 (no access) or 1 (access) or -1 (error)
95  */
96 int smack_pid_have_access(pid_t pid,
97                                                         const char* object,
98                                                         const char *access_type);
99
100 /**
101  * Set DAC and SMACK privileges for application.
102  * This function is meant to be called by the application launcher just before
103  * it launches an application. It will setup DAC and SMACK privileges based
104  * on app type and accesses.
105  * It must be called with root privileges, which will be dropped in the function.
106  *
107  * @param name package name
108  * @param type application type (currently distinguished types: "wgt", "wgt_partner", "wgt_platform" and other)
109  * @param path file system path to the binary
110  * @return PC_OPERATION_SUCCESS on success, PC_ERR_* on error
111  */
112 int perm_app_set_privilege(const char* name, const char* type, const char* path);
113 int set_app_privilege(const char* name, const char* type, const char* path) DEPRECATED;
114
115 /**
116  * For a UNIX socket endpoint determine the other side's pkg_id.
117  *
118  * @param sockfd socket file descriptor
119  * @return id of the connecting widget on success, NULL on failure.
120  * Caller is responsible for freeing the return widget id.
121  */
122 char* perm_app_id_from_socket(int sockfd);
123 char* app_id_from_socket(int sockfd) DEPRECATED;
124
125 /**
126  * Inform about installation of a new app.
127  * It is intended to be called during app installation.
128  * It will create an empty SMACK rules file used by other functions operating
129  * on permissions if it doesn't already exist. It is needed for tracking
130  * lifetime of an app. It must be called by privileged user, before using any
131  * other app_* function. It may be called more than once during installation.
132  *
133  *
134  * @param pkg_id application identifier
135  * @return PC_OPERATION_SUCCESS on success, PC_ERR_* on error
136  */
137 int perm_app_install(const char* pkg_id);
138 int app_install(const char* pkg_id) DEPRECATED;
139
140 /**
141  * Inform about deinstallation of an app.
142  * It will remove the SMACK rules file, enabling future installation of app
143  * with the same identifier. It is needed for tracking lifetime of an app.
144  * You should call app_revoke_permissions() before this function.
145  * It must be called by privileged user.
146  *
147  *
148  * @param pkg_id application identifier
149  * @return PC_OPERATION_SUCCESS on success, PC_ERR_* on error
150  */
151 int perm_app_uninstall(const char* pkg_id);
152 int app_uninstall(const char* pkg_id) DEPRECATED;
153
154 /**
155  * Inform about installation of new Anti Virus application.
156  * It is intended to be called during Anti Virus installation.
157  * It will give this application SMACK rules to RWX access to all other apps
158  * installed in system.
159  * It must be called by privileged user.
160  *
161  * @param app_id application identifier
162  * @return PC_OPERATION_SUCCESS on success, PC_ERR_* on error.
163  */
164 int app_register_av(const char* app_av_id) DEPRECATED;
165
166 /**
167  * Grant SMACK permissions based on permissions list.
168  * It is intended to be called during app installation.
169  * It will construct SMACK rules based on permissions list, grant them
170  * and store it in a file, so they will be automatically granted on
171  * system boot.
172  * It must be called by privileged user.
173  * THIS FUNCTION IS NOW DEPRECATED. app_enable_permissions() SHOULD BE USED INSTEAD.
174  *
175  *
176  * @param app_id application identifier
177  * @param perm_list array of permission names, last element must be NULL
178  * @return PC_OPERATION_SUCCESS on success, PC_ERR_* on error
179  */
180 int app_add_permissions(const char* app_id, const char** perm_list) DEPRECATED;
181
182 /**
183  * Grant temporary SMACK permissions based on permissions list.
184  * It will construct SMACK rules based on permissions list, grant them,
185  * but not store it anywhere, so they won't be granted again on system boot.
186  * It must be called by privileged user.
187  * THIS FUNCTION IS NOW DEPRECATED. app_enable_permissions() SHOULD BE USED INSTEAD.
188  *
189  *
190  * @param app_id application identifier
191  * @param perm_list array of permission names, last element must be NULL
192  * @return PC_OPERATION_SUCCESS on success, PC_ERR_* on error
193  */
194 int app_add_volatile_permissions(const char* app_id, const char** perm_list) DEPRECATED;
195
196 /**
197  * Grant SMACK permissions based on permissions list.
198  * It is intended to be called during app installation.
199  * It will construct SMACK rules based on permissions list, grant them
200  * and store it in a file, so they will be automatically granted on
201  * system boot, when persistent mode is enabled.
202  * It must be called by privileged user.
203  *
204  *
205  * @param pkg_id application identifier
206  * @param app_type application type
207  * @param perm_list array of permission names, last element must be NULL
208  * @param persistent boolean for choosing between persistent and temporary rules
209  * @return PC_OPERATION_SUCCESS on success, PC_ERR_* on error
210  */
211 int perm_app_enable_permissions(const char* pkg_id, app_type_t app_type, const char** perm_list, bool persistent);
212 int app_enable_permissions(const char* pkg_id, app_type_t app_type, const char** perm_list, bool persistent) DEPRECATED;
213
214 /**
215  * Remove previously granted SMACK permissions based on permissions list.
216  * It will remove given permissions from an app, leaving other granted
217  * permissions untouched. Results will be persistent.
218  * It must be called by privileged user.
219  *
220  *
221  * @param pkg_id application identifier
222  * @param app_type application type
223  * @param perm_list array of permission names, last element must be NULL
224  * @return PC_OPERATION_SUCCESS on success, PC_ERR_* on error
225  */
226 int perm_app_disable_permissions(const char* pkg_id, app_type_t app_type, const char** perm_list);
227 int app_disable_permissions(const char* pkg_id, app_type_t app_type, const char** perm_list) DEPRECATED;
228
229 /**
230  * Revoke SMACK permissions from an application.
231  * This function should be called during app deinstallation.
232  * It will revoke all SMACK rules previously granted by app_add_permissions().
233  * It must be called by privileged user.
234  *
235  * @param pkg_id application identifier
236  * @return PC_OPERATION_SUCCESS on success, PC_ERR_* on error
237  */
238 int perm_app_revoke_permissions(const char* pkg_id);
239 int app_revoke_permissions(const char* pkg_id) DEPRECATED;
240
241 /**
242  * Reset SMACK permissions for an application by revoking all previously
243  * granted rules and enabling them again from a rules file from disk.
244  * It must be called by privileged user.
245  *
246  * @param pkg_id application identifier
247  * @return PC_OPERATION_SUCCESS on success, PC_ERR_* on error
248  */
249 int perm_app_reset_permissions(const char* pkg_id);
250 int app_reset_permissions(const char* pkg_id) DEPRECATED;
251
252 /**
253  * Recursively set SMACK access labels for an application directory
254  * and execute labels for executable files.
255  * This function should be called once during app installation.
256  * Results will be persistent on the file system.
257  * It must be called by privileged user.
258  * THIS FUNCTION IS NOW DEPRECATED. perm_app_setup_path() SHOULD BE USED INSTEAD.
259  *
260  * @param app_label label name
261  * @param path directory path
262  * @return PC_OPERATION_SUCCESS on success, PC_ERR_* on error
263  */
264 int app_label_dir(const char* app_label, const char* path) DEPRECATED;
265
266 /**
267  * Recursively set SMACK access and transmute labels for an application
268  * directory and add SMACK rule for application.
269  * This function should be called once during app installation.
270  * Results will be persistent on the file system.
271  * It must be called by privileged user.
272  * Labels app_label and shared_label should not be equal.
273  * THIS FUNCTION IS NOW DEPRECATED. app_setup_path() SHOULD BE USED INSTEAD.
274  *
275  * @param app_label label name, used as subject for SMACK rule
276  * @param shared_label, used as object for SMACK rule
277  * @param path directory path
278  * @return PC_OPERATION_SUCCESS on success, PC_ERR_* on error
279  */
280 int app_label_shared_dir(const char* app_label, const char* shared_label,
281                                                  const char* path) DEPRECATED;
282
283 /**
284  * Add SMACK rx rules for application identifiers to shared_label.
285  * This function should be called during app installation.
286  * It must be called by privileged user.
287  * THIS FUNCTION IS NOW DEPRECATED. NO REPLACEMENT IS NEEDED.
288  *
289  * @param shared_label label of the shared resource
290  * @param app_list list of application SMACK identifiers
291  * @return PC_OPERATION_SUCCESS on success, PC_ERR_* on error
292  */
293 int add_shared_dir_readers(const char* shared_label, const char** app_list) DEPRECATED;
294
295 /**
296  * Recursively set SMACK labels for an application directory. The exact behavior
297  * depends on app_path_type argument:
298  *      - APP_PATH_PRIVATE: label with app's label, set access label on everything
299  *    and execute label on executable files and symlinks to executable files
300  *
301  *      - APP_PATH_GROUP_RW: label with given shared_label, set access label on
302  *        everything and enable transmute on directories. Also give pkg_id full access
303  *        to the shared label.
304  *
305  *      - APP_PATH_PUBLIC_RO: label with autogenerated label, set access label on
306  *        everything and enable transmute on directories. Give full access to the label to
307  *        pkg_id and RX access to all other apps.
308  *
309  *      - APP_PATH_SETTINGS_RW: label with autogenerated label, set access label on
310  *        everything and enable transmute on directories. Give full access to the label to
311  *        pkg_id and RWX access to all appsetting apps.
312  *
313  *      - APP_PATH_ANY_LABEL: label with given shared_label. Set access label on
314  *        everything and execute label on executable files and symlinks to
315  *        executable files.
316  *
317  * This function should be called during app installation.
318  * Results will be persistent on the file system.
319  * It must be called by privileged user.
320  *
321  * @param pkg_id
322  * @param path
323  * @param app_path_type
324  * @param shared_label (optional argument for APP_PATH_GROUP_RW and
325  *        APP_PATH_ANY_LABEL path type; type is const char*)
326  * @return PC_OPERATION_SUCCESS on success, PC_ERR_* on error
327  */
328 int perm_app_setup_path(const char* pkg_id, const char* path, app_path_type_t app_path_type, ...);
329 int app_setup_path(const char* pkg_id, const char* path, app_path_type_t app_path_type, ...) DEPRECATED;
330
331
332 /**
333  * Make two applications "friends", by giving them both full permissions on
334  * each other.
335  * Results will be persistent on the file system. Must be called after
336  * app_add_permissions() has been called for each application.
337  * It must be called by privileged user.
338  *
339  * @param pkg_id1 first application identifier
340  * @param pkg_id2 second application identifier
341  * @return PC_OPERATION_SUCCESS on success, PC_ERR_* on error
342  */
343 int perm_app_add_friend(const char* pkg_id1, const char* pkg_id2);
344 int app_add_friend(const char* pkg_id1, const char* pkg_id2) DEPRECATED;
345
346 /**
347  * Adds new api feature by installing new *.smack file.
348  * It must be called by privileged user.
349  *
350  * @param app_type application type
351  * @param api_feature_name name of newly added feature
352  * @param smack_rule_set set of rules required by the feature - NULL terminated
353  * list of NULL terminated rules.
354  * @param list_of_db_gids list of gids required to access databases controlled
355  * by the feature
356  * @return PC_OPERATION_SUCCESS on success, PC_ERR_* on error
357  */
358 int perm_add_api_feature(app_type_t app_type,
359                                         const char* api_feature_name,
360                                         const char** set_smack_rule_set,
361                                         const gid_t* list_of_db_gids,
362                                         size_t list_size);
363 int add_api_feature(app_type_t app_type,
364                     const char* api_feature_name,
365                     const char** set_smack_rule_set,
366                     const gid_t* list_of_db_gids,
367                     size_t list_size) DEPRECATED;
368
369 #ifdef __cplusplus
370 }
371 #endif // __cplusplus
372
373 #endif // _PRIVILEGE_CONTROL_H_