diff options
author | Andrew Bartlett <abartlet@samba.org> | 2008-11-10 11:40:31 +1100 |
---|---|---|
committer | Stefan Metzmacher <metze@samba.org> | 2008-11-16 16:24:33 +0100 |
commit | 536de25faef82611e61b12126d432368badeed65 (patch) | |
tree | f809e4e12b2448780ef8ffb49a85c534ea2e2b92 /librpc | |
parent | 8c2c62c5eaf7c6adc445950f4917208dc4bced87 (diff) | |
download | samba-536de25faef82611e61b12126d432368badeed65.tar.gz samba-536de25faef82611e61b12126d432368badeed65.tar.bz2 samba-536de25faef82611e61b12126d432368badeed65.zip |
Add a new function to parse a DATA_BLOB into a GUID
The reason for this new function is to ensure the length is not
discarded when the input is a ldb_val (aka DATA_BLOB) in ldb.
Andrew Bartlett
Diffstat (limited to 'librpc')
-rw-r--r-- | librpc/ndr/libndr.h | 1 | ||||
-rw-r--r-- | librpc/ndr/uuid.c | 28 |
2 files changed, 22 insertions, 7 deletions
diff --git a/librpc/ndr/libndr.h b/librpc/ndr/libndr.h index 127f6734e3..ad94c59e90 100644 --- a/librpc/ndr/libndr.h +++ b/librpc/ndr/libndr.h @@ -511,6 +511,7 @@ enum ndr_err_code ndr_push_charset(struct ndr_push *ndr, int ndr_flags, const ch /* GUIDs */ bool GUID_equal(const struct GUID *u1, const struct GUID *u2); +NTSTATUS GUID_from_data_blob(const DATA_BLOB *s, struct GUID *guid); NTSTATUS GUID_from_string(const char *s, struct GUID *guid); NTSTATUS NS_GUID_from_string(const char *s, struct GUID *guid); struct GUID GUID_zero(void); diff --git a/librpc/ndr/uuid.c b/librpc/ndr/uuid.c index 1e6ee0a3db..308b5c0688 100644 --- a/librpc/ndr/uuid.c +++ b/librpc/ndr/uuid.c @@ -27,7 +27,7 @@ /** build a GUID from a string */ -_PUBLIC_ NTSTATUS GUID_from_string(const char *s, struct GUID *guid) +_PUBLIC_ NTSTATUS GUID_from_data_blob(const DATA_BLOB *s, struct GUID *guid) { NTSTATUS status = NT_STATUS_INVALID_PARAMETER; uint32_t time_low; @@ -36,19 +36,23 @@ _PUBLIC_ NTSTATUS GUID_from_string(const char *s, struct GUID *guid) uint32_t node[6]; int i; - if (s == NULL) { + if (s->data == NULL) { return NT_STATUS_INVALID_PARAMETER; } - if (11 == sscanf(s, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", + if (s->length == 36 && + 11 == sscanf((const char *)s->data, + "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", &time_low, &time_mid, &time_hi_and_version, &clock_seq[0], &clock_seq[1], &node[0], &node[1], &node[2], &node[3], &node[4], &node[5])) { status = NT_STATUS_OK; - } else if (11 == sscanf(s, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}", - &time_low, &time_mid, &time_hi_and_version, - &clock_seq[0], &clock_seq[1], - &node[0], &node[1], &node[2], &node[3], &node[4], &node[5])) { + } else if (s->length == 38 + && 11 == sscanf((const char *)s->data, + "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}", + &time_low, &time_mid, &time_hi_and_version, + &clock_seq[0], &clock_seq[1], + &node[0], &node[1], &node[2], &node[3], &node[4], &node[5])) { status = NT_STATUS_OK; } @@ -71,6 +75,16 @@ _PUBLIC_ NTSTATUS GUID_from_string(const char *s, struct GUID *guid) /** build a GUID from a string */ +_PUBLIC_ NTSTATUS GUID_from_string(const char *s, struct GUID *guid) +{ + DATA_BLOB blob = data_blob_string_const(s); + return GUID_from_data_blob(&blob, guid); + return NT_STATUS_OK; +} + +/** + build a GUID from a string +*/ _PUBLIC_ NTSTATUS NS_GUID_from_string(const char *s, struct GUID *guid) { NTSTATUS status = NT_STATUS_INVALID_PARAMETER; |