Skip to content

Commit

Permalink
cmake UPDATE use authorized_keys path cmake var
Browse files Browse the repository at this point in the history
  • Loading branch information
roman authored and michalvasko committed Dec 21, 2023
1 parent dc69329 commit 1f2e9c8
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
7 changes: 1 addition & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ endif()
option(ENABLE_COVERAGE "Build code coverage report from tests" OFF)
option(BUILD_CLI "Build and install neotpeer2-cli" ON)
option(ENABLE_URL "Enable URL capability" ON)
set(SSH_AUTHORIZED_KEYS_FORMAT "%h/.ssh/authorized_keys" CACHE STRING "sshd-like pattern (with '%h', '%u', '%U') for determining path to users' SSH authorized_keys file.")
set(THREAD_COUNT 3 CACHE STRING "Number of threads accepting new sessions and handling requests")
set(POLL_IO_TIMEOUT 10 CACHE STRING "Timeout in milliseconds of polling sessions for new data. It is also used for synchronization of low level IO such as sending a reply while a notification is being sent")
set(YANG_MODULE_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/yang/modules/netopeer2" CACHE STRING "Directory where to copy the YANG modules to")
Expand Down Expand Up @@ -109,12 +110,6 @@ if(NOT PIDFILE_PREFIX)
set(PIDFILE_PREFIX "/var/run")
endif()

set(NP2SRV_SSH_AUTHORIZED_KEYS_PATTERN "%s/.ssh/authorized_keys" CACHE STRING "printf-like pattern for determining path to users' SSH authorized_keys file. Must contain exactly one '%s'.")
set(NP2SRV_SSH_AUTHORIZED_KEYS_ARG_IS_USERNAME 0 CACHE STRING "If true, replace '%s' by username. If not set, replace '%s' by home directory. By default, unset.")
if(NOT NP2SRV_SSH_AUTHORIZED_KEYS_PATTERN MATCHES "^[^%]*%s[^%]*$")
message(FATAL_ERROR "Wrong format string given for NP2SRV_SSH_AUTHORIZED_KEYS_PATTERN: exactly one '%s' expected.")
endif()

if(NOT SERVER_DIR)
if("${BUILD_TYPE_UPPER}" STREQUAL "DEBUG")
set(SERVER_DIR "$ENV{HOME}/.netopeer2-server")
Expand Down
6 changes: 2 additions & 4 deletions src/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,8 @@
*/
#cmakedefine NP2SRV_HAVE_SYSTEMD

/** @brief printf-like pattern for path to the authorized_keys file */
#define NP2SRV_SSH_AUTHORIZED_KEYS_PATTERN "@NP2SRV_SSH_AUTHORIZED_KEYS_PATTERN@"
/** @brief Replace %s in NP2SRV_SSH_AUTHORIZED_KEYS_PATTERN by username (1), or by the home dir (0) */
#cmakedefine01 NP2SRV_SSH_AUTHORIZED_KEYS_ARG_IS_USERNAME
/** @brief sshd-like pattern for path to the authorized_keys file */
#define NP2SRV_SSH_AUTHORIZED_KEYS_FORMAT "@SSH_AUTHORIZED_KEYS_FORMAT@"

/** @brief directory for server files (only confirmed-commit backups at the moment) */
#define SERVER_DIR "@SERVER_DIR@"
Expand Down
4 changes: 2 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -603,8 +603,8 @@ server_init(void)
/* if PAM is not supported, the function will return an error, but don't check it, because PAM is not required */
nc_server_ssh_set_pam_conf_filename("netopeer2.conf");

/* set authorized_keys path format to {client_home}/.ssh/authorized_keys */
if (nc_server_ssh_set_authkey_path_format("%h/.ssh/authorized_keys")) {
/* set authorized_keys path format to by default {client_home}/.ssh/authorized_keys */
if (nc_server_ssh_set_authkey_path_format(NP2SRV_SSH_AUTHORIZED_KEYS_FORMAT)) {
ERR("Setting authorized_keys path format failed.");
goto error;
}
Expand Down

0 comments on commit 1f2e9c8

Please sign in to comment.