31#include "cmdhandler.h"
35#include "clientpipe.h"
36#include "longgetopt.h"
43static const char *module_str =
"key_generate_cmd";
50 " --duration <duration> aka -d\n"
51 " --policy <policy> aka -p \n"
60 "Pre-generate keys for all or a given policy, the duration to pre-generate for\n"
61 "can be specified or otherwise its taken from the conf.xml.\n"
63 "duration duration to generate keys for\n"
64 "policy|all generate keys for a specified policy or for all of them \n\n");
68run(cmdhandler_ctx_type* context,
int argc,
char* argv[])
70 int sockfd = context->sockfd;
71 struct longgetopt optctx;
72 int long_index =0, opt = 0;
74 const char* duration_text = NULL;
75 time_t duration_time = 0;
76 duration_type* duration = NULL;
82 static struct option long_options[] = {
83 {
"policy", required_argument, 0,
'p'},
84 {
"all", no_argument, 0,
'a'},
85 {
"duration", required_argument, 0,
'd'},
89 ods_log_debug(
"[%s] key generate command", module_str);
91 for(opt = longgetopt(argc, argv,
"p:ad:", long_options, &long_index, &optctx); opt != -1;
92 opt = longgetopt(argc, argv, NULL, long_options, &long_index, &optctx)) {
95 duration_text = optctx.optarg;
104 client_printf_err(sockfd,
"unknown arguments\n");
105 ods_log_error(
"[%s] unknown arguments for key generate command", module_str);
110 if (!(duration = duration_create_from_string(duration_text))
111 || !(duration_time = duration2time(duration)))
113 client_printf_err(sockfd,
"Error parsing the specified duration!\n");
114 duration_cleanup(duration);
117 duration_cleanup(duration);
125 client_printf_err(sockfd,
"Unable to find policy %s!\n",
policy_name);
132 client_printf_err(sockfd,
"Either --all or --policy needs to be given!\n");
136 client_printf(sockfd,
"Key generation task scheduled.\n");
141 "key generate", &usage, &help, NULL, NULL, &run, NULL
db_connection_t * getconnectioncontext(cmdhandler_ctx_type *context)
engine_type * getglobalcontext(cmdhandler_ctx_type *context)
int hsm_key_factory_schedule_generate_policy(engine_type *engine, const policy_t *policy_orig, time_t duration)
int hsm_key_factory_schedule_generate_all(engine_type *engine, time_t duration)
struct cmd_func_block key_generate_funcblock
policy_t * policy_new_get_by_name(const db_connection_t *connection, const char *name)
const char * policy_name(const policy_t *policy)
void policy_free(policy_t *policy)