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"
32 "This command will remove keys from the database (and HSM) that "
33 "are dead. Use with caution.\n"
35 "policy limit the purge to the given policy\n"
36 "zone limit the purge to the given zone\n"
37 "the -d flag will cause the keys to be deleted from the HSM\n\n"
50 run(
int sockfd, cmdhandler_ctx_type* context,
const char *cmd)
54 const char *zone_name = NULL;
59 int long_index = 0, opt = 0;
64 static struct option long_options[] = {
65 {
"zone", required_argument, 0,
'z'},
66 {
"policy", required_argument, 0,
'p'},
67 {
"delete", no_argument, 0,
'd'},
71 if (!dbconn)
return 1;
75 if (!(buf = strdup(cmd))) {
76 client_printf_err(sockfd,
"memory error\n");
80 argc = ods_str_explode(buf,
MAX_ARGS, argv);
82 client_printf_err(sockfd,
"too many arguments\n");
83 ods_log_error(
"[%s] too many arguments for %s command",
90 while ((opt = getopt_long(argc, (
char*
const*)argv,
"z:p:d", long_options, &long_index)) != -1) {
102 client_printf_err(sockfd,
"unknown arguments\n");
103 ods_log_error(
"[%s] unknown arguments for %s command",
111 ods_log_error(
"[%s] expected either --zone or --policy", module_str);
112 client_printf_err(sockfd,
"expected either --zone or --policy \n");
120 client_printf_err(sockfd,
"unknown zone %s\n", zone_name);
139 client_printf_err(sockfd,
"unknown policy %s\n",
policy_name);
150 "key purge", &usage, &help, NULL, &run
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
const char * policy_name(const policy_t *policy)
int policy_get_by_name(policy_t *policy, const char *name)
void policy_free(policy_t *policy)
policy_t * policy_new(const db_connection_t *connection)
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)