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(TALLOC_CTX
*);
28 static NTSTATUS
sclassic_init(TALLOC_CTX
*mem_ctx
,
29 const struct share_ops
*ops
,
30 struct loadparm_context
*lp_ctx
,
31 struct share_context
**ctx
)
33 *ctx
= talloc(mem_ctx
, struct share_context
);
35 DEBUG(0, ("ERROR: Out of memory!\n"));
36 return NT_STATUS_NO_MEMORY
;
40 (*ctx
)->priv_data
= lp_ctx
;
45 static char *sclassic_string_option(TALLOC_CTX
*mem_ctx
,
46 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
);
71 return talloc_strdup(mem_ctx
, ret
);
74 if (strcmp(opt_name
, SHARE_NAME
) == 0) {
75 return talloc_strdup(mem_ctx
, scfg
->name
);
78 if (strcmp(opt_name
, SHARE_PATH
) == 0) {
79 return lpcfg_path(s
, lpcfg_default_service(lp_ctx
), mem_ctx
);
82 if (strcmp(opt_name
, SHARE_COMMENT
) == 0) {
83 return lpcfg_comment(s
, lpcfg_default_service(lp_ctx
), mem_ctx
);
86 if (strcmp(opt_name
, SHARE_TYPE
) == 0) {
87 if (lpcfg_printable(s
, lpcfg_default_service(lp_ctx
))) {
88 return talloc_strdup(mem_ctx
, "PRINTER");
90 if (strcmp("NTFS", lpcfg_fstype(s
, lpcfg_default_service(lp_ctx
))) == 0) {
91 return talloc_strdup(mem_ctx
, "DISK");
93 return talloc_strdup(mem_ctx
, lpcfg_fstype(s
, lpcfg_default_service(lp_ctx
)));
96 if (strcmp(opt_name
, SHARE_PASSWORD
) == 0) {
97 return talloc_strdup(mem_ctx
, defval
);
100 DEBUG(0,("request for unknown share string option '%s'\n",
103 return talloc_strdup(mem_ctx
, defval
);
106 static int sclassic_int_option(struct share_config
*scfg
, const char *opt_name
, int defval
)
108 struct loadparm_service
*s
= talloc_get_type(scfg
->opaque
,
109 struct loadparm_service
);
110 struct loadparm_context
*lp_ctx
= talloc_get_type(scfg
->ctx
->priv_data
,
111 struct loadparm_context
);
115 if (strchr(opt_name
, ':')) {
116 parm
= talloc_strdup(scfg
, opt_name
);
120 val
= strchr(parm
, ':');
124 ret
= lpcfg_parm_int(lp_ctx
, s
, parm
, val
, defval
);
132 if (strcmp(opt_name
, SHARE_CSC_POLICY
) == 0) {
133 return lpcfg_csc_policy(s
, lpcfg_default_service(lp_ctx
));
136 if (strcmp(opt_name
, SHARE_MAX_CONNECTIONS
) == 0) {
137 return lpcfg_max_connections(s
, lpcfg_default_service(lp_ctx
));
140 if (strcmp(opt_name
, SHARE_CREATE_MASK
) == 0) {
141 return lpcfg_create_mask(s
, lpcfg_default_service(lp_ctx
));
144 if (strcmp(opt_name
, SHARE_DIR_MASK
) == 0) {
145 return lpcfg_directory_mask(s
, lpcfg_default_service(lp_ctx
));
148 if (strcmp(opt_name
, SHARE_FORCE_DIR_MODE
) == 0) {
149 return lpcfg_force_directory_mode(s
, lpcfg_default_service(lp_ctx
));
152 if (strcmp(opt_name
, SHARE_FORCE_CREATE_MODE
) == 0) {
153 return lpcfg_force_create_mode(s
, lpcfg_default_service(lp_ctx
));
157 DEBUG(0,("request for unknown share int option '%s'\n",
163 static bool sclassic_bool_option(struct share_config
*scfg
, const char *opt_name
,
166 struct loadparm_service
*s
= talloc_get_type(scfg
->opaque
,
167 struct loadparm_service
);
168 struct loadparm_context
*lp_ctx
= talloc_get_type(scfg
->ctx
->priv_data
,
169 struct loadparm_context
);
173 if (strchr(opt_name
, ':')) {
174 parm
= talloc_strdup(scfg
, opt_name
);
178 val
= strchr(parm
, ':');
182 ret
= lpcfg_parm_bool(lp_ctx
, s
, parm
, val
, defval
);
187 if (strcmp(opt_name
, SHARE_AVAILABLE
) == 0) {
191 if (strcmp(opt_name
, SHARE_BROWSEABLE
) == 0) {
192 return lpcfg_browseable(s
, lpcfg_default_service(lp_ctx
));
195 if (strcmp(opt_name
, SHARE_READONLY
) == 0) {
196 return lpcfg_read_only(s
, lpcfg_default_service(lp_ctx
));
199 if (strcmp(opt_name
, SHARE_MAP_SYSTEM
) == 0) {
200 return lpcfg_map_system(s
, lpcfg_default_service(lp_ctx
));
203 if (strcmp(opt_name
, SHARE_MAP_HIDDEN
) == 0) {
204 return lpcfg_map_hidden(s
, lpcfg_default_service(lp_ctx
));
207 if (strcmp(opt_name
, SHARE_MAP_ARCHIVE
) == 0) {
208 return lpcfg_map_archive(s
, lpcfg_default_service(lp_ctx
));
211 if (strcmp(opt_name
, SHARE_STRICT_LOCKING
) == 0) {
212 return lpcfg_strict_locking(s
, lpcfg_default_service(lp_ctx
));
215 if (strcmp(opt_name
, SHARE_OPLOCKS
) == 0) {
216 return lpcfg_oplocks(s
, lpcfg_default_service(lp_ctx
));
219 if (strcmp(opt_name
, SHARE_STRICT_SYNC
) == 0) {
220 return lpcfg_strict_sync(s
, lpcfg_default_service(lp_ctx
));
223 if (strcmp(opt_name
, SHARE_MSDFS_ROOT
) == 0) {
224 return lpcfg_msdfs_root(s
, lpcfg_default_service(lp_ctx
));
227 if (strcmp(opt_name
, SHARE_CI_FILESYSTEM
) == 0) {
228 int case_sensitive
= lpcfg_case_sensitive(s
, lpcfg_default_service(lp_ctx
));
230 * Yes, this confusingly named option means Samba acts
231 * case sensitive, so that the filesystem can act case
235 if (case_sensitive
== Auto
) {
236 /* Auto is for unix extensions and unix
237 * clients, which we don't support here.
238 * Samba needs to do the case changing,
239 * because the filesystem is case
242 } else if (case_sensitive
) {
243 /* True means that Samba won't do anything to
244 * change the case of incoming requests.
245 * Essentially this means we trust the file
246 * system to be case insensitive */
249 /* False means that Smaba needs to do the case
250 * changing, because the filesystem is case
256 DEBUG(0,("request for unknown share bool option '%s'\n",
262 static const char **sclassic_string_list_option(TALLOC_CTX
*mem_ctx
, struct share_config
*scfg
, const char *opt_name
)
264 struct loadparm_service
*s
= talloc_get_type(scfg
->opaque
,
265 struct loadparm_service
);
266 struct loadparm_context
*lp_ctx
= talloc_get_type(scfg
->ctx
->priv_data
,
267 struct loadparm_context
);
271 if (strchr(opt_name
, ':')) {
272 parm
= talloc_strdup(scfg
, opt_name
);
276 val
= strchr(parm
, ':');
280 ret
= lpcfg_parm_string_list(mem_ctx
, lp_ctx
, s
, parm
, val
, ",;");
285 if (strcmp(opt_name
, SHARE_HOSTS_ALLOW
) == 0) {
286 return lpcfg_hosts_allow(s
, lpcfg_default_service(lp_ctx
));
289 if (strcmp(opt_name
, SHARE_HOSTS_DENY
) == 0) {
290 return lpcfg_hosts_deny(s
, lpcfg_default_service(lp_ctx
));
293 if (strcmp(opt_name
, SHARE_NTVFS_HANDLER
) == 0) {
294 return lpcfg_ntvfs_handler(s
, lpcfg_default_service(lp_ctx
));
297 DEBUG(0,("request for unknown share list option '%s'\n",
303 static NTSTATUS
sclassic_list_all(TALLOC_CTX
*mem_ctx
,
304 struct share_context
*ctx
,
312 num_services
= lpcfg_numservices((struct loadparm_context
*)ctx
->priv_data
);
314 n
= talloc_array(mem_ctx
, const char *, num_services
);
316 DEBUG(0,("ERROR: Out of memory!\n"));
317 return NT_STATUS_NO_MEMORY
;
320 for (i
= 0; i
< num_services
; i
++) {
321 n
[i
] = talloc_strdup(n
, lpcfg_servicename(lpcfg_servicebynum((struct loadparm_context
*)ctx
->priv_data
, i
)));
323 DEBUG(0,("ERROR: Out of memory!\n"));
325 return NT_STATUS_NO_MEMORY
;
330 *count
= num_services
;
335 static NTSTATUS
sclassic_get_config(TALLOC_CTX
*mem_ctx
,
336 struct share_context
*ctx
,
338 struct share_config
**scfg
)
340 struct share_config
*s
;
341 struct loadparm_service
*service
;
343 service
= lpcfg_service((struct loadparm_context
*)ctx
->priv_data
, name
);
345 if (service
== NULL
) {
346 return NT_STATUS_OBJECT_NAME_NOT_FOUND
;
349 s
= talloc(mem_ctx
, struct share_config
);
351 DEBUG(0,("ERROR: Out of memory!\n"));
352 return NT_STATUS_NO_MEMORY
;
355 s
->name
= talloc_strdup(s
, lpcfg_servicename(service
));
357 DEBUG(0,("ERROR: Out of memory!\n"));
359 return NT_STATUS_NO_MEMORY
;
362 s
->opaque
= (void *)service
;
370 static const struct share_ops ops
= {
372 .init
= sclassic_init
,
373 .string_option
= sclassic_string_option
,
374 .int_option
= sclassic_int_option
,
375 .bool_option
= sclassic_bool_option
,
376 .string_list_option
= sclassic_string_list_option
,
377 .list_all
= sclassic_list_all
,
378 .get_config
= sclassic_get_config
381 NTSTATUS
share_classic_init(TALLOC_CTX
*ctx
)
383 return share_register(&ops
);