summaryrefslogtreecommitdiff
path: root/source4/auth
diff options
context:
space:
mode:
Diffstat (limited to 'source4/auth')
-rw-r--r--source4/auth/credentials/credentials.c4
-rw-r--r--source4/auth/credentials/credentials.h6
-rw-r--r--source4/auth/gensec/config.mk2
-rw-r--r--source4/auth/gensec/gensec.h4
-rw-r--r--source4/auth/gensec/schannel.c31
-rw-r--r--source4/auth/gensec/schannel.h6
-rw-r--r--source4/auth/gensec/schannel_state.c283
-rw-r--r--source4/auth/ntlm/auth_sam.c2
-rw-r--r--source4/auth/ntlm/config.mk5
-rw-r--r--source4/auth/ntlm/ntlm_check.c603
-rw-r--r--source4/auth/ntlm/ntlm_check.h76
-rw-r--r--source4/auth/ntlmssp/config.mk6
-rw-r--r--source4/auth/ntlmssp/ntlmssp.h5
-rw-r--r--source4/auth/ntlmssp/ntlmssp_parse.c368
14 files changed, 34 insertions, 1367 deletions
diff --git a/source4/auth/credentials/credentials.c b/source4/auth/credentials/credentials.c
index 5fb180d7b1..83901db6a5 100644
--- a/source4/auth/credentials/credentials.c
+++ b/source4/auth/credentials/credentials.c
@@ -668,7 +668,7 @@ _PUBLIC_ void cli_credentials_guess(struct cli_credentials *cred,
*/
_PUBLIC_ void cli_credentials_set_netlogon_creds(struct cli_credentials *cred,
- struct creds_CredentialState *netlogon_creds)
+ struct netlogon_creds_CredentialState *netlogon_creds)
{
cred->netlogon_creds = talloc_reference(cred, netlogon_creds);
}
@@ -677,7 +677,7 @@ _PUBLIC_ void cli_credentials_set_netlogon_creds(struct cli_credentials *cred,
* Return attached NETLOGON credentials
*/
-struct creds_CredentialState *cli_credentials_get_netlogon_creds(struct cli_credentials *cred)
+struct netlogon_creds_CredentialState *cli_credentials_get_netlogon_creds(struct cli_credentials *cred)
{
return cred->netlogon_creds;
}
diff --git a/source4/auth/credentials/credentials.h b/source4/auth/credentials/credentials.h
index 3c2fb8f2e6..311cdc2450 100644
--- a/source4/auth/credentials/credentials.h
+++ b/source4/auth/credentials/credentials.h
@@ -102,7 +102,7 @@ struct cli_credentials {
/* Private handle for the callback routines to use */
void *priv_data;
- struct creds_CredentialState *netlogon_creds;
+ struct netlogon_creds_CredentialState *netlogon_creds;
enum netr_SchannelType secure_channel_type;
int kvno;
@@ -167,7 +167,7 @@ int cli_credentials_get_keytab(struct cli_credentials *cred,
struct loadparm_context *lp_ctx,
struct keytab_container **_ktc);
const char *cli_credentials_get_domain(struct cli_credentials *cred);
-struct creds_CredentialState *cli_credentials_get_netlogon_creds(struct cli_credentials *cred);
+struct netlogon_creds_CredentialState *cli_credentials_get_netlogon_creds(struct cli_credentials *cred);
void cli_credentials_set_machine_account_pending(struct cli_credentials *cred,
struct loadparm_context *lp_ctx);
void cli_credentials_set_conf(struct cli_credentials *cred,
@@ -210,7 +210,7 @@ bool cli_credentials_set_realm(struct cli_credentials *cred,
void cli_credentials_set_secure_channel_type(struct cli_credentials *cred,
enum netr_SchannelType secure_channel_type);
void cli_credentials_set_netlogon_creds(struct cli_credentials *cred,
- struct creds_CredentialState *netlogon_creds);
+ struct netlogon_creds_CredentialState *netlogon_creds);
NTSTATUS cli_credentials_set_krb5_context(struct cli_credentials *cred,
struct smb_krb5_context *smb_krb5_context);
NTSTATUS cli_credentials_set_stored_principal(struct cli_credentials *cred,
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/gensec.h b/source4/auth/gensec/gensec.h
index c4e93ee97b..3b27e0f733 100644
--- a/source4/auth/gensec/gensec.h
+++ b/source4/auth/gensec/gensec.h
@@ -284,10 +284,10 @@ NTSTATUS gensec_server_start(TALLOC_CTX *mem_ctx,
NTSTATUS gensec_session_info(struct gensec_security *gensec_security,
struct auth_session_info **session_info);
NTSTATUS auth_nt_status_squash(NTSTATUS nt_status);
-struct creds_CredentialState;
+struct netlogon_creds_CredentialState;
NTSTATUS dcerpc_schannel_creds(struct gensec_security *gensec_security,
TALLOC_CTX *mem_ctx,
- struct creds_CredentialState **creds);
+ struct netlogon_creds_CredentialState **creds);
NTSTATUS gensec_set_peer_addr(struct gensec_security *gensec_security, struct socket_address *peer_addr);
NTSTATUS gensec_set_my_addr(struct gensec_security *gensec_security, struct socket_address *my_addr);
diff --git a/source4/auth/gensec/schannel.c b/source4/auth/gensec/schannel.c
index e6d38c14a3..08fce2f049 100644
--- a/source4/auth/gensec/schannel.c
+++ b/source4/auth/gensec/schannel.c
@@ -27,8 +27,6 @@
#include "auth/gensec/gensec.h"
#include "auth/gensec/gensec_proto.h"
#include "auth/gensec/schannel.h"
-#include "auth/gensec/schannel_state.h"
-#include "auth/gensec/schannel_proto.h"
#include "librpc/rpc/dcerpc.h"
#include "param/param.h"
#include "auth/session_proto.h"
@@ -52,8 +50,8 @@ static NTSTATUS schannel_update(struct gensec_security *gensec_security, TALLOC_
enum ndr_err_code ndr_err;
struct schannel_bind bind_schannel;
struct schannel_bind_ack bind_schannel_ack;
- struct creds_CredentialState *creds;
-
+ struct netlogon_creds_CredentialState *creds;
+ struct ldb_context *schannel_ldb;
const char *workstation;
const char *domain;
*out = data_blob(NULL, 0);
@@ -124,10 +122,22 @@ static NTSTATUS schannel_update(struct gensec_security *gensec_security, TALLOC_
domain = bind_schannel.u.info3.domain;
}
+ if (strcasecmp_m(domain, lp_workgroup(gensec_security->settings->lp_ctx)) != 0) {
+ DEBUG(3, ("Request for schannel to incorrect domain: %s != our domain %s\n",
+ domain, lp_workgroup(gensec_security->settings->lp_ctx)));
+
+ return NT_STATUS_LOGON_FAILURE;
+ }
+
+ schannel_ldb = schannel_db_connect(out_mem_ctx, gensec_security->event_ctx,
+ gensec_security->settings->lp_ctx);
+ if (!schannel_ldb) {
+ return NT_STATUS_ACCESS_DENIED;
+ }
/* pull the session key for this client */
- status = schannel_fetch_session_key(out_mem_ctx, gensec_security->event_ctx,
- gensec_security->settings->lp_ctx, workstation,
- domain, &creds);
+ status = schannel_fetch_session_key(schannel_ldb,
+ out_mem_ctx, workstation, &creds);
+ talloc_free(schannel_ldb);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(3, ("Could not find session key for attempted schannel connection from %s: %s\n",
workstation, nt_errstr(status)));
@@ -161,15 +171,16 @@ static NTSTATUS schannel_update(struct gensec_security *gensec_security, TALLOC_
}
/**
- * Return the struct creds_CredentialState.
+ * Return the struct netlogon_creds_CredentialState.
*
* Make sure not to call this unless gensec is using schannel...
*/
/* TODO: make this non-public */
+
_PUBLIC_ NTSTATUS dcerpc_schannel_creds(struct gensec_security *gensec_security,
- TALLOC_CTX *mem_ctx,
- struct creds_CredentialState **creds)
+ TALLOC_CTX *mem_ctx,
+ struct netlogon_creds_CredentialState **creds)
{
struct schannel_state *state = talloc_get_type(gensec_security->private_data, struct schannel_state);
diff --git a/source4/auth/gensec/schannel.h b/source4/auth/gensec/schannel.h
index 2ddea29006..ee841ef639 100644
--- a/source4/auth/gensec/schannel.h
+++ b/source4/auth/gensec/schannel.h
@@ -20,7 +20,9 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "libcli/auth/credentials.h"
+#include "auth/gensec/schannel_proto.h"
+#include "auth/gensec/schannel_state.h"
+#include "libcli/auth/schannel_state.h"
enum schannel_position {
SCHANNEL_STATE_START = 0,
@@ -31,6 +33,6 @@ struct schannel_state {
enum schannel_position state;
uint32_t seq_num;
bool initiator;
- struct creds_CredentialState *creds;
+ struct netlogon_creds_CredentialState *creds;
};
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;
-}
diff --git a/source4/auth/ntlm/auth_sam.c b/source4/auth/ntlm/auth_sam.c
index 96a13d5ed9..2b9b92812c 100644
--- a/source4/auth/ntlm/auth_sam.c
+++ b/source4/auth/ntlm/auth_sam.c
@@ -25,7 +25,7 @@
#include "lib/ldb/include/ldb.h"
#include "../lib/util/util_ldb.h"
#include "auth/auth.h"
-#include "auth/ntlm/ntlm_check.h"
+#include "../libcli/auth/ntlm_check.h"
#include "auth/ntlm/auth_proto.h"
#include "auth/auth_sam.h"
#include "dsdb/samdb/samdb.h"
diff --git a/source4/auth/ntlm/config.mk b/source4/auth/ntlm/config.mk
index 668c528ea9..a9ae18e7c2 100644
--- a/source4/auth/ntlm/config.mk
+++ b/source4/auth/ntlm/config.mk
@@ -1,10 +1,5 @@
# NTLM auth server subsystem
-[SUBSYSTEM::ntlm_check]
-PRIVATE_DEPENDENCIES = LIBSAMBA-UTIL
-
-ntlm_check_OBJ_FILES = $(addprefix $(authsrcdir)/ntlm/, ntlm_check.o)
-
#######################
# Start MODULE auth_sam
[MODULE::auth_sam_module]
diff --git a/source4/auth/ntlm/ntlm_check.c b/source4/auth/ntlm/ntlm_check.c
deleted file mode 100644
index 0805b1b043..0000000000
--- a/source4/auth/ntlm/ntlm_check.c
+++ /dev/null
@@ -1,603 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
- Password and authentication handling
- Copyright (C) Andrew Bartlett <abartlet@samba.org> 2001-2004
- Copyright (C) Gerald Carter 2003
- Copyright (C) Luke Kenneth Casson Leighton 1996-2000
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#include "includes.h"
-#include "../lib/crypto/crypto.h"
-#include "librpc/gen_ndr/netlogon.h"
-#include "libcli/auth/libcli_auth.h"
-#include "auth/ntlm/ntlm_check.h"
-
-/****************************************************************************
- Core of smb password checking routine.
-****************************************************************************/
-
-static bool smb_pwd_check_ntlmv1(TALLOC_CTX *mem_ctx,
- const DATA_BLOB *nt_response,
- const uint8_t *part_passwd,
- const DATA_BLOB *sec_blob,
- DATA_BLOB *user_sess_key)
-{
- /* Finish the encryption of part_passwd. */
- uint8_t p24[24];
-
- if (part_passwd == NULL) {
- DEBUG(10,("No password set - DISALLOWING access\n"));
- /* No password set - always false ! */
- return false;
- }
-
- if (sec_blob->length != 8) {
- DEBUG(0, ("smb_pwd_check_ntlmv1: incorrect challenge size (%lu)\n",
- (unsigned long)sec_blob->length));
- return false;
- }
-
- if (nt_response->length != 24) {
- DEBUG(0, ("smb_pwd_check_ntlmv1: incorrect password length (%lu)\n",
- (unsigned long)nt_response->length));
- return false;
- }
-
- SMBOWFencrypt(part_passwd, sec_blob->data, p24);
-
-#if DEBUG_PASSWORD
- DEBUG(100,("Part password (P16) was |\n"));
- dump_data(100, part_passwd, 16);
- DEBUGADD(100,("Password from client was |\n"));
- dump_data(100, nt_response->data, nt_response->length);
- DEBUGADD(100,("Given challenge was |\n"));
- dump_data(100, sec_blob->data, sec_blob->length);
- DEBUGADD(100,("Value from encryption was |\n"));
- dump_data(100, p24, 24);
-#endif
- if (memcmp(p24, nt_response->data, 24) == 0) {
- if (user_sess_key != NULL) {
- *user_sess_key = data_blob_talloc(mem_ctx, NULL, 16);
- SMBsesskeygen_ntv1(part_passwd, user_sess_key->data);
- }
- return true;
- }
- return false;
-}
-
-/****************************************************************************
- Core of smb password checking routine. (NTLMv2, LMv2)
- Note: The same code works with both NTLMv2 and LMv2.
-****************************************************************************/
-
-static bool smb_pwd_check_ntlmv2(TALLOC_CTX *mem_ctx,
- const DATA_BLOB *ntv2_response,
- const uint8_t *part_passwd,
- const DATA_BLOB *sec_blob,
- const char *user, const char *domain,
- bool upper_case_domain, /* should the domain be transformed into upper case? */
- DATA_BLOB *user_sess_key)
-{
- /* Finish the encryption of part_passwd. */
- uint8_t kr[16];
- uint8_t value_from_encryption[16];
- DATA_BLOB client_key_data;
-
- if (part_passwd == NULL) {
- DEBUG(10,("No password set - DISALLOWING access\n"));
- /* No password set - always false */
- return false;
- }
-
- if (sec_blob->length != 8) {
- DEBUG(0, ("smb_pwd_check_ntlmv2: incorrect challenge size (%lu)\n",
- (unsigned long)sec_blob->length));
- return false;
- }
-
- if (ntv2_response->length < 24) {
- /* We MUST have more than 16 bytes, or the stuff below will go
- crazy. No known implementation sends less than the 24 bytes
- for LMv2, let alone NTLMv2. */
- DEBUG(0, ("smb_pwd_check_ntlmv2: incorrect password length (%lu)\n",
- (unsigned long)ntv2_response->length));
- return false;
- }
-
- client_key_data = data_blob_talloc(mem_ctx, ntv2_response->data+16, ntv2_response->length-16);
- /*
- todo: should we be checking this for anything? We can't for LMv2,
- but for NTLMv2 it is meant to contain the current time etc.
- */
-
- if (!ntv2_owf_gen(part_passwd, user, domain, upper_case_domain, kr)) {
- return false;
- }
-
- SMBOWFencrypt_ntv2(kr, sec_blob, &client_key_data, value_from_encryption);
-
-#if DEBUG_PASSWORD
- DEBUG(100,("Part password (P16) was |\n"));
- dump_data(100, part_passwd, 16);
- DEBUGADD(100,("Password from client was |\n"));
- dump_data(100, ntv2_response->data, ntv2_response->length);
- DEBUGADD(100,("Variable data from client was |\n"));
- dump_data(100, client_key_data.data, client_key_data.length);
- DEBUGADD(100,("Given challenge was |\n"));
- dump_data(100, sec_blob->data, sec_blob->length);
- DEBUGADD(100,("Value from encryption was |\n"));
- dump_data(100, value_from_encryption, 16);
-#endif
- data_blob_clear_free(&client_key_data);
- if (memcmp(value_from_encryption, ntv2_response->data, 16) == 0) {
- if (user_sess_key != NULL) {
- *user_sess_key = data_blob_talloc(mem_ctx, NULL, 16);
- SMBsesskeygen_ntv2(kr, value_from_encryption, user_sess_key->data);
- }
- return true;
- }
- return false;
-}
-
-/****************************************************************************
- Core of smb password checking routine. (NTLMv2, LMv2)
- Note: The same code works with both NTLMv2 and LMv2.
-****************************************************************************/
-
-static bool smb_sess_key_ntlmv2(TALLOC_CTX *mem_ctx,
- const DATA_BLOB *ntv2_response,
- const uint8_t *part_passwd,
- const DATA_BLOB *sec_blob,
- const char *user, const char *domain,
- bool upper_case_domain, /* should the domain be transformed into upper case? */
- DATA_BLOB *user_sess_key)
-{
- /* Finish the encryption of part_passwd. */
- uint8_t kr[16];
- uint8_t value_from_encryption[16];
- DATA_BLOB client_key_data;
-
- if (part_passwd == NULL) {
- DEBUG(10,("No password set - DISALLOWING access\n"));
- /* No password set - always false */
- return false;
- }
-
- if (sec_blob->length != 8) {
- DEBUG(0, ("smb_sess_key_ntlmv2: incorrect challenge size (%lu)\n",
- (unsigned long)sec_blob->length));
- return false;
- }
-
- if (ntv2_response->length < 24) {
- /* We MUST have more than 16 bytes, or the stuff below will go
- crazy. No known implementation sends less than the 24 bytes
- for LMv2, let alone NTLMv2. */
- DEBUG(0, ("smb_sess_key_ntlmv2: incorrect password length (%lu)\n",
- (unsigned long)ntv2_response->length));
- return false;
- }
-
- client_key_data = data_blob_talloc(mem_ctx, ntv2_response->data+16, ntv2_response->length-16);
-
- if (!ntv2_owf_gen(part_passwd, user, domain, upper_case_domain, kr)) {
- return false;
- }
-
- SMBOWFencrypt_ntv2(kr, sec_blob, &client_key_data, value_from_encryption);
- *user_sess_key = data_blob_talloc(mem_ctx, NULL, 16);
- SMBsesskeygen_ntv2(kr, value_from_encryption, user_sess_key->data);
- return true;
-}
-
-/**
- * Compare password hashes against those from the SAM
- *
- * @param mem_ctx talloc context
- * @param client_lanman LANMAN password hash, as supplied by the client
- * @param client_nt NT (MD4) password hash, as supplied by the client
- * @param username internal Samba username, for log messages
- * @param client_username username the client used
- * @param client_domain domain name the client used (may be mapped)
- * @param stored_lanman LANMAN password hash, as stored on the SAM
- * @param stored_nt NT (MD4) password hash, as stored on the SAM
- * @param user_sess_key User session key
- * @param lm_sess_key LM session key (first 8 bytes of the LM hash)
- */
-
-NTSTATUS hash_password_check(TALLOC_CTX *mem_ctx,
- bool lanman_auth,
- const struct samr_Password *client_lanman,
- const struct samr_Password *client_nt,
- const char *username,
- const struct samr_Password *stored_lanman,
- const struct samr_Password *stored_nt)
-{
- if (stored_nt == NULL) {
- DEBUG(3,("ntlm_password_check: NO NT password stored for user %s.\n",
- username));
- }
-
- if (client_nt && stored_nt) {
- if (memcmp(client_nt->hash, stored_nt->hash, sizeof(stored_nt->hash)) == 0) {
- return NT_STATUS_OK;
- } else {
- DEBUG(3,("ntlm_password_check: Interactive logon: NT password check failed for user %s\n",
- username));
- return NT_STATUS_WRONG_PASSWORD;
- }
-
- } else if (client_lanman && stored_lanman) {
- if (!lanman_auth) {
- DEBUG(3,("ntlm_password_check: Interactive logon: only LANMAN password supplied for user %s, and LM passwords are disabled!\n",
- username));
- return NT_STATUS_WRONG_PASSWORD;
- }
- if (strchr_m(username, '@')) {
- return NT_STATUS_NOT_FOUND;
- }
-
- if (memcmp(client_lanman->hash, stored_lanman->hash, sizeof(stored_lanman->hash)) == 0) {
- return NT_STATUS_OK;
- } else {
- DEBUG(3,("ntlm_password_check: Interactive logon: LANMAN password check failed for user %s\n",
- username));
- return NT_STATUS_WRONG_PASSWORD;
- }
- }
- if (strchr_m(username, '@')) {
- return NT_STATUS_NOT_FOUND;
- }
- return NT_STATUS_WRONG_PASSWORD;
-}
-
-/**
- * Check a challenge-response password against the value of the NT or
- * LM password hash.
- *
- * @param mem_ctx talloc context
- * @param challenge 8-byte challenge. If all zero, forces plaintext comparison
- * @param nt_response 'unicode' NT response to the challenge, or unicode password
- * @param lm_response ASCII or LANMAN response to the challenge, or password in DOS code page
- * @param username internal Samba username, for log messages
- * @param client_username username the client used
- * @param client_domain domain name the client used (may be mapped)
- * @param stored_lanman LANMAN ASCII password from our passdb or similar
- * @param stored_nt MD4 unicode password from our passdb or similar
- * @param user_sess_key User session key
- * @param lm_sess_key LM session key (first 8 bytes of the LM hash)
- */
-
-NTSTATUS ntlm_password_check(TALLOC_CTX *mem_ctx,
- bool lanman_auth,
- bool ntlm_auth,
- uint32_t logon_parameters,
- const DATA_BLOB *challenge,
- const DATA_BLOB *lm_response,
- const DATA_BLOB *nt_response,
- const char *username,
- const char *client_username,
- const char *client_domain,
- const struct samr_Password *stored_lanman,
- const struct samr_Password *stored_nt,
- DATA_BLOB *user_sess_key,
- DATA_BLOB *lm_sess_key)
-{
- const static uint8_t zeros[8];
- DATA_BLOB tmp_sess_key;
-
- if (stored_nt == NULL) {
- DEBUG(3,("ntlm_password_check: NO NT password stored for user %s.\n",
- username));
- }
-
- *lm_sess_key = data_blob(NULL, 0);
- *user_sess_key = data_blob(NULL, 0);
-
- /* Check for cleartext netlogon. Used by Exchange 5.5. */
- if ((logon_parameters & MSV1_0_CLEARTEXT_PASSWORD_ALLOWED)
- && challenge->length == sizeof(zeros)
- && (memcmp(challenge->data, zeros, challenge->length) == 0 )) {
- struct samr_Password client_nt;
- struct samr_Password client_lm;
- char *unix_pw = NULL;
- bool lm_ok;
-
- DEBUG(4,("ntlm_password_check: checking plaintext passwords for user %s\n",
- username));
- mdfour(client_nt.hash, nt_response->data, nt_response->length);
-
- if (lm_response->length &&
- (convert_string_talloc(mem_ctx, CH_DOS, CH_UNIX,
- lm_response->data, lm_response->length,
- (void **)&unix_pw, NULL, false))) {
- if (E_deshash(unix_pw, client_lm.hash)) {
- lm_ok = true;
- } else {
- lm_ok = false;
- }
- } else {
- lm_ok = false;
- }
- return hash_password_check(mem_ctx,
- lanman_auth,
- lm_ok ? &client_lm : NULL,
- nt_response->length ? &client_nt : NULL,
- username,
- stored_lanman, stored_nt);
- }
-
- if (nt_response->length != 0 && nt_response->length < 24) {
- DEBUG(2,("ntlm_password_check: invalid NT password length (%lu) for user %s\n",
- (unsigned long)nt_response->length, username));
- }
-
- if (nt_response->length > 24 && stored_nt) {
- /* We have the NT MD4 hash challenge available - see if we can
- use it
- */
- DEBUG(4,("ntlm_password_check: Checking NTLMv2 password with domain [%s]\n", client_domain));
- if (smb_pwd_check_ntlmv2(mem_ctx,
- nt_response,
- stored_nt->hash, challenge,
- client_username,
- client_domain,
- false,
- user_sess_key)) {
- *lm_sess_key = *user_sess_key;
- if (user_sess_key->length) {
- lm_sess_key->length = 8;
- }
- return NT_STATUS_OK;
- }
-
- DEBUG(4,("ntlm_password_check: Checking NTLMv2 password with uppercased version of domain [%s]\n", client_domain));
- if (smb_pwd_check_ntlmv2(mem_ctx,
- nt_response,
- stored_nt->hash, challenge,
- client_username,
- client_domain,
- true,
- user_sess_key)) {
- *lm_sess_key = *user_sess_key;
- if (user_sess_key->length) {
- lm_sess_key->length = 8;
- }
- return NT_STATUS_OK;
- }
-
- DEBUG(4,("ntlm_password_check: Checking NTLMv2 password without a domain\n"));
- if (smb_pwd_check_ntlmv2(mem_ctx,
- nt_response,
- stored_nt->hash, challenge,
- client_username,
- "",
- false,
- user_sess_key)) {
- *lm_sess_key = *user_sess_key;
- if (user_sess_key->length) {
- lm_sess_key->length = 8;
- }
- return NT_STATUS_OK;
- } else {
- DEBUG(3,("ntlm_password_check: NTLMv2 password check failed\n"));
- }
- } else if (nt_response->length == 24 && stored_nt) {
- if (ntlm_auth) {
- /* We have the NT MD4 hash challenge available - see if we can
- use it (ie. does it exist in the smbpasswd file).
- */
- DEBUG(4,("ntlm_password_check: Checking NT MD4 password\n"));
- if (smb_pwd_check_ntlmv1(mem_ctx,
- nt_response,
- stored_nt->hash, challenge,
- user_sess_key)) {
- /* The LM session key for this response is not very secure,
- so use it only if we otherwise allow LM authentication */
-
- if (lanman_auth && stored_lanman) {
- *lm_sess_key = data_blob_talloc(mem_ctx, stored_lanman->hash, 8);
- }
- return NT_STATUS_OK;
- } else {
- DEBUG(3,("ntlm_password_check: NT MD4 password check failed for user %s\n",
- username));
- return NT_STATUS_WRONG_PASSWORD;
- }
- } else {
- DEBUG(2,("ntlm_password_check: NTLMv1 passwords NOT PERMITTED for user %s\n",
- username));
- /* no return, becouse we might pick up LMv2 in the LM field */
- }
- }
-
- if (lm_response->length == 0) {
- DEBUG(3,("ntlm_password_check: NEITHER LanMan nor NT password supplied for user %s\n",
- username));
- return NT_STATUS_WRONG_PASSWORD;
- }
-
- if (lm_response->length < 24) {
- DEBUG(2,("ntlm_password_check: invalid LanMan password length (%lu) for user %s\n",
- (unsigned long)nt_response->length, username));
- return NT_STATUS_WRONG_PASSWORD;
- }
-
- if (!lanman_auth) {
- DEBUG(3,("ntlm_password_check: Lanman passwords NOT PERMITTED for user %s\n",
- username));
- } else if (!stored_lanman) {
- DEBUG(3,("ntlm_password_check: NO LanMan password set for user %s (and no NT password supplied)\n",
- username));
- } else if (strchr_m(username, '@')) {
- DEBUG(3,("ntlm_password_check: NO LanMan password allowed for username@realm logins (user: %s)\n",
- username));
- } else {
- DEBUG(4,("ntlm_password_check: Checking LM password\n"));
- if (smb_pwd_check_ntlmv1(mem_ctx,
- lm_response,
- stored_lanman->hash, challenge,
- NULL)) {
- /* The session key for this response is still very odd.
- It not very secure, so use it only if we otherwise
- allow LM authentication */
-
- if (lanman_auth && stored_lanman) {
- uint8_t first_8_lm_hash[16];
- memcpy(first_8_lm_hash, stored_lanman->hash, 8);
- memset(first_8_lm_hash + 8, '\0', 8);
- *user_sess_key = data_blob_talloc(mem_ctx, first_8_lm_hash, 16);
- *lm_sess_key = data_blob_talloc(mem_ctx, stored_lanman->hash, 8);
- }
- return NT_STATUS_OK;
- }
- }
-
- if (!stored_nt) {
- DEBUG(4,("ntlm_password_check: LM password check failed for user, no NT password %s\n",username));
- return NT_STATUS_WRONG_PASSWORD;
- }
-
- /* This is for 'LMv2' authentication. almost NTLMv2 but limited to 24 bytes.
- - related to Win9X, legacy NAS pass-though authentication
- */
- DEBUG(4,("ntlm_password_check: Checking LMv2 password with domain %s\n", client_domain));
- if (smb_pwd_check_ntlmv2(mem_ctx,
- lm_response,
- stored_nt->hash, challenge,
- client_username,
- client_domain,
- false,
- &tmp_sess_key)) {
- if (nt_response->length > 24) {
- /* If NTLMv2 authentication has preceeded us
- * (even if it failed), then use the session
- * key from that. See the RPC-SAMLOGON
- * torture test */
- smb_sess_key_ntlmv2(mem_ctx,
- nt_response,
- stored_nt->hash, challenge,
- client_username,
- client_domain,
- false,
- user_sess_key);
- } else {
- /* Otherwise, use the LMv2 session key */
- *user_sess_key = tmp_sess_key;
- }
- *lm_sess_key = *user_sess_key;
- if (user_sess_key->length) {
- lm_sess_key->length = 8;
- }
- return NT_STATUS_OK;
- }
-
- DEBUG(4,("ntlm_password_check: Checking LMv2 password with upper-cased version of domain %s\n", client_domain));
- if (smb_pwd_check_ntlmv2(mem_ctx,
- lm_response,
- stored_nt->hash, challenge,
- client_username,
- client_domain,
- true,
- &tmp_sess_key)) {
- if (nt_response->length > 24) {
- /* If NTLMv2 authentication has preceeded us
- * (even if it failed), then use the session
- * key from that. See the RPC-SAMLOGON
- * torture test */
- smb_sess_key_ntlmv2(mem_ctx,
- nt_response,
- stored_nt->hash, challenge,
- client_username,
- client_domain,
- true,
- user_sess_key);
- } else {
- /* Otherwise, use the LMv2 session key */
- *user_sess_key = tmp_sess_key;
- }
- *lm_sess_key = *user_sess_key;
- if (user_sess_key->length) {
- lm_sess_key->length = 8;
- }
- return NT_STATUS_OK;
- }
-
- DEBUG(4,("ntlm_password_check: Checking LMv2 password without a domain\n"));
- if (smb_pwd_check_ntlmv2(mem_ctx,
- lm_response,
- stored_nt->hash, challenge,
- client_username,
- "",
- false,
- &tmp_sess_key)) {
- if (nt_response->length > 24) {
- /* If NTLMv2 authentication has preceeded us
- * (even if it failed), then use the session
- * key from that. See the RPC-SAMLOGON
- * torture test */
- smb_sess_key_ntlmv2(mem_ctx,
- nt_response,
- stored_nt->hash, challenge,
- client_username,
- "",
- false,
- user_sess_key);
- } else {
- /* Otherwise, use the LMv2 session key */
- *user_sess_key = tmp_sess_key;
- }
- *lm_sess_key = *user_sess_key;
- if (user_sess_key->length) {
- lm_sess_key->length = 8;
- }
- return NT_STATUS_OK;
- }
-
- /* Apparently NT accepts NT responses in the LM field
- - I think this is related to Win9X pass-though authentication
- */
- DEBUG(4,("ntlm_password_check: Checking NT MD4 password in LM field\n"));
- if (ntlm_auth) {
- if (smb_pwd_check_ntlmv1(mem_ctx,
- lm_response,
- stored_nt->hash, challenge,
- NULL)) {
- /* The session key for this response is still very odd.
- It not very secure, so use it only if we otherwise
- allow LM authentication */
-
- if (lanman_auth && stored_lanman) {
- uint8_t first_8_lm_hash[16];
- memcpy(first_8_lm_hash, stored_lanman->hash, 8);
- memset(first_8_lm_hash + 8, '\0', 8);
- *user_sess_key = data_blob_talloc(mem_ctx, first_8_lm_hash, 16);
- *lm_sess_key = data_blob_talloc(mem_ctx, stored_lanman->hash, 8);
- }
- return NT_STATUS_OK;
- }
- DEBUG(3,("ntlm_password_check: LM password, NT MD4 password in LM field and LMv2 failed for user %s\n",username));
- } else {
- DEBUG(3,("ntlm_password_check: LM password and LMv2 failed for user %s, and NT MD4 password in LM field not permitted\n",username));
- }
-
- /* Try and match error codes */
- if (strchr_m(username, '@')) {
- return NT_STATUS_NOT_FOUND;
- }
- return NT_STATUS_WRONG_PASSWORD;
-}
-
diff --git a/source4/auth/ntlm/ntlm_check.h b/source4/auth/ntlm/ntlm_check.h
deleted file mode 100644
index df11f7d7a2..0000000000
--- a/source4/auth/ntlm/ntlm_check.h
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
- Password and authentication handling
- Copyright (C) Andrew Bartlett <abartlet@samba.org> 2001-2004
- Copyright (C) Gerald Carter 2003
- Copyright (C) Luke Kenneth Casson Leighton 1996-2000
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-
-/**
- * Compare password hashes against those from the SAM
- *
- * @param mem_ctx talloc context
- * @param client_lanman LANMAN password hash, as supplied by the client
- * @param client_nt NT (MD4) password hash, as supplied by the client
- * @param username internal Samba username, for log messages
- * @param client_username username the client used
- * @param client_domain domain name the client used (may be mapped)
- * @param stored_lanman LANMAN password hash, as stored on the SAM
- * @param stored_nt NT (MD4) password hash, as stored on the SAM
- * @param user_sess_key User session key
- * @param lm_sess_key LM session key (first 8 bytes of the LM hash)
- */
-
-NTSTATUS hash_password_check(TALLOC_CTX *mem_ctx,
- bool lanman_auth,
- const struct samr_Password *client_lanman,
- const struct samr_Password *client_nt,
- const char *username,
- const struct samr_Password *stored_lanman,
- const struct samr_Password *stored_nt);
-
-/**
- * Check a challenge-response password against the value of the NT or
- * LM password hash.
- *
- * @param mem_ctx talloc context
- * @param challenge 8-byte challenge. If all zero, forces plaintext comparison
- * @param nt_response 'unicode' NT response to the challenge, or unicode password
- * @param lm_response ASCII or LANMAN response to the challenge, or password in DOS code page
- * @param username internal Samba username, for log messages
- * @param client_username username the client used
- * @param client_domain domain name the client used (may be mapped)
- * @param stored_lanman LANMAN ASCII password from our passdb or similar
- * @param stored_nt MD4 unicode password from our passdb or similar
- * @param user_sess_key User session key
- * @param lm_sess_key LM session key (first 8 bytes of the LM hash)
- */
-
-NTSTATUS ntlm_password_check(TALLOC_CTX *mem_ctx,
- bool lanman_auth,
- bool ntlm_auth,
- uint32_t logon_parameters,
- const DATA_BLOB *challenge,
- const DATA_BLOB *lm_response,
- const DATA_BLOB *nt_response,
- const char *username,
- const char *client_username,
- const char *client_domain,
- const struct samr_Password *stored_lanman,
- const struct samr_Password *stored_nt,
- DATA_BLOB *user_sess_key,
- DATA_BLOB *lm_sess_key);
diff --git a/source4/auth/ntlmssp/config.mk b/source4/auth/ntlmssp/config.mk
index c0446bcac1..1be5fa98e7 100644
--- a/source4/auth/ntlmssp/config.mk
+++ b/source4/auth/ntlmssp/config.mk
@@ -1,9 +1,3 @@
-[SUBSYSTEM::MSRPC_PARSE]
-
-MSRPC_PARSE_OBJ_FILES = $(addprefix $(authsrcdir)/ntlmssp/, ntlmssp_parse.o)
-
-$(eval $(call proto_header_template,$(authsrcdir)/ntlmssp/msrpc_parse.h,$(MSRPC_PARSE_OBJ_FILES:.o=.c)))
-
################################################
# Start MODULE gensec_ntlmssp
[MODULE::gensec_ntlmssp]
diff --git a/source4/auth/ntlmssp/ntlmssp.h b/source4/auth/ntlmssp/ntlmssp.h
index df950e4756..ff7225bb3c 100644
--- a/source4/auth/ntlmssp/ntlmssp.h
+++ b/source4/auth/ntlmssp/ntlmssp.h
@@ -66,11 +66,6 @@ enum ntlmssp_message_type
#define NTLMSSP_NEGOTIATE_KEY_EXCH 0x40000000
#define NTLMSSP_NEGOTIATE_56 0x80000000
-#define NTLMSSP_NAME_TYPE_SERVER 0x01
-#define NTLMSSP_NAME_TYPE_DOMAIN 0x02
-#define NTLMSSP_NAME_TYPE_SERVER_DNS 0x03
-#define NTLMSSP_NAME_TYPE_DOMAIN_DNS 0x04
-
#define NTLMSSP_SIGN_VERSION 1
#define NTLMSSP_SIG_SIZE 16
diff --git a/source4/auth/ntlmssp/ntlmssp_parse.c b/source4/auth/ntlmssp/ntlmssp_parse.c
deleted file mode 100644
index 969845d6c5..0000000000
--- a/source4/auth/ntlmssp/ntlmssp_parse.c
+++ /dev/null
@@ -1,368 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
- simple kerberos5/SPNEGO routines
- Copyright (C) Andrew Tridgell 2001
- Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2002
- Copyright (C) Andrew Bartlett 2002-2003
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#include "includes.h"
-#include "auth/ntlmssp/msrpc_parse.h"
-
-/*
- this is a tiny msrpc packet generator. I am only using this to
- avoid tying this code to a particular varient of our rpc code. This
- generator is not general enough for all our rpc needs, its just
- enough for the spnego/ntlmssp code
-
- format specifiers are:
-
- U = unicode string (input is unix string)
- a = address (input is char *unix_string)
- (1 byte type, 1 byte length, unicode/ASCII string, all inline)
- A = ASCII string (input is unix string)
- B = data blob (pointer + length)
- b = data blob in header (pointer + length)
- D
- d = word (4 bytes)
- C = constant ascii string
- */
-bool msrpc_gen(TALLOC_CTX *mem_ctx,
- DATA_BLOB *blob,
- const char *format, ...)
-{
- int i, j;
- bool ret;
- va_list ap;
- char *s;
- uint8_t *b;
- int head_size=0, data_size=0;
- int head_ofs, data_ofs;
- int *intargs;
- size_t n;
-
- DATA_BLOB *pointers;
-
- pointers = talloc_array(mem_ctx, DATA_BLOB, strlen(format));
- intargs = talloc_array(pointers, int, strlen(format));
-
- /* first scan the format to work out the header and body size */
- va_start(ap, format);
- for (i=0; format[i]; i++) {
- switch (format[i]) {
- case 'U':
- s = va_arg(ap, char *);
- head_size += 8;
- ret = push_ucs2_talloc(pointers, (smb_ucs2_t **)&pointers[i].data,
- s, &n);
- if (!ret) {
- return false;
- }
- pointers[i].length = n;
- pointers[i].length -= 2;
- data_size += pointers[i].length;
- break;
- case 'A':
- s = va_arg(ap, char *);
- head_size += 8;
- ret = push_ascii_talloc(pointers, (char **)&pointers[i].data, s,
- &n);
- if (!ret) {
- return false;
- }
- pointers[i].length = n;
- pointers[i].length -= 1;
- data_size += pointers[i].length;
- break;
- case 'a':
- j = va_arg(ap, int);
- intargs[i] = j;
- s = va_arg(ap, char *);
- ret = push_ucs2_talloc(pointers, (smb_ucs2_t **)&pointers[i].data,
- s, &n);
- if (!ret) {
- return false;
- }
- pointers[i].length = n;
- pointers[i].length -= 2;
- data_size += pointers[i].length + 4;
- break;
- case 'B':
- b = va_arg(ap, uint8_t *);
- head_size += 8;
- pointers[i].data = b;
- pointers[i].length = va_arg(ap, int);
- data_size += pointers[i].length;
- break;
- case 'b':
- b = va_arg(ap, uint8_t *);
- pointers[i].data = b;
- pointers[i].length = va_arg(ap, int);
- head_size += pointers[i].length;
- break;
- case 'd':
- j = va_arg(ap, int);
- intargs[i] = j;
- head_size += 4;
- break;
- case 'C':
- s = va_arg(ap, char *);
- pointers[i].data = (uint8_t *)s;
- pointers[i].length = strlen(s)+1;
- head_size += pointers[i].length;
- break;
- }
- }
- va_end(ap);
-
- /* allocate the space, then scan the format again to fill in the values */
- *blob = data_blob_talloc(mem_ctx, NULL, head_size + data_size);
-
- head_ofs = 0;
- data_ofs = head_size;
-
- va_start(ap, format);
- for (i=0; format[i]; i++) {
- switch (format[i]) {
- case 'U':
- case 'A':
- case 'B':
- n = pointers[i].length;
- SSVAL(blob->data, head_ofs, n); head_ofs += 2;
- SSVAL(blob->data, head_ofs, n); head_ofs += 2;
- SIVAL(blob->data, head_ofs, data_ofs); head_ofs += 4;
- if (pointers[i].data && n) /* don't follow null pointers... */
- memcpy(blob->data+data_ofs, pointers[i].data, n);
- data_ofs += n;
- break;
- case 'a':
- j = intargs[i];
- SSVAL(blob->data, data_ofs, j); data_ofs += 2;
-
- n = pointers[i].length;
- SSVAL(blob->data, data_ofs, n); data_ofs += 2;
- if (n >= 0) {
- memcpy(blob->data+data_ofs, pointers[i].data, n);
- }
- data_ofs += n;
- break;
- case 'd':
- j = intargs[i];
- SIVAL(blob->data, head_ofs, j);
- head_ofs += 4;
- break;
- case 'b':
- n = pointers[i].length;
- memcpy(blob->data + head_ofs, pointers[i].data, n);
- head_ofs += n;
- break;
- case 'C':
- n = pointers[i].length;
- memcpy(blob->data + head_ofs, pointers[i].data, n);
- head_ofs += n;
- break;
- }
- }
- va_end(ap);
-
- talloc_free(pointers);
-
- return true;
-}
-
-
-/* a helpful macro to avoid running over the end of our blob */
-#define NEED_DATA(amount) \
-if ((head_ofs + amount) > blob->length) { \
- return false; \
-}
-
-/**
- this is a tiny msrpc packet parser. This the the partner of msrpc_gen
-
- format specifiers are:
-
- U = unicode string (output is unix string)
- A = ascii string
- B = data blob
- b = data blob in header
- d = word (4 bytes)
- C = constant ascii string
- */
-
-bool msrpc_parse(TALLOC_CTX *mem_ctx,
- const DATA_BLOB *blob,
- const char *format, ...)
-{
- int i;
- va_list ap;
- const char **ps, *s;
- DATA_BLOB *b;
- size_t head_ofs = 0;
- uint16_t len1, len2;
- uint32_t ptr;
- uint32_t *v;
- size_t p_len = 1024;
- char *p = talloc_array(mem_ctx, char, p_len);
- bool ret = true;
-
- va_start(ap, format);
- for (i=0; format[i]; i++) {
- switch (format[i]) {
- case 'U':
- NEED_DATA(8);
- len1 = SVAL(blob->data, head_ofs); head_ofs += 2;
- len2 = SVAL(blob->data, head_ofs); head_ofs += 2;
- ptr = IVAL(blob->data, head_ofs); head_ofs += 4;
-
- ps = (const char **)va_arg(ap, char **);
- if (len1 == 0 && len2 == 0) {
- *ps = "";
- } else {
- /* make sure its in the right format - be strict */
- if ((len1 != len2) || (ptr + len1 < ptr) || (ptr + len1 < len1) || (ptr + len1 > blob->length)) {
- ret = false;
- goto cleanup;
- }
- if (len1 & 1) {
- /* if odd length and unicode */
- ret = false;
- goto cleanup;
- }
- if (blob->data + ptr < (uint8_t *)(uintptr_t)ptr ||
- blob->data + ptr < blob->data) {
- ret = false;
- goto cleanup;
- }
-
- if (0 < len1) {
- pull_string(p, blob->data + ptr, p_len,
- len1, STR_UNICODE|STR_NOALIGN);
- (*ps) = talloc_strdup(mem_ctx, p);
- if (!(*ps)) {
- ret = false;
- goto cleanup;
- }
- } else {
- (*ps) = "";
- }
- }
- break;
- case 'A':
- NEED_DATA(8);
- len1 = SVAL(blob->data, head_ofs); head_ofs += 2;
- len2 = SVAL(blob->data, head_ofs); head_ofs += 2;
- ptr = IVAL(blob->data, head_ofs); head_ofs += 4;
-
- ps = (const char **)va_arg(ap, char **);
- /* make sure its in the right format - be strict */
- if (len1 == 0 && len2 == 0) {
- *ps = "";
- } else {
- if ((len1 != len2) || (ptr + len1 < ptr) || (ptr + len1 < len1) || (ptr + len1 > blob->length)) {
- ret = false;
- goto cleanup;
- }
-
- if (blob->data + ptr < (uint8_t *)(uintptr_t)ptr ||
- blob->data + ptr < blob->data) {
- ret = false;
- goto cleanup;
- }
-
- if (0 < len1) {
- pull_string(p, blob->data + ptr, p_len,
- len1, STR_ASCII|STR_NOALIGN);
- (*ps) = talloc_strdup(mem_ctx, p);
- if (!(*ps)) {
- ret = false;
- goto cleanup;
- }
- } else {
- (*ps) = "";
- }
- }
- break;
- case 'B':
- NEED_DATA(8);
- len1 = SVAL(blob->data, head_ofs); head_ofs += 2;
- len2 = SVAL(blob->data, head_ofs); head_ofs += 2;
- ptr = IVAL(blob->data, head_ofs); head_ofs += 4;
-
- b = (DATA_BLOB *)va_arg(ap, void *);
- if (len1 == 0 && len2 == 0) {
- *b = data_blob_talloc(mem_ctx, NULL, 0);
- } else {
- /* make sure its in the right format - be strict */
- if ((len1 != len2) || (ptr + len1 < ptr) || (ptr + len1 < len1) || (ptr + len1 > blob->length)) {
- ret = false;
- goto cleanup;
- }
-
- if (blob->data + ptr < (uint8_t *)(uintptr_t)ptr ||
- blob->data + ptr < blob->data) {
- ret = false;
- goto cleanup;
- }
-
- *b = data_blob_talloc(mem_ctx, blob->data + ptr, len1);
- }
- break;
- case 'b':
- b = (DATA_BLOB *)va_arg(ap, void *);
- len1 = va_arg(ap, uint_t);
- /* make sure its in the right format - be strict */
- NEED_DATA(len1);
- if (blob->data + head_ofs < (uint8_t *)head_ofs ||
- blob->data + head_ofs < blob->data) {
- ret = false;
- goto cleanup;
- }
-
- *b = data_blob_talloc(mem_ctx, blob->data + head_ofs, len1);
- head_ofs += len1;
- break;
- case 'd':
- v = va_arg(ap, uint32_t *);
- NEED_DATA(4);
- *v = IVAL(blob->data, head_ofs); head_ofs += 4;
- break;
- case 'C':
- s = va_arg(ap, char *);
-
- if (blob->data + head_ofs < (uint8_t *)head_ofs ||
- blob->data + head_ofs < blob->data) {
- ret = false;
- goto cleanup;
- }
-
- head_ofs += pull_string(p,
- blob->data+head_ofs, p_len,
- blob->length - head_ofs,
- STR_ASCII|STR_TERMINATE);
- if (strcmp(s, p) != 0) {
- ret = false;
- goto cleanup;
- }
- break;
- }
- }
-
-cleanup:
- va_end(ap);
- talloc_free(p);
- return ret;
-}