summaryrefslogtreecommitdiff
path: root/source3/lib/util_uuid.c
diff options
context:
space:
mode:
Diffstat (limited to 'source3/lib/util_uuid.c')
-rw-r--r--source3/lib/util_uuid.c85
1 files changed, 84 insertions, 1 deletions
diff --git a/source3/lib/util_uuid.c b/source3/lib/util_uuid.c
index fe8595c8cb..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 <jmcd@us.ibm.com> 2002.
+ * Copyright (C) Jim McDonough <jmcd@us.ibm.com> 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
@@ -89,3 +89,86 @@ const char *smb_uuid_string_static(const struct uuid uu)
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;
+}