diff options
author | Stefan Metzmacher <metze@samba.org> | 2009-12-30 17:57:54 +0100 |
---|---|---|
committer | Günther Deschner <gd@samba.org> | 2010-03-24 17:34:51 +0100 |
commit | d3e7266676f3516c4d5493d11cf75099365b69dc (patch) | |
tree | 538bf391b8791d71564f334dafb0f3aef983ca46 | |
parent | 706333856b53c7544dcb44a6505ab82bd38d860c (diff) | |
download | samba-d3e7266676f3516c4d5493d11cf75099365b69dc.tar.gz samba-d3e7266676f3516c4d5493d11cf75099365b69dc.tar.bz2 samba-d3e7266676f3516c4d5493d11cf75099365b69dc.zip |
s4:ntlmssp: rename gensec_ntlmssp_state => ntlmssp_state
Inspired by the NTLMSSP merge work by Andrew Bartlett.
metze
Signed-off-by: Günther Deschner <gd@samba.org>
-rw-r--r-- | source4/auth/ntlmssp/ntlmssp.c | 102 | ||||
-rw-r--r-- | source4/auth/ntlmssp/ntlmssp.h | 13 | ||||
-rw-r--r-- | source4/auth/ntlmssp/ntlmssp_client.c | 116 | ||||
-rw-r--r-- | source4/auth/ntlmssp/ntlmssp_server.c | 328 | ||||
-rw-r--r-- | source4/auth/ntlmssp/ntlmssp_sign.c | 145 | ||||
-rw-r--r-- | source4/torture/auth/ntlmssp.c | 28 | ||||
-rw-r--r-- | source4/utils/ntlm_auth.c | 8 |
7 files changed, 370 insertions, 370 deletions
diff --git a/source4/auth/ntlmssp/ntlmssp.c b/source4/auth/ntlmssp/ntlmssp.c index 37020366bd..1866eb56b9 100644 --- a/source4/auth/ntlmssp/ntlmssp.c +++ b/source4/auth/ntlmssp/ntlmssp.c @@ -119,17 +119,17 @@ static NTSTATUS gensec_ntlmssp_magic(struct gensec_security *gensec_security, } } -static NTSTATUS gensec_ntlmssp_update_find(struct gensec_ntlmssp_state *gensec_ntlmssp_state, +static NTSTATUS gensec_ntlmssp_update_find(struct ntlmssp_state *ntlmssp_state, const DATA_BLOB input, uint32_t *idx) { struct gensec_ntlmssp_context *gensec_ntlmssp = - talloc_get_type_abort(gensec_ntlmssp_state->callback_private, + talloc_get_type_abort(ntlmssp_state->callback_private, struct gensec_ntlmssp_context); struct gensec_security *gensec_security = gensec_ntlmssp->gensec_security; uint32_t ntlmssp_command; uint32_t i; - if (gensec_ntlmssp_state->expected_state == NTLMSSP_DONE) { + if (ntlmssp_state->expected_state == NTLMSSP_DONE) { /* We are strict here because other modules, which we * don't fully control (such as GSSAPI) are also * strict, but are tested less often */ @@ -139,7 +139,7 @@ static NTSTATUS gensec_ntlmssp_update_find(struct gensec_ntlmssp_state *gensec_n } if (!input.length) { - switch (gensec_ntlmssp_state->role) { + switch (ntlmssp_state->role) { case NTLMSSP_CLIENT: ntlmssp_command = NTLMSSP_INITIAL; break; @@ -155,7 +155,7 @@ static NTSTATUS gensec_ntlmssp_update_find(struct gensec_ntlmssp_state *gensec_n break; } } else { - if (!msrpc_parse(gensec_ntlmssp_state, + if (!msrpc_parse(ntlmssp_state, &input, "Cd", "NTLMSSP", &ntlmssp_command)) { @@ -165,13 +165,13 @@ static NTSTATUS gensec_ntlmssp_update_find(struct gensec_ntlmssp_state *gensec_n } } - if (ntlmssp_command != gensec_ntlmssp_state->expected_state) { - DEBUG(2, ("got NTLMSSP command %u, expected %u\n", ntlmssp_command, gensec_ntlmssp_state->expected_state)); + if (ntlmssp_command != ntlmssp_state->expected_state) { + DEBUG(2, ("got NTLMSSP command %u, expected %u\n", ntlmssp_command, ntlmssp_state->expected_state)); return NT_STATUS_INVALID_PARAMETER; } for (i=0; i < ARRAY_SIZE(ntlmssp_callbacks); i++) { - if (ntlmssp_callbacks[i].role == gensec_ntlmssp_state->role && + if (ntlmssp_callbacks[i].role == ntlmssp_state->role && ntlmssp_callbacks[i].command == ntlmssp_command) { *idx = i; return NT_STATUS_OK; @@ -179,7 +179,7 @@ static NTSTATUS gensec_ntlmssp_update_find(struct gensec_ntlmssp_state *gensec_n } DEBUG(1, ("failed to find NTLMSSP callback for NTLMSSP mode %u, command %u\n", - gensec_ntlmssp_state->role, ntlmssp_command)); + ntlmssp_state->role, ntlmssp_command)); return NT_STATUS_INVALID_PARAMETER; } @@ -202,7 +202,7 @@ static NTSTATUS gensec_ntlmssp_update(struct gensec_security *gensec_security, struct gensec_ntlmssp_context *gensec_ntlmssp = talloc_get_type_abort(gensec_security->private_data, struct gensec_ntlmssp_context); - struct gensec_ntlmssp_state *gensec_ntlmssp_state = gensec_ntlmssp->ntlmssp_state; + struct ntlmssp_state *ntlmssp_state = gensec_ntlmssp->ntlmssp_state; NTSTATUS status; uint32_t i; @@ -211,10 +211,10 @@ static NTSTATUS gensec_ntlmssp_update(struct gensec_security *gensec_security, if (!out_mem_ctx) { /* if the caller doesn't want to manage/own the memory, we can put it on our context */ - out_mem_ctx = gensec_ntlmssp_state; + out_mem_ctx = ntlmssp_state; } - status = gensec_ntlmssp_update_find(gensec_ntlmssp_state, input, &i); + status = gensec_ntlmssp_update_find(ntlmssp_state, input, &i); NT_STATUS_NOT_OK_RETURN(status); status = ntlmssp_callbacks[i].sync_fn(gensec_security, out_mem_ctx, input, out); @@ -226,7 +226,7 @@ static NTSTATUS gensec_ntlmssp_update(struct gensec_security *gensec_security, /** * Return the NTLMSSP master session key * - * @param gensec_ntlmssp_state NTLMSSP State + * @param ntlmssp_state NTLMSSP State */ NTSTATUS gensec_ntlmssp_session_key(struct gensec_security *gensec_security, @@ -235,77 +235,77 @@ NTSTATUS gensec_ntlmssp_session_key(struct gensec_security *gensec_security, struct gensec_ntlmssp_context *gensec_ntlmssp = talloc_get_type_abort(gensec_security->private_data, struct gensec_ntlmssp_context); - struct gensec_ntlmssp_state *gensec_ntlmssp_state = gensec_ntlmssp->ntlmssp_state; + struct ntlmssp_state *ntlmssp_state = gensec_ntlmssp->ntlmssp_state; - if (gensec_ntlmssp_state->expected_state != NTLMSSP_DONE) { + if (ntlmssp_state->expected_state != NTLMSSP_DONE) { return NT_STATUS_NO_USER_SESSION_KEY; } - if (!gensec_ntlmssp_state->session_key.data) { + if (!ntlmssp_state->session_key.data) { return NT_STATUS_NO_USER_SESSION_KEY; } - *session_key = gensec_ntlmssp_state->session_key; + *session_key = ntlmssp_state->session_key; return NT_STATUS_OK; } -void ntlmssp_handle_neg_flags(struct gensec_ntlmssp_state *gensec_ntlmssp_state, +void ntlmssp_handle_neg_flags(struct ntlmssp_state *ntlmssp_state, uint32_t neg_flags, bool allow_lm) { if (neg_flags & NTLMSSP_NEGOTIATE_UNICODE) { - gensec_ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_UNICODE; - gensec_ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_OEM; - gensec_ntlmssp_state->unicode = true; + ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_UNICODE; + ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_OEM; + ntlmssp_state->unicode = true; } else { - gensec_ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_UNICODE; - gensec_ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_OEM; - gensec_ntlmssp_state->unicode = false; + ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_UNICODE; + ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_OEM; + ntlmssp_state->unicode = false; } - if ((neg_flags & NTLMSSP_NEGOTIATE_LM_KEY) && allow_lm && !gensec_ntlmssp_state->use_ntlmv2) { + if ((neg_flags & NTLMSSP_NEGOTIATE_LM_KEY) && allow_lm && !ntlmssp_state->use_ntlmv2) { /* other end forcing us to use LM */ - gensec_ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_LM_KEY; - gensec_ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_NTLM2; + ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_LM_KEY; + ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_NTLM2; } else { - gensec_ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_LM_KEY; + ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_LM_KEY; } if (!(neg_flags & NTLMSSP_NEGOTIATE_ALWAYS_SIGN)) { - gensec_ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_ALWAYS_SIGN; + ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_ALWAYS_SIGN; } if (!(neg_flags & NTLMSSP_NEGOTIATE_SIGN)) { - gensec_ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_SIGN; + ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_SIGN; } if (!(neg_flags & NTLMSSP_NEGOTIATE_SEAL)) { - gensec_ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_SEAL; + ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_SEAL; } if (!(neg_flags & NTLMSSP_NEGOTIATE_NTLM2)) { - gensec_ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_NTLM2; + ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_NTLM2; } if (!(neg_flags & NTLMSSP_NEGOTIATE_128)) { - gensec_ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_128; + ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_128; } if (!(neg_flags & NTLMSSP_NEGOTIATE_56)) { - gensec_ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_56; + ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_56; } if (!(neg_flags & NTLMSSP_NEGOTIATE_KEY_EXCH)) { - gensec_ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_KEY_EXCH; + ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_KEY_EXCH; } /* Woop Woop - unknown flag for Windows compatibility... What does this really do ? JRA. */ if (!(neg_flags & NTLMSSP_NEGOTIATE_VERSION)) { - gensec_ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_VERSION; + ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_VERSION; } if ((neg_flags & NTLMSSP_REQUEST_TARGET)) { - gensec_ntlmssp_state->neg_flags |= NTLMSSP_REQUEST_TARGET; + ntlmssp_state->neg_flags |= NTLMSSP_REQUEST_TARGET; } } @@ -318,12 +318,12 @@ void ntlmssp_handle_neg_flags(struct gensec_ntlmssp_state *gensec_ntlmssp_state, by the client lanman auth/lanman auth parameters, it isn't too bad. */ -DATA_BLOB ntlmssp_weakend_key(struct gensec_ntlmssp_state *gensec_ntlmssp_state, +DATA_BLOB ntlmssp_weakend_key(struct ntlmssp_state *ntlmssp_state, TALLOC_CTX *mem_ctx) { DATA_BLOB weakened_key = data_blob_talloc(mem_ctx, - gensec_ntlmssp_state->session_key.data, - gensec_ntlmssp_state->session_key.length); + ntlmssp_state->session_key.data, + ntlmssp_state->session_key.length); /* Nothing to weaken. We certainly don't want to 'extend' the length... */ if (weakened_key.length < 16) { /* perhaps there was no key? */ @@ -334,11 +334,11 @@ DATA_BLOB ntlmssp_weakend_key(struct gensec_ntlmssp_state *gensec_ntlmssp_state, and does not occour for NTLM1. Therefore we only need to do this for the LM_KEY. */ - if (gensec_ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_LM_KEY) { + if (ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_LM_KEY) { /* LM key doesn't support 128 bit crypto, so this is * the best we can do. If you negotiate 128 bit, but * not 56, you end up with 40 bit... */ - if (gensec_ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_56) { + if (ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_56) { weakened_key.data[7] = 0xa0; weakened_key.length = 8; } else { /* forty bits */ @@ -357,26 +357,26 @@ static bool gensec_ntlmssp_have_feature(struct gensec_security *gensec_security, struct gensec_ntlmssp_context *gensec_ntlmssp = talloc_get_type_abort(gensec_security->private_data, struct gensec_ntlmssp_context); - struct gensec_ntlmssp_state *gensec_ntlmssp_state = gensec_ntlmssp->ntlmssp_state; + struct ntlmssp_state *ntlmssp_state = gensec_ntlmssp->ntlmssp_state; if (feature & GENSEC_FEATURE_SIGN) { - if (!gensec_ntlmssp_state->session_key.length) { + if (!ntlmssp_state->session_key.length) { return false; } - if (gensec_ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_SIGN) { + if (ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_SIGN) { return true; } } if (feature & GENSEC_FEATURE_SEAL) { - if (!gensec_ntlmssp_state->session_key.length) { + if (!ntlmssp_state->session_key.length) { return false; } - if (gensec_ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_SEAL) { + if (ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_SEAL) { return true; } } if (feature & GENSEC_FEATURE_SESSION_KEY) { - if (gensec_ntlmssp_state->session_key.length) { + if (ntlmssp_state->session_key.length) { return true; } } @@ -384,7 +384,7 @@ static bool gensec_ntlmssp_have_feature(struct gensec_security *gensec_security, return true; } if (feature & GENSEC_FEATURE_ASYNC_REPLIES) { - if (gensec_ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_NTLM2) { + if (ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_NTLM2) { return true; } } @@ -394,7 +394,7 @@ static bool gensec_ntlmssp_have_feature(struct gensec_security *gensec_security, NTSTATUS gensec_ntlmssp_start(struct gensec_security *gensec_security) { struct gensec_ntlmssp_context *gensec_ntlmssp; - struct gensec_ntlmssp_state *ntlmssp_state; + struct ntlmssp_state *ntlmssp_state; gensec_ntlmssp = talloc_zero(gensec_security, struct gensec_ntlmssp_context); @@ -405,7 +405,7 @@ NTSTATUS gensec_ntlmssp_start(struct gensec_security *gensec_security) gensec_ntlmssp->gensec_security = gensec_security; ntlmssp_state = talloc_zero(gensec_ntlmssp, - struct gensec_ntlmssp_state); + struct ntlmssp_state); if (!ntlmssp_state) { return NT_STATUS_NO_MEMORY; } diff --git a/source4/auth/ntlmssp/ntlmssp.h b/source4/auth/ntlmssp/ntlmssp.h index 181c8bf685..374a221a9c 100644 --- a/source4/auth/ntlmssp/ntlmssp.h +++ b/source4/auth/ntlmssp/ntlmssp.h @@ -44,7 +44,7 @@ enum ntlmssp_message_type #define NTLMSSP_FEATURE_SEAL 0x00000004 #define NTLMSSP_FEATURE_CCACHE 0x00000008 -struct gensec_ntlmssp_state +struct ntlmssp_state { enum ntlmssp_role role; uint32_t expected_state; @@ -95,7 +95,7 @@ struct gensec_ntlmssp_state * @return 8 bytes of challenge data, determined by the server to be the challenge for NTLM authentication * */ - NTSTATUS (*get_challenge)(const struct gensec_ntlmssp_state *, + NTSTATUS (*get_challenge)(const struct ntlmssp_state *ntlmssp_state, uint8_t challenge[8]); /** @@ -108,7 +108,7 @@ struct gensec_ntlmssp_state * @return Can the challenge be set to arbitary values? * */ - bool (*may_set_challenge)(const struct gensec_ntlmssp_state *); + bool (*may_set_challenge)(const struct ntlmssp_state *ntlmssp_state); /** * Callback to set the 'challenge' used for NTLM authentication. @@ -120,7 +120,7 @@ struct gensec_ntlmssp_state * @param challenge 8 bytes of data, agreed by the client and server to be the effective challenge for NTLM2 authentication * */ - NTSTATUS (*set_challenge)(struct gensec_ntlmssp_state *, DATA_BLOB *challenge); + NTSTATUS (*set_challenge)(struct ntlmssp_state *ntlmssp_state, DATA_BLOB *challenge); /** * Callback to check the user's password. @@ -131,8 +131,7 @@ struct gensec_ntlmssp_state * @param lm_session_key If an LM session key is returned by the authentication process, return it here * */ - NTSTATUS (*check_password)(struct gensec_ntlmssp_state *, - DATA_BLOB *nt_session_key, DATA_BLOB *lm_session_key); + NTSTATUS (*check_password)(struct ntlmssp_state *ntlmssp_state, DATA_BLOB *nt_session_key, DATA_BLOB *lm_session_key); bool doing_ntlm2; @@ -160,7 +159,7 @@ struct gensec_ntlmssp_state struct gensec_ntlmssp_context { struct gensec_security *gensec_security; - struct gensec_ntlmssp_state *ntlmssp_state; + struct ntlmssp_state *ntlmssp_state; struct auth_context *auth_context; struct auth_serversupplied_info *server_info; }; diff --git a/source4/auth/ntlmssp/ntlmssp_client.c b/source4/auth/ntlmssp/ntlmssp_client.c index cdd377b2bc..005b42f4e8 100644 --- a/source4/auth/ntlmssp/ntlmssp_client.c +++ b/source4/auth/ntlmssp/ntlmssp_client.c @@ -50,8 +50,8 @@ NTSTATUS ntlmssp_client_initial(struct gensec_security *gensec_security, struct gensec_ntlmssp_context *gensec_ntlmssp = talloc_get_type_abort(gensec_security->private_data, struct gensec_ntlmssp_context); - struct gensec_ntlmssp_state *gensec_ntlmssp_state = gensec_ntlmssp->ntlmssp_state; - const char *domain = gensec_ntlmssp_state->domain; + struct ntlmssp_state *ntlmssp_state = gensec_ntlmssp->ntlmssp_state; + const char *domain = ntlmssp_state->domain; const char *workstation = cli_credentials_get_workstation(gensec_security->credentials); /* These don't really matter in the initial packet, so don't panic if they are not set */ @@ -63,14 +63,14 @@ NTSTATUS ntlmssp_client_initial(struct gensec_security *gensec_security, workstation = ""; } - if (gensec_ntlmssp_state->unicode) { - gensec_ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_UNICODE; + if (ntlmssp_state->unicode) { + ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_UNICODE; } else { - gensec_ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_OEM; + ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_OEM; } - if (gensec_ntlmssp_state->use_ntlmv2) { - gensec_ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_NTLM2; + if (ntlmssp_state->use_ntlmv2) { + ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_NTLM2; } /* generate the ntlmssp negotiate packet */ @@ -78,11 +78,11 @@ NTSTATUS ntlmssp_client_initial(struct gensec_security *gensec_security, out, "CddAA", "NTLMSSP", NTLMSSP_NEGOTIATE, - gensec_ntlmssp_state->neg_flags, + ntlmssp_state->neg_flags, domain, workstation); - gensec_ntlmssp_state->expected_state = NTLMSSP_CHALLENGE; + ntlmssp_state->expected_state = NTLMSSP_CHALLENGE; return NT_STATUS_MORE_PROCESSING_REQUIRED; } @@ -104,7 +104,7 @@ NTSTATUS ntlmssp_client_challenge(struct gensec_security *gensec_security, struct gensec_ntlmssp_context *gensec_ntlmssp = talloc_get_type_abort(gensec_security->private_data, struct gensec_ntlmssp_context); - struct gensec_ntlmssp_state *gensec_ntlmssp_state = gensec_ntlmssp->ntlmssp_state; + struct ntlmssp_state *ntlmssp_state = gensec_ntlmssp->ntlmssp_state; uint32_t chal_flags, ntlmssp_command, unkn1, unkn2; DATA_BLOB server_domain_blob; DATA_BLOB challenge_blob; @@ -144,9 +144,9 @@ NTSTATUS ntlmssp_client_challenge(struct gensec_security *gensec_security, DEBUG(3, ("Got challenge flags:\n")); debug_ntlmssp_flags(chal_flags); - ntlmssp_handle_neg_flags(gensec_ntlmssp_state, chal_flags, gensec_ntlmssp_state->allow_lm_key); + ntlmssp_handle_neg_flags(ntlmssp_state, chal_flags, ntlmssp_state->allow_lm_key); - if (gensec_ntlmssp_state->unicode) { + if (ntlmssp_state->unicode) { if (chal_flags & NTLMSSP_NEGOTIATE_TARGET_INFO) { chal_parse_string = "CdUdbddB"; } else { @@ -179,15 +179,15 @@ NTSTATUS ntlmssp_client_challenge(struct gensec_security *gensec_security, } if (chal_flags & NTLMSSP_TARGET_TYPE_SERVER) { - gensec_ntlmssp_state->server.is_standalone = true; + ntlmssp_state->server.is_standalone = true; } else { - gensec_ntlmssp_state->server.is_standalone = false; + ntlmssp_state->server.is_standalone = false; } /* TODO: parse struct_blob and fill in the rest */ - gensec_ntlmssp_state->server.netbios_name = ""; - gensec_ntlmssp_state->server.netbios_domain = server_domain; - gensec_ntlmssp_state->server.dns_name = ""; - gensec_ntlmssp_state->server.dns_domain = ""; + ntlmssp_state->server.netbios_name = ""; + ntlmssp_state->server.netbios_domain = server_domain; + ntlmssp_state->server.dns_name = ""; + ntlmssp_state->server.dns_domain = ""; if (challenge_blob.length != 8) { talloc_free(mem_ctx); @@ -197,13 +197,13 @@ NTSTATUS ntlmssp_client_challenge(struct gensec_security *gensec_security, cli_credentials_get_ntlm_username_domain(gensec_security->credentials, mem_ctx, &user, &domain); - if (gensec_ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_NTLM2) { + if (ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_NTLM2) { flags |= CLI_CRED_NTLM2; } - if (gensec_ntlmssp_state->use_ntlmv2) { + if (ntlmssp_state->use_ntlmv2) { flags |= CLI_CRED_NTLMv2_AUTH; } - if (gensec_ntlmssp_state->use_nt_response) { + if (ntlmssp_state->use_nt_response) { flags |= CLI_CRED_NTLM_AUTH; } if (lp_client_lanman_auth(gensec_security->settings->lp_ctx)) { @@ -222,15 +222,15 @@ NTSTATUS ntlmssp_client_challenge(struct gensec_security *gensec_security, if (!(flags & CLI_CRED_LANMAN_AUTH)) { /* LM Key is still possible, just silly. Fortunetly * we require command line options to end up here */ - /* gensec_ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_LM_KEY; */ + /* ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_LM_KEY; */ } if (!(flags & CLI_CRED_NTLM2)) { /* NTLM2 is incompatible... */ - gensec_ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_NTLM2; + ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_NTLM2; } - if ((gensec_ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_LM_KEY) + if ((ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_LM_KEY) && lp_client_lanman_auth(gensec_security->settings->lp_ctx) && lm_session_key.length == 16) { DATA_BLOB new_session_key = data_blob_talloc(mem_ctx, NULL, 16); if (lm_response.length == 24) { @@ -248,13 +248,13 @@ NTSTATUS ntlmssp_client_challenge(struct gensec_security *gensec_security, /* Key exchange encryptes a new client-generated session key with the password-derived key */ - if (gensec_ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_KEY_EXCH) { + if (ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_KEY_EXCH) { /* Make up a new session key */ uint8_t client_session_key[16]; generate_secret_buffer(client_session_key, sizeof(client_session_key)); /* Encrypt the new session key with the old one */ - encrypted_session_key = data_blob_talloc(gensec_ntlmssp_state, + encrypted_session_key = data_blob_talloc(ntlmssp_state, client_session_key, sizeof(client_session_key)); dump_data_pw("KEY_EXCH session key:\n", encrypted_session_key.data, encrypted_session_key.length); arcfour_crypt(encrypted_session_key.data, session_key.data, encrypted_session_key.length); @@ -265,7 +265,7 @@ NTSTATUS ntlmssp_client_challenge(struct gensec_security *gensec_security, } DEBUG(3, ("NTLMSSP: Set final flags:\n")); - debug_ntlmssp_flags(gensec_ntlmssp_state->neg_flags); + debug_ntlmssp_flags(ntlmssp_state->neg_flags); /* this generates the actual auth packet */ if (!msrpc_gen(mem_ctx, @@ -278,26 +278,26 @@ NTSTATUS ntlmssp_client_challenge(struct gensec_security *gensec_security, user, cli_credentials_get_workstation(gensec_security->credentials), encrypted_session_key.data, encrypted_session_key.length, - gensec_ntlmssp_state->neg_flags)) { + ntlmssp_state->neg_flags)) { talloc_free(mem_ctx); return NT_STATUS_NO_MEMORY; } - gensec_ntlmssp_state->session_key = session_key; - talloc_steal(gensec_ntlmssp_state, session_key.data); + ntlmssp_state->session_key = session_key; + talloc_steal(ntlmssp_state, session_key.data); talloc_steal(out_mem_ctx, out->data); - gensec_ntlmssp_state->chal = challenge_blob; - gensec_ntlmssp_state->lm_resp = lm_response; - talloc_steal(gensec_ntlmssp_state->lm_resp.data, lm_response.data); - gensec_ntlmssp_state->nt_resp = nt_response; - talloc_steal(gensec_ntlmssp_state->nt_resp.data, nt_response.data); + ntlmssp_state->chal = challenge_blob; + ntlmssp_state->lm_resp = lm_response; + talloc_steal(ntlmssp_state->lm_resp.data, lm_response.data); + ntlmssp_state->nt_resp = nt_response; + talloc_steal(ntlmssp_state->nt_resp.data, nt_response.data); - gensec_ntlmssp_state->expected_state = NTLMSSP_DONE; + ntlmssp_state->expected_state = NTLMSSP_DONE; if (gensec_security->want_features & (GENSEC_FEATURE_SIGN|GENSEC_FEATURE_SEAL)) { - nt_status = ntlmssp_sign_init(gensec_ntlmssp_state); + nt_status = ntlmssp_sign_init(ntlmssp_state); if (!NT_STATUS_IS_OK(nt_status)) { DEBUG(1, ("Could not setup NTLMSSP signing/sealing system (error was: %s)\n", nt_errstr(nt_status))); @@ -313,7 +313,7 @@ NTSTATUS ntlmssp_client_challenge(struct gensec_security *gensec_security, NTSTATUS gensec_ntlmssp_client_start(struct gensec_security *gensec_security) { struct gensec_ntlmssp_context *gensec_ntlmssp; - struct gensec_ntlmssp_state *gensec_ntlmssp_state; + struct ntlmssp_state *ntlmssp_state; NTSTATUS nt_status; nt_status = gensec_ntlmssp_start(gensec_security); @@ -321,53 +321,53 @@ NTSTATUS gensec_ntlmssp_client_start(struct gensec_security *gensec_security) gensec_ntlmssp = talloc_get_type_abort(gensec_security->private_data, struct gensec_ntlmssp_context); - gensec_ntlmssp_state = gensec_ntlmssp->ntlmssp_state; + ntlmssp_state = gensec_ntlmssp->ntlmssp_state; - gensec_ntlmssp_state->role = NTLMSSP_CLIENT; + ntlmssp_state->role = NTLMSSP_CLIENT; - gensec_ntlmssp_state->domain = lp_workgroup(gensec_security->settings->lp_ctx); + ntlmssp_state->domain = lp_workgroup(gensec_security->settings->lp_ctx); - gensec_ntlmssp_state->unicode = gensec_setting_bool(gensec_security->settings, "ntlmssp_client", "unicode", true); + ntlmssp_state->unicode = gensec_setting_bool(gensec_security->settings, "ntlmssp_client", "unicode", true); - gensec_ntlmssp_state->use_nt_response = gensec_setting_bool(gensec_security->settings, "ntlmssp_client", "send_nt_reponse", true); + ntlmssp_state->use_nt_response = gensec_setting_bool(gensec_security->settings, "ntlmssp_client", "send_nt_reponse", true); - gensec_ntlmssp_state->allow_lm_key = (lp_client_lanman_auth(gensec_security->settings->lp_ctx) + ntlmssp_state->allow_lm_key = (lp_client_lanman_auth(gensec_security->settings->lp_ctx) && (gensec_setting_bool(gensec_security->settings, "ntlmssp_client", "allow_lm_key", false) || gensec_setting_bool(gensec_security->settings, "ntlmssp_client", "lm_key", false))); - gensec_ntlmssp_state->use_ntlmv2 = lp_client_ntlmv2_auth(gensec_security->settings->lp_ctx); + ntlmssp_state->use_ntlmv2 = lp_client_ntlmv2_auth(gensec_security->settings->lp_ctx); - gensec_ntlmssp_state->expected_state = NTLMSSP_INITIAL; + ntlmssp_state->expected_state = NTLMSSP_INITIAL; - gensec_ntlmssp_state->neg_flags = + ntlmssp_state->neg_flags = NTLMSSP_NEGOTIATE_NTLM | NTLMSSP_REQUEST_TARGET; if (gensec_setting_bool(gensec_security->settings, "ntlmssp_client", "128bit", true)) { - gensec_ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_128; + ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_128; } if (gensec_setting_bool(gensec_security->settings, "ntlmssp_client", "56bit", false)) { - gensec_ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_56; + ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_56; } if (gensec_setting_bool(gensec_security->settings, "ntlmssp_client", "lm_key", false)) { - gensec_ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_LM_KEY; + ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_LM_KEY; } if (gensec_setting_bool(gensec_security->settings, "ntlmssp_client", "keyexchange", true)) { - gensec_ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_KEY_EXCH; + ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_KEY_EXCH; } if (gensec_setting_bool(gensec_security->settings, "ntlmssp_client", "alwayssign", true)) { - gensec_ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_ALWAYS_SIGN; + ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_ALWAYS_SIGN; } if (gensec_setting_bool(gensec_security->settings, "ntlmssp_client", "ntlm2", true)) { - gensec_ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_NTLM2; + ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_NTLM2; } else { /* apparently we can't do ntlmv2 if we don't do ntlm2 */ - gensec_ntlmssp_state->use_ntlmv2 = false; + ntlmssp_state->use_ntlmv2 = false; } if (gensec_security->want_features & GENSEC_FEATURE_SESSION_KEY) { @@ -380,14 +380,14 @@ NTSTATUS gensec_ntlmssp_client_start(struct gensec_security *gensec_security) * that it thinks is only used for NTLMSSP signing and * sealing. (It is actually pulled out and used directly) */ - gensec_ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_SIGN; + ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_SIGN; } if (gensec_security->want_features & GENSEC_FEATURE_SIGN) { - gensec_ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_SIGN; + ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_SIGN; } if (gensec_security->want_features & GENSEC_FEATURE_SEAL) { - gensec_ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_SIGN; - gensec_ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_SEAL; + ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_SIGN; + ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_SEAL; } return NT_STATUS_OK; diff --git a/source4/auth/ntlmssp/ntlmssp_server.c b/source4/auth/ntlmssp/ntlmssp_server.c index 488aa63620..537cf6d383 100644 --- a/source4/auth/ntlmssp/ntlmssp_server.c +++ b/source4/auth/ntlmssp/ntlmssp_server.c @@ -36,15 +36,15 @@ * */ -static NTSTATUS ntlmssp_set_username(struct gensec_ntlmssp_state *gensec_ntlmssp_state, const char *user) +static NTSTATUS ntlmssp_set_username(struct ntlmssp_state *ntlmssp_state, const char *user) { if (!user) { /* it should be at least "" */ DEBUG(1, ("NTLMSSP failed to set username - cannot accept NULL username\n")); return NT_STATUS_INVALID_PARAMETER; } - gensec_ntlmssp_state->user = talloc_strdup(gensec_ntlmssp_state, user); - if (!gensec_ntlmssp_state->user) { + ntlmssp_state->user = talloc_strdup(ntlmssp_state, user); + if (!ntlmssp_state->user) { return NT_STATUS_NO_MEMORY; } return NT_STATUS_OK; @@ -54,10 +54,10 @@ static NTSTATUS ntlmssp_set_username(struct gensec_ntlmssp_state *gensec_ntlmssp * Set a domain on an NTLMSSP context - ensures it is talloc()ed * */ -static NTSTATUS ntlmssp_set_domain(struct gensec_ntlmssp_state *gensec_ntlmssp_state, const char *domain) +static NTSTATUS ntlmssp_set_domain(struct ntlmssp_state *ntlmssp_state, const char *domain) { - gensec_ntlmssp_state->domain = talloc_strdup(gensec_ntlmssp_state, domain); - if (!gensec_ntlmssp_state->domain) { + ntlmssp_state->domain = talloc_strdup(ntlmssp_state, domain); + if (!ntlmssp_state->domain) { return NT_STATUS_NO_MEMORY; } return NT_STATUS_OK; @@ -67,10 +67,10 @@ static NTSTATUS ntlmssp_set_domain(struct gensec_ntlmssp_state *gensec_ntlmssp_s * Set a workstation on an NTLMSSP context - ensures it is talloc()ed * */ -static NTSTATUS ntlmssp_set_workstation(struct gensec_ntlmssp_state *gensec_ntlmssp_state, const char *workstation) +static NTSTATUS ntlmssp_set_workstation(struct ntlmssp_state *ntlmssp_state, const char *workstation) { - gensec_ntlmssp_state->workstation = talloc_strdup(gensec_ntlmssp_state, workstation); - if (!gensec_ntlmssp_state->workstation) { + ntlmssp_state->workstation = talloc_strdup(ntlmssp_state, workstation); + if (!ntlmssp_state->workstation) { return NT_STATUS_NO_MEMORY; } return NT_STATUS_OK; @@ -80,24 +80,24 @@ static NTSTATUS ntlmssp_set_workstation(struct gensec_ntlmssp_state *gensec_ntlm * Determine correct target name flags for reply, given server role * and negotiated flags * - * @param gensec_ntlmssp_state NTLMSSP State + * @param ntlmssp_state NTLMSSP State * @param neg_flags The flags from the packet * @param chal_flags The flags to be set in the reply packet * @return The 'target name' string. */ -static const char *ntlmssp_target_name(struct gensec_ntlmssp_state *gensec_ntlmssp_state, +static const char *ntlmssp_target_name(struct ntlmssp_state *ntlmssp_state, uint32_t neg_flags, uint32_t *chal_flags) { if (neg_flags & NTLMSSP_REQUEST_TARGET) { *chal_flags |= NTLMSSP_NEGOTIATE_TARGET_INFO; *chal_flags |= NTLMSSP_REQUEST_TARGET; - if (gensec_ntlmssp_state->server.is_standalone) { + if (ntlmssp_state->server.is_standalone) { *chal_flags |= NTLMSSP_TARGET_TYPE_SERVER; - return gensec_ntlmssp_state->server.netbios_name; + return ntlmssp_state->server.netbios_name; } else { *chal_flags |= NTLMSSP_TARGET_TYPE_DOMAIN; - return gensec_ntlmssp_state->server.netbios_domain; + return ntlmssp_state->server.netbios_domain; }; } else { return ""; @@ -123,7 +123,7 @@ NTSTATUS ntlmssp_server_negotiate(struct gensec_security *gensec_security, struct gensec_ntlmssp_context *gensec_ntlmssp = talloc_get_type_abort(gensec_security->private_data, struct gensec_ntlmssp_context); - struct gensec_ntlmssp_state *gensec_ntlmssp_state = gensec_ntlmssp->ntlmssp_state; + struct ntlmssp_state *ntlmssp_state = gensec_ntlmssp->ntlmssp_state; DATA_BLOB struct_blob; uint32_t neg_flags = 0; uint32_t ntlmssp_command, chal_flags; @@ -151,10 +151,10 @@ NTSTATUS ntlmssp_server_negotiate(struct gensec_security *gensec_security, debug_ntlmssp_flags(neg_flags); } - ntlmssp_handle_neg_flags(gensec_ntlmssp_state, neg_flags, gensec_ntlmssp_state->allow_lm_key); + ntlmssp_handle_neg_flags(ntlmssp_state, neg_flags, ntlmssp_state->allow_lm_key); /* Ask our caller what challenge they would like in the packet */ - status = gensec_ntlmssp_state->get_challenge(gensec_ntlmssp_state, cryptkey); + status = ntlmssp_state->get_challenge(ntlmssp_state, cryptkey); if (!NT_STATUS_IS_OK(status)) { DEBUG(1, ("ntlmssp_server_negotiate: backend doesn't give a challenge: %s\n", nt_errstr(status))); @@ -162,8 +162,8 @@ NTSTATUS ntlmssp_server_negotiate(struct gensec_security *gensec_security, } /* Check if we may set the challenge */ - if (!gensec_ntlmssp_state->may_set_challenge(gensec_ntlmssp_state)) { - gensec_ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_NTLM2; + if (!ntlmssp_state->may_set_challenge(ntlmssp_state)) { + ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_NTLM2; } /* The flags we send back are not just the negotiated flags, @@ -171,25 +171,25 @@ NTSTATUS ntlmssp_server_negotiate(struct gensec_security *gensec_security, * operate on 'chal_flags' from here on */ - chal_flags = gensec_ntlmssp_state->neg_flags; + chal_flags = ntlmssp_state->neg_flags; /* get the right name to fill in as 'target' */ - target_name = ntlmssp_target_name(gensec_ntlmssp_state, + target_name = ntlmssp_target_name(ntlmssp_state, neg_flags, &chal_flags); if (target_name == NULL) return NT_STATUS_INVALID_PARAMETER; - gensec_ntlmssp_state->chal = data_blob_talloc(gensec_ntlmssp_state, cryptkey, 8); - gensec_ntlmssp_state->internal_chal = data_blob_talloc(gensec_ntlmssp_state, cryptkey, 8); + ntlmssp_state->chal = data_blob_talloc(ntlmssp_state, cryptkey, 8); + ntlmssp_state->internal_chal = data_blob_talloc(ntlmssp_state, cryptkey, 8); /* This creates the 'blob' of names that appears at the end of the packet */ if (chal_flags & NTLMSSP_NEGOTIATE_TARGET_INFO) { msrpc_gen(out_mem_ctx, &struct_blob, "aaaaa", MsvAvNbDomainName, target_name, - MsvAvNbComputerName, gensec_ntlmssp_state->server.netbios_name, - MsvAvDnsDomainName, gensec_ntlmssp_state->server.dns_domain, - MsvAvDnsComputerName, gensec_ntlmssp_state->server.dns_name, + MsvAvNbComputerName, ntlmssp_state->server.netbios_name, + MsvAvDnsDomainName, ntlmssp_state->server.dns_domain, + MsvAvDnsComputerName, ntlmssp_state->server.dns_name, MsvAvEOL, ""); } else { struct_blob = data_blob(NULL, 0); @@ -198,7 +198,7 @@ NTSTATUS ntlmssp_server_negotiate(struct gensec_security *gensec_security, { /* Marshal the packet in the right format, be it unicode or ASCII */ const char *gen_string; - if (gensec_ntlmssp_state->unicode) { + if (ntlmssp_state->unicode) { gen_string = "CdUdbddB"; } else { gen_string = "CdAdbddB"; @@ -215,7 +215,7 @@ NTSTATUS ntlmssp_server_negotiate(struct gensec_security *gensec_security, struct_blob.data, struct_blob.length); } - gensec_ntlmssp_state->expected_state = NTLMSSP_AUTH; + ntlmssp_state->expected_state = NTLMSSP_AUTH; return NT_STATUS_MORE_PROCESSING_REQUIRED; } @@ -223,12 +223,12 @@ NTSTATUS ntlmssp_server_negotiate(struct gensec_security *gensec_security, /** * Next state function for the Authenticate packet * - * @param gensec_ntlmssp_state NTLMSSP State + * @param ntlmssp_state NTLMSSP State * @param request The request, as a DATA_BLOB * @return Errors or NT_STATUS_OK. */ -static NTSTATUS ntlmssp_server_preauth(struct gensec_ntlmssp_state *gensec_ntlmssp_state, +static NTSTATUS ntlmssp_server_preauth(struct ntlmssp_state *ntlmssp_state, const DATA_BLOB request) { uint32_t ntlmssp_command, auth_flags; @@ -245,55 +245,55 @@ static NTSTATUS ntlmssp_server_preauth(struct gensec_ntlmssp_state *gensec_ntlms file_save("ntlmssp_auth.dat", request.data, request.length); #endif - if (gensec_ntlmssp_state->unicode) { + if (ntlmssp_state->unicode) { parse_string = "CdBBUUUBd"; } else { parse_string = "CdBBAAABd"; } /* zero these out */ - data_blob_free(&gensec_ntlmssp_state->session_key); - data_blob_free(&gensec_ntlmssp_state->lm_resp); - data_blob_free(&gensec_ntlmssp_state->nt_resp); - data_blob_free(&gensec_ntlmssp_state->encrypted_session_key); + data_blob_free(&ntlmssp_state->session_key); + data_blob_free(&ntlmssp_state->lm_resp); + data_blob_free(&ntlmssp_state->nt_resp); + data_blob_free(&ntlmssp_state->encrypted_session_key); - gensec_ntlmssp_state->user = NULL; - gensec_ntlmssp_state->domain = NULL; - gensec_ntlmssp_state->workstation = NULL; + ntlmssp_state->user = NULL; + ntlmssp_state->domain = NULL; + ntlmssp_state->workstation = NULL; /* now the NTLMSSP encoded auth hashes */ - if (!msrpc_parse(gensec_ntlmssp_state, + if (!msrpc_parse(ntlmssp_state, &request, parse_string, "NTLMSSP", &ntlmssp_command, - &gensec_ntlmssp_state->lm_resp, - &gensec_ntlmssp_state->nt_resp, + &ntlmssp_state->lm_resp, + &ntlmssp_state->nt_resp, &domain, &user, &workstation, - &gensec_ntlmssp_state->encrypted_session_key, + &ntlmssp_state->encrypted_session_key, &auth_flags)) { DEBUG(10, ("ntlmssp_server_auth: failed to parse NTLMSSP (nonfatal):\n")); dump_data(10, request.data, request.length); /* zero this out */ - data_blob_free(&gensec_ntlmssp_state->encrypted_session_key); + data_blob_free(&ntlmssp_state->encrypted_session_key); auth_flags = 0; /* Try again with a shorter string (Win9X truncates this packet) */ - if (gensec_ntlmssp_state->unicode) { + if (ntlmssp_state->unicode) { parse_string = "CdBBUUU"; } else { parse_string = "CdBBAAA"; } /* now the NTLMSSP encoded auth hashes */ - if (!msrpc_parse(gensec_ntlmssp_state, + if (!msrpc_parse(ntlmssp_state, &request, parse_string, "NTLMSSP", &ntlmssp_command, - &gensec_ntlmssp_state->lm_resp, - &gensec_ntlmssp_state->nt_resp, + &ntlmssp_state->lm_resp, + &ntlmssp_state->nt_resp, &domain, &user, &workstation)) { @@ -305,32 +305,32 @@ static NTSTATUS ntlmssp_server_preauth(struct gensec_ntlmssp_state *gensec_ntlms } if (auth_flags) - ntlmssp_handle_neg_flags(gensec_ntlmssp_state, auth_flags, gensec_ntlmssp_state->allow_lm_key); + ntlmssp_handle_neg_flags(ntlmssp_state, auth_flags, ntlmssp_state->allow_lm_key); - if (!NT_STATUS_IS_OK(nt_status = ntlmssp_set_domain(gensec_ntlmssp_state, domain))) { + if (!NT_STATUS_IS_OK(nt_status = ntlmssp_set_domain(ntlmssp_state, domain))) { /* zero this out */ - data_blob_free(&gensec_ntlmssp_state->encrypted_session_key); + data_blob_free(&ntlmssp_state->encrypted_session_key); return nt_status; } - if (!NT_STATUS_IS_OK(nt_status = ntlmssp_set_username(gensec_ntlmssp_state, user))) { + if (!NT_STATUS_IS_OK(nt_status = ntlmssp_set_username(ntlmssp_state, user))) { /* zero this out */ - data_blob_free(&gensec_ntlmssp_state->encrypted_session_key); + data_blob_free(&ntlmssp_state->encrypted_session_key); return nt_status; } - if (!NT_STATUS_IS_OK(nt_status = ntlmssp_set_workstation(gensec_ntlmssp_state, workstation))) { + if (!NT_STATUS_IS_OK(nt_status = ntlmssp_set_workstation(ntlmssp_state, workstation))) { /* zero this out */ - data_blob_free(&gensec_ntlmssp_state->encrypted_session_key); + data_blob_free(&ntlmssp_state->encrypted_session_key); return nt_status; } DEBUG(3,("Got user=[%s] domain=[%s] workstation=[%s] len1=%lu len2=%lu\n", - gensec_ntlmssp_state->user, gensec_ntlmssp_state->domain, gensec_ntlmssp_state->workstation, (unsigned long)gensec_ntlmssp_state->lm_resp.length, (unsigned long)gensec_ntlmssp_state->nt_resp.length)); + ntlmssp_state->user, ntlmssp_state->domain, ntlmssp_state->workstation, (unsigned long)ntlmssp_state->lm_resp.length, (unsigned long)ntlmssp_state->nt_resp.length)); #if 0 - file_save("nthash1.dat", &gensec_ntlmssp_state->nt_resp.data, &gensec_ntlmssp_state->nt_resp.length); - file_save("lmhash1.dat", &gensec_ntlmssp_state->lm_resp.data, &gensec_ntlmssp_state->lm_resp.length); + file_save("nthash1.dat", &ntlmssp_state->nt_resp.data, &ntlmssp_state->nt_resp.length); + file_save("lmhash1.dat", &ntlmssp_state->lm_resp.data, &ntlmssp_state->lm_resp.length); #endif /* NTLM2 uses a 'challenge' that is made of up both the server challenge, and a @@ -338,38 +338,38 @@ static NTSTATUS ntlmssp_server_preauth(struct gensec_ntlmssp_state *gensec_ntlms However, the NTLM2 flag may still be set for the real NTLMv2 logins, be careful. */ - if (gensec_ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_NTLM2) { - if (gensec_ntlmssp_state->nt_resp.length == 24 && gensec_ntlmssp_state->lm_resp.length == 24) { + if (ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_NTLM2) { + if (ntlmssp_state->nt_resp.length == 24 && ntlmssp_state->lm_resp.length == 24) { struct MD5Context md5_session_nonce_ctx; - SMB_ASSERT(gensec_ntlmssp_state->internal_chal.data - && gensec_ntlmssp_state->internal_chal.length == 8); + SMB_ASSERT(ntlmssp_state->internal_chal.data + && ntlmssp_state->internal_chal.length == 8); - gensec_ntlmssp_state->doing_ntlm2 = true; + ntlmssp_state->doing_ntlm2 = true; - memcpy(gensec_ntlmssp_state->crypt.ntlm2.session_nonce, gensec_ntlmssp_state->internal_chal.data, 8); - memcpy(&gensec_ntlmssp_state->crypt.ntlm2.session_nonce[8], gensec_ntlmssp_state->lm_resp.data, 8); + memcpy(ntlmssp_state->crypt.ntlm2.session_nonce, ntlmssp_state->internal_chal.data, 8); + memcpy(&ntlmssp_state->crypt.ntlm2.session_nonce[8], ntlmssp_state->lm_resp.data, 8); MD5Init(&md5_session_nonce_ctx); - MD5Update(&md5_session_nonce_ctx, gensec_ntlmssp_state->crypt.ntlm2.session_nonce, 16); + MD5Update(&md5_session_nonce_ctx, ntlmssp_state->crypt.ntlm2.session_nonce, 16); MD5Final(session_nonce_hash, &md5_session_nonce_ctx); - gensec_ntlmssp_state->chal = data_blob_talloc(gensec_ntlmssp_state, + ntlmssp_state->chal = data_blob_talloc(ntlmssp_state, session_nonce_hash, 8); /* LM response is no longer useful, zero it out */ - data_blob_free(&gensec_ntlmssp_state->lm_resp); + data_blob_free(&ntlmssp_state->lm_resp); /* We changed the effective challenge - set it */ if (!NT_STATUS_IS_OK(nt_status = - gensec_ntlmssp_state->set_challenge(gensec_ntlmssp_state, - &gensec_ntlmssp_state->chal))) { + ntlmssp_state->set_challenge(ntlmssp_state, + &ntlmssp_state->chal))) { /* zero this out */ - data_blob_free(&gensec_ntlmssp_state->encrypted_session_key); + data_blob_free(&ntlmssp_state->encrypted_session_key); return nt_status; } /* LM Key is incompatible... */ - gensec_ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_LM_KEY; + ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_LM_KEY; } } return NT_STATUS_OK; @@ -379,7 +379,7 @@ static NTSTATUS ntlmssp_server_preauth(struct gensec_ntlmssp_state *gensec_ntlms * Next state function for the Authenticate packet * (after authentication - figures out the session keys etc) * - * @param gensec_ntlmssp_state NTLMSSP State + * @param ntlmssp_state NTLMSSP State * @return Errors or NT_STATUS_OK. */ @@ -390,7 +390,7 @@ static NTSTATUS ntlmssp_server_postauth(struct gensec_security *gensec_security, struct gensec_ntlmssp_context *gensec_ntlmssp = talloc_get_type_abort(gensec_security->private_data, struct gensec_ntlmssp_context); - struct gensec_ntlmssp_state *gensec_ntlmssp_state = gensec_ntlmssp->ntlmssp_state; + struct ntlmssp_state *ntlmssp_state = gensec_ntlmssp->ntlmssp_state; NTSTATUS nt_status; DATA_BLOB session_key = data_blob(NULL, 0); @@ -406,11 +406,11 @@ static NTSTATUS ntlmssp_server_postauth(struct gensec_security *gensec_security, dump_data_pw("LM first-8:\n", lm_session_key->data, lm_session_key->length); /* Handle the different session key derivation for NTLM2 */ - if (gensec_ntlmssp_state->doing_ntlm2) { + if (ntlmssp_state->doing_ntlm2) { if (user_session_key && user_session_key->data && user_session_key->length == 16) { - session_key = data_blob_talloc(gensec_ntlmssp_state, NULL, 16); - hmac_md5(user_session_key->data, gensec_ntlmssp_state->crypt.ntlm2.session_nonce, - sizeof(gensec_ntlmssp_state->crypt.ntlm2.session_nonce), session_key.data); + session_key = data_blob_talloc(ntlmssp_state, NULL, 16); + hmac_md5(user_session_key->data, ntlmssp_state->crypt.ntlm2.session_nonce, + sizeof(ntlmssp_state->crypt.ntlm2.session_nonce), session_key.data); DEBUG(10,("ntlmssp_server_auth: Created NTLM2 session key.\n")); dump_data_pw("NTLM2 session key:\n", session_key.data, session_key.length); @@ -418,14 +418,14 @@ static NTSTATUS ntlmssp_server_postauth(struct gensec_security *gensec_security, DEBUG(10,("ntlmssp_server_auth: Failed to create NTLM2 session key.\n")); session_key = data_blob(NULL, 0); } - } else if ((gensec_ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_LM_KEY) + } else if ((ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_LM_KEY) /* Ensure we can never get here on NTLMv2 */ - && (gensec_ntlmssp_state->nt_resp.length == 0 || gensec_ntlmssp_state->nt_resp.length == 24)) { + && (ntlmssp_state->nt_resp.length == 0 || ntlmssp_state->nt_resp.length == 24)) { if (lm_session_key && lm_session_key->data && lm_session_key->length >= 8) { - if (gensec_ntlmssp_state->lm_resp.data && gensec_ntlmssp_state->lm_resp.length == 24) { - session_key = data_blob_talloc(gensec_ntlmssp_state, NULL, 16); - SMBsesskeygen_lm_sess_key(lm_session_key->data, gensec_ntlmssp_state->lm_resp.data, + if (ntlmssp_state->lm_resp.data && ntlmssp_state->lm_resp.length == 24) { + session_key = data_blob_talloc(ntlmssp_state, NULL, 16); + SMBsesskeygen_lm_sess_key(lm_session_key->data, ntlmssp_state->lm_resp.data, session_key.data); DEBUG(10,("ntlmssp_server_auth: Created NTLM session key.\n")); dump_data_pw("LM session key:\n", session_key.data, session_key.length); @@ -433,7 +433,7 @@ static NTSTATUS ntlmssp_server_postauth(struct gensec_security *gensec_security, /* When there is no LM response, just use zeros */ static const uint8_t zeros[24]; - session_key = data_blob_talloc(gensec_ntlmssp_state, NULL, 16); + session_key = data_blob_talloc(ntlmssp_state, NULL, 16); SMBsesskeygen_lm_sess_key(zeros, zeros, session_key.data); DEBUG(10,("ntlmssp_server_auth: Created NTLM session key.\n")); @@ -441,85 +441,85 @@ static NTSTATUS ntlmssp_server_postauth(struct gensec_security *gensec_security, } } else { /* LM Key not selected */ - gensec_ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_LM_KEY; + ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_LM_KEY; DEBUG(10,("ntlmssp_server_auth: Failed to create NTLM session key.\n")); session_key = data_blob(NULL, 0); } } else if (user_session_key && user_session_key->data) { - session_key = data_blob_talloc(gensec_ntlmssp_state, user_session_key->data, user_session_key->length); + session_key = data_blob_talloc(ntlmssp_state, user_session_key->data, user_session_key->length); DEBUG(10,("ntlmssp_server_auth: Using unmodified nt session key.\n")); dump_data_pw("unmodified session key:\n", session_key.data, session_key.length); /* LM Key not selected */ - gensec_ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_LM_KEY; + ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_LM_KEY; } else if (lm_session_key && lm_session_key->data) { /* Very weird to have LM key, but no user session key, but anyway.. */ - session_key = data_blob_talloc(gensec_ntlmssp_state, lm_session_key->data, lm_session_key->length); + session_key = data_blob_talloc(ntlmssp_state, lm_session_key->data, lm_session_key->length); DEBUG(10,("ntlmssp_server_auth: Using unmodified lm session key.\n")); dump_data_pw("unmodified session key:\n", session_key.data, session_key.length); /* LM Key not selected */ - gensec_ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_LM_KEY; + ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_LM_KEY; } else { DEBUG(10,("ntlmssp_server_auth: Failed to create unmodified session key.\n")); session_key = data_blob(NULL, 0); /* LM Key not selected */ - gensec_ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_LM_KEY; + ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_LM_KEY; } /* With KEY_EXCH, the client supplies the proposed session key, but encrypts it with the long-term key */ - if (gensec_ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_KEY_EXCH) { - if (!gensec_ntlmssp_state->encrypted_session_key.data - || gensec_ntlmssp_state->encrypted_session_key.length != 16) { - data_blob_free(&gensec_ntlmssp_state->encrypted_session_key); + if (ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_KEY_EXCH) { + if (!ntlmssp_state->encrypted_session_key.data + || ntlmssp_state->encrypted_session_key.length != 16) { + data_blob_free(&ntlmssp_state->encrypted_session_key); DEBUG(1, ("Client-supplied KEY_EXCH session key was of invalid length (%u)!\n", - (unsigned)gensec_ntlmssp_state->encrypted_session_key.length)); + (unsigned)ntlmssp_state->encrypted_session_key.length)); return NT_STATUS_INVALID_PARAMETER; } else if (!session_key.data || session_key.length != 16) { DEBUG(5, ("server session key is invalid (len == %u), cannot do KEY_EXCH!\n", (unsigned)session_key.length)); - gensec_ntlmssp_state->session_key = session_key; + ntlmssp_state->session_key = session_key; } else { dump_data_pw("KEY_EXCH session key (enc):\n", - gensec_ntlmssp_state->encrypted_session_key.data, - gensec_ntlmssp_state->encrypted_session_key.length); - arcfour_crypt(gensec_ntlmssp_state->encrypted_session_key.data, + ntlmssp_state->encrypted_session_key.data, + ntlmssp_state->encrypted_session_key.length); + arcfour_crypt(ntlmssp_state->encrypted_session_key.data, session_key.data, - gensec_ntlmssp_state->encrypted_session_key.length); - gensec_ntlmssp_state->session_key = data_blob_talloc(gensec_ntlmssp_state, - gensec_ntlmssp_state->encrypted_session_key.data, - gensec_ntlmssp_state->encrypted_session_key.length); - dump_data_pw("KEY_EXCH session key:\n", gensec_ntlmssp_state->encrypted_session_key.data, - gensec_ntlmssp_state->encrypted_session_key.length); + ntlmssp_state->encrypted_session_key.length); + ntlmssp_state->session_key = data_blob_talloc(ntlmssp_state, + ntlmssp_state->encrypted_session_key.data, + ntlmssp_state->encrypted_session_key.length); + dump_data_pw("KEY_EXCH session key:\n", ntlmssp_state->encrypted_session_key.data, + ntlmssp_state->encrypted_session_key.length); talloc_free(session_key.data); } } else { - gensec_ntlmssp_state->session_key = session_key; + ntlmssp_state->session_key = session_key; } if ((gensec_security->want_features & GENSEC_FEATURE_SIGN) || (gensec_security->want_features & GENSEC_FEATURE_SEAL)) { - nt_status = ntlmssp_sign_init(gensec_ntlmssp_state); + nt_status = ntlmssp_sign_init(ntlmssp_state); } else { nt_status = NT_STATUS_OK; } - data_blob_free(&gensec_ntlmssp_state->encrypted_session_key); + data_blob_free(&ntlmssp_state->encrypted_session_key); /* allow arbitarily many authentications, but watch that this will cause a - memory leak, until the gensec_ntlmssp_state is shutdown + memory leak, until the ntlmssp_state is shutdown */ - if (gensec_ntlmssp_state->server_multiple_authentications) { - gensec_ntlmssp_state->expected_state = NTLMSSP_AUTH; + if (ntlmssp_state->server_multiple_authentications) { + ntlmssp_state->expected_state = NTLMSSP_AUTH; } else { - gensec_ntlmssp_state->expected_state = NTLMSSP_DONE; + ntlmssp_state->expected_state = NTLMSSP_DONE; } return nt_status; @@ -543,7 +543,7 @@ NTSTATUS ntlmssp_server_auth(struct gensec_security *gensec_security, struct gensec_ntlmssp_context *gensec_ntlmssp = talloc_get_type_abort(gensec_security->private_data, struct gensec_ntlmssp_context); - struct gensec_ntlmssp_state *gensec_ntlmssp_state = gensec_ntlmssp->ntlmssp_state; + struct ntlmssp_state *ntlmssp_state = gensec_ntlmssp->ntlmssp_state; DATA_BLOB user_session_key = data_blob_null; DATA_BLOB lm_session_key = data_blob_null; NTSTATUS nt_status; @@ -551,7 +551,7 @@ NTSTATUS ntlmssp_server_auth(struct gensec_security *gensec_security, /* zero the outbound NTLMSSP packet */ *out = data_blob_null; - nt_status = ntlmssp_server_preauth(gensec_ntlmssp_state, in); + nt_status = ntlmssp_server_preauth(ntlmssp_state, in); if (!NT_STATUS_IS_OK(nt_status)) { return nt_status; } @@ -564,7 +564,7 @@ NTSTATUS ntlmssp_server_auth(struct gensec_security *gensec_security, */ /* Finally, actually ask if the password is OK */ - nt_status = gensec_ntlmssp_state->check_password(gensec_ntlmssp_state, + nt_status = ntlmssp_state->check_password(ntlmssp_state, &user_session_key, &lm_session_key); if (!NT_STATUS_IS_OK(nt_status)) { @@ -586,11 +586,11 @@ NTSTATUS ntlmssp_server_auth(struct gensec_security *gensec_security, * @return an 8 byte random challenge */ -static NTSTATUS auth_ntlmssp_get_challenge(const struct gensec_ntlmssp_state *gensec_ntlmssp_state, +static NTSTATUS auth_ntlmssp_get_challenge(const struct ntlmssp_state *ntlmssp_state, uint8_t chal[8]) { struct gensec_ntlmssp_context *gensec_ntlmssp = - talloc_get_type_abort(gensec_ntlmssp_state->callback_private, + talloc_get_type_abort(ntlmssp_state->callback_private, struct gensec_ntlmssp_context); struct auth_context *auth_context = gensec_ntlmssp->auth_context; NTSTATUS status; @@ -610,10 +610,10 @@ static NTSTATUS auth_ntlmssp_get_challenge(const struct gensec_ntlmssp_state *ge * * @return If the effective challenge used by the auth subsystem may be modified */ -static bool auth_ntlmssp_may_set_challenge(const struct gensec_ntlmssp_state *gensec_ntlmssp_state) +static bool auth_ntlmssp_may_set_challenge(const struct ntlmssp_state *ntlmssp_state) { struct gensec_ntlmssp_context *gensec_ntlmssp = - talloc_get_type_abort(gensec_ntlmssp_state->callback_private, + talloc_get_type_abort(ntlmssp_state->callback_private, struct gensec_ntlmssp_context); struct auth_context *auth_context = gensec_ntlmssp->auth_context; @@ -624,10 +624,10 @@ static bool auth_ntlmssp_may_set_challenge(const struct gensec_ntlmssp_state *ge * NTLM2 authentication modifies the effective challenge, * @param challenge The new challenge value */ -static NTSTATUS auth_ntlmssp_set_challenge(struct gensec_ntlmssp_state *gensec_ntlmssp_state, DATA_BLOB *challenge) +static NTSTATUS auth_ntlmssp_set_challenge(struct ntlmssp_state *ntlmssp_state, DATA_BLOB *challenge) { struct gensec_ntlmssp_context *gensec_ntlmssp = - talloc_get_type_abort(gensec_ntlmssp_state->callback_private, + talloc_get_type_abort(ntlmssp_state->callback_private, struct gensec_ntlmssp_context); struct auth_context *auth_context = gensec_ntlmssp->auth_context; NTSTATUS nt_status; @@ -652,17 +652,17 @@ static NTSTATUS auth_ntlmssp_set_challenge(struct gensec_ntlmssp_state *gensec_n * Return the session keys used on the connection. */ -static NTSTATUS auth_ntlmssp_check_password(struct gensec_ntlmssp_state *gensec_ntlmssp_state, +static NTSTATUS auth_ntlmssp_check_password(struct ntlmssp_state *ntlmssp_state, DATA_BLOB *user_session_key, DATA_BLOB *lm_session_key) { struct gensec_ntlmssp_context *gensec_ntlmssp = - talloc_get_type_abort(gensec_ntlmssp_state->callback_private, + talloc_get_type_abort(ntlmssp_state->callback_private, struct gensec_ntlmssp_context); struct auth_context *auth_context = gensec_ntlmssp->auth_context; NTSTATUS nt_status; struct auth_usersupplied_info *user_info; - user_info = talloc(gensec_ntlmssp_state, struct auth_usersupplied_info); + user_info = talloc(ntlmssp_state, struct auth_usersupplied_info); if (!user_info) { return NT_STATUS_NO_MEMORY; } @@ -670,16 +670,16 @@ static NTSTATUS auth_ntlmssp_check_password(struct gensec_ntlmssp_state *gensec_ user_info->logon_parameters = MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT | MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT; user_info->flags = 0; user_info->mapped_state = false; - user_info->client.account_name = gensec_ntlmssp_state->user; - user_info->client.domain_name = gensec_ntlmssp_state->domain; - user_info->workstation_name = gensec_ntlmssp_state->workstation; + user_info->client.account_name = ntlmssp_state->user; + user_info->client.domain_name = ntlmssp_state->domain; + user_info->workstation_name = ntlmssp_state->workstation; user_info->remote_host = gensec_get_remote_address(gensec_ntlmssp->gensec_security); user_info->password_state = AUTH_PASSWORD_RESPONSE; - user_info->password.response.lanman = gensec_ntlmssp_state->lm_resp; - user_info->password.response.lanman.data = talloc_steal(user_info, gensec_ntlmssp_state->lm_resp.data); - user_info->password.response.nt = gensec_ntlmssp_state->nt_resp; - user_info->password.response.nt.data = talloc_steal(user_info, gensec_ntlmssp_state->nt_resp.data); + user_info->password.response.lanman = ntlmssp_state->lm_resp; + user_info->password.response.lanman.data = talloc_steal(user_info, ntlmssp_state->lm_resp.data); + user_info->password.response.nt = ntlmssp_state->nt_resp; + user_info->password.response.nt.data = talloc_steal(user_info, ntlmssp_state->nt_resp.data); nt_status = auth_context->check_password(auth_context, gensec_ntlmssp, @@ -718,9 +718,9 @@ NTSTATUS gensec_ntlmssp_session_info(struct gensec_security *gensec_security, struct gensec_ntlmssp_context *gensec_ntlmssp = talloc_get_type_abort(gensec_security->private_data, struct gensec_ntlmssp_context); - struct gensec_ntlmssp_state *gensec_ntlmssp_state = gensec_ntlmssp->ntlmssp_state; + struct ntlmssp_state *ntlmssp_state = gensec_ntlmssp->ntlmssp_state; - nt_status = auth_generate_session_info(gensec_ntlmssp_state, + nt_status = auth_generate_session_info(ntlmssp_state, gensec_security->event_ctx, gensec_security->settings->lp_ctx, gensec_ntlmssp->server_info, @@ -728,8 +728,8 @@ NTSTATUS gensec_ntlmssp_session_info(struct gensec_security *gensec_security, NT_STATUS_NOT_OK_RETURN(nt_status); (*session_info)->session_key = data_blob_talloc(*session_info, - gensec_ntlmssp_state->session_key.data, - gensec_ntlmssp_state->session_key.length); + ntlmssp_state->session_key.data, + ntlmssp_state->session_key.length); return NT_STATUS_OK; } @@ -741,7 +741,7 @@ NTSTATUS gensec_ntlmssp_session_info(struct gensec_security *gensec_security, NTSTATUS gensec_ntlmssp_server_start(struct gensec_security *gensec_security) { NTSTATUS nt_status; - struct gensec_ntlmssp_state *gensec_ntlmssp_state; + struct ntlmssp_state *ntlmssp_state; struct gensec_ntlmssp_context *gensec_ntlmssp; nt_status = gensec_ntlmssp_start(gensec_security); @@ -749,66 +749,66 @@ NTSTATUS gensec_ntlmssp_server_start(struct gensec_security *gensec_security) gensec_ntlmssp = talloc_get_type_abort(gensec_security->private_data, struct gensec_ntlmssp_context); - gensec_ntlmssp_state = gensec_ntlmssp->ntlmssp_state; + ntlmssp_state = gensec_ntlmssp->ntlmssp_state; - gensec_ntlmssp_state->role = NTLMSSP_SERVER; + ntlmssp_state->role = NTLMSSP_SERVER; - gensec_ntlmssp_state->expected_state = NTLMSSP_NEGOTIATE; + ntlmssp_state->expected_state = NTLMSSP_NEGOTIATE; - gensec_ntlmssp_state->allow_lm_key = (lp_lanman_auth(gensec_security->settings->lp_ctx) + ntlmssp_state->allow_lm_key = (lp_lanman_auth(gensec_security->settings->lp_ctx) && gensec_setting_bool(gensec_security->settings, "ntlmssp_server", "allow_lm_key", false)); - gensec_ntlmssp_state->server_multiple_authentications = false; + ntlmssp_state->server_multiple_authentications = false; - gensec_ntlmssp_state->neg_flags = + ntlmssp_state->neg_flags = NTLMSSP_NEGOTIATE_NTLM | NTLMSSP_NEGOTIATE_VERSION; - gensec_ntlmssp_state->lm_resp = data_blob(NULL, 0); - gensec_ntlmssp_state->nt_resp = data_blob(NULL, 0); - gensec_ntlmssp_state->encrypted_session_key = data_blob(NULL, 0); + ntlmssp_state->lm_resp = data_blob(NULL, 0); + ntlmssp_state->nt_resp = data_blob(NULL, 0); + ntlmssp_state->encrypted_session_key = data_blob(NULL, 0); if (gensec_setting_bool(gensec_security->settings, "ntlmssp_server", "128bit", true)) { - gensec_ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_128; + ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_128; } if (gensec_setting_bool(gensec_security->settings, "ntlmssp_server", "56bit", true)) { - gensec_ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_56; + ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_56; } if (gensec_setting_bool(gensec_security->settings, "ntlmssp_server", "keyexchange", true)) { - gensec_ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_KEY_EXCH; + ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_KEY_EXCH; } if (gensec_setting_bool(gensec_security->settings, "ntlmssp_server", "alwayssign", true)) { - gensec_ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_ALWAYS_SIGN; + ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_ALWAYS_SIGN; } if (gensec_setting_bool(gensec_security->settings, "ntlmssp_server", "ntlm2", true)) { - gensec_ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_NTLM2; + ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_NTLM2; } if (gensec_security->want_features & GENSEC_FEATURE_SIGN) { - gensec_ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_SIGN; + ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_SIGN; } if (gensec_security->want_features & GENSEC_FEATURE_SEAL) { - gensec_ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_SEAL; + ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_SEAL; } gensec_ntlmssp->auth_context = gensec_security->auth_context; - gensec_ntlmssp_state->get_challenge = auth_ntlmssp_get_challenge; - gensec_ntlmssp_state->may_set_challenge = auth_ntlmssp_may_set_challenge; - gensec_ntlmssp_state->set_challenge = auth_ntlmssp_set_challenge; - gensec_ntlmssp_state->check_password = auth_ntlmssp_check_password; + ntlmssp_state->get_challenge = auth_ntlmssp_get_challenge; + ntlmssp_state->may_set_challenge = auth_ntlmssp_may_set_challenge; + ntlmssp_state->set_challenge = auth_ntlmssp_set_challenge; + ntlmssp_state->check_password = auth_ntlmssp_check_password; if (lp_server_role(gensec_security->settings->lp_ctx) == ROLE_STANDALONE) { - gensec_ntlmssp_state->server.is_standalone = true; + ntlmssp_state->server.is_standalone = true; } else { - gensec_ntlmssp_state->server.is_standalone = false; + ntlmssp_state->server.is_standalone = false; } - gensec_ntlmssp_state->server.netbios_name = lp_netbios_name(gensec_security->settings->lp_ctx); + ntlmssp_state->server.netbios_name = lp_netbios_name(gensec_security->settings->lp_ctx); - gensec_ntlmssp_state->server.netbios_domain = lp_workgroup(gensec_security->settings->lp_ctx); + ntlmssp_state->server.netbios_domain = lp_workgroup(gensec_security->settings->lp_ctx); { char dnsdomname[MAXHOSTNAMELEN], dnsname[MAXHOSTNAMELEN]; @@ -818,20 +818,20 @@ NTSTATUS gensec_ntlmssp_server_start(struct gensec_security *gensec_security) safe_strcpy(dnsdomname, lp_dnsdomain(gensec_security->settings->lp_ctx), sizeof(dnsdomname) - 1); /* Find out the DNS host name */ - safe_strcpy(dnsname, gensec_ntlmssp_state->server.netbios_name, sizeof(dnsname) - 1); + safe_strcpy(dnsname, ntlmssp_state->server.netbios_name, sizeof(dnsname) - 1); if (dnsdomname[0] != '\0') { safe_strcat(dnsname, ".", sizeof(dnsname) - 1); safe_strcat(dnsname, dnsdomname, sizeof(dnsname) - 1); } strlower_m(dnsname); - gensec_ntlmssp_state->server.dns_name = talloc_strdup(gensec_ntlmssp_state, + ntlmssp_state->server.dns_name = talloc_strdup(ntlmssp_state, dnsname); - NT_STATUS_HAVE_NO_MEMORY(gensec_ntlmssp_state->server.dns_name); + NT_STATUS_HAVE_NO_MEMORY(ntlmssp_state->server.dns_name); - gensec_ntlmssp_state->server.dns_domain = talloc_strdup(gensec_ntlmssp_state, + ntlmssp_state->server.dns_domain = talloc_strdup(ntlmssp_state, dnsdomname); - NT_STATUS_HAVE_NO_MEMORY(gensec_ntlmssp_state->server.dns_domain); + NT_STATUS_HAVE_NO_MEMORY(ntlmssp_state->server.dns_domain); } return NT_STATUS_OK; diff --git a/source4/auth/ntlmssp/ntlmssp_sign.c b/source4/auth/ntlmssp/ntlmssp_sign.c index 62b5f61766..7877439962 100644 --- a/source4/auth/ntlmssp/ntlmssp_sign.c +++ b/source4/auth/ntlmssp/ntlmssp_sign.c @@ -58,14 +58,14 @@ enum ntlmssp_direction { NTLMSSP_RECEIVE }; -static NTSTATUS ntlmssp_make_packet_signature(struct gensec_ntlmssp_state *gensec_ntlmssp_state, +static NTSTATUS ntlmssp_make_packet_signature(struct ntlmssp_state *ntlmssp_state, TALLOC_CTX *sig_mem_ctx, const uint8_t *data, size_t length, const uint8_t *whole_pdu, size_t pdu_length, enum ntlmssp_direction direction, DATA_BLOB *sig, bool encrypt_sig) { - if (gensec_ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_NTLM2) { + if (ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_NTLM2) { HMACMD5Context ctx; uint8_t digest[16]; @@ -78,29 +78,29 @@ static NTSTATUS ntlmssp_make_packet_signature(struct gensec_ntlmssp_state *gense switch (direction) { case NTLMSSP_SEND: - SIVAL(seq_num, 0, gensec_ntlmssp_state->crypt.ntlm2.send_seq_num); - gensec_ntlmssp_state->crypt.ntlm2.send_seq_num++; - hmac_md5_init_limK_to_64(gensec_ntlmssp_state->crypt.ntlm2.send_sign_key.data, - gensec_ntlmssp_state->crypt.ntlm2.send_sign_key.length, &ctx); + SIVAL(seq_num, 0, ntlmssp_state->crypt.ntlm2.send_seq_num); + ntlmssp_state->crypt.ntlm2.send_seq_num++; + hmac_md5_init_limK_to_64(ntlmssp_state->crypt.ntlm2.send_sign_key.data, + ntlmssp_state->crypt.ntlm2.send_sign_key.length, &ctx); break; case NTLMSSP_RECEIVE: - SIVAL(seq_num, 0, gensec_ntlmssp_state->crypt.ntlm2.recv_seq_num); - gensec_ntlmssp_state->crypt.ntlm2.recv_seq_num++; - hmac_md5_init_limK_to_64(gensec_ntlmssp_state->crypt.ntlm2.recv_sign_key.data, - gensec_ntlmssp_state->crypt.ntlm2.recv_sign_key.length, &ctx); + SIVAL(seq_num, 0, ntlmssp_state->crypt.ntlm2.recv_seq_num); + ntlmssp_state->crypt.ntlm2.recv_seq_num++; + hmac_md5_init_limK_to_64(ntlmssp_state->crypt.ntlm2.recv_sign_key.data, + ntlmssp_state->crypt.ntlm2.recv_sign_key.length, &ctx); break; } hmac_md5_update(seq_num, sizeof(seq_num), &ctx); hmac_md5_update(whole_pdu, pdu_length, &ctx); hmac_md5_final(digest, &ctx); - if (encrypt_sig && gensec_ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_KEY_EXCH) { + if (encrypt_sig && ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_KEY_EXCH) { switch (direction) { case NTLMSSP_SEND: - arcfour_crypt_sbox(gensec_ntlmssp_state->crypt.ntlm2.send_seal_arcfour_state, digest, 8); + arcfour_crypt_sbox(ntlmssp_state->crypt.ntlm2.send_seal_arcfour_state, digest, 8); break; case NTLMSSP_RECEIVE: - arcfour_crypt_sbox(gensec_ntlmssp_state->crypt.ntlm2.recv_seal_arcfour_state, digest, 8); + arcfour_crypt_sbox(ntlmssp_state->crypt.ntlm2.recv_seal_arcfour_state, digest, 8); break; } } @@ -116,12 +116,13 @@ static NTSTATUS ntlmssp_make_packet_signature(struct gensec_ntlmssp_state *gense uint32_t crc; crc = crc32_calc_buffer(data, length); if (!msrpc_gen(sig_mem_ctx, - sig, "dddd", NTLMSSP_SIGN_VERSION, 0, crc, gensec_ntlmssp_state->crypt.ntlm.seq_num)) { + sig, "dddd", NTLMSSP_SIGN_VERSION, 0, + crc, ntlmssp_state->crypt.ntlm.seq_num)) { return NT_STATUS_NO_MEMORY; } - gensec_ntlmssp_state->crypt.ntlm.seq_num++; + ntlmssp_state->crypt.ntlm.seq_num++; - arcfour_crypt_sbox(gensec_ntlmssp_state->crypt.ntlm.arcfour_state, sig->data+4, sig->length-4); + arcfour_crypt_sbox(ntlmssp_state->crypt.ntlm.arcfour_state, sig->data+4, sig->length-4); DEBUG(10, ("NTLM1: created signature over %llu bytes of input:\n", (unsigned long long)length)); dump_data(11, sig->data, sig->length); @@ -129,7 +130,7 @@ static NTSTATUS ntlmssp_make_packet_signature(struct gensec_ntlmssp_state *gense return NT_STATUS_OK; } -NTSTATUS ntlmssp_sign_packet(struct gensec_ntlmssp_state *ntlmssp_state, +NTSTATUS ntlmssp_sign_packet(struct ntlmssp_state *ntlmssp_state, TALLOC_CTX *sig_mem_ctx, const uint8_t *data, size_t length, const uint8_t *whole_pdu, size_t pdu_length, @@ -147,7 +148,7 @@ NTSTATUS ntlmssp_sign_packet(struct gensec_ntlmssp_state *ntlmssp_state, * */ -NTSTATUS ntlmssp_check_packet(struct gensec_ntlmssp_state *ntlmssp_state, +NTSTATUS ntlmssp_check_packet(struct ntlmssp_state *ntlmssp_state, TALLOC_CTX *sig_mem_ctx, const uint8_t *data, size_t length, const uint8_t *whole_pdu, size_t pdu_length, @@ -211,7 +212,7 @@ NTSTATUS ntlmssp_check_packet(struct gensec_ntlmssp_state *ntlmssp_state, * */ -NTSTATUS ntlmssp_seal_packet(struct gensec_ntlmssp_state *ntlmssp_state, +NTSTATUS ntlmssp_seal_packet(struct ntlmssp_state *ntlmssp_state, TALLOC_CTX *sig_mem_ctx, uint8_t *data, size_t length, const uint8_t *whole_pdu, size_t pdu_length, @@ -271,7 +272,7 @@ NTSTATUS ntlmssp_seal_packet(struct gensec_ntlmssp_state *ntlmssp_state, * */ -NTSTATUS ntlmssp_unseal_packet(struct gensec_ntlmssp_state *ntlmssp_state, +NTSTATUS ntlmssp_unseal_packet(struct ntlmssp_state *ntlmssp_state, TALLOC_CTX *sig_mem_ctx, uint8_t *data, size_t length, const uint8_t *whole_pdu, size_t pdu_length, @@ -303,26 +304,26 @@ NTSTATUS ntlmssp_unseal_packet(struct gensec_ntlmssp_state *ntlmssp_state, Initialise the state for NTLMSSP signing. */ /* TODO: make this non-public */ -NTSTATUS ntlmssp_sign_init(struct gensec_ntlmssp_state *gensec_ntlmssp_state) +NTSTATUS ntlmssp_sign_init(struct ntlmssp_state *ntlmssp_state) { - TALLOC_CTX *mem_ctx = talloc_new(gensec_ntlmssp_state); + TALLOC_CTX *mem_ctx = talloc_new(ntlmssp_state); if (!mem_ctx) { return NT_STATUS_NO_MEMORY; } DEBUG(3, ("NTLMSSP Sign/Seal - Initialising with flags:\n")); - debug_ntlmssp_flags(gensec_ntlmssp_state->neg_flags); + debug_ntlmssp_flags(ntlmssp_state->neg_flags); - if (gensec_ntlmssp_state->session_key.length < 8) { + if (ntlmssp_state->session_key.length < 8) { talloc_free(mem_ctx); DEBUG(3, ("NO session key, cannot intialise signing\n")); return NT_STATUS_NO_USER_SESSION_KEY; } - if (gensec_ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_NTLM2) + if (ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_NTLM2) { - DATA_BLOB weak_session_key = gensec_ntlmssp_state->session_key; + DATA_BLOB weak_session_key = ntlmssp_state->session_key; const char *send_sign_const; const char *send_seal_const; const char *recv_sign_const; @@ -331,7 +332,7 @@ NTSTATUS ntlmssp_sign_init(struct gensec_ntlmssp_state *gensec_ntlmssp_state) DATA_BLOB send_seal_key; DATA_BLOB recv_seal_key; - switch (gensec_ntlmssp_state->role) { + switch (ntlmssp_state->role) { case NTLMSSP_CLIENT: send_sign_const = CLI_SIGN; send_seal_const = CLI_SEAL; @@ -349,10 +350,10 @@ NTSTATUS ntlmssp_sign_init(struct gensec_ntlmssp_state *gensec_ntlmssp_state) return NT_STATUS_INTERNAL_ERROR; } - gensec_ntlmssp_state->crypt.ntlm2.send_seal_arcfour_state = talloc(gensec_ntlmssp_state, struct arcfour_state); - NT_STATUS_HAVE_NO_MEMORY(gensec_ntlmssp_state->crypt.ntlm2.send_seal_arcfour_state); - gensec_ntlmssp_state->crypt.ntlm2.recv_seal_arcfour_state = talloc(gensec_ntlmssp_state, struct arcfour_state); - NT_STATUS_HAVE_NO_MEMORY(gensec_ntlmssp_state->crypt.ntlm2.send_seal_arcfour_state); + ntlmssp_state->crypt.ntlm2.send_seal_arcfour_state = talloc(ntlmssp_state, struct arcfour_state); + NT_STATUS_HAVE_NO_MEMORY(ntlmssp_state->crypt.ntlm2.send_seal_arcfour_state); + ntlmssp_state->crypt.ntlm2.recv_seal_arcfour_state = talloc(ntlmssp_state, struct arcfour_state); + NT_STATUS_HAVE_NO_MEMORY(ntlmssp_state->crypt.ntlm2.send_seal_arcfour_state); /** Weaken NTLMSSP keys to cope with down-level @@ -368,9 +369,9 @@ NTSTATUS ntlmssp_sign_init(struct gensec_ntlmssp_state *gensec_ntlmssp_state) * we don't have this code for the ntlmv1 case. */ - if (gensec_ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_128) { + if (ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_128) { - } else if (gensec_ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_56) { + } else if (ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_56) { weak_session_key.length = 7; } else { /* forty bits */ weak_session_key.length = 5; @@ -380,12 +381,12 @@ NTSTATUS ntlmssp_sign_init(struct gensec_ntlmssp_state *gensec_ntlmssp_state) weak_session_key.length); /* SEND: sign key */ - calc_ntlmv2_key(gensec_ntlmssp_state, - &gensec_ntlmssp_state->crypt.ntlm2.send_sign_key, - gensec_ntlmssp_state->session_key, send_sign_const); + calc_ntlmv2_key(ntlmssp_state, + &ntlmssp_state->crypt.ntlm2.send_sign_key, + ntlmssp_state->session_key, send_sign_const); dump_data_pw("NTLMSSP send sign key:\n", - gensec_ntlmssp_state->crypt.ntlm2.send_sign_key.data, - gensec_ntlmssp_state->crypt.ntlm2.send_sign_key.length); + ntlmssp_state->crypt.ntlm2.send_sign_key.data, + ntlmssp_state->crypt.ntlm2.send_sign_key.length); /* SEND: seal ARCFOUR pad */ calc_ntlmv2_key(mem_ctx, @@ -394,19 +395,19 @@ NTSTATUS ntlmssp_sign_init(struct gensec_ntlmssp_state *gensec_ntlmssp_state) dump_data_pw("NTLMSSP send seal key:\n", send_seal_key.data, send_seal_key.length); - arcfour_init(gensec_ntlmssp_state->crypt.ntlm2.send_seal_arcfour_state, + arcfour_init(ntlmssp_state->crypt.ntlm2.send_seal_arcfour_state, &send_seal_key); dump_data_pw("NTLMSSP send sesl hash:\n", - gensec_ntlmssp_state->crypt.ntlm2.send_seal_arcfour_state->sbox, - sizeof(gensec_ntlmssp_state->crypt.ntlm2.send_seal_arcfour_state->sbox)); + ntlmssp_state->crypt.ntlm2.send_seal_arcfour_state->sbox, + sizeof(ntlmssp_state->crypt.ntlm2.send_seal_arcfour_state->sbox)); /* RECV: sign key */ - calc_ntlmv2_key(gensec_ntlmssp_state, - &gensec_ntlmssp_state->crypt.ntlm2.recv_sign_key, - gensec_ntlmssp_state->session_key, recv_sign_const); + calc_ntlmv2_key(ntlmssp_state, + &ntlmssp_state->crypt.ntlm2.recv_sign_key, + ntlmssp_state->session_key, recv_sign_const); dump_data_pw("NTLMSSP recv sign key:\n", - gensec_ntlmssp_state->crypt.ntlm2.recv_sign_key.data, - gensec_ntlmssp_state->crypt.ntlm2.recv_sign_key.length); + ntlmssp_state->crypt.ntlm2.recv_sign_key.data, + ntlmssp_state->crypt.ntlm2.recv_sign_key.length); /* RECV: seal ARCFOUR pad */ calc_ntlmv2_key(mem_ctx, @@ -415,28 +416,28 @@ NTSTATUS ntlmssp_sign_init(struct gensec_ntlmssp_state *gensec_ntlmssp_state) dump_data_pw("NTLMSSP recv seal key:\n", recv_seal_key.data, recv_seal_key.length); - arcfour_init(gensec_ntlmssp_state->crypt.ntlm2.recv_seal_arcfour_state, + arcfour_init(ntlmssp_state->crypt.ntlm2.recv_seal_arcfour_state, &recv_seal_key); dump_data_pw("NTLMSSP receive seal hash:\n", - gensec_ntlmssp_state->crypt.ntlm2.recv_seal_arcfour_state->sbox, - sizeof(gensec_ntlmssp_state->crypt.ntlm2.recv_seal_arcfour_state->sbox)); + ntlmssp_state->crypt.ntlm2.recv_seal_arcfour_state->sbox, + sizeof(ntlmssp_state->crypt.ntlm2.recv_seal_arcfour_state->sbox)); - gensec_ntlmssp_state->crypt.ntlm2.send_seq_num = 0; - gensec_ntlmssp_state->crypt.ntlm2.recv_seq_num = 0; + ntlmssp_state->crypt.ntlm2.send_seq_num = 0; + ntlmssp_state->crypt.ntlm2.recv_seq_num = 0; } else { - DATA_BLOB weak_session_key = ntlmssp_weakend_key(gensec_ntlmssp_state, mem_ctx); + DATA_BLOB weak_session_key = ntlmssp_weakend_key(ntlmssp_state, mem_ctx); DEBUG(5, ("NTLMSSP Sign/Seal - using NTLM1\n")); - gensec_ntlmssp_state->crypt.ntlm.arcfour_state = talloc(gensec_ntlmssp_state, struct arcfour_state); - NT_STATUS_HAVE_NO_MEMORY(gensec_ntlmssp_state->crypt.ntlm.arcfour_state); + ntlmssp_state->crypt.ntlm.arcfour_state = talloc(ntlmssp_state, struct arcfour_state); + NT_STATUS_HAVE_NO_MEMORY(ntlmssp_state->crypt.ntlm.arcfour_state); - arcfour_init(gensec_ntlmssp_state->crypt.ntlm.arcfour_state, + arcfour_init(ntlmssp_state->crypt.ntlm.arcfour_state, &weak_session_key); - dump_data_pw("NTLMSSP hash:\n", gensec_ntlmssp_state->crypt.ntlm.arcfour_state->sbox, - sizeof(gensec_ntlmssp_state->crypt.ntlm.arcfour_state->sbox)); + dump_data_pw("NTLMSSP hash:\n", ntlmssp_state->crypt.ntlm.arcfour_state->sbox, + sizeof(ntlmssp_state->crypt.ntlm.arcfour_state->sbox)); - gensec_ntlmssp_state->crypt.ntlm.seq_num = 0; + ntlmssp_state->crypt.ntlm.seq_num = 0; } talloc_free(mem_ctx); @@ -594,7 +595,7 @@ NTSTATUS gensec_ntlmssp_unwrap(struct gensec_security *gensec_security, struct gensec_ntlmssp_context *gensec_ntlmssp = talloc_get_type_abort(gensec_security->private_data, struct gensec_ntlmssp_context); - struct gensec_ntlmssp_state *gensec_ntlmssp_state = gensec_ntlmssp->ntlmssp_state; + struct ntlmssp_state *ntlmssp_state = gensec_ntlmssp->ntlmssp_state; DATA_BLOB sig; if (gensec_have_feature(gensec_security, GENSEC_FEATURE_SEAL)) { @@ -626,15 +627,15 @@ NTSTATUS gensec_ntlmssp_unwrap(struct gensec_security *gensec_security, sig.length = NTLMSSP_SIG_SIZE; *out = data_blob_talloc(sig_mem_ctx, in->data + NTLMSSP_SIG_SIZE, in->length - NTLMSSP_SIG_SIZE); - if (gensec_ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_NTLM2) { - ntlm2_seqnum_r = gensec_ntlmssp_state->crypt.ntlm2.recv_seq_num; - ntlm2_state_r = *gensec_ntlmssp_state->crypt.ntlm2.recv_seal_arcfour_state; + if (ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_NTLM2) { + ntlm2_seqnum_r = ntlmssp_state->crypt.ntlm2.recv_seq_num; + ntlm2_state_r = *ntlmssp_state->crypt.ntlm2.recv_seal_arcfour_state; memcpy(ntlm2_key_r, - gensec_ntlmssp_state->crypt.ntlm2.recv_sign_key.data, + ntlmssp_state->crypt.ntlm2.recv_sign_key.data, 16); } else { - ntlm_seqnum = gensec_ntlmssp_state->crypt.ntlm.seq_num; - ntlm_state = *gensec_ntlmssp_state->crypt.ntlm.arcfour_state; + ntlm_seqnum = ntlmssp_state->crypt.ntlm.seq_num; + ntlm_state = *ntlmssp_state->crypt.ntlm.arcfour_state; } status = gensec_ntlmssp_check_packet(gensec_security, sig_mem_ctx, @@ -649,14 +650,14 @@ NTSTATUS gensec_ntlmssp_unwrap(struct gensec_security *gensec_security, * negotiated. So we need to fallback. */ - if (gensec_ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_NTLM2) { - gensec_ntlmssp_state->crypt.ntlm2.recv_seq_num = ntlm2_seqnum_r; - *gensec_ntlmssp_state->crypt.ntlm2.recv_seal_arcfour_state = ntlm2_state_r; - memcpy(gensec_ntlmssp_state->crypt.ntlm2.recv_sign_key.data, + if (ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_NTLM2) { + ntlmssp_state->crypt.ntlm2.recv_seq_num = ntlm2_seqnum_r; + *ntlmssp_state->crypt.ntlm2.recv_seal_arcfour_state = ntlm2_state_r; + memcpy(ntlmssp_state->crypt.ntlm2.recv_sign_key.data, ntlm2_key_r, 16); } else { - gensec_ntlmssp_state->crypt.ntlm.seq_num = ntlm_seqnum; - *gensec_ntlmssp_state->crypt.ntlm.arcfour_state = ntlm_state; + ntlmssp_state->crypt.ntlm.seq_num = ntlm_seqnum; + *ntlmssp_state->crypt.ntlm.arcfour_state = ntlm_state; } status = gensec_ntlmssp_unseal_packet(gensec_security, @@ -667,7 +668,7 @@ NTSTATUS gensec_ntlmssp_unwrap(struct gensec_security *gensec_security, out->length, &sig); if (NT_STATUS_IS_OK(status)) { - gensec_ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_SEAL; + ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_SEAL; } else { status = check_status; } diff --git a/source4/torture/auth/ntlmssp.c b/source4/torture/auth/ntlmssp.c index 90d0a34e62..6c5bb1d43b 100644 --- a/source4/torture/auth/ntlmssp.c +++ b/source4/torture/auth/ntlmssp.c @@ -28,7 +28,7 @@ static bool torture_ntlmssp_self_check(struct torture_context *tctx) { struct gensec_security *gensec_security; struct gensec_ntlmssp_context *gensec_ntlmssp; - struct gensec_ntlmssp_state *gensec_ntlmssp_state; + struct ntlmssp_state *ntlmssp_state; DATA_BLOB data; DATA_BLOB sig, expected_sig; TALLOC_CTX *mem_ctx = tctx; @@ -49,17 +49,17 @@ static bool torture_ntlmssp_self_check(struct torture_context *tctx) gensec_ntlmssp = talloc_get_type_abort(gensec_security->private_data, struct gensec_ntlmssp_context); - gensec_ntlmssp_state = gensec_ntlmssp->ntlmssp_state; + ntlmssp_state = gensec_ntlmssp->ntlmssp_state; - gensec_ntlmssp_state->session_key = strhex_to_data_blob(tctx, "0102030405060708090a0b0c0d0e0f00"); + ntlmssp_state->session_key = strhex_to_data_blob(tctx, "0102030405060708090a0b0c0d0e0f00"); dump_data_pw("NTLMSSP session key: \n", - gensec_ntlmssp_state->session_key.data, - gensec_ntlmssp_state->session_key.length); + ntlmssp_state->session_key.data, + ntlmssp_state->session_key.length); - gensec_ntlmssp_state->neg_flags = NTLMSSP_NEGOTIATE_SIGN | NTLMSSP_NEGOTIATE_UNICODE | NTLMSSP_NEGOTIATE_128 | NTLMSSP_NEGOTIATE_KEY_EXCH | NTLMSSP_NEGOTIATE_NTLM2; + ntlmssp_state->neg_flags = NTLMSSP_NEGOTIATE_SIGN | NTLMSSP_NEGOTIATE_UNICODE | NTLMSSP_NEGOTIATE_128 | NTLMSSP_NEGOTIATE_KEY_EXCH | NTLMSSP_NEGOTIATE_NTLM2; torture_assert_ntstatus_ok(tctx, - ntlmssp_sign_init(gensec_ntlmssp_state), + ntlmssp_sign_init(ntlmssp_state), "Failed to sign_init"); data = strhex_to_data_blob(tctx, "6a43494653"); @@ -81,7 +81,7 @@ static bool torture_ntlmssp_self_check(struct torture_context *tctx) data.data, data.length, data.data, data.length, &sig), NT_STATUS_ACCESS_DENIED, "Check of just signed packet (should fail, wrong end)"); - gensec_ntlmssp_state->session_key = data_blob(NULL, 0); + ntlmssp_state->session_key = data_blob(NULL, 0); torture_assert_ntstatus_equal(tctx, gensec_ntlmssp_check_packet(gensec_security, gensec_security, @@ -106,17 +106,17 @@ static bool torture_ntlmssp_self_check(struct torture_context *tctx) gensec_ntlmssp = talloc_get_type_abort(gensec_security->private_data, struct gensec_ntlmssp_context); - gensec_ntlmssp_state = gensec_ntlmssp->ntlmssp_state; + ntlmssp_state = gensec_ntlmssp->ntlmssp_state; - gensec_ntlmssp_state->session_key = strhex_to_data_blob(tctx, "0102030405e538b0"); + ntlmssp_state->session_key = strhex_to_data_blob(tctx, "0102030405e538b0"); dump_data_pw("NTLMSSP session key: \n", - gensec_ntlmssp_state->session_key.data, - gensec_ntlmssp_state->session_key.length); + ntlmssp_state->session_key.data, + ntlmssp_state->session_key.length); - gensec_ntlmssp_state->neg_flags = NTLMSSP_NEGOTIATE_SIGN | NTLMSSP_NEGOTIATE_UNICODE | NTLMSSP_NEGOTIATE_KEY_EXCH; + ntlmssp_state->neg_flags = NTLMSSP_NEGOTIATE_SIGN | NTLMSSP_NEGOTIATE_UNICODE | NTLMSSP_NEGOTIATE_KEY_EXCH; torture_assert_ntstatus_ok(tctx, - ntlmssp_sign_init(gensec_ntlmssp_state), + ntlmssp_sign_init(ntlmssp_state), "Failed to sign_init"); data = strhex_to_data_blob(tctx, "6a43494653"); diff --git a/source4/utils/ntlm_auth.c b/source4/utils/ntlm_auth.c index a60ce98d48..e3a43c7727 100644 --- a/source4/utils/ntlm_auth.c +++ b/source4/utils/ntlm_auth.c @@ -646,12 +646,12 @@ static void manage_gensec_request(enum stdio_helper_mode stdio_helper_mode, } if (strncmp(buf, "GF", 2) == 0) { - struct gensec_ntlmssp_state *gensec_ntlmssp_state; + struct ntlmssp_state *ntlmssp_state; uint32_t neg_flags; - gensec_ntlmssp_state = talloc_get_type(state->gensec_state->private_data, - struct gensec_ntlmssp_state); - neg_flags = gensec_ntlmssp_state->neg_flags; + ntlmssp_state = talloc_get_type(state->gensec_state->private_data, + struct ntlmssp_state); + neg_flags = ntlmssp_state->neg_flags; DEBUG(10, ("Requested negotiated feature flags\n")); mux_printf(mux_id, "GF 0x%08x\n", neg_flags); |