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"
25 struct sclassic_snum {
29 static NTSTATUS sclassic_init(TALLOC_CTX *mem_ctx, const struct share_ops *ops, 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 = NULL;
43 static const char *sclassic_string_option(struct share_config *scfg, const char *opt_name, const char *defval)
45 struct sclassic_snum *s = talloc_get_type(scfg->opaque, struct sclassic_snum);
49 if (strchr(opt_name, ':')) {
50 parm = talloc_strdup(scfg, opt_name);
54 val = strchr(parm, ':');
58 ret = lp_parm_string(s->snum, parm, val);
66 if (strcmp(opt_name, SHARE_NAME) == 0) {
70 if (strcmp(opt_name, SHARE_PATH) == 0) {
71 return lp_pathname(s->snum);
74 if (strcmp(opt_name, SHARE_COMMENT) == 0) {
75 return lp_comment(s->snum);
78 if (strcmp(opt_name, SHARE_VOLUME) == 0) {
79 return volume_label(s->snum);
82 if (strcmp(opt_name, SHARE_TYPE) == 0) {
83 if (lp_print_ok(s->snum)) {
86 if (strcmp("NTFS", lp_fstype(s->snum)) == 0) {
89 return lp_fstype(s->snum);
92 if (strcmp(opt_name, SHARE_PASSWORD) == 0) {
96 DEBUG(0,("request for unknown share string option '%s'\n",
102 int sclassic_int_option(struct share_config *scfg, const char *opt_name, int defval)
104 struct sclassic_snum *s = talloc_get_type(scfg->opaque, struct sclassic_snum);
108 if (strchr(opt_name, ':')) {
109 parm = talloc_strdup(scfg, opt_name);
113 val = strchr(parm, ':');
117 ret = lp_parm_int(s->snum, parm, val, defval);
125 if (strcmp(opt_name, SHARE_CSC_POLICY) == 0) {
126 return lp_csc_policy(s->snum);
129 if (strcmp(opt_name, SHARE_MAX_CONNECTIONS) == 0) {
130 return lp_max_connections(s->snum);
133 if (strcmp(opt_name, SHARE_CREATE_MASK) == 0) {
134 return lp_create_mask(s->snum);
137 if (strcmp(opt_name, SHARE_DIR_MASK) == 0) {
138 return lp_dir_mask(s->snum);
141 if (strcmp(opt_name, SHARE_FORCE_DIR_MODE) == 0) {
142 return lp_force_dir_mode(s->snum);
145 if (strcmp(opt_name, SHARE_FORCE_CREATE_MODE) == 0) {
146 return lp_force_create_mode(s->snum);
150 DEBUG(0,("request for unknown share int option '%s'\n",
156 BOOL sclassic_bool_option(struct share_config *scfg, const char *opt_name, BOOL defval)
158 struct sclassic_snum *s = talloc_get_type(scfg->opaque, struct sclassic_snum);
162 if (strchr(opt_name, ':')) {
163 parm = talloc_strdup(scfg, opt_name);
167 val = strchr(parm, ':');
171 ret = lp_parm_bool(s->snum, parm, val, defval);
176 if (strcmp(opt_name, SHARE_AVAILABLE) == 0) {
177 return lp_snum_ok(s->snum);
180 if (strcmp(opt_name, SHARE_BROWSEABLE) == 0) {
181 return lp_browseable(s->snum);
184 if (strcmp(opt_name, SHARE_READONLY) == 0) {
185 return lp_readonly(s->snum);
188 if (strcmp(opt_name, SHARE_MAP_SYSTEM) == 0) {
189 return lp_map_system(s->snum);
192 if (strcmp(opt_name, SHARE_MAP_HIDDEN) == 0) {
193 return lp_map_hidden(s->snum);
196 if (strcmp(opt_name, SHARE_MAP_ARCHIVE) == 0) {
197 return lp_map_archive(s->snum);
200 if (strcmp(opt_name, SHARE_STRICT_LOCKING) == 0) {
201 return lp_strict_locking(s->snum);
204 if (strcmp(opt_name, SHARE_STRICT_SYNC) == 0) {
205 return lp_strict_sync(s->snum);
208 if (strcmp(opt_name, SHARE_MSDFS_ROOT) == 0) {
209 return lp_msdfs_root(s->snum);
212 if (strcmp(opt_name, SHARE_CI_FILESYSTEM) == 0) {
213 return lp_ci_filesystem(s->snum);
216 DEBUG(0,("request for unknown share bool option '%s'\n",
222 const char **sclassic_string_list_option(TALLOC_CTX *mem_ctx, struct share_config *scfg, const char *opt_name)
224 struct sclassic_snum *s = talloc_get_type(scfg->opaque, struct sclassic_snum);
228 if (strchr(opt_name, ':')) {
229 parm = talloc_strdup(scfg, opt_name);
233 val = strchr(parm, ':');
237 ret = lp_parm_string_list(s->snum, parm, val, ",;");
242 if (strcmp(opt_name, SHARE_HOSTS_ALLOW) == 0) {
243 return lp_hostsallow(s->snum);
246 if (strcmp(opt_name, SHARE_HOSTS_DENY) == 0) {
247 return lp_hostsdeny(s->snum);
250 if (strcmp(opt_name, SHARE_NTVFS_HANDLER) == 0) {
251 return lp_ntvfs_handler(s->snum);
254 DEBUG(0,("request for unknown share list option '%s'\n",
260 NTSTATUS sclassic_list_all(TALLOC_CTX *mem_ctx,
261 struct share_context *ctx,
269 num_services = lp_numservices();
271 n = talloc_array(mem_ctx, const char *, num_services);
273 DEBUG(0,("ERROR: Out of memory!\n"));
274 return NT_STATUS_NO_MEMORY;
277 for (i = 0; i < num_services; i++) {
278 n[i] = talloc_strdup(n, lp_servicename(i));
280 DEBUG(0,("ERROR: Out of memory!\n"));
282 return NT_STATUS_NO_MEMORY;
287 *count = num_services;
292 NTSTATUS sclassic_get_config(TALLOC_CTX *mem_ctx,
293 struct share_context *ctx,
295 struct share_config **scfg)
298 struct share_config *s;
299 struct sclassic_snum *scnum;
302 for (i = 0; i < lp_numservices(); i++) {
303 if (strcasecmp_m(name, lp_servicename(i)) == 0) {
310 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
313 s = talloc(mem_ctx, struct share_config);
315 DEBUG(0,("ERROR: Out of memory!\n"));
316 return NT_STATUS_NO_MEMORY;
319 s->name = talloc_strdup(s, lp_servicename(snum));
321 DEBUG(0,("ERROR: Out of memory!\n"));
323 return NT_STATUS_NO_MEMORY;
326 scnum = talloc(s, struct sclassic_snum);
328 DEBUG(0,("ERROR: Out of memory!\n"));
330 return NT_STATUS_NO_MEMORY;
334 s->opaque = (void *)scnum;
342 NTSTATUS share_classic_init(void)
344 static struct share_ops ops = {
346 .init = sclassic_init,
347 .string_option = sclassic_string_option,
348 .int_option = sclassic_int_option,
349 .bool_option = sclassic_bool_option,
350 .string_list_option = sclassic_string_list_option,
351 .list_all = sclassic_list_all,
352 .get_config = sclassic_get_config
355 return share_register(&ops);