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/smb/smb_common.h"
26 #include "libcli/raw/request.h"
27 #include "librpc/gen_ndr/nbt.h"
29 struct smbcli_tree; /* forward declare */
30 struct smbcli_request; /* forward declare */
31 struct smbcli_session; /* forward declare */
32 struct smbcli_transport; /* forward declare */
34 struct resolve_context;
35 struct cli_credentials;
36 struct gensec_settings;
38 /* default timeout for all smb requests */
39 #define SMB_REQUEST_TIMEOUT 60
41 /* context that will be and has been negotiated between the client and server */
42 struct smbcli_negotiate {
44 * negotiated maximum transmit size - this is given to us by the server
48 /* maximum number of requests that can be multiplexed */
51 /* the negotiatiated protocol */
52 enum protocol_types protocol;
54 uint8_t sec_mode; /* security mode returned by negprot */
56 DATA_BLOB server_guid; /* server_guid */
57 DATA_BLOB secblob; /* cryptkey or negTokenInit blob */
60 struct smb_signing_context sign_info;
62 /* capabilities that the server reported */
63 uint32_t capabilities;
67 unsigned int readbraw_supported:1;
68 unsigned int writebraw_supported:1;
69 unsigned int lockread_supported:1;
74 /* this is the context for a SMB socket associated with the socket itself */
75 struct smbcli_socket {
76 struct socket_context *sock;
78 /* what port we ended up connected to */
81 /* the hostname we connected to */
84 /* the event handle for waiting for socket IO */
86 struct tevent_context *ctx;
87 struct tevent_fd *fde;
88 struct tevent_timer *te;
93 this structure allows applications to control the behaviour of the
96 struct smbcli_options {
97 unsigned int use_oplocks:1;
98 unsigned int use_level2_oplocks:1;
99 unsigned int use_spnego:1;
100 unsigned int unicode:1;
101 unsigned int ntstatus_support:1;
106 enum smb_signing_state signing;
109 /* this is the context for the client transport layer */
110 struct smbcli_transport {
111 /* socket level info */
112 struct smbcli_socket *socket;
114 /* the next mid to be allocated - needed for signing and
118 /* negotiated protocol information */
119 struct smbcli_negotiate negotiate;
121 /* options to control the behaviour of the client code */
122 struct smbcli_options options;
124 /* is a readbraw pending? we need to handle that case
125 specially on receiving packets */
126 unsigned int readbraw_pending:1;
128 /* an idle function - if this is defined then it will be
129 called once every period microseconds while we are waiting
132 void (*func)(struct smbcli_transport *, void *);
137 /* the error fields from the last message */
139 enum {ETYPE_NONE, ETYPE_SMB, ETYPE_SOCKET, ETYPE_NBT} etype;
142 enum {SOCKET_READ_TIMEOUT,
146 SOCKET_READ_BAD_SIG} socket_error;
147 unsigned int nbt_error;
152 /* a oplock break request handler */
153 bool (*handler)(struct smbcli_transport *transport,
154 uint16_t tid, uint16_t fnum, uint8_t level, void *private_data);
155 /* private data passed to the oplock handler */
159 /* a list of async requests that are pending for receive on this connection */
160 struct smbcli_request *pending_recv;
162 /* remember the called name - some sub-protocols require us to
163 know the server name */
164 struct nbt_name called;
166 /* context of the stream -> packet parser */
167 struct packet_context *packet;
170 /* this is the context for the user */
172 /* this is the context for the session layer */
173 struct smbcli_session {
174 /* transport layer info */
175 struct smbcli_transport *transport;
177 /* after a session setup the server provides us with
178 a vuid identifying the security context */
181 /* default pid for this session */
184 /* the flags2 for each packet - this allows
185 the user to control these for torture testing */
188 DATA_BLOB user_session_key;
190 /* the spnego context if we use extented security */
191 struct gensec_security *gensec;
193 struct smbcli_session_options {
194 unsigned int lanman_auth:1;
195 unsigned int ntlmv2_auth:1;
196 unsigned int plaintext_auth:1;
204 smbcli_tree context: internal state for a tree connection.
207 /* session layer info */
208 struct smbcli_session *session;
210 uint16_t tid; /* tree id, aka cnum */
217 a client request moves between the following 4 states.
219 enum smbcli_request_state {SMBCLI_REQUEST_INIT, /* we are creating the request */
220 SMBCLI_REQUEST_RECV, /* we are waiting for a matching reply */
221 SMBCLI_REQUEST_DONE, /* the request is finished */
222 SMBCLI_REQUEST_ERROR}; /* a packet or transport level error has occurred */
224 /* the context for a single SMB request. This is passed to any request-context
225 * functions (similar to context.h, the server version).
226 * This will allow requests to be multi-threaded. */
227 struct smbcli_request {
228 /* allow a request to be part of a list of requests */
229 struct smbcli_request *next, *prev;
231 /* each request is in one of 4 possible states */
232 enum smbcli_request_state state;
234 /* a request always has a transport context, nearly always has
235 a session context and usually has a tree context */
236 struct smbcli_transport *transport;
237 struct smbcli_session *session;
238 struct smbcli_tree *tree;
240 /* a receive helper, smbcli_transport_finish_recv will not call
241 req->async.fn callback handler unless the recv_helper returns
242 a value > SMBCLI_REQUEST_RECV. */
244 enum smbcli_request_state (*fn)(struct smbcli_request *);
248 /* the flags2 from the SMB request, in raw form (host byte
249 order). Used to parse strings */
252 /* the NT status for this request. Set by packet receive code
253 or code detecting error. */
256 /* the sequence number of this packet - used for signing */
257 unsigned int seq_num;
259 /* list of ntcancel request for this requests */
260 struct smbcli_request *ntcancel;
262 /* set if this is a one-way request, meaning we are not
263 expecting a reply from the server. */
264 unsigned int one_way_request:1;
266 /* set this when the request should only increment the signing
268 unsigned int sign_single_increment:1;
270 /* the caller wants to do the signing check */
271 bool sign_caller_checks;
273 /* give the caller a chance to prevent the talloc_free() in the _recv() function */
276 /* the mid of this packet - used to match replies */
279 struct smb_request_buffer in;
280 struct smb_request_buffer out;
282 /* information on what to do with a reply when it is received
283 asyncronously. If this is not setup when a reply is received then
284 the reply is discarded
286 The private pointer is private to the caller of the client
287 library (the application), not private to the library
290 void (*fn)(struct smbcli_request *);
295 /* useful way of catching wct errors with file and line number */
296 #define SMBCLI_CHECK_MIN_WCT(req, wcount) if ((req)->in.wct < (wcount)) { \
297 DEBUG(1,("Unexpected WCT %d at %s(%d) - expected min %d\n", (req)->in.wct, __FILE__, __LINE__, wcount)); \
298 req->status = NT_STATUS_INVALID_PARAMETER; \
302 #define SMBCLI_CHECK_WCT(req, wcount) if ((req)->in.wct != (wcount)) { \
303 DEBUG(1,("Unexpected WCT %d at %s(%d) - expected %d\n", (req)->in.wct, __FILE__, __LINE__, wcount)); \
304 req->status = NT_STATUS_INVALID_PARAMETER; \
308 #include "libcli/raw/interfaces.h"
310 NTSTATUS smb_raw_read_recv(struct smbcli_request *req, union smb_read *parms);
311 struct smbcli_request *smb_raw_read_send(struct smbcli_tree *tree, union smb_read *parms);
312 NTSTATUS smb_raw_trans_recv(struct smbcli_request *req,
314 struct smb_trans2 *parms);
315 size_t smb_raw_max_trans_data(struct smbcli_tree *tree, size_t param_size);
316 struct smbcli_request *smb_raw_trans_send(struct smbcli_tree *tree, struct smb_trans2 *parms);
317 NTSTATUS smbcli_request_destroy(struct smbcli_request *req);
318 struct smbcli_request *smb_raw_write_send(struct smbcli_tree *tree, union smb_write *parms);
319 struct smbcli_request *smb_raw_close_send(struct smbcli_tree *tree, union smb_close *parms);
320 NTSTATUS smb_raw_open_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, union smb_open *parms);
321 struct smbcli_request *smb_raw_open_send(struct smbcli_tree *tree, union smb_open *parms);
323 bool smbcli_transport_process(struct smbcli_transport *transport);
324 const char *smbcli_errstr(struct smbcli_tree *tree);
325 NTSTATUS smb_raw_fsinfo(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_fsinfo *fsinfo);
326 NTSTATUS smb_raw_pathinfo(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_fileinfo *parms);
327 NTSTATUS smb_raw_shadow_data(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, struct smb_shadow_copy *info);
328 NTSTATUS smb_raw_fileinfo(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_fileinfo *parms);
329 struct smbcli_tree *smbcli_tree_init(struct smbcli_session *session, TALLOC_CTX *parent_ctx, bool primary);
330 NTSTATUS smb_raw_tcon(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_tcon *parms);
331 void smbcli_oplock_handler(struct smbcli_transport *transport,
332 bool (*handler)(struct smbcli_transport *, uint16_t, uint16_t, uint8_t, void *),
334 void smbcli_transport_idle_handler(struct smbcli_transport *transport,
335 void (*idle_func)(struct smbcli_transport *, void *),
338 NTSTATUS smbcli_request_simple_recv(struct smbcli_request *req);
339 bool smbcli_oplock_ack(struct smbcli_tree *tree, uint16_t fnum, uint16_t ack_level);
340 NTSTATUS smb_raw_open(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_open *parms);
341 NTSTATUS smb_raw_close(struct smbcli_tree *tree, union smb_close *parms);
342 NTSTATUS smb_raw_unlink(struct smbcli_tree *tree, union smb_unlink *parms);
343 NTSTATUS smb_raw_chkpath(struct smbcli_tree *tree, union smb_chkpath *parms);
344 NTSTATUS smb_raw_mkdir(struct smbcli_tree *tree, union smb_mkdir *parms);
345 NTSTATUS smb_raw_rmdir(struct smbcli_tree *tree, struct smb_rmdir *parms);
346 NTSTATUS smb_raw_rename(struct smbcli_tree *tree, union smb_rename *parms);
347 NTSTATUS smb_raw_seek(struct smbcli_tree *tree, union smb_seek *parms);
348 NTSTATUS smb_raw_read(struct smbcli_tree *tree, union smb_read *parms);
349 NTSTATUS smb_raw_write(struct smbcli_tree *tree, union smb_write *parms);
350 NTSTATUS smb_raw_lock(struct smbcli_tree *tree, union smb_lock *parms);
351 NTSTATUS smb_raw_setpathinfo(struct smbcli_tree *tree, union smb_setfileinfo *parms);
352 NTSTATUS smb_raw_setfileinfo(struct smbcli_tree *tree, union smb_setfileinfo *parms);
354 struct smbcli_request *smb_raw_changenotify_send(struct smbcli_tree *tree, union smb_notify *parms);
355 NTSTATUS smb_raw_changenotify_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, union smb_notify *parms);
357 NTSTATUS smb_tree_disconnect(struct smbcli_tree *tree);
358 NTSTATUS smbcli_nt_error(struct smbcli_tree *tree);
359 NTSTATUS smb_raw_exit(struct smbcli_session *session);
360 NTSTATUS smb_raw_pathinfo_recv(struct smbcli_request *req,
362 union smb_fileinfo *parms);
363 struct smbcli_request *smb_raw_pathinfo_send(struct smbcli_tree *tree,
364 union smb_fileinfo *parms);
365 struct smbcli_request *smb_raw_setpathinfo_send(struct smbcli_tree *tree,
366 union smb_setfileinfo *parms);
367 struct smbcli_request *smb_raw_echo_send(struct smbcli_transport *transport,
369 NTSTATUS smb_raw_search_first(struct smbcli_tree *tree,
371 union smb_search_first *io, void *private_data,
372 smbcli_search_callback callback);
373 NTSTATUS smb_raw_flush(struct smbcli_tree *tree, union smb_flush *parms);
375 NTSTATUS smb_raw_trans(struct smbcli_tree *tree,
377 struct smb_trans2 *parms);
379 struct smbcli_socket *smbcli_sock_connect_byname(const char *host, const char **ports,
381 struct resolve_context *resolve_ctx,
382 struct tevent_context *event_ctx,
383 const char *socket_options);
384 void smbcli_sock_dead(struct smbcli_socket *sock);
386 #endif /* __LIBCLI_RAW__H__ */