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 static NTSTATUS
sclassic_init(TALLOC_CTX
*mem_ctx
,
27 const struct share_ops
*ops
,
28 struct tevent_context
*event_ctx
,
29 struct loadparm_context
*lp_ctx
,
30 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
= lp_ctx
;
44 static const char *sclassic_string_option(struct share_config
*scfg
,
48 struct loadparm_service
*s
= talloc_get_type(scfg
->opaque
,
49 struct loadparm_service
);
50 struct loadparm_context
*lp_ctx
= talloc_get_type(scfg
->ctx
->priv_data
,
51 struct loadparm_context
);
55 if (strchr(opt_name
, ':')) {
56 parm
= talloc_strdup(scfg
, opt_name
);
60 val
= strchr(parm
, ':');
64 ret
= lp_parm_string(lp_ctx
, s
, parm
, val
);
72 if (strcmp(opt_name
, SHARE_NAME
) == 0) {
76 if (strcmp(opt_name
, SHARE_PATH
) == 0) {
77 return lp_pathname(s
, lp_default_service(lp_ctx
));
80 if (strcmp(opt_name
, SHARE_COMMENT
) == 0) {
81 return lp_comment(s
, lp_default_service(lp_ctx
));
84 if (strcmp(opt_name
, SHARE_VOLUME
) == 0) {
85 return volume_label(s
, lp_default_service(lp_ctx
));
88 if (strcmp(opt_name
, SHARE_TYPE
) == 0) {
89 if (lp_print_ok(s
, lp_default_service(lp_ctx
))) {
92 if (strcmp("NTFS", lp_fstype(s
, lp_default_service(lp_ctx
))) == 0) {
95 return lp_fstype(s
, lp_default_service(lp_ctx
));
98 if (strcmp(opt_name
, SHARE_PASSWORD
) == 0) {
102 DEBUG(0,("request for unknown share string option '%s'\n",
108 static int sclassic_int_option(struct share_config
*scfg
, const char *opt_name
, int defval
)
110 struct loadparm_service
*s
= talloc_get_type(scfg
->opaque
,
111 struct loadparm_service
);
112 struct loadparm_context
*lp_ctx
= talloc_get_type(scfg
->ctx
->priv_data
,
113 struct loadparm_context
);
117 if (strchr(opt_name
, ':')) {
118 parm
= talloc_strdup(scfg
, opt_name
);
122 val
= strchr(parm
, ':');
126 ret
= lp_parm_int(lp_ctx
, s
, parm
, val
, defval
);
134 if (strcmp(opt_name
, SHARE_CSC_POLICY
) == 0) {
135 return lp_csc_policy(s
, lp_default_service(lp_ctx
));
138 if (strcmp(opt_name
, SHARE_MAX_CONNECTIONS
) == 0) {
139 return lp_max_connections(s
, lp_default_service(lp_ctx
));
142 if (strcmp(opt_name
, SHARE_CREATE_MASK
) == 0) {
143 return lp_create_mask(s
, lp_default_service(lp_ctx
));
146 if (strcmp(opt_name
, SHARE_DIR_MASK
) == 0) {
147 return lp_dir_mask(s
, lp_default_service(lp_ctx
));
150 if (strcmp(opt_name
, SHARE_FORCE_DIR_MODE
) == 0) {
151 return lp_force_dir_mode(s
, lp_default_service(lp_ctx
));
154 if (strcmp(opt_name
, SHARE_FORCE_CREATE_MODE
) == 0) {
155 return lp_force_create_mode(s
, lp_default_service(lp_ctx
));
159 DEBUG(0,("request for unknown share int option '%s'\n",
165 static bool sclassic_bool_option(struct share_config
*scfg
, const char *opt_name
,
168 struct loadparm_service
*s
= talloc_get_type(scfg
->opaque
,
169 struct loadparm_service
);
170 struct loadparm_context
*lp_ctx
= talloc_get_type(scfg
->ctx
->priv_data
,
171 struct loadparm_context
);
175 if (strchr(opt_name
, ':')) {
176 parm
= talloc_strdup(scfg
, opt_name
);
180 val
= strchr(parm
, ':');
184 ret
= lp_parm_bool(lp_ctx
, s
, parm
, val
, defval
);
189 if (strcmp(opt_name
, SHARE_AVAILABLE
) == 0) {
193 if (strcmp(opt_name
, SHARE_BROWSEABLE
) == 0) {
194 return lp_browseable(s
, lp_default_service(lp_ctx
));
197 if (strcmp(opt_name
, SHARE_READONLY
) == 0) {
198 return lp_readonly(s
, lp_default_service(lp_ctx
));
201 if (strcmp(opt_name
, SHARE_MAP_SYSTEM
) == 0) {
202 return lp_map_system(s
, lp_default_service(lp_ctx
));
205 if (strcmp(opt_name
, SHARE_MAP_HIDDEN
) == 0) {
206 return lp_map_hidden(s
, lp_default_service(lp_ctx
));
209 if (strcmp(opt_name
, SHARE_MAP_ARCHIVE
) == 0) {
210 return lp_map_archive(s
, lp_default_service(lp_ctx
));
213 if (strcmp(opt_name
, SHARE_STRICT_LOCKING
) == 0) {
214 return lp_strict_locking(s
, lp_default_service(lp_ctx
));
217 if (strcmp(opt_name
, SHARE_OPLOCKS
) == 0) {
218 return lp_oplocks(s
, lp_default_service(lp_ctx
));
221 if (strcmp(opt_name
, SHARE_STRICT_SYNC
) == 0) {
222 return lp_strict_sync(s
, lp_default_service(lp_ctx
));
225 if (strcmp(opt_name
, SHARE_MSDFS_ROOT
) == 0) {
226 return lp_msdfs_root(s
, lp_default_service(lp_ctx
));
229 if (strcmp(opt_name
, SHARE_CI_FILESYSTEM
) == 0) {
230 return lp_ci_filesystem(s
, lp_default_service(lp_ctx
));
233 DEBUG(0,("request for unknown share bool option '%s'\n",
239 static const char **sclassic_string_list_option(TALLOC_CTX
*mem_ctx
, struct share_config
*scfg
, const char *opt_name
)
241 struct loadparm_service
*s
= talloc_get_type(scfg
->opaque
,
242 struct loadparm_service
);
243 struct loadparm_context
*lp_ctx
= talloc_get_type(scfg
->ctx
->priv_data
,
244 struct loadparm_context
);
248 if (strchr(opt_name
, ':')) {
249 parm
= talloc_strdup(scfg
, opt_name
);
253 val
= strchr(parm
, ':');
257 ret
= lp_parm_string_list(mem_ctx
, lp_ctx
, s
, parm
, val
, ",;");
262 if (strcmp(opt_name
, SHARE_HOSTS_ALLOW
) == 0) {
263 return lp_hostsallow(s
, lp_default_service(lp_ctx
));
266 if (strcmp(opt_name
, SHARE_HOSTS_DENY
) == 0) {
267 return lp_hostsdeny(s
, lp_default_service(lp_ctx
));
270 if (strcmp(opt_name
, SHARE_NTVFS_HANDLER
) == 0) {
271 return lp_ntvfs_handler(s
, lp_default_service(lp_ctx
));
274 DEBUG(0,("request for unknown share list option '%s'\n",
280 static NTSTATUS
sclassic_list_all(TALLOC_CTX
*mem_ctx
,
281 struct share_context
*ctx
,
289 num_services
= lp_numservices((struct loadparm_context
*)ctx
->priv_data
);
291 n
= talloc_array(mem_ctx
, const char *, num_services
);
293 DEBUG(0,("ERROR: Out of memory!\n"));
294 return NT_STATUS_NO_MEMORY
;
297 for (i
= 0; i
< num_services
; i
++) {
298 n
[i
] = talloc_strdup(n
, lp_servicename(lp_servicebynum((struct loadparm_context
*)ctx
->priv_data
, i
)));
300 DEBUG(0,("ERROR: Out of memory!\n"));
302 return NT_STATUS_NO_MEMORY
;
307 *count
= num_services
;
312 static NTSTATUS
sclassic_get_config(TALLOC_CTX
*mem_ctx
,
313 struct share_context
*ctx
,
315 struct share_config
**scfg
)
317 struct share_config
*s
;
318 struct loadparm_service
*service
;
320 service
= lp_service((struct loadparm_context
*)ctx
->priv_data
, name
);
322 if (service
== NULL
) {
323 return NT_STATUS_OBJECT_NAME_NOT_FOUND
;
326 s
= talloc(mem_ctx
, struct share_config
);
328 DEBUG(0,("ERROR: Out of memory!\n"));
329 return NT_STATUS_NO_MEMORY
;
332 s
->name
= talloc_strdup(s
, lp_servicename(service
));
334 DEBUG(0,("ERROR: Out of memory!\n"));
336 return NT_STATUS_NO_MEMORY
;
339 s
->opaque
= (void *)service
;
347 static const struct share_ops ops
= {
349 .init
= sclassic_init
,
350 .string_option
= sclassic_string_option
,
351 .int_option
= sclassic_int_option
,
352 .bool_option
= sclassic_bool_option
,
353 .string_list_option
= sclassic_string_list_option
,
354 .list_all
= sclassic_list_all
,
355 .get_config
= sclassic_get_config
358 NTSTATUS
share_classic_init(void)
360 return share_register(&ops
);