diff options
Diffstat (limited to 'source4')
-rw-r--r-- | source4/lib/ldb/common/ldb.c | 34 | ||||
-rw-r--r-- | source4/lib/ldb/common/ldb_modules.c | 9 | ||||
-rw-r--r-- | source4/lib/ldb/include/ldb_private.h | 6 | ||||
-rw-r--r-- | source4/lib/ldb/ldb_ildap/ldb_ildap.c | 21 | ||||
-rw-r--r-- | source4/lib/ldb/ldb_ldap/ldb_ldap.c | 18 | ||||
-rw-r--r-- | source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c | 216 | ||||
-rw-r--r-- | source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.h | 1 | ||||
-rw-r--r-- | source4/lib/ldb/ldb_tdb/ldb_search.c | 12 | ||||
-rw-r--r-- | source4/lib/ldb/ldb_tdb/ldb_tdb.c | 122 | ||||
-rw-r--r-- | source4/lib/ldb/ldb_tdb/ldb_tdb.h | 3 | ||||
-rw-r--r-- | source4/lib/ldb/modules/ldb_map.c | 27 | ||||
-rw-r--r-- | source4/lib/ldb/modules/rdn_name.c | 43 | ||||
-rw-r--r-- | source4/lib/ldb/modules/schema.c | 102 | ||||
-rw-r--r-- | source4/lib/ldb/modules/skel.c | 13 | ||||
-rw-r--r-- | source4/lib/ldb/modules/timestamps.c | 34 | ||||
-rw-r--r-- | source4/lib/ldb/tools/ldbadd.c | 3 |
16 files changed, 310 insertions, 354 deletions
diff --git a/source4/lib/ldb/common/ldb.c b/source4/lib/ldb/common/ldb.c index 57fb5a81da..a00c2481d8 100644 --- a/source4/lib/ldb/common/ldb.c +++ b/source4/lib/ldb/common/ldb.c @@ -106,6 +106,14 @@ int ldb_connect(struct ldb_context *ldb, const char *url, unsigned int flags, co return LDB_ERR_SUCCESS; } +static void ldb_reset_err_string(struct ldb_context *ldb) +{ + if (ldb->err_string) { + talloc_free(ldb->err_string); + ldb->err_string = NULL; + } +} + /* start a transaction */ @@ -136,6 +144,8 @@ int ldb_search(struct ldb_context *ldb, const char *expression, const char * const *attrs, struct ldb_message ***res) { + ldb_reset_err_string(ldb); + return ldb->modules->ops->search(ldb->modules, base, scope, expression, attrs, res); } @@ -153,6 +163,8 @@ int ldb_search_bytree(struct ldb_context *ldb, struct ldb_parse_tree *tree, const char * const *attrs, struct ldb_message ***res) { + ldb_reset_err_string(ldb); + return ldb->modules->ops->search_bytree(ldb->modules, base, scope, tree, attrs, res); } @@ -165,6 +177,7 @@ int ldb_add(struct ldb_context *ldb, { int status; + ldb_reset_err_string(ldb); status = ldb_msg_sanity_check(message); if (status != LDB_ERR_SUCCESS) return status; @@ -184,6 +197,8 @@ int ldb_modify(struct ldb_context *ldb, { int status; + ldb_reset_err_string(ldb); + status = ldb_msg_sanity_check(message); if (status != LDB_ERR_SUCCESS) return status; @@ -200,7 +215,11 @@ int ldb_modify(struct ldb_context *ldb, */ int ldb_delete(struct ldb_context *ldb, const struct ldb_dn *dn) { - int status = ldb_start_trans(ldb); + int status; + + ldb_reset_err_string(ldb); + + status = ldb_start_trans(ldb); if (status != LDB_ERR_SUCCESS) return status; status = ldb->modules->ops->delete_record(ldb->modules, dn); @@ -212,7 +231,11 @@ int ldb_delete(struct ldb_context *ldb, const struct ldb_dn *dn) */ int ldb_rename(struct ldb_context *ldb, const struct ldb_dn *olddn, const struct ldb_dn *newdn) { - int status = ldb_start_trans(ldb); + int status; + + ldb_reset_err_string(ldb); + + status = ldb_start_trans(ldb); if (status != LDB_ERR_SUCCESS) return status; status = ldb->modules->ops->rename_record(ldb->modules, olddn, newdn); @@ -224,10 +247,11 @@ int ldb_rename(struct ldb_context *ldb, const struct ldb_dn *olddn, const struct */ const char *ldb_errstring(struct ldb_context *ldb) { - if (ldb->modules == NULL) { - return "ldb not connected"; + if (ldb->err_string) { + return ldb->err_string; } - return ldb->modules->ops->errstring(ldb->modules); + + return NULL; } diff --git a/source4/lib/ldb/common/ldb_modules.c b/source4/lib/ldb/common/ldb_modules.c index 29bc8264e9..e1f5b83083 100644 --- a/source4/lib/ldb/common/ldb_modules.c +++ b/source4/lib/ldb/common/ldb_modules.c @@ -322,11 +322,12 @@ int ldb_next_end_trans(struct ldb_module *module, int status) return module->next->ops->end_transaction(module->next, status); } -const char *ldb_next_errstring(struct ldb_module *module) +void ldb_set_errstring(struct ldb_module *module, char *err_string) { - if (!module->next) { - return NULL; + if (module->ldb->err_string) { + talloc_free(module->ldb->err_string); } - return module->next->ops->errstring(module->next); + + module->ldb->err_string = err_string; } diff --git a/source4/lib/ldb/include/ldb_private.h b/source4/lib/ldb/include/ldb_private.h index 96cd458920..7eb2bca679 100644 --- a/source4/lib/ldb/include/ldb_private.h +++ b/source4/lib/ldb/include/ldb_private.h @@ -66,7 +66,6 @@ struct ldb_module_ops { int (*rename_record)(struct ldb_module *, const struct ldb_dn *, const struct ldb_dn *); int (*start_transaction)(struct ldb_module *); int (*end_transaction)(struct ldb_module *, int); - const char * (*errstring)(struct ldb_module *); }; @@ -104,6 +103,8 @@ struct ldb_context { } *opaque; struct ldb_schema schema; + + char *err_string; }; /* the modules init function */ @@ -137,7 +138,8 @@ 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_start_trans(struct ldb_module *module); int ldb_next_end_trans(struct ldb_module *module, int status); -const char *ldb_next_errstring(struct ldb_module *module); + +void ldb_set_errstring(struct ldb_module *module, char *err_string); /* The following definitions come from lib/ldb/common/ldb_debug.c */ void ldb_debug(struct ldb_context *ldb, enum ldb_debug_level level, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4); diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index d4239c0f72..be51a65c58 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -82,6 +82,7 @@ static int ildb_rename(struct ldb_module *module, const struct ldb_dn *olddn, co ildb->last_rc = ildap_rename(ildb->ldap, old_dn, newrdn, parentdn, True); if (!NT_STATUS_IS_OK(ildb->last_rc)) { + ldb_set_errstring(module, talloc_strdup(module, ldap_errstr(ildb->ldap, ildb->last_rc))); ret = -1; } @@ -111,6 +112,7 @@ static int ildb_delete(struct ldb_module *module, const struct ldb_dn *dn) ildb->last_rc = ildap_delete(ildb->ldap, del_dn); if (!NT_STATUS_IS_OK(ildb->last_rc)) { + ldb_set_errstring(module, talloc_strdup(module, ldap_errstr(ildb->ldap, ildb->last_rc))); ret = -1; } @@ -316,6 +318,7 @@ static int ildb_add(struct ldb_module *module, const struct ldb_message *msg) ildb->last_rc = ildap_add(ildb->ldap, dn, mods); if (!NT_STATUS_IS_OK(ildb->last_rc)) { + ldb_set_errstring(module, talloc_strdup(module, ldap_errstr(ildb->ldap, ildb->last_rc))); ret = -1; } @@ -354,6 +357,7 @@ static int ildb_modify(struct ldb_module *module, const struct ldb_message *msg) ildb->last_rc = ildap_modify(ildb->ldap, dn, mods); if (!NT_STATUS_IS_OK(ildb->last_rc)) { + ldb_set_errstring(module, talloc_strdup(module, ldap_errstr(ildb->ldap, ildb->last_rc))); ret = -1; } @@ -376,20 +380,6 @@ static int ildb_end_trans(struct ldb_module *module, int status) return status; } -/* - return extended error information -*/ -static const char *ildb_errstring(struct ldb_module *module) -{ - struct ildb_private *ildb = talloc_get_type(module->private_data, - struct ildb_private); - if (ildb == NULL) { - return "ildap not connected"; - } - return ldap_errstr(ildb->ldap, ildb->last_rc); -} - - static const struct ldb_module_ops ildb_ops = { .name = "ldap", .search = ildb_search, @@ -399,8 +389,7 @@ static const struct ldb_module_ops ildb_ops = { .delete_record = ildb_delete, .rename_record = ildb_rename, .start_transaction = ildb_start_trans, - .end_transaction = ildb_end_trans, - .errstring = ildb_errstring + .end_transaction = ildb_end_trans }; diff --git a/source4/lib/ldb/ldb_ldap/ldb_ldap.c b/source4/lib/ldb/ldb_ldap/ldb_ldap.c index 39f56dba0e..2035913f2a 100644 --- a/source4/lib/ldb/ldb_ldap/ldb_ldap.c +++ b/source4/lib/ldb/ldb_ldap/ldb_ldap.c @@ -78,6 +78,7 @@ static int lldb_rename(struct ldb_module *module, const struct ldb_dn *olddn, co lldb->last_rc = ldap_rename_s(lldb->ldap, old_dn, newrdn, parentdn, 1, NULL, NULL); if (lldb->last_rc != LDAP_SUCCESS) { + ldb_set_errstring(module, talloc_strdup(module, ldap_err2string(lldb->last_rc))); ret = -1; } @@ -107,6 +108,7 @@ static int lldb_delete(struct ldb_module *module, const struct ldb_dn *edn) lldb->last_rc = ldap_delete_s(lldb->ldap, dn); if (lldb->last_rc != LDAP_SUCCESS) { + ldb_set_errstring(module, talloc_strdup(module, ldap_err2string(lldb->last_rc))); ret = -1; } @@ -200,6 +202,7 @@ static int lldb_search(struct ldb_module *module, const struct ldb_dn *base, 0, &ldapres); talloc_free(search_base); if (lldb->last_rc != LDAP_SUCCESS) { + ldb_set_errstring(module, talloc_strdup(module, ldap_err2string(lldb->last_rc))); return -1; } @@ -404,6 +407,7 @@ static int lldb_add(struct ldb_module *module, const struct ldb_message *msg) lldb->last_rc = ldap_add_s(lldb->ldap, dn, mods); if (lldb->last_rc != LDAP_SUCCESS) { + ldb_set_errstring(module, talloc_strdup(module, ldap_err2string(lldb->last_rc))); ret = -1; } @@ -442,6 +446,7 @@ static int lldb_modify(struct ldb_module *module, const struct ldb_message *msg) lldb->last_rc = ldap_modify_s(lldb->ldap, dn, mods); if (lldb->last_rc != LDAP_SUCCESS) { + ldb_set_errstring(module, talloc_strdup(module, ldap_err2string(lldb->last_rc))); ret = -1; } @@ -464,16 +469,6 @@ static int lldb_end_trans(struct ldb_module *module, int status) return status; } -/* - return extended error information -*/ -static const char *lldb_errstring(struct ldb_module *module) -{ - struct lldb_private *lldb = module->private_data; - return ldap_err2string(lldb->last_rc); -} - - static const struct ldb_module_ops lldb_ops = { .name = "ldap", .search = lldb_search, @@ -483,8 +478,7 @@ static const struct ldb_module_ops lldb_ops = { .delete_record = lldb_delete, .rename_record = lldb_rename, .start_transaction = lldb_start_trans, - .end_transaction = lldb_end_trans, - .errstring = lldb_errstring + .end_transaction = lldb_end_trans }; diff --git a/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c b/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c index c0adab7bc3..8742b53962 100644 --- a/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c +++ b/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c @@ -36,6 +36,7 @@ #include <stdarg.h> #include "includes.h" #include "ldb/include/ldb.h" +#include "ldb/include/ldb_errors.h" #include "ldb/include/ldb_private.h" #include "ldb/ldb_sqlite3/ldb_sqlite3.h" @@ -828,12 +829,17 @@ static int lsqlite3_search_bytree(struct ldb_module * module, const struct ldb_d if (basedn) { norm_basedn = ldb_dn_linearize(local_ctx, ldb_dn_casefold(module->ldb, basedn)); - if (norm_basedn == NULL) goto failed; + if (norm_basedn == NULL) { + ret = LDB_ERR_INVALID_DN_SYNTAX; + goto failed; + } } else norm_basedn = talloc_strdup(local_ctx, ""); if (*norm_basedn == '\0' && - (scope == LDB_SCOPE_BASE || scope == LDB_SCOPE_ONELEVEL)) + (scope == LDB_SCOPE_BASE || scope == LDB_SCOPE_ONELEVEL)) { + ret = LDB_ERR_UNWILLING_TO_PERFORM; goto failed; + } /* Convert filter into a series of SQL conditions (constraints) */ sqlfilter = parsetree_to_sql(module, local_ctx, tree); @@ -940,7 +946,7 @@ static int lsqlite3_search_bytree(struct ldb_module * module, const struct ldb_d } if (query == NULL) { - ret = -1; + ret = LDB_ERR_OTHER; goto failed; } @@ -957,15 +963,19 @@ static int lsqlite3_search_bytree(struct ldb_module * module, const struct ldb_d ret = sqlite3_exec(lsqlite3->sqlite, query, lsqlite3_search_callback, &msgs, &errmsg); if (ret != SQLITE_OK) { if (errmsg) { - printf("lsqlite3_search_bytree: Fatal Error: %s\n", errmsg); + ldb_set_errstring(module, talloc_strdup(module, errmsg)); free(errmsg); } + ret = LDB_ERR_OTHER; goto failed; } for (i = 0; i < msgs.count; i++) { msgs.msgs[i] = ldb_msg_canonicalize(module->ldb, msgs.msgs[i]); - if (msgs.msgs[i] == NULL) goto failed; + if (msgs.msgs[i] == NULL) { + ret = LDB_ERR_OTHER; + goto failed; + } } *res = talloc_steal(module, msgs.msgs); @@ -1033,7 +1043,7 @@ static int lsqlite3_add(struct ldb_module *module, const struct ldb_message *msg /* create a local ctx */ local_ctx = talloc_named(lsqlite3, 0, "lsqlite3_add local context"); if (local_ctx == NULL) { - return -1; + return LDB_ERR_OTHER; } /* See if this is an ltdb special */ @@ -1043,6 +1053,7 @@ static int lsqlite3_add(struct ldb_module *module, const struct ldb_message *msg c = ldb_dn_explode(local_ctx, "@SUBCLASSES"); if (ldb_dn_compare(module->ldb, msg->dn, c) == 0) { #warning "insert subclasses into object class tree" + ret = LDB_ERR_UNWILLING_TO_PERFORM; goto failed; } @@ -1054,13 +1065,16 @@ static int lsqlite3_add(struct ldb_module *module, const struct ldb_message *msg } */ /* Others are implicitly ignored */ - return 0; + return LDB_ERR_SUCCESS; } /* create linearized and normalized dns */ dn = ldb_dn_linearize(local_ctx, msg->dn); ndn = ldb_dn_linearize(local_ctx, ldb_dn_casefold(module->ldb, msg->dn)); - if (dn == NULL || ndn == NULL) goto failed; + if (dn == NULL || ndn == NULL) { + ret = LDB_ERR_OTHER; + goto failed; + } query = lsqlite3_tprintf(local_ctx, /* Add new entry */ @@ -1068,19 +1082,26 @@ static int lsqlite3_add(struct ldb_module *module, const struct ldb_message *msg "('dn', 'norm_dn') " "VALUES ('%q', '%q');", dn, ndn); - if (query == NULL) goto failed; + if (query == NULL) { + ret = LDB_ERR_OTHER; + goto failed; + } ret = sqlite3_exec(lsqlite3->sqlite, query, NULL, NULL, &errmsg); if (ret != SQLITE_OK) { if (errmsg) { - printf("lsqlite3_add: exec error: %s\n", errmsg); + ldb_set_errstring(module, talloc_strdup(module, errmsg)); free(errmsg); } + ret = LDB_ERR_OTHER; goto failed; } eid = lsqlite3_get_eid_ndn(lsqlite3->sqlite, local_ctx, ndn); - if (eid == -1) goto failed; + if (eid == -1) { + ret = LDB_ERR_OTHER; + goto failed; + } for (i = 0; i < msg->num_elements; i++) { const struct ldb_message_element *el = &msg->elements[i]; @@ -1090,7 +1111,10 @@ static int lsqlite3_add(struct ldb_module *module, const struct ldb_message *msg /* Get a case-folded copy of the attribute name */ attr = ldb_casefold(local_ctx, el->name); - if (attr == NULL) goto failed; + if (attr == NULL) { + ret = LDB_ERR_OTHER; + goto failed; + } h = ldb_attrib_handler(module->ldb, el->name); @@ -1101,7 +1125,10 @@ static int lsqlite3_add(struct ldb_module *module, const struct ldb_message *msg /* Get a canonicalised copy of the data */ h->canonicalise_fn(module->ldb, local_ctx, &(el->values[j]), &value); - if (value.data == NULL) goto failed; + if (value.data == NULL) { + ret = LDB_ERR_OTHER; + goto failed; + } insert = lsqlite3_tprintf(local_ctx, "INSERT OR ROLLBACK INTO ldb_attribute_values " @@ -1110,25 +1137,29 @@ static int lsqlite3_add(struct ldb_module *module, const struct ldb_message *msg "VALUES ('%lld', '%q', '%q', '%q', '%q');", eid, el->name, attr, el->values[j].data, value.data); - if (insert == NULL) goto failed; + if (insert == NULL) { + ret = LDB_ERR_OTHER; + goto failed; + } ret = sqlite3_exec(lsqlite3->sqlite, insert, NULL, NULL, &errmsg); if (ret != SQLITE_OK) { if (errmsg) { - printf("lsqlite3_add: insert error: %s\n", errmsg); + ldb_set_errstring(module, talloc_strdup(module, errmsg)); free(errmsg); } + ret = LDB_ERR_OTHER; goto failed; } } } talloc_free(local_ctx); - return 0; + return LDB_ERR_SUCCESS; failed: talloc_free(local_ctx); - return -1; + return ret; } @@ -1145,7 +1176,7 @@ static int lsqlite3_modify(struct ldb_module *module, const struct ldb_message * /* create a local ctx */ local_ctx = talloc_named(lsqlite3, 0, "lsqlite3_modify local context"); if (local_ctx == NULL) { - return -1; + return LDB_ERR_OTHER; } /* See if this is an ltdb special */ @@ -1155,21 +1186,17 @@ static int lsqlite3_modify(struct ldb_module *module, const struct ldb_message * c = ldb_dn_explode(local_ctx, "@SUBCLASSES"); if (ldb_dn_compare(module->ldb, msg->dn, c) == 0) { #warning "modify subclasses into object class tree" - goto failed; - } - - c = ldb_dn_explode(local_ctx, "@INDEXLIST"); - if (ldb_dn_compare(module->ldb, msg->dn, c) == 0) { -#warning "should we handle indexes somehow ?" + ret = LDB_ERR_UNWILLING_TO_PERFORM; goto failed; } /* Others are implicitly ignored */ - return 0; + return LDB_ERR_SUCCESS; } eid = lsqlite3_get_eid(module, msg->dn); if (eid == -1) { + ret = LDB_ERR_OTHER; goto failed; } @@ -1184,6 +1211,7 @@ static int lsqlite3_modify(struct ldb_module *module, const struct ldb_message * /* Get a case-folded copy of the attribute name */ attr = ldb_casefold(local_ctx, el->name); if (attr == NULL) { + ret = LDB_ERR_OTHER; goto failed; } @@ -1199,14 +1227,18 @@ static int lsqlite3_modify(struct ldb_module *module, const struct ldb_message * "WHERE eid = '%lld' " "AND norm_attr_name = '%q';", eid, attr); - if (mod == NULL) goto failed; + if (mod == NULL) { + ret = LDB_ERR_OTHER; + goto failed; + } ret = sqlite3_exec(lsqlite3->sqlite, mod, NULL, NULL, &errmsg); if (ret != SQLITE_OK) { if (errmsg) { - printf("lsqlite3_modify: error: %s\n", errmsg); + ldb_set_errstring(module, talloc_strdup(module, errmsg)); free(errmsg); } + ret = LDB_ERR_OTHER; goto failed; } @@ -1221,6 +1253,7 @@ static int lsqlite3_modify(struct ldb_module *module, const struct ldb_message * /* Get a canonicalised copy of the data */ h->canonicalise_fn(module->ldb, local_ctx, &(el->values[j]), &value); if (value.data == NULL) { + ret = LDB_ERR_OTHER; goto failed; } @@ -1232,14 +1265,18 @@ static int lsqlite3_modify(struct ldb_module *module, const struct ldb_message * eid, el->name, attr, el->values[j].data, value.data); - if (mod == NULL) goto failed; + if (mod == NULL) { + ret = LDB_ERR_OTHER; + goto failed; + } ret = sqlite3_exec(lsqlite3->sqlite, mod, NULL, NULL, &errmsg); if (ret != SQLITE_OK) { if (errmsg) { - printf("lsqlite3_modify: error: %s\n", errmsg); + ldb_set_errstring(module, talloc_strdup(module, errmsg)); free(errmsg); } + ret = LDB_ERR_OTHER; goto failed; } } @@ -1254,14 +1291,18 @@ static int lsqlite3_modify(struct ldb_module *module, const struct ldb_message * "WHERE eid = '%lld' " "AND norm_attr_name = '%q';", eid, attr); - if (mod == NULL) goto failed; + if (mod == NULL) { + ret = LDB_ERR_OTHER; + goto failed; + } ret = sqlite3_exec(lsqlite3->sqlite, mod, NULL, NULL, &errmsg); if (ret != SQLITE_OK) { if (errmsg) { - printf("lsqlite3_modify: error: %s\n", errmsg); + ldb_set_errstring(module, talloc_strdup(module, errmsg)); free(errmsg); } + ret = LDB_ERR_OTHER; goto failed; } } @@ -1273,6 +1314,7 @@ static int lsqlite3_modify(struct ldb_module *module, const struct ldb_message * /* Get a canonicalised copy of the data */ h->canonicalise_fn(module->ldb, local_ctx, &(el->values[j]), &value); if (value.data == NULL) { + ret = LDB_ERR_OTHER; goto failed; } @@ -1283,14 +1325,18 @@ static int lsqlite3_modify(struct ldb_module *module, const struct ldb_message * "AND norm_attr_value = '%q';", eid, attr, value.data); - if (mod == NULL) goto failed; + if (mod == NULL) { + ret = LDB_ERR_OTHER; + goto failed; + } ret = sqlite3_exec(lsqlite3->sqlite, mod, NULL, NULL, &errmsg); if (ret != SQLITE_OK) { if (errmsg) { - printf("lsqlite3_modify: error: %s\n", errmsg); + ldb_set_errstring(module, talloc_strdup(module, errmsg)); free(errmsg); } + ret = LDB_ERR_OTHER; goto failed; } } @@ -1300,11 +1346,11 @@ static int lsqlite3_modify(struct ldb_module *module, const struct ldb_message * } talloc_free(local_ctx); - return 0; + return LDB_ERR_SUCCESS; failed: talloc_free(local_ctx); - return -1; + return ret; } /* delete a record */ @@ -1319,17 +1365,20 @@ static int lsqlite3_delete(struct ldb_module *module, const struct ldb_dn *dn) /* ignore ltdb specials */ if (ldb_dn_is_special(dn)) { - return 0; + return LDB_ERR_SUCCESS; } /* create a local ctx */ local_ctx = talloc_named(lsqlite3, 0, "lsqlite3_delete local context"); if (local_ctx == NULL) { - return -1; + return LDB_ERR_OTHER; } eid = lsqlite3_get_eid(module, dn); - if (eid == -1) goto failed; + if (eid == -1) { + ret = LDB_ERR_OTHER; + goto failed; + } query = lsqlite3_tprintf(local_ctx, /* Delete entry */ @@ -1337,23 +1386,27 @@ static int lsqlite3_delete(struct ldb_module *module, const struct ldb_dn *dn) /* Delete attributes */ "DELETE FROM ldb_attribute_values WHERE eid = %lld; ", eid, eid); - if (query == NULL) goto failed; + if (query == NULL) { + ret = LDB_ERR_OTHER; + goto failed; + } ret = sqlite3_exec(lsqlite3->sqlite, query, NULL, NULL, &errmsg); if (ret != SQLITE_OK) { if (errmsg) { - printf("lsqlite3_delete: error getting eid: %s\n", errmsg); + ldb_set_errstring(module, talloc_strdup(module, errmsg)); free(errmsg); } + ret = LDB_ERR_OTHER; goto failed; } talloc_free(local_ctx); - return 0; + return LDB_ERR_SUCCESS; failed: talloc_free(local_ctx); - return -1; + return ret; } /* rename a record */ @@ -1368,45 +1421,52 @@ static int lsqlite3_rename(struct ldb_module *module, const struct ldb_dn *olddn /* ignore ltdb specials */ if (ldb_dn_is_special(olddn) || ldb_dn_is_special(newdn)) { - return 0; + return LDB_ERR_SUCCESS; } /* create a local ctx */ local_ctx = talloc_named(lsqlite3, 0, "lsqlite3_rename local context"); if (local_ctx == NULL) { - return -1; + return LDB_ERR_OTHER; } /* create linearized and normalized dns */ old_cdn = ldb_dn_linearize(local_ctx, ldb_dn_casefold(module->ldb, olddn)); new_cdn = ldb_dn_linearize(local_ctx, ldb_dn_casefold(module->ldb, newdn)); new_dn = ldb_dn_linearize(local_ctx, newdn); - if (old_cdn == NULL || new_cdn == NULL || new_dn == NULL) goto failed; + if (old_cdn == NULL || new_cdn == NULL || new_dn == NULL) { + ret = LDB_ERR_OTHER; + goto failed; + } /* build the SQL query */ query = lsqlite3_tprintf(local_ctx, "UPDATE ldb_entry SET dn = '%q', norm_dn = '%q' " "WHERE norm_dn = '%q';", new_dn, new_cdn, old_cdn); - if (query == NULL) goto failed; + if (query == NULL) { + ret = LDB_ERR_OTHER; + goto failed; + } /* execute */ ret = sqlite3_exec(lsqlite3->sqlite, query, NULL, NULL, &errmsg); if (ret != SQLITE_OK) { if (errmsg) { - printf("lsqlite3_rename: sqlite3_exec error: %s\n", errmsg); + ldb_set_errstring(module, talloc_strdup(module, errmsg)); free(errmsg); } + ret = LDB_ERR_OTHER; goto failed; } /* clean up and exit */ talloc_free(local_ctx); - return 0; + return LDB_ERR_SUCCESS; failed: talloc_free(local_ctx); - return -1; + return ret; } static int lsqlite3_start_trans(struct ldb_module * module) @@ -1415,14 +1475,18 @@ static int lsqlite3_start_trans(struct ldb_module * module) char *errmsg; struct lsqlite3_private * lsqlite3 = module->private_data; - ret = sqlite3_exec(lsqlite3->sqlite, "BEGIN IMMEDIATE;", NULL, NULL, &errmsg); - if (ret != SQLITE_OK) { - if (errmsg) { - printf("lsqlite3_start_trans: error: %s\n", errmsg); - free(errmsg); + if (lsqlite3->trans_count == 0) { + ret = sqlite3_exec(lsqlite3->sqlite, "BEGIN IMMEDIATE;", NULL, NULL, &errmsg); + if (ret != SQLITE_OK) { + if (errmsg) { + printf("lsqlite3_start_trans: error: %s\n", errmsg); + free(errmsg); + } + return -1; } - return -1; - } + }; + + lsqlite3->trans_count++; return 0; } @@ -1433,36 +1497,26 @@ static int lsqlite3_end_trans(struct ldb_module *module, int status) char *errmsg; struct lsqlite3_private *lsqlite3 = module->private_data; - if (status == 0) { - ret = sqlite3_exec(lsqlite3->sqlite, "COMMIT;", NULL, NULL, &errmsg); - if (ret != SQLITE_OK) { - if (errmsg) { - printf("lsqlite3_end_trans: error: %s\n", errmsg); - free(errmsg); + lsqlite3->trans_count--; + + if (lsqlite3->trans_count == 0) { + if (status == 0) { + ret = sqlite3_exec(lsqlite3->sqlite, "COMMIT;", NULL, NULL, &errmsg); + if (ret != SQLITE_OK) { + if (errmsg) { + printf("lsqlite3_end_trans: error: %s\n", errmsg); + free(errmsg); + } + return -1; } - return -1; + } else { + return lsqlite3_safe_rollback(lsqlite3->sqlite); } - } else { - return lsqlite3_safe_rollback(lsqlite3->sqlite); } return 0; } - - -/* return extended error information */ -static const char * -lsqlite3_errstring(struct ldb_module *module) -{ - struct lsqlite3_private * lsqlite3 = module->private_data; - - return sqlite3_errmsg(lsqlite3->sqlite); -} - - - - /* * Static functions */ @@ -1758,8 +1812,7 @@ static const struct ldb_module_ops lsqlite3_ops = { .delete_record = lsqlite3_delete, .rename_record = lsqlite3_rename, .start_transaction = lsqlite3_start_trans, - .end_transaction = lsqlite3_end_trans, - .errstring = lsqlite3_errstring + .end_transaction = lsqlite3_end_trans }; /* @@ -1781,6 +1834,7 @@ int lsqlite3_connect(struct ldb_context *ldb, lsqlite3->sqlite = NULL; lsqlite3->options = NULL; + lsqlite3->trans_count = 0; ret = initialize(lsqlite3, ldb, url); if (ret != SQLITE_OK) { diff --git a/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.h b/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.h index 46c949a564..d14a1aa0e0 100644 --- a/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.h +++ b/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.h @@ -1,6 +1,7 @@ #include <sqlite3.h> struct lsqlite3_private { + int trans_count; char **options; sqlite3 *sqlite; }; diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index ca0ae06354..fc864ac2ea 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -34,6 +34,7 @@ #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" @@ -249,7 +250,6 @@ static int ltdb_search_dn(struct ldb_module *module, const struct ldb_dn *dn, const char * const attrs[], struct ldb_message ***res) { struct ldb_context *ldb = module->ldb; - struct ltdb_private *ltdb = module->private_data; int ret; struct ldb_message *msg, *msg2; @@ -259,8 +259,6 @@ static int ltdb_search_dn(struct ldb_module *module, const struct ldb_dn *dn, return -1; } - ltdb->last_err_string = NULL; - if (ltdb_cache_load(module) != 0) { ltdb_unlock_read(module); return -1; @@ -462,7 +460,6 @@ 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) { - struct ltdb_private *ltdb = module->private_data; int ret; if ((base == NULL || base->comp_num == 0) && @@ -476,7 +473,7 @@ int ltdb_search_bytree(struct ldb_module *module, const struct ldb_dn *base, struct ldb_dn *dn; dn = ldb_dn_explode(module->ldb, tree->u.equality.value.data); if (dn == NULL) { - return -1; + return LDB_ERR_INVALID_DN_SYNTAX; } ret = ltdb_search_dn(module, dn, attrs, res); talloc_free(dn); @@ -487,8 +484,6 @@ int ltdb_search_bytree(struct ldb_module *module, const struct ldb_dn *base, return -1; } - ltdb->last_err_string = NULL; - if (ltdb_cache_load(module) != 0) { ltdb_unlock_read(module); return -1; @@ -530,7 +525,8 @@ int ltdb_search(struct ldb_module *module, const struct ldb_dn *base, tree = ldb_parse_tree(ltdb, expression); if (tree == NULL) { - ltdb->last_err_string = "expression parse failed"; + char *err_string = talloc_strdup(module, "expression parse failed"); + if (err_string) ldb_set_errstring(module, err_string); return -1; } diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index c3f59a2dbe..265e04a057 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -37,6 +37,7 @@ #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" @@ -235,7 +236,6 @@ int ltdb_unlock_read(struct ldb_module *module) */ int ltdb_check_special_dn(struct ldb_module *module, const struct ldb_message *msg) { - struct ltdb_private *ltdb = module->private_data; int i, j; if (! ldb_dn_is_special(msg->dn) || @@ -248,8 +248,11 @@ int ltdb_check_special_dn(struct ldb_module *module, const struct ldb_message *m for (i = 0; i < msg->num_elements; i++) { for (j = 0; j < msg->elements[i].num_values; j++) { if (ltdb_check_at_attributes_values(&msg->elements[i].values[j]) != 0) { - ltdb->last_err_string = "Invalid attribute value in an @ATTRIBUTES entry"; - return -1; + char *err_string = talloc_strdup(module, "Invalid attribute value in an @ATTRIBUTES entry"); + if (err_string) { + ldb_set_errstring(module, err_string); + } + return LDB_ERR_INVALID_ATTRIBUTE_SYNTAX; } } } @@ -292,17 +295,18 @@ int ltdb_store(struct ldb_module *module, const struct ldb_message *msg, int flg tdb_key = ltdb_key(module, msg->dn); if (!tdb_key.dptr) { - return -1; + return LDB_ERR_OTHER; } ret = ltdb_pack_data(module, msg, &tdb_data); if (ret == -1) { talloc_free(tdb_key.dptr); - return -1; + return LDB_ERR_OTHER; } ret = tdb_store(ltdb->tdb, tdb_key, tdb_data, flgs); if (ret == -1) { + ret = LDB_ERR_OTHER; goto done; } @@ -324,28 +328,25 @@ done: */ static int ltdb_add(struct ldb_module *module, const struct ldb_message *msg) { - struct ltdb_private *ltdb = module->private_data; int ret; - ltdb->last_err_string = NULL; - ret = ltdb_check_special_dn(module, msg); - if (ret != 0) { + if (ret != LDB_ERR_SUCCESS) { return ret; } if (ltdb_lock(module, LDBLOCK) != 0) { - return -1; + return LDB_ERR_OTHER; } if (ltdb_cache_load(module) != 0) { ltdb_unlock(module, LDBLOCK); - return -1; + return LDB_ERR_OTHER; } ret = ltdb_store(module, msg, TDB_INSERT); - if (ret == 0) { + if (ret == LDB_ERR_SUCCESS) { ltdb_modified(module, msg->dn); } @@ -366,12 +367,14 @@ int ltdb_delete_noindex(struct ldb_module *module, const struct ldb_dn *dn) tdb_key = ltdb_key(module, dn); if (!tdb_key.dptr) { - return -1; + return LDB_ERR_OTHER; } ret = tdb_delete(ltdb->tdb, tdb_key); talloc_free(tdb_key.dptr); + if (ret != 0) ret = LDB_ERR_OTHER; + return ret; } @@ -380,14 +383,11 @@ int ltdb_delete_noindex(struct ldb_module *module, const struct ldb_dn *dn) */ static int ltdb_delete(struct ldb_module *module, const struct ldb_dn *dn) { - struct ltdb_private *ltdb = module->private_data; - int ret; struct ldb_message *msg = NULL; - - ltdb->last_err_string = NULL; + int ret = LDB_ERR_OTHER; if (ltdb_lock(module, LDBLOCK) != 0) { - return -1; + return ret; } if (ltdb_cache_load(module) != 0) { @@ -404,20 +404,21 @@ static int ltdb_delete(struct ldb_module *module, const struct ldb_dn *dn) ret = ltdb_search_dn1(module, dn, msg); if (ret != 1) { /* not finding the old record is an error */ + ret = LDB_ERR_NO_SUCH_OBJECT; goto failed; } ret = ltdb_delete_noindex(module, dn); - if (ret == -1) { + if (ret != LDB_ERR_SUCCESS) { goto failed; } /* remove any indexed attributes */ ret = ltdb_index_del(module, msg); - - if (ret == 0) { + if (ret == LDB_ERR_SUCCESS) { ltdb_modified(module, dn); - } + } else + ret = LDB_ERR_OTHER; talloc_free(msg); ltdb_unlock(module, LDBLOCK); @@ -426,7 +427,7 @@ static int ltdb_delete(struct ldb_module *module, const struct ldb_dn *dn) failed: talloc_free(msg); ltdb_unlock(module, LDBLOCK); - return -1; + return ret; } @@ -593,26 +594,26 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms tdb_key = ltdb_key(module, msg->dn); if (!tdb_key.dptr) { - return -1; + return LDB_ERR_OTHER; } tdb_data = tdb_fetch(ltdb->tdb, tdb_key); if (!tdb_data.dptr) { talloc_free(tdb_key.dptr); - return -1; + return LDB_ERR_OTHER; } msg2 = talloc(tdb_key.dptr, struct ldb_message); if (msg2 == NULL) { talloc_free(tdb_key.dptr); - return -1; + return LDB_ERR_OTHER; } ret = ltdb_unpack_data(module, &tdb_data, msg2); if (ret == -1) { talloc_free(tdb_key.dptr); free(tdb_data.dptr); - return -1; + return LDB_ERR_OTHER; } if (!msg2->dn) { @@ -623,6 +624,7 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms struct ldb_message_element *el = &msg->elements[i]; struct ldb_message_element *el2; struct ldb_val *vals; + char *err_string; char *dn; switch (msg->elements[i].flags & LDB_FLAG_MOD_MASK) { @@ -634,6 +636,7 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms if (ret == -1) { if (msg_add_element(ldb, msg2, el) != 0) { + ret = LDB_ERR_OTHER; goto failed; } continue; @@ -646,8 +649,9 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms for (j=0;j<el->num_values;j++) { if (ldb_msg_find_val(el2, &el->values[j])) { - ltdb->last_err_string = - "Type or value exists"; + err_string = talloc_strdup(module, "Type or value exists"); + if (err_string) ldb_set_errstring(module, err_string); + ret = LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS; goto failed; } } @@ -690,7 +694,9 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms if (msg->elements[i].num_values == 0) { if (msg_delete_attribute(module, ldb, msg2, msg->elements[i].name) != 0) { - ltdb->last_err_string = "No such attribute"; + err_string = talloc_strdup(module, "No such attribute"); + if (err_string) ldb_set_errstring(module, err_string); + ret = LDB_ERR_NO_SUCH_ATTRIBUTE; goto failed; } break; @@ -700,7 +706,9 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms msg2, msg->elements[i].name, &msg->elements[i].values[j]) != 0) { - ltdb->last_err_string = "No such attribute"; + err_string = talloc_strdup(module, "No such attribute"); + if (err_string) ldb_set_errstring(module, err_string); + ret = LDB_ERR_NO_SUCH_ATTRIBUTE; goto failed; } if (ltdb_index_del_value(module, dn, &msg->elements[i], j) != 0) { @@ -709,7 +717,9 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms } break; default: - ltdb->last_err_string = "Invalid ldb_modify flags"; + err_string = talloc_strdup(module, "Invalid ldb_modify flags"); + if (err_string) ldb_set_errstring(module, err_string); + ret = LDB_ERR_PROTOCOL_ERROR; goto failed; } } @@ -724,7 +734,7 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms failed: talloc_free(tdb_key.dptr); free(tdb_data.dptr); - return -1; + return ret; } /* @@ -732,11 +742,8 @@ failed: */ static int ltdb_modify(struct ldb_module *module, const struct ldb_message *msg) { - struct ltdb_private *ltdb = module->private_data; int ret; - ltdb->last_err_string = NULL; - ret = ltdb_check_special_dn(module, msg); if (ret != 0) { return ret; @@ -753,7 +760,7 @@ static int ltdb_modify(struct ldb_module *module, const struct ldb_message *msg) ret = ltdb_modify_internal(module, msg); - if (ret == 0) { + if (ret == LDB_ERR_SUCCESS) { ltdb_modified(module, msg->dn); } @@ -767,20 +774,17 @@ static int ltdb_modify(struct ldb_module *module, const struct ldb_message *msg) */ static int ltdb_rename(struct ldb_module *module, const struct ldb_dn *olddn, const struct ldb_dn *newdn) { - struct ltdb_private *ltdb = module->private_data; - int ret; struct ldb_message *msg; - const char *error_str; - - ltdb->last_err_string = NULL; + char *error_str; + int ret = LDB_ERR_OTHER; if (ltdb_lock(module, LDBLOCK) != 0) { - return -1; + return ret; } if (ltdb_cache_load(module) != 0) { ltdb_unlock(module, LDBLOCK); - return -1; + return ret; } msg = talloc(module, struct ldb_message); @@ -793,26 +797,28 @@ static int ltdb_rename(struct ldb_module *module, const struct ldb_dn *olddn, co ret = ltdb_search_dn1(module, olddn, msg); if (ret != 1) { /* not finding the old record is an error */ + ret = LDB_ERR_NO_SUCH_OBJECT; goto failed; } msg->dn = ldb_dn_copy(msg, newdn); if (!msg->dn) { + ret = LDB_ERR_OTHER; goto failed; } ret = ltdb_add(module, msg); - if (ret == -1) { + if (ret != LDB_ERR_SUCCESS) { goto failed; } ret = ltdb_delete(module, olddn); - error_str = ltdb->last_err_string; - if (ret == -1) { + error_str = talloc_strdup(module, ldb_errstring(module->ldb)); + if (ret != LDB_ERR_SUCCESS) { ltdb_delete(module, newdn); } - ltdb->last_err_string = error_str; + ldb_set_errstring(module, error_str); talloc_free(msg); ltdb_unlock(module, LDBLOCK); @@ -822,14 +828,14 @@ static int ltdb_rename(struct ldb_module *module, const struct ldb_dn *olddn, co failed: talloc_free(msg); ltdb_unlock(module, LDBLOCK); - return -1; + return ret; } static int ltdb_start_trans(struct ldb_module *module) { /* TODO: implement transactions */ - return 0; + return LDB_ERR_SUCCESS; } static int ltdb_end_trans(struct ldb_module *module, int status) @@ -839,19 +845,6 @@ static int ltdb_end_trans(struct ldb_module *module, int status) return status; } -/* - return extended error information -*/ -static const char *ltdb_errstring(struct ldb_module *module) -{ - struct ltdb_private *ltdb = module->private_data; - if (ltdb->last_err_string) { - return ltdb->last_err_string; - } - return tdb_errorstr(ltdb->tdb); -} - - static const struct ldb_module_ops ltdb_ops = { .name = "tdb", .search = ltdb_search, @@ -861,8 +854,7 @@ static const struct ldb_module_ops ltdb_ops = { .delete_record = ltdb_delete, .rename_record = ltdb_rename, .start_transaction = ltdb_start_trans, - .end_transaction = ltdb_end_trans, - .errstring = ltdb_errstring + .end_transaction = ltdb_end_trans }; diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.h b/source4/lib/ldb/ldb_tdb/ldb_tdb.h index f08601832c..f1da556f99 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.h +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.h @@ -27,9 +27,6 @@ struct ltdb_private { int flags; } last_attribute; } *cache; - - /* error if an internal ldb+tdb error */ - const char *last_err_string; }; /* special record types */ diff --git a/source4/lib/ldb/modules/ldb_map.c b/source4/lib/ldb/modules/ldb_map.c index 93ae13ffc2..69e021b4ee 100644 --- a/source4/lib/ldb/modules/ldb_map.c +++ b/source4/lib/ldb/modules/ldb_map.c @@ -97,7 +97,6 @@ static const struct ldb_map_objectclass *map_find_objectclass_remote(struct ldb_ struct map_private { struct ldb_map_context context; - const char *last_err_string; }; static struct ldb_map_context *map_get_privdat(struct ldb_module *module) @@ -807,8 +806,7 @@ static int map_search_bytree_mp(struct ldb_module *module, const struct ldb_dn * talloc_free(newattrs); if (mpret == -1) { - struct map_private *map_private = module->private_data; - map_private->last_err_string = ldb_errstring(privdat->mapped_ldb); + ldb_set_errstring(module, talloc_strdup(module, ldb_errstring(privdat->mapped_ldb))); return -1; } @@ -910,13 +908,12 @@ static int map_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 map_private *map = module->private_data; struct ldb_parse_tree *tree; int ret; tree = ldb_parse_tree(NULL, expression); if (tree == NULL) { - map->last_err_string = "expression parse failed"; + ldb_set_errstring(module, talloc_strdup(module, "expression parse failed")); return -1; } @@ -1121,7 +1118,7 @@ static int map_add(struct ldb_module *module, const struct ldb_message *msg) ldb_msg_add_string(module->ldb, fb, "isMapped", "TRUE"); ret = ldb_next_add_record(module, fb); if (ret == -1) { - ldb_debug(module->ldb, LDB_DEBUG_WARNING, "Adding fallback record failed: %s", ldb_next_errstring(module)); + ldb_debug(module->ldb, LDB_DEBUG_WARNING, "Adding fallback record failed: %s", ldb_errstring(module->ldb)); return -1; } @@ -1266,19 +1263,6 @@ static int map_end_trans(struct ldb_module *module, int status) return ldb_next_end_trans(module, status); } -/* - return extended error information -*/ -static const char *map_errstring(struct ldb_module *module) -{ - struct map_private *map = module->private_data; - - if (map->last_err_string) - return map->last_err_string; - - return ldb_next_errstring(module); -} - static const struct ldb_module_ops map_ops = { .name = "map", .search = map_search, @@ -1288,8 +1272,7 @@ static const struct ldb_module_ops map_ops = { .delete_record = map_delete, .rename_record = map_rename, .start_transaction = map_start_trans, - .end_transaction = map_end_trans, - .errstring = map_errstring + .end_transaction = map_end_trans }; static char *map_find_url(struct ldb_context *ldb, const char *name) @@ -1354,8 +1337,6 @@ struct ldb_module *ldb_map_init(struct ldb_context *ldb, const struct ldb_map_at talloc_free(url); - data->last_err_string = NULL; - /* Get list of attribute maps */ j = 0; data->context.attribute_maps = NULL; diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c index ed5400176c..c1a0c0852a 100644 --- a/source4/lib/ldb/modules/rdn_name.c +++ b/source4/lib/ldb/modules/rdn_name.c @@ -37,10 +37,6 @@ #include "ldb/include/ldb_private.h" #include <time.h> -struct private_data { - const char *error_string; -}; - static int rdn_name_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) @@ -73,8 +69,6 @@ static struct ldb_message_element *rdn_name_find_attribute(const struct ldb_mess /* add_record: add crateTimestamp/modifyTimestamp attributes */ static int rdn_name_add_record(struct ldb_module *module, const struct ldb_message *msg) { - struct private_data *data = (struct private_data *)module->private_data; - struct ldb_message *msg2; struct ldb_message_element *attribute; struct ldb_dn_component *rdn; @@ -134,8 +128,11 @@ static int rdn_name_add_record(struct ldb_module *module, const struct ldb_messa } } if (i == attribute->num_values) { - data->error_string = talloc_asprintf(data, "RDN mismatch on %s: %s", ldb_dn_linearize(msg2, msg2->dn), rdn->name); - ldb_debug(module->ldb, LDB_DEBUG_FATAL, "%s\n", data->error_string); + char *error_string = talloc_asprintf(module, "RDN mismatch on %s: %s", ldb_dn_linearize(msg2, msg2->dn), rdn->name); + if (error_string) { + ldb_set_errstring(module, error_string); + ldb_debug(module->ldb, LDB_DEBUG_FATAL, "%s\n", error_string); + } talloc_free(msg2); return -1; } @@ -229,23 +226,6 @@ static int rdn_end_trans(struct ldb_module *module, int status) return ldb_next_end_trans(module, status); } -/* return extended error information */ -static const char *rdn_name_errstring(struct ldb_module *module) -{ - struct private_data *data = (struct private_data *)module->private_data; - - ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_name_errstring\n"); - if (data->error_string) { - const char *error; - - error = data->error_string; - data->error_string = NULL; - return error; - } - - return ldb_next_errstring(module); -} - static int rdn_name_destructor(void *module_ctx) { /* struct ldb_module *ctx = module_ctx; */ @@ -262,8 +242,7 @@ static const struct ldb_module_ops rdn_name_ops = { .delete_record = rdn_name_delete_record, .rename_record = rdn_name_rename_record, .start_transaction = rdn_start_trans, - .end_transaction = rdn_end_trans, - .errstring = rdn_name_errstring + .end_transaction = rdn_end_trans }; @@ -275,20 +254,12 @@ struct ldb_module *rdn_name_module_init(struct ldb_context *ldb, const char *opt #endif { struct ldb_module *ctx; - struct private_data *data; ctx = talloc(ldb, struct ldb_module); if (!ctx) return NULL; - data = talloc(ctx, struct private_data); - if (!data) { - talloc_free(ctx); - return NULL; - } - - data->error_string = NULL; - ctx->private_data = data; + ctx->private_data = NULL; ctx->ldb = ldb; ctx->prev = ctx->next = NULL; ctx->ops = &rdn_name_ops; diff --git a/source4/lib/ldb/modules/schema.c b/source4/lib/ldb/modules/schema.c index 9406d54ce7..1a2c2b8f97 100644 --- a/source4/lib/ldb/modules/schema.c +++ b/source4/lib/ldb/modules/schema.c @@ -34,6 +34,7 @@ #include "includes.h" #include "ldb/include/ldb.h" +#include "ldb/include/ldb_errors.h" #include "ldb/include/ldb_private.h" #define SCHEMA_FLAG_RESET 0 @@ -51,10 +52,6 @@ check there's only one structrual class (or a chain of structural classes) */ -struct private_data { - const char *error_string; -}; - struct schema_attribute { int flags; char *name; @@ -189,8 +186,8 @@ static int add_attribute_uniq(void *mem_ctx, struct schema_attribute_list *list, recursively get parent objectlasses attributes */ static int get_attr_list_recursive(struct ldb_module *module, struct schema_structures *schema_struct) { - struct private_data *data = (struct private_data *)module->private_data; struct ldb_message **srch; + char *error_string; int i, j; int ret; @@ -213,14 +210,20 @@ static int get_attr_list_recursive(struct ldb_module *module, struct schema_stru if (ret <= 0) { /* Schema DB Error: Error occurred retrieving Object Class Description */ - ldb_debug(module->ldb, LDB_DEBUG_ERROR, "Error retrieving Objectclass %s.\n", schema_struct->objectclasses.attr[i].name); - data->error_string = "Internal error. Error retrieving schema objectclass"; + error_string = talloc_asprintf(module, "Error retrieving Objectclass %s.\n", schema_struct->objectclasses.attr[i].name); + if (error_string) { + ldb_set_errstring(module, error_string); + ldb_debug(module->ldb, LDB_DEBUG_ERROR, error_string); + } return -1; } if (ret > 1) { /* Schema DB Error: Too Many Records */ - ldb_debug(module->ldb, LDB_DEBUG_ERROR, "Too many records found retrieving Objectclass %s.\n", schema_struct->objectclasses.attr[i].name); - data->error_string = "Internal error. Too many records searching for schema objectclass"; + error_string = talloc_asprintf(module, "Too many records found retrieving Objectclass %s.\n", schema_struct->objectclasses.attr[i].name); + if (error_string) { + ldb_set_errstring(module, error_string); + ldb_debug(module->ldb, LDB_DEBUG_ERROR, error_string); + } return -1; } @@ -297,8 +300,8 @@ static int schema_search_bytree(struct ldb_module *module, const struct ldb_dn * /* add_record */ static int schema_add_record(struct ldb_module *module, const struct ldb_message *msg) { - struct private_data *data = (struct private_data *)module->private_data; struct schema_structures *entry_structs; + char *error_string; unsigned int i; int ret; @@ -342,13 +345,15 @@ static int schema_add_record(struct ldb_module *module, const struct ldb_message entry_structs->required_attrs.attr[i].name); if (attr == NULL) { /* not found */ - ldb_debug(module->ldb, LDB_DEBUG_ERROR, + error_string = talloc_asprintf(module, "The required_attrs attribute %s is missing.\n", entry_structs->required_attrs.attr[i].name); - - data->error_string = "Objectclass violation, a required attribute is missing"; + if (error_string) { + ldb_set_errstring(module, error_string); + ldb_debug(module->ldb, LDB_DEBUG_ERROR, error_string); + } talloc_free(entry_structs); - return -1; + return LDB_ERR_OBJECT_CLASS_VIOLATION; } /* mark the attribute as checked */ @@ -365,13 +370,15 @@ static int schema_add_record(struct ldb_module *module, const struct ldb_message entry_structs->entry_attrs.attr[i].name); if (attr == NULL) { /* not found */ - ldb_debug(module->ldb, LDB_DEBUG_ERROR, + error_string = talloc_asprintf(module, "The attribute %s is not referenced by any objectclass.\n", entry_structs->entry_attrs.attr[i].name); - - data->error_string = "Objectclass violation, an invalid attribute name was found"; + if (error_string) { + ldb_set_errstring(module, error_string); + ldb_debug(module->ldb, LDB_DEBUG_ERROR, error_string); + } talloc_free(entry_structs); - return -1; + return LDB_ERR_OBJECT_CLASS_VIOLATION; } } } @@ -384,8 +391,8 @@ static int schema_add_record(struct ldb_module *module, const struct ldb_message /* modify_record */ static int schema_modify_record(struct ldb_module *module, const struct ldb_message *msg) { - struct private_data *data = (struct private_data *)module->private_data; struct schema_structures *entry_structs; + char *error_string; unsigned int i; int ret; @@ -437,25 +444,30 @@ static int schema_modify_record(struct ldb_module *module, const struct ldb_mess entry_structs->required_attrs.attr[i].name); if (attr == NULL) { /* not found */ - ldb_debug(module->ldb, LDB_DEBUG_ERROR, + error_string = talloc_asprintf(module, "The required_attrs attribute %s is missing.\n", entry_structs->required_attrs.attr[i].name); - - data->error_string = "Objectclass violation, a required attribute is missing"; + if (error_string) { + ldb_set_errstring(module, error_string); + ldb_debug(module->ldb, LDB_DEBUG_ERROR, error_string); + } talloc_free(entry_structs); - return -1; + return LDB_ERR_OBJECT_CLASS_VIOLATION; } /* check we are not trying to delete a required attribute */ /* TODO: consider multivalued attrs */ if ((attr->flags & SCHEMA_FLAG_MOD_DELETE) != 0) { - ldb_debug(module->ldb, LDB_DEBUG_ERROR, + error_string = talloc_asprintf(module, "Trying to delete the required attribute %s.\n", attr->name); + if (error_string) { + ldb_set_errstring(module, error_string); + ldb_debug(module->ldb, LDB_DEBUG_ERROR, error_string); + } - data->error_string = "Objectclass violation, a required attribute cannot be removed"; talloc_free(entry_structs); - return -1; + return LDB_ERR_OBJECT_CLASS_VIOLATION; } /* mark the attribute as checked */ @@ -472,13 +484,16 @@ static int schema_modify_record(struct ldb_module *module, const struct ldb_mess entry_structs->entry_attrs.attr[i].name); if (attr == NULL) { /* not found */ - ldb_debug(module->ldb, LDB_DEBUG_ERROR, + error_string = talloc_asprintf(module, "The attribute %s is not referenced by any objectclass.\n", entry_structs->entry_attrs.attr[i].name); + if (error_string) { + ldb_set_errstring(module, error_string); + ldb_debug(module->ldb, LDB_DEBUG_ERROR, error_string); + } - data->error_string = "Objectclass violation, an invalid attribute name was found"; talloc_free(entry_structs); - return -1; + return LDB_ERR_OBJECT_CLASS_VIOLATION; } } } @@ -509,22 +524,6 @@ static int schema_end_trans(struct ldb_module *module, int status) { return ldb_next_end_trans(module, status); } -/* return extended error information */ -static const char *schema_errstring(struct ldb_module *module) -{ - struct private_data *data = (struct private_data *)module->private_data; - - if (data->error_string) { - const char *error; - - error = data->error_string; - data->error_string = NULL; - return error; - } - - return ldb_next_errstring(module); -} - static int schema_destructor(void *module_ctx) { /* struct ldb_module *ctx = module_ctx; */ @@ -541,8 +540,7 @@ static const struct ldb_module_ops schema_ops = { .delete_record = schema_delete_record, .rename_record = schema_rename_record, .start_transaction = schema_start_trans, - .end_transaction = schema_end_trans, - .errstring = schema_errstring, + .end_transaction = schema_end_trans }; #ifdef HAVE_DLOPEN_DISABLED @@ -552,21 +550,13 @@ struct ldb_module *schema_module_init(struct ldb_context *ldb, const char *optio #endif { struct ldb_module *ctx; - struct private_data *data; ctx = talloc(ldb, struct ldb_module); if (!ctx) { return NULL; } - data = talloc(ctx, struct private_data); - if (data == NULL) { - talloc_free(ctx); - return NULL; - } - - data->error_string = NULL; - ctx->private_data = data; + ctx->private_data = NULL; ctx->ldb = ldb; ctx->prev = ctx->next = NULL; ctx->ops = &schema_ops; diff --git a/source4/lib/ldb/modules/skel.c b/source4/lib/ldb/modules/skel.c index 37c0417c64..701128cd27 100644 --- a/source4/lib/ldb/modules/skel.c +++ b/source4/lib/ldb/modules/skel.c @@ -38,7 +38,7 @@ struct private_data { - char *errstring; + char *some_private_data; }; /* search */ @@ -85,18 +85,12 @@ static int skel_end_trans(struct ldb_module *module, int status) return ldb_next_end_trans(module, status); } -/* return extended error information */ -static const char *skel_errstring(struct ldb_module *module) -{ - return ldb_next_errstring(module); -} - static int skel_destructor(void *module_ctx) { struct ldb_module *ctx = talloc_get_type(module_ctx, struct ldb_module); struct private_data *data = talloc_get_type(ctx->private_data, struct private_data); /* put your clean-up functions here */ - if (data->errstring) talloc_free(data->errstring); + if (data->some_private_data) talloc_free(data->some_private_data); return 0; } @@ -110,7 +104,6 @@ static const struct ldb_module_ops skel_ops = { .rename_record = skel_rename_record, .start_transaction = skel_start_trans, .end_transaction = skel_end_trans, - .errstring = skel_errstring }; #ifdef HAVE_DLOPEN_DISABLED @@ -132,7 +125,7 @@ struct ldb_module *skel_module_init(struct ldb_context *ldb, const char *options return NULL; } - data->errstring = NULL; + data->some_private_data = NULL; ctx->private_data = data; ctx->ldb = ldb; diff --git a/source4/lib/ldb/modules/timestamps.c b/source4/lib/ldb/modules/timestamps.c index 6687b1929d..dc91937f85 100644 --- a/source4/lib/ldb/modules/timestamps.c +++ b/source4/lib/ldb/modules/timestamps.c @@ -37,10 +37,6 @@ #include "ldb/include/ldb_private.h" #include <time.h> -struct private_data { - const char *error_string; -}; - static int timestamps_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) @@ -227,23 +223,6 @@ static int timestamps_end_trans(struct ldb_module *module, int status) return ldb_next_end_trans(module, status); } -/* return extended error information */ -static const char *timestamps_errstring(struct ldb_module *module) -{ - struct private_data *data = (struct private_data *)module->private_data; - - ldb_debug(module->ldb, LDB_DEBUG_TRACE, "timestamps_errstring\n"); - if (data->error_string) { - const char *error; - - error = data->error_string; - data->error_string = NULL; - return error; - } - - return ldb_next_errstring(module); -} - static int timestamps_destructor(void *module_ctx) { /* struct ldb_module *ctx = module_ctx; */ @@ -260,8 +239,7 @@ static const struct ldb_module_ops timestamps_ops = { .delete_record = timestamps_delete_record, .rename_record = timestamps_rename_record, .start_transaction = timestamps_start_trans, - .end_transaction = timestamps_end_trans, - .errstring = timestamps_errstring + .end_transaction = timestamps_end_trans }; @@ -273,20 +251,12 @@ struct ldb_module *timestamps_module_init(struct ldb_context *ldb, const char *o #endif { struct ldb_module *ctx; - struct private_data *data; ctx = talloc(ldb, struct ldb_module); if (!ctx) return NULL; - data = talloc(ctx, struct private_data); - if (!data) { - talloc_free(ctx); - return NULL; - } - - data->error_string = NULL; - ctx->private_data = data; + ctx->private_data = NULL; ctx->ldb = ldb; ctx->prev = ctx->next = NULL; ctx->ops = ×tamps_ops; diff --git a/source4/lib/ldb/tools/ldbadd.c b/source4/lib/ldb/tools/ldbadd.c index de6da0eb5b..ba58f782f0 100644 --- a/source4/lib/ldb/tools/ldbadd.c +++ b/source4/lib/ldb/tools/ldbadd.c @@ -34,6 +34,7 @@ #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" @@ -74,7 +75,7 @@ static int process_file(struct ldb_context *ldb, FILE *f) ldif->msg = ldb_msg_canonicalize(ldb, ldif->msg); ret = ldb_add(ldb, ldif->msg); - if (ret != 0) { + if (ret != LDB_ERR_SUCCESS) { fprintf(stderr, "ERR: \"%s\" on DN %s\n", ldb_errstring(ldb), ldb_dn_linearize(ldb, ldif->msg->dn)); failures++; |