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/>.
24 #include "libcli/raw/interfaces.h"
25 #include "param/share.h"
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
31 struct ntvfs_module_context
;
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
39 enum ntvfs_type
{NTVFS_DISK
=1, NTVFS_IPC
=2, NTVFS_PRINT
=3};
41 /* the ntvfs operations structure - contains function pointers to
42 the backend implementations of each operation */
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
);
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
,
58 /* filesystem operations */
59 NTSTATUS (*fsinfo
)(struct ntvfs_module_context
*ntvfs
,
60 struct ntvfs_request
*req
,
61 union smb_fsinfo
*fs
);
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
,
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
,
88 NTSTATUS (*open
)(struct ntvfs_module_context
*ntvfs
,
89 struct ntvfs_request
*req
,
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
);
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
,
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
,
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
);
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
);
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
);
144 /* change notify request */
145 NTSTATUS (*notify
)(struct ntvfs_module_context
*ntvfs
,
146 struct ntvfs_request
*req
,
147 union smb_notify
*info
);
149 /* cancel - cancels any pending async request */
150 NTSTATUS (*cancel
)(struct ntvfs_module_context
*ntvfs
,
151 struct ntvfs_request
*req
);
153 /* printing specific operations */
154 NTSTATUS (*lpq
)(struct ntvfs_module_context
*ntvfs
,
155 struct ntvfs_request
*req
,
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
);
165 struct ntvfs_module_context
{
166 struct ntvfs_module_context
*prev
, *next
;
167 struct ntvfs_context
*ctx
;
169 const struct ntvfs_ops
*ops
;
173 struct ntvfs_context
{
174 enum ntvfs_type type
;
176 /* the reported filesystem type */
179 /* the reported device type */
182 enum protocol_types protocol
;
185 * client capabilities
186 * this field doesn't use protocol specific
189 #define NTVFS_CLIENT_CAP_LEVEL_II_OPLOCKS 0x0000000000000001LLU
190 uint64_t client_caps
;
193 * linked list of module contexts
195 struct ntvfs_module_context
*modules
;
197 struct share_config
*config
;
199 struct server_id server_id
;
200 struct loadparm_context
*lp_ctx
;
201 struct event_context
*event_ctx
;
202 struct messaging_context
*msg_ctx
;
206 NTSTATUS (*handler
)(void *private_data
, struct ntvfs_handle
*handle
, uint8_t level
);
211 struct socket_address
*(*get_my_addr
)(void *private_data
, TALLOC_CTX
*mem_ctx
);
212 struct socket_address
*(*get_peer_addr
)(void *private_data
, TALLOC_CTX
*mem_ctx
);
217 NTSTATUS (*create_new
)(void *private_data
, struct ntvfs_request
*req
, struct ntvfs_handle
**h
);
218 NTSTATUS (*make_valid
)(void *private_data
, struct ntvfs_handle
*h
);
219 void (*destroy
)(void *private_data
, struct ntvfs_handle
*h
);
220 struct ntvfs_handle
*(*search_by_wire_key
)(void *private_data
, struct ntvfs_request
*req
, const DATA_BLOB
*key
);
221 DATA_BLOB (*get_wire_key
)(void *private_data
, struct ntvfs_handle
*handle
, TALLOC_CTX
*mem_ctx
);
225 /* a set of flags to control handling of request structures */
226 #define NTVFS_ASYNC_STATE_ASYNC (1<<1) /* the backend will answer this one later */
227 #define NTVFS_ASYNC_STATE_MAY_ASYNC (1<<2) /* the backend is allowed to answer async */
229 /* the ntvfs_async_state structure allows backend functions to
230 delay replying to requests. To use this, the front end must
231 set send_fn to a function to be called by the backend
232 when the reply is finally ready to be sent. The backend
233 must set status to the status it wants in the
234 reply. The backend must set the NTVFS_ASYNC_STATE_ASYNC
235 control_flag on the request to indicate that it wishes to
238 If NTVFS_ASYNC_STATE_MAY_ASYNC is not set then the backend cannot
239 ask for a delayed reply for this request
241 note that the private_data pointer is private to the layer which alloced this struct
243 struct ntvfs_async_state
{
244 struct ntvfs_async_state
*prev
, *next
;
245 /* the async handling infos */
248 void (*send_fn
)(struct ntvfs_request
*);
251 /* the passthru module's per session private data */
252 struct ntvfs_module_context
*ntvfs
;
255 struct ntvfs_request
{
256 /* the ntvfs_context this requests belongs to */
257 struct ntvfs_context
*ctx
;
259 /* ntvfs per request async states */
260 struct ntvfs_async_state
*async_states
;
262 /* the session_info, with security_token and maybe delegated credentials */
263 struct auth_session_info
*session_info
;
265 /* the smb pid is needed for locking contexts */
269 * client capabilities
270 * this field doesn't use protocol specific
272 * see NTVFS_CLIENT_CAP_*
274 uint64_t client_caps
;
276 /* some statictics for the management tools */
278 /* the system time when the request arrived */
279 struct timeval request_time
;
287 struct ntvfs_handle
{
288 struct ntvfs_context
*ctx
;
290 struct auth_session_info
*session_info
;
294 struct ntvfs_handle_data
{
295 struct ntvfs_handle_data
*prev
, *next
;
296 struct ntvfs_module_context
*owner
;
297 void *private_data
;/* this must be a valid talloc pointer */
305 /* this structure is used by backends to determine the size of some critical types */
306 struct ntvfs_critical_sizes
{
307 int interface_version
;
308 int sizeof_ntvfs_critical_sizes
;
309 int sizeof_ntvfs_context
;
310 int sizeof_ntvfs_module_context
;
311 int sizeof_ntvfs_ops
;
312 int sizeof_ntvfs_async_state
;
313 int sizeof_ntvfs_request
;
314 int sizeof_ntvfs_handle
;
315 int sizeof_ntvfs_handle_data
;
318 #define NTVFS_CURRENT_CRITICAL_SIZES(c) \
319 struct ntvfs_critical_sizes c = { \
320 .interface_version = NTVFS_INTERFACE_VERSION, \
321 .sizeof_ntvfs_critical_sizes = sizeof(struct ntvfs_critical_sizes), \
322 .sizeof_ntvfs_context = sizeof(struct ntvfs_context), \
323 .sizeof_ntvfs_module_context = sizeof(struct ntvfs_module_context), \
324 .sizeof_ntvfs_ops = sizeof(struct ntvfs_ops), \
325 .sizeof_ntvfs_async_state = sizeof(struct ntvfs_async_state), \
326 .sizeof_ntvfs_request = sizeof(struct ntvfs_request), \
327 .sizeof_ntvfs_handle = sizeof(struct ntvfs_handle), \
328 .sizeof_ntvfs_handle_data = sizeof(struct ntvfs_handle_data), \
331 struct messaging_context
;
332 #include "librpc/gen_ndr/security.h"
333 #include "librpc/gen_ndr/notify.h"
334 #include "ntvfs/ntvfs_proto.h"
336 #endif /* _NTVFS_H_ */