4 Copyright (C) Andrew Tridgell 2004
5 Copyright (C) Simo Sorce 2005-2008
7 ** NOTE! The following LGPL license applies to the ldb
8 ** library. This does NOT imply that all of Samba is released
11 This library is free software; you can redistribute it and/or
12 modify it under the terms of the GNU Lesser General Public
13 License as published by the Free Software Foundation; either
14 version 3 of the License, or (at your option) any later version.
16 This library is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 Lesser General Public License for more details.
21 You should have received a copy of the GNU Lesser General Public
22 License along with this library; if not, see <http://www.gnu.org/licenses/>.
28 * Component: ldb core API
30 * Description: core API routines interfacing to ldb backends
32 * Author: Andrew Tridgell
35 #include "ldb_includes.h"
38 initialise a ldb context
39 The mem_ctx is required
40 The event_ctx is required
42 struct ldb_context *ldb_init(TALLOC_CTX *mem_ctx, struct event_context *ev_ctx)
44 struct ldb_context *ldb;
47 ldb = talloc_zero(mem_ctx, struct ldb_context);
48 /* FIXME: Hack a new event context so that CMD line utilities work
49 * until we have them all converted */
51 ev_ctx = event_context_init(talloc_autofree_context());
54 ret = ldb_setup_wellknown_attributes(ldb);
60 ldb_set_utf8_default(ldb);
61 ldb_set_create_perms(ldb, 0666);
62 ldb_set_modules_dir(ldb, LDB_MODULESDIR);
63 ldb_set_event_context(ldb, ev_ctx);
65 /* TODO: get timeout from options if available there */
66 ldb->default_timeout = 300; /* set default to 5 minutes */
72 try to autodetect a basedn if none specified. This fixes one of my
73 pet hates about ldapsearch, which is that you have to get a long,
74 complex basedn right to make any use of it.
76 void ldb_set_default_dns(struct ldb_context *ldb)
80 struct ldb_result *res;
81 struct ldb_dn *tmp_dn=NULL;
82 static const char *attrs[] = {
83 "rootDomainNamingContext",
84 "configurationNamingContext",
85 "schemaNamingContext",
86 "defaultNamingContext",
90 tmp_ctx = talloc_new(ldb);
91 ret = ldb_search(ldb, ldb_dn_new(tmp_ctx, ldb, NULL), LDB_SCOPE_BASE,
92 "(objectClass=*)", attrs, &res);
93 if (ret != LDB_SUCCESS) {
98 if (res->count != 1) {
103 if (!ldb_get_opaque(ldb, "rootDomainNamingContext")) {
104 tmp_dn = ldb_msg_find_attr_as_dn(ldb, ldb, res->msgs[0],
105 "rootDomainNamingContext");
106 ldb_set_opaque(ldb, "rootDomainNamingContext", tmp_dn);
109 if (!ldb_get_opaque(ldb, "configurationNamingContext")) {
110 tmp_dn = ldb_msg_find_attr_as_dn(ldb, ldb, res->msgs[0],
111 "configurationNamingContext");
112 ldb_set_opaque(ldb, "configurationNamingContext", tmp_dn);
115 if (!ldb_get_opaque(ldb, "schemaNamingContext")) {
116 tmp_dn = ldb_msg_find_attr_as_dn(ldb, ldb, res->msgs[0],
117 "schemaNamingContext");
118 ldb_set_opaque(ldb, "schemaNamingContext", tmp_dn);
121 if (!ldb_get_opaque(ldb, "defaultNamingContext")) {
122 tmp_dn = ldb_msg_find_attr_as_dn(ldb, ldb, res->msgs[0],
123 "defaultNamingContext");
124 ldb_set_opaque(ldb, "defaultNamingContext", tmp_dn);
128 talloc_free(tmp_ctx);
131 struct ldb_dn *ldb_get_root_basedn(struct ldb_context *ldb)
133 void *opaque = ldb_get_opaque(ldb, "rootDomainNamingContext");
134 return talloc_get_type(opaque, struct ldb_dn);
137 struct ldb_dn *ldb_get_config_basedn(struct ldb_context *ldb)
139 void *opaque = ldb_get_opaque(ldb, "configurationNamingContext");
140 return talloc_get_type(opaque, struct ldb_dn);
143 struct ldb_dn *ldb_get_schema_basedn(struct ldb_context *ldb)
145 void *opaque = ldb_get_opaque(ldb, "schemaNamingContext");
146 return talloc_get_type(opaque, struct ldb_dn);
149 struct ldb_dn *ldb_get_default_basedn(struct ldb_context *ldb)
151 void *opaque = ldb_get_opaque(ldb, "defaultNamingContext");
152 return talloc_get_type(opaque, struct ldb_dn);
156 connect to a database. The URL can either be one of the following forms
160 flags is made up of LDB_FLG_*
162 the options are passed uninterpreted to the backend, and are
165 int ldb_connect(struct ldb_context *ldb, const char *url,
166 unsigned int flags, const char *options[])
170 /* We seem to need to do this here, or else some utilities don't
171 * get ldb backends */
175 url2 = talloc_strdup(ldb, url);
178 return LDB_ERR_OPERATIONS_ERROR;
180 ret = ldb_set_opaque(ldb, "ldb_url", talloc_strdup(ldb, url2));
181 if (ret != LDB_SUCCESS) {
185 ret = ldb_connect_backend(ldb, url, options, &ldb->modules);
186 if (ret != LDB_SUCCESS) {
190 if (ldb_load_modules(ldb, options) != LDB_SUCCESS) {
191 ldb_debug(ldb, LDB_DEBUG_FATAL,
192 "Unable to load modules for %s: %s\n",
193 url, ldb_errstring(ldb));
194 return LDB_ERR_OTHER;
197 /* TODO: get timeout from options if available there */
198 ldb->default_timeout = 300; /* set default to 5 minutes */
200 /* set the default base dn */
201 ldb_set_default_dns(ldb);
206 void ldb_set_errstring(struct ldb_context *ldb, const char *err_string)
208 if (ldb->err_string) {
209 talloc_free(ldb->err_string);
211 ldb->err_string = talloc_strdup(ldb, err_string);
214 void ldb_asprintf_errstring(struct ldb_context *ldb, const char *format, ...)
217 char *old_string = NULL;
219 if (ldb->err_string) {
220 old_string = ldb->err_string;
223 va_start(ap, format);
224 ldb->err_string = talloc_vasprintf(ldb, format, ap);
226 talloc_free(old_string);
229 void ldb_reset_err_string(struct ldb_context *ldb)
231 if (ldb->err_string) {
232 talloc_free(ldb->err_string);
233 ldb->err_string = NULL;
237 #define FIRST_OP(ldb, op) do { \
238 module = ldb->modules; \
239 while (module && module->ops->op == NULL) module = module->next; \
240 if (module == NULL) { \
241 ldb_asprintf_errstring(ldb, "unable to find module or backend to handle operation: " #op); \
242 return LDB_ERR_OPERATIONS_ERROR; \
249 static int ldb_transaction_start_internal(struct ldb_context *ldb)
251 struct ldb_module *module;
253 FIRST_OP(ldb, start_transaction);
255 ldb_reset_err_string(ldb);
257 status = module->ops->start_transaction(module);
258 if (status != LDB_SUCCESS) {
259 if (ldb->err_string == NULL) {
260 /* no error string was setup by the backend */
261 ldb_asprintf_errstring(ldb,
262 "ldb transaction start: %s (%d)",
263 ldb_strerror(status),
273 static int ldb_transaction_commit_internal(struct ldb_context *ldb)
275 struct ldb_module *module;
277 FIRST_OP(ldb, end_transaction);
279 ldb_reset_err_string(ldb);
281 status = module->ops->end_transaction(module);
282 if (status != LDB_SUCCESS) {
283 if (ldb->err_string == NULL) {
284 /* no error string was setup by the backend */
285 ldb_asprintf_errstring(ldb,
286 "ldb transaction commit: %s (%d)",
287 ldb_strerror(status),
297 static int ldb_transaction_cancel_internal(struct ldb_context *ldb)
299 struct ldb_module *module;
301 FIRST_OP(ldb, del_transaction);
303 status = module->ops->del_transaction(module);
304 if (status != LDB_SUCCESS) {
305 if (ldb->err_string == NULL) {
306 /* no error string was setup by the backend */
307 ldb_asprintf_errstring(ldb,
308 "ldb transaction cancel: %s (%d)",
309 ldb_strerror(status),
316 int ldb_transaction_start(struct ldb_context *ldb)
318 /* disable autotransactions */
319 ldb->transaction_active++;
321 return ldb_transaction_start_internal(ldb);
324 int ldb_transaction_commit(struct ldb_context *ldb)
326 /* renable autotransactions (when we reach 0) */
327 if (ldb->transaction_active > 0)
328 ldb->transaction_active--;
330 return ldb_transaction_commit_internal(ldb);
333 int ldb_transaction_cancel(struct ldb_context *ldb)
335 /* renable autotransactions (when we reach 0) */
336 if (ldb->transaction_active > 0)
337 ldb->transaction_active--;
339 return ldb_transaction_cancel_internal(ldb);
342 static int ldb_autotransaction_start(struct ldb_context *ldb)
344 /* explicit transaction active, ignore autotransaction request */
345 if (ldb->transaction_active)
348 return ldb_transaction_start_internal(ldb);
351 static int ldb_autotransaction_commit(struct ldb_context *ldb)
353 /* explicit transaction active, ignore autotransaction request */
354 if (ldb->transaction_active)
357 return ldb_transaction_commit_internal(ldb);
360 static int ldb_autotransaction_cancel(struct ldb_context *ldb)
362 /* explicit transaction active, ignore autotransaction request */
363 if (ldb->transaction_active)
366 return ldb_transaction_cancel_internal(ldb);
369 /* autostarts a transacion if none active */
370 static int ldb_autotransaction_request(struct ldb_context *ldb,
371 struct ldb_request *req)
375 ret = ldb_autotransaction_start(ldb);
376 if (ret != LDB_SUCCESS) {
380 ret = ldb_request(ldb, req);
381 if (ret == LDB_SUCCESS) {
382 ret = ldb_wait(req->handle, LDB_WAIT_ALL);
385 if (ret == LDB_SUCCESS) {
386 return ldb_autotransaction_commit(ldb);
388 ldb_autotransaction_cancel(ldb);
390 if (ldb->err_string == NULL) {
391 /* no error string was setup by the backend */
392 ldb_asprintf_errstring(ldb, "%s (%d)", ldb_strerror(ret), ret);
398 int ldb_wait(struct ldb_handle *handle, enum ldb_wait_type type)
405 ret = handle->module->ops->wait(handle, type);
406 if (!ldb_errstring(handle->module->ldb)) {
407 /* Set a default error string, to place the blame somewhere */
408 ldb_asprintf_errstring(handle->module->ldb,
409 "error waiting on module %s: %s (%d)",
410 handle->module->ops->name,
411 ldb_strerror(ret), ret);
416 /* set the specified timeout or, if timeout is 0 set the default timeout */
417 /* timeout == -1 means no timeout */
418 int ldb_set_timeout(struct ldb_context *ldb,
419 struct ldb_request *req,
422 if (req == NULL) return LDB_ERR_OPERATIONS_ERROR;
425 req->timeout = timeout;
427 req->timeout = ldb->default_timeout;
429 req->starttime = time(NULL);
434 /* calculates the new timeout based on the previous starttime and timeout */
435 int ldb_set_timeout_from_prev_req(struct ldb_context *ldb,
436 struct ldb_request *oldreq,
437 struct ldb_request *newreq)
441 if (newreq == NULL) return LDB_ERR_OPERATIONS_ERROR;
446 return ldb_set_timeout(ldb, newreq, 0);
448 if ((now - oldreq->starttime) > oldreq->timeout) {
449 return LDB_ERR_TIME_LIMIT_EXCEEDED;
451 newreq->starttime = oldreq->starttime;
452 newreq->timeout = oldreq->timeout - (now - oldreq->starttime);
459 set the permissions for new files to be passed to open() in
460 backends that use local files
462 void ldb_set_create_perms(struct ldb_context *ldb, unsigned int perms)
464 ldb->create_perms = perms;
467 void ldb_set_event_context(struct ldb_context *ldb, struct event_context *ev)
472 struct event_context * ldb_get_event_context(struct ldb_context *ldb)
479 NOTE: the request must be a talloc context.
480 returns LDB_ERR_* on errors.
482 int ldb_request(struct ldb_context *ldb, struct ldb_request *req)
484 struct ldb_module *module;
487 ldb_reset_err_string(ldb);
489 /* call the first module in the chain */
490 switch (req->operation) {
492 FIRST_OP(ldb, search);
493 ret = module->ops->search(module, req);
497 ret = module->ops->add(module, req);
500 FIRST_OP(ldb, modify);
501 ret = module->ops->modify(module, req);
505 ret = module->ops->del(module, req);
508 FIRST_OP(ldb, rename);
509 ret = module->ops->rename(module, req);
512 FIRST_OP(ldb, extended);
513 ret = module->ops->extended(module, req);
515 case LDB_SEQUENCE_NUMBER:
516 FIRST_OP(ldb, sequence_number);
517 ret = module->ops->sequence_number(module, req);
520 FIRST_OP(ldb, request);
521 ret = module->ops->request(module, req);
529 search the database given a LDAP-like search expression
531 returns an LDB error code
533 Use talloc_free to free the ldb_message returned in 'res', if successful
536 int ldb_search_default_callback(struct ldb_context *ldb,
538 struct ldb_reply *ares)
540 struct ldb_result *res;
544 ldb_set_errstring(ldb, "NULL Context in callback");
545 return LDB_ERR_OPERATIONS_ERROR;
548 res = talloc_get_type(context, struct ldb_result);
551 ldb_set_errstring(ldb, "NULL res or ares in callback");
555 switch (ares->type) {
556 case LDB_REPLY_ENTRY:
557 res->msgs = talloc_realloc(res, res->msgs,
558 struct ldb_message *,
564 res->msgs[res->count + 1] = NULL;
566 res->msgs[res->count] = talloc_move(res->msgs, &ares->message);
569 case LDB_REPLY_REFERRAL:
571 for (n = 0; res->refs[n]; n++) /*noop*/ ;
576 res->refs = talloc_realloc(res, res->refs, char *, n + 2);
581 res->refs[n] = talloc_move(res->refs, &ares->referral);
582 res->refs[n + 1] = NULL;
584 case LDB_REPLY_EXTENDED:
586 /* TODO: we should really support controls on entries
587 * and referrals too! */
588 res->controls = talloc_move(res, &ares->controls);
596 return LDB_ERR_OPERATIONS_ERROR;
599 int ldb_build_search_req(struct ldb_request **ret_req,
600 struct ldb_context *ldb,
603 enum ldb_scope scope,
604 const char *expression,
605 const char * const *attrs,
606 struct ldb_control **controls,
608 ldb_request_callback_t callback)
610 struct ldb_request *req;
614 req = talloc(mem_ctx, struct ldb_request);
616 ldb_set_errstring(ldb, "Out of Memory");
617 return LDB_ERR_OPERATIONS_ERROR;
620 req->operation = LDB_SEARCH;
622 req->op.search.base = ldb_dn_new(req, ldb, NULL);
624 req->op.search.base = base;
626 req->op.search.scope = scope;
628 req->op.search.tree = ldb_parse_tree(req, expression);
629 if (req->op.search.tree == NULL) {
630 ldb_set_errstring(ldb, "Unable to parse search expression");
632 return LDB_ERR_OPERATIONS_ERROR;
635 req->op.search.attrs = attrs;
636 req->controls = controls;
637 req->context = context;
638 req->callback = callback;
644 int ldb_build_add_req(struct ldb_request **ret_req,
645 struct ldb_context *ldb,
647 const struct ldb_message *message,
648 struct ldb_control **controls,
650 ldb_request_callback_t callback)
652 struct ldb_request *req;
656 req = talloc(mem_ctx, struct ldb_request);
658 ldb_set_errstring(ldb, "Out of Memory");
659 return LDB_ERR_OPERATIONS_ERROR;
662 req->operation = LDB_ADD;
663 req->op.add.message = message;
664 req->controls = controls;
665 req->context = context;
666 req->callback = callback;
673 int ldb_build_mod_req(struct ldb_request **ret_req,
674 struct ldb_context *ldb,
676 const struct ldb_message *message,
677 struct ldb_control **controls,
679 ldb_request_callback_t callback)
681 struct ldb_request *req;
685 req = talloc(mem_ctx, struct ldb_request);
687 ldb_set_errstring(ldb, "Out of Memory");
688 return LDB_ERR_OPERATIONS_ERROR;
691 req->operation = LDB_MODIFY;
692 req->op.mod.message = message;
693 req->controls = controls;
694 req->context = context;
695 req->callback = callback;
702 int ldb_build_del_req(struct ldb_request **ret_req,
703 struct ldb_context *ldb,
706 struct ldb_control **controls,
708 ldb_request_callback_t callback)
710 struct ldb_request *req;
714 req = talloc(mem_ctx, struct ldb_request);
716 ldb_set_errstring(ldb, "Out of Memory");
717 return LDB_ERR_OPERATIONS_ERROR;
720 req->operation = LDB_DELETE;
722 req->controls = controls;
723 req->context = context;
724 req->callback = callback;
731 int ldb_build_rename_req(struct ldb_request **ret_req,
732 struct ldb_context *ldb,
734 struct ldb_dn *olddn,
735 struct ldb_dn *newdn,
736 struct ldb_control **controls,
738 ldb_request_callback_t callback)
740 struct ldb_request *req;
744 req = talloc(mem_ctx, struct ldb_request);
746 ldb_set_errstring(ldb, "Out of Memory");
747 return LDB_ERR_OPERATIONS_ERROR;
750 req->operation = LDB_RENAME;
751 req->op.rename.olddn = olddn;
752 req->op.rename.newdn = newdn;
753 req->controls = controls;
754 req->context = context;
755 req->callback = callback;
762 int ldb_extended_default_callback(struct ldb_context *ldb,
764 struct ldb_reply *ares)
766 struct ldb_result *res;
769 ldb_set_errstring(ldb, "NULL Context in callback");
770 return LDB_ERR_OPERATIONS_ERROR;
773 res = talloc_get_type(context, struct ldb_result);
775 ldb_set_errstring(ldb, "NULL res or ares in callback");
779 switch (ares->type) {
780 case LDB_REPLY_ENTRY:
781 case LDB_REPLY_REFERRAL:
783 ldb_set_errstring(ldb, "invalid ares type in callback");
785 case LDB_REPLY_EXTENDED:
786 /* TODO: we should really support controls on entries and
788 res->extended = talloc_move(res, &ares->response);
789 res->controls = talloc_move(res, &ares->controls);
797 return LDB_ERR_OPERATIONS_ERROR;
800 int ldb_build_extended_req(struct ldb_request **ret_req,
801 struct ldb_context *ldb,
805 struct ldb_control **controls,
807 ldb_request_callback_t callback)
809 struct ldb_request *req;
813 req = talloc(mem_ctx, struct ldb_request);
815 ldb_set_errstring(ldb, "Out of Memory");
816 return LDB_ERR_OPERATIONS_ERROR;
819 req->operation = LDB_EXTENDED;
820 req->op.extended.oid = oid;
821 req->op.extended.data = data;
822 req->controls = controls;
823 req->context = context;
824 req->callback = callback;
831 int ldb_extended(struct ldb_context *ldb,
834 struct ldb_result **_res)
836 struct ldb_request *req;
838 struct ldb_result *res;
842 res = talloc_zero(ldb, struct ldb_result);
844 return LDB_ERR_OPERATIONS_ERROR;
847 ret = ldb_build_extended_req(&req, ldb, ldb,
849 res, ldb_extended_default_callback);
850 if (ret != LDB_SUCCESS) goto done;
852 ldb_set_timeout(ldb, req, 0); /* use default timeout */
854 ret = ldb_request(ldb, req);
856 if (ret == LDB_SUCCESS) {
857 ret = ldb_wait(req->handle, LDB_WAIT_ALL);
863 if (ret != LDB_SUCCESS) {
872 note that ldb_search() will automatically replace a NULL 'base' value
873 with the defaultNamingContext from the rootDSE if available.
875 int ldb_search(struct ldb_context *ldb,
877 enum ldb_scope scope,
878 const char *expression,
879 const char * const *attrs,
880 struct ldb_result **_res)
882 struct ldb_request *req;
884 struct ldb_result *res;
888 res = talloc_zero(ldb, struct ldb_result);
890 return LDB_ERR_OPERATIONS_ERROR;
893 ret = ldb_build_search_req(&req, ldb, ldb,
894 base?base:ldb_get_default_basedn(ldb),
900 ldb_search_default_callback);
902 if (ret != LDB_SUCCESS) goto done;
904 ldb_set_timeout(ldb, req, 0); /* use default timeout */
906 ret = ldb_request(ldb, req);
908 if (ret == LDB_SUCCESS) {
909 ret = ldb_wait(req->handle, LDB_WAIT_ALL);
915 if (ret != LDB_SUCCESS) {
924 a useful search function where you can easily define the expression and that
925 takes a memory context where results are allocated
928 int ldb_search_exp_fmt(struct ldb_context *ldb, TALLOC_CTX *mem_ctx,
929 struct ldb_result **result, struct ldb_dn *base,
930 enum ldb_scope scope, const char * const *attrs,
931 const char *exp_fmt, ...)
933 struct ldb_result *res;
941 va_start(ap, exp_fmt);
942 expression = talloc_vasprintf(mem_ctx, exp_fmt, ap);
946 return LDB_ERR_OPERATIONS_ERROR;
949 ret = ldb_search(ldb, base, scope, expression, attrs, &res);
951 if (ret == LDB_SUCCESS) {
952 talloc_steal(mem_ctx, res);
956 talloc_free(expression);
962 add a record to the database. Will fail if a record with the
963 given class and key already exists
965 int ldb_add(struct ldb_context *ldb,
966 const struct ldb_message *message)
968 struct ldb_request *req;
971 ret = ldb_msg_sanity_check(ldb, message);
972 if (ret != LDB_SUCCESS) {
976 ret = ldb_build_add_req(&req, ldb, ldb,
982 if (ret != LDB_SUCCESS) return ret;
984 ldb_set_timeout(ldb, req, 0); /* use default timeout */
986 /* do request and autostart a transaction */
987 ret = ldb_autotransaction_request(ldb, req);
994 modify the specified attributes of a record
996 int ldb_modify(struct ldb_context *ldb,
997 const struct ldb_message *message)
999 struct ldb_request *req;
1002 ret = ldb_msg_sanity_check(ldb, message);
1003 if (ret != LDB_SUCCESS) {
1007 ret = ldb_build_mod_req(&req, ldb, ldb,
1013 if (ret != LDB_SUCCESS) return ret;
1015 ldb_set_timeout(ldb, req, 0); /* use default timeout */
1017 /* do request and autostart a transaction */
1018 ret = ldb_autotransaction_request(ldb, req);
1026 delete a record from the database
1028 int ldb_delete(struct ldb_context *ldb, struct ldb_dn *dn)
1030 struct ldb_request *req;
1033 ret = ldb_build_del_req(&req, ldb, ldb,
1039 if (ret != LDB_SUCCESS) return ret;
1041 ldb_set_timeout(ldb, req, 0); /* use default timeout */
1043 /* do request and autostart a transaction */
1044 ret = ldb_autotransaction_request(ldb, req);
1051 rename a record in the database
1053 int ldb_rename(struct ldb_context *ldb,
1054 struct ldb_dn *olddn, struct ldb_dn *newdn)
1056 struct ldb_request *req;
1059 ret = ldb_build_rename_req(&req, ldb, ldb,
1066 if (ret != LDB_SUCCESS) return ret;
1068 ldb_set_timeout(ldb, req, 0); /* use default timeout */
1070 /* do request and autostart a transaction */
1071 ret = ldb_autotransaction_request(ldb, req);
1079 return the global sequence number
1081 int ldb_sequence_number(struct ldb_context *ldb,
1082 enum ldb_sequence_type type,
1085 struct ldb_request *req;
1088 req = talloc(ldb, struct ldb_request);
1090 ldb_set_errstring(ldb, "Out of Memory");
1091 return LDB_ERR_OPERATIONS_ERROR;
1094 req->operation = LDB_SEQUENCE_NUMBER;
1095 req->controls = NULL;
1096 req->context = NULL;
1097 req->callback = NULL;
1098 ldb_set_timeout(ldb, req, 0); /* use default timeout */
1100 req->op.seq_num.type = type;
1101 /* do request and autostart a transaction */
1102 ret = ldb_request(ldb, req);
1104 if (ret == LDB_SUCCESS) {
1105 *seq_num = req->op.seq_num.seq_num;
1115 return extended error information
1117 const char *ldb_errstring(struct ldb_context *ldb)
1119 if (ldb->err_string) {
1120 return ldb->err_string;
1127 return a string explaining what a ldb error constant meancs
1129 const char *ldb_strerror(int ldb_err)
1134 case LDB_ERR_OPERATIONS_ERROR:
1135 return "Operations error";
1136 case LDB_ERR_PROTOCOL_ERROR:
1137 return "Protocol error";
1138 case LDB_ERR_TIME_LIMIT_EXCEEDED:
1139 return "Time limit exceeded";
1140 case LDB_ERR_SIZE_LIMIT_EXCEEDED:
1141 return "Size limit exceeded";
1142 case LDB_ERR_COMPARE_FALSE:
1143 return "Compare false";
1144 case LDB_ERR_COMPARE_TRUE:
1145 return "Compare true";
1146 case LDB_ERR_AUTH_METHOD_NOT_SUPPORTED:
1147 return "Auth method not supported";
1148 case LDB_ERR_STRONG_AUTH_REQUIRED:
1149 return "Strong auth required";
1151 case LDB_ERR_REFERRAL:
1152 return "Referral error";
1153 case LDB_ERR_ADMIN_LIMIT_EXCEEDED:
1154 return "Admin limit exceeded";
1155 case LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION:
1156 return "Unsupported critical extension";
1157 case LDB_ERR_CONFIDENTIALITY_REQUIRED:
1158 return "Confidentiality required";
1159 case LDB_ERR_SASL_BIND_IN_PROGRESS:
1160 return "SASL bind in progress";
1161 case LDB_ERR_NO_SUCH_ATTRIBUTE:
1162 return "No such attribute";
1163 case LDB_ERR_UNDEFINED_ATTRIBUTE_TYPE:
1164 return "Undefined attribute type";
1165 case LDB_ERR_INAPPROPRIATE_MATCHING:
1166 return "Inappropriate matching";
1167 case LDB_ERR_CONSTRAINT_VIOLATION:
1168 return "Constraint violation";
1169 case LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS:
1170 return "Attribute or value exists";
1171 case LDB_ERR_INVALID_ATTRIBUTE_SYNTAX:
1172 return "Invalid attribute syntax";
1174 case LDB_ERR_NO_SUCH_OBJECT:
1175 return "No such object";
1176 case LDB_ERR_ALIAS_PROBLEM:
1177 return "Alias problem";
1178 case LDB_ERR_INVALID_DN_SYNTAX:
1179 return "Invalid DN syntax";
1181 case LDB_ERR_ALIAS_DEREFERENCING_PROBLEM:
1182 return "Alias dereferencing problem";
1184 case LDB_ERR_INAPPROPRIATE_AUTHENTICATION:
1185 return "Inappropriate authentication";
1186 case LDB_ERR_INVALID_CREDENTIALS:
1187 return "Invalid credentials";
1188 case LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS:
1189 return "insufficient access rights";
1192 case LDB_ERR_UNAVAILABLE:
1193 return "Unavailable";
1194 case LDB_ERR_UNWILLING_TO_PERFORM:
1195 return "Unwilling to perform";
1196 case LDB_ERR_LOOP_DETECT:
1197 return "Loop detect";
1199 case LDB_ERR_NAMING_VIOLATION:
1200 return "Naming violation";
1201 case LDB_ERR_OBJECT_CLASS_VIOLATION:
1202 return "Object class violation";
1203 case LDB_ERR_NOT_ALLOWED_ON_NON_LEAF:
1204 return "Not allowed on non-leaf";
1205 case LDB_ERR_NOT_ALLOWED_ON_RDN:
1206 return "Not allowed on RDN";
1207 case LDB_ERR_ENTRY_ALREADY_EXISTS:
1208 return "Entry already exists";
1209 case LDB_ERR_OBJECT_CLASS_MODS_PROHIBITED:
1210 return "Object class mods prohibited";
1211 /* 70 RESERVED FOR CLDAP */
1212 case LDB_ERR_AFFECTS_MULTIPLE_DSAS:
1213 return "Affects multiple DSAs";
1219 return "Unknown error";
1223 set backend specific opaque parameters
1225 int ldb_set_opaque(struct ldb_context *ldb, const char *name, void *value)
1227 struct ldb_opaque *o;
1229 /* allow updating an existing value */
1230 for (o=ldb->opaque;o;o=o->next) {
1231 if (strcmp(o->name, name) == 0) {
1237 o = talloc(ldb, struct ldb_opaque);
1240 return LDB_ERR_OTHER;
1242 o->next = ldb->opaque;
1250 get a previously set opaque value
1252 void *ldb_get_opaque(struct ldb_context *ldb, const char *name)
1254 struct ldb_opaque *o;
1255 for (o=ldb->opaque;o;o=o->next) {
1256 if (strcmp(o->name, name) == 0) {