r7776: add a method for getting arbitrary opaque data into a ldb context, for use...
authorAndrew Tridgell <tridge@samba.org>
Mon, 20 Jun 2005 04:56:43 +0000 (04:56 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:18:35 +0000 (13:18 -0500)
Currently only EventContext is used in this way.
(This used to be commit 9fa21b245843371f7777682ee4e5b98e2925b4d0)

source4/lib/ldb/common/ldb.c
source4/lib/ldb/include/ldb.h
source4/lib/ldb/include/ldb_private.h
source4/lib/ldb/ldb_ildap/ldb_ildap.c

index 450fa75d8e536e4ec01db726e687dd1c38aad16b..e268a8d0d7e0bb338134c0a749cad465daa03074 100644 (file)
@@ -178,3 +178,34 @@ const char *ldb_errstring(struct ldb_context *ldb)
        return ldb->modules->ops->errstring(ldb->modules);
 }
 
+
+/*
+  set backend specific opaque parameters
+*/
+int ldb_set_opaque(struct ldb_context *ldb, const char *name, void *value)
+{
+       struct ldb_opaque *o = talloc(ldb, struct ldb_opaque);
+       if (o == NULL) {
+               ldb_oom(ldb);
+               return -1;
+       }
+       o->next = ldb->opaque;
+       o->name = name;
+       o->value = value;
+       ldb->opaque = o;
+       return 0;
+}
+
+/*
+  get a previously set opaque value
+*/
+void *ldb_get_opaque(struct ldb_context *ldb, const char *name)
+{
+       struct ldb_opaque *o;
+       for (o=ldb->opaque;o;o=o->next) {
+               if (strcmp(o->name, name) == 0) {
+                       return o->value;
+               }
+       }
+       return NULL;
+}
index e980633a62a616f396b0c508498fe4e2034b9a99..9a3186b41c920d872ae23424967b48d12201a690 100644 (file)
@@ -372,4 +372,8 @@ int ldb_set_debug(struct ldb_context *ldb,
 /* this sets up debug to print messages on stderr */
 int ldb_set_debug_stderr(struct ldb_context *ldb);
 
+/* control backend specific opaque values */
+int ldb_set_opaque(struct ldb_context *ldb, const char *name, void *value);
+void *ldb_get_opaque(struct ldb_context *ldb, const char *name);
+
 #endif
index 92588e13fdcacb8e1b7bb189358cf6a23e7f7922..8f91b0d9b17535f1062d101b88c5c1f6344beed5 100644 (file)
@@ -77,6 +77,13 @@ struct ldb_context {
 
        /* debugging operations */
        struct ldb_debug_ops debug_ops;
+
+       /* backend specific opaque parameters */
+       struct ldb_opaque {
+               struct ldb_opaque *next;
+               const char *name;
+               void *value;
+       } *opaque;
 };
 
 /* the modules init function */
index eefe80c919b8b0931e6a30da5a12c12be871cf64..b51139aa6f978691cd1bd81d1cc337f13ff0150d 100644 (file)
@@ -398,7 +398,7 @@ int ildb_connect(struct ldb_context *ldb, const char *url,
 
        ildb->rootDSE = NULL;
 
-       ildb->ldap = ldap_new_connection(ildb, NULL);
+       ildb->ldap = ldap_new_connection(ildb, ldb_get_opaque(ldb, "EventContext"));
        if (!ildb->ldap) {
                ldb_oom(ldb);
                goto failed;
@@ -421,7 +421,8 @@ int ildb_connect(struct ldb_context *ldb, const char *url,
        ldb->modules->private_data = ildb;
        ldb->modules->ops = &ildb_ops;
 
-       if (cmdline_credentials->username_obtained > CRED_GUESSED) {
+       if (cmdline_credentials != NULL &&
+           cmdline_credentials->username_obtained > CRED_GUESSED) {
                status = ldap_bind_sasl(ildb->ldap, cmdline_credentials);
                if (!NT_STATUS_IS_OK(status)) {
                        ldb_debug(ldb, LDB_DEBUG_ERROR, "Failed to bind - %s\n",