summaryrefslogtreecommitdiff
path: root/source4/auth
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2009-04-06 22:51:32 +1000
committerAndrew Bartlett <abartlet@samba.org>2009-04-14 16:23:43 +1000
commitf23eea294a64fac3cc85609468703fc15f7e3187 (patch)
tree4817c3ef645ed99259c4bbdce25765ae831b0dd5 /source4/auth
parentdf8e1908ef9969ce95a5102959c27491fa7bfa03 (diff)
downloadsamba-f23eea294a64fac3cc85609468703fc15f7e3187.tar.gz
samba-f23eea294a64fac3cc85609468703fc15f7e3187.tar.bz2
samba-f23eea294a64fac3cc85609468703fc15f7e3187.zip
Push schannel_state.c into the top level.
This is the server side state for netlogon credential chaining Andrew Bartlett
Diffstat (limited to 'source4/auth')
-rw-r--r--source4/auth/gensec/config.mk2
-rw-r--r--source4/auth/gensec/schannel_state.c283
2 files changed, 1 insertions, 284 deletions
diff --git a/source4/auth/gensec/config.mk b/source4/auth/gensec/config.mk
index 27cf442b68..a9ce228f12 100644
--- a/source4/auth/gensec/config.mk
+++ b/source4/auth/gensec/config.mk
@@ -78,7 +78,7 @@ $(eval $(call proto_header_template,$(gensecsrcdir)/schannel_proto.h,$(gensec_sc
################################################
# Start SUBSYSTEM SCHANNELDB
[SUBSYSTEM::SCHANNELDB]
-PRIVATE_DEPENDENCIES = LDB_WRAP
+PRIVATE_DEPENDENCIES = LDB_WRAP COMMON_SCHANNELDB
# End SUBSYSTEM SCHANNELDB
################################################
diff --git a/source4/auth/gensec/schannel_state.c b/source4/auth/gensec/schannel_state.c
index ca8537cac9..1320db8933 100644
--- a/source4/auth/gensec/schannel_state.c
+++ b/source4/auth/gensec/schannel_state.c
@@ -21,7 +21,6 @@
#include "includes.h"
#include "lib/ldb/include/ldb.h"
-#include "librpc/gen_ndr/ndr_security.h"
#include "ldb_wrap.h"
#include "../lib/util/util_ldb.h"
#include "libcli/auth/libcli_auth.h"
@@ -29,45 +28,6 @@
#include "param/param.h"
#include "auth/gensec/schannel_state.h"
-static struct ldb_val *schannel_dom_sid_ldb_val(TALLOC_CTX *mem_ctx,
- struct smb_iconv_convenience *smbiconv,
- struct dom_sid *sid)
-{
- enum ndr_err_code ndr_err;
- struct ldb_val *v;
-
- v = talloc(mem_ctx, struct ldb_val);
- if (!v) return NULL;
-
- ndr_err = ndr_push_struct_blob(v, mem_ctx, smbiconv, sid,
- (ndr_push_flags_fn_t)ndr_push_dom_sid);
- if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
- talloc_free(v);
- return NULL;
- }
-
- return v;
-}
-
-static struct dom_sid *schannel_ldb_val_dom_sid(TALLOC_CTX *mem_ctx,
- const struct ldb_val *v)
-{
- enum ndr_err_code ndr_err;
- struct dom_sid *sid;
-
- sid = talloc(mem_ctx, struct dom_sid);
- if (!sid) return NULL;
-
- ndr_err = ndr_pull_struct_blob(v, sid, NULL, sid,
- (ndr_pull_flags_fn_t)ndr_pull_dom_sid);
- if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
- talloc_free(sid);
- return NULL;
- }
- return sid;
-}
-
-
/**
connect to the schannel ldb
*/
@@ -104,246 +64,3 @@ struct ldb_context *schannel_db_connect(TALLOC_CTX *mem_ctx, struct tevent_conte
return ldb;
}
-/*
- remember an established session key for a netr server authentication
- use a simple ldb structure
-*/
-NTSTATUS schannel_store_session_key_ldb(TALLOC_CTX *mem_ctx,
- struct ldb_context *ldb,
- struct creds_CredentialState *creds)
-{
- struct ldb_message *msg;
- struct ldb_val val, seed, client_state, server_state;
- struct smb_iconv_convenience *smbiconv;
- struct ldb_val *sid_val;
- char *f;
- char *sct;
- int ret;
-
- f = talloc_asprintf(mem_ctx, "%u", (unsigned int)creds->negotiate_flags);
-
- if (f == NULL) {
- return NT_STATUS_NO_MEMORY;
- }
-
- sct = talloc_asprintf(mem_ctx, "%u", (unsigned int)creds->secure_channel_type);
-
- if (sct == NULL) {
- return NT_STATUS_NO_MEMORY;
- }
-
- msg = ldb_msg_new(ldb);
- if (msg == NULL) {
- return NT_STATUS_NO_MEMORY;
- }
-
- msg->dn = ldb_dn_new_fmt(msg, ldb, "computerName=%s", creds->computer_name);
- if ( ! msg->dn) {
- return NT_STATUS_NO_MEMORY;
- }
-
- smbiconv = lp_iconv_convenience(ldb_get_opaque(ldb, "loadparm"));
- sid_val = schannel_dom_sid_ldb_val(msg, smbiconv, creds->sid);
- if (sid_val == NULL) {
- return NT_STATUS_NO_MEMORY;
- }
-
- val.data = creds->session_key;
- val.length = sizeof(creds->session_key);
-
- seed.data = creds->seed.data;
- seed.length = sizeof(creds->seed.data);
-
- client_state.data = creds->client.data;
- client_state.length = sizeof(creds->client.data);
- server_state.data = creds->server.data;
- server_state.length = sizeof(creds->server.data);
-
- ldb_msg_add_string(msg, "objectClass", "schannelState");
- ldb_msg_add_value(msg, "sessionKey", &val, NULL);
- ldb_msg_add_value(msg, "seed", &seed, NULL);
- ldb_msg_add_value(msg, "clientState", &client_state, NULL);
- ldb_msg_add_value(msg, "serverState", &server_state, NULL);
- ldb_msg_add_string(msg, "negotiateFlags", f);
- ldb_msg_add_string(msg, "secureChannelType", sct);
- ldb_msg_add_string(msg, "accountName", creds->account_name);
- ldb_msg_add_string(msg, "computerName", creds->computer_name);
- ldb_msg_add_string(msg, "flatname", creds->domain);
- ldb_msg_add_value(msg, "objectSid", sid_val, NULL);
-
- ldb_delete(ldb, msg->dn);
-
- ret = ldb_add(ldb, msg);
-
- if (ret != 0) {
- DEBUG(0,("Unable to add %s to session key db - %s\n",
- ldb_dn_get_linearized(msg->dn), ldb_errstring(ldb)));
- return NT_STATUS_INTERNAL_DB_CORRUPTION;
- }
-
- return NT_STATUS_OK;
-}
-
-NTSTATUS schannel_store_session_key(TALLOC_CTX *mem_ctx,
- struct tevent_context *ev_ctx,
- struct loadparm_context *lp_ctx,
- struct creds_CredentialState *creds)
-{
- struct ldb_context *ldb;
- NTSTATUS nt_status;
- int ret;
-
- ldb = schannel_db_connect(mem_ctx, ev_ctx, lp_ctx);
- if (!ldb) {
- return NT_STATUS_ACCESS_DENIED;
- }
-
- ret = ldb_transaction_start(ldb);
- if (ret != 0) {
- talloc_free(ldb);
- return NT_STATUS_INTERNAL_DB_CORRUPTION;
- }
-
- nt_status = schannel_store_session_key_ldb(mem_ctx, ldb, creds);
-
- if (NT_STATUS_IS_OK(nt_status)) {
- ret = ldb_transaction_commit(ldb);
- } else {
- ret = ldb_transaction_cancel(ldb);
- }
-
- if (ret != 0) {
- DEBUG(0,("Unable to commit adding credentials for %s to schannel key db - %s\n",
- creds->computer_name, ldb_errstring(ldb)));
- talloc_free(ldb);
- return NT_STATUS_INTERNAL_DB_CORRUPTION;
- }
-
- talloc_free(ldb);
- return nt_status;
-}
-
-/*
- read back a credentials back for a computer
-*/
-NTSTATUS schannel_fetch_session_key_ldb(TALLOC_CTX *mem_ctx,
- struct ldb_context *ldb,
- const char *computer_name,
- const char *domain,
- struct creds_CredentialState **creds)
-{
- struct ldb_result *res;
- int ret;
- const struct ldb_val *val;
-
- *creds = talloc_zero(mem_ctx, struct creds_CredentialState);
- if (!*creds) {
- return NT_STATUS_NO_MEMORY;
- }
-
- ret = ldb_search(ldb, mem_ctx, &res,
- NULL, LDB_SCOPE_SUBTREE, NULL,
- "(&(computerName=%s)(flatname=%s))", computer_name, domain);
- if (ret != LDB_SUCCESS) {
- DEBUG(3,("schannel: Failed to find a record for client %s: %s\n", computer_name, ldb_errstring(ldb)));
- return NT_STATUS_INVALID_HANDLE;
- }
- if (res->count != 1) {
- DEBUG(3,("schannel: Failed to find a record for client: %s (found %d records)\n", computer_name, res->count));
- talloc_free(res);
- return NT_STATUS_INVALID_HANDLE;
- }
-
- val = ldb_msg_find_ldb_val(res->msgs[0], "sessionKey");
- if (val == NULL || val->length != 16) {
- DEBUG(1,("schannel: record in schannel DB must contain a sessionKey of length 16, when searching for client: %s\n", computer_name));
- talloc_free(res);
- return NT_STATUS_INTERNAL_ERROR;
- }
-
- memcpy((*creds)->session_key, val->data, 16);
-
- val = ldb_msg_find_ldb_val(res->msgs[0], "seed");
- if (val == NULL || val->length != 8) {
- DEBUG(1,("schannel: record in schannel DB must contain a vaid seed of length 8, when searching for client: %s\n", computer_name));
- talloc_free(res);
- return NT_STATUS_INTERNAL_ERROR;
- }
-
- memcpy((*creds)->seed.data, val->data, 8);
-
- val = ldb_msg_find_ldb_val(res->msgs[0], "clientState");
- if (val == NULL || val->length != 8) {
- DEBUG(1,("schannel: record in schannel DB must contain a vaid clientState of length 8, when searching for client: %s\n", computer_name));
- talloc_free(res);
- return NT_STATUS_INTERNAL_ERROR;
- }
- memcpy((*creds)->client.data, val->data, 8);
-
- val = ldb_msg_find_ldb_val(res->msgs[0], "serverState");
- if (val == NULL || val->length != 8) {
- DEBUG(1,("schannel: record in schannel DB must contain a vaid serverState of length 8, when searching for client: %s\n", computer_name));
- talloc_free(res);
- return NT_STATUS_INTERNAL_ERROR;
- }
- memcpy((*creds)->server.data, val->data, 8);
-
- (*creds)->negotiate_flags = ldb_msg_find_attr_as_int(res->msgs[0], "negotiateFlags", 0);
-
- (*creds)->secure_channel_type = ldb_msg_find_attr_as_int(res->msgs[0], "secureChannelType", 0);
-
- (*creds)->account_name = talloc_strdup(*creds, ldb_msg_find_attr_as_string(res->msgs[0], "accountName", NULL));
- if ((*creds)->account_name == NULL) {
- talloc_free(res);
- return NT_STATUS_NO_MEMORY;
- }
-
- (*creds)->computer_name = talloc_strdup(*creds, ldb_msg_find_attr_as_string(res->msgs[0], "computerName", NULL));
- if ((*creds)->computer_name == NULL) {
- talloc_free(res);
- return NT_STATUS_NO_MEMORY;
- }
-
- (*creds)->domain = talloc_strdup(*creds, ldb_msg_find_attr_as_string(res->msgs[0], "flatname", NULL));
- if ((*creds)->domain == NULL) {
- talloc_free(res);
- return NT_STATUS_NO_MEMORY;
- }
-
- val = ldb_msg_find_ldb_val(res->msgs[0], "objectSid");
- if (val == NULL) {
- DEBUG(1,("schannel: missing ObjectSid for client: %s\n", computer_name));
- talloc_free(res);
- return NT_STATUS_INTERNAL_ERROR;
- }
- (*creds)->sid = schannel_ldb_val_dom_sid(*creds, val);
- if ((*creds)->sid == NULL) {
- talloc_free(res);
- return NT_STATUS_INTERNAL_ERROR;
- }
-
- talloc_free(res);
- return NT_STATUS_OK;
-}
-
-NTSTATUS schannel_fetch_session_key(TALLOC_CTX *mem_ctx,
- struct tevent_context *ev_ctx,
- struct loadparm_context *lp_ctx,
- const char *computer_name,
- const char *domain,
- struct creds_CredentialState **creds)
-{
- NTSTATUS nt_status;
- struct ldb_context *ldb;
-
- ldb = schannel_db_connect(mem_ctx, ev_ctx, lp_ctx);
- if (!ldb) {
- return NT_STATUS_ACCESS_DENIED;
- }
-
- nt_status = schannel_fetch_session_key_ldb(mem_ctx, ldb,
- computer_name, domain,
- creds);
- talloc_free(ldb);
- return nt_status;
-}