Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ set(CMAKE_MACOSX_RPATH TRUE)
# micro version is changed with a set of small changes or bugfixes anywhere in the project.
set(LIBNETCONF2_MAJOR_VERSION 4)
set(LIBNETCONF2_MINOR_VERSION 4)
set(LIBNETCONF2_MICRO_VERSION 14)
set(LIBNETCONF2_MICRO_VERSION 15)
set(LIBNETCONF2_VERSION ${LIBNETCONF2_MAJOR_VERSION}.${LIBNETCONF2_MINOR_VERSION}.${LIBNETCONF2_MICRO_VERSION})

# Version of the library
# Major version is changed with every backward non-compatible API/ABI change in the library, minor version changes
# with backward compatible change and micro version is connected with any internal change of the library.
set(LIBNETCONF2_MAJOR_SOVERSION 5)
set(LIBNETCONF2_MINOR_SOVERSION 4)
set(LIBNETCONF2_MICRO_SOVERSION 13)
set(LIBNETCONF2_MICRO_SOVERSION 14)
set(LIBNETCONF2_SOVERSION_FULL ${LIBNETCONF2_MAJOR_SOVERSION}.${LIBNETCONF2_MINOR_SOVERSION}.${LIBNETCONF2_MICRO_SOVERSION})
set(LIBNETCONF2_SOVERSION ${LIBNETCONF2_MAJOR_SOVERSION})

Expand Down
64 changes: 64 additions & 0 deletions src/server_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ int nc_server_config_add_address_port(const struct ly_ctx *ctx, const char *endp
* If NULL, all of the endpoints will be deleted.
* @param[in,out] config Modified configuration YANG data tree.
* @return 0 on success, non-zero otherwise.
*
* @note If the last endpoint is deleted, the parent listen presence container
* is also deleted to maintain a valid YANG data tree.
*/
int nc_server_config_del_endpt(const char *endpt_name, struct lyd_node **config);

Expand Down Expand Up @@ -400,6 +403,9 @@ int nc_server_config_add_ssh_hostkey(const struct ly_ctx *ctx, const char *endpt
* If NULL, all of the hostkeys on this endpoint will be deleted.
* @param[in,out] config Configuration YANG data tree.
* @return 0 on success, non-zero otherwise.
*
* @note If the last hostkey is deleted, the configuration becomes invalid and
* a warning is printed. Add a new hostkey to make it valid again.
*/
int nc_server_config_del_ssh_hostkey(const struct ly_ctx *ctx, const char *endpt_name,
const char *hostkey_name, struct lyd_node **config);
Expand Down Expand Up @@ -650,6 +656,9 @@ int nc_server_config_add_tls_server_cert(const struct ly_ctx *ctx, const char *e
* @param[in] endpt_name Identifier of an existing endpoint.
* @param[in,out] config Modified configuration YANG data tree.
* @return 0 on success, non-zero otherwise.
*
* @note Deleting the server certificate makes the configuration invalid and
* a warning is printed. Add a new server certificate to make it valid again.
*/
int nc_server_config_del_tls_server_cert(const char *endpt_name, struct lyd_node **config);

Expand All @@ -674,6 +683,9 @@ int nc_server_config_add_tls_keystore_ref(const struct ly_ctx *ctx, const char *
* @param[in] endpt_name Identifier of an existing endpoint.
* @param[in,out] config Modified configuration YANG data tree.
* @return 0 on success, non-zero otherwise.
*
* @note Deleting the keystore reference makes the configuration invalid and
* a warning is printed. Add a new keystore reference to make it valid again.
*/
int nc_server_config_del_tls_keystore_ref(const char *endpt_name, struct lyd_node **config);

Expand Down Expand Up @@ -703,6 +715,10 @@ int nc_server_config_add_tls_client_cert(const struct ly_ctx *ctx, const char *e
* If NULL, all of the end-entity certificates on the given endpoint will be deleted.
* @param[in,out] config Modified configuration YANG data tree.
* @return 0 on success, non-zero otherwise.
*
* @note If the last certificate is deleted, the parent ee-certs container and
* possibly the client-authentication container are also deleted to maintain
* a valid YANG data tree.
*/
int nc_server_config_del_tls_client_cert(const char *endpt_name, const char *cert_name, struct lyd_node **config);

Expand All @@ -726,6 +742,9 @@ int nc_server_config_add_tls_client_cert_truststore_ref(const struct ly_ctx *ctx
* @param[in] endpt_name Identifier of an existing endpoint.
* @param[in,out] config Modified configuration YANG data tree.
* @return 0 on success, non-zero otherwise.
*
* @note The parent ee-certs container and possibly the client-authentication
* container are also deleted to maintain a valid YANG data tree.
*/
int nc_server_config_del_tls_client_cert_truststore_ref(const char *endpt_name, struct lyd_node **config);

Expand Down Expand Up @@ -763,6 +782,10 @@ int nc_server_config_add_tls_ca_cert(const struct ly_ctx *ctx, const char *endpt
* If NULL, all of the CA certificates on the given endpoint will be deleted.
* @param[in,out] config Modified configuration YANG data tree.
* @return 0 on success, non-zero otherwise.
*
* @note If the last certificate is deleted, the parent ca-certs container and
* possibly the client-authentication container are also deleted to maintain
* a valid YANG data tree.
*/
int nc_server_config_del_tls_ca_cert(const char *endpt_name, const char *cert_name, struct lyd_node **config);

Expand All @@ -786,6 +809,9 @@ int nc_server_config_add_tls_ca_cert_truststore_ref(const struct ly_ctx *ctx, co
* @param[in] endpt_name Identifier of an existing endpoint.
* @param[in,out] config Modified configuration YANG data tree.
* @return 0 on success, non-zero otherwise.
*
* @note The parent ca-certs container and possibly the client-authentication
* container are also deleted to maintain a valid YANG data tree.
*/
int nc_server_config_del_tls_ca_cert_truststore_ref(const char *endpt_name, struct lyd_node **config);

Expand Down Expand Up @@ -842,6 +868,10 @@ int nc_server_config_add_tls_ctn(const struct ly_ctx *ctx, const char *endpt_nam
* If 0, all of the cert-to-name entries on the given endpoint will be deleted.
* @param[in,out] config Modified configuration YANG data tree.
* @return 0 on success, non-zero otherwise.
*
* @note If the last cert-to-name entry is deleted, the configuration becomes
* invalid and a warning is printed. Add a new cert-to-name entry to make it
* valid again.
*/
int nc_server_config_del_tls_ctn(const char *endpt_name, uint32_t id, struct lyd_node **config);

Expand Down Expand Up @@ -896,6 +926,9 @@ int nc_server_config_add_ch_address_port(const struct ly_ctx *ctx, const char *c
* If NULL, all of the Call Home clients will be deleted.
* @param[in,out] config Modified configuration YANG data tree.
* @return 0 on success, non-zero otherwise.
*
* @note If the last client is deleted, the parent call-home presence container
* is also deleted to maintain a valid YANG data tree.
*/
int nc_server_config_del_ch_client(const char *client_name, struct lyd_node **config);

Expand All @@ -907,6 +940,10 @@ int nc_server_config_del_ch_client(const char *client_name, struct lyd_node **co
* If NULL, all of the CH endpoints which belong to the given client will be deleted.
* @param[in,out] config Modified configuration YANG data tree.
* @return 0 on success, non-zero otherwise.
*
* @note If the last endpoint of the client is deleted, the configuration
* becomes invalid and a warning is printed. Add a new endpoint to make it
* valid again.
*/
int nc_server_config_del_ch_endpt(const char *client_name, const char *endpt_name, struct lyd_node **config);

Expand Down Expand Up @@ -1074,6 +1111,9 @@ int nc_server_config_add_ch_ssh_hostkey(const struct ly_ctx *ctx, const char *cl
* If NULL, all of the hostkeys on the given endpoint will be deleted.
* @param[in,out] config Modified configuration YANG data tree.
* @return 0 on success, non-zero otherwise.
*
* @note If the last hostkey is deleted, the configuration becomes invalid and
* a warning is printed. Add a new hostkey to make it valid again.
*/
int nc_server_config_del_ch_ssh_hostkey(const char *client_name, const char *endpt_name,
const char *hostkey_name, struct lyd_node **config);
Expand Down Expand Up @@ -1319,6 +1359,9 @@ int nc_server_config_add_ch_tls_server_cert(const struct ly_ctx *ctx, const char
* @param[in] endpt_name Identifier of an existing Call Home endpoint that belongs to the given client.
* @param[in,out] config Modified configuration YANG data tree.
* @return 0 on success, non-zero otherwise.
*
* @note Deleting the server certificate makes the configuration invalid and
* a warning is printed. Add a new server certificate to make it valid again.
*/
int nc_server_config_del_ch_tls_server_cert(const char *client_name, const char *endpt_name,
struct lyd_node **config);
Expand Down Expand Up @@ -1347,6 +1390,9 @@ int nc_server_config_add_ch_tls_keystore_ref(const struct ly_ctx *ctx, const cha
* @param[in] endpt_name Identifier of an existing Call Home endpoint that belongs to the given client.
* @param[in,out] config Modified configuration YANG data tree.
* @return 0 on success, non-zero otherwise.
*
* @note Deleting the keystore reference makes the configuration invalid and
* a warning is printed. Add a new keystore reference to make it valid again.
*/
int nc_server_config_del_ch_tls_keystore_ref(const char *client_name, const char *endpt_name,
struct lyd_node **config);
Expand Down Expand Up @@ -1378,6 +1424,10 @@ int nc_server_config_add_ch_tls_client_cert(const struct ly_ctx *ctx, const char
* If NULL, all of the client certificates will be deleted.
* @param[in,out] config Modified configuration YANG data tree.
* @return 0 on success, non-zero otherwise.
*
* @note If the last certificate is deleted, the parent ee-certs container and
* possibly the client-authentication container are also deleted to maintain
* a valid YANG data tree.
*/
int nc_server_config_del_ch_tls_client_cert(const char *client_name, const char *endpt_name,
const char *cert_name, struct lyd_node **config);
Expand Down Expand Up @@ -1405,6 +1455,9 @@ int nc_server_config_add_ch_tls_client_cert_truststore_ref(const struct ly_ctx *
* @param[in] endpt_name Identifier of an existing Call Home endpoint that belongs to the given client.
* @param[in,out] config Modified configuration YANG data tree.
* @return 0 on success, non-zero otherwise.
*
* @note The parent ee-certs container and possibly the client-authentication
* container are also deleted to maintain a valid YANG data tree.
*/
int nc_server_config_del_ch_tls_client_cert_truststore_ref(const char *client_name, const char *endpt_name,
struct lyd_node **config);
Expand Down Expand Up @@ -1436,6 +1489,10 @@ int nc_server_config_add_ch_tls_ca_cert(const struct ly_ctx *ctx, const char *cl
* If NULL, all of the CA certificates will be deleted.
* @param[in,out] config Modified configuration YANG data tree.
* @return 0 on success, non-zero otherwise.
*
* @note If the last certificate is deleted, the parent ca-certs container and
* possibly the client-authentication container are also deleted to maintain
* a valid YANG data tree.
*/
int nc_server_config_del_ch_tls_ca_cert(const char *client_name, const char *endpt_name,
const char *cert_name, struct lyd_node **config);
Expand Down Expand Up @@ -1463,6 +1520,9 @@ int nc_server_config_add_ch_tls_ca_cert_truststore_ref(const struct ly_ctx *ctx,
* @param[in] endpt_name Identifier of an existing Call Home endpoint that belongs to the given client.
* @param[in,out] config Modified configuration YANG data tree.
* @return 0 on success, non-zero otherwise.
*
* @note The parent ca-certs container and possibly the client-authentication
* container are also deleted to maintain a valid YANG data tree.
*/
int nc_server_config_del_ch_tls_ca_cert_truststore_ref(const char *client_name, const char *endpt_name,
struct lyd_node **config);
Expand Down Expand Up @@ -1496,6 +1556,10 @@ int nc_server_config_add_ch_tls_ctn(const struct ly_ctx *ctx, const char *client
* If 0, all of the CTN entries will be deleted.
* @param[in,out] config Modified configuration YANG data tree.
* @return 0 on success, non-zero otherwise.
*
* @note If the last cert-to-name entry is deleted, the configuration becomes
* invalid and a warning is printed. Add a new cert-to-name entry to make it
* valid again.
*/
int nc_server_config_del_ch_tls_ctn(const char *client_name, const char *endpt_name,
uint32_t id, struct lyd_node **config);
Expand Down
74 changes: 68 additions & 6 deletions src/server_config_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,31 @@ nc_server_config_check_delete(struct lyd_node **tree, const char *path_fmt, ...)
API int
nc_server_config_del_endpt(const char *endpt_name, struct lyd_node **config)
{
int rc = 0;
struct lyd_node *node = NULL;

NC_CHECK_ARG_RET(NULL, config, 1);

if (endpt_name) {
return nc_server_config_delete(config, "/ietf-netconf-server:netconf-server/listen/endpoints/endpoint[name='%s']", endpt_name);
rc = nc_server_config_delete(config, "/ietf-netconf-server:netconf-server/listen/endpoints/endpoint[name='%s']", endpt_name);
} else {
return nc_server_config_delete(config, "/ietf-netconf-server:netconf-server/listen/endpoints/endpoint");
rc = nc_server_config_delete(config, "/ietf-netconf-server:netconf-server/listen/endpoints/endpoint");
}
if (rc) {
goto cleanup;
}

lyd_find_path(*config, "/ietf-netconf-server:netconf-server/listen/endpoints", 0, &node);
if (node && !lyd_child(node)) {
/* no more endpoints, delete the listen container */
VRB(NULL, "Last listen endpoint deleted, also removing the \"listen\" container to maintain YANG validity.");
if ((rc = nc_server_config_check_delete(config, "/ietf-netconf-server:netconf-server/listen"))) {
goto cleanup;
}
}

cleanup:
return rc;
}

API int
Expand Down Expand Up @@ -1092,27 +1110,71 @@ nc_server_config_add_ch_address_port(const struct ly_ctx *ctx, const char *clien
API int
nc_server_config_del_ch_client(const char *ch_client_name, struct lyd_node **config)
{
int rc = 0;
struct lyd_node *node = NULL;

NC_CHECK_ARG_RET(NULL, config, 1);

if (ch_client_name) {
return nc_server_config_delete(config, "/ietf-netconf-server:netconf-server/call-home/netconf-client[name='%s']", ch_client_name);
rc = nc_server_config_delete(config, "/ietf-netconf-server:netconf-server/call-home/netconf-client[name='%s']", ch_client_name);
} else {
return nc_server_config_delete(config, "/ietf-netconf-server:netconf-server/call-home/netconf-client");
rc = nc_server_config_delete(config, "/ietf-netconf-server:netconf-server/call-home/netconf-client");
}
if (rc) {
goto cleanup;
}

lyd_find_path(*config, "/ietf-netconf-server:netconf-server/call-home", 0, &node);
if (node && !lyd_child(node)) {
/* no more clients, delete the call-home container */
VRB(NULL, "Last call-home client deleted, also removing the \"call-home\" container to maintain YANG validity.");
if ((rc = nc_server_config_check_delete(config, "/ietf-netconf-server:netconf-server/call-home"))) {
goto cleanup;
}
}

cleanup:
return rc;
}

API int
nc_server_config_del_ch_endpt(const char *client_name, const char *endpt_name, struct lyd_node **config)
{
int rc = 0;
char *path = NULL;
struct lyd_node *node = NULL;

NC_CHECK_ARG_RET(NULL, client_name, config, 1);

if (endpt_name) {
return nc_server_config_delete(config, "/ietf-netconf-server:netconf-server/call-home/netconf-client[name='%s']/"
rc = nc_server_config_delete(config, "/ietf-netconf-server:netconf-server/call-home/netconf-client[name='%s']/"
"endpoints/endpoint[name='%s']", client_name, endpt_name);
} else {
return nc_server_config_delete(config, "/ietf-netconf-server:netconf-server/call-home/netconf-client[name='%s']/"
rc = nc_server_config_delete(config, "/ietf-netconf-server:netconf-server/call-home/netconf-client[name='%s']/"
"endpoints/endpoint", client_name);
}
if (rc) {
goto cleanup;
}

/* check if there are any more endpoints for this client */
if (asprintf(&path, "/ietf-netconf-server:netconf-server/call-home/netconf-client[name='%s']/endpoints", client_name) == -1) {
ERRMEM;
path = NULL;
rc = 1;
goto cleanup;
}

lyd_find_path(*config, path, 0, &node);
if (node && !lyd_child(node)) {
/* no more endpoints, the configuration is now invalid */
WRN(NULL, "Last endpoint of call-home client \"%s\" deleted, the configuration is now invalid, "
"add a new endpoint to remain valid.", client_name);
}

cleanup:
free(path);
return rc;
}

API int
Expand Down
Loading