31 #include "cmdhandler.h"
35 #include "clientpipe.h"
42 static const char *module_str =
"key_generate_cmd";
49 " --duration <duration> aka -d\n"
50 " --policy <policy> aka -p \n"
59 "Pre-generate keys for all or a given policy, the duration to pre-generate for\n"
60 "can be specified or otherwise its taken from the conf.xml.\n"
62 "duration duration to generate keys for\n"
63 "policy|all generate keys for a specified policy or for all of them \n\n");
67 run(
int sockfd, cmdhandler_ctx_type* context,
const char *cmd)
71 const char* argv[
NARGV];
72 int argc = 0, 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'},
91 if (!(buf = strdup(cmd))) {
92 client_printf_err(sockfd,
"memory error\n");
96 argc = ods_str_explode(buf,
NARGV, argv);
98 client_printf_err(sockfd,
"too many arguments\n");
99 ods_log_error(
"[%s] too many arguments for %s command",
106 while ((opt = getopt_long(argc, (
char*
const*)argv,
"p:ad:", long_options, &long_index)) != -1) {
109 duration_text = optarg;
118 client_printf_err(sockfd,
"unknown arguments\n");
119 ods_log_error(
"[%s] unknown arguments for %s command",
127 if (!(duration = duration_create_from_string(duration_text))
128 || !(duration_time = duration2time(duration)))
130 client_printf_err(sockfd,
"Error parsing the specified duration!\n");
131 duration_cleanup(duration);
135 duration_cleanup(duration);
143 client_printf_err(sockfd,
"Unable to find policy %s!\n",
policy_name);
151 client_printf_err(sockfd,
"Either --all or --policy needs to be given!\n");
156 client_printf(sockfd,
"Key generation task scheduled.\n");
162 "key generate", &usage, &help, NULL, &run
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
const char * policy_name(const policy_t *policy)
void policy_free(policy_t *policy)
policy_t * policy_new_get_by_name(const db_connection_t *connection, const char *name)