2 Unix SMB/CIFS implementation.
3 SMB parameters and setup
5 Copyright (C) Andrew Tridgell 2002-2004
6 Copyright (C) James Myers 2003 <myersjj@samba.org>
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.
24 #include "librpc/gen_ndr/ndr_nbt.h"
26 struct smbcli_tree; /* forward declare */
27 struct smbcli_request; /* forward declare */
28 struct smbcli_session; /* forward declare */
29 struct smbcli_transport; /* forward declare */
31 /* default timeout for all smb requests */
32 #define SMB_REQUEST_TIMEOUT 60
34 /* context that will be and has been negotiated between the client and server */
35 struct smbcli_negotiate {
37 * negotiated maximum transmit size - this is given to us by the server
41 /* maximum number of requests that can be multiplexed */
44 /* the negotiatiated protocol */
45 enum protocol_types protocol;
47 uint8_t sec_mode; /* security mode returned by negprot */
49 DATA_BLOB server_guid; /* server_guid */
50 DATA_BLOB secblob; /* cryptkey or negTokenInit blob */
53 struct smb_signing_context sign_info;
55 /* capabilities that the server reported */
56 uint32_t capabilities;
60 uint_t readbraw_supported:1;
61 uint_t writebraw_supported:1;
66 /* this is the context for a SMB socket associated with the socket itself */
67 struct smbcli_socket {
68 struct socket_context *sock;
70 /* what port we ended up connected to */
73 /* the hostname we connected to */
76 /* the event handle for waiting for socket IO */
78 struct event_context *ctx;
80 struct timed_event *te;
85 this structure allows applications to control the behaviour of the
88 struct smbcli_options {
90 uint_t use_level2_oplocks:1;
97 /* this is the context for the client transport layer */
98 struct smbcli_transport {
99 /* socket level info */
100 struct smbcli_socket *socket;
102 /* the next mid to be allocated - needed for signing and
106 /* negotiated protocol information */
107 struct smbcli_negotiate negotiate;
109 /* options to control the behaviour of the client code */
110 struct smbcli_options options;
112 /* is a readbraw pending? we need to handle that case
113 specially on receiving packets */
114 uint_t readbraw_pending:1;
116 /* an idle function - if this is defined then it will be
117 called once every period microseconds while we are waiting
120 void (*func)(struct smbcli_transport *, void *);
125 /* the error fields from the last message */
127 enum {ETYPE_NONE, ETYPE_SMB, ETYPE_SOCKET, ETYPE_NBT} etype;
130 enum {SOCKET_READ_TIMEOUT,
134 SOCKET_READ_BAD_SIG} socket_error;
140 /* a oplock break request handler */
141 BOOL (*handler)(struct smbcli_transport *transport,
142 uint16_t tid, uint16_t fnum, uint8_t level, void *private);
143 /* private data passed to the oplock handler */
147 /* a list of async requests that are pending for send on this connection */
148 struct smbcli_request *pending_send;
150 /* a list of async requests that are pending for receive on this connection */
151 struct smbcli_request *pending_recv;
153 /* remember the called name - some sub-protocols require us to
154 know the server name */
155 struct nbt_name called;
157 /* a buffer for partially received SMB packets. */
159 uint8_t header[NBT_HDR_SIZE];
166 /* this is the context for the user */
168 /* this is the context for the session layer */
169 struct smbcli_session {
170 /* transport layer info */
171 struct smbcli_transport *transport;
173 /* after a session setup the server provides us with
174 a vuid identifying the security context */
177 /* default pid for this session */
180 /* the flags2 for each packet - this allows
181 the user to control these for torture testing */
184 DATA_BLOB user_session_key;
186 /* the spnego context if we use extented security */
187 struct gensec_security *gensec;
191 smbcli_tree context: internal state for a tree connection.
194 /* session layer info */
195 struct smbcli_session *session;
197 uint16_t tid; /* tree id, aka cnum */
204 a client request moves between the following 4 states.
206 enum smbcli_request_state {SMBCLI_REQUEST_INIT, /* we are creating the request */
207 SMBCLI_REQUEST_SEND, /* the request is in the outgoing socket Q */
208 SMBCLI_REQUEST_RECV, /* we are waiting for a matching reply */
209 SMBCLI_REQUEST_DONE, /* the request is finished */
210 SMBCLI_REQUEST_ERROR}; /* a packet or transport level error has occurred */
212 /* the context for a single SMB request. This is passed to any request-context
213 * functions (similar to context.h, the server version).
214 * This will allow requests to be multi-threaded. */
215 struct smbcli_request {
216 /* allow a request to be part of a list of requests */
217 struct smbcli_request *next, *prev;
219 /* each request is in one of 4 possible states */
220 enum smbcli_request_state state;
222 /* a request always has a transport context, nearly always has
223 a session context and usually has a tree context */
224 struct smbcli_transport *transport;
225 struct smbcli_session *session;
226 struct smbcli_tree *tree;
228 /* the flags2 from the SMB request, in raw form (host byte
229 order). Used to parse strings */
232 /* the NT status for this request. Set by packet receive code
233 or code detecting error. */
236 /* the sequence number of this packet - used for signing */
239 /* set if this is a one-way request, meaning we are not
240 expecting a reply from the server. */
241 uint_t one_way_request:1;
243 /* set this when the request should only increment the signing
245 uint_t sign_single_increment:1;
247 /* the mid of this packet - used to match replies */
250 struct request_buffer in;
251 struct request_buffer out;
253 /* information on what to do with a reply when it is received
254 asyncronously. If this is not setup when a reply is received then
255 the reply is discarded
257 The private pointer is private to the caller of the client
258 library (the application), not private to the library
261 void (*fn)(struct smbcli_request *);
266 /* useful way of catching wct errors with file and line number */
267 #define SMBCLI_CHECK_MIN_WCT(req, wcount) if ((req)->in.wct < (wcount)) { \
268 DEBUG(1,("Unexpected WCT %d at %s(%d) - expected min %d\n", (req)->in.wct, __FILE__, __LINE__, wcount)); \
269 req->status = NT_STATUS_INVALID_PARAMETER; \
273 #define SMBCLI_CHECK_WCT(req, wcount) if ((req)->in.wct != (wcount)) { \
274 DEBUG(1,("Unexpected WCT %d at %s(%d) - expected %d\n", (req)->in.wct, __FILE__, __LINE__, wcount)); \
275 req->status = NT_STATUS_INVALID_PARAMETER; \