2 Unix SMB/CIFS implementation.
6 Copyright (C) Andrew Tridgell 2004
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 this implements most of the POSIX NTVFS backend
24 This is the default backend
28 #include "vfs_posix.h"
29 #include "librpc/gen_ndr/security.h"
30 #include "lib/tdb/include/tdb.h"
32 #include "libcli/security/security.h"
33 #include "lib/events/events.h"
37 setup config options for a posix share
39 static void pvfs_setup_options(struct pvfs_state *pvfs)
41 int snum = pvfs->ntvfs->ctx->config.snum;
44 if (lp_map_hidden(snum)) pvfs->flags |= PVFS_FLAG_MAP_HIDDEN;
45 if (lp_map_archive(snum)) pvfs->flags |= PVFS_FLAG_MAP_ARCHIVE;
46 if (lp_map_system(snum)) pvfs->flags |= PVFS_FLAG_MAP_SYSTEM;
47 if (lp_readonly(snum)) pvfs->flags |= PVFS_FLAG_READONLY;
48 if (lp_strict_sync(snum)) pvfs->flags |= PVFS_FLAG_STRICT_SYNC;
49 if (lp_strict_locking(snum)) pvfs->flags |= PVFS_FLAG_STRICT_LOCKING;
50 if (lp_ci_filesystem(snum)) pvfs->flags |= PVFS_FLAG_CI_FILESYSTEM;
52 if (lp_parm_bool(snum, "posix", "fakeoplocks", False)) {
53 pvfs->flags |= PVFS_FLAG_FAKE_OPLOCKS;
56 /* this must be a power of 2 */
57 pvfs->alloc_size_rounding = lp_parm_int(snum,
58 "posix", "allocationrounding", 512);
60 pvfs->search.inactivity_time = lp_parm_int(snum,
61 "posix", "searchinactivity", 300);
63 #if HAVE_XATTR_SUPPORT
64 if (lp_parm_bool(snum, "posix", "xattr", True)) pvfs->flags |= PVFS_FLAG_XATTR_ENABLE;
67 pvfs->sharing_violation_delay = lp_parm_int(snum, "posix", "sharedelay", 1000000);
69 pvfs->share_name = talloc_strdup(pvfs, lp_servicename(snum));
72 FS_ATTR_CASE_SENSITIVE_SEARCH |
73 FS_ATTR_CASE_PRESERVED_NAMES |
74 FS_ATTR_UNICODE_ON_DISK |
77 /* allow xattrs to be stored in a external tdb */
78 eadb = lp_parm_string(snum, "posix", "eadb");
80 pvfs->ea_db = tdb_wrap_open(pvfs, eadb, 50000,
81 TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
82 if (pvfs->ea_db != NULL) {
83 pvfs->flags |= PVFS_FLAG_XATTR_ENABLE;
85 DEBUG(0,("Failed to open eadb '%s' - %s\n",
86 eadb, strerror(errno)));
87 pvfs->flags &= ~PVFS_FLAG_XATTR_ENABLE;
91 if (pvfs->flags & PVFS_FLAG_XATTR_ENABLE) {
92 pvfs->fs_attribs |= FS_ATTR_NAMED_STREAMS;
94 if (pvfs->flags & PVFS_FLAG_XATTR_ENABLE) {
95 pvfs->fs_attribs |= FS_ATTR_PERSISTANT_ACLS;
98 pvfs->sid_cache.creator_owner = dom_sid_parse_talloc(pvfs, SID_CREATOR_OWNER);
99 pvfs->sid_cache.creator_group = dom_sid_parse_talloc(pvfs, SID_CREATOR_GROUP);
101 /* check if the system really supports xattrs */
102 if (pvfs->flags & PVFS_FLAG_XATTR_ENABLE) {
103 pvfs_xattr_probe(pvfs);
107 static int pvfs_state_destructor(struct pvfs_state *pvfs)
109 struct pvfs_file *f, *fn;
110 struct pvfs_search_state *s, *sn;
113 * make sure we cleanup files and searches before anything else
114 * because there destructors need to acess the pvfs_state struct
116 for (f=pvfs->files.list; f; f=fn) {
121 for (s=pvfs->search.list; s; s=sn) {
130 connect to a share - used when a tree_connect operation comes
131 in. For a disk based backend we needs to ensure that the base
132 directory exists (tho it doesn't need to be accessible by the user,
135 static NTSTATUS pvfs_connect(struct ntvfs_module_context *ntvfs,
136 struct ntvfs_request *req, const char *sharename)
138 struct pvfs_state *pvfs;
140 char *base_directory;
143 pvfs = talloc_zero(ntvfs, struct pvfs_state);
144 NT_STATUS_HAVE_NO_MEMORY(pvfs);
146 /* for simplicity of path construction, remove any trailing slash now */
147 base_directory = talloc_strdup(pvfs, lp_pathname(ntvfs->ctx->config.snum));
148 NT_STATUS_HAVE_NO_MEMORY(base_directory);
149 if (strcmp(base_directory, "/") != 0) {
150 trim_string(base_directory, NULL, "/");
154 pvfs->base_directory = base_directory;
156 /* the directory must exist. Note that we deliberately don't
157 check that it is readable */
158 if (stat(pvfs->base_directory, &st) != 0 || !S_ISDIR(st.st_mode)) {
159 DEBUG(0,("pvfs_connect: '%s' is not a directory, when connecting to [%s]\n",
160 pvfs->base_directory, sharename));
161 return NT_STATUS_BAD_NETWORK_NAME;
164 ntvfs->ctx->fs_type = talloc_strdup(ntvfs->ctx, "NTFS");
165 NT_STATUS_HAVE_NO_MEMORY(ntvfs->ctx->fs_type);
167 ntvfs->ctx->dev_type = talloc_strdup(ntvfs->ctx, "A:");
168 NT_STATUS_HAVE_NO_MEMORY(ntvfs->ctx->dev_type);
170 ntvfs->private_data = pvfs;
172 pvfs->brl_context = brl_init(pvfs,
173 pvfs->ntvfs->ctx->server_id,
174 pvfs->ntvfs->ctx->msg_ctx);
175 if (pvfs->brl_context == NULL) {
176 return NT_STATUS_INTERNAL_DB_CORRUPTION;
179 pvfs->odb_context = odb_init(pvfs, pvfs->ntvfs->ctx);
180 if (pvfs->odb_context == NULL) {
181 return NT_STATUS_INTERNAL_DB_CORRUPTION;
184 /* allow this to be NULL - we just disable change notify */
185 pvfs->notify_context = notify_init(pvfs,
186 pvfs->ntvfs->ctx->server_id,
187 pvfs->ntvfs->ctx->msg_ctx,
188 event_context_find(pvfs),
189 pvfs->ntvfs->ctx->config.snum);
191 pvfs->sidmap = sidmap_open(pvfs);
192 if (pvfs->sidmap == NULL) {
193 return NT_STATUS_INTERNAL_DB_CORRUPTION;
196 /* allocate the search handle -> ptr tree */
197 pvfs->search.idtree = idr_init(pvfs);
198 NT_STATUS_HAVE_NO_MEMORY(pvfs->search.idtree);
200 status = pvfs_mangle_init(pvfs);
201 NT_STATUS_NOT_OK_RETURN(status);
203 pvfs_setup_options(pvfs);
205 talloc_set_destructor(pvfs, pvfs_state_destructor);
208 /* who had the stupid idea to generate a signal on a large
209 file write instead of just failing it!? */
210 BlockSignals(True, SIGXFSZ);
217 disconnect from a share
219 static NTSTATUS pvfs_disconnect(struct ntvfs_module_context *ntvfs)
225 check if a directory exists
227 static NTSTATUS pvfs_chkpath(struct ntvfs_module_context *ntvfs,
228 struct ntvfs_request *req,
229 union smb_chkpath *cp)
231 struct pvfs_state *pvfs = ntvfs->private_data;
232 struct pvfs_filename *name;
235 /* resolve the cifs name to a posix name */
236 status = pvfs_resolve_name(pvfs, req, cp->chkpath.in.path, 0, &name);
237 NT_STATUS_NOT_OK_RETURN(status);
240 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
243 if (!S_ISDIR(name->st.st_mode)) {
244 return NT_STATUS_NOT_A_DIRECTORY;
253 static NTSTATUS pvfs_copy(struct ntvfs_module_context *ntvfs,
254 struct ntvfs_request *req, struct smb_copy *cp)
256 DEBUG(0,("pvfs_copy not implemented\n"));
257 return NT_STATUS_NOT_SUPPORTED;
261 return print queue info
263 static NTSTATUS pvfs_lpq(struct ntvfs_module_context *ntvfs,
264 struct ntvfs_request *req, union smb_lpq *lpq)
266 return NT_STATUS_NOT_SUPPORTED;
269 /* SMBtrans - not used on file shares */
270 static NTSTATUS pvfs_trans(struct ntvfs_module_context *ntvfs,
271 struct ntvfs_request *req, struct smb_trans2 *trans2)
273 return NT_STATUS_ACCESS_DENIED;
277 initialialise the POSIX disk backend, registering ourselves with the ntvfs subsystem
279 NTSTATUS ntvfs_posix_init(void)
282 struct ntvfs_ops ops;
283 NTVFS_CURRENT_CRITICAL_SIZES(vers);
287 ops.type = NTVFS_DISK;
289 /* fill in all the operations */
290 ops.connect = pvfs_connect;
291 ops.disconnect = pvfs_disconnect;
292 ops.unlink = pvfs_unlink;
293 ops.chkpath = pvfs_chkpath;
294 ops.qpathinfo = pvfs_qpathinfo;
295 ops.setpathinfo = pvfs_setpathinfo;
296 ops.open = pvfs_open;
297 ops.mkdir = pvfs_mkdir;
298 ops.rmdir = pvfs_rmdir;
299 ops.rename = pvfs_rename;
300 ops.copy = pvfs_copy;
301 ops.ioctl = pvfs_ioctl;
302 ops.read = pvfs_read;
303 ops.write = pvfs_write;
304 ops.seek = pvfs_seek;
305 ops.flush = pvfs_flush;
306 ops.close = pvfs_close;
307 ops.exit = pvfs_exit;
308 ops.lock = pvfs_lock;
309 ops.setfileinfo = pvfs_setfileinfo;
310 ops.qfileinfo = pvfs_qfileinfo;
311 ops.fsinfo = pvfs_fsinfo;
313 ops.search_first = pvfs_search_first;
314 ops.search_next = pvfs_search_next;
315 ops.search_close = pvfs_search_close;
316 ops.trans = pvfs_trans;
317 ops.logoff = pvfs_logoff;
318 ops.async_setup = pvfs_async_setup;
319 ops.cancel = pvfs_cancel;
320 ops.notify = pvfs_notify;
322 /* register ourselves with the NTVFS subsystem. We register
323 under the name 'default' as we wish to be the default
324 backend, and also register as 'posix' */
325 ops.name = "default";
326 ret = ntvfs_register(&ops, &vers);
328 if (!NT_STATUS_IS_OK(ret)) {
329 DEBUG(0,("Failed to register POSIX backend as '%s'!\n", ops.name));
333 ret = ntvfs_register(&ops, &vers);
335 if (!NT_STATUS_IS_OK(ret)) {
336 DEBUG(0,("Failed to register POSIX backend as '%s'!\n", ops.name));
339 if (NT_STATUS_IS_OK(ret)) {
340 ret = ntvfs_common_init();