Skip to content

Commit

Permalink
config UPDATE delete choice trees on data creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Roytak committed Jul 27, 2023
1 parent a178470 commit 3f551c3
Show file tree
Hide file tree
Showing 2 changed files with 233 additions and 44 deletions.
142 changes: 114 additions & 28 deletions src/config_new_ssh.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,28 @@ _nc_server_config_new_ssh_hostkey(const struct ly_ctx *ctx, const char *tree_pat
goto cleanup;
}

ret = nc_config_new_create_append(ctx, tree_path, "public-key-format", pubkey_format, config);
ret = nc_config_new_create_append(ctx, tree_path, "inline-definition/public-key-format", pubkey_format, config);
if (ret) {
goto cleanup;
}

ret = nc_config_new_create_append(ctx, tree_path, "public-key", pubkey, config);
ret = nc_config_new_create_append(ctx, tree_path, "inline-definition/public-key", pubkey, config);
if (ret) {
goto cleanup;
}

ret = nc_config_new_create_append(ctx, tree_path, "private-key-format", privkey_format, config);
ret = nc_config_new_create_append(ctx, tree_path, "inline-definition/private-key-format", privkey_format, config);
if (ret) {
goto cleanup;
}

ret = nc_config_new_create_append(ctx, tree_path, "cleartext-private-key", privkey, config);
ret = nc_config_new_create_append(ctx, tree_path, "inline-definition/cleartext-private-key", privkey, config);
if (ret) {
goto cleanup;
}

/* delete keystore choice nodes if present */
ret = nc_config_new_check_delete(config, "%s/keystore-reference", tree_path);
if (ret) {
goto cleanup;
}
Expand All @@ -101,7 +107,7 @@ nc_server_config_new_ssh_hostkey(const struct ly_ctx *ctx, const char *endpt_nam
NC_CHECK_ARG_RET(NULL, ctx, endpt_name, hostkey_name, privkey_path, config, 1);

if (asprintf(&path, "/ietf-netconf-server:netconf-server/listen/endpoint[name='%s']/ssh/ssh-server-parameters/"
"server-identity/host-key[name='%s']/public-key/inline-definition", endpt_name, hostkey_name) == -1) {
"server-identity/host-key[name='%s']/public-key", endpt_name, hostkey_name) == -1) {
ERRMEM;
path = NULL;
ret = 1;
Expand Down Expand Up @@ -131,7 +137,7 @@ nc_server_config_new_ch_ssh_hostkey(const struct ly_ctx *ctx, const char *client

if (asprintf(&path, "/ietf-netconf-server:netconf-server/call-home/"
"netconf-client[name='%s']/endpoints/endpoint[name='%s']/ssh/ssh-server-parameters/server-identity/"
"host-key[name='%s']/public-key/inline-definition", client_name, endpt_name, hostkey_name) == -1) {
"host-key[name='%s']/public-key", client_name, endpt_name, hostkey_name) == -1) {
ERRMEM;
path = NULL;
ret = 1;
Expand Down Expand Up @@ -182,37 +188,58 @@ nc_server_config_new_ch_ssh_del_hostkey(const char *client_name, const char *end
}

API int
nc_server_config_new_ch_ssh_keystore_reference(const struct ly_ctx *ctx, const char *client_name,
const char *endpt_name, const char *hostkey_name, const char *keystore_reference, struct lyd_node **config)
nc_server_config_new_ssh_keystore_reference(const struct ly_ctx *ctx, const char *endpt_name, const char *hostkey_name,
const char *keystore_reference, struct lyd_node **config)
{
NC_CHECK_ARG_RET(NULL, ctx, client_name, endpt_name, hostkey_name, keystore_reference, 1);
NC_CHECK_ARG_RET(NULL, config, 1);
int ret = 0;

return nc_config_new_create(ctx, config, keystore_reference, "/ietf-netconf-server:netconf-server/call-home/"
"netconf-client[name='%s']/endpoints/endpoint[name='%s']/ssh/ssh-server-parameters/server-identity/"
"host-key[name='%s']/public-key/keystore-reference", client_name, endpt_name, hostkey_name);
NC_CHECK_ARG_RET(NULL, ctx, endpt_name, hostkey_name, keystore_reference, config, 1);

ret = nc_config_new_create(ctx, config, keystore_reference, "/ietf-netconf-server:netconf-server/listen/"
"endpoint[name='%s']/ssh/ssh-server-parameters/server-identity/host-key[name='%s']/public-key/"
"keystore-reference", endpt_name, hostkey_name);
if (ret) {
goto cleanup;
}

/* delete inline definition nodes if present */
ret = nc_config_new_check_delete(config, "/ietf-netconf-server:netconf-server/listen/"
"endpoint[name='%s']/ssh/ssh-server-parameters/server-identity/host-key[name='%s']/public-key/"
"inline-definition", endpt_name, hostkey_name);
if (ret) {
goto cleanup;
}

cleanup:
return ret;
}

API int
nc_server_config_new_ch_ssh_del_keystore_reference(const char *client_name, const char *endpt_name,
const char *hostkey_name, struct lyd_node **config)
nc_server_config_new_ch_ssh_keystore_reference(const struct ly_ctx *ctx, const char *client_name,
const char *endpt_name, const char *hostkey_name, const char *keystore_reference, struct lyd_node **config)
{
NC_CHECK_ARG_RET(NULL, client_name, endpt_name, hostkey_name, config, 1);
int ret = 0;

return nc_config_new_delete(config, "/ietf-netconf-server:netconf-server/call-home/"
NC_CHECK_ARG_RET(NULL, ctx, client_name, endpt_name, hostkey_name, keystore_reference, 1);
NC_CHECK_ARG_RET(NULL, config, 1);

ret = nc_config_new_create(ctx, config, keystore_reference, "/ietf-netconf-server:netconf-server/call-home/"
"netconf-client[name='%s']/endpoints/endpoint[name='%s']/ssh/ssh-server-parameters/server-identity/"
"host-key[name='%s']/public-key/keystore-reference", client_name, endpt_name, hostkey_name);
}
if (ret) {
goto cleanup;
}

API int
nc_server_config_new_ssh_keystore_reference(const struct ly_ctx *ctx, const char *endpt_name, const char *hostkey_name,
const char *keystore_reference, struct lyd_node **config)
{
NC_CHECK_ARG_RET(NULL, ctx, endpt_name, hostkey_name, keystore_reference, config, 1);
/* delete inline definition nodes if present */
ret = nc_config_new_check_delete(config, "/ietf-netconf-server:netconf-server/call-home/"
"netconf-client[name='%s']/endpoints/endpoint[name='%s']/ssh/ssh-server-parameters/server-identity/"
"host-key[name='%s']/public-key/inline-definition", client_name, endpt_name, hostkey_name);
if (ret) {
goto cleanup;
}

return nc_config_new_create(ctx, config, keystore_reference, "/ietf-netconf-server:netconf-server/listen/"
"endpoint[name='%s']/ssh/ssh-server-parameters/server-identity/host-key[name='%s']/public-key/"
"keystore-reference", endpt_name, hostkey_name);
cleanup:
return ret;
}

API int
Expand All @@ -226,6 +253,17 @@ nc_server_config_new_ssh_del_keystore_reference(const char *endpt_name, const ch
"keystore-reference", endpt_name, hostkey_name);
}

API int
nc_server_config_new_ch_ssh_del_keystore_reference(const char *client_name, const char *endpt_name,
const char *hostkey_name, struct lyd_node **config)
{
NC_CHECK_ARG_RET(NULL, client_name, endpt_name, hostkey_name, config, 1);

return nc_config_new_delete(config, "/ietf-netconf-server:netconf-server/call-home/"
"netconf-client[name='%s']/endpoints/endpoint[name='%s']/ssh/ssh-server-parameters/server-identity/"
"host-key[name='%s']/public-key/keystore-reference", client_name, endpt_name, hostkey_name);
}

API int
nc_server_config_new_ssh_auth_attempts(const struct ly_ctx *ctx, const char *endpt_name, uint16_t auth_attempts,
struct lyd_node **config)
Expand Down Expand Up @@ -390,6 +428,14 @@ nc_server_config_new_ssh_user_pubkey(const struct ly_ctx *ctx, const char *endpt
goto cleanup;
}

/* delete truststore reference if present */
ret = nc_config_new_check_delete(config, "/ietf-netconf-server:netconf-server/listen/endpoint[name='%s']/ssh/"
"ssh-server-parameters/client-authentication/users/user[name='%s']/public-keys/truststore-reference",
endpt_name, user_name);
if (ret) {
goto cleanup;
}

cleanup:
free(path);
return ret;
Expand Down Expand Up @@ -421,6 +467,14 @@ nc_server_config_new_ch_ssh_user_pubkey(const struct ly_ctx *ctx, const char *cl
goto cleanup;
}

/* delete truststore reference if present */
ret = nc_config_new_check_delete(config, "/ietf-netconf-server:netconf-server/call-home/netconf-client[name='%s']/"
"endpoints/endpoint[name='%s']/ssh/ssh-server-parameters/client-authentication/users/user[name='%s']/"
"public-keys/truststore-reference", client_name, endpt_name, user_name);
if (ret) {
goto cleanup;
}

cleanup:
free(path);
return ret;
Expand Down Expand Up @@ -773,23 +827,55 @@ API int
nc_server_config_new_ssh_truststore_reference(const struct ly_ctx *ctx, const char *endpt_name, const char *user_name,
const char *truststore_reference, struct lyd_node **config)
{
int ret = 0;

NC_CHECK_ARG_RET(NULL, ctx, endpt_name, user_name, truststore_reference, config, 1);

return nc_config_new_create(ctx, config, truststore_reference, "/ietf-netconf-server:netconf-server/listen/"
ret = nc_config_new_create(ctx, config, truststore_reference, "/ietf-netconf-server:netconf-server/listen/"
"endpoint[name='%s']/ssh/ssh-server-parameters/client-authentication/users/user[name='%s']/public-keys/"
"truststore-reference", endpt_name, user_name);
if (ret) {
goto cleanup;
}

/* delete inline definition nodes if present */
ret = nc_config_new_check_delete(config, "/ietf-netconf-server:netconf-server/listen/endpoint[name='%s']/ssh/"
"ssh-server-parameters/client-authentication/users/user[name='%s']/public-keys/inline-definition",
endpt_name, user_name);
if (ret) {
goto cleanup;
}

cleanup:
return ret;
}

API int
nc_server_config_new_ch_ssh_truststore_reference(const struct ly_ctx *ctx, const char *client_name,
const char *endpt_name, const char *user_name, const char *truststore_reference, struct lyd_node **config)
{
int ret = 0;

NC_CHECK_ARG_RET(NULL, ctx, client_name, endpt_name, user_name, truststore_reference, 1);
NC_CHECK_ARG_RET(NULL, config, 1);

return nc_config_new_create(ctx, config, truststore_reference, "/ietf-netconf-server:netconf-server/call-home/"
ret = nc_config_new_create(ctx, config, truststore_reference, "/ietf-netconf-server:netconf-server/call-home/"
"netconf-client[name='%s']/endpoints/endpoint[name='%s']/ssh/ssh-server-parameters/client-authentication/"
"users/user[name='%s']/public-keys/truststore-reference", client_name, endpt_name, user_name);
if (ret) {
goto cleanup;
}

/* delete inline definition nodes if present */
ret = nc_config_new_check_delete(config, "/ietf-netconf-server:netconf-server/call-home/netconf-client[name='%s']/"
"endpoints/endpoint[name='%s']/ssh/ssh-server-parameters/client-authentication/users/user[name='%s']/"
"public-keys/inline-definition", client_name, endpt_name, user_name);
if (ret) {
goto cleanup;
}

cleanup:
return ret;
}

API int
Expand Down
Loading

0 comments on commit 3f551c3

Please sign in to comment.