2 Unix SMB/CIFS implementation.
3 VFS structures and parameters
4 Copyright (C) Tim Potter 1999
5 Copyright (C) Alexander Bokovoy 2002
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.
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, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 This work was sponsored by Optifacio Software Services, Inc.
27 /* Avoid conflict with an AIX include file */
34 * As we're now (thanks Andrew ! :-) using file_structs and connection
35 * structs in the vfs - then anyone writing a vfs must include includes.h...
39 * This next constant specifies the version number of the VFS interface
40 * this smbd will load. Increment this if *ANY* changes are made to the
44 /* Changed to version 2 for CIFS UNIX extensions (mknod and link added). JRA. */
45 /* Changed to version 3 for POSIX acl extensions. JRA. */
46 /* Changed to version 4 for cascaded VFS interface. Alexander Bokovoy. */
47 /* Changed to version 5 for sendfile addition. JRA. */
48 #define SMB_VFS_INTERFACE_VERSION 5
51 /* Version of supported cascaded interface backward compatibility.
52 (version 5 corresponds to SMB_VFS_INTERFACE_VERSION 5)
53 It is used in vfs_init_custom() to detect VFS modules which conform to cascaded
54 VFS interface but implement elder version than current version of Samba uses.
55 This allows to use old modules with new VFS interface as far as combined VFS operation
56 set is coherent (will be in most cases).
58 #define SMB_VFS_INTERFACE_CASCADED 5
61 Each VFS module must provide following global functions:
62 vfs_init -- initialization function
63 vfs_done -- finalization function
65 vfs_init must return proper initialized vfs_op_tuple[] array
66 which describes all operations this module claims to intercept. This function
67 is called whenever module is loaded into smbd process using sys_dlopen().
69 vfs_init must store somewhere vfs_handle reference if module wants to store per-instance
70 private information for further usage. vfs_handle->data should be used to
71 store such information. Do not try to change other fields in this structure
72 or results likely to be unpredictable.
74 vfs_done must perform finalization of the module. In particular,
75 this function must free vfs_ops structure returned to module from smb_vfs_get_opaque_ops()
76 function if it is used (see below). This function is called whenever module
77 is unloaded from smbd process using sys_dlclose().
80 vfs_op_tuple *vfs_init(const struct vfs_ops *def_vfs_ops,
81 struct smb_vfs_handle_struct *vfs_handle);
82 void vfs_done(connection_struct *conn);
84 All intercepted VFS operations must be declared as static functions inside module source
85 in order to keep smbd namespace unpolluted. See source of skel, audit, and recycle bin
86 example VFS modules for more details.
90 /* VFS operations structure */
92 struct connection_struct
;
94 struct security_descriptor_info
;
100 int (*connect
)(struct connection_struct
*conn
, const char *service
, const char *user
);
101 void (*disconnect
)(struct connection_struct
*conn
);
102 SMB_BIG_UINT (*disk_free
)(struct connection_struct
*conn
, const char *path
, BOOL small_query
, SMB_BIG_UINT
*bsize
,
103 SMB_BIG_UINT
*dfree
, SMB_BIG_UINT
*dsize
);
105 /* Directory operations */
107 DIR *(*opendir
)(struct connection_struct
*conn
, const char *fname
);
108 struct dirent
*(*readdir
)(struct connection_struct
*conn
, DIR *dirp
);
109 int (*mkdir
)(struct connection_struct
*conn
, const char *path
, mode_t mode
);
110 int (*rmdir
)(struct connection_struct
*conn
, const char *path
);
111 int (*closedir
)(struct connection_struct
*conn
, DIR *dir
);
113 /* File operations */
115 int (*open
)(struct connection_struct
*conn
, const char *fname
, int flags
, mode_t mode
);
116 int (*close
)(struct files_struct
*fsp
, int fd
);
117 ssize_t (*read
)(struct files_struct
*fsp
, int fd
, void *data
, size_t n
);
118 ssize_t (*write
)(struct files_struct
*fsp
, int fd
, const void *data
, size_t n
);
119 SMB_OFF_T (*lseek
)(struct files_struct
*fsp
, int filedes
, SMB_OFF_T offset
, int whence
);
120 ssize_t (*sendfile
)(int tofd
, files_struct
*fsp
, int fromfd
, const DATA_BLOB
*header
, SMB_OFF_T offset
, size_t count
);
121 int (*rename
)(struct connection_struct
*conn
, const char *old
, const char *new);
122 int (*fsync
)(struct files_struct
*fsp
, int fd
);
123 int (*stat
)(struct connection_struct
*conn
, const char *fname
, SMB_STRUCT_STAT
*sbuf
);
124 int (*fstat
)(struct files_struct
*fsp
, int fd
, SMB_STRUCT_STAT
*sbuf
);
125 int (*lstat
)(struct connection_struct
*conn
, const char *path
, SMB_STRUCT_STAT
*sbuf
);
126 int (*unlink
)(struct connection_struct
*conn
, const char *path
);
127 int (*chmod
)(struct connection_struct
*conn
, const char *path
, mode_t mode
);
128 int (*fchmod
)(struct files_struct
*fsp
, int fd
, mode_t mode
);
129 int (*chown
)(struct connection_struct
*conn
, const char *path
, uid_t uid
, gid_t gid
);
130 int (*fchown
)(struct files_struct
*fsp
, int fd
, uid_t uid
, gid_t gid
);
131 int (*chdir
)(struct connection_struct
*conn
, const char *path
);
132 char *(*getwd
)(struct connection_struct
*conn
, char *buf
);
133 int (*utime
)(struct connection_struct
*conn
, const char *path
, struct utimbuf
*times
);
134 int (*ftruncate
)(struct files_struct
*fsp
, int fd
, SMB_OFF_T offset
);
135 BOOL (*lock
)(struct files_struct
*fsp
, int fd
, int op
, SMB_OFF_T offset
, SMB_OFF_T count
, int type
);
136 int (*symlink
)(struct connection_struct
*conn
, const char *oldpath
, const char *newpath
);
137 int (*readlink
)(struct connection_struct
*conn
, const char *path
, char *buf
, size_t bufsiz
);
138 int (*link
)(struct connection_struct
*conn
, const char *oldpath
, const char *newpath
);
139 int (*mknod
)(struct connection_struct
*conn
, const char *path
, mode_t mode
, SMB_DEV_T dev
);
140 char *(*realpath
)(struct connection_struct
*conn
, const char *path
, char *resolved_path
);
142 /* NT ACL operations. */
144 size_t (*fget_nt_acl
)(struct files_struct
*fsp
, int fd
, struct security_descriptor_info
**ppdesc
);
145 size_t (*get_nt_acl
)(struct files_struct
*fsp
, const char *name
, struct security_descriptor_info
**ppdesc
);
146 BOOL (*fset_nt_acl
)(struct files_struct
*fsp
, int fd
, uint32 security_info_sent
, struct security_descriptor_info
*psd
);
147 BOOL (*set_nt_acl
)(struct files_struct
*fsp
, const char *name
, uint32 security_info_sent
, struct security_descriptor_info
*psd
);
149 /* POSIX ACL operations. */
151 int (*chmod_acl
)(struct connection_struct
*conn
, const char *name
, mode_t mode
);
152 int (*fchmod_acl
)(struct files_struct
*fsp
, int fd
, mode_t mode
);
154 int (*sys_acl_get_entry
)(struct connection_struct
*conn
, SMB_ACL_T theacl
, int entry_id
, SMB_ACL_ENTRY_T
*entry_p
);
155 int (*sys_acl_get_tag_type
)(struct connection_struct
*conn
, SMB_ACL_ENTRY_T entry_d
, SMB_ACL_TAG_T
*tag_type_p
);
156 int (*sys_acl_get_permset
)(struct connection_struct
*conn
, SMB_ACL_ENTRY_T entry_d
, SMB_ACL_PERMSET_T
*permset_p
);
157 void * (*sys_acl_get_qualifier
)(struct connection_struct
*conn
, SMB_ACL_ENTRY_T entry_d
);
158 SMB_ACL_T (*sys_acl_get_file
)(struct connection_struct
*conn
, const char *path_p
, SMB_ACL_TYPE_T type
);
159 SMB_ACL_T (*sys_acl_get_fd
)(struct files_struct
*fsp
, int fd
);
160 int (*sys_acl_clear_perms
)(struct connection_struct
*conn
, SMB_ACL_PERMSET_T permset
);
161 int (*sys_acl_add_perm
)(struct connection_struct
*conn
, SMB_ACL_PERMSET_T permset
, SMB_ACL_PERM_T perm
);
162 char * (*sys_acl_to_text
)(struct connection_struct
*conn
, SMB_ACL_T theacl
, ssize_t
*plen
);
163 SMB_ACL_T (*sys_acl_init
)(struct connection_struct
*conn
, int count
);
164 int (*sys_acl_create_entry
)(struct connection_struct
*conn
, SMB_ACL_T
*pacl
, SMB_ACL_ENTRY_T
*pentry
);
165 int (*sys_acl_set_tag_type
)(struct connection_struct
*conn
, SMB_ACL_ENTRY_T entry
, SMB_ACL_TAG_T tagtype
);
166 int (*sys_acl_set_qualifier
)(struct connection_struct
*conn
, SMB_ACL_ENTRY_T entry
, void *qual
);
167 int (*sys_acl_set_permset
)(struct connection_struct
*conn
, SMB_ACL_ENTRY_T entry
, SMB_ACL_PERMSET_T permset
);
168 int (*sys_acl_valid
)(struct connection_struct
*conn
, SMB_ACL_T theacl
);
169 int (*sys_acl_set_file
)(struct connection_struct
*conn
, const char *name
, SMB_ACL_TYPE_T acltype
, SMB_ACL_T theacl
);
170 int (*sys_acl_set_fd
)(struct files_struct
*fsp
, int fd
, SMB_ACL_T theacl
);
171 int (*sys_acl_delete_def_file
)(struct connection_struct
*conn
, const char *path
);
172 int (*sys_acl_get_perm
)(struct connection_struct
*conn
, SMB_ACL_PERMSET_T permset
, SMB_ACL_PERM_T perm
);
173 int (*sys_acl_free_text
)(struct connection_struct
*conn
, char *text
);
174 int (*sys_acl_free_acl
)(struct connection_struct
*conn
, SMB_ACL_T posix_acl
);
175 int (*sys_acl_free_qualifier
)(struct connection_struct
*conn
, void *qualifier
, SMB_ACL_TAG_T tagtype
);
179 struct vfs_options
*prev
, *next
;
185 Available VFS operations. These values must be in sync with vfs_ops struct.
186 In particular, if new operations are added to vfs_ops, appropriate constants
187 should be added to vfs_op_type so that order of them kept same as in vfs_ops.
190 typedef enum _vfs_op_type
{
192 SMB_VFS_OP_NOOP
= -1,
194 /* Disk operations */
196 SMB_VFS_OP_CONNECT
= 0,
197 SMB_VFS_OP_DISCONNECT
,
198 SMB_VFS_OP_DISK_FREE
,
200 /* Directory operations */
208 /* File operations */
229 SMB_VFS_OP_FTRUNCATE
,
237 /* NT ACL operations. */
239 SMB_VFS_OP_FGET_NT_ACL
,
240 SMB_VFS_OP_GET_NT_ACL
,
241 SMB_VFS_OP_FSET_NT_ACL
,
242 SMB_VFS_OP_SET_NT_ACL
,
244 /* POSIX ACL operations. */
246 SMB_VFS_OP_CHMOD_ACL
,
247 SMB_VFS_OP_FCHMOD_ACL
,
249 SMB_VFS_OP_SYS_ACL_GET_ENTRY
,
250 SMB_VFS_OP_SYS_ACL_GET_TAG_TYPE
,
251 SMB_VFS_OP_SYS_ACL_GET_PERMSET
,
252 SMB_VFS_OP_SYS_ACL_GET_QUALIFIER
,
253 SMB_VFS_OP_SYS_ACL_GET_FILE
,
254 SMB_VFS_OP_SYS_ACL_GET_FD
,
255 SMB_VFS_OP_SYS_ACL_CLEAR_PERMS
,
256 SMB_VFS_OP_SYS_ACL_ADD_PERM
,
257 SMB_VFS_OP_SYS_ACL_TO_TEXT
,
258 SMB_VFS_OP_SYS_ACL_INIT
,
259 SMB_VFS_OP_SYS_ACL_CREATE_ENTRY
,
260 SMB_VFS_OP_SYS_ACL_SET_TAG_TYPE
,
261 SMB_VFS_OP_SYS_ACL_SET_QUALIFIER
,
262 SMB_VFS_OP_SYS_ACL_SET_PERMSET
,
263 SMB_VFS_OP_SYS_ACL_VALID
,
264 SMB_VFS_OP_SYS_ACL_SET_FILE
,
265 SMB_VFS_OP_SYS_ACL_SET_FD
,
266 SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE
,
267 SMB_VFS_OP_SYS_ACL_GET_PERM
,
268 SMB_VFS_OP_SYS_ACL_FREE_TEXT
,
269 SMB_VFS_OP_SYS_ACL_FREE_ACL
,
270 SMB_VFS_OP_SYS_ACL_FREE_QUALIFIER
,
272 /* This should always be last enum value */
278 Possible VFS operation layers (per-operation)
280 These values are used by VFS subsystem when building vfs_ops for connection
281 from multiple VFS modules. Internally, Samba differentiates only opaque and
282 transparent layers at this process. Other types are used for providing better
283 diagnosing facilities.
285 Most modules will provide transparent layers. Opaque layer is for modules
286 which implement actual file system calls (like DB-based VFS). For example,
287 default POSIX VFS which is built in into Samba is an opaque VFS module.
289 Other layer types (audit, splitter, scanner) were designed to provide different
290 degree of transparency and for diagnosing VFS module behaviour.
292 Each module can implement several layers at the same time provided that only
293 one layer is used per each operation.
297 typedef enum _vfs_op_layer
{
298 SMB_VFS_LAYER_NOOP
= -1, /* - For using in VFS module to indicate end of array */
299 /* of operations description */
300 SMB_VFS_LAYER_OPAQUE
= 0, /* - Final level, does not call anything beyond itself */
301 SMB_VFS_LAYER_TRANSPARENT
, /* - Normal operation, calls underlying layer after */
302 /* possibly changing passed data */
303 SMB_VFS_LAYER_LOGGER
, /* - Logs data, calls underlying layer, logging does not */
305 SMB_VFS_LAYER_SPLITTER
, /* - Splits operation, calls underlying layer _and_ own facility, */
306 /* then combines result */
307 SMB_VFS_LAYER_SCANNER
/* - Checks data and possibly initiates additional */
308 /* file activity like logging to files _inside_ samba VFS */
312 VFS operation description. Each VFS module initialization function returns to VFS subsystem
313 an array of vfs_op_tuple which describes all operations this module is willing to intercept.
314 VFS subsystem initializes then vfs_ops using this information and passes it
315 to next VFS module as underlying vfs_ops and to connection after all VFS modules are initialized.
318 typedef struct _vfs_op_tuple
{
325 Return vfs_ops filled with current opaque VFS operations. This function is designed to
326 be called from VFS module initialization function for those modules which needs 'direct' VFS
327 access (loggers or initiators of file operations other than connection asks for).
329 Returned vfs_ops must be cleaned up in VFS module's finalizer function (vfs_done_<module_name>)
333 struct vfs_ops *smb_vfs_get_opaque_ops();
335 This prototype will be available via include/proto.h