return ret;
}
-/* modify_record: change modifyTimestamp as well */
-static int objectguid_modify_record(struct ldb_module *module, const struct ldb_message *msg)
-{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "objectguid_modify_record\n");
- return ldb_next_modify_record(module, msg);
-}
-
-static int objectguid_delete_record(struct ldb_module *module, const struct ldb_dn *dn)
-{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "objectguid_delete_record\n");
- return ldb_next_delete_record(module, dn);
-}
-
-static int objectguid_rename_record(struct ldb_module *module, const struct ldb_dn *olddn, const struct ldb_dn *newdn)
-{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "objectguid_rename_record\n");
- return ldb_next_rename_record(module, olddn, newdn);
-}
-
-static int objectguid_start_trans(struct ldb_module *module)
-{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "objectguid_start_trans\n");
- return ldb_next_start_trans(module);
-}
-
-static int objectguid_end_trans(struct ldb_module *module)
-{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "objectguid_end_trans\n");
- return ldb_next_end_trans(module);
-}
-
-static int objectguid_del_trans(struct ldb_module *module)
-{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "objectguid_del_trans\n");
- return ldb_next_del_trans(module);
-}
-
-static int objectguid_destructor(void *module_ctx)
-{
- /* struct ldb_module *ctx = module_ctx; */
- /* put your clean-up functions here */
- return 0;
-}
static const struct ldb_module_ops objectguid_ops = {
.name = "objectguid",
.search_bytree = objectguid_search_bytree,
- .add_record = objectguid_add_record,
- .modify_record = objectguid_modify_record,
- .delete_record = objectguid_delete_record,
- .rename_record = objectguid_rename_record,
- .start_transaction = objectguid_start_trans,
- .end_transaction = objectguid_end_trans,
- .del_transaction = objectguid_del_trans
+ .add_record = objectguid_add_record
};
ctx->prev = ctx->next = NULL;
ctx->ops = &objectguid_ops;
- talloc_set_destructor (ctx, objectguid_destructor);
-
return ctx;
}
return ldb_next_rename_record(module, olddn, newdn);
}
-static int samldb_start_trans(struct ldb_module *module)
-{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "samldb_start_trans\n");
- return ldb_next_start_trans(module);
-}
-
-static int samldb_end_trans(struct ldb_module *module)
-{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "samldb_end_trans\n");
- return ldb_next_end_trans(module);
-}
-
-static int samldb_del_trans(struct ldb_module *module)
-{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "samldb_del_trans\n");
- return ldb_next_del_trans(module);
-}
-
static int samldb_destructor(void *module_ctx)
{
/* struct ldb_module *ctx = module_ctx; */
.add_record = samldb_add_record,
.modify_record = samldb_modify_record,
.delete_record = samldb_delete_record,
- .rename_record = samldb_rename_record,
- .start_transaction = samldb_start_trans,
- .end_transaction = samldb_end_trans,
- .del_transaction = samldb_del_trans
+ .rename_record = samldb_rename_record
};
}
}
+#define FIRST_OP(ldb, op) do { \
+ module = ldb->modules; \
+ while (module && module->ops->op == NULL) module = module->next; \
+ if (module == NULL) return -1; \
+} while (0)
+
/*
start a transaction
*/
int ldb_transaction_start(struct ldb_context *ldb)
{
+ struct ldb_module *module;
+ FIRST_OP(ldb, start_transaction);
+
ldb->transaction_active++;
ldb_reset_err_string(ldb);
- return ldb->modules->ops->start_transaction(ldb->modules);
+ return module->ops->start_transaction(module);
}
/*
*/
int ldb_transaction_commit(struct ldb_context *ldb)
{
+ struct ldb_module *module;
+ FIRST_OP(ldb, end_transaction);
+
if (ldb->transaction_active > 0) {
ldb->transaction_active--;
} else {
ldb_reset_err_string(ldb);
- return ldb->modules->ops->end_transaction(ldb->modules);
+ return module->ops->end_transaction(module);
}
/*
*/
int ldb_transaction_cancel(struct ldb_context *ldb)
{
+ struct ldb_module *module;
+ FIRST_OP(ldb, del_transaction);
+
if (ldb->transaction_active > 0) {
ldb->transaction_active--;
} else {
ldb_reset_err_string(ldb);
- return ldb->modules->ops->del_transaction(ldb->modules);
+ return module->ops->del_transaction(module);
}
/*
struct ldb_parse_tree *tree,
const char * const *attrs, struct ldb_message ***res)
{
+ struct ldb_module *module;
+ FIRST_OP(ldb, search_bytree);
+
ldb_reset_err_string(ldb);
- return ldb->modules->ops->search_bytree(ldb->modules, base, scope, tree, attrs, res);
+ return module->ops->search_bytree(module, base, scope, tree, attrs, res);
}
/*
int ldb_add(struct ldb_context *ldb,
const struct ldb_message *message)
{
+ struct ldb_module *module;
int status;
+ FIRST_OP(ldb, add_record);
+
ldb_reset_err_string(ldb);
status = ldb_msg_sanity_check(message);
status = ldb_transaction_start(ldb);
if (status != LDB_SUCCESS) return status;
- status = ldb->modules->ops->add_record(ldb->modules, message);
+ status = module->ops->add_record(module, message);
if (status != LDB_SUCCESS) return ldb_transaction_cancel(ldb);
return ldb_transaction_commit(ldb);
}
- return ldb->modules->ops->add_record(ldb->modules, message);
+ return module->ops->add_record(module, message);
}
/*
int ldb_modify(struct ldb_context *ldb,
const struct ldb_message *message)
{
+ struct ldb_module *module;
int status;
+ FIRST_OP(ldb, modify_record);
+
ldb_reset_err_string(ldb);
status = ldb_msg_sanity_check(message);
status = ldb_transaction_start(ldb);
if (status != LDB_SUCCESS) return status;
- status = ldb->modules->ops->modify_record(ldb->modules, message);
+ status = module->ops->modify_record(module, message);
if (status != LDB_SUCCESS) return ldb_transaction_cancel(ldb);
return ldb_transaction_commit(ldb);
}
- return ldb->modules->ops->modify_record(ldb->modules, message);
+ return module->ops->modify_record(module, message);
}
*/
int ldb_delete(struct ldb_context *ldb, const struct ldb_dn *dn)
{
+ struct ldb_module *module;
int status;
+ FIRST_OP(ldb, delete_record);
+
ldb_reset_err_string(ldb);
if (! ldb->transaction_active) {
status = ldb_transaction_start(ldb);
if (status != LDB_SUCCESS) return status;
- status = ldb->modules->ops->delete_record(ldb->modules, dn);
+ status = module->ops->delete_record(module, dn);
if (status != LDB_SUCCESS) return ldb_transaction_cancel(ldb);
return ldb_transaction_commit(ldb);
}
- return ldb->modules->ops->delete_record(ldb->modules, dn);
+ return module->ops->delete_record(module, dn);
}
/*
*/
int ldb_rename(struct ldb_context *ldb, const struct ldb_dn *olddn, const struct ldb_dn *newdn)
{
+ struct ldb_module *module;
int status;
+ FIRST_OP(ldb, rename_record);
+
ldb_reset_err_string(ldb);
if (! ldb->transaction_active) {
status = ldb_transaction_start(ldb);
if (status != LDB_SUCCESS) return status;
- status = ldb->modules->ops->rename_record(ldb->modules, olddn, newdn);
+ status = module->ops->rename_record(module, olddn, newdn);
if (status != LDB_SUCCESS) return ldb_transaction_cancel(ldb);
return ldb_transaction_commit(ldb);
}
- return ldb->modules->ops->rename_record(ldb->modules, olddn, newdn);
+ return module->ops->rename_record(module, olddn, newdn);
}
return 0;
}
+/*
+ by using this we allow ldb modules to only implement the functions they care about,
+ which makes writing a module simpler, and makes it more likely to keep working
+ when ldb is extended
+*/
+#define FIND_OP(module, op) do { \
+ module = module->next; \
+ while (module && module->ops->op == NULL) module = module->next; \
+ if (module == NULL) return -1; \
+} while (0)
+
+
/*
helper functions to call the next module in chain
*/
struct ldb_parse_tree *tree,
const char * const *attrs, struct ldb_message ***res)
{
- if (!module->next) {
- return -1;
- }
- return module->next->ops->search_bytree(module->next, base, scope, tree, attrs, res);
+ FIND_OP(module, search_bytree);
+ return module->ops->search_bytree(module, base, scope, tree, attrs, res);
}
int ldb_next_search(struct ldb_module *module,
{
struct ldb_parse_tree *tree;
int ret;
- if (!module->next) {
- return -1;
- }
+ FIND_OP(module, search_bytree);
tree = ldb_parse_tree(module, expression);
if (tree == NULL) {
ldb_set_errstring(module, talloc_strdup(module, "Unable to parse search expression"));
return -1;
}
- ret = module->next->ops->search_bytree(module->next, base, scope, tree, attrs, res);
+ ret = module->ops->search_bytree(module, base, scope, tree, attrs, res);
talloc_free(tree);
return ret;
}
int ldb_next_add_record(struct ldb_module *module, const struct ldb_message *message)
{
- if (!module->next) {
- return -1;
- }
- return module->next->ops->add_record(module->next, message);
+ FIND_OP(module, add_record);
+ return module->ops->add_record(module, message);
}
int ldb_next_modify_record(struct ldb_module *module, const struct ldb_message *message)
{
- if (!module->next) {
- return -1;
- }
- return module->next->ops->modify_record(module->next, message);
+ FIND_OP(module, modify_record);
+ return module->ops->modify_record(module, message);
}
int ldb_next_delete_record(struct ldb_module *module, const struct ldb_dn *dn)
{
- if (!module->next) {
- return -1;
- }
- return module->next->ops->delete_record(module->next, dn);
+ FIND_OP(module, delete_record);
+ return module->ops->delete_record(module, dn);
}
int ldb_next_rename_record(struct ldb_module *module, const struct ldb_dn *olddn, const struct ldb_dn *newdn)
{
- if (!module->next) {
- return -1;
- }
- return module->next->ops->rename_record(module->next, olddn, newdn);
+ FIND_OP(module, rename_record);
+ return module->ops->rename_record(module, olddn, newdn);
}
int ldb_next_start_trans(struct ldb_module *module)
{
- if (!module->next) {
- return -1;
- }
- return module->next->ops->start_transaction(module->next);
+ FIND_OP(module, start_transaction);
+ return module->ops->start_transaction(module);
}
int ldb_next_end_trans(struct ldb_module *module)
{
- if (!module->next) {
- return -1;
- }
- return module->next->ops->end_transaction(module->next);
+ FIND_OP(module, end_transaction);
+ return module->ops->end_transaction(module);
}
int ldb_next_del_trans(struct ldb_module *module)
{
- if (!module->next) {
- return -1;
- }
- return module->next->ops->del_transaction(module->next);
+ FIND_OP(module, del_transaction);
+ return module->ops->del_transaction(module);
}
void ldb_set_errstring(struct ldb_module *module, char *err_string)
return (mp_ret == -1 || fb_ret == -1)?-1:0;
}
-static int map_start_trans(struct ldb_module *module)
-{
- return ldb_next_start_trans(module);
-}
-
-static int map_end_trans(struct ldb_module *module)
-{
- return ldb_next_end_trans(module);
-}
-
-static int map_del_trans(struct ldb_module *module)
-{
- return ldb_next_del_trans(module);
-}
-
static const struct ldb_module_ops map_ops = {
.name = "map",
.search_bytree = map_search_bytree,
.add_record = map_add,
.modify_record = map_modify,
.delete_record = map_delete,
- .rename_record = map_rename,
- .start_transaction = map_start_trans,
- .end_transaction = map_end_trans,
- .del_transaction = map_del_trans
+ .rename_record = map_rename
};
static char *map_find_url(struct ldb_context *ldb, const char *name)
return ret;
}
-static int rdn_name_delete_record(struct ldb_module *module, const struct ldb_dn *dn)
-{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_name_delete_record\n");
- return ldb_next_delete_record(module, dn);
-}
-
static int rdn_name_rename_record(struct ldb_module *module, const struct ldb_dn *olddn, const struct ldb_dn *newdn)
{
ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_name_rename_record\n");
return ldb_next_rename_record(module, olddn, newdn);
}
-static int rdn_start_trans(struct ldb_module *module)
-{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_start_trans\n");
- return ldb_next_start_trans(module);
-}
-
-static int rdn_end_trans(struct ldb_module *module)
-{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_end_trans\n");
- return ldb_next_end_trans(module);
-}
-
-static int rdn_del_trans(struct ldb_module *module)
-{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_del_trans\n");
- return ldb_next_del_trans(module);
-}
-
-static int rdn_name_destructor(void *module_ctx)
-{
- /* struct ldb_module *ctx = module_ctx; */
- /* put your clean-up functions here */
- return 0;
-}
-
static const struct ldb_module_ops rdn_name_ops = {
.name = "rdn_name",
.search_bytree = rdn_name_search_bytree,
.add_record = rdn_name_add_record,
.modify_record = rdn_name_modify_record,
- .delete_record = rdn_name_delete_record,
- .rename_record = rdn_name_rename_record,
- .start_transaction = rdn_start_trans,
- .end_transaction = rdn_end_trans,
- .del_transaction = rdn_del_trans
+ .rename_record = rdn_name_rename_record
};
ctx->prev = ctx->next = NULL;
ctx->ops = &rdn_name_ops;
- talloc_set_destructor (ctx, rdn_name_destructor);
-
return ctx;
}
return ldb_next_rename_record(module, olddn, newdn);
}
-static int schema_start_trans(struct ldb_module *module) {
- return ldb_next_start_trans(module);
-}
-
-static int schema_end_trans(struct ldb_module *module) {
- return ldb_next_end_trans(module);
-}
-
-static int schema_del_trans(struct ldb_module *module) {
- return ldb_next_del_trans(module);
-}
-
-static int schema_destructor(void *module_ctx)
-{
-/* struct ldb_module *ctx = module_ctx; */
- /* put your clean-up functions here */
- return 0;
-}
-
static const struct ldb_module_ops schema_ops = {
.name = "schema",
.search_bytree = schema_search_bytree,
.add_record = schema_add_record,
.modify_record = schema_modify_record,
.delete_record = schema_delete_record,
- .rename_record = schema_rename_record,
- .start_transaction = schema_start_trans,
- .end_transaction = schema_end_trans,
- .del_transaction = schema_del_trans
+ .rename_record = schema_rename_record
};
#ifdef HAVE_DLOPEN_DISABLED
ctx->prev = ctx->next = NULL;
ctx->ops = &schema_ops;
- talloc_set_destructor (ctx, schema_destructor);
-
return ctx;
}
return ret;
}
-static int timestamps_delete_record(struct ldb_module *module, const struct ldb_dn *dn)
-{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "timestamps_delete_record\n");
- return ldb_next_delete_record(module, dn);
-}
-
-static int timestamps_rename_record(struct ldb_module *module, const struct ldb_dn *olddn, const struct ldb_dn *newdn)
-{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "timestamps_rename_record\n");
- return ldb_next_rename_record(module, olddn, newdn);
-}
-
-static int timestamps_start_trans(struct ldb_module *module)
-{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "timestamps_start_trans\n");
- return ldb_next_start_trans(module);
-}
-
-static int timestamps_end_trans(struct ldb_module *module)
-{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "timestamps_end_trans\n");
- return ldb_next_end_trans(module);
-}
-
-static int timestamps_del_trans(struct ldb_module *module)
-{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "timestamps_del_trans\n");
- return ldb_next_del_trans(module);
-}
-
-static int timestamps_destructor(void *module_ctx)
-{
- /* struct ldb_module *ctx = module_ctx; */
- /* put your clean-up functions here */
- return 0;
-}
static const struct ldb_module_ops timestamps_ops = {
.name = "timestamps",
.search_bytree = timestamps_search_bytree,
.add_record = timestamps_add_record,
- .modify_record = timestamps_modify_record,
- .delete_record = timestamps_delete_record,
- .rename_record = timestamps_rename_record,
- .start_transaction = timestamps_start_trans,
- .end_transaction = timestamps_end_trans,
- .del_transaction = timestamps_del_trans
+ .modify_record = timestamps_modify_record
};
ctx->prev = ctx->next = NULL;
ctx->ops = ×tamps_ops;
- talloc_set_destructor (ctx, timestamps_destructor);
-
return ctx;
}
/*
pull a nbt name, WINS Replication uses another on wire format for nbt name
*/
-NTSTATUS ndr_pull_wrepl_nbt_name(struct ndr_pull *ndr, int ndr_flags, struct nbt_name *r)
+NTSTATUS ndr_pull_wrepl_nbt_name(struct ndr_pull *ndr, int ndr_flags, const struct nbt_name **_r)
{
+ struct nbt_name *r;
uint8_t *namebuf;
uint32_t namebuf_len;
NDR_PULL_ALLOC_N(ndr, namebuf, namebuf_len);
NDR_CHECK(ndr_pull_array_uint8(ndr, NDR_SCALARS, namebuf, namebuf_len));
+ NDR_PULL_ALLOC(ndr, r);
+
/* oh wow, what a nasty bug in windows ... */
if (namebuf[0] == 0x1b && namebuf_len >= 16) {
namebuf[0] = namebuf[15];
if (namebuf_len < 17) {
r->type = 0x00;
- r->name = talloc_strndup(ndr->current_mem_ctx, (char *)namebuf, namebuf_len);
+ r->name = talloc_strndup(r, (char *)namebuf, namebuf_len);
if (!r->name) return ndr_pull_error(ndr, NDR_ERR_ALLOC, "out of memory");
r->scope= NULL;
talloc_free(namebuf);
+ *_r = r;
return NT_STATUS_OK;
}
namebuf[15] = '\0';
trim_string((char *)namebuf, NULL, " ");
- r->name = talloc_strdup(ndr->current_mem_ctx, (char *)namebuf);
+ r->name = talloc_strdup(r, (char *)namebuf);
if (!r->name) return ndr_pull_error(ndr, NDR_ERR_ALLOC, "out of memory");
if (namebuf_len > 18) {
- r->scope = talloc_strndup(ndr->current_mem_ctx, (char *)(namebuf+17), namebuf_len-17);
+ r->scope = talloc_strndup(r, (char *)(namebuf+17), namebuf_len-17);
if (!r->scope) return ndr_pull_error(ndr, NDR_ERR_ALLOC, "out of memory");
} else {
r->scope = NULL;
}
talloc_free(namebuf);
+ *_r = r;
return NT_STATUS_OK;
}
/*
push a nbt name, WINS Replication uses another on wire format for nbt name
*/
-NTSTATUS ndr_push_wrepl_nbt_name(struct ndr_push *ndr, int ndr_flags, const struct nbt_name r)
+NTSTATUS ndr_push_wrepl_nbt_name(struct ndr_push *ndr, int ndr_flags, const struct nbt_name *r)
{
uint8_t *namebuf;
uint32_t namebuf_len;
uint32_t name_len;
uint32_t scope_len = 0;
+ if (r == NULL) return NT_STATUS_INVALID_PARAMETER_MIX;
+
if (!(ndr_flags & NDR_SCALARS)) {
return NT_STATUS_OK;
}
- name_len = strlen(r.name);
+ name_len = strlen(r->name);
if (name_len > 15) {
return NT_STATUS_INVALID_PARAMETER_MIX;
}
- if (r.scope) {
- scope_len = strlen(r.scope);
+ if (r->scope) {
+ scope_len = strlen(r->scope);
}
if (scope_len > 238) {
return NT_STATUS_INVALID_PARAMETER_MIX;
}
namebuf = (uint8_t *)talloc_asprintf(ndr, "%-15s%c%s",
- r.name, 'X',
- (r.scope?r.scope:""));
+ r->name, 'X',
+ (r->scope?r->scope:""));
if (!namebuf) return ndr_push_error(ndr, NDR_ERR_ALLOC, "out of memory");
namebuf_len = strlen((char *)namebuf) + 1;
* we need to set the type here, and use a place-holder in the talloc_asprintf()
* as the type can be 0x00, and then the namebuf_len = strlen(namebuf); would give wrong results
*/
- namebuf[15] = r.type;
+ namebuf[15] = r->type;
/* oh wow, what a nasty bug in windows ... */
- if (r.type == 0x1b) {
+ if (r->type == 0x1b) {
namebuf[15] = namebuf[0];
namebuf[0] = 0x1b;
}
return NT_STATUS_OK;
}
-void ndr_print_wrepl_nbt_name(struct ndr_print *ndr, const char *name, const struct nbt_name r)
+void ndr_print_wrepl_nbt_name(struct ndr_print *ndr, const char *name, const struct nbt_name *r)
{
- char *s = nbt_name_string(ndr, &r);
+ char *s = nbt_name_string(ndr, r);
ndr_print_string(ndr, name, s);
talloc_free(s);
}
struct wrepl_wins_name *wname = &packet->message.replication.info.reply.names[i];
struct wrepl_name *name = &io->out.names[i];
- name->name = wname->name;
- talloc_steal(io->out.names, wname->name.name);
- talloc_steal(io->out.names, wname->name.scope);
+ name->name = *wname->name;
+ talloc_steal(io->out.names, wname->name);
name->type = WREPL_NAME_TYPE(wname->flags);
name->state = WREPL_NAME_STATE(wname->flags);
name->node = WREPL_NAME_NODE(wname->flags);
HeaderType($element, $element->{TYPE}, "");
pidl " ";
my $numstar = $element->{POINTERS};
+ if ($numstar >= 1) {
+ $numstar-- if Parse::Pidl::Typelist::scalar_is_reference($element->{TYPE});
+ }
foreach (@{$element->{ARRAY_LEN}})
{
next if is_constant($_) and
not has_property($element, "charset");
$numstar++;
}
- $numstar-- if Parse::Pidl::Typelist::scalar_is_reference($element->{TYPE});
pidl "*" foreach (1..$numstar);
pidl $element->{NAME};
foreach (@{$element->{ARRAY_LEN}}) {
IS_REFERENCE => 1,
},
"wrepl_nbt_name"=> {
- C_TYPE => "struct nbt_name",
- IS_REFERENCE => 0,
+ C_TYPE => "struct nbt_name *",
+ IS_REFERENCE => 1,
},
"ipv4address" => {
C_TYPE => "const char *",