Skip to content

Commit 841b681

Browse files
authored
Merge devel into master as release 1.1.39
2 parents 58ef149 + 7b184c7 commit 841b681

File tree

8 files changed

+88
-38
lines changed

8 files changed

+88
-38
lines changed

CMakeLists.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ set(CMAKE_C_FLAGS_DEBUG "-g -O0 -DDEBUG")
3030
# Generic version of not only the library. Major version is reserved for really big changes of the project,
3131
# minor version changes with added functionality (new tool, functionality of the tool or library, ...) and
3232
# micro version is changed with a set of small changes or bugfixes anywhere in the project.
33-
set(NP2SRV_VERSION 1.1.34)
33+
set(NP2SRV_VERSION 1.1.39)
3434

3535
# build options
3636
if(CMAKE_BUILD_TYPE STREQUAL debug)
@@ -203,11 +203,11 @@ install(TARGETS netopeer2-server DESTINATION ${CMAKE_INSTALL_BINDIR})
203203
if(INSTALL_MODULES)
204204
install(CODE "
205205
message(STATUS \"Installing missing sysrepo modules...\")
206-
set(ENV{NP2_MODULE_DIR} ${YANG_MODULE_DIR})
207-
set(ENV{NP2_MODULE_PERMS} ${MODULES_PERMS})
208-
set(ENV{NP2_MODULE_OWNER} ${MODULES_OWNER})
209-
set(ENV{NP2_MODULE_GROUP} ${MODULES_GROUP})
210-
execute_process(COMMAND ${SCRIPT_DIR}/setup.sh)
206+
set(ENV{NP2_MODULE_DIR} \"${YANG_MODULE_DIR}\")
207+
set(ENV{NP2_MODULE_PERMS} \"${MODULES_PERMS}\")
208+
set(ENV{NP2_MODULE_OWNER} \"${MODULES_OWNER}\")
209+
set(ENV{NP2_MODULE_GROUP} \"${MODULES_GROUP}\")
210+
execute_process(COMMAND \"${SCRIPT_DIR}/setup.sh\")
211211
")
212212
else()
213213
message(WARNING "Server will refuse to start if the modules are not installed!")

cli/commands.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,7 +1729,11 @@ parse_cert(const char *name, const char *path)
17291729
BIO_printf(bio_out, "\n");
17301730

17311731
BIO_printf(bio_out, "Valid until: ");
1732+
#if OPENSSL_VERSION_NUMBER < 0x10100000L // < 1.1.0
17321733
ASN1_TIME_print(bio_out, X509_get_notAfter(cert));
1734+
#else
1735+
ASN1_TIME_print(bio_out, X509_get0_notAfter(cert));
1736+
#endif
17331737
BIO_printf(bio_out, "\n");
17341738

17351739
has_san = 0;

scripts/merge_config.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22

33
set -e
44

5-
# avoid problems with sudo path
6-
SYSREPOCFG=`su -c "which sysrepocfg" $USER`
5+
# avoid problems with sudo PATH
6+
if [ `id -u` -eq 0 ]; then
7+
SYSREPOCFG=`su -c 'which sysrepocfg' -l $USER`
8+
else
9+
SYSREPOCFG=`which sysrepocfg`
10+
fi
711
KS_KEY_NAME=genkey
812

913
# check that there is no listen/Call Home configuration yet

scripts/merge_hostkey.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22

33
set -e
44

5-
# avoid problems with sudo path
6-
SYSREPOCFG=`su -c "which sysrepocfg" $USER`
7-
OPENSSL=`su -c "which openssl" $USER`
5+
# avoid problems with sudo PATH
6+
if [ `id -u` -eq 0 ]; then
7+
SYSREPOCFG=`su -c 'which sysrepocfg' -l $USER`
8+
OPENSSL=`su -c 'which openssl' -l $USER`
9+
else
10+
SYSREPOCFG=`which sysrepocfg`
11+
OPENSSL=`which openssl`
12+
fi
813

914
# check that there is no SSH key with this name yet
1015
KEYSTORE_KEY=`$SYSREPOCFG -X -x "/ietf-keystore:keystore/asymmetric-keys/asymmetric-key[name='genkey']/name"`

scripts/setup.sh

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ if [ -z "$NP2_MODULE_DIR" -o -z "$NP2_MODULE_PERMS" -o -z "$NP2_MODULE_OWNER" -o
66
exit 1
77
fi
88

9-
# avoid problems with sudo path
10-
SYSREPOCTL=`su -c "which sysrepoctl" $USER`
11-
MODDIR=${NP2_MODULE_DIR}
9+
# avoid problems with sudo PATH
10+
if [ `id -u` -eq 0 ]; then
11+
SYSREPOCTL=`su -c 'which sysrepoctl' -l $USER`
12+
else
13+
SYSREPOCTL=`which sysrepoctl`
14+
fi
15+
MODDIR=${DESTDIR}${NP2_MODULE_DIR}
1216
PERMS=${NP2_MODULE_PERMS}
1317
OWNER=${NP2_MODULE_OWNER}
1418
GROUP=${NP2_MODULE_GROUP}
@@ -33,23 +37,23 @@ MODULES=(
3337

3438
# functions
3539
INSTALL_MODULE() {
36-
$SYSREPOCTL -a -i $MODDIR/$1 -s $MODDIR -p $PERMS -o $OWNER -g $GROUP -v2
40+
"$SYSREPOCTL" -a -i $MODDIR/$1 -s "$MODDIR" -p "$PERMS" -o "$OWNER" -g "$GROUP" -v2
3741
local rc=$?
3842
if [ $rc -ne 0 ]; then
3943
exit $rc
4044
fi
4145
}
4246

4347
UPDATE_MODULE() {
44-
$SYSREPOCTL -a -U $MODDIR/$1 -s $MODDIR -p $PERMS -o $OWNER -g $GROUP -v2
48+
"$SYSREPOCTL" -a -U $MODDIR/$1 -s "$MODDIR" -p "$PERMS" -o "$OWNER" -g "$GROUP" -v2
4549
local rc=$?
4650
if [ $rc -ne 0 ]; then
4751
exit $rc
4852
fi
4953
}
5054

5155
ENABLE_FEATURE() {
52-
$SYSREPOCTL -a -c $1 -e $2 -v2
56+
"$SYSREPOCTL" -a -c $1 -e $2 -v2
5357
local rc=$?
5458
if [ $rc -ne 0 ]; then
5559
exit $rc
@@ -74,7 +78,7 @@ for i in "${MODULES[@]}"; do
7478
if [ "$sctl_revision" \< "$revision" ]; then
7579
# update module without any features
7680
file=`echo "$i" | cut -d' ' -f 1`
77-
UPDATE_MODULE $file
81+
UPDATE_MODULE "$file"
7882
fi
7983

8084
# parse sysrepoctl features and add extra space at the end for easier matching

src/main.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ np2srv_err_sr(int err_code, const char *message, const char *xpath)
313313

314314
switch (err_code) {
315315
case SR_ERR_LOCKED:
316+
err_lock_denied:
316317
ptr = strstr(message, "NC SID ");
317318
if (!ptr) {
318319
EINT;
@@ -344,6 +345,12 @@ np2srv_err_sr(int err_code, const char *message, const char *xpath)
344345
default:
345346
if (strstr(message, "authorization failed")) {
346347
goto err_access_denied;
348+
} else if (strstr(message, "is already locked")) {
349+
goto err_lock_denied;
350+
} else if (strstr(message, "Source and target")) {
351+
e = nc_err(NC_ERR_INVALID_VALUE, NC_ERR_TYPE_PROT);
352+
nc_err_set_msg(e, message, "en");
353+
break;
347354
}
348355
e = nc_err(NC_ERR_OP_FAILED, NC_ERR_TYPE_APP);
349356
nc_err_set_msg(e, message, "en");
@@ -928,7 +935,7 @@ worker_thread(void *arg)
928935
int rc, idx = *((int *)arg), monitored;
929936
struct nc_session *ncs;
930937

931-
nc_libssh_thread_verbosity(np2_verbose_level);
938+
nc_libssh_thread_verbosity(np2_libssh_verbose_level);
932939

933940
while (ATOMIC_LOAD_RELAXED(loop_continue)) {
934941
/* try to accept new NETCONF sessions */
@@ -1140,7 +1147,6 @@ main(int argc, char *argv[])
11401147

11411148
/* set verbose for all, we change to debug later if requested */
11421149
np2_verbose_level = NC_VERB_VERBOSE;
1143-
nc_verbosity(np2_verbose_level);
11441150
np2_libssh_verbose_level = 1;
11451151

11461152
ptr = strtok(optarg, ",");
@@ -1157,9 +1163,9 @@ main(int argc, char *argv[])
11571163
verb |= LY_LDGDIFF;
11581164
} else if (!strcmp(ptr, "MSG")) {
11591165
/* NETCONF messages - only lnc2 debug verbosity */
1160-
nc_verbosity(NC_VERB_DEBUG);
1166+
np2_verbose_level = NC_VERB_DEBUG;
11611167
} else if (!strcmp(ptr, "LN2DBG")) {
1162-
nc_verbosity(NC_VERB_DEBUG_LOWLVL);
1168+
np2_verbose_level = NC_VERB_DEBUG_LOWLVL;
11631169
} else if (!strcmp(ptr, "SSH")) {
11641170
/* 2 should be always enough, 3 is too much useless info */
11651171
np2_libssh_verbose_level = 2;
@@ -1170,7 +1176,8 @@ main(int argc, char *argv[])
11701176
return EXIT_FAILURE;
11711177
}
11721178
} while ((ptr = strtok(NULL, ",")));
1173-
/* set final verbosity of libssh and libyang */
1179+
/* set final verbosity */
1180+
nc_verbosity(np2_verbose_level);
11741181
nc_libssh_thread_verbosity(np2_libssh_verbose_level);
11751182
if (verb) {
11761183
ly_verb(LY_LLDBG);

src/netconf.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ int
251251
np2srv_rpc_copyconfig_cb(sr_session_ctx_t *session, const char *UNUSED(op_path), const struct lyd_node *input,
252252
sr_event_t UNUSED(event), uint32_t UNUSED(request_id), struct lyd_node *UNUSED(output), void *UNUSED(private_data))
253253
{
254-
sr_datastore_t ds = SR_DS_OPERATIONAL, sds;
254+
sr_datastore_t ds = SR_DS_OPERATIONAL, sds = SR_DS_OPERATIONAL;
255255
struct ly_set *nodeset;
256256
const sr_error_info_t *err_info;
257257
struct lyd_node *config = NULL;
@@ -303,6 +303,12 @@ np2srv_rpc_copyconfig_cb(sr_session_ctx_t *session, const char *UNUSED(op_path),
303303
} else {
304304
assert(!strcmp(nodeset->set.d[0]->schema->name, "url"));
305305
#ifdef NP2SRV_URL_CAPAB
306+
if (trg_url && !strcmp(trg_url, ((struct lyd_node_leaf_list *)nodeset->set.d[0])->value_str)) {
307+
rc = SR_ERR_INVAL_ARG;
308+
sr_set_error(session, NULL, "Source and target URLs are the same.");
309+
goto cleanup;
310+
}
311+
306312
config = op_parse_url(((struct lyd_node_leaf_list *)nodeset->set.d[0])->value_str,
307313
LYD_OPT_CONFIG | LYD_OPT_STRICT | LYD_OPT_TRUSTED, &rc, session);
308314
if (rc) {
@@ -318,6 +324,12 @@ np2srv_rpc_copyconfig_cb(sr_session_ctx_t *session, const char *UNUSED(op_path),
318324
}
319325
ly_set_free(nodeset);
320326

327+
if (ds == sds) {
328+
rc = SR_ERR_INVAL_ARG;
329+
sr_set_error(session, NULL, "Source and target datastores are the same.");
330+
goto cleanup;
331+
}
332+
321333
/* NACM checks */
322334
if (!config && !run_to_start) {
323335
/* get source datastore data and filter them */
@@ -452,6 +464,7 @@ np2srv_rpc_un_lock_cb(sr_session_ctx_t *session, const char *UNUSED(op_path), co
452464
{
453465
sr_datastore_t ds = 0;
454466
struct ly_set *nodeset;
467+
const sr_error_info_t *err_info;
455468
int rc = SR_ERR_OK;
456469

457470
/* get know which datastore is being affected */
@@ -476,6 +489,8 @@ np2srv_rpc_un_lock_cb(sr_session_ctx_t *session, const char *UNUSED(op_path), co
476489
rc = sr_unlock(session, NULL);
477490
}
478491
if (rc != SR_ERR_OK) {
492+
sr_get_error(session, &err_info);
493+
sr_set_error(session, err_info->err[0].xpath, err_info->err[0].message);
479494
goto cleanup;
480495
}
481496

@@ -709,6 +724,9 @@ np2srv_rpc_subscribe_cb(sr_session_ctx_t *session, const char *UNUSED(op_path),
709724
}
710725
ly_set_free(nodeset);
711726

727+
/* set ongoing notifications flag */
728+
nc_session_set_notif_status(ncs, 1);
729+
712730
/* sysrepo API */
713731
if (!strcmp(stream, "NETCONF")) {
714732
/* subscribe to all modules with notifications */
@@ -747,9 +765,6 @@ np2srv_rpc_subscribe_cb(sr_session_ctx_t *session, const char *UNUSED(op_path),
747765
goto cleanup;
748766
}
749767

750-
/* set ongoing notifications flag */
751-
nc_session_set_notif_status(ncs, 1);
752-
753768
/* success */
754769

755770
cleanup:
@@ -758,5 +773,8 @@ np2srv_rpc_subscribe_cb(sr_session_ctx_t *session, const char *UNUSED(op_path),
758773
}
759774
free(filters);
760775
free(xp);
776+
if (ncs && rc) {
777+
nc_session_set_notif_status(ncs, 0);
778+
}
761779
return rc;
762780
}

src/netconf_acm.c

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ ncac_rule_cb(sr_session_ctx_t *session, const char *UNUSED(module_name), const c
646646
str = ((struct lyd_node_leaf_list *)node)->value_str;
647647
lydict_remove(ly_ctx, rule->module_name);
648648
if (!strcmp(str, "*")) {
649-
rule->module_name = NULL;
649+
rule->module_name = NULL;
650650
} else {
651651
rule->module_name = lydict_insert(ly_ctx, str, 0);
652652
}
@@ -1042,29 +1042,37 @@ ncac_allowed_node(const struct lys_node *node, const char *user, uint8_t oper)
10421042
if (node->nodetype != LYS_RPC) {
10431043
continue;
10441044
}
1045+
if (rule->target && (rule->target != node->name)) {
1046+
/* exact match needed */
1047+
continue;
1048+
}
10451049
break;
10461050
case NCAC_TARGET_NOTIF:
10471051
/* only top-level notification */
10481052
if (lys_parent(node) || (node->nodetype != LYS_NOTIF)) {
10491053
continue;
10501054
}
1055+
if (rule->target && (rule->target != node->name)) {
1056+
/* exact match needed */
1057+
continue;
1058+
}
10511059
break;
10521060
case NCAC_TARGET_DATA:
10531061
if (node->nodetype & (LYS_RPC | LYS_NOTIF)) {
10541062
continue;
10551063
}
1056-
break;
1064+
/* fallthrough */
10571065
case NCAC_TARGET_ANY:
1058-
break;
1059-
}
1060-
if (rule->target) {
1061-
path = lys_data_path(node);
1062-
/* exact match or is a descendant (specified in RFC 8341 page 27) */
1063-
cmp = strncmp(path, rule->target, strlen(rule->target));
1064-
free(path);
1065-
if (cmp) {
1066-
continue;
1066+
if (rule->target) {
1067+
path = lys_data_path(node);
1068+
/* exact match or is a descendant (specified in RFC 8341 page 27) */
1069+
cmp = strncmp(path, rule->target, strlen(rule->target));
1070+
free(path);
1071+
if (cmp) {
1072+
continue;
1073+
}
10671074
}
1075+
break;
10681076
}
10691077

10701078
/* access operation matching */

0 commit comments

Comments
 (0)