2 Unix SMB/CIFS implementation.
4 Classic file based shares 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 loadparm_context *lp_ctx,
29 struct share_context **ctx)
31 *ctx = talloc(mem_ctx, struct share_context);
33 DEBUG(0, ("ERROR: Out of memory!\n"));
34 return NT_STATUS_NO_MEMORY;
38 (*ctx)->priv_data = lp_ctx;
43 static const char *sclassic_string_option(struct share_config *scfg,
47 struct loadparm_service *s = talloc_get_type(scfg->opaque,
48 struct loadparm_service);
49 struct loadparm_context *lp_ctx = talloc_get_type(scfg->ctx->priv_data,
50 struct loadparm_context);
54 if (strchr(opt_name, ':')) {
55 parm = talloc_strdup(scfg, opt_name);
59 val = strchr(parm, ':');
63 ret = lp_parm_string(lp_ctx, s, parm, val);
71 if (strcmp(opt_name, SHARE_NAME) == 0) {
75 if (strcmp(opt_name, SHARE_PATH) == 0) {
76 return lp_pathname(s);
79 if (strcmp(opt_name, SHARE_COMMENT) == 0) {
83 if (strcmp(opt_name, SHARE_VOLUME) == 0) {
84 return volume_label(s);
87 if (strcmp(opt_name, SHARE_TYPE) == 0) {
91 if (strcmp("NTFS", lp_fstype(s)) == 0) {
97 if (strcmp(opt_name, SHARE_PASSWORD) == 0) {
101 DEBUG(0,("request for unknown share string option '%s'\n",
107 static int sclassic_int_option(struct share_config *scfg, const char *opt_name, int defval)
109 struct loadparm_service *s = talloc_get_type(scfg->opaque,
110 struct loadparm_service);
111 struct loadparm_context *lp_ctx = talloc_get_type(scfg->ctx->priv_data,
112 struct loadparm_context);
116 if (strchr(opt_name, ':')) {
117 parm = talloc_strdup(scfg, opt_name);
121 val = strchr(parm, ':');
125 ret = lp_parm_int(lp_ctx, s, parm, val, defval);
133 if (strcmp(opt_name, SHARE_CSC_POLICY) == 0) {
134 return lp_csc_policy(s);
137 if (strcmp(opt_name, SHARE_MAX_CONNECTIONS) == 0) {
138 return lp_max_connections(s);
141 if (strcmp(opt_name, SHARE_CREATE_MASK) == 0) {
142 return lp_create_mask(s);
145 if (strcmp(opt_name, SHARE_DIR_MASK) == 0) {
146 return lp_dir_mask(s);
149 if (strcmp(opt_name, SHARE_FORCE_DIR_MODE) == 0) {
150 return lp_force_dir_mode(s);
153 if (strcmp(opt_name, SHARE_FORCE_CREATE_MODE) == 0) {
154 return lp_force_create_mode(s);
158 DEBUG(0,("request for unknown share int option '%s'\n",
164 static bool sclassic_bool_option(struct share_config *scfg, const char *opt_name,
167 struct loadparm_service *s = talloc_get_type(scfg->opaque,
168 struct loadparm_service);
169 struct loadparm_context *lp_ctx = talloc_get_type(scfg->ctx->priv_data,
170 struct loadparm_context);
174 if (strchr(opt_name, ':')) {
175 parm = talloc_strdup(scfg, opt_name);
179 val = strchr(parm, ':');
183 ret = lp_parm_bool(lp_ctx, s, parm, val, defval);
188 if (strcmp(opt_name, SHARE_AVAILABLE) == 0) {
192 if (strcmp(opt_name, SHARE_BROWSEABLE) == 0) {
193 return lp_browseable(s);
196 if (strcmp(opt_name, SHARE_READONLY) == 0) {
197 return lp_readonly(s);
200 if (strcmp(opt_name, SHARE_MAP_SYSTEM) == 0) {
201 return lp_map_system(s);
204 if (strcmp(opt_name, SHARE_MAP_HIDDEN) == 0) {
205 return lp_map_hidden(s);
208 if (strcmp(opt_name, SHARE_MAP_ARCHIVE) == 0) {
209 return lp_map_archive(s);
212 if (strcmp(opt_name, SHARE_STRICT_LOCKING) == 0) {
213 return lp_strict_locking(s);
216 if (strcmp(opt_name, SHARE_STRICT_SYNC) == 0) {
217 return lp_strict_sync(s);
220 if (strcmp(opt_name, SHARE_MSDFS_ROOT) == 0) {
221 return lp_msdfs_root(s);
224 if (strcmp(opt_name, SHARE_CI_FILESYSTEM) == 0) {
225 return lp_ci_filesystem(s);
228 DEBUG(0,("request for unknown share bool option '%s'\n",
234 static const char **sclassic_string_list_option(TALLOC_CTX *mem_ctx, struct share_config *scfg, const char *opt_name)
236 struct loadparm_service *s = talloc_get_type(scfg->opaque,
237 struct loadparm_service);
238 struct loadparm_context *lp_ctx = talloc_get_type(scfg->ctx->priv_data,
239 struct loadparm_context);
243 if (strchr(opt_name, ':')) {
244 parm = talloc_strdup(scfg, opt_name);
248 val = strchr(parm, ':');
252 ret = lp_parm_string_list(mem_ctx, lp_ctx, s, parm, val, ",;");
257 if (strcmp(opt_name, SHARE_HOSTS_ALLOW) == 0) {
258 return lp_hostsallow(s);
261 if (strcmp(opt_name, SHARE_HOSTS_DENY) == 0) {
262 return lp_hostsdeny(s);
265 if (strcmp(opt_name, SHARE_NTVFS_HANDLER) == 0) {
266 return lp_ntvfs_handler(s);
269 DEBUG(0,("request for unknown share list option '%s'\n",
275 static NTSTATUS sclassic_list_all(TALLOC_CTX *mem_ctx,
276 struct share_context *ctx,
284 num_services = lp_numservices((struct loadparm_context *)ctx->priv_data);
286 n = talloc_array(mem_ctx, const char *, num_services);
288 DEBUG(0,("ERROR: Out of memory!\n"));
289 return NT_STATUS_NO_MEMORY;
292 for (i = 0; i < num_services; i++) {
293 n[i] = talloc_strdup(n, lp_servicename(lp_servicebynum((struct loadparm_context *)ctx->priv_data, i)));
295 DEBUG(0,("ERROR: Out of memory!\n"));
297 return NT_STATUS_NO_MEMORY;
302 *count = num_services;
307 static NTSTATUS sclassic_get_config(TALLOC_CTX *mem_ctx,
308 struct share_context *ctx,
310 struct share_config **scfg)
312 struct share_config *s;
313 struct loadparm_service *service;
315 service = lp_service((struct loadparm_context *)ctx->priv_data, name);
317 if (service == NULL) {
318 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
321 s = talloc(mem_ctx, struct share_config);
323 DEBUG(0,("ERROR: Out of memory!\n"));
324 return NT_STATUS_NO_MEMORY;
327 s->name = talloc_strdup(s, lp_servicename(service));
329 DEBUG(0,("ERROR: Out of memory!\n"));
331 return NT_STATUS_NO_MEMORY;
334 s->opaque = (void *)service;
342 static const struct share_ops ops = {
344 .init = sclassic_init,
345 .string_option = sclassic_string_option,
346 .int_option = sclassic_int_option,
347 .bool_option = sclassic_bool_option,
348 .string_list_option = sclassic_string_list_option,
349 .list_all = sclassic_list_all,
350 .get_config = sclassic_get_config
353 NTSTATUS share_classic_init(void)
355 return share_register(&ops);