Make greater use of 'GUID_from_data_blob'
authorAndrew Bartlett <abartlet@samba.org>
Wed, 3 Dec 2008 23:38:07 +0000 (10:38 +1100)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 17 Dec 2008 01:29:23 +0000 (12:29 +1100)
This avoids accidentily running off the end of a string, and uses a
single 'guess which type of GUID I have' algorithm.

Andrew Bartlett

Signed-off-by: Stefan Metzmacher <metze@samba.org>
source4/dsdb/samdb/ldb_modules/simple_ldap_map.c

index c353914e2cda3d8bec0e6ea4aca27635254acd52..0e42f7869a9243294cc5d426f56c47bb2299a87e 100644 (file)
@@ -44,7 +44,7 @@ struct entryuuid_private {
 static struct ldb_val encode_guid(struct ldb_module *module, TALLOC_CTX *ctx, const struct ldb_val *val)
 {
        struct GUID guid;
-       NTSTATUS status = GUID_from_string((char *)val->data, &guid);
+       NTSTATUS status = GUID_from_data_blob(val, &guid);
        enum ndr_err_code ndr_err;
        struct ldb_val out = data_blob(NULL, 0);
 
@@ -62,27 +62,13 @@ static struct ldb_val encode_guid(struct ldb_module *module, TALLOC_CTX *ctx, co
 
 static struct ldb_val guid_always_string(struct ldb_module *module, TALLOC_CTX *ctx, const struct ldb_val *val)
 {
-       struct GUID *guid;
        struct ldb_val out = data_blob(NULL, 0);
-       if (val->length >= 32 && val->data[val->length] == '\0') {
-               ldb_handler_copy(module->ldb, ctx, val, &out);
-       } else {
-               enum ndr_err_code ndr_err;
-
-               guid = talloc(ctx, struct GUID);
-               if (guid == NULL) {
-                       return out;
-               }
-               ndr_err = ndr_pull_struct_blob(val, guid, NULL, guid,
-                                              (ndr_pull_flags_fn_t)ndr_pull_GUID);
-               if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
-                       talloc_free(guid);
-                       return out;
-               }
-               out = data_blob_string_const(GUID_string(ctx, guid));
-               talloc_free(guid);
+       struct GUID guid;
+       NTSTATUS status = GUID_from_data_blob(val, &guid);
+       if (!NT_STATUS_IS_OK(status)) {
+               return out;
        }
-       return out;
+       return data_blob_string_const(GUID_string(ctx, &guid));
 }
 
 static struct ldb_val encode_ns_guid(struct ldb_module *module, TALLOC_CTX *ctx, const struct ldb_val *val)
@@ -107,27 +93,12 @@ static struct ldb_val encode_ns_guid(struct ldb_module *module, TALLOC_CTX *ctx,
 static struct ldb_val guid_ns_string(struct ldb_module *module, TALLOC_CTX *ctx, const struct ldb_val *val)
 {
        struct ldb_val out = data_blob(NULL, 0);
-       if (val->length >= 32 && val->data[val->length] == '\0') {
-               struct GUID guid;
-               GUID_from_string((char *)val->data, &guid);
-               out = data_blob_string_const(NS_GUID_string(ctx, &guid));
-       } else {
-               enum ndr_err_code ndr_err;
-               struct GUID *guid_p;
-               guid_p = talloc(ctx, struct GUID);
-               if (guid_p == NULL) {
-                       return out;
-               }
-               ndr_err = ndr_pull_struct_blob(val, guid_p, NULL, guid_p,
-                                              (ndr_pull_flags_fn_t)ndr_pull_GUID);
-               if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
-                       talloc_free(guid_p);
-                       return out;
-               }
-               out = data_blob_string_const(NS_GUID_string(ctx, guid_p));
-               talloc_free(guid_p);
+       struct GUID guid;
+       NTSTATUS status = GUID_from_data_blob(val, &guid);
+       if (!NT_STATUS_IS_OK(status)) {
+               return out;
        }
-       return out;
+       return data_blob_string_const(NS_GUID_string(ctx, &guid));
 }
 
 /* The backend holds binary sids, so just copy them back */