diff options
author | Chris Rees <crees@FreeBSD.org> | 2014-07-30 18:21:47 +0000 |
---|---|---|
committer | Chris Rees <crees@FreeBSD.org> | 2014-07-30 18:21:47 +0000 |
commit | 421b8a5f6eb19e46c05ad3aa2b47126dea7afea4 (patch) | |
tree | 82765e74dba0aec7a2d3f138c10c28b2f3adf994 /databases/postgresql84-server/files | |
parent | 89cdfc8da20209fe1a3b5aff32d6bb58341545a3 (diff) |
Notes
Diffstat (limited to 'databases/postgresql84-server/files')
-rw-r--r-- | databases/postgresql84-server/files/patch-contrib-uuid | 184 |
1 files changed, 94 insertions, 90 deletions
diff --git a/databases/postgresql84-server/files/patch-contrib-uuid b/databases/postgresql84-server/files/patch-contrib-uuid index 832076fd6dc7..614ec67bcd88 100644 --- a/databases/postgresql84-server/files/patch-contrib-uuid +++ b/databases/postgresql84-server/files/patch-contrib-uuid @@ -10,11 +10,21 @@ ifdef USE_PGXS PG_CONFIG = pg_config PGXS := $(shell $(PG_CONFIG) --pgxs) ---- contrib/uuid-ossp/uuid-ossp.c.orig 2014-03-17 20:38:14.000000000 +0100 -+++ contrib/uuid-ossp/uuid-ossp.c 2014-03-19 23:01:59.000000000 +0100 +--- contrib/Makefile.orig 2014-03-21 09:09:12.000000000 +0100 ++++ contrib/Makefile 2014-03-21 09:09:28.000000000 +0100 +@@ -39,6 +39,7 @@ + tablefunc \ + test_parser \ + tsearch2 \ ++ uuid-ossp \ + vacuumlo + + ifeq ($(with_openssl),yes) +--- contrib/uuid-ossp/uuid-ossp.c.orig 2014-07-21 20:18:03.000000000 +0100 ++++ contrib/uuid-ossp/uuid-ossp.c 2014-07-30 17:35:22.872934812 +0100 @@ -6,6 +6,10 @@ * - * $PostgreSQL: pgsql/contrib/uuid-ossp/uuid-ossp.c,v 1.12 2010/01/02 16:57:33 momjian Exp $ + * $PostgreSQL: pgsql/contrib/uuid-ossp/uuid-ossp.c,v 1.11 2009/06/11 14:48:53 momjian Exp $ * + * Modified to use FreeBSD's built in uuid instead of ossp: + * Copyright (c) 2009 Andrew Gierth @@ -58,7 +68,7 @@ PG_MODULE_MAGIC; -@@ -64,163 +55,175 @@ +@@ -64,177 +55,175 @@ PG_FUNCTION_INFO_V1(uuid_generate_v4); PG_FUNCTION_INFO_V1(uuid_generate_v5); @@ -81,41 +91,45 @@ + * that pg's internal storage of uuids is the simple byte-oriented + * binary format. */ --static char * --uuid_to_string(const uuid_t *uuid) --{ -- char *buf = palloc(UUID_LEN_STR + 1); -- void *ptr = buf; -- size_t len = UUID_LEN_STR + 1; -- uuid_rc_t rc; -- -- rc = uuid_export(uuid, UUID_FMT_STR, &ptr, &len); -- if (rc != UUID_RC_OK) -- pguuid_complain(rc); -- -- return buf; --} -- -- --static void --string_to_uuid(const char *str, uuid_t *uuid) +-/* +- * We create a uuid_t object just once per session and re-use it for all +- * operations in this module. OSSP UUID caches the system MAC address and +- * other state in this object. Reusing the object has a number of benefits: +- * saving the cycles needed to fetch the system MAC address over and over, +- * reducing the amount of entropy we draw from /dev/urandom, and providing a +- * positive guarantee that successive generated V1-style UUIDs don't collide. +- * (On a machine fast enough to generate multiple UUIDs per microsecond, +- * or whatever the system's wall-clock resolution is, we'd otherwise risk +- * collisions whenever random initialization of the uuid_t's clock sequence +- * value chanced to produce duplicates.) +- * +- * However: when we're doing V3 or V5 UUID creation, uuid_make needs two +- * uuid_t objects, one holding the namespace UUID and one for the result. +- * It's unspecified whether it's safe to use the same uuid_t for both cases, +- * so let's cache a second uuid_t for use as the namespace holder object. +- */ +-static uuid_t * +-get_cached_uuid_t(int which) +static Datum +internal_uuid_create(int v, unsigned char *ns, char *ptr, int len) { -- uuid_rc_t rc; -- -- rc = uuid_import(uuid, UUID_FMT_STR, str, UUID_LEN_STR + 1); -- if (rc != UUID_RC_OK) -- pguuid_complain(rc); --} +- static uuid_t *cached_uuid[2] = {NULL, NULL}; + char strbuf[40]; +- if (cached_uuid[which] == NULL) + switch (v) -+ { + { +- uuid_rc_t rc; + case 0: /* constant-value uuids: nil, or namespace uuids */ + strlcpy(strbuf, ptr, 37); + break; -+ + +- rc = uuid_create(&cached_uuid[which]); +- if (rc != UUID_RC_OK) +- { +- cached_uuid[which] = NULL; +- pguuid_complain(rc); +- } + case 4: default: /* random uuid */ + { + sprintf(strbuf, "%08lx-%04x-%04x-%04x-%04x%08lx", @@ -126,23 +140,37 @@ + (unsigned) (arc4random() & 0xffff), + (unsigned long) arc4random()); + break; -+ } + } +- return cached_uuid[which]; +-} + + case 1: /* time/node-based uuids */ + { + uuid_t uu; + uint32_t status = uuid_s_ok; + char *str = NULL; -+ + +-static char * +-uuid_to_string(const uuid_t *uuid) +-{ +- char *buf = palloc(UUID_LEN_STR + 1); +- void *ptr = buf; +- size_t len = UUID_LEN_STR + 1; +- uuid_rc_t rc; + uuid_create(&uu, &status); -+ + +- rc = uuid_export(uuid, UUID_FMT_STR, &ptr, &len); +- if (rc != UUID_RC_OK) +- pguuid_complain(rc); + if (status == uuid_s_ok) + { + uuid_to_string(&uu, &str, &status); + if (status == uuid_s_ok) + { + strlcpy(strbuf, str, 37); -+ + +- return buf; +-} + /* PTR, if set, replaces the trailing characters of the uuid; + * this is to support v1mc, where a random multicast MAC is + * used instead of the physical one @@ -155,23 +183,6 @@ + free(str); + } --static Datum --special_uuid_value(const char *name) --{ -- uuid_t *uuid; -- char *str; -- uuid_rc_t rc; -- -- rc = uuid_create(&uuid); -- if (rc != UUID_RC_OK) -- pguuid_complain(rc); -- rc = uuid_load(uuid, name); -- if (rc != UUID_RC_OK) -- pguuid_complain(rc); -- str = uuid_to_string(uuid); -- rc = uuid_destroy(uuid); -- if (rc != UUID_RC_OK) -- pguuid_complain(rc); + if (status != uuid_s_ok) + { + ereport(ERROR, @@ -181,7 +192,11 @@ + + break; + } -+ + +-static void +-string_to_uuid(const char *str, uuid_t *uuid) +-{ +- uuid_rc_t rc; + case 3: /* namespace-based MD5 uuids */ + { + /* we could use pg's md5(), but we're already pulling in libmd */ @@ -201,7 +216,11 @@ + buf[4], buf[5], ((buf[6] & 0xf) | 0x30), buf[7], + ((buf[8] & 0x3F) | 0x80), buf[9], buf[10], buf[11], + buf[12], buf[13], buf[14], buf[15]); -+ + +- rc = uuid_import(uuid, UUID_FMT_STR, str, UUID_LEN_STR + 1); +- if (rc != UUID_RC_OK) +- pguuid_complain(rc); +-} + break; + } + @@ -209,7 +228,7 @@ + { + SHA_CTX ctx; + unsigned char buf[20]; -+ + + SHA1_Init(&ctx); + SHA1_Update(&ctx, ns, 16); + SHA1_Update(&ctx, (unsigned char *)ptr, len); @@ -223,7 +242,18 @@ + buf[4], buf[5], ((buf[6] & 0xf) | 0x30), buf[7], + ((buf[8] & 0x3F) | 0x80), buf[9], buf[10], buf[11], + buf[12], buf[13], buf[14], buf[15]); -+ + +-static Datum +-special_uuid_value(const char *name) +-{ +- uuid_t *uuid = get_cached_uuid_t(0); +- char *str; +- uuid_rc_t rc; +- +- rc = uuid_load(uuid, name); +- if (rc != UUID_RC_OK) +- pguuid_complain(rc); +- str = uuid_to_string(uuid); + break; + } + } @@ -275,20 +305,14 @@ -static Datum -uuid_generate_internal(int mode, const uuid_t *ns, const char *name) -{ -- uuid_t *uuid; +- uuid_t *uuid = get_cached_uuid_t(0); - char *str; - uuid_rc_t rc; - -- rc = uuid_create(&uuid); -- if (rc != UUID_RC_OK) -- pguuid_complain(rc); - rc = uuid_make(uuid, mode, ns, name); - if (rc != UUID_RC_OK) - pguuid_complain(rc); - str = uuid_to_string(uuid); -- rc = uuid_destroy(uuid); -- if (rc != UUID_RC_OK) -- pguuid_complain(rc); - - return DirectFunctionCall1(uuid_in, CStringGetDatum(str)); + return internal_uuid_create(0, NULL, "6ba7b814-9dad-11d1-80b4-00c04fd430c8", 36); @@ -313,26 +337,16 @@ -static Datum -uuid_generate_v35_internal(int mode, pg_uuid_t *ns, text *name) -{ -- uuid_t *ns_uuid; -- Datum result; -- uuid_rc_t rc; +- uuid_t *ns_uuid = get_cached_uuid_t(1); - -- rc = uuid_create(&ns_uuid); -- if (rc != UUID_RC_OK) -- pguuid_complain(rc); -- string_to_uuid(DatumGetCString(DirectFunctionCall1(uuid_out, UUIDPGetDatum(ns))), +- string_to_uuid(DatumGetCString(DirectFunctionCall1(uuid_out, +- UUIDPGetDatum(ns))), - ns_uuid); -- -- result = uuid_generate_internal(mode, -- ns_uuid, -- text_to_cstring(name)); -- -- rc = uuid_destroy(ns_uuid); -- if (rc != UUID_RC_OK) -- pguuid_complain(rc); + char buf[20]; -- return result; +- return uuid_generate_internal(mode, +- ns_uuid, +- text_to_cstring(name)); + sprintf(buf, "-%04x-%04x%08lx", + (unsigned)((arc4random() & 0x3FFF) | 0x8000), + /* set IEEE802 multicast and local-admin bits */ @@ -343,7 +357,7 @@ } -@@ -230,14 +233,15 @@ +@@ -244,14 +233,15 @@ pg_uuid_t *ns = PG_GETARG_UUID_P(0); text *name = PG_GETARG_TEXT_P(1); @@ -361,7 +375,7 @@ } -@@ -247,5 +251,6 @@ +@@ -261,5 +251,6 @@ pg_uuid_t *ns = PG_GETARG_UUID_P(0); text *name = PG_GETARG_TEXT_P(1); @@ -369,13 +383,3 @@ + return internal_uuid_create(5, (unsigned char *)ns, + VARDATA(name), VARSIZE(name) - VARHDRSZ); } ---- contrib/Makefile.orig 2014-03-21 09:09:12.000000000 +0100 -+++ contrib/Makefile 2014-03-21 09:09:28.000000000 +0100 -@@ -39,6 +39,7 @@ - tablefunc \ - test_parser \ - tsearch2 \ -+ uuid-ossp \ - vacuumlo - - ifeq ($(with_openssl),yes) |