{
struct ldb_context *ldb;
struct dsdb_schema *schema;
- ldb = ldb_wrap_connect(mem_ctx, ev_ctx, lp_ctx,
- lpcfg_sam_url(lp_ctx), session_info,
- samdb_credentials(ev_ctx, lp_ctx),
- flags);
+ const char *url;
+ struct cli_credentials *credentials;
+ int ret;
- if (!ldb) {
+ url = lpcfg_sam_url(lp_ctx);
+ credentials = samdb_credentials(ev_ctx, lp_ctx);
+
+ ldb = ldb_wrap_find(url, ev_ctx, lp_ctx, session_info, credentials, flags);
+ if (ldb != NULL)
+ return talloc_reference(mem_ctx, ldb);
+
+ ldb = samba_ldb_init(mem_ctx, ev_ctx, lp_ctx, session_info, credentials);
+
+ if (ldb == NULL)
+ return NULL;
+
+ dsdb_set_global_schema(ldb);
+
+ ret = samba_ldb_connect(ldb, lp_ctx, url, flags);
+ if (ret != LDB_SUCCESS) {
+ talloc_free(ldb);
return NULL;
}
dsdb_make_schema_global(ldb, schema);
}
+ if (!ldb_wrap_add(url, ev_ctx, lp_ctx, session_info, credentials, flags, ldb)) {
+ talloc_free(ldb);
+ return NULL;
+ }
+
return ldb;
}
struct tevent_context *ev,
struct loadparm_context *lp_ctx,
struct auth_session_info *session_info,
- struct cli_credentials *credentials,
- int flags
+ struct cli_credentials *credentials
)
{
struct ldb_context *ldb;
return NULL;
}
- /* allow admins to force non-sync ldb for all databases */
- if (lpcfg_parm_bool(lp_ctx, NULL, "ldb", "nosync", false)) {
- flags |= LDB_FLG_NOSYNC;
- }
-
- if (DEBUGLVL(10)) {
- flags |= LDB_FLG_ENABLE_TRACING;
- }
-
/* we usually want Samba databases to be private. If we later
find we need one public, we will need to add a parameter to
ldb_wrap_connect() */
return NULL;
}
-/*
- wrapped connection to a ldb database
- to close just talloc_free() the returned ldb_context
-
- TODO: We need an error_string parameter
- */
- struct ldb_context *ldb_wrap_connect(TALLOC_CTX *mem_ctx,
- struct tevent_context *ev,
- struct loadparm_context *lp_ctx,
- const char *url,
- struct auth_session_info *session_info,
- struct cli_credentials *credentials,
- unsigned int flags)
+int samba_ldb_connect(struct ldb_context *ldb, struct loadparm_context *lp_ctx, const char *url, int flags)
{
- struct ldb_context *ldb;
int ret;
char *real_url = NULL;
- struct ldb_wrap_context c;
- struct ldb_wrap *w;
-
- ldb = ldb_wrap_find(url, ev, lp_ctx, session_info, credentials, flags);
- if (ldb != NULL)
- return talloc_reference(mem_ctx, ldb);
-
- ldb = samba_ldb_init(mem_ctx, ev, lp_ctx, session_info, credentials, flags);
- if (ldb == NULL)
- return NULL;
+ /* allow admins to force non-sync ldb for all databases */
+ if (lpcfg_parm_bool(lp_ctx, NULL, "ldb", "nosync", false)) {
+ flags |= LDB_FLG_NOSYNC;
+ }
- if (lp_ctx != NULL && strcmp(lpcfg_sam_url(lp_ctx), url) == 0) {
- dsdb_set_global_schema(ldb);
+ if (DEBUGLVL(10)) {
+ flags |= LDB_FLG_ENABLE_TRACING;
}
real_url = private_path(ldb, lp_ctx, url);
if (real_url == NULL) {
- talloc_free(ldb);
- return NULL;
+ return LDB_ERR_OPERATIONS_ERROR;
}
-
ret = ldb_connect(ldb, real_url, flags, NULL);
+
if (ret != LDB_SUCCESS) {
- talloc_free(ldb);
- return NULL;
+ return ret;
}
/* setup for leak detection */
ldb_set_opaque(ldb, "wrap_url", real_url);
-
+
+ return LDB_SUCCESS;
+}
+
+ bool ldb_wrap_add(const char *url, struct tevent_context *ev,
+ struct loadparm_context *lp_ctx,
+ struct auth_session_info *session_info,
+ struct cli_credentials *credentials,
+ int flags,
+ struct ldb_context *ldb)
+{
+ struct ldb_wrap *w;
+ struct ldb_wrap_context c;
+
/* add to the list of open ldb contexts */
w = talloc(ldb, struct ldb_wrap);
if (w == NULL) {
- talloc_free(ldb);
- return NULL;
+ return false;
}
c.url = url;
w->context = c;
w->context.url = talloc_strdup(w, url);
if (w->context.url == NULL) {
- talloc_free(ldb);
- return NULL;
+ return false;
}
if (session_info) {
* ldb modules to use
*/
if (talloc_reference(w, session_info) == NULL) {
- talloc_free(ldb);
- return NULL;
+ return false;
}
}
DLIST_ADD(ldb_wrap_list, w);
- DEBUG(3,("ldb_wrap open of %s\n", url));
-
talloc_set_destructor(w, ldb_wrap_destructor);
+ return true;
+}
+
+
+/*
+ wrapped connection to a ldb database
+ to close just talloc_free() the returned ldb_context
+
+ TODO: We need an error_string parameter
+ */
+ struct ldb_context *ldb_wrap_connect(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct loadparm_context *lp_ctx,
+ const char *url,
+ struct auth_session_info *session_info,
+ struct cli_credentials *credentials,
+ unsigned int flags)
+{
+ struct ldb_context *ldb;
+ int ret;
+
+ ldb = ldb_wrap_find(url, ev, lp_ctx, session_info, credentials, flags);
+ if (ldb != NULL)
+ return talloc_reference(mem_ctx, ldb);
+
+ ldb = samba_ldb_init(mem_ctx, ev, lp_ctx, session_info, credentials);
+
+ if (ldb == NULL)
+ return NULL;
+
+ ret = samba_ldb_connect(ldb, lp_ctx, url, flags);
+ if (ret != LDB_SUCCESS) {
+ talloc_free(ldb);
+ return NULL;
+ }
+
+ if (!ldb_wrap_add(url, ev, lp_ctx, session_info, credentials, flags, ldb)) {
+ talloc_free(ldb);
+ return NULL;
+ }
+
+ DEBUG(3,("ldb_wrap open of %s\n", url));
+
return ldb;
}
struct tevent_context *ev,
struct loadparm_context *lp_ctx,
struct auth_session_info *session_info,
- struct cli_credentials *credentials,
- int flags);
+ struct cli_credentials *credentials);
struct ldb_context *ldb_wrap_find(const char *url,
struct tevent_context *ev,
struct loadparm_context *lp_ctx,
struct auth_session_info *session_info,
struct cli_credentials *credentials,
int flags);
+bool ldb_wrap_add(const char *url, struct tevent_context *ev,
+ struct loadparm_context *lp_ctx,
+ struct auth_session_info *session_info,
+ struct cli_credentials *credentials,
+ int flags,
+ struct ldb_context *ldb);
#endif /* _LDB_WRAP_H_ */