summaryrefslogtreecommitdiff
path: root/source4/libcli
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2005-11-12 01:08:43 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:46:14 -0500
commit2b7ee2ceee0a1b2be596a602997908f72a3af14d (patch)
tree92a76c5ae2ee35a9da6c251df04b52848255873e /source4/libcli
parent91e1893741741de04b73a098495c697434105803 (diff)
downloadsamba-2b7ee2ceee0a1b2be596a602997908f72a3af14d.tar.gz
samba-2b7ee2ceee0a1b2be596a602997908f72a3af14d.tar.bz2
samba-2b7ee2ceee0a1b2be596a602997908f72a3af14d.zip
r11692: added a full composite (async) spnego session setup for SMB2. This
simplies the torture code a lot. (This used to be commit 7bf1046fbb7fd83fecb2fa645628ba9a17aab037)
Diffstat (limited to 'source4/libcli')
-rw-r--r--source4/libcli/smb2/request.c4
-rw-r--r--source4/libcli/smb2/session.c146
-rw-r--r--source4/libcli/smb2/smb2.h2
-rw-r--r--source4/libcli/smb_composite/sesssetup.c4
4 files changed, 154 insertions, 2 deletions
diff --git a/source4/libcli/smb2/request.c b/source4/libcli/smb2/request.c
index 108cf0ca55..ccffef9b88 100644
--- a/source4/libcli/smb2/request.c
+++ b/source4/libcli/smb2/request.c
@@ -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;
}
diff --git a/source4/libcli/smb2/session.c b/source4/libcli/smb2/session.c
index 9d945243d2..baa706cf8b 100644
--- a/source4/libcli/smb2/session.c
+++ b/source4/libcli/smb2/session.c
@@ -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);
+}
diff --git a/source4/libcli/smb2/smb2.h b/source4/libcli/smb2/smb2.h
index f6847bfc9b..f452852cf9 100644
--- a/source4/libcli/smb2/smb2.h
+++ b/source4/libcli/smb2/smb2.h
@@ -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;
diff --git a/source4/libcli/smb_composite/sesssetup.c b/source4/libcli/smb_composite/sesssetup.c
index 0d0904b969..4cdc4c5e6b 100644
--- a/source4/libcli/smb_composite/sesssetup.c
+++ b/source4/libcli/smb_composite/sesssetup.c
@@ -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;