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