From 555b45e12c281eb3980d15b12728c59c6b73c302 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 11 Nov 2005 05:53:54 +0000 Subject: r11665: started to put some meat on the structure used for the SMB2 library the call definitions will be in smb2_calls.h, which will play a similar role that smb_interfaces.h plays for the old SMB protocol (This used to be commit 4ef3902a8a99a0b8caa81a07ba07830d7cbbc32c) --- source4/libcli/smb2/session.c | 47 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 source4/libcli/smb2/session.c (limited to 'source4/libcli/smb2/session.c') diff --git a/source4/libcli/smb2/session.c b/source4/libcli/smb2/session.c new file mode 100644 index 0000000000..23fed70e17 --- /dev/null +++ b/source4/libcli/smb2/session.c @@ -0,0 +1,47 @@ +/* + Unix SMB/CIFS implementation. + + SMB2 client session handling + + Copyright (C) Andrew Tridgell 2005 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +#include "libcli/raw/libcliraw.h" +#include "libcli/smb2/smb2.h" + +/* + initialise a smb2_session structure + */ +struct smb2_session *smb2_session_init(struct smb2_transport *transport, + TALLOC_CTX *parent_ctx, BOOL primary) +{ + struct smb2_session *session; + + session = talloc_zero(parent_ctx, struct smb2_session); + if (!session) { + return NULL; + } + if (primary) { + session->transport = talloc_steal(session, transport); + } else { + session->transport = talloc_reference(session, transport); + } + + return session; +} + -- cgit From 86c1370cb03a244fd5644d30732a1fbda762fe6a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 11 Nov 2005 06:26:42 +0000 Subject: r11666: filled in the basic session setup. Vista happily accepts the first stage of the session setup, and waits for more. (This used to be commit 804c229c3ba7f866a7f3d66684e268d5ddc820ce) --- source4/libcli/smb2/session.c | 70 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) (limited to 'source4/libcli/smb2/session.c') diff --git a/source4/libcli/smb2/session.c b/source4/libcli/smb2/session.c index 23fed70e17..2f9a979fea 100644 --- a/source4/libcli/smb2/session.c +++ b/source4/libcli/smb2/session.c @@ -23,6 +23,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" #include "libcli/smb2/smb2.h" +#include "libcli/smb2/smb2_calls.h" /* initialise a smb2_session structure @@ -31,6 +32,7 @@ struct smb2_session *smb2_session_init(struct smb2_transport *transport, TALLOC_CTX *parent_ctx, BOOL primary) { struct smb2_session *session; + NTSTATUS status; session = talloc_zero(parent_ctx, struct smb2_session); if (!session) { @@ -42,6 +44,74 @@ struct smb2_session *smb2_session_init(struct smb2_transport *transport, session->transport = talloc_reference(session, transport); } + /* prepare a gensec context for later use */ + status = gensec_client_start(session, &session->gensec, + session->transport->socket->event.ctx); + if (!NT_STATUS_IS_OK(status)) { + talloc_free(session); + return NULL; + } + return session; } +/* + send a session setup request +*/ +struct smb2_request *smb2_session_setup_send(struct smb2_session *session, + struct smb2_session_setup *io) +{ + struct smb2_request *req; + + req = smb2_request_init(session->transport, SMB2_OP_SESSSETUP, + 0x10 + io->in.secblob.length); + if (req == NULL) return NULL; + + SIVAL(req->out.body, 0x00, io->in.unknown1); + SIVAL(req->out.body, 0x04, io->in.unknown2); + SIVAL(req->out.body, 0x08, io->in.unknown3); + SSVAL(req->out.body, 0x0C, io->in.unknown4); + SSVAL(req->out.body, 0x0E, io->in.secblob.length); + memcpy(req->out.body+0x10, io->in.secblob.data, io->in.secblob.length); + + smb2_transport_send(req); + + return req; +} + + +/* + recv a session setup reply +*/ +NTSTATUS smb2_session_setup_recv(struct smb2_request *req, TALLOC_CTX *mem_ctx, + struct smb2_session_setup *io) +{ + uint16_t blobsize; + + if (!smb2_request_receive(req) || + smb2_request_is_error(req)) { + return smb2_request_destroy(req); + } + + if (req->in.body_size < 0x08) { + return NT_STATUS_BUFFER_TOO_SMALL; + } + + io->out.unknown1 = IVAL(req->in.body, 0x00); + io->out.unknown2 = SVAL(req->in.body, 0x04); + blobsize = SVAL(req->in.body, 0x06); + io->out.secblob = smb2_pull_blob(req, req->in.body+0x08, blobsize); + talloc_steal(mem_ctx, io->out.secblob.data); + + return smb2_request_destroy(req); +} + +/* + sync session setup request +*/ +NTSTATUS smb2_session_setup(struct smb2_session *session, + TALLOC_CTX *mem_ctx, struct smb2_session_setup *io) +{ + struct smb2_request *req = smb2_session_setup_send(session, io); + return smb2_session_setup_recv(req, mem_ctx, io); +} -- cgit From 7a78d2d6b083fbd408c766116693d01b57628f28 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 11 Nov 2005 07:23:45 +0000 Subject: r11668: yay! we get a successful session setup with SMB2, and get back a 64bit uid (This used to be commit 72b34a7c1b66af6be02f66639efc55a19c73e387) --- source4/libcli/smb2/session.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'source4/libcli/smb2/session.c') diff --git a/source4/libcli/smb2/session.c b/source4/libcli/smb2/session.c index 2f9a979fea..031360fcb9 100644 --- a/source4/libcli/smb2/session.c +++ b/source4/libcli/smb2/session.c @@ -62,17 +62,22 @@ struct smb2_request *smb2_session_setup_send(struct smb2_session *session, struct smb2_session_setup *io) { struct smb2_request *req; + NTSTATUS status; req = smb2_request_init(session->transport, SMB2_OP_SESSSETUP, 0x10 + io->in.secblob.length); if (req == NULL) return NULL; + SBVAL(req->out.hdr, SMB2_HDR_UID, session->uid); SIVAL(req->out.body, 0x00, io->in.unknown1); SIVAL(req->out.body, 0x04, io->in.unknown2); SIVAL(req->out.body, 0x08, io->in.unknown3); - SSVAL(req->out.body, 0x0C, io->in.unknown4); - SSVAL(req->out.body, 0x0E, io->in.secblob.length); - memcpy(req->out.body+0x10, io->in.secblob.data, io->in.secblob.length); + + status = smb2_push_ofs_blob(req, req->out.body+0x0C, io->in.secblob); + if (!NT_STATUS_IS_OK(status)) { + talloc_free(req); + return NULL; + } smb2_transport_send(req); @@ -86,10 +91,11 @@ struct smb2_request *smb2_session_setup_send(struct smb2_session *session, NTSTATUS smb2_session_setup_recv(struct smb2_request *req, TALLOC_CTX *mem_ctx, struct smb2_session_setup *io) { - uint16_t blobsize; + NTSTATUS status; if (!smb2_request_receive(req) || - smb2_request_is_error(req)) { + (smb2_request_is_error(req) && + !NT_STATUS_EQUAL(req->status, NT_STATUS_MORE_PROCESSING_REQUIRED))) { return smb2_request_destroy(req); } @@ -97,10 +103,14 @@ NTSTATUS smb2_session_setup_recv(struct smb2_request *req, TALLOC_CTX *mem_ctx, return NT_STATUS_BUFFER_TOO_SMALL; } - io->out.unknown1 = IVAL(req->in.body, 0x00); - io->out.unknown2 = SVAL(req->in.body, 0x04); - blobsize = SVAL(req->in.body, 0x06); - io->out.secblob = smb2_pull_blob(req, req->in.body+0x08, blobsize); + io->out.unknown1 = IVAL(req->in.body, 0x00); + io->out.uid = BVAL(req->in.hdr, SMB2_HDR_UID); + + status = smb2_pull_ofs_blob(req, req->in.body+0x04, &io->out.secblob); + if (!NT_STATUS_IS_OK(status)) { + smb2_request_destroy(req); + return status; + } talloc_steal(mem_ctx, io->out.secblob.data); return smb2_request_destroy(req); -- cgit From 91e1893741741de04b73a098495c697434105803 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 11 Nov 2005 23:27:47 +0000 Subject: r11691: added reply buffer code checks and oplock flags for create request/reply (This used to be commit 26ed781375c03958241d8c93324e04e948944d01) --- source4/libcli/smb2/session.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source4/libcli/smb2/session.c') diff --git a/source4/libcli/smb2/session.c b/source4/libcli/smb2/session.c index 031360fcb9..9d945243d2 100644 --- a/source4/libcli/smb2/session.c +++ b/source4/libcli/smb2/session.c @@ -103,7 +103,9 @@ NTSTATUS smb2_session_setup_recv(struct smb2_request *req, TALLOC_CTX *mem_ctx, return NT_STATUS_BUFFER_TOO_SMALL; } - io->out.unknown1 = IVAL(req->in.body, 0x00); + SMB2_CHECK_BUFFER_CODE(req, 0x09); + + io->out._pad = SVAL(req->in.body, 0x02); io->out.uid = BVAL(req->in.hdr, SMB2_HDR_UID); status = smb2_pull_ofs_blob(req, req->in.body+0x04, &io->out.secblob); -- cgit From 2b7ee2ceee0a1b2be596a602997908f72a3af14d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 12 Nov 2005 01:08:43 +0000 Subject: r11692: added a full composite (async) spnego session setup for SMB2. This simplies the torture code a lot. (This used to be commit 7bf1046fbb7fd83fecb2fa645628ba9a17aab037) --- source4/libcli/smb2/session.c | 146 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 146 insertions(+) (limited to 'source4/libcli/smb2/session.c') 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); +} -- cgit From 56712033d59212c8d72c8d60df885a5764601b7e Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 12 Nov 2005 02:16:19 +0000 Subject: r11694: fixed 2 valgrind errors (This used to be commit 6381fe72417a5cd231b63a87a6a0ba9c65030ce6) --- source4/libcli/smb2/session.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/smb2/session.c') diff --git a/source4/libcli/smb2/session.c b/source4/libcli/smb2/session.c index baa706cf8b..257e754660 100644 --- a/source4/libcli/smb2/session.c +++ b/source4/libcli/smb2/session.c @@ -154,7 +154,7 @@ static void session_request_handler(struct smb2_request *req) 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, + c->status = gensec_update(session->gensec, c, state->io.out.secblob, &state->io.in.secblob); state->gensec_status = c->status; -- cgit From de5d71aebe4e415fcebbfacb852b190498cbf7bf Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 14 Nov 2005 12:31:02 +0000 Subject: r11722: make the smb2_push/pull functions take a smb2_request_buffer and the pull ones also a TALLOC_CTX, then we can reuse this functions in the server later metze (This used to be commit 9b616516cae269f0870e9b9a9cecd8ee3f0a9095) --- source4/libcli/smb2/session.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/libcli/smb2/session.c') diff --git a/source4/libcli/smb2/session.c b/source4/libcli/smb2/session.c index 257e754660..cb2797b9ad 100644 --- a/source4/libcli/smb2/session.c +++ b/source4/libcli/smb2/session.c @@ -77,7 +77,7 @@ struct smb2_request *smb2_session_setup_send(struct smb2_session *session, req->session = session; - status = smb2_push_ofs_blob(req, req->out.body+0x0C, io->in.secblob); + status = smb2_push_ofs_blob(&req->out, req->out.body+0x0C, io->in.secblob); if (!NT_STATUS_IS_OK(status)) { talloc_free(req); return NULL; @@ -112,12 +112,11 @@ NTSTATUS smb2_session_setup_recv(struct smb2_request *req, TALLOC_CTX *mem_ctx, io->out._pad = SVAL(req->in.body, 0x02); io->out.uid = BVAL(req->in.hdr, SMB2_HDR_UID); - status = smb2_pull_ofs_blob(req, req->in.body+0x04, &io->out.secblob); + status = smb2_pull_ofs_blob(&req->in, mem_ctx, req->in.body+0x04, &io->out.secblob); if (!NT_STATUS_IS_OK(status)) { smb2_request_destroy(req); return status; } - talloc_steal(mem_ctx, io->out.secblob.data); return smb2_request_destroy(req); } -- cgit From e9eb56068573d89f8ce45f08220ca870b3daa669 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 16 Nov 2005 11:01:15 +0000 Subject: r11741: - the buffer code (first 2 bytes in the SMB2 body) seem to be the length of the fixed body part, and +1 if there's a dynamic part - there're 3 types of dynamic blobs with uint16_t offset/uint16_t size with uint16_t offset/uint32_t size with uint32_t offset/uint32_t size /* aligned to 8 bytes */ - strings are transmitted in UTF-16 with no termination and packet into a uint16/uint16 blob metze (This used to be commit 79103c51e5c752fbdb4d25a0047b65002828df89) --- source4/libcli/smb2/session.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'source4/libcli/smb2/session.c') diff --git a/source4/libcli/smb2/session.c b/source4/libcli/smb2/session.c index cb2797b9ad..e572227a48 100644 --- a/source4/libcli/smb2/session.c +++ b/source4/libcli/smb2/session.c @@ -67,17 +67,17 @@ struct smb2_request *smb2_session_setup_send(struct smb2_session *session, NTSTATUS status; req = smb2_request_init(session->transport, SMB2_OP_SESSSETUP, - 0x10 + io->in.secblob.length); + 0x10, io->in.secblob.length); if (req == NULL) return NULL; SBVAL(req->out.hdr, SMB2_HDR_UID, session->uid); - SIVAL(req->out.body, 0x00, io->in.unknown1); + SSVAL(req->out.body, 0x02, io->in._pad); 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->out, req->out.body+0x0C, io->in.secblob); + + status = smb2_push_o16s16_blob(&req->out, req->out.body+0x0C, io->in.secblob); if (!NT_STATUS_IS_OK(status)) { talloc_free(req); return NULL; @@ -103,16 +103,12 @@ NTSTATUS smb2_session_setup_recv(struct smb2_request *req, TALLOC_CTX *mem_ctx, return smb2_request_destroy(req); } - if (req->in.body_size < 0x08) { - return NT_STATUS_BUFFER_TOO_SMALL; - } - - SMB2_CHECK_BUFFER_CODE(req, 0x09); + SMB2_CHECK_PACKET_RECV(req, 0x08, True); io->out._pad = SVAL(req->in.body, 0x02); io->out.uid = BVAL(req->in.hdr, SMB2_HDR_UID); - status = smb2_pull_ofs_blob(&req->in, mem_ctx, req->in.body+0x04, &io->out.secblob); + status = smb2_pull_o16s16_blob(&req->in, mem_ctx, req->in.body+0x04, &io->out.secblob); if (!NT_STATUS_IS_OK(status)) { smb2_request_destroy(req); return status; @@ -203,7 +199,7 @@ struct composite_context *smb2_session_setup_spnego_send(struct smb2_session *se c->event_ctx = session->transport->socket->event.ctx; ZERO_STRUCT(state->io); - state->io.in.unknown1 = 0x11; + state->io.in._pad = 0x0; state->io.in.unknown2 = 0xF; state->io.in.unknown3 = 0x00; -- cgit From fe996e8ac687dbf5b5cfdd795f14aed89663f06d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 17 Nov 2005 03:32:38 +0000 Subject: r11754: make the SMB2 blob push routines take offsets, so they fit better with the rest of the packet construction code (This used to be commit 387ec2b17ff30a1c040b460b498c8fa7d8770593) --- source4/libcli/smb2/session.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/smb2/session.c') diff --git a/source4/libcli/smb2/session.c b/source4/libcli/smb2/session.c index e572227a48..0a13a288fc 100644 --- a/source4/libcli/smb2/session.c +++ b/source4/libcli/smb2/session.c @@ -77,7 +77,7 @@ struct smb2_request *smb2_session_setup_send(struct smb2_session *session, req->session = session; - status = smb2_push_o16s16_blob(&req->out, req->out.body+0x0C, io->in.secblob); + status = smb2_push_o16s16_blob(&req->out, 0x0C, io->in.secblob); if (!NT_STATUS_IS_OK(status)) { talloc_free(req); return NULL; -- cgit From 310fa875091a85bb5d7be196906723f14305d406 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 25 Nov 2005 05:23:55 +0000 Subject: r11888: - added SMB2 trans support - added session key to SMB2 - renamed 'unknown2' in create to 'impersonation' (This used to be commit aef915f312a78bf8a4123f7c40fcd14ff293d934) --- source4/libcli/smb2/session.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'source4/libcli/smb2/session.c') diff --git a/source4/libcli/smb2/session.c b/source4/libcli/smb2/session.c index 0a13a288fc..c62b24797d 100644 --- a/source4/libcli/smb2/session.c +++ b/source4/libcli/smb2/session.c @@ -149,10 +149,17 @@ static void session_request_handler(struct smb2_request *req) 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))) { + NTSTATUS session_key_err; + DATA_BLOB session_key; c->status = gensec_update(session->gensec, c, state->io.out.secblob, &state->io.in.secblob); state->gensec_status = c->status; + + session_key_err = gensec_session_key(session->gensec, &session_key); + if (NT_STATUS_IS_OK(session_key_err)) { + session->session_key = session_key; + } } session->uid = state->io.out.uid; -- cgit From 9b2cd2e797c4b0375a1c5112528bbd8ab89b22ca Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 28 Nov 2005 22:53:42 +0000 Subject: r11949: make sure we ask gensec to give us a session key andrew, this answers your question on irc about whether the same session key mechanisms are used in smb2. They are - the RPC-LSA secret tests pass fine over ncacn_np on SMB2, which means the session key must be working (This used to be commit 91327885a2b6432ba20a8dd1370b632240d3263d) --- source4/libcli/smb2/session.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source4/libcli/smb2/session.c') diff --git a/source4/libcli/smb2/session.c b/source4/libcli/smb2/session.c index c62b24797d..12285d5536 100644 --- a/source4/libcli/smb2/session.c +++ b/source4/libcli/smb2/session.c @@ -54,6 +54,8 @@ struct smb2_session *smb2_session_init(struct smb2_transport *transport, return NULL; } + gensec_want_feature(session->gensec, GENSEC_FEATURE_SESSION_KEY); + return session; } -- cgit From fd7fd22e462ef6cf46e3f63e12ffcd684ea20244 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 2 Dec 2005 03:17:40 +0000 Subject: r12006: don't require callers to fill in pad bytes in SMB2 calls (This used to be commit 6935765fda99a6efb19f6f72358d4d48fc35ad5e) --- source4/libcli/smb2/session.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/smb2/session.c') diff --git a/source4/libcli/smb2/session.c b/source4/libcli/smb2/session.c index 12285d5536..07970747c4 100644 --- a/source4/libcli/smb2/session.c +++ b/source4/libcli/smb2/session.c @@ -73,7 +73,7 @@ struct smb2_request *smb2_session_setup_send(struct smb2_session *session, if (req == NULL) return NULL; SBVAL(req->out.hdr, SMB2_HDR_UID, session->uid); - SSVAL(req->out.body, 0x02, io->in._pad); + SSVAL(req->out.body, 0x02, 0); /* pad */ SIVAL(req->out.body, 0x04, io->in.unknown2); SIVAL(req->out.body, 0x08, io->in.unknown3); -- cgit From 111a920fdb92ccef32f89b2f992bdd3051e5ac54 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 8 Dec 2005 01:13:45 +0000 Subject: r12116: got rid of composite_trigger_done() and composite_trigger_error(), and instead make the normal composite_done() and composite_error() functions automatically trigger a delayed callback if the caller has had no opportunity to setup a async callback this removes one of the common mistakes in writing a composite function (This used to be commit f9413ce792ded682e05134b66d433eeec293e6f1) --- source4/libcli/smb2/session.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/smb2/session.c') diff --git a/source4/libcli/smb2/session.c b/source4/libcli/smb2/session.c index 07970747c4..208e2a94de 100644 --- a/source4/libcli/smb2/session.c +++ b/source4/libcli/smb2/session.c @@ -253,7 +253,7 @@ struct composite_context *smb2_session_setup_spnego_send(struct smb2_session *se return c; failed: - composite_trigger_error(c); + composite_error(c, c->status); return c; } -- cgit From 57026269068b035a2f32e971784ab31883854398 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 15 Mar 2006 05:53:15 +0000 Subject: r14435: return after an error (This used to be commit 40e5bfdb0fadedb81d8fbd7e8cc578ef2ea12b13) --- source4/libcli/smb2/session.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/libcli/smb2/session.c') diff --git a/source4/libcli/smb2/session.c b/source4/libcli/smb2/session.c index 208e2a94de..1d1b97600a 100644 --- a/source4/libcli/smb2/session.c +++ b/source4/libcli/smb2/session.c @@ -170,6 +170,7 @@ static void session_request_handler(struct smb2_request *req) state->req = smb2_session_setup_send(session, &state->io); if (state->req == NULL) { composite_error(c, NT_STATUS_NO_MEMORY); + return; } state->req->async.fn = session_request_handler; -- cgit From dc86ab3e454d7219608d01879145dec5609acaa3 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 11 May 2006 10:47:37 +0000 Subject: r15532: add a BOOL body_dynamic_present, because the body_dynamic_size can be 0 also if the dynamic flag should be set metze (This used to be commit 7829100e1ee79f4f5d24004af221288e19c09b3e) --- source4/libcli/smb2/session.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/smb2/session.c') diff --git a/source4/libcli/smb2/session.c b/source4/libcli/smb2/session.c index 1d1b97600a..83e6d1ae00 100644 --- a/source4/libcli/smb2/session.c +++ b/source4/libcli/smb2/session.c @@ -69,7 +69,7 @@ struct smb2_request *smb2_session_setup_send(struct smb2_session *session, NTSTATUS status; req = smb2_request_init(session->transport, SMB2_OP_SESSSETUP, - 0x10, io->in.secblob.length); + 0x10, True, io->in.secblob.length); if (req == NULL) return NULL; SBVAL(req->out.hdr, SMB2_HDR_UID, session->uid); -- cgit From 63d0c5a0570908cee293cca3300a4b50f48f8afd Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 30 Jun 2006 11:07:47 +0000 Subject: r16708: the packet format of SMB2 SessionSetup has changed, there're 8 more unknown bytes... Note: - vista-CTP also support this as a server, but uses the old format as client - but vista-beta2 only uses and accept the new format metze (This used to be commit b3bdd4afdefc9ad3550f86a0aa6e6c90bf8ab416) --- source4/libcli/smb2/session.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'source4/libcli/smb2/session.c') diff --git a/source4/libcli/smb2/session.c b/source4/libcli/smb2/session.c index 83e6d1ae00..7518a3d6d3 100644 --- a/source4/libcli/smb2/session.c +++ b/source4/libcli/smb2/session.c @@ -69,11 +69,11 @@ struct smb2_request *smb2_session_setup_send(struct smb2_session *session, NTSTATUS status; req = smb2_request_init(session->transport, SMB2_OP_SESSSETUP, - 0x10, True, io->in.secblob.length); + 0x18, True, io->in.secblob.length); if (req == NULL) return NULL; SBVAL(req->out.hdr, SMB2_HDR_UID, session->uid); - SSVAL(req->out.body, 0x02, 0); /* pad */ + SSVAL(req->out.body, 0x02, io->in._pad); /* pad */ SIVAL(req->out.body, 0x04, io->in.unknown2); SIVAL(req->out.body, 0x08, io->in.unknown3); @@ -84,6 +84,7 @@ struct smb2_request *smb2_session_setup_send(struct smb2_session *session, talloc_free(req); return NULL; } + SBVAL(req->out.body, 0x10, io->in.unknown4); smb2_transport_send(req); @@ -209,9 +210,10 @@ struct composite_context *smb2_session_setup_spnego_send(struct smb2_session *se c->event_ctx = session->transport->socket->event.ctx; ZERO_STRUCT(state->io); - state->io.in._pad = 0x0; - state->io.in.unknown2 = 0xF; - state->io.in.unknown3 = 0x00; + state->io.in._pad = 0x0000; + state->io.in.unknown2 = 0x0000000F; + state->io.in.unknown3 = 0x00000000; + state->io.in.unknown4 = 0; /* uint64_t */ c->status = gensec_set_credentials(session->gensec, credentials); if (!NT_STATUS_IS_OK(c->status)) { -- cgit From 7c50eec25edd2e70d9127f8cc35588c4bfbb53f9 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sun, 30 Jul 2006 17:29:02 +0000 Subject: r17318: make better usage of the composite api metze (This used to be commit 683fc25f6524a3821ba70529251aabe97bad9370) --- source4/libcli/smb2/session.c | 42 +++++++++--------------------------------- 1 file changed, 9 insertions(+), 33 deletions(-) (limited to 'source4/libcli/smb2/session.c') diff --git a/source4/libcli/smb2/session.c b/source4/libcli/smb2/session.c index 7518a3d6d3..8ebdc93bd4 100644 --- a/source4/libcli/smb2/session.c +++ b/source4/libcli/smb2/session.c @@ -196,18 +196,12 @@ struct composite_context *smb2_session_setup_spnego_send(struct smb2_session *se struct composite_context *c; struct smb2_session_state *state; - c = talloc_zero(session, struct composite_context); + c = composite_create(session, session->transport->socket->event.ctx); 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; + if (composite_nomem(state, c)) return c; c->private_data = state; - c->event_ctx = session->transport->socket->event.ctx; ZERO_STRUCT(state->io); state->io.in._pad = 0x0000; @@ -216,47 +210,29 @@ struct composite_context *smb2_session_setup_spnego_send(struct smb2_session *se state->io.in.unknown4 = 0; /* uint64_t */ c->status = gensec_set_credentials(session->gensec, credentials); - if (!NT_STATUS_IS_OK(c->status)) { - goto failed; - } + if (!composite_is_ok(c)) return c; c->status = gensec_set_target_hostname(session->gensec, session->transport->socket->hostname); - if (!NT_STATUS_IS_OK(c->status)) { - goto failed; - } + if (!composite_is_ok(c)) return c; c->status = gensec_set_target_service(session->gensec, "cifs"); - if (!NT_STATUS_IS_OK(c->status)) { - goto failed; - } + if (!composite_is_ok(c)) return c; c->status = gensec_start_mech_by_oid(session->gensec, GENSEC_OID_SPNEGO); - if (!NT_STATUS_IS_OK(c->status)) { - goto failed; - } + if (!composite_is_ok(c)) return c; 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; + composite_error(c, c->status); + return c; } 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_error(c, c->status); + composite_continue_smb2(c, state->req, session_request_handler, c); return c; } -- cgit From 0479a2f1cbae51fcd8dbdc3c148c808421fb4d25 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 02:07:03 +0000 Subject: r23792: convert Samba4 to GPLv3 There are still a few tidyups of old FSF addresses to come (in both s3 and s4). More commits soon. (This used to be commit fcf38a38ac691abd0fa51b89dc951a08e89fdafa) --- source4/libcli/smb2/session.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/libcli/smb2/session.c') diff --git a/source4/libcli/smb2/session.c b/source4/libcli/smb2/session.c index 8ebdc93bd4..3f9b3ed55c 100644 --- a/source4/libcli/smb2/session.c +++ b/source4/libcli/smb2/session.c @@ -7,7 +7,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -16,8 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" -- cgit From 2151cde58014ea2e822c13d2f8a369b45dc19ca8 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 6 Oct 2007 22:28:14 +0000 Subject: r25554: Convert last instances of BOOL, True and False to the standard types. (This used to be commit 566aa14139510788548a874e9213d91317f83ca9) --- source4/libcli/smb2/session.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/libcli/smb2/session.c') diff --git a/source4/libcli/smb2/session.c b/source4/libcli/smb2/session.c index 3f9b3ed55c..462f60d2c2 100644 --- a/source4/libcli/smb2/session.c +++ b/source4/libcli/smb2/session.c @@ -30,7 +30,7 @@ initialise a smb2_session structure */ struct smb2_session *smb2_session_init(struct smb2_transport *transport, - TALLOC_CTX *parent_ctx, BOOL primary) + TALLOC_CTX *parent_ctx, bool primary) { struct smb2_session *session; NTSTATUS status; @@ -68,7 +68,7 @@ struct smb2_request *smb2_session_setup_send(struct smb2_session *session, NTSTATUS status; req = smb2_request_init(session->transport, SMB2_OP_SESSSETUP, - 0x18, True, io->in.secblob.length); + 0x18, true, io->in.secblob.length); if (req == NULL) return NULL; SBVAL(req->out.hdr, SMB2_HDR_UID, session->uid); @@ -105,7 +105,7 @@ NTSTATUS smb2_session_setup_recv(struct smb2_request *req, TALLOC_CTX *mem_ctx, return smb2_request_destroy(req); } - SMB2_CHECK_PACKET_RECV(req, 0x08, True); + SMB2_CHECK_PACKET_RECV(req, 0x08, true); io->out._pad = SVAL(req->in.body, 0x02); io->out.uid = BVAL(req->in.hdr, SMB2_HDR_UID); -- cgit From ecea5ce24553989103d4a06296b24f4d29f30a36 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 3 Dec 2007 17:41:50 +0100 Subject: r26260: Store loadparm context in gensec context. (This used to be commit b9e3a4862e267be39d603fed8207a237c3d72081) --- source4/libcli/smb2/session.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'source4/libcli/smb2/session.c') diff --git a/source4/libcli/smb2/session.c b/source4/libcli/smb2/session.c index 462f60d2c2..c85dc91579 100644 --- a/source4/libcli/smb2/session.c +++ b/source4/libcli/smb2/session.c @@ -25,8 +25,9 @@ #include "libcli/smb2/smb2_calls.h" #include "libcli/composite/composite.h" #include "auth/gensec/gensec.h" +#include "param/param.h" -/* +/** initialise a smb2_session structure */ struct smb2_session *smb2_session_init(struct smb2_transport *transport, @@ -47,7 +48,8 @@ struct smb2_session *smb2_session_init(struct smb2_transport *transport, /* prepare a gensec context for later use */ status = gensec_client_start(session, &session->gensec, - session->transport->socket->event.ctx); + session->transport->socket->event.ctx, + global_loadparm); if (!NT_STATUS_IS_OK(status)) { talloc_free(session); return NULL; @@ -58,7 +60,7 @@ struct smb2_session *smb2_session_init(struct smb2_transport *transport, return session; } -/* +/** send a session setup request */ struct smb2_request *smb2_session_setup_send(struct smb2_session *session, @@ -91,7 +93,7 @@ struct smb2_request *smb2_session_setup_send(struct smb2_session *session, } -/* +/** recv a session setup reply */ NTSTATUS smb2_session_setup_recv(struct smb2_request *req, TALLOC_CTX *mem_ctx, -- cgit From da2ae4995370affe57cfecfe371a4edf553065d0 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 7 Dec 2007 16:04:25 +0100 Subject: r26337: Move global_loadparm to a higher caller. (This used to be commit baa5bcd303c72431dfa638edde72cded4265c612) --- source4/libcli/smb2/session.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source4/libcli/smb2/session.c') diff --git a/source4/libcli/smb2/session.c b/source4/libcli/smb2/session.c index c85dc91579..a784ea65d8 100644 --- a/source4/libcli/smb2/session.c +++ b/source4/libcli/smb2/session.c @@ -31,6 +31,7 @@ initialise a smb2_session structure */ struct smb2_session *smb2_session_init(struct smb2_transport *transport, + struct loadparm_context *lp_ctx, TALLOC_CTX *parent_ctx, bool primary) { struct smb2_session *session; @@ -49,7 +50,7 @@ struct smb2_session *smb2_session_init(struct smb2_transport *transport, /* prepare a gensec context for later use */ status = gensec_client_start(session, &session->gensec, session->transport->socket->event.ctx, - global_loadparm); + lp_ctx); if (!NT_STATUS_IS_OK(status)) { talloc_free(session); return NULL; -- cgit From 416360895f36d41ce8d29c25ef08e2b8b4e38571 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 12 Feb 2008 16:43:38 +1100 Subject: converted SMB2 session setup to use WSPP protocol field names (This used to be commit 3c2af0fdc4916dce32c2690e49dde0852d1a0c50) --- source4/libcli/smb2/session.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'source4/libcli/smb2/session.c') diff --git a/source4/libcli/smb2/session.c b/source4/libcli/smb2/session.c index a784ea65d8..d06688a598 100644 --- a/source4/libcli/smb2/session.c +++ b/source4/libcli/smb2/session.c @@ -75,9 +75,11 @@ struct smb2_request *smb2_session_setup_send(struct smb2_session *session, if (req == NULL) return NULL; SBVAL(req->out.hdr, SMB2_HDR_UID, session->uid); - SSVAL(req->out.body, 0x02, io->in._pad); /* pad */ - SIVAL(req->out.body, 0x04, io->in.unknown2); - SIVAL(req->out.body, 0x08, io->in.unknown3); + SCVAL(req->out.body, 0x02, io->in.vc_number); + SCVAL(req->out.body, 0x03, io->in.security_mode); + SIVAL(req->out.body, 0x04, io->in.capabilities); + SIVAL(req->out.body, 0x08, io->in.channel); + SBVAL(req->out.body, 0x10, io->in.previous_sessionid); req->session = session; @@ -86,7 +88,6 @@ struct smb2_request *smb2_session_setup_send(struct smb2_session *session, talloc_free(req); return NULL; } - SBVAL(req->out.body, 0x10, io->in.unknown4); smb2_transport_send(req); @@ -110,8 +111,8 @@ NTSTATUS smb2_session_setup_recv(struct smb2_request *req, TALLOC_CTX *mem_ctx, SMB2_CHECK_PACKET_RECV(req, 0x08, true); - io->out._pad = SVAL(req->in.body, 0x02); - io->out.uid = BVAL(req->in.hdr, SMB2_HDR_UID); + io->out.session_flags = SVAL(req->in.body, 0x02); + io->out.uid = BVAL(req->in.hdr, SMB2_HDR_UID); status = smb2_pull_o16s16_blob(&req->in, mem_ctx, req->in.body+0x04, &io->out.secblob); if (!NT_STATUS_IS_OK(status)) { @@ -206,10 +207,11 @@ struct composite_context *smb2_session_setup_spnego_send(struct smb2_session *se c->private_data = state; ZERO_STRUCT(state->io); - state->io.in._pad = 0x0000; - state->io.in.unknown2 = 0x0000000F; - state->io.in.unknown3 = 0x00000000; - state->io.in.unknown4 = 0; /* uint64_t */ + state->io.in.vc_number = 0; + state->io.in.security_mode = 0; + state->io.in.capabilities = 0; + state->io.in.channel = 0; + state->io.in.previous_sessionid = 0; c->status = gensec_set_credentials(session->gensec, credentials); if (!composite_is_ok(c)) return c; -- cgit From a2505c5a2cc2b7b692ffbcdd8c6b86000a15d2c7 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 12 Feb 2008 17:00:35 +1100 Subject: updated SMB2 header defines to match WSPP docs (This used to be commit d2c6ad55eca27f50a38fc6e2a85032eddb3f0aae) --- source4/libcli/smb2/session.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/libcli/smb2/session.c') diff --git a/source4/libcli/smb2/session.c b/source4/libcli/smb2/session.c index d06688a598..18fe3486a4 100644 --- a/source4/libcli/smb2/session.c +++ b/source4/libcli/smb2/session.c @@ -74,7 +74,7 @@ struct smb2_request *smb2_session_setup_send(struct smb2_session *session, 0x18, true, io->in.secblob.length); if (req == NULL) return NULL; - SBVAL(req->out.hdr, SMB2_HDR_UID, session->uid); + SBVAL(req->out.hdr, SMB2_HDR_SESSION_ID, session->uid); SCVAL(req->out.body, 0x02, io->in.vc_number); SCVAL(req->out.body, 0x03, io->in.security_mode); SIVAL(req->out.body, 0x04, io->in.capabilities); @@ -112,7 +112,7 @@ NTSTATUS smb2_session_setup_recv(struct smb2_request *req, TALLOC_CTX *mem_ctx, SMB2_CHECK_PACKET_RECV(req, 0x08, true); io->out.session_flags = SVAL(req->in.body, 0x02); - io->out.uid = BVAL(req->in.hdr, SMB2_HDR_UID); + io->out.uid = BVAL(req->in.hdr, SMB2_HDR_SESSION_ID); status = smb2_pull_o16s16_blob(&req->in, mem_ctx, req->in.body+0x04, &io->out.secblob); if (!NT_STATUS_IS_OK(status)) { -- cgit From c7d7577fb978dfa822b4aab238440816188099c6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 16 May 2008 15:03:58 +1000 Subject: private -> private_data for struct smb2_request (This used to be commit 67290e0ad69df2f2fe651249c6550b8e32dd641b) --- source4/libcli/smb2/session.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/libcli/smb2/session.c') diff --git a/source4/libcli/smb2/session.c b/source4/libcli/smb2/session.c index 18fe3486a4..29af6652f2 100644 --- a/source4/libcli/smb2/session.c +++ b/source4/libcli/smb2/session.c @@ -145,7 +145,7 @@ struct smb2_session_state { */ static void session_request_handler(struct smb2_request *req) { - struct composite_context *c = talloc_get_type(req->async.private, + struct composite_context *c = talloc_get_type(req->async.private_data, struct composite_context); struct smb2_session_state *state = talloc_get_type(c->private_data, struct smb2_session_state); @@ -178,7 +178,7 @@ static void session_request_handler(struct smb2_request *req) } state->req->async.fn = session_request_handler; - state->req->async.private = c; + state->req->async.private_data = c; return; } -- cgit From beaa01e403dda7557a6acdf0181d79d58a33bbbe Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 30 May 2008 17:03:54 +1000 Subject: implemented client side SMB2 signing This doessn't work against Windows yet, and I've submitted a WSPP request for clarification of the docs to try and find out why. Meanwhile this is no worse than what we had, as it only gets used when the server demands signing, and we didn't work then anyway. (This used to be commit b788096add3586d7277efcd3bf5ca7f3a604cb7a) --- source4/libcli/smb2/session.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'source4/libcli/smb2/session.c') diff --git a/source4/libcli/smb2/session.c b/source4/libcli/smb2/session.c index 29af6652f2..54915d8535 100644 --- a/source4/libcli/smb2/session.c +++ b/source4/libcli/smb2/session.c @@ -164,8 +164,8 @@ static void session_request_handler(struct smb2_request *req) session_key_err = gensec_session_key(session->gensec, &session_key); if (NT_STATUS_IS_OK(session_key_err)) { - session->session_key = session_key; - } + session->transport->signing.session_key = session_key; + } } session->uid = state->io.out.uid; @@ -187,6 +187,14 @@ static void session_request_handler(struct smb2_request *req) return; } + if (session->transport->signing.doing_signing) { + c->status = smb2_start_signing(session->transport); + if (!NT_STATUS_IS_OK(c->status)) { + composite_error(c, c->status); + return; + } + } + composite_done(c); } @@ -208,7 +216,10 @@ struct composite_context *smb2_session_setup_spnego_send(struct smb2_session *se ZERO_STRUCT(state->io); state->io.in.vc_number = 0; - state->io.in.security_mode = 0; + if (session->transport->signing.doing_signing) { + state->io.in.security_mode = + SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED; + } state->io.in.capabilities = 0; state->io.in.channel = 0; state->io.in.previous_sessionid = 0; -- cgit From e97cf207fac5e4101376d2a10dd95a93a9a1e0fb Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 6 Jun 2008 22:10:30 -0700 Subject: added server side SMB2 signing (This used to be commit 8e919dcb0826a5b25d037ee6144af5f7cb21f3ae) --- source4/libcli/smb2/session.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'source4/libcli/smb2/session.c') diff --git a/source4/libcli/smb2/session.c b/source4/libcli/smb2/session.c index 54915d8535..42fd4840a1 100644 --- a/source4/libcli/smb2/session.c +++ b/source4/libcli/smb2/session.c @@ -188,11 +188,13 @@ static void session_request_handler(struct smb2_request *req) } if (session->transport->signing.doing_signing) { - c->status = smb2_start_signing(session->transport); - if (!NT_STATUS_IS_OK(c->status)) { - composite_error(c, c->status); + if (session->transport->signing.session_key.length != 16) { + DEBUG(2,("Wrong session key length %u for SMB2 signing\n", + (unsigned)session->transport->signing.session_key.length)); + composite_error(c, NT_STATUS_ACCESS_DENIED); return; } + session->transport->signing.signing_started = true; } composite_done(c); -- cgit From 1c33953ae21384f04de11539afaf9ead5e413b96 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 7 Jun 2008 08:30:51 -0700 Subject: make signing per session in the SMB2 client library Thanks to Metze for spotting this (This used to be commit e9fd9b821c04d1cb7b574f539dd8169611e662aa) --- source4/libcli/smb2/session.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/libcli/smb2/session.c') diff --git a/source4/libcli/smb2/session.c b/source4/libcli/smb2/session.c index 42fd4840a1..91616319d5 100644 --- a/source4/libcli/smb2/session.c +++ b/source4/libcli/smb2/session.c @@ -164,7 +164,7 @@ static void session_request_handler(struct smb2_request *req) session_key_err = gensec_session_key(session->gensec, &session_key); if (NT_STATUS_IS_OK(session_key_err)) { - session->transport->signing.session_key = session_key; + session->session_key = session_key; } } @@ -188,9 +188,9 @@ static void session_request_handler(struct smb2_request *req) } if (session->transport->signing.doing_signing) { - if (session->transport->signing.session_key.length != 16) { + if (session->session_key.length != 16) { DEBUG(2,("Wrong session key length %u for SMB2 signing\n", - (unsigned)session->transport->signing.session_key.length)); + (unsigned)session->session_key.length)); composite_error(c, NT_STATUS_ACCESS_DENIED); return; } -- cgit From 35bd7a6378cc25ed6b24d153c3cf1557d6126788 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 9 Jun 2008 21:57:41 +0200 Subject: libcli/smb2: fix per session signing state metze (This used to be commit 8bc12dc77a59e792830d96e84a4e8d1b2c651505) --- source4/libcli/smb2/session.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/libcli/smb2/session.c') diff --git a/source4/libcli/smb2/session.c b/source4/libcli/smb2/session.c index 91616319d5..6c573bf6d5 100644 --- a/source4/libcli/smb2/session.c +++ b/source4/libcli/smb2/session.c @@ -187,14 +187,14 @@ static void session_request_handler(struct smb2_request *req) return; } - if (session->transport->signing.doing_signing) { + if (session->transport->signing_required) { if (session->session_key.length != 16) { DEBUG(2,("Wrong session key length %u for SMB2 signing\n", (unsigned)session->session_key.length)); composite_error(c, NT_STATUS_ACCESS_DENIED); return; } - session->transport->signing.signing_started = true; + session->signing_active = true; } composite_done(c); @@ -218,7 +218,7 @@ struct composite_context *smb2_session_setup_spnego_send(struct smb2_session *se ZERO_STRUCT(state->io); state->io.in.vc_number = 0; - if (session->transport->signing.doing_signing) { + if (session->transport->signing_required) { state->io.in.security_mode = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED; } -- cgit From 2d2911c7885dc832700185e62160bc18f8abfa04 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 28 Jul 2008 15:49:46 +0200 Subject: libcli/smb2: the session key for SMB2 signing is truncated to 16 bytes To make that work (as a client) with aes128 and aes256 krb5 keys we need to use gsskrb5_get_subkey(). metze (This used to be commit 0c6d988f2083067e1ac7b07a492f88cefd3ba906) --- source4/libcli/smb2/session.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/libcli/smb2/session.c') diff --git a/source4/libcli/smb2/session.c b/source4/libcli/smb2/session.c index 6c573bf6d5..31b3e942e9 100644 --- a/source4/libcli/smb2/session.c +++ b/source4/libcli/smb2/session.c @@ -188,8 +188,8 @@ static void session_request_handler(struct smb2_request *req) } if (session->transport->signing_required) { - if (session->session_key.length != 16) { - DEBUG(2,("Wrong session key length %u for SMB2 signing\n", + if (session->session_key.length == 0) { + DEBUG(0,("Wrong session key length %u for SMB2 signing\n", (unsigned)session->session_key.length)); composite_error(c, NT_STATUS_ACCESS_DENIED); return; -- cgit