2 Unix SMB/CIFS implementation.
4 Classic file based services configuration
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 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/>.
23 #include "param/share.h"
24 #include "param/param.h"
26 static NTSTATUS sclassic_init(TALLOC_CTX *mem_ctx,
27 const struct share_ops *ops,
28 struct share_context **ctx)
30 *ctx = talloc(mem_ctx, struct share_context);
32 DEBUG(0, ("ERROR: Out of memory!\n"));
33 return NT_STATUS_NO_MEMORY;
37 (*ctx)->priv_data = global_loadparm;
42 static const char *sclassic_string_option(struct share_config *scfg,
46 struct loadparm_service *s = talloc_get_type(scfg->opaque,
47 struct loadparm_service);
48 struct loadparm_context *lp_ctx = talloc_get_type(scfg->ctx->priv_data,
49 struct loadparm_context);
53 if (strchr(opt_name, ':')) {
54 parm = talloc_strdup(scfg, opt_name);
58 val = strchr(parm, ':');
62 ret = lp_parm_string(lp_ctx, s, parm, val);
70 if (strcmp(opt_name, SHARE_NAME) == 0) {
74 if (strcmp(opt_name, SHARE_PATH) == 0) {
75 return lp_pathname(s);
78 if (strcmp(opt_name, SHARE_COMMENT) == 0) {
82 if (strcmp(opt_name, SHARE_VOLUME) == 0) {
83 return volume_label(s);
86 if (strcmp(opt_name, SHARE_TYPE) == 0) {
90 if (strcmp("NTFS", lp_fstype(s)) == 0) {
96 if (strcmp(opt_name, SHARE_PASSWORD) == 0) {
100 DEBUG(0,("request for unknown share string option '%s'\n",
106 static int sclassic_int_option(struct share_config *scfg, const char *opt_name, int defval)
108 struct loadparm_service *s = talloc_get_type(scfg->opaque,
109 struct loadparm_service);
110 struct loadparm_context *lp_ctx = talloc_get_type(scfg->ctx->priv_data,
111 struct loadparm_context);
115 if (strchr(opt_name, ':')) {
116 parm = talloc_strdup(scfg, opt_name);
120 val = strchr(parm, ':');
124 ret = lp_parm_int(lp_ctx, s, parm, val, defval);
132 if (strcmp(opt_name, SHARE_CSC_POLICY) == 0) {
133 return lp_csc_policy(s);
136 if (strcmp(opt_name, SHARE_MAX_CONNECTIONS) == 0) {
137 return lp_max_connections(s);
140 if (strcmp(opt_name, SHARE_CREATE_MASK) == 0) {
141 return lp_create_mask(s);
144 if (strcmp(opt_name, SHARE_DIR_MASK) == 0) {
145 return lp_dir_mask(s);
148 if (strcmp(opt_name, SHARE_FORCE_DIR_MODE) == 0) {
149 return lp_force_dir_mode(s);
152 if (strcmp(opt_name, SHARE_FORCE_CREATE_MODE) == 0) {
153 return lp_force_create_mode(s);
157 DEBUG(0,("request for unknown share int option '%s'\n",
163 static bool sclassic_bool_option(struct share_config *scfg, const char *opt_name,
166 struct loadparm_service *s = talloc_get_type(scfg->opaque,
167 struct loadparm_service);
168 struct loadparm_context *lp_ctx = talloc_get_type(scfg->ctx->priv_data,
169 struct loadparm_context);
173 if (strchr(opt_name, ':')) {
174 parm = talloc_strdup(scfg, opt_name);
178 val = strchr(parm, ':');
182 ret = lp_parm_bool(lp_ctx, s, parm, val, defval);
187 if (strcmp(opt_name, SHARE_AVAILABLE) == 0) {
191 if (strcmp(opt_name, SHARE_BROWSEABLE) == 0) {
192 return lp_browseable(s);
195 if (strcmp(opt_name, SHARE_READONLY) == 0) {
196 return lp_readonly(s);
199 if (strcmp(opt_name, SHARE_MAP_SYSTEM) == 0) {
200 return lp_map_system(s);
203 if (strcmp(opt_name, SHARE_MAP_HIDDEN) == 0) {
204 return lp_map_hidden(s);
207 if (strcmp(opt_name, SHARE_MAP_ARCHIVE) == 0) {
208 return lp_map_archive(s);
211 if (strcmp(opt_name, SHARE_STRICT_LOCKING) == 0) {
212 return lp_strict_locking(s);
215 if (strcmp(opt_name, SHARE_STRICT_SYNC) == 0) {
216 return lp_strict_sync(s);
219 if (strcmp(opt_name, SHARE_MSDFS_ROOT) == 0) {
220 return lp_msdfs_root(s);
223 if (strcmp(opt_name, SHARE_CI_FILESYSTEM) == 0) {
224 return lp_ci_filesystem(s);
227 DEBUG(0,("request for unknown share bool option '%s'\n",
233 static const char **sclassic_string_list_option(TALLOC_CTX *mem_ctx, struct share_config *scfg, const char *opt_name)
235 struct loadparm_service *s = talloc_get_type(scfg->opaque,
236 struct loadparm_service);
237 struct loadparm_context *lp_ctx = talloc_get_type(scfg->ctx->priv_data,
238 struct loadparm_context);
242 if (strchr(opt_name, ':')) {
243 parm = talloc_strdup(scfg, opt_name);
247 val = strchr(parm, ':');
251 ret = lp_parm_string_list(mem_ctx, lp_ctx, s, parm, val, ",;");
256 if (strcmp(opt_name, SHARE_HOSTS_ALLOW) == 0) {
257 return lp_hostsallow(s);
260 if (strcmp(opt_name, SHARE_HOSTS_DENY) == 0) {
261 return lp_hostsdeny(s);
264 if (strcmp(opt_name, SHARE_NTVFS_HANDLER) == 0) {
265 return lp_ntvfs_handler(s);
268 DEBUG(0,("request for unknown share list option '%s'\n",
274 static NTSTATUS sclassic_list_all(TALLOC_CTX *mem_ctx,
275 struct share_context *ctx,
283 num_services = lp_numservices((struct loadparm_context *)ctx->priv_data);
285 n = talloc_array(mem_ctx, const char *, num_services);
287 DEBUG(0,("ERROR: Out of memory!\n"));
288 return NT_STATUS_NO_MEMORY;
291 for (i = 0; i < num_services; i++) {
292 n[i] = talloc_strdup(n, lp_servicename(lp_servicebynum((struct loadparm_context *)ctx->priv_data, i)));
294 DEBUG(0,("ERROR: Out of memory!\n"));
296 return NT_STATUS_NO_MEMORY;
301 *count = num_services;
306 static NTSTATUS sclassic_get_config(TALLOC_CTX *mem_ctx,
307 struct share_context *ctx,
309 struct share_config **scfg)
311 struct share_config *s;
312 struct loadparm_service *service;
314 service = lp_service((struct loadparm_context *)ctx->priv_data, name);
316 if (service == NULL) {
317 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
320 s = talloc(mem_ctx, struct share_config);
322 DEBUG(0,("ERROR: Out of memory!\n"));
323 return NT_STATUS_NO_MEMORY;
326 s->name = talloc_strdup(s, lp_servicename(service));
328 DEBUG(0,("ERROR: Out of memory!\n"));
330 return NT_STATUS_NO_MEMORY;
333 s->opaque = (void *)service;
341 static const struct share_ops ops = {
343 .init = sclassic_init,
344 .string_option = sclassic_string_option,
345 .int_option = sclassic_int_option,
346 .bool_option = sclassic_bool_option,
347 .string_list_option = sclassic_string_list_option,
348 .list_all = sclassic_list_all,
349 .get_config = sclassic_get_config
352 NTSTATUS share_classic_init(void)
354 return share_register(&ops);