diff options
author | Andrew Tridgell <tridge@samba.org> | 2004-10-16 13:47:00 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 12:59:56 -0500 |
commit | 12ea0fd34cec2d7b6d8c8374dfd95728112585b3 (patch) | |
tree | 108bca68e9642ac4bb301a9f74e8e73d09c08abc /source4/rpc_server/netlogon/schannel_state.c | |
parent | 645067efc69ff510612f7b63cf262cc9d60df700 (diff) | |
download | samba-12ea0fd34cec2d7b6d8c8374dfd95728112585b3.tar.gz samba-12ea0fd34cec2d7b6d8c8374dfd95728112585b3.tar.bz2 samba-12ea0fd34cec2d7b6d8c8374dfd95728112585b3.zip |
r3005: added talloc wrappers around tdb_open() and ldb_connect(), so that the
caller doesn't have to worry about the constraint of only opening a
database a single time in a process. These wrappers will ensure that
only a single open is done, and will auto-close when the last instance
is gone.
When you are finished with a database pointer, use talloc_free() to
close it.
note that this code does not take account of the threads process
model, and does not yet take account of symlinks or hard links to tdb
files.
(This used to be commit 04e1171996612ddb15f84134cadded68f0d173b2)
Diffstat (limited to 'source4/rpc_server/netlogon/schannel_state.c')
-rw-r--r-- | source4/rpc_server/netlogon/schannel_state.c | 48 |
1 files changed, 25 insertions, 23 deletions
diff --git a/source4/rpc_server/netlogon/schannel_state.c b/source4/rpc_server/netlogon/schannel_state.c index 88eabc6d37..1153e4043d 100644 --- a/source4/rpc_server/netlogon/schannel_state.c +++ b/source4/rpc_server/netlogon/schannel_state.c @@ -28,22 +28,22 @@ /* connect to the schannel ldb */ -static struct ldb_context *schannel_db_connect(TALLOC_CTX *mem_ctx) +static struct ldb_wrap *schannel_db_connect(TALLOC_CTX *mem_ctx) { char *path; - struct ldb_context *ldb; + struct ldb_wrap *ldb; path = lock_path(mem_ctx, "schannel.ldb"); if (!path) { return NULL; } - ldb = ldb_connect(path, 0, NULL); + ldb = ldb_wrap_connect(mem_ctx, path, 0, NULL); if (!ldb) { return NULL; } - ldb_set_alloc(ldb, talloc_realloc_fn, mem_ctx); + ldb_set_alloc(ldb->ldb, talloc_realloc_fn, mem_ctx); return ldb; } @@ -56,7 +56,7 @@ NTSTATUS schannel_store_session_key(TALLOC_CTX *mem_ctx, const char *computer_name, struct creds_CredentialState *creds) { - struct ldb_context *ldb; + struct ldb_wrap *ldb; struct ldb_message msg; struct ldb_val val, seed; char *s = NULL; @@ -71,7 +71,7 @@ NTSTATUS schannel_store_session_key(TALLOC_CTX *mem_ctx, asprintf(&s, "%u", (unsigned int)expiry); if (s == NULL) { - ldb_close(ldb); + talloc_free(ldb); return NT_STATUS_NO_MEMORY; } @@ -79,7 +79,7 @@ NTSTATUS schannel_store_session_key(TALLOC_CTX *mem_ctx, ZERO_STRUCT(msg); msg.dn = talloc_strdup(mem_ctx, computer_name); if (msg.dn == NULL) { - ldb_close(ldb); + talloc_free(ldb); return NT_STATUS_NO_MEMORY; } @@ -89,21 +89,23 @@ NTSTATUS schannel_store_session_key(TALLOC_CTX *mem_ctx, seed.data = creds->seed.data; seed.length = sizeof(creds->seed.data); - ldb_msg_add_value(ldb, &msg, "sessionKey", &val); - ldb_msg_add_value(ldb, &msg, "seed", &seed); - ldb_msg_add_string(ldb, &msg, "expiry", s); + ldb_msg_add_value(ldb->ldb, &msg, "sessionKey", &val); + ldb_msg_add_value(ldb->ldb, &msg, "seed", &seed); + ldb_msg_add_string(ldb->ldb, &msg, "expiry", s); - ldb_delete(ldb, msg.dn); + ldb_delete(ldb->ldb, msg.dn); - ret = ldb_add(ldb, &msg); + ret = ldb_add(ldb->ldb, &msg); if (ret != 0) { - DEBUG(0,("Unable to add %s to session key db - %s\n", msg.dn, ldb_errstring(ldb))); - ldb_close(ldb); + DEBUG(0,("Unable to add %s to session key db - %s\n", + msg.dn, ldb_errstring(ldb->ldb))); + talloc_free(ldb); return NT_STATUS_INTERNAL_DB_CORRUPTION; } - ldb_close(ldb); + talloc_free(ldb); + return NT_STATUS_OK; } @@ -115,7 +117,7 @@ NTSTATUS schannel_fetch_session_key(TALLOC_CTX *mem_ctx, const char *computer_name, struct creds_CredentialState *creds) { - struct ldb_context *ldb; + struct ldb_wrap *ldb; time_t expiry; struct ldb_message **res; int ret; @@ -131,26 +133,26 @@ NTSTATUS schannel_fetch_session_key(TALLOC_CTX *mem_ctx, expr = talloc_asprintf(mem_ctx, "(dn=%s)", computer_name); if (expr == NULL) { - ldb_close(ldb); + talloc_free(ldb); return NT_STATUS_NO_MEMORY; } - ret = ldb_search(ldb, NULL, LDB_SCOPE_SUBTREE, expr, NULL, &res); + ret = ldb_search(ldb->ldb, NULL, LDB_SCOPE_SUBTREE, expr, NULL, &res); if (ret != 1) { - ldb_close(ldb); + talloc_free(ldb); return NT_STATUS_INVALID_HANDLE; } expiry = ldb_msg_find_uint(res[0], "expiry", 0); if (expiry < time(NULL)) { DEBUG(1,("schannel: attempt to use expired session key for %s\n", computer_name)); - ldb_close(ldb); + talloc_free(ldb); return NT_STATUS_INVALID_HANDLE; } val = ldb_msg_find_ldb_val(res[0], "sessionKey"); if (val == NULL || val->length != 16) { - ldb_close(ldb); + talloc_free(ldb); return NT_STATUS_INVALID_HANDLE; } @@ -158,13 +160,13 @@ NTSTATUS schannel_fetch_session_key(TALLOC_CTX *mem_ctx, val = ldb_msg_find_ldb_val(res[0], "seed"); if (val == NULL || val->length != 8) { - ldb_close(ldb); + talloc_free(ldb); return NT_STATUS_INVALID_HANDLE; } memcpy(creds->seed.data, val->data, 8); - ldb_close(ldb); + talloc_free(ldb); return NT_STATUS_OK; } |