opendb_tdb: pass down struct messaging_context directly to odb_oplock_break_send()
[jelmer/samba4-debian.git] / source / ntvfs / ntvfs.h
1 /* 
2    Unix SMB/CIFS implementation.
3    NTVFS structures and defines
4    Copyright (C) Andrew Tridgell                        2003
5    Copyright (C) Stefan Metzmacher                      2004
6    
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3 of the License, or
10    (at your option) any later version.
11    
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16    
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #ifndef _NTVFS_H_
22 #define _NTVFS_H_
23
24 #include "libcli/raw/interfaces.h"
25 #include "param/share.h"
26
27 /* modules can use the following to determine if the interface has changed */
28 /* version 1 -> 0 - make module stacking easier -- metze */
29 #define NTVFS_INTERFACE_VERSION 0
30
31 struct ntvfs_module_context;
32 struct ntvfs_request;
33
34 /* each backend has to be one one of the following 3 basic types. In
35    earlier versions of Samba backends needed to handle all types, now
36    we implement them separately.
37    The values 1..3 match the SMB2 SMB2_SHARE_TYPE_* values
38  */
39 enum ntvfs_type {NTVFS_DISK=1, NTVFS_IPC=2, NTVFS_PRINT=3};
40
41 /* the ntvfs operations structure - contains function pointers to 
42    the backend implementations of each operation */
43 struct ntvfs_ops {
44         const char *name;
45         enum ntvfs_type type;
46
47         /* initial setup */
48         NTSTATUS (*connect)(struct ntvfs_module_context *ntvfs,
49                             struct ntvfs_request *req,
50                             const char *sharename);
51         NTSTATUS (*disconnect)(struct ntvfs_module_context *ntvfs);
52
53         /* async_setup - called when a backend is processing a async request */
54         NTSTATUS (*async_setup)(struct ntvfs_module_context *ntvfs,
55                                 struct ntvfs_request *req,
56                                 void *private);
57
58         /* filesystem operations */
59         NTSTATUS (*fsinfo)(struct ntvfs_module_context *ntvfs,
60                            struct ntvfs_request *req,
61                            union smb_fsinfo *fs);
62
63         /* path operations */
64         NTSTATUS (*unlink)(struct ntvfs_module_context *ntvfs,
65                            struct ntvfs_request *req,
66                            union smb_unlink *unl);
67         NTSTATUS (*chkpath)(struct ntvfs_module_context *ntvfs,
68                             struct ntvfs_request *req,
69                             union smb_chkpath *cp);
70         NTSTATUS (*qpathinfo)(struct ntvfs_module_context *ntvfs,
71                               struct ntvfs_request *req,
72                               union smb_fileinfo *st);
73         NTSTATUS (*setpathinfo)(struct ntvfs_module_context *ntvfs,
74                                 struct ntvfs_request *req,
75                                 union smb_setfileinfo *st);
76         NTSTATUS (*mkdir)(struct ntvfs_module_context *ntvfs,
77                           struct ntvfs_request *req,
78                           union smb_mkdir *md);
79         NTSTATUS (*rmdir)(struct ntvfs_module_context *ntvfs,
80                           struct ntvfs_request *req,
81                           struct smb_rmdir *rd);
82         NTSTATUS (*rename)(struct ntvfs_module_context *ntvfs,
83                            struct ntvfs_request *req,
84                            union smb_rename *ren);
85         NTSTATUS (*copy)(struct ntvfs_module_context *ntvfs,
86                          struct ntvfs_request *req,
87                          struct smb_copy *cp);
88         NTSTATUS (*open)(struct ntvfs_module_context *ntvfs,
89                          struct ntvfs_request *req,
90                          union smb_open *oi);
91
92         /* directory search */
93         NTSTATUS (*search_first)(struct ntvfs_module_context *ntvfs,
94                                  struct ntvfs_request *req,
95                                  union smb_search_first *io, void *private,
96                                  bool (*callback)(void *private, const union smb_search_data *file));
97         NTSTATUS (*search_next)(struct ntvfs_module_context *ntvfs,
98                                 struct ntvfs_request *req,
99                                 union smb_search_next *io, void *private,
100                                 bool (*callback)(void *private, const union smb_search_data *file));
101         NTSTATUS (*search_close)(struct ntvfs_module_context *ntvfs,
102                                  struct ntvfs_request *req,
103                                  union smb_search_close *io);
104
105         /* operations on open files */
106         NTSTATUS (*ioctl)(struct ntvfs_module_context *ntvfs,
107                           struct ntvfs_request *req,
108                           union smb_ioctl *io);
109         NTSTATUS (*read)(struct ntvfs_module_context *ntvfs,
110                          struct ntvfs_request *req,
111                          union smb_read *io);
112         NTSTATUS (*write)(struct ntvfs_module_context *ntvfs,
113                           struct ntvfs_request *req,
114                           union smb_write *io);
115         NTSTATUS (*seek)(struct ntvfs_module_context *ntvfs,
116                          struct ntvfs_request *req,
117                          union smb_seek *io);
118         NTSTATUS (*flush)(struct ntvfs_module_context *ntvfs,
119                           struct ntvfs_request *req,
120                           union smb_flush *flush);
121         NTSTATUS (*lock)(struct ntvfs_module_context *ntvfs,
122                          struct ntvfs_request *req,
123                          union smb_lock *lck);
124         NTSTATUS (*qfileinfo)(struct ntvfs_module_context *ntvfs,
125                               struct ntvfs_request *req,
126                               union smb_fileinfo *info);
127         NTSTATUS (*setfileinfo)(struct ntvfs_module_context *ntvfs,
128                                 struct ntvfs_request *req,
129                                 union smb_setfileinfo *info);
130         NTSTATUS (*close)(struct ntvfs_module_context *ntvfs,
131                           struct ntvfs_request *req,
132                           union smb_close *io);
133
134         /* trans interface - used by IPC backend for pipes and RAP calls */
135         NTSTATUS (*trans)(struct ntvfs_module_context *ntvfs,
136                           struct ntvfs_request *req,
137                           struct smb_trans2 *trans);
138
139         /* trans2 interface - only used by CIFS backend to prover complete passthru for testing */
140         NTSTATUS (*trans2)(struct ntvfs_module_context *ntvfs,
141                            struct ntvfs_request *req,
142                            struct smb_trans2 *trans2);
143
144         /* change notify request */
145         NTSTATUS (*notify)(struct ntvfs_module_context *ntvfs,
146                            struct ntvfs_request *req,
147                            union smb_notify *info);
148
149         /* cancel - cancels any pending async request */
150         NTSTATUS (*cancel)(struct ntvfs_module_context *ntvfs,
151                            struct ntvfs_request *req);
152
153         /* printing specific operations */
154         NTSTATUS (*lpq)(struct ntvfs_module_context *ntvfs, 
155                         struct ntvfs_request *req,
156                         union smb_lpq *lpq);
157
158         /* logoff - called when a vuid is closed */
159         NTSTATUS (*logoff)(struct ntvfs_module_context *ntvfs,
160                            struct ntvfs_request *req);
161         NTSTATUS (*exit)(struct ntvfs_module_context *ntvfs,
162                          struct ntvfs_request *req);
163 };
164
165 struct ntvfs_module_context {
166         struct ntvfs_module_context *prev, *next;
167         struct ntvfs_context *ctx;
168         int depth;
169         const struct ntvfs_ops *ops;
170         void *private_data;
171 };
172
173 struct ntvfs_context {
174         enum ntvfs_type type;
175
176         /* the reported filesystem type */
177         char *fs_type;
178
179         /* the reported device type */
180         char *dev_type;
181
182         enum protocol_types protocol;
183
184         /*
185          * client capabilities
186          * this field doesn't use protocol specific
187          * values!
188          */
189 #define NTVFS_CLIENT_CAP_LEVEL_II_OPLOCKS       0x0000000000000001LLU
190         uint64_t client_caps;
191
192         /* 
193          * linked list of module contexts
194          */
195         struct ntvfs_module_context *modules;
196
197         struct share_config *config;
198
199         struct server_id server_id;
200         struct loadparm_context *lp_ctx;
201         struct event_context *event_ctx;
202         struct messaging_context *msg_ctx;
203
204         struct {
205                 void *private_data;
206                 NTSTATUS (*handler)(void *private_data, struct ntvfs_handle *handle, uint8_t level);
207         } oplock;
208
209         struct {
210                 void *private_data;
211                 struct socket_address *(*get_my_addr)(void *private_data, TALLOC_CTX *mem_ctx);
212                 struct socket_address *(*get_peer_addr)(void *private_data, TALLOC_CTX *mem_ctx);
213         } client;
214
215         struct {
216                 void *private_data;
217                 NTSTATUS (*create_new)(void *private_data, struct ntvfs_request *req, struct ntvfs_handle **h);
218                 NTSTATUS (*make_valid)(void *private_data, struct ntvfs_handle *h);
219                 void (*destroy)(void *private_data, struct ntvfs_handle *h);
220                 struct ntvfs_handle *(*search_by_wire_key)(void *private_data,  struct ntvfs_request *req, const DATA_BLOB *key);
221                 DATA_BLOB (*get_wire_key)(void *private_data, struct ntvfs_handle *handle, TALLOC_CTX *mem_ctx);
222         } handles;
223 };
224
225 /* a set of flags to control handling of request structures */
226 #define NTVFS_ASYNC_STATE_ASYNC     (1<<1) /* the backend will answer this one later */
227 #define NTVFS_ASYNC_STATE_MAY_ASYNC (1<<2) /* the backend is allowed to answer async */
228
229 /* the ntvfs_async_state structure allows backend functions to 
230    delay replying to requests. To use this, the front end must
231    set send_fn to a function to be called by the backend
232    when the reply is finally ready to be sent. The backend
233    must set status to the status it wants in the
234    reply. The backend must set the NTVFS_ASYNC_STATE_ASYNC
235    control_flag on the request to indicate that it wishes to
236    delay the reply
237
238    If NTVFS_ASYNC_STATE_MAY_ASYNC is not set then the backend cannot
239    ask for a delayed reply for this request
240
241    note that the private_data pointer is private to the layer which alloced this struct
242 */
243 struct ntvfs_async_state {
244         struct ntvfs_async_state *prev, *next;
245         /* the async handling infos */
246         unsigned int state;
247         void *private_data;
248         void (*send_fn)(struct ntvfs_request *);
249         NTSTATUS status;
250
251         /* the passthru module's per session private data */
252         struct ntvfs_module_context *ntvfs;
253 };
254
255 struct ntvfs_request {
256         /* the ntvfs_context this requests belongs to */
257         struct ntvfs_context *ctx;
258
259         /* ntvfs per request async states */
260         struct ntvfs_async_state *async_states;
261
262         /* the session_info, with security_token and maybe delegated credentials */
263         struct auth_session_info *session_info;
264
265         /* the smb pid is needed for locking contexts */
266         uint16_t smbpid;
267
268         /*
269          * client capabilities
270          * this field doesn't use protocol specific
271          * values!
272          * see NTVFS_CLIENT_CAP_*
273          */
274         uint64_t client_caps;
275
276         /* some statictics for the management tools */
277         struct {
278                 /* the system time when the request arrived */
279                 struct timeval request_time;
280         } statistics;
281
282         struct {
283                 void *private_data;
284         } frontend_data;
285 };
286
287 struct ntvfs_handle {
288         struct ntvfs_context *ctx;
289
290         struct auth_session_info *session_info;
291
292         uint16_t smbpid;
293
294         struct ntvfs_handle_data {
295                 struct ntvfs_handle_data *prev, *next;
296                 struct ntvfs_module_context *owner;
297                 void *private_data;/* this must be a valid talloc pointer */
298         } *backend_data;
299
300         struct {
301                 void *private_data;
302         } frontend_data;
303 };
304
305 /* this structure is used by backends to determine the size of some critical types */
306 struct ntvfs_critical_sizes {
307         int interface_version;
308         int sizeof_ntvfs_critical_sizes;
309         int sizeof_ntvfs_context;
310         int sizeof_ntvfs_module_context;
311         int sizeof_ntvfs_ops;
312         int sizeof_ntvfs_async_state;
313         int sizeof_ntvfs_request;
314         int sizeof_ntvfs_handle;
315         int sizeof_ntvfs_handle_data;
316 };
317
318 #define NTVFS_CURRENT_CRITICAL_SIZES(c) \
319     struct ntvfs_critical_sizes c = { \
320         .interface_version              = NTVFS_INTERFACE_VERSION, \
321         .sizeof_ntvfs_critical_sizes    = sizeof(struct ntvfs_critical_sizes), \
322         .sizeof_ntvfs_context           = sizeof(struct ntvfs_context), \
323         .sizeof_ntvfs_module_context    = sizeof(struct ntvfs_module_context), \
324         .sizeof_ntvfs_ops               = sizeof(struct ntvfs_ops), \
325         .sizeof_ntvfs_async_state       = sizeof(struct ntvfs_async_state), \
326         .sizeof_ntvfs_request           = sizeof(struct ntvfs_request), \
327         .sizeof_ntvfs_handle            = sizeof(struct ntvfs_handle), \
328         .sizeof_ntvfs_handle_data       = sizeof(struct ntvfs_handle_data), \
329     }
330
331 struct messaging_context;
332 #include "librpc/gen_ndr/security.h"
333 #include "librpc/gen_ndr/notify.h"
334 #include "ntvfs/ntvfs_proto.h"
335
336 #endif /* _NTVFS_H_ */