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 NTSTATUS
share_classic_init(void);
28 static NTSTATUS
sclassic_init(TALLOC_CTX
*mem_ctx
,
29 const struct share_ops
*ops
,
30 struct tevent_context
*event_ctx
,
31 struct loadparm_context
*lp_ctx
,
32 struct share_context
**ctx
)
34 *ctx
= talloc(mem_ctx
, struct share_context
);
36 DEBUG(0, ("ERROR: Out of memory!\n"));
37 return NT_STATUS_NO_MEMORY
;
41 (*ctx
)->priv_data
= lp_ctx
;
46 static const char *sclassic_string_option(struct share_config
*scfg
,
50 struct loadparm_service
*s
= talloc_get_type(scfg
->opaque
,
51 struct loadparm_service
);
52 struct loadparm_context
*lp_ctx
= talloc_get_type(scfg
->ctx
->priv_data
,
53 struct loadparm_context
);
57 if (strchr(opt_name
, ':')) {
58 parm
= talloc_strdup(scfg
, opt_name
);
62 val
= strchr(parm
, ':');
66 ret
= lpcfg_parm_string(lp_ctx
, s
, parm
, val
);
74 if (strcmp(opt_name
, SHARE_NAME
) == 0) {
78 if (strcmp(opt_name
, SHARE_PATH
) == 0) {
79 return lpcfg_pathname(s
, lpcfg_default_service(lp_ctx
));
82 if (strcmp(opt_name
, SHARE_COMMENT
) == 0) {
83 return lpcfg_comment(s
, lpcfg_default_service(lp_ctx
));
86 if (strcmp(opt_name
, SHARE_VOLUME
) == 0) {
87 return lpcfg_volume_label(s
, lpcfg_default_service(lp_ctx
));
90 if (strcmp(opt_name
, SHARE_TYPE
) == 0) {
91 if (lpcfg_print_ok(s
, lpcfg_default_service(lp_ctx
))) {
94 if (strcmp("NTFS", lpcfg_fstype(s
, lpcfg_default_service(lp_ctx
))) == 0) {
97 return lpcfg_fstype(s
, lpcfg_default_service(lp_ctx
));
100 if (strcmp(opt_name
, SHARE_PASSWORD
) == 0) {
104 DEBUG(0,("request for unknown share string option '%s'\n",
110 static int sclassic_int_option(struct share_config
*scfg
, const char *opt_name
, int defval
)
112 struct loadparm_service
*s
= talloc_get_type(scfg
->opaque
,
113 struct loadparm_service
);
114 struct loadparm_context
*lp_ctx
= talloc_get_type(scfg
->ctx
->priv_data
,
115 struct loadparm_context
);
119 if (strchr(opt_name
, ':')) {
120 parm
= talloc_strdup(scfg
, opt_name
);
124 val
= strchr(parm
, ':');
128 ret
= lpcfg_parm_int(lp_ctx
, s
, parm
, val
, defval
);
136 if (strcmp(opt_name
, SHARE_CSC_POLICY
) == 0) {
137 return lpcfg_csc_policy(s
, lpcfg_default_service(lp_ctx
));
140 if (strcmp(opt_name
, SHARE_MAX_CONNECTIONS
) == 0) {
141 return lpcfg_max_connections(s
, lpcfg_default_service(lp_ctx
));
144 if (strcmp(opt_name
, SHARE_CREATE_MASK
) == 0) {
145 return lpcfg_create_mask(s
, lpcfg_default_service(lp_ctx
));
148 if (strcmp(opt_name
, SHARE_DIR_MASK
) == 0) {
149 return lpcfg_dir_mask(s
, lpcfg_default_service(lp_ctx
));
152 if (strcmp(opt_name
, SHARE_FORCE_DIR_MODE
) == 0) {
153 return lpcfg_force_dir_mode(s
, lpcfg_default_service(lp_ctx
));
156 if (strcmp(opt_name
, SHARE_FORCE_CREATE_MODE
) == 0) {
157 return lpcfg_force_create_mode(s
, lpcfg_default_service(lp_ctx
));
161 DEBUG(0,("request for unknown share int option '%s'\n",
167 static bool sclassic_bool_option(struct share_config
*scfg
, const char *opt_name
,
170 struct loadparm_service
*s
= talloc_get_type(scfg
->opaque
,
171 struct loadparm_service
);
172 struct loadparm_context
*lp_ctx
= talloc_get_type(scfg
->ctx
->priv_data
,
173 struct loadparm_context
);
177 if (strchr(opt_name
, ':')) {
178 parm
= talloc_strdup(scfg
, opt_name
);
182 val
= strchr(parm
, ':');
186 ret
= lpcfg_parm_bool(lp_ctx
, s
, parm
, val
, defval
);
191 if (strcmp(opt_name
, SHARE_AVAILABLE
) == 0) {
195 if (strcmp(opt_name
, SHARE_BROWSEABLE
) == 0) {
196 return lpcfg_browseable(s
, lpcfg_default_service(lp_ctx
));
199 if (strcmp(opt_name
, SHARE_READONLY
) == 0) {
200 return lpcfg_readonly(s
, lpcfg_default_service(lp_ctx
));
203 if (strcmp(opt_name
, SHARE_MAP_SYSTEM
) == 0) {
204 return lpcfg_map_system(s
, lpcfg_default_service(lp_ctx
));
207 if (strcmp(opt_name
, SHARE_MAP_HIDDEN
) == 0) {
208 return lpcfg_map_hidden(s
, lpcfg_default_service(lp_ctx
));
211 if (strcmp(opt_name
, SHARE_MAP_ARCHIVE
) == 0) {
212 return lpcfg_map_archive(s
, lpcfg_default_service(lp_ctx
));
215 if (strcmp(opt_name
, SHARE_STRICT_LOCKING
) == 0) {
216 return lpcfg_strict_locking(s
, lpcfg_default_service(lp_ctx
));
219 if (strcmp(opt_name
, SHARE_OPLOCKS
) == 0) {
220 return lpcfg_oplocks(s
, lpcfg_default_service(lp_ctx
));
223 if (strcmp(opt_name
, SHARE_STRICT_SYNC
) == 0) {
224 return lpcfg_strict_sync(s
, lpcfg_default_service(lp_ctx
));
227 if (strcmp(opt_name
, SHARE_MSDFS_ROOT
) == 0) {
228 return lpcfg_msdfs_root(s
, lpcfg_default_service(lp_ctx
));
231 if (strcmp(opt_name
, SHARE_CI_FILESYSTEM
) == 0) {
232 return lpcfg_ci_filesystem(s
, lpcfg_default_service(lp_ctx
));
235 DEBUG(0,("request for unknown share bool option '%s'\n",
241 static const char **sclassic_string_list_option(TALLOC_CTX
*mem_ctx
, struct share_config
*scfg
, const char *opt_name
)
243 struct loadparm_service
*s
= talloc_get_type(scfg
->opaque
,
244 struct loadparm_service
);
245 struct loadparm_context
*lp_ctx
= talloc_get_type(scfg
->ctx
->priv_data
,
246 struct loadparm_context
);
250 if (strchr(opt_name
, ':')) {
251 parm
= talloc_strdup(scfg
, opt_name
);
255 val
= strchr(parm
, ':');
259 ret
= lpcfg_parm_string_list(mem_ctx
, lp_ctx
, s
, parm
, val
, ",;");
264 if (strcmp(opt_name
, SHARE_HOSTS_ALLOW
) == 0) {
265 return lpcfg_hostsallow(s
, lpcfg_default_service(lp_ctx
));
268 if (strcmp(opt_name
, SHARE_HOSTS_DENY
) == 0) {
269 return lpcfg_hostsdeny(s
, lpcfg_default_service(lp_ctx
));
272 if (strcmp(opt_name
, SHARE_NTVFS_HANDLER
) == 0) {
273 return lpcfg_ntvfs_handler(s
, lpcfg_default_service(lp_ctx
));
276 DEBUG(0,("request for unknown share list option '%s'\n",
282 static NTSTATUS
sclassic_list_all(TALLOC_CTX
*mem_ctx
,
283 struct share_context
*ctx
,
291 num_services
= lpcfg_numservices((struct loadparm_context
*)ctx
->priv_data
);
293 n
= talloc_array(mem_ctx
, const char *, num_services
);
295 DEBUG(0,("ERROR: Out of memory!\n"));
296 return NT_STATUS_NO_MEMORY
;
299 for (i
= 0; i
< num_services
; i
++) {
300 n
[i
] = talloc_strdup(n
, lpcfg_servicename(lpcfg_servicebynum((struct loadparm_context
*)ctx
->priv_data
, i
)));
302 DEBUG(0,("ERROR: Out of memory!\n"));
304 return NT_STATUS_NO_MEMORY
;
309 *count
= num_services
;
314 static NTSTATUS
sclassic_get_config(TALLOC_CTX
*mem_ctx
,
315 struct share_context
*ctx
,
317 struct share_config
**scfg
)
319 struct share_config
*s
;
320 struct loadparm_service
*service
;
322 service
= lpcfg_service((struct loadparm_context
*)ctx
->priv_data
, name
);
324 if (service
== NULL
) {
325 return NT_STATUS_OBJECT_NAME_NOT_FOUND
;
328 s
= talloc(mem_ctx
, struct share_config
);
330 DEBUG(0,("ERROR: Out of memory!\n"));
331 return NT_STATUS_NO_MEMORY
;
334 s
->name
= talloc_strdup(s
, lpcfg_servicename(service
));
336 DEBUG(0,("ERROR: Out of memory!\n"));
338 return NT_STATUS_NO_MEMORY
;
341 s
->opaque
= (void *)service
;
349 static const struct share_ops ops
= {
351 .init
= sclassic_init
,
352 .string_option
= sclassic_string_option
,
353 .int_option
= sclassic_int_option
,
354 .bool_option
= sclassic_bool_option
,
355 .string_list_option
= sclassic_string_list_option
,
356 .list_all
= sclassic_list_all
,
357 .get_config
= sclassic_get_config
360 NTSTATUS
share_classic_init(void)
362 return share_register(&ops
);