2 #include "libcli/util/ntstatus.h"
3 #include "util_str_hex.h"
5 NTSTATUS read_hex_bytes(const char *s, uint hexchars, uint64_t *dest)
11 if ((hexchars & 1) || hexchars > 16) {
12 return NT_STATUS_INVALID_PARAMETER;
15 for (i = 0; i < hexchars; i++) {
18 if (c >= '0' && c <= '9') {
21 else if (c >= 'a' && c <= 'f') {
24 else if (c >= 'A' && c <= 'F') {
28 /* BAD character (including '\0') */
29 return NT_STATUS_INVALID_PARAMETER;
37 NTSTATUS parse_guid_string(const char *s,
40 uint32_t *time_hi_and_version,
41 uint32_t clock_seq[2],
47 /* "e12b56b6-0a95-11d1-adbb-00c04fd8d5cd"
50 | | | \_____ clock_seq[2]
51 | | \__________ time_hi_and_version
52 | \_______________ time_mid
53 \_____________________ time_low
55 status = read_hex_bytes(s, 8, &tmp);
56 if (!NT_STATUS_IS_OK(status) || s[8] != '-') {
57 return NT_STATUS_INVALID_PARAMETER;
62 status = read_hex_bytes(s, 4, &tmp);
63 if (!NT_STATUS_IS_OK(status) || s[4] != '-') {
64 return NT_STATUS_INVALID_PARAMETER;
69 status = read_hex_bytes(s, 4, &tmp);
70 if (!NT_STATUS_IS_OK(status) || s[4] != '-') {
71 return NT_STATUS_INVALID_PARAMETER;
73 *time_hi_and_version = tmp;
76 for (i = 0; i < 2; i++) {
77 status = read_hex_bytes(s, 2, &tmp);
78 if (!NT_STATUS_IS_OK(status)) {
79 return NT_STATUS_INVALID_PARAMETER;
85 return NT_STATUS_INVALID_PARAMETER;
90 for (i = 0; i < 6; i++) {
91 status = read_hex_bytes(s, 2, &tmp);
92 if (!NT_STATUS_IS_OK(status)) {
93 return NT_STATUS_INVALID_PARAMETER;