From c6395a30b057c87de8ce410d5ea5ebe2e017093d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 14 Nov 2005 05:09:26 +0000 Subject: r11715: added SMB2 read and write requests (This used to be commit d3556cbfa38447d2d385b697c1855b3c13d42744) --- source4/libcli/smb2/read.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 source4/libcli/smb2/read.c (limited to 'source4/libcli/smb2/read.c') diff --git a/source4/libcli/smb2/read.c b/source4/libcli/smb2/read.c new file mode 100644 index 0000000000..cbb3f74fa4 --- /dev/null +++ b/source4/libcli/smb2/read.c @@ -0,0 +1,95 @@ +/* + Unix SMB/CIFS implementation. + + SMB2 client read call + + 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" +#include "libcli/smb2/smb2_calls.h" + +/* + send a read request +*/ +struct smb2_request *smb2_read_send(struct smb2_tree *tree, struct smb2_read *io) +{ + struct smb2_request *req; + + req = smb2_request_init_tree(tree, SMB2_OP_READ, 0x31); + if (req == NULL) return NULL; + + SSVAL(req->out.body, 0x00, io->in.buffer_code); + SSVAL(req->out.body, 0x02, 0); + SIVAL(req->out.body, 0x04, io->in.length); + SBVAL(req->out.body, 0x08, io->in.offset); + smb2_put_handle(req->out.body+0x10, io->in.handle); + memcpy(req->out.body+0x20, io->in._pad, 17); + + smb2_transport_send(req); + + return req; +} + + +/* + recv a read reply +*/ +NTSTATUS smb2_read_recv(struct smb2_request *req, + TALLOC_CTX *mem_ctx, struct smb2_read *io) +{ + uint16_t ofs; + uint32_t nread; + + if (!smb2_request_receive(req) || + smb2_request_is_error(req)) { + return smb2_request_destroy(req); + } + + if (req->in.body_size < 16) { + return NT_STATUS_BUFFER_TOO_SMALL; + } + + SMB2_CHECK_BUFFER_CODE(req, 0x11); + + ofs = SVAL(req->in.body, 0x02); + + nread = IVAL(req->in.body, 0x04); + memcpy(io->out.unknown, req->in.body+0x08, 8); + + if (smb2_oob_in(req, req->in.hdr+ofs, nread)) { + return NT_STATUS_BUFFER_TOO_SMALL; + } + + io->out.data = data_blob_talloc(mem_ctx, req->in.hdr+ofs, nread); + if (io->out.data.data == NULL) { + return NT_STATUS_NO_MEMORY; + } + + return smb2_request_destroy(req); +} + +/* + sync read request +*/ +NTSTATUS smb2_read(struct smb2_tree *tree, TALLOC_CTX *mem_ctx, struct smb2_read *io) +{ + struct smb2_request *req = smb2_read_send(tree, io); + return smb2_read_recv(req, mem_ctx, io); +} -- cgit From 61317df8aab2fe2fd47baba8a137566df7b23395 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 14 Nov 2005 07:06:16 +0000 Subject: r11721: Fix warnings (This used to be commit d760583e388157ff25e317da06c57e5a42f171bd) --- source4/libcli/smb2/read.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/smb2/read.c') diff --git a/source4/libcli/smb2/read.c b/source4/libcli/smb2/read.c index cbb3f74fa4..0d63a6ba0a 100644 --- a/source4/libcli/smb2/read.c +++ b/source4/libcli/smb2/read.c @@ -39,7 +39,7 @@ struct smb2_request *smb2_read_send(struct smb2_tree *tree, struct smb2_read *io SSVAL(req->out.body, 0x02, 0); SIVAL(req->out.body, 0x04, io->in.length); SBVAL(req->out.body, 0x08, io->in.offset); - smb2_put_handle(req->out.body+0x10, io->in.handle); + smb2_put_handle(req->out.body+0x10, &io->in.handle); memcpy(req->out.body+0x20, io->in._pad, 17); smb2_transport_send(req); -- 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/read.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'source4/libcli/smb2/read.c') diff --git a/source4/libcli/smb2/read.c b/source4/libcli/smb2/read.c index 0d63a6ba0a..720d0bdbe0 100644 --- a/source4/libcli/smb2/read.c +++ b/source4/libcli/smb2/read.c @@ -73,11 +73,7 @@ NTSTATUS smb2_read_recv(struct smb2_request *req, nread = IVAL(req->in.body, 0x04); memcpy(io->out.unknown, req->in.body+0x08, 8); - if (smb2_oob_in(req, req->in.hdr+ofs, nread)) { - return NT_STATUS_BUFFER_TOO_SMALL; - } - - io->out.data = data_blob_talloc(mem_ctx, req->in.hdr+ofs, nread); + io->out.data = smb2_pull_blob(&req->in, mem_ctx, req->in.hdr+ofs, nread); if (io->out.data.data == NULL) { return NT_STATUS_NO_MEMORY; } -- 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/read.c | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) (limited to 'source4/libcli/smb2/read.c') diff --git a/source4/libcli/smb2/read.c b/source4/libcli/smb2/read.c index 720d0bdbe0..f598a78cba 100644 --- a/source4/libcli/smb2/read.c +++ b/source4/libcli/smb2/read.c @@ -32,15 +32,16 @@ struct smb2_request *smb2_read_send(struct smb2_tree *tree, struct smb2_read *io { struct smb2_request *req; - req = smb2_request_init_tree(tree, SMB2_OP_READ, 0x31); + req = smb2_request_init_tree(tree, SMB2_OP_READ, 0x31, 0); if (req == NULL) return NULL; - SSVAL(req->out.body, 0x00, io->in.buffer_code); - SSVAL(req->out.body, 0x02, 0); + SSVAL(req->out.body, 0x02, io->in._pad); SIVAL(req->out.body, 0x04, io->in.length); SBVAL(req->out.body, 0x08, io->in.offset); - smb2_put_handle(req->out.body+0x10, &io->in.handle); - memcpy(req->out.body+0x20, io->in._pad, 17); + smb2_push_handle(req->out.body+0x10, &io->in.handle); + SBVAL(req->out.body, 0x20, io->in.unknown1); + SBVAL(req->out.body, 0x28, io->in.unknown2); + SCVAL(req->out.body, 0x30, io->in._bug); smb2_transport_send(req); @@ -54,30 +55,23 @@ struct smb2_request *smb2_read_send(struct smb2_tree *tree, struct smb2_read *io NTSTATUS smb2_read_recv(struct smb2_request *req, TALLOC_CTX *mem_ctx, struct smb2_read *io) { - uint16_t ofs; - uint32_t nread; + NTSTATUS status; if (!smb2_request_receive(req) || smb2_request_is_error(req)) { return smb2_request_destroy(req); } - if (req->in.body_size < 16) { - return NT_STATUS_BUFFER_TOO_SMALL; - } - - SMB2_CHECK_BUFFER_CODE(req, 0x11); - - ofs = SVAL(req->in.body, 0x02); + SMB2_CHECK_PACKET_RECV(req, 0x10, True); - nread = IVAL(req->in.body, 0x04); - memcpy(io->out.unknown, req->in.body+0x08, 8); - - io->out.data = smb2_pull_blob(&req->in, mem_ctx, req->in.hdr+ofs, nread); - if (io->out.data.data == NULL) { - return NT_STATUS_NO_MEMORY; + status = smb2_pull_o16s32_blob(&req->in, mem_ctx, req->in.body+0x02, &io->out.data); + if (!NT_STATUS_IS_OK(status)) { + smb2_request_destroy(req); + return status; } + io->out.unknown1 = BVAL(req->in.body, 0x08); + return smb2_request_destroy(req); } -- 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/read.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/smb2/read.c') diff --git a/source4/libcli/smb2/read.c b/source4/libcli/smb2/read.c index f598a78cba..8709aa6ce2 100644 --- a/source4/libcli/smb2/read.c +++ b/source4/libcli/smb2/read.c @@ -35,7 +35,7 @@ struct smb2_request *smb2_read_send(struct smb2_tree *tree, struct smb2_read *io req = smb2_request_init_tree(tree, SMB2_OP_READ, 0x31, 0); if (req == NULL) return NULL; - SSVAL(req->out.body, 0x02, io->in._pad); + SSVAL(req->out.body, 0x02, 0); /* pad */ SIVAL(req->out.body, 0x04, io->in.length); SBVAL(req->out.body, 0x08, io->in.offset); smb2_push_handle(req->out.body+0x10, &io->in.handle); -- cgit From d4de4c2d210d2e8c9b5aedf70695594809ad6a0b Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 30 Dec 2005 13:16:54 +0000 Subject: r12608: Remove some unused #include lines. (This used to be commit 70e7449318aa0e9d2639c76730a7d1683b2f4981) --- source4/libcli/smb2/read.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source4/libcli/smb2/read.c') diff --git a/source4/libcli/smb2/read.c b/source4/libcli/smb2/read.c index 8709aa6ce2..da2d3bb7c9 100644 --- a/source4/libcli/smb2/read.c +++ b/source4/libcli/smb2/read.c @@ -21,7 +21,6 @@ */ #include "includes.h" -#include "libcli/raw/libcliraw.h" #include "libcli/smb2/smb2.h" #include "libcli/smb2/smb2_calls.h" -- 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/read.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/smb2/read.c') diff --git a/source4/libcli/smb2/read.c b/source4/libcli/smb2/read.c index da2d3bb7c9..82e9b13280 100644 --- a/source4/libcli/smb2/read.c +++ b/source4/libcli/smb2/read.c @@ -31,7 +31,7 @@ struct smb2_request *smb2_read_send(struct smb2_tree *tree, struct smb2_read *io { struct smb2_request *req; - req = smb2_request_init_tree(tree, SMB2_OP_READ, 0x31, 0); + req = smb2_request_init_tree(tree, SMB2_OP_READ, 0x31, False, 0); if (req == NULL) return NULL; SSVAL(req->out.body, 0x02, 0); /* pad */ -- cgit From e306c5bf129a981693bd251d45597f1e584ee850 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sat, 20 May 2006 10:46:38 +0000 Subject: r15741: move smb2 request structures into the main smb request structs as new levels metze (This used to be commit 91806353174704857dfcc15a730af7232cfde660) --- source4/libcli/smb2/read.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/smb2/read.c') diff --git a/source4/libcli/smb2/read.c b/source4/libcli/smb2/read.c index 82e9b13280..6806adb8f6 100644 --- a/source4/libcli/smb2/read.c +++ b/source4/libcli/smb2/read.c @@ -37,7 +37,7 @@ struct smb2_request *smb2_read_send(struct smb2_tree *tree, struct smb2_read *io SSVAL(req->out.body, 0x02, 0); /* pad */ SIVAL(req->out.body, 0x04, io->in.length); SBVAL(req->out.body, 0x08, io->in.offset); - smb2_push_handle(req->out.body+0x10, &io->in.handle); + smb2_push_handle(req->out.body+0x10, &io->in.file.handle); SBVAL(req->out.body, 0x20, io->in.unknown1); SBVAL(req->out.body, 0x28, io->in.unknown2); SCVAL(req->out.body, 0x30, io->in._bug); -- cgit From d63dd113ae2c7f4f6d64def00a488548e805bc7e Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 29 Jun 2006 22:16:58 +0000 Subject: r16699: the layout of SMB2 Read and Write is identical... so we know that the 9th bytes is just uninitialized padding metze (This used to be commit f97a21b970ed23973cced2c67b5bc9ecd7afee88) --- source4/libcli/smb2/read.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source4/libcli/smb2/read.c') diff --git a/source4/libcli/smb2/read.c b/source4/libcli/smb2/read.c index 6806adb8f6..eb935fb4f1 100644 --- a/source4/libcli/smb2/read.c +++ b/source4/libcli/smb2/read.c @@ -31,7 +31,7 @@ struct smb2_request *smb2_read_send(struct smb2_tree *tree, struct smb2_read *io { struct smb2_request *req; - req = smb2_request_init_tree(tree, SMB2_OP_READ, 0x31, False, 0); + req = smb2_request_init_tree(tree, SMB2_OP_READ, 0x30, True, 0); if (req == NULL) return NULL; SSVAL(req->out.body, 0x02, 0); /* pad */ @@ -40,7 +40,6 @@ struct smb2_request *smb2_read_send(struct smb2_tree *tree, struct smb2_read *io smb2_push_handle(req->out.body+0x10, &io->in.file.handle); SBVAL(req->out.body, 0x20, io->in.unknown1); SBVAL(req->out.body, 0x28, io->in.unknown2); - SCVAL(req->out.body, 0x30, io->in._bug); smb2_transport_send(req); -- cgit From 19f9b91d288c781e71539804467c9c9726e1060d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 20 Sep 2006 16:33:25 +0000 Subject: r18715: 0x8 style status returns should also fail here (thanks metze) (This used to be commit f55de25ab30f9270bbd139dc1e683101db1069c8) --- source4/libcli/smb2/read.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/smb2/read.c') diff --git a/source4/libcli/smb2/read.c b/source4/libcli/smb2/read.c index eb935fb4f1..272bc82882 100644 --- a/source4/libcli/smb2/read.c +++ b/source4/libcli/smb2/read.c @@ -56,7 +56,7 @@ NTSTATUS smb2_read_recv(struct smb2_request *req, NTSTATUS status; if (!smb2_request_receive(req) || - smb2_request_is_error(req)) { + !smb2_request_is_ok(req)) { return smb2_request_destroy(req); } -- 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/read.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/libcli/smb2/read.c') diff --git a/source4/libcli/smb2/read.c b/source4/libcli/smb2/read.c index 272bc82882..f78a1a8b0e 100644 --- a/source4/libcli/smb2/read.c +++ b/source4/libcli/smb2/read.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/read.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/libcli/smb2/read.c') diff --git a/source4/libcli/smb2/read.c b/source4/libcli/smb2/read.c index f78a1a8b0e..b61f918481 100644 --- a/source4/libcli/smb2/read.c +++ b/source4/libcli/smb2/read.c @@ -30,7 +30,7 @@ struct smb2_request *smb2_read_send(struct smb2_tree *tree, struct smb2_read *io { struct smb2_request *req; - req = smb2_request_init_tree(tree, SMB2_OP_READ, 0x30, True, 0); + req = smb2_request_init_tree(tree, SMB2_OP_READ, 0x30, true, 0); if (req == NULL) return NULL; SSVAL(req->out.body, 0x02, 0); /* pad */ @@ -59,7 +59,7 @@ NTSTATUS smb2_read_recv(struct smb2_request *req, return smb2_request_destroy(req); } - SMB2_CHECK_PACKET_RECV(req, 0x10, True); + SMB2_CHECK_PACKET_RECV(req, 0x10, true); status = smb2_pull_o16s32_blob(&req->in, mem_ctx, req->in.body+0x02, &io->out.data); if (!NT_STATUS_IS_OK(status)) { -- cgit From 275f32ae2df333c089343dd20fc4efee1bed2b7b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 14 Apr 2008 11:31:17 +0200 Subject: fill in unknown fields in SMB2 READ call (This used to be commit 9b686c138037f613da15168d0722786e00f023e5) --- source4/libcli/smb2/read.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'source4/libcli/smb2/read.c') diff --git a/source4/libcli/smb2/read.c b/source4/libcli/smb2/read.c index b61f918481..9d40e32a4d 100644 --- a/source4/libcli/smb2/read.c +++ b/source4/libcli/smb2/read.c @@ -33,12 +33,16 @@ struct smb2_request *smb2_read_send(struct smb2_tree *tree, struct smb2_read *io req = smb2_request_init_tree(tree, SMB2_OP_READ, 0x30, true, 0); if (req == NULL) return NULL; - SSVAL(req->out.body, 0x02, 0); /* pad */ + SCVAL(req->out.body, 0x02, 0); /* pad */ + SCVAL(req->out.body, 0x03, 0); /* reserved */ SIVAL(req->out.body, 0x04, io->in.length); SBVAL(req->out.body, 0x08, io->in.offset); smb2_push_handle(req->out.body+0x10, &io->in.file.handle); - SBVAL(req->out.body, 0x20, io->in.unknown1); - SBVAL(req->out.body, 0x28, io->in.unknown2); + SIVAL(req->out.body, 0x20, io->in.min_count); + SIVAL(req->out.body, 0x24, io->in.channel); + SIVAL(req->out.body, 0x28, io->in.remaining); + SSVAL(req->out.body, 0x2C, io->in.channel_offset); + SSVAL(req->out.body, 0x2E, io->in.channel_length); smb2_transport_send(req); @@ -67,7 +71,8 @@ NTSTATUS smb2_read_recv(struct smb2_request *req, return status; } - io->out.unknown1 = BVAL(req->in.body, 0x08); + io->out.remaining = IVAL(req->in.body, 0x08); + io->out.reserved = IVAL(req->in.body, 0x0C); return smb2_request_destroy(req); } -- cgit