diff --git a/src/sshmngr.c b/src/sshmngr.c index 3ee2e5762e697dedd786682e907a3094159f319c..bbccd1eabb01de9a3d52dd42ada1a187f98c94dd 100644 --- a/src/sshmngr.c +++ b/src/sshmngr.c @@ -179,9 +179,9 @@ static int delObjSSHKey(char *refparam, struct dmctx *ctx, void *data, char *ins switch (del_action) { case DEL_INST: - dmuci_get_value_by_section_string((struct uci_section *)data, "pubkey", &value); + dmuci_get_value_by_section_string(((struct dm_data *)data)->dmmap_section, "pubkey", &value); remove_pubkey(value); - dmuci_delete_by_section((struct uci_section *)data, NULL, NULL); + dmuci_delete_by_section(((struct dm_data *)data)->dmmap_section, NULL, NULL); break; case DEL_ALL: uci_path_foreach_sections_safe(bbfdm, "dmmap_sshmngr", "authkey", stmp, s) { @@ -248,6 +248,7 @@ static int browseSSHKeyInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev char *key = NULL; unsigned idx = 0; json_object *json_key_list = NULL, *arr_obj = NULL; + struct dm_data data = {0}; dmubus_call("sshmngr", "list_keys", UBUS_ARGS{0}, 0, &json_key_list); DM_ASSERT(json_key_list, return 0); @@ -272,26 +273,22 @@ static int browseSSHKeyInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev } } - /* delete keys from dmmap which are not available in KEY_FILE */ stmp = NULL; s = NULL; uci_path_foreach_sections_safe(bbfdm, "dmmap_sshmngr", "authkey", stmp, s) { char *val = NULL; dmuci_get_value_by_section_string(s, "pubkey", &val); if (!key_exist_in_keyfile(val, json_key_list)) { + /* delete keys from dmmap which are not available in KEY_FILE */ dmuci_delete_by_section(s, NULL, NULL); - } - } - - /* enlist objects */ - stmp = NULL; - s = NULL; + } else { + data.dmmap_section = s; + /* enlist objects */ + inst = handle_instance(dmctx, parent_node, s, "instance", "alias"); - uci_path_foreach_sections_safe(bbfdm, "dmmap_sshmngr", "authkey", stmp, s) { - inst = handle_instance(dmctx, parent_node, s, "instance", "alias"); - - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)s, inst) == DM_STOP) - break; + if (DM_LINK_INST_OBJ(dmctx, parent_node, &data, inst) == DM_STOP) + break; + } } return 0; } @@ -634,17 +631,17 @@ static int get_ssh_server_session_port(char *refparam, struct dmctx *ctx, void * static int get_ssh_key_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - return bbf_get_alias(ctx, (struct uci_section *)data, "alias", instance, value); + return bbf_get_alias(ctx, ((struct dm_data *)data)->dmmap_section, "alias", instance, value); } static int set_ssh_key_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - return bbf_set_alias(ctx, (struct uci_section *)data, "alias", instance, value); + return bbf_set_alias(ctx, ((struct dm_data *)data)->dmmap_section, "alias", instance, value); } static int get_ssh_key_pubkey(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string((struct uci_section *)data, "pubkey", value); + dmuci_get_value_by_section_string(((struct dm_data *)data)->dmmap_section, "pubkey", value); return 0; } @@ -658,7 +655,7 @@ static int set_ssh_key_pubkey(char *refparam, struct dmctx *ctx, void *data, cha return FAULT_9007; /* check if same as current key value */ - dmuci_get_value_by_section_string((struct uci_section *)data, "pubkey", &cur_val); + dmuci_get_value_by_section_string(((struct dm_data *)data)->dmmap_section, "pubkey", &cur_val); if (DM_STRCMP(cur_val, value) == 0) break; @@ -668,12 +665,12 @@ static int set_ssh_key_pubkey(char *refparam, struct dmctx *ctx, void *data, cha break; case VALUESET: /* check if same as current key value then nothing to do */ - dmuci_get_value_by_section_string((struct uci_section *)data, "pubkey", &cur_val); + dmuci_get_value_by_section_string(((struct dm_data *)data)->dmmap_section, "pubkey", &cur_val); if (DM_STRCMP(cur_val, value) == 0) break; add_pubkey(cur_val, value); - dmuci_set_value_by_section((struct uci_section *)data, "pubkey", value); + dmuci_set_value_by_section(((struct dm_data *)data)->dmmap_section, "pubkey", value); break; } return 0;