2 Unix SMB/CIFS implementation.
4 SMB2 client library header
6 Copyright (C) Andrew Tridgell 2005
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 information returned from the negotiate response
30 struct smb2_negotiate {
34 /* this is the context for the smb2 transport layer */
35 struct smb2_transport {
36 /* socket level info */
37 struct smbcli_socket *socket;
39 struct smb2_options options;
40 struct smb2_negotiate negotiate;
42 /* next seqnum to allocate */
45 /* a list of requests that are pending for receive on this
47 struct smb2_request *pending_recv;
49 /* context of the stream -> packet parser */
50 struct packet_context *packet;
58 struct smb2_session *session;
66 struct smb2_transport *transport;
67 struct gensec_security *gensec;
72 struct smb2_request_buffer {
73 /* the raw SMB2 buffer, including the 4 byte length header */
76 /* the size of the raw buffer, including 4 byte header */
79 /* how much has been allocated - on reply the buffer is over-allocated to
80 prevent too many realloc() calls
84 /* the start of the SMB2 header - this is always buffer+4 */
91 /* ptr is used as a moving pointer into the data area
92 * of the packet. The reason its here and not a local
93 * variable in each function is that when a realloc of
94 * a send packet is done we need to move this
101 a client request moves between the following 4 states.
103 enum smb2_request_state {SMB2_REQUEST_INIT, /* we are creating the request */
104 SMB2_REQUEST_RECV, /* we are waiting for a matching reply */
105 SMB2_REQUEST_DONE, /* the request is finished */
106 SMB2_REQUEST_ERROR}; /* a packet or transport level error has occurred */
108 /* the context for a single SMB2 request */
109 struct smb2_request {
110 /* allow a request to be part of a list of requests */
111 struct smb2_request *next, *prev;
113 /* each request is in one of 3 possible states */
114 enum smb2_request_state state;
116 struct smb2_transport *transport;
120 /* the NT status for this request. Set by packet receive code
121 or code detecting error. */
124 struct smb2_request_buffer in;
125 struct smb2_request_buffer out;
127 /* information on what to do with a reply when it is received
128 asyncronously. If this is not setup when a reply is received then
129 the reply is discarded
131 The private pointer is private to the caller of the client
132 library (the application), not private to the library
135 void (*fn)(struct smb2_request *);
141 #define SMB2_MIN_SIZE 0x40
143 /* offsets into header elements */
144 #define SMB2_HDR_LENGTH 0x04
145 #define SMB2_HDR_PAD1 0x06
146 #define SMB2_HDR_STATUS 0x08
147 #define SMB2_HDR_OPCODE 0x0c
148 #define SMB2_HDR_PAD2 0x0e
149 #define SMB2_HDR_FLAGS 0x10
150 #define SMB2_HDR_UNKNOWN 0x14
151 #define SMB2_HDR_SEQNUM 0x18
152 #define SMB2_HDR_PID 0x20
153 #define SMB2_HDR_TID 0x24
154 #define SMB2_HDR_UID 0x28 /* 64 bit */
155 #define SMB2_HDR_SIG 0x30 /* guess ... */
156 #define SMB2_HDR_BODY 0x40
159 #define SMB2_OP_NEGPROT 0x00
160 #define SMB2_OP_SESSSETUP 0x01
161 #define SMB2_OP_TCON 0x03
162 #define SMB2_OP_TDIS 0x04
163 #define SMB2_OP_CREATE 0x05
164 #define SMB2_OP_CLOSE 0x06
165 #define SMB2_OP_READ 0x08
166 #define SMB2_OP_WRITE 0x09
167 #define SMB2_OP_FIND 0x0e
169 #define SMB2_MAGIC 0x424D53FE /* 0xFE 'S' 'M' 'B' */
172 check that a buffer code matches the expected value
174 #define SMB2_CHECK_BUFFER_CODE(req, code) do { \
175 io->out.buffer_code = SVAL(req->in.body, 0); \
176 if (io->out.buffer_code != (code)) { \
177 DEBUG(0,("Unexpected buffer code 0x%x. Expected 0x%x\n", \
178 io->out.buffer_code, code)); \
179 return NT_STATUS_INVALID_PARAMETER; \