[SCM] Samba Shared Repository - branch master updated

Andrew Bartlett abartlet at samba.org
Wed Nov 11 22:39:42 MST 2009


The branch, master has been updated
       via  bbe4a9c... s4:repl_meta_data Parse linked attributes with schema syntaxes
       via  a9f6a56... s4:dsdb/schema Add more unit tests for DN+Binary syntaxes
       via  95a12cd... s4:torture Use (some) torture_assert() calls in RPC-DSSYNC test
       via  693ddf5... s4:dsdb Improve debug message in extended_dn_out
       via  06b234e... s4:torture Remove _drs_util_verify_attids() from RPC-DSSYNC
       via  6d1e609... s4:torture/dsdb Add verification of the push-to-LDB functions in RPC-DSSYNC
       via  30a0800... s4:torture Add const
       via  ae72153... s4:ldb Allow ldb_msg_canonicalize to handle empty elements
       via  081d573... s4:dsdb/schema Allow a schema set when bound against a remote LDAP server
       via  5940ca6... s4:ldb Don't segfault if we somehow get an unknown extended dn element
       via  716bba5... s4:ldb Change ldb_request_add_control to the normal 'for loop' pattern
       via  87e984f... s4:torture Convert RPC-DSSYNC test to use LDB rather than raw LDAP
       via  1012b80... NET-API-BECOME-DC: resolve the host name to an address before calling libnet_BecomeDC and libnet_UnbecomeDC()
       via  2a60171... s4:dsdb Add expected value tests for most DRS syntax conversions
       via  9ba1870... s4:Fix regression in dsdb_dn code - all parses of the DN would be rejected
       via  6b0b3fe... s4:provision Add C binding to get at the generate schema
       via  6437c38... s4:provision Remove unused 'sambadn' parameter
       via  df7546a... s4:dsdb/repl Split the 'convert' or 'commit' stages in the DRS import
       via  d656380... s4:dsdb/schema Simplify schema loading from ldb messages
       via  d053584... s4:vampire Print error message when we fail on the CLDAP ping
       via  6fd6dc1... s4:dsdb Cosmetic fixes found by metze in review of dsdb_dn changes
       via  4e2b4be... s4:dsdb Ensure we allow 'odd' lengths for DN+String
       via  d6d0c23... s4:ldb Add Well Known GUID (WKGUID) tests to ldap.py
       via  da1ac55... s4:dsdb Add extensive tests for the behaviour of dsdb_dn
       via  f5890dd... s4:ldb Remove DN+Binary code from the core ldb_dn
       via  f0d43e9... s4:dsdb Use new dsdb_dn code in LDB modules and Samba4 schema
       via  973197c... s4:ldb-samba Use new ldb_any_comparison helper function in ldb-samba
       via  390ac7d... s4:dsdb Add new dsdb_dn to handle DN+Binary and DN+String
       via  3abc3e7... s4:ldb Add a helper function for 'canonicalise' both strings base compares
       via  fd5174e... lib/util Split data_blob_hex_string() into upper and lower
      from  a8769e6... Second part of bugfix for 6865 - acl_xattr module: Has dependency that inherit acls = yes or xattrs are removed. We also need dos filemode = true set as well. Jeremy.

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


- Log -----------------------------------------------------------------
commit bbe4a9cf0fb09a0a2348149e4fb43e3c74ed3abf
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Thu Nov 12 15:39:17 2009 +1100

    s4:repl_meta_data Parse linked attributes with schema syntaxes
    
    The bug here was that by assuming all linked attributes were 'normal
    DNs', we would miss the binary portion of DN+Binary.
    
    This patch then has us reparse the string to determine it's GUID, for
    the GUID lookup, but maintains the binary porition into the on-disk
    format.
    
    Andrew Bartlett

commit a9f6a56227a067490ac8fcd41321ec4d19333da7
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Thu Nov 12 15:38:16 2009 +1100

    s4:dsdb/schema Add more unit tests for DN+Binary syntaxes

commit 95a12cdf21ba86f460c2ffa51223e8564fd25014
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Thu Nov 12 15:37:34 2009 +1100

    s4:torture Use (some) torture_assert() calls in RPC-DSSYNC test

commit 693ddf5ba0d5e7a9fcc0f9727ff7f78b83d18343
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Thu Nov 12 15:35:54 2009 +1100

    s4:dsdb Improve debug message in extended_dn_out

commit 06b234e8118166ded401284eaf3a2227ec56eae7
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Thu Nov 12 08:08:26 2009 +1100

    s4:torture Remove _drs_util_verify_attids() from RPC-DSSYNC
    
    I'm satisfied that the task this test does is already done by the time
    we map the incoming schema, and process the objects.  If we have the
    OID mapping wrong or incomplete, we will get any errors this test
    found errors there.
    
    (And this dramaticly reduces the test time, so we can now add
    RPC-DSSYNC to 'make test').
    
    Andrew Bartlett

commit 6d1e60987b34db4850754f33b62c79284eb53b09
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Wed Nov 11 22:31:06 2009 +1100

    s4:torture/dsdb Add verification of the push-to-LDB functions in RPC-DSSYNC
    
    This is done by comparing the values against the remote host's LDAP
    server.
    
    Andrew Bartlett

commit 30a08005ca1a15e7dee88f482894b68fea2c1f2f
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Wed Nov 11 19:27:30 2009 +1100

    s4:torture Add const

commit ae72153daaa5dc50751a35af22533a666c65eb42
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Wed Nov 11 19:26:28 2009 +1100

    s4:ldb Allow ldb_msg_canonicalize to handle empty elements
    
    (These are deliberately there in DRS replication).
    
    Andrew Bartlett

commit 081d57345fad546d73f9ec97e61f59c64cefee58
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Wed Nov 11 19:25:32 2009 +1100

    s4:dsdb/schema Allow a schema set when bound against a remote LDAP server

commit 5940ca60e23d142e4d3d0b2ce12f191663147d03
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Wed Nov 11 19:24:48 2009 +1100

    s4:ldb Don't segfault if we somehow get an unknown extended dn element

commit 716bba545729dbb46631bf233c1023576de54926
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Wed Nov 11 19:24:08 2009 +1100

    s4:ldb Change ldb_request_add_control to the normal 'for loop' pattern

commit 87e984f0bd893abd65cf36f74162efed0d4930ca
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Wed Nov 11 12:56:55 2009 +1100

    s4:torture Convert RPC-DSSYNC test to use LDB rather than raw LDAP
    
    (This should make it easier to do more 'compare DRS with LDAP'
    operations, as LDB is an easier interface to program.)
    
    Andrew Bartlett

commit 1012b806a7d54e8d442bd14573d9c00747a23f74
Author: Stefan Metzmacher <metze at samba.org>
Date:   Tue Nov 10 12:49:48 2009 +0100

    NET-API-BECOME-DC: resolve the host name to an address before calling
    libnet_BecomeDC and libnet_UnbecomeDC()
    
    We're supposed to pass in source_dsa_address...
    
    metze

commit 2a601719f219686b3a3b38b61b8f549941ecf632
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Tue Nov 10 15:21:40 2009 +1100

    s4:dsdb Add expected value tests for most DRS syntax conversions
    
    I've left out those for which I could not find an expected value in my
    default Windows 2003 server's database, and the values that rely on
    the current prefix map at the time.
    
    Andrew Bartlett

commit 9ba1870fb9ae784b429b8e13b4ab0cc3def06aee
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Tue Nov 10 15:20:07 2009 +1100

    s4:Fix regression in dsdb_dn code - all parses of the DN would be rejected
    
    This is most likely the cause of the DRS replication failures I
    observed with my changes.
    
    Andrew Bartlett

commit 6b0b3fed3127dd2da15a79eabea62708e82cc941
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Tue Nov 10 15:18:52 2009 +1100

    s4:provision Add C binding to get at the generate schema
    
    This will allow us to do local tests against that schema

commit 6437c38aeb5880b18728e65e1c19edf08ac5e4e9
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Tue Nov 10 15:18:01 2009 +1100

    s4:provision Remove unused 'sambadn' parameter

commit df7546ac16db6e802f8c8ef7bac6f01acc9233b2
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Mon Nov 9 21:26:02 2009 +1100

    s4:dsdb/repl Split the 'convert' or 'commit' stages in the DRS import
    
    This will allow us in future to do tests on the LDB values we generate
    from the DRS replication.
    
    Andrew Bartlett

commit d6563801d1783a8cb1b9740878d0a07d40085f32
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Mon Nov 9 20:40:21 2009 +1100

    s4:dsdb/schema Simplify schema loading from ldb messages
    
    It turns out that we always add the class/attribute to the schema.

commit d053584443613177bc8e7e18c594378baf9df34d
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Mon Nov 9 20:31:42 2009 +1100

    s4:vampire Print error message when we fail on the CLDAP ping
    
    Andrew Bartlett

commit 6fd6dc10897763670bf116746a6d8c2041b2bacd
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Sat Nov 7 12:07:06 2009 +1100

    s4:dsdb Cosmetic fixes found by metze in review of dsdb_dn changes
    
    These changes include reworking the code to call ldb_module_get_ctx()
    less often (avoid the function calls, particularly during the step
    into a complex function).
    
    Andrew Bartlett

commit 4e2b4be9d3bd406a303b74c8d5ebd56714a337ae
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Sat Nov 7 12:06:11 2009 +1100

    s4:dsdb Ensure we allow 'odd' lengths for DN+String
    
    (Found in a code review by metze)
    
    Andrew Bartlett

commit d6d0c23d49fd299d292b30338a9fc0ffcdaf1f2e
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Fri Nov 6 17:00:05 2009 +1100

    s4:ldb Add Well Known GUID (WKGUID) tests to ldap.py

commit da1ac55bc18b09f0a0e5756cc3fde45248f1d146
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Fri Nov 6 16:40:07 2009 +1100

    s4:dsdb Add extensive tests for the behaviour of dsdb_dn

commit f5890ddd83df35ff3fe4088c9b65858405ba7e4a
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Thu Nov 5 17:06:45 2009 +1100

    s4:ldb Remove DN+Binary code from the core ldb_dn
    
    This is now in dsdb_dn.  Removing this to a specific wrapper avoids a
    number of bugs where Binary DNs were being handled incorrectly.
    
    This reverts much of tridge's commit
    fd22e0304782e20b9bbb29464b6c745d409ff4c6
    
    Andrew Bartlett

commit f0d43e9e562bfd7c254a9b2446fb11f85186b45e
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Thu Nov 5 17:04:10 2009 +1100

    s4:dsdb Use new dsdb_dn code in LDB modules and Samba4 schema
    
    This converts the code from using the binary DN code in ldb_dn to
    using a special Samba-specfic wrapper around ldb_dn.
    
    We also use the dsdb_dn code for DN+Binary and DN+String comparisons
    (changed from treating them as Binary blobs)
    
    Andrew Bartlett

commit 973197cd9ded571ff02996cb5c133435a35976c5
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Thu Nov 5 17:00:20 2009 +1100

    s4:ldb-samba Use new ldb_any_comparison helper function in ldb-samba

commit 390ac7d3063fdc64d64ecb498eb0c9b4626e2eb8
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Thu Nov 5 16:57:20 2009 +1100

    s4:dsdb Add new dsdb_dn to handle DN+Binary and DN+String
    
    This aims to replace (and is based on) the code in ldb_dn.c.  It is
    however much stricter in the DNs it will accept.
    
    Andrew Bartlett

commit 3abc3e7a3a4e3833c8c08cc21deeaae174887f7f
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Thu Nov 5 16:56:05 2009 +1100

    s4:ldb Add a helper function for 'canonicalise' both strings base compares
    
    This will help simplify boilerplate comparison functions where we
    don't have a shortcut way to compare.
    
    Andrew Bartlett

commit fd5174e88ca1727a91d6dc9bf9bd898ff9087fe8
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Wed Nov 4 17:42:53 2009 +1100

    lib/util Split data_blob_hex_string() into upper and lower
    
    Rather than have a repeat of the bugs we found at the plugfest where
    hexidecimal strings must be in upper or lower case in particular
    places, ensure that each caller chooses which case they want.
    
    This reverts most of the callers back to upper case, as things were
    before tridge's patch.  The critical call in the extended DN code is
    of course handled in lower case.
    
    Andrew Bartlett

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

Summary of changes:
 lib/util/data_blob.c                               |   19 +-
 lib/util/data_blob.h                               |    7 +-
 lib/util/tests/data_blob.c                         |    3 +-
 librpc/ndr/ndr_drsuapi.c                           |    2 +-
 librpc/ndr/uuid.c                                  |    2 +-
 librpc/rpc/binding.c                               |    2 +-
 source4/dsdb/common/dsdb_dn.c                      |  325 +++++++++++++++++
 source4/dsdb/common/dsdb_dn.h                      |   16 +
 source4/dsdb/common/tests/dsdb_dn.c                |  357 +++++++++++++++++++
 source4/dsdb/config.mk                             |    3 +-
 source4/dsdb/repl/drepl_out_helpers.c              |   30 +-
 source4/dsdb/repl/replicated_objects.c             |   63 ++--
 source4/dsdb/samdb/ldb_modules/extended_dn_out.c   |   75 +++--
 source4/dsdb/samdb/ldb_modules/extended_dn_store.c |  101 ++++--
 source4/dsdb/samdb/ldb_modules/password_hash.c     |   10 +-
 source4/dsdb/samdb/ldb_modules/repl_meta_data.c    |   83 +++--
 source4/dsdb/samdb/samdb.h                         |    1 +
 source4/dsdb/schema/schema_init.c                  |  109 +++----
 source4/dsdb/schema/schema_set.c                   |   76 ++--
 source4/dsdb/schema/schema_syntax.c                |   40 +-
 source4/dsdb/schema/tests/schema_syntax.c          |  154 ++++++++
 source4/lib/ldb-samba/ldif_handlers.c              |   60 +---
 source4/lib/ldb/common/attrib_handlers.c           |   27 ++
 source4/lib/ldb/common/ldb_controls.c              |    3 +-
 source4/lib/ldb/common/ldb_dn.c                    |  270 +--------------
 source4/lib/ldb/common/ldb_msg.c                   |    2 +-
 source4/lib/ldb/include/ldb_module.h               |    6 +
 source4/lib/ldb/tests/python/ldap.py               |   17 +
 source4/lib/registry/util.c                        |    2 +-
 source4/libnet/libnet_become_dc.c                  |    9 +-
 source4/libnet/libnet_vampire.c                    |   63 ++--
 source4/param/provision.c                          |   61 ++++
 source4/param/provision.h                          |    2 +
 source4/scripting/python/samba/provision.py        |   12 +-
 source4/scripting/python/samba/schema.py           |   25 ++-
 source4/selftest/skip                              |    1 -
 source4/torture/drs/drs_util.c                     |    2 +-
 source4/torture/ldap/schema.c                      |   21 +-
 source4/torture/libnet/libnet_BecomeDC.c           |   82 +++--
 source4/torture/local/config.mk                    |    8 +-
 source4/torture/local/local.c                      |    2 +
 source4/torture/rpc/dssync.c                       |  365 +++++++++++++-------
 source4/torture/rpc/samsync.c                      |    4 +-
 43 files changed, 1727 insertions(+), 795 deletions(-)
 create mode 100644 source4/dsdb/common/dsdb_dn.c
 create mode 100644 source4/dsdb/common/dsdb_dn.h
 create mode 100644 source4/dsdb/common/tests/dsdb_dn.c
 create mode 100644 source4/dsdb/schema/tests/schema_syntax.c


Changeset truncated at 500 lines:

diff --git a/lib/util/data_blob.c b/lib/util/data_blob.c
index 825d8cf..6e7557f 100644
--- a/lib/util/data_blob.c
+++ b/lib/util/data_blob.c
@@ -153,7 +153,7 @@ _PUBLIC_ int data_blob_cmp(const DATA_BLOB *d1, const DATA_BLOB *d2)
 /**
 print the data_blob as hex string
 **/
-_PUBLIC_ char *data_blob_hex_string(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob)
+_PUBLIC_ char *data_blob_hex_string_lower(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob)
 {
 	int i;
 	char *hex_string;
@@ -173,6 +173,23 @@ _PUBLIC_ char *data_blob_hex_string(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob)
 	return hex_string;
 }
 
+_PUBLIC_ char *data_blob_hex_string_upper(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob)
+{
+	int i;
+	char *hex_string;
+
+	hex_string = talloc_array(mem_ctx, char, (blob->length*2)+1);
+	if (!hex_string) {
+		return NULL;
+	}
+
+	for (i = 0; i < blob->length; i++)
+		slprintf(&hex_string[i*2], 3, "%02X", blob->data[i]);
+
+	hex_string[(blob->length*2)] = '\0';
+	return hex_string;
+}
+
 /**
   useful for constructing data blobs in test suites, while
   avoiding const warnings
diff --git a/lib/util/data_blob.h b/lib/util/data_blob.h
index ffde51c..c294533 100644
--- a/lib/util/data_blob.h
+++ b/lib/util/data_blob.h
@@ -96,7 +96,12 @@ _PUBLIC_ int data_blob_cmp(const DATA_BLOB *d1, const DATA_BLOB *d2);
 /**
 print the data_blob as hex string
 **/
-_PUBLIC_ char *data_blob_hex_string(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob);
+_PUBLIC_ char *data_blob_hex_string_upper(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob);
+
+/**
+print the data_blob as hex string
+**/
+_PUBLIC_ char *data_blob_hex_string_lower(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob);
 
 /**
   useful for constructing data blobs in test suites, while
diff --git a/lib/util/tests/data_blob.c b/lib/util/tests/data_blob.c
index f0b02b8..53330a4 100644
--- a/lib/util/tests/data_blob.c
+++ b/lib/util/tests/data_blob.c
@@ -78,7 +78,8 @@ static bool test_cmp(struct torture_context *tctx)
 static bool test_hex_string(struct torture_context *tctx)
 {
 	DATA_BLOB a = data_blob_string_const("\xC\xA\xF\xE");
-	torture_assert_str_equal(tctx, data_blob_hex_string(tctx, &a), "0c0a0f0e", "hex string");
+	torture_assert_str_equal(tctx, data_blob_hex_string_lower(tctx, &a), "0c0a0f0e", "hex string");
+	torture_assert_str_equal(tctx, data_blob_hex_string_upper(tctx, &a), "0C0A0F0E", "hex string");
 	return true;
 }
 
diff --git a/librpc/ndr/ndr_drsuapi.c b/librpc/ndr/ndr_drsuapi.c
index bfc3c75..15f2f84 100644
--- a/librpc/ndr/ndr_drsuapi.c
+++ b/librpc/ndr/ndr_drsuapi.c
@@ -91,7 +91,7 @@ _PUBLIC_ void ndr_print_drsuapi_DsReplicaOID(struct ndr_print *ndr, const char *
 	if (r->binary_oid) {
 		char *partial_oid = NULL;
 		DATA_BLOB oid_blob = data_blob_const(r->binary_oid, r->length);
-		char *hex_str = data_blob_hex_string(ndr, &oid_blob);
+		char *hex_str = data_blob_hex_string_upper(ndr, &oid_blob);
 		ber_read_partial_OID_String(ndr, oid_blob, (const char **)&partial_oid);
 		ndr->depth++;
 		ndr->print(ndr, "%-25s: 0x%s (%s)", "binary_oid", hex_str, partial_oid);
diff --git a/librpc/ndr/uuid.c b/librpc/ndr/uuid.c
index 004a8d3..df17d78 100644
--- a/librpc/ndr/uuid.c
+++ b/librpc/ndr/uuid.c
@@ -291,7 +291,7 @@ _PUBLIC_ char *GUID_hexstring(TALLOC_CTX *mem_ctx, const struct GUID *guid)
 		return NULL;
 	}
 
-	ret = data_blob_hex_string(mem_ctx, &guid_blob);
+	ret = data_blob_hex_string_upper(mem_ctx, &guid_blob);
 	talloc_free(tmp_mem);
 	return ret;
 }
diff --git a/librpc/rpc/binding.c b/librpc/rpc/binding.c
index 7344714..20c3a38 100644
--- a/librpc/rpc/binding.c
+++ b/librpc/rpc/binding.c
@@ -113,7 +113,7 @@ const char *epm_floor_string(TALLOC_CTX *mem_ctx, struct epm_floor *epm_floor)
 				return talloc_asprintf(mem_ctx, " uuid %s/0x%02x", uuidstr, syntax.if_version);
 			} else { /* IPX */
 				return talloc_asprintf(mem_ctx, "IPX:%s", 
-						data_blob_hex_string(mem_ctx, &epm_floor->rhs.uuid.unknown));
+						data_blob_hex_string_upper(mem_ctx, &epm_floor->rhs.uuid.unknown));
 			}
 
 		case EPM_PROTOCOL_NCACN:
diff --git a/source4/dsdb/common/dsdb_dn.c b/source4/dsdb/common/dsdb_dn.c
new file mode 100644
index 0000000..dbc63a9
--- /dev/null
+++ b/source4/dsdb/common/dsdb_dn.c
@@ -0,0 +1,325 @@
+/* 
+   Unix SMB/CIFS implementation.
+   Samba utility functions
+
+   Copyright (C) Andrew Tridgell 2009
+   Copyright (C) Andrew Bartlett <abartlet at samba.org> 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/>.
+*/
+
+#include "includes.h"
+#include "dsdb/samdb/samdb.h"
+#include "lib/ldb/include/ldb_module.h"
+
+enum dsdb_dn_format dsdb_dn_oid_to_format(const char *oid) 
+{
+	if (strcmp(oid, LDB_SYNTAX_DN) == 0) {
+		return DSDB_NORMAL_DN;
+	} else if (strcmp(oid, DSDB_SYNTAX_BINARY_DN) == 0) {
+		return DSDB_BINARY_DN;
+	} else if (strcmp(oid, DSDB_SYNTAX_STRING_DN) == 0) {
+		return DSDB_STRING_DN;
+	} else {
+		return DSDB_INVALID_DN;
+	}
+}
+
+static struct dsdb_dn *dsdb_dn_construct_internal(TALLOC_CTX *mem_ctx, 
+						  struct ldb_dn *dn, 
+						  DATA_BLOB extra_part, 
+						  enum dsdb_dn_format dn_format, 
+						  const char *oid) 
+{
+	struct dsdb_dn *dsdb_dn = talloc(mem_ctx, struct dsdb_dn);
+	if (!dsdb_dn) {
+		return NULL;
+	}
+	dsdb_dn->dn = talloc_steal(dsdb_dn, dn);
+	dsdb_dn->extra_part = extra_part;
+	dsdb_dn->dn_format = dn_format;
+	/* Look to see if this attributeSyntax is a DN */
+	if (dsdb_dn->dn_format == DSDB_INVALID_DN) {
+		talloc_free(dsdb_dn);
+		return NULL;
+	}
+
+	dsdb_dn->oid = oid;
+	talloc_steal(dsdb_dn, extra_part.data);
+	return dsdb_dn;
+}
+
+struct dsdb_dn *dsdb_dn_construct(TALLOC_CTX *mem_ctx, struct ldb_dn *dn, DATA_BLOB extra_part, 
+				  const char *oid) 
+{
+	enum dsdb_dn_format dn_format = dsdb_dn_oid_to_format(oid);
+	return dsdb_dn_construct_internal(mem_ctx, dn, extra_part, dn_format, oid);
+}
+
+struct dsdb_dn *dsdb_dn_parse(TALLOC_CTX *mem_ctx, struct ldb_context *ldb, 
+			      const struct ldb_val *dn_blob, const char *dn_oid)
+{
+	struct dsdb_dn *dsdb_dn;
+	struct ldb_dn *dn;
+	const char *data;
+	size_t len;
+	TALLOC_CTX *tmp_ctx;
+	char *p1;
+	char *p2;
+	uint32_t blen;
+	struct ldb_val bval;
+	struct ldb_val dval;
+	char *dn_str;
+
+	enum dsdb_dn_format dn_format = dsdb_dn_oid_to_format(dn_oid);
+	switch (dn_format) {
+	case DSDB_INVALID_DN:
+		return NULL;
+	case DSDB_NORMAL_DN:
+	{
+		dn = ldb_dn_from_ldb_val(mem_ctx, ldb, dn_blob);
+		if (!dn || !ldb_dn_validate(dn)) {
+			talloc_free(dn);
+			return NULL;
+		}
+		return dsdb_dn_construct_internal(mem_ctx, dn, data_blob_null, dn_format, dn_oid);
+	}
+	case DSDB_BINARY_DN:
+		if (dn_blob->length < 2 || dn_blob->data[0] != 'B' || dn_blob->data[1] != ':') {
+			return NULL;
+		}
+		break;
+	case DSDB_STRING_DN:
+		if (dn_blob->length < 2 || dn_blob->data[0] != 'S' || dn_blob->data[1] != ':') {
+			return NULL;
+		}
+		break;
+	default:
+		return NULL;
+	}
+
+	if (dn_blob && dn_blob->data
+	    && (strlen((const char*)dn_blob->data) != dn_blob->length)) {
+		/* The RDN must not contain a character with value 0x0 */
+		return NULL;
+	}
+		
+	if (!dn_blob->data || dn_blob->length == 0) {
+		return NULL;
+	}
+		
+	tmp_ctx = talloc_new(mem_ctx);
+	if (tmp_ctx == NULL) {
+		return NULL;
+	}
+		
+	data = (const char *)dn_blob->data;
+
+	len = dn_blob->length - 2;
+	p1 = talloc_strndup(tmp_ctx, (const char *)dn_blob->data + 2, len);
+	if (!p1) {
+		goto failed;
+	}
+
+	errno = 0;
+	blen = strtoul(p1, &p2, 10);
+	if (errno != 0) {
+		DEBUG(10, (__location__ ": failed\n"));
+		goto failed;
+	}
+	if (p2 == NULL) {
+		DEBUG(10, (__location__ ": failed\n"));
+		goto failed;
+	}
+	if (p2[0] != ':') {
+		DEBUG(10, (__location__ ": failed\n"));
+		goto failed;
+	}
+	len -= PTR_DIFF(p2,p1);//???
+	p1 = p2+1;
+	len--;
+		
+	if (blen >= len) {
+		DEBUG(10, (__location__ ": blen=%u len=%u\n", (unsigned)blen, (unsigned)len));
+		goto failed;
+	}
+		
+	p2 = p1 + blen;
+	if (p2[0] != ':') {
+		DEBUG(10, (__location__ ": %s", p2));
+		goto failed;
+	}
+	dn_str = p2+1;
+		
+		
+	switch (dn_format) {
+	case DSDB_BINARY_DN:
+		if ((blen % 2 != 0)) {
+			DEBUG(10, (__location__ ": blen=%u - not an even number\n", (unsigned)blen));
+			goto failed;
+		}
+		
+		if (blen >= 2) {
+			bval.length = (blen/2)+1;
+			bval.data = talloc_size(tmp_ctx, bval.length);
+			if (bval.data == NULL) {
+				DEBUG(10, (__location__ ": err\n"));
+				goto failed;
+			}
+			bval.data[bval.length-1] = 0;
+		
+			bval.length = strhex_to_str((char *)bval.data, bval.length,
+						    p1, blen);
+			if (bval.length != (blen / 2)) {
+				DEBUG(10, (__location__ ": non hexidecimal characters found in binary prefix\n"));
+				goto failed;
+			}
+		} else {
+			bval = data_blob_null;
+		}
+
+		break;
+	case DSDB_STRING_DN:
+		bval = data_blob(p1, blen);
+		break;
+	default:
+		/* never reached */
+		return NULL;
+	}
+	
+
+	dval.data = (uint8_t *)dn_str;
+	dval.length = strlen(dn_str);
+		
+	dn = ldb_dn_from_ldb_val(tmp_ctx, ldb, &dval);
+	if (!dn || !ldb_dn_validate(dn)) {
+		DEBUG(10, (__location__ ": err\n"));
+		goto failed;
+	}
+		
+	dsdb_dn = dsdb_dn_construct(mem_ctx, dn, bval, dn_oid);
+		
+	return dsdb_dn;
+
+failed:
+	talloc_free(tmp_ctx);
+	return NULL;
+}
+
+
+static char *dsdb_dn_get_with_postfix(TALLOC_CTX *mem_ctx, 
+				     struct dsdb_dn *dsdb_dn,
+				     const char *postfix)
+{
+	if (!postfix) {
+		return NULL;
+	}
+
+	switch (dsdb_dn->dn_format) {
+	case DSDB_NORMAL_DN:
+	{
+		return talloc_strdup(mem_ctx, postfix);
+	}
+	case DSDB_BINARY_DN:
+	{
+		char *hexstr = data_blob_hex_string_upper(mem_ctx, &dsdb_dn->extra_part);
+	
+		char *p = talloc_asprintf(mem_ctx, "B:%u:%s:%s", (unsigned)(dsdb_dn->extra_part.length*2), hexstr, 
+					  postfix);
+		talloc_free(hexstr);
+		return p;
+	}
+	case DSDB_STRING_DN:
+	{
+		return talloc_asprintf(mem_ctx, "S:%u:%*.*s:%s", 
+				    (unsigned)(dsdb_dn->extra_part.length), 
+				    (int)(dsdb_dn->extra_part.length), 
+				    (int)(dsdb_dn->extra_part.length), 
+				    (const char *)dsdb_dn->extra_part.data, 
+				    postfix);
+	}
+	default:
+		return NULL;
+	}
+}
+
+char *dsdb_dn_get_linearized(TALLOC_CTX *mem_ctx, 
+			      struct dsdb_dn *dsdb_dn)
+{
+	const char *postfix = ldb_dn_get_linearized(dsdb_dn->dn);
+	return dsdb_dn_get_with_postfix(mem_ctx, dsdb_dn, postfix);
+}
+
+char *dsdb_dn_get_casefold(TALLOC_CTX *mem_ctx, 
+			   struct dsdb_dn *dsdb_dn) 
+{
+	const char *postfix = ldb_dn_get_casefold(dsdb_dn->dn);
+	return dsdb_dn_get_with_postfix(mem_ctx, dsdb_dn, postfix);
+}
+
+char *dsdb_dn_get_extended_linearized(TALLOC_CTX *mem_ctx, 
+				      struct dsdb_dn *dsdb_dn,
+				      int mode)
+{
+	char *postfix = ldb_dn_get_extended_linearized(mem_ctx, dsdb_dn->dn, mode);
+	char *ret = dsdb_dn_get_with_postfix(mem_ctx, dsdb_dn, postfix);
+	talloc_free(postfix);
+	return ret;
+}
+
+int dsdb_dn_binary_canonicalise(struct ldb_context *ldb, void *mem_ctx,
+				const struct ldb_val *in, struct ldb_val *out)
+{
+	struct dsdb_dn *dsdb_dn = dsdb_dn_parse(mem_ctx, ldb, in, DSDB_SYNTAX_BINARY_DN);
+	
+	if (!dsdb_dn) {
+		return -1;
+	}
+	*out = data_blob_string_const(dsdb_dn_get_casefold(mem_ctx, dsdb_dn));
+	talloc_free(dsdb_dn);
+	if (!out->data) {
+		return -1;
+	}
+	return 0;
+}
+
+int dsdb_dn_binary_comparison(struct ldb_context *ldb, void *mem_ctx,
+				     const struct ldb_val *v1,
+				     const struct ldb_val *v2)
+{
+	return ldb_any_comparison(ldb, mem_ctx, dsdb_dn_binary_canonicalise, v1, v2);
+}
+
+int dsdb_dn_string_canonicalise(struct ldb_context *ldb, void *mem_ctx,
+				const struct ldb_val *in, struct ldb_val *out)
+{
+	struct dsdb_dn *dsdb_dn = dsdb_dn_parse(mem_ctx, ldb, in, DSDB_SYNTAX_STRING_DN);
+	
+	if (!dsdb_dn) {
+		return -1;
+	}
+	*out = data_blob_string_const(dsdb_dn_get_casefold(mem_ctx, dsdb_dn));
+	talloc_free(dsdb_dn);
+	if (!out->data) {
+		return -1;
+	}
+	return 0;
+}
+
+int dsdb_dn_string_comparison(struct ldb_context *ldb, void *mem_ctx,
+				     const struct ldb_val *v1,
+				     const struct ldb_val *v2)
+{
+	return ldb_any_comparison(ldb, mem_ctx, dsdb_dn_string_canonicalise, v1, v2);
+}
diff --git a/source4/dsdb/common/dsdb_dn.h b/source4/dsdb/common/dsdb_dn.h
new file mode 100644
index 0000000..55b5c0b
--- /dev/null
+++ b/source4/dsdb/common/dsdb_dn.h
@@ -0,0 +1,16 @@
+enum dsdb_dn_format {
+	DSDB_NORMAL_DN,
+	DSDB_BINARY_DN,
+	DSDB_STRING_DN,
+	DSDB_INVALID_DN
+};
+
+struct dsdb_dn {
+	struct ldb_dn *dn;
+	DATA_BLOB extra_part;
+	enum dsdb_dn_format dn_format;
+	const char *oid;
+};
+
+#define DSDB_SYNTAX_BINARY_DN "1.2.840.113556.1.4.903"
+#define DSDB_SYNTAX_STRING_DN  "1.2.840.113556.1.4.904"
diff --git a/source4/dsdb/common/tests/dsdb_dn.c b/source4/dsdb/common/tests/dsdb_dn.c
new file mode 100644
index 0000000..8f1aeca
--- /dev/null
+++ b/source4/dsdb/common/tests/dsdb_dn.c
@@ -0,0 +1,357 @@
+/* 
+   Unix SMB/CIFS implementation.
+
+   Test LDB attribute functions
+
+   Copyright (C) Andrew Bartlet <abartlet at samba.org> 2008
+   
+   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/>.
+*/
+
+#include "includes.h"
+#include "lib/events/events.h"
+#include "lib/ldb/include/ldb.h"
+#include "lib/ldb/include/ldb_errors.h"
+#include "lib/ldb-samba/ldif_handlers.h"
+#include "ldb_wrap.h"
+#include "dsdb/samdb/samdb.h"
+#include "param/param.h"
+#include "torture/smbtorture.h"
+#include "torture/local/proto.h"
+
+#define DSDB_DN_TEST_SID "S-1-5-21-4177067393-1453636373-93818737"


-- 
Samba Shared Repository


More information about the samba-cvs mailing list