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;
43 pvfs->share_name = talloc_strdup(pvfs, lp_servicename(snum));
48 connect to a share - used when a tree_connect operation comes
49 in. For a disk based backend we needs to ensure that the base
50 directory exists (tho it doesn't need to be accessible by the user,
53 static NTSTATUS pvfs_connect(struct smbsrv_request *req, const char *sharename)
55 struct smbsrv_tcon *tcon = req->tcon;
56 struct pvfs_state *pvfs;
60 DEBUG(0,("WARNING: the posix vfs handler is incomplete - you probably want \"ntvfs handler = simple\"\n"));
62 pvfs = talloc_named(tcon, sizeof(struct pvfs_state), "pvfs_connect(%s)", sharename);
64 return NT_STATUS_NO_MEMORY;
68 /* for simplicity of path construction, remove any trailing slash now */
69 base_directory = talloc_strdup(pvfs, lp_pathname(tcon->service));
70 trim_string(base_directory, NULL, "/");
73 pvfs->base_directory = base_directory;
75 /* the directory must exist. Note that we deliberately don't
76 check that it is readable */
77 if (stat(pvfs->base_directory, &st) != 0 || !S_ISDIR(st.st_mode)) {
78 DEBUG(0,("pvfs_connect: '%s' is not a directory, when connecting to [%s]\n",
79 pvfs->base_directory, sharename));
80 return NT_STATUS_BAD_NETWORK_NAME;
83 tcon->fs_type = talloc_strdup(tcon, "NTFS");
84 tcon->dev_type = talloc_strdup(tcon, "A:");
85 tcon->ntvfs_private = pvfs;
87 pvfs_setup_options(pvfs);
93 disconnect from a share
95 static NTSTATUS pvfs_disconnect(struct smbsrv_tcon *tcon)
101 ioctl interface - we don't do any
103 static NTSTATUS pvfs_ioctl(struct smbsrv_request *req, union smb_ioctl *io)
105 DEBUG(0,("pvfs_ioctl not implemented\n"));
106 return NT_STATUS_INVALID_PARAMETER;
110 check if a directory exists
112 static NTSTATUS pvfs_chkpath(struct smbsrv_request *req, struct smb_chkpath *cp)
114 struct pvfs_state *pvfs = req->tcon->ntvfs_private;
115 struct pvfs_filename *name;
118 /* resolve the cifs name to a posix name */
119 status = pvfs_resolve_name(pvfs, req, cp->in.path, 0, &name);
120 if (!NT_STATUS_IS_OK(status)) {
125 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
128 if (!S_ISDIR(name->st.st_mode)) {
129 return NT_STATUS_NOT_A_DIRECTORY;
136 rename a set of files
138 static NTSTATUS pvfs_rename(struct smbsrv_request *req, union smb_rename *ren)
140 DEBUG(0,("pvfs_rename not implemented\n"));
141 return NT_STATUS_NOT_IMPLEMENTED;
147 static NTSTATUS pvfs_copy(struct smbsrv_request *req, struct smb_copy *cp)
149 DEBUG(0,("pvfs_copy not implemented\n"));
150 return NT_STATUS_NOT_SUPPORTED;
156 static NTSTATUS pvfs_seek(struct smbsrv_request *req, struct smb_seek *io)
158 DEBUG(0,("pvfs_seek not implemented\n"));
159 return NT_STATUS_NOT_SUPPORTED;
165 static NTSTATUS pvfs_flush(struct smbsrv_request *req, struct smb_flush *io)
167 DEBUG(0,("pvfs_flush not implemented\n"));
168 return NT_STATUS_NOT_IMPLEMENTED;
172 exit - closing files?
174 static NTSTATUS pvfs_exit(struct smbsrv_request *req)
176 DEBUG(0,("pvfs_exit not implemented\n"));
177 return NT_STATUS_NOT_SUPPORTED;
183 static NTSTATUS pvfs_lock(struct smbsrv_request *req, union smb_lock *lck)
185 DEBUG(0,("pvfs_lock not implemented\n"));
186 return NT_STATUS_NOT_IMPLEMENTED;
190 set info on a pathname
192 static NTSTATUS pvfs_setpathinfo(struct smbsrv_request *req, union smb_setfileinfo *st)
194 DEBUG(0,("pvfs_setpathinfo not implemented\n"));
195 return NT_STATUS_NOT_SUPPORTED;
199 return print queue info
201 static NTSTATUS pvfs_lpq(struct smbsrv_request *req, union smb_lpq *lpq)
203 return NT_STATUS_NOT_SUPPORTED;
206 /* SMBtrans - not used on file shares */
207 static NTSTATUS pvfs_trans(struct smbsrv_request *req, struct smb_trans2 *trans2)
209 return NT_STATUS_ACCESS_DENIED;
213 initialialise the POSIX disk backend, registering ourselves with the ntvfs subsystem
215 NTSTATUS ntvfs_posix_init(void)
218 struct ntvfs_ops ops;
222 ops.type = NTVFS_DISK;
224 /* fill in all the operations */
225 ops.connect = pvfs_connect;
226 ops.disconnect = pvfs_disconnect;
227 ops.unlink = pvfs_unlink;
228 ops.chkpath = pvfs_chkpath;
229 ops.qpathinfo = pvfs_qpathinfo;
230 ops.setpathinfo = pvfs_setpathinfo;
231 ops.open = pvfs_open;
232 ops.mkdir = pvfs_mkdir;
233 ops.rmdir = pvfs_rmdir;
234 ops.rename = pvfs_rename;
235 ops.copy = pvfs_copy;
236 ops.ioctl = pvfs_ioctl;
237 ops.read = pvfs_read;
238 ops.write = pvfs_write;
239 ops.seek = pvfs_seek;
240 ops.flush = pvfs_flush;
241 ops.close = pvfs_close;
242 ops.exit = pvfs_exit;
243 ops.lock = pvfs_lock;
244 ops.setfileinfo = pvfs_setfileinfo;
245 ops.qfileinfo = pvfs_qfileinfo;
246 ops.fsinfo = pvfs_fsinfo;
248 ops.search_first = pvfs_search_first;
249 ops.search_next = pvfs_search_next;
250 ops.search_close = pvfs_search_close;
251 ops.trans = pvfs_trans;
253 /* register ourselves with the NTVFS subsystem. We register
254 under the name 'default' as we wish to be the default
255 backend, and also register as 'posix' */
256 ops.name = "default";
257 ret = register_backend("ntvfs", &ops);
260 ret = register_backend("ntvfs", &ops);
262 if (!NT_STATUS_IS_OK(ret)) {
263 DEBUG(0,("Failed to register POSIX backend!\n"));