vfs_ceph_new: Remove unused symbol for ceph_readdir
[Samba.git] / source4 / param / share_classic.c
blobd03558d1aa5da5a837dd53a9671e75a859898f96
1 /*
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/>.
22 #include "includes.h"
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);
34 if (!*ctx) {
35 DEBUG(0, ("ERROR: Out of memory!\n"));
36 return NT_STATUS_NO_MEMORY;
39 (*ctx)->ops = ops;
40 (*ctx)->priv_data = lp_ctx;
42 return NT_STATUS_OK;
45 static char *sclassic_string_option(TALLOC_CTX *mem_ctx,
46 struct share_config *scfg,
47 const char *opt_name,
48 const char *defval)
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);
54 char *parm, *val;
55 const char *ret;
57 if (strchr(opt_name, ':')) {
58 parm = talloc_strdup(scfg, opt_name);
59 if (!parm) {
60 return NULL;
62 val = strchr(parm, ':');
63 *val = '\0';
64 val++;
66 ret = lpcfg_parm_string(lp_ctx, s, parm, val);
67 if (!ret) {
68 ret = defval;
70 talloc_free(parm);
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",
101 opt_name));
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);
112 char *parm, *val;
113 int ret;
115 if (strchr(opt_name, ':')) {
116 parm = talloc_strdup(scfg, opt_name);
117 if (!parm) {
118 return -1;
120 val = strchr(parm, ':');
121 *val = '\0';
122 val++;
124 ret = lpcfg_parm_int(lp_ctx, s, parm, val, defval);
125 if (!ret) {
126 ret = defval;
128 talloc_free(parm);
129 return ret;
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",
158 opt_name));
160 return defval;
163 static bool sclassic_bool_option(struct share_config *scfg, const char *opt_name,
164 bool defval)
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);
170 char *parm, *val;
171 bool ret;
173 if (strchr(opt_name, ':')) {
174 parm = talloc_strdup(scfg, opt_name);
175 if(!parm) {
176 return false;
178 val = strchr(parm, ':');
179 *val = '\0';
180 val++;
182 ret = lpcfg_parm_bool(lp_ctx, s, parm, val, defval);
183 talloc_free(parm);
184 return ret;
187 if (strcmp(opt_name, SHARE_AVAILABLE) == 0) {
188 return s != NULL;
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
232 * insensitive.
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
240 * sensitive */
241 return false;
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 */
247 return true;
248 } else {
249 /* False means that Smaba needs to do the case
250 * changing, because the filesystem is case
251 * sensitive */
252 return false;
256 DEBUG(0,("request for unknown share bool option '%s'\n",
257 opt_name));
259 return defval;
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);
268 char *parm, *val;
269 const char **ret;
271 if (strchr(opt_name, ':')) {
272 parm = talloc_strdup(scfg, opt_name);
273 if (!parm) {
274 return NULL;
276 val = strchr(parm, ':');
277 *val = '\0';
278 val++;
280 ret = lpcfg_parm_string_list(mem_ctx, lp_ctx, s, parm, val, ",;");
281 talloc_free(parm);
282 return ret;
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",
298 opt_name));
300 return NULL;
303 static NTSTATUS sclassic_list_all(TALLOC_CTX *mem_ctx,
304 struct share_context *ctx,
305 int *count,
306 const char ***names)
308 int i;
309 int num_services;
310 const char **n;
312 num_services = lpcfg_numservices((struct loadparm_context *)ctx->priv_data);
314 n = talloc_array(mem_ctx, const char *, num_services);
315 if (!n) {
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)));
322 if (!n[i]) {
323 DEBUG(0,("ERROR: Out of memory!\n"));
324 talloc_free(n);
325 return NT_STATUS_NO_MEMORY;
329 *names = n;
330 *count = num_services;
332 return NT_STATUS_OK;
335 static NTSTATUS sclassic_get_config(TALLOC_CTX *mem_ctx,
336 struct share_context *ctx,
337 const char *name,
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);
350 if (!s) {
351 DEBUG(0,("ERROR: Out of memory!\n"));
352 return NT_STATUS_NO_MEMORY;
355 s->name = talloc_strdup(s, lpcfg_servicename(service));
356 if (!s->name) {
357 DEBUG(0,("ERROR: Out of memory!\n"));
358 talloc_free(s);
359 return NT_STATUS_NO_MEMORY;
362 s->opaque = (void *)service;
363 s->ctx = ctx;
365 *scfg = s;
367 return NT_STATUS_OK;
370 static const struct share_ops ops = {
371 .name = "classic",
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);