r22522: Print why we can't find these entries.
[Samba.git] / source / libcli / smb2 / smb2.h
blob586acaccf608de7ef60482df329889b0e6eebd86
1 /*
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.
23 struct smb2_options {
24 uint32_t timeout;
28 information returned from the negotiate response
30 struct smb2_negotiate {
31 DATA_BLOB secblob;
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 */
43 uint64_t seqnum;
45 /* a list of requests that are pending for receive on this
46 connection */
47 struct smb2_request *pending_recv;
49 /* context of the stream -> packet parser */
50 struct packet_context *packet;
52 /* an idle function - if this is defined then it will be
53 called once every period microseconds while we are waiting
54 for a packet */
55 struct {
56 void (*func)(struct smb2_transport *, void *);
57 void *private;
58 uint_t period;
59 } idle;
64 SMB2 tree context
66 struct smb2_tree {
67 struct smb2_session *session;
68 uint32_t tid;
72 SMB2 session context
74 struct smb2_session {
75 struct smb2_transport *transport;
76 struct gensec_security *gensec;
77 uint64_t uid;
78 DATA_BLOB session_key;
82 struct smb2_request_buffer {
83 /* the raw SMB2 buffer, including the 4 byte length header */
84 uint8_t *buffer;
86 /* the size of the raw buffer, including 4 byte header */
87 size_t size;
89 /* how much has been allocated - on reply the buffer is over-allocated to
90 prevent too many realloc() calls
92 size_t allocated;
94 /* the start of the SMB2 header - this is always buffer+4 */
95 uint8_t *hdr;
97 /* the packet body */
98 uint8_t *body;
99 size_t body_fixed;
100 size_t body_size;
102 /* this point to the next dynamic byte that can be used
103 * this will be moved when some dynamic data is pushed
105 uint8_t *dynamic;
110 a client request moves between the following 4 states.
112 enum smb2_request_state {SMB2_REQUEST_INIT, /* we are creating the request */
113 SMB2_REQUEST_RECV, /* we are waiting for a matching reply */
114 SMB2_REQUEST_DONE, /* the request is finished */
115 SMB2_REQUEST_ERROR}; /* a packet or transport level error has occurred */
117 /* the context for a single SMB2 request */
118 struct smb2_request {
119 /* allow a request to be part of a list of requests */
120 struct smb2_request *next, *prev;
122 /* each request is in one of 3 possible states */
123 enum smb2_request_state state;
125 struct smb2_transport *transport;
126 struct smb2_session *session;
127 struct smb2_tree *tree;
129 uint64_t seqnum;
131 struct {
132 BOOL do_cancel;
133 BOOL can_cancel;
134 uint32_t pending_id;
135 } cancel;
137 /* the NT status for this request. Set by packet receive code
138 or code detecting error. */
139 NTSTATUS status;
141 struct smb2_request_buffer in;
142 struct smb2_request_buffer out;
144 /* information on what to do with a reply when it is received
145 asyncronously. If this is not setup when a reply is received then
146 the reply is discarded
148 The private pointer is private to the caller of the client
149 library (the application), not private to the library
151 struct {
152 void (*fn)(struct smb2_request *);
153 void *private;
154 } async;
158 #define SMB2_MIN_SIZE 0x42
160 /* offsets into header elements */
161 #define SMB2_HDR_LENGTH 0x04
162 #define SMB2_HDR_PAD1 0x06
163 #define SMB2_HDR_STATUS 0x08
164 #define SMB2_HDR_OPCODE 0x0c
165 #define SMB2_HDR_UNKNOWN1 0x0e
166 #define SMB2_HDR_FLAGS 0x10
167 #define SMB2_HDR_UNKNOWN2 0x14
168 #define SMB2_HDR_SEQNUM 0x18
169 #define SMB2_HDR_PID 0x20
170 #define SMB2_HDR_TID 0x24
171 #define SMB2_HDR_UID 0x28 /* 64 bit */
172 #define SMB2_HDR_SIG 0x30 /* guess ... */
173 #define SMB2_HDR_BODY 0x40
175 /* SMB2 opcodes */
176 #define SMB2_OP_NEGPROT 0x00
177 #define SMB2_OP_SESSSETUP 0x01
178 #define SMB2_OP_LOGOFF 0x02
179 #define SMB2_OP_TCON 0x03
180 #define SMB2_OP_TDIS 0x04
181 #define SMB2_OP_CREATE 0x05
182 #define SMB2_OP_CLOSE 0x06
183 #define SMB2_OP_FLUSH 0x07
184 #define SMB2_OP_READ 0x08
185 #define SMB2_OP_WRITE 0x09
186 #define SMB2_OP_LOCK 0x0a
187 #define SMB2_OP_IOCTL 0x0b
188 #define SMB2_OP_CANCEL 0x0c
189 #define SMB2_OP_KEEPALIVE 0x0d
190 #define SMB2_OP_FIND 0x0e
191 #define SMB2_OP_NOTIFY 0x0f
192 #define SMB2_OP_GETINFO 0x10
193 #define SMB2_OP_SETINFO 0x11
194 #define SMB2_OP_BREAK 0x12
196 #define SMB2_MAGIC 0x424D53FE /* 0xFE 'S' 'M' 'B' */
199 check that a body has the expected size
201 #define SMB2_CHECK_PACKET_RECV(req, size, dynamic) do { \
202 size_t is_size = req->in.body_size; \
203 uint16_t field_size = SVAL(req->in.body, 0); \
204 uint16_t want_size = ((dynamic)?(size)+1:(size)); \
205 if (is_size < (size)) { \
206 DEBUG(0,("%s: buffer too small 0x%x. Expected 0x%x\n", \
207 __location__, (unsigned)is_size, (unsigned)want_size)); \
208 return NT_STATUS_BUFFER_TOO_SMALL; \
210 if (field_size != want_size) { \
211 DEBUG(0,("%s: unexpected fixed body size 0x%x. Expected 0x%x\n", \
212 __location__, (unsigned)field_size, (unsigned)want_size)); \
213 return NT_STATUS_INVALID_PARAMETER; \
215 } while (0)