s4-netlogon: implement dcesrv_netr_DsRAddressToSitenamesExW
[Samba/aatanasov.git] / source4 / ntvfs / ntvfs_base.c
blobb581588d9d9eeb7689357f5deece3dff8df89dd2
1 /*
2 Unix SMB/CIFS implementation.
3 NTVFS base code
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 3 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, see <http://www.gnu.org/licenses/>.
22 this implements the core code for all NTVFS modules. Backends register themselves here.
25 #include "includes.h"
26 #include "../lib/util/dlinklist.h"
27 #include "ntvfs/ntvfs.h"
28 #include "param/param.h"
30 /* the list of currently registered NTVFS backends, note that there
31 * can be more than one backend with the same name, as long as they
32 * have different typesx */
33 static struct ntvfs_backend {
34 const struct ntvfs_ops *ops;
35 } *backends = NULL;
36 static int num_backends;
39 register a NTVFS backend.
41 The 'name' can be later used by other backends to find the operations
42 structure for this backend.
44 The 'type' is used to specify whether this is for a disk, printer or IPC$ share
46 NTSTATUS ntvfs_register(const struct ntvfs_ops *ops,
47 const struct ntvfs_critical_sizes *const sizes)
49 struct ntvfs_ops *new_ops;
51 if (ntvfs_interface_differs(sizes)) {
52 DEBUG(0, ("NTVFS backend '%s' for type %d "
53 "failed version check\n",
54 ops->name, (int)ops->type));
55 return NT_STATUS_BAD_FUNCTION_TABLE;
58 if (ntvfs_backend_byname(ops->name, ops->type) != NULL) {
59 /* its already registered! */
60 DEBUG(0,("NTVFS backend '%s' for type %d already registered\n",
61 ops->name, (int)ops->type));
62 return NT_STATUS_OBJECT_NAME_COLLISION;
65 backends = realloc_p(backends, struct ntvfs_backend, num_backends+1);
66 if (!backends) {
67 smb_panic("out of memory in ntvfs_register");
70 new_ops = smb_xmemdup(ops, sizeof(*ops));
71 new_ops->name = smb_xstrdup(ops->name);
73 backends[num_backends].ops = new_ops;
75 num_backends++;
77 DEBUG(3,("NTVFS backend '%s' for type %d registered\n",
78 ops->name,ops->type));
80 return NT_STATUS_OK;
85 return the operations structure for a named backend of the specified type
87 const struct ntvfs_ops *ntvfs_backend_byname(const char *name, enum ntvfs_type type)
89 int i;
91 for (i=0;i<num_backends;i++) {
92 if (backends[i].ops->type == type &&
93 strcmp(backends[i].ops->name, name) == 0) {
94 return backends[i].ops;
98 return NULL;
103 return the NTVFS interface version, and the size of some critical types
104 This can be used by backends to either detect compilation errors, or provide
105 multiple implementations for different smbd compilation options in one module
108 static const NTVFS_CURRENT_CRITICAL_SIZES(critical_sizes);
110 const struct ntvfs_critical_sizes *ntvfs_interface_version(void)
112 return &critical_sizes;
115 bool ntvfs_interface_differs(const struct ntvfs_critical_sizes *const iface)
117 /* The comparison would be easier with memcmp, but compiler-interset
118 * alignment padding is not guaranteed to be zeroed.
121 #define FIELD_DIFFERS(field) (iface->field != critical_sizes.field)
123 if (FIELD_DIFFERS(interface_version))
124 return true;
126 if (FIELD_DIFFERS(sizeof_ntvfs_critical_sizes))
127 return true;
129 if (FIELD_DIFFERS(sizeof_ntvfs_context))
130 return true;
132 if (FIELD_DIFFERS(sizeof_ntvfs_module_context))
133 return true;
135 if (FIELD_DIFFERS(sizeof_ntvfs_ops))
136 return true;
138 if (FIELD_DIFFERS(sizeof_ntvfs_async_state))
139 return true;
141 if (FIELD_DIFFERS(sizeof_ntvfs_request))
142 return true;
144 /* Versions match. */
145 return false;
147 #undef FIELD_DIFFERS
151 initialise a connection structure to point at a NTVFS backend
153 NTSTATUS ntvfs_init_connection(TALLOC_CTX *mem_ctx, struct share_config *scfg, enum ntvfs_type type,
154 enum protocol_types protocol,
155 uint64_t ntvfs_client_caps,
156 struct tevent_context *ev, struct messaging_context *msg,
157 struct loadparm_context *lp_ctx,
158 struct server_id server_id, struct ntvfs_context **_ctx)
160 const char **handlers = share_string_list_option(mem_ctx, scfg, SHARE_NTVFS_HANDLER);
161 int i;
162 struct ntvfs_context *ctx;
164 if (!handlers) {
165 return NT_STATUS_INTERNAL_ERROR;
168 ctx = talloc_zero(mem_ctx, struct ntvfs_context);
169 NT_STATUS_HAVE_NO_MEMORY(ctx);
170 ctx->protocol = protocol;
171 ctx->client_caps = ntvfs_client_caps;
172 ctx->type = type;
173 ctx->config = talloc_steal(ctx, scfg);
174 ctx->event_ctx = ev;
175 ctx->msg_ctx = msg;
176 ctx->server_id = server_id;
177 ctx->lp_ctx = lp_ctx;
179 for (i=0; handlers[i]; i++) {
180 struct ntvfs_module_context *ntvfs;
182 ntvfs = talloc_zero(ctx, struct ntvfs_module_context);
183 NT_STATUS_HAVE_NO_MEMORY(ntvfs);
184 ntvfs->ctx = ctx;
185 ntvfs->ops = ntvfs_backend_byname(handlers[i], ctx->type);
186 if (!ntvfs->ops) {
187 DEBUG(1,("ntvfs_init_connection: failed to find backend=%s, type=%d\n",
188 handlers[i], ctx->type));
189 return NT_STATUS_INTERNAL_ERROR;
191 ntvfs->depth = i;
192 DLIST_ADD_END(ctx->modules, ntvfs, struct ntvfs_module_context *);
195 if (!ctx->modules) {
196 return NT_STATUS_INTERNAL_ERROR;
199 *_ctx = ctx;
200 return NT_STATUS_OK;
203 NTSTATUS ntvfs_init(struct loadparm_context *lp_ctx)
205 static bool initialized = false;
206 extern NTSTATUS ntvfs_posix_init(void);
207 extern NTSTATUS ntvfs_cifs_init(void);
208 extern NTSTATUS ntvfs_smb2_init(void);
209 extern NTSTATUS ntvfs_nbench_init(void);
210 extern NTSTATUS ntvfs_unixuid_init(void);
211 extern NTSTATUS ntvfs_ipc_init(void);
212 extern NTSTATUS ntvfs_print_init(void);
213 extern NTSTATUS ntvfs_simple_init(void);
214 extern NTSTATUS ntvfs_cifs_posix_init(void);
215 init_module_fn static_init[] = { STATIC_ntvfs_MODULES };
216 init_module_fn *shared_init;
218 if (initialized) return NT_STATUS_OK;
219 initialized = true;
221 shared_init = load_samba_modules(NULL, lp_ctx, "ntvfs");
223 run_init_functions(static_init);
224 run_init_functions(shared_init);
226 talloc_free(shared_init);
228 return NT_STATUS_OK;