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.
27 #include "dlinklist.h"
29 #include "ntvfs/ntvfs.h"
31 /* the list of currently registered NTVFS backends, note that there
32 * can be more than one backend with the same name, as long as they
33 * have different typesx */
34 static struct ntvfs_backend {
35 const struct ntvfs_ops *ops;
37 static int num_backends;
40 register a NTVFS backend.
42 The 'name' can be later used by other backends to find the operations
43 structure for this backend.
45 The 'type' is used to specify whether this is for a disk, printer or IPC$ share
47 _PUBLIC_ NTSTATUS ntvfs_register(const struct ntvfs_ops *ops)
49 struct ntvfs_ops *new_ops;
51 if (ntvfs_backend_byname(ops->name, ops->type) != NULL) {
52 /* its already registered! */
53 DEBUG(0,("NTVFS backend '%s' for type %d already registered\n",
54 ops->name, (int)ops->type));
55 return NT_STATUS_OBJECT_NAME_COLLISION;
58 backends = realloc_p(backends, struct ntvfs_backend, num_backends+1);
60 smb_panic("out of memory in ntvfs_register");
63 new_ops = smb_xmemdup(ops, sizeof(*ops));
64 new_ops->name = smb_xstrdup(ops->name);
66 backends[num_backends].ops = new_ops;
70 DEBUG(3,("NTVFS backend '%s' for type %d registered\n",
71 ops->name,ops->type));
78 return the operations structure for a named backend of the specified type
80 _PUBLIC_ const struct ntvfs_ops *ntvfs_backend_byname(const char *name, enum ntvfs_type type)
84 for (i=0;i<num_backends;i++) {
85 if (backends[i].ops->type == type &&
86 strcmp(backends[i].ops->name, name) == 0) {
87 return backends[i].ops;
96 return the NTVFS interface version, and the size of some critical types
97 This can be used by backends to either detect compilation errors, or provide
98 multiple implementations for different smbd compilation options in one module
101 static const NTVFS_CURRENT_CRITICAL_SIZES(critical_sizes);
103 _PUBLIC_ const struct ntvfs_critical_sizes *ntvfs_interface_version(void)
105 return &critical_sizes;
108 _PUBLIC_ BOOL ntvfs_interface_differs(const struct ntvfs_critical_sizes *const iface)
110 /* The comparison would be easier with memcmp, but compiler-interset
111 * alignment padding is not guaranteed to be zeroed.
114 #define FIELD_DIFFERS(field) (iface->field != critical_sizes.field)
116 if (FIELD_DIFFERS(interface_version))
119 if (FIELD_DIFFERS(sizeof_ntvfs_critical_sizes))
122 if (FIELD_DIFFERS(sizeof_ntvfs_context))
125 if (FIELD_DIFFERS(sizeof_ntvfs_module_context))
128 if (FIELD_DIFFERS(sizeof_ntvfs_ops))
131 if (FIELD_DIFFERS(sizeof_ntvfs_async_state))
134 if (FIELD_DIFFERS(sizeof_ntvfs_request))
137 /* Versions match. */
145 initialise a connection structure to point at a NTVFS backend
147 NTSTATUS ntvfs_init_connection(TALLOC_CTX *mem_ctx, int snum, enum ntvfs_type type,
148 enum protocol_types protocol,
149 struct event_context *ev, struct messaging_context *msg,
150 uint32_t server_id, struct ntvfs_context **_ctx)
152 const char **handlers = lp_ntvfs_handler(snum);
154 struct ntvfs_context *ctx;
157 return NT_STATUS_INTERNAL_ERROR;
160 ctx = talloc_zero(mem_ctx, struct ntvfs_context);
161 NT_STATUS_HAVE_NO_MEMORY(ctx);
162 ctx->protocol = protocol;
164 ctx->config.snum = snum;
167 ctx->server_id = server_id;
169 for (i=0; handlers[i]; i++) {
170 struct ntvfs_module_context *ntvfs;
172 ntvfs = talloc_zero(ctx, struct ntvfs_module_context);
173 NT_STATUS_HAVE_NO_MEMORY(ntvfs);
175 ntvfs->ops = ntvfs_backend_byname(handlers[i], ctx->type);
177 DEBUG(1,("ntvfs_init_connection: failed to find backend=%s, type=%d\n",
178 handlers[i], ctx->type));
179 return NT_STATUS_INTERNAL_ERROR;
182 DLIST_ADD_END(ctx->modules, ntvfs, struct ntvfs_module_context *);
186 return NT_STATUS_INTERNAL_ERROR;
193 NTSTATUS ntvfs_init(void)
195 init_module_fn static_init[] = STATIC_ntvfs_MODULES;
196 init_module_fn *shared_init = load_samba_modules(NULL, "ntvfs");
198 run_init_functions(static_init);
199 run_init_functions(shared_init);
201 talloc_free(shared_init);