• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt/router/samba-3.5.8/source4/libcli/raw/
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/raw/request.h"
26#include "librpc/gen_ndr/nbt.h"
27
28struct smbcli_tree;  /* forward declare */
29struct smbcli_request;  /* forward declare */
30struct smbcli_session;  /* forward declare */
31struct smbcli_transport;  /* forward declare */
32
33struct resolve_context;
34struct cli_credentials;
35struct gensec_settings;
36
37/* default timeout for all smb requests */
38#define SMB_REQUEST_TIMEOUT 60
39
40/* context that will be and has been negotiated between the client and server */
41struct smbcli_negotiate {
42	/*
43	 * negotiated maximum transmit size - this is given to us by the server
44	 */
45	uint32_t max_xmit;
46
47	/* maximum number of requests that can be multiplexed */
48	uint16_t max_mux;
49
50	/* the negotiatiated protocol */
51	enum protocol_types protocol;
52
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;
58
59	struct smb_signing_context sign_info;
60
61	/* capabilities that the server reported */
62	uint32_t capabilities;
63
64	int server_zone;
65	time_t server_time;
66	uint_t readbraw_supported:1;
67	uint_t writebraw_supported:1;
68
69	char *server_domain;
70};
71
72/* this is the context for a SMB socket associated with the socket itself */
73struct smbcli_socket {
74	struct socket_context *sock;
75
76	/* what port we ended up connected to */
77	int port;
78
79	/* the hostname we connected to */
80	const char *hostname;
81
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;
88};
89
90/*
91  this structure allows applications to control the behaviour of the
92  client library
93*/
94struct 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;
105};
106
107/* this is the context for the client transport layer */
108struct smbcli_transport {
109	/* socket level info */
110	struct smbcli_socket *socket;
111
112	/* the next mid to be allocated - needed for signing and
113	   request matching */
114	uint16_t next_mid;
115
116	/* negotiated protocol information */
117	struct smbcli_negotiate negotiate;
118
119	/* options to control the behaviour of the client code */
120	struct smbcli_options options;
121
122	/* is a readbraw pending? we need to handle that case
123	   specially on receiving packets */
124	uint_t readbraw_pending:1;
125
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;
134
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;
148
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;
156
157	/* a list of async requests that are pending for receive on this connection */
158	struct smbcli_request *pending_recv;
159
160	/* remember the called name - some sub-protocols require us to
161	   know the server name */
162	struct nbt_name called;
163
164	/* context of the stream -> packet parser */
165	struct packet_context *packet;
166
167	/* iconv convenience */
168	struct smb_iconv_convenience *iconv_convenience;
169};
170
171/* this is the context for the user */
172
173/* this is the context for the session layer */
174struct smbcli_session {
175	/* transport layer info */
176	struct smbcli_transport *transport;
177
178	/* after a session setup the server provides us with
179	   a vuid identifying the security context */
180	uint16_t vuid;
181
182	/* default pid for this session */
183	uint32_t pid;
184
185	/* the flags2 for each packet - this allows
186	   the user to control these for torture testing */
187	uint16_t flags2;
188
189	DATA_BLOB user_session_key;
190
191	/* the spnego context if we use extented security */
192	struct gensec_security *gensec;
193
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;
199
200	const char *os;
201	const char *lanman;
202};
203
204/*
205   smbcli_tree context: internal state for a tree connection.
206 */
207struct smbcli_tree {
208	/* session layer info */
209	struct smbcli_session *session;
210
211	uint16_t tid;			/* tree id, aka cnum */
212	char *device;
213	char *fs_type;
214};
215
216
217/*
218  a client request moves between the following 4 states.
219*/
220enum smbcli_request_state {SMBCLI_REQUEST_INIT, /* we are creating the request */
221			SMBCLI_REQUEST_RECV, /* we are waiting for a matching reply */
222			SMBCLI_REQUEST_DONE, /* the request is finished */
223			SMBCLI_REQUEST_ERROR}; /* a packet or transport level error has occurred */
224
225/* the context for a single SMB request. This is passed to any request-context
226 * functions (similar to context.h, the server version).
227 * This will allow requests to be multi-threaded. */
228struct smbcli_request {
229	/* allow a request to be part of a list of requests */
230	struct smbcli_request *next, *prev;
231
232	/* each request is in one of 4 possible states */
233	enum smbcli_request_state state;
234
235	/* a request always has a transport context, nearly always has
236	   a session context and usually has a tree context */
237	struct smbcli_transport *transport;
238	struct smbcli_session *session;
239	struct smbcli_tree *tree;
240
241	/* a receive helper, smbcli_transport_finish_recv will not call
242	   req->async.fn callback handler unless the recv_helper returns
243	   a value > SMBCLI_REQUEST_RECV. */
244	struct {
245		enum smbcli_request_state (*fn)(struct smbcli_request *);
246		void *private_data;
247	} recv_helper;
248
249	/* the flags2 from the SMB request, in raw form (host byte
250	   order). Used to parse strings */
251	uint16_t flags2;
252
253	/* the NT status for this request. Set by packet receive code
254	   or code detecting error. */
255	NTSTATUS status;
256
257	/* the sequence number of this packet - used for signing */
258	uint_t seq_num;
259
260	/* list of ntcancel request for this requests */
261	struct smbcli_request *ntcancel;
262
263	/* set if this is a one-way request, meaning we are not
264	   expecting a reply from the server. */
265	uint_t one_way_request:1;
266
267	/* set this when the request should only increment the signing
268	   counter by one */
269	uint_t sign_single_increment:1;
270
271	/* the caller wants to do the signing check */
272	bool sign_caller_checks;
273
274	/* give the caller a chance to prevent the talloc_free() in the _recv() function */
275	bool do_not_free;
276
277	/* the mid of this packet - used to match replies */
278	uint16_t mid;
279
280	struct smb_request_buffer in;
281	struct smb_request_buffer out;
282
283	/* information on what to do with a reply when it is received
284	   asyncronously. If this is not setup when a reply is received then
285	   the reply is discarded
286
287	   The private pointer is private to the caller of the client
288	   library (the application), not private to the library
289	*/
290	struct {
291		void (*fn)(struct smbcli_request *);
292		void *private_data;
293	} async;
294};
295
296/* useful way of catching wct errors with file and line number */
297#define SMBCLI_CHECK_MIN_WCT(req, wcount) if ((req)->in.wct < (wcount)) { \
298      DEBUG(1,("Unexpected WCT %d at %s(%d) - expected min %d\n", (req)->in.wct, __FILE__, __LINE__, wcount)); \
299      req->status = NT_STATUS_INVALID_PARAMETER; \
300      goto failed; \
301}
302
303#define SMBCLI_CHECK_WCT(req, wcount) if ((req)->in.wct != (wcount)) { \
304      DEBUG(1,("Unexpected WCT %d at %s(%d) - expected %d\n", (req)->in.wct, __FILE__, __LINE__, wcount)); \
305      req->status = NT_STATUS_INVALID_PARAMETER; \
306      goto failed; \
307}
308
309#include "libcli/raw/interfaces.h"
310
311NTSTATUS smb_raw_read_recv(struct smbcli_request *req, union smb_read *parms);
312struct smbcli_request *smb_raw_read_send(struct smbcli_tree *tree, union smb_read *parms);
313NTSTATUS smb_raw_trans_recv(struct smbcli_request *req,
314			     TALLOC_CTX *mem_ctx,
315			     struct smb_trans2 *parms);
316size_t smb_raw_max_trans_data(struct smbcli_tree *tree, size_t param_size);
317struct smbcli_request *smb_raw_trans_send(struct smbcli_tree *tree, struct smb_trans2 *parms);
318NTSTATUS smbcli_request_destroy(struct smbcli_request *req);
319struct smbcli_request *smb_raw_write_send(struct smbcli_tree *tree, union smb_write *parms);
320struct smbcli_request *smb_raw_close_send(struct smbcli_tree *tree, union smb_close *parms);
321NTSTATUS smb_raw_open_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, union smb_open *parms);
322struct smbcli_request *smb_raw_open_send(struct smbcli_tree *tree, union smb_open *parms);
323
324bool smbcli_transport_process(struct smbcli_transport *transport);
325const char *smbcli_errstr(struct smbcli_tree *tree);
326NTSTATUS smb_raw_fsinfo(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_fsinfo *fsinfo);
327NTSTATUS smb_raw_pathinfo(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_fileinfo *parms);
328NTSTATUS smb_raw_shadow_data(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, struct smb_shadow_copy *info);
329NTSTATUS smb_raw_fileinfo(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_fileinfo *parms);
330struct smbcli_tree *smbcli_tree_init(struct smbcli_session *session, TALLOC_CTX *parent_ctx, bool primary);
331NTSTATUS smb_raw_tcon(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_tcon *parms);
332void smbcli_oplock_handler(struct smbcli_transport *transport,
333			bool (*handler)(struct smbcli_transport *, uint16_t, uint16_t, uint8_t, void *),
334			void *private_data);
335void smbcli_transport_idle_handler(struct smbcli_transport *transport,
336				   void (*idle_func)(struct smbcli_transport *, void *),
337				   uint64_t period,
338				   void *private_data);
339NTSTATUS smbcli_request_simple_recv(struct smbcli_request *req);
340bool smbcli_oplock_ack(struct smbcli_tree *tree, uint16_t fnum, uint16_t ack_level);
341NTSTATUS smb_raw_open(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_open *parms);
342NTSTATUS smb_raw_close(struct smbcli_tree *tree, union smb_close *parms);
343NTSTATUS smb_raw_unlink(struct smbcli_tree *tree, union smb_unlink *parms);
344NTSTATUS smb_raw_chkpath(struct smbcli_tree *tree, union smb_chkpath *parms);
345NTSTATUS smb_raw_mkdir(struct smbcli_tree *tree, union smb_mkdir *parms);
346NTSTATUS smb_raw_rmdir(struct smbcli_tree *tree, struct smb_rmdir *parms);
347NTSTATUS smb_raw_rename(struct smbcli_tree *tree, union smb_rename *parms);
348NTSTATUS smb_raw_seek(struct smbcli_tree *tree, union smb_seek *parms);
349NTSTATUS smb_raw_read(struct smbcli_tree *tree, union smb_read *parms);
350NTSTATUS smb_raw_write(struct smbcli_tree *tree, union smb_write *parms);
351NTSTATUS smb_raw_lock(struct smbcli_tree *tree, union smb_lock *parms);
352NTSTATUS smb_raw_setpathinfo(struct smbcli_tree *tree, union smb_setfileinfo *parms);
353NTSTATUS smb_raw_setfileinfo(struct smbcli_tree *tree, union smb_setfileinfo *parms);
354
355struct smbcli_request *smb_raw_changenotify_send(struct smbcli_tree *tree, union smb_notify *parms);
356NTSTATUS smb_raw_changenotify_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, union smb_notify *parms);
357
358NTSTATUS smb_tree_disconnect(struct smbcli_tree *tree);
359NTSTATUS smbcli_nt_error(struct smbcli_tree *tree);
360NTSTATUS smb_raw_exit(struct smbcli_session *session);
361NTSTATUS smb_raw_pathinfo_recv(struct smbcli_request *req,
362			       TALLOC_CTX *mem_ctx,
363			       union smb_fileinfo *parms);
364struct smbcli_request *smb_raw_pathinfo_send(struct smbcli_tree *tree,
365					     union smb_fileinfo *parms);
366struct smbcli_request *smb_raw_setpathinfo_send(struct smbcli_tree *tree,
367					     union smb_setfileinfo *parms);
368struct smbcli_request *smb_raw_echo_send(struct smbcli_transport *transport,
369					 struct smb_echo *p);
370NTSTATUS 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);
374NTSTATUS smb_raw_flush(struct smbcli_tree *tree, union smb_flush *parms);
375
376NTSTATUS smb_raw_trans(struct smbcli_tree *tree,
377		       TALLOC_CTX *mem_ctx,
378		       struct smb_trans2 *parms);
379
380struct 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);
385void smbcli_sock_dead(struct smbcli_socket *sock);
386
387#endif /* __LIBCLI_RAW__H__ */
388