summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source3/lib/util_uuid.c39
1 files changed, 35 insertions, 4 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;
+}