libndr: added a GUID_to_ndr_blob() helper function
authorAndrew Tridgell <tridge@samba.org>
Thu, 10 Dec 2009 03:29:19 +0000 (14:29 +1100)
committerAndrew Tridgell <tridge@samba.org>
Thu, 10 Dec 2009 06:51:28 +0000 (17:51 +1100)
This can be used in many places that deal with GUIDs

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

index d26adb8bbee57e5add3daadcab7903233e299667..dbdc0e65bf362201dd129b167b7243f3101d1df6 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_to_ndr_blob(const struct GUID *guid, TALLOC_CTX *mem_ctx, DATA_BLOB *b);
 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);
index c3f6a054534ab49f08fa1ae57d09c532a43bec3d..429a1b1ac993d7c20bf9c22d272b822196a89db4 100644 (file)
 #include "librpc/ndr/libndr.h"
 #include "librpc/gen_ndr/ndr_misc.h"
 
+/**
+  build a NDR blob from a GUID
+*/
+_PUBLIC_ NTSTATUS GUID_to_ndr_blob(const struct GUID *guid, TALLOC_CTX *mem_ctx, DATA_BLOB *b)
+{
+       enum ndr_err_code ndr_err;
+       ndr_err = ndr_push_struct_blob(b, mem_ctx, NULL, guid,
+                                      (ndr_push_flags_fn_t)ndr_push_GUID);
+       return ndr_map_error2ntstatus(ndr_err);
+}
+
 
 /**
   build a GUID from a NDR data blob
@@ -280,18 +291,15 @@ _PUBLIC_ char *GUID_hexstring(TALLOC_CTX *mem_ctx, const struct GUID *guid)
 {
        char *ret;
        DATA_BLOB guid_blob;
-       enum ndr_err_code ndr_err;
        TALLOC_CTX *tmp_mem;
+       NTSTATUS status;
 
        tmp_mem = talloc_new(mem_ctx);
        if (!tmp_mem) {
                return NULL;
        }
-       ndr_err = ndr_push_struct_blob(&guid_blob, tmp_mem,
-                                      NULL,
-                                      guid,
-                                      (ndr_push_flags_fn_t)ndr_push_GUID);
-       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+       status = GUID_to_ndr_blob(guid, tmp_mem, &guid_blob);
+       if (!NT_STATUS_IS_OK(status)) {
                talloc_free(tmp_mem);
                return NULL;
        }