nfs4acls: Use talloc_realloc()
[Samba.git] / source4 / param / share_classic.c
blob67ea392824fb8fe3f2e1f77365df10c9b2280bb2
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(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);
35 if (!*ctx) {
36 DEBUG(0, ("ERROR: Out of memory!\n"));
37 return NT_STATUS_NO_MEMORY;
40 (*ctx)->ops = ops;
41 (*ctx)->priv_data = lp_ctx;
43 return NT_STATUS_OK;
46 static char *sclassic_string_option(TALLOC_CTX *mem_ctx,
47 struct share_config *scfg,
48 const char *opt_name,
49 const char *defval)
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);
55 char *parm, *val;
56 const char *ret;
58 if (strchr(opt_name, ':')) {
59 parm = talloc_strdup(scfg, opt_name);
60 if (!parm) {
61 return NULL;
63 val = strchr(parm, ':');
64 *val = '\0';
65 val++;
67 ret = lpcfg_parm_string(lp_ctx, s, parm, val);
68 if (!ret) {
69 ret = defval;
71 talloc_free(parm);
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",
106 opt_name));
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);
117 char *parm, *val;
118 int ret;
120 if (strchr(opt_name, ':')) {
121 parm = talloc_strdup(scfg, opt_name);
122 if (!parm) {
123 return -1;
125 val = strchr(parm, ':');
126 *val = '\0';
127 val++;
129 ret = lpcfg_parm_int(lp_ctx, s, parm, val, defval);
130 if (!ret) {
131 ret = defval;
133 talloc_free(parm);
134 return ret;
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",
163 opt_name));
165 return defval;
168 static bool sclassic_bool_option(struct share_config *scfg, const char *opt_name,
169 bool defval)
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);
175 char *parm, *val;
176 bool ret;
178 if (strchr(opt_name, ':')) {
179 parm = talloc_strdup(scfg, opt_name);
180 if(!parm) {
181 return false;
183 val = strchr(parm, ':');
184 *val = '\0';
185 val++;
187 ret = lpcfg_parm_bool(lp_ctx, s, parm, val, defval);
188 talloc_free(parm);
189 return ret;
192 if (strcmp(opt_name, SHARE_AVAILABLE) == 0) {
193 return s != NULL;
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
237 * insensitive.
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
245 * sensitive */
246 return false;
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 */
252 return true;
253 } else {
254 /* False means that Smaba needs to do the case
255 * changing, because the filesystem is case
256 * sensitive */
257 return false;
261 DEBUG(0,("request for unknown share bool option '%s'\n",
262 opt_name));
264 return defval;
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);
273 char *parm, *val;
274 const char **ret;
276 if (strchr(opt_name, ':')) {
277 parm = talloc_strdup(scfg, opt_name);
278 if (!parm) {
279 return NULL;
281 val = strchr(parm, ':');
282 *val = '\0';
283 val++;
285 ret = lpcfg_parm_string_list(mem_ctx, lp_ctx, s, parm, val, ",;");
286 talloc_free(parm);
287 return ret;
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",
303 opt_name));
305 return NULL;
308 static NTSTATUS sclassic_list_all(TALLOC_CTX *mem_ctx,
309 struct share_context *ctx,
310 int *count,
311 const char ***names)
313 int i;
314 int num_services;
315 const char **n;
317 num_services = lpcfg_numservices((struct loadparm_context *)ctx->priv_data);
319 n = talloc_array(mem_ctx, const char *, num_services);
320 if (!n) {
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)));
327 if (!n[i]) {
328 DEBUG(0,("ERROR: Out of memory!\n"));
329 talloc_free(n);
330 return NT_STATUS_NO_MEMORY;
334 *names = n;
335 *count = num_services;
337 return NT_STATUS_OK;
340 static NTSTATUS sclassic_get_config(TALLOC_CTX *mem_ctx,
341 struct share_context *ctx,
342 const char *name,
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);
355 if (!s) {
356 DEBUG(0,("ERROR: Out of memory!\n"));
357 return NT_STATUS_NO_MEMORY;
360 s->name = talloc_strdup(s, lpcfg_servicename(service));
361 if (!s->name) {
362 DEBUG(0,("ERROR: Out of memory!\n"));
363 talloc_free(s);
364 return NT_STATUS_NO_MEMORY;
367 s->opaque = (void *)service;
368 s->ctx = ctx;
370 *scfg = s;
372 return NT_STATUS_OK;
375 static const struct share_ops ops = {
376 .name = "classic",
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(void)
388 return share_register(&ops);