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"
27 struct service *service;
30 static NTSTATUS sclassic_init(TALLOC_CTX *mem_ctx, const struct share_ops *ops, struct share_context **ctx)
32 *ctx = talloc(mem_ctx, struct share_context);
34 DEBUG(0, ("ERROR: Out of memory!\n"));
35 return NT_STATUS_NO_MEMORY;
39 (*ctx)->priv_data = NULL;
44 static const char *sclassic_string_option(struct share_config *scfg, const char *opt_name, const char *defval)
46 struct service *s = talloc_get_type(scfg->opaque, struct service);
50 if (strchr(opt_name, ':')) {
51 parm = talloc_strdup(scfg, opt_name);
55 val = strchr(parm, ':');
59 ret = lp_parm_string(s, parm, val);
67 if (strcmp(opt_name, SHARE_NAME) == 0) {
71 if (strcmp(opt_name, SHARE_PATH) == 0) {
72 return lp_pathname(s);
75 if (strcmp(opt_name, SHARE_COMMENT) == 0) {
79 if (strcmp(opt_name, SHARE_VOLUME) == 0) {
80 return volume_label(s);
83 if (strcmp(opt_name, SHARE_TYPE) == 0) {
87 if (strcmp("NTFS", lp_fstype(s)) == 0) {
93 if (strcmp(opt_name, SHARE_PASSWORD) == 0) {
97 DEBUG(0,("request for unknown share string option '%s'\n",
103 static int sclassic_int_option(struct share_config *scfg, const char *opt_name, int defval)
105 struct service *s = talloc_get_type(scfg->opaque, struct service);
109 if (strchr(opt_name, ':')) {
110 parm = talloc_strdup(scfg, opt_name);
114 val = strchr(parm, ':');
118 ret = lp_parm_int(s, parm, val, defval);
126 if (strcmp(opt_name, SHARE_CSC_POLICY) == 0) {
127 return lp_csc_policy(s);
130 if (strcmp(opt_name, SHARE_MAX_CONNECTIONS) == 0) {
131 return lp_max_connections(s);
134 if (strcmp(opt_name, SHARE_CREATE_MASK) == 0) {
135 return lp_create_mask(s);
138 if (strcmp(opt_name, SHARE_DIR_MASK) == 0) {
139 return lp_dir_mask(s);
142 if (strcmp(opt_name, SHARE_FORCE_DIR_MODE) == 0) {
143 return lp_force_dir_mode(s);
146 if (strcmp(opt_name, SHARE_FORCE_CREATE_MODE) == 0) {
147 return lp_force_create_mode(s);
151 DEBUG(0,("request for unknown share int option '%s'\n",
157 static bool sclassic_bool_option(struct share_config *scfg, const char *opt_name,
160 struct service *s = talloc_get_type(scfg->opaque, struct service);
164 if (strchr(opt_name, ':')) {
165 parm = talloc_strdup(scfg, opt_name);
169 val = strchr(parm, ':');
173 ret = lp_parm_bool(s, parm, val, defval);
178 if (strcmp(opt_name, SHARE_AVAILABLE) == 0) {
182 if (strcmp(opt_name, SHARE_BROWSEABLE) == 0) {
183 return lp_browseable(s);
186 if (strcmp(opt_name, SHARE_READONLY) == 0) {
187 return lp_readonly(s);
190 if (strcmp(opt_name, SHARE_MAP_SYSTEM) == 0) {
191 return lp_map_system(s);
194 if (strcmp(opt_name, SHARE_MAP_HIDDEN) == 0) {
195 return lp_map_hidden(s);
198 if (strcmp(opt_name, SHARE_MAP_ARCHIVE) == 0) {
199 return lp_map_archive(s);
202 if (strcmp(opt_name, SHARE_STRICT_LOCKING) == 0) {
203 return lp_strict_locking(s);
206 if (strcmp(opt_name, SHARE_STRICT_SYNC) == 0) {
207 return lp_strict_sync(s);
210 if (strcmp(opt_name, SHARE_MSDFS_ROOT) == 0) {
211 return lp_msdfs_root(s);
214 if (strcmp(opt_name, SHARE_CI_FILESYSTEM) == 0) {
215 return lp_ci_filesystem(s);
218 DEBUG(0,("request for unknown share bool option '%s'\n",
224 static const char **sclassic_string_list_option(TALLOC_CTX *mem_ctx, struct share_config *scfg, const char *opt_name)
226 struct service *s = talloc_get_type(scfg->opaque, struct service);
230 if (strchr(opt_name, ':')) {
231 parm = talloc_strdup(scfg, opt_name);
235 val = strchr(parm, ':');
239 ret = lp_parm_string_list(s, parm, val, ",;");
244 if (strcmp(opt_name, SHARE_HOSTS_ALLOW) == 0) {
245 return lp_hostsallow(s);
248 if (strcmp(opt_name, SHARE_HOSTS_DENY) == 0) {
249 return lp_hostsdeny(s);
252 if (strcmp(opt_name, SHARE_NTVFS_HANDLER) == 0) {
253 return lp_ntvfs_handler(s);
256 DEBUG(0,("request for unknown share list option '%s'\n",
262 static NTSTATUS sclassic_list_all(TALLOC_CTX *mem_ctx,
263 struct share_context *ctx,
271 num_services = lp_numservices();
273 n = talloc_array(mem_ctx, const char *, num_services);
275 DEBUG(0,("ERROR: Out of memory!\n"));
276 return NT_STATUS_NO_MEMORY;
279 for (i = 0; i < num_services; i++) {
280 n[i] = talloc_strdup(n, lp_servicename(lp_servicebynum(i)));
282 DEBUG(0,("ERROR: Out of memory!\n"));
284 return NT_STATUS_NO_MEMORY;
289 *count = num_services;
294 static NTSTATUS sclassic_get_config(TALLOC_CTX *mem_ctx,
295 struct share_context *ctx,
297 struct share_config **scfg)
299 struct share_config *s;
300 struct service *service;
302 service = lp_service(name);
304 if (service == NULL) {
305 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
308 s = talloc(mem_ctx, struct share_config);
310 DEBUG(0,("ERROR: Out of memory!\n"));
311 return NT_STATUS_NO_MEMORY;
314 s->name = talloc_strdup(s, lp_servicename(service));
316 DEBUG(0,("ERROR: Out of memory!\n"));
318 return NT_STATUS_NO_MEMORY;
321 s->opaque = (void *)service;
329 NTSTATUS share_classic_init(void)
331 static struct share_ops ops = {
333 .init = sclassic_init,
334 .string_option = sclassic_string_option,
335 .int_option = sclassic_int_option,
336 .bool_option = sclassic_bool_option,
337 .string_list_option = sclassic_string_list_option,
338 .list_all = sclassic_list_all,
339 .get_config = sclassic_get_config
342 return share_register(&ops);