]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
archive_version_details' update (#2349)
authorljdarj <ljd@luigiscorner.mu>
Sat, 8 Mar 2025 03:28:51 +0000 (04:28 +0100)
committerGitHub <noreply@github.com>
Sat, 8 Mar 2025 03:28:51 +0000 (19:28 -0800)
Adding missing librairies to `archive_version_details()`'s output. I put
"system" if the library doesn't give a way to query its version and
"bundled" if there's a choice between the system copy of a library and a
bundled one and we took the bundled copy (Only one library in that case,
libb2. Maybe also xxhash in the future?).

I would have a question for the Windows specialists though: is there a
way to query the interface version of a CNG cryptographic provider?
Because I know of a way for Crypto API providers but I haven't found any
for CNG ones, despite `<bcrypt.h>` having an interface version
structure.

Fixes #2300.

CMakeLists.txt
build/cmake/config.h.in
configure.ac
libarchive/archive.h
libarchive/archive_cryptor_private.h
libarchive/archive_digest_private.h
libarchive/archive_version_details.c

index ec65e83651a344da1331456faffa32e606403fe1..19f7438b45b8f6cbbd179d204145c4a1529af865 100644 (file)
@@ -107,6 +107,9 @@ set(MACHO_CURRENT_VERSION "${MACHO_COMPATIBILITY_VERSION}.${_revision}")
 # saving and restoring the state of the variables.
 INCLUDE(CMakePushCheckState)
 
+# Enable the pkg-config helpers.
+INCLUDE(FindPkgConfig)
+
 # Initialize the state of the variables. This initialization is not
 # necessary but this shows you what value the variables initially have.
 SET(CMAKE_REQUIRED_DEFINITIONS)
@@ -608,6 +611,7 @@ IF(ENABLE_LIBB2)
   FIND_PACKAGE_HANDLE_STANDARD_ARGS(LIBB2 DEFAULT_MSG LIBB2_LIBRARY LIBB2_INCLUDE_DIR)
 ELSE(ENABLE_LIBB2)
   SET(LIBB2_FOUND FALSE) # Override cached value
+  UNSET(LIBB2_PKGCONFIG_VERSION CACHE)
 ENDIF(ENABLE_LIBB2)
 IF(LIBB2_FOUND)
   SET(HAVE_LIBB2 1)
@@ -620,8 +624,13 @@ IF(LIBB2_FOUND)
   SET(CMAKE_REQUIRED_INCLUDES ${LIBB2_INCLUDE_DIR})
   CHECK_FUNCTION_EXISTS(blake2sp_init HAVE_LIBB2)
   CMAKE_POP_CHECK_STATE()
+  pkg_check_modules(LIBB2 libb2)
+  IF(LIBB2_VERSION)
+    SET(LIBB2_PKGCONFIG_VERSION LIBB2_VERSION)
+  ENDIF(LIBB2_VERSION)
 ELSE(LIBB2_FOUND)
   SET(ARCHIVE_BLAKE2 TRUE)
+  UNSET(LIBB2_PKGCONFIG_VERSION CACHE)
 ENDIF(LIBB2_FOUND)
 #
 # Find LZ4
@@ -693,7 +702,6 @@ ENDIF(ZSTD_FOUND)
 MARK_AS_ADVANCED(CLEAR ZSTD_INCLUDE_DIR)
 MARK_AS_ADVANCED(CLEAR ZSTD_LIBRARY)
 
-
 #
 # Check headers
 #
@@ -824,7 +832,7 @@ IF(ENABLE_MBEDTLS)
     LA_CHECK_INCLUDE_FILE("mbedtls/aes.h" HAVE_MBEDTLS_AES_H)
     LA_CHECK_INCLUDE_FILE("mbedtls/md.h" HAVE_MBEDTLS_MD_H)
     LA_CHECK_INCLUDE_FILE("mbedtls/pkcs5.h" HAVE_MBEDTLS_PKCS5_H)
-
+    LA_CHECK_INCLUDE_FILE("mbedtls/version.h" HAVE_MBEDTLS_VERSION_H)
   ENDIF(MBEDTLS_FOUND)
   MARK_AS_ADVANCED(CLEAR MBEDTLS_INCLUDE_DIRS)
   MARK_AS_ADVANCED(CLEAR MBEDCRYPTO_LIBRARY)
@@ -847,7 +855,7 @@ IF(ENABLE_NETTLE)
     LA_CHECK_INCLUDE_FILE("nettle/pbkdf2.h" HAVE_NETTLE_PBKDF2_H)
     LA_CHECK_INCLUDE_FILE("nettle/ripemd160.h" HAVE_NETTLE_RIPEMD160_H)
     LA_CHECK_INCLUDE_FILE("nettle/sha.h" HAVE_NETTLE_SHA_H)
-
+    LA_CHECK_INCLUDE_FILE("nettle/version.h" HAVE_NETTLE_VERSION_H)
   ENDIF(NETTLE_FOUND)
   MARK_AS_ADVANCED(CLEAR NETTLE_INCLUDE_DIR)
   MARK_AS_ADVANCED(CLEAR NETTLE_LIBRARIES)
@@ -866,6 +874,7 @@ IF(ENABLE_OPENSSL AND NOT CMAKE_SYSTEM_NAME MATCHES "Darwin")
     SET(CMAKE_REQUIRED_LIBRARIES ${OPENSSL_CRYPTO_LIBRARY})
     SET(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR})
     LA_CHECK_INCLUDE_FILE("openssl/evp.h" HAVE_OPENSSL_EVP_H)
+    LA_CHECK_INCLUDE_FILE("openssl/opensslv.h" HAVE_OPENSSL_OPENSSLV_H)
     CHECK_FUNCTION_EXISTS(PKCS5_PBKDF2_HMAC_SHA1 HAVE_PKCS5_PBKDF2_HMAC_SHA1)
   ENDIF(OPENSSL_FOUND)
 ELSE()
@@ -1073,7 +1082,6 @@ main(int argc, char **argv)
                "${OUTPUT}\n"
                "Source file was:\n${SOURCE}\n")
        ENDIF (ARCHIVE_CRYPTO_${CRYPTO}_WIN)
-
       ENDIF(NOT DEFINED ARCHIVE_CRYPTO_${CRYPTO}_WIN)
       ENDIF(NOT ARCHIVE_CRYPTO_${CRYPTO})
     ENDFOREACH(CRYPTO)
@@ -1166,6 +1174,7 @@ IF(ENABLE_ICONV)
       CHECK_ICONV("libiconv" "const")
       CHECK_ICONV("libiconv" "")
       IF (HAVE_ICONV)
+        SET(HAVE_LIBICONV 1)
         LIST(APPEND ADDITIONAL_LIBS ${LIBICONV_PATH})
       ENDIF(HAVE_ICONV)
     ENDIF(NOT HAVE_ICONV AND LIBICONV_PATH)
@@ -1209,6 +1218,7 @@ ELSE(ENABLE_ICONV)
   # (once enabled).
   UNSET(HAVE_LOCALE_CHARSET CACHE)
   UNSET(HAVE_ICONV CACHE)
+  UNSET(HAVE_LIBICONV CACHE)
   UNSET(HAVE_ICONV_libc_ CACHE)
   UNSET(HAVE_ICONV_libc_const CACHE)
   UNSET(HAVE_ICONV_libiconv_ CACHE)
@@ -1238,6 +1248,7 @@ IF(LIBXML2_FOUND)
   SET(CMAKE_REQUIRED_INCLUDES ${ICONV_INCLUDE_DIR} ${LIBXML2_INCLUDE_DIR})
   CHECK_INCLUDE_FILES("libxml/xmlreader.h" HAVE_LIBXML_XMLREADER_H)
   CHECK_INCLUDE_FILES("libxml/xmlwriter.h" HAVE_LIBXML_XMLWRITER_H)
+  CHECK_INCLUDE_FILES("libxml/xmlversion.h" HAVE_LIBXML_XMLVERSION_H)
   # Test if a macro is needed for the library.
   TRY_MACRO_FOR_LIBRARY(
     "${ICONV_INCLUDE_DIR};${LIBXML2_INCLUDE_DIR}"
@@ -1818,11 +1829,16 @@ IF(ENABLE_XATTR)
   CHECK_LIBRARY_EXISTS(attr "setxattr" "" HAVE_LIBATTR)
   IF(HAVE_LIBATTR)
     SET(CMAKE_REQUIRED_LIBRARIES "attr")
-  ELSE()
+         pkg_check_modules(LIBATTR libattr)
+         IF(LIBATTR_VERSION)
+           SET(LIBATTR_PKGCONFIG_VERSION ${LIBATTR_VERSION})
+         ENDIF(LIBATTR_VERSION)
+  ELSE(HAVE_LIBATTR)
     CHECK_LIBRARY_EXISTS(gnu "setxattr" "" HAVE_LIBATTR_GNU)
     IF(HAVE_LIBATTR_GNU)
       SET(CMAKE_REQUIRED_LIBRARIES "gnu")
     ENDIF()
+    UNSET(LIBATTR_PKGCONFIG_VERSION CACHE)
   ENDIF(HAVE_LIBATTR)
   CHECK_SYMBOL_EXISTS(EXTATTR_NAMESPACE_USER "sys/types.h;sys/extattr.h" HAVE_DECL_EXTATTR_NAMESPACE_USER)
   CHECK_SYMBOL_EXISTS(XATTR_NOFOLLOW "sys/xattr.h" HAVE_DECL_XATTR_NOFOLLOW)
@@ -1940,6 +1956,12 @@ IF(ENABLE_ACL)
     SET(CMAKE_REQUIRED_LIBRARIES "acl")
     FIND_LIBRARY(ACL_LIBRARY NAMES acl)
     LIST(APPEND ADDITIONAL_LIBS ${ACL_LIBRARY})
+         pkg_check_modules(LIBACL libacl)
+         IF(LIBACL_VERSION)
+           SET(LIBACL_PKGCONFIG_VERSION ${LIBACL_VERSION})
+         ENDIF(LIBACL_VERSION)
+  ELSE(HAVE_LIBACL)
+    UNSET(LIBACL_PKGCONFIG_VERSION CACHE)
   ENDIF(HAVE_LIBACL)
 
   CHECK_TYPE_EXISTS(acl_t "sys/types.h;sys/acl.h" HAVE_ACL_T)
@@ -2079,6 +2101,12 @@ int main(void) { return ACL_SYNCHRONIZE; }" HAVE_DECL_ACL_SYNCHRONIZE)
     SET(CMAKE_REQUIRED_LIBRARIES "richacl")
     FIND_LIBRARY(RICHACL_LIBRARY NAMES richacl)
     LIST(APPEND ADDITIONAL_LIBS ${RICHACL_LIBRARY})
+         pkg_check_modules(LIBRICHACL librichacl)
+         IF(LIBRICHACL_VERSION)
+           SET(LIBRICHACL_PKGCONFIG_VERSION ${LIBRICHACL_VERSION})
+         ENDIF(LIBRICHACL_VERSION)
+  ELSE(HAVE_LIBRICHACL)
+    UNSET(LIBRICHACL_PKGCONFIG_VERSION CACHE)
   ENDIF(HAVE_LIBRICHACL)
 
   CHECK_STRUCT_HAS_MEMBER("struct richace" e_type "sys/richacl.h"
index 1e05dafcbc48a13db501289223ad955d93cca741..c15582a9872ed0a0312d3c978c8fb97cdea1d8fb 100644 (file)
@@ -729,6 +729,9 @@ typedef uint64_t uintmax_t;
 /* Define to 1 if you have the `gcc' library (-lgcc). */
 #cmakedefine HAVE_LIBGCC 1
 
+/* Define to 1 if you have the `iconv' library (-liconv). */
+#cmakedefine HAVE_LIBICONV 1
+
 /* Define to 1 if you have the `lz4' library (-llz4). */
 #cmakedefine HAVE_LIBLZ4 1
 
@@ -765,6 +768,9 @@ typedef uint64_t uintmax_t;
 /* Define to 1 if you have the <libxml/xmlwriter.h> header file. */
 #cmakedefine HAVE_LIBXML_XMLWRITER_H 1
 
+/* Define to 1 if you have the <libxml/xmlversion.h> header file. */
+#cmakedefine HAVE_LIBXML_XMLVERSION_H 1
+
 /* Define to 1 if you have the `z' library (-lz). */
 #cmakedefine HAVE_LIBZ 1
 
@@ -868,6 +874,9 @@ typedef uint64_t uintmax_t;
 /* Define to 1 if you have the <mbedtls/pkcs5.h> header file. */
 #cmakedefine HAVE_MBEDTLS_PKCS5_H 1
 
+/* Define to 1 if you have the <mbedtls/pkcs5.h> header file. */
+#cmakedefine HAVE_MBEDTLS_VERSION_H 1
+
 /* Define to 1 if you have the `mbrtowc' function. */
 #cmakedefine HAVE_MBRTOWC 1
 
@@ -913,6 +922,9 @@ typedef uint64_t uintmax_t;
 /* Define to 1 if you have the <nettle/sha.h> header file. */
 #cmakedefine HAVE_NETTLE_SHA_H 1
 
+/* Define to 1 if you have the <nettle/version.h> header file. */
+#cmakedefine HAVE_NETTLE_VERSION_H 1
+
 /* Define to 1 if you have the `nl_langinfo' function. */
 #cmakedefine HAVE_NL_LANGINFO 1
 
@@ -922,6 +934,9 @@ typedef uint64_t uintmax_t;
 /* Define to 1 if you have the <openssl/evp.h> header file. */
 #cmakedefine HAVE_OPENSSL_EVP_H 1
 
+/* Define to 1 if you have the <openssl/opensslv.h> header file. */
+#cmakedefine HAVE_OPENSSL_OPENSSLV_H 1
+
 /* Define to 1 if you have the <paths.h> header file. */
 #cmakedefine HAVE_PATHS_H 1
 
@@ -1144,7 +1159,6 @@ typedef uint64_t uintmax_t;
 /* Define to 1 if you have the <sys/stat.h> header file. */
 #cmakedefine HAVE_SYS_STAT_H 1
 
-
 /* Define to 1 if you have the <sys/sysmacros.h> header file. */
 #cmakedefine HAVE_SYS_SYSMACROS_H 1
 
@@ -1325,6 +1339,15 @@ typedef uint64_t uintmax_t;
 /* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
 #cmakedefine TIME_WITH_SYS_TIME 1
 
+/* Version number of package */
+#cmakedefine LIBATTR_PKGCONFIG_VERSION "@LIBATTR_PKGCONFIG_VERSION@"
+
+/* Version number of package */
+#cmakedefine LIBACL_PKGCONFIG_VERSION "@LIBACL_PKGCONFIG_VERSION@"
+
+/* Version number of package */
+#cmakedefine LIBRICHACL_PKGCONFIG_VERSION "@LIBRICHACL_PKGCONFIG_VERSION@"
+
 /*
  * Some platform requires a macro to use extension functions.
  */
@@ -1408,4 +1431,4 @@ typedef uint64_t uintmax_t;
 #cmakedefine intptr_t @intptr_t@
 
 /* Define to `unsigned int' if <sys/types.h> does not define. */
-#cmakedefine uintptr_t @uintptr_t@
+#cmakedefine uintptr_t @uintptr_t@
\ No newline at end of file
index 57c3793c11d25189832a1b9b378a216276fb70ed..8713827e891ad1688ce10db400e04c1c0f8f7a16 100644 (file)
@@ -38,7 +38,7 @@ m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
 ARCHIVE_MINOR=$(( (LIBARCHIVE_VERSION_N() / 1000) % 1000 ))
 # Libarchive 2.7 == libtool interface 9 = 2 + 7
 # Libarchive 2.8 == libtool interface 10 = 2 + 8
-# Libarchive 2.9 == libtool interface 11 = 2 + 8
+# Libarchive 2.9 == libtool interface 11 = 2 + 9
 # Libarchive 3.0 == libtool interface 12
 # Libarchive 3.1 == libtool interface 13
 ARCHIVE_INTERFACE=`echo $((13 + ${ARCHIVE_MINOR}))`
@@ -399,6 +399,7 @@ if test "x$with_zlib" != "xno"; then
       int main(int argc, char **argv) { inflate(NULL, 0); return 0; }
     ]])],
     [AC_DEFINE([HAVE_ZLIB_H], [1], [Define to 1 if you have zlib >= 1.2.1])
+      AC_DEFINE([HAVE_LIBZ], [1], [Define to 1 if you have zlib >= 1.2.1])
       AC_MSG_RESULT([found a suitable version of zlib (>= 1.2.1)])
     ],
     [AC_MSG_RESULT([could not find a suitable version of zlib (>= 1.2.1)])
@@ -441,6 +442,10 @@ AC_ARG_WITH([libb2],
 if test "x$with_libb2" != "xno"; then
   AC_CHECK_HEADERS([blake2.h])
   AC_CHECK_LIB(b2,blake2sp_init)
+  BLAKE2_PC_VER=`pkg-config --modversion libb2`
+  if test "x$BLAKE2_PC_VER" != "x"; then
+    AC_DEFINE_UNQUOTED([LIBB2_PKGCONFIG_VERSION], ["$BLAKE2_PC_VER"], [Libb2 version coming from pkg-config.])
+  fi
 fi
 
 AM_CONDITIONAL([INC_BLAKE2], [test "x$ac_cv_lib_b2_blake2sp_init" != "xyes"])
@@ -456,6 +461,7 @@ if test "x$with_iconv" != "xno"; then
     am_save_LIBS="$LIBS"
     LIBS="${LIBS} ${LIBICONV}"
     if test -n "$LIBICONV"; then
+         AC_DEFINE([HAVE_LIBICONV], [1], [Define to 1 if you have the `iconv' library (-liconv).])
       LIBSREQUIRED="$LIBSREQUIRED${LIBSREQUIRED:+ }iconv"
     fi
     AC_CHECK_FUNCS([locale_charset])
@@ -555,7 +561,7 @@ if test "x$with_xml2" != "xno"; then
   ], [
     AC_CHECK_LIB(xml2,xmlInitParser)
   ])
-  AC_CHECK_HEADERS([libxml/xmlreader.h libxml/xmlwriter.h])
+  AC_CHECK_HEADERS([libxml/xmlreader.h libxml/xmlwriter.h libxml/xmlversion.h])
 fi
 if test "x$ac_cv_header_libxml_xmlreader_h" != "xyes"; then
   if test "x$with_expat" != "xno"; then
@@ -916,6 +922,10 @@ if test "x$enable_xattr" != "xno"; then
 ])
     AC_CHECK_DECLS([XATTR_NOFOLLOW], [], [], [#include <sys/xattr.h>
 ])
+    ATTR_PC_VER=`pkg-config --modversion libattr`
+    if test "x$ATTR_PC_VER" != "x"; then
+      AC_DEFINE_UNQUOTED([LIBATTR_PKGCONFIG_VERSION], ["$ATTR_PC_VER"], [Libattr version coming from pkg-config.])
+    fi
     if test "x$ac_cv_header_sys_xattr_h" = "xyes" \
         -a "x$ac_cv_have_decl_XATTR_NOFOLLOW" = "xyes"; then
        # Darwin extended attributes support
@@ -1011,7 +1021,10 @@ AC_ARG_ENABLE([acl],
 if test "x$enable_acl" != "xno"; then
     # Libacl
     AC_CHECK_LIB([acl], [acl_get_file])
-
+    ACL_PC_VER=`pkg-config --modversion libacl`
+    if test "x$ACL_PC_VER" != "x"; then
+      AC_DEFINE_UNQUOTED([LIBACL_PKGCONFIG_VERSION], ["$ACL_PC_VER"], [Libacl version coming from pkg-config.])
+    fi
     AC_CHECK_TYPES([acl_t, acl_entry_t, acl_permset_t, acl_tag_t], [], [], [
       #if HAVE_SYS_TYPES_H
       #include <sys/types.h>
@@ -1022,7 +1035,10 @@ if test "x$enable_acl" != "xno"; then
     ])
 
     AC_CHECK_LIB([richacl], [richacl_get_file])
-
+    RICHACL_PC_VER=`pkg-config --modversion librichacl`
+    if test "x$RICHACL_PC_VER" != "x"; then
+      AC_DEFINE_UNQUOTED([LIBRICHACL_PKGCONFIG_VERSION], ["$RICHACL_PC_VER"], [Librichacl version coming from pkg-config.])
+    fi
     AC_CHECK_TYPES([[struct richace], [struct richacl]], [], [], [
       #if HAVE_SYS_RICHACL_H
       #include <sys/richacl.h>
@@ -1305,6 +1321,7 @@ fi
 
 if test "x$with_mbedtls" = "xyes"; then
     AC_CHECK_HEADERS([mbedtls/aes.h mbedtls/md.h mbedtls/pkcs5.h])
+    AC_CHECK_HEADERS([mbedtls/version.h])
     saved_LIBS=$LIBS
     AC_CHECK_LIB(mbedcrypto,mbedtls_sha1_init)
     CRYPTO_CHECK(MD5, MBEDTLS, md5)
@@ -1321,6 +1338,7 @@ fi
 if test "x$with_nettle" = "xyes"; then
     AC_CHECK_HEADERS([nettle/md5.h nettle/ripemd160.h nettle/sha.h])
     AC_CHECK_HEADERS([nettle/pbkdf2.h nettle/aes.h nettle/hmac.h])
+    AC_CHECK_HEADERS([nettle/version.h])
     saved_LIBS=$LIBS
     AC_CHECK_LIB(nettle,nettle_sha1_init)
     CRYPTO_CHECK(MD5, NETTLE, md5)
@@ -1335,7 +1353,7 @@ if test "x$with_nettle" = "xyes"; then
 fi
 
 if test "x$with_openssl" != "xno"; then
-    AC_CHECK_HEADERS([openssl/evp.h])
+    AC_CHECK_HEADERS([openssl/evp.h openssl/opensslv.h])
     saved_LIBS=$LIBS
     LIBSREQUIRED="$LIBSREQUIRED${LIBSREQUIRED:+ }libcrypto"
     AC_CHECK_LIB(crypto,OPENSSL_config)
index 105df69e9da1bd624bd2798520ca12d6b7abdb71..d6de7fd12c59df58db93b2fae6cbd02ff9f2c8e7 100644 (file)
@@ -197,6 +197,23 @@ __LA_DECL const char *  archive_liblzma_version(void);
 __LA_DECL const char *  archive_bzlib_version(void);
 __LA_DECL const char *  archive_liblz4_version(void);
 __LA_DECL const char *  archive_libzstd_version(void);
+__LA_DECL const char *  archive_liblzo2_version(void);
+__LA_DECL const char *  archive_libexpat_version(void);
+__LA_DECL const char *  archive_libbsdxml_version(void);
+__LA_DECL const char *  archive_libxml2_version(void);
+__LA_DECL const char *  archive_mbedtls_version(void);
+__LA_DECL const char *  archive_nettle_version(void);
+__LA_DECL const char *  archive_openssl_version(void);
+__LA_DECL const char *  archive_libmd_version(void);
+__LA_DECL const char *  archive_commoncrypto_version(void);
+__LA_DECL const char *  archive_cng_version(void);
+__LA_DECL const char *  archive_wincrypt_version(void);
+__LA_DECL const char *  archive_librichacl_version(void);
+__LA_DECL const char *  archive_libacl_version(void);
+__LA_DECL const char *  archive_libattr_version(void);
+__LA_DECL const char *  archive_libiconv_version(void);
+__LA_DECL const char *  archive_libpcre_version(void);
+__LA_DECL const char *  archive_libpcre2_version(void);
 
 /* Declare our basic types. */
 struct archive;
index c13f29260a07bc0d0763fe110461d9196f00c06c..460d38c122a6356666732ddee4d5a10e26a32f88 100644 (file)
@@ -64,6 +64,7 @@ typedef struct {
 
 #elif defined(_WIN32) && !defined(__CYGWIN__) && defined(HAVE_BCRYPT_H) && _WIN32_WINNT >= _WIN32_WINNT_VISTA
 #include <bcrypt.h>
+#define        ARCHIVE_CRYPTOR_USE_CNG 1
 
 /* Common in other bcrypt implementations, but missing from VS2008. */
 #ifndef BCRYPT_SUCCESS
@@ -86,6 +87,7 @@ typedef struct {
 #include <mbedtls/aes.h>
 #include <mbedtls/md.h>
 #include <mbedtls/pkcs5.h>
+#define        ARCHIVE_CRYPTOR_USE_MBED 1
 
 #define AES_MAX_KEY_SIZE 32
 #define AES_BLOCK_SIZE 16
@@ -105,6 +107,7 @@ typedef struct {
 #endif
 #include <nettle/aes.h>
 #include <nettle/version.h>
+#define        ARCHIVE_CRYPTOR_USE_NETTLE 1
 
 typedef struct {
 #if NETTLE_VERSION_MAJOR < 3
@@ -125,6 +128,7 @@ typedef struct {
 
 #elif defined(HAVE_LIBCRYPTO)
 #include "archive_openssl_evp_private.h"
+#define        ARCHIVE_CRYPTOR_USE_OPENSSL 1
 #define AES_BLOCK_SIZE 16
 #define AES_MAX_KEY_SIZE 32
 
index 339b4edca48d72b1ee6c80dadf40d91df151381d..c61b183f93d2c07f29daf564d080bc6b1678958f 100644 (file)
   defined(ARCHIVE_CRYPTO_SHA384_LIBSYSTEM) ||\
   defined(ARCHIVE_CRYPTO_SHA512_LIBSYSTEM)
 #include <CommonCrypto/CommonDigest.h>
+#define        ARCHIVE_CRYPTO_CommonCrypto 1
 #endif
 
 /* mbed TLS crypto headers */
 #if defined(HAVE_BCRYPT_H) && _WIN32_WINNT >= _WIN32_WINNT_VISTA
 /* don't use bcrypt when XP needs to be supported */
 #include <bcrypt.h>
+#define        ARCHIVE_CRYPTO_CNG 1
 typedef struct {
   int   valid;
   BCRYPT_ALG_HANDLE  hAlg;
@@ -175,6 +177,7 @@ typedef struct {
 #else
 #include <windows.h>
 #include <wincrypt.h>
+#define        ARCHIVE_CRYPTO_WINCRYPT 1
 typedef struct {
   int   valid;
   HCRYPTPROV  cryptProv;
@@ -191,8 +194,10 @@ typedef MD5_CTX archive_md5_ctx;
 #elif defined(ARCHIVE_CRYPTO_MD5_LIBSYSTEM)
 typedef CC_MD5_CTX archive_md5_ctx;
 #elif defined(ARCHIVE_CRYPTO_MD5_MBEDTLS)
+#define        ARCHIVE_CRYPTO_MBED 1
 typedef mbedtls_md5_context archive_md5_ctx;
 #elif defined(ARCHIVE_CRYPTO_MD5_NETTLE)
+#define        ARCHIVE_CRYPTO_NETTLE 1
 typedef struct md5_ctx archive_md5_ctx;
 #elif defined(ARCHIVE_CRYPTO_MD5_OPENSSL)
 typedef EVP_MD_CTX *archive_md5_ctx;
@@ -207,8 +212,10 @@ typedef RMD160_CTX archive_rmd160_ctx;
 #elif defined(ARCHIVE_CRYPTO_RMD160_LIBMD)
 typedef RIPEMD160_CTX archive_rmd160_ctx;
 #elif defined(ARCHIVE_CRYPTO_RMD160_MBEDTLS)
+#define        ARCHIVE_CRYPTO_MBED 1
 typedef mbedtls_ripemd160_context archive_rmd160_ctx;
 #elif defined(ARCHIVE_CRYPTO_RMD160_NETTLE)
+#define        ARCHIVE_CRYPTO_NETTLE 1
 typedef struct ripemd160_ctx archive_rmd160_ctx;
 #elif defined(ARCHIVE_CRYPTO_RMD160_OPENSSL)
 typedef EVP_MD_CTX *archive_rmd160_ctx;
@@ -223,8 +230,10 @@ typedef SHA1_CTX archive_sha1_ctx;
 #elif defined(ARCHIVE_CRYPTO_SHA1_LIBSYSTEM)
 typedef CC_SHA1_CTX archive_sha1_ctx;
 #elif defined(ARCHIVE_CRYPTO_SHA1_MBEDTLS)
+#define        ARCHIVE_CRYPTO_MBED 1
 typedef mbedtls_sha1_context archive_sha1_ctx;
 #elif defined(ARCHIVE_CRYPTO_SHA1_NETTLE)
+#define        ARCHIVE_CRYPTO_NETTLE 1
 typedef struct sha1_ctx archive_sha1_ctx;
 #elif defined(ARCHIVE_CRYPTO_SHA1_OPENSSL)
 typedef EVP_MD_CTX *archive_sha1_ctx;
@@ -245,8 +254,10 @@ typedef SHA256_CTX archive_sha256_ctx;
 #elif defined(ARCHIVE_CRYPTO_SHA256_LIBSYSTEM)
 typedef CC_SHA256_CTX archive_sha256_ctx;
 #elif defined(ARCHIVE_CRYPTO_SHA256_MBEDTLS)
+#define        ARCHIVE_CRYPTO_MBED 1
 typedef mbedtls_sha256_context archive_sha256_ctx;
 #elif defined(ARCHIVE_CRYPTO_SHA256_NETTLE)
+#define        ARCHIVE_CRYPTO_NETTLE 1
 typedef struct sha256_ctx archive_sha256_ctx;
 #elif defined(ARCHIVE_CRYPTO_SHA256_OPENSSL)
 typedef EVP_MD_CTX *archive_sha256_ctx;
@@ -265,8 +276,10 @@ typedef SHA2_CTX archive_sha384_ctx;
 #elif defined(ARCHIVE_CRYPTO_SHA384_LIBSYSTEM)
 typedef CC_SHA512_CTX archive_sha384_ctx;
 #elif defined(ARCHIVE_CRYPTO_SHA384_MBEDTLS)
+#define        ARCHIVE_CRYPTO_MBED 1
 typedef mbedtls_sha512_context archive_sha384_ctx;
 #elif defined(ARCHIVE_CRYPTO_SHA384_NETTLE)
+#define        ARCHIVE_CRYPTO_NETTLE 1
 typedef struct sha384_ctx archive_sha384_ctx;
 #elif defined(ARCHIVE_CRYPTO_SHA384_OPENSSL)
 typedef EVP_MD_CTX *archive_sha384_ctx;
@@ -287,8 +300,10 @@ typedef SHA512_CTX archive_sha512_ctx;
 #elif defined(ARCHIVE_CRYPTO_SHA512_LIBSYSTEM)
 typedef CC_SHA512_CTX archive_sha512_ctx;
 #elif defined(ARCHIVE_CRYPTO_SHA512_MBEDTLS)
+#define        ARCHIVE_CRYPTO_MBED 1
 typedef mbedtls_sha512_context archive_sha512_ctx;
 #elif defined(ARCHIVE_CRYPTO_SHA512_NETTLE)
+#define        ARCHIVE_CRYPTO_NETTLE 1
 typedef struct sha512_ctx archive_sha512_ctx;
 #elif defined(ARCHIVE_CRYPTO_SHA512_OPENSSL)
 typedef EVP_MD_CTX *archive_sha512_ctx;
index 29be24f3222ece18e205c7665d61ee3655e20250..0530e2f4242bd214f01ce367fd2f54a83e0ca7d8 100644 (file)
 #endif
 #ifdef HAVE_ZSTD_H
 #include <zstd.h>
+#include <stdio.h>
+#endif
+#ifdef HAVE_LZO_LZOCONF_H
+#include <lzo/lzoconf.h>
+#endif
+#if HAVE_LIBXML_XMLVERSION_H
+#include <libxml/xmlversion.h>
+#elif HAVE_BSDXML_H
+#include <bsdxml.h>
+#elif HAVE_EXPAT_H
+#include <expat.h>
+#endif
+#if HAVE_MBEDTLS_VERSION_H
+#include <mbedtls/version.h>
+#endif
+#if HAVE_NETTLE_VERSION_H
+#include <nettle/version.h>
+#include <stdio.h>
+#endif
+#if HAVE_OPENSSL_OPENSSLV_H
+#include <openssl/opensslv.h>
+#include <stdio.h>
+#endif
+#if HAVE_ICONV_H
+#include <iconv.h>
+#endif
+#if HAVE_PCRE_H
+#include <pcre.h>
+#endif
+#if HAVE_PCRE2_H
+#include <pcre2.h>
 #endif
 
 #include "archive.h"
 #include "archive_private.h"
 #include "archive_string.h"
+#include "archive_cryptor_private.h"
+#include "archive_digest_private.h"
+
+static void
+archive_regex_version(struct archive_string* str)
+{
+#if HAVE_LIBPCREPOSIX && HAVE_PCRE_H
+       archive_strcat(str, " libpcre/");
+       archive_strcat(str, archive_libpcre_version());
+#elif HAVE_LIBPCRE2POSIX && HAVE_PCRE2_H
+       archive_strcat(str, " libpcre2/");
+       archive_strcat(str, archive_libpcre2_version());
+#else
+       (void)str; /* UNUSED */
+#endif
+}
+
+static void
+archive_xml_version(struct archive_string* str)
+{
+#if HAVE_LIBXML_XMLVERSION_H && HAVE_LIBXML2
+       archive_strcat(str, " libxml2/");
+       archive_strcat(str, archive_libxml2_version());
+#elif HAVE_BSDXML_H && HAVE_LIBBSDXML
+       archive_strcat(str, " bsdxml/");
+       archive_strcat(str, archive_libbsdxml_version());
+#elif HAVE_EXPAT_H && HAVE_LIBEXPAT
+       archive_strcat(str, " expat/");
+       archive_strcat(str, archive_libexpat_version());
+#else
+       (void)str; /* UNUSED */
+#endif
+}
+
+static void
+archive_libb2_version(struct archive_string* str)
+{
+       archive_strcat(str, " libb2/");
+#if HAVE_BLAKE2_H && HAVE_LIBB2
+#if defined(LIBB2_PKGCONFIG_VERSION)
+       archive_strcat(str, LIBB2_PKGCONFIG_VERSION);
+#else
+       archive_strcat(str, "system");
+#endif
+#else
+       archive_strcat(str, "bundled");
+#endif
+}
+
+static void
+archive_crypto_version(struct archive_string* str)
+{
+#if defined(ARCHIVE_CRYPTOR_USE_Apple_CommonCrypto) || defined(ARCHIVE_DIGEST_USE_Apple_CommonCrypto)
+       archive_strcat(str, " CommonCrypto/");
+       archive_strcat(str, archive_commoncrypto_version());
+#endif
+#if defined(ARCHIVE_CRYPTOR_USE_CNG) || defined(ARCHIVE_DIGEST_USE_CNG)
+       archive_strcat(str, " cng/");
+       archive_strcat(str, archive_cng_version());
+#endif
+#if defined(ARCHIVE_CRYPTOR_USE_MBED) || defined(ARCHIVE_DIGEST_USE_MBED)
+       archive_strcat(str, " mbedtls/");
+       archive_strcat(str, archive_mbedtls_version());
+#endif
+#if defined(ARCHIVE_CRYPTOR_USE_NETTLE) || defined(ARCHIVE_DIGEST_USE_NETTLE)
+       archive_strcat(str, " nettle/");
+       archive_strcat(str, archive_nettle_version());
+#endif
+#if defined(ARCHIVE_CRYPTOR_USE_OPENSSL) || defined(ARCHIVE_DIGEST_USE_OPENSSL)
+       archive_strcat(str, " openssl/");
+       archive_strcat(str, archive_openssl_version());
+#endif
+#if defined(ARCHIVE_CRYPTOR_USE_LIBMD) || defined(ARCHIVE_DIGEST_USE_LIBMD)
+       archive_strcat(str, " libmd/");
+       archive_strcat(str, archive_libmd_version());
+#endif
+#if defined(ARCHIVE_CRYPTOR_USE_WINCRYPT) || defined(ARCHIVE_DIGEST_USE_WINCRYPT)
+       archive_strcat(str, " WinCrypt/");
+       archive_strcat(str, archive_wincrypt_version());
+#endif
+       // Just in case
+       (void)str; /* UNUSED */
+}
 
 const char *
 archive_version_details(void)
@@ -62,12 +176,17 @@ archive_version_details(void)
        const char *bzlib = archive_bzlib_version();
        const char *liblz4 = archive_liblz4_version();
        const char *libzstd = archive_libzstd_version();
+       const char *liblzo = archive_liblzo2_version();
+       const char *libiconv = archive_libiconv_version();
+       const char *libacl = archive_libacl_version();
+       const char *librichacl = archive_librichacl_version();
+       const char *libattr = archive_libacl_version();
 
        if (!init) {
                archive_string_init(&str);
 
                archive_strcat(&str, ARCHIVE_VERSION_STRING);
-               if (zlib != NULL) {
+               if (zlib) {
                        archive_strcat(&str, " zlib/");
                        archive_strcat(&str, zlib);
                }
@@ -91,6 +210,30 @@ archive_version_details(void)
                        archive_strcat(&str, " libzstd/");
                        archive_strcat(&str, libzstd);
                }
+               if (liblzo) {
+                       archive_strcat(&str, " liblzo2/");
+                       archive_strcat(&str, liblzo);
+               }
+               archive_xml_version(&str);
+               archive_regex_version(&str);
+               archive_crypto_version(&str);
+               archive_libb2_version(&str);
+               if (librichacl) {
+                       archive_strcat(&str, " librichacl/");
+                       archive_strcat(&str, librichacl);
+               }
+               if (libacl) {
+                       archive_strcat(&str, " libacl/");
+                       archive_strcat(&str, libacl);
+               }
+               if (libattr) {
+                       archive_strcat(&str, " libattr/");
+                       archive_strcat(&str, libattr);
+               }
+               if (libiconv) {
+                       archive_strcat(&str, " libiconv/");
+                       archive_strcat(&str, libiconv);
+               }
        }
        return str.s;
 }
@@ -98,8 +241,8 @@ archive_version_details(void)
 const char *
 archive_zlib_version(void)
 {
-#ifdef HAVE_ZLIB_H
-       return ZLIB_VERSION;
+#if HAVE_ZLIB_H && HAVE_LIBZ
+       return zlibVersion();
 #else
        return NULL;
 #endif
@@ -108,8 +251,8 @@ archive_zlib_version(void)
 const char *
 archive_liblzma_version(void)
 {
-#ifdef HAVE_LZMA_H
-       return LZMA_VERSION_STRING;
+#if HAVE_LZMA_H && HAVE_LIBLZMA
+       return lzma_version_string();
 #else
        return NULL;
 #endif
@@ -118,7 +261,7 @@ archive_liblzma_version(void)
 const char *
 archive_bzlib_version(void)
 {
-#ifdef HAVE_BZLIB_H
+#if HAVE_BZLIB_H && HAVE_LIBBZ2
        return BZ2_bzlibVersion();
 #else
        return NULL;
@@ -128,12 +271,22 @@ archive_bzlib_version(void)
 const char *
 archive_liblz4_version(void)
 {
-#if defined(HAVE_LZ4_H) && defined(HAVE_LIBLZ4)
+#if HAVE_LZ4_H && HAVE_LIBLZ4
+#if LZ4_VERSION_NUMBER > 10705
+       return LZ4_versionString();
+#elif LZ4_VERSION_NUMBER > 10300
+       div_t major = div(LZ4_versionNumber(), 10000);
+       div_t minor = div(major.rem, 100);
+       static char lz4_version[9];
+       snprintf(lz4_version, 9, "%d.%d.%d", major.quot, minor.quot, minor.rem);
+       return lz4_version;
+#else
 #define str(s) #s
 #define NUMBER(x) str(x)
        return NUMBER(LZ4_VERSION_MAJOR) "." NUMBER(LZ4_VERSION_MINOR) "." NUMBER(LZ4_VERSION_RELEASE);
 #undef NUMBER
 #undef str
+#endif
 #else
        return NULL;
 #endif
@@ -143,7 +296,243 @@ const char *
 archive_libzstd_version(void)
 {
 #if HAVE_ZSTD_H && HAVE_LIBZSTD
-       return ZSTD_VERSION_STRING;
+#if ZSTD_VERSION_NUMBER > 10300
+       return ZSTD_versionString();
+#else
+       div_t major = div(ZSTD_versionNumber(), 10000);
+       div_t minor = div(major.rem, 100);
+       static char zstd_version[9];
+       snprintf(zstd_version, 9, "%d.%d.%d", major.quot, minor.quot, minor.rem);
+       return zstd_version;
+#endif
+#else
+       return NULL;
+#endif
+}
+
+const char *
+archive_liblzo2_version(void)
+{
+#if HAVE_LZO_LZOCONF_H && HAVE_LIBLZO2
+       return LZO_VERSION_STRING;
+#else
+       return NULL;
+#endif
+}
+
+const char *
+archive_libbsdxml_version(void)
+{
+#if HAVE_BSDXML_H && HAVE_LIBBSDXML
+       return XML_ExpatVersion();
+#else
+       return NULL;
+#endif
+}
+
+const char *
+archive_libxml2_version(void)
+{
+#if HAVE_LIBXML_XMLREADER_H && HAVE_LIBXML2
+       return LIBXML_DOTTED_VERSION;
+#else
+       return NULL;
+#endif
+}
+
+const char *
+archive_libexpat_version(void)
+{
+#if HAVE_EXPAT_H && HAVE_LIBEXPAT
+       return XML_ExpatVersion();
+#else
+       return NULL;
+#endif
+}
+
+const char *
+archive_mbedtls_version(void)
+{
+#if defined(ARCHIVE_CRYPTOR_USE_MBED) || defined(ARCHIVE_CRYPTO_MBED)
+       static char mbed_version[9];
+       mbedtls_version_get_string(mbed_version);
+       return mbed_version;
+#else
+       return NULL;
+#endif
+}
+
+const char *
+archive_nettle_version(void)
+{
+#if defined(ARCHIVE_CRYPTOR_USE_NETTLE) || defined(ARCHIVE_CRYPTO_NETTLE)
+       static char nettle_version[6];
+       snprintf(nettle_version, 6, "%d.%d", nettle_version_major(), nettle_version_minor());
+       return nettle_version;
+#else
+       return NULL;
+#endif
+}
+
+const char *
+archive_openssl_version(void)
+{
+#if defined(ARCHIVE_CRYPTOR_USE_OPENSSL) || defined(ARCHIVE_CRYPTO_OPENSSL)
+#ifdef OPENSSL_VERSION_STR
+       return OPENSSL_VERSION_STR;
+#else
+#define OPENSSL_MAJOR (OPENSSL_VERSION_NUMBER >> 28)
+#define OPENSSL_MINOR ((OPENSSL_VERSION_NUMBER >> 20) & 0xFF)
+       static char openssl_version[6];
+       snprintf(openssl_version, 6, "%ld.%ld", OPENSSL_MAJOR, OPENSSL_MINOR);
+       return openssl_version;
+#undef OPENSSL_MAJOR
+#undef OPENSSL_MINOR
+#endif
+#else
+       return NULL;
+#endif
+}
+
+const char *
+archive_libmd_version(void)
+{
+#if defined(ARCHIVE_CRYPTOR_USE_LIBMD) || defined(ARCHIVE_CRYPTO_LIBMD)
+       return "system";
+#else
+       return NULL;
+#endif
+}
+
+const char *
+archive_commoncrypto_version(void)
+{
+#if defined(ARCHIVE_CRYPTOR_USE_Apple_CommonCrypto) || defined(ARCHIVE_CRYPTO_CommonCrypto)
+       return "system";
+#else
+       return NULL;
+#endif
+}
+
+const char *
+archive_cng_version(void)
+{
+#if defined(ARCHIVE_CRYPTOR_USE_CNG) || defined(ARCHIVE_CRYPTO_CNG)
+#ifdef BCRYPT_HASH_INTERFACE_MAJORVERSION_2
+       return "2.0";
+#else
+       return "1.0";
+#endif
+#else
+       return NULL;
+#endif
+}
+
+const char *
+archive_wincrypt_version(void)
+{
+#if defined(ARCHIVE_CRYPTOR_USE_WINCRYPT) || defined(ARCHIVE_CRYPTO_WINCRYPT)
+       HCRYPTPROV prov;
+       if (!CryptAcquireContext(&prov, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) {
+               if (GetLastError() != (DWORD)NTE_BAD_KEYSET)
+                       return NULL;
+               if (!CryptAcquireContext(&prov, NULL, NULL, PROV_RSA_FULL, CRYPT_NEWKEYSET))
+                       return NULL;
+       }
+       DWORD length, version;
+       if (!CryptGetProvParam(prov, PP_VERSION, &version, &length, 0)) {
+               return NULL;
+       } else {
+               char major = version >> 8;
+               char minor = version & 0xFF
+               static char wincrypt_version[6];
+               snprintf(wincrypt_version, 6, "%hhd.%hhd", major, minor);
+               return wincrypt_version;
+       }
+#else
+       return NULL;
+#endif
+}
+
+const char *
+archive_librichacl_version(void)
+{
+#if HAVE_LIBRICHACL
+#if defined(LIBRICHACL_PKGCONFIG_VERSION)
+       return LIBRICHACL_PKGCONFIG_VERSION;
+#else
+       return "system";
+#endif
+#else
+       return NULL;
+#endif
+}
+
+const char *
+archive_libacl_version(void)
+{
+#if HAVE_LIBACL
+#if defined(LIBACL_PKGCONFIG_VERSION)
+       return LIBACL_PKGCONFIG_VERSION;
+#else
+       return "system";
+#endif
+#else
+       return NULL;
+#endif
+}
+
+const char *
+archive_libattr_version(void)
+{
+#if HAVE_LIBATTR
+#if defined(LIBATTR_PKGCONFIG_VERSION)
+       return LIBATTR_PKGCONFIG_VERSION;
+#else
+       return "system";
+#endif
+#else
+       return NULL;
+#endif
+}
+
+const char *
+archive_libiconv_version(void)
+{
+#if HAVE_LIBCHARSET && HAVE_ICONV_H
+       char major = _libiconv_version >> 8;
+       char minor = _libiconv_version & 0xFF
+       static char charset_version[6];
+       snprintf(charset_version, 6, "%hhd.%hhd", major, minor);
+       return charset_version;
+#else
+       return NULL;
+#endif
+}
+
+const char *
+archive_libpcre_version(void)
+{
+#if HAVE_LIBPCREPOSIX && HAVE_PCRE_H
+#define str(s) #s
+#define NUMBER(x) str(x)
+       return NUMBER(PCRE_MAJOR) "." NUMBER(PCRE_MINOR);
+#undef NUMBER
+#undef str
+#else
+       return NULL;
+#endif
+}
+
+const char *
+archive_libpcre2_version(void)
+{
+#if HAVE_LIBPCRE2POSIX && HAVE_PCRE2_H
+#define str(s) #s
+#define NUMBER(x) str(x)
+       return NUMBER(PCRE2_MAJOR) "." NUMBER(PCRE2_MINOR);
+#undef NUMBER
+#undef str
 #else
        return NULL;
 #endif