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"
34 setup config options for a posix share
36 static void pvfs_setup_options(struct pvfs_state *pvfs)
38 int snum = pvfs->tcon->service;
41 if (lp_map_hidden(snum)) pvfs->flags |= PVFS_FLAG_MAP_HIDDEN;
42 if (lp_map_archive(snum)) pvfs->flags |= PVFS_FLAG_MAP_ARCHIVE;
43 if (lp_map_system(snum)) pvfs->flags |= PVFS_FLAG_MAP_SYSTEM;
44 if (lp_readonly(snum)) pvfs->flags |= PVFS_FLAG_READONLY;
45 if (lp_strict_sync(snum)) pvfs->flags |= PVFS_FLAG_STRICT_SYNC;
46 if (lp_strict_locking(snum)) pvfs->flags |= PVFS_FLAG_STRICT_LOCKING;
47 if (lp_ci_filesystem(snum)) pvfs->flags |= PVFS_FLAG_CI_FILESYSTEM;
49 if (lp_parm_bool(snum, "posix", "fakeoplocks", False)) {
50 pvfs->flags |= PVFS_FLAG_FAKE_OPLOCKS;
53 #if HAVE_XATTR_SUPPORT
54 if (lp_parm_bool(snum, "posix", "xattr", True)) pvfs->flags |= PVFS_FLAG_XATTR_ENABLE;
57 pvfs->sharing_violation_delay = lp_parm_int(snum, "posix", "sharedelay", 1000000);
59 pvfs->share_name = talloc_strdup(pvfs, lp_servicename(snum));
62 FS_ATTR_CASE_SENSITIVE_SEARCH |
63 FS_ATTR_CASE_PRESERVED_NAMES |
64 FS_ATTR_UNICODE_ON_DISK |
67 /* allow xattrs to be stored in a external tdb */
68 eadb = lp_parm_string(snum, "posix", "eadb");
70 pvfs->ea_db = tdb_wrap_open(pvfs, eadb, 50000,
71 TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
72 if (pvfs->ea_db != NULL) {
73 pvfs->flags |= PVFS_FLAG_XATTR_ENABLE;
75 DEBUG(0,("Failed to open eadb '%s' - %s\n",
76 eadb, strerror(errno)));
77 pvfs->flags &= ~PVFS_FLAG_XATTR_ENABLE;
81 if (pvfs->flags & PVFS_FLAG_XATTR_ENABLE) {
82 pvfs->fs_attribs |= FS_ATTR_NAMED_STREAMS;
84 if (pvfs->flags & PVFS_FLAG_XATTR_ENABLE) {
85 pvfs->fs_attribs |= FS_ATTR_PERSISTANT_ACLS;
88 pvfs->sid_cache.creator_owner = dom_sid_parse_talloc(pvfs, SID_CREATOR_OWNER);
89 pvfs->sid_cache.creator_group = dom_sid_parse_talloc(pvfs, SID_CREATOR_GROUP);
94 connect to a share - used when a tree_connect operation comes
95 in. For a disk based backend we needs to ensure that the base
96 directory exists (tho it doesn't need to be accessible by the user,
99 static NTSTATUS pvfs_connect(struct ntvfs_module_context *ntvfs,
100 struct smbsrv_request *req, const char *sharename)
102 struct smbsrv_tcon *tcon = req->tcon;
103 struct pvfs_state *pvfs;
105 char *base_directory;
108 pvfs = talloc_zero(tcon, struct pvfs_state);
110 return NT_STATUS_NO_MEMORY;
113 /* for simplicity of path construction, remove any trailing slash now */
114 base_directory = talloc_strdup(pvfs, lp_pathname(tcon->service));
115 trim_string(base_directory, NULL, "/");
118 pvfs->base_directory = base_directory;
120 /* the directory must exist. Note that we deliberately don't
121 check that it is readable */
122 if (stat(pvfs->base_directory, &st) != 0 || !S_ISDIR(st.st_mode)) {
123 DEBUG(0,("pvfs_connect: '%s' is not a directory, when connecting to [%s]\n",
124 pvfs->base_directory, sharename));
125 return NT_STATUS_BAD_NETWORK_NAME;
128 tcon->fs_type = talloc_strdup(tcon, "NTFS");
129 tcon->dev_type = talloc_strdup(tcon, "A:");
131 ntvfs->private_data = pvfs;
133 pvfs->brl_context = brl_init(pvfs,
134 pvfs->tcon->smb_conn->connection->server_id,
136 pvfs->tcon->smb_conn->connection->msg_ctx);
137 if (pvfs->brl_context == NULL) {
138 return NT_STATUS_INTERNAL_DB_CORRUPTION;
141 pvfs->odb_context = odb_init(pvfs,
142 pvfs->tcon->smb_conn->connection->server_id,
143 pvfs->tcon->smb_conn->connection->msg_ctx);
144 if (pvfs->odb_context == NULL) {
145 return NT_STATUS_INTERNAL_DB_CORRUPTION;
148 pvfs->sidmap = sidmap_open(pvfs);
149 if (pvfs->sidmap == NULL) {
150 return NT_STATUS_INTERNAL_DB_CORRUPTION;
153 /* allocate the fnum id -> ptr tree */
154 pvfs->idtree_fnum = idr_init(pvfs);
155 if (pvfs->idtree_fnum == NULL) {
156 return NT_STATUS_NO_MEMORY;
159 /* allocate the search handle -> ptr tree */
160 pvfs->idtree_search = idr_init(pvfs);
161 if (pvfs->idtree_search == NULL) {
162 return NT_STATUS_NO_MEMORY;
165 status = pvfs_mangle_init(pvfs);
166 if (!NT_STATUS_IS_OK(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 if (!NT_STATUS_IS_OK(status)) {
207 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
210 if (!S_ISDIR(name->st.st_mode)) {
211 return NT_STATUS_NOT_A_DIRECTORY;
220 static NTSTATUS pvfs_copy(struct ntvfs_module_context *ntvfs,
221 struct smbsrv_request *req, struct smb_copy *cp)
223 DEBUG(0,("pvfs_copy not implemented\n"));
224 return NT_STATUS_NOT_SUPPORTED;
228 return print queue info
230 static NTSTATUS pvfs_lpq(struct ntvfs_module_context *ntvfs,
231 struct smbsrv_request *req, union smb_lpq *lpq)
233 return NT_STATUS_NOT_SUPPORTED;
236 /* SMBtrans - not used on file shares */
237 static NTSTATUS pvfs_trans(struct ntvfs_module_context *ntvfs,
238 struct smbsrv_request *req, struct smb_trans2 *trans2)
240 return NT_STATUS_ACCESS_DENIED;
244 initialialise the POSIX disk backend, registering ourselves with the ntvfs subsystem
246 NTSTATUS ntvfs_posix_init(void)
249 struct ntvfs_ops ops;
253 ops.type = NTVFS_DISK;
255 /* fill in all the operations */
256 ops.connect = pvfs_connect;
257 ops.disconnect = pvfs_disconnect;
258 ops.unlink = pvfs_unlink;
259 ops.chkpath = pvfs_chkpath;
260 ops.qpathinfo = pvfs_qpathinfo;
261 ops.setpathinfo = pvfs_setpathinfo;
262 ops.openfile = pvfs_open;
263 ops.mkdir = pvfs_mkdir;
264 ops.rmdir = pvfs_rmdir;
265 ops.rename = pvfs_rename;
266 ops.copy = pvfs_copy;
267 ops.ioctl = pvfs_ioctl;
268 ops.read = pvfs_read;
269 ops.write = pvfs_write;
270 ops.seek = pvfs_seek;
271 ops.flush = pvfs_flush;
272 ops.close = pvfs_close;
273 ops.exit = pvfs_exit;
274 ops.lock = pvfs_lock;
275 ops.setfileinfo = pvfs_setfileinfo;
276 ops.qfileinfo = pvfs_qfileinfo;
277 ops.fsinfo = pvfs_fsinfo;
279 ops.search_first = pvfs_search_first;
280 ops.search_next = pvfs_search_next;
281 ops.search_close = pvfs_search_close;
282 ops.trans = pvfs_trans;
283 ops.logoff = pvfs_logoff;
284 ops.async_setup = pvfs_async_setup;
285 ops.cancel = pvfs_cancel;
287 /* register ourselves with the NTVFS subsystem. We register
288 under the name 'default' as we wish to be the default
289 backend, and also register as 'posix' */
290 ops.name = "default";
291 ret = ntvfs_register(&ops);
294 ret = ntvfs_register(&ops);
296 if (!NT_STATUS_IS_OK(ret)) {
297 DEBUG(0,("Failed to register POSIX backend!\n"));