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"
28 #include "smb_server/smb_server.h"
30 #include "ntvfs/ntvfs.h"
32 /* the list of currently registered NTVFS backends, note that there
33 * can be more than one backend with the same name, as long as they
34 * have different typesx */
35 static struct ntvfs_backend {
36 const struct ntvfs_ops *ops;
38 static int num_backends;
41 register a NTVFS backend.
43 The 'name' can be later used by other backends to find the operations
44 structure for this backend.
46 The 'type' is used to specify whether this is for a disk, printer or IPC$ share
48 _PUBLIC_ NTSTATUS ntvfs_register(const void *_ops)
50 const struct ntvfs_ops *ops = _ops;
51 struct ntvfs_ops *new_ops;
53 if (ntvfs_backend_byname(ops->name, ops->type) != NULL) {
54 /* its already registered! */
55 DEBUG(0,("NTVFS backend '%s' for type %d already registered\n",
56 ops->name, (int)ops->type));
57 return NT_STATUS_OBJECT_NAME_COLLISION;
60 backends = realloc_p(backends, struct ntvfs_backend, num_backends+1);
62 smb_panic("out of memory in ntvfs_register");
65 new_ops = smb_xmemdup(ops, sizeof(*ops));
66 new_ops->name = smb_xstrdup(ops->name);
68 backends[num_backends].ops = new_ops;
72 DEBUG(3,("NTVFS backend '%s' for type %d registered\n",
73 ops->name,ops->type));
80 return the operations structure for a named backend of the specified type
82 _PUBLIC_ const struct ntvfs_ops *ntvfs_backend_byname(const char *name, enum ntvfs_type type)
86 for (i=0;i<num_backends;i++) {
87 if (backends[i].ops->type == type &&
88 strcmp(backends[i].ops->name, name) == 0) {
89 return backends[i].ops;
98 return the NTVFS interface version, and the size of some critical types
99 This can be used by backends to either detect compilation errors, or provide
100 multiple implementations for different smbd compilation options in one module
102 static const struct ntvfs_critical_sizes critical_sizes = {
103 .interface_version = NTVFS_INTERFACE_VERSION,
104 .sizeof_ntvfs_critical_sizes = sizeof(struct ntvfs_critical_sizes),
105 .sizeof_ntvfs_context = sizeof(struct ntvfs_context),
106 .sizeof_ntvfs_module_context = sizeof(struct ntvfs_module_context),
107 .sizeof_ntvfs_ops = sizeof(struct ntvfs_ops),
108 .sizeof_ntvfs_async_state = sizeof(struct ntvfs_async_state),
109 .sizeof_ntvfs_request = sizeof(struct ntvfs_request),
112 _PUBLIC_ const struct ntvfs_critical_sizes *ntvfs_interface_version(void)
114 return &critical_sizes;
119 initialise a connection structure to point at a NTVFS backend
121 NTSTATUS ntvfs_init_connection(TALLOC_CTX *mem_ctx, int snum, enum ntvfs_type type,
122 enum protocol_types protocol,
123 struct event_context *ev, struct messaging_context *msg,
124 uint32_t server_id, struct ntvfs_context **_ctx)
126 const char **handlers = lp_ntvfs_handler(snum);
128 struct ntvfs_context *ctx;
131 return NT_STATUS_INTERNAL_ERROR;
134 ctx = talloc_zero(mem_ctx, struct ntvfs_context);
135 NT_STATUS_HAVE_NO_MEMORY(ctx);
136 ctx->protocol = protocol;
138 ctx->config.snum = snum;
141 ctx->server_id = server_id;
143 for (i=0; handlers[i]; i++) {
144 struct ntvfs_module_context *ntvfs;
146 ntvfs = talloc_zero(ctx, struct ntvfs_module_context);
147 NT_STATUS_HAVE_NO_MEMORY(ntvfs);
149 ntvfs->ops = ntvfs_backend_byname(handlers[i], ctx->type);
151 DEBUG(1,("ntvfs_init_connection: failed to find backend=%s, type=%d\n",
152 handlers[i], ctx->type));
153 return NT_STATUS_INTERNAL_ERROR;
156 DLIST_ADD_END(ctx->modules, ntvfs, struct ntvfs_module_context *);
160 return NT_STATUS_INTERNAL_ERROR;
167 NTSTATUS ntvfs_init(void)
169 init_module_fn static_init[] = STATIC_ntvfs_MODULES;
170 init_module_fn *shared_init = load_samba_modules(NULL, "ntvfs");
172 run_init_functions(static_init);
173 run_init_functions(shared_init);
175 talloc_free(shared_init);