1/* 2 Unix SMB/CIFS implementation. 3 4 Modular shares configuration system 5 6 Copyright (C) Simo Sorce 2006 7 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. 12 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. 17 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/>. 20*/ 21 22#include "includes.h" 23#include "param/share.h" 24#include "param/param.h" 25 26const char *share_string_option(struct share_config *scfg, const char *opt_name, const char *defval) 27{ 28 return scfg->ctx->ops->string_option(scfg, opt_name, defval); 29} 30 31int share_int_option(struct share_config *scfg, const char *opt_name, int defval) 32{ 33 return scfg->ctx->ops->int_option(scfg, opt_name, defval); 34} 35 36bool share_bool_option(struct share_config *scfg, const char *opt_name, bool defval) 37{ 38 return scfg->ctx->ops->bool_option(scfg, opt_name, defval); 39} 40 41const char **share_string_list_option(TALLOC_CTX *mem_ctx, struct share_config *scfg, const char *opt_name) 42{ 43 return scfg->ctx->ops->string_list_option(mem_ctx, scfg, opt_name); 44} 45 46NTSTATUS share_list_all(TALLOC_CTX *mem_ctx, struct share_context *sctx, int *count, const char ***names) 47{ 48 return sctx->ops->list_all(mem_ctx, sctx, count, names); 49} 50 51NTSTATUS share_get_config(TALLOC_CTX *mem_ctx, struct share_context *sctx, const char *name, struct share_config **scfg) 52{ 53 return sctx->ops->get_config(mem_ctx, sctx, name, scfg); 54} 55 56NTSTATUS share_create(struct share_context *sctx, const char *name, struct share_info *info, int count) 57{ 58 if (sctx->ops->create) { 59 return sctx->ops->create(sctx, name, info, count); 60 } 61 return NT_STATUS_NOT_IMPLEMENTED; 62} 63 64NTSTATUS share_set(struct share_context *sctx, const char *name, struct share_info *info, int count) 65{ 66 if (sctx->ops->set) { 67 return sctx->ops->set(sctx, name, info, count); 68 } 69 return NT_STATUS_NOT_IMPLEMENTED; 70} 71 72NTSTATUS share_remove(struct share_context *sctx, const char *name) 73{ 74 if (sctx->ops->remove) { 75 return sctx->ops->remove(sctx, name); 76 } 77 return NT_STATUS_NOT_IMPLEMENTED; 78} 79 80/* List of currently available share backends */ 81static struct share_ops **backends = NULL; 82 83static const struct share_ops *share_backend_by_name(const char *name) 84{ 85 int i; 86 87 for (i = 0; backends && backends[i]; i++) { 88 if (strcmp(backends[i]->name, name) == 0) { 89 return backends[i]; 90 } 91 } 92 93 return NULL; 94} 95 96/* 97 Register the share backend 98*/ 99NTSTATUS share_register(const struct share_ops *ops) 100{ 101 int i; 102 103 if (share_backend_by_name(ops->name) != NULL) { 104 DEBUG(0,("SHARE backend [%s] already registered\n", ops->name)); 105 return NT_STATUS_OBJECT_NAME_COLLISION; 106 } 107 108 i = 0; 109 while (backends && backends[i]) { 110 i++; 111 } 112 113 backends = realloc_p(backends, struct share_ops *, i + 2); 114 if (!backends) { 115 smb_panic("out of memory in share_register"); 116 } 117 118 backends[i] = (struct share_ops *)smb_xmemdup(ops, sizeof(*ops)); 119 backends[i]->name = smb_xstrdup(ops->name); 120 121 backends[i + 1] = NULL; 122 123 DEBUG(3, ("SHARE backend [%s] registered.\n", ops->name)); 124 125 return NT_STATUS_OK; 126} 127 128NTSTATUS share_get_context_by_name(TALLOC_CTX *mem_ctx, const char *backend_name, 129 struct tevent_context *event_ctx, 130 struct loadparm_context *lp_ctx, 131 struct share_context **ctx) 132{ 133 const struct share_ops *ops; 134 135 ops = share_backend_by_name(backend_name); 136 if (!ops) { 137 DEBUG(0, ("share_init_connection: share backend [%s] not found!\n", backend_name)); 138 return NT_STATUS_INTERNAL_ERROR; 139 } 140 141 return ops->init(mem_ctx, ops, event_ctx, lp_ctx, ctx); 142} 143 144/* 145 initialise the SHARE subsystem 146*/ 147NTSTATUS share_init(void) 148{ 149 extern NTSTATUS share_ldb_init(void); 150 extern NTSTATUS share_classic_init(void); 151 init_module_fn static_init[] = { STATIC_share_MODULES }; 152 153 run_init_functions(static_init); 154 155 return NT_STATUS_OK; 156} 157