Commit 525e60b7 authored by Michael Paquier's avatar Michael Paquier

Fix compilation of uuid-ossp

This module had a dependency on pgcrypto's md5.c that got removed by
b67b57a9.  Instead of the code from pgcrypto, this code can just use the
new cryptohash routines for MD5 as a drop-in replacement, so let's just
do this switch.  This has also the merit to simplify a bit the
compilation of uuid-ossp.

This requires --with-uuid to be reproduced, and I have used e2fs as a
way to reproduce the failure, then test this commit.

Per reports from buildfarm members longfin, florican and sifaka.

Discussion: https://postgr.es/m/X9GToVd3QmWeNvj8@paquier.xyz
parent b67b57a9
...@@ -8307,12 +8307,12 @@ if test "$with_uuid" = bsd ; then ...@@ -8307,12 +8307,12 @@ if test "$with_uuid" = bsd ; then
$as_echo "#define HAVE_UUID_BSD 1" >>confdefs.h $as_echo "#define HAVE_UUID_BSD 1" >>confdefs.h
UUID_EXTRA_OBJS="md5.o sha1.o" UUID_EXTRA_OBJS="sha1.o"
elif test "$with_uuid" = e2fs ; then elif test "$with_uuid" = e2fs ; then
$as_echo "#define HAVE_UUID_E2FS 1" >>confdefs.h $as_echo "#define HAVE_UUID_E2FS 1" >>confdefs.h
UUID_EXTRA_OBJS="md5.o sha1.o" UUID_EXTRA_OBJS="sha1.o"
elif test "$with_uuid" = ossp ; then elif test "$with_uuid" = ossp ; then
$as_echo "#define HAVE_UUID_OSSP 1" >>confdefs.h $as_echo "#define HAVE_UUID_OSSP 1" >>confdefs.h
......
...@@ -921,10 +921,10 @@ fi ...@@ -921,10 +921,10 @@ fi
if test "$with_uuid" = bsd ; then if test "$with_uuid" = bsd ; then
AC_DEFINE([HAVE_UUID_BSD], 1, [Define to 1 if you have BSD UUID support.]) AC_DEFINE([HAVE_UUID_BSD], 1, [Define to 1 if you have BSD UUID support.])
UUID_EXTRA_OBJS="md5.o sha1.o" UUID_EXTRA_OBJS="sha1.o"
elif test "$with_uuid" = e2fs ; then elif test "$with_uuid" = e2fs ; then
AC_DEFINE([HAVE_UUID_E2FS], 1, [Define to 1 if you have E2FS UUID support.]) AC_DEFINE([HAVE_UUID_E2FS], 1, [Define to 1 if you have E2FS UUID support.])
UUID_EXTRA_OBJS="md5.o sha1.o" UUID_EXTRA_OBJS="sha1.o"
elif test "$with_uuid" = ossp ; then elif test "$with_uuid" = ossp ; then
AC_DEFINE([HAVE_UUID_OSSP], 1, [Define to 1 if you have OSSP UUID support.]) AC_DEFINE([HAVE_UUID_OSSP], 1, [Define to 1 if you have OSSP UUID support.])
UUID_EXTRA_OBJS="" UUID_EXTRA_OBJS=""
......
...@@ -19,7 +19,7 @@ pgcrypto_src = $(top_srcdir)/contrib/pgcrypto ...@@ -19,7 +19,7 @@ pgcrypto_src = $(top_srcdir)/contrib/pgcrypto
PG_CPPFLAGS = -I$(pgcrypto_src) PG_CPPFLAGS = -I$(pgcrypto_src)
EXTRA_CLEAN = md5.c sha1.c EXTRA_CLEAN = sha1.c
ifdef USE_PGXS ifdef USE_PGXS
PG_CONFIG = pg_config PG_CONFIG = pg_config
...@@ -32,5 +32,5 @@ include $(top_builddir)/src/Makefile.global ...@@ -32,5 +32,5 @@ include $(top_builddir)/src/Makefile.global
include $(top_srcdir)/contrib/contrib-global.mk include $(top_srcdir)/contrib/contrib-global.mk
endif endif
md5.c sha1.c: % : $(pgcrypto_src)/% sha1.c: % : $(pgcrypto_src)/%
rm -f $@ && $(LN_S) $< . rm -f $@ && $(LN_S) $< .
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "postgres.h" #include "postgres.h"
#include "fmgr.h" #include "fmgr.h"
#include "common/cryptohash.h"
#include "port/pg_bswap.h" #include "port/pg_bswap.h"
#include "utils/builtins.h" #include "utils/builtins.h"
#include "utils/uuid.h" #include "utils/uuid.h"
...@@ -44,7 +45,6 @@ ...@@ -44,7 +45,6 @@
* so we use a copy of the ones from pgcrypto. Not needed with OSSP, though. * so we use a copy of the ones from pgcrypto. Not needed with OSSP, though.
*/ */
#ifndef HAVE_UUID_OSSP #ifndef HAVE_UUID_OSSP
#include "md5.h"
#include "sha1.h" #include "sha1.h"
#endif #endif
...@@ -324,13 +324,17 @@ uuid_generate_internal(int v, unsigned char *ns, const char *ptr, int len) ...@@ -324,13 +324,17 @@ uuid_generate_internal(int v, unsigned char *ns, const char *ptr, int len)
if (v == 3) if (v == 3)
{ {
MD5_CTX ctx; pg_cryptohash_ctx *ctx = pg_cryptohash_create(PG_MD5);
MD5Init(&ctx); if (pg_cryptohash_init(ctx) < 0)
MD5Update(&ctx, ns, sizeof(uu)); elog(ERROR, "could not initialize %s context", "MD5");
MD5Update(&ctx, (unsigned char *) ptr, len); if (pg_cryptohash_update(ctx, ns, sizeof(uu)) < 0 ||
pg_cryptohash_update(ctx, (unsigned char *) ptr, len) < 0)
elog(ERROR, "could not update %s context", "MD5");
/* we assume sizeof MD5 result is 16, same as UUID size */ /* we assume sizeof MD5 result is 16, same as UUID size */
MD5Final((unsigned char *) &uu, &ctx); if (pg_cryptohash_final(ctx, (unsigned char *) &uu) < 0)
elog(ERROR, "could not finalize %s context", "MD5");
pg_cryptohash_free(ctx);
} }
else else
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment