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
27 #include "include/includes.h"
28 #include "vfs_posix.h"
32 setup config options for a posix share
34 static void pvfs_setup_options(struct pvfs_state *pvfs)
36 int snum = pvfs->tcon->service;
38 if (lp_map_hidden(snum)) pvfs->flags |= PVFS_FLAG_MAP_HIDDEN;
39 if (lp_map_archive(snum)) pvfs->flags |= PVFS_FLAG_MAP_ARCHIVE;
40 if (lp_map_system(snum)) pvfs->flags |= PVFS_FLAG_MAP_SYSTEM;
41 if (lp_readonly(snum)) pvfs->flags |= PVFS_FLAG_READONLY;
42 if (lp_strict_sync(snum)) pvfs->flags |= PVFS_FLAG_STRICT_SYNC;
43 if (lp_strict_locking(snum)) pvfs->flags |= PVFS_FLAG_STRICT_LOCKING;
44 if (lp_ci_filesystem(snum)) pvfs->flags |= PVFS_FLAG_CI_FILESYSTEM;
46 pvfs->share_name = talloc_strdup(pvfs, lp_servicename(snum));
51 connect to a share - used when a tree_connect operation comes
52 in. For a disk based backend we needs to ensure that the base
53 directory exists (tho it doesn't need to be accessible by the user,
56 static NTSTATUS pvfs_connect(struct ntvfs_module_context *ntvfs,
57 struct smbsrv_request *req, const char *sharename)
59 struct smbsrv_tcon *tcon = req->tcon;
60 struct pvfs_state *pvfs;
65 pvfs = talloc_zero_p(tcon, struct pvfs_state);
67 return NT_STATUS_NO_MEMORY;
70 /* for simplicity of path construction, remove any trailing slash now */
71 base_directory = talloc_strdup(pvfs, lp_pathname(tcon->service));
72 trim_string(base_directory, NULL, "/");
75 pvfs->base_directory = base_directory;
77 /* the directory must exist. Note that we deliberately don't
78 check that it is readable */
79 if (stat(pvfs->base_directory, &st) != 0 || !S_ISDIR(st.st_mode)) {
80 DEBUG(0,("pvfs_connect: '%s' is not a directory, when connecting to [%s]\n",
81 pvfs->base_directory, sharename));
82 return NT_STATUS_BAD_NETWORK_NAME;
85 tcon->fs_type = talloc_strdup(tcon, "NTFS");
86 tcon->dev_type = talloc_strdup(tcon, "A:");
88 ntvfs->private_data = pvfs;
90 pvfs->brl_context = brl_init(pvfs,
91 pvfs->tcon->smb_conn->connection->server_id,
93 pvfs->tcon->smb_conn->connection->messaging_ctx);
94 if (pvfs->brl_context == NULL) {
95 return NT_STATUS_INTERNAL_DB_CORRUPTION;
98 pvfs->odb_context = odb_init(pvfs,
99 pvfs->tcon->smb_conn->connection->server_id,
101 pvfs->tcon->smb_conn->connection->messaging_ctx);
102 if (pvfs->odb_context == NULL) {
103 return NT_STATUS_INTERNAL_DB_CORRUPTION;
106 /* allocate the fnum id -> ptr tree */
107 pvfs->idtree_fnum = idr_init(pvfs);
108 if (pvfs->idtree_fnum == NULL) {
109 return NT_STATUS_NO_MEMORY;
112 /* allocate the search handle -> ptr tree */
113 pvfs->idtree_search = idr_init(pvfs);
114 if (pvfs->idtree_search == NULL) {
115 return NT_STATUS_NO_MEMORY;
118 status = pvfs_mangle_init(pvfs);
119 if (!NT_STATUS_IS_OK(status)) {
123 pvfs_setup_options(pvfs);
129 disconnect from a share
131 static NTSTATUS pvfs_disconnect(struct ntvfs_module_context *ntvfs,
132 struct smbsrv_tcon *tcon)
138 ioctl interface - we don't do any
140 static NTSTATUS pvfs_ioctl(struct ntvfs_module_context *ntvfs,
141 struct smbsrv_request *req, union smb_ioctl *io)
143 return NT_STATUS_INVALID_PARAMETER;
147 check if a directory exists
149 static NTSTATUS pvfs_chkpath(struct ntvfs_module_context *ntvfs,
150 struct smbsrv_request *req, struct smb_chkpath *cp)
152 struct pvfs_state *pvfs = ntvfs->private_data;
153 struct pvfs_filename *name;
156 /* resolve the cifs name to a posix name */
157 status = pvfs_resolve_name(pvfs, req, cp->in.path, 0, &name);
158 if (!NT_STATUS_IS_OK(status)) {
163 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
166 if (!S_ISDIR(name->st.st_mode)) {
167 return NT_STATUS_NOT_A_DIRECTORY;
176 static NTSTATUS pvfs_copy(struct ntvfs_module_context *ntvfs,
177 struct smbsrv_request *req, struct smb_copy *cp)
179 DEBUG(0,("pvfs_copy not implemented\n"));
180 return NT_STATUS_NOT_SUPPORTED;
184 return print queue info
186 static NTSTATUS pvfs_lpq(struct ntvfs_module_context *ntvfs,
187 struct smbsrv_request *req, union smb_lpq *lpq)
189 return NT_STATUS_NOT_SUPPORTED;
192 /* SMBtrans - not used on file shares */
193 static NTSTATUS pvfs_trans(struct ntvfs_module_context *ntvfs,
194 struct smbsrv_request *req, struct smb_trans2 *trans2)
196 return NT_STATUS_ACCESS_DENIED;
200 initialialise the POSIX disk backend, registering ourselves with the ntvfs subsystem
202 NTSTATUS ntvfs_posix_init(void)
205 struct ntvfs_ops ops;
209 ops.type = NTVFS_DISK;
211 /* fill in all the operations */
212 ops.connect = pvfs_connect;
213 ops.disconnect = pvfs_disconnect;
214 ops.unlink = pvfs_unlink;
215 ops.chkpath = pvfs_chkpath;
216 ops.qpathinfo = pvfs_qpathinfo;
217 ops.setpathinfo = pvfs_setpathinfo;
218 ops.open = pvfs_open;
219 ops.mkdir = pvfs_mkdir;
220 ops.rmdir = pvfs_rmdir;
221 ops.rename = pvfs_rename;
222 ops.copy = pvfs_copy;
223 ops.ioctl = pvfs_ioctl;
224 ops.read = pvfs_read;
225 ops.write = pvfs_write;
226 ops.seek = pvfs_seek;
227 ops.flush = pvfs_flush;
228 ops.close = pvfs_close;
229 ops.exit = pvfs_exit;
230 ops.lock = pvfs_lock;
231 ops.setfileinfo = pvfs_setfileinfo;
232 ops.qfileinfo = pvfs_qfileinfo;
233 ops.fsinfo = pvfs_fsinfo;
235 ops.search_first = pvfs_search_first;
236 ops.search_next = pvfs_search_next;
237 ops.search_close = pvfs_search_close;
238 ops.trans = pvfs_trans;
239 ops.logoff = pvfs_logoff;
240 ops.async_setup = pvfs_async_setup;
242 /* register ourselves with the NTVFS subsystem. We register
243 under the name 'default' as we wish to be the default
244 backend, and also register as 'posix' */
245 ops.name = "default";
246 ret = register_backend("ntvfs", &ops);
249 ret = register_backend("ntvfs", &ops);
251 if (!NT_STATUS_IS_OK(ret)) {
252 DEBUG(0,("Failed to register POSIX backend!\n"));