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, const struct share_ops *ops, struct share_context **ctx)
28 *ctx = talloc(mem_ctx, struct share_context);
30 DEBUG(0, ("ERROR: Out of memory!\n"));
31 return NT_STATUS_NO_MEMORY;
35 (*ctx)->priv_data = global_loadparm;
40 static const char *sclassic_string_option(struct share_config *scfg, const char *opt_name, const char *defval)
42 struct loadparm_service *s = talloc_get_type(scfg->opaque,
43 struct loadparm_service);
47 if (strchr(opt_name, ':')) {
48 parm = talloc_strdup(scfg, opt_name);
52 val = strchr(parm, ':');
56 ret = lp_parm_string(global_loadparm, s, parm, val);
64 if (strcmp(opt_name, SHARE_NAME) == 0) {
68 if (strcmp(opt_name, SHARE_PATH) == 0) {
69 return lp_pathname(s);
72 if (strcmp(opt_name, SHARE_COMMENT) == 0) {
76 if (strcmp(opt_name, SHARE_VOLUME) == 0) {
77 return volume_label(s);
80 if (strcmp(opt_name, SHARE_TYPE) == 0) {
84 if (strcmp("NTFS", lp_fstype(s)) == 0) {
90 if (strcmp(opt_name, SHARE_PASSWORD) == 0) {
94 DEBUG(0,("request for unknown share string option '%s'\n",
100 static int sclassic_int_option(struct share_config *scfg, const char *opt_name, int defval)
102 struct loadparm_service *s = talloc_get_type(scfg->opaque,
103 struct loadparm_service);
107 if (strchr(opt_name, ':')) {
108 parm = talloc_strdup(scfg, opt_name);
112 val = strchr(parm, ':');
116 ret = lp_parm_int(global_loadparm, s, parm, val, defval);
124 if (strcmp(opt_name, SHARE_CSC_POLICY) == 0) {
125 return lp_csc_policy(s);
128 if (strcmp(opt_name, SHARE_MAX_CONNECTIONS) == 0) {
129 return lp_max_connections(s);
132 if (strcmp(opt_name, SHARE_CREATE_MASK) == 0) {
133 return lp_create_mask(s);
136 if (strcmp(opt_name, SHARE_DIR_MASK) == 0) {
137 return lp_dir_mask(s);
140 if (strcmp(opt_name, SHARE_FORCE_DIR_MODE) == 0) {
141 return lp_force_dir_mode(s);
144 if (strcmp(opt_name, SHARE_FORCE_CREATE_MODE) == 0) {
145 return lp_force_create_mode(s);
149 DEBUG(0,("request for unknown share int option '%s'\n",
155 static bool sclassic_bool_option(struct share_config *scfg, const char *opt_name,
158 struct loadparm_service *s = talloc_get_type(scfg->opaque,
159 struct loadparm_service);
163 if (strchr(opt_name, ':')) {
164 parm = talloc_strdup(scfg, opt_name);
168 val = strchr(parm, ':');
172 ret = lp_parm_bool(global_loadparm, s, parm, val, defval);
177 if (strcmp(opt_name, SHARE_AVAILABLE) == 0) {
181 if (strcmp(opt_name, SHARE_BROWSEABLE) == 0) {
182 return lp_browseable(s);
185 if (strcmp(opt_name, SHARE_READONLY) == 0) {
186 return lp_readonly(s);
189 if (strcmp(opt_name, SHARE_MAP_SYSTEM) == 0) {
190 return lp_map_system(s);
193 if (strcmp(opt_name, SHARE_MAP_HIDDEN) == 0) {
194 return lp_map_hidden(s);
197 if (strcmp(opt_name, SHARE_MAP_ARCHIVE) == 0) {
198 return lp_map_archive(s);
201 if (strcmp(opt_name, SHARE_STRICT_LOCKING) == 0) {
202 return lp_strict_locking(s);
205 if (strcmp(opt_name, SHARE_STRICT_SYNC) == 0) {
206 return lp_strict_sync(s);
209 if (strcmp(opt_name, SHARE_MSDFS_ROOT) == 0) {
210 return lp_msdfs_root(s);
213 if (strcmp(opt_name, SHARE_CI_FILESYSTEM) == 0) {
214 return lp_ci_filesystem(s);
217 DEBUG(0,("request for unknown share bool option '%s'\n",
223 static const char **sclassic_string_list_option(TALLOC_CTX *mem_ctx, struct share_config *scfg, const char *opt_name)
225 struct loadparm_service *s = talloc_get_type(scfg->opaque,
226 struct loadparm_service);
230 if (strchr(opt_name, ':')) {
231 parm = talloc_strdup(scfg, opt_name);
235 val = strchr(parm, ':');
239 ret = lp_parm_string_list(global_loadparm, 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((struct loadparm_context *)ctx->priv_data);
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((struct loadparm_context *)ctx->priv_data, 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 loadparm_service *service;
302 service = lp_service((struct loadparm_context *)ctx->priv_data, 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 static const struct share_ops ops = {
331 .init = sclassic_init,
332 .string_option = sclassic_string_option,
333 .int_option = sclassic_int_option,
334 .bool_option = sclassic_bool_option,
335 .string_list_option = sclassic_string_list_option,
336 .list_all = sclassic_list_all,
337 .get_config = sclassic_get_config
340 NTSTATUS share_classic_init(void)
342 return share_register(&ops);