r19281: Generalize what we do for the RAW-QFILEINFO test call so that the same process
[Samba/ekacnet.git] / source4 / param / share.c
blob7cbaa8a85cd39bbb69a61aa650e44215385449ee
1 /*
2 Unix SMB/CIFS implementation.
4 Modular services configuration system
6 Copyright (C) Simo Sorce 2006
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 #include "includes.h"
24 #include "param/share.h"
25 #include "build.h"
27 const char *share_string_option(struct share_config *scfg, const char *opt_name, const char *defval)
29 return scfg->ctx->ops->string_option(scfg, opt_name, defval);
32 int share_int_option(struct share_config *scfg, const char *opt_name, int defval)
34 return scfg->ctx->ops->int_option(scfg, opt_name, defval);
37 BOOL share_bool_option(struct share_config *scfg, const char *opt_name, BOOL defval)
39 return scfg->ctx->ops->bool_option(scfg, opt_name, defval);
42 const char **share_string_list_option(TALLOC_CTX *mem_ctx, struct share_config *scfg, const char *opt_name)
44 return scfg->ctx->ops->string_list_option(mem_ctx, scfg, opt_name);
47 NTSTATUS share_list_all(TALLOC_CTX *mem_ctx, struct share_context *sctx, int *count, const char ***names)
49 return sctx->ops->list_all(mem_ctx, sctx, count, names);
52 NTSTATUS share_get_config(TALLOC_CTX *mem_ctx, struct share_context *sctx, const char *name, struct share_config **scfg)
54 return sctx->ops->get_config(mem_ctx, sctx, name, scfg);
57 NTSTATUS share_create(struct share_context *sctx, const char *name, struct share_info *info, int count)
59 if (sctx->ops->create) {
60 return sctx->ops->create(sctx, name, info, count);
62 return NT_STATUS_NOT_IMPLEMENTED;
65 NTSTATUS share_set(struct share_context *sctx, const char *name, struct share_info *info, int count)
67 if (sctx->ops->set) {
68 return sctx->ops->set(sctx, name, info, count);
70 return NT_STATUS_NOT_IMPLEMENTED;
73 NTSTATUS share_remove(struct share_context *sctx, const char *name)
75 if (sctx->ops->remove) {
76 return sctx->ops->remove(sctx, name);
78 return NT_STATUS_NOT_IMPLEMENTED;
81 /* List of currently available share backends */
82 static struct share_ops **backends = NULL;
84 static const struct share_ops *share_backend_by_name(const char *name)
86 int i;
88 for (i = 0; backends && backends[i]; i++) {
89 if (strcmp(backends[i]->name, name) == 0) {
90 return backends[i];
94 return NULL;
98 Register the share backend
100 NTSTATUS share_register(const struct share_ops *ops)
102 int i;
104 if (share_backend_by_name(ops->name) != NULL) {
105 DEBUG(0,("SHARE backend [%s] already registered\n", ops->name));
106 return NT_STATUS_OBJECT_NAME_COLLISION;
109 i = 0;
110 while (backends && backends[i]) {
111 i++;
114 backends = realloc_p(backends, struct share_ops *, i + 2);
115 if (!backends) {
116 smb_panic("out of memory in share_register");
119 backends[i] = malloc(sizeof(struct share_ops));
120 if (!backends[i]) {
121 smb_panic("out of memory in share_register");
124 backends[i] = smb_xmemdup(ops, sizeof(*ops));
125 backends[i]->name = smb_xstrdup(ops->name);
127 backends[i + 1] = NULL;
129 DEBUG(3, ("SHARE backend [%s] registered.\n", ops->name));
131 return NT_STATUS_OK;
134 NTSTATUS share_get_context(TALLOC_CTX *mem_ctx, struct share_context **ctx)
136 const struct share_ops *ops;
138 ops = share_backend_by_name(lp_share_backend());
139 if (!ops) {
140 DEBUG(0, ("share_init_connection: share backend [%s] not found!\n", lp_share_backend()));
141 return NT_STATUS_INTERNAL_ERROR;
144 return ops->init(mem_ctx, ops, ctx);
148 initialise the SHARE subsystem
150 NTSTATUS share_init(void)
152 init_module_fn static_init[] = STATIC_share_MODULES;
153 init_module_fn *shared_init = load_samba_modules(NULL, "share");
155 run_init_functions(static_init);
156 run_init_functions(shared_init);
158 talloc_free(shared_init);
160 return NT_STATUS_OK;