1
0
mirror of https://github.com/samba-team/samba.git synced 2025-08-30 17:49:30 +03:00

auth3: Replace auth3_check_password() by _send and _recv

This is just fake async, but it avoids one use of a sync function
pointer in auth4_context

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
This commit is contained in:
Volker Lendecke
2020-01-02 17:22:36 +01:00
committed by Jeremy Allison
parent 004e553174
commit d3d2e6df9c
3 changed files with 118 additions and 48 deletions

View File

@ -197,7 +197,8 @@ static struct auth4_context *make_auth4_context_s3(TALLOC_CTX *mem_ctx, struct a
auth4_context->generate_session_info = auth3_generate_session_info; auth4_context->generate_session_info = auth3_generate_session_info;
auth4_context->get_ntlm_challenge = auth3_get_challenge; auth4_context->get_ntlm_challenge = auth3_get_challenge;
auth4_context->set_ntlm_challenge = auth3_set_challenge; auth4_context->set_ntlm_challenge = auth3_set_challenge;
auth4_context->check_ntlm_password = auth3_check_password; auth4_context->check_ntlm_password_send = auth3_check_password_send;
auth4_context->check_ntlm_password_recv = auth3_check_password_recv;
auth4_context->private_data = talloc_steal(auth4_context, auth_context); auth4_context->private_data = talloc_steal(auth4_context, auth_context);
return auth4_context; return auth4_context;
} }

View File

@ -24,6 +24,7 @@
#include "includes.h" #include "includes.h"
#include "auth.h" #include "auth.h"
#include "libcli/security/security.h" #include "libcli/security/security.h"
#include "lib/util/tevent_ntstatus.h"
NTSTATUS auth3_generate_session_info(struct auth4_context *auth_context, NTSTATUS auth3_generate_session_info(struct auth4_context *auth_context,
TALLOC_CTX *mem_ctx, TALLOC_CTX *mem_ctx,
@ -130,24 +131,38 @@ NTSTATUS auth3_set_challenge(struct auth4_context *auth4_context, const uint8_t
* Return the session keys used on the connection. * Return the session keys used on the connection.
*/ */
NTSTATUS auth3_check_password(struct auth4_context *auth4_context, struct auth3_check_password_state {
TALLOC_CTX *mem_ctx, uint8_t authoritative;
const struct auth_usersupplied_info *user_info, void *server_info;
uint8_t *pauthoritative, DATA_BLOB nt_session_key;
void **server_returned_info, DATA_BLOB lm_session_key;
DATA_BLOB *session_key, DATA_BLOB *lm_session_key) };
struct tevent_req *auth3_check_password_send(
TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
struct auth4_context *auth4_context,
const struct auth_usersupplied_info *user_info)
{ {
struct auth_context *auth_context = talloc_get_type_abort(auth4_context->private_data, struct tevent_req *req = NULL;
struct auth_context); struct auth3_check_password_state *state = NULL;
struct auth_context *auth_context = talloc_get_type_abort(
auth4_context->private_data, struct auth_context);
struct auth_usersupplied_info *mapped_user_info = NULL; struct auth_usersupplied_info *mapped_user_info = NULL;
struct auth_serversupplied_info *server_info; struct auth_serversupplied_info *server_info = NULL;
NTSTATUS nt_status; NTSTATUS nt_status;
bool username_was_mapped; bool username_was_mapped;
req = tevent_req_create(
mem_ctx, &state, struct auth3_check_password_state);
if (req == NULL) {
return NULL;
}
/* /*
* Be authoritative by default. * Be authoritative by default.
*/ */
*pauthoritative = 1; state->authoritative = 1;
/* The client has given us its machine name (which we only get over NBT transport). /* The client has given us its machine name (which we only get over NBT transport).
We need to possibly reload smb.conf if smb.conf includes depend on the machine name. */ We need to possibly reload smb.conf if smb.conf includes depend on the machine name. */
@ -173,27 +188,27 @@ NTSTATUS auth3_check_password(struct auth4_context *auth4_context,
NULL, NULL, NULL, NULL, NULL, NULL,
AUTH_PASSWORD_RESPONSE); AUTH_PASSWORD_RESPONSE);
if (!NT_STATUS_IS_OK(nt_status)) { if (tevent_req_nterror(req, nt_status)) {
return nt_status; return tevent_req_post(req, ev);
} }
mapped_user_info->logon_parameters = user_info->logon_parameters; mapped_user_info->logon_parameters = user_info->logon_parameters;
mapped_user_info->flags = user_info->flags; mapped_user_info->flags = user_info->flags;
nt_status = auth_check_ntlm_password(mem_ctx, nt_status = auth_check_ntlm_password(state,
auth_context, auth_context,
mapped_user_info, mapped_user_info,
&server_info, &server_info,
pauthoritative); &state->authoritative);
if (!NT_STATUS_IS_OK(nt_status)) { if (!NT_STATUS_IS_OK(nt_status)) {
DEBUG(5,("Checking NTLMSSP password for %s\\%s failed: " DBG_INFO("Checking NTLMSSP password for %s\\%s failed: "
"%s, authoritative=%u\n", "%s, authoritative=%"PRIu8"\n",
user_info->client.domain_name, user_info->client.domain_name,
user_info->client.account_name, user_info->client.account_name,
nt_errstr(nt_status), nt_errstr(nt_status),
*pauthoritative)); state->authoritative);
} }
username_was_mapped = mapped_user_info->was_mapped; username_was_mapped = mapped_user_info->was_mapped;
@ -201,16 +216,18 @@ NTSTATUS auth3_check_password(struct auth4_context *auth4_context,
TALLOC_FREE(mapped_user_info); TALLOC_FREE(mapped_user_info);
if (!NT_STATUS_IS_OK(nt_status)) { if (!NT_STATUS_IS_OK(nt_status)) {
nt_status = do_map_to_guest_server_info(mem_ctx, nt_status = do_map_to_guest_server_info(
nt_status, state,
user_info->client.account_name, nt_status,
user_info->client.domain_name, user_info->client.account_name,
&server_info); user_info->client.domain_name,
if (NT_STATUS_IS_OK(nt_status)) { &server_info);
*pauthoritative = 1; if (!tevent_req_nterror(req, nt_status)) {
*server_returned_info = talloc_steal(mem_ctx, server_info); state->authoritative = 1;
tevent_req_done(req);
} }
return nt_status; state->server_info = server_info;
return tevent_req_post(req, ev);
} }
server_info->nss_token |= username_was_mapped; server_info->nss_token |= username_was_mapped;
@ -219,21 +236,68 @@ NTSTATUS auth3_check_password(struct auth4_context *auth4_context,
* They will not be used in this form again - instead the * They will not be used in this form again - instead the
* NTLMSSP code will decide on the final correct session key, * NTLMSSP code will decide on the final correct session key,
* and supply it to create_local_token() */ * and supply it to create_local_token() */
if (session_key) {
DBG_DEBUG("Got NT session key of length %zu\n", DBG_DEBUG("Got NT session key of length %zu\n",
server_info->session_key.length); server_info->session_key.length);
*session_key = server_info->session_key; state->nt_session_key = (DATA_BLOB) {
talloc_steal(mem_ctx, server_info->session_key.data); .data = talloc_move(
server_info->session_key = data_blob_null; state, &server_info->session_key.data),
} .length = server_info->session_key.length,
if (lm_session_key) { };
DBG_DEBUG("Got LM session key of length %zu\n", server_info->session_key = data_blob_null;
server_info->lm_session_key.length);
*lm_session_key = server_info->lm_session_key; DBG_DEBUG("Got LM session key of length %zu\n",
talloc_steal(mem_ctx, server_info->lm_session_key.data); server_info->lm_session_key.length);
server_info->lm_session_key = data_blob_null; state->lm_session_key = (DATA_BLOB) {
.data = talloc_move(
state, &server_info->lm_session_key.data),
.length = server_info->lm_session_key.length,
};
server_info->lm_session_key = data_blob_null;
state->server_info = server_info;
tevent_req_done(req);
return tevent_req_post(req, ev);
}
NTSTATUS auth3_check_password_recv(struct tevent_req *req,
TALLOC_CTX *mem_ctx,
uint8_t *pauthoritative,
void **server_returned_info,
DATA_BLOB *nt_session_key,
DATA_BLOB *lm_session_key)
{
struct auth3_check_password_state *state = tevent_req_data(
req, struct auth3_check_password_state);
NTSTATUS status;
if (pauthoritative != NULL) {
*pauthoritative = state->authoritative;
} }
*server_returned_info = talloc_steal(mem_ctx, server_info); if (tevent_req_is_nterror(req, &status)) {
return nt_status; return status;
}
if (server_returned_info != NULL) {
*server_returned_info = talloc_move(
mem_ctx, &state->server_info);
}
if (nt_session_key != NULL) {
*nt_session_key = (DATA_BLOB) {
.data = talloc_move(
mem_ctx, &state->nt_session_key.data),
.length = state->nt_session_key.length,
};
}
if (lm_session_key != NULL) {
*lm_session_key = (DATA_BLOB) {
.data = talloc_move(
mem_ctx, &state->lm_session_key.data),
.length = state->lm_session_key.length,
};
}
return NT_STATUS_OK;
} }

View File

@ -127,12 +127,17 @@ NTSTATUS auth3_get_challenge(struct auth4_context *auth4_context,
NTSTATUS auth3_set_challenge(struct auth4_context *auth4_context, const uint8_t *chal, NTSTATUS auth3_set_challenge(struct auth4_context *auth4_context, const uint8_t *chal,
const char *challenge_set_by); const char *challenge_set_by);
NTSTATUS auth3_check_password(struct auth4_context *auth4_context, struct tevent_req *auth3_check_password_send(
TALLOC_CTX *mem_ctx, TALLOC_CTX *mem_ctx,
const struct auth_usersupplied_info *user_info, struct tevent_context *ev,
uint8_t *pauthoritative, struct auth4_context *auth4_context,
void **server_returned_info, const struct auth_usersupplied_info *user_info);
DATA_BLOB *session_key, DATA_BLOB *lm_session_key); NTSTATUS auth3_check_password_recv(struct tevent_req *req,
TALLOC_CTX *mem_ctx,
uint8_t *pauthoritative,
void **server_returned_info,
DATA_BLOB *nt_session_key,
DATA_BLOB *lm_session_key);
/* The following definitions come from auth/auth_sam.c */ /* The following definitions come from auth/auth_sam.c */