From 493c0cb8e46ff95f5b456dac3275a7df78d19aae Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Tue, 1 Sep 2015 09:53:12 +1200 Subject: [PATCH 1/8] ldb: Move ldb_(un)pack_data into ldb_module.h for testing BUG: https://bugzilla.samba.org/show_bug.cgi?id=11602 Signed-off-by: Adrian Cochrane Reviewed-by: Andrew Bartlett --- lib/ldb/include/ldb_module.h | 12 ++++++++++++ lib/ldb/include/ldb_private.h | 11 ----------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/ldb/include/ldb_module.h b/lib/ldb/include/ldb_module.h index 34e33c0..f00ba50 100644 --- a/lib/ldb/include/ldb_module.h +++ b/lib/ldb/include/ldb_module.h @@ -382,4 +382,16 @@ struct ldb_extended_match_rule int ldb_register_extended_match_rule(struct ldb_context *ldb, const struct ldb_extended_match_rule *rule); +/* + * these pack/unpack functions are exposed in the library for use by + * ldb tools like ldbdump and for use in tests, + * but are not part of the public API + */ +int ldb_pack_data(struct ldb_context *ldb, + const struct ldb_message *message, + struct ldb_val *data); +int ldb_unpack_data(struct ldb_context *ldb, + const struct ldb_val *data, + struct ldb_message *message); + #endif diff --git a/lib/ldb/include/ldb_private.h b/lib/ldb/include/ldb_private.h index eef5e1b..26a9d42 100644 --- a/lib/ldb/include/ldb_private.h +++ b/lib/ldb/include/ldb_private.h @@ -201,17 +201,6 @@ char *ldb_ldif_write_redacted_trace_string(struct ldb_context *ldb, TALLOC_CTX * const struct ldb_ldif *ldif); /* - * these pack/unpack functions are exposed in the library for use by - * ldb tools like ldbdump, but are not part of the public API - */ -int ldb_pack_data(struct ldb_context *ldb, - const struct ldb_message *message, - struct ldb_val *data); -int ldb_unpack_data(struct ldb_context *ldb, - const struct ldb_val *data, - struct ldb_message *message); - -/* * Get the LDB context in use on an LDB DN. * * This is helpful to the python LDB code, which may use as part of -- 2.6.1 From a7c0db4893b4c4294f0c37e142174b95ad8103ed Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Tue, 1 Sep 2015 09:54:09 +1200 Subject: [PATCH 2/8] ldb torture: Test ldb unpacking and printing BUG: https://bugzilla.samba.org/show_bug.cgi?id=11602 Signed-off-by: Adrian Cochrane Reviewed-by: Andrew Bartlett --- source4/torture/ldb/ldb.c | 329 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 329 insertions(+) diff --git a/source4/torture/ldb/ldb.c b/source4/torture/ldb/ldb.c index fbf82d8..2fc71c5 100644 --- a/source4/torture/ldb/ldb.c +++ b/source4/torture/ldb/ldb.c @@ -22,7 +22,9 @@ #include "includes.h" #include "lib/events/events.h" #include +#include #include +#include #include "lib/ldb-samba/ldif_handlers.h" #include "ldb_wrap.h" #include "dsdb/samdb/samdb.h" @@ -39,6 +41,214 @@ static const char *hex_guid = "fac55a97d9351d43b86a845bcd34fff9"; static const char *prefix_map_newline = "2:1.2.840.113556.1.2\n5:2.16.840.1.101.2.2.3"; static const char *prefix_map_semi = "2:1.2.840.113556.1.2;5:2.16.840.1.101.2.2.3"; +/* This is the hex code derived from the tdbdump for +"st/ad_dc/private/sam.ldb.d/DC=ADDC,DC=SAMBA,DC=EXAMPLE,DC=COM.ldb" +key "DN=CN=DDA1D01D-4BD7-4C49-A184-46F9241B560E,CN=OPERATIONS,CN=DOMAINUPDATES,CN=SYSTEM,DC=ADDC,DC=SAMBA,DC=EXAMPLE,DC=COM\00" + -- adrianc */ + +static const uint8_t dda1d01d_bin[] = { + 0x67, 0x19, 0x01, 0x26, 0x0d, 0x00, 0x00, 0x00, 0x43, 0x4e, 0x3d, 0x64, 0x64, 0x61, 0x31, 0x64, + 0x30, 0x31, 0x64, 0x2d, 0x34, 0x62, 0x64, 0x37, 0x2d, 0x34, 0x63, 0x34, 0x39, 0x2d, 0x61, 0x31, + 0x38, 0x34, 0x2d, 0x34, 0x36, 0x66, 0x39, 0x32, 0x34, 0x31, 0x62, 0x35, 0x36, 0x30, 0x65, 0x2c, + 0x43, 0x4e, 0x3d, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2c, 0x43, 0x4e, + 0x3d, 0x44, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x73, 0x2c, 0x43, + 0x4e, 0x3d, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2c, 0x44, 0x43, 0x3d, 0x61, 0x64, 0x64, 0x63, + 0x2c, 0x44, 0x43, 0x3d, 0x73, 0x61, 0x6d, 0x62, 0x61, 0x2c, 0x44, 0x43, 0x3d, 0x65, 0x78, 0x61, + 0x6d, 0x70, 0x6c, 0x65, 0x2c, 0x44, 0x43, 0x3d, 0x63, 0x6f, 0x6d, 0x00, 0x6f, 0x62, 0x6a, 0x65, + 0x63, 0x74, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x74, 0x6f, 0x70, 0x00, 0x09, 0x00, 0x00, 0x00, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, + 0x72, 0x00, 0x63, 0x6e, 0x00, 0x01, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x64, 0x64, 0x61, + 0x31, 0x64, 0x30, 0x31, 0x64, 0x2d, 0x34, 0x62, 0x64, 0x37, 0x2d, 0x34, 0x63, 0x34, 0x39, 0x2d, + 0x61, 0x31, 0x38, 0x34, 0x2d, 0x34, 0x36, 0x66, 0x39, 0x32, 0x34, 0x31, 0x62, 0x35, 0x36, 0x30, + 0x65, 0x00, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x54, 0x79, 0x70, 0x65, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x34, 0x00, 0x77, 0x68, 0x65, 0x6e, 0x43, 0x72, 0x65, + 0x61, 0x74, 0x65, 0x64, 0x00, 0x01, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x32, 0x30, 0x31, + 0x35, 0x30, 0x37, 0x30, 0x38, 0x32, 0x32, 0x34, 0x33, 0x31, 0x30, 0x2e, 0x30, 0x5a, 0x00, 0x77, + 0x68, 0x65, 0x6e, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x64, 0x00, 0x01, 0x00, 0x00, 0x00, 0x11, + 0x00, 0x00, 0x00, 0x32, 0x30, 0x31, 0x35, 0x30, 0x37, 0x30, 0x38, 0x32, 0x32, 0x34, 0x33, 0x31, + 0x30, 0x2e, 0x30, 0x5a, 0x00, 0x75, 0x53, 0x4e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x33, 0x34, 0x36, 0x37, 0x00, 0x75, 0x53, 0x4e, + 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x64, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x33, 0x34, 0x36, 0x37, 0x00, 0x73, 0x68, 0x6f, 0x77, 0x49, 0x6e, 0x41, 0x64, 0x76, 0x61, 0x6e, + 0x63, 0x65, 0x64, 0x56, 0x69, 0x65, 0x77, 0x4f, 0x6e, 0x6c, 0x79, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x54, 0x52, 0x55, 0x45, 0x00, 0x6e, 0x54, 0x53, 0x65, 0x63, 0x75, 0x72, + 0x69, 0x74, 0x79, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, 0x00, 0x01, 0x00, + 0x00, 0x00, 0x18, 0x05, 0x00, 0x00, 0x01, 0x00, 0x17, 0x8c, 0x14, 0x00, 0x00, 0x00, 0x30, 0x00, + 0x00, 0x00, 0x4c, 0x00, 0x00, 0x00, 0xc4, 0x00, 0x00, 0x00, 0x01, 0x05, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x05, 0x15, 0x00, 0x00, 0x00, 0x9a, 0xbd, 0x91, 0x7d, 0xd5, 0xe0, 0x11, 0x3c, 0x6e, 0x5e, + 0x1a, 0x4b, 0x00, 0x02, 0x00, 0x00, 0x01, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x15, 0x00, + 0x00, 0x00, 0x9a, 0xbd, 0x91, 0x7d, 0xd5, 0xe0, 0x11, 0x3c, 0x6e, 0x5e, 0x1a, 0x4b, 0x00, 0x02, + 0x00, 0x00, 0x04, 0x00, 0x78, 0x00, 0x02, 0x00, 0x00, 0x00, 0x07, 0x5a, 0x38, 0x00, 0x20, 0x00, + 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xbe, 0x3b, 0x0e, 0xf3, 0xf0, 0x9f, 0xd1, 0x11, 0xb6, 0x03, + 0x00, 0x00, 0xf8, 0x03, 0x67, 0xc1, 0xa5, 0x7a, 0x96, 0xbf, 0xe6, 0x0d, 0xd0, 0x11, 0xa2, 0x85, + 0x00, 0xaa, 0x00, 0x30, 0x49, 0xe2, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, + 0x00, 0x00, 0x07, 0x5a, 0x38, 0x00, 0x20, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xbf, 0x3b, + 0x0e, 0xf3, 0xf0, 0x9f, 0xd1, 0x11, 0xb6, 0x03, 0x00, 0x00, 0xf8, 0x03, 0x67, 0xc1, 0xa5, 0x7a, + 0x96, 0xbf, 0xe6, 0x0d, 0xd0, 0x11, 0xa2, 0x85, 0x00, 0xaa, 0x00, 0x30, 0x49, 0xe2, 0x01, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x54, 0x04, 0x17, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x24, 0x00, 0xff, 0x01, 0x0f, 0x00, 0x01, 0x05, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x05, 0x15, 0x00, 0x00, 0x00, 0x9a, 0xbd, 0x91, 0x7d, 0xd5, 0xe0, 0x11, 0x3c, 0x6e, 0x5e, + 0x1a, 0x4b, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0xff, 0x01, 0x0f, 0x00, 0x01, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x94, 0x00, + 0x02, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x0b, 0x00, 0x00, 0x00, 0x05, 0x1a, + 0x3c, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x42, 0x16, 0x4c, 0xc0, 0x20, + 0xd0, 0x11, 0xa7, 0x68, 0x00, 0xaa, 0x00, 0x6e, 0x05, 0x29, 0x14, 0xcc, 0x28, 0x48, 0x37, 0x14, + 0xbc, 0x45, 0x9b, 0x07, 0xad, 0x6f, 0x01, 0x5e, 0x5f, 0x28, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x05, 0x20, 0x00, 0x00, 0x00, 0x2a, 0x02, 0x00, 0x00, 0x05, 0x1a, 0x3c, 0x00, 0x10, 0x00, + 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x42, 0x16, 0x4c, 0xc0, 0x20, 0xd0, 0x11, 0xa7, 0x68, + 0x00, 0xaa, 0x00, 0x6e, 0x05, 0x29, 0xba, 0x7a, 0x96, 0xbf, 0xe6, 0x0d, 0xd0, 0x11, 0xa2, 0x85, + 0x00, 0xaa, 0x00, 0x30, 0x49, 0xe2, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x20, 0x00, + 0x00, 0x00, 0x2a, 0x02, 0x00, 0x00, 0x05, 0x1a, 0x3c, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x00, + 0x00, 0x00, 0x10, 0x20, 0x20, 0x5f, 0xa5, 0x79, 0xd0, 0x11, 0x90, 0x20, 0x00, 0xc0, 0x4f, 0xc2, + 0xd4, 0xcf, 0x14, 0xcc, 0x28, 0x48, 0x37, 0x14, 0xbc, 0x45, 0x9b, 0x07, 0xad, 0x6f, 0x01, 0x5e, + 0x5f, 0x28, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x20, 0x00, 0x00, 0x00, 0x2a, 0x02, + 0x00, 0x00, 0x05, 0x1a, 0x3c, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x10, 0x20, + 0x20, 0x5f, 0xa5, 0x79, 0xd0, 0x11, 0x90, 0x20, 0x00, 0xc0, 0x4f, 0xc2, 0xd4, 0xcf, 0xba, 0x7a, + 0x96, 0xbf, 0xe6, 0x0d, 0xd0, 0x11, 0xa2, 0x85, 0x00, 0xaa, 0x00, 0x30, 0x49, 0xe2, 0x01, 0x02, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x20, 0x00, 0x00, 0x00, 0x2a, 0x02, 0x00, 0x00, 0x05, 0x1a, + 0x3c, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x40, 0xc2, 0x0a, 0xbc, 0xa9, 0x79, + 0xd0, 0x11, 0x90, 0x20, 0x00, 0xc0, 0x4f, 0xc2, 0xd4, 0xcf, 0x14, 0xcc, 0x28, 0x48, 0x37, 0x14, + 0xbc, 0x45, 0x9b, 0x07, 0xad, 0x6f, 0x01, 0x5e, 0x5f, 0x28, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x05, 0x20, 0x00, 0x00, 0x00, 0x2a, 0x02, 0x00, 0x00, 0x05, 0x1a, 0x3c, 0x00, 0x10, 0x00, + 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x40, 0xc2, 0x0a, 0xbc, 0xa9, 0x79, 0xd0, 0x11, 0x90, 0x20, + 0x00, 0xc0, 0x4f, 0xc2, 0xd4, 0xcf, 0xba, 0x7a, 0x96, 0xbf, 0xe6, 0x0d, 0xd0, 0x11, 0xa2, 0x85, + 0x00, 0xaa, 0x00, 0x30, 0x49, 0xe2, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x20, 0x00, + 0x00, 0x00, 0x2a, 0x02, 0x00, 0x00, 0x05, 0x1a, 0x3c, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x00, + 0x00, 0x00, 0x42, 0x2f, 0xba, 0x59, 0xa2, 0x79, 0xd0, 0x11, 0x90, 0x20, 0x00, 0xc0, 0x4f, 0xc2, + 0xd3, 0xcf, 0x14, 0xcc, 0x28, 0x48, 0x37, 0x14, 0xbc, 0x45, 0x9b, 0x07, 0xad, 0x6f, 0x01, 0x5e, + 0x5f, 0x28, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x20, 0x00, 0x00, 0x00, 0x2a, 0x02, + 0x00, 0x00, 0x05, 0x1a, 0x3c, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x42, 0x2f, + 0xba, 0x59, 0xa2, 0x79, 0xd0, 0x11, 0x90, 0x20, 0x00, 0xc0, 0x4f, 0xc2, 0xd3, 0xcf, 0xba, 0x7a, + 0x96, 0xbf, 0xe6, 0x0d, 0xd0, 0x11, 0xa2, 0x85, 0x00, 0xaa, 0x00, 0x30, 0x49, 0xe2, 0x01, 0x02, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x20, 0x00, 0x00, 0x00, 0x2a, 0x02, 0x00, 0x00, 0x05, 0x1a, + 0x3c, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xf8, 0x88, 0x70, 0x03, 0xe1, 0x0a, + 0xd2, 0x11, 0xb4, 0x22, 0x00, 0xa0, 0xc9, 0x68, 0xf9, 0x39, 0x14, 0xcc, 0x28, 0x48, 0x37, 0x14, + 0xbc, 0x45, 0x9b, 0x07, 0xad, 0x6f, 0x01, 0x5e, 0x5f, 0x28, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x05, 0x20, 0x00, 0x00, 0x00, 0x2a, 0x02, 0x00, 0x00, 0x05, 0x1a, 0x3c, 0x00, 0x10, 0x00, + 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xf8, 0x88, 0x70, 0x03, 0xe1, 0x0a, 0xd2, 0x11, 0xb4, 0x22, + 0x00, 0xa0, 0xc9, 0x68, 0xf9, 0x39, 0xba, 0x7a, 0x96, 0xbf, 0xe6, 0x0d, 0xd0, 0x11, 0xa2, 0x85, + 0x00, 0xaa, 0x00, 0x30, 0x49, 0xe2, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x20, 0x00, + 0x00, 0x00, 0x2a, 0x02, 0x00, 0x00, 0x05, 0x1a, 0x38, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x00, + 0x00, 0x00, 0x6d, 0x9e, 0xc6, 0xb7, 0xc7, 0x2c, 0xd2, 0x11, 0x85, 0x4e, 0x00, 0xa0, 0xc9, 0x83, + 0xf6, 0x08, 0x86, 0x7a, 0x96, 0xbf, 0xe6, 0x0d, 0xd0, 0x11, 0xa2, 0x85, 0x00, 0xaa, 0x00, 0x30, + 0x49, 0xe2, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x09, 0x00, 0x00, 0x00, 0x05, 0x1a, + 0x38, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x6d, 0x9e, 0xc6, 0xb7, 0xc7, 0x2c, + 0xd2, 0x11, 0x85, 0x4e, 0x00, 0xa0, 0xc9, 0x83, 0xf6, 0x08, 0x9c, 0x7a, 0x96, 0xbf, 0xe6, 0x0d, + 0xd0, 0x11, 0xa2, 0x85, 0x00, 0xaa, 0x00, 0x30, 0x49, 0xe2, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x05, 0x09, 0x00, 0x00, 0x00, 0x05, 0x1a, 0x38, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x00, + 0x00, 0x00, 0x6d, 0x9e, 0xc6, 0xb7, 0xc7, 0x2c, 0xd2, 0x11, 0x85, 0x4e, 0x00, 0xa0, 0xc9, 0x83, + 0xf6, 0x08, 0xba, 0x7a, 0x96, 0xbf, 0xe6, 0x0d, 0xd0, 0x11, 0xa2, 0x85, 0x00, 0xaa, 0x00, 0x30, + 0x49, 0xe2, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x09, 0x00, 0x00, 0x00, 0x05, 0x1a, + 0x2c, 0x00, 0x94, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x14, 0xcc, 0x28, 0x48, 0x37, 0x14, + 0xbc, 0x45, 0x9b, 0x07, 0xad, 0x6f, 0x01, 0x5e, 0x5f, 0x28, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x05, 0x20, 0x00, 0x00, 0x00, 0x2a, 0x02, 0x00, 0x00, 0x05, 0x1a, 0x2c, 0x00, 0x94, 0x00, + 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x9c, 0x7a, 0x96, 0xbf, 0xe6, 0x0d, 0xd0, 0x11, 0xa2, 0x85, + 0x00, 0xaa, 0x00, 0x30, 0x49, 0xe2, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x20, 0x00, + 0x00, 0x00, 0x2a, 0x02, 0x00, 0x00, 0x05, 0x1a, 0x2c, 0x00, 0x94, 0x00, 0x02, 0x00, 0x02, 0x00, + 0x00, 0x00, 0xba, 0x7a, 0x96, 0xbf, 0xe6, 0x0d, 0xd0, 0x11, 0xa2, 0x85, 0x00, 0xaa, 0x00, 0x30, + 0x49, 0xe2, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x20, 0x00, 0x00, 0x00, 0x2a, 0x02, + 0x00, 0x00, 0x05, 0x12, 0x28, 0x00, 0x30, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xde, 0x47, + 0xe6, 0x91, 0x6f, 0xd9, 0x70, 0x4b, 0x95, 0x57, 0xd6, 0x3f, 0xf4, 0xf3, 0xcc, 0xd8, 0x01, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x12, 0x24, 0x00, 0xff, 0x01, + 0x0f, 0x00, 0x01, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x15, 0x00, 0x00, 0x00, 0x9a, 0xbd, + 0x91, 0x7d, 0xd5, 0xe0, 0x11, 0x3c, 0x6e, 0x5e, 0x1a, 0x4b, 0x07, 0x02, 0x00, 0x00, 0x00, 0x12, + 0x18, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x20, 0x00, + 0x00, 0x00, 0x2a, 0x02, 0x00, 0x00, 0x00, 0x12, 0x18, 0x00, 0xbd, 0x01, 0x0f, 0x00, 0x01, 0x02, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x20, 0x00, 0x00, 0x00, 0x20, 0x02, 0x00, 0x00, 0x00, 0x6e, + 0x61, 0x6d, 0x65, 0x00, 0x01, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x64, 0x64, 0x61, 0x31, + 0x64, 0x30, 0x31, 0x64, 0x2d, 0x34, 0x62, 0x64, 0x37, 0x2d, 0x34, 0x63, 0x34, 0x39, 0x2d, 0x61, + 0x31, 0x38, 0x34, 0x2d, 0x34, 0x36, 0x66, 0x39, 0x32, 0x34, 0x31, 0x62, 0x35, 0x36, 0x30, 0x65, + 0x00, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x47, 0x55, 0x49, 0x44, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x57, 0x93, 0x1e, 0x29, 0x25, 0x49, 0xe5, 0x40, 0x9d, 0x98, 0x36, 0x07, + 0x11, 0x9e, 0xbd, 0xe5, 0x00, 0x72, 0x65, 0x70, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, + 0x79, 0x4d, 0x65, 0x74, 0x61, 0x44, 0x61, 0x74, 0x61, 0x00, 0x01, 0x00, 0x00, 0x00, 0x90, 0x01, + 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x7e, 0x38, 0xae, 0x0b, 0x03, 0x00, + 0x00, 0x00, 0x9d, 0xcd, 0xcd, 0x57, 0xee, 0x58, 0x6e, 0x4e, 0x96, 0x99, 0xcc, 0x7d, 0xe1, 0x96, + 0xf1, 0x05, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x7e, 0x38, 0xae, 0x0b, 0x03, 0x00, + 0x00, 0x00, 0x9d, 0xcd, 0xcd, 0x57, 0xee, 0x58, 0x6e, 0x4e, 0x96, 0x99, 0xcc, 0x7d, 0xe1, 0x96, + 0xf1, 0x05, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x02, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x7e, 0x38, 0xae, 0x0b, 0x03, 0x00, + 0x00, 0x00, 0x9d, 0xcd, 0xcd, 0x57, 0xee, 0x58, 0x6e, 0x4e, 0x96, 0x99, 0xcc, 0x7d, 0xe1, 0x96, + 0xf1, 0x05, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xa9, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x7e, 0x38, 0xae, 0x0b, 0x03, 0x00, + 0x00, 0x00, 0x9d, 0xcd, 0xcd, 0x57, 0xee, 0x58, 0x6e, 0x4e, 0x96, 0x99, 0xcc, 0x7d, 0xe1, 0x96, + 0xf1, 0x05, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x19, 0x01, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x7e, 0x38, 0xae, 0x0b, 0x03, 0x00, + 0x00, 0x00, 0x9d, 0xcd, 0xcd, 0x57, 0xee, 0x58, 0x6e, 0x4e, 0x96, 0x99, 0xcc, 0x7d, 0xe1, 0x96, + 0xf1, 0x05, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x01, 0x00, 0x09, 0x00, 0x01, 0x00, 0x00, 0x00, 0x7e, 0x38, 0xae, 0x0b, 0x03, 0x00, + 0x00, 0x00, 0x9d, 0xcd, 0xcd, 0x57, 0xee, 0x58, 0x6e, 0x4e, 0x96, 0x99, 0xcc, 0x7d, 0xe1, 0x96, + 0xf1, 0x05, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x0e, 0x03, 0x09, 0x00, 0x01, 0x00, 0x00, 0x00, 0x7e, 0x38, 0xae, 0x0b, 0x03, 0x00, + 0x00, 0x00, 0x9d, 0xcd, 0xcd, 0x57, 0xee, 0x58, 0x6e, 0x4e, 0x96, 0x99, 0xcc, 0x7d, 0xe1, 0x96, + 0xf1, 0x05, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x7e, 0x38, 0xae, 0x0b, 0x03, 0x00, + 0x00, 0x00, 0x9d, 0xcd, 0xcd, 0x57, 0xee, 0x58, 0x6e, 0x4e, 0x96, 0x99, 0xcc, 0x7d, 0xe1, 0x96, + 0xf1, 0x05, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, + 0x79, 0x00, 0x01, 0x00, 0x00, 0x00, 0x76, 0x00, 0x00, 0x00, 0x3c, 0x47, 0x55, 0x49, 0x44, 0x3d, + 0x35, 0x32, 0x34, 0x32, 0x39, 0x30, 0x33, 0x38, 0x2d, 0x65, 0x34, 0x33, 0x35, 0x2d, 0x34, 0x66, + 0x65, 0x33, 0x2d, 0x39, 0x36, 0x34, 0x65, 0x2d, 0x38, 0x30, 0x64, 0x61, 0x31, 0x35, 0x34, 0x39, + 0x39, 0x63, 0x39, 0x63, 0x3e, 0x3b, 0x43, 0x4e, 0x3d, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, + 0x65, 0x72, 0x2c, 0x43, 0x4e, 0x3d, 0x53, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x2c, 0x43, 0x4e, 0x3d, + 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2c, 0x44, 0x43, + 0x3d, 0x61, 0x64, 0x64, 0x63, 0x2c, 0x44, 0x43, 0x3d, 0x73, 0x61, 0x6d, 0x62, 0x61, 0x2c, 0x44, + 0x43, 0x3d, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2c, 0x44, 0x43, 0x3d, 0x63, 0x6f, 0x6d, + 0x00 +}; + +static const char dda1d01d_ldif[] = "" +"dn: CN=dda1d01d-4bd7-4c49-a184-46f9241b560e,CN=Operations,CN=DomainUpdates,CN=System,DC=addc,DC=samba,DC=example,DC=com\n" +"objectClass: top\n" +"objectClass: container\n" +"cn: dda1d01d-4bd7-4c49-a184-46f9241b560e\n" +"instanceType: 4\n" +"whenCreated: 20150708224310.0Z\n" +"whenChanged: 20150708224310.0Z\n" +"uSNCreated: 3467\n" +"uSNChanged: 3467\n" +"showInAdvancedViewOnly: TRUE\n" +"nTSecurityDescriptor: O:S-1-5-21-2106703258-1007804629-1260019310-512G:S-1-5-2\n" +" 1-2106703258-1007804629-1260019310-512D:AI(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;S-\n" +" 1-5-21-2106703258-1007804629-1260019310-512)(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;\n" +" SY)(A;;RPLCLORC;;;AU)(OA;CIIOID;RP;4c164200-20c0-11d0-a768-00aa006e0529;4828c\n" +" c14-1437-45bc-9b07-ad6f015e5f28;RU)(OA;CIIOID;RP;4c164200-20c0-11d0-a768-00aa\n" +" 006e0529;bf967aba-0de6-11d0-a285-00aa003049e2;RU)(OA;CIIOID;RP;5f202010-79a5-\n" +" 11d0-9020-00c04fc2d4cf;4828cc14-1437-45bc-9b07-ad6f015e5f28;RU)(OA;CIIOID;RP;\n" +" 5f202010-79a5-11d0-9020-00c04fc2d4cf;bf967aba-0de6-11d0-a285-00aa003049e2;RU)\n" +" (OA;CIIOID;RP;bc0ac240-79a9-11d0-9020-00c04fc2d4cf;4828cc14-1437-45bc-9b07-ad\n" +" 6f015e5f28;RU)(OA;CIIOID;RP;bc0ac240-79a9-11d0-9020-00c04fc2d4cf;bf967aba-0de\n" +" 6-11d0-a285-00aa003049e2;RU)(OA;CIIOID;RP;59ba2f42-79a2-11d0-9020-00c04fc2d3c\n" +" f;4828cc14-1437-45bc-9b07-ad6f015e5f28;RU)(OA;CIIOID;RP;59ba2f42-79a2-11d0-90\n" +" 20-00c04fc2d3cf;bf967aba-0de6-11d0-a285-00aa003049e2;RU)(OA;CIIOID;RP;037088f\n" +" 8-0ae1-11d2-b422-00a0c968f939;4828cc14-1437-45bc-9b07-ad6f015e5f28;RU)(OA;CII\n" +" OID;RP;037088f8-0ae1-11d2-b422-00a0c968f939;bf967aba-0de6-11d0-a285-00aa00304\n" +" 9e2;RU)(OA;CIIOID;RP;b7c69e6d-2cc7-11d2-854e-00a0c983f608;bf967a86-0de6-11d0-\n" +" a285-00aa003049e2;ED)(OA;CIIOID;RP;b7c69e6d-2cc7-11d2-854e-00a0c983f608;bf967\n" +" a9c-0de6-11d0-a285-00aa003049e2;ED)(OA;CIIOID;RP;b7c69e6d-2cc7-11d2-854e-00a0\n" +" c983f608;bf967aba-0de6-11d0-a285-00aa003049e2;ED)(OA;CIIOID;RPLCLORC;;4828cc1\n" +" 4-1437-45bc-9b07-ad6f015e5f28;RU)(OA;CIIOID;RPLCLORC;;bf967a9c-0de6-11d0-a285\n" +" -00aa003049e2;RU)(OA;CIIOID;RPLCLORC;;bf967aba-0de6-11d0-a285-00aa003049e2;RU\n" +" )(OA;CIID;RPWPCR;91e647de-d96f-4b70-9557-d63ff4f3ccd8;;PS)(A;CIID;RPWPCRCCDCL\n" +" CLORCWOWDSDDTSW;;;S-1-5-21-2106703258-1007804629-1260019310-519)(A;CIID;LC;;;\n" +" RU)(A;CIID;RPWPCRCCLCLORCWOWDSDSW;;;BA)S:AI(OU;CIIOIDSA;WP;f30e3bbe-9ff0-11d1\n" +" -b603-0000f80367c1;bf967aa5-0de6-11d0-a285-00aa003049e2;WD)(OU;CIIOIDSA;WP;f3\n" +" 0e3bbf-9ff0-11d1-b603-0000f80367c1;bf967aa5-0de6-11d0-a285-00aa003049e2;WD)\n" +"name: dda1d01d-4bd7-4c49-a184-46f9241b560e\n" +"objectGUID: 291e9357-4925-40e5-9d98-3607119ebde5\n" +"replPropertyMetaData:: AQAAAAAAAAAIAAAAAAAAAAAAAAABAAAAfjiuCwMAAACdzc1X7lhuTpa\n" +" ZzH3hlvEFiw0AAAAAAACLDQAAAAAAAAEAAgABAAAAfjiuCwMAAACdzc1X7lhuTpaZzH3hlvEFiw0A\n" +" AAAAAACLDQAAAAAAAAIAAgABAAAAfjiuCwMAAACdzc1X7lhuTpaZzH3hlvEFiw0AAAAAAACLDQAAA\n" +" AAAAKkAAgABAAAAfjiuCwMAAACdzc1X7lhuTpaZzH3hlvEFiw0AAAAAAACLDQAAAAAAABkBAgABAA\n" +" AAfjiuCwMAAACdzc1X7lhuTpaZzH3hlvEFiw0AAAAAAACLDQAAAAAAAAEACQABAAAAfjiuCwMAAAC\n" +" dzc1X7lhuTpaZzH3hlvEFiw0AAAAAAACLDQAAAAAAAA4DCQABAAAAfjiuCwMAAACdzc1X7lhuTpaZ\n" +" zH3hlvEFiw0AAAAAAACLDQAAAAAAAAMAAAABAAAAfjiuCwMAAACdzc1X7lhuTpaZzH3hlvEFiw0AA\n" +" AAAAACLDQAAAAAAAA==\n" +"objectCategory: ;CN=Container,CN=Sc\n" +" hema,CN=Configuration,DC=addc,DC=samba,DC=example,DC=com\n\n"; + static bool torture_ldb_attrs(struct torture_context *torture) { TALLOC_CTX *mem_ctx = talloc_new(torture); @@ -793,6 +1003,123 @@ static bool torture_ldb_dn_invalid_extended(struct torture_context *torture) return true; } +static bool helper_ldb_message_compare(struct torture_context *torture, + struct ldb_message *a, + struct ldb_message *b) +{ + int i; + + if (a->num_elements != b->num_elements) return false; + + for (i = 0; i < a->num_elements; i++) { + int j; + struct ldb_message_element x = a->elements[i]; + struct ldb_message_element y = b->elements[i]; + + torture_comment(torture, "#%s\n", x.name); + torture_assert_int_equal(torture, x.flags, y.flags, + "Flags do not match"); + torture_assert_str_equal(torture, x.name, y.name, + "Names do not match in field"); + torture_assert_int_equal(torture, x.num_values, y.num_values, + "Number of values do not match"); + + /* + * Records cannot round trip via the SDDL string with a + * nTSecurityDescriptor field. + * + * Parsing from SDDL and diffing the NDR dump output gives the + * following: + * + * in: struct decode_security_descriptor + * sd: struct security_descriptor + * revision : SECURITY_DESCRIPTOR_REVISION_1 (1) + *- type : 0x8c14 (35860) + *- 0: SEC_DESC_OWNER_DEFAULTED + *- 0: SEC_DESC_GROUP_DEFAULTED + *+ type : 0x8c17 (35863) + *+ 1: SEC_DESC_OWNER_DEFAULTED + *+ 1: SEC_DESC_GROUP_DEFAULTED + * 1: SEC_DESC_DACL_PRESENT + * 0: SEC_DESC_DACL_DEFAULTED + * 1: SEC_DESC_SACL_PRESENT + */ + if (strcmp(x.name, "nTSecurityDescriptor") == 0) { + continue; + } + for (j = 0; j < x.num_values; j++) { + torture_assert_int_equal(torture, x.values[j].length, + y.values[j].length, + "Does not match in length"); + torture_assert_mem_equal(torture, + x.values[j].data, + y.values[j].data, + x.values[j].length, + "Does not match in data"); + } + } + return true; +} + +static bool torture_ldb_unpack(struct torture_context *torture) +{ + TALLOC_CTX *mem_ctx = talloc_new(torture); + struct ldb_context *ldb; + struct ldb_val data = data_blob_const(dda1d01d_bin, sizeof(dda1d01d_bin)); + struct ldb_message *msg = ldb_msg_new(mem_ctx); + const char *ldif_text = dda1d01d_ldif; + struct ldb_ldif ldif; + + torture_assert(torture, + ldb = samba_ldb_init(mem_ctx, torture->ev, NULL, NULL, NULL), + "Failed to init ldb"); + + torture_assert_int_equal(torture, ldb_unpack_data(ldb, &data, msg), 0, + "ldb_unpack_data failed"); + + ldif.changetype = LDB_CHANGETYPE_NONE; + ldif.msg = msg; + ldif_text = ldb_ldif_write_string(ldb, mem_ctx, &ldif); + + torture_assert_int_equal(torture, + strcmp(ldif_text, dda1d01d_ldif), 0, + "ldif form differs from binary form"); + return true; +} + +static bool torture_ldb_parse_ldif(struct torture_context *torture) +{ + TALLOC_CTX *mem_ctx = talloc_new(torture); + const char *ldif_text = dda1d01d_ldif; + struct ldb_context *ldb; + struct ldb_ldif *ldif; + struct ldb_val binary; + struct ldb_val data = data_blob_const(dda1d01d_bin, sizeof(dda1d01d_bin)); + struct ldb_message *msg = ldb_msg_new(mem_ctx); + + torture_assert(torture, + ldb=samba_ldb_init(mem_ctx, torture->ev, NULL,NULL,NULL), + "Failed to init ldb"); + + torture_assert(torture, + ldif = ldb_ldif_read_string(ldb, &ldif_text), + "ldb_ldif_read_string failed"); + torture_assert_int_equal(torture, ldif->changetype, LDB_CHANGETYPE_NONE, + "changetype is incorrect"); + torture_assert_int_equal(torture, + ldb_pack_data(ldb, ldif->msg, &binary), 0, + "ldb_pack_data failed"); + + torture_assert_int_equal(torture, ldb_unpack_data(ldb, &data, msg), 0, + "ldb_unpack_data failed"); + + torture_assert(torture, + helper_ldb_message_compare(torture, ldif->msg, msg), + "Forms differ in memory"); + + return true; +} + struct torture_suite *torture_ldb(TALLOC_CTX *mem_ctx) { struct torture_suite *suite = torture_suite_create(mem_ctx, "ldb"); @@ -806,6 +1133,8 @@ struct torture_suite *torture_ldb(TALLOC_CTX *mem_ctx) torture_suite_add_simple_test(suite, "dn-extended", torture_ldb_dn_extended); torture_suite_add_simple_test(suite, "dn-invalid-extended", torture_ldb_dn_invalid_extended); torture_suite_add_simple_test(suite, "dn", torture_ldb_dn); + torture_suite_add_simple_test(suite, "unpack-data", torture_ldb_unpack); + torture_suite_add_simple_test(suite, "parse-ldif", torture_ldb_parse_ldif); suite->description = talloc_strdup(suite, "LDB (samba-specific behaviour) tests"); -- 2.6.1 From 207f7824897410cac1a4b849ce37738a09c50dab Mon Sep 17 00:00:00 2001 From: Matthieu Patou Date: Thu, 27 Dec 2012 21:38:29 -0800 Subject: [PATCH 3/8] ldb: introduce ldb_unpack_data_withlist to unpack partial list of attributes When provided with non NULL list ldb_unpack_data_withlist will only unpack attributes that are specified in the list (+ distinguished name) ldb_unpack_data is changed to call ldb_unpack_data_withlist behind the scene. (for modifications found by testing, and re-indentation requested in review) Signed-off-by: Adrian Cochrane Sadly a signed-off-by was not available from Matthieu Patou for the original version of this patch posted to samba-technical for comment, so instead: (for supervision of Adrian) Signed-off-by: Andrew Bartlett Reviewed-by: Andrew Bartlett BUG: https://bugzilla.samba.org/show_bug.cgi?id=11602 --- lib/ldb/common/ldb_pack.c | 127 ++++++++++++++++++++++++++++++++++++------- lib/ldb/include/ldb_module.h | 6 ++ 2 files changed, 112 insertions(+), 21 deletions(-) diff --git a/lib/ldb/common/ldb_pack.c b/lib/ldb/common/ldb_pack.c index 4382d5b..a97e818 100644 --- a/lib/ldb/common/ldb_pack.c +++ b/lib/ldb/common/ldb_pack.c @@ -146,20 +146,52 @@ int ldb_pack_data(struct ldb_context *ldb, return 0; } +static bool ldb_consume_element_data(uint8_t **pp, unsigned int *premaining) +{ + unsigned int remaining = *premaining; + uint8_t *p = *pp; + uint32_t num_values = pull_uint32(p, 0); + uint32_t len; + int j; + + p += 4; + remaining -= 4; + for (j=0; j < num_values; j++) { + len = pull_uint32(p, 0); + if (len > remaining - 5) { + return false; + } + remaining -= len + 4 + 1; + p += len + 4 + 1; + } + + *premaining = remaining; + *pp = p; + return true; +} /* unpack a ldb message from a linear buffer in ldb_val Free with ldb_unpack_data_free() */ -int ldb_unpack_data(struct ldb_context *ldb, - const struct ldb_val *data, - struct ldb_message *message) +int ldb_unpack_data_withlist(struct ldb_context *ldb, + const struct ldb_val *data, + struct ldb_message *message, + const char * const *list, + unsigned int list_size, + unsigned int *nb_elements_in_db) { uint8_t *p; unsigned int remaining; unsigned int i, j; unsigned format; + unsigned int nelem = 0; size_t len; + unsigned int found = 0; + + if (list == NULL) { + list_size = 0; + } message->elements = NULL; @@ -172,6 +204,9 @@ int ldb_unpack_data(struct ldb_context *ldb, format = pull_uint32(p, 0); message->num_elements = pull_uint32(p, 4); p += 8; + if (nb_elements_in_db) { + *nb_elements_in_db = message->num_elements; + } remaining = data->length - 8; @@ -209,7 +244,8 @@ int ldb_unpack_data(struct ldb_context *ldb, goto failed; } - message->elements = talloc_array(message, struct ldb_message_element, message->num_elements); + message->elements = talloc_array(message, struct ldb_message_element, + message->num_elements); if (!message->elements) { errno = ENOMEM; goto failed; @@ -219,6 +255,7 @@ int ldb_unpack_data(struct ldb_context *ldb, message->num_elements * sizeof(struct ldb_message_element)); for (i=0;inum_elements;i++) { + struct ldb_message_element *element = NULL; if (remaining < 10) { errno = EIO; goto failed; @@ -232,51 +269,92 @@ int ldb_unpack_data(struct ldb_context *ldb, errno = EIO; goto failed; } - message->elements[i].flags = 0; - message->elements[i].name = talloc_strndup(message->elements, (char *)p, len); - if (message->elements[i].name == NULL) { + /* + * This is a bit expensive but normally the list is pretty small + * also the cost of freeing unused attributes is quite important + * and can dwarf the cost of looping + */ + if (list_size != 0) { + bool keep = false; + int h; + + /* + * We know that p has a \0 terminator before the + * end of the buffer due to the check above. + */ + for (h = 0; h < list_size && found < list_size; h++) { + if (ldb_attr_cmp(attr, list[h]) == 0) { + keep = true; + found++; + break; + } + } + + if (!keep) { + remaining -= len + 1; + p += len + 1; + if (!ldb_consume_element_data(&p, &remaining)) { + errno = EIO; + goto failed; + } + continue; + } + } + element = &message->elements[nelem]; + element->name = talloc_strndup(message->elements, (char *)p, len); + if (element->name == NULL) { errno = ENOMEM; goto failed; } + element->flags = 0; remaining -= len + 1; p += len + 1; - message->elements[i].num_values = pull_uint32(p, 0); - message->elements[i].values = NULL; - if (message->elements[i].num_values != 0) { - message->elements[i].values = talloc_array(message->elements, - struct ldb_val, - message->elements[i].num_values); - if (!message->elements[i].values) { + element->num_values = pull_uint32(p, 0); + element->values = NULL; + if (element->num_values != 0) { + element->values = talloc_array(message->elements, + struct ldb_val, + element->num_values); + if (!element->values) { errno = ENOMEM; goto failed; } } p += 4; remaining -= 4; - for (j=0;jelements[i].num_values;j++) { + for (j=0;jnum_values;j++) { len = pull_uint32(p, 0); if (len > remaining-5) { errno = EIO; goto failed; } - message->elements[i].values[j].length = len; - message->elements[i].values[j].data = talloc_size(message->elements[i].values, len+1); - if (message->elements[i].values[j].data == NULL) { + element->values[j].length = len; + element->values[j].data = talloc_size(element->values, len+1); + if (element->values[j].data == NULL) { errno = ENOMEM; goto failed; } - memcpy(message->elements[i].values[j].data, p+4, len); - message->elements[i].values[j].data[len] = 0; + memcpy(element->values[j].data, p + 4, + len); + element->values[j].data[len] = 0; remaining -= len+4+1; p += len+4+1; } + nelem++; } + /* + * Adapt the number of elements to the real number of unpacked elements, + * it means that we overallocated elements array, I guess it's not that + * bad. + */ + message->num_elements = nelem; if (remaining != 0) { ldb_debug(ldb, LDB_DEBUG_ERROR, - "Error: %d bytes unread in ldb_unpack_data", remaining); + "Error: %d bytes unread in ldb_unpack_data_withlist", + remaining); } return 0; @@ -285,3 +363,10 @@ failed: talloc_free(message->elements); return -1; } + +int ldb_unpack_data(struct ldb_context *ldb, + const struct ldb_val *data, + struct ldb_message *message) +{ + return ldb_unpack_data_withlist(ldb, data, message, NULL, 0, NULL); +} diff --git a/lib/ldb/include/ldb_module.h b/lib/ldb/include/ldb_module.h index f00ba50..7176721 100644 --- a/lib/ldb/include/ldb_module.h +++ b/lib/ldb/include/ldb_module.h @@ -390,6 +390,12 @@ int ldb_register_extended_match_rule(struct ldb_context *ldb, int ldb_pack_data(struct ldb_context *ldb, const struct ldb_message *message, struct ldb_val *data); +int ldb_unpack_data_withlist(struct ldb_context *ldb, + const struct ldb_val *data, + struct ldb_message *message, + const char* const * list, + unsigned int list_size, + unsigned int *nb_attributes_indb); int ldb_unpack_data(struct ldb_context *ldb, const struct ldb_val *data, struct ldb_message *message); -- 2.6.1 From 9f4da48879bdf0d063bdb6c3174e1f81d63d5da6 Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Tue, 1 Sep 2015 13:27:52 +1200 Subject: [PATCH 4/8] lib/ldb: Use better variable names in ldb_unpack_withlist BUG: https://bugzilla.samba.org/show_bug.cgi?id=11602 Signed-off-by: Adrian Cochrane Reviewed-by: Andrew Bartlett --- lib/ldb/common/ldb_pack.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/ldb/common/ldb_pack.c b/lib/ldb/common/ldb_pack.c index a97e818..dae762d 100644 --- a/lib/ldb/common/ldb_pack.c +++ b/lib/ldb/common/ldb_pack.c @@ -255,20 +255,27 @@ int ldb_unpack_data_withlist(struct ldb_context *ldb, message->num_elements * sizeof(struct ldb_message_element)); for (i=0;inum_elements;i++) { + const char *attr; + size_t attr_len; struct ldb_message_element *element = NULL; if (remaining < 10) { errno = EIO; goto failed; } - len = strnlen((char *)p, remaining-6); - if (len == remaining-6) { + /* + * With this check, we know that the attribute name at + * p is \0 terminated. + */ + attr_len = strnlen((char *)p, remaining-6); + if (attr_len == remaining-6) { errno = EIO; goto failed; } - if (len == 0) { + if (attr_len == 0) { errno = EIO; goto failed; } + attr = (char *)p; /* * This is a bit expensive but normally the list is pretty small * also the cost of freeing unused attributes is quite important @@ -291,8 +298,8 @@ int ldb_unpack_data_withlist(struct ldb_context *ldb, } if (!keep) { - remaining -= len + 1; - p += len + 1; + remaining -= attr_len + 1; + p += attr_len + 1; if (!ldb_consume_element_data(&p, &remaining)) { errno = EIO; goto failed; @@ -301,14 +308,14 @@ int ldb_unpack_data_withlist(struct ldb_context *ldb, } } element = &message->elements[nelem]; - element->name = talloc_strndup(message->elements, (char *)p, len); + element->name = talloc_strndup(message->elements, (char *)p, attr_len); if (element->name == NULL) { errno = ENOMEM; goto failed; } element->flags = 0; - remaining -= len + 1; - p += len + 1; + remaining -= attr_len + 1; + p += attr_len + 1; element->num_values = pull_uint32(p, 0); element->values = NULL; if (element->num_values != 0) { -- 2.6.1 From bc985a3e2d0b412ffee3fabcc6e269a10b578f65 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 13 Nov 2015 18:45:23 +1300 Subject: [PATCH 5/8] lib/ldb Add checks for overflow during ldb pack and parse Both as requested by Jeremy Allison during patch review and as found by american fuzzy lop. BUG: https://bugzilla.samba.org/show_bug.cgi?id=11602 Signed-off-by: Andrew Bartlett --- lib/ldb/common/ldb_pack.c | 128 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 105 insertions(+), 23 deletions(-) diff --git a/lib/ldb/common/ldb_pack.c b/lib/ldb/common/ldb_pack.c index dae762d..f37b073 100644 --- a/lib/ldb/common/ldb_pack.c +++ b/lib/ldb/common/ldb_pack.c @@ -77,7 +77,7 @@ int ldb_pack_data(struct ldb_context *ldb, struct ldb_val *data) { unsigned int i, j, real_elements=0; - size_t size; + size_t size, dn_len, attr_len, value_len; const char *dn; uint8_t *p; size_t len; @@ -91,8 +91,19 @@ int ldb_pack_data(struct ldb_context *ldb, /* work out how big it needs to be */ size = 8; - size += 1 + strlen(dn); + size += 1; + dn_len = strlen(dn); + if (size + dn_len < size) { + errno = ENOMEM; + return -1; + } + size += dn_len; + + /* + * First calcuate the buffer size we need, and check for + * overflows + */ for (i=0;inum_elements;i++) { if (attribute_storable_values(&message->elements[i]) == 0) { continue; @@ -100,9 +111,32 @@ int ldb_pack_data(struct ldb_context *ldb, real_elements++; - size += 1 + strlen(message->elements[i].name) + 4; + if (size + 5 < size) { + errno = ENOMEM; + return -1; + } + size += 5; + + attr_len = strlen(message->elements[i].name); + if (size + attr_len < size) { + errno = ENOMEM; + return -1; + } + size += attr_len; + for (j=0;jelements[i].num_values;j++) { - size += 4 + message->elements[i].values[j].length + 1; + if (size + 5 < size) { + errno = ENOMEM; + return -1; + } + size += 5; + + value_len = message->elements[i].values[j].length; + if (size + value_len < size) { + errno = ENOMEM; + return -1; + } + size += value_len; } } @@ -121,7 +155,7 @@ int ldb_pack_data(struct ldb_context *ldb, /* the dn needs to be packed so we can be case preserving while hashing on a case folded dn */ - len = strlen(dn); + len = dn_len; memcpy(p, dn, len+1); p += len + 1; @@ -146,7 +180,7 @@ int ldb_pack_data(struct ldb_context *ldb, return 0; } -static bool ldb_consume_element_data(uint8_t **pp, unsigned int *premaining) +static bool ldb_consume_element_data(uint8_t **pp, size_t *premaining) { unsigned int remaining = *premaining; uint8_t *p = *pp; @@ -155,13 +189,20 @@ static bool ldb_consume_element_data(uint8_t **pp, unsigned int *premaining) int j; p += 4; + if (remaining < 4) { + return false; + } remaining -= 4; for (j=0; j < num_values; j++) { len = pull_uint32(p, 0); - if (len > remaining - 5) { + if (remaining < 5) { + return false; + } + remaining -= 5; + if (len > remaining) { return false; } - remaining -= len + 4 + 1; + remaining -= len; p += len + 4 + 1; } @@ -182,7 +223,8 @@ int ldb_unpack_data_withlist(struct ldb_context *ldb, unsigned int *nb_elements_in_db) { uint8_t *p; - unsigned int remaining; + size_t remaining; + size_t dn_len; unsigned int i, j; unsigned format; unsigned int nelem = 0; @@ -216,8 +258,12 @@ int ldb_unpack_data_withlist(struct ldb_context *ldb, break; case LDB_PACKING_FORMAT: - len = strnlen((char *)p, remaining); - if (len == remaining) { + /* + * With this check, we know that the DN at p is \0 + * terminated. + */ + dn_len = strnlen((char *)p, remaining); + if (dn_len == remaining) { errno = EIO; goto failed; } @@ -226,8 +272,17 @@ int ldb_unpack_data_withlist(struct ldb_context *ldb, errno = ENOMEM; goto failed; } - remaining -= len + 1; - p += len + 1; + /* + * Rudundent: by definition, remaining must be more + * than one less than dn_len, as otherwise it would be + * == dn_len + */ + if (remaining < dn_len + 1) { + errno = EIO; + goto failed; + } + remaining -= dn_len + 1; + p += dn_len + 1; break; default: @@ -244,16 +299,13 @@ int ldb_unpack_data_withlist(struct ldb_context *ldb, goto failed; } - message->elements = talloc_array(message, struct ldb_message_element, - message->num_elements); + message->elements = talloc_zero_array(message, struct ldb_message_element, + message->num_elements); if (!message->elements) { errno = ENOMEM; goto failed; } - memset(message->elements, 0, - message->num_elements * sizeof(struct ldb_message_element)); - for (i=0;inum_elements;i++) { const char *attr; size_t attr_len; @@ -298,6 +350,10 @@ int ldb_unpack_data_withlist(struct ldb_context *ldb, } if (!keep) { + if (remaining < (attr_len + 1)) { + errno = EIO; + goto failed; + } remaining -= attr_len + 1; p += attr_len + 1; if (!ldb_consume_element_data(&p, &remaining)) { @@ -314,6 +370,11 @@ int ldb_unpack_data_withlist(struct ldb_context *ldb, goto failed; } element->flags = 0; + + if (remaining < (attr_len + 1)) { + errno = EIO; + goto failed; + } remaining -= attr_len + 1; p += attr_len + 1; element->num_values = pull_uint32(p, 0); @@ -328,10 +389,24 @@ int ldb_unpack_data_withlist(struct ldb_context *ldb, } } p += 4; + if (remaining < 4) { + errno = EIO; + goto failed; + } remaining -= 4; for (j=0;jnum_values;j++) { + if (remaining < 5) { + errno = EIO; + goto failed; + } + remaining -= 5; + len = pull_uint32(p, 0); - if (len > remaining-5) { + if (remaining < len) { + errno = EIO; + goto failed; + } + if (len + 1 < len) { errno = EIO; goto failed; } @@ -346,21 +421,28 @@ int ldb_unpack_data_withlist(struct ldb_context *ldb, len); element->values[j].data[len] = 0; - remaining -= len+4+1; + remaining -= len; p += len+4+1; } nelem++; } /* * Adapt the number of elements to the real number of unpacked elements, - * it means that we overallocated elements array, I guess it's not that - * bad. + * it means that we overallocated elements array. */ message->num_elements = nelem; + /* + * Shrink the allocated size. On current talloc behaviour + * this will help if we skipped 32 or more attributes. + */ + message->elements = talloc_realloc(message, message->elements, + struct ldb_message_element, + message->num_elements); + if (remaining != 0) { ldb_debug(ldb, LDB_DEBUG_ERROR, - "Error: %d bytes unread in ldb_unpack_data_withlist", + "Error: %zu bytes unread in ldb_unpack_data_withlist", remaining); } -- 2.6.1 From e90a8254d625305273f372ff0e04aa3af7df94a4 Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Tue, 1 Sep 2015 13:33:52 +1200 Subject: [PATCH 6/8] lib/ldb: Use talloc_memdup() because we know the length of the attribute already BUG: https://bugzilla.samba.org/show_bug.cgi?id=11602 Signed-off-by: Adrian Cochrane Reviewed-by: Andrew Bartlett --- lib/ldb/common/ldb_pack.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ldb/common/ldb_pack.c b/lib/ldb/common/ldb_pack.c index f37b073..04e25b5 100644 --- a/lib/ldb/common/ldb_pack.c +++ b/lib/ldb/common/ldb_pack.c @@ -364,7 +364,7 @@ int ldb_unpack_data_withlist(struct ldb_context *ldb, } } element = &message->elements[nelem]; - element->name = talloc_strndup(message->elements, (char *)p, attr_len); + element->name = talloc_memdup(message->elements, attr, attr_len+1); if (element->name == NULL) { errno = ENOMEM; goto failed; -- 2.6.1 From 8151e2576ffc9939ba82a5b1eb43be96f45013f9 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 6 Nov 2015 18:04:53 +1300 Subject: [PATCH 7/8] ldb: increment version due to added ldb_unpack_data_withlist BUG: https://bugzilla.samba.org/show_bug.cgi?id=11602 Signed-off-by: Adrian Cochrane Reviewed-by: Andrew Bartlett --- lib/ldb/ABI/ldb-1.1.24.sigs | 265 +++++++++++++++++++++++++++++++++++++ lib/ldb/ABI/pyldb-util-1.1.24.sigs | 2 + lib/ldb/wscript | 2 +- 3 files changed, 268 insertions(+), 1 deletion(-) create mode 100644 lib/ldb/ABI/ldb-1.1.24.sigs create mode 100644 lib/ldb/ABI/pyldb-util-1.1.24.sigs diff --git a/lib/ldb/ABI/ldb-1.1.24.sigs b/lib/ldb/ABI/ldb-1.1.24.sigs new file mode 100644 index 0000000..b724aea --- /dev/null +++ b/lib/ldb/ABI/ldb-1.1.24.sigs @@ -0,0 +1,265 @@ +ldb_add: int (struct ldb_context *, const struct ldb_message *) +ldb_any_comparison: int (struct ldb_context *, void *, ldb_attr_handler_t, const struct ldb_val *, const struct ldb_val *) +ldb_asprintf_errstring: void (struct ldb_context *, const char *, ...) +ldb_attr_casefold: char *(TALLOC_CTX *, const char *) +ldb_attr_dn: int (const char *) +ldb_attr_in_list: int (const char * const *, const char *) +ldb_attr_list_copy: const char **(TALLOC_CTX *, const char * const *) +ldb_attr_list_copy_add: const char **(TALLOC_CTX *, const char * const *, const char *) +ldb_base64_decode: int (char *) +ldb_base64_encode: char *(TALLOC_CTX *, const char *, int) +ldb_binary_decode: struct ldb_val (TALLOC_CTX *, const char *) +ldb_binary_encode: char *(TALLOC_CTX *, struct ldb_val) +ldb_binary_encode_string: char *(TALLOC_CTX *, const char *) +ldb_build_add_req: int (struct ldb_request **, struct ldb_context *, TALLOC_CTX *, const struct ldb_message *, struct ldb_control **, void *, ldb_request_callback_t, struct ldb_request *) +ldb_build_del_req: int (struct ldb_request **, struct ldb_context *, TALLOC_CTX *, struct ldb_dn *, struct ldb_control **, void *, ldb_request_callback_t, struct ldb_request *) +ldb_build_extended_req: int (struct ldb_request **, struct ldb_context *, TALLOC_CTX *, const char *, void *, struct ldb_control **, void *, ldb_request_callback_t, struct ldb_request *) +ldb_build_mod_req: int (struct ldb_request **, struct ldb_context *, TALLOC_CTX *, const struct ldb_message *, struct ldb_control **, void *, ldb_request_callback_t, struct ldb_request *) +ldb_build_rename_req: int (struct ldb_request **, struct ldb_context *, TALLOC_CTX *, struct ldb_dn *, struct ldb_dn *, struct ldb_control **, void *, ldb_request_callback_t, struct ldb_request *) +ldb_build_search_req: int (struct ldb_request **, struct ldb_context *, TALLOC_CTX *, struct ldb_dn *, enum ldb_scope, const char *, const char * const *, struct ldb_control **, void *, ldb_request_callback_t, struct ldb_request *) +ldb_build_search_req_ex: int (struct ldb_request **, struct ldb_context *, TALLOC_CTX *, struct ldb_dn *, enum ldb_scope, struct ldb_parse_tree *, const char * const *, struct ldb_control **, void *, ldb_request_callback_t, struct ldb_request *) +ldb_casefold: char *(struct ldb_context *, TALLOC_CTX *, const char *, size_t) +ldb_casefold_default: char *(void *, TALLOC_CTX *, const char *, size_t) +ldb_check_critical_controls: int (struct ldb_control **) +ldb_comparison_binary: int (struct ldb_context *, void *, const struct ldb_val *, const struct ldb_val *) +ldb_comparison_fold: int (struct ldb_context *, void *, const struct ldb_val *, const struct ldb_val *) +ldb_connect: int (struct ldb_context *, const char *, unsigned int, const char **) +ldb_control_to_string: char *(TALLOC_CTX *, const struct ldb_control *) +ldb_controls_except_specified: struct ldb_control **(struct ldb_control **, TALLOC_CTX *, struct ldb_control *) +ldb_debug: void (struct ldb_context *, enum ldb_debug_level, const char *, ...) +ldb_debug_add: void (struct ldb_context *, const char *, ...) +ldb_debug_end: void (struct ldb_context *, enum ldb_debug_level) +ldb_debug_set: void (struct ldb_context *, enum ldb_debug_level, const char *, ...) +ldb_delete: int (struct ldb_context *, struct ldb_dn *) +ldb_dn_add_base: bool (struct ldb_dn *, struct ldb_dn *) +ldb_dn_add_base_fmt: bool (struct ldb_dn *, const char *, ...) +ldb_dn_add_child: bool (struct ldb_dn *, struct ldb_dn *) +ldb_dn_add_child_fmt: bool (struct ldb_dn *, const char *, ...) +ldb_dn_alloc_casefold: char *(TALLOC_CTX *, struct ldb_dn *) +ldb_dn_alloc_linearized: char *(TALLOC_CTX *, struct ldb_dn *) +ldb_dn_canonical_ex_string: char *(TALLOC_CTX *, struct ldb_dn *) +ldb_dn_canonical_string: char *(TALLOC_CTX *, struct ldb_dn *) +ldb_dn_check_local: bool (struct ldb_module *, struct ldb_dn *) +ldb_dn_check_special: bool (struct ldb_dn *, const char *) +ldb_dn_compare: int (struct ldb_dn *, struct ldb_dn *) +ldb_dn_compare_base: int (struct ldb_dn *, struct ldb_dn *) +ldb_dn_copy: struct ldb_dn *(TALLOC_CTX *, struct ldb_dn *) +ldb_dn_escape_value: char *(TALLOC_CTX *, struct ldb_val) +ldb_dn_extended_add_syntax: int (struct ldb_context *, unsigned int, const struct ldb_dn_extended_syntax *) +ldb_dn_extended_filter: void (struct ldb_dn *, const char * const *) +ldb_dn_extended_syntax_by_name: const struct ldb_dn_extended_syntax *(struct ldb_context *, const char *) +ldb_dn_from_ldb_val: struct ldb_dn *(TALLOC_CTX *, struct ldb_context *, const struct ldb_val *) +ldb_dn_get_casefold: const char *(struct ldb_dn *) +ldb_dn_get_comp_num: int (struct ldb_dn *) +ldb_dn_get_component_name: const char *(struct ldb_dn *, unsigned int) +ldb_dn_get_component_val: const struct ldb_val *(struct ldb_dn *, unsigned int) +ldb_dn_get_extended_comp_num: int (struct ldb_dn *) +ldb_dn_get_extended_component: const struct ldb_val *(struct ldb_dn *, const char *) +ldb_dn_get_extended_linearized: char *(TALLOC_CTX *, struct ldb_dn *, int) +ldb_dn_get_ldb_context: struct ldb_context *(struct ldb_dn *) +ldb_dn_get_linearized: const char *(struct ldb_dn *) +ldb_dn_get_parent: struct ldb_dn *(TALLOC_CTX *, struct ldb_dn *) +ldb_dn_get_rdn_name: const char *(struct ldb_dn *) +ldb_dn_get_rdn_val: const struct ldb_val *(struct ldb_dn *) +ldb_dn_has_extended: bool (struct ldb_dn *) +ldb_dn_is_null: bool (struct ldb_dn *) +ldb_dn_is_special: bool (struct ldb_dn *) +ldb_dn_is_valid: bool (struct ldb_dn *) +ldb_dn_map_local: struct ldb_dn *(struct ldb_module *, void *, struct ldb_dn *) +ldb_dn_map_rebase_remote: struct ldb_dn *(struct ldb_module *, void *, struct ldb_dn *) +ldb_dn_map_remote: struct ldb_dn *(struct ldb_module *, void *, struct ldb_dn *) +ldb_dn_minimise: bool (struct ldb_dn *) +ldb_dn_new: struct ldb_dn *(TALLOC_CTX *, struct ldb_context *, const char *) +ldb_dn_new_fmt: struct ldb_dn *(TALLOC_CTX *, struct ldb_context *, const char *, ...) +ldb_dn_remove_base_components: bool (struct ldb_dn *, unsigned int) +ldb_dn_remove_child_components: bool (struct ldb_dn *, unsigned int) +ldb_dn_remove_extended_components: void (struct ldb_dn *) +ldb_dn_replace_components: bool (struct ldb_dn *, struct ldb_dn *) +ldb_dn_set_component: int (struct ldb_dn *, int, const char *, const struct ldb_val) +ldb_dn_set_extended_component: int (struct ldb_dn *, const char *, const struct ldb_val *) +ldb_dn_update_components: int (struct ldb_dn *, const struct ldb_dn *) +ldb_dn_validate: bool (struct ldb_dn *) +ldb_dump_results: void (struct ldb_context *, struct ldb_result *, FILE *) +ldb_error_at: int (struct ldb_context *, int, const char *, const char *, int) +ldb_errstring: const char *(struct ldb_context *) +ldb_extended: int (struct ldb_context *, const char *, void *, struct ldb_result **) +ldb_extended_default_callback: int (struct ldb_request *, struct ldb_reply *) +ldb_filter_from_tree: char *(TALLOC_CTX *, const struct ldb_parse_tree *) +ldb_get_config_basedn: struct ldb_dn *(struct ldb_context *) +ldb_get_create_perms: unsigned int (struct ldb_context *) +ldb_get_default_basedn: struct ldb_dn *(struct ldb_context *) +ldb_get_event_context: struct tevent_context *(struct ldb_context *) +ldb_get_flags: unsigned int (struct ldb_context *) +ldb_get_opaque: void *(struct ldb_context *, const char *) +ldb_get_root_basedn: struct ldb_dn *(struct ldb_context *) +ldb_get_schema_basedn: struct ldb_dn *(struct ldb_context *) +ldb_global_init: int (void) +ldb_handle_new: struct ldb_handle *(TALLOC_CTX *, struct ldb_context *) +ldb_handler_copy: int (struct ldb_context *, void *, const struct ldb_val *, struct ldb_val *) +ldb_handler_fold: int (struct ldb_context *, void *, const struct ldb_val *, struct ldb_val *) +ldb_init: struct ldb_context *(TALLOC_CTX *, struct tevent_context *) +ldb_ldif_message_string: char *(struct ldb_context *, TALLOC_CTX *, enum ldb_changetype, const struct ldb_message *) +ldb_ldif_parse_modrdn: int (struct ldb_context *, const struct ldb_ldif *, TALLOC_CTX *, struct ldb_dn **, struct ldb_dn **, bool *, struct ldb_dn **, struct ldb_dn **) +ldb_ldif_read: struct ldb_ldif *(struct ldb_context *, int (*)(void *), void *) +ldb_ldif_read_file: struct ldb_ldif *(struct ldb_context *, FILE *) +ldb_ldif_read_file_state: struct ldb_ldif *(struct ldb_context *, struct ldif_read_file_state *) +ldb_ldif_read_free: void (struct ldb_context *, struct ldb_ldif *) +ldb_ldif_read_string: struct ldb_ldif *(struct ldb_context *, const char **) +ldb_ldif_write: int (struct ldb_context *, int (*)(void *, const char *, ...), void *, const struct ldb_ldif *) +ldb_ldif_write_file: int (struct ldb_context *, FILE *, const struct ldb_ldif *) +ldb_ldif_write_redacted_trace_string: char *(struct ldb_context *, TALLOC_CTX *, const struct ldb_ldif *) +ldb_ldif_write_string: char *(struct ldb_context *, TALLOC_CTX *, const struct ldb_ldif *) +ldb_load_modules: int (struct ldb_context *, const char **) +ldb_map_add: int (struct ldb_module *, struct ldb_request *) +ldb_map_delete: int (struct ldb_module *, struct ldb_request *) +ldb_map_init: int (struct ldb_module *, const struct ldb_map_attribute *, const struct ldb_map_objectclass *, const char * const *, const char *, const char *) +ldb_map_modify: int (struct ldb_module *, struct ldb_request *) +ldb_map_rename: int (struct ldb_module *, struct ldb_request *) +ldb_map_search: int (struct ldb_module *, struct ldb_request *) +ldb_match_msg: int (struct ldb_context *, const struct ldb_message *, const struct ldb_parse_tree *, struct ldb_dn *, enum ldb_scope) +ldb_match_msg_error: int (struct ldb_context *, const struct ldb_message *, const struct ldb_parse_tree *, struct ldb_dn *, enum ldb_scope, bool *) +ldb_match_msg_objectclass: int (const struct ldb_message *, const char *) +ldb_mod_register_control: int (struct ldb_module *, const char *) +ldb_modify: int (struct ldb_context *, const struct ldb_message *) +ldb_modify_default_callback: int (struct ldb_request *, struct ldb_reply *) +ldb_module_call_chain: char *(struct ldb_request *, TALLOC_CTX *) +ldb_module_connect_backend: int (struct ldb_context *, const char *, const char **, struct ldb_module **) +ldb_module_done: int (struct ldb_request *, struct ldb_control **, struct ldb_extended *, int) +ldb_module_flags: uint32_t (struct ldb_context *) +ldb_module_get_ctx: struct ldb_context *(struct ldb_module *) +ldb_module_get_name: const char *(struct ldb_module *) +ldb_module_get_ops: const struct ldb_module_ops *(struct ldb_module *) +ldb_module_get_private: void *(struct ldb_module *) +ldb_module_init_chain: int (struct ldb_context *, struct ldb_module *) +ldb_module_load_list: int (struct ldb_context *, const char **, struct ldb_module *, struct ldb_module **) +ldb_module_new: struct ldb_module *(TALLOC_CTX *, struct ldb_context *, const char *, const struct ldb_module_ops *) +ldb_module_next: struct ldb_module *(struct ldb_module *) +ldb_module_popt_options: struct poptOption **(struct ldb_context *) +ldb_module_send_entry: int (struct ldb_request *, struct ldb_message *, struct ldb_control **) +ldb_module_send_referral: int (struct ldb_request *, char *) +ldb_module_set_next: void (struct ldb_module *, struct ldb_module *) +ldb_module_set_private: void (struct ldb_module *, void *) +ldb_modules_hook: int (struct ldb_context *, enum ldb_module_hook_type) +ldb_modules_list_from_string: const char **(struct ldb_context *, TALLOC_CTX *, const char *) +ldb_modules_load: int (const char *, const char *) +ldb_msg_add: int (struct ldb_message *, const struct ldb_message_element *, int) +ldb_msg_add_empty: int (struct ldb_message *, const char *, int, struct ldb_message_element **) +ldb_msg_add_fmt: int (struct ldb_message *, const char *, const char *, ...) +ldb_msg_add_linearized_dn: int (struct ldb_message *, const char *, struct ldb_dn *) +ldb_msg_add_steal_string: int (struct ldb_message *, const char *, char *) +ldb_msg_add_steal_value: int (struct ldb_message *, const char *, struct ldb_val *) +ldb_msg_add_string: int (struct ldb_message *, const char *, const char *) +ldb_msg_add_value: int (struct ldb_message *, const char *, const struct ldb_val *, struct ldb_message_element **) +ldb_msg_canonicalize: struct ldb_message *(struct ldb_context *, const struct ldb_message *) +ldb_msg_check_string_attribute: int (const struct ldb_message *, const char *, const char *) +ldb_msg_copy: struct ldb_message *(TALLOC_CTX *, const struct ldb_message *) +ldb_msg_copy_attr: int (struct ldb_message *, const char *, const char *) +ldb_msg_copy_shallow: struct ldb_message *(TALLOC_CTX *, const struct ldb_message *) +ldb_msg_diff: struct ldb_message *(struct ldb_context *, struct ldb_message *, struct ldb_message *) +ldb_msg_difference: int (struct ldb_context *, TALLOC_CTX *, struct ldb_message *, struct ldb_message *, struct ldb_message **) +ldb_msg_element_compare: int (struct ldb_message_element *, struct ldb_message_element *) +ldb_msg_element_compare_name: int (struct ldb_message_element *, struct ldb_message_element *) +ldb_msg_element_equal_ordered: bool (const struct ldb_message_element *, const struct ldb_message_element *) +ldb_msg_find_attr_as_bool: int (const struct ldb_message *, const char *, int) +ldb_msg_find_attr_as_dn: struct ldb_dn *(struct ldb_context *, TALLOC_CTX *, const struct ldb_message *, const char *) +ldb_msg_find_attr_as_double: double (const struct ldb_message *, const char *, double) +ldb_msg_find_attr_as_int: int (const struct ldb_message *, const char *, int) +ldb_msg_find_attr_as_int64: int64_t (const struct ldb_message *, const char *, int64_t) +ldb_msg_find_attr_as_string: const char *(const struct ldb_message *, const char *, const char *) +ldb_msg_find_attr_as_uint: unsigned int (const struct ldb_message *, const char *, unsigned int) +ldb_msg_find_attr_as_uint64: uint64_t (const struct ldb_message *, const char *, uint64_t) +ldb_msg_find_element: struct ldb_message_element *(const struct ldb_message *, const char *) +ldb_msg_find_ldb_val: const struct ldb_val *(const struct ldb_message *, const char *) +ldb_msg_find_val: struct ldb_val *(const struct ldb_message_element *, struct ldb_val *) +ldb_msg_new: struct ldb_message *(TALLOC_CTX *) +ldb_msg_normalize: int (struct ldb_context *, TALLOC_CTX *, const struct ldb_message *, struct ldb_message **) +ldb_msg_remove_attr: void (struct ldb_message *, const char *) +ldb_msg_remove_element: void (struct ldb_message *, struct ldb_message_element *) +ldb_msg_rename_attr: int (struct ldb_message *, const char *, const char *) +ldb_msg_sanity_check: int (struct ldb_context *, const struct ldb_message *) +ldb_msg_sort_elements: void (struct ldb_message *) +ldb_next_del_trans: int (struct ldb_module *) +ldb_next_end_trans: int (struct ldb_module *) +ldb_next_init: int (struct ldb_module *) +ldb_next_prepare_commit: int (struct ldb_module *) +ldb_next_remote_request: int (struct ldb_module *, struct ldb_request *) +ldb_next_request: int (struct ldb_module *, struct ldb_request *) +ldb_next_start_trans: int (struct ldb_module *) +ldb_op_default_callback: int (struct ldb_request *, struct ldb_reply *) +ldb_options_find: const char *(struct ldb_context *, const char **, const char *) +ldb_pack_data: int (struct ldb_context *, const struct ldb_message *, struct ldb_val *) +ldb_parse_control_from_string: struct ldb_control *(struct ldb_context *, TALLOC_CTX *, const char *) +ldb_parse_control_strings: struct ldb_control **(struct ldb_context *, TALLOC_CTX *, const char **) +ldb_parse_tree: struct ldb_parse_tree *(TALLOC_CTX *, const char *) +ldb_parse_tree_attr_replace: void (struct ldb_parse_tree *, const char *, const char *) +ldb_parse_tree_copy_shallow: struct ldb_parse_tree *(TALLOC_CTX *, const struct ldb_parse_tree *) +ldb_parse_tree_walk: int (struct ldb_parse_tree *, int (*)(struct ldb_parse_tree *, void *), void *) +ldb_qsort: void (void * const, size_t, size_t, void *, ldb_qsort_cmp_fn_t) +ldb_register_backend: int (const char *, ldb_connect_fn, bool) +ldb_register_extended_match_rule: int (struct ldb_context *, const struct ldb_extended_match_rule *) +ldb_register_hook: int (ldb_hook_fn) +ldb_register_module: int (const struct ldb_module_ops *) +ldb_rename: int (struct ldb_context *, struct ldb_dn *, struct ldb_dn *) +ldb_reply_add_control: int (struct ldb_reply *, const char *, bool, void *) +ldb_reply_get_control: struct ldb_control *(struct ldb_reply *, const char *) +ldb_req_get_custom_flags: uint32_t (struct ldb_request *) +ldb_req_is_untrusted: bool (struct ldb_request *) +ldb_req_location: const char *(struct ldb_request *) +ldb_req_mark_trusted: void (struct ldb_request *) +ldb_req_mark_untrusted: void (struct ldb_request *) +ldb_req_set_custom_flags: void (struct ldb_request *, uint32_t) +ldb_req_set_location: void (struct ldb_request *, const char *) +ldb_request: int (struct ldb_context *, struct ldb_request *) +ldb_request_add_control: int (struct ldb_request *, const char *, bool, void *) +ldb_request_done: int (struct ldb_request *, int) +ldb_request_get_control: struct ldb_control *(struct ldb_request *, const char *) +ldb_request_get_status: int (struct ldb_request *) +ldb_request_replace_control: int (struct ldb_request *, const char *, bool, void *) +ldb_request_set_state: void (struct ldb_request *, int) +ldb_reset_err_string: void (struct ldb_context *) +ldb_save_controls: int (struct ldb_control *, struct ldb_request *, struct ldb_control ***) +ldb_schema_attribute_add: int (struct ldb_context *, const char *, unsigned int, const char *) +ldb_schema_attribute_add_with_syntax: int (struct ldb_context *, const char *, unsigned int, const struct ldb_schema_syntax *) +ldb_schema_attribute_by_name: const struct ldb_schema_attribute *(struct ldb_context *, const char *) +ldb_schema_attribute_remove: void (struct ldb_context *, const char *) +ldb_schema_attribute_set_override_handler: void (struct ldb_context *, ldb_attribute_handler_override_fn_t, void *) +ldb_search: int (struct ldb_context *, TALLOC_CTX *, struct ldb_result **, struct ldb_dn *, enum ldb_scope, const char * const *, const char *, ...) +ldb_search_default_callback: int (struct ldb_request *, struct ldb_reply *) +ldb_sequence_number: int (struct ldb_context *, enum ldb_sequence_type, uint64_t *) +ldb_set_create_perms: void (struct ldb_context *, unsigned int) +ldb_set_debug: int (struct ldb_context *, void (*)(void *, enum ldb_debug_level, const char *, va_list), void *) +ldb_set_debug_stderr: int (struct ldb_context *) +ldb_set_default_dns: void (struct ldb_context *) +ldb_set_errstring: void (struct ldb_context *, const char *) +ldb_set_event_context: void (struct ldb_context *, struct tevent_context *) +ldb_set_flags: void (struct ldb_context *, unsigned int) +ldb_set_modules_dir: void (struct ldb_context *, const char *) +ldb_set_opaque: int (struct ldb_context *, const char *, void *) +ldb_set_timeout: int (struct ldb_context *, struct ldb_request *, int) +ldb_set_timeout_from_prev_req: int (struct ldb_context *, struct ldb_request *, struct ldb_request *) +ldb_set_utf8_default: void (struct ldb_context *) +ldb_set_utf8_fns: void (struct ldb_context *, void *, char *(*)(void *, void *, const char *, size_t)) +ldb_setup_wellknown_attributes: int (struct ldb_context *) +ldb_should_b64_encode: int (struct ldb_context *, const struct ldb_val *) +ldb_standard_syntax_by_name: const struct ldb_schema_syntax *(struct ldb_context *, const char *) +ldb_strerror: const char *(int) +ldb_string_to_time: time_t (const char *) +ldb_string_utc_to_time: time_t (const char *) +ldb_timestring: char *(TALLOC_CTX *, time_t) +ldb_timestring_utc: char *(TALLOC_CTX *, time_t) +ldb_transaction_cancel: int (struct ldb_context *) +ldb_transaction_cancel_noerr: int (struct ldb_context *) +ldb_transaction_commit: int (struct ldb_context *) +ldb_transaction_prepare_commit: int (struct ldb_context *) +ldb_transaction_start: int (struct ldb_context *) +ldb_unpack_data: int (struct ldb_context *, const struct ldb_val *, struct ldb_message *) +ldb_unpack_data_withlist: int (struct ldb_context *, const struct ldb_val *, struct ldb_message *, const char * const *, unsigned int, unsigned int *) +ldb_val_dup: struct ldb_val (TALLOC_CTX *, const struct ldb_val *) +ldb_val_equal_exact: int (const struct ldb_val *, const struct ldb_val *) +ldb_val_map_local: struct ldb_val (struct ldb_module *, void *, const struct ldb_map_attribute *, const struct ldb_val *) +ldb_val_map_remote: struct ldb_val (struct ldb_module *, void *, const struct ldb_map_attribute *, const struct ldb_val *) +ldb_val_string_cmp: int (const struct ldb_val *, const char *) +ldb_val_to_time: int (const struct ldb_val *, time_t *) +ldb_valid_attr_name: int (const char *) +ldb_vdebug: void (struct ldb_context *, enum ldb_debug_level, const char *, va_list) +ldb_wait: int (struct ldb_handle *, enum ldb_wait_type) diff --git a/lib/ldb/ABI/pyldb-util-1.1.24.sigs b/lib/ldb/ABI/pyldb-util-1.1.24.sigs new file mode 100644 index 0000000..74d6719 --- /dev/null +++ b/lib/ldb/ABI/pyldb-util-1.1.24.sigs @@ -0,0 +1,2 @@ +pyldb_Dn_FromDn: PyObject *(struct ldb_dn *) +pyldb_Object_AsDn: bool (TALLOC_CTX *, PyObject *, struct ldb_context *, struct ldb_dn **) diff --git a/lib/ldb/wscript b/lib/ldb/wscript index 662bec9..a0c2637 100755 --- a/lib/ldb/wscript +++ b/lib/ldb/wscript @@ -1,7 +1,7 @@ #!/usr/bin/env python APPNAME = 'ldb' -VERSION = '1.1.23' +VERSION = '1.1.24' blddir = 'bin' -- 2.6.1 From 5730f9b3b1d223194f82b2ad3b393abda31d8343 Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Fri, 14 Aug 2015 14:27:03 +1200 Subject: [PATCH 8/8] ldb torture: test ldb_unpack_data_withlist BUG: https://bugzilla.samba.org/show_bug.cgi?id=11602 Signed-off-by: Adrian Cochrane Reviewed-by: Andrew Bartlett --- source4/torture/ldb/ldb.c | 121 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) diff --git a/source4/torture/ldb/ldb.c b/source4/torture/ldb/ldb.c index 2fc71c5..c928688 100644 --- a/source4/torture/ldb/ldb.c +++ b/source4/torture/ldb/ldb.c @@ -249,6 +249,16 @@ static const char dda1d01d_ldif[] = "" "objectCategory: ;CN=Container,CN=Sc\n" " hema,CN=Configuration,DC=addc,DC=samba,DC=example,DC=com\n\n"; +static const char *dda1d01d_ldif_reduced = "" +"dn: CN=dda1d01d-4bd7-4c49-a184-46f9241b560e,CN=Operations,CN=DomainUpdates,CN=System,DC=addc,DC=samba,DC=example,DC=com\n" +"objectClass: top\n" +"objectClass: container\n" +"instanceType: 4\n" +"whenChanged: 20150708224310.0Z\n" +"uSNCreated: 3467\n" +"showInAdvancedViewOnly: TRUE\n" +"name: dda1d01d-4bd7-4c49-a184-46f9241b560e\n\n"; + static bool torture_ldb_attrs(struct torture_context *torture) { TALLOC_CTX *mem_ctx = talloc_new(torture); @@ -1120,6 +1130,116 @@ static bool torture_ldb_parse_ldif(struct torture_context *torture) return true; } +static bool torture_ldb_unpack_withlist(struct torture_context *torture) +{ + TALLOC_CTX *mem_ctx = talloc_new(torture); + struct ldb_context *ldb; + struct ldb_val data = data_blob_const(dda1d01d_bin, sizeof(dda1d01d_bin)); + struct ldb_message *msg = ldb_msg_new(mem_ctx); + const char *lookup_names[] = {"instanceType", "nonexistant", "whenChanged", + "objectClass", "uSNCreated", + "showInAdvancedViewOnly", "name", "cnNotHere"}; + unsigned int nb_elements_in_db; + const char *ldif_text; + struct ldb_ldif ldif; + + torture_assert(torture, + ldb=samba_ldb_init(mem_ctx, torture->ev, NULL, NULL, NULL), + "Failed to init samba"); + + torture_assert_int_equal(torture, + ldb_unpack_data_withlist(ldb, &data, msg, + lookup_names, ARRAY_SIZE(lookup_names), + &nb_elements_in_db), 0, + "ldb_unpack_data_withlist failed"); + torture_assert_int_equal(torture, nb_elements_in_db, 13, + "Got wrong count of elements"); + + /* Compare data in binary form */ + torture_assert_int_equal(torture, msg->num_elements, 6, + "Got wrong number of parsed elements"); + + torture_assert_str_equal(torture, msg->elements[0].name, "objectClass", + "First element has wrong name"); + torture_assert_int_equal(torture, msg->elements[0].num_values, 2, + "First element has wrong count of values"); + torture_assert_int_equal(torture, + msg->elements[0].values[0].length, 3, + "First element's first value is of wrong length"); + torture_assert_mem_equal(torture, + msg->elements[0].values[0].data, "top", 3, + "First element's first value is incorrect"); + torture_assert_int_equal(torture, + msg->elements[0].values[1].length, strlen("container"), + "First element's second value is of wrong length"); + torture_assert_mem_equal(torture, msg->elements[0].values[1].data, + "container", strlen("container"), + "First element's second value is incorrect"); + + torture_assert_str_equal(torture, msg->elements[1].name, "instanceType", + "Second element has wrong name"); + torture_assert_int_equal(torture, msg->elements[1].num_values, 1, + "Second element has too many values"); + torture_assert_int_equal(torture, msg->elements[1].values[0].length, 1, + "Second element's value is of wrong length"); + torture_assert_mem_equal(torture, msg->elements[1].values[0].data, + "4", 1, + "Second element's value is incorrect"); + + torture_assert_str_equal(torture, msg->elements[2].name, "whenChanged", + "Third element has wrong name"); + torture_assert_int_equal(torture, msg->elements[2].num_values, 1, + "Third element has too many values"); + torture_assert_int_equal(torture, msg->elements[2].values[0].length, + strlen("20150708224310.0Z"), + "Third element's value is of wrong length"); + torture_assert_mem_equal(torture, msg->elements[2].values[0].data, + "20150708224310.0Z", strlen("20150708224310.0Z"), + "Third element's value is incorrect"); + + torture_assert_str_equal(torture, msg->elements[3].name, "uSNCreated", + "Fourth element has wrong name"); + torture_assert_int_equal(torture, msg->elements[3].num_values, 1, + "Fourth element has too many values"); + torture_assert_int_equal(torture, msg->elements[3].values[0].length, 4, + "Fourth element's value is of wrong length"); + torture_assert_mem_equal(torture, msg->elements[3].values[0].data, + "3467", 4, + "Fourth element's value is incorrect"); + + torture_assert_str_equal(torture, msg->elements[4].name, "showInAdvancedViewOnly", + "Fifth element has wrong name"); + torture_assert_int_equal(torture, msg->elements[4].num_values, 1, + "Fifth element has too many values"); + torture_assert_int_equal(torture, msg->elements[4].values[0].length, 4, + "Fifth element's value is of wrong length"); + torture_assert_mem_equal(torture, msg->elements[4].values[0].data, + "TRUE", 4, + "Fourth element's value is incorrect"); + + torture_assert_str_equal(torture, msg->elements[5].name, "name", + "Sixth element has wrong name"); + torture_assert_int_equal(torture, msg->elements[5].num_values, 1, + "Sixth element has too many values"); + torture_assert_int_equal(torture, msg->elements[5].values[0].length, + strlen("dda1d01d-4bd7-4c49-a184-46f9241b560e"), + "Sixth element's value is of wrong length"); + torture_assert_mem_equal(torture, msg->elements[5].values[0].data, + "dda1d01d-4bd7-4c49-a184-46f9241b560e", + strlen("dda1d01d-4bd7-4c49-a184-46f9241b560e"), + "Sixth element's value is incorrect"); + + /* Compare data in ldif form */ + ldif.changetype = LDB_CHANGETYPE_NONE; + ldif.msg = msg; + ldif_text = ldb_ldif_write_string(ldb, mem_ctx, &ldif); + + torture_assert_str_equal(torture, ldif_text, dda1d01d_ldif_reduced, + "Expected fields did not match"); + + return true; +} + struct torture_suite *torture_ldb(TALLOC_CTX *mem_ctx) { struct torture_suite *suite = torture_suite_create(mem_ctx, "ldb"); @@ -1135,6 +1255,7 @@ struct torture_suite *torture_ldb(TALLOC_CTX *mem_ctx) torture_suite_add_simple_test(suite, "dn", torture_ldb_dn); torture_suite_add_simple_test(suite, "unpack-data", torture_ldb_unpack); torture_suite_add_simple_test(suite, "parse-ldif", torture_ldb_parse_ldif); + torture_suite_add_simple_test(suite, "unpack-data-withlist", torture_ldb_unpack_withlist); suite->description = talloc_strdup(suite, "LDB (samba-specific behaviour) tests"); -- 2.6.1