diff options
Diffstat (limited to 'source4')
-rw-r--r-- | source4/dsdb/samdb/samdb.c | 30 | ||||
-rw-r--r-- | source4/lib/ldb-samba/ldb_wrap.c | 122 | ||||
-rw-r--r-- | source4/lib/ldb-samba/ldb_wrap.h | 9 | ||||
-rw-r--r-- | source4/smbd/server.c | 2 |
4 files changed, 104 insertions, 59 deletions
diff --git a/source4/dsdb/samdb/samdb.c b/source4/dsdb/samdb/samdb.c index 8b0c0fec3f..c2a1e9ec80 100644 --- a/source4/dsdb/samdb/samdb.c +++ b/source4/dsdb/samdb/samdb.c @@ -128,12 +128,27 @@ struct ldb_context *samdb_connect(TALLOC_CTX *mem_ctx, { 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; } @@ -143,6 +158,11 @@ struct ldb_context *samdb_connect(TALLOC_CTX *mem_ctx, 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; } 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_ */ diff --git a/source4/smbd/server.c b/source4/smbd/server.c index 65364556fc..2d837dd1fc 100644 --- a/source4/smbd/server.c +++ b/source4/smbd/server.c @@ -191,7 +191,7 @@ static void prime_ldb_databases(struct tevent_context *event_ctx) TALLOC_CTX *db_context; db_context = talloc_new(event_ctx); - samdb_connect(db_context, event_ctx, cmdline_lp_ctx, system_session(cmdline_lp_ctx)); + samdb_connect(db_context, event_ctx, cmdline_lp_ctx, system_session(cmdline_lp_ctx), 0); privilege_connect(db_context, event_ctx, cmdline_lp_ctx); /* we deliberately leave these open, which allows them to be |