source: vendor/current/source4/libcli/raw/libcliraw.h

Last change on this file was 988, checked in by Silvan Scherrer, 9 years ago

Samba Server: update vendor to version 4.4.3

File size: 11.9 KB
Line 
1/*
2 Unix SMB/CIFS implementation.
3 SMB parameters and setup
4
5 Copyright (C) Andrew Tridgell 2002-2004
6 Copyright (C) James Myers 2003 <myersjj@samba.org>
7
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.
12
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.
17
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/>.
20*/
21
22#ifndef __LIBCLI_RAW_H__
23#define __LIBCLI_RAW_H__
24
25#include "../libcli/smb/smb_common.h"
26#include "libcli/raw/request.h"
27#include "librpc/gen_ndr/nbt.h"
28#include "libcli/raw/interfaces.h"
29
30struct smbcli_tree; /* forward declare */
31struct smbcli_request; /* forward declare */
32struct smbcli_session; /* forward declare */
33struct smbcli_transport; /* forward declare */
34
35struct resolve_context;
36struct cli_credentials;
37struct gensec_settings;
38
39/* default timeout for all smb requests */
40#define SMB_REQUEST_TIMEOUT 60
41
42/* context that will be and has been negotiated between the client and server */
43struct smbcli_negotiate {
44 /*
45 * negotiated maximum transmit size - this is given to us by the server
46 */
47 uint32_t max_xmit;
48
49 /* maximum number of requests that can be multiplexed */
50 uint16_t max_mux;
51
52 /* the negotiatiated protocol */
53 enum protocol_types protocol;
54
55 uint8_t sec_mode; /* security mode returned by negprot */
56 DATA_BLOB secblob; /* cryptkey or negTokenInit blob */
57 uint32_t sesskey;
58
59 /* capabilities that the server reported */
60 uint32_t capabilities;
61
62 int server_zone;
63 time_t server_time;
64
65 unsigned int readbraw_supported:1;
66 unsigned int writebraw_supported:1;
67 unsigned int lockread_supported:1;
68};
69
70/* this is the context for a SMB socket associated with the socket itself */
71struct smbcli_socket {
72 struct socket_context *sock;
73
74 /* what port we ended up connected to */
75 int port;
76
77 /* the hostname we connected to */
78 const char *hostname;
79
80 /* the event handle for waiting for socket IO */
81 struct {
82 struct tevent_context *ctx;
83 struct tevent_fd *fde;
84 struct tevent_timer *te;
85 } event;
86};
87
88/*
89 this structure allows applications to control the behaviour of the
90 client library
91*/
92struct smbcli_options {
93 unsigned int use_oplocks:1;
94 unsigned int use_level2_oplocks:1;
95 unsigned int use_spnego:1;
96 unsigned int unicode:1;
97 unsigned int ntstatus_support:1;
98 int min_protocol;
99 int max_protocol;
100 uint32_t max_xmit;
101 uint16_t max_mux;
102 int request_timeout;
103 enum smb_signing_setting signing;
104 uint32_t smb2_capabilities;
105 struct GUID client_guid;
106};
107
108/* this is the context for the client transport layer */
109struct smbcli_transport {
110 struct tevent_context *ev; /* TODO: remove this !!! */
111 struct smbXcli_conn *conn;
112
113 /* negotiated protocol information */
114 struct smbcli_negotiate negotiate;
115
116 /* options to control the behaviour of the client code */
117 struct smbcli_options options;
118
119 /* an idle function - if this is defined then it will be
120 called once every period microseconds while we are waiting
121 for a packet */
122 struct {
123 void (*func)(struct smbcli_transport *, void *);
124 void *private_data;
125 unsigned int period;
126 struct tevent_timer *te;
127 } idle;
128
129 /* the error fields from the last message */
130 struct {
131 enum {ETYPE_NONE, ETYPE_SMB, ETYPE_SOCKET, ETYPE_NBT} etype;
132 union {
133 NTSTATUS nt_status;
134 enum {SOCKET_READ_TIMEOUT,
135 SOCKET_READ_EOF,
136 SOCKET_READ_ERROR,
137 SOCKET_WRITE_ERROR,
138 SOCKET_READ_BAD_SIG} socket_error;
139 unsigned int nbt_error;
140 } e;
141 } error;
142
143 struct {
144 /* a oplock break request handler */
145 bool (*handler)(struct smbcli_transport *transport,
146 uint16_t tid, uint16_t fnum, uint8_t level, void *private_data);
147 /* private data passed to the oplock handler */
148 void *private_data;
149 } oplock;
150 struct tevent_req *break_subreq;
151};
152
153/* this is the context for the user */
154
155/* this is the context for the session layer */
156struct smbcli_session {
157 /* transport layer info */
158 struct smbcli_transport *transport;
159
160 /* after a session setup the server provides us with
161 a vuid identifying the security context */
162 struct smbXcli_session *smbXcli;
163 uint16_t vuid;
164
165 /* default pid for this session */
166 uint32_t pid;
167
168 /* the flags2 for each packet - this allows
169 the user to control these for torture testing */
170 uint16_t flags2;
171
172 /* the spnego context if we use extented security */
173 struct gensec_security *gensec;
174
175 struct smbcli_session_options {
176 unsigned int lanman_auth:1;
177 unsigned int ntlmv2_auth:1;
178 unsigned int plaintext_auth:1;
179 } options;
180
181 const char *os;
182 const char *lanman;
183};
184
185/*
186 smbcli_tree context: internal state for a tree connection.
187 */
188struct smbcli_tree {
189 /* session layer info */
190 struct smbcli_session *session;
191
192 struct smbXcli_tcon *smbXcli;
193 uint16_t tid; /* tree id, aka cnum */
194 char *device;
195 char *fs_type;
196};
197
198
199/*
200 a client request moves between the following 4 states.
201*/
202enum smbcli_request_state {SMBCLI_REQUEST_INIT, /* we are creating the request */
203 SMBCLI_REQUEST_RECV, /* we are waiting for a matching reply */
204 SMBCLI_REQUEST_DONE, /* the request is finished */
205 SMBCLI_REQUEST_ERROR}; /* a packet or transport level error has occurred */
206
207/* the context for a single SMB request. This is passed to any request-context
208 * functions (similar to context.h, the server version).
209 * This will allow requests to be multi-threaded. */
210struct smbcli_request {
211 /* smbXcli_req */
212 struct tevent_req *subreqs[2];
213
214 /* each request is in one of 4 possible states */
215 enum smbcli_request_state state;
216
217 /* a request always has a transport context, nearly always has
218 a session context and usually has a tree context */
219 struct smbcli_transport *transport;
220 struct smbcli_session *session;
221 struct smbcli_tree *tree;
222
223 /* the flags2 from the SMB request, in raw form (host byte
224 order). Used to parse strings */
225 uint16_t flags2;
226
227 /* the NT status for this request. Set by packet receive code
228 or code detecting error. */
229 NTSTATUS status;
230
231 /* the caller wants to do the signing check */
232 bool sign_caller_checks;
233
234 /* give the caller a chance to prevent the talloc_free() in the _recv() function */
235 bool do_not_free;
236
237 struct smb_request_buffer in;
238 struct smb_request_buffer out;
239
240 struct smb_trans2 trans2;
241 struct smb_nttrans nttrans;
242
243 /* information on what to do with a reply when it is received
244 asyncronously. If this is not setup when a reply is received then
245 the reply is discarded
246
247 The private pointer is private to the caller of the client
248 library (the application), not private to the library
249 */
250 struct {
251 void (*fn)(struct smbcli_request *);
252 void *private_data;
253 } async;
254};
255
256/* useful way of catching wct errors with file and line number */
257#define SMBCLI_CHECK_MIN_WCT(req, wcount) if ((req)->in.wct < (wcount)) { \
258 DEBUG(1,("Unexpected WCT %d at %s(%d) - expected min %d\n", (req)->in.wct, __FILE__, __LINE__, wcount)); \
259 req->status = NT_STATUS_INVALID_PARAMETER; \
260 goto failed; \
261}
262
263#define SMBCLI_CHECK_WCT(req, wcount) if ((req)->in.wct != (wcount)) { \
264 DEBUG(1,("Unexpected WCT %d at %s(%d) - expected %d\n", (req)->in.wct, __FILE__, __LINE__, wcount)); \
265 req->status = NT_STATUS_INVALID_PARAMETER; \
266 goto failed; \
267}
268
269NTSTATUS smb_raw_read_recv(struct smbcli_request *req, union smb_read *parms);
270struct smbcli_request *smb_raw_read_send(struct smbcli_tree *tree, union smb_read *parms);
271NTSTATUS smb_raw_trans_recv(struct smbcli_request *req,
272 TALLOC_CTX *mem_ctx,
273 struct smb_trans2 *parms);
274size_t smb_raw_max_trans_data(struct smbcli_tree *tree, size_t param_size);
275struct smbcli_request *smb_raw_trans_send(struct smbcli_tree *tree, struct smb_trans2 *parms);
276NTSTATUS smbcli_request_destroy(struct smbcli_request *req);
277struct smbcli_request *smb_raw_write_send(struct smbcli_tree *tree, union smb_write *parms);
278NTSTATUS smb_raw_write_recv(struct smbcli_request *req, union smb_write *parms);
279struct smbcli_request *smb_raw_close_send(struct smbcli_tree *tree, union smb_close *parms);
280NTSTATUS smb_raw_open_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, union smb_open *parms);
281struct smbcli_request *smb_raw_open_send(struct smbcli_tree *tree, union smb_open *parms);
282
283bool smbcli_transport_process(struct smbcli_transport *transport);
284const char *smbcli_errstr(struct smbcli_tree *tree);
285NTSTATUS smb_raw_fsinfo(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_fsinfo *fsinfo);
286NTSTATUS smb_raw_setfsinfo(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_setfsinfo *set_fsinfo);
287NTSTATUS smb_raw_pathinfo(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_fileinfo *parms);
288NTSTATUS smb_raw_shadow_data(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, struct smb_shadow_copy *info);
289NTSTATUS smb_raw_fileinfo(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_fileinfo *parms);
290struct smbcli_tree *smbcli_tree_init(struct smbcli_session *session, TALLOC_CTX *parent_ctx, bool primary);
291NTSTATUS smb_raw_tcon(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_tcon *parms);
292void smbcli_oplock_handler(struct smbcli_transport *transport,
293 bool (*handler)(struct smbcli_transport *, uint16_t, uint16_t, uint8_t, void *),
294 void *private_data);
295void smbcli_transport_idle_handler(struct smbcli_transport *transport,
296 void (*idle_func)(struct smbcli_transport *, void *),
297 uint64_t period,
298 void *private_data);
299NTSTATUS smbcli_request_simple_recv(struct smbcli_request *req);
300bool smbcli_oplock_ack(struct smbcli_tree *tree, uint16_t fnum, uint16_t ack_level);
301NTSTATUS smb_raw_open(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_open *parms);
302NTSTATUS smb_raw_close(struct smbcli_tree *tree, union smb_close *parms);
303NTSTATUS smb_raw_unlink(struct smbcli_tree *tree, union smb_unlink *parms);
304NTSTATUS smb_raw_chkpath(struct smbcli_tree *tree, union smb_chkpath *parms);
305NTSTATUS smb_raw_mkdir(struct smbcli_tree *tree, union smb_mkdir *parms);
306NTSTATUS smb_raw_rmdir(struct smbcli_tree *tree, struct smb_rmdir *parms);
307NTSTATUS smb_raw_rename(struct smbcli_tree *tree, union smb_rename *parms);
308NTSTATUS smb_raw_seek(struct smbcli_tree *tree, union smb_seek *parms);
309NTSTATUS smb_raw_read(struct smbcli_tree *tree, union smb_read *parms);
310NTSTATUS smb_raw_write(struct smbcli_tree *tree, union smb_write *parms);
311NTSTATUS smb_raw_lock(struct smbcli_tree *tree, union smb_lock *parms);
312NTSTATUS smb_raw_setpathinfo(struct smbcli_tree *tree, union smb_setfileinfo *parms);
313NTSTATUS smb_raw_setfileinfo(struct smbcli_tree *tree, union smb_setfileinfo *parms);
314
315struct smbcli_request *smb_raw_changenotify_send(struct smbcli_tree *tree, union smb_notify *parms);
316NTSTATUS smb_raw_changenotify_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, union smb_notify *parms);
317
318NTSTATUS smb_tree_disconnect(struct smbcli_tree *tree);
319NTSTATUS smbcli_nt_error(struct smbcli_tree *tree);
320NTSTATUS smb_raw_exit(struct smbcli_session *session);
321NTSTATUS smb_raw_pathinfo_recv(struct smbcli_request *req,
322 TALLOC_CTX *mem_ctx,
323 union smb_fileinfo *parms);
324struct smbcli_request *smb_raw_pathinfo_send(struct smbcli_tree *tree,
325 union smb_fileinfo *parms);
326struct smbcli_request *smb_raw_setpathinfo_send(struct smbcli_tree *tree,
327 union smb_setfileinfo *parms);
328struct smbcli_request *smb_raw_echo_send(struct smbcli_transport *transport,
329 struct smb_echo *p);
330NTSTATUS smb_raw_search_first(struct smbcli_tree *tree,
331 TALLOC_CTX *mem_ctx,
332 union smb_search_first *io, void *private_data,
333 smbcli_search_callback callback);
334NTSTATUS smb_raw_flush(struct smbcli_tree *tree, union smb_flush *parms);
335
336NTSTATUS smb_raw_trans(struct smbcli_tree *tree,
337 TALLOC_CTX *mem_ctx,
338 struct smb_trans2 *parms);
339
340#endif /* __LIBCLI_RAW__H__ */
Note: See TracBrowser for help on using the repository browser.