[SCM] Samba Shared Repository - branch master updated
Stefan Metzmacher
metze at samba.org
Fri Apr 27 05:11:04 MDT 2012
The branch, master has been updated
via 34ffa61 s3:winbindd: also try SMB2 when connecting to "IPC$"
via b3a3c50 s3:libsmb/cli_np_tstream: add support for SMB2
via b88d649 s3:libsmb/cli_np_tstream: remove unused tstream_cli_np_existing()
via 8422ab2 s3:libsmb: add smb2cli_ioctl*
via 42b403c libcli/smb: move SMB2_IOCTL_FLAG_IS_FSCTL to smb2_constants.h
via 2ccf5f6 s4:ntvfs/ipc: don't echo back the smb2 ioctl input_buffer
from 54a6d7b s3: oplock_timeout is a talloc child of fsp
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit 34ffa6175bca1cee755e454c14683b7c826dd6c7
Author: Stefan Metzmacher <metze at samba.org>
Date: Thu Apr 26 12:06:21 2012 +0200
s3:winbindd: also try SMB2 when connecting to "IPC$"
metze
Autobuild-User: Stefan Metzmacher <metze at samba.org>
Autobuild-Date: Fri Apr 27 13:10:15 CEST 2012 on sn-devel-104
commit b3a3c50eb8ebfe2cc1fa602cb9680e4aa3f083cd
Author: Stefan Metzmacher <metze at samba.org>
Date: Wed Apr 25 20:18:22 2012 +0200
s3:libsmb/cli_np_tstream: add support for SMB2
metze
commit b88d649e401078a74103a78205f2c324a86eaafb
Author: Stefan Metzmacher <metze at samba.org>
Date: Thu Apr 26 14:05:40 2012 +0200
s3:libsmb/cli_np_tstream: remove unused tstream_cli_np_existing()
metze
commit 8422ab26095dd5c8e618e6606c64ebe05753f809
Author: Stefan Metzmacher <metze at samba.org>
Date: Wed Dec 21 11:04:43 2011 +0100
s3:libsmb: add smb2cli_ioctl*
metze
commit 42b403c19fb74b1e38e12d19c12b2e6e3bfddc6e
Author: Stefan Metzmacher <metze at samba.org>
Date: Thu Apr 26 09:35:34 2012 +0200
libcli/smb: move SMB2_IOCTL_FLAG_IS_FSCTL to smb2_constants.h
metze
commit 2ccf5f67a55d8ccc4a3120fe036174d5d66fba24
Author: Stefan Metzmacher <metze at samba.org>
Date: Thu Apr 26 12:05:24 2012 +0200
s4:ntvfs/ipc: don't echo back the smb2 ioctl input_buffer
metze
-----------------------------------------------------------------------
Summary of changes:
libcli/smb/smb2_constants.h | 3 +
source3/Makefile.in | 1 +
source3/libsmb/cli_np_tstream.c | 257 ++++++++++++++++++++++--------
source3/libsmb/cli_np_tstream.h | 8 -
source3/libsmb/smb2cli.h | 28 ++++
source3/libsmb/smb2cli_ioctl.c | 330 +++++++++++++++++++++++++++++++++++++++
source3/winbindd/winbindd_cm.c | 27 +++-
source3/wscript_build | 1 +
source4/libcli/raw/interfaces.h | 3 -
source4/ntvfs/ipc/vfs_ipc.c | 2 +-
10 files changed, 574 insertions(+), 86 deletions(-)
create mode 100644 source3/libsmb/smb2cli_ioctl.c
Changeset truncated at 500 lines:
diff --git a/libcli/smb/smb2_constants.h b/libcli/smb/smb2_constants.h
index fe681a3..b472c76 100644
--- a/libcli/smb/smb2_constants.h
+++ b/libcli/smb/smb2_constants.h
@@ -216,6 +216,9 @@
#define SMB2_WRITEFLAG_WRITE_THROUGH 0x00000001
+/* 2.2.31 SMB2 IOCTL Request */
+#define SMB2_IOCTL_FLAG_IS_FSCTL 0x00000001
+
/*
* Flags for durable handle v2 requests
*/
diff --git a/source3/Makefile.in b/source3/Makefile.in
index 1353bd2..e5aba23 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -628,6 +628,7 @@ LIBSMB_OBJ = libsmb/clientgen.o libsmb/cliconnect.o libsmb/clifile.o \
libsmb/smb2cli_read.o \
libsmb/smb2cli_write.o \
libsmb/smb2cli_query_directory.o \
+ libsmb/smb2cli_ioctl.o \
libsmb/cli_np_tstream.o \
libsmb/smbsock_connect.o \
$(LIBSAMBA_OBJ) \
diff --git a/source3/libsmb/cli_np_tstream.c b/source3/libsmb/cli_np_tstream.c
index 37fd68a..658f308 100644
--- a/source3/libsmb/cli_np_tstream.c
+++ b/source3/libsmb/cli_np_tstream.c
@@ -20,6 +20,7 @@
#include "includes.h"
#include "system/network.h"
#include "libsmb/libsmb.h"
+#include "libsmb/smb2cli.h"
#include "../lib/util/tevent_ntstatus.h"
#include "../lib/tsocket/tsocket.h"
#include "../lib/tsocket/tsocket_internal.h"
@@ -50,7 +51,10 @@ static const struct tstream_context_ops tstream_cli_np_ops;
struct tstream_cli_np {
struct cli_state *cli;
const char *npipe;
+ bool is_smb1;
uint16_t fnum;
+ uint64_t fid_persistent;
+ uint64_t fid_volatile;
unsigned int default_timeout;
struct {
@@ -88,7 +92,13 @@ static int tstream_cli_np_destructor(struct tstream_cli_np *cli_nps)
* tstream_disconnect_send()/_recv(), this will
* never be called.
*/
- status = cli_close(cli_nps->cli, cli_nps->fnum);
+ if (cli_nps->is_smb1) {
+ status = cli_close(cli_nps->cli, cli_nps->fnum);
+ } else {
+ status = smb2cli_close(cli_nps->cli, 0,
+ cli_nps->fid_persistent,
+ cli_nps->fid_volatile);
+ }
if (!NT_STATUS_IS_OK(status)) {
DEBUG(1, ("tstream_cli_np_destructor: cli_close "
"failed on pipe %s. Error was %s\n",
@@ -102,7 +112,10 @@ static int tstream_cli_np_destructor(struct tstream_cli_np *cli_nps)
struct tstream_cli_np_open_state {
struct cli_state *cli;
+ bool is_smb1;
uint16_t fnum;
+ uint64_t fid_persistent;
+ uint64_t fid_volatile;
const char *npipe;
};
@@ -129,15 +142,32 @@ struct tevent_req *tstream_cli_np_open_send(TALLOC_CTX *mem_ctx,
return tevent_req_post(req, ev);
}
- subreq = cli_ntcreate_send(state, ev, cli,
- npipe,
- 0,
- DESIRED_ACCESS_PIPE,
- 0,
- FILE_SHARE_READ|FILE_SHARE_WRITE,
- FILE_OPEN,
- 0,
- 0);
+ if (cli_state_protocol(cli) < PROTOCOL_SMB2_02) {
+ state->is_smb1 = true;
+ }
+
+ if (state->is_smb1) {
+ subreq = cli_ntcreate_send(state, ev, cli,
+ npipe,
+ 0,
+ DESIRED_ACCESS_PIPE,
+ 0,
+ FILE_SHARE_READ|FILE_SHARE_WRITE,
+ FILE_OPEN,
+ 0,
+ 0);
+ } else {
+ subreq = smb2cli_create_send(state, ev, cli,
+ npipe,
+ SMB2_OPLOCK_LEVEL_NONE,
+ SMB2_IMPERSONATION_IMPERSONATION,
+ DESIRED_ACCESS_PIPE,
+ 0, /* file_attributes */
+ FILE_SHARE_READ|FILE_SHARE_WRITE,
+ FILE_OPEN,
+ 0, /* create_options */
+ NULL); /* blobs */
+ }
if (tevent_req_nomem(subreq, req)) {
return tevent_req_post(req, ev);
}
@@ -154,7 +184,13 @@ static void tstream_cli_np_open_done(struct tevent_req *subreq)
tevent_req_data(req, struct tstream_cli_np_open_state);
NTSTATUS status;
- status = cli_ntcreate_recv(subreq, &state->fnum);
+ if (state->is_smb1) {
+ status = cli_ntcreate_recv(subreq, &state->fnum);
+ } else {
+ status = smb2cli_create_recv(subreq,
+ &state->fid_persistent,
+ &state->fid_volatile);
+ }
TALLOC_FREE(subreq);
if (!NT_STATUS_IS_OK(status)) {
tevent_req_nterror(req, status);
@@ -193,7 +229,10 @@ NTSTATUS _tstream_cli_np_open_recv(struct tevent_req *req,
cli_nps->cli = state->cli;
cli_nps->npipe = talloc_move(cli_nps, &state->npipe);
+ cli_nps->is_smb1 = state->is_smb1;
cli_nps->fnum = state->fnum;
+ cli_nps->fid_persistent = state->fid_persistent;
+ cli_nps->fid_volatile = state->fid_volatile;
cli_nps->default_timeout = cli_set_timeout(state->cli, 0);
cli_set_timeout(state->cli, cli_nps->default_timeout);
@@ -421,11 +460,23 @@ static void tstream_cli_np_writev_write_next(struct tevent_req *req)
return;
}
- subreq = cli_write_andx_send(state, state->ev, cli_nps->cli,
- cli_nps->fnum,
- 8, /* 8 means message mode. */
- cli_nps->write.buf, 0,
- cli_nps->write.ofs);
+ if (cli_nps->is_smb1) {
+ subreq = cli_write_andx_send(state, state->ev, cli_nps->cli,
+ cli_nps->fnum,
+ 8, /* 8 means message mode. */
+ cli_nps->write.buf,
+ 0, /* offset */
+ cli_nps->write.ofs); /* size */
+ } else {
+ subreq = smb2cli_write_send(state, state->ev, cli_nps->cli,
+ cli_nps->write.ofs, /* length */
+ 0, /* offset */
+ cli_nps->fid_persistent,
+ cli_nps->fid_volatile,
+ 0, /* remaining_bytes */
+ 0, /* flags */
+ cli_nps->write.buf);
+ }
if (tevent_req_nomem(subreq, req)) {
return;
}
@@ -450,7 +501,12 @@ static void tstream_cli_np_writev_write_done(struct tevent_req *subreq)
size_t written;
NTSTATUS status;
- status = cli_write_andx_recv(subreq, &written);
+ if (cli_nps->is_smb1) {
+ status = cli_write_andx_recv(subreq, &written);
+ } else {
+ status = smb2cli_write_recv(subreq);
+ written = cli_nps->write.ofs; // TODO: get the value from the server
+ }
TALLOC_FREE(subreq);
if (!NT_STATUS_IS_OK(status)) {
tstream_cli_np_writev_disconnect_now(req, EIO, __location__);
@@ -488,7 +544,15 @@ static void tstream_cli_np_writev_disconnect_now(struct tevent_req *req,
return;
}
- subreq = cli_close_send(state, state->ev, cli_nps->cli, cli_nps->fnum);
+ if (cli_nps->is_smb1) {
+ subreq = cli_close_send(state, state->ev, cli_nps->cli,
+ cli_nps->fnum);
+ } else {
+ subreq = smb2cli_close_send(state, state->ev, cli_nps->cli,
+ 0, /* flags */
+ cli_nps->fid_persistent,
+ cli_nps->fid_volatile);
+ }
if (subreq == NULL) {
/* return the original error */
_tevent_req_error(req, state->error.val, state->error.location);
@@ -508,7 +572,11 @@ static void tstream_cli_np_writev_disconnect_done(struct tevent_req *subreq)
struct tstream_cli_np *cli_nps =
tstream_context_data(state->stream, struct tstream_cli_np);
- cli_close_recv(subreq);
+ if (cli_nps->is_smb1) {
+ cli_close_recv(subreq);
+ } else {
+ smb2cli_close_recv(subreq);
+ }
TALLOC_FREE(subreq);
cli_nps->cli = NULL;
@@ -668,8 +736,20 @@ static void tstream_cli_np_readv_read_next(struct tevent_req *req)
return;
}
- subreq = cli_read_andx_send(state, state->ev, cli_nps->cli,
- cli_nps->fnum, 0, TSTREAM_CLI_NP_MAX_BUF_SIZE);
+ if (cli_nps->is_smb1) {
+ subreq = cli_read_andx_send(state, state->ev, cli_nps->cli,
+ cli_nps->fnum,
+ 0, /* offset */
+ TSTREAM_CLI_NP_MAX_BUF_SIZE);
+ } else {
+ subreq = smb2cli_read_send(state, state->ev, cli_nps->cli,
+ TSTREAM_CLI_NP_MAX_BUF_SIZE, /* length */
+ 0, /* offset */
+ cli_nps->fid_persistent,
+ cli_nps->fid_volatile,
+ 0, /* minimum_count */
+ 0); /* remaining_bytes */
+ }
if (tevent_req_nomem(subreq, req)) {
return;
}
@@ -695,17 +775,37 @@ static void tstream_cli_np_readv_trans_start(struct tevent_req *req)
return;
}
- subreq = cli_trans_send(state, state->ev,
- cli_nps->cli,
- SMBtrans,
- "\\PIPE\\",
- 0, 0, 0,
- cli_nps->trans.setup, 2,
- 0,
- NULL, 0, 0,
- cli_nps->write.buf,
- cli_nps->write.ofs,
- TSTREAM_CLI_NP_MAX_BUF_SIZE);
+ if (cli_nps->is_smb1) {
+ subreq = cli_trans_send(state, state->ev,
+ cli_nps->cli,
+ SMBtrans,
+ "\\PIPE\\",
+ 0, 0, 0,
+ cli_nps->trans.setup, 2,
+ 0,
+ NULL, 0, 0,
+ cli_nps->write.buf,
+ cli_nps->write.ofs,
+ TSTREAM_CLI_NP_MAX_BUF_SIZE);
+ } else {
+ DATA_BLOB in_input_buffer = data_blob_null;
+ DATA_BLOB in_output_buffer = data_blob_null;
+
+ in_input_buffer = data_blob_const(cli_nps->write.buf,
+ cli_nps->write.ofs);
+
+ subreq = smb2cli_ioctl_send(state, state->ev,
+ cli_nps->cli,
+ cli_nps->fid_persistent,
+ cli_nps->fid_volatile,
+ FSCTL_NAMED_PIPE_READ_WRITE,
+ 0, /* in_max_input_length */
+ &in_input_buffer,
+ /* in_max_output_length */
+ TSTREAM_CLI_NP_MAX_BUF_SIZE,
+ &in_output_buffer,
+ SMB2_IOCTL_FLAG_IS_FSCTL);
+ }
if (tevent_req_nomem(subreq, req)) {
return;
}
@@ -733,9 +833,22 @@ static void tstream_cli_np_readv_trans_done(struct tevent_req *subreq)
uint32_t received;
NTSTATUS status;
- status = cli_trans_recv(subreq, state, NULL, NULL, 0, NULL,
- NULL, 0, NULL,
- &rcvbuf, 0, &received);
+ if (cli_nps->is_smb1) {
+ status = cli_trans_recv(subreq, state, NULL, NULL, 0, NULL,
+ NULL, 0, NULL,
+ &rcvbuf, 0, &received);
+ } else {
+ DATA_BLOB out_input_buffer = data_blob_null;
+ DATA_BLOB out_output_buffer = data_blob_null;
+
+ status = smb2cli_ioctl_recv(subreq, state,
+ &out_input_buffer,
+ &out_output_buffer);
+
+ /* Note that rcvbuf is not a talloc pointer here */
+ rcvbuf = out_output_buffer.data;
+ received = out_output_buffer.length;
+ }
TALLOC_FREE(subreq);
if (NT_STATUS_EQUAL(status, NT_STATUS_BUFFER_TOO_SMALL)) {
status = NT_STATUS_OK;
@@ -757,7 +870,13 @@ static void tstream_cli_np_readv_trans_done(struct tevent_req *subreq)
cli_nps->read.ofs = 0;
cli_nps->read.left = received;
- cli_nps->read.buf = talloc_move(cli_nps, &rcvbuf);
+ cli_nps->read.buf = talloc_array(cli_nps, uint8_t, received);
+ if (cli_nps->read.buf == NULL) {
+ TALLOC_FREE(subreq);
+ tevent_req_nomem(cli_nps->read.buf, req);
+ return;
+ }
+ memcpy(cli_nps->read.buf, rcvbuf, received);
if (cli_nps->trans.write_req == NULL) {
tstream_cli_np_readv_read_next(req);
@@ -798,7 +917,13 @@ static void tstream_cli_np_readv_read_done(struct tevent_req *subreq)
* a timer event attached to it.
*/
- status = cli_read_andx_recv(subreq, &received, &rcvbuf);
+ if (cli_nps->is_smb1) {
+ status = cli_read_andx_recv(subreq, &received, &rcvbuf);
+ } else {
+ uint32_t data_length = 0;
+ status = smb2cli_read_recv(subreq, state, &rcvbuf, &data_length);
+ received = data_length;
+ }
/*
* We can't TALLOC_FREE(subreq) as usual here, as rcvbuf still is a
* child of that.
@@ -870,7 +995,15 @@ static void tstream_cli_np_readv_disconnect_now(struct tevent_req *req,
return;
}
- subreq = cli_close_send(state, state->ev, cli_nps->cli, cli_nps->fnum);
+ if (cli_nps->is_smb1) {
+ subreq = cli_close_send(state, state->ev, cli_nps->cli,
+ cli_nps->fnum);
+ } else {
+ subreq = smb2cli_close_send(state, state->ev, cli_nps->cli,
+ 0, /* flags */
+ cli_nps->fid_persistent,
+ cli_nps->fid_volatile);
+ }
if (subreq == NULL) {
/* return the original error */
tstream_cli_np_readv_error(req);
@@ -890,7 +1023,11 @@ static void tstream_cli_np_readv_disconnect_done(struct tevent_req *subreq)
struct tstream_cli_np *cli_nps =
tstream_context_data(state->stream, struct tstream_cli_np);
- cli_close_recv(subreq);
+ if (cli_nps->is_smb1) {
+ cli_close_recv(subreq);
+ } else {
+ smb2cli_close_recv(subreq);
+ }
TALLOC_FREE(subreq);
cli_nps->cli = NULL;
@@ -991,7 +1128,15 @@ static struct tevent_req *tstream_cli_np_disconnect_send(TALLOC_CTX *mem_ctx,
return tevent_req_post(req, ev);
}
- subreq = cli_close_send(state, ev, cli_nps->cli, cli_nps->fnum);
+ if (cli_nps->is_smb1) {
+ subreq = cli_close_send(state, ev, cli_nps->cli,
+ cli_nps->fnum);
+ } else {
+ subreq = smb2cli_close_send(state, ev, cli_nps->cli,
+ 0, /* flags */
+ cli_nps->fid_persistent,
+ cli_nps->fid_volatile);
+ }
if (tevent_req_nomem(subreq, req)) {
return tevent_req_post(req, ev);
}
@@ -1010,7 +1155,11 @@ static void tstream_cli_np_disconnect_done(struct tevent_req *subreq)
tstream_context_data(state->stream, struct tstream_cli_np);
NTSTATUS status;
- status = cli_close_recv(subreq);
+ if (cli_nps->is_smb1) {
+ status = cli_close_recv(subreq);
+ } else {
+ status = smb2cli_close_recv(subreq);
+ }
TALLOC_FREE(subreq);
if (!NT_STATUS_IS_OK(status)) {
tevent_req_error(req, EIO);
@@ -1047,29 +1196,3 @@ static const struct tstream_context_ops tstream_cli_np_ops = {
.disconnect_send = tstream_cli_np_disconnect_send,
.disconnect_recv = tstream_cli_np_disconnect_recv,
};
-
-NTSTATUS _tstream_cli_np_existing(TALLOC_CTX *mem_ctx,
- struct cli_state *cli,
- uint16_t fnum,
- struct tstream_context **_stream,
- const char *location)
-{
- struct tstream_context *stream;
- struct tstream_cli_np *cli_nps;
-
- stream = tstream_context_create(mem_ctx,
- &tstream_cli_np_ops,
- &cli_nps,
- struct tstream_cli_np,
- location);
- if (!stream) {
- return NT_STATUS_NO_MEMORY;
- }
- ZERO_STRUCTP(cli_nps);
-
- cli_nps->cli = cli;
- cli_nps->fnum = fnum;
-
- *_stream = stream;
- return NT_STATUS_OK;
-}
diff --git a/source3/libsmb/cli_np_tstream.h b/source3/libsmb/cli_np_tstream.h
index b7def34..5f59d14 100644
--- a/source3/libsmb/cli_np_tstream.h
+++ b/source3/libsmb/cli_np_tstream.h
@@ -36,14 +36,6 @@ NTSTATUS _tstream_cli_np_open_recv(struct tevent_req *req,
#define tstream_cli_np_open_recv(req, mem_ctx, stream) \
_tstream_cli_np_open_recv(req, mem_ctx, stream, __location__)
-NTSTATUS _tstream_cli_np_existing(TALLOC_CTX *mem_ctx,
- struct cli_state *cli,
- uint16_t fnum,
- struct tstream_context **_stream,
- const char *location);
-#define tstream_cli_np_existing(mem_ctx, cli, npipe, stream) \
- _tstream_cli_np_existing(mem_ctx, cli, npipe, stream, __location__)
-
bool tstream_is_cli_np(struct tstream_context *stream);
NTSTATUS tstream_cli_np_use_trans(struct tstream_context *stream);
diff --git a/source3/libsmb/smb2cli.h b/source3/libsmb/smb2cli.h
index eeb6292..132fffd 100644
--- a/source3/libsmb/smb2cli.h
+++ b/source3/libsmb/smb2cli.h
@@ -160,4 +160,32 @@ NTSTATUS smb2cli_query_directory(struct cli_state *cli,
uint8_t **data,
uint32_t *data_length);
+struct tevent_req *smb2cli_ioctl_send(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct cli_state *cli,
+ uint64_t in_fid_persistent,
+ uint64_t in_fid_volatile,
+ uint32_t in_ctl_code,
+ uint32_t in_max_input_length,
+ const DATA_BLOB *in_input_buffer,
+ uint32_t in_max_output_length,
+ const DATA_BLOB *in_output_buffer,
+ uint32_t in_flags);
+NTSTATUS smb2cli_ioctl_recv(struct tevent_req *req,
+ TALLOC_CTX *mem_ctx,
+ DATA_BLOB *out_input_buffer,
+ DATA_BLOB *out_output_buffer);
+NTSTATUS smb2cli_ioctl(struct cli_state *cli,
+ uint64_t in_fid_persistent,
+ uint64_t in_fid_volatile,
+ uint32_t in_ctl_code,
+ uint32_t in_max_input_length,
+ const DATA_BLOB *in_input_buffer,
+ uint32_t in_max_output_length,
+ const DATA_BLOB *in_output_buffer,
+ uint32_t in_flags,
+ TALLOC_CTX *mem_ctx,
+ DATA_BLOB *out_input_buffer,
+ DATA_BLOB *out_output_buffer);
+
#endif /* __SMB2CLI_H__ */
diff --git a/source3/libsmb/smb2cli_ioctl.c b/source3/libsmb/smb2cli_ioctl.c
new file mode 100644
index 0000000..188bf1b
--- /dev/null
+++ b/source3/libsmb/smb2cli_ioctl.c
@@ -0,0 +1,330 @@
+/*
+ Unix SMB/CIFS implementation.
+ smb2 lib
+ Copyright (C) Stefan Metzmacher 2011
--
Samba Shared Repository
More information about the samba-cvs
mailing list