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 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 char *sclassic_string_option(TALLOC_CTX
*mem_ctx
,
47 struct share_config
*scfg
,
51 struct loadparm_service
*s
= talloc_get_type(scfg
->opaque
,
52 struct loadparm_service
);
53 struct loadparm_context
*lp_ctx
= talloc_get_type(scfg
->ctx
->priv_data
,
54 struct loadparm_context
);
58 if (strchr(opt_name
, ':')) {
59 parm
= talloc_strdup(scfg
, opt_name
);
63 val
= strchr(parm
, ':');
67 ret
= lpcfg_parm_string(lp_ctx
, s
, parm
, val
);
72 return talloc_strdup(mem_ctx
, ret
);
75 if (strcmp(opt_name
, SHARE_NAME
) == 0) {
76 return talloc_strdup(mem_ctx
, scfg
->name
);
79 if (strcmp(opt_name
, SHARE_PATH
) == 0) {
80 return lpcfg_path(s
, lpcfg_default_service(lp_ctx
), mem_ctx
);
83 if (strcmp(opt_name
, SHARE_COMMENT
) == 0) {
84 return lpcfg_comment(s
, lpcfg_default_service(lp_ctx
), mem_ctx
);
87 if (strcmp(opt_name
, SHARE_VOLUME
) == 0) {
88 return talloc_strdup(mem_ctx
, lpcfg_volume_label(s
, lpcfg_default_service(lp_ctx
)));
91 if (strcmp(opt_name
, SHARE_TYPE
) == 0) {
92 if (lpcfg_printable(s
, lpcfg_default_service(lp_ctx
))) {
93 return talloc_strdup(mem_ctx
, "PRINTER");
95 if (strcmp("NTFS", lpcfg_fstype(s
, lpcfg_default_service(lp_ctx
))) == 0) {
96 return talloc_strdup(mem_ctx
, "DISK");
98 return talloc_strdup(mem_ctx
, lpcfg_fstype(s
, lpcfg_default_service(lp_ctx
)));
101 if (strcmp(opt_name
, SHARE_PASSWORD
) == 0) {
102 return talloc_strdup(mem_ctx
, defval
);
105 DEBUG(0,("request for unknown share string option '%s'\n",
108 return talloc_strdup(mem_ctx
, defval
);
111 static int sclassic_int_option(struct share_config
*scfg
, const char *opt_name
, int defval
)
113 struct loadparm_service
*s
= talloc_get_type(scfg
->opaque
,
114 struct loadparm_service
);
115 struct loadparm_context
*lp_ctx
= talloc_get_type(scfg
->ctx
->priv_data
,
116 struct loadparm_context
);
120 if (strchr(opt_name
, ':')) {
121 parm
= talloc_strdup(scfg
, opt_name
);
125 val
= strchr(parm
, ':');
129 ret
= lpcfg_parm_int(lp_ctx
, s
, parm
, val
, defval
);
137 if (strcmp(opt_name
, SHARE_CSC_POLICY
) == 0) {
138 return lpcfg_csc_policy(s
, lpcfg_default_service(lp_ctx
));
141 if (strcmp(opt_name
, SHARE_MAX_CONNECTIONS
) == 0) {
142 return lpcfg_max_connections(s
, lpcfg_default_service(lp_ctx
));
145 if (strcmp(opt_name
, SHARE_CREATE_MASK
) == 0) {
146 return lpcfg_create_mask(s
, lpcfg_default_service(lp_ctx
));
149 if (strcmp(opt_name
, SHARE_DIR_MASK
) == 0) {
150 return lpcfg_directory_mask(s
, lpcfg_default_service(lp_ctx
));
153 if (strcmp(opt_name
, SHARE_FORCE_DIR_MODE
) == 0) {
154 return lpcfg_force_directory_mode(s
, lpcfg_default_service(lp_ctx
));
157 if (strcmp(opt_name
, SHARE_FORCE_CREATE_MODE
) == 0) {
158 return lpcfg_force_create_mode(s
, lpcfg_default_service(lp_ctx
));
162 DEBUG(0,("request for unknown share int option '%s'\n",
168 static bool sclassic_bool_option(struct share_config
*scfg
, const char *opt_name
,
171 struct loadparm_service
*s
= talloc_get_type(scfg
->opaque
,
172 struct loadparm_service
);
173 struct loadparm_context
*lp_ctx
= talloc_get_type(scfg
->ctx
->priv_data
,
174 struct loadparm_context
);
178 if (strchr(opt_name
, ':')) {
179 parm
= talloc_strdup(scfg
, opt_name
);
183 val
= strchr(parm
, ':');
187 ret
= lpcfg_parm_bool(lp_ctx
, s
, parm
, val
, defval
);
192 if (strcmp(opt_name
, SHARE_AVAILABLE
) == 0) {
196 if (strcmp(opt_name
, SHARE_BROWSEABLE
) == 0) {
197 return lpcfg_browseable(s
, lpcfg_default_service(lp_ctx
));
200 if (strcmp(opt_name
, SHARE_READONLY
) == 0) {
201 return lpcfg_read_only(s
, lpcfg_default_service(lp_ctx
));
204 if (strcmp(opt_name
, SHARE_MAP_SYSTEM
) == 0) {
205 return lpcfg_map_system(s
, lpcfg_default_service(lp_ctx
));
208 if (strcmp(opt_name
, SHARE_MAP_HIDDEN
) == 0) {
209 return lpcfg_map_hidden(s
, lpcfg_default_service(lp_ctx
));
212 if (strcmp(opt_name
, SHARE_MAP_ARCHIVE
) == 0) {
213 return lpcfg_map_archive(s
, lpcfg_default_service(lp_ctx
));
216 if (strcmp(opt_name
, SHARE_STRICT_LOCKING
) == 0) {
217 return lpcfg_strict_locking(s
, lpcfg_default_service(lp_ctx
));
220 if (strcmp(opt_name
, SHARE_OPLOCKS
) == 0) {
221 return lpcfg_oplocks(s
, lpcfg_default_service(lp_ctx
));
224 if (strcmp(opt_name
, SHARE_STRICT_SYNC
) == 0) {
225 return lpcfg_strict_sync(s
, lpcfg_default_service(lp_ctx
));
228 if (strcmp(opt_name
, SHARE_MSDFS_ROOT
) == 0) {
229 return lpcfg_msdfs_root(s
, lpcfg_default_service(lp_ctx
));
232 if (strcmp(opt_name
, SHARE_CI_FILESYSTEM
) == 0) {
233 int case_sensitive
= lpcfg_case_sensitive(s
, lpcfg_default_service(lp_ctx
));
235 * Yes, this confusingly named option means Samba acts
236 * case sensitive, so that the filesystem can act case
240 if (case_sensitive
== Auto
) {
241 /* Auto is for unix extensions and unix
242 * clients, which we don't support here.
243 * Samba needs to do the case changing,
244 * because the filesystem is case
247 } else if (case_sensitive
) {
248 /* True means that Samba won't do anything to
249 * change the case of incoming requests.
250 * Essentially this means we trust the file
251 * system to be case insensitive */
254 /* False means that Smaba needs to do the case
255 * changing, because the filesystem is case
261 DEBUG(0,("request for unknown share bool option '%s'\n",
267 static const char **sclassic_string_list_option(TALLOC_CTX
*mem_ctx
, struct share_config
*scfg
, const char *opt_name
)
269 struct loadparm_service
*s
= talloc_get_type(scfg
->opaque
,
270 struct loadparm_service
);
271 struct loadparm_context
*lp_ctx
= talloc_get_type(scfg
->ctx
->priv_data
,
272 struct loadparm_context
);
276 if (strchr(opt_name
, ':')) {
277 parm
= talloc_strdup(scfg
, opt_name
);
281 val
= strchr(parm
, ':');
285 ret
= lpcfg_parm_string_list(mem_ctx
, lp_ctx
, s
, parm
, val
, ",;");
290 if (strcmp(opt_name
, SHARE_HOSTS_ALLOW
) == 0) {
291 return lpcfg_hosts_allow(s
, lpcfg_default_service(lp_ctx
));
294 if (strcmp(opt_name
, SHARE_HOSTS_DENY
) == 0) {
295 return lpcfg_hosts_deny(s
, lpcfg_default_service(lp_ctx
));
298 if (strcmp(opt_name
, SHARE_NTVFS_HANDLER
) == 0) {
299 return lpcfg_ntvfs_handler(s
, lpcfg_default_service(lp_ctx
));
302 DEBUG(0,("request for unknown share list option '%s'\n",
308 static NTSTATUS
sclassic_list_all(TALLOC_CTX
*mem_ctx
,
309 struct share_context
*ctx
,
317 num_services
= lpcfg_numservices((struct loadparm_context
*)ctx
->priv_data
);
319 n
= talloc_array(mem_ctx
, const char *, num_services
);
321 DEBUG(0,("ERROR: Out of memory!\n"));
322 return NT_STATUS_NO_MEMORY
;
325 for (i
= 0; i
< num_services
; i
++) {
326 n
[i
] = talloc_strdup(n
, lpcfg_servicename(lpcfg_servicebynum((struct loadparm_context
*)ctx
->priv_data
, i
)));
328 DEBUG(0,("ERROR: Out of memory!\n"));
330 return NT_STATUS_NO_MEMORY
;
335 *count
= num_services
;
340 static NTSTATUS
sclassic_get_config(TALLOC_CTX
*mem_ctx
,
341 struct share_context
*ctx
,
343 struct share_config
**scfg
)
345 struct share_config
*s
;
346 struct loadparm_service
*service
;
348 service
= lpcfg_service((struct loadparm_context
*)ctx
->priv_data
, name
);
350 if (service
== NULL
) {
351 return NT_STATUS_OBJECT_NAME_NOT_FOUND
;
354 s
= talloc(mem_ctx
, struct share_config
);
356 DEBUG(0,("ERROR: Out of memory!\n"));
357 return NT_STATUS_NO_MEMORY
;
360 s
->name
= talloc_strdup(s
, lpcfg_servicename(service
));
362 DEBUG(0,("ERROR: Out of memory!\n"));
364 return NT_STATUS_NO_MEMORY
;
367 s
->opaque
= (void *)service
;
375 static const struct share_ops ops
= {
377 .init
= sclassic_init
,
378 .string_option
= sclassic_string_option
,
379 .int_option
= sclassic_int_option
,
380 .bool_option
= sclassic_bool_option
,
381 .string_list_option
= sclassic_string_list_option
,
382 .list_all
= sclassic_list_all
,
383 .get_config
= sclassic_get_config
386 NTSTATUS
share_classic_init(TALLOC_CTX
*ctx
)
388 return share_register(&ops
);