From cebe4102e050ddfef760cc9390323af533c8c8e4 Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Mon, 1 Feb 2016 11:54:52 +0900 Subject: [PATCH] Add blacklist commands add blacklist commands use macro for opt value instead of constants Change-Id: Ic09994716c7464084cc59d8f441c6ecc4075425e Signed-off-by: Sangyoon Jang --- src/pkg_cmd.c | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 110 insertions(+), 3 deletions(-) diff --git a/src/pkg_cmd.c b/src/pkg_cmd.c index 6fa9e1a..9f451ee 100644 --- a/src/pkg_cmd.c +++ b/src/pkg_cmd.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -51,6 +52,11 @@ #define OWNER_ROOT 0 #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER) +#define OPTVAL_GLOBAL 1000 +#define OPTVAL_ADD_BLACKLIST 1001 +#define OPTVAL_REMOVE_BLACKLIST 1002 +#define OPTVAL_CHECK_BLACKLIST 1003 + static int __process_request(uid_t uid); static void __print_usage(); static int __is_app_installed(char *pkgid, uid_t uid); @@ -89,9 +95,12 @@ const struct option long_options[] = { {"csc", 1, NULL, 'S'}, {"tep-path", 1, NULL, 'e'}, {"tep-move", 1, NULL, 'M'}, - {"global", 0, NULL, 1000}, + {"global", 0, NULL, OPTVAL_GLOBAL}, {"quiet", 0, NULL, 'q'}, {"help", 0, NULL, 'h'}, + {"add-blacklist", 1, NULL, OPTVAL_ADD_BLACKLIST}, + {"remove-blacklist", 1, NULL, OPTVAL_REMOVE_BLACKLIST}, + {"check-blacklist", 1, NULL, OPTVAL_CHECK_BLACKLIST}, {0, 0, 0, 0} /* sentinel */ }; @@ -111,7 +120,10 @@ enum pm_tool_request_e { LIST_REQ, SHOW_REQ, HELP_REQ, - CREATE_DELTA + CREATE_DELTA, + ADD_BLACKLIST_REQ, + REMOVE_BLACKLIST_REQ, + CHECK_BLACKLIST_REQ, }; typedef enum pm_tool_request_e req_type; @@ -409,6 +421,9 @@ static void __print_usage() printf("--global Global Mode [Warning user should be privilegied to use this mode] \n"); printf("-e, --tep-path provide TEP package path\n"); printf("-M, --tep-move decide move/copy of TEP package[0:copy TEP package /1 : move TEP package, \n"); + printf("--add-blacklist add a package to blacklist\n"); + printf("--remove-blacklist remove a package from blacklist\n"); + printf("--check-blacklist check if the given package is blacklisted\n"); printf("-h, --help . print this help\n\n"); printf("Usage: pkgcmd [options]\n"); @@ -512,6 +527,7 @@ static int __process_request(uid_t uid) int pid = -1; char pkg_old[PATH_MAX] = {0, }; char pkg_new[PATH_MAX] = {0, }; + bool blacklist; #if !GLIB_CHECK_VERSION(2,35,0) g_type_init(); @@ -941,6 +957,76 @@ static int __process_request(uid_t uid) ret = 0; break; + case ADD_BLACKLIST_REQ: + if (data.pkgid[0] == '\0') { + printf("Please provide the arguments.\n"); + printf("use -h option to see usage\n"); + ret = -1; + break; + } + pc = pkgmgr_client_new(PC_REQUEST); + if (pc == NULL) { + printf("PkgMgr Client Creation Failed\n"); + data.result = PKGCMD_ERRCODE_ERROR; + break; + } + ret = pkgmgr_client_usr_add_blacklist(pc, data.pkgid, uid); + if (ret < 0) { + data.result = PKGCMD_ERRCODE_ERROR; + break; + } + + printf("%d\n", ret); + ret = data.result; + break; + case REMOVE_BLACKLIST_REQ: + if (data.pkgid[0] == '\0') { + printf("Please provide the arguments.\n"); + printf("use -h option to see usage\n"); + ret = -1; + break; + } + pc = pkgmgr_client_new(PC_REQUEST); + if (pc == NULL) { + printf("PkgMgr Client Creation Failed\n"); + data.result = PKGCMD_ERRCODE_ERROR; + break; + } + ret = pkgmgr_client_usr_remove_blacklist(pc, data.pkgid, uid); + if (ret < 0) { + data.result = PKGCMD_ERRCODE_ERROR; + break; + } + + printf("%d\n", ret); + ret = data.result; + break; + case CHECK_BLACKLIST_REQ: + if (data.pkgid[0] == '\0') { + printf("Please provide the arguments.\n"); + printf("use -h option to see usage\n"); + ret = -1; + break; + } + pc = pkgmgr_client_new(PC_REQUEST); + if (pc == NULL) { + printf("PkgMgr Client Creation Failed\n"); + data.result = PKGCMD_ERRCODE_ERROR; + break; + } + ret = pkgmgr_client_usr_check_blacklist(pc, data.pkgid, &blacklist, uid); + if (ret < 0) { + data.result = PKGCMD_ERRCODE_ERROR; + break; + } + + if (blacklist) + printf("%s is blacklisted\n", data.pkgid); + else + printf("%s is not blacklisted\n", data.pkgid); + ret = data.result; + break; + default: printf("Wrong Request\n"); ret = -1; @@ -997,7 +1083,7 @@ int main(int argc, char *argv[]) if (c == -1) break; /* Parse end */ switch (c) { - case 1000: /* global mode */ + case OPTVAL_GLOBAL: /* global mode */ data.global = 1; break; @@ -1152,6 +1238,27 @@ int main(int argc, char *argv[]) case 'q': /* quiet mode is removed */ break; + case OPTVAL_ADD_BLACKLIST: + data.request = ADD_BLACKLIST_REQ; + if (optarg) + snprintf(data.pkgid, sizeof(data.pkgid), + "%s", optarg); + break; + + case OPTVAL_REMOVE_BLACKLIST: + data.request = REMOVE_BLACKLIST_REQ; + if (optarg) + snprintf(data.pkgid, sizeof(data.pkgid), + "%s", optarg); + break; + + case OPTVAL_CHECK_BLACKLIST: + data.request = CHECK_BLACKLIST_REQ; + if (optarg) + snprintf(data.pkgid, sizeof(data.pkgid), + "%s", optarg); + break; + /* Otherwise */ case '?': /* Not an option */ __print_usage(); -- 2.7.4