Logo Search packages:      
Sourcecode: ldb version File versions  Download package

int ldb_connect ( struct ldb_context *  ldb,
const char *  url,
unsigned int  flags,
const char *  options[] 
)

Connect to a database.

This is typically called soon after ldb_init(), and is required prior to any search or database modification operations.

The URL can be one of the following forms:

  • tdb://path
  • ldapi://path
  • ldap://host
  • sqlite://path

Parameters:
ldb the context associated with the database (from ldb_init())
url the URL of the database to connect to, as noted above
flags a combination of LDB_FLG_* to modify the connection behaviour
options backend specific options - passed uninterpreted to the backend
Returns:
result code (LDB_SUCCESS on success, or a failure code)
Note:
It is an error to connect to a database that does not exist in readonly mode (that is, with LDB_FLG_RDONLY). However in read-write mode, the database will be created if it does not exist.

Definition at line 230 of file ldb.c.

References LDB_ERR_OPERATIONS_ERROR, LDB_ERR_OTHER, and LDB_SUCCESS.

{
      int ret;
      const char *url2;
      /* We seem to need to do this here, or else some utilities don't get ldb backends */
      ldb_global_init();

      ldb->flags = flags;

      url2 = talloc_strdup(ldb, url);
      if (!url2) {
            ldb_oom(ldb);
            return LDB_ERR_OPERATIONS_ERROR;
      }
      ret = ldb_set_opaque(ldb, "ldb_url", talloc_strdup(ldb, url2));
      if (ret != LDB_SUCCESS) {
            return ret;
      }

      ret = ldb_connect_backend(ldb, url, options, &ldb->modules);
      if (ret != LDB_SUCCESS) {
            return ret;
      }

      if (ldb_load_modules(ldb, options) != LDB_SUCCESS) {
            ldb_debug(ldb, LDB_DEBUG_FATAL, "Unable to load modules for %s: %s\n",
                    url, ldb_errstring(ldb));
            return LDB_ERR_OTHER;
      }

      /* TODO: get timeout from options if available there */
      ldb->default_timeout = 300; /* set default to 5 minutes */

      /* set the default base dn */
      ldb_set_default_dns(ldb);

      return LDB_SUCCESS;
}


Generated by  Doxygen 1.6.0   Back to index