Tizen 2.1 base
[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 #ifndef _PRIVILEGE_CONTROL_H_
23 #define _PRIVILEGE_CONTROL_H_
24
25 /* Macros for converting preprocessor token to string */
26 #define STRINGIFY(x) #x
27 #define TOSTRING(x) STRINGIFY(x)
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif // __cplusplus
32
33 #ifndef API
34 #define API __attribute__((visibility("default")))
35 #endif // API
36
37 /* error codes */
38 #define PC_OPERATION_SUCCESS            ((int)0)
39 #define PC_ERR_FILE_OPERATION           -1
40 #define PC_ERR_MEM_OPERATION            -2
41 #define PC_ERR_NOT_PERMITTED            -3
42 #define PC_ERR_INVALID_PARAM            -4
43 #define PC_ERR_INVALID_OPERATION        -5
44
45 /* APIs - used by applications */
46 int control_privilege(void) __attribute__((deprecated));
47
48 int set_privilege(const char* pkg_name) __attribute__((deprecated));
49
50 /**
51  * Set DAC and SMACK privileges for application.
52  * This function is meant to be call by the application launcher just before
53  * it launches an application. It will setup DAC and SMACK privileges based
54  * on app type and accesses.
55  * It must be called with root privileges, which will be dropped in the function.
56  *
57  * @param name package name
58  * @param type application type (currently distinguished types: "wgt" and other)
59  * @param path file system path to the binary
60  * @return PC_OPERATION_SUCCESS on success, PC_ERR_* on error
61  */
62 int set_app_privilege(const char* name, const char* type, const char* path);
63
64 /* APIs for WRT */
65
66 /**
67 * Set DAC and SMACK privileges for web application.
68 * This is a specialized version of set_app_privilege() to be called by WRT
69 * when it is being launched from the console instead of AUL.
70 *
71 * @param widget_id widget identificator
72 * @return PC_OPERATION_SUCCESS on success, PC_ERR_* on error
73 */
74 int wrt_set_privilege(const char* widget_id);
75
76 /**
77  * Reset all SMACK permissions for a widget.
78  * This function should be called when previously granted permissions
79  * for a widget are no longer needed (e.g. after its termination or
80  * deinstallation).
81  * It must be called by privileged user.
82  *
83  * @param widget_id widget identifier from WRT
84  * @return PC_OPERATION_SUCCESS on success, PC_ERR_* on error
85  */
86 int wrt_permissions_reset(const char* widget_id);
87
88 /**
89  * Grant SMACK permissions required to use selected devcaps.
90  * This function should be called during preparation for widget run
91  * (after wrt_permissions_reset()) and whenever widget is supposed to
92  * gain any new devcap permissions.
93  * It must be called by privileged user.
94  *
95  * @param widget_id widget identifier from WRT
96  * @param devcap_list array of devcap names, last element must be NULL
97  * @return PC_OPERATION_SUCCESS on success, PC_ERR_* on error
98  */
99 int wrt_permissions_add(const char* widget_id, const char** devcap_list);
100
101 /**
102  * Recursively set SMACK labels for a widget source directory.
103  * This function should be called once during widget installation, after
104  * widget's source is unpacked in it's destination directory.
105  * Results will be persistent on the file system.
106  * It must be called by privileged user.
107  *
108  * @param widget_id widget identifier from WRT
109  * @param path parent directory path with widget's source
110  * @return PC_OPERATION_SUCCESS on success, PC_ERR_* on error
111  */
112 int wrt_set_src_dir(const char* widget_id, const char *path);
113
114 /**
115  * Recursively set SMACK labels for a widget data directory.
116  * This function should be called once during widget installation, after
117  * widget's initial data is unpacked in it's destination directory.
118  * Results will be persistent on the file system.
119  * It must be called by privileged user.
120  *
121  * @param widget_id widget identifier from WRT
122  * @param path parent directory path with widget's data
123  * @return PC_OPERATION_SUCCESS on success, PC_ERR_* on error
124  */
125 int wrt_set_data_dir(const char* widget_id, const char *path);
126
127 /**
128  * For a UNIX socket endpoint determine if the other side is a widget
129  * and return its widget id.
130  *
131  * @param sockfd socket file descriptor
132  * @return id of the connecting widget on success, NULL on failure.
133  * Caller is responsible for freeing the return widget id.
134  */
135 char* wrt_widget_id_from_socket(int sockfd);
136
137 /**
138  * Grant SMACK permissions based on permissions list.
139  * It is intended to be called during app installation.
140  * It will construct SMACK rules based on permissions list, grant them
141  * and store it in a file, so they will be automatically granted on
142  * system boot.
143  * It must be called by privileged user.
144  *
145  * @param app_id application identifier
146  * @param perm_list array of permission names, last element must be NULL
147  * @return PC_OPERATION_SUCCESS on success, PC_ERR_* on error
148  */
149 int app_add_permissions(const char* app_id, const char** perm_list);
150
151 /**
152  * Revoke SMACK permissions from an application.
153  * This function should be called during app deinstallation.
154  * It will revoke all SMACK rules previously granted by  app_add_permissions().
155  * It will also remove a rules file from disk.
156  * It must be called by privileged user.
157  *
158  * @param app_id application identifier
159  * @return PC_OPERATION_SUCCESS on success, PC_ERR_* on error
160  */
161 int app_revoke_permissions(const char* app_id);
162
163 /**
164  * Recursively set SMACK labels for an application directory.
165  * This function should be called once during app installation.
166  * Results will be persistent on the file system.
167  * It must be called by privileged user.
168  *
169  * @param app_id application identifier
170  * @param path directory path
171  * @return PC_OPERATION_SUCCESS on success, PC_ERR_* on error
172  */
173 int app_label_dir(const char* app_id, const char* path);
174
175
176 #ifdef __cplusplus
177 }
178 #endif // __cplusplus
179
180 #endif // _PRIVILEGE_CONTROL_H_