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