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 3 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, see <http://www.gnu.org/licenses/>.
27 information returned from the negotiate response
29 struct smb2_negotiate {
33 /* this is the context for the smb2 transport layer */
34 struct smb2_transport {
35 /* socket level info */
36 struct smbcli_socket *socket;
38 struct smb2_options options;
39 struct smb2_negotiate negotiate;
41 /* next seqnum to allocate */
44 /* a list of requests that are pending for receive on this
46 struct smb2_request *pending_recv;
48 /* context of the stream -> packet parser */
49 struct packet_context *packet;
51 /* an idle function - if this is defined then it will be
52 called once every period microseconds while we are waiting
55 void (*func)(struct smb2_transport *, void *);
66 struct smb2_session *session;
74 struct smb2_transport *transport;
75 struct gensec_security *gensec;
77 DATA_BLOB session_key;
81 struct smb2_request_buffer {
82 /* the raw SMB2 buffer, including the 4 byte length header */
85 /* the size of the raw buffer, including 4 byte header */
88 /* how much has been allocated - on reply the buffer is over-allocated to
89 prevent too many realloc() calls
93 /* the start of the SMB2 header - this is always buffer+4 */
101 /* this point to the next dynamic byte that can be used
102 * this will be moved when some dynamic data is pushed
109 a client request moves between the following 4 states.
111 enum smb2_request_state {SMB2_REQUEST_INIT, /* we are creating the request */
112 SMB2_REQUEST_RECV, /* we are waiting for a matching reply */
113 SMB2_REQUEST_DONE, /* the request is finished */
114 SMB2_REQUEST_ERROR}; /* a packet or transport level error has occurred */
116 /* the context for a single SMB2 request */
117 struct smb2_request {
118 /* allow a request to be part of a list of requests */
119 struct smb2_request *next, *prev;
121 /* each request is in one of 3 possible states */
122 enum smb2_request_state state;
124 struct smb2_transport *transport;
125 struct smb2_session *session;
126 struct smb2_tree *tree;
136 /* the NT status for this request. Set by packet receive code
137 or code detecting error. */
140 struct smb2_request_buffer in;
141 struct smb2_request_buffer out;
143 /* information on what to do with a reply when it is received
144 asyncronously. If this is not setup when a reply is received then
145 the reply is discarded
147 The private pointer is private to the caller of the client
148 library (the application), not private to the library
151 void (*fn)(struct smb2_request *);
157 #define SMB2_MIN_SIZE 0x42
159 /* offsets into header elements */
160 #define SMB2_HDR_LENGTH 0x04
161 #define SMB2_HDR_PAD1 0x06
162 #define SMB2_HDR_STATUS 0x08
163 #define SMB2_HDR_OPCODE 0x0c
164 #define SMB2_HDR_UNKNOWN1 0x0e
165 #define SMB2_HDR_FLAGS 0x10
166 #define SMB2_HDR_CHAIN_OFFSET 0x14
167 #define SMB2_HDR_SEQNUM 0x18
168 #define SMB2_HDR_PID 0x20
169 #define SMB2_HDR_TID 0x24
170 #define SMB2_HDR_UID 0x28 /* 64 bit */
171 #define SMB2_HDR_SIG 0x30 /* guess ... */
172 #define SMB2_HDR_BODY 0x40
175 #define SMB2_OP_NEGPROT 0x00
176 #define SMB2_OP_SESSSETUP 0x01
177 #define SMB2_OP_LOGOFF 0x02
178 #define SMB2_OP_TCON 0x03
179 #define SMB2_OP_TDIS 0x04
180 #define SMB2_OP_CREATE 0x05
181 #define SMB2_OP_CLOSE 0x06
182 #define SMB2_OP_FLUSH 0x07
183 #define SMB2_OP_READ 0x08
184 #define SMB2_OP_WRITE 0x09
185 #define SMB2_OP_LOCK 0x0a
186 #define SMB2_OP_IOCTL 0x0b
187 #define SMB2_OP_CANCEL 0x0c
188 #define SMB2_OP_KEEPALIVE 0x0d
189 #define SMB2_OP_FIND 0x0e
190 #define SMB2_OP_NOTIFY 0x0f
191 #define SMB2_OP_GETINFO 0x10
192 #define SMB2_OP_SETINFO 0x11
193 #define SMB2_OP_BREAK 0x12
195 #define SMB2_MAGIC 0x424D53FE /* 0xFE 'S' 'M' 'B' */
198 check that a body has the expected size
200 #define SMB2_CHECK_PACKET_RECV(req, size, dynamic) do { \
201 size_t is_size = req->in.body_size; \
202 uint16_t field_size = SVAL(req->in.body, 0); \
203 uint16_t want_size = ((dynamic)?(size)+1:(size)); \
204 if (is_size < (size)) { \
205 DEBUG(0,("%s: buffer too small 0x%x. Expected 0x%x\n", \
206 __location__, (unsigned)is_size, (unsigned)want_size)); \
207 return NT_STATUS_BUFFER_TOO_SMALL; \
209 if (field_size != want_size) { \
210 DEBUG(0,("%s: unexpected fixed body size 0x%x. Expected 0x%x\n", \
211 __location__, (unsigned)field_size, (unsigned)want_size)); \
212 return NT_STATUS_INVALID_PARAMETER; \