[SCM] Samba Shared Repository - branch master updated - tevent-0-9-8-855-ga58bc2c

Matthias Dieter Wallnöfer mdw at samba.org
Thu Oct 1 15:15:06 MDT 2009


The branch, master has been updated
       via  a58bc2c9a93597f3625dc8b64221c601b6f59833 (commit)
       via  a96c8c23553489ff86be1257bd2cce81b78e1d5b (commit)
       via  a51571bf410ac2f9fb6c6dd0854cfcfcc5c58cea (commit)
       via  97e7f48f7504132ca7f661c6ed56905c235f5715 (commit)
       via  5021301a0e6a15de5552583b1ffeb66619d398d8 (commit)
       via  681064e66e8146518be42393ecb58baa94d6a913 (commit)
       via  3c3ef94ab328698b7b5a2ffeea787d44b2898dfb (commit)
       via  bd5343924f07154012488ff96d3dd8f64e729a64 (commit)
       via  8330d78b2126ac072d9c7abb146d1f8a8bf91844 (commit)
       via  154ab0b0472e1519b18936e8a14edb7ff689120f (commit)
       via  540759ec4d0ea432ad0cd3eb10ed2f977f7b6d29 (commit)
       via  55dfc116f47b7c7242567f596c82bfd8f81d7b98 (commit)
       via  715c790600477b9b1ebdae7aa98779fc06be3bd1 (commit)
      from  2af2334522bc3d2c44bdcf7c9f1e80d2bcbf2024 (commit)

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


- Log -----------------------------------------------------------------
commit a58bc2c9a93597f3625dc8b64221c601b6f59833
Author: Kamen Mazdrashki <kamen.mazdrashki at postpath.com>
Date:   Sat Sep 26 01:41:18 2009 +0300

    s4/asn1: ber_read_OID_String() to be based on _ber_read_OID_String_impl()

commit a96c8c23553489ff86be1257bd2cce81b78e1d5b
Author: Kamen Mazdrashki <kamen.mazdrashki at postpath.com>
Date:   Sat Sep 26 01:36:01 2009 +0300

    s4/asn1: local TALLOC_CTX should be child of torture_context

commit a51571bf410ac2f9fb6c6dd0854cfcfcc5c58cea
Author: Kamen Mazdrashki <kamen.mazdrashki at postpath.com>
Date:   Sat Sep 26 01:34:17 2009 +0300

    s4/asn1: fixed typo in torture messages

commit 97e7f48f7504132ca7f661c6ed56905c235f5715
Author: Kamen Mazdrashki <kamen.mazdrashki at postpath.com>
Date:   Sat Sep 26 01:32:40 2009 +0300

    s4/asn1: Added test for ber_read_partial_OID_String()

commit 5021301a0e6a15de5552583b1ffeb66619d398d8
Author: Kamen Mazdrashki <kamen.mazdrashki at postpath.com>
Date:   Sat Sep 26 01:25:28 2009 +0300

    s4/asn1: Added test for ber_read_OID_String()

commit 681064e66e8146518be42393ecb58baa94d6a913
Author: Kamen Mazdrashki <kamen.mazdrashki at postpath.com>
Date:   Fri Sep 25 23:46:52 2009 +0300

    s4/asn1: Added test for ber_write_partial_OID_String()

commit 3c3ef94ab328698b7b5a2ffeea787d44b2898dfb
Author: Kamen Mazdrashki <kamen.mazdrashki at postpath.com>
Date:   Fri Sep 25 23:46:07 2009 +0300

    s4/asn1: Added test for ber_write_OID_String()

commit bd5343924f07154012488ff96d3dd8f64e729a64
Author: Kamen Mazdrashki <kamen.mazdrashki at postpath.com>
Date:   Fri Sep 25 23:43:56 2009 +0300

    s4/asn1: Added torture suite for ASN1

commit 8330d78b2126ac072d9c7abb146d1f8a8bf91844
Author: Kamen Mazdrashki <kamen.mazdrashki at postpath.com>
Date:   Fri Sep 25 23:40:55 2009 +0300

    util: strhex_to_str() fixed to handle '0x' correctly

commit 154ab0b0472e1519b18936e8a14edb7ff689120f
Author: Kamen Mazdrashki <kamen.mazdrashki at postpath.com>
Date:   Fri Sep 25 23:40:04 2009 +0300

    util: fixed compile time "discards qualifiers" warning

commit 540759ec4d0ea432ad0cd3eb10ed2f977f7b6d29
Author: Kamen Mazdrashki <kamen.mazdrashki at postpath.com>
Date:   Fri Sep 25 17:29:05 2009 +0300

    s4/drsuapi: ber_read_partial_OID_String() implementation

commit 55dfc116f47b7c7242567f596c82bfd8f81d7b98
Author: Kamen Mazdrashki <kamen.mazdrashki at postpath.com>
Date:   Fri Sep 25 17:28:33 2009 +0300

    s4/drsuapi: Internal implementation for ber_read_OID_String
    
    Modified implementation _ber_read_OID_String_impl()
    returns how much bytes are converted.
    The intentation is to use this implementation both for
    reading OIDs and partial-OIDs in the future

commit 715c790600477b9b1ebdae7aa98779fc06be3bd1
Author: Kamen Mazdrashki <kamen.mazdrashki at postpath.com>
Date:   Fri Sep 25 16:38:54 2009 +0300

    s4/drsuapi: ber_write_partial_OID_String() implementation

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

Summary of changes:
 lib/util/asn1.c                 |   96 ++++++++++++++-
 lib/util/asn1.h                 |    2 +
 lib/util/tests/asn1_tests.c     |  260 +++++++++++++++++++++++++++++++++++++++
 lib/util/util.c                 |   18 ++--
 source4/torture/local/config.mk |    1 +
 source4/torture/local/local.c   |    1 +
 6 files changed, 363 insertions(+), 15 deletions(-)
 create mode 100644 lib/util/tests/asn1_tests.c


Changeset truncated at 500 lines:

diff --git a/lib/util/asn1.c b/lib/util/asn1.c
index 70c2c57..ec8ef3f 100644
--- a/lib/util/asn1.c
+++ b/lib/util/asn1.c
@@ -258,6 +258,41 @@ bool ber_write_OID_String(DATA_BLOB *blob, const char *OID)
 	return true;
 }
 
+/**
+ * Serialize partial OID string.
+ * Partial OIDs are in the form:
+ *   1:2.5.6:0x81
+ *   1:2.5.6:0x8182
+ */
+bool ber_write_partial_OID_String(DATA_BLOB *blob, const char *partial_oid)
+{
+	TALLOC_CTX *mem_ctx = talloc_new(NULL);
+	char *oid = talloc_strdup(mem_ctx, partial_oid);
+	char *p;
+
+	/* truncate partial part so ber_write_OID_String() works */
+	p = strchr(oid, ':');
+	if (p) {
+		*p = '\0';
+		p++;
+	}
+
+	if (!ber_write_OID_String(blob, oid)) {
+		talloc_free(mem_ctx);
+		return false;
+	}
+
+	/* Add partially endcoded subidentifier */
+	if (p) {
+		DATA_BLOB tmp_blob = strhex_to_data_blob(mem_ctx, p);
+		data_blob_append(NULL, blob, tmp_blob.data, tmp_blob.length);
+	}
+
+	talloc_free(mem_ctx);
+
+	return true;
+}
+
 /* write an object ID to a ASN1 buffer */
 bool asn1_write_OID(struct asn1_data *data, const char *OID)
 {
@@ -543,8 +578,13 @@ int asn1_tag_remaining(struct asn1_data *data)
 	return remaining;
 }
 
-/* read an object ID from a data blob */
-bool ber_read_OID_String(TALLOC_CTX *mem_ctx, DATA_BLOB blob, const char **OID)
+/**
+ * Internal implementation for reading binary OIDs
+ * Reading is done as far in the buffer as valid OID
+ * till buffer ends or not valid sub-identifier is found.
+ */
+static bool _ber_read_OID_String_impl(TALLOC_CTX *mem_ctx, DATA_BLOB blob,
+					const char **OID, size_t *bytes_eaten)
 {
 	int i;
 	uint8_t *b;
@@ -565,19 +605,63 @@ bool ber_read_OID_String(TALLOC_CTX *mem_ctx, DATA_BLOB blob, const char **OID)
 		if ( ! (b[i] & 0x80)) {
 			tmp_oid = talloc_asprintf_append_buffer(tmp_oid, ".%u",  v);
 			v = 0;
+			if (bytes_eaten)
+				*bytes_eaten = i+1;
 		}
 		if (!tmp_oid) goto nomem;
 	}
 
-	if (v != 0) {
-		talloc_free(tmp_oid);
+	*OID = tmp_oid;
+	return true;
+
+nomem:
+	return false;
+}
+
+/* read an object ID from a data blob */
+bool ber_read_OID_String(TALLOC_CTX *mem_ctx, DATA_BLOB blob, const char **OID)
+{
+	size_t bytes_eaten;
+
+	if (!_ber_read_OID_String_impl(mem_ctx, blob, OID, &bytes_eaten))
+		return false;
+
+	return (bytes_eaten == blob.length);
+}
+
+/**
+ * Deserialize partial OID string.
+ * Partial OIDs are in the form:
+ *   1:2.5.6:0x81
+ *   1:2.5.6:0x8182
+ */
+bool ber_read_partial_OID_String(TALLOC_CTX *mem_ctx, DATA_BLOB blob, const char **partial_oid)
+{
+	size_t bytes_left;
+	size_t bytes_eaten;
+	char *identifier = NULL;
+	char *tmp_oid = NULL;
+
+	if (!_ber_read_OID_String_impl(mem_ctx, blob, (const char **)&tmp_oid, &bytes_eaten))
 		return false;
+
+	if (bytes_eaten < blob.length) {
+		bytes_left = blob.length - bytes_eaten;
+		identifier = hex_encode_talloc(mem_ctx, &blob.data[bytes_eaten], bytes_left);
+		if (!identifier)	goto nomem;
+
+		*partial_oid = talloc_asprintf_append_buffer(tmp_oid, ":0x%s", identifier);
+		if (!*partial_oid)	goto nomem;
+		TALLOC_FREE(identifier);
+	} else {
+		*partial_oid = tmp_oid;
 	}
 
-	*OID = tmp_oid;
 	return true;
 
-nomem:	
+nomem:
+	TALLOC_FREE(identifier);
+	TALLOC_FREE(tmp_oid);
 	return false;
 }
 
diff --git a/lib/util/asn1.h b/lib/util/asn1.h
index 9abae50..3d8e37b 100644
--- a/lib/util/asn1.h
+++ b/lib/util/asn1.h
@@ -62,6 +62,7 @@ bool asn1_write_implicit_Integer(struct asn1_data *data, int i);
 bool asn1_write_Integer(struct asn1_data *data, int i);
 bool asn1_write_BitString(struct asn1_data *data, const void *p, size_t length, uint8_t padding);
 bool ber_write_OID_String(DATA_BLOB *blob, const char *OID);
+bool ber_write_partial_OID_String(DATA_BLOB *blob, const char *partial_oid);
 bool asn1_write_OID(struct asn1_data *data, const char *OID);
 bool asn1_write_OctetString(struct asn1_data *data, const void *p, size_t length);
 bool asn1_write_LDAPString(struct asn1_data *data, const char *s);
@@ -83,6 +84,7 @@ bool asn1_start_tag(struct asn1_data *data, uint8_t tag);
 bool asn1_end_tag(struct asn1_data *data);
 int asn1_tag_remaining(struct asn1_data *data);
 bool ber_read_OID_String(TALLOC_CTX *mem_ctx, DATA_BLOB blob, const char **OID);
+bool ber_read_partial_OID_String(TALLOC_CTX *mem_ctx, DATA_BLOB blob, const char **partial_oid);
 bool asn1_read_OID(struct asn1_data *data, TALLOC_CTX *mem_ctx, const char **OID);
 bool asn1_check_OID(struct asn1_data *data, const char *OID);
 bool asn1_read_LDAPString(struct asn1_data *data, TALLOC_CTX *mem_ctx, char **s);
diff --git a/lib/util/tests/asn1_tests.c b/lib/util/tests/asn1_tests.c
new file mode 100644
index 0000000..56363c2
--- /dev/null
+++ b/lib/util/tests/asn1_tests.c
@@ -0,0 +1,260 @@
+/*
+   Unix SMB/CIFS implementation.
+
+   util_asn1 testing
+
+   Copyright (C) Kamen Mazdrashki <kamen.mazdrashki at postpath.com> 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 "torture/torture.h"
+#include "../asn1.h"
+
+struct oid_data {
+	const char *oid;	/* String OID */
+	const char *bin_oid;	/* Binary OID represented as string */
+};
+
+/* Data for successfull OIDs conversions */
+struct oid_data oid_data_ok[] = {
+	{
+		.oid = "2.5.4.0",
+		.bin_oid = "550400"
+	},
+	{
+		.oid = "2.5.4.1",
+		.bin_oid = "550401"
+	},
+	{
+		.oid = "2.5.4.130",
+		.bin_oid = "55048102"
+	},
+	{
+		.oid = "2.5.130.4",
+		.bin_oid = "55810204"
+	},
+	{
+		.oid = "2.5.4.16387",
+		.bin_oid = "5504818003"
+	},
+	{
+		.oid = "2.5.16387.4",
+		.bin_oid = "5581800304"
+	},
+	{
+		.oid = "2.5.2097155.4",
+		.bin_oid = "558180800304"
+	},
+	{
+		.oid = "2.5.4.130.16387.2097155.268435459",
+		.bin_oid = "55048102818003818080038180808003"
+	},
+};
+
+/* Data for successfull Partial OIDs conversions */
+struct oid_data partial_oid_data_ok[] = {
+	{
+		.oid = "2.5.4.130:0x81",
+		.bin_oid = "5504810281"
+	},
+	{
+		.oid = "2.5.4.16387:0x8180",
+		.bin_oid = "55048180038180"
+	},
+	{
+		.oid = "2.5.4.16387:0x81",
+		.bin_oid = "550481800381"
+	},
+	{
+		.oid = "2.5.2097155.4:0x818080",
+		.bin_oid = "558180800304818080"
+	},
+	{
+		.oid = "2.5.2097155.4:0x8180",
+		.bin_oid = "5581808003048180"
+	},
+	{
+		.oid = "2.5.2097155.4:0x81",
+		.bin_oid = "55818080030481"
+	},
+};
+
+
+/* Testing ber_write_OID_String() function */
+static bool test_ber_write_OID_String(struct torture_context *tctx)
+{
+	int i;
+	char *hex_str;
+	DATA_BLOB blob;
+	TALLOC_CTX *mem_ctx;
+	struct oid_data *data = oid_data_ok;
+
+	mem_ctx = talloc_new(tctx);
+
+	for (i = 0; i < ARRAY_SIZE(oid_data_ok); i++) {
+		torture_assert(tctx, ber_write_OID_String(&blob, data[i].oid),
+				"ber_write_OID_String failed");
+
+		hex_str = hex_encode_talloc(mem_ctx, blob.data, blob.length);
+		torture_assert(tctx, hex_str, "No memory!");
+
+		torture_assert(tctx, strequal(data[i].bin_oid, hex_str),
+				talloc_asprintf(mem_ctx,
+						"Failed: oid=%s, bin_oid:%s",
+						data[i].oid, data[i].bin_oid));
+	}
+
+	talloc_free(mem_ctx);
+
+	return true;
+}
+
+/* Testing ber_read_OID_String() function */
+static bool test_ber_read_OID_String(struct torture_context *tctx)
+{
+	int i;
+	const char *oid;
+	DATA_BLOB oid_blob;
+	TALLOC_CTX *mem_ctx;
+	struct oid_data *data = oid_data_ok;
+
+	mem_ctx = talloc_new(tctx);
+
+	for (i = 0; i < ARRAY_SIZE(oid_data_ok); i++) {
+		oid_blob = strhex_to_data_blob(mem_ctx, data[i].bin_oid);
+
+		torture_assert(tctx, ber_read_OID_String(mem_ctx, oid_blob, &oid),
+				"ber_read_OID_String failed");
+
+		torture_assert(tctx, strequal(data[i].oid, oid),
+				talloc_asprintf(mem_ctx,
+						"Failed: oid=%s, bin_oid:%s",
+						data[i].oid, data[i].bin_oid));
+	}
+
+	talloc_free(mem_ctx);
+
+	return true;
+}
+
+/* Testing ber_write_partial_OID_String() function */
+static bool test_ber_write_partial_OID_String(struct torture_context *tctx)
+{
+	int i;
+	char *hex_str;
+	DATA_BLOB blob;
+	TALLOC_CTX *mem_ctx;
+	struct oid_data *data = oid_data_ok;
+
+	mem_ctx = talloc_new(tctx);
+
+	/* ber_write_partial_OID_String() should work with not partial OIDs also */
+	for (i = 0; i < ARRAY_SIZE(oid_data_ok); i++) {
+		torture_assert(tctx, ber_write_partial_OID_String(&blob, data[i].oid),
+				"ber_write_partial_OID_String failed");
+
+		hex_str = hex_encode_talloc(mem_ctx, blob.data, blob.length);
+		torture_assert(tctx, hex_str, "No memory!");
+
+		torture_assert(tctx, strequal(data[i].bin_oid, hex_str),
+				talloc_asprintf(mem_ctx,
+						"Failed: oid=%s, bin_oid:%s",
+						data[i].oid, data[i].bin_oid));
+	}
+
+	/* ber_write_partial_OID_String() test with partial OIDs */
+	data = partial_oid_data_ok;
+	for (i = 0; i < ARRAY_SIZE(partial_oid_data_ok); i++) {
+		torture_assert(tctx, ber_write_partial_OID_String(&blob, data[i].oid),
+				"ber_write_partial_OID_String failed");
+
+		hex_str = hex_encode_talloc(mem_ctx, blob.data, blob.length);
+		torture_assert(tctx, hex_str, "No memory!");
+
+		torture_assert(tctx, strequal(data[i].bin_oid, hex_str),
+				talloc_asprintf(mem_ctx,
+						"Failed: oid=%s, bin_oid:%s",
+						data[i].oid, data[i].bin_oid));
+	}
+
+	talloc_free(mem_ctx);
+
+	return true;
+}
+
+/* Testing ber_read_partial_OID_String() function */
+static bool test_ber_read_partial_OID_String(struct torture_context *tctx)
+{
+	int i;
+	const char *oid;
+	DATA_BLOB oid_blob;
+	TALLOC_CTX *mem_ctx;
+	struct oid_data *data = oid_data_ok;
+
+	mem_ctx = talloc_new(tctx);
+
+	/* ber_read_partial_OID_String() should work with not partial OIDs also */
+	for (i = 0; i < ARRAY_SIZE(oid_data_ok); i++) {
+		oid_blob = strhex_to_data_blob(mem_ctx, data[i].bin_oid);
+
+		torture_assert(tctx, ber_read_partial_OID_String(mem_ctx, oid_blob, &oid),
+				"ber_read_partial_OID_String failed");
+
+		torture_assert(tctx, strequal(data[i].oid, oid),
+				talloc_asprintf(mem_ctx,
+						"Failed: oid=%s, bin_oid:%s",
+						data[i].oid, data[i].bin_oid));
+	}
+
+	/* ber_read_partial_OID_String() test with partial OIDs */
+	data = partial_oid_data_ok;
+	for (i = 0; i < ARRAY_SIZE(partial_oid_data_ok); i++) {
+		oid_blob = strhex_to_data_blob(mem_ctx, data[i].bin_oid);
+
+		torture_assert(tctx, ber_read_partial_OID_String(mem_ctx, oid_blob, &oid),
+				"ber_read_partial_OID_String failed");
+
+		torture_assert(tctx, strequal(data[i].oid, oid),
+				talloc_asprintf(mem_ctx,
+						"Failed: oid=%s, bin_oid:%s",
+						data[i].oid, data[i].bin_oid));
+	}
+
+	talloc_free(mem_ctx);
+
+	return true;
+}
+
+
+/* LOCAL-ASN1 test suite creation */
+struct torture_suite *torture_local_util_asn1(TALLOC_CTX *mem_ctx)
+{
+	struct torture_suite *suite = torture_suite_create(mem_ctx, "ASN1");
+
+	torture_suite_add_simple_test(suite, "ber_write_OID_String",
+				      test_ber_write_OID_String);
+
+	torture_suite_add_simple_test(suite, "ber_read_OID_String",
+				      test_ber_read_OID_String);
+
+	torture_suite_add_simple_test(suite, "ber_write_partial_OID_String",
+				      test_ber_write_partial_OID_String);
+
+	torture_suite_add_simple_test(suite, "ber_read_partial_OID_String",
+				      test_ber_read_partial_OID_String);
+
+	return suite;
+}
diff --git a/lib/util/util.c b/lib/util/util.c
index 2a809d3..fd0e6b8 100644
--- a/lib/util/util.c
+++ b/lib/util/util.c
@@ -579,18 +579,18 @@ _PUBLIC_ _PURE_ size_t count_chars(const char *s, char c)
 **/
 _PUBLIC_ size_t strhex_to_str(char *p, size_t p_len, const char *strhex, size_t strhex_len)
 {
-	size_t i;
+	size_t i = 0;
 	size_t num_chars = 0;
 	uint8_t   lonybble, hinybble;
 	const char     *hexchars = "0123456789ABCDEF";
 	char           *p1 = NULL, *p2 = NULL;
 
-	for (i = 0; i < strhex_len && strhex[i] != 0; i++) {
-		if (strncasecmp(hexchars, "0x", 2) == 0) {
-			i++; /* skip two chars */
-			continue;
-		}
+	/* skip leading 0x prefix */
+	if (strncasecmp(strhex, "0x", 2) == 0) {
+		i += 2; /* skip two chars */
+	}
 
+	for (; i < strhex_len && strhex[i] != 0; i++) {
 		if (!(p1 = strchr(hexchars, toupper((unsigned char)strhex[i]))))
 			break;
 
@@ -804,8 +804,8 @@ static bool next_token_internal_talloc(TALLOC_CTX *ctx,
                                 const char *sep,
                                 bool ltrim)
 {
-	char *s;
-	char *saved_s;
+	const char *s;
+	const char *saved_s;
 	char *pbuf;
 	bool quoted;
 	size_t len=1;
@@ -815,7 +815,7 @@ static bool next_token_internal_talloc(TALLOC_CTX *ctx,
 		return(false);
 	}
 
-	s = (char *)*ptr;
+	s = *ptr;
 
 	/* default to simple separators */
 	if (!sep) {
diff --git a/source4/torture/local/config.mk b/source4/torture/local/config.mk
index 1c3a721..7633d6c 100644
--- a/source4/torture/local/config.mk
+++ b/source4/torture/local/config.mk
@@ -41,6 +41,7 @@ TORTURE_LOCAL_OBJ_FILES = \
 		$(torturesrcdir)/../../lib/util/tests/parmlist.o \
 		$(torturesrcdir)/../../lib/util/tests/str.o \
 		$(torturesrcdir)/../../lib/util/tests/time.o \
+		$(torturesrcdir)/../../lib/util/tests/asn1_tests.o \
 		$(torturesrcdir)/../../lib/util/tests/data_blob.o \
 		$(torturesrcdir)/../../lib/util/tests/file.o \
 		$(torturesrcdir)/../../lib/util/tests/genrand.o \
diff --git a/source4/torture/local/local.c b/source4/torture/local/local.c
index 4180d30..8c6fd5e 100644
--- a/source4/torture/local/local.c
+++ b/source4/torture/local/local.c
@@ -39,6 +39,7 @@
 	torture_local_util_str, 
 	torture_local_util_time, 
 	torture_local_util_data_blob, 
+	torture_local_util_asn1,
 	torture_local_idtree, 
 	torture_local_genrand, 
 	torture_local_iconv,


-- 
Samba Shared Repository


More information about the samba-cvs mailing list