summaryrefslogtreecommitdiff
path: root/source4/rpc_server/samr/samdb.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2004-08-25 06:44:23 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:58:21 -0500
commitede02ee03867d2f6582c446fcab0882072baaa5a (patch)
treeea7e56a1b9f1552cc9752cf8736084555005518c /source4/rpc_server/samr/samdb.c
parent294f6f16947c56d3fac5b24e5c95e8df522e18d6 (diff)
downloadsamba-ede02ee03867d2f6582c446fcab0882072baaa5a.tar.gz
samba-ede02ee03867d2f6582c446fcab0882072baaa5a.tar.bz2
samba-ede02ee03867d2f6582c446fcab0882072baaa5a.zip
r2051: switched the samdb over to using the new destructor and reference
count features of talloc, instead of re-implementing both those features inside of samdb (which is what we did before). This makes samdb considerably simpler, and also fixes some bugs, as I found some error paths that didn't call samdb_close(). Those are now handled by the fact that a talloc_free() will auto-close and destroy the samdb context, using a destructor. (This used to be commit da60987a92266734c33b81ee217081abdc4330f3)
Diffstat (limited to 'source4/rpc_server/samr/samdb.c')
-rw-r--r--source4/rpc_server/samr/samdb.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/source4/rpc_server/samr/samdb.c b/source4/rpc_server/samr/samdb.c
index c02692703c..7be75258af 100644
--- a/source4/rpc_server/samr/samdb.c
+++ b/source4/rpc_server/samr/samdb.c
@@ -42,11 +42,20 @@ void samdb_debug(void *context, enum ldb_debug_level level, const char *fmt, va_
free(s);
}
+/* close a connection to the sam */
+int samdb_destructor(void *ctx)
+{
+ struct samdb_context *sam_ctx = ctx;
+ /* we don't actually close due to broken posix locking semantics */
+ sam_ctx->ldb = NULL;
+ return 0;
+}
+
/*
connect to the SAM database
return an opaque context pointer on success, or NULL on failure
*/
-void *samdb_connect(void)
+void *samdb_connect(TALLOC_CTX *mem_ctx)
{
struct samdb_context *ctx;
/*
@@ -68,26 +77,18 @@ void *samdb_connect(void)
ldb_set_debug(static_sam_db, samdb_debug, NULL);
- ctx = malloc_p(struct samdb_context);
+ ctx = talloc_p(NULL, struct samdb_context);
if (!ctx) {
errno = ENOMEM;
return NULL;
}
ctx->ldb = static_sam_db;
+ talloc_set_destructor(ctx, samdb_destructor);
return ctx;
}
-/* close a connection to the sam */
-void samdb_close(void *ctx)
-{
- struct samdb_context *sam_ctx = ctx;
- /* we don't actually close due to broken posix locking semantics */
- sam_ctx->ldb = NULL;
- free(sam_ctx);
-}
-
/*
search the sam for the specified attributes - varargs variant
*/