4 Copyright (C) Andrew Tridgell 2004
5 Copyright (C) Simo Sorce 2005-2006
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 2 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, write to the Free Software
23 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 * Component: ldb core API
31 * Description: core API routines interfacing to ldb backends
33 * Author: Andrew Tridgell
37 #include "ldb/include/includes.h"
40 initialise a ldb context
41 The mem_ctx is optional
43 struct ldb_context *ldb_init(void *mem_ctx)
45 struct ldb_context *ldb = talloc_zero(mem_ctx, struct ldb_context);
48 ret = ldb_setup_wellknown_attributes(ldb);
54 ldb_set_utf8_default(ldb);
55 ldb_set_create_perms(ldb, 0666);
60 static struct ldb_backend {
62 ldb_connect_fn connect_fn;
63 struct ldb_backend *prev, *next;
64 } *ldb_backends = NULL;
67 static ldb_connect_fn ldb_find_backend(const char *url)
69 struct ldb_backend *backend;
71 for (backend = ldb_backends; backend; backend = backend->next) {
72 if (strncmp(backend->name, url, strlen(backend->name)) == 0) {
73 return backend->connect_fn;
81 register a new ldb backend
83 int ldb_register_backend(const char *url_prefix, ldb_connect_fn connectfn)
85 struct ldb_backend *backend = talloc(talloc_autofree_context(), struct ldb_backend);
87 if (ldb_find_backend(url_prefix)) {
91 /* Maybe check for duplicity here later on? */
93 backend->name = talloc_strdup(backend, url_prefix);
94 backend->connect_fn = connectfn;
95 DLIST_ADD(ldb_backends, backend);
101 Return the ldb module form of a database. The URL can either be one of the following forms
105 flags is made up of LDB_FLG_*
107 the options are passed uninterpreted to the backend, and are
110 This allows modules to get at only the backend module, for example where a module
111 may wish to direct certain requests at a particular backend.
113 int ldb_connect_backend(struct ldb_context *ldb, const char *url, const char *options[],
114 struct ldb_module **backend_module)
120 if (strchr(url, ':') != NULL) {
121 backend = talloc_strndup(ldb, url, strchr(url, ':')-url);
124 backend = talloc_strdup(ldb, "tdb");
127 fn = ldb_find_backend(backend);
130 if (ldb_try_load_dso(ldb, backend) == 0) {
131 fn = ldb_find_backend(backend);
135 talloc_free(backend);
138 ldb_debug(ldb, LDB_DEBUG_FATAL, "Unable to find backend for '%s'\n", url);
139 return LDB_ERR_OTHER;
142 ret = fn(ldb, url, ldb->flags, options, backend_module);
144 if (ret != LDB_SUCCESS) {
145 ldb_debug(ldb, LDB_DEBUG_ERROR, "Failed to connect to '%s'\n", url);
152 try to autodetect a basedn if none specified. This fixes one of my
153 pet hates about ldapsearch, which is that you have to get a long,
154 complex basedn right to make any use of it.
156 static const struct ldb_dn *ldb_set_default_basedn(struct ldb_context *ldb)
160 static const char *attrs[] = { "defaultNamingContext", NULL };
161 struct ldb_result *res;
162 struct ldb_dn *basedn=NULL;
164 basedn = (struct ldb_dn *)ldb_get_opaque(ldb, "default_baseDN");
169 tmp_ctx = talloc_new(ldb);
170 ret = ldb_search(ldb, ldb_dn_new(tmp_ctx), LDB_SCOPE_BASE,
171 "(objectClass=*)", attrs, &res);
172 if (ret == LDB_SUCCESS) {
173 if (res->count == 1) {
174 basedn = ldb_msg_find_attr_as_dn(ldb, res->msgs[0], "defaultNamingContext");
175 ldb_set_opaque(ldb, "default_baseDN", basedn);
180 talloc_free(tmp_ctx);
184 const struct ldb_dn *ldb_get_default_basedn(struct ldb_context *ldb)
186 return (const struct ldb_dn *)ldb_get_opaque(ldb, "default_baseDN");
190 connect to a database. The URL can either be one of the following forms
194 flags is made up of LDB_FLG_*
196 the options are passed uninterpreted to the backend, and are
199 int ldb_connect(struct ldb_context *ldb, const char *url, unsigned int flags, const char *options[])
205 ret = ldb_connect_backend(ldb, url, options, &ldb->modules);
206 if (ret != LDB_SUCCESS) {
210 if (ldb_load_modules(ldb, options) != LDB_SUCCESS) {
211 ldb_debug(ldb, LDB_DEBUG_FATAL, "Unable to load modules for %s: %s\n",
212 url, ldb_errstring(ldb));
213 return LDB_ERR_OTHER;
216 /* TODO: get timeout from options if available there */
217 ldb->default_timeout = 300; /* set default to 5 minutes */
219 /* set the default base dn */
220 ldb_set_default_basedn(ldb);
225 void ldb_set_errstring(struct ldb_context *ldb, const char *err_string)
227 if (ldb->err_string) {
228 talloc_free(ldb->err_string);
230 ldb->err_string = talloc_strdup(ldb, err_string);
233 void ldb_asprintf_errstring(struct ldb_context *ldb, const char *format, ...)
237 if (ldb->err_string) {
238 talloc_free(ldb->err_string);
241 va_start(ap, format);
242 ldb->err_string = talloc_vasprintf(ldb, format, ap);
246 void ldb_reset_err_string(struct ldb_context *ldb)
248 if (ldb->err_string) {
249 talloc_free(ldb->err_string);
250 ldb->err_string = NULL;
254 #define FIRST_OP(ldb, op) do { \
255 module = ldb->modules; \
256 while (module && module->ops->op == NULL) module = module->next; \
257 if (module == NULL) { \
258 ldb_asprintf_errstring(ldb, "unable to find module or backend to handle operation: " #op); \
259 return LDB_ERR_OPERATIONS_ERROR; \
266 static int ldb_transaction_start_internal(struct ldb_context *ldb)
268 struct ldb_module *module;
270 FIRST_OP(ldb, start_transaction);
272 ldb_reset_err_string(ldb);
274 status = module->ops->start_transaction(module);
275 if (status != LDB_SUCCESS) {
276 if (ldb->err_string == NULL) {
277 /* no error string was setup by the backend */
278 ldb_asprintf_errstring(ldb,
279 "ldb transaction start: %s (%d)",
280 ldb_strerror(status),
290 static int ldb_transaction_commit_internal(struct ldb_context *ldb)
292 struct ldb_module *module;
294 FIRST_OP(ldb, end_transaction);
296 ldb_reset_err_string(ldb);
298 status = module->ops->end_transaction(module);
299 if (status != LDB_SUCCESS) {
300 if (ldb->err_string == NULL) {
301 /* no error string was setup by the backend */
302 ldb_asprintf_errstring(ldb,
303 "ldb transaction commit: %s (%d)",
304 ldb_strerror(status),
314 static int ldb_transaction_cancel_internal(struct ldb_context *ldb)
316 struct ldb_module *module;
318 FIRST_OP(ldb, del_transaction);
320 status = module->ops->del_transaction(module);
321 if (status != LDB_SUCCESS) {
322 if (ldb->err_string == NULL) {
323 /* no error string was setup by the backend */
324 ldb_asprintf_errstring(ldb,
325 "ldb transaction cancel: %s (%d)",
326 ldb_strerror(status),
333 int ldb_transaction_start(struct ldb_context *ldb)
335 /* disable autotransactions */
336 ldb->transaction_active++;
338 return ldb_transaction_start_internal(ldb);
341 int ldb_transaction_commit(struct ldb_context *ldb)
343 /* renable autotransactions (when we reach 0) */
344 if (ldb->transaction_active > 0)
345 ldb->transaction_active--;
347 return ldb_transaction_commit_internal(ldb);
350 int ldb_transaction_cancel(struct ldb_context *ldb)
352 /* renable autotransactions (when we reach 0) */
353 if (ldb->transaction_active > 0)
354 ldb->transaction_active--;
356 return ldb_transaction_cancel_internal(ldb);
359 static int ldb_autotransaction_start(struct ldb_context *ldb)
361 /* explicit transaction active, ignore autotransaction request */
362 if (ldb->transaction_active)
365 return ldb_transaction_start_internal(ldb);
368 static int ldb_autotransaction_commit(struct ldb_context *ldb)
370 /* explicit transaction active, ignore autotransaction request */
371 if (ldb->transaction_active)
374 return ldb_transaction_commit_internal(ldb);
377 static int ldb_autotransaction_cancel(struct ldb_context *ldb)
379 /* explicit transaction active, ignore autotransaction request */
380 if (ldb->transaction_active)
383 return ldb_transaction_cancel_internal(ldb);
386 /* autostarts a transacion if none active */
387 static int ldb_autotransaction_request(struct ldb_context *ldb, struct ldb_request *req)
391 ret = ldb_autotransaction_start(ldb);
392 if (ret != LDB_SUCCESS) {
396 ret = ldb_request(ldb, req);
397 if (ret == LDB_SUCCESS) {
398 ret = ldb_wait(req->handle, LDB_WAIT_ALL);
401 if (ret == LDB_SUCCESS) {
402 return ldb_autotransaction_commit(ldb);
404 ldb_autotransaction_cancel(ldb);
406 if (ldb->err_string == NULL) {
407 /* no error string was setup by the backend */
408 ldb_asprintf_errstring(ldb, "%s (%d)", ldb_strerror(ret), ret);
414 int ldb_wait(struct ldb_handle *handle, enum ldb_wait_type type)
420 return handle->module->ops->wait(handle, type);
423 /* set the specified timeout or, if timeout is 0 set the default timeout */
424 /* timeout == -1 means no timeout */
425 int ldb_set_timeout(struct ldb_context *ldb, struct ldb_request *req, int timeout)
427 if (req == NULL) return LDB_ERR_OPERATIONS_ERROR;
430 req->timeout = timeout;
432 req->timeout = ldb->default_timeout;
434 req->starttime = time(NULL);
439 /* calculates the new timeout based on the previous starttime and timeout */
440 int ldb_set_timeout_from_prev_req(struct ldb_context *ldb, struct ldb_request *oldreq, struct ldb_request *newreq)
444 if (newreq == NULL) return LDB_ERR_OPERATIONS_ERROR;
449 return ldb_set_timeout(ldb, newreq, 0);
451 if ((now - oldreq->starttime) > oldreq->timeout) {
452 return LDB_ERR_TIME_LIMIT_EXCEEDED;
454 newreq->starttime = oldreq->starttime;
455 newreq->timeout = oldreq->timeout - (now - oldreq->starttime);
462 set the permissions for new files to be passed to open() in
463 backends that use local files
465 void ldb_set_create_perms(struct ldb_context *ldb, unsigned int perms)
467 ldb->create_perms = perms;
472 NOTE: the request must be a talloc context.
473 returns LDB_ERR_* on errors.
475 int ldb_request(struct ldb_context *ldb, struct ldb_request *req)
477 struct ldb_module *module;
480 ldb_reset_err_string(ldb);
482 /* call the first module in the chain */
483 switch (req->operation) {
485 FIRST_OP(ldb, search);
486 ret = module->ops->search(module, req);
490 ret = module->ops->add(module, req);
493 FIRST_OP(ldb, modify);
494 ret = module->ops->modify(module, req);
498 ret = module->ops->del(module, req);
501 FIRST_OP(ldb, rename);
502 ret = module->ops->rename(module, req);
504 case LDB_SEQUENCE_NUMBER:
505 FIRST_OP(ldb, sequence_number);
506 ret = module->ops->sequence_number(module, req);
509 FIRST_OP(ldb, request);
510 ret = module->ops->request(module, req);
518 search the database given a LDAP-like search expression
520 returns an LDB error code
522 Use talloc_free to free the ldb_message returned in 'res', if successful
525 static int ldb_search_callback(struct ldb_context *ldb, void *context, struct ldb_reply *ares)
527 struct ldb_result *res;
531 ldb_set_errstring(ldb, "NULL Context in callback");
532 return LDB_ERR_OPERATIONS_ERROR;
535 res = *((struct ldb_result **)context);
541 switch (ares->type) {
542 case LDB_REPLY_ENTRY:
543 res->msgs = talloc_realloc(res, res->msgs, struct ldb_message *, res->count + 2);
548 res->msgs[res->count + 1] = NULL;
550 res->msgs[res->count] = talloc_move(res->msgs, &ares->message);
553 case LDB_REPLY_REFERRAL:
555 for (n = 0; res->refs[n]; n++) /*noop*/ ;
560 res->refs = talloc_realloc(res, res->refs, char *, n + 2);
565 res->refs[n] = talloc_move(res->refs, &ares->referral);
566 res->refs[n + 1] = NULL;
568 /* Should do something here to detect if this never
572 talloc_steal(res, ares->controls);
579 *((struct ldb_result **)context) = NULL;
580 return LDB_ERR_OPERATIONS_ERROR;
583 int ldb_build_search_req(struct ldb_request **ret_req,
584 struct ldb_context *ldb,
586 const struct ldb_dn *base,
587 enum ldb_scope scope,
588 const char *expression,
589 const char * const *attrs,
590 struct ldb_control **controls,
592 ldb_request_callback_t callback)
594 struct ldb_request *req;
598 req = talloc(mem_ctx, struct ldb_request);
600 ldb_set_errstring(ldb, "Out of Memory");
601 return LDB_ERR_OPERATIONS_ERROR;
604 req->operation = LDB_SEARCH;
606 req->op.search.base = ldb_dn_new(req);
608 req->op.search.base = base;
610 req->op.search.scope = scope;
612 req->op.search.tree = ldb_parse_tree(req, expression);
613 if (req->op.search.tree == NULL) {
614 ldb_set_errstring(ldb, "Unable to parse search expression");
616 return LDB_ERR_OPERATIONS_ERROR;
619 req->op.search.attrs = attrs;
620 req->controls = controls;
621 req->context = context;
622 req->callback = callback;
628 int ldb_build_add_req(struct ldb_request **ret_req,
629 struct ldb_context *ldb,
631 const struct ldb_message *message,
632 struct ldb_control **controls,
634 ldb_request_callback_t callback)
636 struct ldb_request *req;
640 req = talloc(mem_ctx, struct ldb_request);
642 ldb_set_errstring(ldb, "Out of Memory");
643 return LDB_ERR_OPERATIONS_ERROR;
646 req->operation = LDB_ADD;
647 req->op.add.message = message;
648 req->controls = controls;
649 req->context = context;
650 req->callback = callback;
657 int ldb_build_mod_req(struct ldb_request **ret_req,
658 struct ldb_context *ldb,
660 const struct ldb_message *message,
661 struct ldb_control **controls,
663 ldb_request_callback_t callback)
665 struct ldb_request *req;
669 req = talloc(mem_ctx, struct ldb_request);
671 ldb_set_errstring(ldb, "Out of Memory");
672 return LDB_ERR_OPERATIONS_ERROR;
675 req->operation = LDB_MODIFY;
676 req->op.mod.message = message;
677 req->controls = controls;
678 req->context = context;
679 req->callback = callback;
686 int ldb_build_del_req(struct ldb_request **ret_req,
687 struct ldb_context *ldb,
689 const struct ldb_dn *dn,
690 struct ldb_control **controls,
692 ldb_request_callback_t callback)
694 struct ldb_request *req;
698 req = talloc(mem_ctx, struct ldb_request);
700 ldb_set_errstring(ldb, "Out of Memory");
701 return LDB_ERR_OPERATIONS_ERROR;
704 req->operation = LDB_DELETE;
706 req->controls = controls;
707 req->context = context;
708 req->callback = callback;
715 int ldb_build_rename_req(struct ldb_request **ret_req,
716 struct ldb_context *ldb,
718 const struct ldb_dn *olddn,
719 const struct ldb_dn *newdn,
720 struct ldb_control **controls,
722 ldb_request_callback_t callback)
724 struct ldb_request *req;
728 req = talloc(mem_ctx, struct ldb_request);
730 ldb_set_errstring(ldb, "Out of Memory");
731 return LDB_ERR_OPERATIONS_ERROR;
734 req->operation = LDB_RENAME;
735 req->op.rename.olddn = olddn;
736 req->op.rename.newdn = newdn;
737 req->controls = controls;
738 req->context = context;
739 req->callback = callback;
747 note that ldb_search() will automatically replace a NULL 'base' value with the
748 defaultNamingContext from the rootDSE if available.
750 int ldb_search(struct ldb_context *ldb,
751 const struct ldb_dn *base,
752 enum ldb_scope scope,
753 const char *expression,
754 const char * const *attrs,
755 struct ldb_result **res)
757 struct ldb_request *req;
760 *res = talloc_zero(ldb, struct ldb_result);
762 return LDB_ERR_OPERATIONS_ERROR;
765 ret = ldb_build_search_req(&req, ldb, ldb,
766 base?base:ldb_get_default_basedn(ldb),
772 ldb_search_callback);
774 if (ret != LDB_SUCCESS) goto done;
776 ldb_set_timeout(ldb, req, 0); /* use default timeout */
778 ret = ldb_request(ldb, req);
780 if (ret == LDB_SUCCESS) {
781 ret = ldb_wait(req->handle, LDB_WAIT_ALL);
787 if (ret != LDB_SUCCESS) {
796 add a record to the database. Will fail if a record with the given class and key
799 int ldb_add(struct ldb_context *ldb,
800 const struct ldb_message *message)
802 struct ldb_request *req;
805 ret = ldb_msg_sanity_check(ldb, message);
806 if (ret != LDB_SUCCESS) {
810 ret = ldb_build_add_req(&req, ldb, ldb,
816 if (ret != LDB_SUCCESS) return ret;
818 ldb_set_timeout(ldb, req, 0); /* use default timeout */
820 /* do request and autostart a transaction */
821 ret = ldb_autotransaction_request(ldb, req);
828 modify the specified attributes of a record
830 int ldb_modify(struct ldb_context *ldb,
831 const struct ldb_message *message)
833 struct ldb_request *req;
836 ret = ldb_msg_sanity_check(ldb, message);
837 if (ret != LDB_SUCCESS) {
841 ret = ldb_build_mod_req(&req, ldb, ldb,
847 if (ret != LDB_SUCCESS) return ret;
849 ldb_set_timeout(ldb, req, 0); /* use default timeout */
851 /* do request and autostart a transaction */
852 ret = ldb_autotransaction_request(ldb, req);
860 delete a record from the database
862 int ldb_delete(struct ldb_context *ldb, const struct ldb_dn *dn)
864 struct ldb_request *req;
867 ret = ldb_build_del_req(&req, ldb, ldb,
873 if (ret != LDB_SUCCESS) return ret;
875 ldb_set_timeout(ldb, req, 0); /* use default timeout */
877 /* do request and autostart a transaction */
878 ret = ldb_autotransaction_request(ldb, req);
885 rename a record in the database
887 int ldb_rename(struct ldb_context *ldb, const struct ldb_dn *olddn, const struct ldb_dn *newdn)
889 struct ldb_request *req;
892 ret = ldb_build_rename_req(&req, ldb, ldb,
899 if (ret != LDB_SUCCESS) return ret;
901 ldb_set_timeout(ldb, req, 0); /* use default timeout */
903 /* do request and autostart a transaction */
904 ret = ldb_autotransaction_request(ldb, req);
912 return the global sequence number
914 int ldb_sequence_number(struct ldb_context *ldb, enum ldb_sequence_type type, uint64_t *seq_num)
916 struct ldb_request *req;
919 req = talloc(ldb, struct ldb_request);
921 ldb_set_errstring(ldb, "Out of Memory");
922 return LDB_ERR_OPERATIONS_ERROR;
925 req->operation = LDB_SEQUENCE_NUMBER;
926 req->controls = NULL;
928 req->callback = NULL;
929 ldb_set_timeout(ldb, req, 0); /* use default timeout */
931 req->op.seq_num.type = type;
932 /* do request and autostart a transaction */
933 ret = ldb_request(ldb, req);
935 if (ret == LDB_SUCCESS) {
936 *seq_num = req->op.seq_num.seq_num;
946 return extended error information
948 const char *ldb_errstring(struct ldb_context *ldb)
950 if (ldb->err_string) {
951 return ldb->err_string;
958 return a string explaining what a ldb error constant meancs
960 const char *ldb_strerror(int ldb_err)
965 case LDB_ERR_OPERATIONS_ERROR:
966 return "Operations error";
967 case LDB_ERR_PROTOCOL_ERROR:
968 return "Protocol error";
969 case LDB_ERR_TIME_LIMIT_EXCEEDED:
970 return "Time limit exceeded";
971 case LDB_ERR_SIZE_LIMIT_EXCEEDED:
972 return "Size limit exceeded";
973 case LDB_ERR_COMPARE_FALSE:
974 return "Compare false";
975 case LDB_ERR_COMPARE_TRUE:
976 return "Compare true";
977 case LDB_ERR_AUTH_METHOD_NOT_SUPPORTED:
978 return "Auth method not supported";
979 case LDB_ERR_STRONG_AUTH_REQUIRED:
980 return "Strong auth required";
982 case LDB_ERR_REFERRAL:
983 return "Referral error";
984 case LDB_ERR_ADMIN_LIMIT_EXCEEDED:
985 return "Admin limit exceeded";
986 case LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION:
987 return "Unsupported critical extension";
988 case LDB_ERR_CONFIDENTIALITY_REQUIRED:
989 return "Confidentiality required";
990 case LDB_ERR_SASL_BIND_IN_PROGRESS:
991 return "SASL bind in progress";
992 case LDB_ERR_NO_SUCH_ATTRIBUTE:
993 return "No such attribute";
994 case LDB_ERR_UNDEFINED_ATTRIBUTE_TYPE:
995 return "Undefined attribute type";
996 case LDB_ERR_INAPPROPRIATE_MATCHING:
997 return "Inappropriate matching";
998 case LDB_ERR_CONSTRAINT_VIOLATION:
999 return "Constraint violation";
1000 case LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS:
1001 return "Attribute or value exists";
1002 case LDB_ERR_INVALID_ATTRIBUTE_SYNTAX:
1003 return "Invalid attribute syntax";
1005 case LDB_ERR_NO_SUCH_OBJECT:
1006 return "No such object";
1007 case LDB_ERR_ALIAS_PROBLEM:
1008 return "Alias problem";
1009 case LDB_ERR_INVALID_DN_SYNTAX:
1010 return "Invalid DN syntax";
1012 case LDB_ERR_ALIAS_DEREFERENCING_PROBLEM:
1013 return "Alias dereferencing problem";
1015 case LDB_ERR_INAPPROPRIATE_AUTHENTICATION:
1016 return "Inappropriate authentication";
1017 case LDB_ERR_INVALID_CREDENTIALS:
1018 return "Invalid credentials";
1019 case LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS:
1020 return "insufficient access rights";
1023 case LDB_ERR_UNAVAILABLE:
1024 return "Unavailable";
1025 case LDB_ERR_UNWILLING_TO_PERFORM:
1026 return "Unwilling to perform";
1027 case LDB_ERR_LOOP_DETECT:
1028 return "Loop detect";
1030 case LDB_ERR_NAMING_VIOLATION:
1031 return "Naming violation";
1032 case LDB_ERR_OBJECT_CLASS_VIOLATION:
1033 return "Object class violation";
1034 case LDB_ERR_NOT_ALLOWED_ON_NON_LEAF:
1035 return "Not allowed on non-leaf";
1036 case LDB_ERR_NOT_ALLOWED_ON_RDN:
1037 return "Not allowed on RDN";
1038 case LDB_ERR_ENTRY_ALREADY_EXISTS:
1039 return "Entry already exists";
1040 case LDB_ERR_OBJECT_CLASS_MODS_PROHIBITED:
1041 return "Object class mods prohibited";
1042 /* 70 RESERVED FOR CLDAP */
1043 case LDB_ERR_AFFECTS_MULTIPLE_DSAS:
1044 return "Affects multiple DSAs";
1050 return "Unknown error";
1054 set backend specific opaque parameters
1056 int ldb_set_opaque(struct ldb_context *ldb, const char *name, void *value)
1058 struct ldb_opaque *o;
1060 /* allow updating an existing value */
1061 for (o=ldb->opaque;o;o=o->next) {
1062 if (strcmp(o->name, name) == 0) {
1068 o = talloc(ldb, struct ldb_opaque);
1071 return LDB_ERR_OTHER;
1073 o->next = ldb->opaque;
1081 get a previously set opaque value
1083 void *ldb_get_opaque(struct ldb_context *ldb, const char *name)
1085 struct ldb_opaque *o;
1086 for (o=ldb->opaque;o;o=o->next) {
1087 if (strcmp(o->name, name) == 0) {