27#include "cmdhandler.h"
31#include "clientpipe.h"
32#include "longgetopt.h"
41static const char *module_str =
"key_purge_cmd";
48 " --policy <policy> | --zone <zone> aka -p | -z\n"
56 "This command will remove keys from the database (and HSM) that "
57 "are dead. Use with caution.\n"
59 "policy limit the purge to the given policy\n"
60 "zone limit the purge to the given zone\n"
61 "the -d flag will cause the keys to be deleted from the HSM\n\n"
74run(cmdhandler_ctx_type* context,
int argc,
char* argv[])
76 int sockfd = context->sockfd;
77 struct longgetopt optctx;
80 const char *zone_name = NULL;
82 int long_index = 0, opt = 0;
87 static struct option long_options[] = {
88 {
"zone", required_argument, 0,
'z'},
89 {
"policy", required_argument, 0,
'p'},
90 {
"delete", no_argument, 0,
'd'},
94 if (!dbconn)
return 1;
96 for(opt = longgetopt(argc, argv,
"z:p:d", long_options, &long_index, &optctx); opt != -1;
97 opt = longgetopt(argc, argv, NULL, long_options, &long_index, &optctx)) {
100 zone_name = optctx.optarg;
109 client_printf_err(sockfd,
"unknown arguments\n");
110 ods_log_error(
"[%s] unknown arguments for key purge command", module_str);
116 ods_log_error(
"[%s] expected either --zone or --policy", module_str);
117 client_printf_err(sockfd,
"expected either --zone or --policy \n");
124 client_printf_err(sockfd,
"unknown zone %s\n", zone_name);
140 client_printf_err(sockfd,
"unknown policy %s\n",
policy_name);
150 "key purge", &usage, &help, NULL, NULL, &run, NULL};
db_connection_t * getconnectioncontext(cmdhandler_ctx_type *context)
int removeDeadKeysNow(int sockfd, db_connection_t *dbconn, policy_t *policy, zone_db_t *rzone, int purge)
struct cmd_func_block key_purge_funcblock
policy_t * policy_new(const db_connection_t *connection)
int policy_get_by_name(policy_t *policy, const char *name)
const char * policy_name(const policy_t *policy)
void policy_free(policy_t *policy)
void zone_db_free(zone_db_t *zone)
zone_db_t * zone_db_new(const db_connection_t *connection)
int zone_db_get_by_name(zone_db_t *zone, const char *name)