Commit e867b8c4 authored by Mark Karpilovskij's avatar Mark Karpilovskij Committed by Daniel Salzman
Browse files

keymgr: fixed share command

parent 15c4e627
......@@ -574,17 +574,8 @@ int keymgr_get_key(kdnssec_ctx_t *ctx, const char *key_spec, knot_kasp_key_t **k
return KNOT_EOK;
}
int keymgr_foreign_key_id(int argc, char *argv[], const char *req_action,
knot_dname_t **key_zone, char **key_id)
int keymgr_foreign_key_id(char *argv[], knot_dname_t **key_zone, char **key_id)
{
if (argc < 1) {
printf("Key to %s - zone is not specified.\n", req_action);
return KNOT_EINVAL;
}
if (argc < 2) {
printf("Key to %s is not specified.\n", req_action);
return KNOT_EINVAL;
}
*key_zone = knot_dname_from_str_alloc(argv[0]);
if (*key_zone == NULL) {
return KNOT_ENOMEM;
......@@ -600,7 +591,7 @@ int keymgr_foreign_key_id(int argc, char *argv[], const char *req_action,
return KNOT_ENOZONE;
}
knot_kasp_key_t *key;
ret = keymgr_get_key(&kctx, argv[1], &key);
ret = keymgr_get_key(&kctx, argv[2], &key);
if (ret == KNOT_EOK) {
*key_id = strdup(key->id);
if (*key_id == NULL) {
......
......@@ -26,8 +26,7 @@ int keymgr_generate_tsig(const char *tsig_name, const char *alg_name, int bits);
int keymgr_get_key(kdnssec_ctx_t *ctx, const char *key_spec, knot_kasp_key_t **key);
int keymgr_foreign_key_id(int argc, char *argv[], const char *req_action,
knot_dname_t **key_zone, char **key_id);
int keymgr_foreign_key_id(char *argv[], knot_dname_t **key_zone, char **key_id);
int keymgr_set_timing(knot_kasp_key_t *key, int argc, char *argv[]);
......
......@@ -148,9 +148,11 @@ static int key_command(int argc, char *argv[])
}
}
} else if (strcmp(argv[1], "share") == 0) {
CHECK_MISSING_ARG("Key to be shared is not specified");
knot_dname_t *other_zone = NULL;
char *key_to_share = NULL;
if (keymgr_foreign_key_id(argc - 2, argv + 2, "be shared", &other_zone, &key_to_share) == KNOT_EOK) {
ret = keymgr_foreign_key_id(argv, &other_zone, &key_to_share);
if (ret == KNOT_EOK) {
ret = kasp_db_share_key(*kctx.kasp_db, other_zone, kctx.zone->dname, key_to_share);
}
free(other_zone);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment