r2249: got rid of some more mem_ctx elements in structures
[jelmer/samba4-debian.git] / source / ntvfs / posix / vfs_posix.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    POSIX NTVFS backend
5
6    Copyright (C) Andrew Tridgell 2004
7
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.
12    
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.
17    
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.
21 */
22 /*
23   this implements most of the POSIX NTVFS backend
24   This is the default backend
25 */
26
27 #include "include/includes.h"
28 #include "vfs_posix.h"
29
30
31 /*
32   connect to a share - used when a tree_connect operation comes
33   in. For a disk based backend we needs to ensure that the base
34   directory exists (tho it doesn't need to be accessible by the user,
35   that comes later)
36 */
37 static NTSTATUS pvfs_connect(struct smbsrv_request *req, const char *sharename)
38 {
39         struct smbsrv_tcon *tcon = req->tcon;
40         struct pvfs_state *pvfs;
41         struct stat st;
42
43         DEBUG(0,("WARNING: the posix vfs handler is incomplete - you probably want \"ntvfs handler = simple\"\n"));
44
45         pvfs = talloc_named(tcon, sizeof(struct pvfs_state), "pvfs_connect(%s)", sharename);
46         if (pvfs == NULL) {
47                 return NT_STATUS_NO_MEMORY;
48         }
49
50         pvfs->base_directory = talloc_strdup(pvfs, lp_pathname(tcon->service));
51
52         /* the directory must exist. Note that we deliberately don't
53            check that it is readable */
54         if (stat(pvfs->base_directory, &st) != 0 || !S_ISDIR(st.st_mode)) {
55                 DEBUG(0,("pvfs_connect: '%s' is not a directory, when connecting to [%s]\n", 
56                          pvfs->base_directory, sharename));
57                 return NT_STATUS_BAD_NETWORK_NAME;
58         }
59
60         tcon->fs_type = talloc_strdup(tcon, "NTFS");
61         tcon->dev_type = talloc_strdup(tcon, "A:");
62
63         return NT_STATUS_OK;
64 }
65
66 /*
67   disconnect from a share
68 */
69 static NTSTATUS pvfs_disconnect(struct smbsrv_tcon *tcon)
70 {
71         return NT_STATUS_OK;
72 }
73
74 /*
75   initialialise the POSIX disk backend, registering ourselves with the ntvfs subsystem
76  */
77 NTSTATUS ntvfs_posix_init(void)
78 {
79         NTSTATUS ret;
80         struct ntvfs_ops ops;
81
82         ZERO_STRUCT(ops);
83
84         ops.name = "default";
85         ops.type = NTVFS_DISK;
86         
87         /* fill in all the operations */
88         ops.connect = pvfs_connect;
89         ops.disconnect = pvfs_disconnect;
90
91         /* register ourselves with the NTVFS subsystem. We register under the name 'default'
92            as we wish to be the default backend */
93         ret = register_backend("ntvfs", &ops);
94
95         if (!NT_STATUS_IS_OK(ret)) {
96                 DEBUG(0,("Failed to register POSIX backend!\n"));
97         }
98
99         return ret;
100 }