1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-23 09:57:40 +03:00

r11692: added a full composite (async) spnego session setup for SMB2. This

simplies the torture code a lot.
(This used to be commit 7bf1046fbb7fd83fecb2fa645628ba9a17aab037)
This commit is contained in:
Andrew Tridgell 2005-11-12 01:08:43 +00:00 committed by Gerald (Jerry) Carter
parent 91e1893741
commit 2b7ee2ceee
5 changed files with 164 additions and 68 deletions

View File

@ -39,6 +39,8 @@ struct smb2_request *smb2_request_init(struct smb2_transport *transport,
req->state = SMB2_REQUEST_INIT;
req->transport = transport;
req->session = NULL;
req->tree = NULL;
req->seqnum = transport->seqnum++;
req->status = NT_STATUS_OK;
req->async.fn = NULL;
@ -88,6 +90,8 @@ struct smb2_request *smb2_request_init_tree(struct smb2_tree *tree,
SBVAL(req->out.hdr, SMB2_HDR_UID, tree->session->uid);
SIVAL(req->out.hdr, SMB2_HDR_TID, tree->tid);
req->session = tree->session;
req->tree = tree;
return req;
}

View File

@ -24,6 +24,8 @@
#include "libcli/raw/libcliraw.h"
#include "libcli/smb2/smb2.h"
#include "libcli/smb2/smb2_calls.h"
#include "libcli/composite/composite.h"
#include "auth/gensec/gensec.h"
/*
initialise a smb2_session structure
@ -73,6 +75,8 @@ struct smb2_request *smb2_session_setup_send(struct smb2_session *session,
SIVAL(req->out.body, 0x04, io->in.unknown2);
SIVAL(req->out.body, 0x08, io->in.unknown3);
req->session = session;
status = smb2_push_ofs_blob(req, req->out.body+0x0C, io->in.secblob);
if (!NT_STATUS_IS_OK(status)) {
talloc_free(req);
@ -127,3 +131,145 @@ NTSTATUS smb2_session_setup(struct smb2_session *session,
struct smb2_request *req = smb2_session_setup_send(session, io);
return smb2_session_setup_recv(req, mem_ctx, io);
}
struct smb2_session_state {
struct smb2_session_setup io;
struct smb2_request *req;
NTSTATUS gensec_status;
};
/*
handle continuations of the spnego session setup
*/
static void session_request_handler(struct smb2_request *req)
{
struct composite_context *c = talloc_get_type(req->async.private,
struct composite_context);
struct smb2_session_state *state = talloc_get_type(c->private_data,
struct smb2_session_state);
struct smb2_session *session = req->session;
c->status = smb2_session_setup_recv(req, c, &state->io);
if (NT_STATUS_EQUAL(c->status, NT_STATUS_MORE_PROCESSING_REQUIRED) ||
(NT_STATUS_IS_OK(c->status) &&
NT_STATUS_EQUAL(state->gensec_status, NT_STATUS_MORE_PROCESSING_REQUIRED))) {
c->status = gensec_update(req->session->gensec, c,
state->io.out.secblob,
&state->io.in.secblob);
state->gensec_status = c->status;
}
session->uid = state->io.out.uid;
if (NT_STATUS_EQUAL(c->status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
state->req = smb2_session_setup_send(session, &state->io);
if (state->req == NULL) {
composite_error(c, NT_STATUS_NO_MEMORY);
}
state->req->async.fn = session_request_handler;
state->req->async.private = c;
return;
}
if (!NT_STATUS_IS_OK(c->status)) {
composite_error(c, c->status);
return;
}
composite_done(c);
}
/*
a composite function that does a full SPNEGO session setup
*/
struct composite_context *smb2_session_setup_spnego_send(struct smb2_session *session,
struct cli_credentials *credentials)
{
struct composite_context *c;
struct smb2_session_state *state;
c = talloc_zero(session, struct composite_context);
if (c == NULL) return NULL;
state = talloc(c, struct smb2_session_state);
if (state == NULL) {
c->status = NT_STATUS_NO_MEMORY;
goto failed;
}
c->state = COMPOSITE_STATE_IN_PROGRESS;
c->private_data = state;
c->event_ctx = session->transport->socket->event.ctx;
ZERO_STRUCT(state->io);
state->io.in.unknown1 = 0x11;
state->io.in.unknown2 = 0xF;
state->io.in.unknown3 = 0x00;
c->status = gensec_set_credentials(session->gensec, credentials);
if (!NT_STATUS_IS_OK(c->status)) {
goto failed;
}
c->status = gensec_set_target_hostname(session->gensec,
session->transport->socket->hostname);
if (!NT_STATUS_IS_OK(c->status)) {
goto failed;
}
c->status = gensec_set_target_service(session->gensec, "cifs");
if (!NT_STATUS_IS_OK(c->status)) {
goto failed;
}
c->status = gensec_start_mech_by_oid(session->gensec, GENSEC_OID_SPNEGO);
if (!NT_STATUS_IS_OK(c->status)) {
goto failed;
}
c->status = gensec_update(session->gensec, c,
session->transport->negotiate.secblob,
&state->io.in.secblob);
if (!NT_STATUS_EQUAL(c->status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
goto failed;
}
state->gensec_status = c->status;
state->req = smb2_session_setup_send(session, &state->io);
if (state->req == NULL) {
c->status = NT_STATUS_NO_MEMORY;
goto failed;
}
state->req->async.fn = session_request_handler;
state->req->async.private = c;
return c;
failed:
composite_trigger_error(c);
return c;
}
/*
receive a composite session setup reply
*/
NTSTATUS smb2_session_setup_spnego_recv(struct composite_context *c)
{
NTSTATUS status;
status = composite_wait(c);
talloc_free(c);
return status;
}
/*
sync version of smb2_session_setup_spnego
*/
NTSTATUS smb2_session_setup_spnego(struct smb2_session *session,
struct cli_credentials *credentials)
{
struct composite_context *c = smb2_session_setup_spnego_send(session, credentials);
return smb2_session_setup_spnego_recv(c);
}

View File

@ -114,6 +114,8 @@ struct smb2_request {
enum smb2_request_state state;
struct smb2_transport *transport;
struct smb2_session *session;
struct smb2_tree *tree;
uint64_t seqnum;

View File

@ -370,8 +370,8 @@ struct composite_context *smb_composite_sesssetup_send(struct smbcli_session *se
state = talloc(c, struct sesssetup_state);
if (state == NULL) {
c->state = COMPOSITE_STATE_ERROR;
c->status = NT_STATUS_NO_MEMORY;
talloc_free(c);
return NULL;
}
state->io = io;

View File

@ -27,7 +27,6 @@
#include "librpc/gen_ndr/ndr_security.h"
#include "lib/cmdline/popt_common.h"
#include "lib/events/events.h"
#include "auth/gensec/gensec.h"
#define BASEDIR "\\testsmb2"
@ -88,77 +87,16 @@ static struct smb2_session *torture_smb2_session(struct smb2_transport *transpor
struct cli_credentials *credentials)
{
struct smb2_session *session;
struct smb2_session_setup io;
NTSTATUS status;
TALLOC_CTX *tmp_ctx = talloc_new(transport);
DATA_BLOB secblob;
ZERO_STRUCT(io);
io.in.unknown1 = 0x11;
io.in.unknown2 = 0xF;
io.in.unknown3 = 0x00;
session = smb2_session_init(transport, transport, True);
status = gensec_set_credentials(session->gensec, credentials);
status = smb2_session_setup_spnego(session, credentials);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(1, ("Failed to start set GENSEC client credentails: %s\n",
nt_errstr(status)));
printf("Session setup failed - %s\n", nt_errstr(status));
return NULL;
}
status = gensec_set_target_hostname(session->gensec, transport->socket->hostname);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(1, ("Failed to start set GENSEC target hostname: %s\n",
nt_errstr(status)));
return NULL;
}
status = gensec_set_target_service(session->gensec, "cifs");
if (!NT_STATUS_IS_OK(status)) {
DEBUG(1, ("Failed to start set GENSEC target service: %s\n",
nt_errstr(status)));
return NULL;
}
status = gensec_start_mech_by_oid(session->gensec, GENSEC_OID_SPNEGO);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(1, ("Failed to start set GENSEC client - %s\n",
nt_errstr(status)));
return NULL;
}
secblob = session->transport->negotiate.secblob;
do {
NTSTATUS status1;
status1 = gensec_update(session->gensec, tmp_ctx, secblob, &io.in.secblob);
if (!NT_STATUS_EQUAL(status1, NT_STATUS_MORE_PROCESSING_REQUIRED) &&
!NT_STATUS_IS_OK(status1)) {
DEBUG(1, ("Failed initial gensec_update : %s\n",
nt_errstr(status1)));
status = status1;
break;
}
status = smb2_session_setup(session, tmp_ctx, &io);
secblob = io.out.secblob;
session->uid = io.out.uid;
if (NT_STATUS_IS_OK(status) &&
NT_STATUS_EQUAL(status1, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
status = gensec_update(session->gensec, tmp_ctx, secblob,
&io.in.secblob);
}
} while (NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED));
if (!NT_STATUS_IS_OK(status)) {
printf("session setup failed - %s\n", nt_errstr(status));
return NULL;
}
printf("Session setup gave UID 0x%016llx\n", session->uid);
return session;
@ -292,8 +230,14 @@ BOOL torture_smb2_connect(void)
struct smb2_handle h1, h2;
transport = torture_smb2_negprot(mem_ctx, host);
if (transport == NULL) return False;
session = torture_smb2_session(transport, credentials);
if (session == NULL) return False;
tree = torture_smb2_tree(session, share);
if (tree == NULL) return False;
h1 = torture_smb2_create(tree, "test9.dat");
h2 = torture_smb2_create(tree, "test9.dat");
torture_smb2_close(tree, h1);