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 /* this must be a power of 2 */
55 pvfs->alloc_size_rounding = lp_parm_int(snum,
56 "posix", "allocationrounding", 512);
58 pvfs->search_inactivity_time = lp_parm_int(snum,
59 "posix", "searchinactivity", 300);
61 #if HAVE_XATTR_SUPPORT
62 if (lp_parm_bool(snum, "posix", "xattr", True)) pvfs->flags |= PVFS_FLAG_XATTR_ENABLE;
65 pvfs->sharing_violation_delay = lp_parm_int(snum, "posix", "sharedelay", 1000000);
67 pvfs->share_name = talloc_strdup(pvfs, lp_servicename(snum));
70 FS_ATTR_CASE_SENSITIVE_SEARCH |
71 FS_ATTR_CASE_PRESERVED_NAMES |
72 FS_ATTR_UNICODE_ON_DISK |
75 /* allow xattrs to be stored in a external tdb */
76 eadb = lp_parm_string(snum, "posix", "eadb");
78 pvfs->ea_db = tdb_wrap_open(pvfs, eadb, 50000,
79 TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
80 if (pvfs->ea_db != NULL) {
81 pvfs->flags |= PVFS_FLAG_XATTR_ENABLE;
83 DEBUG(0,("Failed to open eadb '%s' - %s\n",
84 eadb, strerror(errno)));
85 pvfs->flags &= ~PVFS_FLAG_XATTR_ENABLE;
89 if (pvfs->flags & PVFS_FLAG_XATTR_ENABLE) {
90 pvfs->fs_attribs |= FS_ATTR_NAMED_STREAMS;
92 if (pvfs->flags & PVFS_FLAG_XATTR_ENABLE) {
93 pvfs->fs_attribs |= FS_ATTR_PERSISTANT_ACLS;
96 pvfs->sid_cache.creator_owner = dom_sid_parse_talloc(pvfs, SID_CREATOR_OWNER);
97 pvfs->sid_cache.creator_group = dom_sid_parse_talloc(pvfs, SID_CREATOR_GROUP);
99 /* check if the system really supports xattrs */
100 if (pvfs->flags & PVFS_FLAG_XATTR_ENABLE) {
101 pvfs_xattr_probe(pvfs);
107 connect to a share - used when a tree_connect operation comes
108 in. For a disk based backend we needs to ensure that the base
109 directory exists (tho it doesn't need to be accessible by the user,
112 static NTSTATUS pvfs_connect(struct ntvfs_module_context *ntvfs,
113 struct smbsrv_request *req, const char *sharename)
115 struct smbsrv_tcon *tcon = req->tcon;
116 struct pvfs_state *pvfs;
118 char *base_directory;
121 pvfs = talloc_zero(tcon, struct pvfs_state);
122 NT_STATUS_HAVE_NO_MEMORY(pvfs);
124 /* for simplicity of path construction, remove any trailing slash now */
125 base_directory = talloc_strdup(pvfs, lp_pathname(tcon->service));
126 NT_STATUS_HAVE_NO_MEMORY(base_directory);
127 if (strcmp(base_directory, "/") != 0) {
128 trim_string(base_directory, NULL, "/");
132 pvfs->base_directory = base_directory;
134 /* the directory must exist. Note that we deliberately don't
135 check that it is readable */
136 if (stat(pvfs->base_directory, &st) != 0 || !S_ISDIR(st.st_mode)) {
137 DEBUG(0,("pvfs_connect: '%s' is not a directory, when connecting to [%s]\n",
138 pvfs->base_directory, sharename));
139 return NT_STATUS_BAD_NETWORK_NAME;
142 tcon->fs_type = talloc_strdup(tcon, "NTFS");
143 NT_STATUS_HAVE_NO_MEMORY(tcon->fs_type);
145 tcon->dev_type = talloc_strdup(tcon, "A:");
146 NT_STATUS_HAVE_NO_MEMORY(tcon->dev_type);
148 ntvfs->private_data = pvfs;
150 pvfs->brl_context = brl_init(pvfs,
151 pvfs->tcon->smb_conn->connection->server_id,
153 pvfs->tcon->smb_conn->connection->msg_ctx);
154 if (pvfs->brl_context == NULL) {
155 return NT_STATUS_INTERNAL_DB_CORRUPTION;
158 pvfs->odb_context = odb_init(pvfs,
159 pvfs->tcon->smb_conn->connection->server_id,
160 pvfs->tcon->smb_conn->connection->msg_ctx);
161 if (pvfs->odb_context == NULL) {
162 return NT_STATUS_INTERNAL_DB_CORRUPTION;
165 pvfs->sidmap = sidmap_open(pvfs);
166 if (pvfs->sidmap == NULL) {
167 return NT_STATUS_INTERNAL_DB_CORRUPTION;
170 /* allocate the fnum id -> ptr tree */
171 pvfs->idtree_fnum = idr_init(pvfs);
172 NT_STATUS_HAVE_NO_MEMORY(pvfs->idtree_fnum);
174 /* allocate the search handle -> ptr tree */
175 pvfs->idtree_search = idr_init(pvfs);
176 NT_STATUS_HAVE_NO_MEMORY(pvfs->idtree_search);
178 status = pvfs_mangle_init(pvfs);
179 NT_STATUS_NOT_OK_RETURN(status);
181 pvfs_setup_options(pvfs);
184 /* who had the stupid idea to generate a signal on a large
185 file write instead of just failing it!? */
186 BlockSignals(True, SIGXFSZ);
193 disconnect from a share
195 static NTSTATUS pvfs_disconnect(struct ntvfs_module_context *ntvfs,
196 struct smbsrv_tcon *tcon)
202 check if a directory exists
204 static NTSTATUS pvfs_chkpath(struct ntvfs_module_context *ntvfs,
205 struct smbsrv_request *req, struct smb_chkpath *cp)
207 struct pvfs_state *pvfs = ntvfs->private_data;
208 struct pvfs_filename *name;
211 /* resolve the cifs name to a posix name */
212 status = pvfs_resolve_name(pvfs, req, cp->in.path, 0, &name);
213 NT_STATUS_NOT_OK_RETURN(status);
216 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
219 if (!S_ISDIR(name->st.st_mode)) {
220 return NT_STATUS_NOT_A_DIRECTORY;
229 static NTSTATUS pvfs_copy(struct ntvfs_module_context *ntvfs,
230 struct smbsrv_request *req, struct smb_copy *cp)
232 DEBUG(0,("pvfs_copy not implemented\n"));
233 return NT_STATUS_NOT_SUPPORTED;
237 return print queue info
239 static NTSTATUS pvfs_lpq(struct ntvfs_module_context *ntvfs,
240 struct smbsrv_request *req, union smb_lpq *lpq)
242 return NT_STATUS_NOT_SUPPORTED;
245 /* SMBtrans - not used on file shares */
246 static NTSTATUS pvfs_trans(struct ntvfs_module_context *ntvfs,
247 struct smbsrv_request *req, struct smb_trans2 *trans2)
249 return NT_STATUS_ACCESS_DENIED;
253 initialialise the POSIX disk backend, registering ourselves with the ntvfs subsystem
255 NTSTATUS ntvfs_posix_init(void)
258 struct ntvfs_ops ops;
262 ops.type = NTVFS_DISK;
264 /* fill in all the operations */
265 ops.connect = pvfs_connect;
266 ops.disconnect = pvfs_disconnect;
267 ops.unlink = pvfs_unlink;
268 ops.chkpath = pvfs_chkpath;
269 ops.qpathinfo = pvfs_qpathinfo;
270 ops.setpathinfo = pvfs_setpathinfo;
271 ops.openfile = pvfs_open;
272 ops.mkdir = pvfs_mkdir;
273 ops.rmdir = pvfs_rmdir;
274 ops.rename = pvfs_rename;
275 ops.copy = pvfs_copy;
276 ops.ioctl = pvfs_ioctl;
277 ops.read = pvfs_read;
278 ops.write = pvfs_write;
279 ops.seek = pvfs_seek;
280 ops.flush = pvfs_flush;
281 ops.close = pvfs_close;
282 ops.exit = pvfs_exit;
283 ops.lock = pvfs_lock;
284 ops.setfileinfo = pvfs_setfileinfo;
285 ops.qfileinfo = pvfs_qfileinfo;
286 ops.fsinfo = pvfs_fsinfo;
288 ops.search_first = pvfs_search_first;
289 ops.search_next = pvfs_search_next;
290 ops.search_close = pvfs_search_close;
291 ops.trans = pvfs_trans;
292 ops.logoff = pvfs_logoff;
293 ops.async_setup = pvfs_async_setup;
294 ops.cancel = pvfs_cancel;
296 /* register ourselves with the NTVFS subsystem. We register
297 under the name 'default' as we wish to be the default
298 backend, and also register as 'posix' */
299 ops.name = "default";
300 ret = ntvfs_register(&ops);
303 ret = ntvfs_register(&ops);
305 if (!NT_STATUS_IS_OK(ret)) {
306 DEBUG(0,("Failed to register POSIX backend!\n"));