#include "system/time.h"
#include "auth/auth.h"
#include "lib/ldb/include/ldb.h"
+#include "lib/ldb/include/ldb_errors.h"
#include "db_wrap.h"
/*
struct creds_CredentialState **creds)
{
struct ldb_context *ldb;
- struct ldb_message **res;
+ struct ldb_result *res;
int ret;
const struct ldb_val *val;
char *expr=NULL;
}
ret = ldb_search(ldb, NULL, LDB_SCOPE_SUBTREE, expr, NULL, &res);
- if (ret != 1) {
+ if (ret != LDB_SUCCESS || res->count != 1) {
talloc_free(ldb);
return NT_STATUS_INVALID_HANDLE;
}
- val = ldb_msg_find_ldb_val(res[0], "sessionKey");
+ val = ldb_msg_find_ldb_val(res->msgs[0], "sessionKey");
if (val == NULL || val->length != 16) {
DEBUG(1,("schannel: record in schannel DB must contain a sessionKey of length 16, when searching for client: %s\n", computer_name));
talloc_free(ldb);
memcpy((*creds)->session_key, val->data, 16);
- val = ldb_msg_find_ldb_val(res[0], "seed");
+ val = ldb_msg_find_ldb_val(res->msgs[0], "seed");
if (val == NULL || val->length != 8) {
DEBUG(1,("schannel: record in schannel DB must contain a vaid seed of length 8, when searching for client: %s\n", computer_name));
talloc_free(ldb);
memcpy((*creds)->seed.data, val->data, 8);
- (*creds)->negotiate_flags = ldb_msg_find_int(res[0], "negotiateFlags", 0);
+ (*creds)->negotiate_flags = ldb_msg_find_int(res->msgs[0], "negotiateFlags", 0);
- (*creds)->secure_channel_type = ldb_msg_find_int(res[0], "secureChannelType", 0);
+ (*creds)->secure_channel_type = ldb_msg_find_int(res->msgs[0], "secureChannelType", 0);
- (*creds)->account_name = talloc_reference(*creds, ldb_msg_find_string(res[0], "accountName", NULL));
+ (*creds)->account_name = talloc_reference(*creds, ldb_msg_find_string(res->msgs[0], "accountName", NULL));
- (*creds)->computer_name = talloc_reference(*creds, ldb_msg_find_string(res[0], "computerName", NULL));
+ (*creds)->computer_name = talloc_reference(*creds, ldb_msg_find_string(res->msgs[0], "computerName", NULL));
- (*creds)->domain = talloc_reference(*creds, ldb_msg_find_string(res[0], "flatname", NULL));
+ (*creds)->domain = talloc_reference(*creds, ldb_msg_find_string(res->msgs[0], "flatname", NULL));
- (*creds)->sid = samdb_result_dom_sid(*creds, res[0], "objectSid");
+ (*creds)->sid = samdb_result_dom_sid(*creds, res->msgs[0], "objectSid");
talloc_free(ldb);
#include "rpc_server/common/common.h"
#include "rpc_server/drsuapi/dcesrv_drsuapi.h"
#include "lib/ldb/include/ldb.h"
+#include "lib/ldb/include/ldb_errors.h"
#include "system/kerberos.h"
#include "auth/kerberos/kerberos.h"
char **alias_to)
{
int i;
- int count;
- struct ldb_message **msg;
+ int ret;
+ struct ldb_result *res;
struct ldb_message_element *spnmappings;
struct ldb_dn *service_dn = ldb_dn_string_compose(mem_ctx, samdb_base_dn(mem_ctx),
"CN=Directory Service,CN=Windows NT"
NULL
};
- count = ldb_search(ldb_ctx, service_dn, LDB_SCOPE_BASE, "(objectClass=nTDSService)",
- directory_attrs, &msg);
- talloc_steal(mem_ctx, msg);
+ ret = ldb_search(ldb_ctx, service_dn, LDB_SCOPE_BASE, "(objectClass=nTDSService)",
+ directory_attrs, &res);
+ talloc_steal(mem_ctx, res);
- if (count < 1) {
- DEBUG(1, ("ldb_search: dn: %s not found: %d", service_dn_str, count));
+ if (ret != LDB_SUCCESS) {
+ DEBUG(1, ("ldb_search: dn: %s not found: %s", service_dn_str, ldb_errstring(ldb_ctx)));
return DRSUAPI_DS_NAME_STATUS_NOT_FOUND;
- } else if (count > 1) {
- DEBUG(1, ("ldb_search: dn: %s found %d times!", service_dn_str, count));
+ } else if (res->count > 1) {
+ DEBUG(1, ("ldb_search: dn: %s found %d times!", service_dn_str, res->count));
return DRSUAPI_DS_NAME_STATUS_NOT_FOUND;
}
- spnmappings = ldb_msg_find_element(msg[0], "sPNMappings");
+ spnmappings = ldb_msg_find_element(res->msgs[0], "sPNMappings");
if (!spnmappings || spnmappings->num_values == 0) {
DEBUG(1, ("ldb_search: dn: %s no sPNMappings attribute", service_dn_str));
return DRSUAPI_DS_NAME_STATUS_NOT_FOUND;
#include "ldb/include/ldb_private.h"
#include "librpc/gen_ndr/ndr_misc.h"
-static int objectguid_search_bytree(struct ldb_module *module, const struct ldb_dn *base,
- enum ldb_scope scope, struct ldb_parse_tree *tree,
- const char * const *attrs, struct ldb_message ***res)
-{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "objectguid_search\n");
- return ldb_next_search_bytree(module, base, scope, tree, attrs, res);
-}
-
static struct ldb_message_element *objectguid_find_attribute(const struct ldb_message *msg, const char *name)
{
int i;
}
/* add_record: add objectGUID attribute */
-static int objectguid_add_record(struct ldb_module *module, const struct ldb_message *msg)
+static int objectguid_add(struct ldb_module *module, struct ldb_request *req)
{
+ const struct ldb_message *msg = req->op.add.message;
struct ldb_val v;
struct ldb_message *msg2;
struct ldb_message_element *attribute;
ldb_debug(module->ldb, LDB_DEBUG_TRACE, "objectguid_add_record\n");
if (ldb_dn_is_special(msg->dn)) { /* do not manipulate our control entries */
- return ldb_next_add_record(module, msg);
+ return ldb_next_request(module, req);
}
if ((attribute = objectguid_find_attribute(msg, "objectGUID")) != NULL ) {
- return ldb_next_add_record(module, msg);
+ return ldb_next_request(module, req);
}
msg2 = talloc(module, struct ldb_message);
return ret;
}
- ret = ldb_next_add_record(module, msg2);
+ req->op.add.message = msg2;
+ ret = ldb_next_request(module, req);
+ req->op.add.message = msg;
+
talloc_free(msg2);
return ret;
}
+static int objectguid_request(struct ldb_module *module, struct ldb_request *req)
+{
+ switch (req->operation) {
+
+ case LDB_REQ_ADD:
+ return objectguid_add(module, req);
+
+ default:
+ return ldb_next_request(module, req);
+
+ }
+}
+
static const struct ldb_module_ops objectguid_ops = {
.name = "objectguid",
- .search_bytree = objectguid_search_bytree,
- .add_record = objectguid_add_record
+ .request = objectguid_request
};
#include "includes.h"
#include "ldb/include/ldb.h"
+#include "ldb/include/ldb_errors.h"
#include "ldb/include/ldb_private.h"
#include "lib/cmdline/popt_common.h"
{
struct proxy_data *proxy = talloc_get_type(module->private_data, struct proxy_data);
struct ldb_dn *dn;
- struct ldb_message **msg;
- int res;
+ struct ldb_result *res;
+ int ret;
const char *olddn, *newdn, *url, *username, *password, *oldstr, *newstr;
struct cli_credentials *creds;
if (dn == NULL) {
goto failed;
}
- res = ldb_search(module->ldb, dn, LDB_SCOPE_BASE, NULL, NULL, &msg);
+ ret = ldb_search(module->ldb, dn, LDB_SCOPE_BASE, NULL, NULL, &res);
talloc_free(dn);
- if (res != 1) {
+ if (ret != LDB_SUCCESS || res->count != 1) {
ldb_debug(module->ldb, LDB_DEBUG_FATAL, "Can't find @PROXYINFO\n");
goto failed;
}
- url = ldb_msg_find_string(msg[0], "url", NULL);
- olddn = ldb_msg_find_string(msg[0], "olddn", NULL);
- newdn = ldb_msg_find_string(msg[0], "newdn", NULL);
- username = ldb_msg_find_string(msg[0], "username", NULL);
- password = ldb_msg_find_string(msg[0], "password", NULL);
- oldstr = ldb_msg_find_string(msg[0], "oldstr", NULL);
- newstr = ldb_msg_find_string(msg[0], "newstr", NULL);
+ url = ldb_msg_find_string(res->msgs[0], "url", NULL);
+ olddn = ldb_msg_find_string(res->msgs[0], "olddn", NULL);
+ newdn = ldb_msg_find_string(res->msgs[0], "newdn", NULL);
+ username = ldb_msg_find_string(res->msgs[0], "username", NULL);
+ password = ldb_msg_find_string(res->msgs[0], "password", NULL);
+ oldstr = ldb_msg_find_string(res->msgs[0], "oldstr", NULL);
+ newstr = ldb_msg_find_string(res->msgs[0], "newstr", NULL);
if (url == NULL || olddn == NULL || newdn == NULL || username == NULL || password == NULL) {
ldb_debug(module->ldb, LDB_DEBUG_FATAL, "Need url, olddn, newdn, oldstr, newstr, username and password in @PROXYINFO\n");
ldb_set_opaque(proxy->upstream, "credentials", creds);
- res = ldb_connect(proxy->upstream, url, 0, NULL);
- if (res != 0) {
+ ret = ldb_connect(proxy->upstream, url, 0, NULL);
+ if (ret != 0) {
ldb_debug(module->ldb, LDB_DEBUG_FATAL, "proxy failed to connect to %s\n", url);
goto failed;
}
ldb_debug(module->ldb, LDB_DEBUG_TRACE, "proxy connected to %s\n", url);
- talloc_free(msg);
+ talloc_free(res);
return 0;
failed:
- talloc_free(msg);
+ talloc_free(res);
talloc_free(proxy->olddn);
talloc_free(proxy->newdn);
talloc_free(proxy->upstream);
}
/* search */
-static int proxy_search_bytree(struct ldb_module *module, const struct ldb_dn *base,
- enum ldb_scope scope, struct ldb_parse_tree *tree,
- const char * const *attrs, struct ldb_message ***res)
+static int proxy_search_bytree(struct ldb_module *module, struct ldb_request *req)
{
struct proxy_data *proxy = talloc_get_type(module->private_data, struct proxy_data);
- struct ldb_dn *newbase;
+ struct ldb_request newreq;
+ struct ldb_dn *base;
int ret, i;
- if (base == NULL || (base->comp_num == 1 && base->components[0].name[0] == '@')) {
+ if (req->op.search.base == NULL ||
+ (req->op.search.base->comp_num == 1 &&
+ req->op.search.base->components[0].name[0] == '@')) {
goto passthru;
}
}
/* see if the dn is within olddn */
- if (ldb_dn_compare_base(module->ldb, proxy->newdn, base) != 0) {
+ if (ldb_dn_compare_base(module->ldb, proxy->newdn, req->op.search.base) != 0) {
goto passthru;
}
- tree = proxy_convert_tree(module, tree);
+ newreq.op.search.tree = proxy_convert_tree(module, req->op.search.tree);
/* convert the basedn of this search */
- newbase = ldb_dn_copy(proxy, base);
- if (newbase == NULL) {
+ base = ldb_dn_copy(proxy, req->op.search.base);
+ if (base == NULL) {
goto failed;
}
- newbase->comp_num -= proxy->newdn->comp_num;
- newbase = ldb_dn_compose(proxy, newbase, proxy->olddn);
+ base->comp_num -= proxy->newdn->comp_num;
+ base = ldb_dn_compose(proxy, newreq.op.search.base, proxy->olddn);
ldb_debug(module->ldb, LDB_DEBUG_FATAL, "proxying: '%s' with dn '%s' \n",
- ldb_filter_from_tree(proxy, tree), ldb_dn_linearize(proxy, newbase));
- for (i=0;attrs && attrs[i];i++) {
- ldb_debug(module->ldb, LDB_DEBUG_FATAL, "attr: '%s'\n", attrs[i]);
+ ldb_filter_from_tree(proxy, newreq.op.search.tree), ldb_dn_linearize(proxy, newreq.op.search.base));
+ for (i = 0; req->op.search.attrs && req->op.search.attrs[i]; i++) {
+ ldb_debug(module->ldb, LDB_DEBUG_FATAL, "attr: '%s'\n", req->op.search.attrs[i]);
}
-
- ret = ldb_search_bytree(proxy->upstream, newbase, scope, tree, attrs, res);
- if (ret == -1) {
+
+ newreq.op.search.base = base;
+ newreq.op.search.scope = req->op.search.scope;
+ newreq.op.search.attrs = req->op.search.attrs;
+ newreq.op.search.res = req->op.search.res;
+ ret = ldb_request(proxy->upstream, &newreq);
+ if (ret != LDB_SUCCESS) {
ldb_set_errstring(module, talloc_strdup(module, ldb_errstring(proxy->upstream)));
return -1;
}
- for (i=0;i<ret;i++) {
+ for (i = 0; i < (*newreq.op.search.res)->count; i++) {
struct ldb_ldif ldif;
printf("# record %d\n", i+1);
- proxy_convert_record(module, (*res)[i]);
+ proxy_convert_record(module, (*newreq.op.search.res)->msgs[i]);
ldif.changetype = LDB_CHANGETYPE_NONE;
- ldif.msg = (*res)[i];
+ ldif.msg = (*newreq.op.search.res)->msgs[i];
}
return ret;
failed:
ldb_debug(module->ldb, LDB_DEBUG_TRACE, "proxy failed for %s\n",
- ldb_dn_linearize(proxy, base));
+ ldb_dn_linearize(proxy, req->op.search.base));
passthru:
- return ldb_next_search_bytree(module, base, scope, tree, attrs, res);
+ return ldb_next_request(module, req);
}
+static int proxy_request(struct ldb_module *module, struct ldb_request *req)
+{
+ switch (req->operation) {
+
+ case LDB_REQ_SEARCH:
+ return proxy_search_bytree(module, req);
+
+ default:
+ return ldb_next_request(module, req);
+
+ }
+}
static const struct ldb_module_ops proxy_ops = {
- .name = "proxy",
- .search_bytree = proxy_search_bytree
+ .name = "proxy",
+ .request = proxy_request
};
#ifdef HAVE_DLOPEN_DISABLED
#include "includes.h"
#include "lib/ldb/include/ldb.h"
+#include "lib/ldb/include/ldb_errors.h"
#include "lib/ldb/include/ldb_private.h"
#include "system/time.h"
#include "librpc/gen_ndr/ndr_security.h"
#define SAM_ACCOUNT_NAME_BASE "$000000-000000000000"
-static int samldb_search_bytree(struct ldb_module *module, const struct ldb_dn *base,
- enum ldb_scope scope, struct ldb_parse_tree *tree,
- const char * const *attrs, struct ldb_message ***res)
-{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "samldb_search\n");
- return ldb_next_search_bytree(module, base, scope, tree, attrs, res);
-}
-
/*
allocate a new id, attempting to do it atomically
return 0 on failure, the id on success
const struct ldb_dn *dn, uint32_t *id)
{
const char * const attrs[2] = { "nextRid", NULL };
- struct ldb_message **res = NULL;
+ struct ldb_result *res = NULL;
struct ldb_message msg;
int ret;
const char *str;
struct ldb_message_element els[2];
ret = ldb_search(ldb, dn, LDB_SCOPE_BASE, "nextRid=*", attrs, &res);
- if (ret != 1) {
+ if (ret != LDB_SUCCESS || res->count != 1) {
if (res) talloc_free(res);
return -1;
}
- str = ldb_msg_find_string(res[0], "nextRid", NULL);
+ str = ldb_msg_find_string(res->msgs[0], "nextRid", NULL);
if (str == NULL) {
ldb_debug(ldb, LDB_DEBUG_FATAL, "attribute nextRid not found in %s\n", ldb_dn_linearize(res, dn));
talloc_free(res);
{
TALLOC_CTX *local_ctx;
struct ldb_dn *sdn;
- struct ldb_message **res = NULL;
+ struct ldb_result *res = NULL;
int ret = 0;
local_ctx = talloc_named(mem_ctx, 0, "samldb_search_domain memory conext");
ret = ldb_search(module->ldb, sdn, LDB_SCOPE_BASE, "objectClass=domain", NULL, &res);
talloc_free(res);
- if (ret == 1)
+ if (ret == LDB_SUCCESS && res->count == 1)
break;
} while ((sdn = ldb_dn_get_parent(local_ctx, sdn)));
- if (ret != 1) {
+ if (ret != LDB_SUCCESS || res->count != 1) {
talloc_free(local_ctx);
return NULL;
}
TALLOC_CTX *mem_ctx, const struct ldb_dn *obj_dn)
{
const char * const attrs[2] = { "objectSid", NULL };
- struct ldb_message **res = NULL;
+ struct ldb_result *res = NULL;
const struct ldb_dn *dom_dn;
uint32_t rid;
int ret;
/* find the domain sid */
ret = ldb_search(module->ldb, dom_dn, LDB_SCOPE_BASE, "objectSid=*", attrs, &res);
- if (ret != 1) {
+ if (ret != LDB_SUCCESS || res->count != 1) {
ldb_debug(module->ldb, LDB_DEBUG_FATAL, "samldb_get_new_sid: error retrieving domain sid!\n");
talloc_free(res);
return NULL;
}
- dom_sid = samdb_result_dom_sid(res, res[0], "objectSid");
+ dom_sid = samdb_result_dom_sid(res, res->msgs[0], "objectSid");
if (dom_sid == NULL) {
ldb_debug(module->ldb, LDB_DEBUG_FATAL, "samldb_get_new_sid: error retrieving domain sid!\n");
talloc_free(res);
static int samldb_copy_template(struct ldb_module *module, struct ldb_message *msg, const char *filter)
{
- struct ldb_message **res, *t;
+ struct ldb_result *res;
+ struct ldb_message *t;
int ret, i, j;
/* pull the template record */
ret = ldb_search(module->ldb, NULL, LDB_SCOPE_SUBTREE, filter, NULL, &res);
- if (ret != 1) {
- ldb_debug(module->ldb, LDB_DEBUG_WARNING, "samldb: ERROR: template '%s' matched %d records\n", filter, ret);
+ if (ret != LDB_SUCCESS || res->count != 1) {
+ ldb_debug(module->ldb, LDB_DEBUG_WARNING, "samldb: ERROR: template '%s' matched too many records\n", filter);
return -1;
}
- t = res[0];
+ t = res->msgs[0];
for (i = 0; i < t->num_elements; i++) {
struct ldb_message_element *el = &t->elements[i];
}
/* add_record */
-static int samldb_add_record(struct ldb_module *module, const struct ldb_message *msg)
+static int samldb_add(struct ldb_module *module, struct ldb_request *req)
{
+ const struct ldb_message *msg = req->op.add.message;
struct ldb_message *msg2 = NULL;
int ret;
if (ldb_dn_is_special(msg->dn)) { /* do not manipulate our control entries */
- return ldb_next_add_record(module, msg);
+ return ldb_next_request(module, req);
}
/* is user or computer? add all relevant missing objects */
}
if (msg2) {
- ret = ldb_next_add_record(module, msg2);
+ req->op.add.message = msg2;
+ ret = ldb_next_request(module, req);
+ req->op.add.message = msg;
} else {
- ret = ldb_next_add_record(module, msg);
+ ret = ldb_next_request(module, req);
}
return ret;
}
-/* modify_record: change modifyTimestamp as well */
-static int samldb_modify_record(struct ldb_module *module, const struct ldb_message *msg)
+static int samldb_destructor(void *module_ctx)
{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "samldb_modify_record\n");
- return ldb_next_modify_record(module, msg);
+ /* struct ldb_module *ctx = module_ctx; */
+ /* put your clean-up functions here */
+ return 0;
}
-static int samldb_delete_record(struct ldb_module *module, const struct ldb_dn *dn)
+static int samldb_request(struct ldb_module *module, struct ldb_request *req)
{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "samldb_delete_record\n");
- return ldb_next_delete_record(module, dn);
-}
+ switch (req->operation) {
-static int samldb_rename_record(struct ldb_module *module, const struct ldb_dn *olddn, const struct ldb_dn *newdn)
-{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "samldb_rename_record\n");
- return ldb_next_rename_record(module, olddn, newdn);
-}
+ case LDB_REQ_ADD:
+ return samldb_add(module, req);
-static int samldb_destructor(void *module_ctx)
-{
- /* struct ldb_module *ctx = module_ctx; */
- /* put your clean-up functions here */
- return 0;
+ default:
+ return ldb_next_request(module, req);
+
+ }
}
static const struct ldb_module_ops samldb_ops = {
.name = "samldb",
- .search_bytree = samldb_search_bytree,
- .add_record = samldb_add_record,
- .modify_record = samldb_modify_record,
- .delete_record = samldb_delete_record,
- .rename_record = samldb_rename_record
+ .request = samldb_request
};
#include "ads.h"
#include "hdb.h"
#include "lib/ldb/include/ldb.h"
+#include "lib/ldb/include/ldb_errors.h"
#include "system/iconv.h"
#include "librpc/gen_ndr/netlogon.h"
struct ldb_message ***pmsg)
{
krb5_error_code ret;
- int count;
+ int lret;
char *filter = NULL;
const char * const *princ_attrs = krb5_attrs;
char *realm_dn_str;
- struct ldb_message **msg = NULL;
+ struct ldb_result *res = NULL;
ret = krb5_unparse_name(context, principal, &princ_str);
return ENOMEM;
}
- count = ldb_search(ldb_ctx, realm_dn, LDB_SCOPE_SUBTREE, filter,
- princ_attrs, &msg);
+ lret = ldb_search(ldb_ctx, realm_dn, LDB_SCOPE_SUBTREE, filter, princ_attrs, &res);
realm_dn_str = ldb_dn_linearize(mem_ctx, realm_dn);
- if (count < 1) {
- krb5_warnx(context, "ldb_search: basedn: '%s' filter: '%s' failed: %d",
- realm_dn_str, filter, count);
- krb5_set_error_string(context, "ldb_search: basedn: '%s' filter: '%s' failed: %d",
- realm_dn_str, filter, count);
+ if (lret != LDB_SUCCESS || res->count == 0) {
+ krb5_warnx(context, "ldb_search: basedn: '%s' filter: '%s' failed: %s",
+ realm_dn_str, filter, ldb_errstring(ldb_ctx));
+ krb5_set_error_string(context, "ldb_search: basedn: '%s' filter: '%s' failed: %s",
+ realm_dn_str, filter, ldb_errstring(ldb_ctx));
return HDB_ERR_NOENTRY;
- } else if (count > 1) {
- talloc_free(msg);
+ } else if (res->count > 1) {
krb5_warnx(context, "ldb_search: basedn: '%s' filter: '%s' more than 1 entry: %d",
- realm_dn_str, filter, count);
+ realm_dn_str, filter, res->count);
krb5_set_error_string(context, "ldb_search: basedn: '%s' filter: '%s' more than 1 entry: %d",
- realm_dn_str, filter, count);
+ realm_dn_str, filter, res->count);
+ talloc_free(res);
return HDB_ERR_NOENTRY;
}
- *pmsg = talloc_steal(mem_ctx, msg);
+ *pmsg = talloc_steal(mem_ctx, res->msgs);
+ talloc_free(res);
return 0;
}
const char *realm,
struct ldb_message ***pmsg)
{
- int count;
+ int ret;
char *cross_ref_filter;
- struct ldb_message **cross_ref_msg;
+ struct ldb_result *cross_ref_res;
cross_ref_filter = talloc_asprintf(mem_ctx,
"(&(&(|(&(dnsRoot=%s)(nETBIOSName=*))(nETBIOSName=%s))(objectclass=crossRef))(ncName=*))",
return ENOMEM;
}
- count = ldb_search(ldb_ctx, NULL, LDB_SCOPE_SUBTREE, cross_ref_filter,
- realm_ref_attrs, &cross_ref_msg);
+ ret = ldb_search(ldb_ctx, NULL, LDB_SCOPE_SUBTREE, cross_ref_filter, realm_ref_attrs, &cross_ref_res);
- if (count < 1) {
- krb5_warnx(context, "ldb_search: filter: '%s' failed: %d", cross_ref_filter, count);
- krb5_set_error_string(context, "ldb_search: filter: '%s' failed: %d", cross_ref_filter, count);
+ if (ret != LDB_SUCCESS || cross_ref_res->count == 0) {
+ krb5_warnx(context, "ldb_search: filter: '%s' failed: %s", cross_ref_filter, ldb_errstring(ldb_ctx));
+ krb5_set_error_string(context, "ldb_search: filter: '%s' failed: %s", cross_ref_filter, ldb_errstring(ldb_ctx));
- talloc_free(cross_ref_msg);
+ talloc_free(cross_ref_res);
return HDB_ERR_NOENTRY;
- } else if (count > 1) {
- krb5_warnx(context, "ldb_search: filter: '%s' more than 1 entry: %d", cross_ref_filter, count);
- krb5_set_error_string(context, "ldb_search: filter: '%s' more than 1 entry: %d", cross_ref_filter, count);
+ } else if (cross_ref_res->count > 1) {
+ krb5_warnx(context, "ldb_search: filter: '%s' more than 1 entry: %d", cross_ref_filter, cross_ref_res->count);
+ krb5_set_error_string(context, "ldb_search: filter: '%s' more than 1 entry: %d", cross_ref_filter, cross_ref_res->count);
- talloc_free(cross_ref_msg);
+ talloc_free(cross_ref_res);
return HDB_ERR_NOENTRY;
}
if (pmsg) {
- *pmsg = talloc_steal(mem_ctx, cross_ref_msg);
+ *pmsg = talloc_steal(mem_ctx, cross_ref_res->msgs);
} else {
- talloc_free(cross_ref_msg);
+ talloc_free(cross_ref_res);
}
return 0;
struct hdb_ldb_seq *priv = (struct hdb_ldb_seq *)db->hdb_openp;
char *realm;
struct ldb_dn *realm_dn = NULL;
- struct ldb_message **msgs = NULL;
+ struct ldb_result *res = NULL;
struct ldb_message **realm_ref_msgs = NULL;
krb5_error_code ret;
TALLOC_CTX *mem_ctx;
+ int lret;
if (priv) {
talloc_free(priv);
krb5_warnx(context, "LDB_firstkey: realm ok\n");
- priv->count = ldb_search(ldb_ctx, realm_dn,
+ lret = ldb_search(ldb_ctx, realm_dn,
LDB_SCOPE_SUBTREE, "(objectClass=user)",
- krb5_attrs, &msgs);
+ krb5_attrs, &res);
- priv->msgs = talloc_steal(priv, msgs);
-
- if (priv->count <= 0) {
+ if (lret != LDB_SUCCESS) {
talloc_free(priv);
return HDB_ERR_NOENTRY;
}
+ priv->count = res->count;
+ priv->msgs = talloc_steal(priv, res->msgs);
+
db->hdb_openp = priv;
ret = LDB_seq(context, db, flags, entry);
#include "ldap_server/ldap_server.h"
#include "system/time.h"
#include "lib/ldb/include/ldb.h"
+#include "lib/ldb/include/ldb_errors.h"
#define ATTR_BLOB_CONST(val) data_blob_talloc(mem_ctx, val, sizeof(val)-1)
void *local_ctx;
struct ldap_SearchResEntry *ent;
struct ldap_Result *done;
- struct ldb_message **res = NULL;
+ struct ldb_result *res = NULL;
int result = LDAP_SUCCESS;
struct ldapsrv_reply *ent_r, *done_r;
struct ldb_context *ldb;
const char *errstr = NULL;
- int count, j;
+ int ret, j;
const char **attrs = NULL;
if (r->scope != LDAP_SEARCH_SCOPE_BASE) {
attrs[j] = NULL;
}
- count = ldb_search(ldb, ldb_dn_explode(local_ctx, "cn=rootDSE"), 0,
- NULL, attrs, &res);
+ ret = ldb_search(ldb, ldb_dn_explode(local_ctx, "cn=rootDSE"), 0, NULL, attrs, &res);
talloc_steal(local_ctx, res);
- if (count == 1) {
+ if (ret == LDB_SUCCESS && res->count == 1) {
ent_r = ldapsrv_init_reply(call, LDAP_TAG_SearchResultEntry);
NT_STATUS_HAVE_NO_MEMORY(ent_r);
ent->dn = "";
ent->num_attributes = 0;
ent->attributes = NULL;
- if (res[0]->num_elements == 0) {
+ if (res->msgs[0]->num_elements == 0) {
goto queue_reply;
}
- ent->num_attributes = res[0]->num_elements;
- ent->attributes = talloc_steal(ent_r, res[0]->elements);
+ ent->num_attributes = res->msgs[0]->num_elements;
+ ent->attributes = talloc_steal(ent_r, res->msgs[0]->elements);
for (j=0; j < ent->num_attributes; j++) {
if (ent->attributes[j].num_values == 1 &&
done_r = ldapsrv_init_reply(call, LDAP_TAG_SearchResultDone);
NT_STATUS_HAVE_NO_MEMORY(done_r);
- if (count == 1) {
- DEBUG(10,("rootdse_Search: results: [%d]\n",count));
- result = LDAP_SUCCESS;
- errstr = NULL;
- } else if (count == 0) {
+ if (ret != LDB_SUCCESS) {
+ DEBUG(10,("rootdse_Search: error\n"));
+ result = LDAP_OTHER;
+ errstr = ldb_errstring(ldb);
+ } else if (res->count == 0) {
DEBUG(10,("rootdse_Search: no results\n"));
result = LDAP_NO_SUCH_OBJECT;
errstr = ldb_errstring(ldb);
- } else if (count > 1) {
- DEBUG(10,("rootdse_Search: too many results[%d]\n", count));
+ } else if (res->count == 1) {
+ DEBUG(10,("rootdse_Search: results: [%d]\n", res->count));
+ result = LDAP_SUCCESS;
+ errstr = NULL;
+ } else if (res->count > 1) {
+ DEBUG(10,("rootdse_Search: too many results[%d]\n", res->count));
result = LDAP_OTHER;
errstr = "internal error";
- } else if (count == -1) {
- DEBUG(10,("rootdse_Search: error\n"));
- result = LDAP_OTHER;
- errstr = ldb_errstring(ldb);
}
done = &done_r->msg->r.SearchResultDone;
#include "includes.h"
#include "ldap_server/ldap_server.h"
#include "lib/ldb/include/ldb.h"
+#include "lib/ldb/include/ldb_errors.h"
#include "auth/auth.h"
#include "db_wrap.h"
struct ldapsrv_reply *ent_r, *done_r;
int result = LDAP_SUCCESS;
struct ldb_context *samdb;
- struct ldb_message **res = NULL;
- int i, j, y, count = 0;
+ struct ldb_result *res = NULL;
+ int i, j, y, ret;
int success_limit = 1;
enum ldb_scope scope = LDB_SCOPE_DEFAULT;
const char **attrs = NULL;
const char *errstr = NULL;
+ struct ldb_request lreq;
local_ctx = talloc_named(call, 0, "sldb_Search local memory context");
NT_STATUS_HAVE_NO_MEMORY(local_ctx);
attrs[i] = NULL;
}
- DEBUG(5,("ldb_search_bytree dn=%s filter=%s\n",
+ DEBUG(5,("ldb_request dn=%s filter=%s\n",
r->basedn, ldb_filter_from_tree(call, r->tree)));
- count = ldb_search_bytree(samdb, basedn, scope, r->tree, attrs, &res);
- talloc_steal(samdb, res);
+ ZERO_STRUCT(lreq);
+ lreq.operation = LDB_REQ_SEARCH;
+ lreq.op.search.base = basedn;
+ lreq.op.search.scope = scope;
+ lreq.op.search.tree = r->tree;
+ lreq.op.search.attrs = attrs;
+ lreq.op.search.res = &res;
- for (i=0; i < count; i++) {
- ent_r = ldapsrv_init_reply(call, LDAP_TAG_SearchResultEntry);
- NT_STATUS_HAVE_NO_MEMORY(ent_r);
+ ret = ldb_request(samdb, &lreq);
+ talloc_steal(samdb, res);
- ent = &ent_r->msg->r.SearchResultEntry;
- ent->dn = ldb_dn_linearize(ent_r, res[i]->dn);
- ent->num_attributes = 0;
- ent->attributes = NULL;
- if (res[i]->num_elements == 0) {
- goto queue_reply;
- }
- ent->num_attributes = res[i]->num_elements;
- ent->attributes = talloc_array(ent_r, struct ldb_message_element, ent->num_attributes);
- NT_STATUS_HAVE_NO_MEMORY(ent->attributes);
- for (j=0; j < ent->num_attributes; j++) {
- ent->attributes[j].name = talloc_steal(ent->attributes, res[i]->elements[j].name);
- ent->attributes[j].num_values = 0;
- ent->attributes[j].values = NULL;
- if (r->attributesonly && (res[i]->elements[j].num_values == 0)) {
- continue;
+ if (ret == LDB_SUCCESS) {
+ for (i = 0; i < res->count; i++) {
+ ent_r = ldapsrv_init_reply(call, LDAP_TAG_SearchResultEntry);
+ NT_STATUS_HAVE_NO_MEMORY(ent_r);
+
+ ent = &ent_r->msg->r.SearchResultEntry;
+ ent->dn = ldb_dn_linearize(ent_r, res->msgs[i]->dn);
+ ent->num_attributes = 0;
+ ent->attributes = NULL;
+ if (res->msgs[i]->num_elements == 0) {
+ goto queue_reply;
}
- ent->attributes[j].num_values = res[i]->elements[j].num_values;
- ent->attributes[j].values = talloc_array(ent->attributes,
- DATA_BLOB, ent->attributes[j].num_values);
- NT_STATUS_HAVE_NO_MEMORY(ent->attributes[j].values);
- for (y=0; y < ent->attributes[j].num_values; y++) {
- ent->attributes[j].values[y].length = res[i]->elements[j].values[y].length;
- ent->attributes[j].values[y].data = talloc_steal(ent->attributes[j].values,
- res[i]->elements[j].values[y].data);
+ ent->num_attributes = res->msgs[i]->num_elements;
+ ent->attributes = talloc_array(ent_r, struct ldb_message_element, ent->num_attributes);
+ NT_STATUS_HAVE_NO_MEMORY(ent->attributes);
+ for (j=0; j < ent->num_attributes; j++) {
+ ent->attributes[j].name = talloc_steal(ent->attributes, res->msgs[i]->elements[j].name);
+ ent->attributes[j].num_values = 0;
+ ent->attributes[j].values = NULL;
+ if (r->attributesonly && (res->msgs[i]->elements[j].num_values == 0)) {
+ continue;
+ }
+ ent->attributes[j].num_values = res->msgs[i]->elements[j].num_values;
+ ent->attributes[j].values = talloc_array(ent->attributes,
+ DATA_BLOB, ent->attributes[j].num_values);
+ NT_STATUS_HAVE_NO_MEMORY(ent->attributes[j].values);
+ for (y=0; y < ent->attributes[j].num_values; y++) {
+ ent->attributes[j].values[y].length = res->msgs[i]->elements[j].values[y].length;
+ ent->attributes[j].values[y].data = talloc_steal(ent->attributes[j].values,
+ res->msgs[i]->elements[j].values[y].data);
+ }
}
- }
queue_reply:
- ldapsrv_queue_reply(call, ent_r);
+ ldapsrv_queue_reply(call, ent_r);
+ }
}
reply:
done_r = ldapsrv_init_reply(call, LDAP_TAG_SearchResultDone);
NT_STATUS_HAVE_NO_MEMORY(done_r);
- if (result == LDAP_SUCCESS) {
- if (count >= success_limit) {
- DEBUG(10,("sldb_Search: results: [%d]\n",count));
+ if (ret == LDB_SUCCESS) {
+ if (res->count >= success_limit) {
+ DEBUG(10,("sldb_Search: results: [%d]\n", res->count));
result = LDAP_SUCCESS;
errstr = NULL;
- } else if (count == 0) {
+ } else if (res->count == 0) {
DEBUG(10,("sldb_Search: no results\n"));
result = LDAP_NO_SUCH_OBJECT;
errstr = ldb_errstring(samdb);
- } else if (count == -1) {
- DEBUG(10,("sldb_Search: error\n"));
- result = LDAP_OTHER;
- errstr = ldb_errstring(samdb);
}
+ } else {
+ DEBUG(10,("sldb_Search: error\n"));
+ result = ret;
+ errstr = ldb_errstring(samdb);
}
done = &done_r->msg->r.SearchResultDone;
done->dn = NULL;
done->resultcode = result;
- done->errormessage = (errstr?talloc_strdup(done_r,errstr):NULL);
+ done->errormessage = (errstr?talloc_strdup(done_r, errstr):NULL);
done->referral = NULL;
talloc_free(local_ctx);
struct ldapsrv_reply *compare_r;
int result = LDAP_SUCCESS;
struct ldb_context *samdb;
- struct ldb_message **res = NULL;
+ struct ldb_result *res = NULL;
const char *attrs[1];
const char *errstr = NULL;
const char *filter = NULL;
- int count;
+ int ret;
local_ctx = talloc_named(call, 0, "sldb_Compare local_memory_context");
NT_STATUS_HAVE_NO_MEMORY(local_ctx);
NT_STATUS_HAVE_NO_MEMORY(compare_r);
if (result == LDAP_SUCCESS) {
- count = ldb_search(samdb, dn, LDB_SCOPE_BASE, filter, attrs, &res);
+ ret = ldb_search(samdb, dn, LDB_SCOPE_BASE, filter, attrs, &res);
talloc_steal(samdb, res);
- if (count == 1) {
- DEBUG(10,("sldb_Compare: matched\n"));
- result = LDAP_COMPARE_TRUE;
- errstr = NULL;
- } else if (count == 0) {
+ if (ret != LDB_SUCCESS) {
+ result = LDAP_OTHER;
+ errstr = ldb_errstring(samdb);
+ DEBUG(10,("sldb_Compare: error: %s\n", errstr));
+ } else if (res->count == 0) {
DEBUG(10,("sldb_Compare: doesn't matched\n"));
result = LDAP_COMPARE_FALSE;
errstr = NULL;
- } else if (count > 1) {
+ } else if (res->count == 1) {
+ DEBUG(10,("sldb_Compare: matched\n"));
+ result = LDAP_COMPARE_TRUE;
+ errstr = NULL;
+ } else if (res->count > 1) {
result = LDAP_OTHER;
errstr = "too many objects match";
- DEBUG(10,("sldb_Compare: %d results: %s\n", count, errstr));
- } else if (count == -1) {
- result = LDAP_OTHER;
- errstr = ldb_errstring(samdb);
- DEBUG(10,("sldb_Compare: error: %s\n", errstr));
+ DEBUG(10,("sldb_Compare: %d results: %s\n", res->count, errstr));
}
}
#include "includes.h"
#include "lib/ldb/include/ldb.h"
+#include "lib/ldb/include/ldb_errors.h"
/*
search the sam for the specified attributes - va_list variant
int gendb_search_v(struct ldb_context *ldb,
TALLOC_CTX *mem_ctx,
const struct ldb_dn *basedn,
- struct ldb_message ***res,
+ struct ldb_message ***msgs,
const char * const *attrs,
const char *format,
va_list ap) _PRINTF_ATTRIBUTE(6,0)
{
enum ldb_scope scope = LDB_SCOPE_SUBTREE;
+ struct ldb_result *res;
char *expr = NULL;
- int count;
+ int ret;
if (format) {
vasprintf(&expr, format, ap);
scope = LDB_SCOPE_BASE;
}
- *res = NULL;
+ res = NULL;
+
+ ret = ldb_search(ldb, basedn, scope, expr, attrs, &res);
+
+ if (ret == LDB_SUCCESS) {
+ talloc_steal(mem_ctx, res);
- count = ldb_search(ldb, basedn, scope, expr, attrs, res);
+ DEBUG(4,("gendb_search_v: %s %s -> %d\n",
+ basedn?ldb_dn_linearize(mem_ctx,basedn):"NULL",
+ expr?expr:"NULL", res->count));
- if (*res) talloc_steal(mem_ctx, *res);
+ ret = res->count;
+ *msgs = res->msgs;
- DEBUG(4,("gendb_search_v: %s %s -> %d (%s)\n",
- basedn?ldb_dn_linearize(mem_ctx,basedn):"NULL",
- expr?expr:"NULL", count,
- count==-1?ldb_errstring(ldb):"OK"));
+ } else {
+ DEBUG(4,("gendb_search_v: search failed: %s", ldb_errstring(ldb)));
+ ret = -1;
+ }
free(expr);
- return count;
+ return ret;
}
/*
return module->ops->del_transaction(module);
}
+/*
+ check for an error return from an op
+ if an op fails, but has not setup an error string, then setup one now
+*/
+static int ldb_op_finish(struct ldb_context *ldb, int status)
+{
+ if (status == LDB_SUCCESS) {
+ return ldb_transaction_commit(ldb);
+ }
+ if (ldb->err_string == NULL) {
+ /* no error string was setup by the backend */
+ ldb_set_errstring(ldb->modules,
+ talloc_asprintf(ldb, "ldb error %d", status));
+ }
+ ldb_transaction_cancel(ldb);
+ return status;
+}
+
+/*
+ start an ldb request
+ autostarts a transacion if none active and the operation is not a search
+ returns -1 on errors.
+*/
+
+int ldb_request(struct ldb_context *ldb, struct ldb_request *request)
+{
+ int status;
+
+ ldb_reset_err_string(ldb);
+
+ if ((!ldb->transaction_active) &&
+ (request->operation == LDB_REQ_ADD ||
+ request->operation == LDB_REQ_MODIFY ||
+ request->operation == LDB_REQ_DELETE ||
+ request->operation == LDB_REQ_RENAME)) {
+
+ status = ldb_transaction_start(ldb);
+ if (status != LDB_SUCCESS) return status;
+
+ status = ldb->modules->ops->request(ldb->modules, request);
+ return ldb_op_finish(ldb, status);
+ }
+
+ return ldb->modules->ops->request(ldb->modules, request);
+}
+
/*
search the database given a LDAP-like search expression
const struct ldb_dn *base,
enum ldb_scope scope,
const char *expression,
- const char * const *attrs, struct ldb_message ***res)
+ const char * const *attrs, struct ldb_result **res)
{
+ struct ldb_request *request;
struct ldb_parse_tree *tree;
int ret;
+ request = talloc(ldb, struct ldb_request);
+ if (request == NULL) {
+ ldb_set_errstring(ldb->modules, talloc_strdup(ldb, "Not Enough memory"));
+ return -1;
+ }
+
tree = ldb_parse_tree(ldb, expression);
if (tree == NULL) {
ldb_set_errstring(ldb->modules, talloc_strdup(ldb, "Unable to parse search expression"));
return -1;
}
- ret = ldb_search_bytree(ldb, base, scope, tree, attrs, res);
- talloc_free(tree);
-
- return ret;
-}
-
-/*
- search the database given a search tree
-
- return the number of records found, or -1 on error
-
- Use talloc_free to free the ldb_message returned in 'res'
-
-*/
-int ldb_search_bytree(struct ldb_context *ldb,
- const struct ldb_dn *base,
- enum ldb_scope scope,
- struct ldb_parse_tree *tree,
- const char * const *attrs, struct ldb_message ***res)
-{
- struct ldb_module *module;
- FIRST_OP(ldb, search_bytree);
+ request->operation = LDB_REQ_SEARCH;
+ request->op.search.base = base;
+ request->op.search.scope = scope;
+ request->op.search.tree = tree;
+ request->op.search.attrs = attrs;
+ request->op.search.res = res;
- ldb_reset_err_string(ldb);
+ ret = ldb_request(ldb, request);
- return module->ops->search_bytree(module, base, scope, tree, attrs, res);
-}
+ talloc_free(tree);
-/*
- check for an error return from an op
- if an op fails, but has not setup an error string, then setup one now
-*/
-static int ldb_op_finish(struct ldb_context *ldb, int status)
-{
- if (status == LDB_SUCCESS) {
- return ldb_transaction_commit(ldb);
- }
- if (ldb->err_string == NULL) {
- /* no error string was setup by the backend */
- ldb_set_errstring(ldb->modules,
- talloc_asprintf(ldb, "ldb error %d", status));
- }
- ldb_transaction_cancel(ldb);
- return status;
+ return ret;
}
/*
int ldb_add(struct ldb_context *ldb,
const struct ldb_message *message)
{
- struct ldb_module *module;
+ struct ldb_request *request;
int status;
- FIRST_OP(ldb, add_record);
-
- ldb_reset_err_string(ldb);
-
status = ldb_msg_sanity_check(message);
if (status != LDB_SUCCESS) return status;
- if (! ldb->transaction_active) {
- status = ldb_transaction_start(ldb);
- if (status != LDB_SUCCESS) return status;
-
- status = module->ops->add_record(module, message);
- return ldb_op_finish(ldb, status);
+ request = talloc(ldb, struct ldb_request);
+ if (request == NULL) {
+ ldb_set_errstring(ldb->modules, talloc_strdup(ldb, "Not Enough memory"));
+ return -1;
}
- return module->ops->add_record(module, message);
+ request->operation = LDB_REQ_ADD;
+ request->op.add.message = message;
+
+ return ldb_request(ldb, request);
}
/*
int ldb_modify(struct ldb_context *ldb,
const struct ldb_message *message)
{
- struct ldb_module *module;
+ struct ldb_request *request;
int status;
- FIRST_OP(ldb, modify_record);
-
- ldb_reset_err_string(ldb);
-
status = ldb_msg_sanity_check(message);
if (status != LDB_SUCCESS) return status;
- if (! ldb->transaction_active) {
- status = ldb_transaction_start(ldb);
- if (status != LDB_SUCCESS) return status;
-
- status = module->ops->modify_record(module, message);
- return ldb_op_finish(ldb, status);
+ request = talloc(ldb, struct ldb_request);
+ if (request == NULL) {
+ ldb_set_errstring(ldb->modules, talloc_strdup(ldb, "Not Enough memory"));
+ return -1;
}
- return module->ops->modify_record(module, message);
+ request->operation = LDB_REQ_MODIFY;
+ request->op.mod.message = message;
+
+ return ldb_request(ldb, request);
}
*/
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;
+ struct ldb_request *request;
- status = module->ops->delete_record(module, dn);
- return ldb_op_finish(ldb, status);
+ request = talloc(ldb, struct ldb_request);
+ if (request == NULL) {
+ ldb_set_errstring(ldb->modules, talloc_strdup(ldb, "Not Enough memory"));
+ return -1;
}
- return module->ops->delete_record(module, dn);
+ request->operation = LDB_REQ_DELETE;
+ request->op.del.dn = dn;
+
+ return ldb_request(ldb, request);
}
/*
*/
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;
+ struct ldb_request *request;
- status = module->ops->rename_record(module, olddn, newdn);
- return ldb_op_finish(ldb, status);
+ request = talloc(ldb, struct ldb_request);
+ if (request == NULL) {
+ ldb_set_errstring(ldb->modules, talloc_strdup(ldb, "Not Enough memory"));
+ return -1;
}
- return module->ops->rename_record(module, olddn, newdn);
+ request->operation = LDB_REQ_RENAME;
+ request->op.rename.olddn = olddn;
+ request->op.rename.newdn = newdn;
+
+ return ldb_request(ldb, request);
}
#include "includes.h"
#include "ldb/include/ldb.h"
+#include "ldb/include/ldb_errors.h"
#include "ldb/include/ldb_private.h"
#include "dlinklist.h"
#include <sys/types.h>
if ((modules == NULL) && (strcmp("ldap", ldb->modules->ops->name) != 0)) {
int ret;
const char * const attrs[] = { "@LIST" , NULL};
- struct ldb_message **msg = NULL;
+ struct ldb_result *res = NULL;
struct ldb_dn *mods;
mods = ldb_dn_explode(ldb, "@MODULES");
return -1;
}
- ret = ldb_search(ldb, mods, LDB_SCOPE_BASE, "", attrs, &msg);
+ ret = ldb_search(ldb, mods, LDB_SCOPE_BASE, "", attrs, &res);
talloc_free(mods);
- if (ret == 0 || (ret == 1 && msg[0]->num_elements == 0)) {
+ if (ret == LDB_SUCCESS && (res->count == 0 || res->msgs[0]->num_elements == 0)) {
ldb_debug(ldb, LDB_DEBUG_TRACE, "no modules required by the db\n");
} else {
- if (ret < 0) {
+ if (ret != LDB_SUCCESS) {
ldb_debug(ldb, LDB_DEBUG_FATAL, "ldb error (%s) occurred searching for modules, bailing out\n", ldb_errstring(ldb));
return -1;
}
- if (ret > 1) {
- ldb_debug(ldb, LDB_DEBUG_FATAL, "Too many records found (%d), bailing out\n", ret);
- talloc_free(msg);
+ if (res->count > 1) {
+ ldb_debug(ldb, LDB_DEBUG_FATAL, "Too many records found (%d), bailing out\n", res->count);
+ talloc_free(res);
return -1;
}
modules = ldb_modules_list_from_string(ldb,
- (const char *)msg[0]->elements[0].values[0].data);
+ (const char *)res->msgs[0]->elements[0].values[0].data);
}
- talloc_free(msg);
+ talloc_free(res);
}
if (modules == NULL) {
/*
helper functions to call the next module in chain
*/
-int ldb_next_search_bytree(struct ldb_module *module,
- const struct ldb_dn *base,
- enum ldb_scope scope,
- struct ldb_parse_tree *tree,
- const char * const *attrs, struct ldb_message ***res)
+int ldb_next_request(struct ldb_module *module, struct ldb_request *request)
{
- FIND_OP(module, search_bytree);
- return module->ops->search_bytree(module, base, scope, tree, attrs, res);
-}
-
-int ldb_next_search(struct ldb_module *module,
- const struct ldb_dn *base,
- enum ldb_scope scope,
- const char *expression,
- const char * const *attrs, struct ldb_message ***res)
-{
- struct ldb_parse_tree *tree;
- int ret;
- 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->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)
-{
- 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)
-{
- 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)
-{
- 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)
-{
- FIND_OP(module, rename_record);
- return module->ops->rename_record(module, olddn, newdn);
+ FIND_OP(module, request);
+ return module->ops->request(module, request);
}
int ldb_next_start_trans(struct ldb_module *module)
#define LDB_SYNTAX_UTC_TIME "1.3.6.1.4.1.1466.115.121.1.53"
#define LDB_SYNTAX_OBJECTCLASS "LDB_SYNTAX_OBJECTCLASS"
+struct ldb_controls;
+struct ldb_credentials;
+
+enum ldb_request_type {
+ LDB_REQ_SEARCH,
+ LDB_REQ_ADD,
+ LDB_REQ_MODIFY,
+ LDB_REQ_DELETE,
+ LDB_REQ_RENAME
+};
+
+struct ldb_result {
+ unsigned int count;
+ struct ldb_message **msgs;
+};
+
+struct ldb_search {
+ const struct ldb_dn *base;
+ enum ldb_scope scope;
+ struct ldb_parse_tree *tree;
+ const char * const *attrs;
+ struct ldb_result **res;
+};
+
+struct ldb_add {
+ const struct ldb_message *message;
+};
+
+struct ldb_modify {
+ const struct ldb_message *message;
+};
+
+struct ldb_delete {
+ const struct ldb_dn *dn;
+};
+
+struct ldb_rename {
+ const struct ldb_dn *olddn;
+ const struct ldb_dn *newdn;
+};
+
+struct ldb_request {
+
+ int operation;
+
+ union {
+ struct ldb_search search;
+ struct ldb_add add;
+ struct ldb_modify mod;
+ struct ldb_delete del;
+ struct ldb_rename rename;
+ } op;
+
+ struct ldb_controls *controls;
+ struct ldb_credentials *creds;
+};
+
+int ldb_request(struct ldb_context *ldb, struct ldb_request *request);
+
/*
initialise a ldb context
*/
const struct ldb_dn *base,
enum ldb_scope scope,
const char *expression,
- const char * const *attrs, struct ldb_message ***res);
+ const char * const *attrs, struct ldb_result **res);
/*
like ldb_search() but takes a parse tree
const struct ldb_dn *base,
enum ldb_scope scope,
struct ldb_parse_tree *tree,
- const char * const *attrs, struct ldb_message ***res);
+ const char * const *attrs, struct ldb_result **res);
/*
add a record to the database. Will fail if a record with the given class and key
*/
struct ldb_module_ops {
const char *name;
- int (*search_bytree)(struct ldb_module *, const struct ldb_dn *, enum ldb_scope,
- struct ldb_parse_tree *, const char * const [], struct ldb_message ***);
- int (*add_record)(struct ldb_module *, const struct ldb_message *);
- int (*modify_record)(struct ldb_module *, const struct ldb_message *);
- int (*delete_record)(struct ldb_module *, const struct ldb_dn *);
- int (*rename_record)(struct ldb_module *, const struct ldb_dn *, const struct ldb_dn *);
+ int (*request)(struct ldb_module *, struct ldb_request *);
int (*start_transaction)(struct ldb_module *);
int (*end_transaction)(struct ldb_module *);
int (*del_transaction)(struct ldb_module *);
/* The following definitions come from lib/ldb/common/ldb_modules.c */
int ldb_load_modules(struct ldb_context *ldb, const char *options[]);
-int ldb_next_search(struct ldb_module *module,
- const struct ldb_dn *base,
- enum ldb_scope scope,
- const char *expression,
- const char * const *attrs, struct ldb_message ***res);
-int ldb_next_search_bytree(struct ldb_module *module,
- const struct ldb_dn *base,
- enum ldb_scope scope,
- struct ldb_parse_tree *tree,
- const char * const *attrs, struct ldb_message ***res);
-int ldb_next_add_record(struct ldb_module *module, const struct ldb_message *message);
-int ldb_next_modify_record(struct ldb_module *module, const struct ldb_message *message);
-int ldb_next_delete_record(struct ldb_module *module, const struct ldb_dn *dn);
-int ldb_next_rename_record(struct ldb_module *module, const struct ldb_dn *olddn, const struct ldb_dn *newdn);
+int ldb_next_request(struct ldb_module *module, struct ldb_request *request);
int ldb_next_start_trans(struct ldb_module *module);
int ldb_next_end_trans(struct ldb_module *module);
int ldb_next_del_trans(struct ldb_module *module);
*/
static int ildb_search_bytree(struct ldb_module *module, const struct ldb_dn *base,
enum ldb_scope scope, struct ldb_parse_tree *tree,
- const char * const *attrs, struct ldb_message ***res)
+ const char * const *attrs, struct ldb_result **res)
{
struct ildb_private *ildb = module->private_data;
int count, i;
}
if (search_base == NULL) {
ldb_set_errstring(module, talloc_asprintf(module, "Unable to determine baseDN"));
- return -1;
+ return LDB_ERR_OTHER;
}
if (tree == NULL) {
ldb_set_errstring(module, talloc_asprintf(module, "Invalid expression parse tree"));
- return -1;
+ return LDB_ERR_OTHER;
}
+ (*res) = talloc(ildb, struct ldb_result);
+ if (! *res) {
+ return LDB_ERR_OTHER;
+ }
+ (*res)->count = 0;
+ (*res)->msgs = NULL;
+
status = ildap_search_bytree(ildb->ldap, search_base, scope, tree, attrs,
0, &ldapres);
talloc_free(search_base);
if (!NT_STATUS_IS_OK(status)) {
ildb_map_error(ildb, status);
- return -1;
+ return LDB_ERR_OTHER;
}
count = ildap_count_entries(ildb->ldap, ldapres);
- if (count == -1 || count == 0) {
+ if (count == -1) {
talloc_free(ldapres);
- return count;
+ return LDB_ERR_OTHER;
}
- (*res) = talloc_array(ildb, struct ldb_message *, count+1);
- if (! *res) {
+ if (count == 0) {
talloc_free(ldapres);
- return -1;
+ return LDB_SUCCESS;
+ }
+
+ (*res)->msgs = talloc_array(*res, struct ldb_message *, count + 1);
+ if (! (*res)->msgs) {
+ talloc_free(ldapres);
+ return LDB_ERR_OTHER;
}
- (*res)[0] = NULL;
+ (*res)->msgs[0] = NULL;
/* loop over all messages */
for (i=0;i<count;i++) {
msg = ldapres[i];
search = &msg->r.SearchResultEntry;
- (*res)[i] = talloc(*res, struct ldb_message);
- if (!(*res)[i]) {
+ (*res)->msgs[i] = talloc(*res, struct ldb_message);
+ if (!(*res)->msgs[i]) {
goto failed;
}
- (*res)[i+1] = NULL;
+ (*res)->msgs[i+1] = NULL;
- (*res)[i]->dn = ldb_dn_explode((*res)[i], search->dn);
- if ((*res)[i]->dn == NULL) {
+ (*res)->msgs[i]->dn = ldb_dn_explode((*res)->msgs[i], search->dn);
+ if ((*res)->msgs[i]->dn == NULL) {
goto failed;
}
- (*res)[i]->num_elements = search->num_attributes;
- (*res)[i]->elements = talloc_steal((*res)[i], search->attributes);
- (*res)[i]->private_data = NULL;
+ (*res)->msgs[i]->num_elements = search->num_attributes;
+ (*res)->msgs[i]->elements = talloc_steal((*res)->msgs[i], search->attributes);
+ (*res)->msgs[i]->private_data = NULL;
}
talloc_free(ldapres);
- return count;
+ (*res)->count = count;
+ return LDB_SUCCESS;
failed:
if (*res) talloc_free(*res);
- return -1;
+ return LDB_ERR_OTHER;
}
return 0;
}
+static int ildb_request(struct ldb_module *module, struct ldb_request *req)
+{
+ switch (req->operation) {
+
+ case LDB_REQ_SEARCH:
+ return ildb_search_bytree(module,
+ req->op.search.base,
+ req->op.search.scope,
+ req->op.search.tree,
+ req->op.search.attrs,
+ req->op.search.res);
+
+ case LDB_REQ_ADD:
+ return ildb_add(module, req->op.add.message);
+
+ case LDB_REQ_MODIFY:
+ return ildb_modify(module, req->op.mod.message);
+
+ case LDB_REQ_DELETE:
+ return ildb_delete(module, req->op.del.dn);
+
+ case LDB_REQ_RENAME:
+ return ildb_rename(module,
+ req->op.rename.olddn,
+ req->op.rename.newdn);
+
+ default:
+ return -1;
+
+ }
+}
+
static const struct ldb_module_ops ildb_ops = {
.name = "ldap",
- .search_bytree = ildb_search_bytree,
- .add_record = ildb_add,
- .modify_record = ildb_modify,
- .delete_record = ildb_delete,
- .rename_record = ildb_rename,
+ .request = ildb_request,
.start_transaction = ildb_start_trans,
.end_transaction = ildb_end_trans,
.del_transaction = ildb_del_trans
static void ildb_rootdse(struct ldb_module *module)
{
struct ildb_private *ildb = module->private_data;
- struct ldb_message **res = NULL;
+ struct ldb_result *res = NULL;
struct ldb_dn *empty_dn = ldb_dn_new(ildb);
int ret;
ret = ildb_search_bytree(module, empty_dn, LDB_SCOPE_BASE,
ldb_parse_tree(empty_dn, "dn=dc=rootDSE"),
NULL, &res);
- if (ret == 1) {
- ildb->rootDSE = talloc_steal(ildb, res[0]);
+ if (ret == LDB_SUCCESS && res->count == 1) {
+ ildb->rootDSE = talloc_steal(ildb, res->msgs[0]);
}
- if (ret != -1) talloc_free(res);
+ if (ret == LDB_SUCCESS) talloc_free(res);
talloc_free(empty_dn);
}
#include "includes.h"
#include "ldb/include/ldb.h"
+#include "ldb/include/ldb_errors.h"
#include "ldb/include/ldb_private.h"
#include "ldb/ldb_ldap/ldb_ldap.h"
*/
static int lldb_search_bytree(struct ldb_module *module, const struct ldb_dn *base,
enum ldb_scope scope, struct ldb_parse_tree *tree,
- const char * const *attrs, struct ldb_message ***res)
+ const char * const *attrs, struct ldb_result **res)
{
struct ldb_context *ldb = module->ldb;
struct lldb_private *lldb = module->private_data;
break;
}
+ (*res) = talloc(lldb, struct ldb_result);
+ if (! *res) {
+ errno = ENOMEM;
+ return LDB_ERR_OTHER;
+ }
+ (*res)->count = 0;
+ (*res)->msgs = NULL;
+
lldb->last_rc = ldap_search_s(lldb->ldap, search_base, ldap_scope,
expression,
discard_const_p(char *, attrs),
talloc_free(search_base);
if (lldb->last_rc != LDAP_SUCCESS) {
ldb_set_errstring(module, talloc_strdup(module, ldap_err2string(lldb->last_rc)));
- return -1;
+ return lldb->last_rc;
}
count = ldap_count_entries(lldb->ldap, ldapres);
if (count == -1 || count == 0) {
ldap_msgfree(ldapres);
- return count;
+ return LDB_SUCCESS;
}
- (*res) = talloc_array(lldb, struct ldb_message *, count+1);
- if (! *res) {
+ (*res)->msgs = talloc_array(*res, struct ldb_message *, count+1);
+ if (! (*res)->msgs) {
ldap_msgfree(ldapres);
+ talloc_free(*res);
errno = ENOMEM;
- return -1;
+ return LDB_ERR_OTHER;
}
- (*res)[0] = NULL;
+ (*res)->msgs[0] = NULL;
msg_count = 0;
break;
}
- (*res)[msg_count] = talloc(*res, struct ldb_message);
- if (!(*res)[msg_count]) {
+ (*res)->msgs[msg_count] = talloc((*res)->msgs, struct ldb_message);
+ if (!(*res)->msgs[msg_count]) {
goto failed;
}
- (*res)[msg_count+1] = NULL;
+ (*res)->msgs[msg_count+1] = NULL;
dn = ldap_get_dn(lldb->ldap, msg);
if (!dn) {
goto failed;
}
- (*res)[msg_count]->dn = ldb_dn_explode((*res)[msg_count], dn);
+ (*res)->msgs[msg_count]->dn = ldb_dn_explode((*res)->msgs[msg_count], dn);
ldap_memfree(dn);
- if (!(*res)[msg_count]->dn) {
+ if (!(*res)->msgs[msg_count]->dn) {
goto failed;
}
- (*res)[msg_count]->num_elements = 0;
- (*res)[msg_count]->elements = NULL;
- (*res)[msg_count]->private_data = NULL;
+ (*res)->msgs[msg_count]->num_elements = 0;
+ (*res)->msgs[msg_count]->elements = NULL;
+ (*res)->msgs[msg_count]->private_data = NULL;
/* loop over all attributes */
for (attr=ldap_first_attribute(lldb->ldap, msg, &berptr);
bval = ldap_get_values_len(lldb->ldap, msg, attr);
if (bval) {
- lldb_add_msg_attr(ldb, (*res)[msg_count], attr, bval);
+ lldb_add_msg_attr(ldb, (*res)->msgs[msg_count], attr, bval);
ldap_value_free_len(bval);
}
ldap_msgfree(ldapres);
- return msg_count;
+ (*res)->count = msg_count;
+ return LDB_SUCCESS;
failed:
if (*res) talloc_free(*res);
- return -1;
+ return LDB_ERR_OTHER;
}
return 0;
}
+static int lldb_request(struct ldb_module *module, struct ldb_request *req)
+{
+ switch (req->operation) {
+
+ case LDB_REQ_SEARCH:
+ return lldb_search_bytree(module,
+ req->op.search.base,
+ req->op.search.scope,
+ req->op.search.tree,
+ req->op.search.attrs,
+ req->op.search.res);
+
+ case LDB_REQ_ADD:
+ return lldb_add(module, req->op.add.message);
+
+ case LDB_REQ_MODIFY:
+ return lldb_modify(module, req->op.mod.message);
+
+ case LDB_REQ_DELETE:
+ return lldb_delete(module, req->op.del.dn);
+
+ case LDB_REQ_RENAME:
+ return lldb_rename(module,
+ req->op.rename.olddn,
+ req->op.rename.newdn);
+
+ default:
+ return -1;
+
+ }
+}
+
static const struct ldb_module_ops lldb_ops = {
.name = "ldap",
- .search_bytree = lldb_search_bytree,
- .add_record = lldb_add,
- .modify_record = lldb_modify,
- .delete_record = lldb_delete,
- .rename_record = lldb_rename,
+ .request = lldb_request,
.start_transaction = lldb_start_trans,
.end_transaction = lldb_end_trans,
.del_transaction = lldb_del_trans
/* search for matching records, by tree */
static int lsqlite3_search_bytree(struct ldb_module * module, const struct ldb_dn* basedn,
enum ldb_scope scope, struct ldb_parse_tree * tree,
- const char * const * attrs, struct ldb_message *** res)
+ const char * const * attrs, struct ldb_result ** res)
{
TALLOC_CTX *local_ctx;
struct lsqlite3_private *lsqlite3 = module->private_data;
for (i = 0; i < msgs.count; i++) {
msgs.msgs[i] = ldb_msg_canonicalize(module->ldb, msgs.msgs[i]);
if (msgs.msgs[i] == NULL) {
- ret = LDB_ERR_OTHER;
goto failed;
}
}
- *res = talloc_steal(module, msgs.msgs);
- ret = msgs.count;
+ *res = talloc(module, struct ldb_result);
+ if (! *res) {
+ goto failed;
+ }
+
+ (*res)->msgs = talloc_steal(*res, msgs.msgs);
+ (*res)->count = msgs.count;
talloc_free(local_ctx);
- return ret;
+ return LDB_SUCCESS;
/* If error, return error code; otherwise return number of results */
failed:
talloc_free(local_ctx);
- return -1;
+ return LDB_ERR_OTHER;
}
}
+static int lsqlite3_request(struct ldb_module *module, struct ldb_request *req)
+{
+ switch (req->operation) {
+
+ case LDB_REQ_SEARCH:
+ return lsqlite3_search_bytree(module,
+ req->op.search.base,
+ req->op.search.scope,
+ req->op.search.tree,
+ req->op.search.attrs,
+ req->op.search.res);
+
+ case LDB_REQ_ADD:
+ return lsqlite3_add(module, req->op.add.message);
+
+ case LDB_REQ_MODIFY:
+ return lsqlite3_modify(module, req->op.mod.message);
+
+ case LDB_REQ_DELETE:
+ return lsqlite3_delete(module, req->op.del.dn);
+
+ case LDB_REQ_RENAME:
+ return lsqlite3_rename(module,
+ req->op.rename.olddn,
+ req->op.rename.newdn);
+
+ default:
+ return LDB_ERR_OPERATIONS_ERROR;
+
+ }
+}
+
/*
* Table of operations for the sqlite3 backend
*/
static const struct ldb_module_ops lsqlite3_ops = {
.name = "sqlite",
- .search_bytree = lsqlite3_search_bytree,
- .add_record = lsqlite3_add,
- .modify_record = lsqlite3_modify,
- .delete_record = lsqlite3_delete,
- .rename_record = lsqlite3_rename,
+ .request = lsqlite3_request,
.start_transaction = lsqlite3_start_trans,
.end_transaction = lsqlite3_end_trans,
.del_transaction = lsqlite3_del_trans
#include "includes.h"
#include "ldb/include/ldb.h"
+#include "ldb/include/ldb_errors.h"
#include "ldb/include/ldb_private.h"
#include "ldb/ldb_tdb/ldb_tdb.h"
const struct ldb_dn *base,
enum ldb_scope scope,
const struct dn_list *dn_list,
- const char * const attrs[], struct ldb_message ***res)
+ const char * const attrs[], struct ldb_result *res)
{
unsigned int i;
- int count = 0;
for (i = 0; i < dn_list->count; i++) {
struct ldb_message *msg;
msg = talloc(module, struct ldb_message);
if (msg == NULL) {
- return -1;
+ return LDB_ERR_OTHER;
}
dn = ldb_dn_explode(msg, dn_list->dn[i]);
if (dn == NULL) {
talloc_free(msg);
- return -1;
+ return LDB_ERR_OTHER;
}
ret = ltdb_search_dn1(module, dn, msg);
if (ret == -1) {
/* an internal error */
talloc_free(msg);
- return -1;
+ return LDB_ERR_OTHER;
}
ret = 0;
if (ldb_match_msg(module->ldb, msg, tree, base, scope) == 1) {
- ret = ltdb_add_attr_results(module, msg, attrs, &count, res);
+ ret = ltdb_add_attr_results(module, msg, attrs, &(res->count), &(res->msgs));
}
talloc_free(msg);
if (ret != 0) {
- return -1;
+ return LDB_ERR_OTHER;
}
}
- return count;
+ return LDB_SUCCESS;
}
/*
const struct ldb_dn *base,
enum ldb_scope scope,
struct ldb_parse_tree *tree,
- const char * const attrs[], struct ldb_message ***res)
+ const char * const attrs[], struct ldb_result **res)
{
struct ltdb_private *ltdb = module->private_data;
struct dn_list *dn_list;
return -1;
}
+ *res = talloc(module, struct ldb_result);
+ if (*res == NULL) {
+ return LDB_ERR_OTHER;
+ }
+ (*res)->count = 0;
+ (*res)->msgs = NULL;
+
if (scope == LDB_SCOPE_BASE) {
/* with BASE searches only one DN can match */
dn_list->dn = talloc_array(dn_list, char *, 1);
/* we've got a candidate list - now filter by the full tree
and extract the needed attributes */
ret = ldb_index_filter(module, tree, base, scope, dn_list,
- attrs, res);
+ attrs, *res);
}
talloc_free(dn_list);
*/
int ltdb_add_attr_results(struct ldb_module *module, struct ldb_message *msg,
const char * const attrs[],
- int *count,
+ unsigned int *count,
struct ldb_message ***res)
{
struct ldb_context *ldb = module->ldb;
enum ldb_scope scope;
const char * const *attrs;
struct ldb_message **msgs;
- int failures;
- int count;
+ unsigned int failures;
+ unsigned int count;
};
const struct ldb_dn *base,
enum ldb_scope scope,
struct ldb_parse_tree *tree,
- const char * const attrs[], struct ldb_message ***res)
+ const char * const attrs[], struct ldb_result **res)
{
struct ltdb_private *ltdb = module->private_data;
- int ret, count;
+ struct ldb_result *result;
+ int ret;
struct ltdb_search_info *sinfo;
+ result = talloc(ltdb, struct ldb_result);
+ if (result == NULL) {
+ return LDB_ERR_OTHER;
+ }
+
sinfo = talloc(ltdb, struct ltdb_search_info);
if (sinfo == NULL) {
- return -1;
+ talloc_free(result);
+ return LDB_ERR_OTHER;
}
sinfo->tree = tree;
ret = tdb_traverse_read(ltdb->tdb, search_func, sinfo);
if (ret == -1) {
+ talloc_free(result);
talloc_free(sinfo);
return -1;
}
- *res = talloc_steal(ltdb, sinfo->msgs);
- count = sinfo->count;
+ result->msgs = talloc_steal(result, sinfo->msgs);
+ result->count = sinfo->count;
+ *res = result;
talloc_free(sinfo);
- return count;
+ return LDB_SUCCESS;
}
*/
int ltdb_search_bytree(struct ldb_module *module, const struct ldb_dn *base,
enum ldb_scope scope, struct ldb_parse_tree *tree,
- const char * const attrs[], struct ldb_message ***res)
+ const char * const attrs[], struct ldb_result **res)
{
int ret;
return LDB_SUCCESS;
}
+static int ltdb_request(struct ldb_module *module, struct ldb_request *req)
+{
+ switch (req->operation) {
+
+ case LDB_REQ_SEARCH:
+ return ltdb_search_bytree(module,
+ req->op.search.base,
+ req->op.search.scope,
+ req->op.search.tree,
+ req->op.search.attrs,
+ req->op.search.res);
+
+ case LDB_REQ_ADD:
+ return ltdb_add(module, req->op.add.message);
+
+ case LDB_REQ_MODIFY:
+ return ltdb_modify(module, req->op.mod.message);
+
+ case LDB_REQ_DELETE:
+ return ltdb_delete(module, req->op.del.dn);
+
+ case LDB_REQ_RENAME:
+ return ltdb_rename(module,
+ req->op.rename.olddn,
+ req->op.rename.newdn);
+
+ default:
+ return LDB_ERR_OPERATIONS_ERROR;
+
+ }
+}
+
static const struct ldb_module_ops ltdb_ops = {
.name = "tdb",
- .search_bytree = ltdb_search_bytree,
- .add_record = ltdb_add,
- .modify_record = ltdb_modify,
- .delete_record = ltdb_delete,
- .rename_record = ltdb_rename,
+ .request = ltdb_request,
.start_transaction = ltdb_start_trans,
.end_transaction = ltdb_end_trans,
.del_transaction = ltdb_del_trans
const struct ldb_dn *base,
enum ldb_scope scope,
struct ldb_parse_tree *tree,
- const char * const attrs[], struct ldb_message ***res);
+ const char * const attrs[], struct ldb_result **res);
int ltdb_index_add(struct ldb_module *module, const struct ldb_message *msg);
int ltdb_index_del(struct ldb_module *module, const struct ldb_message *msg);
int ltdb_reindex(struct ldb_module *module);
int ltdb_search_dn1(struct ldb_module *module, const struct ldb_dn *dn, struct ldb_message *msg);
int ltdb_add_attr_results(struct ldb_module *module, struct ldb_message *msg,
const char * const attrs[],
- int *count,
+ unsigned int *count,
struct ldb_message ***res);
int ltdb_search_bytree(struct ldb_module *module, const struct ldb_dn *base,
enum ldb_scope scope, struct ldb_parse_tree *tree,
- const char * const attrs[], struct ldb_message ***res);
+ const char * const attrs[], struct ldb_result **res);
/* The following definitions come from lib/ldb/ldb_tdb/ldb_tdb.c */
#include "includes.h"
#include "ldb/include/ldb.h"
+#include "ldb/include/ldb_errors.h"
#include "ldb/include/ldb_private.h"
#include "ldb/modules/ldb_map.h"
/*
rename a record
*/
-static int map_rename(struct ldb_module *module, const struct ldb_dn *olddn, const struct ldb_dn *newdn)
+static int map_rename(struct ldb_module *module, struct ldb_request *req)
{
+ const struct ldb_dn *olddn = req->op.rename.olddn;
+ const struct ldb_dn *newdn = req->op.rename.newdn;
struct ldb_map_context *privdat = map_get_privdat(module);
struct ldb_dn *n_olddn, *n_newdn;
int ret;
ret = ldb_rename(privdat->mapped_ldb, n_olddn, n_newdn);
if (ret != -1) {
ldb_debug(module->ldb, LDB_DEBUG_TRACE, "Mapped record renamed");
- ldb_next_rename_record(module, olddn, newdn);
+ ldb_next_request(module, req);
} else {
- ret = ldb_next_rename_record(module, olddn, newdn);
+ ret = ldb_next_request(module, req);
if (ret != -1) {
ldb_debug(module->ldb, LDB_DEBUG_TRACE, "Fallback record renamed");
/*
delete a record
*/
-static int map_delete(struct ldb_module *module, const struct ldb_dn *dn)
+static int map_delete(struct ldb_module *module, struct ldb_request *req)
{
+ const struct ldb_dn *dn = req->op.del.dn;
struct ldb_map_context *privdat = map_get_privdat(module);
struct ldb_dn *newdn;
int ret;
if (ret != -1) {
ldb_debug(module->ldb, LDB_DEBUG_TRACE, "Mapped record deleted");
} else {
- ret = ldb_next_delete_record(module, dn);
+ ret = ldb_next_request(module, req);
if (ret != -1) {
ldb_debug(module->ldb, LDB_DEBUG_TRACE, "Fallback record deleted");
}
}
- ldb_next_delete_record(module, newdn);
+ req->op.del.dn = newdn;
+ ret = ldb_next_request(module, req);
+ req->op.del.dn = dn;
talloc_free(newdn);
}
/* search fallback database */
-static int map_search_fb(struct ldb_module *module, const struct ldb_dn *base,
- enum ldb_scope scope, struct ldb_parse_tree *tree,
- const char * const *attrs, struct ldb_message ***res)
+static int map_search_fb(struct ldb_module *module, struct ldb_request *req)
{
- int ret;
+ struct ldb_parse_tree *tree = req->op.search.tree;
struct ldb_parse_tree t_and, t_not, t_present, *childs[2];
+ int ret;
char *ismapped;
t_present.operation = LDB_OP_PRESENT;
t_and.operation = LDB_OP_AND;
t_and.u.list.num_elements = 2;
t_and.u.list.elements = childs;
-
- ret = ldb_next_search_bytree(module, base, scope, &t_and, attrs, res);
+
+ req->op.search.tree = &t_and;
+ ret = ldb_next_request(module, req);
+ req->op.search.tree = tree;
talloc_free(ismapped);
}
/* Search in the database against which we are mapping */
-static int map_search_mp(struct ldb_module *module, const struct ldb_dn *base,
- enum ldb_scope scope, struct ldb_parse_tree *tree,
- const char * const *attrs, struct ldb_message ***res)
+static int map_search_mp(struct ldb_module *module, struct ldb_request *req)
{
+ const struct ldb_dn *base = req->op.search.base;
+ enum ldb_scope scope = req->op.search.scope;
+ struct ldb_parse_tree *tree = req->op.search.tree;
+ const char * const *attrs = req->op.search.attrs;
+ struct ldb_result **res = req->op.search.res;
+ struct ldb_request new_req;
struct ldb_parse_tree *new_tree;
struct ldb_dn *new_base;
- struct ldb_message **newres;
+ struct ldb_result *newres;
const char **newattrs;
int mpret, ret;
struct ldb_map_context *privdat = map_get_privdat(module);
newattrs = ldb_map_attrs(module, attrs);
new_base = map_local_dn(module, module, base);
- mpret = ldb_search_bytree(privdat->mapped_ldb, new_base, scope, new_tree, newattrs, &newres);
+ memset((char *)&(new_req), 0, sizeof(new_req));
+ new_req.operation = LDB_REQ_SEARCH;
+ new_req.op.search.base = new_base;
+ new_req.op.search.scope = scope;
+ new_req.op.search.tree = new_tree;
+ new_req.op.search.attrs = newattrs;
+ new_req.op.search.res = &newres;
+ mpret = ldb_request(privdat->mapped_ldb, req);
talloc_free(new_base);
talloc_free(new_tree);
talloc_free(newattrs);
- if (mpret == -1) {
+ if (mpret != LDB_SUCCESS) {
ldb_set_errstring(module, talloc_strdup(module, ldb_errstring(privdat->mapped_ldb)));
- return -1;
+ return mpret;
}
/*
- test if (full expression) is now true
*/
- *res = talloc_array(module, struct ldb_message *, mpret);
+ *res = talloc(module, struct ldb_result);
+ (*res)->msgs = talloc_array(module, struct ldb_message *, newres->count);
+ (*res)->count = newres->count;
ret = 0;
for (i = 0; i < mpret; i++) {
+ struct ldb_request mergereq;
struct ldb_message *merged;
- struct ldb_message **extrares = NULL;
+ struct ldb_result *extrares = NULL;
int extraret;
/* Always get special DN's from the fallback database */
- if (ldb_dn_is_special(newres[i]->dn))
+ if (ldb_dn_is_special(newres->msgs[i]->dn))
continue;
- merged = ldb_map_message_incoming(module, attrs, newres[i]);
+ merged = ldb_map_message_incoming(module, attrs, newres->msgs[i]);
/* Merge with additional data from fallback database */
- extraret = ldb_next_search(module, merged->dn, LDB_SCOPE_BASE, "", NULL, &extrares);
+ memset((char *)&(mergereq), 0, sizeof(mergereq)); /* zero off the request structure */
+ mergereq.operation = LDB_REQ_SEARCH;
+ mergereq.op.search.base = merged->dn;
+ mergereq.op.search.scope = LDB_SCOPE_BASE;
+ mergereq.op.search.tree = ldb_parse_tree(module, "");
+ mergereq.op.search.attrs = NULL;
+ mergereq.op.search.res = &extrares;
+
+ extraret = ldb_next_request(module, &mergereq);
if (extraret == -1) {
ldb_debug(module->ldb, LDB_DEBUG_ERROR, "Error searching for extra data!\n");
if (extraret == 1) {
int j;
ldb_debug(module->ldb, LDB_DEBUG_TRACE, "Extra data found for remote DN: %s", ldb_dn_linearize(merged, merged->dn));
- for (j = 0; j < extrares[0]->num_elements; j++) {
- ldb_msg_add(merged, &(extrares[0]->elements[j]), extrares[0]->elements[j].flags);
+ for (j = 0; j < extrares->msgs[0]->num_elements; j++) {
+ ldb_msg_add(merged, &(extrares->msgs[0]->elements[j]), extrares->msgs[0]->elements[j].flags);
}
}
if (ldb_match_msg(module->ldb, merged, tree, base, scope) != 0) {
- (*res)[ret] = merged;
+ (*res)->msgs[ret] = merged;
ret++;
} else {
ldb_debug(module->ldb, LDB_DEBUG_TRACE, "Discarded merged message because it did not match");
talloc_free(newres);
- return ret;
+ (*res)->count = ret;
+ return LDB_SUCCESS;
}
/*
search for matching records using a ldb_parse_tree
*/
-static int map_search_bytree(struct ldb_module *module, const struct ldb_dn *base,
- enum ldb_scope scope, struct ldb_parse_tree *tree,
- const char * const *attrs, struct ldb_message ***res)
+static int map_search_bytree(struct ldb_module *module, struct ldb_request *req)
{
- struct ldb_message **fbres, **mpres = NULL;
- int i;
- int ret_fb, ret_mp;
+ const struct ldb_dn *base = req->op.search.base;
+ struct ldb_result **res = req->op.search.res;
+ struct ldb_result *fbres, *mpres = NULL;
+ int i, ret;
- ret_fb = map_search_fb(module, base, scope, tree, attrs, &fbres);
- if (ret_fb == -1)
- return -1;
+ req->op.search.res = &fbres;
+ ret = map_search_fb(module, req);
+ req->op.search.res = res;
+ if (ret != LDB_SUCCESS)
+ return ret;
/* special dn's are never mapped.. */
if (ldb_dn_is_special(base)) {
*res = fbres;
- return ret_fb;
+ return ret;
}
- ret_mp = map_search_mp(module, base, scope, tree, attrs, &mpres);
- if (ret_mp == -1) {
- return -1;
+ req->op.search.res = &mpres;
+ ret = map_search_mp(module, req);
+ req->op.search.res = res;
+ if (ret != LDB_SUCCESS) {
+ return ret;
}
/* Merge results */
- *res = talloc_array(module, struct ldb_message *, ret_fb + ret_mp);
+ *res = talloc(module, struct ldb_result);
+ (*res)->msgs = talloc_array(*res, struct ldb_message *, fbres->count + mpres->count);
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "Merging %d mapped and %d fallback messages", ret_mp, ret_fb);
+ ldb_debug(module->ldb, LDB_DEBUG_TRACE, "Merging %d mapped and %d fallback messages", mpres->count, fbres->count);
- for (i = 0; i < ret_fb; i++) (*res)[i] = fbres[i];
- for (i = 0; i < ret_mp; i++) (*res)[ret_fb+i] = mpres[i];
+ for (i = 0; i < fbres->count; i++) (*res)->msgs[i] = fbres->msgs[i];
+ for (i = 0; i < mpres->count; i++) (*res)->msgs[fbres->count + i] = mpres->msgs[i];
- return ret_fb + ret_mp;
+ (*res)->count = fbres->count + mpres->count;
+ return LDB_SUCCESS;
}
static int msg_contains_objectclass(const struct ldb_message *msg, const char *name)
/*
add a record
*/
-static int map_add(struct ldb_module *module, const struct ldb_message *msg)
+static int map_add(struct ldb_module *module, struct ldb_request *req)
{
- int ret;
+ const struct ldb_message *msg = req->op.add.message;
struct ldb_map_context *privdat = map_get_privdat(module);
struct ldb_message *fb, *mp;
struct ldb_message_element *ocs;
+ int ret;
int i;
ldb_debug(module->ldb, LDB_DEBUG_TRACE, "ldb_map_add");
if (ldb_dn_is_special(msg->dn)) {
ldb_debug(module->ldb, LDB_DEBUG_TRACE, "ldb_map_add: Added fallback record");
- return ldb_next_add_record(module, msg);
+ return ldb_next_request(module, req);
}
mp = talloc_zero(module, struct ldb_message);
ocs = ldb_msg_find_element(mp, "objectClass");
if (ocs->num_values == 1) { /* Only top */
ldb_debug(module->ldb, LDB_DEBUG_TRACE, "ldb_map_add: Added fallback record");
- return ldb_next_add_record(module, msg);
+ return ldb_next_request(module, req);
}
/*
ldb_debug(module->ldb, LDB_DEBUG_TRACE, "ldb_map_add: Added mapped record");
ldb_msg_add_string(fb, "isMapped", "TRUE");
- ret = ldb_next_add_record(module, fb);
+
+ req->op.add.message = fb;
+ ret = ldb_next_request(module, req);
+ req->op.add.message = msg;
if (ret == -1) {
ldb_debug(module->ldb, LDB_DEBUG_WARNING, "Adding fallback record failed: %s", ldb_errstring(module->ldb));
return -1;
/*
modify a record
*/
-static int map_modify(struct ldb_module *module, const struct ldb_message *msg)
+static int map_modify(struct ldb_module *module, struct ldb_request *req)
{
+ const struct ldb_message *msg = req->op.mod.message;
struct ldb_map_context *privdat = map_get_privdat(module);
struct ldb_message *fb, *mp;
struct ldb_message_element *elm;
ldb_debug(module->ldb, LDB_DEBUG_TRACE, "ldb_map_modify");
if (ldb_dn_is_special(msg->dn))
- return ldb_next_modify_record(module, msg);
+ return ldb_next_request(module, req);
fb = talloc_zero(module, struct ldb_message);
fb->dn = talloc_reference(fb, msg->dn);
if (fb->num_elements > 0) {
ldb_debug(module->ldb, LDB_DEBUG_TRACE, "Modifying fallback record with %d elements", fb->num_elements);
- fb_ret = ldb_next_modify_record(module, fb);
+ req->op.mod.message = fb;
+ fb_ret = ldb_next_request(module, req);
if (fb_ret == -1) {
ldb_msg_add_string(fb, "isMapped", "TRUE");
- fb_ret = ldb_next_add_record(module, fb);
+ req->operation = LDB_REQ_ADD;
+ req->op.add.message = fb;
+ fb_ret = ldb_next_request(module, req);
+ req->operation = LDB_REQ_MODIFY;
}
+ req->op.mod.message = msg;
} else fb_ret = 0;
talloc_free(fb);
return (mp_ret == -1 || fb_ret == -1)?-1:0;
}
+
+static int map_request(struct ldb_module *module, struct ldb_request *req)
+{
+ switch (req->operation) {
+
+ case LDB_REQ_SEARCH:
+ return map_search_bytree(module, req);
+
+ case LDB_REQ_ADD:
+ return map_add(module, req);
+
+ case LDB_REQ_MODIFY:
+ return map_modify(module, req);
+
+ case LDB_REQ_DELETE:
+ return map_delete(module, req);
+
+ case LDB_REQ_RENAME:
+ return map_rename(module, req);
+
+ default:
+ return ldb_next_request(module, req);
+
+ }
+}
+
+
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
+ .request = map_request
};
static char *map_find_url(struct ldb_context *ldb, const char *name)
{
const char * const attrs[] = { "@MAP_URL" , NULL};
- struct ldb_message **msg = NULL;
+ struct ldb_result *result = NULL;
struct ldb_dn *mods;
char *url;
int ret;
return NULL;
}
- ret = ldb_search(ldb, mods, LDB_SCOPE_BASE, "", attrs, &msg);
+ ret = ldb_search(ldb, mods, LDB_SCOPE_BASE, "", attrs, &result);
talloc_free(mods);
- if (ret < 1) {
+ if (ret != LDB_SUCCESS || result->count == 0) {
ldb_debug(ldb, LDB_DEBUG_ERROR, "Not enough results found looking for @MAP");
return NULL;
}
- url = talloc_strdup(ldb, ldb_msg_find_string(msg[0], "@MAP_URL", NULL));
+ url = talloc_strdup(ldb, ldb_msg_find_string(result->msgs[0], "@MAP_URL", NULL));
- talloc_free(msg);
+ talloc_free(result);
return url;
}
#include "includes.h"
#include "ldb/include/ldb.h"
+#include "ldb/include/ldb_errors.h"
#include "ldb/include/ldb_private.h"
#include <time.h>
/*
hook search operations
*/
-static int operational_search_bytree(struct ldb_module *module,
- const struct ldb_dn *base,
- enum ldb_scope scope, struct ldb_parse_tree *tree,
- const char * const *attrs,
- struct ldb_message ***res)
+static int operational_search_bytree(struct ldb_module *module, struct ldb_request *req)
{
int i, r, a;
int ret;
+ const char * const *attrs = req->op.search.attrs;
const char **search_attrs = NULL;
- (*res) = NULL;
+ *(req->op.search.res) = NULL;
/* replace any attributes in the parse tree that are
searchable, but are stored using a different name in the
backend */
for (i=0;i<ARRAY_SIZE(parse_tree_sub);i++) {
- ldb_parse_tree_attr_replace(tree,
+ ldb_parse_tree_attr_replace(req->op.search.tree,
parse_tree_sub[i].attr,
parse_tree_sub[i].replace);
}
}
}
-
+ /* use new set of attrs if any */
+ if (search_attrs) req->op.search.attrs = search_attrs;
/* perform the search */
- ret = ldb_next_search_bytree(module, base, scope, tree,
- search_attrs?search_attrs:attrs, res);
- if (ret <= 0) {
+ ret = ldb_next_request(module, req);
+ /* set back saved attrs if needed */
+ if (search_attrs) req->op.search.attrs = attrs;
+
+ /* check operation result */
+ if (ret != LDB_SUCCESS) {
return ret;
}
/* for each record returned post-process to add any derived
attributes that have been asked for */
- for (r=0;r<ret;r++) {
- if (operational_search_post_process(module, (*res)[r], attrs) != 0) {
+ for (r = 0; r < (*(req->op.search.res))->count; r++) {
+ if (operational_search_post_process(module, (*(req->op.search.res))->msgs[r], attrs) != 0) {
goto failed;
}
}
failed:
talloc_free(search_attrs);
- talloc_free(*res);
+ talloc_free(*(req->op.search.res));
ldb_oom(module->ldb);
- return -1;
+ return LDB_ERR_OTHER;
}
/*
/*
hook add record ops
*/
-static int operational_add_record(struct ldb_module *module,
- const struct ldb_message *msg)
+static int operational_add(struct ldb_module *module, struct ldb_request *req)
{
+ const struct ldb_message *msg = req->op.add.message;
time_t t = time(NULL);
struct ldb_message *msg2;
int ret;
if (ldb_dn_is_special(msg->dn)) {
- return ldb_next_add_record(module, msg);
+ return ldb_next_request(module, req);
}
/* we have to copy the message as the caller might have it as a const */
talloc_free(msg2);
return -1;
}
- ret = ldb_next_add_record(module, msg2);
+ /* use the new structure for the call chain below this point */
+ req->op.add.message = msg2;
+ /* go on with the call chain */
+ ret = ldb_next_request(module, req);
+ /* put back saved message */
+ req->op.add.message = msg;
+ /* free temproary compy */
talloc_free(msg2);
return ret;
}
/*
hook modify record ops
*/
-static int operational_modify_record(struct ldb_module *module,
- const struct ldb_message *msg)
+static int operational_modify(struct ldb_module *module, struct ldb_request *req)
{
+ const struct ldb_message *msg = req->op.mod.message;
time_t t = time(NULL);
struct ldb_message *msg2;
int ret;
if (ldb_dn_is_special(msg->dn)) {
- return ldb_next_modify_record(module, msg);
+ return ldb_next_request(module, req);
}
/* we have to copy the message as the caller might have it as a const */
talloc_free(msg2);
return -1;
}
- ret = ldb_next_modify_record(module, msg2);
+ /* use the new structure for the call chain below this point */
+ req->op.mod.message = msg2;
+ /* go on with the call chain */
+ ret = ldb_next_request(module, req);
+ /* put back saved message */
+ req->op.mod.message = msg;
+ /* free temproary compy */
talloc_free(msg2);
return ret;
}
+
+static int operational_request(struct ldb_module *module, struct ldb_request *req)
+{
+ switch (req->operation) {
+
+ case LDB_REQ_SEARCH:
+ return operational_search_bytree(module, req);
+
+ case LDB_REQ_ADD:
+ return operational_add(module, req);
+
+ case LDB_REQ_MODIFY:
+ return operational_modify(module, req);
+
+ default:
+ return ldb_next_request(module, req);
+
+ }
+}
+
static const struct ldb_module_ops operational_ops = {
.name = "operational",
- .search_bytree = operational_search_bytree,
- .add_record = operational_add_record,
- .modify_record = operational_modify_record
+ .request = operational_request
};
#include "ldb/include/ldb_private.h"
#include <time.h>
-static int rdn_name_search_bytree(struct ldb_module *module, const struct ldb_dn *base,
- enum ldb_scope scope, struct ldb_parse_tree *tree,
- const char * const *attrs, struct ldb_message ***res)
-{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_name_search\n");
- return ldb_next_search_bytree(module, base, scope, tree, attrs, res);
-}
-
static struct ldb_message_element *rdn_name_find_attribute(const struct ldb_message *msg, const char *name)
{
int i;
return NULL;
}
-/* add_record: add crateTimestamp/modifyTimestamp attributes */
-static int rdn_name_add_record(struct ldb_module *module, const struct ldb_message *msg)
+static int rdn_name_add(struct ldb_module *module, struct ldb_request *req)
{
+ const struct ldb_message *msg = req->op.add.message;
struct ldb_message *msg2;
struct ldb_message_element *attribute;
struct ldb_dn_component *rdn;
/* do not manipulate our control entries */
if (ldb_dn_is_special(msg->dn)) {
- return ldb_next_add_record(module, msg);
+ return ldb_next_request(module, req);
}
/* Perhaps someone above us knows better */
if ((attribute = rdn_name_find_attribute(msg, "name")) != NULL ) {
- return ldb_next_add_record(module, msg);
+ return ldb_next_request(module, req);
}
msg2 = talloc(module, struct ldb_message);
}
}
- ret = ldb_next_add_record(module, msg2);
+ req->op.add.message = msg2;
+ ret = ldb_next_request(module, req);
+ req->op.add.message = msg;
+
talloc_free(msg2);
return ret;
}
-/* modify_record: change modifyTimestamp as well */
-static int rdn_name_modify_record(struct ldb_module *module, const struct ldb_message *msg)
+static int rdn_name_modify(struct ldb_module *module, struct ldb_request *req)
{
+ const struct ldb_message *msg = req->op.mod.message;
struct ldb_message *msg2;
struct ldb_message_element *attribute;
struct ldb_dn_component *rdn;
/* do not manipulate our control entries */
if (ldb_dn_is_special(msg->dn)) {
- return ldb_next_modify_record(module, msg);
+ return ldb_next_request(module, req);
}
/* Perhaps someone above us knows better */
if ((attribute = rdn_name_find_attribute(msg, "name")) != NULL ) {
- return ldb_next_modify_record(module, msg);
+ return ldb_next_request(module, req);
}
msg2 = talloc(module, struct ldb_message);
attribute->flags = LDB_FLAG_MOD_REPLACE;
- ret = ldb_next_modify_record(module, msg2);
+ req->op.add.message = msg2;
+ ret = ldb_next_request(module, req);
+ req->op.add.message = msg;
+
talloc_free(msg2);
return ret;
}
-static int rdn_name_rename_record(struct ldb_module *module, const struct ldb_dn *olddn, const struct ldb_dn *newdn)
+static int rdn_name_request(struct ldb_module *module, struct ldb_request *req)
{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_name_rename_record\n");
- return ldb_next_rename_record(module, olddn, newdn);
+ switch (req->operation) {
+
+ case LDB_REQ_ADD:
+ return rdn_name_add(module, req);
+
+ case LDB_REQ_MODIFY:
+ return rdn_name_modify(module, req);
+
+
+ default:
+ return ldb_next_request(module, req);
+
+ }
}
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,
- .rename_record = rdn_name_rename_record
+ .request = rdn_name_request
};
static int get_entry_attributes(struct ldb_context *ldb, const struct ldb_dn *dn, struct schema_structures *ss)
{
- struct ldb_message **srch;
+ struct ldb_result *srch;
int ret;
ret = ldb_search(ldb, dn, LDB_SCOPE_BASE, NULL, NULL, &srch);
talloc_steal(ss, srch);
/* set flags to 0 as flags on search have undefined values */
- ret = get_msg_attributes(ss, *srch, 0);
+ ret = get_msg_attributes(ss, *(srch->msgs), 0);
if (ret != 0) {
talloc_free(srch);
return ret;
recursively get parent objectlasses attributes */
static int get_attr_list_recursive(struct ldb_module *module, struct schema_structures *schema_struct)
{
- struct ldb_message **srch;
+ struct ldb_result *srch;
int i, j;
int ret;
/* Add inherited classes eliminating duplicates */
/* fill in required_attrs and optional_attrs attribute lists */
- for (j = 0; j < (*srch)->num_elements; j++) {
+ for (j = 0; j < srch->msgs[0]->num_elements; j++) {
int is_aux, is_class;
is_aux = 0;
is_class = 0;
- if (ldb_attr_cmp((*srch)->elements[j].name, "systemAuxiliaryclass") == 0) {
+ if (ldb_attr_cmp(srch->msgs[0]->elements[j].name, "systemAuxiliaryclass") == 0) {
is_aux = SCHEMA_FLAG_AUXILIARY;
is_class = 1;
}
- if (ldb_attr_cmp((*srch)->elements[j].name, "auxiliaryClass") == 0) {
+ if (ldb_attr_cmp(srch->msgs[0]->elements[j].name, "auxiliaryClass") == 0) {
is_aux = SCHEMA_FLAG_AUXILIARY;
is_class = 1;
}
- if (ldb_attr_cmp((*srch)->elements[j].name, "subClassOf") == 0) {
+ if (ldb_attr_cmp(srch->msgs[0]->elements[j].name, "subClassOf") == 0) {
is_class = 1;
}
if (add_attribute_uniq(schema_struct,
&schema_struct->objectclasses,
is_aux,
- &(*srch)->elements[j]) != 0) {
+ &srch->msgs[0]->elements[j]) != 0) {
return -1;
}
} else {
- if (ldb_attr_cmp((*srch)->elements[j].name, "mustContain") == 0 ||
- ldb_attr_cmp((*srch)->elements[j].name, "SystemMustContain") == 0) {
+ if (ldb_attr_cmp(srch->msgs[0]->elements[j].name, "mustContain") == 0 ||
+ ldb_attr_cmp(srch->msgs[0]->elements[j].name, "SystemMustContain") == 0) {
if (add_attribute_uniq(schema_struct,
&schema_struct->required_attrs,
SCHEMA_FLAG_RESET,
- &(*srch)->elements[j]) != 0) {
+ &srch->msgs[0]->elements[j]) != 0) {
return -1;
}
}
- if (ldb_attr_cmp((*srch)->elements[j].name, "mayContain") == 0 ||
- ldb_attr_cmp((*srch)->elements[j].name, "SystemMayContain") == 0) {
+ if (ldb_attr_cmp(srch->msgs[0]->elements[j].name, "mayContain") == 0 ||
+ ldb_attr_cmp(srch->msgs[0]->elements[j].name, "SystemMayContain") == 0) {
if (add_attribute_uniq(schema_struct,
&schema_struct->optional_attrs,
SCHEMA_FLAG_RESET,
- &(*srch)->elements[j]) != 0) {
+ &srch->msgs[0]->elements[j]) != 0) {
return -1;
}
}
return 0;
}
-/* search */
-static int schema_search_bytree(struct ldb_module *module, const struct ldb_dn *base,
- enum ldb_scope scope, struct ldb_parse_tree *tree,
- const char * const *attrs, struct ldb_message ***res)
-{
- return ldb_next_search_bytree(module, base, scope, tree, attrs, res);
-}
-
/* add_record */
-static int schema_add_record(struct ldb_module *module, const struct ldb_message *msg)
+static int schema_add(struct ldb_module *module, struct ldb_request *req)
{
+ const struct ldb_message *msg = req->op.add.message;
struct schema_structures *entry_structs;
unsigned int i;
int ret;
/* do not check on our control entries */
if (ldb_dn_is_special(msg->dn)) {
- return ldb_next_add_record(module, msg);
+ return ldb_next_request(module, req);
}
/* TODO: check parent exists */
talloc_free(entry_structs);
- return ldb_next_add_record(module, msg);
+ return ldb_next_request(module, req);
}
/* modify_record */
-static int schema_modify_record(struct ldb_module *module, const struct ldb_message *msg)
+static int schema_modify(struct ldb_module *module, struct ldb_request *req)
{
+ const struct ldb_message *msg = req->op.mod.message;
struct schema_structures *entry_structs;
unsigned int i;
int ret;
/* do not check on our control entries */
if (ldb_dn_is_special(msg->dn)) {
- return ldb_next_add_record(module, msg);
+ return ldb_next_request(module, req);
}
/* allocate object structs */
talloc_free(entry_structs);
- return ldb_next_modify_record(module, msg);
+ return ldb_next_request(module, req);
}
-/* delete_record */
-static int schema_delete_record(struct ldb_module *module, const struct ldb_dn *dn)
+static int schema_request(struct ldb_module *module, struct ldb_request *req)
{
-/* struct private_data *data = (struct private_data *)module->private_data; */
- return ldb_next_delete_record(module, dn);
-}
+ switch (req->operation) {
-/* rename_record */
-static int schema_rename_record(struct ldb_module *module, const struct ldb_dn *olddn, const struct ldb_dn *newdn)
-{
- return ldb_next_rename_record(module, olddn, newdn);
+ case LDB_REQ_ADD:
+ return schema_add(module, req);
+
+ case LDB_REQ_MODIFY:
+ return schema_modify(module, req);
+
+ default:
+ return ldb_next_request(module, req);
+
+ }
}
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
+ .request = schema_request
};
#ifdef HAVE_DLOPEN_DISABLED
/* search */
static int skel_search(struct ldb_module *module, const struct ldb_dn *base,
enum ldb_scope scope, struct ldb_parse_tree *tree,
- const char * const *attrs, struct ldb_message ***res)
+ const char * const *attrs, struct ldb_result **res)
{
return ldb_next_search(module, base, scope, tree, attrs, res);
}
return 0;
}
+static int skel_request(struct ldb_module *module, struct ldb_request *req)
+{
+ switch (req->operation) {
+
+ case LDB_REQ_SEARCH:
+ return skel_search_bytree(module,
+ req->op.search->base,
+ req->op.search->scope,
+ req->op.search->tree,
+ req->op.search->attrs,
+ req->op.search->res);
+
+ case LDB_REQ_ADD:
+ return skel_add(module, req->op.add->message);
+
+ case LDB_REQ_MODIFY:
+ return skel_modify(module, req->op.mod->message);
+
+ case LDB_REQ_DELETE:
+ return skel_delete(module, req->op.del->dn);
+
+ case LDB_REQ_RENAME:
+ return skel_rename(module,
+ req->op.rename->olddn,
+ req->op.rename->newdn);
+
+ default:
+ return ldb_next_request(module, req);
+
+ }
+}
+
static const struct ldb_module_ops skel_ops = {
.name = "skel",
- .search_bytree = skel_search_bytree,
- .add_record = skel_add_record,
- .modify_record = skel_modify_record,
- .delete_record = skel_delete_record,
- .rename_record = skel_rename_record,
+ .request = skel_request,
.start_transaction = skel_start_trans,
.end_transaction = skel_end_trans,
.del_transaction = skel_del_trans,
allow update_anon bind_anon_dn
-modulepath /usr/lib/ldap
-moduleload back_bdb
+#modulepath /usr/lib/ldap
+#moduleload back_bdb
defaultsearchbase "o=University of Michigan,c=TEST"
#include "includes.h"
#include "ldb/include/ldb.h"
+#include "ldb/include/ldb_errors.h"
#include "ldb/include/ldb_private.h"
#include "ldb/tools/cmdline.h"
{
int ret, i, total=0;
const char *attrs[] = { NULL };
- struct ldb_message **res;
+ struct ldb_result *res;
ret = ldb_search(ldb, dn, LDB_SCOPE_SUBTREE, "distinguishedName=*", attrs, &res);
- if (ret <= 0) return -1;
+ if (ret != LDB_SUCCESS) return -1;
- for (i=0;i<ret;i++) {
- if (ldb_delete(ldb, res[i]->dn) == 0) {
+ for (i = 0; i < res->count; i++) {
+ if (ldb_delete(ldb, res->msgs[i]->dn) == 0) {
total++;
}
}
#include "includes.h"
#include "ldb/include/ldb.h"
+#include "ldb/include/ldb_errors.h"
#include "ldb/include/ldb_private.h"
#include "ldb/tools/cmdline.h"
int main(int argc, const char **argv)
{
struct ldb_context *ldb;
- struct ldb_message **msgs;
+ struct ldb_result *result = NULL;
struct ldb_dn *basedn = NULL;
int ret;
const char *expression = "(|(objectclass=*)(distinguishedName=*))";
}
}
- ret = ldb_search(ldb, basedn, options->scope, expression, attrs, &msgs);
- if (ret == -1) {
+ ret = ldb_search(ldb, basedn, options->scope, expression, attrs, &result);
+ if (ret != LDB_SUCCESS) {
printf("search failed - %s\n", ldb_errstring(ldb));
exit(1);
}
- if (ret == 0) {
+ if (result->count == 0) {
printf("no matching records - cannot edit\n");
return 0;
}
- do_edit(ldb, msgs, ret, options->editor);
+ do_edit(ldb, result->msgs, result->count, options->editor);
- if (ret > 0) {
- ret = talloc_free(msgs);
+ if (result) {
+ ret = talloc_free(result);
if (ret == -1) {
fprintf(stderr, "talloc_free failed\n");
exit(1);
#include "includes.h"
#include "ldb/include/ldb.h"
+#include "ldb/include/ldb_errors.h"
#include "ldb/include/ldb_private.h"
#include "ldb/tools/cmdline.h"
const char * const *attrs)
{
int ret, i;
- struct ldb_message **msgs;
+ struct ldb_result *result = NULL;
- ret = ldb_search(ldb, basedn, scope, expression, attrs, &msgs);
- if (ret == -1) {
+ ret = ldb_search(ldb, basedn, scope, expression, attrs, &result);
+ if (ret != LDB_SUCCESS) {
printf("search failed - %s\n", ldb_errstring(ldb));
return -1;
}
ldbsearch_ldb = ldb;
if (sort_attribs) {
- qsort(msgs, ret, sizeof(struct ldb_message *),
+ qsort(result->msgs, ret, sizeof(struct ldb_message *),
(comparison_fn_t)do_compare_msg);
}
- for (i=0;i<ret;i++) {
+ for (i = 0; i < result->count; i++) {
struct ldb_ldif ldif;
printf("# record %d\n", i+1);
ldif.changetype = LDB_CHANGETYPE_NONE;
- ldif.msg = msgs[i];
+ ldif.msg = result->msgs[i];
if (sort_attribs) {
/*
ldb_ldif_write_file(ldb, stdout, &ldif);
}
- if (ret > 0) {
- ret = talloc_free(msgs);
+ if (result) {
+ ret = talloc_free(result);
if (ret == -1) {
fprintf(stderr, "talloc_free failed\n");
exit(1);
#include "includes.h"
#include "ldb/include/ldb.h"
+#include "ldb/include/ldb_errors.h"
#include "ldb/include/ldb_private.h"
#include "ldb/tools/cmdline.h"
for (i=0;i<nsearches;i++) {
int uid = (i * 700 + 17) % (nrecords * 2);
char *expr;
- struct ldb_message **res;
+ struct ldb_result *res = NULL;
int ret;
asprintf(&expr, "(uid=TEST%d)", uid);
ret = ldb_search(ldb, basedn, LDB_SCOPE_SUBTREE, expr, NULL, &res);
- if (uid < nrecords && ret != 1) {
+ if (ret != LDB_SUCCESS || (uid < nrecords && res->count != 1)) {
printf("Failed to find %s - %s\n", expr, ldb_errstring(ldb));
exit(1);
}
- if (uid >= nrecords && ret > 0) {
+ if (uid >= nrecords && res->count > 0) {
printf("Found %s !? - %d\n", expr, ret);
exit(1);
}
- if (ret > 0) {
- talloc_free(res);
- }
-
- printf("testing uid %d/%d - %d \r", i, uid, ret);
+ printf("testing uid %d/%d - %d \r", i, uid, res->count);
fflush(stdout);
+ talloc_free(res);
free(expr);
}
static void start_test_index(struct ldb_context **ldb)
{
struct ldb_message *msg;
- struct ldb_message **res;
+ struct ldb_result *res = NULL;
struct ldb_dn *indexlist;
struct ldb_dn *basedn;
int ret;
}
ret = ldb_search(*ldb, basedn, LDB_SCOPE_SUBTREE, "uid=test", NULL, &res);
- if (ret != 1) {
- printf("Should have found 1 record - found %d\n", ret);
+ if (ret != LDB_SUCCESS) {
+ printf("Search with (uid=test) filter failed!\n");
+ exit(1);
+ }
+ if(res->count != 1) {
+ printf("Should have found 1 record - found %d\n", res->count);
exit(1);
}
#include "includes.h"
#include "registry.h"
#include "lib/ldb/include/ldb.h"
+#include "lib/ldb/include/ldb_errors.h"
#include "db_wrap.h"
#include "librpc/gen_ndr/winreg.h"
/* Do a search if necessary */
if (kd->subkeys == NULL) {
- kd->subkey_count = ldb_search(c, kd->dn, LDB_SCOPE_ONELEVEL, "(key=*)", NULL, &kd->subkeys);
+ struct ldb_result *res;
+ int ret;
- if(kd->subkey_count < 0) {
+ ret = ldb_search(c, kd->dn, LDB_SCOPE_ONELEVEL, "(key=*)", NULL, &res);
+
+ if (ret != LDB_SUCCESS) {
DEBUG(0, ("Error getting subkeys for '%s': %s\n", ldb_dn_linearize(mem_ctx, kd->dn), ldb_errstring(c)));
return WERR_FOOBAR;
}
+
+ kd->subkey_count = res->count;
+ kd->subkeys = talloc_steal(kd, res->msgs);
+ talloc_free(res);
}
if (idx >= kd->subkey_count) return WERR_NO_MORE_ITEMS;
/* Do the search if necessary */
if (kd->values == NULL) {
- kd->value_count = ldb_search(c, kd->dn, LDB_SCOPE_ONELEVEL, "(value=*)", NULL,&kd->values);
+ struct ldb_result *res;
+ int ret;
+
+ ret = ldb_search(c, kd->dn, LDB_SCOPE_ONELEVEL, "(value=*)", NULL, &res);
- if(kd->value_count < 0) {
+ if (ret != LDB_SUCCESS) {
DEBUG(0, ("Error getting values for '%s': %s\n", ldb_dn_linearize(mem_ctx, kd->dn), ldb_errstring(c)));
return WERR_FOOBAR;
}
+ kd->value_count = res->count;
+ kd->values = talloc_steal(kd, res->msgs);
+ talloc_free(res);
}
if(idx >= kd->value_count) return WERR_NO_MORE_ITEMS;
static WERROR ldb_open_key(TALLOC_CTX *mem_ctx, const struct registry_key *h, const char *name, struct registry_key **key)
{
struct ldb_context *c = talloc_get_type(h->hive->backend_data, struct ldb_context);
- struct ldb_message **msg;
+ struct ldb_result *res;
struct ldb_dn *ldap_path;
int ret;
struct ldb_key_data *newkd;
ldap_path = reg_path_to_ldb(mem_ctx, h, name, NULL);
- ret = ldb_search(c, ldap_path, LDB_SCOPE_BASE, "(key=*)", NULL, &msg);
+ ret = ldb_search(c, ldap_path, LDB_SCOPE_BASE, "(key=*)", NULL, &res);
- if(ret == 0) {
- return WERR_BADFILE;
- } else if(ret < 0) {
+ if (ret != LDB_SUCCESS) {
DEBUG(0, ("Error opening key '%s': %s\n", ldb_dn_linearize(ldap_path, ldap_path), ldb_errstring(c)));
return WERR_FOOBAR;
+ } else if (res->count == 0) {
+ return WERR_BADFILE;
}
*key = talloc(mem_ctx, struct registry_key);
talloc_set_destructor(*key, reg_close_ldb_key);
(*key)->name = talloc_strdup(mem_ctx, strrchr(name, '\\')?strchr(name, '\\'):name);
(*key)->backend_data = newkd = talloc_zero(*key, struct ldb_key_data);
- newkd->dn = ldb_dn_copy(mem_ctx, msg[0]->dn);
+ newkd->dn = ldb_dn_copy(mem_ctx, res->msgs[0]->dn);
- talloc_free(msg);
+ talloc_free(res);
return WERR_OK;
}
-/* include/tdbconfig.h.in. Generated automatically from configure.in by autoheader 2.13. */
+/* include/tdbconfig.h.in. Generated from configure.in by autoheader. */
-/* Define if you have a working `mmap' system call. */
-#undef HAVE_MMAP
-
-/* Define if you have the getpagesize function. */
+/* Define to 1 if you have the `getpagesize' function. */
#undef HAVE_GETPAGESIZE
-/* Define if you have the mmap function. */
+/* Define to 1 if you have the <inttypes.h> header file. */
+#undef HAVE_INTTYPES_H
+
+/* Define to 1 if you have the <memory.h> header file. */
+#undef HAVE_MEMORY_H
+
+/* Define to 1 if you have the `mmap' function. */
#undef HAVE_MMAP
-/* Define if you have the pread function. */
+/* Define to 1 if you have the `pread' function. */
#undef HAVE_PREAD
-/* Define if you have the pwrite function. */
+/* Define to 1 if you have the `pwrite' function. */
#undef HAVE_PWRITE
-/* Define if you have the <unistd.h> header file. */
+/* Define to 1 if you have the <stdint.h> header file. */
+#undef HAVE_STDINT_H
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#undef HAVE_STDLIB_H
+
+/* Define to 1 if you have the <strings.h> header file. */
+#undef HAVE_STRINGS_H
+
+/* Define to 1 if you have the <string.h> header file. */
+#undef HAVE_STRING_H
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#undef HAVE_SYS_STAT_H
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#undef HAVE_SYS_TYPES_H
+
+/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
+
+/* Define to the address where bug reports for this package should be sent. */
+#undef PACKAGE_BUGREPORT
+
+/* Define to the full name of this package. */
+#undef PACKAGE_NAME
+
+/* Define to the full name and version of this package. */
+#undef PACKAGE_STRING
+
+/* Define to the one symbol short name of this package. */
+#undef PACKAGE_TARNAME
+
+/* Define to the version of this package. */
+#undef PACKAGE_VERSION
+
+/* Define to 1 if you have the ANSI C header files. */
+#undef STDC_HEADERS
return ret;
}
+BOOL strhaslower(const char *string)
+{
+ while (*string) {
+ size_t c_size;
+ codepoint_t s;
+ codepoint_t t;
+
+ s = next_codepoint(string, &c_size);
+ string += c_size;
+
+ t = tolower_w(s);
+
+ if (s == t) { /* the source was alreay lower case */
+ return True; /* that means it has lower case chars */
+ }
+ }
+
+ return False;
+}
+
+BOOL strhasupper(const char *string)
+{
+ while (*string) {
+ size_t c_size;
+ codepoint_t s;
+ codepoint_t t;
+
+ s = next_codepoint(string, &c_size);
+ string += c_size;
+
+ t = toupper_w(s);
+
+ if (s == t) { /* the source was alreay upper case */
+ return True; /* that means it has upper case chars */
+ }
+ }
+
+ return False;
+}
+
/**
Convert a string to lower case, allocated with talloc
**/
const struct ldb_dn *account_dn;
const char *account_dn_str;
const char *remote_ldb_url;
- struct ldb_message **msgs, *msg;
+ struct ldb_result *res;
+ struct ldb_message *msg;
- int rtn;
+ int ret, rtn;
unsigned int kvno;
}
/* search for the user's record */
- rtn = ldb_search(remote_ldb, account_dn, LDB_SCOPE_BASE,
- NULL, attrs, &msgs);
- if (rtn != 1) {
+ ret = ldb_search(remote_ldb, account_dn, LDB_SCOPE_BASE,
+ NULL, attrs, &res);
+ if (ret != LDB_SUCCESS || res->count != 1) {
r->out.error_string = talloc_asprintf(r, "ldb_search for %s failed - %s\n",
account_dn_str, ldb_errstring(remote_ldb));
talloc_free(tmp_ctx);
}
/* If we have a kvno recorded in AD, we need it locally as well */
- kvno = ldb_msg_find_uint(msgs[0], "msDS-KeyVersionNumber", 0);
+ kvno = ldb_msg_find_uint(res->msgs[0], "msDS-KeyVersionNumber", 0);
/* Prepare a new message, for the modify */
msg = ldb_msg_new(tmp_ctx);
talloc_free(tmp_ctx);
return NT_STATUS_NO_MEMORY;
}
- msg->dn = msgs[0]->dn;
+ msg->dn = res->msgs[0]->dn;
{
int i;
int ret;
struct ldb_context *ldb = winssrv->wins_db;
struct ldb_dn *dn;
- struct ldb_message **res = NULL;
+ struct ldb_result *res = NULL;
struct ldb_message *msg = NULL;
TALLOC_CTX *tmp_ctx = talloc_new(winssrv);
uint64_t maxVersion = 0;
if (!dn) goto failed;
/* find the record in the WINS database */
- ret = ldb_search(ldb, dn, LDB_SCOPE_BASE,
- NULL, NULL, &res);
- if (res != NULL) {
- talloc_steal(tmp_ctx, res);
- }
- if (ret < 0) goto failed;
- if (ret > 1) goto failed;
+ ret = ldb_search(ldb, dn, LDB_SCOPE_BASE, NULL, NULL, &res);
+
+ if (ret != LDB_SUCCESS) goto failed;
+ if (res->count > 1) goto failed;
- if (ret == 1) {
- maxVersion = ldb_msg_find_uint64(res[0], "maxVersion", 0);
+ talloc_steal(tmp_ctx, res);
+
+ if (res->count == 1) {
+ maxVersion = ldb_msg_find_uint64(res->msgs[0], "maxVersion", 0);
}
maxVersion++;
struct winsdb_record **_rec)
{
NTSTATUS status;
- struct ldb_message **res = NULL;
+ struct ldb_result *res = NULL;
int ret;
struct winsdb_record *rec;
TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
/* find the record in the WINS database */
ret = ldb_search(wins_db, winsdb_dn(tmp_ctx, name), LDB_SCOPE_BASE,
NULL, NULL, &res);
- if (res != NULL) {
- talloc_steal(tmp_ctx, res);
- }
- if (ret == 0) {
- status = NT_STATUS_OBJECT_NAME_NOT_FOUND;
- goto failed;
- } else if (ret != 1) {
+
+ if (ret != LDB_SUCCESS || res->count > 1) {
status = NT_STATUS_INTERNAL_DB_CORRUPTION;
goto failed;
+ } else if (res->count== 0) {
+ status = NT_STATUS_OBJECT_NAME_NOT_FOUND;
+ goto failed;
}
- status = winsdb_record(res[0], name, tmp_ctx, &rec);
+ talloc_steal(tmp_ctx, res);
+
+ status = winsdb_record(res->msgs[0], name, tmp_ctx, &rec);
if (!NT_STATUS_IS_OK(status)) goto failed;
/* see if it has already expired */
DCESRV_PULL_HANDLE_WERR(h, r->in.handle, DCESRV_HANDLE_ANY);
handle = talloc_get_type(h->data, struct ntptr_GenericHandle);
- if (!handle)
- return WERR_BADFID;
switch (handle->type) {
case NTPTR_HANDLE_SERVER:
DCESRV_PULL_HANDLE_WERR(h, r->in.handle, DCESRV_HANDLE_ANY);
handle = talloc_get_type(h->data, struct ntptr_GenericHandle);
- if (!handle)
- return WERR_BADFID;
switch (handle->type) {
case NTPTR_HANDLE_SERVER:
DCESRV_PULL_HANDLE_WERR(h, r->in.handle, DCESRV_HANDLE_ANY);
handle = talloc_get_type(h->data, struct ntptr_GenericHandle);
- if (!handle)
- return WERR_BADFID;
switch (handle->type) {
case NTPTR_HANDLE_SERVER:
DCESRV_PULL_HANDLE_WERR(h, r->in.handle, DCESRV_HANDLE_ANY);
handle = talloc_get_type(h->data, struct ntptr_GenericHandle);
- if (!handle)
- return WERR_BADFID;
switch (handle->type) {
case NTPTR_HANDLE_SERVER:
DCESRV_PULL_HANDLE_WERR(h, r->in.handle, DCESRV_HANDLE_ANY);
handle = talloc_get_type(h->data, struct ntptr_GenericHandle);
- if (!handle)
- return WERR_BADFID;
switch (handle->type) {
case NTPTR_HANDLE_SERVER:
DCESRV_PULL_HANDLE_WERR(h, r->in.handle, DCESRV_HANDLE_ANY);
handle = talloc_get_type(h->data, struct ntptr_GenericHandle);
- if (!handle)
- return WERR_BADFID;
switch (handle->type) {
case NTPTR_HANDLE_SERVER:
#include "scripting/ejs/smbcalls.h"
#include "lib/appweb/ejs/ejs.h"
#include "lib/ldb/include/ldb.h"
+#include "lib/ldb/include/ldb_errors.h"
/*
get the connected db
TALLOC_CTX *tmp_ctx = talloc_new(mprMemCtx());
struct ldb_context *ldb;
int ret;
- struct ldb_message **res;
+ struct ldb_result *res;
/* validate arguments */
if (argc < 1 || argc > 4) {
attrs = mprToList(tmp_ctx, argv[3]);
}
ret = ldb_search(ldb, basedn, scope, expression, attrs, &res);
- if (ret == -1) {
+ if (ret != LDB_SUCCESS) {
ejsSetErrorMsg(eid, "ldb.search failed - %s", ldb_errstring(ldb));
mpr_Return(eid, mprCreateUndefinedVar());
} else {
- mpr_Return(eid, mprLdbArray(ldb, res, ret, "ldb_message"));
+ mpr_Return(eid, mprLdbArray(ldb, res->msgs, res->count, "ldb_message"));
}
talloc_free(tmp_ctx);
#include "libcli/composite/composite.h"
#include "nbt_server/wins/winsdb.h"
#include "lib/ldb/include/ldb.h"
+#include "lib/ldb/include/ldb_errors.h"
static NTSTATUS wreplsrv_in_start_association(struct wreplsrv_in_call *call)
{
struct wreplsrv_owner local_owner;
struct wreplsrv_owner *owner;
const char *filter;
- struct ldb_message **res = NULL;
+ struct ldb_result *res = NULL;
int ret;
struct wrepl_wins_name *names;
struct winsdb_record *rec;
owner_in->min_version, owner_in->max_version);
NT_STATUS_HAVE_NO_MEMORY(filter);
ret = ldb_search(service->wins_db, NULL, LDB_SCOPE_SUBTREE, filter, NULL, &res);
- if (res != NULL) {
- talloc_steal(call, res);
- }
- if (ret < 0) return NT_STATUS_INTERNAL_DB_CORRUPTION;
- if (ret == 0) {
+ if (ret != LDB_SUCCESS) return NT_STATUS_INTERNAL_DB_CORRUPTION;
+ talloc_steal(call, res);
+ if (res->count == 0) {
DEBUG(2,("WINSREPL:reply [%u] records owner[%s] min[%llu] max[%llu] to partner[%s]\n",
- ret, owner_in->address, owner_in->min_version, owner_in->max_version,
+ res->count, owner_in->address, owner_in->min_version, owner_in->max_version,
call->wreplconn->partner->address));
return NT_STATUS_OK;
}
- names = talloc_array(call, struct wrepl_wins_name, ret);
+ names = talloc_array(call, struct wrepl_wins_name, res->count);
NT_STATUS_HAVE_NO_MEMORY(names);
- for (i=0; i < ret; i++) {
- status = winsdb_record(res[i], NULL, call, &rec);
+ for (i = 0; i < res->count; i++) {
+ status = winsdb_record(res->msgs[i], NULL, call, &rec);
NT_STATUS_NOT_OK_RETURN(status);
status = wreplsrv_record2wins_name(names, call->wreplconn->our_ip, &names[i], rec);
NT_STATUS_NOT_OK_RETURN(status);
talloc_free(rec);
- talloc_free(res[i]);
+ talloc_free(res->msgs[i]);
}
/* sort the names before we send them */
#include "wrepl_server/wrepl_server.h"
#include "nbt_server/wins/winsdb.h"
#include "ldb/include/ldb.h"
+#include "ldb/include/ldb_errors.h"
/*
open winsdb
*/
static NTSTATUS wreplsrv_load_partners(struct wreplsrv_service *service)
{
- struct ldb_message **res = NULL;
+ struct ldb_result *res = NULL;
int ret;
TALLOC_CTX *tmp_ctx = talloc_new(service);
int i;
/* find the record in the WINS database */
ret = ldb_search(service->wins_db, ldb_dn_explode(tmp_ctx, "CN=PARTNERS"), LDB_SCOPE_ONELEVEL,
"(objectClass=wreplPartner)", NULL, &res);
- if (res != NULL) {
- talloc_steal(tmp_ctx, res);
- }
- if (ret < 0) goto failed;
- if (ret == 0) goto done;
+ if (ret != LDB_SUCCESS) goto failed;
+ talloc_steal(tmp_ctx, res);
+ if (res->count == 0) goto done;
- for (i=0; i < ret; i++) {
+ for (i=0; i < res->count; i++) {
struct wreplsrv_partner *partner;
partner = talloc_zero(service, struct wreplsrv_partner);
if (partner == NULL) goto failed;
- partner->service = service;
- partner->address = ldb_msg_find_string(res[i], "address", NULL);
+ partner->service = service;
+ partner->address = ldb_msg_find_string(res->msgs[i], "address", NULL);
if (!partner->address) goto failed;
- partner->name = ldb_msg_find_string(res[i], "name", partner->address);
- partner->type = ldb_msg_find_uint(res[i], "type", WINSREPL_PARTNER_BOTH);
- partner->pull.interval = ldb_msg_find_uint(res[i], "pullInterval",
+ partner->name = ldb_msg_find_string(res->msgs[i], "name", partner->address);
+ partner->type = ldb_msg_find_uint(res->msgs[i], "type", WINSREPL_PARTNER_BOTH);
+ partner->pull.interval = ldb_msg_find_uint(res->msgs[i], "pullInterval",
WINSREPL_DEFAULT_PULL_INTERVAL);
- partner->pull.retry_interval = ldb_msg_find_uint(res[i], "pullRetryInterval",
+ partner->pull.retry_interval = ldb_msg_find_uint(res->msgs[i], "pullRetryInterval",
WINSREPL_DEFAULT_PULL_RETRY_INTERVAL);
- partner->our_address = ldb_msg_find_string(res[i], "ourAddress", NULL);
- partner->push.change_count = ldb_msg_find_uint(res[i], "pushChangeCount",
+ partner->our_address = ldb_msg_find_string(res->msgs[i], "ourAddress", NULL);
+ partner->push.change_count = ldb_msg_find_uint(res->msgs[i], "pushChangeCount",
WINSREPL_DEFAULT_PUSH_CHANGE_COUNT);
talloc_steal(partner, partner->address);
int ret;
struct ldb_context *ldb = service->wins_db;
struct ldb_dn *dn;
- struct ldb_message **res = NULL;
+ struct ldb_result *res = NULL;
TALLOC_CTX *tmp_ctx = talloc_new(service);
uint64_t maxVersion = 0;
/* find the record in the WINS database */
ret = ldb_search(ldb, dn, LDB_SCOPE_BASE,
NULL, NULL, &res);
- if (res != NULL) {
- talloc_steal(tmp_ctx, res);
- }
- if (ret < 0) goto failed;
- if (ret > 1) goto failed;
+ if (ret != LDB_SUCCESS) goto failed;
+ talloc_steal(tmp_ctx, res);
+ if (res->count > 1) goto failed;
- if (ret == 1) {
- maxVersion = ldb_msg_find_uint64(res[0], "maxVersion", 0);
+ if (res->count == 1) {
+ maxVersion = ldb_msg_find_uint64(res->msgs[0], "maxVersion", 0);
}
failed:
*/
static NTSTATUS wreplsrv_load_table(struct wreplsrv_service *service)
{
- struct ldb_message **res = NULL;
+ struct ldb_result *res = NULL;
int ret;
NTSTATUS status;
TALLOC_CTX *tmp_ctx = talloc_new(service);
/* find the record in the WINS database */
ret = ldb_search(service->wins_db, NULL, LDB_SCOPE_SUBTREE,
"(objectClass=winsRecord)", attrs, &res);
- if (res != NULL) {
- talloc_steal(tmp_ctx, res);
- }
status = NT_STATUS_INTERNAL_DB_CORRUPTION;
- if (ret < 0) goto failed;
- if (ret == 0) goto done;
+ if (ret != LDB_SUCCESS) goto failed;
+ talloc_steal(tmp_ctx, res);
+ if (res->count == 0) goto done;
- for (i=0; i < ret; i++) {
- wins_owner = ldb_msg_find_string(res[i], "winsOwner", NULL);
- version = ldb_msg_find_uint64(res[i], "versionID", 0);
+ for (i=0; i < res->count; i++) {
+ wins_owner = ldb_msg_find_string(res->msgs[i], "winsOwner", NULL);
+ version = ldb_msg_find_uint64(res->msgs[i], "versionID", 0);
if (wins_owner) {
status = wreplsrv_add_table(service,
wins_owner, version);
if (!NT_STATUS_IS_OK(status)) goto failed;
}
- talloc_free(res[i]);
+ talloc_free(res->msgs[i]);
/* TODO: what's abut the per address owners? */
}