Skip to content

Commit e828675

Browse files
committed
Merge branch 'devel-server'
2 parents 10d028c + f6400d9 commit e828675

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+14928
-1483
lines changed

.travis-install-libs.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ else
1919
cd ../..
2020
fi
2121

22-
git clone https://github.com/CESNET/libyang.git
22+
git clone -b devel https://github.com/CESNET/libyang.git
2323
cd libyang; mkdir build; cd build
2424
cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_BUILD_TYPE=Release ..
2525
make -j2 && sudo make install
2626
cd ../..
2727

28-
if [ ! -d "libssh-0.7.3" ]; then
28+
if [ ! -d "libssh-0.7.3/build" ]; then
2929
echo "Building libssh from source."
3030
wget https://git.libssh.org/projects/libssh.git/snapshot/libssh-0.7.3.tar.bz2
3131
tar -xjf libssh-0.7.3.tar.bz2
@@ -39,7 +39,7 @@ else
3939
cd ../..
4040
fi
4141

42-
git clone https://github.com/CESNET/libnetconf2.git
42+
git clone -b devel https://github.com/CESNET/libnetconf2.git
4343
cd libnetconf2; mkdir build; cd build
4444
cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_BUILD_TYPE=Release ..
4545
make -j2 && sudo make install
@@ -71,7 +71,7 @@ else
7171
cd ..
7272
fi
7373

74-
git clone https://github.com/sysrepo/sysrepo.git
74+
git clone -b devel https://github.com/sysrepo/sysrepo.git
7575
cd sysrepo; mkdir build; cd build
7676
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX:PATH=/usr -DBUILD_EXAMPLES=False -DENABLE_TESTS=False -DGEN_LANGUAGE_BINDINGS=0 -DREPOSITORY_LOC:PATH=/ets/sysrepo ..
7777
make -j2 && sudo make install

.travis.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ compiler:
1111

1212
branches:
1313
only:
14-
- master
14+
- devel-server
1515

1616
cache:
1717
directories:
@@ -21,13 +21,12 @@ cache:
2121
- protobuf-c
2222

2323
before_install:
24-
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then bash .travis-install-libs.sh; fi
24+
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then bash .travis-install-libs.sh; fi
25+
- if [ "$TRAVIS_OS_NAME" = "linux" -a "$CC" = "gcc" ]; then pip install --user codecov; export CFLAGS="-coverage"; fi
2526

2627
script:
27-
- mkdir build-cli && cd build-cli && cmake ../cli && make -j2
28-
- mkdir ../build-server && cd ../build-server && cmake ../server && make -j2 && sudo ctest -V
29-
- cd ..
28+
- mkdir build-server && cd build-server && cmake ../server && make -j2 && ctest -V
3029

3130
after_success:
32-
- if [ "${CC}" = "gcc" ]; then bash <(curl -s https://codecov.io/bash); fi
31+
- if [ "$TRAVIS_OS_NAME" = "linux" -a "$CC" = "gcc" ]; then codecov; fi
3332

keystored/CMakeLists.txt

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
cmake_minimum_required(VERSION 2.6)
2+
3+
# include custom Modules
4+
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/../CMakeModules/")
5+
6+
project(keystored C)
7+
include(GNUInstallDirs)
8+
9+
# check the supported platform
10+
if(NOT UNIX)
11+
message(FATAL_ERROR "Only *nix like systems are supported.")
12+
endif()
13+
14+
# set default build type if not specified by user
15+
if(NOT CMAKE_BUILD_TYPE)
16+
set(CMAKE_BUILD_TYPE debug)
17+
endif()
18+
19+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra")
20+
set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG")
21+
set(CMAKE_C_FLAGS_DEBUG "-g -O0 -DDEBUG")
22+
23+
# set version
24+
set(KEYSTORED_VERSION 0.1.1)
25+
26+
# config variables
27+
if (NOT KEYSTORED_KEYS_DIR)
28+
set(KEYSTORED_KEYS_DIR "${CMAKE_INSTALL_FULL_SYSCONFDIR}/keystored/keys")
29+
endif()
30+
if (NOT OPENSSL_EXECUTABLE)
31+
find_program(OPENSSL_EXECUTABLE openssl)
32+
if (NOT OPENSSL_EXECUTABLE)
33+
message(FATAL_ERROR "openssl utility not found.")
34+
endif()
35+
endif()
36+
37+
configure_file("${PROJECT_SOURCE_DIR}/config.h.in" "${PROJECT_SOURCE_DIR}/config.h" ESCAPE_QUOTES @ONLY)
38+
39+
# keystored plugin
40+
add_library(keystored SHARED keystored.c)
41+
42+
# pkgconfig keys directory
43+
find_package(PkgConfig)
44+
if (PKG_CONFIG_FOUND)
45+
# generate and install pkg-config file
46+
configure_file("keystored.pc.in" "keystored.pc" @ONLY)
47+
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/keystored.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
48+
execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} "--variable=pc_path" "pkg-config" RESULT_VARIABLE RET OUTPUT_VARIABLE OUT)
49+
if (RET)
50+
message(WARNING "Failed to check pkg-config search directories.")
51+
message(WARNING "For netopeer2-server configuration to work, pkg-config search path must include \"${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/pkgconfig\" or you keystored keys directory will have to be set manually to \"${KEYSTORED_KEYS_DIR}\".")
52+
else()
53+
string(REGEX MATCH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/pkgconfig" MATCHED "${OUT}")
54+
if (MATCHED)
55+
message(STATUS "pkg-config check successful, netopeer2-server configuration should work after installation")
56+
else()
57+
message(WARNING "keystored pkg-config file copied into a directory not searched by pkg-config.")
58+
message(WARNING "For netopeer2-server configuration to work, pkg-config search path must include \"${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/pkgconfig\" or keystored keys directory will have to be set manually to \"${KEYSTORED_KEYS_DIR}\".")
59+
endif()
60+
endif()
61+
else()
62+
message(WARNING "pkg-config not detected.")
63+
message(WARNING "For netopeer2-server configuration to work, keystored keys directory will have to be set manually to \"${KEYSTORED_KEYS_DIR}\".")
64+
endif()
65+
66+
# dependencies - sysrepo
67+
find_package(SYSREPO REQUIRED)
68+
target_link_libraries(keystored ${SYSREPO_LIBRARIES})
69+
include_directories(${SYSREPO_INCLUDE_DIRS})
70+
71+
# get sysrepo plugins directory
72+
if (NOT SR_PLUGINS_DIR)
73+
if (PKG_CONFIG_FOUND)
74+
execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} "--variable=SR_PLUGINS_DIR" "libsysrepo" OUTPUT_VARIABLE SR_PLUGINS_DIR)
75+
string(STRIP ${SR_PLUGINS_DIR} SR_PLUGINS_DIR)
76+
endif()
77+
endif()
78+
if (NOT SR_PLUGINS_DIR)
79+
message(FATAL_ERROR "Cannot get sysrepo plugins directory due to missing pkg-config, set SR_PLUGINS_DIR manually.")
80+
endif()
81+
82+
# find programs
83+
if (NOT SYSREPOCTL_EXECUTABLE)
84+
find_program(SYSREPOCTL_EXECUTABLE sysrepoctl)
85+
endif()
86+
if (NOT SYSREPOCTL_EXECUTABLE)
87+
message(FATAL_ERROR "Unable to find sysrepoctl, set SYSREPOCTL_EXECUTABLE manually.")
88+
endif()
89+
90+
if (NOT SYSREPOCFG_EXECUTABLE)
91+
find_program(SYSREPOCFG_EXECUTABLE sysrepocfg)
92+
endif()
93+
if (NOT SYSREPOCFG_EXECUTABLE)
94+
message(FATAL_ERROR "Unable to find sysrepocfg, set SYSREPOCFG_EXECUTABLE manually.")
95+
endif()
96+
97+
if (NOT CHMOD_EXECUTABLE)
98+
find_program(CHMOD_EXECUTABLE chmod)
99+
endif()
100+
if (NOT CHMOD_EXECUTABLE)
101+
message(FATAL_ERROR "Unable to find chmod, set CHMOD_EXECUTABLE manually.")
102+
endif()
103+
104+
# create the keys directory with correct permissions
105+
install(DIRECTORY DESTINATION ${KEYSTORED_KEYS_DIR}
106+
DIRECTORY_PERMISSIONS OWNER_WRITE OWNER_READ OWNER_EXECUTE)
107+
108+
# install all the required modules and enable features
109+
install(CODE "
110+
execute_process(COMMAND ${SYSREPOCTL_EXECUTABLE} -l RESULT_VARIABLE RET OUTPUT_VARIABLE INSTALLED_MODULES ERROR_VARIABLE OUT)
111+
if (RET)
112+
string(REPLACE \"\\n\" \"\\n \" OUT \${OUT})
113+
message(FATAL_ERROR \" Command sysrepoctl list failed:\n \${OUT}\")
114+
endif()
115+
116+
string(REGEX MATCH \"ietf-keystore [^\\n]*\" INSTALLED_MODULE_LINE \"\${INSTALLED_MODULES}\")
117+
if (NOT INSTALLED_MODULE_LINE)
118+
message(STATUS \"Importing module ietf-keystore into sysrepo...\")
119+
execute_process(COMMAND ${SYSREPOCTL_EXECUTABLE} -i -g ${CMAKE_SOURCE_DIR}/../modules/ietf-keystore.yang -o root:root -p 600 RESULT_VARIABLE RET OUTPUT_VARIABLE OUT ERROR_VARIABLE OUT)
120+
if (RET)
121+
string(REPLACE \"\\n\" \"\\n \" OUT \${OUT})
122+
message(FATAL_ERROR \" Command sysrepoctl install failed:\\n \${OUT}\")
123+
endif()
124+
125+
else()
126+
message(STATUS \"Module ietf-keystore already in sysrepo.\")
127+
endif()")
128+
129+
# import stock OpenSSH RSA key
130+
install(CODE "
131+
execute_process(COMMAND ${SYSREPOCFG_EXECUTABLE} -d startup --export ietf-keystore RESULT_VARIABLE RET OUTPUT_VARIABLE OUT ERROR_VARIABLE OUT)
132+
if (RET)
133+
string(REPLACE \"\\n\" \"\\n \" OUT \${OUT})
134+
message(FATAL_ERROR \" Command sysrepocfg export failed:\\n \${OUT}\")
135+
endif()
136+
137+
if (OUT)
138+
message(STATUS \"Some ietf-keystore configuration set, no keys will be imported.\")
139+
elseif(NOT EXISTS \"/etc/ssh/ssh_host_rsa_key\")
140+
message(WARNING \"Default OpenSSH RSA host key \\\"/etc/ssh/ssh_host_rsa_key\\\" not found so a key will have to be imported or generated manually for netopeer2-server to use.\")
141+
else()
142+
message(STATUS \"Importing stock OpenSSH RSA key.\")
143+
file(READ /etc/ssh/ssh_host_rsa_key RSA_KEY)
144+
file(WRITE ${KEYSTORED_KEYS_DIR}/ssh_host_rsa_key.pem \${RSA_KEY})
145+
execute_process(COMMAND ${CHMOD_EXECUTABLE} go-rw ${KEYSTORED_KEYS_DIR}/ssh_host_rsa_key.pem)
146+
execute_process(COMMAND ${OPENSSL_EXECUTABLE} rsa -pubout -in ${KEYSTORED_KEYS_DIR}/ssh_host_rsa_key.pem -out ${KEYSTORED_KEYS_DIR}/ssh_host_rsa_key.pub.pem RESULT_VARIABLE RET OUTPUT_VARIABLE OUT ERROR_VARIABLE OUT)
147+
if (RET)
148+
string(REPLACE \"\\n\" \"\\n \" OUT \${OUT})
149+
message(FATAL_ERROR \" Command openssl generate public key failed:\\n \${OUT}\")
150+
endif()
151+
execute_process(COMMAND ${SYSREPOCFG_EXECUTABLE} -d startup -i ${CMAKE_SOURCE_DIR}/stock_key_config.xml ietf-keystore RESULT_VARIABLE RET OUTPUT_VARIABLE OUT ERROR_VARIABLE OUT)
152+
if (RET)
153+
string(REPLACE \"\\n\" \"\\n \" OUT \${OUT})
154+
message(FATAL_ERROR \" Command sysrepocfg import failed:\\n \${OUT}\")
155+
endif()
156+
endif()")
157+
158+
# plugins should be installed into sysrepo plugins dir
159+
install(TARGETS keystored DESTINATION ${SR_PLUGINS_DIR})

keystored/config.h.in

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* \file config.h
3+
* \author Michal Vasko <mvasko@cesnet.cz>
4+
* \brief keystored plugin configuration.
5+
*
6+
* Copyright (c) 2016 CESNET, z.s.p.o.
7+
*
8+
* This source code is licensed under BSD 3-Clause License (the "License").
9+
* You may not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* https://opensource.org/licenses/BSD-3-Clause
13+
*/
14+
15+
#ifndef KEYSTORED_CONFIG_H_
16+
#define KEYSTORED_CONFIG_H_
17+
18+
#ifdef __GNUC__
19+
# define UNUSED(x) UNUSED_ ## x __attribute__((__unused__))
20+
#else
21+
# define UNUSED(x) UNUSED_ ## x
22+
#endif
23+
24+
#define KEYSTORED_KEYS_DIR "@KEYSTORED_KEYS_DIR@"
25+
26+
#define OPENSSL_EXECUTABLE "@OPENSSL_EXECUTABLE@"
27+
28+
#endif /* KEYSTORED_CONFIG_H_ */

0 commit comments

Comments
 (0)