ldb_search returns LDB_ERR_NO_SUCH_OBJECT when searching for
prefixMap from module
Anatoliy Atanasov
anatoliy.atanasov at postpath.com
Tue Jun 24 10:15:53 GMT 2008
Hi List,
I added a module in dsdb/samdb/ldb_modules called prefix_map. All I need in my init function is to get the prefix map and store it,
but I fail when I do ldb_search with error LDB_ERR_NO_SUCH_OBJECT.
I tried to copy/paste the code from schema_fsmo_init method and it doesn't work in my function also.
I guess my module is not called when it should.
Here is what I have done so far.
I added it to the build system in dsdb/samdb/ldb_modules/config.mk
################################################
# Start MODULE ldb_prefix_map
[MODULE::ldb_prefix_map]
INIT_FUNCTION = LDB_MODULE(prefix_map)
CFLAGS = -Ilib/ldb/include
OUTPUT_TYPE = SHARED_LIBRARY
PRIVATE_DEPENDENCIES = SAMDB LIBTALLOC LIBNDR NDR_MISC NDR_DRSUAPI \
NDR_DRSBLOBS LIBNDR
SUBSYSTEM = LIBLDB
# End MODULE ldb_prefix_map
################################################
ldb_prefix_map_OBJ_FILES = $(dsdbsrcdir)/samdb/ldb_modules/prefix_map.o
Edited the scripting/python/samba/provision.py to put it in the chain
modules_list = ["rootdse",
"paged_results",
"ranged_results",
"anr",
"server_sort",
"extended_dn",
"asq",
"rdn_name",
"objectclass",
"samldb",
"kludge_acl",
"operational",
"prefix_map"]
And added code to the .init_context function
static int prefix_map_init(struct ldb_module *module)
{
const struct ldb_val *prefix_val;
struct ldb_val *prefix_map_string;
struct ldb_dn *schema_dn;
struct ldb_result *schema_res;
int ret;
TALLOC_CTX *mem_ctx;
static const char *schema_attrs[] = {
"prefixMap",
NULL
};
schema_dn = samdb_schema_dn(module->ldb);
if (!schema_dn) {
ldb_reset_err_string(module->ldb);
ldb_debug(module->ldb, LDB_DEBUG_WARNING,
"prefix_map_init: no schema dn present: (skip prefix map init)\n");
return ldb_next_init(module);
}
mem_ctx = talloc_new(module);
if (!mem_ctx) {
ldb_debug(module->ldb, LDB_DEBUG_WARNING,
"prefix_map_init: talloc failed: (skip prefix map init)\n");
return ldb_next_init(module);
}
ret = ldb_search(module->ldb, schema_dn,
LDB_SCOPE_BASE,
NULL, schema_attrs,
&schema_res);
if (ret == LDB_ERR_NO_SUCH_OBJECT) {
ldb_reset_err_string(module->ldb);
ldb_debug(module->ldb, LDB_DEBUG_WARNING,
"prefix_map_init: no prefix map present: (skip prefix map init)\n");
talloc_free(mem_ctx);
return ldb_next_init(module);
} else if (ret != LDB_SUCCESS) {
ldb_asprintf_errstring(module->ldb,
"prefix_map_init: failed to search the schema head: %s",
ldb_errstring(module->ldb));
talloc_free(mem_ctx);
return ret;
}
prefix_val = ldb_msg_find_ldb_val(schema_res->msgs[0], "prefixMap");
if (!prefix_val) {
ldb_debug_set(module->ldb, LDB_DEBUG_FATAL,
"prefix_map_init: no prefixMap attribute found");
talloc_free(mem_ctx);
return ldb_next_init(module);
}
prefix_map_string = talloc( mem_ctx, struct ldb_val );
if ( !ldif_write_prefixMap(module->ldb, mem_ctx, prefix_val, prefix_map_string) ) {
ldb_debug_set(module->ldb, LDB_DEBUG_FATAL,
"prefix_map_init: cannot convert a NDR formatted blob to a ldif formatted prefixMap");
talloc_free(mem_ctx);
return ldb_next_init(module);
}
talloc_free(mem_ctx);
return ldb_next_init(module);
}
Regards,
Anatoliy Atanasov
More information about the samba-technical
mailing list