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;
36 /* default timeout for all smb requests */
37 #define SMB_REQUEST_TIMEOUT 60
39 /* context that will be and has been negotiated between the client and server */
40 struct smbcli_negotiate {
42 * negotiated maximum transmit size - this is given to us by the server
46 /* maximum number of requests that can be multiplexed */
49 /* the negotiatiated protocol */
50 enum protocol_types protocol;
52 uint8_t sec_mode; /* security mode returned by negprot */
54 DATA_BLOB server_guid; /* server_guid */
55 DATA_BLOB secblob; /* cryptkey or negTokenInit blob */
58 struct smb_signing_context sign_info;
60 /* capabilities that the server reported */
61 uint32_t capabilities;
65 uint_t readbraw_supported:1;
66 uint_t writebraw_supported:1;
71 /* this is the context for a SMB socket associated with the socket itself */
72 struct smbcli_socket {
73 struct socket_context *sock;
75 /* what port we ended up connected to */
78 /* the hostname we connected to */
81 /* the event handle for waiting for socket IO */
83 struct event_context *ctx;
85 struct timed_event *te;
90 this structure allows applications to control the behaviour of the
93 struct smbcli_options {
95 uint_t use_level2_oplocks:1;
98 uint_t ntstatus_support:1;
103 enum smb_signing_state signing;
106 /* this is the context for the client transport layer */
107 struct smbcli_transport {
108 /* socket level info */
109 struct smbcli_socket *socket;
111 /* the next mid to be allocated - needed for signing and
115 /* negotiated protocol information */
116 struct smbcli_negotiate negotiate;
118 /* options to control the behaviour of the client code */
119 struct smbcli_options options;
121 /* is a readbraw pending? we need to handle that case
122 specially on receiving packets */
123 uint_t readbraw_pending:1;
125 /* an idle function - if this is defined then it will be
126 called once every period microseconds while we are waiting
129 void (*func)(struct smbcli_transport *, void *);
134 /* the error fields from the last message */
136 enum {ETYPE_NONE, ETYPE_SMB, ETYPE_SOCKET, ETYPE_NBT} etype;
139 enum {SOCKET_READ_TIMEOUT,
143 SOCKET_READ_BAD_SIG} socket_error;
149 /* a oplock break request handler */
150 bool (*handler)(struct smbcli_transport *transport,
151 uint16_t tid, uint16_t fnum, uint8_t level, void *private);
152 /* private data passed to the oplock handler */
156 /* a list of async requests that are pending for receive on this connection */
157 struct smbcli_request *pending_recv;
159 /* remember the called name - some sub-protocols require us to
160 know the server name */
161 struct nbt_name called;
163 /* context of the stream -> packet parser */
164 struct packet_context *packet;
166 /* iconv convenience */
167 struct smb_iconv_convenience *iconv_convenience;
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 uint_t lanman_auth:1;
195 uint_t ntlmv2_auth:1;
196 uint_t plaintext_auth:1;
201 smbcli_tree context: internal state for a tree connection.
204 /* session layer info */
205 struct smbcli_session *session;
207 uint16_t tid; /* tree id, aka cnum */
214 a client request moves between the following 4 states.
216 enum smbcli_request_state {SMBCLI_REQUEST_INIT, /* we are creating the request */
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 /* a receive helper, smbcli_transport_finish_recv will not call
238 req->async.fn callback handler unless the recv_helper returns
239 a value > SMBCLI_REQUEST_RECV. */
241 enum smbcli_request_state (*fn)(struct smbcli_request *);
245 /* the flags2 from the SMB request, in raw form (host byte
246 order). Used to parse strings */
249 /* the NT status for this request. Set by packet receive code
250 or code detecting error. */
253 /* the sequence number of this packet - used for signing */
256 /* list of ntcancel request for this requests */
257 struct smbcli_request *ntcancel;
259 /* set if this is a one-way request, meaning we are not
260 expecting a reply from the server. */
261 uint_t one_way_request:1;
263 /* set this when the request should only increment the signing
265 uint_t sign_single_increment:1;
267 /* the caller wants to do the signing check */
268 bool sign_caller_checks;
270 /* give the caller a chance to prevent the talloc_free() in the _recv() function */
273 /* the mid of this packet - used to match replies */
276 struct smb_request_buffer in;
277 struct smb_request_buffer out;
279 /* information on what to do with a reply when it is received
280 asyncronously. If this is not setup when a reply is received then
281 the reply is discarded
283 The private pointer is private to the caller of the client
284 library (the application), not private to the library
287 void (*fn)(struct smbcli_request *);
292 /* useful way of catching wct errors with file and line number */
293 #define SMBCLI_CHECK_MIN_WCT(req, wcount) if ((req)->in.wct < (wcount)) { \
294 DEBUG(1,("Unexpected WCT %d at %s(%d) - expected min %d\n", (req)->in.wct, __FILE__, __LINE__, wcount)); \
295 req->status = NT_STATUS_INVALID_PARAMETER; \
299 #define SMBCLI_CHECK_WCT(req, wcount) if ((req)->in.wct != (wcount)) { \
300 DEBUG(1,("Unexpected WCT %d at %s(%d) - expected %d\n", (req)->in.wct, __FILE__, __LINE__, wcount)); \
301 req->status = NT_STATUS_INVALID_PARAMETER; \
305 #include "libcli/raw/interfaces.h"
307 NTSTATUS smb_raw_read_recv(struct smbcli_request *req, union smb_read *parms);
308 struct smbcli_request *smb_raw_read_send(struct smbcli_tree *tree, union smb_read *parms);
309 NTSTATUS smb_raw_trans_recv(struct smbcli_request *req,
311 struct smb_trans2 *parms);
312 size_t smb_raw_max_trans_data(struct smbcli_tree *tree, size_t param_size);
313 struct smbcli_request *smb_raw_trans_send(struct smbcli_tree *tree, struct smb_trans2 *parms);
314 NTSTATUS smbcli_request_destroy(struct smbcli_request *req);
315 struct smbcli_request *smb_raw_write_send(struct smbcli_tree *tree, union smb_write *parms);
316 struct smbcli_request *smb_raw_close_send(struct smbcli_tree *tree, union smb_close *parms);
317 NTSTATUS smb_raw_open_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, union smb_open *parms);
318 struct smbcli_request *smb_raw_open_send(struct smbcli_tree *tree, union smb_open *parms);
320 bool smbcli_transport_process(struct smbcli_transport *transport);
321 const char *smbcli_errstr(struct smbcli_tree *tree);
322 NTSTATUS smb_raw_fsinfo(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_fsinfo *fsinfo);
323 NTSTATUS smb_raw_pathinfo(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_fileinfo *parms);
324 NTSTATUS smb_raw_shadow_data(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, struct smb_shadow_copy *info);
325 NTSTATUS smb_raw_fileinfo(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_fileinfo *parms);
326 struct smbcli_tree *smbcli_tree_init(struct smbcli_session *session, TALLOC_CTX *parent_ctx, bool primary);
327 NTSTATUS smb_raw_tcon(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_tcon *parms);
328 void smbcli_oplock_handler(struct smbcli_transport *transport,
329 bool (*handler)(struct smbcli_transport *, uint16_t, uint16_t, uint8_t, void *),
331 void smbcli_transport_idle_handler(struct smbcli_transport *transport,
332 void (*idle_func)(struct smbcli_transport *, void *),
335 NTSTATUS smbcli_request_simple_recv(struct smbcli_request *req);
336 bool smbcli_oplock_ack(struct smbcli_tree *tree, uint16_t fnum, uint16_t ack_level);
337 NTSTATUS smb_raw_open(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_open *parms);
338 NTSTATUS smb_raw_close(struct smbcli_tree *tree, union smb_close *parms);
339 NTSTATUS smb_raw_unlink(struct smbcli_tree *tree, union smb_unlink *parms);
340 NTSTATUS smb_raw_chkpath(struct smbcli_tree *tree, union smb_chkpath *parms);
341 NTSTATUS smb_raw_mkdir(struct smbcli_tree *tree, union smb_mkdir *parms);
342 NTSTATUS smb_raw_rmdir(struct smbcli_tree *tree, struct smb_rmdir *parms);
343 NTSTATUS smb_raw_rename(struct smbcli_tree *tree, union smb_rename *parms);
344 NTSTATUS smb_raw_seek(struct smbcli_tree *tree, union smb_seek *parms);
345 NTSTATUS smb_raw_read(struct smbcli_tree *tree, union smb_read *parms);
346 NTSTATUS smb_raw_write(struct smbcli_tree *tree, union smb_write *parms);
347 NTSTATUS smb_raw_lock(struct smbcli_tree *tree, union smb_lock *parms);
348 NTSTATUS smb_raw_setpathinfo(struct smbcli_tree *tree, union smb_setfileinfo *parms);
349 NTSTATUS smb_raw_setfileinfo(struct smbcli_tree *tree, union smb_setfileinfo *parms);
351 struct smbcli_request *smb_raw_changenotify_send(struct smbcli_tree *tree, union smb_notify *parms);
352 NTSTATUS smb_raw_changenotify_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, union smb_notify *parms);
354 NTSTATUS smb_tree_disconnect(struct smbcli_tree *tree);
355 NTSTATUS smbcli_nt_error(struct smbcli_tree *tree);
356 NTSTATUS smb_raw_exit(struct smbcli_session *session);
357 NTSTATUS smb_raw_pathinfo_recv(struct smbcli_request *req,
359 union smb_fileinfo *parms);
360 struct smbcli_request *smb_raw_pathinfo_send(struct smbcli_tree *tree,
361 union smb_fileinfo *parms);
362 struct smbcli_request *smb_raw_setpathinfo_send(struct smbcli_tree *tree,
363 union smb_setfileinfo *parms);
364 struct smbcli_request *smb_raw_echo_send(struct smbcli_transport *transport,
366 NTSTATUS smb_raw_search_first(struct smbcli_tree *tree,
368 union smb_search_first *io, void *private,
369 smbcli_search_callback callback);
370 NTSTATUS smb_raw_flush(struct smbcli_tree *tree, union smb_flush *parms);
372 NTSTATUS smb_raw_trans(struct smbcli_tree *tree,
374 struct smb_trans2 *parms);
376 struct smbcli_socket *smbcli_sock_connect_byname(const char *host, const char **ports,
378 struct resolve_context *resolve_ctx,
379 struct event_context *event_ctx);
380 void smbcli_sock_dead(struct smbcli_socket *sock);
382 #endif /* __LIBCLI_RAW__H__ */