r14511: Install more headers
[samba.git] / source4 / libcli / raw / libcliraw.h
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 2 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, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #ifndef __LIBCLI_RAW_H__
24 #define __LIBCLI_RAW_H__
25
26 #include "libcli/raw/request.h"
27 #include "librpc/gen_ndr/nbt.h"
28
29 struct smbcli_tree;  /* forward declare */
30 struct smbcli_request;  /* forward declare */
31 struct smbcli_session;  /* forward declare */
32 struct smbcli_transport;  /* forward declare */
33
34 /* default timeout for all smb requests */
35 #define SMB_REQUEST_TIMEOUT 60
36
37 /* context that will be and has been negotiated between the client and server */
38 struct smbcli_negotiate {
39         /* 
40          * negotiated maximum transmit size - this is given to us by the server
41          */
42         uint32_t max_xmit;
43
44         /* maximum number of requests that can be multiplexed */
45         uint16_t max_mux;
46
47         /* the negotiatiated protocol */
48         enum protocol_types protocol;
49
50         uint8_t sec_mode;               /* security mode returned by negprot */
51         uint8_t key_len;
52         DATA_BLOB server_guid;      /* server_guid */
53         DATA_BLOB secblob;      /* cryptkey or negTokenInit blob */
54         uint32_t sesskey;
55         
56         struct smb_signing_context sign_info;
57
58         /* capabilities that the server reported */
59         uint32_t capabilities;
60         
61         int server_zone;
62         time_t server_time;
63         uint_t readbraw_supported:1;
64         uint_t writebraw_supported:1;
65
66         char *server_domain;
67 };
68         
69 /* this is the context for a SMB socket associated with the socket itself */
70 struct smbcli_socket {
71         struct socket_context *sock;
72
73         /* what port we ended up connected to */
74         int port;
75
76         /* the hostname we connected to */
77         const char *hostname;
78
79         /* the event handle for waiting for socket IO */
80         struct {
81                 struct event_context *ctx;
82                 struct fd_event *fde;
83                 struct timed_event *te;
84         } event;
85 };
86
87 /*
88   this structure allows applications to control the behaviour of the
89   client library
90 */
91 struct smbcli_options {
92         uint_t use_oplocks:1;
93         uint_t use_level2_oplocks:1;
94         uint_t use_spnego:1;
95         uint32_t max_xmit;
96         uint16_t max_mux;
97         int request_timeout;
98 };
99
100 /* this is the context for the client transport layer */
101 struct smbcli_transport {
102         /* socket level info */
103         struct smbcli_socket *socket;
104
105         /* the next mid to be allocated - needed for signing and
106            request matching */
107         uint16_t next_mid;
108         
109         /* negotiated protocol information */
110         struct smbcli_negotiate negotiate;
111
112         /* options to control the behaviour of the client code */
113         struct smbcli_options options;
114
115         /* is a readbraw pending? we need to handle that case
116            specially on receiving packets */
117         uint_t readbraw_pending:1;
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;
125                 uint_t period;
126         } idle;
127
128         /* the error fields from the last message */
129         struct {
130                 enum {ETYPE_NONE, ETYPE_SMB, ETYPE_SOCKET, ETYPE_NBT} etype;
131                 union {
132                         NTSTATUS nt_status;
133                         enum {SOCKET_READ_TIMEOUT,
134                               SOCKET_READ_EOF,
135                               SOCKET_READ_ERROR,
136                               SOCKET_WRITE_ERROR,
137                               SOCKET_READ_BAD_SIG} socket_error;
138                         uint_t nbt_error;
139                 } e;
140         } error;
141
142         struct {
143                 /* a oplock break request handler */
144                 BOOL (*handler)(struct smbcli_transport *transport, 
145                                 uint16_t tid, uint16_t fnum, uint8_t level, void *private);
146                 /* private data passed to the oplock handler */
147                 void *private;
148         } oplock;
149
150         /* a list of async requests that are pending for receive on this connection */
151         struct smbcli_request *pending_recv;
152
153         /* remember the called name - some sub-protocols require us to
154            know the server name */
155         struct nbt_name called;
156
157         /* context of the stream -> packet parser */
158         struct packet_context *packet;
159 };
160
161 /* this is the context for the user */
162
163 /* this is the context for the session layer */
164 struct smbcli_session { 
165         /* transport layer info */
166         struct smbcli_transport *transport;
167         
168         /* after a session setup the server provides us with
169            a vuid identifying the security context */
170         uint16_t vuid;
171
172         /* default pid for this session */
173         uint32_t pid;
174
175         /* the flags2 for each packet - this allows
176            the user to control these for torture testing */
177         uint16_t flags2;
178
179         DATA_BLOB user_session_key;
180
181         /* the spnego context if we use extented security */
182         struct gensec_security *gensec;
183 };
184
185 /* 
186    smbcli_tree context: internal state for a tree connection. 
187  */
188 struct smbcli_tree {
189         /* session layer info */
190         struct smbcli_session *session;
191
192         uint16_t tid;                   /* tree id, aka cnum */
193         char *device;
194         char *fs_type;
195 };
196
197
198 /*
199   a client request moves between the following 4 states.
200 */
201 enum smbcli_request_state {SMBCLI_REQUEST_INIT, /* we are creating the request */
202                         SMBCLI_REQUEST_RECV, /* we are waiting for a matching reply */
203                         SMBCLI_REQUEST_DONE, /* the request is finished */
204                         SMBCLI_REQUEST_ERROR}; /* a packet or transport level error has occurred */
205
206 /* the context for a single SMB request. This is passed to any request-context 
207  * functions (similar to context.h, the server version).
208  * This will allow requests to be multi-threaded. */
209 struct smbcli_request {
210         /* allow a request to be part of a list of requests */
211         struct smbcli_request *next, *prev;
212
213         /* each request is in one of 4 possible states */
214         enum smbcli_request_state state;
215         
216         /* a request always has a transport context, nearly always has
217            a session context and usually has a tree context */
218         struct smbcli_transport *transport;
219         struct smbcli_session *session;
220         struct smbcli_tree *tree;
221
222         /* the flags2 from the SMB request, in raw form (host byte
223            order). Used to parse strings */
224         uint16_t flags2;
225
226         /* the NT status for this request. Set by packet receive code
227            or code detecting error. */
228         NTSTATUS status;
229         
230         /* the sequence number of this packet - used for signing */
231         uint_t seq_num;
232
233         /* list of ntcancel request for this requests */
234         struct smbcli_request *ntcancel;
235
236         /* set if this is a one-way request, meaning we are not
237            expecting a reply from the server. */
238         uint_t one_way_request:1;
239
240         /* set this when the request should only increment the signing
241            counter by one */
242         uint_t sign_single_increment:1;
243
244         /* the mid of this packet - used to match replies */
245         uint16_t mid;
246
247         struct request_buffer in;
248         struct request_buffer out;
249
250         /* information on what to do with a reply when it is received
251            asyncronously. If this is not setup when a reply is received then
252            the reply is discarded
253
254            The private pointer is private to the caller of the client
255            library (the application), not private to the library
256         */
257         struct {
258                 void (*fn)(struct smbcli_request *);
259                 void *private;
260         } async;
261 };
262
263 /* useful way of catching wct errors with file and line number */
264 #define SMBCLI_CHECK_MIN_WCT(req, wcount) if ((req)->in.wct < (wcount)) { \
265       DEBUG(1,("Unexpected WCT %d at %s(%d) - expected min %d\n", (req)->in.wct, __FILE__, __LINE__, wcount)); \
266       req->status = NT_STATUS_INVALID_PARAMETER; \
267       goto failed; \
268 }
269
270 #define SMBCLI_CHECK_WCT(req, wcount) if ((req)->in.wct != (wcount)) { \
271       DEBUG(1,("Unexpected WCT %d at %s(%d) - expected %d\n", (req)->in.wct, __FILE__, __LINE__, wcount)); \
272       req->status = NT_STATUS_INVALID_PARAMETER; \
273       goto failed; \
274 }
275
276 #include "libcli/raw/interfaces.h" 
277 #include "libcli/raw/raw_proto.h"
278
279 #endif /* __LIBCLI_RAW__H__ */