From b640169db2e30c4636dcbcf3743081ba950636ff Mon Sep 17 00:00:00 2001 From: Mateo Cindric Date: Tue, 3 Jan 2023 14:56:48 +0000 Subject: [PATCH 01/25] system-plugin: remove plugin library linking --- CMakeLists.txt | 9 --------- 1 file changed, 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5b6461c..17d2596 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,15 +84,6 @@ set( add_library(${PLUGIN_LIRBARY_NAME} STATIC ${SOURCES}) install(TARGETS ${PLUGIN_LIRBARY_NAME} DESTINATION lib) -# link plugin library -target_link_libraries( - ${PLUGIN_LIRBARY_NAME} - ${SYSREPO_LIBRARIES} - ${LIBYANG_LIBRARIES} - ${SRPC_LIBRARIES} - ${UMGMT_LIBRARIES} -) - if(NOT PLUGIN) add_executable( ${CMAKE_PROJECT_NAME} From f41ab13525a45b46324c31d1066aa73647230663 Mon Sep 17 00:00:00 2001 From: Mateo Cindric Date: Tue, 3 Jan 2023 15:01:33 +0000 Subject: [PATCH 02/25] system-plugin: switch to building the core ietf-system sysrepo plugin library --- CMakeLists.txt | 153 +++++++----------- .../api/system/authentication/change.c | 14 +- .../api/system/authentication/change.h | 2 +- .../api/system/authentication/check.c | 6 +- .../api/system/authentication/check.h | 4 +- .../api/system/authentication/load.c | 12 +- .../api/system/authentication/load.h | 4 +- .../api/system/authentication/store.c | 2 +- .../api/system/authentication/store.h | 2 +- src/{plugin => core}/api/system/change.c | 0 src/{plugin => core}/api/system/change.h | 2 +- src/{plugin => core}/api/system/check.c | 0 src/{plugin => core}/api/system/check.h | 4 +- .../api/system/dns_resolver/change.c | 14 +- .../api/system/dns_resolver/change.h | 2 +- .../api/system/dns_resolver/check.c | 8 +- .../api/system/dns_resolver/check.h | 4 +- .../api/system/dns_resolver/load.c | 10 +- .../api/system/dns_resolver/load.h | 4 +- .../api/system/dns_resolver/store.c | 2 +- .../api/system/dns_resolver/store.h | 4 +- src/{plugin => core}/api/system/load.c | 0 src/{plugin => core}/api/system/load.h | 4 +- src/{plugin => core}/api/system/ntp/change.c | 6 +- src/{plugin => core}/api/system/ntp/change.h | 4 +- src/{plugin => core}/api/system/ntp/check.c | 4 +- src/{plugin => core}/api/system/ntp/check.h | 4 +- src/{plugin => core}/api/system/ntp/load.c | 6 +- src/{plugin => core}/api/system/ntp/load.h | 4 +- src/{plugin => core}/api/system/ntp/store.c | 6 +- src/{plugin => core}/api/system/ntp/store.h | 4 +- src/{plugin => core}/api/system/store.c | 2 +- src/{plugin => core}/api/system/store.h | 2 +- src/{plugin => core}/common.c | 0 src/{plugin => core}/common.h | 0 src/{plugin => core}/context.h | 2 +- .../system/authentication/authorized_key.c | 0 .../system/authentication/authorized_key.h | 2 +- .../authentication/authorized_key/list.c | 2 +- .../authentication/authorized_key/list.h | 2 +- .../data/system/authentication/local_user.c | 2 +- .../data/system/authentication/local_user.h | 2 +- .../system/authentication/local_user/list.c | 2 +- .../system/authentication/local_user/list.h | 2 +- .../data/system/dns_resolver/search.c | 0 .../data/system/dns_resolver/search.h | 2 +- .../data/system/dns_resolver/search/list.c | 2 +- .../data/system/dns_resolver/search/list.h | 2 +- .../data/system/dns_resolver/server.c | 0 .../data/system/dns_resolver/server.h | 2 +- .../data/system/dns_resolver/server/list.c | 4 +- .../data/system/dns_resolver/server/list.h | 2 +- src/{plugin => core}/data/system/ip_address.c | 0 src/{plugin => core}/data/system/ip_address.h | 2 +- src/{plugin => core}/data/system/ntp/server.c | 0 src/{plugin => core}/data/system/ntp/server.h | 2 +- .../data/system/ntp/server/list.c | 4 +- .../data/system/ntp/server/list.h | 2 +- src/{plugin => core}/ly_tree.c | 4 +- src/{plugin => core}/ly_tree.h | 0 src/{plugin => core}/startup/load.c | 26 +-- src/{plugin => core}/startup/load.h | 2 +- src/{plugin => core}/startup/store.c | 46 +++--- src/{plugin => core}/startup/store.h | 2 +- src/{plugin => core}/subscription/change.c | 38 ++--- src/{plugin => core}/subscription/change.h | 0 .../subscription/operational.c | 4 +- .../subscription/operational.h | 0 src/{plugin => core}/subscription/rpc.c | 2 +- src/{plugin => core}/subscription/rpc.h | 0 src/{plugin => core}/types.h | 0 src/plugin.c | 14 +- tests/system_utest.c | 10 +- 73 files changed, 226 insertions(+), 261 deletions(-) rename src/{plugin => core}/api/system/authentication/change.c (98%) rename src/{plugin => core}/api/system/authentication/change.h (97%) rename src/{plugin => core}/api/system/authentication/check.c (94%) rename src/{plugin => core}/api/system/authentication/check.h (93%) rename src/{plugin => core}/api/system/authentication/load.c (94%) rename src/{plugin => core}/api/system/authentication/load.h (92%) rename src/{plugin => core}/api/system/authentication/store.c (99%) rename src/{plugin => core}/api/system/authentication/store.h (96%) rename src/{plugin => core}/api/system/change.c (100%) rename src/{plugin => core}/api/system/change.h (96%) rename src/{plugin => core}/api/system/check.c (100%) rename src/{plugin => core}/api/system/check.h (93%) rename src/{plugin => core}/api/system/dns_resolver/change.c (95%) rename src/{plugin => core}/api/system/dns_resolver/change.h (97%) rename src/{plugin => core}/api/system/dns_resolver/check.c (94%) rename src/{plugin => core}/api/system/dns_resolver/check.h (92%) rename src/{plugin => core}/api/system/dns_resolver/load.c (95%) rename src/{plugin => core}/api/system/dns_resolver/load.h (92%) rename src/{plugin => core}/api/system/dns_resolver/store.c (99%) rename src/{plugin => core}/api/system/dns_resolver/store.h (92%) rename src/{plugin => core}/api/system/load.c (100%) rename src/{plugin => core}/api/system/load.h (93%) rename src/{plugin => core}/api/system/ntp/change.c (99%) rename src/{plugin => core}/api/system/ntp/change.h (95%) rename src/{plugin => core}/api/system/ntp/check.c (95%) rename src/{plugin => core}/api/system/ntp/check.h (91%) rename src/{plugin => core}/api/system/ntp/load.c (97%) rename src/{plugin => core}/api/system/ntp/load.h (90%) rename src/{plugin => core}/api/system/ntp/store.c (98%) rename src/{plugin => core}/api/system/ntp/store.h (90%) rename src/{plugin => core}/api/system/store.c (98%) rename src/{plugin => core}/api/system/store.h (96%) rename src/{plugin => core}/common.c (100%) rename src/{plugin => core}/common.h (100%) rename src/{plugin => core}/context.h (98%) rename src/{plugin => core}/data/system/authentication/authorized_key.c (100%) rename src/{plugin => core}/data/system/authentication/authorized_key.h (97%) rename src/{plugin => core}/data/system/authentication/authorized_key/list.c (97%) rename src/{plugin => core}/data/system/authentication/authorized_key/list.h (97%) rename src/{plugin => core}/data/system/authentication/local_user.c (95%) rename src/{plugin => core}/data/system/authentication/local_user.h (96%) rename src/{plugin => core}/data/system/authentication/local_user/list.c (97%) rename src/{plugin => core}/data/system/authentication/local_user/list.h (97%) rename src/{plugin => core}/data/system/dns_resolver/search.c (100%) rename src/{plugin => core}/data/system/dns_resolver/search.h (96%) rename src/{plugin => core}/data/system/dns_resolver/search/list.c (97%) rename src/{plugin => core}/data/system/dns_resolver/search/list.h (97%) rename src/{plugin => core}/data/system/dns_resolver/server.c (100%) rename src/{plugin => core}/data/system/dns_resolver/server.h (97%) rename src/{plugin => core}/data/system/dns_resolver/server/list.c (96%) rename src/{plugin => core}/data/system/dns_resolver/server/list.h (97%) rename src/{plugin => core}/data/system/ip_address.c (100%) rename src/{plugin => core}/data/system/ip_address.h (96%) rename src/{plugin => core}/data/system/ntp/server.c (100%) rename src/{plugin => core}/data/system/ntp/server.h (97%) rename src/{plugin => core}/data/system/ntp/server/list.c (97%) rename src/{plugin => core}/data/system/ntp/server/list.h (97%) rename src/{plugin => core}/ly_tree.c (99%) rename src/{plugin => core}/ly_tree.h (100%) rename src/{plugin => core}/startup/load.c (96%) rename src/{plugin => core}/startup/load.h (94%) rename src/{plugin => core}/startup/store.c (96%) rename src/{plugin => core}/startup/store.h (94%) rename src/{plugin => core}/subscription/change.c (96%) rename src/{plugin => core}/subscription/change.h (100%) rename src/{plugin => core}/subscription/operational.c (99%) rename src/{plugin => core}/subscription/operational.h (100%) rename src/{plugin => core}/subscription/rpc.c (98%) rename src/{plugin => core}/subscription/rpc.h (100%) rename src/{plugin => core}/types.h (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 17d2596..daf4efa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ project(sysrepo-plugin-system C) include(CompileOptions.cmake) -set(PLUGIN_LIRBARY_NAME srplg-ietf-system) +set(PLUGIN_LIRBARY_NAME srplg-ietf-system-core) set(PLUGIN 0 CACHE BOOL "Build a plugin") option(ENABLE_BUILD_TESTS, "Build tests" OFF) @@ -35,112 +35,77 @@ include_directories( set( SOURCES - src/plugin.c - src/plugin/common.c - src/plugin/ly_tree.c + src/core/common.c + src/core/ly_tree.c # startup - src/plugin/startup/load.c - src/plugin/startup/store.c + src/core/startup/load.c + src/core/startup/store.c # subs - src/plugin/subscription/change.c - src/plugin/subscription/operational.c - src/plugin/subscription/rpc.c + src/core/subscription/change.c + src/core/subscription/operational.c + src/core/subscription/rpc.c # data - src/plugin/data/system/ip_address.c - src/plugin/data/system/dns_resolver/search.c - src/plugin/data/system/dns_resolver/search/list.c - src/plugin/data/system/dns_resolver/server.c - src/plugin/data/system/dns_resolver/server/list.c - src/plugin/data/system/ntp/server.c - src/plugin/data/system/ntp/server/list.c - src/plugin/data/system/authentication/authorized_key.c - src/plugin/data/system/authentication/authorized_key/list.c - src/plugin/data/system/authentication/local_user.c - src/plugin/data/system/authentication/local_user/list.c + src/core/data/system/ip_address.c + src/core/data/system/dns_resolver/search.c + src/core/data/system/dns_resolver/search/list.c + src/core/data/system/dns_resolver/server.c + src/core/data/system/dns_resolver/server/list.c + src/core/data/system/ntp/server.c + src/core/data/system/ntp/server/list.c + src/core/data/system/authentication/authorized_key.c + src/core/data/system/authentication/authorized_key/list.c + src/core/data/system/authentication/local_user.c + src/core/data/system/authentication/local_user/list.c # system API - src/plugin/api/system/load.c - src/plugin/api/system/check.c - src/plugin/api/system/store.c - src/plugin/api/system/change.c - src/plugin/api/system/ntp/load.c - src/plugin/api/system/ntp/check.c - src/plugin/api/system/ntp/store.c - src/plugin/api/system/ntp/change.c - src/plugin/api/system/dns_resolver/load.c - src/plugin/api/system/dns_resolver/check.c - src/plugin/api/system/dns_resolver/store.c - src/plugin/api/system/dns_resolver/change.c - src/plugin/api/system/authentication/load.c - src/plugin/api/system/authentication/check.c - src/plugin/api/system/authentication/store.c - src/plugin/api/system/authentication/change.c + src/core/api/system/load.c + src/core/api/system/check.c + src/core/api/system/store.c + src/core/api/system/change.c + src/core/api/system/ntp/load.c + src/core/api/system/ntp/check.c + src/core/api/system/ntp/store.c + src/core/api/system/ntp/change.c + src/core/api/system/dns_resolver/load.c + src/core/api/system/dns_resolver/check.c + src/core/api/system/dns_resolver/store.c + src/core/api/system/dns_resolver/change.c + src/core/api/system/authentication/load.c + src/core/api/system/authentication/check.c + src/core/api/system/authentication/store.c + src/core/api/system/authentication/change.c ) -# build plugin static library +# build plugin core library add_library(${PLUGIN_LIRBARY_NAME} STATIC ${SOURCES}) install(TARGETS ${PLUGIN_LIRBARY_NAME} DESTINATION lib) -if(NOT PLUGIN) - add_executable( - ${CMAKE_PROJECT_NAME} - src/main.c - ) - # link executable - target_link_libraries( - ${CMAKE_PROJECT_NAME} - ${PLUGIN_LIRBARY_NAME} - ${SYSREPO_LIBRARIES} - ${LIBYANG_LIBRARIES} - ${SRPC_LIBRARIES} - ${UMGMT_LIBRARIES} - ) - install(TARGETS ${CMAKE_PROJECT_NAME} DESTINATION bin) -else() - # build plugin as a module for sysrepo-plugind - add_library( - ${CMAKE_PROJECT_NAME} - MODULE - ${SOURCES} - ) - # remove lib prefix from plugin library - set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES PREFIX "") - # link executable - target_link_libraries( - ${CMAKE_PROJECT_NAME} - ${SYSREPO_LIBRARIES} - ${LIBYANG_LIBRARIES} - ${SRPC_LIBRARIES} - ${UMGMT_LIBRARIES} - ) -endif() - -if(SYSTEMD_FOUND) - if(DEFINED SYSTEMD_IFINDEX) - add_compile_definitions(SYSTEMD_IFINDEX=${SYSTEMD_IFINDEX}) - else() - message(SEND_ERROR "No SYSTEMD_IFINDEX value set for default interface index to use with systemd... Unable to build without it") - endif() - - add_compile_definitions(SYSTEMD) - target_link_libraries( - ${CMAKE_PROJECT_NAME} - ${SYSTEMD_LIBRARIES} - ) - include_directories( - ${SYSTEMD_INCLUDE_DIRS} - ) -endif() - -# augyang support -if(AUGYANG_FOUND) - add_compile_definitions(AUGYANG) -else(AUGYANG_FOUND) - message(WARNING "AUGYANG not found - augeas support will be disabled") -endif() +# if(SYSTEMD_FOUND) +# if(DEFINED SYSTEMD_IFINDEX) +# add_compile_definitions(SYSTEMD_IFINDEX=${SYSTEMD_IFINDEX}) +# else() +# message(SEND_ERROR "No SYSTEMD_IFINDEX value set for default interface index to use with systemd... Unable to build without it") +# endif() + +# add_compile_definitions(SYSTEMD) +# target_link_libraries( +# ${CMAKE_PROJECT_NAME} +# ${SYSTEMD_LIBRARIES} +# ) +# include_directories( +# ${SYSTEMD_INCLUDE_DIRS} +# ) +# endif() + +# # augyang support +# if(AUGYANG_FOUND) +# add_compile_definitions(AUGYANG) +# else(AUGYANG_FOUND) +# message(WARNING "AUGYANG not found - augeas support will be disabled") +# endif() if(ENABLE_BUILD_TESTS) find_package(CMOCKA REQUIRED) diff --git a/src/plugin/api/system/authentication/change.c b/src/core/api/system/authentication/change.c similarity index 98% rename from src/plugin/api/system/authentication/change.c rename to src/core/api/system/authentication/change.c index 36325bd..b8da770 100644 --- a/src/plugin/api/system/authentication/change.c +++ b/src/core/api/system/authentication/change.c @@ -11,14 +11,14 @@ * SPDX-License-Identifier: BSD-3-Clause */ #include "change.h" -#include "plugin/common.h" +#include "core/common.h" #include "libyang/tree_data.h" -#include "plugin/api/system/authentication/store.h" -#include "plugin/data/system/authentication/authorized_key.h" -#include "plugin/data/system/authentication/authorized_key/list.h" -#include "plugin/data/system/authentication/local_user.h" -#include "plugin/data/system/authentication/local_user/list.h" -#include "plugin/types.h" +#include "core/api/system/authentication/store.h" +#include "core/data/system/authentication/authorized_key.h" +#include "core/data/system/authentication/authorized_key/list.h" +#include "core/data/system/authentication/local_user.h" +#include "core/data/system/authentication/local_user/list.h" +#include "core/types.h" #include "umgmt/db.h" #include "umgmt/types.h" #include "umgmt/user.h" diff --git a/src/plugin/api/system/authentication/change.h b/src/core/api/system/authentication/change.h similarity index 97% rename from src/plugin/api/system/authentication/change.h rename to src/core/api/system/authentication/change.h index 6f8ceb6..dd5620a 100644 --- a/src/plugin/api/system/authentication/change.h +++ b/src/core/api/system/authentication/change.h @@ -13,7 +13,7 @@ #ifndef SYSTEM_PLUGIN_API_AUTHENTICATION_CHANGE_H #define SYSTEM_PLUGIN_API_AUTHENTICATION_CHANGE_H -#include "plugin/context.h" +#include "core/context.h" #include diff --git a/src/plugin/api/system/authentication/check.c b/src/core/api/system/authentication/check.c similarity index 94% rename from src/plugin/api/system/authentication/check.c rename to src/core/api/system/authentication/check.c index 57df2d2..3a51323 100644 --- a/src/plugin/api/system/authentication/check.c +++ b/src/core/api/system/authentication/check.c @@ -12,9 +12,9 @@ */ #include "check.h" #include "load.h" -#include "plugin/common.h" -#include "plugin/data/system/authentication/local_user/list.h" -#include "plugin/data/system/authentication/authorized_key/list.h" +#include "core/common.h" +#include "core/data/system/authentication/local_user/list.h" +#include "core/data/system/authentication/authorized_key/list.h" #include #include diff --git a/src/plugin/api/system/authentication/check.h b/src/core/api/system/authentication/check.h similarity index 93% rename from src/plugin/api/system/authentication/check.h rename to src/core/api/system/authentication/check.h index 41f28c4..71fbd31 100644 --- a/src/plugin/api/system/authentication/check.h +++ b/src/core/api/system/authentication/check.h @@ -13,8 +13,8 @@ #ifndef SYSTEM_PLUGIN_API_AUTHENTICATION_CHECK_H #define SYSTEM_PLUGIN_API_AUTHENTICATION_CHECK_H -#include "plugin/context.h" -#include "plugin/types.h" +#include "core/context.h" +#include "core/types.h" #include srpc_check_status_t system_authentication_check_user(system_ctx_t *ctx, system_local_user_element_t *head, system_local_user_element_t **system_head); diff --git a/src/plugin/api/system/authentication/load.c b/src/core/api/system/authentication/load.c similarity index 94% rename from src/plugin/api/system/authentication/load.c rename to src/core/api/system/authentication/load.c index e1db4a5..9425980 100644 --- a/src/plugin/api/system/authentication/load.c +++ b/src/core/api/system/authentication/load.c @@ -12,13 +12,13 @@ */ #include "load.h" #include "sysrepo.h" -#include "plugin/types.h" -#include "plugin/common.h" +#include "core/types.h" +#include "core/common.h" -#include "plugin/data/system/authentication/authorized_key/list.h" -#include "plugin/data/system/authentication/authorized_key.h" -#include "plugin/data/system/authentication/local_user/list.h" -#include "plugin/data/system/authentication/local_user.h" +#include "core/data/system/authentication/authorized_key/list.h" +#include "core/data/system/authentication/authorized_key.h" +#include "core/data/system/authentication/local_user/list.h" +#include "core/data/system/authentication/local_user.h" #include "umgmt/user.h" #include diff --git a/src/plugin/api/system/authentication/load.h b/src/core/api/system/authentication/load.h similarity index 92% rename from src/plugin/api/system/authentication/load.h rename to src/core/api/system/authentication/load.h index 3e5538f..6be9804 100644 --- a/src/plugin/api/system/authentication/load.h +++ b/src/core/api/system/authentication/load.h @@ -13,8 +13,8 @@ #ifndef SYSTEM_PLUGIN_API_AUTHENTICATION_LOAD_H #define SYSTEM_PLUGIN_API_AUTHENTICATION_LOAD_H -#include "plugin/context.h" -#include "plugin/types.h" +#include "core/context.h" +#include "core/types.h" int system_authentication_load_user(system_ctx_t *ctx, system_local_user_element_t **head); int system_authentication_load_user_authorized_key(system_ctx_t *ctx, const char *user, system_authorized_key_element_t **head); diff --git a/src/plugin/api/system/authentication/store.c b/src/core/api/system/authentication/store.c similarity index 99% rename from src/plugin/api/system/authentication/store.c rename to src/core/api/system/authentication/store.c index 217fdd6..419a964 100644 --- a/src/plugin/api/system/authentication/store.c +++ b/src/core/api/system/authentication/store.c @@ -11,7 +11,7 @@ * SPDX-License-Identifier: BSD-3-Clause */ #include "store.h" -#include "plugin/common.h" +#include "core/common.h" #include "umgmt/group.h" #include diff --git a/src/plugin/api/system/authentication/store.h b/src/core/api/system/authentication/store.h similarity index 96% rename from src/plugin/api/system/authentication/store.h rename to src/core/api/system/authentication/store.h index 71d34ee..6096261 100644 --- a/src/plugin/api/system/authentication/store.h +++ b/src/core/api/system/authentication/store.h @@ -13,7 +13,7 @@ #ifndef SYSTEM_PLUGIN_API_AUTHENTICATION_STORE_H #define SYSTEM_PLUGIN_API_AUTHENTICATION_STORE_H -#include "plugin/context.h" +#include "core/context.h" int system_authentication_store_user(system_ctx_t *ctx, system_local_user_element_t *head); int system_authentication_store_user_authorized_key(system_ctx_t *ctx, const char *user, system_authorized_key_element_t *head); diff --git a/src/plugin/api/system/change.c b/src/core/api/system/change.c similarity index 100% rename from src/plugin/api/system/change.c rename to src/core/api/system/change.c diff --git a/src/plugin/api/system/change.h b/src/core/api/system/change.h similarity index 96% rename from src/plugin/api/system/change.h rename to src/core/api/system/change.h index 01e003c..709be47 100644 --- a/src/plugin/api/system/change.h +++ b/src/core/api/system/change.h @@ -13,7 +13,7 @@ #ifndef SYSTEM_PLUGIN_API_CHANGE_H #define SYSTEM_PLUGIN_API_CHANGE_H -#include "plugin/context.h" +#include "core/context.h" #include diff --git a/src/plugin/api/system/check.c b/src/core/api/system/check.c similarity index 100% rename from src/plugin/api/system/check.c rename to src/core/api/system/check.c diff --git a/src/plugin/api/system/check.h b/src/core/api/system/check.h similarity index 93% rename from src/plugin/api/system/check.h rename to src/core/api/system/check.h index 4b2d5df..2b81dac 100644 --- a/src/plugin/api/system/check.h +++ b/src/core/api/system/check.h @@ -13,8 +13,8 @@ #ifndef SYSTEM_PLUGIN_API_CHECK_H #define SYSTEM_PLUGIN_API_CHECK_H -#include "plugin/common.h" -#include "plugin/context.h" +#include "core/common.h" +#include "core/context.h" #include diff --git a/src/plugin/api/system/dns_resolver/change.c b/src/core/api/system/dns_resolver/change.c similarity index 95% rename from src/plugin/api/system/dns_resolver/change.c rename to src/core/api/system/dns_resolver/change.c index 3c28834..429b1bb 100644 --- a/src/plugin/api/system/dns_resolver/change.c +++ b/src/core/api/system/dns_resolver/change.c @@ -16,15 +16,15 @@ #include "srpc/types.h" #include "store.h" #include "sysrepo_types.h" -#include "plugin/types.h" -#include "plugin/common.h" +#include "core/types.h" +#include "core/common.h" // data -#include "plugin/data/system/dns_resolver/server/list.h" -#include "plugin/data/system/dns_resolver/search/list.h" -#include "plugin/data/system/dns_resolver/search.h" -#include "plugin/data/system/dns_resolver/server.h" -#include "plugin/data/system/ip_address.h" +#include "core/data/system/dns_resolver/server/list.h" +#include "core/data/system/dns_resolver/search/list.h" +#include "core/data/system/dns_resolver/search.h" +#include "core/data/system/dns_resolver/server.h" +#include "core/data/system/ip_address.h" #include diff --git a/src/plugin/api/system/dns_resolver/change.h b/src/core/api/system/dns_resolver/change.h similarity index 97% rename from src/plugin/api/system/dns_resolver/change.h rename to src/core/api/system/dns_resolver/change.h index c6b0798..a111f1f 100644 --- a/src/plugin/api/system/dns_resolver/change.h +++ b/src/core/api/system/dns_resolver/change.h @@ -13,7 +13,7 @@ #ifndef SYSTEM_PLUGIN_API_DNS_RESOLVER_CHANGE_H #define SYSTEM_PLUGIN_API_DNS_RESOLVER_CHANGE_H -#include "plugin/context.h" +#include "core/context.h" #include diff --git a/src/plugin/api/system/dns_resolver/check.c b/src/core/api/system/dns_resolver/check.c similarity index 94% rename from src/plugin/api/system/dns_resolver/check.c rename to src/core/api/system/dns_resolver/check.c index a76db06..3086b74 100644 --- a/src/plugin/api/system/dns_resolver/check.c +++ b/src/core/api/system/dns_resolver/check.c @@ -13,10 +13,10 @@ #include "check.h" #include "load.h" #include "srpc/types.h" -#include "plugin/types.h" -#include "plugin/common.h" -#include "plugin/data/system/dns_resolver/search/list.h" -#include "plugin/data/system/dns_resolver/server/list.h" +#include "core/types.h" +#include "core/common.h" +#include "core/data/system/dns_resolver/search/list.h" +#include "core/data/system/dns_resolver/server/list.h" #include diff --git a/src/plugin/api/system/dns_resolver/check.h b/src/core/api/system/dns_resolver/check.h similarity index 92% rename from src/plugin/api/system/dns_resolver/check.h rename to src/core/api/system/dns_resolver/check.h index 2e7b422..182b309 100644 --- a/src/plugin/api/system/dns_resolver/check.h +++ b/src/core/api/system/dns_resolver/check.h @@ -13,8 +13,8 @@ #ifndef SYSTEM_PLUGIN_API_DNS_RESOLVER_CHECK_H #define SYSTEM_PLUGIN_API_DNS_RESOLVER_CHECK_H -#include "plugin/context.h" -#include "plugin/types.h" +#include "core/context.h" +#include "core/types.h" #include diff --git a/src/plugin/api/system/dns_resolver/load.c b/src/core/api/system/dns_resolver/load.c similarity index 95% rename from src/plugin/api/system/dns_resolver/load.c rename to src/core/api/system/dns_resolver/load.c index 6ec1500..30c9f90 100644 --- a/src/plugin/api/system/dns_resolver/load.c +++ b/src/core/api/system/dns_resolver/load.c @@ -11,13 +11,13 @@ * SPDX-License-Identifier: BSD-3-Clause */ #include "load.h" -#include "plugin/common.h" +#include "core/common.h" // data -#include "plugin/data/system/dns_resolver/server.h" -#include "plugin/data/system/dns_resolver/server/list.h" -#include "plugin/data/system/dns_resolver/search/list.h" -#include "plugin/data/system/ip_address.h" +#include "core/data/system/dns_resolver/server.h" +#include "core/data/system/dns_resolver/server/list.h" +#include "core/data/system/dns_resolver/search/list.h" +#include "core/data/system/ip_address.h" #include diff --git a/src/plugin/api/system/dns_resolver/load.h b/src/core/api/system/dns_resolver/load.h similarity index 92% rename from src/plugin/api/system/dns_resolver/load.h rename to src/core/api/system/dns_resolver/load.h index bd5b048..1e0f68c 100644 --- a/src/plugin/api/system/dns_resolver/load.h +++ b/src/core/api/system/dns_resolver/load.h @@ -13,8 +13,8 @@ #ifndef SYSTEM_PLUGIN_API_DNS_RESOLVER_LOAD_H #define SYSTEM_PLUGIN_API_DNS_RESOLVER_LOAD_H -#include "plugin/types.h" -#include "plugin/context.h" +#include "core/types.h" +#include "core/context.h" int system_dns_resolver_load_search(system_ctx_t *ctx, system_dns_search_element_t **head); int system_dns_resolver_load_server(system_ctx_t *ctx, system_dns_server_element_t **head); diff --git a/src/plugin/api/system/dns_resolver/store.c b/src/core/api/system/dns_resolver/store.c similarity index 99% rename from src/plugin/api/system/dns_resolver/store.c rename to src/core/api/system/dns_resolver/store.c index 790be71..72dcf63 100644 --- a/src/plugin/api/system/dns_resolver/store.c +++ b/src/core/api/system/dns_resolver/store.c @@ -11,7 +11,7 @@ * SPDX-License-Identifier: BSD-3-Clause */ #include "store.h" -#include "plugin/common.h" +#include "core/common.h" #include diff --git a/src/plugin/api/system/dns_resolver/store.h b/src/core/api/system/dns_resolver/store.h similarity index 92% rename from src/plugin/api/system/dns_resolver/store.h rename to src/core/api/system/dns_resolver/store.h index 8043809..6fd486d 100644 --- a/src/plugin/api/system/dns_resolver/store.h +++ b/src/core/api/system/dns_resolver/store.h @@ -13,8 +13,8 @@ #ifndef SYSTEM_PLUGIN_API_DNS_RESOLVER_STORE_H #define SYSTEM_PLUGIN_API_DNS_RESOLVER_STORE_H -#include "plugin/types.h" -#include "plugin/context.h" +#include "core/types.h" +#include "core/context.h" int system_dns_resolver_store_search(system_ctx_t *ctx, system_dns_search_element_t *head); int system_dns_resolver_store_server(system_ctx_t *ctx, system_dns_server_element_t *head); diff --git a/src/plugin/api/system/load.c b/src/core/api/system/load.c similarity index 100% rename from src/plugin/api/system/load.c rename to src/core/api/system/load.c diff --git a/src/plugin/api/system/load.h b/src/core/api/system/load.h similarity index 93% rename from src/plugin/api/system/load.h rename to src/core/api/system/load.h index 4f3a9a5..f2fb751 100644 --- a/src/plugin/api/system/load.h +++ b/src/core/api/system/load.h @@ -13,8 +13,8 @@ #ifndef SYSTEM_PLUGIN_API_LOAD_H #define SYSTEM_PLUGIN_API_LOAD_H -#include "plugin/common.h" -#include "plugin/context.h" +#include "core/common.h" +#include "core/context.h" int system_load_hostname(system_ctx_t *ctx, char buffer[SYSTEM_HOSTNAME_LENGTH_MAX]); int system_load_contact(system_ctx_t *ctx, char buffer[256]); diff --git a/src/plugin/api/system/ntp/change.c b/src/core/api/system/ntp/change.c similarity index 99% rename from src/plugin/api/system/ntp/change.c rename to src/core/api/system/ntp/change.c index ab24569..847cf84 100644 --- a/src/plugin/api/system/ntp/change.c +++ b/src/core/api/system/ntp/change.c @@ -11,13 +11,13 @@ * SPDX-License-Identifier: BSD-3-Clause */ #include "change.h" -#include "plugin/common.h" +#include "core/common.h" #include "libyang/tree_data.h" #include "sysrepo/xpath.h" #include "sysrepo_types.h" -#include "plugin/data/system/ntp/server.h" -#include "plugin/data/system/ntp/server/list.h" +#include "core/data/system/ntp/server.h" +#include "core/data/system/ntp/server/list.h" #include #include diff --git a/src/plugin/api/system/ntp/change.h b/src/core/api/system/ntp/change.h similarity index 95% rename from src/plugin/api/system/ntp/change.h rename to src/core/api/system/ntp/change.h index a43a714..3ad0f8f 100644 --- a/src/plugin/api/system/ntp/change.h +++ b/src/core/api/system/ntp/change.h @@ -13,8 +13,8 @@ #ifndef SYSTEM_PLUGIN_API_NTP_CHANGE_H #define SYSTEM_PLUGIN_API_NTP_CHANGE_H -#include "plugin/types.h" -#include "plugin/context.h" +#include "core/types.h" +#include "core/context.h" #include diff --git a/src/plugin/api/system/ntp/check.c b/src/core/api/system/ntp/check.c similarity index 95% rename from src/plugin/api/system/ntp/check.c rename to src/core/api/system/ntp/check.c index 00b729f..3475884 100644 --- a/src/plugin/api/system/ntp/check.c +++ b/src/core/api/system/ntp/check.c @@ -12,8 +12,8 @@ */ #include "check.h" #include "load.h" -#include "plugin/common.h" -#include "plugin/data/system/ntp/server/list.h" +#include "core/common.h" +#include "core/data/system/ntp/server/list.h" #include #include diff --git a/src/plugin/api/system/ntp/check.h b/src/core/api/system/ntp/check.h similarity index 91% rename from src/plugin/api/system/ntp/check.h rename to src/core/api/system/ntp/check.h index c88f42a..ea8b7c1 100644 --- a/src/plugin/api/system/ntp/check.h +++ b/src/core/api/system/ntp/check.h @@ -13,8 +13,8 @@ #ifndef SYSTEM_PLUGIN_API_NTP_CHECK_H #define SYSTEM_PLUGIN_API_NTP_CHECK_H -#include "plugin/types.h" -#include "plugin/context.h" +#include "core/types.h" +#include "core/context.h" #include diff --git a/src/plugin/api/system/ntp/load.c b/src/core/api/system/ntp/load.c similarity index 97% rename from src/plugin/api/system/ntp/load.c rename to src/core/api/system/ntp/load.c index 4d1e172..6991461 100644 --- a/src/plugin/api/system/ntp/load.c +++ b/src/core/api/system/ntp/load.c @@ -11,11 +11,11 @@ * SPDX-License-Identifier: BSD-3-Clause */ #include "load.h" -#include "plugin/common.h" +#include "core/common.h" // data -#include "plugin/data/system/ntp/server.h" -#include "plugin/data/system/ntp/server/list.h" +#include "core/data/system/ntp/server.h" +#include "core/data/system/ntp/server/list.h" #include #include diff --git a/src/plugin/api/system/ntp/load.h b/src/core/api/system/ntp/load.h similarity index 90% rename from src/plugin/api/system/ntp/load.h rename to src/core/api/system/ntp/load.h index 483fe3b..5339089 100644 --- a/src/plugin/api/system/ntp/load.h +++ b/src/core/api/system/ntp/load.h @@ -13,8 +13,8 @@ #ifndef SYSTEM_PLUGIN_API_NTP_LOAD_H #define SYSTEM_PLUGIN_API_NTP_LOAD_H -#include "plugin/types.h" -#include "plugin/context.h" +#include "core/types.h" +#include "core/context.h" int system_ntp_load_server(system_ctx_t *ctx, system_ntp_server_element_t **head); diff --git a/src/plugin/api/system/ntp/store.c b/src/core/api/system/ntp/store.c similarity index 98% rename from src/plugin/api/system/ntp/store.c rename to src/core/api/system/ntp/store.c index 8650a37..85c54f5 100644 --- a/src/plugin/api/system/ntp/store.c +++ b/src/core/api/system/ntp/store.c @@ -11,11 +11,11 @@ * SPDX-License-Identifier: BSD-3-Clause */ #include "store.h" -#include "plugin/common.h" -#include "plugin/context.h" +#include "core/common.h" +#include "core/context.h" #include "libyang/printer_data.h" #include "srpc/ly_tree.h" -#include "plugin/types.h" +#include "core/types.h" #include #include diff --git a/src/plugin/api/system/ntp/store.h b/src/core/api/system/ntp/store.h similarity index 90% rename from src/plugin/api/system/ntp/store.h rename to src/core/api/system/ntp/store.h index a5a6bf5..22b82b1 100644 --- a/src/plugin/api/system/ntp/store.h +++ b/src/core/api/system/ntp/store.h @@ -13,8 +13,8 @@ #ifndef SYSTEM_PLUGIN_API_NTP_STORE_H #define SYSTEM_PLUGIN_API_NTP_STORE_H -#include "plugin/types.h" -#include "plugin/context.h" +#include "core/types.h" +#include "core/context.h" int system_ntp_store_server(system_ctx_t *ctx, system_ntp_server_element_t *head); diff --git a/src/plugin/api/system/store.c b/src/core/api/system/store.c similarity index 98% rename from src/plugin/api/system/store.c rename to src/core/api/system/store.c index ea91cc8..0c51f37 100644 --- a/src/plugin/api/system/store.c +++ b/src/core/api/system/store.c @@ -11,7 +11,7 @@ * SPDX-License-Identifier: BSD-3-Clause */ #include "store.h" -#include "plugin/common.h" +#include "core/common.h" #include #include diff --git a/src/plugin/api/system/store.h b/src/core/api/system/store.h similarity index 96% rename from src/plugin/api/system/store.h rename to src/core/api/system/store.h index 2108809..570b2ce 100644 --- a/src/plugin/api/system/store.h +++ b/src/core/api/system/store.h @@ -13,7 +13,7 @@ #ifndef SYSTEM_PLUGIN_API_STORE_H #define SYSTEM_PLUGIN_API_STORE_H -#include "plugin/context.h" +#include "core/context.h" int system_store_hostname(system_ctx_t *ctx, const char *hostname); int system_store_contact(system_ctx_t *ctx, const char *contact); diff --git a/src/plugin/common.c b/src/core/common.c similarity index 100% rename from src/plugin/common.c rename to src/core/common.c diff --git a/src/plugin/common.h b/src/core/common.h similarity index 100% rename from src/plugin/common.h rename to src/core/common.h diff --git a/src/plugin/context.h b/src/core/context.h similarity index 98% rename from src/plugin/context.h rename to src/core/context.h index 1c8fc53..ae955ad 100644 --- a/src/plugin/context.h +++ b/src/core/context.h @@ -13,7 +13,7 @@ #ifndef SYSTEM_PLUGIN_CONTEXT_H #define SYSTEM_PLUGIN_CONTEXT_H -#include "plugin/types.h" +#include "core/types.h" #include "srpc/types.h" #include "umgmt/types.h" #include diff --git a/src/plugin/data/system/authentication/authorized_key.c b/src/core/data/system/authentication/authorized_key.c similarity index 100% rename from src/plugin/data/system/authentication/authorized_key.c rename to src/core/data/system/authentication/authorized_key.c diff --git a/src/plugin/data/system/authentication/authorized_key.h b/src/core/data/system/authentication/authorized_key.h similarity index 97% rename from src/plugin/data/system/authentication/authorized_key.h rename to src/core/data/system/authentication/authorized_key.h index 067a8bb..67955e9 100644 --- a/src/plugin/data/system/authentication/authorized_key.h +++ b/src/core/data/system/authentication/authorized_key.h @@ -13,7 +13,7 @@ #ifndef SYSTEM_PLUGIN_DATA_AUTHENTICATION_AUTHORIZED_KEY_H #define SYSTEM_PLUGIN_DATA_AUTHENTICATION_AUTHORIZED_KEY_H -#include "plugin/types.h" +#include "core/types.h" void system_authorized_key_init(system_authorized_key_t *key); int system_authorized_key_set_name(system_authorized_key_t *key, const char *name); diff --git a/src/plugin/data/system/authentication/authorized_key/list.c b/src/core/data/system/authentication/authorized_key/list.c similarity index 97% rename from src/plugin/data/system/authentication/authorized_key/list.c rename to src/core/data/system/authentication/authorized_key/list.c index 2b388f2..d7fe070 100644 --- a/src/plugin/data/system/authentication/authorized_key/list.c +++ b/src/core/data/system/authentication/authorized_key/list.c @@ -11,7 +11,7 @@ * SPDX-License-Identifier: BSD-3-Clause */ #include "list.h" -#include "plugin/data/system/authentication/authorized_key.h" +#include "core/data/system/authentication/authorized_key.h" #include #include diff --git a/src/plugin/data/system/authentication/authorized_key/list.h b/src/core/data/system/authentication/authorized_key/list.h similarity index 97% rename from src/plugin/data/system/authentication/authorized_key/list.h rename to src/core/data/system/authentication/authorized_key/list.h index 3eda85c..6a1f29d 100644 --- a/src/plugin/data/system/authentication/authorized_key/list.h +++ b/src/core/data/system/authentication/authorized_key/list.h @@ -13,7 +13,7 @@ #ifndef SYSTEM_PLUGIN_DATA_AUTHENTICATION_AUTHORIZED_KEY_LIST_H #define SYSTEM_PLUGIN_DATA_AUTHENTICATION_AUTHORIZED_KEY_LIST_H -#include "plugin/types.h" +#include "core/types.h" void system_authorized_key_list_init(system_authorized_key_element_t **head); int system_authorized_key_list_add(system_authorized_key_element_t **head, system_authorized_key_t key); diff --git a/src/plugin/data/system/authentication/local_user.c b/src/core/data/system/authentication/local_user.c similarity index 95% rename from src/plugin/data/system/authentication/local_user.c rename to src/core/data/system/authentication/local_user.c index e43b3a8..a695f49 100644 --- a/src/plugin/data/system/authentication/local_user.c +++ b/src/core/data/system/authentication/local_user.c @@ -11,7 +11,7 @@ * SPDX-License-Identifier: BSD-3-Clause */ #include "local_user.h" -#include "plugin/data/system/authentication/authorized_key/list.h" +#include "core/data/system/authentication/authorized_key/list.h" #include #include diff --git a/src/plugin/data/system/authentication/local_user.h b/src/core/data/system/authentication/local_user.h similarity index 96% rename from src/plugin/data/system/authentication/local_user.h rename to src/core/data/system/authentication/local_user.h index 556bd67..c4075b5 100644 --- a/src/plugin/data/system/authentication/local_user.h +++ b/src/core/data/system/authentication/local_user.h @@ -13,7 +13,7 @@ #ifndef SYSTEM_PLUGIN_DATA_AUTHENTICATION_LOCAL_USER_H #define SYSTEM_PLUGIN_DATA_AUTHENTICATION_LOCAL_USER_H -#include "plugin/types.h" +#include "core/types.h" void system_local_user_init(system_local_user_t *user); int system_local_user_set_name(system_local_user_t *user, const char *name); diff --git a/src/plugin/data/system/authentication/local_user/list.c b/src/core/data/system/authentication/local_user/list.c similarity index 97% rename from src/plugin/data/system/authentication/local_user/list.c rename to src/core/data/system/authentication/local_user/list.c index 6ee7b60..72d2c90 100644 --- a/src/plugin/data/system/authentication/local_user/list.c +++ b/src/core/data/system/authentication/local_user/list.c @@ -11,7 +11,7 @@ * SPDX-License-Identifier: BSD-3-Clause */ #include "list.h" -#include "plugin/data/system/authentication/local_user.h" +#include "core/data/system/authentication/local_user.h" #include #include diff --git a/src/plugin/data/system/authentication/local_user/list.h b/src/core/data/system/authentication/local_user/list.h similarity index 97% rename from src/plugin/data/system/authentication/local_user/list.h rename to src/core/data/system/authentication/local_user/list.h index b42f305..777cbf2 100644 --- a/src/plugin/data/system/authentication/local_user/list.h +++ b/src/core/data/system/authentication/local_user/list.h @@ -13,7 +13,7 @@ #ifndef SYSTEM_PLUGIN_DATA_AUTHENTICATION_LOCAL_USER_LIST_H #define SYSTEM_PLUGIN_DATA_AUTHENTICATION_LOCAL_USER_LIST_H -#include "plugin/types.h" +#include "core/types.h" void system_local_user_list_init(system_local_user_element_t **head); int system_local_user_list_add(system_local_user_element_t **head, system_local_user_t user); diff --git a/src/plugin/data/system/dns_resolver/search.c b/src/core/data/system/dns_resolver/search.c similarity index 100% rename from src/plugin/data/system/dns_resolver/search.c rename to src/core/data/system/dns_resolver/search.c diff --git a/src/plugin/data/system/dns_resolver/search.h b/src/core/data/system/dns_resolver/search.h similarity index 96% rename from src/plugin/data/system/dns_resolver/search.h rename to src/core/data/system/dns_resolver/search.h index d4a0e4a..76376b0 100644 --- a/src/plugin/data/system/dns_resolver/search.h +++ b/src/core/data/system/dns_resolver/search.h @@ -13,7 +13,7 @@ #ifndef SYSTEM_PLUGIN_DATA_DNS_RESOLVER_SEARCH_H #define SYSTEM_PLUGIN_DATA_DNS_RESOLVER_SEARCH_H -#include "plugin/types.h" +#include "core/types.h" void system_dns_search_init(system_dns_search_t *search); int system_dns_search_set_domain(system_dns_search_t *search, const char *domain); diff --git a/src/plugin/data/system/dns_resolver/search/list.c b/src/core/data/system/dns_resolver/search/list.c similarity index 97% rename from src/plugin/data/system/dns_resolver/search/list.c rename to src/core/data/system/dns_resolver/search/list.c index e358233..a2c15dc 100644 --- a/src/plugin/data/system/dns_resolver/search/list.c +++ b/src/core/data/system/dns_resolver/search/list.c @@ -11,7 +11,7 @@ * SPDX-License-Identifier: BSD-3-Clause */ #include "list.h" -#include "plugin/data/system/dns_resolver/search.h" +#include "core/data/system/dns_resolver/search.h" #include #include diff --git a/src/plugin/data/system/dns_resolver/search/list.h b/src/core/data/system/dns_resolver/search/list.h similarity index 97% rename from src/plugin/data/system/dns_resolver/search/list.h rename to src/core/data/system/dns_resolver/search/list.h index c815db9..5e276b0 100644 --- a/src/plugin/data/system/dns_resolver/search/list.h +++ b/src/core/data/system/dns_resolver/search/list.h @@ -13,7 +13,7 @@ #ifndef SYSTEM_PLUGIN_DATA_DNS_RESOLVER_SEARCH_LIST_H #define SYSTEM_PLUGIN_DATA_DNS_RESOLVER_SEARCH_LIST_H -#include "plugin/types.h" +#include "core/types.h" void system_dns_search_list_init(system_dns_search_element_t **head); int system_dns_search_list_add(system_dns_search_element_t **head, system_dns_search_t search); diff --git a/src/plugin/data/system/dns_resolver/server.c b/src/core/data/system/dns_resolver/server.c similarity index 100% rename from src/plugin/data/system/dns_resolver/server.c rename to src/core/data/system/dns_resolver/server.c diff --git a/src/plugin/data/system/dns_resolver/server.h b/src/core/data/system/dns_resolver/server.h similarity index 97% rename from src/plugin/data/system/dns_resolver/server.h rename to src/core/data/system/dns_resolver/server.h index b39d640..69f6da0 100644 --- a/src/plugin/data/system/dns_resolver/server.h +++ b/src/core/data/system/dns_resolver/server.h @@ -13,7 +13,7 @@ #ifndef SYSTEM_PLUGIN_DATA_DNS_RESOLVER_SERVER_H #define SYSTEM_PLUGIN_DATA_DNS_RESOLVER_SERVER_H -#include "plugin/types.h" +#include "core/types.h" void system_dns_server_init(system_dns_server_t *server); int system_dns_server_set_name(system_dns_server_t *server, const char *name); diff --git a/src/plugin/data/system/dns_resolver/server/list.c b/src/core/data/system/dns_resolver/server/list.c similarity index 96% rename from src/plugin/data/system/dns_resolver/server/list.c rename to src/core/data/system/dns_resolver/server/list.c index 1935e1f..8111085 100644 --- a/src/plugin/data/system/dns_resolver/server/list.c +++ b/src/core/data/system/dns_resolver/server/list.c @@ -11,8 +11,8 @@ * SPDX-License-Identifier: BSD-3-Clause */ #include "list.h" -#include "plugin/data/system/dns_resolver/server.h" -#include "plugin/types.h" +#include "core/data/system/dns_resolver/server.h" +#include "core/types.h" #include #include diff --git a/src/plugin/data/system/dns_resolver/server/list.h b/src/core/data/system/dns_resolver/server/list.h similarity index 97% rename from src/plugin/data/system/dns_resolver/server/list.h rename to src/core/data/system/dns_resolver/server/list.h index 0a8e29f..7d6fb0e 100644 --- a/src/plugin/data/system/dns_resolver/server/list.h +++ b/src/core/data/system/dns_resolver/server/list.h @@ -13,7 +13,7 @@ #ifndef SYSTEM_PLUGIN_DATA_DNS_RESOLVER_SERVER_LIST_H #define SYSTEM_PLUGIN_DATA_DNS_RESOLVER_SERVER_LIST_H -#include "plugin/types.h" +#include "core/types.h" void system_dns_server_list_init(system_dns_server_element_t **head); int system_dns_server_list_add(system_dns_server_element_t **head, system_dns_server_t server); diff --git a/src/plugin/data/system/ip_address.c b/src/core/data/system/ip_address.c similarity index 100% rename from src/plugin/data/system/ip_address.c rename to src/core/data/system/ip_address.c diff --git a/src/plugin/data/system/ip_address.h b/src/core/data/system/ip_address.h similarity index 96% rename from src/plugin/data/system/ip_address.h rename to src/core/data/system/ip_address.h index 5c35cc1..edc670b 100644 --- a/src/plugin/data/system/ip_address.h +++ b/src/core/data/system/ip_address.h @@ -13,7 +13,7 @@ #ifndef SYSTEM_PLUGIN_DATA_IP_ADDRESS_H #define SYSTEM_PLUGIN_DATA_IP_ADDRESS_H -#include "plugin/types.h" +#include "core/types.h" void system_ip_address_init(system_ip_address_t *address); int system_ip_address_to_str(system_ip_address_t *address, char *buffer, const unsigned int buffer_size); diff --git a/src/plugin/data/system/ntp/server.c b/src/core/data/system/ntp/server.c similarity index 100% rename from src/plugin/data/system/ntp/server.c rename to src/core/data/system/ntp/server.c diff --git a/src/plugin/data/system/ntp/server.h b/src/core/data/system/ntp/server.h similarity index 97% rename from src/plugin/data/system/ntp/server.h rename to src/core/data/system/ntp/server.h index 182aec4..e07adf3 100644 --- a/src/plugin/data/system/ntp/server.h +++ b/src/core/data/system/ntp/server.h @@ -13,7 +13,7 @@ #ifndef SYSTEM_PLUGIN_DATA_NTP_SERVER_H #define SYSTEM_PLUGIN_DATA_NTP_SERVER_H -#include "plugin/types.h" +#include "core/types.h" void system_ntp_server_init(system_ntp_server_t *server); int system_ntp_server_set_name(system_ntp_server_t *server, const char *name); diff --git a/src/plugin/data/system/ntp/server/list.c b/src/core/data/system/ntp/server/list.c similarity index 97% rename from src/plugin/data/system/ntp/server/list.c rename to src/core/data/system/ntp/server/list.c index 9cfb29a..c8d8f22 100644 --- a/src/plugin/data/system/ntp/server/list.c +++ b/src/core/data/system/ntp/server/list.c @@ -11,8 +11,8 @@ * SPDX-License-Identifier: BSD-3-Clause */ #include "list.h" -#include "plugin/data/system/ntp/server.h" -#include "plugin/types.h" +#include "core/data/system/ntp/server.h" +#include "core/types.h" #include #include diff --git a/src/plugin/data/system/ntp/server/list.h b/src/core/data/system/ntp/server/list.h similarity index 97% rename from src/plugin/data/system/ntp/server/list.h rename to src/core/data/system/ntp/server/list.h index 28303e8..7e4f293 100644 --- a/src/plugin/data/system/ntp/server/list.h +++ b/src/core/data/system/ntp/server/list.h @@ -13,7 +13,7 @@ #ifndef SYSTEM_PLUGIN_DATA_NTP_SERVER_LIST_H #define SYSTEM_PLUGIN_DATA_NTP_SERVER_LIST_H -#include "plugin/types.h" +#include "core/types.h" void system_ntp_server_list_init(system_ntp_server_element_t **head); int system_ntp_server_list_add(system_ntp_server_element_t **head, system_ntp_server_t server); diff --git a/src/plugin/ly_tree.c b/src/core/ly_tree.c similarity index 99% rename from src/plugin/ly_tree.c rename to src/core/ly_tree.c index 6cb3ac1..3f9f375 100644 --- a/src/plugin/ly_tree.c +++ b/src/core/ly_tree.c @@ -10,8 +10,8 @@ * * SPDX-License-Identifier: BSD-3-Clause */ -#include "plugin/ly_tree.h" -#include "plugin/common.h" +#include "core/ly_tree.h" +#include "core/common.h" #include #include diff --git a/src/plugin/ly_tree.h b/src/core/ly_tree.h similarity index 100% rename from src/plugin/ly_tree.h rename to src/core/ly_tree.h diff --git a/src/plugin/startup/load.c b/src/core/startup/load.c similarity index 96% rename from src/plugin/startup/load.c rename to src/core/startup/load.c index 045d110..e045835 100644 --- a/src/plugin/startup/load.c +++ b/src/core/startup/load.c @@ -11,26 +11,26 @@ * SPDX-License-Identifier: BSD-3-Clause */ #include "load.h" -#include "plugin/common.h" -#include "plugin/context.h" -#include "plugin/ly_tree.h" +#include "core/common.h" +#include "core/context.h" +#include "core/ly_tree.h" // API for getting system data #include "srpc/common.h" #include "srpc/feature_status.h" #include "srpc/ly_tree.h" -#include "plugin/api/system/load.h" -#include "plugin/api/system/authentication/load.h" -#include "plugin/api/system/dns_resolver/load.h" +#include "core/api/system/load.h" +#include "core/api/system/authentication/load.h" +#include "core/api/system/dns_resolver/load.h" // data manipulation -#include "plugin/api/system/ntp/load.h" -#include "plugin/data/system/authentication/authorized_key/list.h" -#include "plugin/data/system/authentication/local_user/list.h" -#include "plugin/data/system/ip_address.h" -#include "plugin/data/system/dns_resolver/search/list.h" -#include "plugin/data/system/dns_resolver/server/list.h" -#include "plugin/data/system/ntp/server/list.h" +#include "core/api/system/ntp/load.h" +#include "core/data/system/authentication/authorized_key/list.h" +#include "core/data/system/authentication/local_user/list.h" +#include "core/data/system/ip_address.h" +#include "core/data/system/dns_resolver/search/list.h" +#include "core/data/system/dns_resolver/server/list.h" +#include "core/data/system/ntp/server/list.h" #include #include diff --git a/src/plugin/startup/load.h b/src/core/startup/load.h similarity index 94% rename from src/plugin/startup/load.h rename to src/core/startup/load.h index e4da4c6..ba68016 100644 --- a/src/plugin/startup/load.h +++ b/src/core/startup/load.h @@ -13,7 +13,7 @@ #ifndef SYSTEM_PLUGIN_STARTUP_LOAD_H #define SYSTEM_PLUGIN_STARTUP_LOAD_H -#include "plugin/context.h" +#include "core/context.h" int system_startup_load_data(system_ctx_t *ctx, sr_session_ctx_t *session); diff --git a/src/plugin/startup/store.c b/src/core/startup/store.c similarity index 96% rename from src/plugin/startup/store.c rename to src/core/startup/store.c index d0d863e..c3edeac 100644 --- a/src/plugin/startup/store.c +++ b/src/core/startup/store.c @@ -11,38 +11,38 @@ * SPDX-License-Identifier: BSD-3-Clause */ #include "store.h" -#include "plugin/common.h" +#include "core/common.h" #include "libyang/printer_data.h" -#include "plugin/ly_tree.h" +#include "core/ly_tree.h" // API for getting system data #include "srpc/common.h" #include "srpc/feature_status.h" #include "srpc/ly_tree.h" #include "srpc/types.h" -#include "plugin/api/system/authentication/check.h" -#include "plugin/api/system/authentication/load.h" -#include "plugin/api/system/check.h" -#include "plugin/api/system/ntp/check.h" -#include "plugin/api/system/ntp/store.h" -#include "plugin/api/system/store.h" -#include "plugin/api/system/dns_resolver/store.h" -#include "plugin/api/system/dns_resolver/check.h" -#include "plugin/api/system/authentication/store.h" +#include "core/api/system/authentication/check.h" +#include "core/api/system/authentication/load.h" +#include "core/api/system/check.h" +#include "core/api/system/ntp/check.h" +#include "core/api/system/ntp/store.h" +#include "core/api/system/store.h" +#include "core/api/system/dns_resolver/store.h" +#include "core/api/system/dns_resolver/check.h" +#include "core/api/system/authentication/store.h" // data manipulation -#include "plugin/data/system/authentication/authorized_key.h" -#include "plugin/data/system/authentication/authorized_key/list.h" -#include "plugin/data/system/authentication/local_user.h" -#include "plugin/data/system/authentication/local_user/list.h" -#include "plugin/data/system/ip_address.h" -#include "plugin/data/system/dns_resolver/search.h" -#include "plugin/data/system/dns_resolver/search/list.h" -#include "plugin/data/system/dns_resolver/server.h" -#include "plugin/data/system/dns_resolver/server/list.h" -#include "plugin/data/system/ntp/server.h" -#include "plugin/data/system/ntp/server/list.h" -#include "plugin/types.h" +#include "core/data/system/authentication/authorized_key.h" +#include "core/data/system/authentication/authorized_key/list.h" +#include "core/data/system/authentication/local_user.h" +#include "core/data/system/authentication/local_user/list.h" +#include "core/data/system/ip_address.h" +#include "core/data/system/dns_resolver/search.h" +#include "core/data/system/dns_resolver/search/list.h" +#include "core/data/system/dns_resolver/server.h" +#include "core/data/system/dns_resolver/server/list.h" +#include "core/data/system/ntp/server.h" +#include "core/data/system/ntp/server/list.h" +#include "core/types.h" #include #include diff --git a/src/plugin/startup/store.h b/src/core/startup/store.h similarity index 94% rename from src/plugin/startup/store.h rename to src/core/startup/store.h index ab9aed1..954e287 100644 --- a/src/plugin/startup/store.h +++ b/src/core/startup/store.h @@ -13,7 +13,7 @@ #ifndef SYSTEM_PLUGIN_STARTUP_STORE_H #define SYSTEM_PLUGIN_STARTUP_STORE_H -#include "plugin/context.h" +#include "core/context.h" int system_startup_store_data(system_ctx_t *ctx, sr_session_ctx_t *session); diff --git a/src/plugin/subscription/change.c b/src/core/subscription/change.c similarity index 96% rename from src/plugin/subscription/change.c rename to src/core/subscription/change.c index 2014b21..6ab77cb 100644 --- a/src/plugin/subscription/change.c +++ b/src/core/subscription/change.c @@ -11,37 +11,37 @@ * SPDX-License-Identifier: BSD-3-Clause */ #include "change.h" -#include "plugin/common.h" -#include "plugin/context.h" +#include "core/common.h" +#include "core/context.h" #include "libyang/printer_data.h" -#include "plugin/ly_tree.h" +#include "core/ly_tree.h" #include "srpc/common.h" #include "srpc/feature_status.h" #include "srpc/ly_tree.h" #include "sysrepo_types.h" -#include "plugin/api/system/authentication/load.h" -#include "plugin/data/system/authentication/local_user/list.h" -#include "plugin/data/system/dns_resolver/search/list.h" -#include "plugin/data/system/dns_resolver/server/list.h" -#include "plugin/data/system/ntp/server/list.h" -#include "plugin/types.h" +#include "core/api/system/authentication/load.h" +#include "core/data/system/authentication/local_user/list.h" +#include "core/data/system/dns_resolver/search/list.h" +#include "core/data/system/dns_resolver/server/list.h" +#include "core/data/system/ntp/server/list.h" +#include "core/types.h" #include "umgmt/db.h" // Load API -#include "plugin/api/system/load.h" -#include "plugin/api/system/dns_resolver/load.h" -#include "plugin/api/system/ntp/load.h" +#include "core/api/system/load.h" +#include "core/api/system/dns_resolver/load.h" +#include "core/api/system/ntp/load.h" // Change API -#include "plugin/api/system/change.h" -#include "plugin/api/system/dns_resolver/change.h" -#include "plugin/api/system/ntp/change.h" -#include "plugin/api/system/authentication/change.h" +#include "core/api/system/change.h" +#include "core/api/system/dns_resolver/change.h" +#include "core/api/system/ntp/change.h" +#include "core/api/system/authentication/change.h" // Store API -#include "plugin/api/system/store.h" -#include "plugin/api/system/dns_resolver/store.h" -#include "plugin/api/system/ntp/store.h" +#include "core/api/system/store.h" +#include "core/api/system/dns_resolver/store.h" +#include "core/api/system/ntp/store.h" #include #include diff --git a/src/plugin/subscription/change.h b/src/core/subscription/change.h similarity index 100% rename from src/plugin/subscription/change.h rename to src/core/subscription/change.h diff --git a/src/plugin/subscription/operational.c b/src/core/subscription/operational.c similarity index 99% rename from src/plugin/subscription/operational.c rename to src/core/subscription/operational.c index 9785677..b85bcd3 100644 --- a/src/plugin/subscription/operational.c +++ b/src/core/subscription/operational.c @@ -11,8 +11,8 @@ * SPDX-License-Identifier: BSD-3-Clause */ #include "operational.h" -#include "plugin/common.h" -#include "plugin/ly_tree.h" +#include "core/common.h" +#include "core/ly_tree.h" #include #include diff --git a/src/plugin/subscription/operational.h b/src/core/subscription/operational.h similarity index 100% rename from src/plugin/subscription/operational.h rename to src/core/subscription/operational.h diff --git a/src/plugin/subscription/rpc.c b/src/core/subscription/rpc.c similarity index 98% rename from src/plugin/subscription/rpc.c rename to src/core/subscription/rpc.c index 9f33c58..60f6d24 100644 --- a/src/plugin/subscription/rpc.c +++ b/src/core/subscription/rpc.c @@ -11,7 +11,7 @@ * SPDX-License-Identifier: BSD-3-Clause */ #include "rpc.h" -#include "plugin/common.h" +#include "core/common.h" #include #include diff --git a/src/plugin/subscription/rpc.h b/src/core/subscription/rpc.h similarity index 100% rename from src/plugin/subscription/rpc.h rename to src/core/subscription/rpc.h diff --git a/src/plugin/types.h b/src/core/types.h similarity index 100% rename from src/plugin/types.h rename to src/core/types.h diff --git a/src/plugin.c b/src/plugin.c index de65254..5d435ba 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -11,8 +11,8 @@ * SPDX-License-Identifier: BSD-3-Clause */ #include "plugin.h" -#include "plugin/common.h" -#include "plugin/context.h" +#include "core/common.h" +#include "core/context.h" // stdlib #include @@ -28,13 +28,13 @@ #include "srpc/types.h" // startup -#include "plugin/startup/load.h" -#include "plugin/startup/store.h" +#include "core/startup/load.h" +#include "core/startup/store.h" // subs -#include "plugin/subscription/change.h" -#include "plugin/subscription/operational.h" -#include "plugin/subscription/rpc.h" +#include "core/subscription/change.h" +#include "core/subscription/operational.h" +#include "core/subscription/rpc.h" #include diff --git a/tests/system_utest.c b/tests/system_utest.c index 8e506cc..e3c9b97 100644 --- a/tests/system_utest.c +++ b/tests/system_utest.c @@ -12,19 +12,19 @@ #include // plugin code -#include "plugin/context.h" +#include "core/context.h" // store API -#include "plugin/api/system/store.h" +#include "core/api/system/store.h" // load API -#include "plugin/api/system/load.h" +#include "core/api/system/load.h" // check API -#include "plugin/api/system/check.h" +#include "core/api/system/check.h" // ntp load API -#include "plugin/api/system/dns_resolver/load.h" +#include "core/api/system/dns_resolver/load.h" // init functionality static int setup(void **state); From 46609918f50a84a89c1ffe365260caa52147982b Mon Sep 17 00:00:00 2001 From: Mateo Cindric Date: Tue, 3 Jan 2023 15:32:28 +0000 Subject: [PATCH 03/25] Split project into multiple plugins --- CMakeLists.txt | 47 +++++++----------- src/main.c | 1 + src/plugins/ietf-system-augeas/CMakeLists.txt | 40 ++++++++++++++++ src/plugins/ietf-system-augeas/plugin.c | 11 +++++ src/plugins/ietf-system-augeas/plugin.h | 21 ++++++++ src/plugins/ietf-system/CMakeLists.txt | 48 +++++++++++++++++++ src/{ => plugins/ietf-system}/plugin.c | 0 src/{ => plugins/ietf-system}/plugin.h | 0 tests/Tests.cmake | 2 +- 9 files changed, 139 insertions(+), 31 deletions(-) create mode 100644 src/plugins/ietf-system-augeas/CMakeLists.txt create mode 100644 src/plugins/ietf-system-augeas/plugin.c create mode 100644 src/plugins/ietf-system-augeas/plugin.h create mode 100644 src/plugins/ietf-system/CMakeLists.txt rename src/{ => plugins/ietf-system}/plugin.c (100%) rename src/{ => plugins/ietf-system}/plugin.h (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index daf4efa..1ffbeea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,9 +3,9 @@ project(sysrepo-plugin-system C) include(CompileOptions.cmake) -set(PLUGIN_LIRBARY_NAME srplg-ietf-system-core) +set(PLUGIN_CORE_LIBRARY_NAME "srplg-ietf-system-core") -set(PLUGIN 0 CACHE BOOL "Build a plugin") +# set(PLUGIN 0 CACHE BOOL "Build a plugin") option(ENABLE_BUILD_TESTS, "Build tests" OFF) # local includes @@ -14,13 +14,13 @@ include_directories( ${CMAKE_SOURCE_DIR}/deps/uthash/include ) -# first - find needed and optional packages +# find needed and optional packages set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules") find_package(SYSREPO REQUIRED) find_package(LIBYANG REQUIRED) find_package(SRPC REQUIRED) find_package(UMGMT REQUIRED) -find_package(LIBSYSTEMD) +find_package(LIBSYSTEMD REQUIRED) find_package(AUGYANG) # package includes @@ -29,11 +29,12 @@ include_directories( ${LIBYANG_INCLUDE_DIRS} ${SRPC_INCLUDE_DIRS} ${UMGMT_INCLUDE_DIRS} + ${SYSTEMD_INCLUDE_DIRS} ) # sources set( - SOURCES + CORE_SOURCES src/core/common.c src/core/ly_tree.c @@ -79,33 +80,19 @@ set( src/core/api/system/authentication/change.c ) -# build plugin core library -add_library(${PLUGIN_LIRBARY_NAME} STATIC ${SOURCES}) -install(TARGETS ${PLUGIN_LIRBARY_NAME} DESTINATION lib) - -# if(SYSTEMD_FOUND) -# if(DEFINED SYSTEMD_IFINDEX) -# add_compile_definitions(SYSTEMD_IFINDEX=${SYSTEMD_IFINDEX}) -# else() -# message(SEND_ERROR "No SYSTEMD_IFINDEX value set for default interface index to use with systemd... Unable to build without it") -# endif() - -# add_compile_definitions(SYSTEMD) -# target_link_libraries( -# ${CMAKE_PROJECT_NAME} -# ${SYSTEMD_LIBRARIES} -# ) -# include_directories( -# ${SYSTEMD_INCLUDE_DIRS} -# ) -# endif() +# build plugin static library +add_library(${PLUGIN_CORE_LIBRARY_NAME} STATIC ${CORE_SOURCES}) +install(TARGETS ${PLUGIN_CORE_LIBRARY_NAME} DESTINATION lib) + +# add main plugin to the build process +add_subdirectory("src/plugins/ietf-system") # # augyang support -# if(AUGYANG_FOUND) -# add_compile_definitions(AUGYANG) -# else(AUGYANG_FOUND) -# message(WARNING "AUGYANG not found - augeas support will be disabled") -# endif() +if(AUGYANG_FOUND) + add_subdirectory("src/plugins/ietf-system-augeas") +else(AUGYANG_FOUND) + message(WARNING "AUGYANG not found - disabled build of the augeas specific plugin") +endif() if(ENABLE_BUILD_TESTS) find_package(CMOCKA REQUIRED) diff --git a/src/main.c b/src/main.c index 4b70f23..fde1178 100644 --- a/src/main.c +++ b/src/main.c @@ -16,6 +16,7 @@ volatile int exit_application = 0; +// extern needed data to build the plugin executable extern const char *PLUGIN_NAME; extern int sr_plugin_init_cb(sr_session_ctx_t *session, void **private_data); extern void sr_plugin_cleanup_cb(sr_session_ctx_t *session, void *private_data); diff --git a/src/plugins/ietf-system-augeas/CMakeLists.txt b/src/plugins/ietf-system-augeas/CMakeLists.txt new file mode 100644 index 0000000..89808e8 --- /dev/null +++ b/src/plugins/ietf-system-augeas/CMakeLists.txt @@ -0,0 +1,40 @@ +cmake_minimum_required(VERSION 3.0) + +set(PLUGIN_LIBRARY_NAME "srplg-ietf-system-augeas") +set(PLUGIN_EXECUTABLE_NAME "ietf-system-augeas-plugin") + +set( + PLUGIN_SOURCES + + plugin.c +) + +# add plugin as a sysrepo-plugind library +add_library( + ${PLUGIN_LIBRARY_NAME} + MODULE + ${PLUGIN_SOURCES} +) + +add_executable( + ${PLUGIN_EXECUTABLE_NAME} + + ${PLUGIN_SOURCES} + ${CMAKE_SOURCE_DIR}/src/main.c +) + +target_link_libraries( + ${PLUGIN_EXECUTABLE_NAME} + + # link against the core plugin library + ${PLUGIN_CORE_LIBRARY_NAME} + + # link other external libraries + ${SYSREPO_LIBRARIES} + ${LIBYANG_LIBRARIES} + ${SRPC_LIBRARIES} + ${UMGMT_LIBRARIES} +) + +install(TARGETS ${PLUGIN_LIBRARY_NAME} DESTINATION lib) +install(TARGETS ${PLUGIN_EXECUTABLE_NAME} DESTINATION bin) \ No newline at end of file diff --git a/src/plugins/ietf-system-augeas/plugin.c b/src/plugins/ietf-system-augeas/plugin.c new file mode 100644 index 0000000..c9dffa0 --- /dev/null +++ b/src/plugins/ietf-system-augeas/plugin.c @@ -0,0 +1,11 @@ +#include "plugin.h" + +int sr_plugin_init_cb(sr_session_ctx_t *session, void **private_data) +{ + int error = SR_ERR_OK; + return error; +} + +void sr_plugin_cleanup_cb(sr_session_ctx_t *session, void *private_data) +{ +} diff --git a/src/plugins/ietf-system-augeas/plugin.h b/src/plugins/ietf-system-augeas/plugin.h new file mode 100644 index 0000000..b9c55e2 --- /dev/null +++ b/src/plugins/ietf-system-augeas/plugin.h @@ -0,0 +1,21 @@ +/* + * telekom / sysrepo-plugin-system + * + * This program is made available under the terms of the + * BSD 3-Clause license which is available at + * https://opensource.org/licenses/BSD-3-Clause + * + * SPDX-FileCopyrightText: 2022 Deutsche Telekom AG + * SPDX-FileContributor: Sartura Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ +#ifndef SYSTEM_AUGEAS_PLUGIN_H +#define SYSTEM_AUGEAS_PLUGIN_H + +#include + +int sr_plugin_init_cb(sr_session_ctx_t *session, void **private_data); +void sr_plugin_cleanup_cb(sr_session_ctx_t *session, void *private_data); + +#endif // SYSTEM_AUGEAS_PLUGIN_H diff --git a/src/plugins/ietf-system/CMakeLists.txt b/src/plugins/ietf-system/CMakeLists.txt new file mode 100644 index 0000000..f2b7702 --- /dev/null +++ b/src/plugins/ietf-system/CMakeLists.txt @@ -0,0 +1,48 @@ +cmake_minimum_required(VERSION 3.0) + +set(PLUGIN_LIBRARY_NAME "srplg-ietf-system") +set(PLUGIN_EXECUTABLE_NAME "ietf-system-plugin") + +set( + PLUGIN_SOURCES + + plugin.c +) + +# check for systemd flag +if(DEFINED SYSTEMD_IFINDEX) + add_compile_definitions(SYSTEMD_IFINDEX=${SYSTEMD_IFINDEX}) +else() + message(SEND_ERROR "No SYSTEMD_IFINDEX value set for default interface index to use with systemd... Unable to build without it") +endif() + +# add plugin as a sysrepo-plugind library +add_library( + ${PLUGIN_LIBRARY_NAME} + MODULE + ${PLUGIN_SOURCES} +) + +add_executable( + ${PLUGIN_EXECUTABLE_NAME} + + ${PLUGIN_SOURCES} + ${CMAKE_SOURCE_DIR}/src/main.c +) + +target_link_libraries( + ${PLUGIN_EXECUTABLE_NAME} + + # link against the core plugin library + ${PLUGIN_CORE_LIBRARY_NAME} + + # link other external libraries + ${SYSREPO_LIBRARIES} + ${LIBYANG_LIBRARIES} + ${SRPC_LIBRARIES} + ${UMGMT_LIBRARIES} + ${SYSTEMD_LIBRARIES} +) + +install(TARGETS ${PLUGIN_LIBRARY_NAME} DESTINATION lib) +install(TARGETS ${PLUGIN_EXECUTABLE_NAME} DESTINATION bin) \ No newline at end of file diff --git a/src/plugin.c b/src/plugins/ietf-system/plugin.c similarity index 100% rename from src/plugin.c rename to src/plugins/ietf-system/plugin.c diff --git a/src/plugin.h b/src/plugins/ietf-system/plugin.h similarity index 100% rename from src/plugin.h rename to src/plugins/ietf-system/plugin.h diff --git a/tests/Tests.cmake b/tests/Tests.cmake index 3741a93..c918751 100644 --- a/tests/Tests.cmake +++ b/tests/Tests.cmake @@ -19,7 +19,7 @@ add_executable( target_link_libraries( system_utest - ${PLUGIN_LIRBARY_NAME} + ${PLUGIN_CORE_LIBRARY_NAME} ${CMOCKA_LIBRARIES} ${SYSREPO_LIBRARIES} ${LIBYANG_LIBRARIES} From 2ea81cf4aa3038e2a69b1b621f99c80447a1e916 Mon Sep 17 00:00:00 2001 From: Mateo Cindric Date: Tue, 3 Jan 2023 15:33:42 +0000 Subject: [PATCH 04/25] CMake: fix comments --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ffbeea..868a4c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,6 @@ include(CompileOptions.cmake) set(PLUGIN_CORE_LIBRARY_NAME "srplg-ietf-system-core") -# set(PLUGIN 0 CACHE BOOL "Build a plugin") option(ENABLE_BUILD_TESTS, "Build tests" OFF) # local includes @@ -87,13 +86,14 @@ install(TARGETS ${PLUGIN_CORE_LIBRARY_NAME} DESTINATION lib) # add main plugin to the build process add_subdirectory("src/plugins/ietf-system") -# # augyang support +# augyang support if(AUGYANG_FOUND) add_subdirectory("src/plugins/ietf-system-augeas") else(AUGYANG_FOUND) message(WARNING "AUGYANG not found - disabled build of the augeas specific plugin") endif() +# unit testing if(ENABLE_BUILD_TESTS) find_package(CMOCKA REQUIRED) include(CTest) From 77fd65e200ef91bf745c3a2a6cbf39665cec774e Mon Sep 17 00:00:00 2001 From: Mateo Cindric Date: Tue, 3 Jan 2023 15:35:13 +0000 Subject: [PATCH 05/25] CMake: fix formatting and add comments --- src/plugins/ietf-system-augeas/CMakeLists.txt | 2 +- src/plugins/ietf-system/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/ietf-system-augeas/CMakeLists.txt b/src/plugins/ietf-system-augeas/CMakeLists.txt index 89808e8..cc39900 100644 --- a/src/plugins/ietf-system-augeas/CMakeLists.txt +++ b/src/plugins/ietf-system-augeas/CMakeLists.txt @@ -16,13 +16,13 @@ add_library( ${PLUGIN_SOURCES} ) +# add plugin as a standalone executable add_executable( ${PLUGIN_EXECUTABLE_NAME} ${PLUGIN_SOURCES} ${CMAKE_SOURCE_DIR}/src/main.c ) - target_link_libraries( ${PLUGIN_EXECUTABLE_NAME} diff --git a/src/plugins/ietf-system/CMakeLists.txt b/src/plugins/ietf-system/CMakeLists.txt index f2b7702..fa269b5 100644 --- a/src/plugins/ietf-system/CMakeLists.txt +++ b/src/plugins/ietf-system/CMakeLists.txt @@ -23,13 +23,13 @@ add_library( ${PLUGIN_SOURCES} ) +# add plugin as a standalone executable add_executable( ${PLUGIN_EXECUTABLE_NAME} ${PLUGIN_SOURCES} ${CMAKE_SOURCE_DIR}/src/main.c ) - target_link_libraries( ${PLUGIN_EXECUTABLE_NAME} From 2b3b40104834d4151d72b6a06d9c51c2db4c9c4f Mon Sep 17 00:00:00 2001 From: Mateo Cindric Date: Tue, 3 Jan 2023 15:48:05 +0000 Subject: [PATCH 06/25] unit-testing: move unit testing files to new directory --- CMakeLists.txt | 2 +- tests/{ => unit}/Tests.cmake | 2 +- tests/{ => unit}/system_utest.c | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename tests/{ => unit}/Tests.cmake (93%) rename tests/{ => unit}/system_utest.c (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 868a4c1..ef6fede 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,5 +97,5 @@ endif() if(ENABLE_BUILD_TESTS) find_package(CMOCKA REQUIRED) include(CTest) - include(tests/Tests.cmake) + include(tests/unit/Tests.cmake) endif() \ No newline at end of file diff --git a/tests/Tests.cmake b/tests/unit/Tests.cmake similarity index 93% rename from tests/Tests.cmake rename to tests/unit/Tests.cmake index c918751..4d33ab1 100644 --- a/tests/Tests.cmake +++ b/tests/unit/Tests.cmake @@ -13,7 +13,7 @@ add_executable( system_utest - tests/system_utest.c + ${CMAKE_SOURCE_DIR}/tests/unit/system_utest.c ) target_link_libraries( diff --git a/tests/system_utest.c b/tests/unit/system_utest.c similarity index 100% rename from tests/system_utest.c rename to tests/unit/system_utest.c From 09e03a9e8b7a03c738c648c22ea5f304c2f635e1 Mon Sep 17 00:00:00 2001 From: Mateo Cindric Date: Tue, 3 Jan 2023 15:49:55 +0000 Subject: [PATCH 07/25] CMake: add license to files which are missing one --- CMakeLists.txt | 12 ++++++++++++ src/plugins/ietf-system-augeas/CMakeLists.txt | 12 ++++++++++++ src/plugins/ietf-system/CMakeLists.txt | 12 ++++++++++++ tests/unit/system_utest.c | 13 +++++++++++++ 4 files changed, 49 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index ef6fede..2dfc9cf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,3 +1,15 @@ +# +# telekom / sysrepo-plugin-system +# +# This program is made available under the terms of the +# BSD 3-Clause license which is available at +# https://opensource.org/licenses/BSD-3-Clause +# +# SPDX-FileCopyrightText: 2021 Deutsche Telekom AG +# SPDX-FileContributor: Sartura Ltd. +# +# SPDX-License-Identifier: BSD-3-Clause +# cmake_minimum_required(VERSION 3.0) project(sysrepo-plugin-system C) diff --git a/src/plugins/ietf-system-augeas/CMakeLists.txt b/src/plugins/ietf-system-augeas/CMakeLists.txt index cc39900..935a0a9 100644 --- a/src/plugins/ietf-system-augeas/CMakeLists.txt +++ b/src/plugins/ietf-system-augeas/CMakeLists.txt @@ -1,3 +1,15 @@ +# +# telekom / sysrepo-plugin-system +# +# This program is made available under the terms of the +# BSD 3-Clause license which is available at +# https://opensource.org/licenses/BSD-3-Clause +# +# SPDX-FileCopyrightText: 2021 Deutsche Telekom AG +# SPDX-FileContributor: Sartura Ltd. +# +# SPDX-License-Identifier: BSD-3-Clause +# cmake_minimum_required(VERSION 3.0) set(PLUGIN_LIBRARY_NAME "srplg-ietf-system-augeas") diff --git a/src/plugins/ietf-system/CMakeLists.txt b/src/plugins/ietf-system/CMakeLists.txt index fa269b5..1d37a24 100644 --- a/src/plugins/ietf-system/CMakeLists.txt +++ b/src/plugins/ietf-system/CMakeLists.txt @@ -1,3 +1,15 @@ +# +# telekom / sysrepo-plugin-system +# +# This program is made available under the terms of the +# BSD 3-Clause license which is available at +# https://opensource.org/licenses/BSD-3-Clause +# +# SPDX-FileCopyrightText: 2021 Deutsche Telekom AG +# SPDX-FileContributor: Sartura Ltd. +# +# SPDX-License-Identifier: BSD-3-Clause +# cmake_minimum_required(VERSION 3.0) set(PLUGIN_LIBRARY_NAME "srplg-ietf-system") diff --git a/tests/unit/system_utest.c b/tests/unit/system_utest.c index e3c9b97..be3c15c 100644 --- a/tests/unit/system_utest.c +++ b/tests/unit/system_utest.c @@ -1,3 +1,16 @@ +/* + * telekom / sysrepo-plugin-system + * + * This program is made available under the terms of the + * BSD 3-Clause license which is available at + * https://opensource.org/licenses/BSD-3-Clause + * + * SPDX-FileCopyrightText: 2022 Deutsche Telekom AG + * SPDX-FileContributor: Sartura Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + // cmocka headers #include #include From 0019a7c1ea6dc0a24582ab8238a3134ba7c1229d Mon Sep 17 00:00:00 2001 From: Mateo Cindric Date: Tue, 3 Jan 2023 15:52:48 +0000 Subject: [PATCH 08/25] CMake: move CMake package find scripts to CMakeModules --- CMakeLists.txt | 2 +- {cmake/Modules => CMakeModules}/FindAUGYANG.cmake | 0 {cmake/Modules => CMakeModules}/FindLIBSYSTEMD.cmake | 0 {cmake/Modules => CMakeModules}/FindLIBYANG.cmake | 0 {cmake/Modules => CMakeModules}/FindSRPC.cmake | 0 {cmake/Modules => CMakeModules}/FindSYSREPO.cmake | 0 {cmake/Modules => CMakeModules}/FindUMGMT.cmake | 0 7 files changed, 1 insertion(+), 1 deletion(-) rename {cmake/Modules => CMakeModules}/FindAUGYANG.cmake (100%) rename {cmake/Modules => CMakeModules}/FindLIBSYSTEMD.cmake (100%) rename {cmake/Modules => CMakeModules}/FindLIBYANG.cmake (100%) rename {cmake/Modules => CMakeModules}/FindSRPC.cmake (100%) rename {cmake/Modules => CMakeModules}/FindSYSREPO.cmake (100%) rename {cmake/Modules => CMakeModules}/FindUMGMT.cmake (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2dfc9cf..68645ca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,7 +26,7 @@ include_directories( ) # find needed and optional packages -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules") +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMakeModules") find_package(SYSREPO REQUIRED) find_package(LIBYANG REQUIRED) find_package(SRPC REQUIRED) diff --git a/cmake/Modules/FindAUGYANG.cmake b/CMakeModules/FindAUGYANG.cmake similarity index 100% rename from cmake/Modules/FindAUGYANG.cmake rename to CMakeModules/FindAUGYANG.cmake diff --git a/cmake/Modules/FindLIBSYSTEMD.cmake b/CMakeModules/FindLIBSYSTEMD.cmake similarity index 100% rename from cmake/Modules/FindLIBSYSTEMD.cmake rename to CMakeModules/FindLIBSYSTEMD.cmake diff --git a/cmake/Modules/FindLIBYANG.cmake b/CMakeModules/FindLIBYANG.cmake similarity index 100% rename from cmake/Modules/FindLIBYANG.cmake rename to CMakeModules/FindLIBYANG.cmake diff --git a/cmake/Modules/FindSRPC.cmake b/CMakeModules/FindSRPC.cmake similarity index 100% rename from cmake/Modules/FindSRPC.cmake rename to CMakeModules/FindSRPC.cmake diff --git a/cmake/Modules/FindSYSREPO.cmake b/CMakeModules/FindSYSREPO.cmake similarity index 100% rename from cmake/Modules/FindSYSREPO.cmake rename to CMakeModules/FindSYSREPO.cmake diff --git a/cmake/Modules/FindUMGMT.cmake b/CMakeModules/FindUMGMT.cmake similarity index 100% rename from cmake/Modules/FindUMGMT.cmake rename to CMakeModules/FindUMGMT.cmake From fb3f116045163e5ccb77355479a4a482b0df82ff Mon Sep 17 00:00:00 2001 From: Mateo Cindric Date: Thu, 5 Jan 2023 14:22:24 +0000 Subject: [PATCH 09/25] plugins-core: disable NTP configuration if augyang not used --- src/core/startup/store.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/core/startup/store.c b/src/core/startup/store.c index c3edeac..f1635cd 100644 --- a/src/core/startup/store.c +++ b/src/core/startup/store.c @@ -95,10 +95,12 @@ int system_startup_store_data(system_ctx_t *ctx, sr_session_ctx_t *session) "timezone-name", system_startup_store_timezone_name, }, +#ifdef AUGYANG { "ntp", system_startup_store_ntp, }, +#endif { "dns-resolver", system_startup_store_dns_resolver, From 6576b60b71b83a413680fa2215fe03da94d96538 Mon Sep 17 00:00:00 2001 From: Mateo Cindric Date: Thu, 5 Jan 2023 15:08:27 +0000 Subject: [PATCH 10/25] system-plugins: split augeas based and non-augeas based code between plugins --- src/plugins/ietf-system-augeas/CMakeLists.txt | 2 + .../datastore/running/load.c | 10 + .../datastore/running/load.h | 21 + .../datastore/running/store.c | 10 + .../datastore/running/store.h | 21 + src/plugins/ietf-system-augeas/plugin.c | 170 ++++- src/plugins/ietf-system/CMakeLists.txt | 2 + .../ietf-system/datastore/running/load.c | 502 +++++++++++++ .../ietf-system/datastore/running/load.h | 21 + .../ietf-system/datastore/running/store.c | 692 ++++++++++++++++++ .../ietf-system/datastore/running/store.h | 21 + src/plugins/ietf-system/plugin.c | 16 +- 12 files changed, 1476 insertions(+), 12 deletions(-) create mode 100644 src/plugins/ietf-system-augeas/datastore/running/load.c create mode 100644 src/plugins/ietf-system-augeas/datastore/running/load.h create mode 100644 src/plugins/ietf-system-augeas/datastore/running/store.c create mode 100644 src/plugins/ietf-system-augeas/datastore/running/store.h create mode 100644 src/plugins/ietf-system/datastore/running/load.c create mode 100644 src/plugins/ietf-system/datastore/running/load.h create mode 100644 src/plugins/ietf-system/datastore/running/store.c create mode 100644 src/plugins/ietf-system/datastore/running/store.h diff --git a/src/plugins/ietf-system-augeas/CMakeLists.txt b/src/plugins/ietf-system-augeas/CMakeLists.txt index 935a0a9..c02be91 100644 --- a/src/plugins/ietf-system-augeas/CMakeLists.txt +++ b/src/plugins/ietf-system-augeas/CMakeLists.txt @@ -19,6 +19,8 @@ set( PLUGIN_SOURCES plugin.c + datastore/running/load.c + datastore/running/store.c ) # add plugin as a sysrepo-plugind library diff --git a/src/plugins/ietf-system-augeas/datastore/running/load.c b/src/plugins/ietf-system-augeas/datastore/running/load.c new file mode 100644 index 0000000..e2bff48 --- /dev/null +++ b/src/plugins/ietf-system-augeas/datastore/running/load.c @@ -0,0 +1,10 @@ +#include "load.h" + +static int system_startup_load_hostname(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node); +static int system_startup_load_ntp(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node); + +int system_aug_running_ds_load(system_ctx_t *ctx, sr_session_ctx_t *session) +{ + int error = 0; + return error; +} \ No newline at end of file diff --git a/src/plugins/ietf-system-augeas/datastore/running/load.h b/src/plugins/ietf-system-augeas/datastore/running/load.h new file mode 100644 index 0000000..7e599aa --- /dev/null +++ b/src/plugins/ietf-system-augeas/datastore/running/load.h @@ -0,0 +1,21 @@ +/* + * telekom / sysrepo-plugin-system + * + * This program is made available under the terms of the + * BSD 3-Clause license which is available at + * https://opensource.org/licenses/BSD-3-Clause + * + * SPDX-FileCopyrightText: 2022 Deutsche Telekom AG + * SPDX-FileContributor: Sartura Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ +#ifndef SYSTEM_AUGEAS_PLUGIN_DATASTORE_RUNNING_LOAD_H +#define SYSTEM_AUGEAS_PLUGIN_DATASTORE_RUNNING_LOAD_H + +#include +#include + +int system_aug_running_ds_load(system_ctx_t *ctx, sr_session_ctx_t *session); + +#endif // SYSTEM_AUGEAS_PLUGIN_DATASTORE_RUNNING_LOAD_H \ No newline at end of file diff --git a/src/plugins/ietf-system-augeas/datastore/running/store.c b/src/plugins/ietf-system-augeas/datastore/running/store.c new file mode 100644 index 0000000..1fcb72c --- /dev/null +++ b/src/plugins/ietf-system-augeas/datastore/running/store.c @@ -0,0 +1,10 @@ +#include "store.h" + +static int system_startup_store_hostname(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node); +static int system_startup_store_ntp(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node); + +int system_aug_running_ds_store(system_ctx_t *ctx, sr_session_ctx_t *session) +{ + int error = 0; + return error; +} \ No newline at end of file diff --git a/src/plugins/ietf-system-augeas/datastore/running/store.h b/src/plugins/ietf-system-augeas/datastore/running/store.h new file mode 100644 index 0000000..9fd3a01 --- /dev/null +++ b/src/plugins/ietf-system-augeas/datastore/running/store.h @@ -0,0 +1,21 @@ +/* + * telekom / sysrepo-plugin-system + * + * This program is made available under the terms of the + * BSD 3-Clause license which is available at + * https://opensource.org/licenses/BSD-3-Clause + * + * SPDX-FileCopyrightText: 2022 Deutsche Telekom AG + * SPDX-FileContributor: Sartura Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ +#ifndef SYSTEM_AUGEAS_PLUGIN_DATASTORE_RUNNING_STORE_H +#define SYSTEM_AUGEAS_PLUGIN_DATASTORE_RUNNING_STORE_H + +#include +#include + +int system_aug_running_ds_store(system_ctx_t *ctx, sr_session_ctx_t *session); + +#endif // SYSTEM_AUGEAS_PLUGIN_DATASTORE_RUNNING_STORE_H \ No newline at end of file diff --git a/src/plugins/ietf-system-augeas/plugin.c b/src/plugins/ietf-system-augeas/plugin.c index c9dffa0..9868320 100644 --- a/src/plugins/ietf-system-augeas/plugin.c +++ b/src/plugins/ietf-system-augeas/plugin.c @@ -1,11 +1,173 @@ +/* + * telekom / sysrepo-plugin-system + * + * This program is made available under the terms of the + * BSD 3-Clause license which is available at + * https://opensource.org/licenses/BSD-3-Clause + * + * SPDX-FileCopyrightText: 2022 Deutsche Telekom AG + * SPDX-FileContributor: Sartura Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ #include "plugin.h" +#include "core/common.h" +#include "core/context.h" -int sr_plugin_init_cb(sr_session_ctx_t *session, void **private_data) +// stdlib +#include + +// sysrepo +#include + +// libyang +#include + +#include "srpc/common.h" +#include "srpc/feature_status.h" +#include "srpc/types.h" + +// startup +#include "datastore/running/load.h" +#include "datastore/running/store.h" + +// subs +#include "core/subscription/change.h" +#include "core/subscription/operational.h" +#include "core/subscription/rpc.h" + +#include + +int sr_plugin_init_cb(sr_session_ctx_t *running_session, void **private_data) { - int error = SR_ERR_OK; - return error; + int error = 0; + + bool empty_startup = false; + + // sysrepo + sr_session_ctx_t *startup_session = NULL; + sr_conn_ctx_t *connection = NULL; + sr_subscription_ctx_t *subscription = NULL; + + // plugin + system_ctx_t *ctx = NULL; + + // init context + ctx = malloc(sizeof(*ctx)); + *ctx = (system_ctx_t){0}; + + *private_data = ctx; + + // module changes + srpc_module_change_t module_changes[] = { + { + SYSTEM_HOSTNAME_YANG_PATH, + system_subscription_change_hostname, + }, + { + SYSTEM_NTP_ENABLED_YANG_PATH, + system_subscription_change_ntp_enabled, + }, + { + SYSTEM_NTP_SERVER_YANG_PATH, + system_subscription_change_ntp_server, + }, + }; + + ctx->ietf_system_features = srpc_feature_status_hash_new(); + + // load feature status + SRPC_SAFE_CALL_ERR(error, srpc_feature_status_hash_load(&ctx->ietf_system_features, running_session, "ietf-system"), error_out); + + // log status of features + const char *features[] = { + "radius", + "authentication", + "local-users", + "radius-authentication", + "ntp", + "ntp-udp-port", + "timezone-name", + "dns-udp-tcp-port", + }; + + SRPLG_LOG_INF(PLUGIN_NAME, "Checking ietf-system YANG module used features"); + + for (size_t i = 0; i < ARRAY_SIZE(features); i++) { + const char *feature = features[i]; + + SRPLG_LOG_INF(PLUGIN_NAME, "ietf-system feature \"%s\" status = %s", feature, srpc_feature_status_hash_check(ctx->ietf_system_features, feature) ? "enabled" : "disabled"); + } + + connection = sr_session_get_connection(running_session); + error = sr_session_start(connection, SR_DS_STARTUP, &startup_session); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "sr_session_start() error (%d): %s", error, sr_strerror(error)); + goto error_out; + } + + ctx->startup_session = startup_session; + + error = srpc_check_empty_datastore(running_session, SYSTEM_HOSTNAME_YANG_PATH, &empty_startup); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "Failed checking datastore contents: %d", error); + goto error_out; + } + + if (empty_startup) { + SRPLG_LOG_INF(PLUGIN_NAME, "Running datastore is empty"); + SRPLG_LOG_INF(PLUGIN_NAME, "Loading initial system data"); + + // load data only into running DS - do not use startup unless said explicitly + error = system_aug_running_ds_load(ctx, running_session); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "Error loading initial data into the running datastore... exiting"); + goto error_out; + } + } else { + // make sure the data from startup DS is stored in the system + SRPLG_LOG_INF(PLUGIN_NAME, "Running datastore contains data"); + SRPLG_LOG_INF(PLUGIN_NAME, "Storing running datastore data in the system"); + + // check and apply if needed data from startup to the system + error = system_aug_running_ds_store(ctx, startup_session); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "Error applying initial data from startup datastore to the system... exiting"); + goto error_out; + } + } + + // subscribe every module change + for (size_t i = 0; i < ARRAY_SIZE(module_changes); i++) { + const srpc_module_change_t *change = &module_changes[i]; + + // in case of work on a specific callback set it to NULL + if (change->cb) { + error = sr_module_change_subscribe(running_session, BASE_YANG_MODULE, change->path, change->cb, *private_data, 0, SR_SUBSCR_DEFAULT, &subscription); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "sr_module_change_subscribe() error for \"%s\" (%d): %s", change->path, error, sr_strerror(error)); + goto error_out; + } + } + } + + goto out; + +error_out: + error = -1; + SRPLG_LOG_ERR(PLUGIN_NAME, "Error occured while initializing the plugin (%d)", error); + +out: + return error ? SR_ERR_CALLBACK_FAILED : SR_ERR_OK; } -void sr_plugin_cleanup_cb(sr_session_ctx_t *session, void *private_data) +void sr_plugin_cleanup_cb(sr_session_ctx_t *running_session, void *private_data) { + system_ctx_t *ctx = (system_ctx_t *) private_data; + + if (ctx->ietf_system_features) { + srpc_feature_status_hash_free(&ctx->ietf_system_features); + } + + free(ctx); } diff --git a/src/plugins/ietf-system/CMakeLists.txt b/src/plugins/ietf-system/CMakeLists.txt index 1d37a24..71ad8f4 100644 --- a/src/plugins/ietf-system/CMakeLists.txt +++ b/src/plugins/ietf-system/CMakeLists.txt @@ -19,6 +19,8 @@ set( PLUGIN_SOURCES plugin.c + datastore/running/load.c + datastore/running/store.c ) # check for systemd flag diff --git a/src/plugins/ietf-system/datastore/running/load.c b/src/plugins/ietf-system/datastore/running/load.c new file mode 100644 index 0000000..d24c5e7 --- /dev/null +++ b/src/plugins/ietf-system/datastore/running/load.c @@ -0,0 +1,502 @@ +/* + * telekom / sysrepo-plugin-system + * + * This program is made available under the terms of the + * BSD 3-Clause license which is available at + * https://opensource.org/licenses/BSD-3-Clause + * + * SPDX-FileCopyrightText: 2022 Deutsche Telekom AG + * SPDX-FileContributor: Sartura Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ +#include "load.h" +#include "core/common.h" +#include "core/context.h" +#include "core/ly_tree.h" + +// API for getting system data +#include "srpc/common.h" +#include "srpc/feature_status.h" +#include "srpc/ly_tree.h" +#include "core/api/system/load.h" +#include "core/api/system/authentication/load.h" +#include "core/api/system/dns_resolver/load.h" + +// data manipulation +#include "core/api/system/ntp/load.h" +#include "core/data/system/authentication/authorized_key/list.h" +#include "core/data/system/authentication/local_user/list.h" +#include "core/data/system/ip_address.h" +#include "core/data/system/dns_resolver/search/list.h" +#include "core/data/system/dns_resolver/server/list.h" +#include "core/data/system/ntp/server/list.h" + +#include +#include +#include + +#include + +#include + +#include + +static int system_startup_load_contact(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node); +static int system_startup_load_location(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node); +static int system_startup_load_timezone_name(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node); +static int system_startup_load_dns_resolver(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node); +static int system_startup_load_authentication(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node); + +int system_running_ds_load(system_ctx_t *ctx, sr_session_ctx_t *session) +{ + int error = 0; + + const struct ly_ctx *ly_ctx = NULL; + struct lyd_node *system_container_node = NULL; + sr_conn_ctx_t *conn_ctx = NULL; + + srpc_startup_load_t load_values[] = { + { + "contact", + system_startup_load_contact, + }, + { + "location", + system_startup_load_location, + }, + { + "timezone-name", + system_startup_load_timezone_name, + }, + { + "dns-resolver", + system_startup_load_dns_resolver, + }, + { + "authentication", + system_startup_load_authentication, + }, + }; + + conn_ctx = sr_session_get_connection(session); + ly_ctx = sr_acquire_context(conn_ctx); + if (ly_ctx == NULL) { + SRPLG_LOG_ERR(PLUGIN_NAME, "Unable to get ly_ctx variable"); + goto error_out; + } + + // reload features hash before adding all system values + SRPC_SAFE_CALL_ERR(error, srpc_feature_status_hash_reload(&ctx->ietf_system_features, session, IETF_SYSTEM_YANG_MODULE), error_out); + + // load system container info + error = system_ly_tree_create_system(ly_ctx, &system_container_node); + for (size_t i = 0; i < ARRAY_SIZE(load_values); i++) { + const srpc_startup_load_t *load = &load_values[i]; + + error = load->cb((void *) ctx, session, ly_ctx, system_container_node); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "Node creation callback failed for value %s", load->name); + goto error_out; + } + } + +// enable or disable storing into startup - use when testing load functionality for now +#define SYSTEM_PLUGIN_LOAD_STARTUP + +#ifdef SYSTEM_PLUGIN_LOAD_STARTUP + error = sr_edit_batch(session, system_container_node, "merge"); + if (error != SR_ERR_OK) { + SRPLG_LOG_ERR(PLUGIN_NAME, "sr_edit_batch() error (%d): %s", error, sr_strerror(error)); + goto error_out; + } + + error = sr_apply_changes(session, 0); + if (error != 0) { + SRPLG_LOG_ERR(PLUGIN_NAME, "sr_apply_changes() error (%d): %s", error, sr_strerror(error)); + goto error_out; + } +#endif + + goto out; + +error_out: + error = -1; + +out: + if (system_container_node) { + lyd_free_tree(system_container_node); + } + + sr_release_context(conn_ctx); + + return error; +} + +static int system_startup_load_contact(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node) +{ + int error = 0; + return error; +} + +static int system_startup_load_location(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node) +{ + int error = 0; + return error; +} + +static int system_startup_load_timezone_name(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node) +{ + int error = 0; + system_ctx_t *ctx = (system_ctx_t *) priv; + char timezone_name_buffer[SYSTEM_TIMEZONE_NAME_LENGTH_MAX] = {0}; + struct lyd_node *clock_container_node = NULL; + bool timezone_name_enabled = false; + + timezone_name_enabled = srpc_feature_status_hash_check(ctx->ietf_system_features, "timezone-name"); + + if (timezone_name_enabled) { + error = system_load_timezone_name(ctx, timezone_name_buffer); + + // setup clock container + error = system_ly_tree_create_clock(ly_ctx, parent_node, &clock_container_node); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_ly_tree_create_clock_container() error (%d)", error); + goto error_out; + } + + // set timezone-name leaf + error = system_ly_tree_create_timezone_name(ly_ctx, clock_container_node, timezone_name_buffer); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_ly_tree_create_timezone_name() error (%d)", error); + goto error_out; + } + } + + goto out; + +error_out: + error = -1; + +out: + return error; +} + +static int system_startup_load_ntp(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node) +{ + int error = 0; + + system_ctx_t *ctx = priv; + + // ietf-system nodes + struct lyd_node *ntp_container_node = NULL, *server_list_node = NULL; + + // feature check + bool ntp_enabled = srpc_feature_status_hash_check(ctx->ietf_system_features, "ntp"); + bool ntp_udp_port_enabled = srpc_feature_status_hash_check(ctx->ietf_system_features, "ntp-udp-port"); + + // load list + system_ntp_server_element_t *ntp_server_head = NULL, *ntp_server_iter = NULL; + + SRPLG_LOG_INF(PLUGIN_NAME, "Loading NTP data"); + + if (ntp_enabled) { + error = system_ly_tree_create_ntp(ly_ctx, parent_node, &ntp_container_node); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_ly_tree_create_ntp() error (%d)", error); + goto error_out; + } + + // load system values + system_ntp_server_list_init(&ntp_server_head); + error = system_ntp_load_server(ctx, &ntp_server_head); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_ntp_load_server() error (%d)", error); + goto error_out; + } + + LL_FOREACH(ntp_server_head, ntp_server_iter) + { + // name + error = system_ly_tree_create_ntp_server(ly_ctx, ntp_container_node, &server_list_node, ntp_server_iter->server.name); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_ly_tree_create_ntp_server() error (%d)", error); + goto error_out; + } + + SRPLG_LOG_INF(PLUGIN_NAME, "Setting address %s", ntp_server_iter->server.address); + + // address + error = system_ly_tree_create_ntp_server_address(ly_ctx, server_list_node, ntp_server_iter->server.address); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_ly_tree_create_ntp_server_address() error (%d)", error); + goto error_out; + } + + SRPLG_LOG_INF(PLUGIN_NAME, "Setting port \"%s\"", ntp_server_iter->server.port); + + // port + if (ntp_server_iter->server.port && ntp_udp_port_enabled) { + error = system_ly_tree_create_ntp_server_port(ly_ctx, server_list_node, ntp_server_iter->server.port); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_ly_tree_create_ntp_server_port() error (%d)", error); + goto error_out; + } + } + + // association type + error = system_ly_tree_create_ntp_server_association_type(ly_ctx, server_list_node, ntp_server_iter->server.association_type); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_ly_tree_create_ntp_server_association_type() error (%d)", error); + goto error_out; + } + + // iburst + if (ntp_server_iter->server.iburst) { + error = system_ly_tree_create_ntp_server_iburst(ly_ctx, server_list_node, ntp_server_iter->server.iburst); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_ly_tree_create_ntp_server_iburst() error (%d)", error); + goto error_out; + } + } + + // prefer + if (ntp_server_iter->server.prefer) { + error = system_ly_tree_create_ntp_server_prefer(ly_ctx, server_list_node, ntp_server_iter->server.prefer); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_ly_tree_create_ntp_server_prefer() error (%d)", error); + goto error_out; + } + } + } + + goto out; + } + +error_out: + error = -1; + +out: + + system_ntp_server_list_free(&ntp_server_head); + + return error; +} + +static int system_startup_load_dns_resolver(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node) +{ + int error = 0; + system_ctx_t *ctx = (system_ctx_t *) priv; + struct lyd_node *dns_resolver_container_node = NULL, *server_list_node = NULL; + system_dns_search_element_t *search_head = NULL, *search_iter_el = NULL; + system_dns_server_element_t *servers_head = NULL, *servers_iter_el = NULL; + char address_buffer[100] = {0}; + char port_buffer[10] = {0}; + + // setup dns-resolver container + error = system_ly_tree_create_dns_resolver(ly_ctx, parent_node, &dns_resolver_container_node); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_ly_tree_create_dns_resolver() error (%d)", error); + goto error_out; + } + + SRPLG_LOG_INF(PLUGIN_NAME, "Loading DNS search values from the system"); + + // load values + + error = system_dns_resolver_load_search(ctx, &search_head); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_dns_resolver_load_search_values() error (%d)", error); + goto error_out; + } + + SRPLG_LOG_INF(PLUGIN_NAME, "Loading DNS server values from the system"); + + error = system_dns_resolver_load_server(ctx, &servers_head); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_dns_resolver_load_server_values() error (%d)", error); + goto error_out; + } + + SRPLG_LOG_INF(PLUGIN_NAME, "Saving search values to the datastore"); + + LL_FOREACH(search_head, search_iter_el) + { + error = system_ly_tree_append_dns_resolver_search(ly_ctx, dns_resolver_container_node, search_iter_el->search.domain); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_ly_tree_append_dns_resolver_search() error (%d) for %s", error, search_iter_el->search.domain); + goto error_out; + } + } + + SRPLG_LOG_INF(PLUGIN_NAME, "Saved search values to the datastore"); + SRPLG_LOG_INF(PLUGIN_NAME, "Saving server values to the datastore"); + + LL_FOREACH(servers_head, servers_iter_el) + { + error = system_ip_address_to_str(&servers_iter_el->server.address, address_buffer, sizeof(address_buffer)); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_dns_resolver_server_address_to_str() error (%d)", error); + goto error_out; + } + + error = system_ly_tree_create_dns_resolver_server(ly_ctx, dns_resolver_container_node, &server_list_node, address_buffer); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_ly_tree_create_dns_resolver_server() error (%d) for %s", error, address_buffer); + goto error_out; + } + + // address + error = system_ly_tree_create_dns_resolver_server_address(ly_ctx, server_list_node, address_buffer); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_ly_tree_create_dns_resolver_server_address() error (%d) for %s", error, address_buffer); + goto error_out; + } + + // port + if (servers_iter_el->server.port != 0) { + error = snprintf(port_buffer, sizeof(port_buffer), "%d", servers_iter_el->server.port); + if (error < 0) { + SRPLG_LOG_ERR(PLUGIN_NAME, "snprintf() error (%d) for %d port", error, servers_iter_el->server.port); + goto error_out; + } + + error = system_ly_tree_create_dns_resolver_server_port(ly_ctx, server_list_node, port_buffer); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_ly_tree_create_dns_resolver_server_address() error (%d) for %s port", error, port_buffer); + goto error_out; + } + } + } + + SRPLG_LOG_INF(PLUGIN_NAME, "Saved server values to the datastore"); + + goto out; + +error_out: + error = -1; + +out: + // free values + system_dns_search_list_free(&search_head); + system_dns_server_list_free(&servers_head); + + return error; +} + +static int system_startup_load_authentication(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node) +{ + int error = 0; + system_ctx_t *ctx = (system_ctx_t *) priv; + struct lyd_node *authentication_container_node = NULL; + struct lyd_node *user_list_node = NULL, *authorized_key_list_node = NULL; + system_local_user_element_t *user_head = NULL, *user_iter = NULL; + system_authorized_key_element_t *key_iter = NULL; + + bool enabled_authentication = srpc_feature_status_hash_check(ctx->ietf_system_features, "authentication"); + bool enabled_local_users = srpc_feature_status_hash_check(ctx->ietf_system_features, "local-users"); + + if (enabled_authentication) { + // create authentication container + error = system_ly_tree_create_authentication(ly_ctx, parent_node, &authentication_container_node); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_ly_tree_create_authentication() error (%d)", error); + goto error_out; + } + + if (enabled_local_users) { + SRPLG_LOG_INF(PLUGIN_NAME, "Loading users from the system"); + + // init list first + system_local_user_list_init(&user_head); + + // load user list + error = system_authentication_load_user(ctx, &user_head); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_authentication_load_user() error (%d)", error); + goto error_out; + } + + SRPLG_LOG_INF(PLUGIN_NAME, "Loading user authorized keys"); + + LL_FOREACH(user_head, user_iter) + { + system_authorized_key_list_init(&user_iter->user.key_head); + + error = system_authentication_load_user_authorized_key(ctx, user_iter->user.name, &user_iter->user.key_head); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_authentication_load_user_authorized_key() error (%d)", error); + goto error_out; + } + } + + SRPLG_LOG_INF(PLUGIN_NAME, "Saving users and their keys to the datastore"); + + LL_FOREACH(user_head, user_iter) + { + // list item + error = system_ly_tree_create_authentication_user(ly_ctx, authentication_container_node, &user_list_node, user_iter->user.name); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_ly_tree_create_authentication_user() error (%d) for %s", error, user_iter->user.name); + goto error_out; + } + + // password + if (user_iter->user.password && strcmp(user_iter->user.password, "")) { + error = system_ly_tree_create_authentication_user_password(ly_ctx, user_list_node, user_iter->user.password); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_ly_tree_create_authentication_user_password() error (%d) for %s", error, user_iter->user.password); + goto error_out; + } + } + + // authorized-key + int count = 0; + LL_COUNT(user_iter->user.key_head, key_iter, count); + + if (count > 0) { + key_iter = NULL; + LL_FOREACH(user_iter->user.key_head, key_iter) + { + // list item + error = system_ly_tree_create_authentication_user_authorized_key(ly_ctx, user_list_node, &authorized_key_list_node, key_iter->key.name); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_ly_tree_create_authentication_user_authorized_key() error (%d) for %s", error, key_iter->key.name); + goto error_out; + } + + // algorithm + if (key_iter->key.algorithm) { + error = system_ly_tree_create_authentication_user_authorized_key_algorithm(ly_ctx, authorized_key_list_node, key_iter->key.algorithm); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_ly_tree_create_authentication_user_authorized_key_algorithm() error (%d) for %s", error, key_iter->key.algorithm); + goto error_out; + } + } + + // key-data + if (key_iter->key.data) { + error = system_ly_tree_create_authentication_user_authorized_key_data(ly_ctx, authorized_key_list_node, key_iter->key.data); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_ly_tree_create_authentication_user_authorized_key_data() error (%d) for %s", error, key_iter->key.data); + goto error_out; + } + } + } + } + } + + SRPLG_LOG_INF(PLUGIN_NAME, "Saved users to the datastore"); + } + } + + goto out; + +error_out: + error = -1; + +out: + system_local_user_list_free(&user_head); + + return error; +} \ No newline at end of file diff --git a/src/plugins/ietf-system/datastore/running/load.h b/src/plugins/ietf-system/datastore/running/load.h new file mode 100644 index 0000000..f38d269 --- /dev/null +++ b/src/plugins/ietf-system/datastore/running/load.h @@ -0,0 +1,21 @@ +/* + * telekom / sysrepo-plugin-system + * + * This program is made available under the terms of the + * BSD 3-Clause license which is available at + * https://opensource.org/licenses/BSD-3-Clause + * + * SPDX-FileCopyrightText: 2022 Deutsche Telekom AG + * SPDX-FileContributor: Sartura Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ +#ifndef SYSTEM_PLUGIN_DATASTORE_RUNNING_LOAD_H +#define SYSTEM_PLUGIN_DATASTORE_RUNNING_LOAD_H + +#include +#include + +int system_running_ds_load(system_ctx_t *ctx, sr_session_ctx_t *session); + +#endif // SYSTEM_PLUGIN_DATASTORE_RUNNING_LOAD_H \ No newline at end of file diff --git a/src/plugins/ietf-system/datastore/running/store.c b/src/plugins/ietf-system/datastore/running/store.c new file mode 100644 index 0000000..222bd45 --- /dev/null +++ b/src/plugins/ietf-system/datastore/running/store.c @@ -0,0 +1,692 @@ +/* + * telekom / sysrepo-plugin-system + * + * This program is made available under the terms of the + * BSD 3-Clause license which is available at + * https://opensource.org/licenses/BSD-3-Clause + * + * SPDX-FileCopyrightText: 2022 Deutsche Telekom AG + * SPDX-FileContributor: Sartura Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ +#include "store.h" +#include "core/common.h" +#include "libyang/printer_data.h" +#include "core/ly_tree.h" + +// API for getting system data +#include "srpc/common.h" +#include "srpc/feature_status.h" +#include "srpc/ly_tree.h" +#include "srpc/types.h" +#include "core/api/system/authentication/check.h" +#include "core/api/system/authentication/load.h" +#include "core/api/system/check.h" +#include "core/api/system/ntp/check.h" +#include "core/api/system/ntp/store.h" +#include "core/api/system/store.h" +#include "core/api/system/dns_resolver/store.h" +#include "core/api/system/dns_resolver/check.h" +#include "core/api/system/authentication/store.h" + +// data manipulation +#include "core/data/system/authentication/authorized_key.h" +#include "core/data/system/authentication/authorized_key/list.h" +#include "core/data/system/authentication/local_user.h" +#include "core/data/system/authentication/local_user/list.h" +#include "core/data/system/ip_address.h" +#include "core/data/system/dns_resolver/search.h" +#include "core/data/system/dns_resolver/search/list.h" +#include "core/data/system/dns_resolver/server.h" +#include "core/data/system/dns_resolver/server/list.h" +#include "core/data/system/ntp/server.h" +#include "core/data/system/ntp/server/list.h" +#include "core/types.h" + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + +#include + +static int system_startup_store_contact(void *priv, const struct lyd_node *system_container_node); +static int system_startup_store_location(void *priv, const struct lyd_node *system_container_node); +static int system_startup_store_timezone_name(void *priv, const struct lyd_node *system_container_node); +static int system_startup_store_dns_resolver(void *priv, const struct lyd_node *system_container_node); +static int system_startup_store_authentication(void *priv, const struct lyd_node *system_container_node); + +int system_running_ds_store(system_ctx_t *ctx, sr_session_ctx_t *session) +{ + int error = 0; + sr_data_t *subtree = NULL; + + error = sr_get_subtree(session, SYSTEM_SYSTEM_CONTAINER_YANG_PATH, 0, &subtree); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "sr_get_subtree() error (%d): %s", error, sr_strerror(error)); + goto error_out; + } + + srpc_startup_store_t store_values[] = { + { + "contact", + system_startup_store_contact, + }, + { + "location", + system_startup_store_location, + }, + { + "timezone-name", + system_startup_store_timezone_name, + }, + { + "dns-resolver", + system_startup_store_dns_resolver, + }, + { + "authentication", + system_startup_store_authentication, + }, + }; + + // reload feature status hash before storing system data + SRPC_SAFE_CALL_ERR(error, srpc_feature_status_hash_reload(&ctx->ietf_system_features, session, IETF_SYSTEM_YANG_MODULE), error_out); + + for (size_t i = 0; i < ARRAY_SIZE(store_values); i++) { + const srpc_startup_store_t *store = &store_values[i]; + + error = store->cb(ctx, subtree->tree); + if (error != 0) { + SRPLG_LOG_ERR(PLUGIN_NAME, "Startup store callback failed for value %s", store->name); + goto error_out; + } + } + + goto out; + +error_out: + error = -1; + +out: + if (subtree) { + sr_release_data(subtree); + } + + return error; +} + +static int system_startup_store_contact(void *priv, const struct lyd_node *system_container_node) +{ + int error = 0; + system_ctx_t *ctx = (system_ctx_t *) priv; + + struct lyd_node *contact_node = srpc_ly_tree_get_child_leaf(system_container_node, "contact"); + + if (contact_node) { + const char *contact = lyd_get_value(contact_node); + + SRPLG_LOG_INF(PLUGIN_NAME, "contact value: %s", contact); + + error = system_store_contact(ctx, contact); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_store_contact() failed (%d)", error); + return -1; + } + } + + return 0; +} + +static int system_startup_store_location(void *priv, const struct lyd_node *system_container_node) +{ + int error = 0; + system_ctx_t *ctx = (system_ctx_t *) priv; + + struct lyd_node *location_node = srpc_ly_tree_get_child_leaf(system_container_node, "location"); + + if (location_node) { + const char *location = lyd_get_value(location_node); + + SRPLG_LOG_INF(PLUGIN_NAME, "location value: %s", location); + + error = system_store_location(ctx, location); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_store_location() failed (%d)", error); + return -1; + } + } + + return 0; +} + +static int system_startup_store_timezone_name(void *priv, const struct lyd_node *system_container_node) +{ + int error = 0; + system_ctx_t *ctx = (system_ctx_t *) priv; + srpc_check_status_t check_status = srpc_check_status_none; + bool timezone_name_enabled = srpc_feature_status_hash_check(ctx->ietf_system_features, "timezone-name"); + + struct lyd_node *clock_container_node = NULL, *timezone_name_node = NULL; + + if (timezone_name_enabled) { + clock_container_node = srpc_ly_tree_get_child_container(system_container_node, "clock"); + + if (clock_container_node) { + timezone_name_node = srpc_ly_tree_get_child_leaf(clock_container_node, "timezone-name"); + if (timezone_name_node) { + const char *timezone_name = lyd_get_value(timezone_name_node); + + SRPLG_LOG_INF(PLUGIN_NAME, "Checking system timezone-name value"); + check_status = system_check_timezone_name(ctx, timezone_name); + + switch (check_status) { + case srpc_check_status_none: + SRPLG_LOG_ERR(PLUGIN_NAME, "Error loading current system timezone-name value"); + goto error_out; + break; + case srpc_check_status_error: + SRPLG_LOG_ERR(PLUGIN_NAME, "Error loading current system timezone-name value"); + goto error_out; + break; + case srpc_check_status_non_existant: + SRPLG_LOG_INF(PLUGIN_NAME, "Storing timezone-name value %s", timezone_name); + + error = system_store_timezone_name(ctx, timezone_name); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_store_timezone_name() failed (%d)", error); + return -1; + } + break; + case srpc_check_status_equal: + SRPLG_LOG_ERR(PLUGIN_NAME, "Startup timezone-name value is already applied on the system"); + break; + case srpc_check_status_partial: + // should not be returned - treat as error + SRPLG_LOG_ERR(PLUGIN_NAME, "Error loading current system timezone-name value"); + goto error_out; + break; + } + } + } + } + + goto out; + +error_out: + error = -1; + +out: + return 0; +} + +static int system_startup_store_dns_resolver(void *priv, const struct lyd_node *system_container_node) +{ + int error = 0; + system_ctx_t *ctx = (system_ctx_t *) priv; + struct lyd_node *dns_resolver_container_node = NULL; + struct lyd_node *search_leaf_list_node = NULL; + struct lyd_node *server_list_node = NULL; + struct lyd_node *server_name_leaf_node = NULL; + struct lyd_node *server_address_leaf_node = NULL; + struct lyd_node *server_port_leaf_node = NULL; + struct lyd_node *udp_and_tcp_container_node = NULL; + system_dns_server_element_t *servers_head = NULL; + system_dns_search_element_t *search_head = NULL; + system_dns_server_t tmp_server = {0}; + system_dns_search_t tmp_search = {0}; + system_ip_address_t tmp_ip = {0}; + srpc_check_status_t search_check_status = srpc_check_status_none, server_check_status = srpc_check_status_none; + + SRPLG_LOG_INF(PLUGIN_NAME, "Storing dns-resolver startup data"); + + dns_resolver_container_node = srpc_ly_tree_get_child_container(system_container_node, "dns-resolver"); + if (dns_resolver_container_node) { + // get search leaf list + search_leaf_list_node = srpc_ly_tree_get_child_leaf_list(dns_resolver_container_node, "search"); + server_list_node = srpc_ly_tree_get_child_list(dns_resolver_container_node, "server"); + + if (search_leaf_list_node) { + // store search list + while (search_leaf_list_node) { + system_dns_search_init(&tmp_search); + + const char *domain = lyd_get_value(search_leaf_list_node); + + // SRPLG_LOG_INF(PLUGIN_NAME, "Adding DNS search value %s", domain); + + error = system_dns_search_set_domain(&tmp_search, domain); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_dns_search_set_domain() error (%d)", error); + goto error_out; + } + + error = system_dns_search_set_ifindex(&tmp_search, 0); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_dns_search_set_ifindex() error (%d)", error); + goto error_out; + } + + error = system_dns_search_set_search(&tmp_search, 0); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_dns_search_set_search() error (%d)", error); + goto error_out; + } + + // add to the list + error = system_dns_search_list_add(&search_head, tmp_search); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_dns_search_list_add() error (%d)", error); + goto error_out; + } + + system_dns_search_free(&tmp_search); + + search_leaf_list_node = srpc_ly_tree_get_leaf_list_next(search_leaf_list_node); + } + + SRPLG_LOG_INF(PLUGIN_NAME, "Checking DNS search values on the system"); + search_check_status = system_dns_resolver_check_search(ctx, search_head); + SRPLG_LOG_INF(PLUGIN_NAME, "Recieved check status = %d", search_check_status); + + switch (search_check_status) { + case srpc_check_status_none: + // should not be recieved - treat same as an error + SRPLG_LOG_ERR(PLUGIN_NAME, "Error occured while checking DNS search system values"); + goto error_out; + break; + case srpc_check_status_error: + SRPLG_LOG_ERR(PLUGIN_NAME, "Error occured while checking DNS search system values"); + goto error_out; + break; + case srpc_check_status_non_existant: + // values don't exist - apply them to the system + SRPLG_LOG_INF(PLUGIN_NAME, "Storing DNS search values from the datastore to the system"); + + // apply search values to the system + error = system_dns_resolver_store_search(ctx, search_head); + if (error) { + SRPLG_LOG_INF(PLUGIN_NAME, "system_dns_resolver_store_search() error (%d)", error); + goto error_out; + } + + SRPLG_LOG_INF(PLUGIN_NAME, "Stored DNS search values from the datastore to the system"); + break; + case srpc_check_status_equal: + // values exist - don't do anything + break; + case srpc_check_status_partial: + // TODO: create an union between startup and system values and apply that list to the system + break; + } + } + + if (server_list_node) { + while (server_list_node) { + // process server list node + system_dns_server_init(&tmp_server); + + server_name_leaf_node = srpc_ly_tree_get_child_leaf(server_list_node, "name"); + udp_and_tcp_container_node = srpc_ly_tree_get_child_container(server_list_node, "udp-and-tcp"); + + const char *name = lyd_get_value(server_name_leaf_node); + // SRPLG_LOG_INF(PLUGIN_NAME, "Adding DNS server %s", name); + + // set name + system_dns_server_set_name(&tmp_server, name); + + if (!udp_and_tcp_container_node) { + SRPLG_LOG_ERR(PLUGIN_NAME, "srpc_ly_tree_get_child_container() failed for udp-and-tcp"); + goto error_out; + } + + server_address_leaf_node = srpc_ly_tree_get_child_leaf(udp_and_tcp_container_node, "address"); + server_port_leaf_node = srpc_ly_tree_get_child_leaf(udp_and_tcp_container_node, "port"); + + // address + if (server_address_leaf_node) { + const char *address = lyd_get_value(server_address_leaf_node); + + // parse address + error = system_ip_address_from_str(&tmp_ip, address); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_ip_address_from_str() error (%d)", error); + goto error_out; + } + + // set address + error = system_dns_server_set_address(&tmp_server, tmp_ip); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_dns_server_set_address() error (%d)", error); + goto error_out; + } + } else { + // no address node -> unable to continue + SRPLG_LOG_INF(PLUGIN_NAME, "srpc_ly_tree_get_child_leaf() failed for leaf address"); + goto error_out; + } + + if (server_port_leaf_node) { + const char *port = lyd_get_value(server_port_leaf_node); + + // parse into int + const int port_i32 = atoi(port); + + // set port + error = system_dns_server_set_port(&tmp_server, port_i32); + if (error) { + SRPLG_LOG_INF(PLUGIN_NAME, "system_dns_server_set_port() error (%d)", error); + goto error_out; + } + } + + // append to the list + error = system_dns_server_list_add(&servers_head, tmp_server); + if (error) { + SRPLG_LOG_INF(PLUGIN_NAME, "system_dns_server_list_add() error (%d)", error); + goto error_out; + } + + system_dns_server_free(&tmp_server); + + server_list_node = srpc_ly_tree_get_list_next(server_list_node); + } + + SRPLG_LOG_INF(PLUGIN_NAME, "Checking DNS server values on the system"); + server_check_status = system_dns_resolver_check_server(ctx, servers_head); + SRPLG_LOG_INF(PLUGIN_NAME, "Recieved check status = %d", server_check_status); + + switch (server_check_status) { + case srpc_check_status_none: + // should not be recieved - treat same as an error + SRPLG_LOG_ERR(PLUGIN_NAME, "Error occured while checking DNS server system values"); + goto error_out; + break; + case srpc_check_status_error: + SRPLG_LOG_ERR(PLUGIN_NAME, "Error occured while checking DNS server system values"); + goto error_out; + break; + case srpc_check_status_non_existant: + SRPLG_LOG_INF(PLUGIN_NAME, "Storing DNS server values from the datastore to the system"); + + // gathered all servers - store them to the system + error = system_dns_resolver_store_server(ctx, servers_head); + if (error) { + SRPLG_LOG_INF(PLUGIN_NAME, "system_dns_resolver_store_server() error (%d)", error); + goto error_out; + } + + SRPLG_LOG_INF(PLUGIN_NAME, "Stored DNS server values from the datastore to the system"); + break; + case srpc_check_status_equal: + // don't do anything + SRPLG_LOG_INF(PLUGIN_NAME, "DNS server values already exist on the system - no need to apply anything"); + break; + case srpc_check_status_partial: + // TODO: implement + break; + } + } + } + + goto out; + +error_out: + error = -1; + +out: + // remove temp values if something was interrupted + system_dns_search_free(&tmp_search); + system_dns_server_free(&tmp_server); + + // free allocated lists + system_dns_search_list_free(&search_head); + system_dns_server_list_free(&servers_head); + + return error; +} + +static int system_startup_store_authentication(void *priv, const struct lyd_node *system_container_node) +{ + int error = 0; + + system_ctx_t *ctx = (system_ctx_t *) priv; + + // libyang + struct lyd_node *authentication_container_node = NULL; + struct lyd_node *local_user_list_node = NULL, *user_name_leaf_node = NULL, *user_password_leaf_node; + struct lyd_node *authorized_key_list_node = NULL, *key_name_leaf_node = NULL, *key_algorithm_leaf_node = NULL, *key_data_leaf_node = NULL; + + // data + system_local_user_element_t *user_head = NULL, *found_user_el = NULL, *user_iter = NULL; + system_local_user_element_t *system_user_head = NULL; + system_local_user_element_t *complement_user_head = NULL; + system_local_user_t temp_user = {0}; + system_authorized_key_t temp_key = {0}; + + // features + bool authentication_enabled = srpc_feature_status_hash_check(ctx->ietf_system_features, "authentication"); + bool local_users_enabled = srpc_feature_status_hash_check(ctx->ietf_system_features, "local-users"); + + // srpc + srpc_check_status_t user_check_status = srpc_check_status_none, key_check_status = srpc_check_status_none; + + if (authentication_enabled) { + SRPLG_LOG_INF(PLUGIN_NAME, "Storing authentication startup data"); + + authentication_container_node = srpc_ly_tree_get_child_container(system_container_node, "authentication"); + if (authentication_container_node) { + if (local_users_enabled) { + SRPLG_LOG_INF(PLUGIN_NAME, "Storing local-users startup data"); + + local_user_list_node = srpc_ly_tree_get_child_list(authentication_container_node, "user"); + while (local_user_list_node) { + // create user + system_local_user_init(&temp_user); + + user_name_leaf_node = srpc_ly_tree_get_child_leaf(local_user_list_node, "name"); + user_password_leaf_node = srpc_ly_tree_get_child_leaf(local_user_list_node, "password"); + + // a name has to exist for the list element + assert(user_name_leaf_node != NULL); + + // set name + error = system_local_user_set_name(&temp_user, lyd_get_value(user_name_leaf_node)); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_local_user_set_name() error (%d)", error); + goto error_out; + } + + // set password + if (user_password_leaf_node) { + error = system_local_user_set_password(&temp_user, lyd_get_value(user_password_leaf_node)); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_local_user_set_password() error (%d)", error); + goto error_out; + } + } + + // add user to the list + error = system_local_user_list_add(&user_head, temp_user); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_local_user_list_add() error (%d)", error); + goto error_out; + } + + // get current user + found_user_el = system_local_user_list_find(user_head, temp_user.name); + if (!found_user_el) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_local_user_list_find() failed"); + goto error_out; + } + + // user found - setup keys if any + authorized_key_list_node = srpc_ly_tree_get_child_list(local_user_list_node, "authorized-key"); + while (authorized_key_list_node) { + // add key to the current user (found_user_el) + system_authorized_key_init(&temp_key); + + key_name_leaf_node = srpc_ly_tree_get_child_leaf(authorized_key_list_node, "name"); + key_algorithm_leaf_node = srpc_ly_tree_get_child_leaf(authorized_key_list_node, "algorithm"); + key_data_leaf_node = srpc_ly_tree_get_child_leaf(authorized_key_list_node, "key-data"); + + // key must have a name + assert(key_name_leaf_node != NULL); + + error = system_authorized_key_set_name(&temp_key, lyd_get_value(key_name_leaf_node)); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_authorized_key_set_name() error (%d)", error); + goto error_out; + } + + if (key_algorithm_leaf_node) { + // set algorithm + error = system_authorized_key_set_algorithm(&temp_key, lyd_get_value(key_algorithm_leaf_node)); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_authorized_key_set_algorithm() error (%d)", error); + goto error_out; + } + } + + if (key_data_leaf_node) { + // set algorithm + error = system_authorized_key_set_data(&temp_key, lyd_get_value(key_data_leaf_node)); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_authorized_key_set_data() error (%d)", error); + goto error_out; + } + } + + // add to the list of current user keys + error = system_authorized_key_list_add(&found_user_el->user.key_head, temp_key); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_authorized_key_list_add() error (%d)", error); + goto error_out; + } + + // free temp data + system_authorized_key_free(&temp_key); + authorized_key_list_node = srpc_ly_tree_get_list_next(authorized_key_list_node); + } + + system_local_user_free(&temp_user); + local_user_list_node = srpc_ly_tree_get_list_next(local_user_list_node); + } + + // get system users + system_local_user_list_init(&system_user_head); + + // check if all users exist on the system + SRPLG_LOG_INF(PLUGIN_NAME, "Checking startup local user system values"); + user_check_status = system_authentication_check_user(ctx, user_head, &system_user_head); + SRPLG_LOG_INF(PLUGIN_NAME, "Recieved local users check status: %d", user_check_status); + + switch (user_check_status) { + case srpc_check_status_none: + SRPLG_LOG_ERR(PLUGIN_NAME, "Error occured while checking local user system values"); + goto error_out; + break; + case srpc_check_status_error: + SRPLG_LOG_ERR(PLUGIN_NAME, "Error occured while checking local user system values"); + goto error_out; + break; + case srpc_check_status_non_existant: + SRPLG_LOG_INF(PLUGIN_NAME, "Startup local users don\'t exist on the system - starting to store startup local users"); + error = system_authentication_store_user(ctx, user_head); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_authentication_store_user() error (%d)", error); + goto error_out; + } + break; + case srpc_check_status_equal: + SRPLG_LOG_INF(PLUGIN_NAME, "Startup local users already exist on the system - no need to store anything"); + break; + case srpc_check_status_partial: + SRPLG_LOG_INF(PLUGIN_NAME, "Some startup local users exist while others don\'t - creating non existant users"); + + // get complement of startup without system + complement_user_head = system_local_user_list_complement(user_head, system_user_head); + if (!complement_user_head) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_local_user_list_complement() failed"); + goto error_out; + } + + SRPLG_LOG_INF(PLUGIN_NAME, "Storing missing local users from startup to the system"); + + // add complement users to system + error = system_authentication_store_user(ctx, complement_user_head); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_authentication_store_user() error (%d)", error); + goto error_out; + } + + SRPLG_LOG_INF(PLUGIN_NAME, "Missing local users from startup are stored in the system"); + break; + } + + // after matching startup and system values for users - match key lists for all users + SRPLG_LOG_INF(PLUGIN_NAME, "Checking startup local user authorized key system values"); + LL_FOREACH(user_head, user_iter) + { + // check first if any keys exist in startup + if (user_iter->user.key_head) { + key_check_status = system_authentication_check_user_authorized_key(ctx, user_iter->user.name, user_iter->user.key_head); + SRPLG_LOG_INF(PLUGIN_NAME, "Recieved authorized-key check status %d for user %s", user_check_status, user_iter->user.name); + + switch (key_check_status) { + case srpc_check_status_none: + SRPLG_LOG_ERR(PLUGIN_NAME, "Error occured while checking local user authorized key system values"); + goto error_out; + break; + case srpc_check_status_error: + SRPLG_LOG_ERR(PLUGIN_NAME, "Error occured while checking local user authorized key system values"); + goto error_out; + break; + case srpc_check_status_non_existant: + SRPLG_LOG_INF(PLUGIN_NAME, "Startup authorized keys don\'t exist on the system for user %s - storing authorized keys for user %s", user_iter->user.name, user_iter->user.name); + error = system_authentication_store_user_authorized_key(ctx, user_iter->user.name, user_iter->user.key_head); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_authentication_store_user_authorized_key() error (%d) for user %s", error, user_iter->user.name); + goto error_out; + } + break; + case srpc_check_status_equal: + SRPLG_LOG_INF(PLUGIN_NAME, "Startup authorized keys already exist for local user %s - no need to store anything", user_iter->user.name); + break; + case srpc_check_status_partial: + // TODO + break; + } + } + } + } + } + } + + goto out; + +error_out: + error = -1; + +out: + + // free temp values if interrupted + system_local_user_free(&temp_user); + system_authorized_key_free(&temp_key); + + // free lists + system_local_user_list_free(&user_head); + system_local_user_list_free(&system_user_head); + system_local_user_list_free(&complement_user_head); + + return error; +} \ No newline at end of file diff --git a/src/plugins/ietf-system/datastore/running/store.h b/src/plugins/ietf-system/datastore/running/store.h new file mode 100644 index 0000000..16f7f3a --- /dev/null +++ b/src/plugins/ietf-system/datastore/running/store.h @@ -0,0 +1,21 @@ +/* + * telekom / sysrepo-plugin-system + * + * This program is made available under the terms of the + * BSD 3-Clause license which is available at + * https://opensource.org/licenses/BSD-3-Clause + * + * SPDX-FileCopyrightText: 2022 Deutsche Telekom AG + * SPDX-FileContributor: Sartura Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ +#ifndef SYSTEM_PLUGIN_DATASTORE_RUNNING_STORE_H +#define SYSTEM_PLUGIN_DATASTORE_RUNNING_STORE_H + +#include +#include + +int system_running_ds_store(system_ctx_t *ctx, sr_session_ctx_t *session); + +#endif // SYSTEM_PLUGIN_DATASTORE_RUNNING_STORE_H \ No newline at end of file diff --git a/src/plugins/ietf-system/plugin.c b/src/plugins/ietf-system/plugin.c index 5d435ba..c943b17 100644 --- a/src/plugins/ietf-system/plugin.c +++ b/src/plugins/ietf-system/plugin.c @@ -28,8 +28,8 @@ #include "srpc/types.h" // startup -#include "core/startup/load.h" -#include "core/startup/store.h" +#include "datastore/running/load.h" +#include "datastore/running/store.h" // subs #include "core/subscription/change.h" @@ -186,22 +186,22 @@ int sr_plugin_init_cb(sr_session_ctx_t *running_session, void **private_data) } if (empty_startup) { - SRPLG_LOG_INF(PLUGIN_NAME, "Startup datastore is empty"); + SRPLG_LOG_INF(PLUGIN_NAME, "Running datastore is empty"); SRPLG_LOG_INF(PLUGIN_NAME, "Loading initial system data"); // load data only into running DS - do not use startup unless said explicitly - error = system_startup_load_data(ctx, running_session); + error = system_running_ds_load(ctx, running_session); if (error) { - SRPLG_LOG_ERR(PLUGIN_NAME, "Error loading initial data into the startup datastore... exiting"); + SRPLG_LOG_ERR(PLUGIN_NAME, "Error loading initial data into the running datastore... exiting"); goto error_out; } } else { // make sure the data from startup DS is stored in the system - SRPLG_LOG_INF(PLUGIN_NAME, "Startup datastore contains data"); - SRPLG_LOG_INF(PLUGIN_NAME, "Storing startup datastore data in the system"); + SRPLG_LOG_INF(PLUGIN_NAME, "Running datastore contains data"); + SRPLG_LOG_INF(PLUGIN_NAME, "Storing running datastore data in the system"); // check and apply if needed data from startup to the system - error = system_startup_store_data(ctx, startup_session); + error = system_running_ds_store(ctx, startup_session); if (error) { SRPLG_LOG_ERR(PLUGIN_NAME, "Error applying initial data from startup datastore to the system... exiting"); goto error_out; From fae3c7d3ae9b5acd139cfb08d087fe230b43ca0d Mon Sep 17 00:00:00 2001 From: Mateo Cindric Date: Mon, 9 Jan 2023 12:26:29 +0000 Subject: [PATCH 11/25] CI/CD: change base docker image --- .gitlab-ci.yml | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ccb80e4..0af1fc1 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,4 +1,4 @@ -image: debian +image: ${SYSREPO_CICD_IMAGE} variables: GIT_SUBMODULE_STRATEGY: recursive @@ -7,22 +7,6 @@ stages: - build - test -# install libraries -before_script: - - apt-get update - - apt-get -y install clang cmake git libpcre2-dev libsystemd-dev libcmocka0 libcmocka-dev valgrind - - apt-get -y install python3 python3-pip - - git clone https://github.com/CESNET/libyang.git - - git clone https://github.com/sysrepo/sysrepo.git - - git clone https://github.com/telekom/sysrepo-plugins-common.git - - git clone https://github.com/sartura/umgmt.git - - cd libyang; git checkout devel; mkdir build; cd build; cmake .. -DCMAKE_C_COMPILER=clang; make -j install; cd ../../ - - cd sysrepo; git checkout devel; mkdir build; cd build; cmake .. -DCMAKE_C_COMPILER=clang; make -j install; cd ../../ - - cd sysrepo-plugins-common; git submodule init; git submodule update; mkdir build; cd build; cmake .. -DCMAKE_C_COMPILER=clang; make -j install; cd ../.. - - cd umgmt; git submodule init; git submodule update; mkdir build; cd build; cmake .. -DCMAKE_C_COMPILER=clang; make -j install; cd ../.. - - pip3 install libyang - - pip3 install Jinja2 - build:default: stage: build From ae54990c6c111908b9eaa6f8fe0349d1830efa50 Mon Sep 17 00:00:00 2001 From: Mateo Cindric Date: Sat, 14 Jan 2023 17:09:13 +0000 Subject: [PATCH 12/25] system-plugin: add PIC flag to the core static library --- CMakeLists.txt | 76 ++++++++++++++------------ src/plugins/ietf-system/CMakeLists.txt | 17 +++++- 2 files changed, 54 insertions(+), 39 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 68645ca..0e26841 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,53 +47,57 @@ include_directories( set( CORE_SOURCES - src/core/common.c - src/core/ly_tree.c + ${CMAKE_SOURCE_DIR}/src/core/common.c + ${CMAKE_SOURCE_DIR}/src/core/ly_tree.c # startup - src/core/startup/load.c - src/core/startup/store.c + ${CMAKE_SOURCE_DIR}/src/core/startup/load.c + ${CMAKE_SOURCE_DIR}/src/core/startup/store.c # subs - src/core/subscription/change.c - src/core/subscription/operational.c - src/core/subscription/rpc.c + ${CMAKE_SOURCE_DIR}/src/core/subscription/change.c + ${CMAKE_SOURCE_DIR}/src/core/subscription/operational.c + ${CMAKE_SOURCE_DIR}/src/core/subscription/rpc.c # data - src/core/data/system/ip_address.c - src/core/data/system/dns_resolver/search.c - src/core/data/system/dns_resolver/search/list.c - src/core/data/system/dns_resolver/server.c - src/core/data/system/dns_resolver/server/list.c - src/core/data/system/ntp/server.c - src/core/data/system/ntp/server/list.c - src/core/data/system/authentication/authorized_key.c - src/core/data/system/authentication/authorized_key/list.c - src/core/data/system/authentication/local_user.c - src/core/data/system/authentication/local_user/list.c + ${CMAKE_SOURCE_DIR}/src/core/data/system/ip_address.c + ${CMAKE_SOURCE_DIR}/src/core/data/system/dns_resolver/search.c + ${CMAKE_SOURCE_DIR}/src/core/data/system/dns_resolver/search/list.c + ${CMAKE_SOURCE_DIR}/src/core/data/system/dns_resolver/server.c + ${CMAKE_SOURCE_DIR}/src/core/data/system/dns_resolver/server/list.c + ${CMAKE_SOURCE_DIR}/src/core/data/system/ntp/server.c + ${CMAKE_SOURCE_DIR}/src/core/data/system/ntp/server/list.c + ${CMAKE_SOURCE_DIR}/src/core/data/system/authentication/authorized_key.c + ${CMAKE_SOURCE_DIR}/src/core/data/system/authentication/authorized_key/list.c + ${CMAKE_SOURCE_DIR}/src/core/data/system/authentication/local_user.c + ${CMAKE_SOURCE_DIR}/src/core/data/system/authentication/local_user/list.c # system API - src/core/api/system/load.c - src/core/api/system/check.c - src/core/api/system/store.c - src/core/api/system/change.c - src/core/api/system/ntp/load.c - src/core/api/system/ntp/check.c - src/core/api/system/ntp/store.c - src/core/api/system/ntp/change.c - src/core/api/system/dns_resolver/load.c - src/core/api/system/dns_resolver/check.c - src/core/api/system/dns_resolver/store.c - src/core/api/system/dns_resolver/change.c - src/core/api/system/authentication/load.c - src/core/api/system/authentication/check.c - src/core/api/system/authentication/store.c - src/core/api/system/authentication/change.c + ${CMAKE_SOURCE_DIR}/src/core/api/system/load.c + ${CMAKE_SOURCE_DIR}/src/core/api/system/check.c + ${CMAKE_SOURCE_DIR}/src/core/api/system/store.c + ${CMAKE_SOURCE_DIR}/src/core/api/system/change.c + ${CMAKE_SOURCE_DIR}/src/core/api/system/ntp/load.c + ${CMAKE_SOURCE_DIR}/src/core/api/system/ntp/check.c + ${CMAKE_SOURCE_DIR}/src/core/api/system/ntp/store.c + ${CMAKE_SOURCE_DIR}/src/core/api/system/ntp/change.c + ${CMAKE_SOURCE_DIR}/src/core/api/system/dns_resolver/load.c + ${CMAKE_SOURCE_DIR}/src/core/api/system/dns_resolver/check.c + ${CMAKE_SOURCE_DIR}/src/core/api/system/dns_resolver/store.c + ${CMAKE_SOURCE_DIR}/src/core/api/system/dns_resolver/change.c + ${CMAKE_SOURCE_DIR}/src/core/api/system/authentication/load.c + ${CMAKE_SOURCE_DIR}/src/core/api/system/authentication/check.c + ${CMAKE_SOURCE_DIR}/src/core/api/system/authentication/store.c + ${CMAKE_SOURCE_DIR}/src/core/api/system/authentication/change.c ) -# build plugin static library +# build plugin core static library add_library(${PLUGIN_CORE_LIBRARY_NAME} STATIC ${CORE_SOURCES}) -install(TARGETS ${PLUGIN_CORE_LIBRARY_NAME} DESTINATION lib) +target_compile_options( + ${PLUGIN_CORE_LIBRARY_NAME} + PRIVATE + -fPIC +) # add main plugin to the build process add_subdirectory("src/plugins/ietf-system") diff --git a/src/plugins/ietf-system/CMakeLists.txt b/src/plugins/ietf-system/CMakeLists.txt index 71ad8f4..3393005 100644 --- a/src/plugins/ietf-system/CMakeLists.txt +++ b/src/plugins/ietf-system/CMakeLists.txt @@ -12,7 +12,7 @@ # cmake_minimum_required(VERSION 3.0) -set(PLUGIN_LIBRARY_NAME "srplg-ietf-system") +set(PLUGIN_MODULE_NAME "srplg-ietf-system") set(PLUGIN_EXECUTABLE_NAME "ietf-system-plugin") set( @@ -32,10 +32,21 @@ endif() # add plugin as a sysrepo-plugind library add_library( - ${PLUGIN_LIBRARY_NAME} + ${PLUGIN_MODULE_NAME} MODULE ${PLUGIN_SOURCES} ) +target_link_libraries( + ${PLUGIN_MODULE_NAME} + + ${PLUGIN_CORE_LIBRARY_NAME} + + ${SYSREPO_LIBRARIES} + ${LIBYANG_LIBRARIES} + ${SRPC_LIBRARIES} + ${UMGMT_LIBRARIES} + ${SYSTEMD_LIBRARIES} +) # add plugin as a standalone executable add_executable( @@ -58,5 +69,5 @@ target_link_libraries( ${SYSTEMD_LIBRARIES} ) -install(TARGETS ${PLUGIN_LIBRARY_NAME} DESTINATION lib) +install(TARGETS ${PLUGIN_MODULE_NAME} DESTINATION lib) install(TARGETS ${PLUGIN_EXECUTABLE_NAME} DESTINATION bin) \ No newline at end of file From 9992a794f13cb568d297c4cd547e3d36f4901f7e Mon Sep 17 00:00:00 2001 From: Mateo Cindric Date: Thu, 9 Feb 2023 16:06:11 +0000 Subject: [PATCH 13/25] ietf-system-augeas: move NTP running DS load code into the augeas specific plugin --- .../datastore/running/load.c | 176 +++++++++++++++++- 1 file changed, 175 insertions(+), 1 deletion(-) diff --git a/src/plugins/ietf-system-augeas/datastore/running/load.c b/src/plugins/ietf-system-augeas/datastore/running/load.c index e2bff48..ff4e05c 100644 --- a/src/plugins/ietf-system-augeas/datastore/running/load.c +++ b/src/plugins/ietf-system-augeas/datastore/running/load.c @@ -1,10 +1,184 @@ #include "load.h" -static int system_startup_load_hostname(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node); +#include + +#include + +#include + +// core library +#include "core/ly_tree.h" +#include "core/api/system/ntp/load.h" +#include "core/data/system/ntp/server/list.h" + static int system_startup_load_ntp(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node); int system_aug_running_ds_load(system_ctx_t *ctx, sr_session_ctx_t *session) { int error = 0; + + const struct ly_ctx *ly_ctx = NULL; + struct lyd_node *system_container_node = NULL; + sr_conn_ctx_t *conn_ctx = NULL; + + srpc_startup_load_t load_values[] = { + { + "ntp", + system_startup_load_ntp, + }, + }; + + conn_ctx = sr_session_get_connection(session); + ly_ctx = sr_acquire_context(conn_ctx); + if (ly_ctx == NULL) { + SRPLG_LOG_ERR(PLUGIN_NAME, "Unable to get ly_ctx variable"); + goto error_out; + } + + // reload features hash before adding all system values + SRPC_SAFE_CALL_ERR(error, srpc_feature_status_hash_reload(&ctx->ietf_system_features, session, IETF_SYSTEM_YANG_MODULE), error_out); + + // load system container info + error = system_ly_tree_create_system(ly_ctx, &system_container_node); + for (size_t i = 0; i < ARRAY_SIZE(load_values); i++) { + const srpc_startup_load_t *load = &load_values[i]; + + error = load->cb((void *) ctx, session, ly_ctx, system_container_node); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "Node creation callback failed for value %s", load->name); + goto error_out; + } + } + +// enable or disable storing into startup - use when testing load functionality for now +#define SYSTEM_PLUGIN_LOAD_STARTUP + +#ifdef SYSTEM_PLUGIN_LOAD_STARTUP + error = sr_edit_batch(session, system_container_node, "merge"); + if (error != SR_ERR_OK) { + SRPLG_LOG_ERR(PLUGIN_NAME, "sr_edit_batch() error (%d): %s", error, sr_strerror(error)); + goto error_out; + } + + error = sr_apply_changes(session, 0); + if (error != 0) { + SRPLG_LOG_ERR(PLUGIN_NAME, "sr_apply_changes() error (%d): %s", error, sr_strerror(error)); + goto error_out; + } +#endif + + goto out; + +error_out: + error = -1; + +out: + if (system_container_node) { + lyd_free_tree(system_container_node); + } + + sr_release_context(conn_ctx); + + return error; +} + +static int system_startup_load_ntp(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node) +{ + int error = 0; + + system_ctx_t *ctx = priv; + + // ietf-system nodes + struct lyd_node *ntp_container_node = NULL, *server_list_node = NULL; + + // feature check + bool ntp_enabled = srpc_feature_status_hash_check(ctx->ietf_system_features, "ntp"); + bool ntp_udp_port_enabled = srpc_feature_status_hash_check(ctx->ietf_system_features, "ntp-udp-port"); + + // load list + system_ntp_server_element_t *ntp_server_head = NULL, *ntp_server_iter = NULL; + + SRPLG_LOG_INF(PLUGIN_NAME, "Loading NTP data"); + + if (ntp_enabled) { + error = system_ly_tree_create_ntp(ly_ctx, parent_node, &ntp_container_node); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_ly_tree_create_ntp() error (%d)", error); + goto error_out; + } + + // load system values + system_ntp_server_list_init(&ntp_server_head); + error = system_ntp_load_server(ctx, &ntp_server_head); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_ntp_load_server() error (%d)", error); + goto error_out; + } + + LL_FOREACH(ntp_server_head, ntp_server_iter) + { + // name + error = system_ly_tree_create_ntp_server(ly_ctx, ntp_container_node, &server_list_node, ntp_server_iter->server.name); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_ly_tree_create_ntp_server() error (%d)", error); + goto error_out; + } + + SRPLG_LOG_INF(PLUGIN_NAME, "Setting address %s", ntp_server_iter->server.address); + + // address + error = system_ly_tree_create_ntp_server_address(ly_ctx, server_list_node, ntp_server_iter->server.address); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_ly_tree_create_ntp_server_address() error (%d)", error); + goto error_out; + } + + SRPLG_LOG_INF(PLUGIN_NAME, "Setting port \"%s\"", ntp_server_iter->server.port); + + // port + if (ntp_server_iter->server.port && ntp_udp_port_enabled) { + error = system_ly_tree_create_ntp_server_port(ly_ctx, server_list_node, ntp_server_iter->server.port); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_ly_tree_create_ntp_server_port() error (%d)", error); + goto error_out; + } + } + + // association type + error = system_ly_tree_create_ntp_server_association_type(ly_ctx, server_list_node, ntp_server_iter->server.association_type); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_ly_tree_create_ntp_server_association_type() error (%d)", error); + goto error_out; + } + + // iburst + if (ntp_server_iter->server.iburst) { + error = system_ly_tree_create_ntp_server_iburst(ly_ctx, server_list_node, ntp_server_iter->server.iburst); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_ly_tree_create_ntp_server_iburst() error (%d)", error); + goto error_out; + } + } + + // prefer + if (ntp_server_iter->server.prefer) { + error = system_ly_tree_create_ntp_server_prefer(ly_ctx, server_list_node, ntp_server_iter->server.prefer); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_ly_tree_create_ntp_server_prefer() error (%d)", error); + goto error_out; + } + } + } + + goto out; + } + +error_out: + error = -1; + +out: + + system_ntp_server_list_free(&ntp_server_head); + return error; } \ No newline at end of file From 8c948277f47a7324691689986f3e8ee78a135f50 Mon Sep 17 00:00:00 2001 From: Mateo Cindric Date: Thu, 9 Feb 2023 16:07:09 +0000 Subject: [PATCH 14/25] ietf-system-augeas: remove unused NTP load functionality --- src/core/startup/load.c | 102 ---------------------------------------- 1 file changed, 102 deletions(-) diff --git a/src/core/startup/load.c b/src/core/startup/load.c index e045835..5e35236 100644 --- a/src/core/startup/load.c +++ b/src/core/startup/load.c @@ -46,7 +46,6 @@ static int system_startup_load_hostname(void *priv, sr_session_ctx_t *session, c static int system_startup_load_contact(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node); static int system_startup_load_location(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node); static int system_startup_load_timezone_name(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node); -static int system_startup_load_ntp(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node); static int system_startup_load_dns_resolver(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node); static int system_startup_load_authentication(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node); @@ -221,107 +220,6 @@ static int system_startup_load_timezone_name(void *priv, sr_session_ctx_t *sessi return error; } -static int system_startup_load_ntp(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node) -{ - int error = 0; - - system_ctx_t *ctx = priv; - - // ietf-system nodes - struct lyd_node *ntp_container_node = NULL, *server_list_node = NULL; - - // feature check - bool ntp_enabled = srpc_feature_status_hash_check(ctx->ietf_system_features, "ntp"); - bool ntp_udp_port_enabled = srpc_feature_status_hash_check(ctx->ietf_system_features, "ntp-udp-port"); - - // load list - system_ntp_server_element_t *ntp_server_head = NULL, *ntp_server_iter = NULL; - - SRPLG_LOG_INF(PLUGIN_NAME, "Loading NTP data"); - - if (ntp_enabled) { - error = system_ly_tree_create_ntp(ly_ctx, parent_node, &ntp_container_node); - if (error) { - SRPLG_LOG_ERR(PLUGIN_NAME, "system_ly_tree_create_ntp() error (%d)", error); - goto error_out; - } - - // load system values - system_ntp_server_list_init(&ntp_server_head); - error = system_ntp_load_server(ctx, &ntp_server_head); - if (error) { - SRPLG_LOG_ERR(PLUGIN_NAME, "system_ntp_load_server() error (%d)", error); - goto error_out; - } - - LL_FOREACH(ntp_server_head, ntp_server_iter) - { - // name - error = system_ly_tree_create_ntp_server(ly_ctx, ntp_container_node, &server_list_node, ntp_server_iter->server.name); - if (error) { - SRPLG_LOG_ERR(PLUGIN_NAME, "system_ly_tree_create_ntp_server() error (%d)", error); - goto error_out; - } - - SRPLG_LOG_INF(PLUGIN_NAME, "Setting address %s", ntp_server_iter->server.address); - - // address - error = system_ly_tree_create_ntp_server_address(ly_ctx, server_list_node, ntp_server_iter->server.address); - if (error) { - SRPLG_LOG_ERR(PLUGIN_NAME, "system_ly_tree_create_ntp_server_address() error (%d)", error); - goto error_out; - } - - SRPLG_LOG_INF(PLUGIN_NAME, "Setting port \"%s\"", ntp_server_iter->server.port); - - // port - if (ntp_server_iter->server.port && ntp_udp_port_enabled) { - error = system_ly_tree_create_ntp_server_port(ly_ctx, server_list_node, ntp_server_iter->server.port); - if (error) { - SRPLG_LOG_ERR(PLUGIN_NAME, "system_ly_tree_create_ntp_server_port() error (%d)", error); - goto error_out; - } - } - - // association type - error = system_ly_tree_create_ntp_server_association_type(ly_ctx, server_list_node, ntp_server_iter->server.association_type); - if (error) { - SRPLG_LOG_ERR(PLUGIN_NAME, "system_ly_tree_create_ntp_server_association_type() error (%d)", error); - goto error_out; - } - - // iburst - if (ntp_server_iter->server.iburst) { - error = system_ly_tree_create_ntp_server_iburst(ly_ctx, server_list_node, ntp_server_iter->server.iburst); - if (error) { - SRPLG_LOG_ERR(PLUGIN_NAME, "system_ly_tree_create_ntp_server_iburst() error (%d)", error); - goto error_out; - } - } - - // prefer - if (ntp_server_iter->server.prefer) { - error = system_ly_tree_create_ntp_server_prefer(ly_ctx, server_list_node, ntp_server_iter->server.prefer); - if (error) { - SRPLG_LOG_ERR(PLUGIN_NAME, "system_ly_tree_create_ntp_server_prefer() error (%d)", error); - goto error_out; - } - } - } - - goto out; - } - -error_out: - error = -1; - -out: - - system_ntp_server_list_free(&ntp_server_head); - - return error; -} - static int system_startup_load_dns_resolver(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node) { int error = 0; From fc9487f57fc09a72d4897042c384388f617c73f1 Mon Sep 17 00:00:00 2001 From: Mateo Cindric Date: Thu, 9 Feb 2023 16:09:23 +0000 Subject: [PATCH 15/25] ietf-system-augeas: remove unused NTP load functionality from the main plugin --- .../ietf-system/datastore/running/load.c | 101 ------------------ 1 file changed, 101 deletions(-) diff --git a/src/plugins/ietf-system/datastore/running/load.c b/src/plugins/ietf-system/datastore/running/load.c index d24c5e7..44af2c2 100644 --- a/src/plugins/ietf-system/datastore/running/load.c +++ b/src/plugins/ietf-system/datastore/running/load.c @@ -182,107 +182,6 @@ static int system_startup_load_timezone_name(void *priv, sr_session_ctx_t *sessi return error; } -static int system_startup_load_ntp(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node) -{ - int error = 0; - - system_ctx_t *ctx = priv; - - // ietf-system nodes - struct lyd_node *ntp_container_node = NULL, *server_list_node = NULL; - - // feature check - bool ntp_enabled = srpc_feature_status_hash_check(ctx->ietf_system_features, "ntp"); - bool ntp_udp_port_enabled = srpc_feature_status_hash_check(ctx->ietf_system_features, "ntp-udp-port"); - - // load list - system_ntp_server_element_t *ntp_server_head = NULL, *ntp_server_iter = NULL; - - SRPLG_LOG_INF(PLUGIN_NAME, "Loading NTP data"); - - if (ntp_enabled) { - error = system_ly_tree_create_ntp(ly_ctx, parent_node, &ntp_container_node); - if (error) { - SRPLG_LOG_ERR(PLUGIN_NAME, "system_ly_tree_create_ntp() error (%d)", error); - goto error_out; - } - - // load system values - system_ntp_server_list_init(&ntp_server_head); - error = system_ntp_load_server(ctx, &ntp_server_head); - if (error) { - SRPLG_LOG_ERR(PLUGIN_NAME, "system_ntp_load_server() error (%d)", error); - goto error_out; - } - - LL_FOREACH(ntp_server_head, ntp_server_iter) - { - // name - error = system_ly_tree_create_ntp_server(ly_ctx, ntp_container_node, &server_list_node, ntp_server_iter->server.name); - if (error) { - SRPLG_LOG_ERR(PLUGIN_NAME, "system_ly_tree_create_ntp_server() error (%d)", error); - goto error_out; - } - - SRPLG_LOG_INF(PLUGIN_NAME, "Setting address %s", ntp_server_iter->server.address); - - // address - error = system_ly_tree_create_ntp_server_address(ly_ctx, server_list_node, ntp_server_iter->server.address); - if (error) { - SRPLG_LOG_ERR(PLUGIN_NAME, "system_ly_tree_create_ntp_server_address() error (%d)", error); - goto error_out; - } - - SRPLG_LOG_INF(PLUGIN_NAME, "Setting port \"%s\"", ntp_server_iter->server.port); - - // port - if (ntp_server_iter->server.port && ntp_udp_port_enabled) { - error = system_ly_tree_create_ntp_server_port(ly_ctx, server_list_node, ntp_server_iter->server.port); - if (error) { - SRPLG_LOG_ERR(PLUGIN_NAME, "system_ly_tree_create_ntp_server_port() error (%d)", error); - goto error_out; - } - } - - // association type - error = system_ly_tree_create_ntp_server_association_type(ly_ctx, server_list_node, ntp_server_iter->server.association_type); - if (error) { - SRPLG_LOG_ERR(PLUGIN_NAME, "system_ly_tree_create_ntp_server_association_type() error (%d)", error); - goto error_out; - } - - // iburst - if (ntp_server_iter->server.iburst) { - error = system_ly_tree_create_ntp_server_iburst(ly_ctx, server_list_node, ntp_server_iter->server.iburst); - if (error) { - SRPLG_LOG_ERR(PLUGIN_NAME, "system_ly_tree_create_ntp_server_iburst() error (%d)", error); - goto error_out; - } - } - - // prefer - if (ntp_server_iter->server.prefer) { - error = system_ly_tree_create_ntp_server_prefer(ly_ctx, server_list_node, ntp_server_iter->server.prefer); - if (error) { - SRPLG_LOG_ERR(PLUGIN_NAME, "system_ly_tree_create_ntp_server_prefer() error (%d)", error); - goto error_out; - } - } - } - - goto out; - } - -error_out: - error = -1; - -out: - - system_ntp_server_list_free(&ntp_server_head); - - return error; -} - static int system_startup_load_dns_resolver(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node) { int error = 0; From 232563dd89fff1fd3fda7422302173f8a395f2df Mon Sep 17 00:00:00 2001 From: Mateo Cindric Date: Thu, 9 Feb 2023 16:11:02 +0000 Subject: [PATCH 16/25] ietf-system-augeas: add hostname load functionality to the main plugin --- .../ietf-system/datastore/running/load.c | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/plugins/ietf-system/datastore/running/load.c b/src/plugins/ietf-system/datastore/running/load.c index 44af2c2..4e3e34e 100644 --- a/src/plugins/ietf-system/datastore/running/load.c +++ b/src/plugins/ietf-system/datastore/running/load.c @@ -42,6 +42,7 @@ #include +static int system_startup_load_hostname(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node); static int system_startup_load_contact(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node); static int system_startup_load_location(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node); static int system_startup_load_timezone_name(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node); @@ -57,6 +58,10 @@ int system_running_ds_load(system_ctx_t *ctx, sr_session_ctx_t *session) sr_conn_ctx_t *conn_ctx = NULL; srpc_startup_load_t load_values[] = { + { + "hostname", + system_startup_load_hostname, + }, { "contact", system_startup_load_contact, @@ -133,6 +138,33 @@ int system_running_ds_load(system_ctx_t *ctx, sr_session_ctx_t *session) return error; } +static int system_startup_load_hostname(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node) +{ + int error = 0; + system_ctx_t *ctx = (system_ctx_t *) priv; + char hostname_buffer[SYSTEM_HOSTNAME_LENGTH_MAX] = {0}; + + error = system_load_hostname(ctx, hostname_buffer); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_load_hostname() error (%d)", error); + goto error_out; + } + + error = system_ly_tree_create_hostname(ly_ctx, parent_node, hostname_buffer); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_ly_tree_create_hostname() error (%d)", error); + goto error_out; + } + + goto out; + +error_out: + error = -1; + +out: + return error; +} + static int system_startup_load_contact(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node) { int error = 0; From 3e47766256ee2ed1ffc7ba59f394f3e7a9e879a1 Mon Sep 17 00:00:00 2001 From: Mateo Cindric Date: Thu, 9 Feb 2023 16:21:20 +0000 Subject: [PATCH 17/25] ietf-system-augeas: move hostname and NTP augyang store related functionality to the augeas specific plugin --- .../datastore/running/load.c | 15 +- .../datastore/running/store.c | 301 +++++++++++++++++- .../ietf-system/datastore/running/load.c | 4 - 3 files changed, 310 insertions(+), 10 deletions(-) diff --git a/src/plugins/ietf-system-augeas/datastore/running/load.c b/src/plugins/ietf-system-augeas/datastore/running/load.c index ff4e05c..cfda0ec 100644 --- a/src/plugins/ietf-system-augeas/datastore/running/load.c +++ b/src/plugins/ietf-system-augeas/datastore/running/load.c @@ -11,7 +11,8 @@ #include "core/api/system/ntp/load.h" #include "core/data/system/ntp/server/list.h" -static int system_startup_load_ntp(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node); +static int system_aug_running_load_hostname(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node); +static int system_aug_running_load_ntp(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node); int system_aug_running_ds_load(system_ctx_t *ctx, sr_session_ctx_t *session) { @@ -22,9 +23,13 @@ int system_aug_running_ds_load(system_ctx_t *ctx, sr_session_ctx_t *session) sr_conn_ctx_t *conn_ctx = NULL; srpc_startup_load_t load_values[] = { + { + "hostname", + system_aug_running_load_hostname, + }, { "ntp", - system_startup_load_ntp, + system_aug_running_load_ntp, }, }; @@ -82,7 +87,11 @@ int system_aug_running_ds_load(system_ctx_t *ctx, sr_session_ctx_t *session) return error; } -static int system_startup_load_ntp(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node) +static int system_aug_running_load_hostname(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node) +{ +} + +static int system_aug_running_load_ntp(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node) { int error = 0; diff --git a/src/plugins/ietf-system-augeas/datastore/running/store.c b/src/plugins/ietf-system-augeas/datastore/running/store.c index 1fcb72c..06eda68 100644 --- a/src/plugins/ietf-system-augeas/datastore/running/store.c +++ b/src/plugins/ietf-system-augeas/datastore/running/store.c @@ -1,10 +1,305 @@ #include "store.h" -static int system_startup_store_hostname(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node); -static int system_startup_store_ntp(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node); +#include +#include +#include + +// core library +#include "core/ly_tree.h" +#include "core/api/system/ntp/store.h" +#include "core/api/system/ntp/check.h" +#include "core/api/system/store.h" +#include "core/api/system/check.h" + +// core data +#include "core/data/system/ntp/server/list.h" +#include "core/data/system/ntp/server.h" + +static int system_aug_running_store_hostname(void *priv, const struct lyd_node *system_container_node); +static int system_aug_running_store_ntp(void *priv, const struct lyd_node *system_container_node); int system_aug_running_ds_store(system_ctx_t *ctx, sr_session_ctx_t *session) { int error = 0; + sr_data_t *subtree = NULL; + + error = sr_get_subtree(session, SYSTEM_SYSTEM_CONTAINER_YANG_PATH, 0, &subtree); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "sr_get_subtree() error (%d): %s", error, sr_strerror(error)); + goto error_out; + } + + srpc_startup_store_t store_values[] = { + { + "hostname", + system_aug_running_store_hostname, + }, + { + "ntp", + system_aug_running_store_ntp, + }, + }; + + // reload feature status hash before storing system data + SRPC_SAFE_CALL_ERR(error, srpc_feature_status_hash_reload(&ctx->ietf_system_features, session, IETF_SYSTEM_YANG_MODULE), error_out); + + for (size_t i = 0; i < ARRAY_SIZE(store_values); i++) { + const srpc_startup_store_t *store = &store_values[i]; + + error = store->cb(ctx, subtree->tree); + if (error != 0) { + SRPLG_LOG_ERR(PLUGIN_NAME, "Startup store callback failed for value %s", store->name); + goto error_out; + } + } + + goto out; + +error_out: + error = -1; + +out: + if (subtree) { + sr_release_data(subtree); + } + + return error; +} + +static int system_aug_running_store_hostname(void *priv, const struct lyd_node *system_container_node) +{ + int error = 0; + system_ctx_t *ctx = (system_ctx_t *) priv; + srpc_check_status_t check_status = srpc_check_status_none; + + struct lyd_node *hostname_node = srpc_ly_tree_get_child_leaf(system_container_node, "hostname"); + + if (hostname_node) { + const char *hostname = lyd_get_value(hostname_node); + + SRPLG_LOG_INF(PLUGIN_NAME, "Checking system hostname value"); + check_status = system_check_hostname(ctx, hostname); + + switch (check_status) { + case srpc_check_status_none: + SRPLG_LOG_ERR(PLUGIN_NAME, "Error loading current system hostname value"); + goto error_out; + break; + case srpc_check_status_error: + SRPLG_LOG_ERR(PLUGIN_NAME, "Error loading current system hostname value"); + goto error_out; + break; + case srpc_check_status_non_existant: + SRPLG_LOG_INF(PLUGIN_NAME, "Storing hostname value %s", hostname); + + error = system_store_hostname(ctx, hostname); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_store_hostname() failed (%d)", error); + return -1; + } + break; + case srpc_check_status_equal: + SRPLG_LOG_ERR(PLUGIN_NAME, "Startup hostname value is already applied on the system"); + break; + case srpc_check_status_partial: + // should not be returned - treat as error + SRPLG_LOG_ERR(PLUGIN_NAME, "Error loading current system hostname value"); + goto error_out; + break; + } + } + + goto out; + +error_out: + error = -1; + +out: + return 0; +} + +static int system_aug_running_store_ntp(void *priv, const struct lyd_node *system_container_node) +{ + int error = 0; + system_ctx_t *ctx = (system_ctx_t *) priv; + struct lyd_node *ntp_container_node = NULL; + struct lyd_node *server_list_node = NULL; + struct lyd_node *server_name_leaf_node = NULL; + struct lyd_node *server_address_leaf_node = NULL; + struct lyd_node *server_port_leaf_node = NULL; + struct lyd_node *server_association_type_leaf_node = NULL; + struct lyd_node *server_iburst_leaf_node = NULL, *server_prefer_leaf_node = NULL; + struct lyd_node *udp_container_node = NULL; + system_ntp_server_element_t *ntp_server_head = NULL; + + bool ntp_enabled = srpc_feature_status_hash_check(ctx->ietf_system_features, "ntp"); + bool ntp_udp_port_enabled = srpc_feature_status_hash_check(ctx->ietf_system_features, "ntp-udp-port"); + + system_ntp_server_t temp_server = {0}; + srpc_check_status_t server_check_status = srpc_check_status_none; + + if (ntp_enabled) { + SRPLG_LOG_INF(PLUGIN_NAME, "Storing NTP startup data"); + + ntp_container_node = srpc_ly_tree_get_child_container(system_container_node, "ntp"); + if (ntp_container_node) { + server_list_node = srpc_ly_tree_get_child_list(ntp_container_node, "server"); + + if (server_list_node) { + while (server_list_node) { + // process server list node + system_ntp_server_init(&temp_server); + + server_name_leaf_node = srpc_ly_tree_get_child_leaf(server_list_node, "name"); + udp_container_node = srpc_ly_tree_get_child_container(server_list_node, "udp"); + server_association_type_leaf_node = srpc_ly_tree_get_child_leaf(server_list_node, "association-type"); + server_iburst_leaf_node = srpc_ly_tree_get_child_leaf(server_list_node, "iburst"); + server_prefer_leaf_node = srpc_ly_tree_get_child_leaf(server_list_node, "prefer"); + + const char *name = lyd_get_value(server_name_leaf_node); + + // set name + system_ntp_server_set_name(&temp_server, name); + + if (!udp_container_node) { + SRPLG_LOG_ERR(PLUGIN_NAME, "srpc_ly_tree_get_child_container() failed for udp"); + goto error_out; + } + + server_address_leaf_node = srpc_ly_tree_get_child_leaf(udp_container_node, "address"); + + // address + if (server_address_leaf_node) { + const char *address = lyd_get_value(server_address_leaf_node); + + // set address + error = system_ntp_server_set_address(&temp_server, address); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_ntp_server_set_address() error (%d)", error); + goto error_out; + } + } else { + // no address node -> unable to continue + SRPLG_LOG_INF(PLUGIN_NAME, "srpc_ly_tree_get_child_leaf() failed for leaf address"); + goto error_out; + } + + if (ntp_udp_port_enabled) { + server_port_leaf_node = srpc_ly_tree_get_child_leaf(udp_container_node, "port"); + + // port + if (server_port_leaf_node) { + const char *port = lyd_get_value(server_port_leaf_node); + + // set port + error = system_ntp_server_set_port(&temp_server, port); + if (error) { + SRPLG_LOG_INF(PLUGIN_NAME, "system_ntp_server_set_port() error (%d)", error); + goto error_out; + } + } + } + + // association-type + if (server_association_type_leaf_node) { + const char *association_type = lyd_get_value(server_association_type_leaf_node); + + error = system_ntp_server_set_association_type(&temp_server, association_type); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_ntp_server_set_association_type() error (%d)", error); + goto error_out; + } + } else { + // unable to create config entry without association type + SRPLG_LOG_ERR(PLUGIN_NAME, "srpc_ly_tree_get_child_leaf() failed for leaf association-type"); + goto error_out; + } + + // iburst + if (server_iburst_leaf_node) { + const char *iburst = lyd_get_value(server_iburst_leaf_node); + + error = system_ntp_server_set_iburst(&temp_server, iburst); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_ntp_server_set_iburst() error (%d)", error); + goto error_out; + } + } + + // prefer + if (server_prefer_leaf_node) { + const char *prefer = lyd_get_value(server_prefer_leaf_node); + + error = system_ntp_server_set_prefer(&temp_server, prefer); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_ntp_server_set_prefer() error (%d)", error); + goto error_out; + } + } + + // append to the list + error = system_ntp_server_list_add(&ntp_server_head, temp_server); + if (error) { + SRPLG_LOG_INF(PLUGIN_NAME, "system_ntp_server_list_add() error (%d)", error); + goto error_out; + } + + system_ntp_server_free(&temp_server); + + // iterate list + server_list_node = srpc_ly_tree_get_list_next(server_list_node); + } + } + + SRPLG_LOG_INF(PLUGIN_NAME, "Checking NTP server list status on the system"); + + server_check_status = system_ntp_check_server(ctx, ntp_server_head); + + SRPLG_LOG_INF(PLUGIN_NAME, "Recieved check status: %d", server_check_status); + + switch (server_check_status) { + case srpc_check_status_none: + SRPLG_LOG_ERR(PLUGIN_NAME, "Error occured while checking NTP server system values"); + goto error_out; + break; + case srpc_check_status_error: + SRPLG_LOG_ERR(PLUGIN_NAME, "Error occured while checking NTP server system values"); + goto error_out; + break; + case srpc_check_status_non_existant: + SRPLG_LOG_INF(PLUGIN_NAME, "NTP server list values don\'t exist on the system - applying values"); + + error = system_ntp_store_server(ctx, ntp_server_head); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_ntp_store_server() error (%d)", error); + goto error_out; + } + + SRPLG_LOG_INF(PLUGIN_NAME, "Applied NTP server startup values to the system"); + break; + case srpc_check_status_equal: + SRPLG_LOG_INF(PLUGIN_NAME, "NTP server startup values already exist on the system - no need to apply anything"); + break; + case srpc_check_status_partial: + // TODO: implement + break; + } + } + } else { + SRPLG_LOG_INF(PLUGIN_NAME, "\"ntp\" feature disabled - skipping NTP startup configuration"); + } + + goto out; + +error_out: + error = -1; + +out: + // remove temp values if something was interrupted + system_ntp_server_free(&temp_server); + + // free allocated lists + system_ntp_server_list_free(&ntp_server_head); + return error; -} \ No newline at end of file +} diff --git a/src/plugins/ietf-system/datastore/running/load.c b/src/plugins/ietf-system/datastore/running/load.c index 4e3e34e..17a1ba3 100644 --- a/src/plugins/ietf-system/datastore/running/load.c +++ b/src/plugins/ietf-system/datastore/running/load.c @@ -58,10 +58,6 @@ int system_running_ds_load(system_ctx_t *ctx, sr_session_ctx_t *session) sr_conn_ctx_t *conn_ctx = NULL; srpc_startup_load_t load_values[] = { - { - "hostname", - system_startup_load_hostname, - }, { "contact", system_startup_load_contact, From e375ec7b47c9174f85e829754f332bce4887920d Mon Sep 17 00:00:00 2001 From: Mateo Cindric Date: Thu, 9 Feb 2023 16:22:29 +0000 Subject: [PATCH 18/25] ietf-system-augeas: move hostname load functionality to the augeas specific plugin --- .../datastore/running/load.c | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/plugins/ietf-system-augeas/datastore/running/load.c b/src/plugins/ietf-system-augeas/datastore/running/load.c index cfda0ec..6e1b812 100644 --- a/src/plugins/ietf-system-augeas/datastore/running/load.c +++ b/src/plugins/ietf-system-augeas/datastore/running/load.c @@ -8,6 +8,7 @@ // core library #include "core/ly_tree.h" +#include "core/api/system/load.h" #include "core/api/system/ntp/load.h" #include "core/data/system/ntp/server/list.h" @@ -89,6 +90,29 @@ int system_aug_running_ds_load(system_ctx_t *ctx, sr_session_ctx_t *session) static int system_aug_running_load_hostname(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node) { + int error = 0; + system_ctx_t *ctx = (system_ctx_t *) priv; + char hostname_buffer[SYSTEM_HOSTNAME_LENGTH_MAX] = {0}; + + error = system_load_hostname(ctx, hostname_buffer); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_load_hostname() error (%d)", error); + goto error_out; + } + + error = system_ly_tree_create_hostname(ly_ctx, parent_node, hostname_buffer); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "system_ly_tree_create_hostname() error (%d)", error); + goto error_out; + } + + goto out; + +error_out: + error = -1; + +out: + return error; } static int system_aug_running_load_ntp(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node) From 6485c2f83d3863da916edeee220e5c59e192e92a Mon Sep 17 00:00:00 2001 From: Mateo Cindric Date: Thu, 9 Feb 2023 16:23:50 +0000 Subject: [PATCH 19/25] ietf-system-augeas: fix spacing --- src/plugins/ietf-system-augeas/datastore/running/store.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/plugins/ietf-system-augeas/datastore/running/store.c b/src/plugins/ietf-system-augeas/datastore/running/store.c index 06eda68..20a1938 100644 --- a/src/plugins/ietf-system-augeas/datastore/running/store.c +++ b/src/plugins/ietf-system-augeas/datastore/running/store.c @@ -121,7 +121,9 @@ static int system_aug_running_store_hostname(void *priv, const struct lyd_node * static int system_aug_running_store_ntp(void *priv, const struct lyd_node *system_container_node) { int error = 0; + system_ctx_t *ctx = (system_ctx_t *) priv; + struct lyd_node *ntp_container_node = NULL; struct lyd_node *server_list_node = NULL; struct lyd_node *server_name_leaf_node = NULL; @@ -130,6 +132,7 @@ static int system_aug_running_store_ntp(void *priv, const struct lyd_node *syste struct lyd_node *server_association_type_leaf_node = NULL; struct lyd_node *server_iburst_leaf_node = NULL, *server_prefer_leaf_node = NULL; struct lyd_node *udp_container_node = NULL; + system_ntp_server_element_t *ntp_server_head = NULL; bool ntp_enabled = srpc_feature_status_hash_check(ctx->ietf_system_features, "ntp"); From 7714c576d6375254d0ab432fc8e07213892e4d17 Mon Sep 17 00:00:00 2001 From: Mateo Cindric Date: Thu, 9 Feb 2023 16:25:29 +0000 Subject: [PATCH 20/25] ietf-system-augeas: fix function naming --- .../ietf-system/datastore/running/load.c | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/plugins/ietf-system/datastore/running/load.c b/src/plugins/ietf-system/datastore/running/load.c index 17a1ba3..80db48d 100644 --- a/src/plugins/ietf-system/datastore/running/load.c +++ b/src/plugins/ietf-system/datastore/running/load.c @@ -42,12 +42,12 @@ #include -static int system_startup_load_hostname(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node); -static int system_startup_load_contact(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node); -static int system_startup_load_location(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node); -static int system_startup_load_timezone_name(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node); -static int system_startup_load_dns_resolver(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node); -static int system_startup_load_authentication(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node); +static int system_running_load_hostname(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node); +static int system_running_load_contact(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node); +static int system_running_load_location(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node); +static int system_running_load_timezone_name(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node); +static int system_running_load_dns_resolver(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node); +static int system_running_load_authentication(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node); int system_running_ds_load(system_ctx_t *ctx, sr_session_ctx_t *session) { @@ -60,23 +60,23 @@ int system_running_ds_load(system_ctx_t *ctx, sr_session_ctx_t *session) srpc_startup_load_t load_values[] = { { "contact", - system_startup_load_contact, + system_running_load_contact, }, { "location", - system_startup_load_location, + system_running_load_location, }, { "timezone-name", - system_startup_load_timezone_name, + system_running_load_timezone_name, }, { "dns-resolver", - system_startup_load_dns_resolver, + system_running_load_dns_resolver, }, { "authentication", - system_startup_load_authentication, + system_running_load_authentication, }, }; @@ -102,7 +102,7 @@ int system_running_ds_load(system_ctx_t *ctx, sr_session_ctx_t *session) } } -// enable or disable storing into startup - use when testing load functionality for now +// enable or disable storing into running - use when testing load functionality for now #define SYSTEM_PLUGIN_LOAD_STARTUP #ifdef SYSTEM_PLUGIN_LOAD_STARTUP @@ -134,7 +134,7 @@ int system_running_ds_load(system_ctx_t *ctx, sr_session_ctx_t *session) return error; } -static int system_startup_load_hostname(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node) +static int system_running_load_hostname(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node) { int error = 0; system_ctx_t *ctx = (system_ctx_t *) priv; @@ -161,19 +161,19 @@ static int system_startup_load_hostname(void *priv, sr_session_ctx_t *session, c return error; } -static int system_startup_load_contact(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node) +static int system_running_load_contact(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node) { int error = 0; return error; } -static int system_startup_load_location(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node) +static int system_running_load_location(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node) { int error = 0; return error; } -static int system_startup_load_timezone_name(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node) +static int system_running_load_timezone_name(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node) { int error = 0; system_ctx_t *ctx = (system_ctx_t *) priv; @@ -210,7 +210,7 @@ static int system_startup_load_timezone_name(void *priv, sr_session_ctx_t *sessi return error; } -static int system_startup_load_dns_resolver(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node) +static int system_running_load_dns_resolver(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node) { int error = 0; system_ctx_t *ctx = (system_ctx_t *) priv; @@ -311,7 +311,7 @@ static int system_startup_load_dns_resolver(void *priv, sr_session_ctx_t *sessio return error; } -static int system_startup_load_authentication(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node) +static int system_running_load_authentication(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node) { int error = 0; system_ctx_t *ctx = (system_ctx_t *) priv; From 35ebcd7ae2bfbe9763ddc451f8042d8b2748c60c Mon Sep 17 00:00:00 2001 From: Mateo Cindric Date: Thu, 9 Feb 2023 16:26:02 +0000 Subject: [PATCH 21/25] ietf-system-augeas: remove hostname configuration from the ietf-system plugin --- .../ietf-system/datastore/running/load.c | 28 ------------------- 1 file changed, 28 deletions(-) diff --git a/src/plugins/ietf-system/datastore/running/load.c b/src/plugins/ietf-system/datastore/running/load.c index 80db48d..5d81493 100644 --- a/src/plugins/ietf-system/datastore/running/load.c +++ b/src/plugins/ietf-system/datastore/running/load.c @@ -42,7 +42,6 @@ #include -static int system_running_load_hostname(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node); static int system_running_load_contact(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node); static int system_running_load_location(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node); static int system_running_load_timezone_name(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node); @@ -134,33 +133,6 @@ int system_running_ds_load(system_ctx_t *ctx, sr_session_ctx_t *session) return error; } -static int system_running_load_hostname(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node) -{ - int error = 0; - system_ctx_t *ctx = (system_ctx_t *) priv; - char hostname_buffer[SYSTEM_HOSTNAME_LENGTH_MAX] = {0}; - - error = system_load_hostname(ctx, hostname_buffer); - if (error) { - SRPLG_LOG_ERR(PLUGIN_NAME, "system_load_hostname() error (%d)", error); - goto error_out; - } - - error = system_ly_tree_create_hostname(ly_ctx, parent_node, hostname_buffer); - if (error) { - SRPLG_LOG_ERR(PLUGIN_NAME, "system_ly_tree_create_hostname() error (%d)", error); - goto error_out; - } - - goto out; - -error_out: - error = -1; - -out: - return error; -} - static int system_running_load_contact(void *priv, sr_session_ctx_t *session, const struct ly_ctx *ly_ctx, struct lyd_node *parent_node) { int error = 0; From f67ed6180f3e4c338e839635d0364753d28ff037 Mon Sep 17 00:00:00 2001 From: Mateo Cindric Date: Thu, 9 Feb 2023 16:27:10 +0000 Subject: [PATCH 22/25] ietf-system-augeas: fix function names --- .../ietf-system/datastore/running/store.c | 56 +++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/src/plugins/ietf-system/datastore/running/store.c b/src/plugins/ietf-system/datastore/running/store.c index 222bd45..402664e 100644 --- a/src/plugins/ietf-system/datastore/running/store.c +++ b/src/plugins/ietf-system/datastore/running/store.c @@ -59,11 +59,11 @@ #include -static int system_startup_store_contact(void *priv, const struct lyd_node *system_container_node); -static int system_startup_store_location(void *priv, const struct lyd_node *system_container_node); -static int system_startup_store_timezone_name(void *priv, const struct lyd_node *system_container_node); -static int system_startup_store_dns_resolver(void *priv, const struct lyd_node *system_container_node); -static int system_startup_store_authentication(void *priv, const struct lyd_node *system_container_node); +static int system_running_store_contact(void *priv, const struct lyd_node *system_container_node); +static int system_running_store_location(void *priv, const struct lyd_node *system_container_node); +static int system_running_store_timezone_name(void *priv, const struct lyd_node *system_container_node); +static int system_running_store_dns_resolver(void *priv, const struct lyd_node *system_container_node); +static int system_running_store_authentication(void *priv, const struct lyd_node *system_container_node); int system_running_ds_store(system_ctx_t *ctx, sr_session_ctx_t *session) { @@ -79,23 +79,23 @@ int system_running_ds_store(system_ctx_t *ctx, sr_session_ctx_t *session) srpc_startup_store_t store_values[] = { { "contact", - system_startup_store_contact, + system_running_store_contact, }, { "location", - system_startup_store_location, + system_running_store_location, }, { "timezone-name", - system_startup_store_timezone_name, + system_running_store_timezone_name, }, { "dns-resolver", - system_startup_store_dns_resolver, + system_running_store_dns_resolver, }, { "authentication", - system_startup_store_authentication, + system_running_store_authentication, }, }; @@ -125,7 +125,7 @@ int system_running_ds_store(system_ctx_t *ctx, sr_session_ctx_t *session) return error; } -static int system_startup_store_contact(void *priv, const struct lyd_node *system_container_node) +static int system_running_store_contact(void *priv, const struct lyd_node *system_container_node) { int error = 0; system_ctx_t *ctx = (system_ctx_t *) priv; @@ -147,7 +147,7 @@ static int system_startup_store_contact(void *priv, const struct lyd_node *syste return 0; } -static int system_startup_store_location(void *priv, const struct lyd_node *system_container_node) +static int system_running_store_location(void *priv, const struct lyd_node *system_container_node) { int error = 0; system_ctx_t *ctx = (system_ctx_t *) priv; @@ -169,7 +169,7 @@ static int system_startup_store_location(void *priv, const struct lyd_node *syst return 0; } -static int system_startup_store_timezone_name(void *priv, const struct lyd_node *system_container_node) +static int system_running_store_timezone_name(void *priv, const struct lyd_node *system_container_node) { int error = 0; system_ctx_t *ctx = (system_ctx_t *) priv; @@ -229,7 +229,7 @@ static int system_startup_store_timezone_name(void *priv, const struct lyd_node return 0; } -static int system_startup_store_dns_resolver(void *priv, const struct lyd_node *system_container_node) +static int system_running_store_dns_resolver(void *priv, const struct lyd_node *system_container_node) { int error = 0; system_ctx_t *ctx = (system_ctx_t *) priv; @@ -247,7 +247,7 @@ static int system_startup_store_dns_resolver(void *priv, const struct lyd_node * system_ip_address_t tmp_ip = {0}; srpc_check_status_t search_check_status = srpc_check_status_none, server_check_status = srpc_check_status_none; - SRPLG_LOG_INF(PLUGIN_NAME, "Storing dns-resolver startup data"); + SRPLG_LOG_INF(PLUGIN_NAME, "Storing dns-resolver running data"); dns_resolver_container_node = srpc_ly_tree_get_child_container(system_container_node, "dns-resolver"); if (dns_resolver_container_node) { @@ -325,7 +325,7 @@ static int system_startup_store_dns_resolver(void *priv, const struct lyd_node * // values exist - don't do anything break; case srpc_check_status_partial: - // TODO: create an union between startup and system values and apply that list to the system + // TODO: create an union between running and system values and apply that list to the system break; } } @@ -455,7 +455,7 @@ static int system_startup_store_dns_resolver(void *priv, const struct lyd_node * return error; } -static int system_startup_store_authentication(void *priv, const struct lyd_node *system_container_node) +static int system_running_store_authentication(void *priv, const struct lyd_node *system_container_node) { int error = 0; @@ -481,12 +481,12 @@ static int system_startup_store_authentication(void *priv, const struct lyd_node srpc_check_status_t user_check_status = srpc_check_status_none, key_check_status = srpc_check_status_none; if (authentication_enabled) { - SRPLG_LOG_INF(PLUGIN_NAME, "Storing authentication startup data"); + SRPLG_LOG_INF(PLUGIN_NAME, "Storing authentication running data"); authentication_container_node = srpc_ly_tree_get_child_container(system_container_node, "authentication"); if (authentication_container_node) { if (local_users_enabled) { - SRPLG_LOG_INF(PLUGIN_NAME, "Storing local-users startup data"); + SRPLG_LOG_INF(PLUGIN_NAME, "Storing local-users running data"); local_user_list_node = srpc_ly_tree_get_child_list(authentication_container_node, "user"); while (local_user_list_node) { @@ -586,7 +586,7 @@ static int system_startup_store_authentication(void *priv, const struct lyd_node system_local_user_list_init(&system_user_head); // check if all users exist on the system - SRPLG_LOG_INF(PLUGIN_NAME, "Checking startup local user system values"); + SRPLG_LOG_INF(PLUGIN_NAME, "Checking running local user system values"); user_check_status = system_authentication_check_user(ctx, user_head, &system_user_head); SRPLG_LOG_INF(PLUGIN_NAME, "Recieved local users check status: %d", user_check_status); @@ -600,7 +600,7 @@ static int system_startup_store_authentication(void *priv, const struct lyd_node goto error_out; break; case srpc_check_status_non_existant: - SRPLG_LOG_INF(PLUGIN_NAME, "Startup local users don\'t exist on the system - starting to store startup local users"); + SRPLG_LOG_INF(PLUGIN_NAME, "Startup local users don\'t exist on the system - starting to store running local users"); error = system_authentication_store_user(ctx, user_head); if (error) { SRPLG_LOG_ERR(PLUGIN_NAME, "system_authentication_store_user() error (%d)", error); @@ -611,16 +611,16 @@ static int system_startup_store_authentication(void *priv, const struct lyd_node SRPLG_LOG_INF(PLUGIN_NAME, "Startup local users already exist on the system - no need to store anything"); break; case srpc_check_status_partial: - SRPLG_LOG_INF(PLUGIN_NAME, "Some startup local users exist while others don\'t - creating non existant users"); + SRPLG_LOG_INF(PLUGIN_NAME, "Some running local users exist while others don\'t - creating non existant users"); - // get complement of startup without system + // get complement of running without system complement_user_head = system_local_user_list_complement(user_head, system_user_head); if (!complement_user_head) { SRPLG_LOG_ERR(PLUGIN_NAME, "system_local_user_list_complement() failed"); goto error_out; } - SRPLG_LOG_INF(PLUGIN_NAME, "Storing missing local users from startup to the system"); + SRPLG_LOG_INF(PLUGIN_NAME, "Storing missing local users from running to the system"); // add complement users to system error = system_authentication_store_user(ctx, complement_user_head); @@ -629,15 +629,15 @@ static int system_startup_store_authentication(void *priv, const struct lyd_node goto error_out; } - SRPLG_LOG_INF(PLUGIN_NAME, "Missing local users from startup are stored in the system"); + SRPLG_LOG_INF(PLUGIN_NAME, "Missing local users from running are stored in the system"); break; } - // after matching startup and system values for users - match key lists for all users - SRPLG_LOG_INF(PLUGIN_NAME, "Checking startup local user authorized key system values"); + // after matching running and system values for users - match key lists for all users + SRPLG_LOG_INF(PLUGIN_NAME, "Checking running local user authorized key system values"); LL_FOREACH(user_head, user_iter) { - // check first if any keys exist in startup + // check first if any keys exist in running if (user_iter->user.key_head) { key_check_status = system_authentication_check_user_authorized_key(ctx, user_iter->user.name, user_iter->user.key_head); SRPLG_LOG_INF(PLUGIN_NAME, "Recieved authorized-key check status %d for user %s", user_check_status, user_iter->user.name); From e50b31c93513400dd0ad2ba5dac63e98c1b43810 Mon Sep 17 00:00:00 2001 From: Mateo Cindric Date: Thu, 9 Feb 2023 16:51:43 +0000 Subject: [PATCH 23/25] CMake: add option for augeas plugin build --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0e26841..a501022 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -103,7 +103,7 @@ target_compile_options( add_subdirectory("src/plugins/ietf-system") # augyang support -if(AUGYANG_FOUND) +if(AUGYANG_FOUND AND ENABLE_AUGEAS_PLUGIN) add_subdirectory("src/plugins/ietf-system-augeas") else(AUGYANG_FOUND) message(WARNING "AUGYANG not found - disabled build of the augeas specific plugin") From 0b407f4e168006dbfa7c5f3109e9df053e080a7a Mon Sep 17 00:00:00 2001 From: Mateo Cindric Date: Thu, 9 Feb 2023 16:53:27 +0000 Subject: [PATCH 24/25] CI/CD: build augeas plugin --- .gitlab-ci.yml | 6 +++--- CMakeLists.txt | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0af1fc1..3a22f40 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -12,7 +12,7 @@ build:default: script: - mkdir build - - cmake -S . -B build/ -DSYSTEMD_IFINDEX=1 -DENABLE_BUILD_TESTS=ON -DCMAKE_C_COMPILER=clang + - cmake -S . -B build/ -DSYSTEMD_IFINDEX=1 -DENABLE_BUILD_TESTS=ON -DENABLE_AUGEAS_PLUGIN=ON -DCMAKE_C_COMPILER=clang - cmake --build build/ artifacts: @@ -24,7 +24,7 @@ build:sanitized: script: - mkdir build-sanitized - - cmake -S . -B build-sanitized/ -DSYSTEMD_IFINDEX=1 -DENABLE_BUILD_TESTS=ON -DCMAKE_C_COMPILER=clang -DCMAKE_C_FLAGS=\"-fsanitize=address,undefined\" -DENABLE_SANITIZER=ON + - cmake -S . -B build-sanitized/ -DSYSTEMD_IFINDEX=1 -DENABLE_BUILD_TESTS=ON -DENABLE_AUGEAS_PLUGIN=ON -DCMAKE_C_COMPILER=clang -DCMAKE_C_FLAGS=\"-fsanitize=address,undefined\" -DENABLE_SANITIZER=ON - cmake --build build-sanitized/ artifacts: paths: @@ -35,7 +35,7 @@ build:sanitized_memory: script: - mkdir build-sanitized-memory - - cmake -S . -B build-sanitized-memory/ -DSYSTEMD_IFINDEX=1 -DENABLE_BUILD_TESTS=ON -DCMAKE_C_COMPILER=clang -DCMAKE_C_FLAGS=\"-fsanitize=memory\" -DENABLE_SANITIZER=ON + - cmake -S . -B build-sanitized-memory/ -DSYSTEMD_IFINDEX=1 -DENABLE_BUILD_TESTS=ON -DENABLE_AUGEAS_PLUGIN=ON -DCMAKE_C_COMPILER=clang -DCMAKE_C_FLAGS=\"-fsanitize=memory\" -DENABLE_SANITIZER=ON - cmake --build build-sanitized-memory/ artifacts: paths: diff --git a/CMakeLists.txt b/CMakeLists.txt index a501022..e067540 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,7 @@ include(CompileOptions.cmake) set(PLUGIN_CORE_LIBRARY_NAME "srplg-ietf-system-core") option(ENABLE_BUILD_TESTS, "Build tests" OFF) +option(ENABLE_AUGEAS_PLUGIN, "Build augeas specific plugin" OFF) # local includes include_directories( From ad7da1c7ce9f472d5ddaeda9eae0a6d8cbaaa196 Mon Sep 17 00:00:00 2001 From: Mateo Cindric Date: Thu, 9 Feb 2023 17:07:20 +0000 Subject: [PATCH 25/25] README.md: include augeas plugin info and update build instructions --- README.md | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index b2b4914..e526d46 100644 --- a/README.md +++ b/README.md @@ -63,17 +63,20 @@ $ cmake -DSYSTEMD_IFINDEX=1 .. ``` note: SYSTEMD_IFINDEX cmake flag is the index of the interface you wish to configure DNS on (to get a list of indexes for all interfaces, use: `ip link`) -The default configuration builds the plugin as a stand-alone foreground application. To build the plugin as a shared object file for use with `sysrepo-plugind`, run the following instead: - +If augeas/augyang configuration is needed (only supported for `ntp` container and the `hostname` leaf node), the augeas specific plugin can be built by providing the CMake option: ``` -$ cmake -DPLUGIN=ON .. +$ mkdir build +$ cd build +$ cmake -DSYSTEMD_IFINDEX=1 -DENABLE_AUGEAS_PLUGIN=ON .. ``` -Lastly, invoke the build and install using `make`: +### Build artifacts -``` -$ make -j$(nproc) install -``` +Plugin will be built as a standalone application and also as a `sysrepo-plugind` module. For example, for the main ietf-system plugin there are two build artifacts: +- **ietf-system-plugin**: standalone application +- **libsrplg-ietf-system.so**: `sysrepo-plugind` module which exposes the plugin init and cleanup callbacks and can be installed by invoking the following command: `sysrepo-plugind -P libsrplg-ietf-system.so` + +### Sysrepo/YANG requirements The plugin requires the `iana-crypt-hash` and `ietf-system` YANG modules to be loaded into the Sysrepo datastore. This can be achieved by invoking the following commands: