2 Unix SMB/CIFS implementation.
3 SMB parameters and setup
4 Copyright (C) Andrew Tridgell 1992-1998
5 Copyright (C) Luke Kenneth Casson Leighton 1996-1998
6 Copyright (C) Jeremy Allison 1998
7 Copyright (C) James Myers 2003 <myersjj@samba.org>
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 struct smbcli_tree; /* forward declare */
25 struct smbcli_request; /* forward declare */
26 struct smbcli_session; /* forward declare */
27 struct smbcli_transport; /* forward declare */
29 /* context that will be and has been negotiated between the client and server */
30 struct smbcli_negotiate {
32 * negotiated maximum transmit size - this is given to us by the server
36 /* maximum number of requests that can be multiplexed */
39 /* the negotiatiated protocol */
40 enum protocol_types protocol;
42 uint8_t sec_mode; /* security mode returned by negprot */
44 DATA_BLOB server_guid; /* server_guid */
45 DATA_BLOB secblob; /* cryptkey or negTokenInit blob */
48 struct smb_signing_context sign_info;
50 /* capabilities that the server reported */
51 uint32_t capabilities;
55 uint_t readbraw_supported:1;
56 uint_t writebraw_supported:1;
61 /* this is the context for a SMB socket associated with the socket itself */
62 struct smbcli_socket {
63 struct ipv4_addr dest_ip;
64 /* dest hostname (which may or may not be a DNS name) */
70 struct socket_context *sock;
72 /* a count of the number of packets we have received. We
73 * actually only care about zero/non-zero at this stage */
76 /* the network address of the client */
79 /* timeout for socket operations in milliseconds. */
84 this structure allows applications to control the behaviour of the
87 struct smbcli_options {
89 uint_t use_level2_oplocks:1;
95 /* this is the context for the client transport layer */
96 struct smbcli_transport {
97 /* socket level info */
98 struct smbcli_socket *socket;
100 /* the next mid to be allocated - needed for signing and
104 /* negotiated protocol information */
105 struct smbcli_negotiate negotiate;
107 /* options to control the behaviour of the client code */
108 struct smbcli_options options;
110 /* is a readbraw pending? we need to handle that case
111 specially on receiving packets */
112 uint_t readbraw_pending:1;
114 /* an idle function - if this is defined then it will be
115 called once every period seconds while we are waiting
118 void (*func)(struct smbcli_transport *, void *);
123 /* the error fields from the last message */
125 enum {ETYPE_NONE, ETYPE_DOS, ETYPE_NT, ETYPE_SOCKET, ETYPE_NBT} etype;
132 enum {SOCKET_READ_TIMEOUT,
136 SOCKET_READ_BAD_SIG} socket_error;
142 /* a oplock break request handler */
143 BOOL (*handler)(struct smbcli_transport *transport,
144 uint16_t tid, uint16_t fnum, uint8_t level, void *private);
145 /* private data passed to the oplock handler */
149 /* a list of async requests that are pending for send on this connection */
150 struct smbcli_request *pending_send;
152 /* a list of async requests that are pending for receive on this connection */
153 struct smbcli_request *pending_recv;
155 /* remember the called name - some sub-protocols require us to
156 know the server name */
157 struct nmb_name called;
159 /* a buffer for partially received SMB packets. */
161 uint8_t header[NBT_HDR_SIZE];
167 /* the event handle for waiting for socket IO */
169 struct event_context *ctx;
170 struct fd_event *fde;
171 struct timed_event *te;
175 /* this is the context for the user */
177 /* this is the context for the session layer */
178 struct smbcli_session {
179 /* transport layer info */
180 struct smbcli_transport *transport;
182 /* after a session setup the server provides us with
183 a vuid identifying the security context */
186 /* default pid for this session */
189 /* the flags2 for each packet - this allows
190 the user to control these for torture testing */
193 DATA_BLOB user_session_key;
195 /* the spnego context if we use extented security */
196 struct gensec_security *gensec;
200 smbcli_tree context: internal state for a tree connection.
203 /* session layer info */
204 struct smbcli_session *session;
206 uint16_t tid; /* tree id, aka cnum */
213 a client request moves between the following 4 states.
215 enum smbcli_request_state {SMBCLI_REQUEST_INIT, /* we are creating the request */
216 SMBCLI_REQUEST_SEND, /* the request is in the outgoing socket Q */
217 SMBCLI_REQUEST_RECV, /* we are waiting for a matching reply */
218 SMBCLI_REQUEST_DONE, /* the request is finished */
219 SMBCLI_REQUEST_ERROR}; /* a packet or transport level error has occurred */
221 /* the context for a single SMB request. This is passed to any request-context
222 * functions (similar to context.h, the server version).
223 * This will allow requests to be multi-threaded. */
224 struct smbcli_request {
225 /* allow a request to be part of a list of requests */
226 struct smbcli_request *next, *prev;
228 /* each request is in one of 4 possible states */
229 enum smbcli_request_state state;
231 /* a request always has a transport context, nearly always has
232 a session context and usually has a tree context */
233 struct smbcli_transport *transport;
234 struct smbcli_session *session;
235 struct smbcli_tree *tree;
237 /* the flags2 from the SMB request, in raw form (host byte
238 order). Used to parse strings */
241 /* the NT status for this request. Set by packet receive code
242 or code detecting error. */
245 /* the sequence number of this packet - used for signing */
248 /* set if this is a one-way request, meaning we are not
249 expecting a reply from the server. */
250 uint_t one_way_request:1;
252 /* set this when the request should only increment the signing
254 uint_t sign_single_increment:1;
256 /* the mid of this packet - used to match replies */
259 struct request_buffer in;
260 struct request_buffer out;
262 /* information on what to do with a reply when it is received
263 asyncronously. If this is not setup when a reply is received then
264 the reply is discarded
266 The private pointer is private to the caller of the client
267 library (the application), not private to the library
270 void (*fn)(struct smbcli_request *);
275 /* useful way of catching wct errors with file and line number */
276 #define SMBCLI_CHECK_MIN_WCT(req, wcount) if ((req)->in.wct < (wcount)) { \
277 DEBUG(1,("Unexpected WCT %d at %s(%d) - expected min %d\n", (req)->in.wct, __FILE__, __LINE__, wcount)); \
278 req->status = NT_STATUS_INVALID_PARAMETER; \
282 #define SMBCLI_CHECK_WCT(req, wcount) if ((req)->in.wct != (wcount)) { \
283 DEBUG(1,("Unexpected WCT %d at %s(%d) - expected %d\n", (req)->in.wct, __FILE__, __LINE__, wcount)); \
284 req->status = NT_STATUS_INVALID_PARAMETER; \