From 7cc159d72079770937b9aebadf40e9f2c4fafbc6 Mon Sep 17 00:00:00 2001 From: Anderson Toshiyuki Sasaki Date: Mon, 6 May 2019 15:19:40 +0200 Subject: [PATCH] cmake,options: Allow to set global client config file This allows the global client (ssh_session) configuration file path to be set in configuration time by defining GLOBAL_CLIENT_CONFIG when calling cmake. If it is not defined, the default path is set as "/etc/ssh/ssh_config". usage example: $ cmake -DGLOBAL_CLIENT_CONFIG=/etc/my/custom/path .. Signed-off-by: Anderson Toshiyuki Sasaki Reviewed-by: Andreas Schneider --- CMakeLists.txt | 1 + DefineOptions.cmake | 4 ++++ config.h.cmake | 3 +++ src/options.c | 2 +- tests/unittests/torture_config.c | 2 ++ 5 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6bffbc6d..0681e6e0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -243,6 +243,7 @@ message(STATUS "Benchmarks: ${WITH_BENCHMARKS}") message(STATUS "Symbol versioning: ${WITH_SYMBOL_VERSIONING}") message(STATUS "Allow ABI break: ${WITH_ABI_BREAK}") message(STATUS "Release is final: ${WITH_FINAL}") +message(STATUS "Global client config: ${GLOBAL_CLIENT_CONFIG}") if (WITH_SERVER) message(STATUS "Global bind config: ${GLOBAL_BIND_CONFIG}") endif() diff --git a/DefineOptions.cmake b/DefineOptions.cmake index 5af58977..52b68a73 100644 --- a/DefineOptions.cmake +++ b/DefineOptions.cmake @@ -53,3 +53,7 @@ endif (WITH_ABI_BREAK) if (NOT GLOBAL_BIND_CONFIG) set(GLOBAL_BIND_CONFIG "/etc/ssh/libssh_server_config") endif (NOT GLOBAL_BIND_CONFIG) + +if (NOT GLOBAL_CLIENT_CONFIG) + set(GLOBAL_CLIENT_CONFIG "/etc/ssh/ssh_config") +endif (NOT GLOBAL_CLIENT_CONFIG) diff --git a/config.h.cmake b/config.h.cmake index 404c0168..5e4edc8a 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -15,6 +15,9 @@ /* Global bind configuration file path */ #cmakedefine GLOBAL_BIND_CONFIG "${GLOBAL_BIND_CONFIG}" +/* Global client configuration file path */ +#cmakedefine GLOBAL_CLIENT_CONFIG "${GLOBAL_CLIENT_CONFIG}" + /************************** HEADER FILES *************************/ /* Define to 1 if you have the header file. */ diff --git a/src/options.c b/src/options.c index c620077e..e9d8a721 100644 --- a/src/options.c +++ b/src/options.c @@ -1399,7 +1399,7 @@ int ssh_options_parse_config(ssh_session session, const char *filename) { goto out; } if (filename == NULL) { - r = ssh_config_parse_file(session, "/etc/ssh/ssh_config"); + r = ssh_config_parse_file(session, GLOBAL_CLIENT_CONFIG); } /* Do not process the default configuration as part of connection again */ diff --git a/tests/unittests/torture_config.c b/tests/unittests/torture_config.c index 958a6b6d..55b0f038 100644 --- a/tests/unittests/torture_config.c +++ b/tests/unittests/torture_config.c @@ -394,6 +394,8 @@ static void torture_config_unknown(void **state) { assert_true(ret == 0); ret = ssh_config_parse_file(session, "/etc/ssh/ssh_config"); assert_true(ret == 0); + ret = ssh_config_parse_file(session, GLOBAL_CLIENT_CONFIG); + assert_true(ret == 0); }