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 3 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, see <http://www.gnu.org/licenses/>.
22 this implements most of the POSIX NTVFS backend
23 This is the default backend
27 #include "vfs_posix.h"
28 #include "librpc/gen_ndr/security.h"
29 #include "lib/tdb/include/tdb.h"
31 #include "util/util_ldb.h"
32 #include "libcli/security/security.h"
33 #include "lib/events/events.h"
34 #include "param/param.h"
37 setup config options for a posix share
39 static void pvfs_setup_options(struct pvfs_state *pvfs)
41 struct share_config *scfg = pvfs->ntvfs->ctx->config;
44 if (share_bool_option(scfg, SHARE_MAP_HIDDEN, SHARE_MAP_HIDDEN_DEFAULT))
45 pvfs->flags |= PVFS_FLAG_MAP_HIDDEN;
46 if (share_bool_option(scfg, SHARE_MAP_ARCHIVE, SHARE_MAP_ARCHIVE_DEFAULT))
47 pvfs->flags |= PVFS_FLAG_MAP_ARCHIVE;
48 if (share_bool_option(scfg, SHARE_MAP_SYSTEM, SHARE_MAP_SYSTEM_DEFAULT))
49 pvfs->flags |= PVFS_FLAG_MAP_SYSTEM;
50 if (share_bool_option(scfg, SHARE_READONLY, SHARE_READONLY_DEFAULT))
51 pvfs->flags |= PVFS_FLAG_READONLY;
52 if (share_bool_option(scfg, SHARE_STRICT_SYNC, SHARE_STRICT_SYNC_DEFAULT))
53 pvfs->flags |= PVFS_FLAG_STRICT_SYNC;
54 if (share_bool_option(scfg, SHARE_STRICT_LOCKING, SHARE_STRICT_LOCKING_DEFAULT))
55 pvfs->flags |= PVFS_FLAG_STRICT_LOCKING;
56 if (share_bool_option(scfg, SHARE_CI_FILESYSTEM, SHARE_CI_FILESYSTEM_DEFAULT))
57 pvfs->flags |= PVFS_FLAG_CI_FILESYSTEM;
58 if (share_bool_option(scfg, PVFS_FAKE_OPLOCKS, PVFS_FAKE_OPLOCKS_DEFAULT))
59 pvfs->flags |= PVFS_FLAG_FAKE_OPLOCKS;
60 if (share_bool_option(scfg, PVFS_AIO, false))
61 pvfs->flags |= PVFS_FLAG_LINUX_AIO;
63 /* file perm options */
64 pvfs->options.create_mask = share_int_option(scfg,
66 SHARE_CREATE_MASK_DEFAULT);
67 pvfs->options.dir_mask = share_int_option(scfg,
69 SHARE_DIR_MASK_DEFAULT);
70 pvfs->options.force_dir_mode = share_int_option(scfg,
72 SHARE_FORCE_DIR_MODE_DEFAULT);
73 pvfs->options.force_create_mode = share_int_option(scfg,
74 SHARE_FORCE_CREATE_MODE,
75 SHARE_FORCE_CREATE_MODE_DEFAULT);
76 /* this must be a power of 2 */
77 pvfs->alloc_size_rounding = share_int_option(scfg,
78 PVFS_ALLOCATION_ROUNDING,
79 PVFS_ALLOCATION_ROUNDING_DEFAULT);
81 pvfs->search.inactivity_time = share_int_option(scfg,
82 PVFS_SEARCH_INACTIVITY,
83 PVFS_SEARCH_INACTIVITY_DEFAULT);
85 #if HAVE_XATTR_SUPPORT
86 if (share_bool_option(scfg, PVFS_XATTR, PVFS_XATTR_DEFAULT))
87 pvfs->flags |= PVFS_FLAG_XATTR_ENABLE;
90 pvfs->sharing_violation_delay = share_int_option(scfg,
92 PVFS_SHARE_DELAY_DEFAULT);
94 pvfs->oplock_break_timeout = share_int_option(scfg,
96 PVFS_OPLOCK_TIMEOUT_DEFAULT);
98 pvfs->writetime_delay = share_int_option(scfg,
100 PVFS_WRITETIME_DELAY_DEFAULT);
102 pvfs->share_name = talloc_strdup(pvfs, scfg->name);
105 FS_ATTR_CASE_SENSITIVE_SEARCH |
106 FS_ATTR_CASE_PRESERVED_NAMES |
107 FS_ATTR_UNICODE_ON_DISK |
108 FS_ATTR_SPARSE_FILES;
110 /* allow xattrs to be stored in a external tdb */
111 eadb = share_string_option(scfg, PVFS_EADB, NULL);
113 pvfs->ea_db = tdb_wrap_open(pvfs, eadb, 50000,
114 TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
115 if (pvfs->ea_db != NULL) {
116 pvfs->flags |= PVFS_FLAG_XATTR_ENABLE;
118 DEBUG(0,("Failed to open eadb '%s' - %s\n",
119 eadb, strerror(errno)));
120 pvfs->flags &= ~PVFS_FLAG_XATTR_ENABLE;
124 if (pvfs->flags & PVFS_FLAG_XATTR_ENABLE) {
125 pvfs->fs_attribs |= FS_ATTR_NAMED_STREAMS;
127 if (pvfs->flags & PVFS_FLAG_XATTR_ENABLE) {
128 pvfs->fs_attribs |= FS_ATTR_PERSISTANT_ACLS;
131 pvfs->sid_cache.creator_owner = dom_sid_parse_talloc(pvfs, SID_CREATOR_OWNER);
132 pvfs->sid_cache.creator_group = dom_sid_parse_talloc(pvfs, SID_CREATOR_GROUP);
134 /* check if the system really supports xattrs */
135 if (pvfs->flags & PVFS_FLAG_XATTR_ENABLE) {
136 pvfs_xattr_probe(pvfs);
139 /* enable an ACL backend */
140 pvfs->acl_ops = pvfs_acl_backend_byname(share_string_option(scfg, PVFS_ACL, "xattr"));
143 static int pvfs_state_destructor(struct pvfs_state *pvfs)
145 struct pvfs_file *f, *fn;
146 struct pvfs_search_state *s, *sn;
149 * make sure we cleanup files and searches before anything else
150 * because there destructors need to acess the pvfs_state struct
152 for (f=pvfs->files.list; f; f=fn) {
157 for (s=pvfs->search.list; s; s=sn) {
166 connect to a share - used when a tree_connect operation comes
167 in. For a disk based backend we needs to ensure that the base
168 directory exists (tho it doesn't need to be accessible by the user,
171 static NTSTATUS pvfs_connect(struct ntvfs_module_context *ntvfs,
172 struct ntvfs_request *req, const char *sharename)
174 struct pvfs_state *pvfs;
176 char *base_directory;
179 pvfs = talloc_zero(ntvfs, struct pvfs_state);
180 NT_STATUS_HAVE_NO_MEMORY(pvfs);
182 /* for simplicity of path construction, remove any trailing slash now */
183 base_directory = talloc_strdup(pvfs, share_string_option(ntvfs->ctx->config, SHARE_PATH, ""));
184 NT_STATUS_HAVE_NO_MEMORY(base_directory);
185 if (strcmp(base_directory, "/") != 0) {
186 trim_string(base_directory, NULL, "/");
190 pvfs->base_directory = base_directory;
192 /* the directory must exist. Note that we deliberately don't
193 check that it is readable */
194 if (stat(pvfs->base_directory, &st) != 0 || !S_ISDIR(st.st_mode)) {
195 DEBUG(0,("pvfs_connect: '%s' is not a directory, when connecting to [%s]\n",
196 pvfs->base_directory, sharename));
197 return NT_STATUS_BAD_NETWORK_NAME;
200 ntvfs->ctx->fs_type = talloc_strdup(ntvfs->ctx, "NTFS");
201 NT_STATUS_HAVE_NO_MEMORY(ntvfs->ctx->fs_type);
203 ntvfs->ctx->dev_type = talloc_strdup(ntvfs->ctx, "A:");
204 NT_STATUS_HAVE_NO_MEMORY(ntvfs->ctx->dev_type);
206 ntvfs->private_data = pvfs;
208 pvfs->brl_context = brl_init(pvfs,
209 pvfs->ntvfs->ctx->server_id,
210 pvfs->ntvfs->ctx->lp_ctx,
211 pvfs->ntvfs->ctx->msg_ctx);
212 if (pvfs->brl_context == NULL) {
213 return NT_STATUS_INTERNAL_DB_CORRUPTION;
216 pvfs->odb_context = odb_init(pvfs, pvfs->ntvfs->ctx);
217 if (pvfs->odb_context == NULL) {
218 return NT_STATUS_INTERNAL_DB_CORRUPTION;
221 /* allow this to be NULL - we just disable change notify */
222 pvfs->notify_context = notify_init(pvfs,
223 pvfs->ntvfs->ctx->server_id,
224 pvfs->ntvfs->ctx->msg_ctx,
225 pvfs->ntvfs->ctx->lp_ctx,
226 pvfs->ntvfs->ctx->event_ctx,
227 pvfs->ntvfs->ctx->config);
229 pvfs->wbc_ctx = wbc_init(pvfs,
230 pvfs->ntvfs->ctx->msg_ctx,
231 pvfs->ntvfs->ctx->event_ctx);
232 if (pvfs->wbc_ctx == NULL) {
233 return NT_STATUS_INTERNAL_DB_CORRUPTION;
236 /* allocate the search handle -> ptr tree */
237 pvfs->search.idtree = idr_init(pvfs);
238 NT_STATUS_HAVE_NO_MEMORY(pvfs->search.idtree);
240 status = pvfs_mangle_init(pvfs);
241 NT_STATUS_NOT_OK_RETURN(status);
243 pvfs_setup_options(pvfs);
245 talloc_set_destructor(pvfs, pvfs_state_destructor);
248 /* who had the stupid idea to generate a signal on a large
249 file write instead of just failing it!? */
250 BlockSignals(true, SIGXFSZ);
257 disconnect from a share
259 static NTSTATUS pvfs_disconnect(struct ntvfs_module_context *ntvfs)
265 check if a directory exists
267 static NTSTATUS pvfs_chkpath(struct ntvfs_module_context *ntvfs,
268 struct ntvfs_request *req,
269 union smb_chkpath *cp)
271 struct pvfs_state *pvfs = ntvfs->private_data;
272 struct pvfs_filename *name;
275 /* resolve the cifs name to a posix name */
276 status = pvfs_resolve_name(pvfs, req, cp->chkpath.in.path, 0, &name);
277 NT_STATUS_NOT_OK_RETURN(status);
280 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
283 if (!S_ISDIR(name->st.st_mode)) {
284 return NT_STATUS_NOT_A_DIRECTORY;
293 static NTSTATUS pvfs_copy(struct ntvfs_module_context *ntvfs,
294 struct ntvfs_request *req, struct smb_copy *cp)
296 DEBUG(0,("pvfs_copy not implemented\n"));
297 return NT_STATUS_NOT_SUPPORTED;
301 return print queue info
303 static NTSTATUS pvfs_lpq(struct ntvfs_module_context *ntvfs,
304 struct ntvfs_request *req, union smb_lpq *lpq)
306 return NT_STATUS_NOT_SUPPORTED;
309 /* SMBtrans - not used on file shares */
310 static NTSTATUS pvfs_trans(struct ntvfs_module_context *ntvfs,
311 struct ntvfs_request *req, struct smb_trans2 *trans2)
313 return NT_STATUS_ACCESS_DENIED;
317 initialialise the POSIX disk backend, registering ourselves with the ntvfs subsystem
319 NTSTATUS ntvfs_posix_init(void)
322 struct ntvfs_ops ops;
323 NTVFS_CURRENT_CRITICAL_SIZES(vers);
327 ops.type = NTVFS_DISK;
329 /* fill in all the operations */
330 ops.connect = pvfs_connect;
331 ops.disconnect = pvfs_disconnect;
332 ops.unlink = pvfs_unlink;
333 ops.chkpath = pvfs_chkpath;
334 ops.qpathinfo = pvfs_qpathinfo;
335 ops.setpathinfo = pvfs_setpathinfo;
336 ops.open = pvfs_open;
337 ops.mkdir = pvfs_mkdir;
338 ops.rmdir = pvfs_rmdir;
339 ops.rename = pvfs_rename;
340 ops.copy = pvfs_copy;
341 ops.ioctl = pvfs_ioctl;
342 ops.read = pvfs_read;
343 ops.write = pvfs_write;
344 ops.seek = pvfs_seek;
345 ops.flush = pvfs_flush;
346 ops.close = pvfs_close;
347 ops.exit = pvfs_exit;
348 ops.lock = pvfs_lock;
349 ops.setfileinfo = pvfs_setfileinfo;
350 ops.qfileinfo = pvfs_qfileinfo;
351 ops.fsinfo = pvfs_fsinfo;
353 ops.search_first = pvfs_search_first;
354 ops.search_next = pvfs_search_next;
355 ops.search_close = pvfs_search_close;
356 ops.trans = pvfs_trans;
357 ops.logoff = pvfs_logoff;
358 ops.async_setup = pvfs_async_setup;
359 ops.cancel = pvfs_cancel;
360 ops.notify = pvfs_notify;
362 /* register ourselves with the NTVFS subsystem. We register
363 under the name 'default' as we wish to be the default
364 backend, and also register as 'posix' */
365 ops.name = "default";
366 ret = ntvfs_register(&ops, &vers);
368 if (!NT_STATUS_IS_OK(ret)) {
369 DEBUG(0,("Failed to register POSIX backend as '%s'!\n", ops.name));
373 ret = ntvfs_register(&ops, &vers);
375 if (!NT_STATUS_IS_OK(ret)) {
376 DEBUG(0,("Failed to register POSIX backend as '%s'!\n", ops.name));
379 if (NT_STATUS_IS_OK(ret)) {
380 ret = ntvfs_common_init();