pvfs: send oplock breaks to none to level2 holders on write/lock requests
[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          * linked list of module contexts
186          */
187         struct ntvfs_module_context *modules;
188
189         struct share_config *config;
190
191         struct server_id server_id;
192         struct loadparm_context *lp_ctx;
193         struct event_context *event_ctx;
194         struct messaging_context *msg_ctx;
195
196         struct {
197                 void *private_data;
198                 NTSTATUS (*handler)(void *private_data, struct ntvfs_handle *handle, uint8_t level);
199         } oplock;
200
201         struct {
202                 void *private_data;
203                 struct socket_address *(*get_my_addr)(void *private_data, TALLOC_CTX *mem_ctx);
204                 struct socket_address *(*get_peer_addr)(void *private_data, TALLOC_CTX *mem_ctx);
205         } client;
206
207         struct {
208                 void *private_data;
209                 NTSTATUS (*create_new)(void *private_data, struct ntvfs_request *req, struct ntvfs_handle **h);
210                 NTSTATUS (*make_valid)(void *private_data, struct ntvfs_handle *h);
211                 void (*destroy)(void *private_data, struct ntvfs_handle *h);
212                 struct ntvfs_handle *(*search_by_wire_key)(void *private_data,  struct ntvfs_request *req, const DATA_BLOB *key);
213                 DATA_BLOB (*get_wire_key)(void *private_data, struct ntvfs_handle *handle, TALLOC_CTX *mem_ctx);
214         } handles;
215 };
216
217 /* a set of flags to control handling of request structures */
218 #define NTVFS_ASYNC_STATE_ASYNC     (1<<1) /* the backend will answer this one later */
219 #define NTVFS_ASYNC_STATE_MAY_ASYNC (1<<2) /* the backend is allowed to answer async */
220
221 /* the ntvfs_async_state structure allows backend functions to 
222    delay replying to requests. To use this, the front end must
223    set send_fn to a function to be called by the backend
224    when the reply is finally ready to be sent. The backend
225    must set status to the status it wants in the
226    reply. The backend must set the NTVFS_ASYNC_STATE_ASYNC
227    control_flag on the request to indicate that it wishes to
228    delay the reply
229
230    If NTVFS_ASYNC_STATE_MAY_ASYNC is not set then the backend cannot
231    ask for a delayed reply for this request
232
233    note that the private_data pointer is private to the layer which alloced this struct
234 */
235 struct ntvfs_async_state {
236         struct ntvfs_async_state *prev, *next;
237         /* the async handling infos */
238         unsigned int state;
239         void *private_data;
240         void (*send_fn)(struct ntvfs_request *);
241         NTSTATUS status;
242
243         /* the passthru module's per session private data */
244         struct ntvfs_module_context *ntvfs;
245 };
246
247 struct ntvfs_request {
248         /* the ntvfs_context this requests belongs to */
249         struct ntvfs_context *ctx;
250
251         /* ntvfs per request async states */
252         struct ntvfs_async_state *async_states;
253
254         /* the session_info, with security_token and maybe delegated credentials */
255         struct auth_session_info *session_info;
256
257         /* the smb pid is needed for locking contexts */
258         uint16_t smbpid;
259
260         /* some statictics for the management tools */
261         struct {
262                 /* the system time when the request arrived */
263                 struct timeval request_time;
264         } statistics;
265
266         struct {
267                 void *private_data;
268         } frontend_data;
269 };
270
271 struct ntvfs_handle {
272         struct ntvfs_context *ctx;
273
274         struct auth_session_info *session_info;
275
276         uint16_t smbpid;
277
278         struct ntvfs_handle_data {
279                 struct ntvfs_handle_data *prev, *next;
280                 struct ntvfs_module_context *owner;
281                 void *private_data;/* this must be a valid talloc pointer */
282         } *backend_data;
283
284         struct {
285                 void *private_data;
286         } frontend_data;
287 };
288
289 /* this structure is used by backends to determine the size of some critical types */
290 struct ntvfs_critical_sizes {
291         int interface_version;
292         int sizeof_ntvfs_critical_sizes;
293         int sizeof_ntvfs_context;
294         int sizeof_ntvfs_module_context;
295         int sizeof_ntvfs_ops;
296         int sizeof_ntvfs_async_state;
297         int sizeof_ntvfs_request;
298         int sizeof_ntvfs_handle;
299         int sizeof_ntvfs_handle_data;
300 };
301
302 #define NTVFS_CURRENT_CRITICAL_SIZES(c) \
303     struct ntvfs_critical_sizes c = { \
304         .interface_version              = NTVFS_INTERFACE_VERSION, \
305         .sizeof_ntvfs_critical_sizes    = sizeof(struct ntvfs_critical_sizes), \
306         .sizeof_ntvfs_context           = sizeof(struct ntvfs_context), \
307         .sizeof_ntvfs_module_context    = sizeof(struct ntvfs_module_context), \
308         .sizeof_ntvfs_ops               = sizeof(struct ntvfs_ops), \
309         .sizeof_ntvfs_async_state       = sizeof(struct ntvfs_async_state), \
310         .sizeof_ntvfs_request           = sizeof(struct ntvfs_request), \
311         .sizeof_ntvfs_handle            = sizeof(struct ntvfs_handle), \
312         .sizeof_ntvfs_handle_data       = sizeof(struct ntvfs_handle_data), \
313     }
314
315 struct messaging_context;
316 #include "librpc/gen_ndr/security.h"
317 #include "librpc/gen_ndr/notify.h"
318 #include "ntvfs/ntvfs_proto.h"
319
320 #endif /* _NTVFS_H_ */