s4:libcli/raw: remove unuded CMD_REPLY define
[Samba/gebeck_regimport.git] / source4 / libcli / raw / libcliraw.h
blobb7b02c668eaee6a83ea1b6efe660fab9698932e1
1 /*
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 {
43 /*
44 * negotiated maximum transmit size - this is given to us by the server
46 uint32_t max_xmit;
48 /* maximum number of requests that can be multiplexed */
49 uint16_t max_mux;
51 /* the negotiatiated protocol */
52 enum protocol_types protocol;
54 uint8_t sec_mode; /* security mode returned by negprot */
55 uint8_t key_len;
56 DATA_BLOB server_guid; /* server_guid */
57 DATA_BLOB secblob; /* cryptkey or negTokenInit blob */
58 uint32_t sesskey;
60 struct smb_signing_context sign_info;
62 /* capabilities that the server reported */
63 uint32_t capabilities;
65 int server_zone;
66 time_t server_time;
67 unsigned int readbraw_supported:1;
68 unsigned int writebraw_supported:1;
69 unsigned int lockread_supported:1;
71 char *server_domain;
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 */
79 int port;
81 /* the hostname we connected to */
82 const char *hostname;
84 /* the event handle for waiting for socket IO */
85 struct {
86 struct tevent_context *ctx;
87 struct tevent_fd *fde;
88 struct tevent_timer *te;
89 } event;
93 this structure allows applications to control the behaviour of the
94 client library
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;
102 int max_protocol;
103 uint32_t max_xmit;
104 uint16_t max_mux;
105 int request_timeout;
106 enum smb_signing_setting 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
115 request matching */
116 uint16_t next_mid;
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
130 for a packet */
131 struct {
132 void (*func)(struct smbcli_transport *, void *);
133 void *private_data;
134 unsigned int period;
135 } idle;
137 /* the error fields from the last message */
138 struct {
139 enum {ETYPE_NONE, ETYPE_SMB, ETYPE_SOCKET, ETYPE_NBT} etype;
140 union {
141 NTSTATUS nt_status;
142 enum {SOCKET_READ_TIMEOUT,
143 SOCKET_READ_EOF,
144 SOCKET_READ_ERROR,
145 SOCKET_WRITE_ERROR,
146 SOCKET_READ_BAD_SIG} socket_error;
147 unsigned int nbt_error;
148 } e;
149 } error;
151 struct {
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 */
156 void *private_data;
157 } oplock;
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 */
179 uint16_t vuid;
181 /* default pid for this session */
182 uint32_t pid;
184 /* the flags2 for each packet - this allows
185 the user to control these for torture testing */
186 uint16_t flags2;
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;
197 } options;
199 const char *os;
200 const char *lanman;
204 smbcli_tree context: internal state for a tree connection.
206 struct smbcli_tree {
207 /* session layer info */
208 struct smbcli_session *session;
210 uint16_t tid; /* tree id, aka cnum */
211 char *device;
212 char *fs_type;
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. */
243 struct {
244 enum smbcli_request_state (*fn)(struct smbcli_request *);
245 void *private_data;
246 } recv_helper;
248 /* the flags2 from the SMB request, in raw form (host byte
249 order). Used to parse strings */
250 uint16_t flags2;
252 /* the NT status for this request. Set by packet receive code
253 or code detecting error. */
254 NTSTATUS status;
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
267 counter by one */
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 */
274 bool do_not_free;
276 /* the mid of this packet - used to match replies */
277 uint16_t mid;
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
289 struct {
290 void (*fn)(struct smbcli_request *);
291 void *private_data;
292 } async;
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; \
299 goto failed; \
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; \
305 goto failed; \
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,
313 TALLOC_CTX *mem_ctx,
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 NTSTATUS smb_raw_write_recv(struct smbcli_request *req, union smb_write *parms);
320 struct smbcli_request *smb_raw_close_send(struct smbcli_tree *tree, union smb_close *parms);
321 NTSTATUS smb_raw_open_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, union smb_open *parms);
322 struct smbcli_request *smb_raw_open_send(struct smbcli_tree *tree, union smb_open *parms);
324 bool smbcli_transport_process(struct smbcli_transport *transport);
325 const char *smbcli_errstr(struct smbcli_tree *tree);
326 NTSTATUS smb_raw_fsinfo(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_fsinfo *fsinfo);
327 NTSTATUS smb_raw_pathinfo(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_fileinfo *parms);
328 NTSTATUS smb_raw_shadow_data(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, struct smb_shadow_copy *info);
329 NTSTATUS smb_raw_fileinfo(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_fileinfo *parms);
330 struct smbcli_tree *smbcli_tree_init(struct smbcli_session *session, TALLOC_CTX *parent_ctx, bool primary);
331 NTSTATUS smb_raw_tcon(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_tcon *parms);
332 void smbcli_oplock_handler(struct smbcli_transport *transport,
333 bool (*handler)(struct smbcli_transport *, uint16_t, uint16_t, uint8_t, void *),
334 void *private_data);
335 void smbcli_transport_idle_handler(struct smbcli_transport *transport,
336 void (*idle_func)(struct smbcli_transport *, void *),
337 uint64_t period,
338 void *private_data);
339 NTSTATUS smbcli_request_simple_recv(struct smbcli_request *req);
340 bool smbcli_oplock_ack(struct smbcli_tree *tree, uint16_t fnum, uint16_t ack_level);
341 NTSTATUS smb_raw_open(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_open *parms);
342 NTSTATUS smb_raw_close(struct smbcli_tree *tree, union smb_close *parms);
343 NTSTATUS smb_raw_unlink(struct smbcli_tree *tree, union smb_unlink *parms);
344 NTSTATUS smb_raw_chkpath(struct smbcli_tree *tree, union smb_chkpath *parms);
345 NTSTATUS smb_raw_mkdir(struct smbcli_tree *tree, union smb_mkdir *parms);
346 NTSTATUS smb_raw_rmdir(struct smbcli_tree *tree, struct smb_rmdir *parms);
347 NTSTATUS smb_raw_rename(struct smbcli_tree *tree, union smb_rename *parms);
348 NTSTATUS smb_raw_seek(struct smbcli_tree *tree, union smb_seek *parms);
349 NTSTATUS smb_raw_read(struct smbcli_tree *tree, union smb_read *parms);
350 NTSTATUS smb_raw_write(struct smbcli_tree *tree, union smb_write *parms);
351 NTSTATUS smb_raw_lock(struct smbcli_tree *tree, union smb_lock *parms);
352 NTSTATUS smb_raw_setpathinfo(struct smbcli_tree *tree, union smb_setfileinfo *parms);
353 NTSTATUS smb_raw_setfileinfo(struct smbcli_tree *tree, union smb_setfileinfo *parms);
355 struct smbcli_request *smb_raw_changenotify_send(struct smbcli_tree *tree, union smb_notify *parms);
356 NTSTATUS smb_raw_changenotify_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, union smb_notify *parms);
358 NTSTATUS smb_tree_disconnect(struct smbcli_tree *tree);
359 NTSTATUS smbcli_nt_error(struct smbcli_tree *tree);
360 NTSTATUS smb_raw_exit(struct smbcli_session *session);
361 NTSTATUS smb_raw_pathinfo_recv(struct smbcli_request *req,
362 TALLOC_CTX *mem_ctx,
363 union smb_fileinfo *parms);
364 struct smbcli_request *smb_raw_pathinfo_send(struct smbcli_tree *tree,
365 union smb_fileinfo *parms);
366 struct smbcli_request *smb_raw_setpathinfo_send(struct smbcli_tree *tree,
367 union smb_setfileinfo *parms);
368 struct smbcli_request *smb_raw_echo_send(struct smbcli_transport *transport,
369 struct smb_echo *p);
370 NTSTATUS smb_raw_search_first(struct smbcli_tree *tree,
371 TALLOC_CTX *mem_ctx,
372 union smb_search_first *io, void *private_data,
373 smbcli_search_callback callback);
374 NTSTATUS smb_raw_flush(struct smbcli_tree *tree, union smb_flush *parms);
376 NTSTATUS smb_raw_trans(struct smbcli_tree *tree,
377 TALLOC_CTX *mem_ctx,
378 struct smb_trans2 *parms);
380 struct smbcli_socket *smbcli_sock_connect_byname(const char *host, const char **ports,
381 TALLOC_CTX *mem_ctx,
382 struct resolve_context *resolve_ctx,
383 struct tevent_context *event_ctx,
384 const char *socket_options);
385 void smbcli_sock_dead(struct smbcli_socket *sock);
387 #endif /* __LIBCLI_RAW__H__ */