5 #include <tzplatform_config.h>
6 #include <security-manager.h>
7 #include <pkgmgr_parser.h>
11 #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
13 static const char *_get_path(const char *pkgid, const char *appid, uid_t uid)
18 /* TODO: unify application directory layout */
19 if (uid == OWNER_ROOT || uid == GLOBAL_USER)
20 snprintf(buf, BUFSIZE - 1, "%s", pkgid);
22 snprintf(buf, BUFSIZE - 1, "%s/%s", pkgid, appid);
24 tzplatform_set_user(uid);
25 path = tzplatform_mkpath((uid == OWNER_ROOT || uid == GLOBAL_USER) ?
26 TZ_SYS_RO_APP : TZ_USER_APP, buf);
27 tzplatform_reset_user();
32 static app_inst_req *_prepare_request(manifest_x *mfx, uid_t uid)
36 struct uiapplication_x *uiapp;
37 struct serviceapplication_x *svcapp;
39 if (security_manager_app_inst_req_new(&req)) {
40 printf("security_manager_app_inst_req_new failed\n");
44 security_manager_app_inst_req_set_pkg_id(req, mfx->package);
46 uiapp = mfx->uiapplication;
48 security_manager_app_inst_req_set_app_id(req, uiapp->appid);
49 path = _get_path(mfx->package, uiapp->appid, uid);
50 security_manager_app_inst_req_add_path(req, path,
51 SECURITY_MANAGER_PATH_PRIVATE);
55 svcapp = mfx->serviceapplication;
57 security_manager_app_inst_req_set_app_id(req, svcapp->appid);
58 path = _get_path(mfx->package, svcapp->appid, uid);
59 security_manager_app_inst_req_add_path(req, path,
60 SECURITY_MANAGER_PATH_PRIVATE);
61 svcapp = svcapp->next;
67 static int _insert_privilege(char *manifest, uid_t uid)
74 mfx = pkgmgr_parser_process_manifest_xml(manifest);
76 printf("Parse manifest failed\n");
80 req = _prepare_request(mfx, uid);
82 pkgmgr_parser_free_manifest_xml(mfx);
86 if (mfx->privileges != NULL) {
87 for (priv = mfx->privileges->privilege; priv; priv = priv->next)
88 security_manager_app_inst_req_add_privilege(req,
92 ret = security_manager_app_install(req);
93 if (ret != SECURITY_MANAGER_SUCCESS)
94 printf("security_manager_app_install failed: %d\n", ret);
96 security_manager_app_inst_req_free(req);
97 pkgmgr_parser_free_manifest_xml(mfx);
102 static int _remove_privilege(char *manifest, uid_t uid)
109 mfx = pkgmgr_parser_process_manifest_xml(manifest);
111 printf("Parse manifest failed\n");
115 req = _prepare_request(mfx, uid);
117 pkgmgr_parser_free_manifest_xml(mfx);
121 ret = security_manager_app_uninstall(req);
122 if (ret != SECURITY_MANAGER_SUCCESS)
123 printf("security_manager_app_uninstall failed: %d\n", ret);
125 security_manager_app_inst_req_free(req);
126 pkgmgr_parser_free_manifest_xml(mfx);
131 static void _print_usage(const char *cmd)
133 printf("usage: %s <option> <manifest>\n"
134 " -i \t\t install privilege\n"
135 " -u \t\t uninstall privilege\n", cmd);
138 int main(int argc, char **argv)
143 _print_usage(argv[0]);
147 if (!strcmp(argv[1], "-i")) {
148 ret = _insert_privilege(argv[2], getuid());
149 } else if (!strcmp(argv[1], "-u")) {
150 ret = _remove_privilege(argv[2], getuid());
152 _print_usage(argv[0]);