/* * Test set up */ static int setup(void **state) { struct ldbtest_ctx *test_ctx = NULL; struct ldb_module *eol = NULL; int rc; test_ctx = talloc_zero(NULL, struct ldbtest_ctx); assert_non_null(test_ctx); test_ctx->ev = tevent_context_init(test_ctx); assert_non_null(test_ctx->ev); test_ctx->ldb = ldb_init(test_ctx, test_ctx->ev); assert_non_null(test_ctx->ldb); test_ctx->domain_sid = talloc_zero(test_ctx, struct dom_sid); assert_non_null(test_ctx->domain_sid); assert_true(string_to_sid(test_ctx->domain_sid, DOMAIN_SID)); ldb_set_opaque(test_ctx->ldb, "cache.domain_sid", test_ctx->domain_sid); test_ctx->module = ldb_module_new( test_ctx, test_ctx->ldb, "unique_object_sids", &ldb_unique_object_sids_module_ops); assert_non_null(test_ctx->module); eol = ldb_module_new(test_ctx, test_ctx->ldb, "eol", &eol_ops); assert_non_null(eol); ldb_module_set_next(test_ctx->module, eol); test_ctx->dbfile = talloc_strdup(test_ctx, "duptest.ldb"); assert_non_null(test_ctx->dbfile); test_ctx->lockfile = talloc_asprintf(test_ctx, "%s-lock", test_ctx->dbfile); assert_non_null(test_ctx->lockfile); test_ctx->dbpath = talloc_asprintf(test_ctx, TEST_BE"://%s", test_ctx->dbfile); assert_non_null(test_ctx->dbpath); unlink_old_db(test_ctx); rc = ldb_connect(test_ctx->ldb, test_ctx->dbpath, 0, NULL); assert_int_equal(rc, LDB_SUCCESS); rc = unique_object_sids_init(test_ctx->module); assert_int_equal(rc, LDB_SUCCESS); *state = test_ctx; last_request = NULL; return 0; }
/* connect to the database */ static int lldb_connect(struct ldb_context *ldb, const char *url, unsigned int flags, const char *options[], struct ldb_module **_module) { struct ldb_module *module; struct lldb_private *lldb; int version = 3; int ret; module = ldb_module_new(ldb, ldb, "ldb_ldap backend", &lldb_ops); if (!module) return LDB_ERR_OPERATIONS_ERROR; lldb = talloc_zero(module, struct lldb_private); if (!lldb) { ldb_oom(ldb); goto failed; } ldb_module_set_private(module, lldb); ret = ldap_initialize(&lldb->ldap, url); if (ret != LDAP_SUCCESS) { ldb_debug(ldb, LDB_DEBUG_FATAL, "ldap_initialize failed for URL '%s' - %s", url, ldap_err2string(ret)); goto failed; } talloc_set_destructor(lldb, lldb_destructor); ret = ldap_set_option(lldb->ldap, LDAP_OPT_PROTOCOL_VERSION, &version); if (ret != LDAP_SUCCESS) { ldb_debug(ldb, LDB_DEBUG_FATAL, "ldap_set_option failed - %s", ldap_err2string(ret)); goto failed; } *_module = module; ret = lldb_bind(module, options); if (ret != LDB_SUCCESS) { goto failed; } return LDB_SUCCESS; failed: talloc_free(module); return LDB_ERR_OPERATIONS_ERROR; }
/* connect to the database */ static int ltdb_connect(struct ldb_context *ldb, const char *url, unsigned int flags, const char *options[], struct ldb_module **_module) { struct ldb_module *module; const char *path; int tdb_flags, open_flags; struct ltdb_private *ltdb; /* parse the url */ if (strchr(url, ':')) { if (strncmp(url, "tdb://", 6) != 0) { ldb_debug(ldb, LDB_DEBUG_ERROR, "Invalid tdb URL '%s'", url); return LDB_ERR_OPERATIONS_ERROR; } path = url+6; } else { path = url; } tdb_flags = TDB_DEFAULT | TDB_SEQNUM; /* check for the 'nosync' option */ if (flags & LDB_FLG_NOSYNC) { tdb_flags |= TDB_NOSYNC; } /* and nommap option */ if (flags & LDB_FLG_NOMMAP) { tdb_flags |= TDB_NOMMAP; } if (flags & LDB_FLG_RDONLY) { open_flags = O_RDONLY; } else { open_flags = O_CREAT | O_RDWR; } ltdb = talloc_zero(ldb, struct ltdb_private); if (!ltdb) { ldb_oom(ldb); return LDB_ERR_OPERATIONS_ERROR; } /* note that we use quite a large default hash size */ ltdb->tdb = ltdb_wrap_open(ltdb, path, 10000, tdb_flags, open_flags, ldb_get_create_perms(ldb), ldb); if (!ltdb->tdb) { ldb_asprintf_errstring(ldb, "Unable to open tdb '%s': %s", path, strerror(errno)); ldb_debug(ldb, LDB_DEBUG_ERROR, "Unable to open tdb '%s': %s", path, strerror(errno)); talloc_free(ltdb); if (errno == EACCES || errno == EPERM) { return LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS; } return LDB_ERR_OPERATIONS_ERROR; } if (getenv("LDB_WARN_UNINDEXED")) { ltdb->warn_unindexed = true; } if (getenv("LDB_WARN_REINDEX")) { ltdb->warn_reindex = true; } ltdb->sequence_number = 0; module = ldb_module_new(ldb, ldb, "ldb_tdb backend", <db_ops); if (!module) { ldb_oom(ldb); talloc_free(ltdb); return LDB_ERR_OPERATIONS_ERROR; } ldb_module_set_private(module, ltdb); talloc_steal(module, ltdb); if (ltdb_cache_load(module) != 0) { ldb_asprintf_errstring(ldb, "Unable to load ltdb cache records of tdb '%s'", path); talloc_free(module); return LDB_ERR_OPERATIONS_ERROR; } *_module = module; return LDB_SUCCESS; }