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/ndr_security.h"
30 #include "smbd/service_stream.h"
31 #include "lib/tdb/include/tdb.h"
35 setup config options for a posix share
37 static void pvfs_setup_options(struct pvfs_state *pvfs)
39 int snum = pvfs->tcon->service;
42 if (lp_map_hidden(snum)) pvfs->flags |= PVFS_FLAG_MAP_HIDDEN;
43 if (lp_map_archive(snum)) pvfs->flags |= PVFS_FLAG_MAP_ARCHIVE;
44 if (lp_map_system(snum)) pvfs->flags |= PVFS_FLAG_MAP_SYSTEM;
45 if (lp_readonly(snum)) pvfs->flags |= PVFS_FLAG_READONLY;
46 if (lp_strict_sync(snum)) pvfs->flags |= PVFS_FLAG_STRICT_SYNC;
47 if (lp_strict_locking(snum)) pvfs->flags |= PVFS_FLAG_STRICT_LOCKING;
48 if (lp_ci_filesystem(snum)) pvfs->flags |= PVFS_FLAG_CI_FILESYSTEM;
50 if (lp_parm_bool(snum, "posix", "fakeoplocks", False)) {
51 pvfs->flags |= PVFS_FLAG_FAKE_OPLOCKS;
54 #if HAVE_XATTR_SUPPORT
55 if (lp_parm_bool(snum, "posix", "xattr", True)) pvfs->flags |= PVFS_FLAG_XATTR_ENABLE;
58 pvfs->sharing_violation_delay = lp_parm_int(snum, "posix", "sharedelay", 1000000);
60 pvfs->share_name = talloc_strdup(pvfs, lp_servicename(snum));
63 FS_ATTR_CASE_SENSITIVE_SEARCH |
64 FS_ATTR_CASE_PRESERVED_NAMES |
65 FS_ATTR_UNICODE_ON_DISK |
68 /* allow xattrs to be stored in a external tdb */
69 eadb = lp_parm_string(snum, "posix", "eadb");
71 pvfs->ea_db = tdb_wrap_open(pvfs, eadb, 50000,
72 TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
73 if (pvfs->ea_db != NULL) {
74 pvfs->flags |= PVFS_FLAG_XATTR_ENABLE;
76 DEBUG(0,("Failed to open eadb '%s' - %s\n",
77 eadb, strerror(errno)));
78 pvfs->flags &= ~PVFS_FLAG_XATTR_ENABLE;
82 if (pvfs->flags & PVFS_FLAG_XATTR_ENABLE) {
83 pvfs->fs_attribs |= FS_ATTR_NAMED_STREAMS;
85 if (pvfs->flags & PVFS_FLAG_XATTR_ENABLE) {
86 pvfs->fs_attribs |= FS_ATTR_PERSISTANT_ACLS;
89 pvfs->sid_cache.creator_owner = dom_sid_parse_talloc(pvfs, SID_CREATOR_OWNER);
90 pvfs->sid_cache.creator_group = dom_sid_parse_talloc(pvfs, SID_CREATOR_GROUP);
92 pvfs->blkid_cache = NULL;
98 connect to a share - used when a tree_connect operation comes
99 in. For a disk based backend we needs to ensure that the base
100 directory exists (tho it doesn't need to be accessible by the user,
103 static NTSTATUS pvfs_connect(struct ntvfs_module_context *ntvfs,
104 struct smbsrv_request *req, const char *sharename)
106 struct smbsrv_tcon *tcon = req->tcon;
107 struct pvfs_state *pvfs;
109 char *base_directory;
112 pvfs = talloc_zero(tcon, struct pvfs_state);
113 NT_STATUS_HAVE_NO_MEMORY(pvfs);
115 /* for simplicity of path construction, remove any trailing slash now */
116 base_directory = talloc_strdup(pvfs, lp_pathname(tcon->service));
117 NT_STATUS_HAVE_NO_MEMORY(base_directory);
118 trim_string(base_directory, NULL, "/");
121 pvfs->base_directory = base_directory;
123 /* the directory must exist. Note that we deliberately don't
124 check that it is readable */
125 if (stat(pvfs->base_directory, &st) != 0 || !S_ISDIR(st.st_mode)) {
126 DEBUG(0,("pvfs_connect: '%s' is not a directory, when connecting to [%s]\n",
127 pvfs->base_directory, sharename));
128 return NT_STATUS_BAD_NETWORK_NAME;
131 tcon->fs_type = talloc_strdup(tcon, "NTFS");
132 NT_STATUS_HAVE_NO_MEMORY(tcon->fs_type);
134 tcon->dev_type = talloc_strdup(tcon, "A:");
135 NT_STATUS_HAVE_NO_MEMORY(tcon->dev_type);
137 ntvfs->private_data = pvfs;
139 pvfs->brl_context = brl_init(pvfs,
140 pvfs->tcon->smb_conn->connection->server_id,
142 pvfs->tcon->smb_conn->connection->msg_ctx);
143 if (pvfs->brl_context == NULL) {
144 return NT_STATUS_INTERNAL_DB_CORRUPTION;
147 pvfs->odb_context = odb_init(pvfs,
148 pvfs->tcon->smb_conn->connection->server_id,
149 pvfs->tcon->smb_conn->connection->msg_ctx);
150 if (pvfs->odb_context == NULL) {
151 return NT_STATUS_INTERNAL_DB_CORRUPTION;
154 pvfs->sidmap = sidmap_open(pvfs);
155 if (pvfs->sidmap == NULL) {
156 return NT_STATUS_INTERNAL_DB_CORRUPTION;
159 /* allocate the fnum id -> ptr tree */
160 pvfs->idtree_fnum = idr_init(pvfs);
161 NT_STATUS_HAVE_NO_MEMORY(pvfs->idtree_fnum);
163 /* allocate the search handle -> ptr tree */
164 pvfs->idtree_search = idr_init(pvfs);
165 NT_STATUS_HAVE_NO_MEMORY(pvfs->idtree_search);
167 status = pvfs_mangle_init(pvfs);
168 NT_STATUS_NOT_OK_RETURN(status);
170 pvfs_setup_options(pvfs);
173 /* who had the stupid idea to generate a signal on a large
174 file write instead of just failing it!? */
175 BlockSignals(True, SIGXFSZ);
182 disconnect from a share
184 static NTSTATUS pvfs_disconnect(struct ntvfs_module_context *ntvfs,
185 struct smbsrv_tcon *tcon)
191 check if a directory exists
193 static NTSTATUS pvfs_chkpath(struct ntvfs_module_context *ntvfs,
194 struct smbsrv_request *req, struct smb_chkpath *cp)
196 struct pvfs_state *pvfs = ntvfs->private_data;
197 struct pvfs_filename *name;
200 /* resolve the cifs name to a posix name */
201 status = pvfs_resolve_name(pvfs, req, cp->in.path, 0, &name);
202 NT_STATUS_NOT_OK_RETURN(status);
205 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
208 if (!S_ISDIR(name->st.st_mode)) {
209 return NT_STATUS_NOT_A_DIRECTORY;
218 static NTSTATUS pvfs_copy(struct ntvfs_module_context *ntvfs,
219 struct smbsrv_request *req, struct smb_copy *cp)
221 DEBUG(0,("pvfs_copy not implemented\n"));
222 return NT_STATUS_NOT_SUPPORTED;
226 return print queue info
228 static NTSTATUS pvfs_lpq(struct ntvfs_module_context *ntvfs,
229 struct smbsrv_request *req, union smb_lpq *lpq)
231 return NT_STATUS_NOT_SUPPORTED;
234 /* SMBtrans - not used on file shares */
235 static NTSTATUS pvfs_trans(struct ntvfs_module_context *ntvfs,
236 struct smbsrv_request *req, struct smb_trans2 *trans2)
238 return NT_STATUS_ACCESS_DENIED;
242 initialialise the POSIX disk backend, registering ourselves with the ntvfs subsystem
244 NTSTATUS ntvfs_posix_init(void)
247 struct ntvfs_ops ops;
251 ops.type = NTVFS_DISK;
253 /* fill in all the operations */
254 ops.connect = pvfs_connect;
255 ops.disconnect = pvfs_disconnect;
256 ops.unlink = pvfs_unlink;
257 ops.chkpath = pvfs_chkpath;
258 ops.qpathinfo = pvfs_qpathinfo;
259 ops.setpathinfo = pvfs_setpathinfo;
260 ops.openfile = pvfs_open;
261 ops.mkdir = pvfs_mkdir;
262 ops.rmdir = pvfs_rmdir;
263 ops.rename = pvfs_rename;
264 ops.copy = pvfs_copy;
265 ops.ioctl = pvfs_ioctl;
266 ops.read = pvfs_read;
267 ops.write = pvfs_write;
268 ops.seek = pvfs_seek;
269 ops.flush = pvfs_flush;
270 ops.close = pvfs_close;
271 ops.exit = pvfs_exit;
272 ops.lock = pvfs_lock;
273 ops.setfileinfo = pvfs_setfileinfo;
274 ops.qfileinfo = pvfs_qfileinfo;
275 ops.fsinfo = pvfs_fsinfo;
277 ops.search_first = pvfs_search_first;
278 ops.search_next = pvfs_search_next;
279 ops.search_close = pvfs_search_close;
280 ops.trans = pvfs_trans;
281 ops.logoff = pvfs_logoff;
282 ops.async_setup = pvfs_async_setup;
283 ops.cancel = pvfs_cancel;
285 /* register ourselves with the NTVFS subsystem. We register
286 under the name 'default' as we wish to be the default
287 backend, and also register as 'posix' */
288 ops.name = "default";
289 ret = ntvfs_register(&ops);
292 ret = ntvfs_register(&ops);
294 if (!NT_STATUS_IS_OK(ret)) {
295 DEBUG(0,("Failed to register POSIX backend!\n"));