From d8d1d65958fd00514aff92d9d2240b8ff89583fb Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Mon, 12 Aug 2002 13:48:19 +0000 Subject: Code to generate uuids for ADS setups. Uses our random generator but conforms to standard OSF/DCE uuid format. (This used to be commit 3b50c3b8cd86ff9a12a6e22ca3b3e904671be547) --- source3/lib/util_uuid.c | 108 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 source3/lib/util_uuid.c (limited to 'source3/lib/util_uuid.c') diff --git a/source3/lib/util_uuid.c b/source3/lib/util_uuid.c new file mode 100644 index 0000000000..b70db8de5b --- /dev/null +++ b/source3/lib/util_uuid.c @@ -0,0 +1,108 @@ +/* + * Unix SMB/CIFS implementation. + * UUID server routines + * Copyright (C) Theodore Ts'o 1996, 1997, + * Copyright (C) Jim McDonough 2002. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include "includes.h" + +/* + * Offset between 15-Oct-1582 and 1-Jan-70 + */ +#define TIME_OFFSET_HIGH 0x01B21DD2 +#define TIME_OFFSET_LOW 0x13814000 + +struct uuid { + uint32 time_low; + uint16 time_mid; + uint16 time_hi_and_version; + uint16 clock_seq; + uint8 node[6]; +}; + + +static void uuid_pack(const struct uuid *uu, GUID *ptr) +{ + uint32 tmp; + uint8 *out = ptr->info; + + tmp = uu->time_low; + out[3] = (uint8) tmp; + tmp >>= 8; + out[2] = (uint8) tmp; + tmp >>= 8; + out[1] = (uint8) tmp; + tmp >>= 8; + out[0] = (uint8) tmp; + + tmp = uu->time_mid; + out[5] = (uint8) tmp; + tmp >>= 8; + out[4] = (uint8) tmp; + + tmp = uu->time_hi_and_version; + out[7] = (uint8) tmp; + tmp >>= 8; + out[6] = (uint8) tmp; + + tmp = uu->clock_seq; + out[9] = (uint8) tmp; + tmp >>= 8; + out[8] = (uint8) tmp; + + memcpy(out+10, uu->node, 6); +} + +static void uuid_unpack(const GUID in, struct uuid *uu) +{ + const uint8 *ptr = in.info; + uint32 tmp; + + tmp = *ptr++; + tmp = (tmp << 8) | *ptr++; + tmp = (tmp << 8) | *ptr++; + tmp = (tmp << 8) | *ptr++; + uu->time_low = tmp; + + tmp = *ptr++; + tmp = (tmp << 8) | *ptr++; + uu->time_mid = tmp; + + tmp = *ptr++; + tmp = (tmp << 8) | *ptr++; + uu->time_hi_and_version = tmp; + + tmp = *ptr++; + tmp = (tmp << 8) | *ptr++; + uu->clock_seq = tmp; + + memcpy(uu->node, ptr, 6); +} + +void uuid_generate_random(GUID *out) +{ + GUID tmp; + struct uuid uu; + + generate_random_buffer(tmp.info, sizeof(tmp.info), True); + uuid_unpack(tmp, &uu); + + uu.clock_seq = (uu.clock_seq & 0x3FFF) | 0x8000; + uu.time_hi_and_version = (uu.time_hi_and_version & 0x0FFF) | 0x4000; + uuid_pack(&uu, out); +} -- cgit From f3a15363d82b5b6204948ef623ad87c855dd5f57 Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Mon, 12 Aug 2002 16:39:10 +0000 Subject: Use byteorder.h macros (This used to be commit eb9004efc3580799063009a8298c35cbc420626f) --- source3/lib/util_uuid.c | 54 +++++++++---------------------------------------- 1 file changed, 9 insertions(+), 45 deletions(-) (limited to 'source3/lib/util_uuid.c') diff --git a/source3/lib/util_uuid.c b/source3/lib/util_uuid.c index b70db8de5b..63e2504982 100644 --- a/source3/lib/util_uuid.c +++ b/source3/lib/util_uuid.c @@ -38,60 +38,24 @@ struct uuid { static void uuid_pack(const struct uuid *uu, GUID *ptr) { - uint32 tmp; uint8 *out = ptr->info; - tmp = uu->time_low; - out[3] = (uint8) tmp; - tmp >>= 8; - out[2] = (uint8) tmp; - tmp >>= 8; - out[1] = (uint8) tmp; - tmp >>= 8; - out[0] = (uint8) tmp; - - tmp = uu->time_mid; - out[5] = (uint8) tmp; - tmp >>= 8; - out[4] = (uint8) tmp; - - tmp = uu->time_hi_and_version; - out[7] = (uint8) tmp; - tmp >>= 8; - out[6] = (uint8) tmp; - - tmp = uu->clock_seq; - out[9] = (uint8) tmp; - tmp >>= 8; - out[8] = (uint8) tmp; - + SIVAL(out, 0, uu->time_low); + SSVAL(out, 4, uu->time_mid); + SSVAL(out, 6, uu->time_hi_and_version); + SSVAL(out, 8, uu->clock_seq); memcpy(out+10, uu->node, 6); } static void uuid_unpack(const GUID in, struct uuid *uu) { const uint8 *ptr = in.info; - uint32 tmp; - - tmp = *ptr++; - tmp = (tmp << 8) | *ptr++; - tmp = (tmp << 8) | *ptr++; - tmp = (tmp << 8) | *ptr++; - uu->time_low = tmp; - - tmp = *ptr++; - tmp = (tmp << 8) | *ptr++; - uu->time_mid = tmp; - - tmp = *ptr++; - tmp = (tmp << 8) | *ptr++; - uu->time_hi_and_version = tmp; - - tmp = *ptr++; - tmp = (tmp << 8) | *ptr++; - uu->clock_seq = tmp; - memcpy(uu->node, ptr, 6); + uu->time_low = IVAL(ptr, 0); + uu->time_mid = SVAL(ptr, 4); + uu->time_hi_and_version = SVAL(ptr, 6); + uu->clock_seq = SVAL(ptr, 8); + memcpy(uu->node, ptr+10, 6); } void uuid_generate_random(GUID *out) -- cgit From e5fda27b09ed7f550ecbc9a9b3cae9d0f21e1d52 Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Tue, 29 Oct 2002 14:45:41 +0000 Subject: Move guid formatting functions over from HEAD. (This used to be commit 60b9e352b3c0769d0d3fe3067399bb3441f29502) --- source3/lib/util_uuid.c | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) (limited to 'source3/lib/util_uuid.c') diff --git a/source3/lib/util_uuid.c b/source3/lib/util_uuid.c index 63e2504982..1543094d40 100644 --- a/source3/lib/util_uuid.c +++ b/source3/lib/util_uuid.c @@ -31,7 +31,7 @@ struct uuid { uint32 time_low; uint16 time_mid; uint16 time_hi_and_version; - uint16 clock_seq; + uint8 clock_seq[2]; uint8 node[6]; }; @@ -43,7 +43,7 @@ static void uuid_pack(const struct uuid *uu, GUID *ptr) SIVAL(out, 0, uu->time_low); SSVAL(out, 4, uu->time_mid); SSVAL(out, 6, uu->time_hi_and_version); - SSVAL(out, 8, uu->clock_seq); + memcpy(out+8, uu->clock_seq, 2); memcpy(out+10, uu->node, 6); } @@ -54,7 +54,7 @@ static void uuid_unpack(const GUID in, struct uuid *uu) uu->time_low = IVAL(ptr, 0); uu->time_mid = SVAL(ptr, 4); uu->time_hi_and_version = SVAL(ptr, 6); - uu->clock_seq = SVAL(ptr, 8); + memcpy(uu->clock_seq, ptr+8, 2); memcpy(uu->node, ptr+10, 6); } @@ -66,7 +66,38 @@ void uuid_generate_random(GUID *out) generate_random_buffer(tmp.info, sizeof(tmp.info), True); uuid_unpack(tmp, &uu); - uu.clock_seq = (uu.clock_seq & 0x3FFF) | 0x8000; + uu.clock_seq[0] = (uu.clock_seq[0] & 0x3F) | 0x80; uu.time_hi_and_version = (uu.time_hi_and_version & 0x0FFF) | 0x4000; uuid_pack(&uu, out); } + +char *uuid_to_string(const GUID in) +{ + struct uuid uu; + char *out; + + uuid_unpack(in, &uu); + + asprintf(&out, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", + uu.time_low, uu.time_mid, uu.time_hi_and_version, + uu.clock_seq[0], uu.clock_seq[1], + uu.node[0], uu.node[1], uu.node[2], + uu.node[3], uu.node[4], uu.node[5]); + + return out; +} + +const char *uuid_string_static(const GUID in) +{ + struct uuid uu; + static char out[37]; + + uuid_unpack(in, &uu); + slprintf(out, sizeof(out) -1, + "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", + uu.time_low, uu.time_mid, uu.time_hi_and_version, + uu.clock_seq[0], uu.clock_seq[1], + uu.node[0], uu.node[1], uu.node[2], + uu.node[3], uu.node[4], uu.node[5]); + return out; +} -- cgit From f3e3a56ea9085b186af24b0b4e911863fd9ceacc Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 29 Nov 2002 02:58:59 +0000 Subject: Merge a bunch of trivial changes from HEAD. The difference remaining should actual functional differences between HEAD and 3.0. - Mostly reformatting - Removal of unecessary #include "smb.h" - Merge of dyn_DRIVERFILE removal - Silly bug fix for python code (This used to be commit d3998307adc50ba50defe610cb656c73799ae3b9) --- source3/lib/util_uuid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/util_uuid.c') diff --git a/source3/lib/util_uuid.c b/source3/lib/util_uuid.c index 1543094d40..699f2cd632 100644 --- a/source3/lib/util_uuid.c +++ b/source3/lib/util_uuid.c @@ -71,7 +71,7 @@ void uuid_generate_random(GUID *out) uuid_pack(&uu, out); } -char *uuid_to_string(const GUID in) +char *guid_to_string(const GUID in) { struct uuid uu; char *out; -- cgit From 0a9396dcca1e30fa32fbcde3ee2dce86f586ba4b Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 13 Jun 2003 04:35:53 +0000 Subject: Rename some uuid functions so as not to conflict with system versions. Fixes bug #154. (This used to be commit 986eae40f7669d15dc75aed340e628aa7efafddc) --- source3/lib/util_uuid.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/lib/util_uuid.c') diff --git a/source3/lib/util_uuid.c b/source3/lib/util_uuid.c index 699f2cd632..83553ec28e 100644 --- a/source3/lib/util_uuid.c +++ b/source3/lib/util_uuid.c @@ -58,7 +58,7 @@ static void uuid_unpack(const GUID in, struct uuid *uu) memcpy(uu->node, ptr+10, 6); } -void uuid_generate_random(GUID *out) +void smb_uuid_generate_random(GUID *out) { GUID tmp; struct uuid uu; @@ -71,7 +71,7 @@ void uuid_generate_random(GUID *out) uuid_pack(&uu, out); } -char *guid_to_string(const GUID in) +char *smb_uuid_to_string(const GUID in) { struct uuid uu; char *out; @@ -87,7 +87,7 @@ char *guid_to_string(const GUID in) return out; } -const char *uuid_string_static(const GUID in) +const char *smb_uuid_string_static(const GUID in) { struct uuid uu; static char out[37]; -- cgit From 9f2e6167d22cc06fa94495574fc29d6bcbb1dd8a Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Fri, 1 Aug 2003 15:21:20 +0000 Subject: Update my copyrights according to my agreement with IBM (This used to be commit c9b209be2b17c2e4677cc30b46b1074f48878f43) --- source3/lib/util_uuid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/util_uuid.c') diff --git a/source3/lib/util_uuid.c b/source3/lib/util_uuid.c index 83553ec28e..56f0ecd85b 100644 --- a/source3/lib/util_uuid.c +++ b/source3/lib/util_uuid.c @@ -2,7 +2,7 @@ * Unix SMB/CIFS implementation. * UUID server routines * Copyright (C) Theodore Ts'o 1996, 1997, - * Copyright (C) Jim McDonough 2002. + * Copyright (C) Jim McDonough 2002. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by -- cgit From 8ad3d8c9b065f3a2040beff801bdc9dceac868a8 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 13 Apr 2004 14:39:48 +0000 Subject: r196: merging struct uuid from trunk (This used to be commit 911a28361b9d8dd50597627f245ebfb57c6294fb) --- source3/lib/util_uuid.c | 149 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 110 insertions(+), 39 deletions(-) (limited to 'source3/lib/util_uuid.c') diff --git a/source3/lib/util_uuid.c b/source3/lib/util_uuid.c index 56f0ecd85b..4c35236c90 100644 --- a/source3/lib/util_uuid.c +++ b/source3/lib/util_uuid.c @@ -2,7 +2,7 @@ * Unix SMB/CIFS implementation. * UUID server routines * Copyright (C) Theodore Ts'o 1996, 1997, - * Copyright (C) Jim McDonough 2002. + * Copyright (C) Jim McDonough 2002, 2003 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,57 +27,47 @@ #define TIME_OFFSET_HIGH 0x01B21DD2 #define TIME_OFFSET_LOW 0x13814000 -struct uuid { - uint32 time_low; - uint16 time_mid; - uint16 time_hi_and_version; - uint8 clock_seq[2]; - uint8 node[6]; -}; - - -static void uuid_pack(const struct uuid *uu, GUID *ptr) +void smb_uuid_pack(const struct uuid uu, UUID_FLAT *ptr) { - uint8 *out = ptr->info; + SIVAL(ptr, 0, uu.time_low); + SSVAL(ptr, 4, uu.time_mid); + SSVAL(ptr, 6, uu.time_hi_and_version); + memcpy(ptr+8, uu.clock_seq, 2); + memcpy(ptr+10, uu.node, 6); +} - SIVAL(out, 0, uu->time_low); - SSVAL(out, 4, uu->time_mid); - SSVAL(out, 6, uu->time_hi_and_version); - memcpy(out+8, uu->clock_seq, 2); - memcpy(out+10, uu->node, 6); +void smb_uuid_unpack(const UUID_FLAT in, struct uuid *uu) +{ + uu->time_low = IVAL(in.info, 0); + uu->time_mid = SVAL(in.info, 4); + uu->time_hi_and_version = SVAL(in.info, 6); + memcpy(uu->clock_seq, in.info+8, 2); + memcpy(uu->node, in.info+10, 6); } -static void uuid_unpack(const GUID in, struct uuid *uu) +const struct uuid smb_uuid_unpack_static(const UUID_FLAT in) { - const uint8 *ptr = in.info; + static struct uuid uu; - uu->time_low = IVAL(ptr, 0); - uu->time_mid = SVAL(ptr, 4); - uu->time_hi_and_version = SVAL(ptr, 6); - memcpy(uu->clock_seq, ptr+8, 2); - memcpy(uu->node, ptr+10, 6); + smb_uuid_unpack(in, &uu); + return uu; } -void smb_uuid_generate_random(GUID *out) +void smb_uuid_generate_random(struct uuid *uu) { - GUID tmp; - struct uuid uu; + UUID_FLAT tmp; generate_random_buffer(tmp.info, sizeof(tmp.info), True); - uuid_unpack(tmp, &uu); + smb_uuid_unpack(tmp, uu); - uu.clock_seq[0] = (uu.clock_seq[0] & 0x3F) | 0x80; - uu.time_hi_and_version = (uu.time_hi_and_version & 0x0FFF) | 0x4000; - uuid_pack(&uu, out); + uu->clock_seq[0] = (uu->clock_seq[0] & 0x3F) | 0x80; + uu->time_hi_and_version = (uu->time_hi_and_version & 0x0FFF) | 0x4000; } -char *smb_uuid_to_string(const GUID in) +char *smb_uuid_to_string(const struct uuid uu) { - struct uuid uu; char *out; - uuid_unpack(in, &uu); - asprintf(&out, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", uu.time_low, uu.time_mid, uu.time_hi_and_version, uu.clock_seq[0], uu.clock_seq[1], @@ -87,13 +77,11 @@ char *smb_uuid_to_string(const GUID in) return out; } -const char *smb_uuid_string_static(const GUID in) +const char *smb_uuid_string_static(const struct uuid uu) { - struct uuid uu; static char out[37]; - uuid_unpack(in, &uu); - slprintf(out, sizeof(out) -1, + slprintf(out, sizeof(out), "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", uu.time_low, uu.time_mid, uu.time_hi_and_version, uu.clock_seq[0], uu.clock_seq[1], @@ -101,3 +89,86 @@ const char *smb_uuid_string_static(const GUID in) uu.node[3], uu.node[4], uu.node[5]); return out; } + +BOOL smb_string_to_uuid(const char *in, struct uuid* uu) +{ + BOOL ret = False; + const char *ptr = in; + char *end = (char *)in; + int i; + + if (!in || !uu) goto out; + + uu->time_low = strtoul(ptr, &end, 16); + if ((end - ptr) != 8 || *end != '-') goto out; + ptr = (end + 1); + + uu->time_mid = strtoul(ptr, &end, 16); + if ((end - ptr) != 4 || *end != '-') goto out; + ptr = (end + 1); + + uu->time_hi_and_version = strtoul(ptr, &end, 16); + if ((end - ptr) != 4 || *end != '-') goto out; + ptr = (end + 1); + + for (i = 0; i < 2; i++) { + int adj = 0; + if (*ptr >= '0' && *ptr <= '9') { + adj = '0'; + } else if (*ptr >= 'a' && *ptr <= 'f') { + adj = 'a'; + } else if (*ptr >= 'A' && *ptr <= 'F') { + adj = 'A'; + } else { + goto out; + } + uu->clock_seq[i] = (*ptr - adj) << 4; + ptr++; + + if (*ptr >= '0' && *ptr <= '9') { + adj = '0'; + } else if (*ptr >= 'a' && *ptr <= 'f') { + adj = 'a'; + } else if (*ptr >= 'A' && *ptr <= 'F') { + adj = 'A'; + } else { + goto out; + } + uu->clock_seq[i] |= (*ptr - adj); + ptr++; + } + + if (*ptr != '-') goto out; + ptr++; + + for (i = 0; i < 6; i++) { + int adj = 0; + if (*ptr >= '0' && *ptr <= '9') { + adj = '0'; + } else if (*ptr >= 'a' && *ptr <= 'f') { + adj = 'a'; + } else if (*ptr >= 'A' && *ptr <= 'F') { + adj = 'A'; + } else { + goto out; + } + uu->node[i] = (*ptr - adj) << 4; + ptr++; + + if (*ptr >= '0' && *ptr <= '9') { + adj = '0'; + } else if (*ptr >= 'a' && *ptr <= 'f') { + adj = 'a'; + } else if (*ptr >= 'A' && *ptr <= 'F') { + adj = 'A'; + } else { + goto out; + } + uu->node[i] |= (*ptr - adj); + ptr++; + } + + ret = True; +out: + return ret; +} -- cgit From f9eda19d80f40b39ffbd48119928651512a11d49 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 5 May 2004 03:03:38 +0000 Subject: r487: fixing some compile issues with the IBM AIX compiler reoported on the ml -- now to watch the build farm some more (This used to be commit 79fed5f5a73cfe4811f626acbcf85860e23e7826) --- source3/lib/util_uuid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/util_uuid.c') diff --git a/source3/lib/util_uuid.c b/source3/lib/util_uuid.c index 4c35236c90..dc9bc92023 100644 --- a/source3/lib/util_uuid.c +++ b/source3/lib/util_uuid.c @@ -45,7 +45,7 @@ void smb_uuid_unpack(const UUID_FLAT in, struct uuid *uu) memcpy(uu->node, in.info+10, 6); } -const struct uuid smb_uuid_unpack_static(const UUID_FLAT in) +struct uuid smb_uuid_unpack_static(const UUID_FLAT in) { static struct uuid uu; -- cgit From 9d0783bf211dffe58845b36b0669f05bf8bf25b5 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 14 Jul 2004 04:36:01 +0000 Subject: r1492: Rework our random number generation system. On systems with /dev/urandom, this avoids a change to secrets.tdb for every fork(). For other systems, we now only re-seed after a fork, and on startup. No need to do it per-operation. This removes the 'need_reseed' parameter from generate_random_buffer(). Andrew Bartlett (This used to be commit 36741d3cf53a7bd17d361251f2bb50851cdb035f) --- source3/lib/util_uuid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/util_uuid.c') diff --git a/source3/lib/util_uuid.c b/source3/lib/util_uuid.c index dc9bc92023..8f86c2109e 100644 --- a/source3/lib/util_uuid.c +++ b/source3/lib/util_uuid.c @@ -57,7 +57,7 @@ void smb_uuid_generate_random(struct uuid *uu) { UUID_FLAT tmp; - generate_random_buffer(tmp.info, sizeof(tmp.info), True); + generate_random_buffer(tmp.info, sizeof(tmp.info)); smb_uuid_unpack(tmp, uu); uu->clock_seq[0] = (uu->clock_seq[0] & 0x3F) | 0x80; -- cgit From 018de0186bfee8226a43ee9b6d81101b318a0261 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 1 Sep 2004 04:46:15 +0000 Subject: r2160: fixed the uuid pack/unpack routines (they could go past the end of the UUID structure) (This used to be commit 43cf57e86bfae3ab68e97c2238338581411eb2ff) --- source3/lib/util_uuid.c | 66 +++++++++++-------------------------------------- 1 file changed, 14 insertions(+), 52 deletions(-) (limited to 'source3/lib/util_uuid.c') diff --git a/source3/lib/util_uuid.c b/source3/lib/util_uuid.c index 8f86c2109e..df70740b33 100644 --- a/source3/lib/util_uuid.c +++ b/source3/lib/util_uuid.c @@ -29,11 +29,11 @@ void smb_uuid_pack(const struct uuid uu, UUID_FLAT *ptr) { - SIVAL(ptr, 0, uu.time_low); - SSVAL(ptr, 4, uu.time_mid); - SSVAL(ptr, 6, uu.time_hi_and_version); - memcpy(ptr+8, uu.clock_seq, 2); - memcpy(ptr+10, uu.node, 6); + SIVAL(ptr->info, 0, uu.time_low); + SSVAL(ptr->info, 4, uu.time_mid); + SSVAL(ptr->info, 6, uu.time_hi_and_version); + memcpy(ptr->info+8, uu.clock_seq, 2); + memcpy(ptr->info+10, uu.node, 6); } void smb_uuid_unpack(const UUID_FLAT in, struct uuid *uu) @@ -96,6 +96,7 @@ BOOL smb_string_to_uuid(const char *in, struct uuid* uu) const char *ptr = in; char *end = (char *)in; int i; + unsigned v1, v2; if (!in || !uu) goto out; @@ -111,61 +112,22 @@ BOOL smb_string_to_uuid(const char *in, struct uuid* uu) if ((end - ptr) != 4 || *end != '-') goto out; ptr = (end + 1); - for (i = 0; i < 2; i++) { - int adj = 0; - if (*ptr >= '0' && *ptr <= '9') { - adj = '0'; - } else if (*ptr >= 'a' && *ptr <= 'f') { - adj = 'a'; - } else if (*ptr >= 'A' && *ptr <= 'F') { - adj = 'A'; - } else { - goto out; - } - uu->clock_seq[i] = (*ptr - adj) << 4; - ptr++; - - if (*ptr >= '0' && *ptr <= '9') { - adj = '0'; - } else if (*ptr >= 'a' && *ptr <= 'f') { - adj = 'a'; - } else if (*ptr >= 'A' && *ptr <= 'F') { - adj = 'A'; - } else { - goto out; - } - uu->clock_seq[i] |= (*ptr - adj); - ptr++; + if (sscanf(ptr, "%02x%02x", &v1, &v2) != 2) { + goto out; } + uu->clock_seq[0] = v1; + uu->clock_seq[1] = v2; + ptr += 4; if (*ptr != '-') goto out; ptr++; for (i = 0; i < 6; i++) { - int adj = 0; - if (*ptr >= '0' && *ptr <= '9') { - adj = '0'; - } else if (*ptr >= 'a' && *ptr <= 'f') { - adj = 'a'; - } else if (*ptr >= 'A' && *ptr <= 'F') { - adj = 'A'; - } else { - goto out; - } - uu->node[i] = (*ptr - adj) << 4; - ptr++; - - if (*ptr >= '0' && *ptr <= '9') { - adj = '0'; - } else if (*ptr >= 'a' && *ptr <= 'f') { - adj = 'a'; - } else if (*ptr >= 'A' && *ptr <= 'F') { - adj = 'A'; - } else { + if (sscanf(ptr, "%02x", &v1) != 1) { goto out; } - uu->node[i] |= (*ptr - adj); - ptr++; + uu->node[i] = v1; + ptr += 2; } ret = True; -- cgit From 9840db418bad5a39edc4a32a1786f5e2d2c9dff8 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Thu, 31 Mar 2005 05:06:04 +0000 Subject: r6149: Fixes bugs #2498 and 2484. 1. using smbc_getxattr() et al, one may now request all access control entities in the ACL without getting all other NT attributes. 2. added the ability to exclude specified attributes from the result set provided by smbc_getxattr() et al, when requesting all attributes, all NT attributes, or all DOS attributes. 3. eliminated all compiler warnings, including when --enable-developer compiler flags are in use. removed -Wcast-qual flag from list, as that is specifically to force warnings in the case of casting away qualifiers. Note: In the process of eliminating compiler warnings, a few nasties were discovered. In the file libads/sasl.c, PRIVATE kerberos interfaces are being used; and in libsmb/clikrb5.c, both PRIAVE and DEPRECATED kerberos interfaces are being used. Someone who knows kerberos should look at these and determine if there is an alternate method of accomplishing the task. (This used to be commit 994694f7f26da5099f071e1381271a70407f33bb) --- source3/lib/util_uuid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/util_uuid.c') diff --git a/source3/lib/util_uuid.c b/source3/lib/util_uuid.c index df70740b33..8b8e70a36e 100644 --- a/source3/lib/util_uuid.c +++ b/source3/lib/util_uuid.c @@ -94,7 +94,7 @@ BOOL smb_string_to_uuid(const char *in, struct uuid* uu) { BOOL ret = False; const char *ptr = in; - char *end = (char *)in; + char *end = CONST_DISCARD(char *, in); int i; unsigned v1, v2; -- cgit From f24d88cf9da46680d52b42b92bd484e7b09ce99b Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 31 May 2005 13:46:45 +0000 Subject: r7139: trying to reduce the number of diffs between trunk and 3.0; changing version to 3.0.20pre1 (This used to be commit 9727d05241574042dd3aa8844ae5c701d22e2da1) --- source3/lib/util_uuid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/util_uuid.c') diff --git a/source3/lib/util_uuid.c b/source3/lib/util_uuid.c index 8b8e70a36e..df70740b33 100644 --- a/source3/lib/util_uuid.c +++ b/source3/lib/util_uuid.c @@ -94,7 +94,7 @@ BOOL smb_string_to_uuid(const char *in, struct uuid* uu) { BOOL ret = False; const char *ptr = in; - char *end = CONST_DISCARD(char *, in); + char *end = (char *)in; int i; unsigned v1, v2; -- cgit From 4e7d11449ad419f4fa791e26e059a9f73d6d4042 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 19 Sep 2006 00:12:11 +0000 Subject: r18654: Rename "struct uuid" => "struct GUID" for consistency. (This used to be commit 5de76767e857e9d159ea46e2ded612ccd6d6bf19) --- source3/lib/util_uuid.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'source3/lib/util_uuid.c') diff --git a/source3/lib/util_uuid.c b/source3/lib/util_uuid.c index df70740b33..6374c2d8a9 100644 --- a/source3/lib/util_uuid.c +++ b/source3/lib/util_uuid.c @@ -27,7 +27,7 @@ #define TIME_OFFSET_HIGH 0x01B21DD2 #define TIME_OFFSET_LOW 0x13814000 -void smb_uuid_pack(const struct uuid uu, UUID_FLAT *ptr) +void smb_uuid_pack(const struct GUID uu, UUID_FLAT *ptr) { SIVAL(ptr->info, 0, uu.time_low); SSVAL(ptr->info, 4, uu.time_mid); @@ -36,7 +36,7 @@ void smb_uuid_pack(const struct uuid uu, UUID_FLAT *ptr) memcpy(ptr->info+10, uu.node, 6); } -void smb_uuid_unpack(const UUID_FLAT in, struct uuid *uu) +void smb_uuid_unpack(const UUID_FLAT in, struct GUID *uu) { uu->time_low = IVAL(in.info, 0); uu->time_mid = SVAL(in.info, 4); @@ -45,15 +45,15 @@ void smb_uuid_unpack(const UUID_FLAT in, struct uuid *uu) memcpy(uu->node, in.info+10, 6); } -struct uuid smb_uuid_unpack_static(const UUID_FLAT in) +struct GUID smb_uuid_unpack_static(const UUID_FLAT in) { - static struct uuid uu; + static struct GUID uu; smb_uuid_unpack(in, &uu); return uu; } -void smb_uuid_generate_random(struct uuid *uu) +void smb_uuid_generate_random(struct GUID *uu) { UUID_FLAT tmp; @@ -64,7 +64,7 @@ void smb_uuid_generate_random(struct uuid *uu) uu->time_hi_and_version = (uu->time_hi_and_version & 0x0FFF) | 0x4000; } -char *smb_uuid_to_string(const struct uuid uu) +char *smb_uuid_to_string(const struct GUID uu) { char *out; @@ -77,7 +77,7 @@ char *smb_uuid_to_string(const struct uuid uu) return out; } -const char *smb_uuid_string_static(const struct uuid uu) +const char *smb_uuid_string_static(const struct GUID uu) { static char out[37]; @@ -90,7 +90,7 @@ const char *smb_uuid_string_static(const struct uuid uu) return out; } -BOOL smb_string_to_uuid(const char *in, struct uuid* uu) +BOOL smb_string_to_uuid(const char *in, struct GUID* uu) { BOOL ret = False; const char *ptr = in; -- cgit From d824b98f80ba186030cbb70b3a1e5daf80469ecd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 9 Jul 2007 19:25:36 +0000 Subject: r23779: Change from v2 or later to v3 or later. Jeremy. (This used to be commit 407e6e695b8366369b7c76af1ff76869b45347b3) --- source3/lib/util_uuid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/util_uuid.c') diff --git a/source3/lib/util_uuid.c b/source3/lib/util_uuid.c index 6374c2d8a9..e50836e265 100644 --- a/source3/lib/util_uuid.c +++ b/source3/lib/util_uuid.c @@ -6,7 +6,7 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, -- cgit From 153cfb9c83534b09f15cc16205d7adb19b394928 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 05:23:25 +0000 Subject: r23801: The FSF has moved around a lot. This fixes their Mass Ave address. (This used to be commit 87c91e4362c51819032bfbebbb273c52e203b227) --- source3/lib/util_uuid.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/lib/util_uuid.c') diff --git a/source3/lib/util_uuid.c b/source3/lib/util_uuid.c index e50836e265..a20387e8e5 100644 --- a/source3/lib/util_uuid.c +++ b/source3/lib/util_uuid.c @@ -15,8 +15,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * along with this program; if not, see . */ #include "includes.h" -- cgit From e7705f9eb920715b95a331e2f3c1f1c60258ac18 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 11 Jul 2007 10:26:02 +0000 Subject: r23829: Add ads_get_attrname_by_guid(). Guenther (This used to be commit a84fd8300661fd895ed7a8a104b743628718dfc8) --- source3/lib/util_uuid.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'source3/lib/util_uuid.c') diff --git a/source3/lib/util_uuid.c b/source3/lib/util_uuid.c index a20387e8e5..4a9c0848d2 100644 --- a/source3/lib/util_uuid.c +++ b/source3/lib/util_uuid.c @@ -133,3 +133,19 @@ BOOL smb_string_to_uuid(const char *in, struct GUID* uu) out: return ret; } + +/***************************************************************** + Return the binary string representation of a GUID. + Caller must free. +*****************************************************************/ + +char *guid_binstring(const struct GUID *guid) +{ + UUID_FLAT guid_flat; + + smb_uuid_pack(*guid, &guid_flat); + + return binary_string_rfc2254((char *)guid_flat.info, UUID_FLAT_SIZE); +} + + -- cgit From 30191d1a5704ad2b158386b511558972d539ce47 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 18 Oct 2007 17:40:25 -0700 Subject: RIP BOOL. Convert BOOL -> bool. I found a few interesting bugs in various places whilst doing this (places that assumed BOOL == int). I also need to fix the Samba4 pidl generation (next checkin). Jeremy. (This used to be commit f35a266b3cbb3e5fa6a86be60f34fe340a3ca71f) --- source3/lib/util_uuid.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/lib/util_uuid.c') diff --git a/source3/lib/util_uuid.c b/source3/lib/util_uuid.c index 4a9c0848d2..606bfd2147 100644 --- a/source3/lib/util_uuid.c +++ b/source3/lib/util_uuid.c @@ -89,9 +89,9 @@ const char *smb_uuid_string_static(const struct GUID uu) return out; } -BOOL smb_string_to_uuid(const char *in, struct GUID* uu) +bool smb_string_to_uuid(const char *in, struct GUID* uu) { - BOOL ret = False; + bool ret = False; const char *ptr = in; char *end = (char *)in; int i; -- cgit From 1011b32678c7b32472a909b9f515698947d2a389 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 25 Nov 2007 10:10:52 +0100 Subject: Remove some statics (This used to be commit 1fab16ffb888cd4ec18e52d9da33976a67a5d104) --- source3/lib/util_uuid.c | 44 +++++++++++++------------------------------- 1 file changed, 13 insertions(+), 31 deletions(-) (limited to 'source3/lib/util_uuid.c') diff --git a/source3/lib/util_uuid.c b/source3/lib/util_uuid.c index 606bfd2147..36c04e9b84 100644 --- a/source3/lib/util_uuid.c +++ b/source3/lib/util_uuid.c @@ -44,14 +44,6 @@ void smb_uuid_unpack(const UUID_FLAT in, struct GUID *uu) memcpy(uu->node, in.info+10, 6); } -struct GUID smb_uuid_unpack_static(const UUID_FLAT in) -{ - static struct GUID uu; - - smb_uuid_unpack(in, &uu); - return uu; -} - void smb_uuid_generate_random(struct GUID *uu) { UUID_FLAT tmp; @@ -63,30 +55,20 @@ void smb_uuid_generate_random(struct GUID *uu) uu->time_hi_and_version = (uu->time_hi_and_version & 0x0FFF) | 0x4000; } -char *smb_uuid_to_string(const struct GUID uu) -{ - char *out; - - asprintf(&out, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", - uu.time_low, uu.time_mid, uu.time_hi_and_version, - uu.clock_seq[0], uu.clock_seq[1], - uu.node[0], uu.node[1], uu.node[2], - uu.node[3], uu.node[4], uu.node[5]); - - return out; -} - -const char *smb_uuid_string_static(const struct GUID uu) +const char *smb_uuid_string(TALLOC_CTX *mem_ctx, const struct GUID uu) { - static char out[37]; - - slprintf(out, sizeof(out), - "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", - uu.time_low, uu.time_mid, uu.time_hi_and_version, - uu.clock_seq[0], uu.clock_seq[1], - uu.node[0], uu.node[1], uu.node[2], - uu.node[3], uu.node[4], uu.node[5]); - return out; + char *result; + + result = talloc_asprintf( + mem_ctx, + "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", + uu.time_low, uu.time_mid, uu.time_hi_and_version, + uu.clock_seq[0], uu.clock_seq[1], + uu.node[0], uu.node[1], uu.node[2], + uu.node[3], uu.node[4], uu.node[5]); + + SMB_ASSERT(result != NULL); + return result; } bool smb_string_to_uuid(const char *in, struct GUID* uu) -- cgit From e65ea7471e2447ed150ade9a2c4f0a67663fb8d2 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 16 Jul 2008 22:18:43 +0200 Subject: Add ndr_syntax_id_equal() (This used to be commit 5fc90908deb417130af122941e084542304a2543) --- source3/lib/util_uuid.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'source3/lib/util_uuid.c') diff --git a/source3/lib/util_uuid.c b/source3/lib/util_uuid.c index 36c04e9b84..0d788ac8b4 100644 --- a/source3/lib/util_uuid.c +++ b/source3/lib/util_uuid.c @@ -130,4 +130,12 @@ char *guid_binstring(const struct GUID *guid) return binary_string_rfc2254((char *)guid_flat.info, UUID_FLAT_SIZE); } - +bool guid_equal(const struct GUID *g1, const struct GUID *g2) +{ + return ((g1->time_low == g2->time_low) + && (g1->time_mid == g2->time_mid) + && (g1->time_hi_and_version == g2->time_hi_and_version) + && (memcmp(g1->clock_seq, g2->clock_seq, + sizeof(g1->clock_seq)) == 0) + && (memcmp(g1->node, g2->node, sizeof(g1->node)) == 0)); +} -- cgit From 8e02cb17fe5e9931532b0ecf0b61825f500fd719 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 19 Jul 2008 19:50:36 +0200 Subject: Ooops, GUID_equal was already around :-) (This used to be commit 9a0bc277f23831124d049301bc7009a285d91a11) --- source3/lib/util_uuid.c | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'source3/lib/util_uuid.c') diff --git a/source3/lib/util_uuid.c b/source3/lib/util_uuid.c index 0d788ac8b4..3a8f7b3f4f 100644 --- a/source3/lib/util_uuid.c +++ b/source3/lib/util_uuid.c @@ -129,13 +129,3 @@ char *guid_binstring(const struct GUID *guid) return binary_string_rfc2254((char *)guid_flat.info, UUID_FLAT_SIZE); } - -bool guid_equal(const struct GUID *g1, const struct GUID *g2) -{ - return ((g1->time_low == g2->time_low) - && (g1->time_mid == g2->time_mid) - && (g1->time_hi_and_version == g2->time_hi_and_version) - && (memcmp(g1->clock_seq, g2->clock_seq, - sizeof(g1->clock_seq)) == 0) - && (memcmp(g1->node, g2->node, sizeof(g1->node)) == 0)); -} -- cgit