2 #include "cmdhandler.h"
6 #include "clientpipe.h"
17 static const char *module_str =
"key_purge_cmd";
24 " --policy <policy> | --zone <zone> aka -p | -z\n");
31 "This command will remove keys from the database and HSM that "
32 "are dead. Use with caution.\n"
34 "policy limit the purge to the given policy\n"
35 "zone limit the purge to the given zone\n\n"
48 run(
int sockfd, cmdhandler_ctx_type* context,
const char *cmd)
52 const char *zone_name = NULL;
57 int long_index = 0, opt = 0;
61 static struct option long_options[] = {
62 {
"zone", required_argument, 0,
'z'},
63 {
"policy", required_argument, 0,
'p'},
67 if (!dbconn)
return 1;
71 if (!(buf = strdup(cmd))) {
72 client_printf_err(sockfd,
"memory error\n");
76 argc = ods_str_explode(buf,
MAX_ARGS, argv);
78 client_printf_err(sockfd,
"too many arguments\n");
79 ods_log_error(
"[%s] too many arguments for %s command",
86 while ((opt = getopt_long(argc, (
char*
const*)argv,
"z:p:", long_options, &long_index)) != -1) {
95 client_printf_err(sockfd,
"unknown arguments\n");
96 ods_log_error(
"[%s] unknown arguments for %s command",
104 ods_log_error(
"[%s] expected either --zone or --policy", module_str);
105 client_printf_err(sockfd,
"expected either --zone or --policy \n");
113 client_printf_err(sockfd,
"unknown zone %s\n", zone_name);
132 client_printf_err(sockfd,
"unknown policy %s\n",
policy_name);
143 "key purge", &usage, &help, NULL, &run