Skip to content

Commit cda4ae6

Browse files
committed
session server UPDATE add unixsock dir getter
1 parent e89f511 commit cda4ae6

File tree

4 files changed

+64
-14
lines changed

4 files changed

+64
-14
lines changed

doc/libnetconf.doc

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -493,27 +493,32 @@
493493
* - ::nc_server_config_add_tls_ctn()
494494
* - ::nc_server_config_del_tls_ctn()
495495
*
496-
* UNIX Socket
496+
* UNIX Socket
497497
* ===========
498498
*
499499
* A UNIX socket endpoint can be established using one of two mechanisms:
500500
*
501-
* 1) **Cleartext Path**: The filesystem path is explicitly stored in the configuration.
501+
* 1) **Standard Filesystem Path**: The filesystem path is explicitly stored in the configuration.
502502
* To use this, pass a valid path string to ::nc_server_config_add_unix_socket().
503503
*
504504
* 2) **Hidden Path**: The filesystem path is managed via the API and is not visible
505505
* in the YANG configuration. To use this, pass NULL as the path argument to
506506
* ::nc_server_config_add_unix_socket(). The actual runtime path must then be set
507507
* using ::nc_server_set_unix_socket_path().
508508
*
509+
* All UNIX sockets require a designated base directory for their creation.
510+
* This directory must be set using ::nc_server_set_unix_socket_dir().
511+
* A base directory must be set to create any UNIX socket.
512+
* All socket paths will be relative to this base directory.
513+
*
509514
* Security Recommendation
510515
* -----------------------
511516
* The **Hidden Path** (Option 2) is strongly recommended.
512517
*
513-
* If Cleartext paths are enabled, any user with permission to modify the server
518+
* If standard paths are enabled, any user with permission to modify the server
514519
* configuration can change the UNIX socket path via YANG. This allows them to
515-
* force the server to create or overwrite arbitrary files on the filesystem
516-
* with the privileges of the server process.
520+
* force the server to create or overwrite arbitrary files in a subdirectory
521+
* set by ::nc_server_set_unix_socket_dir() with the privileges of the server process.
517522
*
518523
* FD
519524
* ==

modules/[email protected]

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ module libnetconf2-netconf-server {
330330
description
331331
"Relative filesystem path where the UNIX socket will be bound.
332332
The parent directory must be set by an internal server API setting.
333+
The final resolved path must be within the configured parent directory.
333334
334335
Example: netconf.sock";
335336
}
@@ -339,7 +340,10 @@ module libnetconf2-netconf-server {
339340
type empty;
340341
description
341342
"Indicates that the UNIX socket path is not configured via YANG, but is instead
342-
determined by internal server API settings.";
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.";
343347
}
344348
}
345349
}

src/session_server.c

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4469,28 +4469,39 @@ nc_server_set_unix_socket_path(const char *endpoint_name, const char *socket_pat
44694469
return rc;
44704470
}
44714471

4472-
API const char *
4473-
nc_server_get_unix_socket_path(const char *endpoint_name)
4472+
API int
4473+
nc_server_get_unix_socket_path(const char *endpoint_name, char **socket_path)
44744474
{
4475-
const char *socket_path = NULL;
4475+
int rc = 0;
4476+
char *p = NULL;
44764477
LY_ARRAY_COUNT_TYPE i;
44774478

4478-
NC_CHECK_ARG_RET(NULL, endpoint_name, NULL);
4479+
NC_CHECK_ARG_RET(NULL, endpoint_name, socket_path, 1);
4480+
4481+
*socket_path = NULL;
44794482

44804483
/* CONFIG READ LOCK */
44814484
pthread_rwlock_rdlock(&server_opts.config_lock);
44824485

44834486
/* try to find the path for this endpoint */
44844487
LY_ARRAY_FOR(server_opts.unix_paths, i) {
44854488
if (!strcmp(server_opts.unix_paths[i].endpt_name, endpoint_name)) {
4486-
socket_path = server_opts.unix_paths[i].path;
4489+
p = server_opts.unix_paths[i].path;
44874490
break;
44884491
}
44894492
}
44904493

4494+
if (!p) {
4495+
goto cleanup;
4496+
}
4497+
4498+
*socket_path = strdup(p);
4499+
NC_CHECK_ERRMEM_GOTO(!*socket_path, rc = 1, cleanup);
4500+
4501+
cleanup:
44914502
/* CONFIG READ UNLOCK */
44924503
pthread_rwlock_unlock(&server_opts.config_lock);
4493-
return socket_path;
4504+
return rc;
44944505
}
44954506

44964507
API int
@@ -4510,3 +4521,24 @@ nc_server_set_unix_socket_dir(const char *dir)
45104521
pthread_rwlock_unlock(&server_opts.config_lock);
45114522
return rc;
45124523
}
4524+
4525+
API int
4526+
nc_server_get_unix_socket_dir(char **dir)
4527+
{
4528+
int rc = 0;
4529+
4530+
*dir = NULL;
4531+
4532+
/* CONFIG READ LOCK */
4533+
pthread_rwlock_rdlock(&server_opts.config_lock);
4534+
4535+
if (server_opts.unix_socket_dir) {
4536+
*dir = strdup(server_opts.unix_socket_dir);
4537+
NC_CHECK_ERRMEM_GOTO(!*dir, rc = 1, cleanup);
4538+
}
4539+
4540+
cleanup:
4541+
/* CONFIG READ UNLOCK */
4542+
pthread_rwlock_unlock(&server_opts.config_lock);
4543+
return rc;
4544+
}

src/session_server.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,9 +463,10 @@ int nc_server_set_unix_socket_path(const char *endpoint_name, const char *socket
463463
* @brief Get the UNIX socket path for a given endpoint name.
464464
*
465465
* @param[in] endpoint_name Name of the endpoint.
466-
* @return UNIX socket path, NULL if not found.
466+
* @param[out] socket_path Found UNIX socket path.
467+
* @return 0 on success, 1 on error.
467468
*/
468-
const char *nc_server_get_unix_socket_path(const char *endpoint_name);
469+
int nc_server_get_unix_socket_path(const char *endpoint_name, char **socket_path);
469470

470471
/**
471472
* @brief Set the base directory for UNIX socket paths.
@@ -478,6 +479,14 @@ const char *nc_server_get_unix_socket_path(const char *endpoint_name);
478479
*/
479480
int nc_server_set_unix_socket_dir(const char *dir);
480481

482+
/**
483+
* @brief Get the base directory for UNIX socket paths.
484+
*
485+
* @param[out] dir Base directory for UNIX socket paths.
486+
* @return 0 on success, 1 on error.
487+
*/
488+
int nc_server_get_unix_socket_dir(char **dir);
489+
481490
/** @} Server Session */
482491

483492
/**

0 commit comments

Comments
 (0)