]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
Extend fipshmac to take a path to libgnutls.so
authorZoltan Fridrich <zfridric@redhat.com>
Thu, 5 May 2022 10:10:46 +0000 (12:10 +0200)
committerZoltan Fridrich <zfridric@redhat.com>
Thu, 5 May 2022 10:13:06 +0000 (12:13 +0200)
Signed-off-by: Zoltan Fridrich <zfridric@redhat.com>
bootstrap.conf
lib/Makefile.am
lib/fipshmac.c

index d922baeae36625a3ab32e3ba0672055e0c395864..9f6ffd8880ce0fb2f82310124ed77c619cf7f530 100644 (file)
@@ -30,7 +30,7 @@ common_modules="
 alloca attribute byteswap c-ctype c-strcase explicit_bzero fopen-gnu func getline gettext-h gettimeofday hash hash-pjw-bare arpa_inet inet_ntop inet_pton intprops lock memmem-simple minmax netdb netinet_in read-file secure_getenv setsockopt snprintf stdint stpcpy strcase strdup-posix strndup strtok_r strverscmp sys_socket sys_stat sys_types threadlib time_r unistd valgrind-tests vasprintf verify vsnprintf xalloc-oversized
 "
 gnulib_modules="
-$common_modules extensions gendocs havelib ldd lib-msvc-compat lib-symbol-versions maintainer-makefile manywarnings pmccabe2html warnings
+$common_modules dirname-lgpl extensions gendocs havelib ldd lib-msvc-compat lib-symbol-versions maintainer-makefile manywarnings pmccabe2html warnings
 "
 
 unistring_modules="
index 4354cc53dd194896f394681f2362f46c9449ed55..0b43ef9ce0be2dacaf52ed198d3a7f981eae8f81 100644 (file)
@@ -200,7 +200,7 @@ thirdparty_libadd += $(FIPS140_LIBS) $(LTLIBDL)
 
 noinst_PROGRAMS = fipshmac
 fipshmac_SOURCES = fipshmac.c
-fipshmac_LDADD = libgnutls.la
+fipshmac_LDADD = libgnutls.la ../gl/libgnu.la
 
 hmac_files = .libs/.gnutls.hmac
 
index 91ee1d6579b9581417f6a0d2d53b4947988965cb..b091572bdf063d3a50ffb0fe82147f10e01c5644 100644 (file)
@@ -28,6 +28,7 @@
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include "dirname.h"
 #include "errors.h"
 
 #define FORMAT_VERSION 1
@@ -98,45 +99,69 @@ static int get_hmac(const char *path, char *hmac, size_t hmac_size)
        return 0;
 }
 
-static int print_lib(const char *lib, const char *sym)
+static int print_lib_path(const char *path)
 {
        int ret;
-       char path[GNUTLS_PATH_MAX];
        char hmac[HMAC_STR_SIZE];
 
-       ret = get_path(lib, sym, path, sizeof(path));
-       if (ret < 0) {
-               fprintf(stderr, "Could not get lib path for %s: %s\n",
-                        lib, gnutls_strerror(ret));
-               return ret;
-       }
-
        ret = get_hmac(path, hmac, sizeof(hmac));
        if (ret < 0) {
                fprintf(stderr, "Could not calculate HMAC for %s: %s\n",
-                        lib, gnutls_strerror(ret));
+                        last_component(path), gnutls_strerror(ret));
                return ret;
        }
 
-       printf("[%s]\n", lib);
+       printf("[%s]\n", last_component(path));
        printf("path = %s\n", path);
        printf("hmac = %s\n", hmac);
 
        return 0;
 }
 
-int main(void)
+static int print_lib_dl(const char *lib, const char *sym)
+{
+       int ret;
+       char path[GNUTLS_PATH_MAX];
+
+       ret = get_path(lib, sym, path, sizeof(path));
+       if (ret < 0) {
+               fprintf(stderr, "Could not get lib path for %s: %s\n",
+                        lib, gnutls_strerror(ret));
+               return ret;
+       }
+
+       return print_lib_path(path);
+}
+
+int main(int argc, char **argv)
 {
+       int ret;
+
+       if (argc != 1 && argc != 2) {
+               fprintf(stderr, "Usage: %s [gnutls_so_path]\n", last_component(argv[0]));
+               return EXIT_FAILURE;
+       }
+
        printf("[global]\n");
        printf("format-version = %d\n", FORMAT_VERSION);
 
-       if (print_lib(GNUTLS_LIBRARY_SONAME, "gnutls_global_init") < 0)
+       if (argc == 2)
+               ret = print_lib_path(argv[1]);
+       else
+               ret = print_lib_dl(GNUTLS_LIBRARY_SONAME, "gnutls_global_init");
+       if (ret < 0)
                return EXIT_FAILURE;
-       if (print_lib(NETTLE_LIBRARY_SONAME, "nettle_aes_set_encrypt_key") < 0)
+
+       ret = print_lib_dl(NETTLE_LIBRARY_SONAME, "nettle_aes_set_encrypt_key");
+       if (ret < 0)
                return EXIT_FAILURE;
-       if (print_lib(HOGWEED_LIBRARY_SONAME, "nettle_mpz_sizeinbase_256_u") < 0)
+       
+       ret = print_lib_dl(HOGWEED_LIBRARY_SONAME, "nettle_mpz_sizeinbase_256_u");
+       if (ret < 0)
                return EXIT_FAILURE;
-       if (print_lib(GMP_LIBRARY_SONAME, "__gmpz_init") < 0)
+       
+       ret = print_lib_dl(GMP_LIBRARY_SONAME, "__gmpz_init");
+       if (ret < 0)
                return EXIT_FAILURE;
 
        return EXIT_SUCCESS;