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 2 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, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "param/share.h"
26 struct sclassic_snum {
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 sclassic_snum *s = talloc_get_type(scfg->opaque, struct sclassic_snum);
50 if (strchr(opt_name, ':')) {
51 parm = talloc_strdup(scfg, opt_name);
55 val = strchr(parm, ':');
59 ret = lp_parm_string(s->snum, parm, val);
67 if (strcmp(opt_name, SHARE_NAME) == 0) {
71 if (strcmp(opt_name, SHARE_PATH) == 0) {
72 return lp_pathname(s->snum);
75 if (strcmp(opt_name, SHARE_COMMENT) == 0) {
76 return lp_comment(s->snum);
79 if (strcmp(opt_name, SHARE_VOLUME) == 0) {
80 return volume_label(s->snum);
83 if (strcmp(opt_name, SHARE_TYPE) == 0) {
84 if (lp_print_ok(s->snum)) {
87 if (strcmp("NTFS", lp_fstype(s->snum)) == 0) {
90 return lp_fstype(s->snum);
93 DEBUG(0,("request for unknown share string option '%s'\n",
99 int sclassic_int_option(struct share_config *scfg, const char *opt_name, int defval)
101 struct sclassic_snum *s = talloc_get_type(scfg->opaque, struct sclassic_snum);
105 if (strchr(opt_name, ':')) {
106 parm = talloc_strdup(scfg, opt_name);
110 val = strchr(parm, ':');
114 ret = lp_parm_int(s->snum, parm, val, defval);
122 if (strcmp(opt_name, SHARE_CSC_POLICY) == 0) {
123 return lp_csc_policy(s->snum);
126 if (strcmp(opt_name, SHARE_MAX_CONNECTIONS) == 0) {
127 return lp_max_connections(s->snum);
130 if (strcmp(opt_name, SHARE_CREATE_MASK) == 0) {
131 return lp_create_mask(s->snum);
134 if (strcmp(opt_name, SHARE_DIR_MASK) == 0) {
135 return lp_dir_mask(s->snum);
138 if (strcmp(opt_name, SHARE_FORCE_DIR_MODE) == 0) {
139 return lp_force_dir_mode(s->snum);
142 if (strcmp(opt_name, SHARE_FORCE_CREATE_MODE) == 0) {
143 return lp_force_create_mode(s->snum);
147 DEBUG(0,("request for unknown share int option '%s'\n",
153 BOOL sclassic_bool_option(struct share_config *scfg, const char *opt_name, BOOL defval)
155 struct sclassic_snum *s = talloc_get_type(scfg->opaque, struct sclassic_snum);
159 if (strchr(opt_name, ':')) {
160 parm = talloc_strdup(scfg, opt_name);
164 val = strchr(parm, ':');
168 ret = lp_parm_bool(s->snum, parm, val, defval);
173 if (strcmp(opt_name, SHARE_AVAILABLE) == 0) {
174 return lp_snum_ok(s->snum);
177 if (strcmp(opt_name, SHARE_BROWSEABLE) == 0) {
178 return lp_browseable(s->snum);
181 if (strcmp(opt_name, SHARE_READONLY) == 0) {
182 return lp_readonly(s->snum);
185 if (strcmp(opt_name, SHARE_MAP_SYSTEM) == 0) {
186 return lp_map_system(s->snum);
189 if (strcmp(opt_name, SHARE_MAP_HIDDEN) == 0) {
190 return lp_map_hidden(s->snum);
193 if (strcmp(opt_name, SHARE_MAP_ARCHIVE) == 0) {
194 return lp_map_archive(s->snum);
197 if (strcmp(opt_name, SHARE_STRICT_LOCKING) == 0) {
198 return lp_strict_locking(s->snum);
201 if (strcmp(opt_name, SHARE_STRICT_SYNC) == 0) {
202 return lp_strict_sync(s->snum);
205 if (strcmp(opt_name, SHARE_MSDFS_ROOT) == 0) {
206 return lp_msdfs_root(s->snum);
209 if (strcmp(opt_name, SHARE_CI_FILESYSTEM) == 0) {
210 return lp_ci_filesystem(s->snum);
213 DEBUG(0,("request for unknown share bool option '%s'\n",
219 const char **sclassic_string_list_option(TALLOC_CTX *mem_ctx, struct share_config *scfg, const char *opt_name)
221 struct sclassic_snum *s = talloc_get_type(scfg->opaque, struct sclassic_snum);
225 if (strchr(opt_name, ':')) {
226 parm = talloc_strdup(scfg, opt_name);
230 val = strchr(parm, ':');
234 ret = lp_parm_string_list(s->snum, parm, val, ",;");
239 if (strcmp(opt_name, SHARE_HOSTS_ALLOW) == 0) {
240 return lp_hostsallow(s->snum);
243 if (strcmp(opt_name, SHARE_HOSTS_DENY) == 0) {
244 return lp_hostsdeny(s->snum);
247 if (strcmp(opt_name, SHARE_NTVFS_HANDLER) == 0) {
248 return lp_ntvfs_handler(s->snum);
251 DEBUG(0,("request for unknown share list option '%s'\n",
257 NTSTATUS sclassic_list_all(TALLOC_CTX *mem_ctx,
258 struct share_context *ctx,
266 num_services = lp_numservices();
268 n = talloc_array(mem_ctx, const char *, num_services);
270 DEBUG(0,("ERROR: Out of memory!\n"));
271 return NT_STATUS_NO_MEMORY;
274 for (i = 0; i < num_services; i++) {
275 n[i] = talloc_strdup(n, lp_servicename(i));
277 DEBUG(0,("ERROR: Out of memory!\n"));
279 return NT_STATUS_NO_MEMORY;
284 *count = num_services;
289 NTSTATUS sclassic_get_config(TALLOC_CTX *mem_ctx,
290 struct share_context *ctx,
292 struct share_config **scfg)
295 struct share_config *s;
296 struct sclassic_snum *scnum;
299 for (i = 0; i < lp_numservices(); i++) {
300 if (strcasecmp_m(name, lp_servicename(i)) == 0) {
307 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
310 s = talloc(mem_ctx, struct share_config);
312 DEBUG(0,("ERROR: Out of memory!\n"));
313 return NT_STATUS_NO_MEMORY;
316 s->name = talloc_strdup(s, lp_servicename(snum));
318 DEBUG(0,("ERROR: Out of memory!\n"));
320 return NT_STATUS_NO_MEMORY;
323 scnum = talloc(s, struct sclassic_snum);
325 DEBUG(0,("ERROR: Out of memory!\n"));
327 return NT_STATUS_NO_MEMORY;
331 s->opaque = (void *)scnum;
339 NTSTATUS share_classic_init(void)
341 static 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 return share_register(&ops);