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 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/>.
22 #ifndef __LIBCLI_RAW_H__
23 #define __LIBCLI_RAW_H__
25 #include "libcli/raw/request.h"
26 #include "librpc/gen_ndr/nbt.h"
28 struct smbcli_tree
; /* forward declare */
29 struct smbcli_request
; /* forward declare */
30 struct smbcli_session
; /* forward declare */
31 struct smbcli_transport
; /* forward declare */
33 struct resolve_context
;
34 struct cli_credentials
;
35 struct gensec_settings
;
37 /* default timeout for all smb requests */
38 #define SMB_REQUEST_TIMEOUT 60
40 /* context that will be and has been negotiated between the client and server */
41 struct smbcli_negotiate
{
43 * negotiated maximum transmit size - this is given to us by the server
47 /* maximum number of requests that can be multiplexed */
50 /* the negotiatiated protocol */
51 enum protocol_types protocol
;
53 uint8_t sec_mode
; /* security mode returned by negprot */
55 DATA_BLOB server_guid
; /* server_guid */
56 DATA_BLOB secblob
; /* cryptkey or negTokenInit blob */
59 struct smb_signing_context sign_info
;
61 /* capabilities that the server reported */
62 uint32_t capabilities
;
66 uint_t readbraw_supported
:1;
67 uint_t writebraw_supported
:1;
72 /* this is the context for a SMB socket associated with the socket itself */
73 struct smbcli_socket
{
74 struct socket_context
*sock
;
76 /* what port we ended up connected to */
79 /* the hostname we connected to */
82 /* the event handle for waiting for socket IO */
84 struct tevent_context
*ctx
;
85 struct tevent_fd
*fde
;
86 struct tevent_timer
*te
;
91 this structure allows applications to control the behaviour of the
94 struct smbcli_options
{
96 uint_t use_level2_oplocks
:1;
99 uint_t ntstatus_support
:1;
104 enum smb_signing_state signing
;
107 /* this is the context for the client transport layer */
108 struct smbcli_transport
{
109 /* socket level info */
110 struct smbcli_socket
*socket
;
112 /* the next mid to be allocated - needed for signing and
116 /* negotiated protocol information */
117 struct smbcli_negotiate negotiate
;
119 /* options to control the behaviour of the client code */
120 struct smbcli_options options
;
122 /* is a readbraw pending? we need to handle that case
123 specially on receiving packets */
124 uint_t readbraw_pending
:1;
126 /* an idle function - if this is defined then it will be
127 called once every period microseconds while we are waiting
130 void (*func
)(struct smbcli_transport
*, void *);
135 /* the error fields from the last message */
137 enum {ETYPE_NONE
, ETYPE_SMB
, ETYPE_SOCKET
, ETYPE_NBT
} etype
;
140 enum {SOCKET_READ_TIMEOUT
,
144 SOCKET_READ_BAD_SIG
} socket_error
;
150 /* a oplock break request handler */
151 bool (*handler
)(struct smbcli_transport
*transport
,
152 uint16_t tid
, uint16_t fnum
, uint8_t level
, void *private_data
);
153 /* private data passed to the oplock handler */
157 /* a list of async requests that are pending for receive on this connection */
158 struct smbcli_request
*pending_recv
;
160 /* remember the called name - some sub-protocols require us to
161 know the server name */
162 struct nbt_name called
;
164 /* context of the stream -> packet parser */
165 struct packet_context
*packet
;
167 /* iconv convenience */
168 struct smb_iconv_convenience
*iconv_convenience
;
171 /* this is the context for the user */
173 /* this is the context for the session layer */
174 struct smbcli_session
{
175 /* transport layer info */
176 struct smbcli_transport
*transport
;
178 /* after a session setup the server provides us with
179 a vuid identifying the security context */
182 /* default pid for this session */
185 /* the flags2 for each packet - this allows
186 the user to control these for torture testing */
189 DATA_BLOB user_session_key
;
191 /* the spnego context if we use extented security */
192 struct gensec_security
*gensec
;
194 struct smbcli_session_options
{
195 uint_t lanman_auth
:1;
196 uint_t ntlmv2_auth
:1;
197 uint_t plaintext_auth
:1;
202 smbcli_tree context: internal state for a tree connection.
205 /* session layer info */
206 struct smbcli_session
*session
;
208 uint16_t tid
; /* tree id, aka cnum */
215 a client request moves between the following 4 states.
217 enum smbcli_request_state
{SMBCLI_REQUEST_INIT
, /* we are creating the request */
218 SMBCLI_REQUEST_RECV
, /* we are waiting for a matching reply */
219 SMBCLI_REQUEST_DONE
, /* the request is finished */
220 SMBCLI_REQUEST_ERROR
}; /* a packet or transport level error has occurred */
222 /* the context for a single SMB request. This is passed to any request-context
223 * functions (similar to context.h, the server version).
224 * This will allow requests to be multi-threaded. */
225 struct smbcli_request
{
226 /* allow a request to be part of a list of requests */
227 struct smbcli_request
*next
, *prev
;
229 /* each request is in one of 4 possible states */
230 enum smbcli_request_state state
;
232 /* a request always has a transport context, nearly always has
233 a session context and usually has a tree context */
234 struct smbcli_transport
*transport
;
235 struct smbcli_session
*session
;
236 struct smbcli_tree
*tree
;
238 /* a receive helper, smbcli_transport_finish_recv will not call
239 req->async.fn callback handler unless the recv_helper returns
240 a value > SMBCLI_REQUEST_RECV. */
242 enum smbcli_request_state (*fn
)(struct smbcli_request
*);
246 /* the flags2 from the SMB request, in raw form (host byte
247 order). Used to parse strings */
250 /* the NT status for this request. Set by packet receive code
251 or code detecting error. */
254 /* the sequence number of this packet - used for signing */
257 /* list of ntcancel request for this requests */
258 struct smbcli_request
*ntcancel
;
260 /* set if this is a one-way request, meaning we are not
261 expecting a reply from the server. */
262 uint_t one_way_request
:1;
264 /* set this when the request should only increment the signing
266 uint_t sign_single_increment
:1;
268 /* the caller wants to do the signing check */
269 bool sign_caller_checks
;
271 /* give the caller a chance to prevent the talloc_free() in the _recv() function */
274 /* the mid of this packet - used to match replies */
277 struct smb_request_buffer in
;
278 struct smb_request_buffer out
;
280 /* information on what to do with a reply when it is received
281 asyncronously. If this is not setup when a reply is received then
282 the reply is discarded
284 The private pointer is private to the caller of the client
285 library (the application), not private to the library
288 void (*fn
)(struct smbcli_request
*);
293 /* useful way of catching wct errors with file and line number */
294 #define SMBCLI_CHECK_MIN_WCT(req, wcount) if ((req)->in.wct < (wcount)) { \
295 DEBUG(1,("Unexpected WCT %d at %s(%d) - expected min %d\n", (req)->in.wct, __FILE__, __LINE__, wcount)); \
296 req->status = NT_STATUS_INVALID_PARAMETER; \
300 #define SMBCLI_CHECK_WCT(req, wcount) if ((req)->in.wct != (wcount)) { \
301 DEBUG(1,("Unexpected WCT %d at %s(%d) - expected %d\n", (req)->in.wct, __FILE__, __LINE__, wcount)); \
302 req->status = NT_STATUS_INVALID_PARAMETER; \
306 #include "libcli/raw/interfaces.h"
308 NTSTATUS
smb_raw_read_recv(struct smbcli_request
*req
, union smb_read
*parms
);
309 struct smbcli_request
*smb_raw_read_send(struct smbcli_tree
*tree
, union smb_read
*parms
);
310 NTSTATUS
smb_raw_trans_recv(struct smbcli_request
*req
,
312 struct smb_trans2
*parms
);
313 size_t smb_raw_max_trans_data(struct smbcli_tree
*tree
, size_t param_size
);
314 struct smbcli_request
*smb_raw_trans_send(struct smbcli_tree
*tree
, struct smb_trans2
*parms
);
315 NTSTATUS
smbcli_request_destroy(struct smbcli_request
*req
);
316 struct smbcli_request
*smb_raw_write_send(struct smbcli_tree
*tree
, union smb_write
*parms
);
317 struct smbcli_request
*smb_raw_close_send(struct smbcli_tree
*tree
, union smb_close
*parms
);
318 NTSTATUS
smb_raw_open_recv(struct smbcli_request
*req
, TALLOC_CTX
*mem_ctx
, union smb_open
*parms
);
319 struct smbcli_request
*smb_raw_open_send(struct smbcli_tree
*tree
, union smb_open
*parms
);
321 bool smbcli_transport_process(struct smbcli_transport
*transport
);
322 const char *smbcli_errstr(struct smbcli_tree
*tree
);
323 NTSTATUS
smb_raw_fsinfo(struct smbcli_tree
*tree
, TALLOC_CTX
*mem_ctx
, union smb_fsinfo
*fsinfo
);
324 NTSTATUS
smb_raw_pathinfo(struct smbcli_tree
*tree
, TALLOC_CTX
*mem_ctx
, union smb_fileinfo
*parms
);
325 NTSTATUS
smb_raw_shadow_data(struct smbcli_tree
*tree
, TALLOC_CTX
*mem_ctx
, struct smb_shadow_copy
*info
);
326 NTSTATUS
smb_raw_fileinfo(struct smbcli_tree
*tree
, TALLOC_CTX
*mem_ctx
, union smb_fileinfo
*parms
);
327 struct smbcli_tree
*smbcli_tree_init(struct smbcli_session
*session
, TALLOC_CTX
*parent_ctx
, bool primary
);
328 NTSTATUS
smb_raw_tcon(struct smbcli_tree
*tree
, TALLOC_CTX
*mem_ctx
, union smb_tcon
*parms
);
329 void smbcli_oplock_handler(struct smbcli_transport
*transport
,
330 bool (*handler
)(struct smbcli_transport
*, uint16_t, uint16_t, uint8_t, void *),
332 void smbcli_transport_idle_handler(struct smbcli_transport
*transport
,
333 void (*idle_func
)(struct smbcli_transport
*, void *),
336 NTSTATUS
smbcli_request_simple_recv(struct smbcli_request
*req
);
337 bool smbcli_oplock_ack(struct smbcli_tree
*tree
, uint16_t fnum
, uint16_t ack_level
);
338 NTSTATUS
smb_raw_open(struct smbcli_tree
*tree
, TALLOC_CTX
*mem_ctx
, union smb_open
*parms
);
339 NTSTATUS
smb_raw_close(struct smbcli_tree
*tree
, union smb_close
*parms
);
340 NTSTATUS
smb_raw_unlink(struct smbcli_tree
*tree
, union smb_unlink
*parms
);
341 NTSTATUS
smb_raw_chkpath(struct smbcli_tree
*tree
, union smb_chkpath
*parms
);
342 NTSTATUS
smb_raw_mkdir(struct smbcli_tree
*tree
, union smb_mkdir
*parms
);
343 NTSTATUS
smb_raw_rmdir(struct smbcli_tree
*tree
, struct smb_rmdir
*parms
);
344 NTSTATUS
smb_raw_rename(struct smbcli_tree
*tree
, union smb_rename
*parms
);
345 NTSTATUS
smb_raw_seek(struct smbcli_tree
*tree
, union smb_seek
*parms
);
346 NTSTATUS
smb_raw_read(struct smbcli_tree
*tree
, union smb_read
*parms
);
347 NTSTATUS
smb_raw_write(struct smbcli_tree
*tree
, union smb_write
*parms
);
348 NTSTATUS
smb_raw_lock(struct smbcli_tree
*tree
, union smb_lock
*parms
);
349 NTSTATUS
smb_raw_setpathinfo(struct smbcli_tree
*tree
, union smb_setfileinfo
*parms
);
350 NTSTATUS
smb_raw_setfileinfo(struct smbcli_tree
*tree
, union smb_setfileinfo
*parms
);
352 struct smbcli_request
*smb_raw_changenotify_send(struct smbcli_tree
*tree
, union smb_notify
*parms
);
353 NTSTATUS
smb_raw_changenotify_recv(struct smbcli_request
*req
, TALLOC_CTX
*mem_ctx
, union smb_notify
*parms
);
355 NTSTATUS
smb_tree_disconnect(struct smbcli_tree
*tree
);
356 NTSTATUS
smbcli_nt_error(struct smbcli_tree
*tree
);
357 NTSTATUS
smb_raw_exit(struct smbcli_session
*session
);
358 NTSTATUS
smb_raw_pathinfo_recv(struct smbcli_request
*req
,
360 union smb_fileinfo
*parms
);
361 struct smbcli_request
*smb_raw_pathinfo_send(struct smbcli_tree
*tree
,
362 union smb_fileinfo
*parms
);
363 struct smbcli_request
*smb_raw_setpathinfo_send(struct smbcli_tree
*tree
,
364 union smb_setfileinfo
*parms
);
365 struct smbcli_request
*smb_raw_echo_send(struct smbcli_transport
*transport
,
367 NTSTATUS
smb_raw_search_first(struct smbcli_tree
*tree
,
369 union smb_search_first
*io
, void *private_data
,
370 smbcli_search_callback callback
);
371 NTSTATUS
smb_raw_flush(struct smbcli_tree
*tree
, union smb_flush
*parms
);
373 NTSTATUS
smb_raw_trans(struct smbcli_tree
*tree
,
375 struct smb_trans2
*parms
);
377 struct smbcli_socket
*smbcli_sock_connect_byname(const char *host
, const char **ports
,
379 struct resolve_context
*resolve_ctx
,
380 struct tevent_context
*event_ctx
,
381 const char *socket_options
);
382 void smbcli_sock_dead(struct smbcli_socket
*sock
);
384 #endif /* __LIBCLI_RAW__H__ */