diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2010-10-10 23:25:38 +0200 |
---|---|---|
committer | Jelmer Vernooij <jelmer@samba.org> | 2010-10-10 23:25:38 +0200 |
commit | c1884f31ea13618cd3a94a30f9c413d176d1e258 (patch) | |
tree | 4c049b69f9f4b44503a0109d579e7893da25c8f7 /source4/lib | |
parent | 7f68870bc939e33df958f708ec7f46253fefadd9 (diff) | |
download | samba-c1884f31ea13618cd3a94a30f9c413d176d1e258.tar.gz samba-c1884f31ea13618cd3a94a30f9c413d176d1e258.tar.bz2 samba-c1884f31ea13618cd3a94a30f9c413d176d1e258.zip |
ldb-samba: Add ldb_wrap_add, remove last schema reference from ldb_wrap.
Diffstat (limited to 'source4/lib')
-rw-r--r-- | source4/lib/ldb-samba/ldb_wrap.c | 122 | ||||
-rw-r--r-- | source4/lib/ldb-samba/ldb_wrap.h | 9 |
2 files changed, 78 insertions, 53 deletions
diff --git a/source4/lib/ldb-samba/ldb_wrap.c b/source4/lib/ldb-samba/ldb_wrap.c index 5aff11229e..7ac94dea2c 100644 --- a/source4/lib/ldb-samba/ldb_wrap.c +++ b/source4/lib/ldb-samba/ldb_wrap.c @@ -107,8 +107,7 @@ static int ldb_wrap_destructor(struct ldb_wrap *w) 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; @@ -164,15 +163,6 @@ static int ldb_wrap_destructor(struct ldb_wrap *w) 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() */ @@ -203,60 +193,51 @@ static int ldb_wrap_destructor(struct ldb_wrap *w) 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; @@ -269,8 +250,7 @@ static int ldb_wrap_destructor(struct ldb_wrap *w) 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) { @@ -283,8 +263,7 @@ static int ldb_wrap_destructor(struct ldb_wrap *w) * ldb modules to use */ if (talloc_reference(w, session_info) == NULL) { - talloc_free(ldb); - return NULL; + return false; } } @@ -292,10 +271,51 @@ static int ldb_wrap_destructor(struct ldb_wrap *w) 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; } diff --git a/source4/lib/ldb-samba/ldb_wrap.h b/source4/lib/ldb-samba/ldb_wrap.h index f576802836..a835f665fc 100644 --- a/source4/lib/ldb-samba/ldb_wrap.h +++ b/source4/lib/ldb-samba/ldb_wrap.h @@ -47,13 +47,18 @@ struct ldb_context *samba_ldb_init(TALLOC_CTX *mem_ctx, 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_ */ |