2 Unix SMB/CIFS implementation.
5 Copyright (C) Andrew Tridgell 2003
6 Copyright (C) Stefan (metze) Metzmacher 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 the core code for all NTVFS modules. Backends register themselves here.
29 /* the list of currently registered NTVFS backends, note that there
30 * can be more than one backend with the same name, as long as they
31 * have different typesx */
33 struct ntvfs_ops *ops;
35 static int num_backends;
38 register a NTVFS backend.
40 The 'name' can be later used by other backends to find the operations
41 structure for this backend.
43 The 'type' is used to specify whether this is for a disk, printer or IPC$ share
45 static NTSTATUS ntvfs_register(void *_ops)
47 struct ntvfs_ops *ops = _ops;
49 if (ntvfs_backend_byname(ops->name, ops->type) != NULL) {
50 /* its already registered! */
51 DEBUG(2,("NTVFS backend '%s' for type %d already registered\n",
52 ops->name, (int)ops->type));
53 return NT_STATUS_OBJECT_NAME_COLLISION;
56 backends = Realloc(backends, sizeof(backends[0]) * (num_backends+1));
58 smb_panic("out of memory in ntvfs_register");
61 backends[num_backends].ops = smb_xmemdup(ops, sizeof(*ops));
62 backends[num_backends].ops->name = smb_xstrdup(ops->name);
71 return the operations structure for a named backend of the specified type
73 struct ntvfs_ops *ntvfs_backend_byname(const char *name, enum ntvfs_type type)
77 for (i=0;i<num_backends;i++) {
78 if (backends[i].ops->type == type &&
79 strcmp(backends[i].ops->name, name) == 0) {
80 return backends[i].ops;
89 return the NTVFS interface version, and the size of some critical types
90 This can be used by backends to either detect compilation errors, or provide
91 multiple implementations for different smbd compilation options in one module
93 const struct ntvfs_critical_sizes *ntvfs_interface_version(void)
95 static const struct ntvfs_critical_sizes critical_sizes = {
96 NTVFS_INTERFACE_VERSION,
97 sizeof(struct ntvfs_ops),
99 sizeof(struct tcon_context),
100 sizeof(struct request_context),
103 return &critical_sizes;
108 initialise the NTVFS subsystem
110 BOOL ntvfs_init(void)
114 status = register_subsystem("ntvfs", ntvfs_register);
115 if (!NT_STATUS_IS_OK(status)) {
119 /* FIXME: Perhaps panic if a basic backend, such as IPC, fails to initialise? */
122 DEBUG(3,("NTVFS subsystem version %d initialised\n", NTVFS_INTERFACE_VERSION));
128 initialise a connection structure to point at a NTVFS backend
130 NTSTATUS ntvfs_init_connection(struct request_context *req)
132 const char *handler = lp_ntvfs_handler(req->conn->service);
134 if (strequal(handler, "default"))
137 req->conn->ntvfs_ops = ntvfs_backend_byname(handler, req->conn->type);
139 if (!req->conn->ntvfs_ops) {
140 DEBUG(1,("ntvfs_init_connection: failed to find backend=%s, type=%d\n", handler, req->conn->type));
141 return NT_STATUS_UNSUCCESSFUL;