make secure_getenv discovery project wide

Since the tests need to know if secure_getenv exists or not, the detection and
setup logic is now in the top level CMakeLists.txt.
This commit is contained in:
Charles Giessen 2022-03-09 14:54:58 -07:00 committed by Charles Giessen
parent 7e55b0d86e
commit eac5f00928
3 changed files with 23 additions and 25 deletions

View File

@ -327,6 +327,23 @@ endif()
# Add git branch and tag info in debug mode
target_compile_definitions(loader_common_options INTERFACE $<$<CONFIG:DEBUG>:DEBUG;GIT_BRANCH_NAME=${GIT_BRANCH_NAME};GIT_TAG_INFO=${GIT_TAG_INFO}>)
# Check for the existance of the secure_getenv or __secure_getenv commands
include(CheckFunctionExists)
include(CheckIncludeFile)
check_function_exists(secure_getenv HAVE_SECURE_GETENV)
check_function_exists(__secure_getenv HAVE___SECURE_GETENV)
if (HAVE_SECURE_GETENV)
target_compile_definitions(loader_common_options INTERFACE HAVE_SECURE_GETENV)
endif()
if (HAVE___SECURE_GETENV)
target_compile_definitions(loader_common_options INTERFACE HAVE___SECURE_GETENV)
endif()
if(NOT MSVC AND NOT (HAVE_SECURE_GETENV OR HAVE___SECURE_GETENV))
message(WARNING "Using non-secure environmental lookups. This loader will not properly disable environent variables when run with elevated permissions.")
endif()
# Optional codegen target
if(PYTHONINTERP_FOUND)
add_custom_target(VulkanLoader_generated_source

View File

@ -24,23 +24,6 @@ add_library(loader_specific_options INTERFACE)
target_link_libraries(loader_specific_options INTERFACE loader_common_options Vulkan::Headers)
target_include_directories(loader_specific_options INTERFACE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/generated ${CMAKE_CURRENT_BINARY_DIR})
# Check for the existance of the secure_getenv or __secure_getenv commands
include(CheckFunctionExists)
include(CheckIncludeFile)
check_function_exists(secure_getenv HAVE_SECURE_GETENV)
check_function_exists(__secure_getenv HAVE___SECURE_GETENV)
if (HAVE_SECURE_GETENV)
target_compile_definitions(loader_specific_options INTERFACE HAVE_SECURE_GETENV)
endif()
if (HAVE___SECURE_GETENV)
target_compile_definitions(loader_specific_options INTERFACE HAVE___SECURE_GETENV)
endif()
if(NOT MSVC AND NOT (HAVE_SECURE_GETENV OR HAVE___SECURE_GETENV))
message(WARNING "Using non-secure environmental lookups. This loader will not properly disable environent variables when run with elevated permissions.")
endif()
if(WIN32)
if(MSVC)
# Use static MSVCRT libraries

View File

@ -25,10 +25,6 @@
* Author: Charles Giessen <charles@lunarg.com>
*/
#if !defined(VULKAN_NON_CMAKE_BUILD)
#include "loader_cmake_config.h"
#endif // !defined(VULKAN_NON_CMAKE_BUILD)
#include "shim.h"
static PlatformShim platform_shim;
@ -165,7 +161,7 @@ FRAMEWORK_EXPORT gid_t GETEGID_FUNC_NAME(void) {
}
#if defined(HAVE_SECURE_GETENV)
FRAMEWORK_EXPORT char* SECURE_GETENV_FUNC_NAME(const char *name) {
FRAMEWORK_EXPORT char* SECURE_GETENV_FUNC_NAME(const char* name) {
if (!real_secure_getenv) real_secure_getenv = (PFN_SEC_GETENV)dlsym(RTLD_NEXT, "secure_getenv");
if (platform_shim.use_fake_elevation) {
@ -176,7 +172,7 @@ FRAMEWORK_EXPORT char* SECURE_GETENV_FUNC_NAME(const char *name) {
}
#endif
#if defined(HAVE___SECURE_GETENV)
FRAMEWORK_EXPORT char* __SECURE_GETENV_FUNC_NAME(const char *name) {
FRAMEWORK_EXPORT char* __SECURE_GETENV_FUNC_NAME(const char* name) {
if (!real__secure_getenv) real__secure_getenv = (PFN_SEC_GETENV)dlsym(RTLD_NEXT, "__secure_getenv");
if (platform_shim.use_fake_elevation) {
@ -206,10 +202,12 @@ __attribute__((used)) static Interposer _interpose_fopen MACOS_ATTRIB = {VOIDP_C
__attribute__((used)) static Interposer _interpose_euid MACOS_ATTRIB = {VOIDP_CAST(my_geteuid), VOIDP_CAST(geteuid)};
__attribute__((used)) static Interposer _interpose_egid MACOS_ATTRIB = {VOIDP_CAST(my_getegid), VOIDP_CAST(getegid)};
#if defined(HAVE_SECURE_GETENV)
__attribute__((used)) static Interposer _interpose_secure_getenv MACOS_ATTRIB = {VOIDP_CAST(my_secure_getenv), VOIDP_CAST(secure_getenv)};
__attribute__((used)) static Interposer _interpose_secure_getenv MACOS_ATTRIB = {VOIDP_CAST(my_secure_getenv),
VOIDP_CAST(secure_getenv)};
#endif
#if defined(HAVE___SECURE_GETENV)
__attribute__((used)) static Interposer _interpose__secure_getenv MACOS_ATTRIB = {VOIDP_CAST(my__secure_getenv), VOIDP_CAST(__secure_getenv)};
__attribute__((used)) static Interposer _interpose__secure_getenv MACOS_ATTRIB = {VOIDP_CAST(my__secure_getenv),
VOIDP_CAST(__secure_getenv)};
#endif
#endif
} // extern "C"