Copyright (C) Andrew Tridgell 2004
Copyright (C) Stefan Metzmacher 2004
Copyright (C) Simo Sorce 2006-2008
- Copyright (C) Matthias Dieter Wallnöfer 2009
+ Copyright (C) Matthias Dieter Wallnöfer 2009-2010
** NOTE! The following LGPL license applies to the ldb
** library. This does NOT imply that all of Samba is released
*
* Modifications:
*
- * - description: make the module use asyncronous calls
+ * - description: make the module use asynchronous calls
* date: Feb 2006
* Author: Simo Sorce
*
return LDB_ERR_NO_SUCH_OBJECT;
case TDB_ERR_RDONLY:
return LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
+ default:
+ break;
}
return LDB_ERR_OTHER;
}
currently only @ATTRIBUTES is checked
*/
static int ltdb_check_special_dn(struct ldb_module *module,
- const struct ldb_message *msg)
+ const struct ldb_message *msg)
{
struct ldb_context *ldb = ldb_module_get_ctx(module);
- int i, j;
+ unsigned int i, j;
if (! ldb_dn_is_special(msg->dn) ||
! ldb_dn_check_special(msg->dn, LTDB_ATTRIBUTES)) {
const struct ldb_message *msg)
{
struct ldb_context *ldb = ldb_module_get_ctx(module);
- int ret = LDB_SUCCESS, i;
-
- ret = ltdb_check_special_dn(module, msg);
- if (ret != LDB_SUCCESS) {
- return ret;
- }
-
- if (ltdb_cache_load(module) != 0) {
- return LDB_ERR_OPERATIONS_ERROR;
- }
+ int ret = LDB_SUCCESS;
+ unsigned int i;
for (i=0;i<msg->num_elements;i++) {
struct ldb_message_element *el = &msg->elements[i];
const struct ldb_schema_attribute *a = ldb_schema_attribute_by_name(ldb, el->name);
if (el->num_values == 0) {
- ldb_asprintf_errstring(ldb, "attribute %s on %s specified, but with 0 values (illegal)",
+ ldb_asprintf_errstring(ldb, "attribute '%s' on '%s' specified, but with 0 values (illegal)",
el->name, ldb_dn_get_linearized(msg->dn));
return LDB_ERR_CONSTRAINT_VIOLATION;
}
- if (a && a->flags & LDB_ATTR_FLAG_SINGLE_VALUE) {
+ if (a && (a->flags & LDB_ATTR_FLAG_SINGLE_VALUE) &&
+ !(el->flags & LDB_FLAG_INTERNAL_DISABLE_SINGLE_VALUE_CHECK)) {
if (el->num_values > 1) {
ldb_asprintf_errstring(ldb, "SINGLE-VALUE attribute %s on %s specified more than once",
el->name, ldb_dn_get_linearized(msg->dn));
struct ldb_request *req = ctx->req;
int ret = LDB_SUCCESS;
+ ret = ltdb_check_special_dn(module, req->op.add.message);
+ if (ret != LDB_SUCCESS) {
+ return ret;
+ }
+
ldb_request_set_state(req, LDB_ASYNC_PENDING);
if (ltdb_cache_load(module) != 0) {
struct ldb_message *msg;
int ret = LDB_SUCCESS;
- msg = talloc(module, struct ldb_message);
+ msg = ldb_msg_new(module);
if (msg == NULL) {
return LDB_ERR_OPERATIONS_ERROR;
}
return LDB_ERR_NO_SUCH_ATTRIBUTE;
}
- el = &msg->elements[found];
+ i = (unsigned int) found;
+ el = &(msg->elements[i]);
a = ldb_schema_attribute_by_name(ldb, el->name);
for (i=0;i<el->num_values;i++) {
- if (a->syntax->comparison_fn(ldb, ldb,
- &el->values[i], val) == 0) {
+ bool matched;
+ if (a->syntax->operator_fn) {
+ ret = a->syntax->operator_fn(ldb, LDB_OP_EQUALITY, a,
+ &el->values[i], val, &matched);
+ if (ret != LDB_SUCCESS) return ret;
+ } else {
+ matched = (a->syntax->comparison_fn(ldb, ldb,
+ &el->values[i], val) == 0);
+ }
+ if (matched) {
if (el->num_values == 1) {
return msg_delete_attribute(module, ldb, msg, name);
}
struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private);
TDB_DATA tdb_key, tdb_data;
struct ldb_message *msg2;
- unsigned i, j, k;
+ unsigned int i, j, k;
int ret = LDB_SUCCESS, idx;
struct ldb_control *control_permissive = NULL;
return ltdb_err_map(tdb_error(ltdb->tdb));
}
- msg2 = talloc(tdb_key.dptr, struct ldb_message);
+ msg2 = ldb_msg_new(tdb_key.dptr);
if (msg2 == NULL) {
free(tdb_data.dptr);
ret = LDB_ERR_OTHER;
const struct ldb_schema_attribute *a = ldb_schema_attribute_by_name(ldb, el->name);
const char *dn;
- if (ldb_attr_cmp(el->name, "distinguishedName") == 0) {
- ldb_asprintf_errstring(ldb, "it is not permitted to perform a modify on 'distinguishedName' (use rename instead): %s",
- ldb_dn_get_linearized(msg2->dn));
- ret = LDB_ERR_CONSTRAINT_VIOLATION;
- goto done;
- }
-
switch (msg->elements[i].flags & LDB_FLAG_MOD_MASK) {
case LDB_FLAG_MOD_ADD:
if (el->num_values == 0) {
- ldb_asprintf_errstring(ldb, "attribute %s on %s specified, but with 0 values (illigal)",
+ ldb_asprintf_errstring(ldb,
+ "attribute '%s': attribute on '%s' specified, but with 0 values (illegal)",
el->name, ldb_dn_get_linearized(msg2->dn));
ret = LDB_ERR_CONSTRAINT_VIOLATION;
goto done;
}
}
- if (a && a->flags & LDB_ATTR_FLAG_SINGLE_VALUE) {
+ if (a && (a->flags & LDB_ATTR_FLAG_SINGLE_VALUE) &&
+ !(el->flags & LDB_FLAG_INTERNAL_DISABLE_SINGLE_VALUE_CHECK)) {
if (el->num_values > 1) {
ldb_asprintf_errstring(ldb, "SINGLE-VALUE attribute %s on %s specified more than once",
el->name, ldb_dn_get_linearized(msg2->dn));
ret = LDB_ERR_OTHER;
goto done;
}
- ret = ltdb_index_add_element(module, msg2->dn, el);
+ ret = ltdb_index_add_element(module, msg2->dn,
+ el);
if (ret != LDB_SUCCESS) {
goto done;
}
} else {
+ j = (unsigned int) idx;
+ el2 = &(msg2->elements[j]);
+
/* We cannot add another value on a existing one
if the attribute is single-valued */
- if (a && a->flags & LDB_ATTR_FLAG_SINGLE_VALUE) {
+ if (a && (a->flags & LDB_ATTR_FLAG_SINGLE_VALUE) &&
+ !(el->flags & LDB_FLAG_INTERNAL_DISABLE_SINGLE_VALUE_CHECK)) {
ldb_asprintf_errstring(ldb, "SINGLE-VALUE attribute %s on %s specified more than once",
el->name, ldb_dn_get_linearized(msg2->dn));
ret = LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS;
goto done;
}
- el2 = &(msg2->elements[idx]);
-
/* Check that values don't exist yet on multi-
valued attributes or aren't provided twice */
for (j = 0; j < el->num_values; j++) {
continue;
}
- ldb_asprintf_errstring(ldb, "%s: value #%d already exists", el->name, j);
+ ldb_asprintf_errstring(ldb,
+ "attribute '%s': value #%u on '%s' already exists",
+ el->name, j, ldb_dn_get_linearized(msg2->dn));
ret = LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS;
goto done;
}
if (ldb_msg_find_val(el, &el->values[j]) != &el->values[j]) {
- ldb_asprintf_errstring(ldb, "%s: value #%d provided more than once", el->name, j);
+ ldb_asprintf_errstring(ldb,
+ "attribute '%s': value #%u on '%s' provided more than once",
+ el->name, j, ldb_dn_get_linearized(msg2->dn));
ret = LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS;
goto done;
}
case LDB_FLAG_MOD_REPLACE:
- if (a && a->flags & LDB_ATTR_FLAG_SINGLE_VALUE) {
- /* the RELAX control overrides this
- check for replace. This is needed as
- DRS replication can produce multiple
- values here for a single valued
- attribute when the values are deleted
- links
- */
- if (el->num_values > 1 &&
- (!req || !ldb_request_get_control(req, LDB_CONTROL_RELAX_OID))) {
+ if (a && (a->flags & LDB_ATTR_FLAG_SINGLE_VALUE) &&
+ !(el->flags & LDB_FLAG_INTERNAL_DISABLE_SINGLE_VALUE_CHECK)) {
+ if (el->num_values > 1) {
ldb_asprintf_errstring(ldb, "SINGLE-VALUE attribute %s on %s specified more than once",
el->name, ldb_dn_get_linearized(msg2->dn));
ret = LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS;
/* TODO: This is O(n^2) - replace with more efficient check */
for (j=0; j<el->num_values; j++) {
if (ldb_msg_find_val(el, &el->values[j]) != &el->values[j]) {
- ldb_asprintf_errstring(ldb, "%s: value #%d provided more than once", el->name, j);
+ ldb_asprintf_errstring(ldb,
+ "attribute '%s': value #%u on '%s' provided more than once",
+ el->name, j, ldb_dn_get_linearized(msg2->dn));
ret = LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS;
goto done;
}
}
+ /* Checks if element already exists */
idx = find_element(msg2, el->name);
if (idx != -1) {
- el2 = &(msg2->elements[idx]);
+ j = (unsigned int) idx;
+ el2 = &(msg2->elements[j]);
if (ldb_msg_element_compare(el, el2) == 0) {
/* we are replacing with the same values */
continue;
}
/* Delete the attribute if it exists in the DB */
- if (msg_delete_attribute(module, ldb, msg2, el->name) != 0) {
+ if (msg_delete_attribute(module, ldb, msg2,
+ el->name) != 0) {
ret = LDB_ERR_OTHER;
goto done;
}
control_permissive) {
ret = LDB_SUCCESS;
} else {
- ldb_asprintf_errstring(ldb, "No such attribute: %s for delete on %s",
+ ldb_asprintf_errstring(ldb,
+ "attribute '%s': no such attribute for delete on '%s'",
msg->elements[i].name, dn);
}
if (ret != LDB_SUCCESS) {
control_permissive) {
ret = LDB_SUCCESS;
} else {
- ldb_asprintf_errstring(ldb, "No matching attribute value when deleting attribute: %s on %s",
+ ldb_asprintf_errstring(ldb,
+ "attribute '%s': no matching attribute value while deleting attribute on '%s'",
msg->elements[i].name, dn);
}
if (ret != LDB_SUCCESS) {
break;
default:
ldb_asprintf_errstring(ldb,
- "Invalid ldb_modify flags on %s: 0x%x",
- msg->elements[i].name,
- msg->elements[i].flags & LDB_FLAG_MOD_MASK);
+ "attribute '%s': invalid modify flags on '%s': 0x%x",
+ msg->elements[i].name, ldb_dn_get_linearized(msg->dn),
+ msg->elements[i].flags & LDB_FLAG_MOD_MASK);
ret = LDB_ERR_PROTOCOL_ERROR;
goto done;
}
return LDB_ERR_OPERATIONS_ERROR;
}
- msg = talloc(ctx, struct ldb_message);
+ msg = ldb_msg_new(ctx);
if (msg == NULL) {
return LDB_ERR_OPERATIONS_ERROR;
}
dn = ldb_dn_new(tmp_ctx, ldb, LTDB_BASEINFO);
- msg = talloc(tmp_ctx, struct ldb_message);
+ msg = ldb_msg_new(tmp_ctx);
if (msg == NULL) {
ret = LDB_ERR_OPERATIONS_ERROR;
goto done;
goto done;
default:
/* no other op supported */
- ret = LDB_ERR_UNWILLING_TO_PERFORM;
+ ret = LDB_ERR_PROTOCOL_ERROR;
}
if (!ctx->request_terminated) {
struct ltdb_context *ac;
struct tevent_timer *te;
struct timeval tv;
- int i;
+ unsigned int i;
ldb = ldb_module_get_ctx(module);
ret = ldb_mod_register_control(module,
LDB_CONTROL_PERMISSIVE_MODIFY_OID);
- if (ret != LDB_SUCCESS) {
- ldb_debug(ldb, LDB_DEBUG_WARNING, "ldb_tdb: "
- "Unable to register control with rootdse!");
- }
+ /* ignore errors on this - we expect it for non-sam databases */
/* there can be no module beyond the backend, just return */
return LDB_SUCCESS;
return LDB_ERR_OPERATIONS_ERROR;
}
+ if (getenv("LDB_WARN_UNINDEXED")) {
+ ltdb->warn_unindexed = true;
+ }
+
ltdb->sequence_number = 0;
module = ldb_module_new(ldb, ldb, "ldb_tdb backend", <db_ops);
return LDB_SUCCESS;
}
-const struct ldb_backend_ops ldb_tdb_backend_ops = {
- .name = "tdb",
- .connect_fn = ltdb_connect,
-};
+int ldb_tdb_init(const char *version)
+{
+ LDB_MODULE_CHECK_VERSION(version);
+ return ldb_register_backend("tdb", ltdb_connect, false);
+}