4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
22 #include <security-manager.h>
27 SECURITY_MANAGER_SUCCESS,
28 SECURITY_MANAGER_ERROR_INPUT_PARAM,
29 SECURITY_MANAGER_ERROR_MEMORY,
30 SECURITY_MANAGER_ERROR_REQ_NOT_COMPLETE,
31 SECURITY_MANAGER_ERROR_AUTHENTICATION_FAILED,
32 SECURITY_MANAGER_ERROR_ACCESS_DENIED
34 enum app_install_path_type {
35 SECURITY_MANAGER_PATH_PUBLIC_RO,
36 SECURITY_MANAGER_PATH_RO,
37 SECURITY_MANAGER_PATH_RW
39 typedef void app_inst_req;
41 #define security_manager_app_inst_req_free(r) \
42 (printf("security_manager_app_inst_req_free(%p)\n",r),(void)0)
44 #define security_manager_app_inst_req_new(pr) \
45 (*(pr)=(void*)(intptr_t)(++diese), printf("security_manager_app_inst_req_new(%p)\n",*pr), SECURITY_MANAGER_SUCCESS)
47 #define security_manager_app_inst_req_set_pkg_id(r,i) \
48 (printf("security_manager_app_inst_req_set_pkg_id(%p,\"%s\")\n",r,i), SECURITY_MANAGER_SUCCESS)
50 #define security_manager_app_inst_req_set_app_id(r,i) \
51 (printf("security_manager_app_inst_req_set_app_id(%p,\"%s\")\n",r,i), SECURITY_MANAGER_SUCCESS)
53 #define security_manager_app_inst_req_add_privilege(r,p) \
54 (printf("security_manager_app_inst_req_add_privilege(%p,\"%s\")\n",r,p), SECURITY_MANAGER_SUCCESS)
56 #define security_manager_app_inst_req_add_path(r,p,t) \
57 (printf("security_manager_app_inst_req_add_path(%p,\"%s\",%d)\n",r,p,t), SECURITY_MANAGER_SUCCESS)
59 #define security_manager_app_install(r) \
60 (printf("security_manager_app_install(%p)\n",r), SECURITY_MANAGER_SUCCESS)
64 #include "secmgr-wrap.h"
66 static app_inst_req *request = NULL;
68 static int retcode(enum lib_retcode rc)
71 case SECURITY_MANAGER_SUCCESS: return 0;
72 case SECURITY_MANAGER_ERROR_INPUT_PARAM: errno = EINVAL; break;
73 case SECURITY_MANAGER_ERROR_MEMORY: errno = ENOMEM; break;
74 case SECURITY_MANAGER_ERROR_REQ_NOT_COMPLETE: errno = EBADMSG; break;
75 case SECURITY_MANAGER_ERROR_AUTHENTICATION_FAILED: errno = EPERM; break;
76 case SECURITY_MANAGER_ERROR_ACCESS_DENIED: errno = EACCES; break;
77 default: errno = 0; break;
82 int secmgr_init(const char *pkgid, const char *appid)
85 assert(request == NULL);
86 rc = security_manager_app_inst_req_new(&request);
87 if (rc == SECURITY_MANAGER_SUCCESS) {
88 rc = security_manager_app_inst_req_set_pkg_id(request, pkgid);
89 if (rc == SECURITY_MANAGER_SUCCESS)
90 rc = security_manager_app_inst_req_set_app_id(request, appid);
92 if (rc != SECURITY_MANAGER_SUCCESS)
99 security_manager_app_inst_req_free(request);
106 assert(request != NULL);
107 rc = security_manager_app_install(request);
111 int secmgr_permit(const char *permission)
114 assert(request != NULL);
115 rc = security_manager_app_inst_req_add_privilege(request, permission);
119 static int addpath(const char *pathname, enum app_install_path_type type)
122 assert(request != NULL);
123 rc = security_manager_app_inst_req_add_path(request, pathname, type);
127 int secmgr_path_public_read_only(const char *pathname)
129 return addpath(pathname, SECURITY_MANAGER_PATH_PUBLIC_RO);
132 int secmgr_path_read_only(const char *pathname)
134 return addpath(pathname, SECURITY_MANAGER_PATH_RO);
137 int secmgr_path_read_write(const char *pathname)
139 return addpath(pathname, SECURITY_MANAGER_PATH_RW);