The branch, master has been updated
       via  c59372b... s4-ldb: fixed 2 bugs in ldb_dn_set_extended_component()
       via  62dc7f6... s4-libcli: GUID_from_ndr_blob() is strict about the blob 
size
       via  c7c97b6... s4-schema: use GUID_to_ndr_blob()
       via  d35b7d0... s4-schema: use binsearch.h
       via  71943e8... util: added binsearch.h for binary array searches
       via  261ba40... s4-dsdb: use GUID_to_ndr_blob()
       via  215cc5a... s4-ldb: use GUID_to_ndr_blob()
       via  9822286... s4-libnet: use GUID_to_ndr_blob()
       via  b4ea96e... s4-libcli: use GUID_to_ndr_blob()
       via  33cbe9c... s4-server: use GUID_to_ndr_blob() in cldap and smb 
servers
       via  1b20002... libcli: use GUID_to_ndr_blob()
       via  d035a60... s3-ldb: use GUID_to_ndr_blob()
       via  3ce800d... libndr: added a GUID_to_ndr_blob() helper function
       via  2493776... s4-ldb: simplify ldif handlers using new GUID functions
       via  d337cef... s4-dsdb: simplify samdb_result_guid()
       via  56b887e... s4-dsdb: simplify linked attributes code using GUID 
functions
       via  81bc561... s4-dsdb: simplify schema code using new GUID functions
       via  f01ea8b... s4-smb2: use new GUID function in smb2 negprot
       via  498f2b8... s4-libcli: use new GUID functions in libcli
       via  08e8988... s4-dsdb: use GUID_from_ndr_blob() to create 
dsdb_get_extended_dn_guid()
       via  effff54... librpc: split out a separate GUID_from_ndr_blob() 
function
      from  d2f13dd... s4-smbtorture: enhance spoolss_EnumPrinterKey torture 
test.

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit c59372b0b87ca85c1b9061545b6714f00736bb35
Author: Andrew Tridgell <tri...@samba.org>
Date:   Thu Dec 10 17:23:00 2009 +1100

    s4-ldb: fixed 2 bugs in ldb_dn_set_extended_component()
    
    The first bug was that setting a component twice could cause it to
    appear twice in the DN.
    
    The second bug was that using an existing ldb_val from a previous call
    of ldb_dn_get_extended_component() as an argument to
    ldb_dn_set_extended_component() would cause a valgrind error (as the
    array the val pointed into will change).

commit 62dc7f6b2dd7df83740e4761988eb2f87205c73c
Author: Andrew Tridgell <tri...@samba.org>
Date:   Thu Dec 10 14:48:56 2009 +1100

    s4-libcli: GUID_from_ndr_blob() is strict about the blob size
    
    We need to create a blob of the right length

commit c7c97b61aef94d6adc786b3e6eb6e347d1d9382c
Author: Andrew Tridgell <tri...@samba.org>
Date:   Thu Dec 10 14:36:12 2009 +1100

    s4-schema: use GUID_to_ndr_blob()

commit d35b7d0aa4bf66af25c23fe26699b2dc86584e26
Author: Andrew Tridgell <tri...@samba.org>
Date:   Thu Dec 10 14:35:42 2009 +1100

    s4-schema: use binsearch.h

commit 71943e8858943718affb6a3c0ded2127f07057f0
Author: Andrew Tridgell <tri...@samba.org>
Date:   Thu Dec 10 14:35:24 2009 +1100

    util: added binsearch.h for binary array searches
    
    This was moved from the schema_query code. It will now be used in more
    than one place, so best to make it a library macro. I think there are
    quite a few places that could benefit from this.

commit 261ba40e77192d0354d332a9a72eb94f327cb4e6
Author: Andrew Tridgell <tri...@samba.org>
Date:   Thu Dec 10 14:33:13 2009 +1100

    s4-dsdb: use GUID_to_ndr_blob()

commit 215cc5a9edfbe9b50440266fba72e8f91c64066b
Author: Andrew Tridgell <tri...@samba.org>
Date:   Thu Dec 10 14:32:47 2009 +1100

    s4-ldb: use GUID_to_ndr_blob()

commit 982228605f3bc77901467f1673bd1385808423e0
Author: Andrew Tridgell <tri...@samba.org>
Date:   Thu Dec 10 14:32:29 2009 +1100

    s4-libnet: use GUID_to_ndr_blob()

commit b4ea96ecd9bab32d06599d872f091576e31e12f8
Author: Andrew Tridgell <tri...@samba.org>
Date:   Thu Dec 10 14:32:15 2009 +1100

    s4-libcli: use GUID_to_ndr_blob()

commit 33cbe9c6310a7853a0189cd17b0f6c26f208cf16
Author: Andrew Tridgell <tri...@samba.org>
Date:   Thu Dec 10 14:31:52 2009 +1100

    s4-server: use GUID_to_ndr_blob() in cldap and smb servers

commit 1b20002cc246f6bab6fe2369412bd4c65311785f
Author: Andrew Tridgell <tri...@samba.org>
Date:   Thu Dec 10 14:31:13 2009 +1100

    libcli: use GUID_to_ndr_blob()

commit d035a600893bcbfeed97d8c65989eee6f067393a
Author: Andrew Tridgell <tri...@samba.org>
Date:   Thu Dec 10 14:30:46 2009 +1100

    s3-ldb: use GUID_to_ndr_blob()
    
    this also fixes an error in NTSTATUS handling

commit 3ce800dcbe097f0683cedf7465f0562c7111444a
Author: Andrew Tridgell <tri...@samba.org>
Date:   Thu Dec 10 14:29:19 2009 +1100

    libndr: added a GUID_to_ndr_blob() helper function
    
    This can be used in many places that deal with GUIDs

commit 2493776f59f13ce20a39c0767bdfe85de6b0bdcd
Author: Andrew Tridgell <tri...@samba.org>
Date:   Thu Dec 10 11:27:09 2009 +1100

    s4-ldb: simplify ldif handlers using new GUID functions

commit d337cefa92e959a611027307e52118de787ab7f5
Author: Andrew Tridgell <tri...@samba.org>
Date:   Thu Dec 10 11:26:36 2009 +1100

    s4-dsdb: simplify samdb_result_guid()

commit 56b887e5b94efedd0203550f6bc21d767da5d6c6
Author: Andrew Tridgell <tri...@samba.org>
Date:   Thu Dec 10 11:26:18 2009 +1100

    s4-dsdb: simplify linked attributes code using GUID functions

commit 81bc561330abfec837bd65ad57c4a5266c237990
Author: Andrew Tridgell <tri...@samba.org>
Date:   Thu Dec 10 11:25:44 2009 +1100

    s4-dsdb: simplify schema code using new GUID functions

commit f01ea8bf589a876bab14907d1ec6a998c23f87c9
Author: Andrew Tridgell <tri...@samba.org>
Date:   Thu Dec 10 11:25:13 2009 +1100

    s4-smb2: use new GUID function in smb2 negprot

commit 498f2b879a38b7b3888fcb2892a9d073417f7d84
Author: Andrew Tridgell <tri...@samba.org>
Date:   Thu Dec 10 11:24:54 2009 +1100

    s4-libcli: use new GUID functions in libcli

commit 08e8988bd850de8050cd05aacdcd0e0f78200c7d
Author: Andrew Tridgell <tri...@samba.org>
Date:   Thu Dec 10 11:23:20 2009 +1100

    s4-dsdb: use GUID_from_ndr_blob() to create dsdb_get_extended_dn_guid()

commit effff544265c63c95cf630d426b630bfe4d25aec
Author: Andrew Tridgell <tri...@samba.org>
Date:   Thu Dec 10 11:22:20 2009 +1100

    librpc: split out a separate GUID_from_ndr_blob() function
    
    This will simplify many of the places that deal with NDR formatted
    GUIDs

-----------------------------------------------------------------------

Summary of changes:
 lib/util/binsearch.h                               |   68 ++++++++++++++++++
 libcli/ldap/ldap_ndr.c                             |    7 +-
 librpc/ndr/libndr.h                                |    2 +
 librpc/ndr/uuid.c                                  |   55 +++++++++------
 source3/lib/ldb/samba/ldif_handlers.c              |    3 +-
 source4/cldap_server/netlogon.c                    |    8 +--
 source4/dsdb/common/util.c                         |   39 ++++++-----
 source4/dsdb/repl/replicated_objects.c             |    9 +--
 source4/dsdb/samdb/ldb_modules/extended_dn_out.c   |   14 +---
 source4/dsdb/samdb/ldb_modules/linked_attributes.c |   34 +++++-----
 source4/dsdb/samdb/ldb_modules/simple_ldap_map.c   |   16 ++---
 source4/dsdb/schema/schema_init.c                  |    8 +--
 source4/dsdb/schema/schema_query.c                 |   69 ++++++-------------
 source4/dsdb/schema/schema_set.c                   |    8 +-
 source4/dsdb/schema/schema_syntax.c                |   72 +++++++++-----------
 source4/lib/ldb-samba/ldif_handlers.c              |   23 +++---
 source4/lib/ldb/common/ldb_dn.c                    |   14 +++-
 source4/libcli/raw/rawfsinfo.c                     |   12 ++--
 source4/libcli/raw/rawrequest.c                    |   26 +++-----
 source4/libcli/smb2/negprot.c                      |   13 ++--
 source4/libnet/libnet_become_dc.c                  |    6 +-
 source4/libnet/libnet_samsync_ldb.c                |   10 +--
 source4/smb_server/blob.c                          |   10 +--
 source4/smb_server/smb2/negprot.c                  |   10 +--
 24 files changed, 276 insertions(+), 260 deletions(-)
 create mode 100644 lib/util/binsearch.h


Changeset truncated at 500 lines:

diff --git a/lib/util/binsearch.h b/lib/util/binsearch.h
new file mode 100644
index 0000000..ac83990
--- /dev/null
+++ b/lib/util/binsearch.h
@@ -0,0 +1,68 @@
+/*
+   Unix SMB/CIFS implementation.
+
+   a generic binary search macro
+
+   Copyright (C) Andrew Tridgell 2009
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _BINSEARCH_H
+#define _BINSEARCH_H
+
+/* a binary array search, where the array is an array of pointers to 
structures,
+   and we want to find a match for 'target' on 'field' in those structures.
+
+   Inputs:
+      array:          base pointer to an array of structures
+      arrray_size:    number of elements in the array
+      field:          the name of the field in the structure we are keying off
+      target:         the field value we are looking for
+      comparison_fn:  the comparison function
+      result:         where the result of the search is put
+
+   if the element is found, then 'result' is set to point to the found array 
element. If not,
+   then 'result' is set to NULL.
+
+   The array is assumed to be sorted by the same comparison_fn as the
+   search (with, for example, qsort)
+ */
+#define BINARY_ARRAY_SEARCH_P(array, array_size, field, target, comparison_fn, 
result) do { \
+       int32_t _b, _e; \
+       (result) = NULL; \
+       if (array_size) { for (_b = 0, _e = (array_size)-1; _b <= _e; ) { \
+               int32_t _i = (_b+_e)/2; \
+               int _r = comparison_fn(target, array[_i]->field); \
+               if (_r == 0) { (result) = array[_i]; break; } \
+               if (_r < 0) _e = _i - 1; else _b = _i + 1; \
+       }} } while (0)
+
+/*
+  like BINARY_ARRAY_SEARCH_P, but assumes that the array is an array
+  of structures, rather than pointers to structures
+
+  result points to the found structure, or NULL
+ */
+#define BINARY_ARRAY_SEARCH(array, array_size, field, target, comparison_fn, 
result) do { \
+       int32_t _b, _e; \
+       (result) = NULL; \
+       if (array_size) { for (_b = 0, _e = (array_size)-1; _b <= _e; ) {       
\
+               int32_t _i = (_b+_e)/2; \
+               int _r = comparison_fn(target, array[_i].field); \
+               if (_r == 0) { (result) = &array[_i]; break; } \
+               if (_r < 0) _e = _i - 1; else _b = _i + 1; \
+       }} } while (0)
+
+#endif
diff --git a/libcli/ldap/ldap_ndr.c b/libcli/ldap/ldap_ndr.c
index dd820ff..6f1bb4e 100644
--- a/libcli/ldap/ldap_ndr.c
+++ b/libcli/ldap/ldap_ndr.c
@@ -64,11 +64,10 @@ char *ldap_encode_ndr_dom_sid(TALLOC_CTX *mem_ctx, const 
struct dom_sid *sid)
 char *ldap_encode_ndr_GUID(TALLOC_CTX *mem_ctx, struct GUID *guid)
 {
        DATA_BLOB blob;
-       enum ndr_err_code ndr_err;
+       NTSTATUS status;
        char *ret;
-       ndr_err = ndr_push_struct_blob(&blob, mem_ctx, NULL, guid,
-                                      (ndr_push_flags_fn_t)ndr_push_GUID);
-       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+       status = GUID_to_ndr_blob(guid, mem_ctx, &blob);
+       if (!NT_STATUS_IS_OK(status)) {
                return NULL;
        }
        ret = ldb_binary_encode(mem_ctx, blob);
diff --git a/librpc/ndr/libndr.h b/librpc/ndr/libndr.h
index e881a5c..dbdc0e6 100644
--- a/librpc/ndr/libndr.h
+++ b/librpc/ndr/libndr.h
@@ -536,6 +536,8 @@ 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);
 NTSTATUS NS_GUID_from_string(const char *s, struct GUID *guid);
diff --git a/librpc/ndr/uuid.c b/librpc/ndr/uuid.c
index df17d78..429a1b1 100644
--- a/librpc/ndr/uuid.c
+++ b/librpc/ndr/uuid.c
@@ -26,6 +26,36 @@
 #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
+*/
+_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
 */
 _PUBLIC_ NTSTATUS GUID_from_data_blob(const DATA_BLOB *s, struct GUID *guid)
@@ -89,21 +119,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)) {
@@ -275,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;
        }
diff --git a/source3/lib/ldb/samba/ldif_handlers.c 
b/source3/lib/ldb/samba/ldif_handlers.c
index 689a668..61619c5 100644
--- a/source3/lib/ldb/samba/ldif_handlers.c
+++ b/source3/lib/ldb/samba/ldif_handlers.c
@@ -146,8 +146,7 @@ static int ldif_read_objectGUID(struct ldb_context *ldb, 
void *mem_ctx,
                return -1;
        }
 
-       status = ndr_push_struct_blob(out, mem_ctx, &guid,
-                                     (ndr_push_flags_fn_t)ndr_push_GUID);
+       status = GUID_to_ndr_blob(&guid, mem_ctx, out);
        if (!NT_STATUS_IS_OK(status)) {
                return -1;
        }
diff --git a/source4/cldap_server/netlogon.c b/source4/cldap_server/netlogon.c
index 049b008..7072953 100644
--- a/source4/cldap_server/netlogon.c
+++ b/source4/cldap_server/netlogon.c
@@ -104,7 +104,6 @@ NTSTATUS fill_netlogon_samlogon_response(struct ldb_context 
*sam_ctx,
                if (domain_guid) {
                        struct GUID binary_guid;
                        struct ldb_val guid_val;
-                       enum ndr_err_code ndr_err;
 
                        /* By this means, we ensure we don't have funny stuff 
in the GUID */
 
@@ -114,10 +113,9 @@ NTSTATUS fill_netlogon_samlogon_response(struct 
ldb_context *sam_ctx,
                        }
 
                        /* And this gets the result into the binary format we 
want anyway */
-                       ndr_err = ndr_push_struct_blob(&guid_val, mem_ctx, 
NULL, &binary_guid,
-                                                      
(ndr_push_flags_fn_t)ndr_push_GUID);
-                       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
-                               return NT_STATUS_INVALID_PARAMETER;
+                       status = GUID_to_ndr_blob(&binary_guid, mem_ctx, 
&guid_val);
+                       if (!NT_STATUS_IS_OK(status)) {
+                               return status;
                        }
                        ret = ldb_search(sam_ctx, mem_ctx, &dom_res,
                                                 NULL, LDB_SCOPE_SUBTREE, 
diff --git a/source4/dsdb/common/util.c b/source4/dsdb/common/util.c
index 512230f..bfb2f0c 100644
--- a/source4/dsdb/common/util.c
+++ b/source4/dsdb/common/util.c
@@ -396,22 +396,15 @@ struct dom_sid *samdb_result_dom_sid(TALLOC_CTX *mem_ctx, 
const struct ldb_messa
 struct GUID samdb_result_guid(const struct ldb_message *msg, const char *attr)
 {
        const struct ldb_val *v;
-       enum ndr_err_code ndr_err;
        struct GUID guid;
-       TALLOC_CTX *mem_ctx;
-
-       ZERO_STRUCT(guid);
+       NTSTATUS status;
 
        v = ldb_msg_find_ldb_val(msg, attr);
        if (!v) return guid;
 
-       mem_ctx = talloc_named_const(NULL, 0, "samdb_result_guid");
-       if (!mem_ctx) return guid;
-       ndr_err = ndr_pull_struct_blob(v, mem_ctx, NULL, &guid,
-                                      (ndr_pull_flags_fn_t)ndr_pull_GUID);
-       talloc_free(mem_ctx);
-       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
-               return guid;
+       status = GUID_from_ndr_blob(v, &guid);
+       if (!NT_STATUS_IS_OK(status)) {
+               return GUID_zero();
        }
 
        return guid;
@@ -2296,16 +2289,12 @@ int dsdb_msg_add_guid(struct ldb_message *msg,
                const char *attr_name)
 {
        int ret;
-       enum ndr_err_code ndr_err;
        struct ldb_val v;
-
+       NTSTATUS status;
        TALLOC_CTX *tmp_ctx =  talloc_init("dsdb_msg_add_guid");
 
-       ndr_err = ndr_push_struct_blob(&v, tmp_ctx, 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_ctx, &v);
+       if (!NT_STATUS_IS_OK(status)) {
                ret = LDB_ERR_OPERATIONS_ERROR;
                goto done;
        }
@@ -2721,3 +2710,17 @@ int dsdb_functional_level(struct ldb_context *ldb)
        return *domainFunctionality;
 }
 
+/*
+  return a GUID from a extended DN structure
+ */
+NTSTATUS dsdb_get_extended_dn_guid(struct ldb_dn *dn, struct GUID *guid)
+{
+       const struct ldb_val *v;
+
+       v = ldb_dn_get_extended_component(dn, "GUID");
+       if (v == NULL) {
+               return NT_STATUS_OBJECT_NAME_NOT_FOUND;
+       }
+
+       return GUID_from_ndr_blob(v, guid);
+}
diff --git a/source4/dsdb/repl/replicated_objects.c 
b/source4/dsdb/repl/replicated_objects.c
index a8a93e4..1efbd29 100644
--- a/source4/dsdb/repl/replicated_objects.c
+++ b/source4/dsdb/repl/replicated_objects.c
@@ -39,7 +39,6 @@ static WERROR dsdb_convert_object_ex(struct ldb_context *ldb,
                                     struct dsdb_extended_replicated_object 
*out)
 {
        NTSTATUS nt_status;
-       enum ndr_err_code ndr_err;
        WERROR status;
        uint32_t i;
        struct ldb_message *msg;
@@ -202,12 +201,8 @@ static WERROR dsdb_convert_object_ex(struct ldb_context 
*ldb,
        whenChanged_s = ldb_timestring(msg, whenChanged_t);
        W_ERROR_HAVE_NO_MEMORY(whenChanged_s);
 
-       ndr_err = ndr_push_struct_blob(&guid_value, msg, 
-                                      lp_iconv_convenience(ldb_get_opaque(ldb, 
"loadparm")),
-                                      &in->object.identifier->guid,
-                                        (ndr_push_flags_fn_t)ndr_push_GUID);
-       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
-               nt_status = ndr_map_error2ntstatus(ndr_err);
+       nt_status = GUID_to_ndr_blob(&in->object.identifier->guid, msg, 
&guid_value);
+       if (!NT_STATUS_IS_OK(nt_status)) {
                return ntstatus_to_werror(nt_status);
        }
 
diff --git a/source4/dsdb/samdb/ldb_modules/extended_dn_out.c 
b/source4/dsdb/samdb/ldb_modules/extended_dn_out.c
index 1463e19..55dd693 100644
--- a/source4/dsdb/samdb/ldb_modules/extended_dn_out.c
+++ b/source4/dsdb/samdb/ldb_modules/extended_dn_out.c
@@ -202,8 +202,6 @@ static int handle_dereference_openldap(struct ldb_dn *dn,
        entryUUIDblob = ldb_msg_find_ldb_val(&fake_msg, "entryUUID");
        if (entryUUIDblob) {
                NTSTATUS status;
-               enum ndr_err_code ndr_err;
-               
                struct ldb_val guid_blob;
                struct GUID guid;
                
@@ -212,9 +210,8 @@ static int handle_dereference_openldap(struct ldb_dn *dn,
                if (!NT_STATUS_IS_OK(status)) {
                        return LDB_ERR_INVALID_DN_SYNTAX;
                }
-               ndr_err = ndr_push_struct_blob(&guid_blob, NULL, NULL, &guid,
-                                              
(ndr_push_flags_fn_t)ndr_push_GUID);
-               if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+               status = GUID_to_ndr_blob(&guid, dn, &guid_blob);
+               if (!NT_STATUS_IS_OK(status)) {
                        return LDB_ERR_INVALID_DN_SYNTAX;
                }
                
@@ -259,8 +256,6 @@ static int handle_dereference_fds(struct ldb_dn *dn,
        nsUniqueIdBlob = ldb_msg_find_ldb_val(&fake_msg, "nsUniqueId");
        if (nsUniqueIdBlob) {
                NTSTATUS status;
-               enum ndr_err_code ndr_err;
-               
                struct ldb_val guid_blob;
                struct GUID guid;
                
@@ -269,9 +264,8 @@ static int handle_dereference_fds(struct ldb_dn *dn,
                if (!NT_STATUS_IS_OK(status)) {
                        return LDB_ERR_INVALID_DN_SYNTAX;
                }
-               ndr_err = ndr_push_struct_blob(&guid_blob, NULL, NULL, &guid,
-                                               
(ndr_push_flags_fn_t)ndr_push_GUID);
-               if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+               status = GUID_to_ndr_blob(&guid, dn, &guid_blob);
+               if (!NT_STATUS_IS_OK(status)) {
                        return LDB_ERR_INVALID_DN_SYNTAX;
                }
                
diff --git a/source4/dsdb/samdb/ldb_modules/linked_attributes.c 
b/source4/dsdb/samdb/ldb_modules/linked_attributes.c
index bd9af55..f54693d 100644
--- a/source4/dsdb/samdb/ldb_modules/linked_attributes.c
+++ b/source4/dsdb/samdb/ldb_modules/linked_attributes.c
@@ -105,26 +105,24 @@ static struct la_context *linked_attributes_init(struct 
ldb_module *module,
  */
 static int la_guid_from_dn(struct la_context *ac, struct ldb_dn *dn, struct 
GUID *guid)
 {
-       const struct ldb_val *guid_val;
        int ret;
+       NTSTATUS status;
 
-       guid_val = ldb_dn_get_extended_component(dn, "GUID");
-       if (guid_val) {
-               /* there is a GUID embedded in the DN */
-               enum ndr_err_code ndr_err;
-               ndr_err = ndr_pull_struct_blob(guid_val, ac, NULL, guid,
-                                              
(ndr_pull_flags_fn_t)ndr_pull_GUID);
-               if (ndr_err != NDR_ERR_SUCCESS) {
-                       DEBUG(0,(__location__ ": Failed to parse GUID\n"));
-                       return LDB_ERR_OPERATIONS_ERROR;
-               }
-       } else {
-               ret = dsdb_find_guid_by_dn(ldb_module_get_ctx(ac->module), dn, 
guid);
-               if (ret != LDB_SUCCESS) {
-                       DEBUG(4,(__location__ ": Failed to find GUID for dn 
%s\n",
-                                ldb_dn_get_linearized(dn)));
-                       return ret;
-               }
+       status = dsdb_get_extended_dn_guid(dn, guid);
+       if (NT_STATUS_IS_OK(status)) {
+               return LDB_SUCCESS;
+       }
+       if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
+               DEBUG(4,(__location__ ": Unable to parse GUID for dn %s\n",
+                        ldb_dn_get_linearized(dn)));
+               return LDB_ERR_OPERATIONS_ERROR;
+       }
+
+       ret = dsdb_find_guid_by_dn(ldb_module_get_ctx(ac->module), dn, guid);
+       if (ret != LDB_SUCCESS) {
+               DEBUG(4,(__location__ ": Failed to find GUID for dn %s\n",
+                        ldb_dn_get_linearized(dn)));
+               return ret;
        }
        return LDB_SUCCESS;
 }
diff --git a/source4/dsdb/samdb/ldb_modules/simple_ldap_map.c 
b/source4/dsdb/samdb/ldb_modules/simple_ldap_map.c
index 8d3c78d..4340224 100644
--- a/source4/dsdb/samdb/ldb_modules/simple_ldap_map.c
+++ b/source4/dsdb/samdb/ldb_modules/simple_ldap_map.c
@@ -44,16 +44,14 @@ static struct ldb_val encode_guid(struct ldb_module 
*module, TALLOC_CTX *ctx, co
 {
        struct GUID guid;
        NTSTATUS status = GUID_from_data_blob(val, &guid);
-       enum ndr_err_code ndr_err;
        struct ldb_val out = data_blob(NULL, 0);
 
        if (!NT_STATUS_IS_OK(status)) {
                return out;
        }
-       ndr_err = ndr_push_struct_blob(&out, ctx, NULL, &guid,
-                                      (ndr_push_flags_fn_t)ndr_push_GUID);
-       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
-               return out;
+       status = GUID_to_ndr_blob(&guid, ctx, &out);
+       if (!NT_STATUS_IS_OK(status)) {
+               return data_blob(NULL, 0);
        }
 
        return out;
@@ -74,16 +72,14 @@ static struct ldb_val encode_ns_guid(struct ldb_module 
*module, TALLOC_CTX *ctx,
 {
        struct GUID guid;
        NTSTATUS status = NS_GUID_from_string((char *)val->data, &guid);
-       enum ndr_err_code ndr_err;
        struct ldb_val out = data_blob(NULL, 0);
 
        if (!NT_STATUS_IS_OK(status)) {
                return out;
        }
-       ndr_err = ndr_push_struct_blob(&out, ctx, NULL, &guid,
-                                      (ndr_push_flags_fn_t)ndr_push_GUID);
-       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
-               return out;
+       status = GUID_to_ndr_blob(&guid, ctx, &out);
+       if (!NT_STATUS_IS_OK(status)) {
+               return data_blob(NULL, 0);
        }
 
        return out;
diff --git a/source4/dsdb/schema/schema_init.c 
b/source4/dsdb/schema/schema_init.c
index 069da95..4af3683 100644
--- a/source4/dsdb/schema/schema_init.c
+++ b/source4/dsdb/schema/schema_init.c
@@ -975,12 +975,8 @@ static struct drsuapi_DsReplicaAttribute 
*dsdb_find_object_attr_name(struct dsdb
        if (_a && _a->value_ctr.num_values >= 1 \
            && _a->value_ctr.values[0].blob \
            && _a->value_ctr.values[0].blob->length == 16) { \
-               enum ndr_err_code _ndr_err; \
-               _ndr_err = 
ndr_pull_struct_blob_all(_a->value_ctr.values[0].blob, \
-                                                     mem_ctx, 
s->iconv_convenience, &(p)->elem, \
-                                                     
(ndr_pull_flags_fn_t)ndr_pull_GUID); \
-               if (!NDR_ERR_CODE_IS_SUCCESS(_ndr_err)) { \
-                       NTSTATUS _nt_status = ndr_map_error2ntstatus(_ndr_err); 
\
+               NTSTATUS _nt_status = 
GUID_from_ndr_blob(_a->value_ctr.values[0].blob, &(p)->elem); \
+               if (!NT_STATUS_IS_OK(_nt_status)) { \
                        return ntstatus_to_werror(_nt_status); \
                } \
        } else { \
diff --git a/source4/dsdb/schema/schema_query.c 
b/source4/dsdb/schema/schema_query.c
index 3d46cfb..0a58f7a 100644
--- a/source4/dsdb/schema/schema_query.c
+++ b/source4/dsdb/schema/schema_query.c
@@ -22,34 +22,7 @@
 
 #include "includes.h"
 #include "dsdb/samdb/samdb.h"
-
-/* a binary array search, where the array is an array of pointers to 
structures,
-   and we want to find a match for 'target' on 'field' in those structures.
-
-   Inputs:
-      array:          base pointer to an array of structures
-      arrray_size:    number of elements in the array
-      field:          the name of the field in the structure we are keying off


-- 
Samba Shared Repository

Reply via email to