From e042a93cce2fdadfd88c93b813e10f0cc12f570e Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Fri, 18 Oct 2002 20:11:29 +0000 Subject: Format objectGUIDs on ads dumps. (This used to be commit 7eaf7e7115c75e682b1b9368c6f28c60429885e5) --- source3/lib/util_uuid.c | 39 +++++++++++++++++++++++++++++++++++---- source3/libads/ldap.c | 19 ++++++++++++++++++- 2 files changed, 53 insertions(+), 5 deletions(-) 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; +} diff --git a/source3/libads/ldap.c b/source3/libads/ldap.c index d3c8b39e22..2359dbd7ed 100644 --- a/source3/libads/ldap.c +++ b/source3/libads/ldap.c @@ -1106,6 +1106,23 @@ static void dump_binary(const char *field, struct berval **values) } } +struct uuid { + uint32 i1; + uint16 i2; + uint16 i3; + uint8 s[8]; +}; + +static void dump_guid(const char *field, struct berval **values) +{ + int i; + GUID guid; + for (i=0; values[i]; i++) { + memcpy(guid.info, values[i]->bv_val, sizeof(guid.info)); + printf("%s: %s\n", field, uuid_string_static(guid)); + } +} + /* dump a sid result from ldap */ @@ -1172,7 +1189,7 @@ static BOOL ads_dump_field(char *field, void **values, void *data_area) BOOL string; void (*handler)(const char *, struct berval **); } handlers[] = { - {"objectGUID", False, dump_binary}, + {"objectGUID", False, dump_guid}, {"nTSecurityDescriptor", False, dump_sd}, {"dnsRecord", False, dump_binary}, {"objectSid", False, dump_sid}, -- cgit