Skip to content

Commit

Permalink
Merge pull request #21 from telekom/augeas-plugin
Browse files Browse the repository at this point in the history
Augeas/augyang specific plugin
  • Loading branch information
zinccyy authored Feb 13, 2023
2 parents 2fe1abe + ad7da1c commit 96556c0
Show file tree
Hide file tree
Showing 96 changed files with 2,294 additions and 410 deletions.
24 changes: 4 additions & 20 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
image: debian
image: ${SYSREPO_CICD_IMAGE}

variables:
GIT_SUBMODULE_STRATEGY: recursive
Expand All @@ -7,28 +7,12 @@ 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

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:
Expand All @@ -40,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:
Expand All @@ -51,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:
Expand Down
172 changes: 66 additions & 106 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
#
# 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)

include(CompileOptions.cmake)

set(PLUGIN_LIRBARY_NAME srplg-ietf-system)
set(PLUGIN_CORE_LIBRARY_NAME "srplg-ietf-system-core")

set(PLUGIN 0 CACHE BOOL "Build a plugin")
option(ENABLE_BUILD_TESTS, "Build tests" OFF)
option(ENABLE_AUGEAS_PLUGIN, "Build augeas specific plugin" OFF)

# local includes
include_directories(
${CMAKE_SOURCE_DIR}/src/
${CMAKE_SOURCE_DIR}/deps/uthash/include
)

# first - find needed and optional packages
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules")
# find needed and optional packages
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMakeModules")
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
Expand All @@ -29,130 +41,78 @@ include_directories(
${LIBYANG_INCLUDE_DIRS}
${SRPC_INCLUDE_DIRS}
${UMGMT_INCLUDE_DIRS}
${SYSTEMD_INCLUDE_DIRS}
)

# sources
set(
SOURCES
CORE_SOURCES

src/plugin.c
src/plugin/common.c
src/plugin/ly_tree.c
${CMAKE_SOURCE_DIR}/src/core/common.c
${CMAKE_SOURCE_DIR}/src/core/ly_tree.c

# startup
src/plugin/startup/load.c
src/plugin/startup/store.c
${CMAKE_SOURCE_DIR}/src/core/startup/load.c
${CMAKE_SOURCE_DIR}/src/core/startup/store.c

# subs
src/plugin/subscription/change.c
src/plugin/subscription/operational.c
src/plugin/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/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
${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/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
${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
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}
# build plugin core static library
add_library(${PLUGIN_CORE_LIBRARY_NAME} STATIC ${CORE_SOURCES})
target_compile_options(
${PLUGIN_CORE_LIBRARY_NAME}
PRIVATE
-fPIC
)

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()
# add main plugin to the build process
add_subdirectory("src/plugins/ietf-system")

# augyang support
if(AUGYANG_FOUND)
add_compile_definitions(AUGYANG)
if(AUGYANG_FOUND AND ENABLE_AUGEAS_PLUGIN)
add_subdirectory("src/plugins/ietf-system-augeas")
else(AUGYANG_FOUND)
message(WARNING "AUGYANG not found - augeas support will be disabled")
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)
include(tests/Tests.cmake)
include(tests/unit/Tests.cmake)
endif()
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <srpc.h>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <sysrepo.h>
#include <utlist.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.h>

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <unistd.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 96556c0

Please sign in to comment.