s3:profile: Use GnuTLS MD5
authorAndreas Schneider <asn@samba.org>
Mon, 5 Nov 2018 17:03:51 +0000 (18:03 +0100)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 21 May 2019 00:03:22 +0000 (00:03 +0000)
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source3/profile/profile.c

index 5e7b69d25d6ea0139eba7a0e5f9af36890fbd0ef..df0ba5b0af3f700fab3779cb0324bacd08416f59 100644 (file)
@@ -33,6 +33,9 @@
 #include <sys/resource.h>
 #endif
 
+#include <gnutls/gnutls.h>
+#include <gnutls/crypto.h>
+
 struct profile_stats *profile_p;
 struct smbprofile_global_state smbprofile_state;
 
@@ -122,8 +125,10 @@ static void reqprofile_message(struct messaging_context *msg_ctx,
 bool profile_setup(struct messaging_context *msg_ctx, bool rdonly)
 {
        unsigned char tmp[16] = {};
-       MD5_CTX md5;
+       gnutls_hash_hd_t hash_hnd = NULL;
        char *db_name;
+       bool ok = false;
+       int rc;
 
        if (smbprofile_state.internal.db != NULL) {
                return true;
@@ -149,14 +154,16 @@ bool profile_setup(struct messaging_context *msg_ctx, bool rdonly)
                                   reqprofile_message);
        }
 
-       MD5Init(&md5);
-
-       MD5Update(&md5,
-                 (const uint8_t *)&smbprofile_state.stats.global,
-                 sizeof(smbprofile_state.stats.global));
+       rc = gnutls_hash_init(&hash_hnd, GNUTLS_DIG_MD5);
+       if (rc < 0) {
+               goto out;
+       }
+       rc = gnutls_hash(hash_hnd,
+                        &smbprofile_state.stats.global,
+                        sizeof(smbprofile_state.stats.global));
 
 #define __UPDATE(str) do { \
-       MD5Update(&md5, (const uint8_t *)str, strlen(str)); \
+       rc |= gnutls_hash(hash_hnd, str, strlen(str)); \
 } while(0)
 #define SMBPROFILE_STATS_START
 #define SMBPROFILE_STATS_SECTION_START(name, display) do { \
@@ -198,8 +205,12 @@ bool profile_setup(struct messaging_context *msg_ctx, bool rdonly)
 #undef SMBPROFILE_STATS_IOBYTES
 #undef SMBPROFILE_STATS_SECTION_END
 #undef SMBPROFILE_STATS_END
+       if (rc != 0) {
+               gnutls_hash_deinit(hash_hnd, NULL);
+               goto out;
+       }
 
-       MD5Final(tmp, &md5);
+       gnutls_hash_deinit(hash_hnd, tmp);
 
        profile_p = &smbprofile_state.stats.global;
 
@@ -207,8 +218,11 @@ bool profile_setup(struct messaging_context *msg_ctx, bool rdonly)
        if (profile_p->magic == 0) {
                profile_p->magic = BVAL(tmp, 8);
        }
+       ZERO_ARRAY(tmp);
 
-       return True;
+       ok = true;
+out:
+       return ok;
 }
 
 void smbprofile_dump_setup(struct tevent_context *ev)