#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
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);
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);
+}
#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"
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);
- if (!NT_STATUS_IS_OK(status)) {
- DEBUG(1, ("Failed to start set GENSEC client credentails: %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);
+ status = smb2_session_setup_spnego(session, credentials);
if (!NT_STATUS_IS_OK(status)) {
- DEBUG(1, ("Failed to start set GENSEC client - %s\n",
- nt_errstr(status)));
+ printf("Session setup failed - %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;
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);