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