librpc: split out a separate GUID_from_ndr_blob() function
authorAndrew Tridgell <tridge@samba.org>
Thu, 10 Dec 2009 00:22:20 +0000 (11:22 +1100)
committerAndrew Tridgell <tridge@samba.org>
Thu, 10 Dec 2009 06:51:26 +0000 (17:51 +1100)
This will simplify many of the places that deal with NDR formatted
GUIDs

librpc/ndr/libndr.h
librpc/ndr/uuid.c

index e881a5c691d579022c0e7065d79b4d32a6605c3b..d26adb8bbee57e5add3daadcab7903233e299667 100644 (file)
@@ -536,6 +536,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_ndr_blob(const DATA_BLOB *b, struct GUID *guid);
 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);
index df17d7824e96864d0cb6d96bd3902008c941007d..c3f6a054534ab49f08fa1ae57d09c532a43bec3d 100644 (file)
 #include "librpc/ndr/libndr.h"
 #include "librpc/gen_ndr/ndr_misc.h"
 
+
+/**
+  build a GUID from a NDR data blob
+*/
+_PUBLIC_ NTSTATUS GUID_from_ndr_blob(const DATA_BLOB *b, struct GUID *guid)
+{
+       enum ndr_err_code ndr_err;
+       TALLOC_CTX *mem_ctx;
+
+       mem_ctx = talloc_new(NULL);
+       NT_STATUS_HAVE_NO_MEMORY(mem_ctx);
+
+       ndr_err = ndr_pull_struct_blob_all(b, mem_ctx, NULL, guid,
+                                          (ndr_pull_flags_fn_t)ndr_pull_GUID);
+       talloc_free(mem_ctx);
+       return ndr_map_error2ntstatus(ndr_err);
+}
+
+
 /**
   build a GUID from a string
 */
@@ -89,21 +108,7 @@ _PUBLIC_ NTSTATUS GUID_from_data_blob(const DATA_BLOB *s, struct GUID *guid)
        }
 
        if (s->length == 16) {
-               enum ndr_err_code ndr_err;
-               struct GUID guid2;
-               TALLOC_CTX *mem_ctx;
-
-               mem_ctx = talloc_new(NULL);
-               NT_STATUS_HAVE_NO_MEMORY(mem_ctx);
-
-               ndr_err = ndr_pull_struct_blob(s, mem_ctx, NULL, &guid2,
-                                              (ndr_pull_flags_fn_t)ndr_pull_GUID);
-               talloc_free(mem_ctx);
-               if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
-                       return ndr_map_error2ntstatus(ndr_err);
-               }
-               *guid = guid2;
-               return NT_STATUS_OK;
+               return GUID_from_ndr_blob(s, guid);
        }
 
        if (!NT_STATUS_IS_OK(status)) {