ntvfs proxy module rollup REWORK ME
[Samba/vfs_proxy.git] / source4 / ntvfs / ntvfs.h
blobf688faea1bc8669e4ef8d3067ceca4f61613f55a
1 /*
2 Unix SMB/CIFS implementation.
3 NTVFS structures and defines
4 Copyright (C) Andrew Tridgell 2003
5 Copyright (C) Stefan Metzmacher 2004
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.
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.
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/>.
21 #ifndef _NTVFS_H_
22 #define _NTVFS_H_
24 #include "libcli/raw/interfaces.h"
25 #include "param/share.h"
26 #include "librpc/gen_ndr/security.h"
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
32 struct ntvfs_module_context;
33 struct ntvfs_request;
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 The values 1..3 match the SMB2 SMB2_SHARE_TYPE_* values
40 enum ntvfs_type {NTVFS_DISK=1, NTVFS_IPC=2, NTVFS_PRINT=3};
42 /* the ntvfs operations structure - contains function pointers to
43 the backend implementations of each operation */
44 struct ntvfs_ops {
45 const char *name;
46 enum ntvfs_type type;
48 /* initial setup */
49 NTSTATUS (*connect)(struct ntvfs_module_context *ntvfs,
50 struct ntvfs_request *req,
51 const char *sharename);
52 NTSTATUS (*disconnect)(struct ntvfs_module_context *ntvfs);
54 /* async_setup - called when a backend is processing a async request */
55 NTSTATUS (*async_setup)(struct ntvfs_module_context *ntvfs,
56 struct ntvfs_request *req,
57 void *private);
59 /* filesystem operations */
60 NTSTATUS (*fsinfo)(struct ntvfs_module_context *ntvfs,
61 struct ntvfs_request *req,
62 union smb_fsinfo *fs);
64 /* path operations */
65 NTSTATUS (*unlink)(struct ntvfs_module_context *ntvfs,
66 struct ntvfs_request *req,
67 union smb_unlink *unl);
68 NTSTATUS (*chkpath)(struct ntvfs_module_context *ntvfs,
69 struct ntvfs_request *req,
70 union smb_chkpath *cp);
71 NTSTATUS (*qpathinfo)(struct ntvfs_module_context *ntvfs,
72 struct ntvfs_request *req,
73 union smb_fileinfo *st);
74 NTSTATUS (*setpathinfo)(struct ntvfs_module_context *ntvfs,
75 struct ntvfs_request *req,
76 union smb_setfileinfo *st);
77 NTSTATUS (*mkdir)(struct ntvfs_module_context *ntvfs,
78 struct ntvfs_request *req,
79 union smb_mkdir *md);
80 NTSTATUS (*rmdir)(struct ntvfs_module_context *ntvfs,
81 struct ntvfs_request *req,
82 struct smb_rmdir *rd);
83 NTSTATUS (*rename)(struct ntvfs_module_context *ntvfs,
84 struct ntvfs_request *req,
85 union smb_rename *ren);
86 NTSTATUS (*copy)(struct ntvfs_module_context *ntvfs,
87 struct ntvfs_request *req,
88 struct smb_copy *cp);
89 NTSTATUS (*open)(struct ntvfs_module_context *ntvfs,
90 struct ntvfs_request *req,
91 union smb_open *oi);
93 /* directory search */
94 NTSTATUS (*search_first)(struct ntvfs_module_context *ntvfs,
95 struct ntvfs_request *req,
96 union smb_search_first *io, void *private,
97 bool (*callback)(void *private, const union smb_search_data *file));
98 NTSTATUS (*search_next)(struct ntvfs_module_context *ntvfs,
99 struct ntvfs_request *req,
100 union smb_search_next *io, void *private,
101 bool (*callback)(void *private, const union smb_search_data *file));
102 NTSTATUS (*search_close)(struct ntvfs_module_context *ntvfs,
103 struct ntvfs_request *req,
104 union smb_search_close *io);
106 /* operations on open files */
107 NTSTATUS (*ioctl)(struct ntvfs_module_context *ntvfs,
108 struct ntvfs_request *req,
109 union smb_ioctl *io);
110 NTSTATUS (*read)(struct ntvfs_module_context *ntvfs,
111 struct ntvfs_request *req,
112 union smb_read *io);
113 NTSTATUS (*write)(struct ntvfs_module_context *ntvfs,
114 struct ntvfs_request *req,
115 union smb_write *io);
116 NTSTATUS (*seek)(struct ntvfs_module_context *ntvfs,
117 struct ntvfs_request *req,
118 union smb_seek *io);
119 NTSTATUS (*flush)(struct ntvfs_module_context *ntvfs,
120 struct ntvfs_request *req,
121 union smb_flush *flush);
122 NTSTATUS (*lock)(struct ntvfs_module_context *ntvfs,
123 struct ntvfs_request *req,
124 union smb_lock *lck);
125 NTSTATUS (*qfileinfo)(struct ntvfs_module_context *ntvfs,
126 struct ntvfs_request *req,
127 union smb_fileinfo *info);
128 NTSTATUS (*setfileinfo)(struct ntvfs_module_context *ntvfs,
129 struct ntvfs_request *req,
130 union smb_setfileinfo *info);
131 NTSTATUS (*close)(struct ntvfs_module_context *ntvfs,
132 struct ntvfs_request *req,
133 union smb_close *io);
135 /* trans interface - used by IPC backend for pipes and RAP calls */
136 NTSTATUS (*trans)(struct ntvfs_module_context *ntvfs,
137 struct ntvfs_request *req,
138 struct smb_trans2 *trans);
140 /* trans2 interface - only used by CIFS backend to prover complete passthru for testing */
141 NTSTATUS (*trans2)(struct ntvfs_module_context *ntvfs,
142 struct ntvfs_request *req,
143 struct smb_trans2 *trans2);
145 /* change notify request */
146 NTSTATUS (*notify)(struct ntvfs_module_context *ntvfs,
147 struct ntvfs_request *req,
148 union smb_notify *info);
150 /* cancel - cancels any pending async request */
151 NTSTATUS (*cancel)(struct ntvfs_module_context *ntvfs,
152 struct ntvfs_request *req);
154 /* printing specific operations */
155 NTSTATUS (*lpq)(struct ntvfs_module_context *ntvfs,
156 struct ntvfs_request *req,
157 union smb_lpq *lpq);
159 /* logoff - called when a vuid is closed */
160 NTSTATUS (*logoff)(struct ntvfs_module_context *ntvfs,
161 struct ntvfs_request *req);
162 NTSTATUS (*exit)(struct ntvfs_module_context *ntvfs,
163 struct ntvfs_request *req);
166 struct ntvfs_module_context {
167 struct ntvfs_module_context *prev, *next;
168 struct ntvfs_context *ctx;
169 int depth;
170 const struct ntvfs_ops *ops;
171 void *private_data;
174 struct ntvfs_context {
175 enum ntvfs_type type;
177 /* the reported filesystem type */
178 char *fs_type;
180 /* the reported device type */
181 char *dev_type;
183 enum protocol_types protocol;
186 * client capabilities
187 * this field doesn't use protocol specific
188 * values!
190 #define NTVFS_CLIENT_CAP_LEVEL_II_OPLOCKS 0x0000000000000001LLU
191 uint64_t client_caps;
194 * linked list of module contexts
196 struct ntvfs_module_context *modules;
198 struct share_config *config;
200 struct server_id server_id;
201 struct loadparm_context *lp_ctx;
202 struct event_context *event_ctx;
203 struct messaging_context *msg_ctx;
205 struct {
206 void *private_data;
207 NTSTATUS (*handler)(void *private_data, struct ntvfs_handle *handle, uint8_t level);
208 } oplock;
210 struct {
211 void *private_data;
212 struct socket_address *(*get_my_addr)(void *private_data, TALLOC_CTX *mem_ctx);
213 struct socket_address *(*get_peer_addr)(void *private_data, TALLOC_CTX *mem_ctx);
214 } client;
216 struct {
217 void *private_data;
218 NTSTATUS (*create_new)(void *private_data, struct ntvfs_request *req, struct ntvfs_handle **h);
219 NTSTATUS (*make_valid)(void *private_data, struct ntvfs_handle *h);
220 void (*destroy)(void *private_data, struct ntvfs_handle *h);
221 struct ntvfs_handle *(*search_by_wire_key)(void *private_data, struct ntvfs_request *req, const DATA_BLOB *key);
222 DATA_BLOB (*get_wire_key)(void *private_data, struct ntvfs_handle *handle, TALLOC_CTX *mem_ctx);
223 } handles;
226 /* a set of flags to control handling of request structures */
227 #define NTVFS_ASYNC_STATE_ASYNC (1<<1) /* the backend will answer this one later */
228 #define NTVFS_ASYNC_STATE_MAY_ASYNC (1<<2) /* the backend is allowed to answer async */
229 #define NTVFS_ASYNC_STATE_CLOSE (1<<3) /* the backend session should be closed */
231 /* the ntvfs_async_state structure allows backend functions to
232 delay replying to requests. To use this, the front end must
233 set send_fn to a function to be called by the backend
234 when the reply is finally ready to be sent. The backend
235 must set status to the status it wants in the
236 reply. The backend must set the NTVFS_ASYNC_STATE_ASYNC
237 control_flag on the request to indicate that it wishes to
238 delay the reply
240 If NTVFS_ASYNC_STATE_MAY_ASYNC is not set then the backend cannot
241 ask for a delayed reply for this request
243 note that the private_data pointer is private to the layer which alloced this struct
245 struct ntvfs_async_state {
246 struct ntvfs_async_state *prev, *next;
247 /* the async handling infos */
248 unsigned int state;
249 void *private_data;
250 void (*send_fn)(struct ntvfs_request *);
251 NTSTATUS status;
253 /* the passthru module's per session private data */
254 struct ntvfs_module_context *ntvfs;
257 struct ntvfs_request {
258 /* the ntvfs_context this requests belongs to */
259 struct ntvfs_context *ctx;
261 /* ntvfs per request async states */
262 struct ntvfs_async_state *async_states;
264 /* the session_info, with security_token and maybe delegated credentials */
265 struct auth_session_info *session_info;
267 /* the smb pid is needed for locking contexts */
268 uint32_t smbpid;
271 * client capabilities
272 * this field doesn't use protocol specific
273 * values!
274 * see NTVFS_CLIENT_CAP_*
276 uint64_t client_caps;
278 /* some statictics for the management tools */
279 struct {
280 /* the system time when the request arrived */
281 struct timeval request_time;
282 } statistics;
284 struct {
285 void *private_data;
286 } frontend_data;
289 struct ntvfs_handle {
290 struct ntvfs_context *ctx;
292 struct auth_session_info *session_info;
294 uint16_t smbpid;
296 struct ntvfs_handle_data {
297 struct ntvfs_handle_data *prev, *next;
298 struct ntvfs_module_context *owner;
299 void *private_data;/* this must be a valid talloc pointer */
300 } *backend_data;
302 struct {
303 void *private_data;
304 } frontend_data;
307 /* this structure is used by backends to determine the size of some critical types */
308 struct ntvfs_critical_sizes {
309 int interface_version;
310 int sizeof_ntvfs_critical_sizes;
311 int sizeof_ntvfs_context;
312 int sizeof_ntvfs_module_context;
313 int sizeof_ntvfs_ops;
314 int sizeof_ntvfs_async_state;
315 int sizeof_ntvfs_request;
316 int sizeof_ntvfs_handle;
317 int sizeof_ntvfs_handle_data;
320 #define NTVFS_CURRENT_CRITICAL_SIZES(c) \
321 struct ntvfs_critical_sizes c = { \
322 .interface_version = NTVFS_INTERFACE_VERSION, \
323 .sizeof_ntvfs_critical_sizes = sizeof(struct ntvfs_critical_sizes), \
324 .sizeof_ntvfs_context = sizeof(struct ntvfs_context), \
325 .sizeof_ntvfs_module_context = sizeof(struct ntvfs_module_context), \
326 .sizeof_ntvfs_ops = sizeof(struct ntvfs_ops), \
327 .sizeof_ntvfs_async_state = sizeof(struct ntvfs_async_state), \
328 .sizeof_ntvfs_request = sizeof(struct ntvfs_request), \
329 .sizeof_ntvfs_handle = sizeof(struct ntvfs_handle), \
330 .sizeof_ntvfs_handle_data = sizeof(struct ntvfs_handle_data), \
333 struct messaging_context;
335 /* a second stage function converts from the out parameters of the generic
336 call onto the out parameters of the specific call made */
337 typedef NTSTATUS (*second_stage_t)(struct ntvfs_module_context *,
338 struct ntvfs_request *,
339 void *, void *, NTSTATUS);
342 this structure holds the async state for pending mapped async calls
344 struct ntvfs_map_async {
345 struct ntvfs_module_context *ntvfs;
346 void *io, *io2;
347 second_stage_t fn;
350 _PUBLIC_ NTSTATUS ntvfs_map_async_setup(struct ntvfs_module_context *ntvfs,
351 struct ntvfs_request *req,
352 void *io, void *io2,
353 second_stage_t fn);
354 _PUBLIC_ NTSTATUS ntvfs_map_async_finish(struct ntvfs_request *req, NTSTATUS status);
356 #include "librpc/gen_ndr/security.h"
357 #include "librpc/gen_ndr/notify.h"
358 #include "ntvfs/ntvfs_proto.h"
360 #endif /* _NTVFS_H_ */