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;
45 pvfs->share_name = talloc_strdup(pvfs, lp_servicename(snum));
50 connect to a share - used when a tree_connect operation comes
51 in. For a disk based backend we needs to ensure that the base
52 directory exists (tho it doesn't need to be accessible by the user,
55 static NTSTATUS pvfs_connect(struct ntvfs_module_context *ntvfs,
56 struct smbsrv_request *req, const char *sharename)
58 struct smbsrv_tcon *tcon = req->tcon;
59 struct pvfs_state *pvfs;
64 pvfs = talloc_p(tcon, struct pvfs_state);
66 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 if (pvfs->brl_context == NULL) {
94 return NT_STATUS_INTERNAL_DB_CORRUPTION;
97 status = pvfs_mangle_init(pvfs);
98 if (!NT_STATUS_IS_OK(status)) {
102 pvfs_setup_options(pvfs);
108 disconnect from a share
110 static NTSTATUS pvfs_disconnect(struct ntvfs_module_context *ntvfs,
111 struct smbsrv_tcon *tcon)
117 ioctl interface - we don't do any
119 static NTSTATUS pvfs_ioctl(struct ntvfs_module_context *ntvfs,
120 struct smbsrv_request *req, union smb_ioctl *io)
122 return NT_STATUS_INVALID_PARAMETER;
126 check if a directory exists
128 static NTSTATUS pvfs_chkpath(struct ntvfs_module_context *ntvfs,
129 struct smbsrv_request *req, struct smb_chkpath *cp)
131 struct pvfs_state *pvfs = ntvfs->private_data;
132 struct pvfs_filename *name;
135 /* resolve the cifs name to a posix name */
136 status = pvfs_resolve_name(pvfs, req, cp->in.path, 0, &name);
137 if (!NT_STATUS_IS_OK(status)) {
142 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
145 if (!S_ISDIR(name->st.st_mode)) {
146 return NT_STATUS_NOT_A_DIRECTORY;
155 static NTSTATUS pvfs_copy(struct ntvfs_module_context *ntvfs,
156 struct smbsrv_request *req, struct smb_copy *cp)
158 DEBUG(0,("pvfs_copy not implemented\n"));
159 return NT_STATUS_NOT_SUPPORTED;
165 static NTSTATUS pvfs_seek(struct ntvfs_module_context *ntvfs,
166 struct smbsrv_request *req, struct smb_seek *io)
168 DEBUG(0,("pvfs_seek not implemented\n"));
169 return NT_STATUS_NOT_SUPPORTED;
173 set info on a pathname
175 static NTSTATUS pvfs_setpathinfo(struct ntvfs_module_context *ntvfs,
176 struct smbsrv_request *req, union smb_setfileinfo *st)
178 DEBUG(0,("pvfs_setpathinfo not implemented\n"));
179 return NT_STATUS_NOT_SUPPORTED;
183 return print queue info
185 static NTSTATUS pvfs_lpq(struct ntvfs_module_context *ntvfs,
186 struct smbsrv_request *req, union smb_lpq *lpq)
188 return NT_STATUS_NOT_SUPPORTED;
191 /* SMBtrans - not used on file shares */
192 static NTSTATUS pvfs_trans(struct ntvfs_module_context *ntvfs,
193 struct smbsrv_request *req, struct smb_trans2 *trans2)
195 return NT_STATUS_ACCESS_DENIED;
199 initialialise the POSIX disk backend, registering ourselves with the ntvfs subsystem
201 NTSTATUS ntvfs_posix_init(void)
204 struct ntvfs_ops ops;
208 ops.type = NTVFS_DISK;
210 /* fill in all the operations */
211 ops.connect = pvfs_connect;
212 ops.disconnect = pvfs_disconnect;
213 ops.unlink = pvfs_unlink;
214 ops.chkpath = pvfs_chkpath;
215 ops.qpathinfo = pvfs_qpathinfo;
216 ops.setpathinfo = pvfs_setpathinfo;
217 ops.open = pvfs_open;
218 ops.mkdir = pvfs_mkdir;
219 ops.rmdir = pvfs_rmdir;
220 ops.rename = pvfs_rename;
221 ops.copy = pvfs_copy;
222 ops.ioctl = pvfs_ioctl;
223 ops.read = pvfs_read;
224 ops.write = pvfs_write;
225 ops.seek = pvfs_seek;
226 ops.flush = pvfs_flush;
227 ops.close = pvfs_close;
228 ops.exit = pvfs_exit;
229 ops.lock = pvfs_lock;
230 ops.setfileinfo = pvfs_setfileinfo;
231 ops.qfileinfo = pvfs_qfileinfo;
232 ops.fsinfo = pvfs_fsinfo;
234 ops.search_first = pvfs_search_first;
235 ops.search_next = pvfs_search_next;
236 ops.search_close = pvfs_search_close;
237 ops.trans = pvfs_trans;
238 ops.logoff = pvfs_logoff;
240 /* register ourselves with the NTVFS subsystem. We register
241 under the name 'default' as we wish to be the default
242 backend, and also register as 'posix' */
243 ops.name = "default";
244 ret = register_backend("ntvfs", &ops);
247 ret = register_backend("ntvfs", &ops);
249 if (!NT_STATUS_IS_OK(ret)) {
250 DEBUG(0,("Failed to register POSIX backend!\n"));