4 * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd All Rights Reserved
6 * Contact: Kidong Kim <kd0228.kim@samsung.com>
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #ifndef _PRIVILEGE_CONTROL_H_
23 #define _PRIVILEGE_CONTROL_H_
25 /* Macros for converting preprocessor token to string */
26 #define STRINGIFY(x) #x
27 #define TOSTRING(x) STRINGIFY(x)
34 #define API __attribute__((visibility("default")))
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
45 /* APIs - used by applications */
46 int control_privilege(void) __attribute__((deprecated));
48 int set_privilege(const char* pkg_name) __attribute__((deprecated));
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.
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
62 int set_app_privilege(const char* name, const char* type, const char* path);
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.
71 * @param widget_id widget identificator
72 * @return PC_OPERATION_SUCCESS on success, PC_ERR_* on error
74 int wrt_set_privilege(const char* widget_id);
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
81 * It must be called by privileged user.
83 * @param widget_id widget identifier from WRT
84 * @return PC_OPERATION_SUCCESS on success, PC_ERR_* on error
86 int wrt_permissions_reset(const char* widget_id);
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.
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
99 int wrt_permissions_add(const char* widget_id, const char** devcap_list);
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.
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
112 int wrt_set_src_dir(const char* widget_id, const char *path);
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.
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
125 int wrt_set_data_dir(const char* widget_id, const char *path);
128 * For a UNIX socket endpoint determine if the other side is a widget
129 * and return its widget id.
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.
135 char* wrt_widget_id_from_socket(int sockfd);
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
143 * It must be called by privileged user.
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
149 int app_add_permissions(const char* app_id, const char** perm_list);
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.
158 * @param app_id application identifier
159 * @return PC_OPERATION_SUCCESS on success, PC_ERR_* on error
161 int app_revoke_permissions(const char* app_id);
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.
169 * @param app_id application identifier
170 * @param path directory path
171 * @return PC_OPERATION_SUCCESS on success, PC_ERR_* on error
173 int app_label_dir(const char* app_id, const char* path);
178 #endif // __cplusplus
180 #endif // _PRIVILEGE_CONTROL_H_