diff --git a/CMakeLists.txt b/CMakeLists.txt index e2bdbc13..20016219 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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) diff --git a/cmake/ConfigureChecks.cmake b/cmake/ConfigureChecks.cmake index a0b0a7ea..a28846ad 100644 --- a/cmake/ConfigureChecks.cmake +++ b/cmake/ConfigureChecks.cmake @@ -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) diff --git a/cmake/Modules/FindLibKrb5.cmake b/cmake/Modules/FindLibKrb5.cmake new file mode 100644 index 00000000..3c8c6ca6 --- /dev/null +++ b/cmake/Modules/FindLibKrb5.cmake @@ -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 +) \ No newline at end of file diff --git a/cmake/config.h.cmake b/cmake/config.h.cmake index 0b1c8203..f3ba0c77 100644 --- a/cmake/config.h.cmake +++ b/cmake/config.h.cmake @@ -15,6 +15,9 @@ /* Define to 1 if you have the 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 header file. */ #cmakedefine HAVE_INTTYPES_H "@HAVE_INTTYPES_H@" diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 3b7b51ac..e4b8518d 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -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 ".") @@ -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 @@ -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() @@ -172,7 +126,7 @@ else() hmac.c hmac-md5.c init.c - krb5-wrapper.c + ${KRB5_SOURCE} libsmb2.c md4c.c md5.c @@ -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 @@ -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}) diff --git a/lib/init.c b/lib/init.c index 13ae90a5..f248eead 100644 --- a/lib/init.c +++ b/lib/init.c @@ -76,8 +76,6 @@ #define MAX_URL_SIZE 1024 -#include "compat.h" - static int smb2_parse_args(struct smb2_context *smb2, const char *args) { diff --git a/lib/krb5-wrapper.c b/lib/krb5-wrapper.c index 0a30121e..4900ea3c 100644 --- a/lib/krb5-wrapper.c +++ b/lib/krb5-wrapper.c @@ -19,8 +19,6 @@ #include "config.h" #endif -#ifdef HAVE_LIBKRB5 - #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif @@ -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 */ +} \ No newline at end of file diff --git a/lib/krb5-wrapper.h b/lib/krb5-wrapper.h index 9cbe5f41..7db52ac8 100644 --- a/lib/krb5-wrapper.h +++ b/lib/krb5-wrapper.h @@ -22,8 +22,6 @@ #include "config.h" #endif -#ifdef HAVE_LIBKRB5 - #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif @@ -94,6 +92,4 @@ krb5_set_gss_error(struct smb2_context *smb2, char *func, } #endif -#endif /* HAVE_LIBKRB5 */ - #endif /* _KRB5_WRAPPER_H_ */