Skip to content

Commit e409bd8

Browse files
Roytakmichalvasko
authored andcommitted
session server UPDATE hidden unix path without base
1 parent ddcbd56 commit e409bd8

4 files changed

Lines changed: 18 additions & 17 deletions

File tree

modules/libnetconf2-netconf-server@2025-11-11.yang

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,10 +340,7 @@ module libnetconf2-netconf-server {
340340
type empty;
341341
description
342342
"Indicates that the UNIX socket path is not configured via YANG, but is instead
343-
determined by internal server API settings.
344-
345-
The parent directory must be set by an internal server API setting.
346-
The final resolved path must be within the configured parent directory.";
343+
determined by internal server API settings.";
347344
}
348345
}
349346
}

src/session_server.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -461,33 +461,36 @@ char *
461461
nc_server_unix_get_socket_path(const struct nc_endpt *endpt)
462462
{
463463
LY_ARRAY_COUNT_TYPE i;
464-
const char *filename = NULL;
464+
const char *p = NULL;
465465
char *path = NULL;
466466

467467
/* check the endpoints options for type of socket path */
468468
if (endpt->opts.unix->path_type == NC_UNIX_SOCKET_PATH_FILE) {
469469
/* UNIX socket endpoints always have only one bind, get its address */
470-
filename = endpt->binds[0].address;
470+
p = endpt->binds[0].address;
471+
472+
/* it is relative, we need to construct the full path */
473+
if (nc_session_unix_construct_socket_path(p, &path)) {
474+
return NULL;
475+
}
471476
} else if (endpt->opts.unix->path_type == NC_UNIX_SOCKET_PATH_HIDDEN) {
472-
/* search the mappings */
477+
/* search the mappings, no need to construct the path */
473478
LY_ARRAY_FOR(server_opts.unix_paths, i) {
474479
if (!strcmp(server_opts.unix_paths[i].endpt_name, endpt->name)) {
475-
filename = server_opts.unix_paths[i].path;
480+
p = server_opts.unix_paths[i].path;
476481
break;
477482
}
478483
}
479-
if (!filename) {
484+
if (!p) {
480485
ERR(NULL, "UNIX socket path mapping for endpoint \"%s\" not found.", endpt->name);
481486
}
487+
488+
path = strdup(p);
489+
NC_CHECK_ERRMEM_RET(!path, NULL);
482490
} else {
483491
ERRINT;
484492
}
485493

486-
/* construct the full socket path */
487-
if (nc_session_unix_construct_socket_path(filename, &path)) {
488-
return NULL;
489-
}
490-
491494
return path;
492495
}
493496

src/session_server.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,9 @@ int nc_server_get_unix_socket_path(const char *endpoint_name, char **socket_path
471471
/**
472472
* @brief Set the base directory for UNIX socket paths.
473473
*
474-
* All UNIX socket paths will be relative to this directory.
474+
* All YANG defined UNIX socket paths will be relative to this directory.
475475
* It must exist and be writable by the server process.
476+
* This does not apply to "hidden" UNIX socket paths set via ::nc_server_set_unix_socket_path().
476477
*
477478
* @param[in] dir Base directory for UNIX socket paths.
478479
* @return 0 on success, 1 on error.

tests/test_unix_socket.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ setup_glob_f(void **state)
5959
assert_int_equal(ret, 0);
6060

6161
/* set two hidden paths for UNIX sockets */
62-
ret = nc_server_set_unix_socket_path("unix", "nc2_test_unix_sock");
62+
ret = nc_server_set_unix_socket_path("unix", "/tmp/nc2_test_unix_sock");
6363
assert_int_equal(ret, 0);
64-
ret = nc_server_set_unix_socket_path("unix2", "nc2_test_unix_sock2");
64+
ret = nc_server_set_unix_socket_path("unix2", "/tmp/nc2_test_unix_sock2");
6565
assert_int_equal(ret, 0);
6666

6767
return 0;

0 commit comments

Comments
 (0)