misc: mark winreg_Data little-endian except for a REG_DWORD_BIG_ENDIAN.
[Samba/gbeck.git] / source4 / libcli / raw / libcliraw.h
bloba9fcdab9ccdc81daf99d8f3bc2f035ad64d0c656
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/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 {
42 /*
43 * negotiated maximum transmit size - this is given to us by the server
45 uint32_t max_xmit;
47 /* maximum number of requests that can be multiplexed */
48 uint16_t max_mux;
50 /* the negotiatiated protocol */
51 enum protocol_types protocol;
53 uint8_t sec_mode; /* security mode returned by negprot */
54 uint8_t key_len;
55 DATA_BLOB server_guid; /* server_guid */
56 DATA_BLOB secblob; /* cryptkey or negTokenInit blob */
57 uint32_t sesskey;
59 struct smb_signing_context sign_info;
61 /* capabilities that the server reported */
62 uint32_t capabilities;
64 int server_zone;
65 time_t server_time;
66 uint_t readbraw_supported:1;
67 uint_t writebraw_supported:1;
69 char *server_domain;
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 */
77 int port;
79 /* the hostname we connected to */
80 const char *hostname;
82 /* the event handle for waiting for socket IO */
83 struct {
84 struct tevent_context *ctx;
85 struct tevent_fd *fde;
86 struct tevent_timer *te;
87 } event;
91 this structure allows applications to control the behaviour of the
92 client library
94 struct smbcli_options {
95 uint_t use_oplocks:1;
96 uint_t use_level2_oplocks:1;
97 uint_t use_spnego:1;
98 uint_t unicode:1;
99 uint_t ntstatus_support:1;
100 int max_protocol;
101 uint32_t max_xmit;
102 uint16_t max_mux;
103 int request_timeout;
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
113 request matching */
114 uint16_t next_mid;
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
128 for a packet */
129 struct {
130 void (*func)(struct smbcli_transport *, void *);
131 void *private_data;
132 uint_t period;
133 } idle;
135 /* the error fields from the last message */
136 struct {
137 enum {ETYPE_NONE, ETYPE_SMB, ETYPE_SOCKET, ETYPE_NBT} etype;
138 union {
139 NTSTATUS nt_status;
140 enum {SOCKET_READ_TIMEOUT,
141 SOCKET_READ_EOF,
142 SOCKET_READ_ERROR,
143 SOCKET_WRITE_ERROR,
144 SOCKET_READ_BAD_SIG} socket_error;
145 uint_t nbt_error;
146 } e;
147 } error;
149 struct {
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 */
154 void *private_data;
155 } oplock;
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 */
180 uint16_t vuid;
182 /* default pid for this session */
183 uint32_t pid;
185 /* the flags2 for each packet - this allows
186 the user to control these for torture testing */
187 uint16_t flags2;
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;
198 } options;
202 smbcli_tree context: internal state for a tree connection.
204 struct smbcli_tree {
205 /* session layer info */
206 struct smbcli_session *session;
208 uint16_t tid; /* tree id, aka cnum */
209 char *device;
210 char *fs_type;
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. */
241 struct {
242 enum smbcli_request_state (*fn)(struct smbcli_request *);
243 void *private_data;
244 } recv_helper;
246 /* the flags2 from the SMB request, in raw form (host byte
247 order). Used to parse strings */
248 uint16_t flags2;
250 /* the NT status for this request. Set by packet receive code
251 or code detecting error. */
252 NTSTATUS status;
254 /* the sequence number of this packet - used for signing */
255 uint_t seq_num;
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
265 counter by one */
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 */
272 bool do_not_free;
274 /* the mid of this packet - used to match replies */
275 uint16_t mid;
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
287 struct {
288 void (*fn)(struct smbcli_request *);
289 void *private_data;
290 } async;
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; \
297 goto failed; \
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; \
303 goto failed; \
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,
311 TALLOC_CTX *mem_ctx,
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 *),
331 void *private_data);
332 void smbcli_transport_idle_handler(struct smbcli_transport *transport,
333 void (*idle_func)(struct smbcli_transport *, void *),
334 uint64_t period,
335 void *private_data);
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,
359 TALLOC_CTX *mem_ctx,
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,
366 struct smb_echo *p);
367 NTSTATUS smb_raw_search_first(struct smbcli_tree *tree,
368 TALLOC_CTX *mem_ctx,
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,
374 TALLOC_CTX *mem_ctx,
375 struct smb_trans2 *parms);
377 struct smbcli_socket *smbcli_sock_connect_byname(const char *host, const char **ports,
378 TALLOC_CTX *mem_ctx,
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__ */