Skip to content

Commit e17e029

Browse files
committed
Merge branch 'devel-server'
2 parents d3ae542 + ca0256d commit e17e029

30 files changed

+1043
-756
lines changed

cli/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ set(CMAKE_C_FLAGS_RELEASE "-O2")
2121
set(CMAKE_C_FLAGS_DEBUG "-g -O0")
2222

2323
# set version
24-
set(NP2CLI_VERSION 2.0.48)
24+
set(NP2CLI_VERSION 2.0.49)
2525
configure_file("${PROJECT_SOURCE_DIR}/version.h.in" "${PROJECT_BINARY_DIR}/version.h" ESCAPE_QUOTES @ONLY)
2626
include_directories(${PROJECT_BINARY_DIR})
2727

cli/commands.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2402,7 +2402,7 @@ cmd_searchpath(const char *arg, char **UNUSED(tmp_config_file))
24022402

24032403
if (!arg[0]) {
24042404
path = nc_client_get_schema_searchpath();
2405-
fprintf(stdout, "%s\n", path[0] ? path : "<none>");
2405+
fprintf(stdout, "%s\n", path && path[0] ? path : "<none>");
24062406
return 0;
24072407
}
24082408

keystored/CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG")
2121
set(CMAKE_C_FLAGS_DEBUG "-g -O0 -DDEBUG")
2222

2323
# set version
24-
set(KEYSTORED_VERSION 0.1.1)
24+
set(KEYSTORED_VERSION 0.1.2)
2525

2626
# config variables
2727
if (NOT KEYSTORED_KEYS_DIR)
@@ -131,10 +131,17 @@ endif()
131131

132132
option(SSH_KEY_INSTALL "Enable ssh key import" ON)
133133
if (SSH_KEY_INSTALL)
134+
if (NOT SSH_KEYGEN_EXECUTABLE)
135+
find_program(SSH_KEYGEN_EXECUTABLE ssh-keygen)
136+
endif()
137+
if (NOT SSH_KEYGEN_EXECUTABLE)
138+
message(FATAL_ERROR "Unable to find ssh-keygen, set SSH_KEYGEN_EXECUTABLE manually.")
139+
endif()
134140
install(CODE "
135141
set(ENV{SYSREPOCFG} ${SYSREPOCFG_EXECUTABLE})
136142
set(ENV{CHMOD} ${CHMOD_EXECUTABLE})
137143
set(ENV{OPENSSL} ${OPENSSL_EXECUTABLE})
144+
set(ENV{SSH_KEYGEN} ${SSH_KEYGEN_EXECUTABLE})
138145
set(ENV{KEYSTORED_KEYS_DIR} ${KEYSTORED_KEYS_DIR})
139146
set(ENV{KEYSTORED_CHECK_SSH_KEY} ${KEYSTORED_CHECK_SSH_KEY})
140147
execute_process(COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/scripts/ssh-key-import.sh)")

keystored/keystored.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ ks_cert_change_cb(sr_session_ctx_t *UNUSED(session), const char *UNUSED(module_n
121121
}
122122

123123
static int
124-
ks_privkey_get_cb(const char *xpath, sr_val_t **values, size_t *values_cnt, void *UNUSED(private_ctx))
124+
ks_privkey_get_cb(const char *xpath, sr_val_t **values, size_t *values_cnt, uint64_t UNUSED(request_id), void *UNUSED(private_ctx))
125125
{
126126
int ret;
127127
const char *name;
@@ -137,7 +137,7 @@ ks_privkey_get_cb(const char *xpath, sr_val_t **values, size_t *values_cnt, void
137137
}
138138
name += 18;
139139

140-
if (asprintf(&path, "%s/%.*s.pub.pem", KEYSTORED_KEYS_DIR, (int)(strchr(name, '\'') - name), name) == -1) {
140+
if (asprintf(&path, "%s/%.*s.pem.pub", KEYSTORED_KEYS_DIR, (int)(strchr(name, '\'') - name), name) == -1) {
141141
SRP_LOG_ERR("Memory allocation failed (%s:%d).", __FILE__, __LINE__);
142142
return SR_ERR_NOMEM;
143143
}
@@ -337,7 +337,7 @@ ks_privkey_gen_cb(const char *UNUSED(xpath), const sr_node_t *input, const size_
337337
goto cleanup;
338338
}
339339
sprintf(priv_path, "%s/%s.pem", KEYSTORED_KEYS_DIR, input[0].data.string_val);
340-
sprintf(pub_path, "%s/%s.pub.pem", KEYSTORED_KEYS_DIR, input[0].data.string_val);
340+
sprintf(pub_path, "%s/%s.pem.pub", KEYSTORED_KEYS_DIR, input[0].data.string_val);
341341

342342
if (!(pid = fork())) {
343343
/* child */
@@ -451,7 +451,7 @@ ks_privkey_load_cb(const char *UNUSED(xpath), const sr_node_t *input, const size
451451
goto cleanup;
452452
}
453453
sprintf(priv_path, "%s/%s.pem", KEYSTORED_KEYS_DIR, input[0].data.string_val);
454-
sprintf(pub_path, "%s/%s.pub.pem", KEYSTORED_KEYS_DIR, input[0].data.string_val);
454+
sprintf(pub_path, "%s/%s.pem.pub", KEYSTORED_KEYS_DIR, input[0].data.string_val);
455455

456456
fd = open(priv_path, O_CREAT | O_TRUNC | O_WRONLY, 00600);
457457
if (fd == -1) {

keystored/scripts/ssh-key-import.sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ local_path=$(dirname $0)
99
: ${SYSREPOCFG:=sysrepocfg}
1010
: ${CHMOD:=chmod}
1111
: ${OPENSSL:=openssl}
12+
: ${SSH_KEYGEN:=ssh-keygen}
1213
: ${STOCK_KEY_CONFIG:=$local_path/../stock_key_config.xml}
1314
: ${KEYSTORED_KEYS_DIR:=/etc/keystored/keys}
1415

@@ -21,13 +22,14 @@ if [ $KEYSTORED_CHECK_SSH_KEY -eq 0 ]; then
2122
echo "- Warning: Assuming that an external script will provide the SSH key in a PEM format at \"${KEYSTORED_KEYS_DIR}/ssh_host_rsa_key.pem\"."
2223
echo "- Importing ietf-keystore stock key configuration..."
2324
$SYSREPOCFG -d startup -i ${STOCK_KEY_CONFIG} ietf-keystore
24-
elif [ -r /etc/ssh/ssh_host_rsa_key ]; then
25-
cp /etc/ssh/ssh_host_rsa_key ${KEYSTORED_KEYS_DIR}/ssh_host_rsa_key.pem
25+
else
26+
if [ -r ${KEYSTORED_KEYS_DIR}/ssh_host_rsa_key.pem -a -r ${KEYSTORED_KEYS_DIR}/ssh_host_rsa_key.pem.pub ]; then
27+
echo "- SSH hostkey found, no need to generate a new one."
28+
else
29+
echo "- SSH hostkey not found, generating a new one..."
30+
$SSH_KEYGEN -m pem -t rsa -q -N "" -f ${KEYSTORED_KEYS_DIR}/ssh_host_rsa_key.pem
31+
fi
2632
$CHMOD go-rw ${KEYSTORED_KEYS_DIR}/ssh_host_rsa_key.pem
27-
$OPENSSL rsa -pubout -in ${KEYSTORED_KEYS_DIR}/ssh_host_rsa_key.pem \
28-
-out ${KEYSTORED_KEYS_DIR}/ssh_host_rsa_key.pub.pem
2933
echo "- Importing ietf-keystore stock key configuration..."
3034
$SYSREPOCFG -d startup -i ${STOCK_KEY_CONFIG} ietf-keystore
31-
else
32-
echo "- Warning: Cannot read the SSH hostkey at /etc/ssh/ssh_host_rsa_key, skipping."
3335
fi

server/CMakeLists.txt

100644100755
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ if(NOT UNIX)
1313
endif()
1414

1515
# set version
16-
set(NP2SRV_VERSION 0.5.31)
16+
set(NP2SRV_VERSION 0.6.15)
1717

1818
# set default build type if not specified by user
1919
if(NOT CMAKE_BUILD_TYPE)
2020
set(CMAKE_BUILD_TYPE debug)
2121
endif()
2222

23-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra")
23+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -std=gnu11")
2424
set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG")
2525
set(CMAKE_C_FLAGS_DEBUG "-g -O0 -DDEBUG")
2626

@@ -36,6 +36,11 @@ option(ENABLE_CONFIGURATION "Enable server configuration" ON)
3636
set(THREAD_COUNT 5 CACHE STRING "Number of threads accepting new sessions and handling requests")
3737
set(DEFAULT_HOST_KEY "/etc/ssh/ssh_host_rsa_key" CACHE STRING "Default server host key (used only if configuration is disabled)")
3838

39+
option(ENABLE_LY_CTX_INFO_CACHE "Enable caching the ly_ctx_info() result; reduces processing at the cost of increased memory usage." ON)
40+
if(ENABLE_LY_CTX_INFO_CACHE)
41+
set(NP2SRV_ENABLED_LY_CTX_INFO_CACHE 1)
42+
endif()
43+
3944
# set prefix for the PID file
4045
if (NOT PIDFILE_PREFIX)
4146
set(PIDFILE_PREFIX "/var/run")

server/KNOWNISSUES.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,11 @@ pthread_rwlockattr_setkind_np() and the number of worker threads is increased
66
(via cmake THREAD_COUNT variable), the thread processing the modules changes in
77
sysrepo (module install/uninstall or feature changes) can starve by waiting
88
for lock to wite changes into the netopeer's context.
9+
10+
XPath filter limitations
11+
------------------------
12+
13+
Correct filter result is guaranteed only when all the filtered nodes
14+
are only from one YANG schema and no unions are used. Otherwise,
15+
the <get> or <get-config> may finish with an error or possibly
16+
less data than would be correct.

server/common.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ struct np2srv {
4949
pthread_t workers[NP2SRV_THREAD_COUNT]; /**< worker threads handling sessions */
5050

5151
struct ly_ctx *ly_ctx; /**< libyang's context */
52+
#ifdef NP2SRV_ENABLED_LY_CTX_INFO_CACHE
53+
uint16_t cached_ly_ctx_module_set_id; /**< module-set-id at the time ly_ctx_info was last cached */
54+
struct lyd_node *ly_ctx_info_cache; /**< a cache of calling ly_ctx_info on the ly_ctx */
55+
#endif
5256
pthread_rwlock_t ly_ctx_lock; /**< libyang's context rwlock */
5357
};
5458
extern struct np2srv np2srv;

server/config.h.in

100644100755
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,8 @@
5252
*/
5353
#define NP2SRV_SR_LOCKED_RETRIES 3
5454

55+
/** @brief Enable caching the ly_ctx_info() result
56+
*/
57+
#cmakedefine NP2SRV_ENABLED_LY_CTX_INFO_CACHE
58+
5559
#endif /* NP2SRV_CONFIG_H_ */

server/ietf_keystore.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,57 @@ np_server_cert_clb(const char *name, void *UNUSED(user_data), char **UNUSED(cert
101101
return 0;
102102
}
103103

104+
int
105+
np_server_cert_chain_clb(const char *name, void *UNUSED(user_data), char ***UNUSED(cert_paths), int *UNUSED(cert_path_count),
106+
char ***cert_data, int *cert_data_count)
107+
{
108+
int ret;
109+
char *path;
110+
sr_val_t *sr_certs;
111+
size_t sr_cert_count, i, used_count;
112+
113+
ret = asprintf(&path, "/ietf-keystore:keystore/private-keys/private-key/certificate-chains/"
114+
"certificate-chain[name='%s']/certificate", name);
115+
if (ret == -1) {
116+
EMEM;
117+
return 1;
118+
}
119+
120+
if (np2srv.sr_sess.ds != SR_DS_RUNNING) {
121+
if (np2srv_sr_session_switch_ds(np2srv.sr_sess.srs, SR_DS_RUNNING, NULL)) {
122+
free(path);
123+
return 1;
124+
}
125+
np2srv.sr_sess.ds = SR_DS_RUNNING;
126+
}
127+
128+
/* Refresh the session to prevent sysrepo returning cached data */
129+
if (np2srv_sr_session_refresh(np2srv.sr_sess.srs, NULL)) {
130+
ERR("%s:%d Failed session refresh", __func__, __LINE__);
131+
free(path);
132+
return 1;
133+
}
134+
135+
if (np2srv_sr_get_items(np2srv.sr_sess.srs, path, &sr_certs, &sr_cert_count, NULL)) {
136+
free(path);
137+
return 1;
138+
}
139+
free(path);
140+
141+
/* Ignore the first cert since it's already loaded */
142+
if (sr_cert_count > 1) {
143+
used_count = sr_cert_count - 1;
144+
*cert_data = calloc(used_count, sizeof **cert_data);
145+
for (i = 0; i < used_count; ++i) {
146+
(*cert_data)[i] = strdup(sr_certs[i + 1].data.binary_val);
147+
}
148+
*cert_data_count = used_count;
149+
}
150+
151+
sr_free_values(sr_certs, sr_cert_count);
152+
return 0;
153+
}
154+
104155
int
105156
np_trusted_cert_list_clb(const char *name, void *UNUSED(user_data), char ***UNUSED(cert_paths), int *UNUSED(cert_path_count),
106157
char ***cert_data, int *cert_data_count)

0 commit comments

Comments
 (0)