diff options
author | Jim McDonough <jmcd@samba.org> | 2003-10-30 23:43:18 +0000 |
---|---|---|
committer | Jim McDonough <jmcd@samba.org> | 2003-10-30 23:43:18 +0000 |
commit | 8270b9bd298719e81646abf19caf42e452752090 (patch) | |
tree | 2610a25bd18e4362ee76797891ccc37733f9127d /source3/lib | |
parent | 29f33e828720a01224f9fe40ac156a1c51be41ba (diff) | |
download | samba-8270b9bd298719e81646abf19caf42e452752090.tar.gz samba-8270b9bd298719e81646abf19caf42e452752090.tar.bz2 samba-8270b9bd298719e81646abf19caf42e452752090.zip |
Add string to uuid fn. Thanks aliguori.
(This used to be commit 5f9fe8304f037f91fa765e64580a7119aeb201dd)
Diffstat (limited to 'source3/lib')
-rw-r--r-- | source3/lib/util_uuid.c | 85 |
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; +} |