Skip to content

Commit

Permalink
Improve GSSAPI and libkrb5 detection.
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolf3s committed Jul 15, 2024
1 parent a039c02 commit a3eb912
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 122 deletions.
15 changes: 8 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,10 @@ endif()
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules)
endif()

if(IOS)
find_package(GSSAPI)

if(GSSAPI_FOUND)
add_definitions(-DHAVE_LIBKRB5)
endif()
if(CMAKE_SYSTEM_NAME MATCHES Linux)
find_package(LibKrb5)
elseif(IOS)
find_package(GSSAPI)
endif()

if(NOT PICO_BOARD OR NOT ESP_PLATFORM)
Expand Down Expand Up @@ -99,8 +97,11 @@ endif()
)
endif()

if(IOS)
if(GSSAPI_FOUND AND LIBKRB5_FOUND)
set(core_DEPENDS ${GSSAPI_LIBRARIES} CACHE STRING "" FORCE)
if(NOT IOS)
set(core_DEPENDS ${LIBKRB5_LIBRARY} CACHE STRING "" FORCE)
endif()
endif()

if(MSVC AND BUILD_SHARED_LIBS)
Expand Down
1 change: 1 addition & 0 deletions cmake/ConfigureChecks.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ check_include_file("arpa/inet.h" HAVE_ARPA_INET_H)
check_include_file("dlfcn.h" HAVE_DLFCN_H)
check_include_file("fcntl.h" HAVE_FCNTL_H)
check_include_file("gssapi/gssapi.h" HAVE_GSSAPI_GSSAPI_H)
check_include_file("krb5/krb5.h" HAVE_LIBKRB5)
check_include_file("inttypes.h" HAVE_INTTYPES_H)
check_include_file("netdb.h" HAVE_NETDB_H)
check_include_file("netinet/in.h" HAVE_NETINET_IN_H)
Expand Down
44 changes: 44 additions & 0 deletions cmake/Modules/FindLibKrb5.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# - Try to find Krb5 headers and libraries
#
# Usage of this module as follows:
#
# find_package(LibKrb5)
#
# Variables used by this module, they can change the default behaviour and need
# to be set before calling find_package:
#
# LibKrb5_ROOT_DIR Set this variable to the root installation of
# libKrb5 if the module has problems finding the
# proper installation path.
#
# Variables defined by this module:
#
# LibKrb5_FOUND System has Krb5 libraries and headers
# LibKrb5_LIBRARY The Krb5 library
# LibKrb5_INCLUDE_DIR The location of Krb5 headers

find_path(LibKrb5_ROOT_DIR
NAMES include/krb5.h
)

find_library(LibKrb5_LIBRARY
NAMES krb5
HINTS ${LibKrb5_ROOT_DIR}/lib
)

find_path(LibKrb5_INCLUDE_DIR
NAMES krb5.h
HINTS ${LibKrb5_ROOT_DIR}/include
)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LibKrb5 DEFAULT_MSG
LibKrb5_LIBRARY
LibKrb5_INCLUDE_DIR
)

mark_as_advanced(
LibKrb5_ROOT_DIR
LibKrb5_LIBRARY
LibKrb5_INCLUDE_DIR
)
3 changes: 3 additions & 0 deletions cmake/config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
/* Define to 1 if you have the <gssapi/gssapi.h> header file. */
#cmakedefine HAVE_GSSAPI_GSSAPI_H "@HAVE_GSSAPI_GSSAPI_H@"

/* Whether we use gssapi_krb5 or not */
#cmakedefine HAVE_LIBKRB5 "@HAVE_LIBKRB5@"

/* Define to 1 if you have the <inttypes.h> header file. */
#cmakedefine HAVE_INTTYPES_H "@HAVE_INTTYPES_H@"

Expand Down
164 changes: 60 additions & 104 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,104 +1,57 @@
if(PICO_BOARD)
add_library(libsmb2 STATIC
lib/aes.c
lib/aes128ccm.c
lib/alloc.c
lib/compat.c
lib/dcerpc.c
lib/dcerpc-lsa.c
lib/dcerpc-srvsvc.c
lib/errors.c
lib/hmac.c
lib/hmac-md5.c
lib/init.c
lib/krb5-wrapper.c
lib/libsmb2.c
lib/md4c.c
lib/md5.c
lib/ntlmssp.c
lib/pdu.c
lib/sha1.c
lib/sha224-256.c
lib/sha384-512.c
lib/smb2-cmd-close.c
lib/smb2-cmd-create.c
lib/smb2-cmd-echo.c
lib/smb2-cmd-error.c
lib/smb2-cmd-flush.c
lib/smb2-cmd-ioctl.c
lib/smb2-cmd-logoff.c
lib/smb2-cmd-negotiate.c
lib/smb2-cmd-query-directory.c
lib/smb2-cmd-query-info.c
lib/smb2-cmd-read.c
lib/smb2-cmd-session-setup.c
lib/smb2-cmd-set-info.c
lib/smb2-cmd-tree-connect.c
lib/smb2-cmd-tree-disconnect.c
lib/smb2-cmd-write.c
lib/smb2-data-file-info.c
lib/smb2-data-filesystem-info.c
lib/smb2-data-security-descriptor.c
lib/smb2-data-reparse-point.c
lib/smb2-share-enum.c
lib/smb3-seal.c
lib/smb2-signing.c
lib/socket.c
lib/sync.c
lib/timestamps.c
lib/unicode.c
lib/usha.c
)
elseif(ESP_PLATFORM)
if(GSSAPI_FOUND OR LIBKRB5_FOUND)
set(KRB5_SOURCE krb5-wrapper.c)
endif()

if(ESP_PLATFORM)
set(COMPONENT_SRCS
lib/aes.c
lib/aes128ccm.c
lib/alloc.c
lib/compat.c
lib/dcerpc.c
lib/dcerpc-lsa.c
lib/dcerpc-srvsvc.c
lib/errors.c
lib/init.c
lib/hmac.c
lib/hmac-md5.c
lib/krb5-wrapper.c
lib/libsmb2.c
lib/md4c.c
lib/md5.c
lib/ntlmssp.c
lib/pdu.c
lib/sha1.c
lib/sha224-256.c
lib/sha384-512.c
lib/smb2-cmd-close.c
lib/smb2-cmd-create.c
lib/smb2-cmd-echo.c
lib/smb2-cmd-error.c
lib/smb2-cmd-flush.c
lib/smb2-cmd-ioctl.c
lib/smb2-cmd-logoff.c
lib/smb2-cmd-negotiate.c
lib/smb2-cmd-query-directory.c
lib/smb2-cmd-query-info.c
lib/smb2-cmd-read.c
lib/smb2-cmd-session-setup.c
lib/smb2-cmd-set-info.c
lib/smb2-cmd-tree-connect.c
lib/smb2-cmd-tree-disconnect.c
lib/smb2-cmd-write.c
lib/smb2-data-file-info.c
lib/smb2-data-filesystem-info.c
lib/smb2-data-security-descriptor.c
lib/smb2-data-reparse-point.c
lib/smb2-share-enum.c
lib/smb3-seal.c
lib/smb2-signing.c
lib/socket.c
lib/sync.c
lib/timestamps.c
lib/unicode.c
lib/usha.c
aes.c
aes128ccm.c
alloc.c
compat.c
dcerpc.c
dcerpc-lsa.c
dcerpc-srvsvc.c
errors.c
init.c
hmac.c
hmac-md5.c
${KRB5_SOURCE}
libsmb2.c
md4c.c
md5.c
ntlmssp.c
pdu.c
sha1.c
sha224-256.c
sha384-512.c
smb2-cmd-close.c
smb2-cmd-create.c
smb2-cmd-echo.c
smb2-cmd-error.c
smb2-cmd-flush.c
smb2-cmd-ioctl.c
smb2-cmd-logoff.c
smb2-cmd-negotiate.c
smb2-cmd-query-directory.c
smb2-cmd-query-info.c
smb2-cmd-read.c
smb2-cmd-session-setup.c
smb2-cmd-set-info.c
smb2-cmd-tree-connect.c
smb2-cmd-tree-disconnect.c
smb2-cmd-write.c
smb2-data-file-info.c
smb2-data-filesystem-info.c
smb2-data-security-descriptor.c
smb2-data-reparse-point.c
smb2-share-enum.c
smb3-seal.c
smb2-signing.c
socket.c
sync.c
timestamps.c
unicode.c
usha.c
)

set(COMPONENT_NAME ".")
Expand All @@ -121,7 +74,7 @@ elseif(IOP AND BUILD_IRX)
hmac.c
hmac-md5.c
init.c
krb5-wrapper.c
${KRB5_SOURCE}
libsmb2.c
md4c.c
md5.c
Expand Down Expand Up @@ -158,6 +111,7 @@ elseif(IOP AND BUILD_IRX)
timestamps.c
unicode.c
usha.c)

BUILD_IOP_IMPORTS(${CMAKE_CURRENT_SOURCE_DIR}/ps2/imports.c ${CMAKE_CURRENT_SOURCE_DIR}/ps2/imports.lst)

else()
Expand All @@ -172,7 +126,7 @@ else()
hmac.c
hmac-md5.c
init.c
krb5-wrapper.c
${KRB5_SOURCE}
libsmb2.c
md4c.c
md5.c
Expand Down Expand Up @@ -211,7 +165,7 @@ else()
usha.c)
endif()

if(NOT PICO_BOARD OR NOT ESP_PLATFORM)
if(NOT ESP_PLATFORM)
set(INCLUDE_PATH ../include)
set(SMB2_INCLUDE "${INCLUDE_PATH}/smb2")
set(HEADERS
Expand Down Expand Up @@ -251,7 +205,9 @@ target_link_libraries(smb2man.irx
PRIVATE
gcc)

add_custom_command(TARGET smb2man.irx POST_BUILD COMMAND md5sum ARGS smb2man.irx)
add_custom_command(TARGET smb2man.irx POST_BUILD COMMAND md5sum ARGS smb2man.irx)
elseif(PICO_BOARD)
add_library(libsmb2 STATIC ${SOURCES})
else()
add_library(smb2 ${SOURCES} ${HEADERS})
target_link_libraries(smb2 PUBLIC ${core_DEPENDS} ${CORE_LIBRARIES})
Expand Down
2 changes: 0 additions & 2 deletions lib/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@

#define MAX_URL_SIZE 1024

#include "compat.h"

static int
smb2_parse_args(struct smb2_context *smb2, const char *args)
{
Expand Down
6 changes: 1 addition & 5 deletions lib/krb5-wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
#include "config.h"
#endif

#ifdef HAVE_LIBKRB5

#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
Expand Down Expand Up @@ -415,6 +413,4 @@ unsigned char *
krb5_get_output_token_buffer(struct private_auth_data *auth_data)
{
return auth_data->output_token.value;
}

#endif /* HAVE_LIBKRB5 */
}
4 changes: 0 additions & 4 deletions lib/krb5-wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
#include "config.h"
#endif

#ifdef HAVE_LIBKRB5

#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
Expand Down Expand Up @@ -94,6 +92,4 @@ krb5_set_gss_error(struct smb2_context *smb2, char *func,
}
#endif

#endif /* HAVE_LIBKRB5 */

#endif /* _KRB5_WRAPPER_H_ */

0 comments on commit a3eb912

Please sign in to comment.