Add privilege uninstall at pkg_privilege 96/42596/3
authorSangyoon Jang <s89.jang@samsung.com>
Tue, 30 Jun 2015 11:37:58 +0000 (20:37 +0900)
committerSangyoon Jang <s89.jang@samsung.com>
Tue, 30 Jun 2015 11:46:50 +0000 (20:46 +0900)
Change-Id: I7d060f6964567e357ca3279afb32c8eb4bcdcdbe
Signed-off-by: Sangyoon Jang <s89.jang@samsung.com>
tool/pkg_initdb.c
tool/pkg_privilege.c

index 2b586c5..568233f 100644 (file)
@@ -194,7 +194,7 @@ static int initdb_install_manifest(void)
 
 static int initdb_install_privilege(void)
 {
-       return __initdb_load_directory(SYS_MANIFEST_DIRECTORY, "/usr/bin/pkg_privilege");
+       return __initdb_load_directory(SYS_MANIFEST_DIRECTORY, "/usr/bin/pkg_privilege -i");
 }
 
 static int initdb_change_perm(const char *db_file)
index e6d7030..44ec833 100644 (file)
@@ -10,7 +10,7 @@
 #define OWNER_ROOT 0
 #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
 
-static const char *__get_path(const char *pkgid, const char *appid, uid_t uid)
+static const char *_get_path(const char *pkgid, const char *appid, uid_t uid)
 {
        char buf[BUFSIZE];
        const char *path;
@@ -29,26 +29,16 @@ static const char *__get_path(const char *pkgid, const char *appid, uid_t uid)
        return path;
 }
 
-static int __insert_privilege(char *manifest, uid_t uid)
+static app_inst_req *_prepare_request(manifest_x *mfx, uid_t uid)
 {
-       int ret;
-       manifest_x *mfx;
+       app_inst_req *req;
+       char *path;
        struct uiapplication_x *uiapp;
        struct serviceapplication_x *svcapp;
-       char *path;
-
-       privilege_x *priv;
-       app_inst_req *req;
 
-       mfx = pkgmgr_parser_process_manifest_xml(manifest);
-       if (mfx == NULL) {
-               printf("Parse manifest failed\n");
-               return -1;
-       }
        if (security_manager_app_inst_req_new(&req)) {
                printf("security_manager_app_inst_req_new failed\n");
-               pkgmgr_parser_free_manifest_xml(mfx);
-               return -1;
+               return NULL;
        }
 
        security_manager_app_inst_req_set_pkg_id(req, mfx->package);
@@ -56,7 +46,7 @@ static int __insert_privilege(char *manifest, uid_t uid)
        uiapp = mfx->uiapplication;
        while (uiapp) {
                security_manager_app_inst_req_set_app_id(req, uiapp->appid);
-               path = __get_path(mfx->package, uiapp->appid, uid);
+               path = _get_path(mfx->package, uiapp->appid, uid);
                security_manager_app_inst_req_add_path(req, path,
                                SECURITY_MANAGER_PATH_PRIVATE);
                uiapp = uiapp->next;
@@ -65,12 +55,34 @@ static int __insert_privilege(char *manifest, uid_t uid)
        svcapp = mfx->serviceapplication;
        while (svcapp) {
                security_manager_app_inst_req_set_app_id(req, svcapp->appid);
-               path = __get_path(mfx->package, svcapp->appid, uid);
+               path = _get_path(mfx->package, svcapp->appid, uid);
                security_manager_app_inst_req_add_path(req, path,
                                SECURITY_MANAGER_PATH_PRIVATE);
                svcapp = svcapp->next;
        }
 
+       return req;
+}
+
+static int _insert_privilege(char *manifest, uid_t uid)
+{
+       int ret;
+       app_inst_req *req;
+       manifest_x *mfx;
+       privilege_x *priv;
+
+       mfx = pkgmgr_parser_process_manifest_xml(manifest);
+       if (mfx == NULL) {
+               printf("Parse manifest failed\n");
+               return -1;
+       }
+
+       req = _prepare_request(mfx, uid);
+       if (req == NULL) {
+               pkgmgr_parser_free_manifest_xml(mfx);
+               return -1;
+       }
+
        if (mfx->privileges != NULL) {
                for (priv = mfx->privileges->privilege; priv; priv = priv->next)
                        security_manager_app_inst_req_add_privilege(req,
@@ -87,12 +99,59 @@ static int __insert_privilege(char *manifest, uid_t uid)
        return 0;
 }
 
+static int _remove_privilege(char *manifest, uid_t uid)
+{
+       int ret;
+       app_inst_req *req;
+       manifest_x *mfx;
+       privilege_x *priv;
+
+       mfx = pkgmgr_parser_process_manifest_xml(manifest);
+       if (mfx == NULL) {
+               printf("Parse manifest failed\n");
+               return -1;
+       }
+
+       req = _prepare_request(mfx, uid);
+       if (req == NULL) {
+               pkgmgr_parser_free_manifest_xml(mfx);
+               return -1;
+       }
+
+       ret = security_manager_app_uninstall(req);
+       if (ret != SECURITY_MANAGER_SUCCESS)
+               printf("security_manager_app_uninstall failed: %d\n", ret);
+
+       security_manager_app_inst_req_free(req);
+       pkgmgr_parser_free_manifest_xml(mfx);
+
+       return 0;
+}
+
+static void _print_usage(const char *cmd)
+{
+       printf("usage: %s <option> <manifest>\n"
+              "   -i \t\t install privilege\n"
+              "   -u \t\t uninstall privilege\n", cmd);
+}
+
 int main(int argc, char **argv)
 {
-       if (argc < 2) {
-               printf("missing operand\n");
+       int ret;
+
+       if (argc < 3) {
+               _print_usage(argv[0]);
                return -1;
        }
 
-       return __insert_privilege(argv[1], getuid());
+       if (!strcmp(argv[1], "-i")) {
+               ret = _insert_privilege(argv[2], getuid());
+       } else if (!strcmp(argv[1], "-u")) {
+               ret = _remove_privilege(argv[2], getuid());
+       } else {
+               _print_usage(argv[0]);
+               ret = -1;
+       }
+
+       return ret;
 }