s4:lib/messaging: terminate the irpc_servers_byname() result with server_id_set_disco...
[Samba/gebeck_regimport.git] / source4 / param / share_classic.c
blob50b05f322e94fa402f1dc5781e42b35cd4d8f002
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 const char *sclassic_string_option(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 ret;
74 if (strcmp(opt_name, SHARE_NAME) == 0) {
75 return scfg->name;
78 if (strcmp(opt_name, SHARE_PATH) == 0) {
79 return lpcfg_pathname(s, lpcfg_default_service(lp_ctx));
82 if (strcmp(opt_name, SHARE_COMMENT) == 0) {
83 return lpcfg_comment(s, lpcfg_default_service(lp_ctx));
86 if (strcmp(opt_name, SHARE_VOLUME) == 0) {
87 return lpcfg_volume_label(s, lpcfg_default_service(lp_ctx));
90 if (strcmp(opt_name, SHARE_TYPE) == 0) {
91 if (lpcfg_print_ok(s, lpcfg_default_service(lp_ctx))) {
92 return "PRINTER";
94 if (strcmp("NTFS", lpcfg_fstype(s, lpcfg_default_service(lp_ctx))) == 0) {
95 return "DISK";
97 return lpcfg_fstype(s, lpcfg_default_service(lp_ctx));
100 if (strcmp(opt_name, SHARE_PASSWORD) == 0) {
101 return defval;
104 DEBUG(0,("request for unknown share string option '%s'\n",
105 opt_name));
107 return defval;
110 static int sclassic_int_option(struct share_config *scfg, const char *opt_name, int defval)
112 struct loadparm_service *s = talloc_get_type(scfg->opaque,
113 struct loadparm_service);
114 struct loadparm_context *lp_ctx = talloc_get_type(scfg->ctx->priv_data,
115 struct loadparm_context);
116 char *parm, *val;
117 int ret;
119 if (strchr(opt_name, ':')) {
120 parm = talloc_strdup(scfg, opt_name);
121 if (!parm) {
122 return -1;
124 val = strchr(parm, ':');
125 *val = '\0';
126 val++;
128 ret = lpcfg_parm_int(lp_ctx, s, parm, val, defval);
129 if (!ret) {
130 ret = defval;
132 talloc_free(parm);
133 return ret;
136 if (strcmp(opt_name, SHARE_CSC_POLICY) == 0) {
137 return lpcfg_csc_policy(s, lpcfg_default_service(lp_ctx));
140 if (strcmp(opt_name, SHARE_MAX_CONNECTIONS) == 0) {
141 return lpcfg_max_connections(s, lpcfg_default_service(lp_ctx));
144 if (strcmp(opt_name, SHARE_CREATE_MASK) == 0) {
145 return lpcfg_create_mask(s, lpcfg_default_service(lp_ctx));
148 if (strcmp(opt_name, SHARE_DIR_MASK) == 0) {
149 return lpcfg_dir_mask(s, lpcfg_default_service(lp_ctx));
152 if (strcmp(opt_name, SHARE_FORCE_DIR_MODE) == 0) {
153 return lpcfg_force_dir_mode(s, lpcfg_default_service(lp_ctx));
156 if (strcmp(opt_name, SHARE_FORCE_CREATE_MODE) == 0) {
157 return lpcfg_force_create_mode(s, lpcfg_default_service(lp_ctx));
161 DEBUG(0,("request for unknown share int option '%s'\n",
162 opt_name));
164 return defval;
167 static bool sclassic_bool_option(struct share_config *scfg, const char *opt_name,
168 bool defval)
170 struct loadparm_service *s = talloc_get_type(scfg->opaque,
171 struct loadparm_service);
172 struct loadparm_context *lp_ctx = talloc_get_type(scfg->ctx->priv_data,
173 struct loadparm_context);
174 char *parm, *val;
175 bool ret;
177 if (strchr(opt_name, ':')) {
178 parm = talloc_strdup(scfg, opt_name);
179 if(!parm) {
180 return false;
182 val = strchr(parm, ':');
183 *val = '\0';
184 val++;
186 ret = lpcfg_parm_bool(lp_ctx, s, parm, val, defval);
187 talloc_free(parm);
188 return ret;
191 if (strcmp(opt_name, SHARE_AVAILABLE) == 0) {
192 return s != NULL;
195 if (strcmp(opt_name, SHARE_BROWSEABLE) == 0) {
196 return lpcfg_browseable(s, lpcfg_default_service(lp_ctx));
199 if (strcmp(opt_name, SHARE_READONLY) == 0) {
200 return lpcfg_readonly(s, lpcfg_default_service(lp_ctx));
203 if (strcmp(opt_name, SHARE_MAP_SYSTEM) == 0) {
204 return lpcfg_map_system(s, lpcfg_default_service(lp_ctx));
207 if (strcmp(opt_name, SHARE_MAP_HIDDEN) == 0) {
208 return lpcfg_map_hidden(s, lpcfg_default_service(lp_ctx));
211 if (strcmp(opt_name, SHARE_MAP_ARCHIVE) == 0) {
212 return lpcfg_map_archive(s, lpcfg_default_service(lp_ctx));
215 if (strcmp(opt_name, SHARE_STRICT_LOCKING) == 0) {
216 return lpcfg_strict_locking(s, lpcfg_default_service(lp_ctx));
219 if (strcmp(opt_name, SHARE_OPLOCKS) == 0) {
220 return lpcfg_oplocks(s, lpcfg_default_service(lp_ctx));
223 if (strcmp(opt_name, SHARE_STRICT_SYNC) == 0) {
224 return lpcfg_strict_sync(s, lpcfg_default_service(lp_ctx));
227 if (strcmp(opt_name, SHARE_MSDFS_ROOT) == 0) {
228 return lpcfg_msdfs_root(s, lpcfg_default_service(lp_ctx));
231 if (strcmp(opt_name, SHARE_CI_FILESYSTEM) == 0) {
232 int case_sensitive = lpcfg_casesensitive(s, lpcfg_default_service(lp_ctx));
234 * Yes, this confusingly named option means Samba acts
235 * case sensitive, so that the filesystem can act case
236 * insensitive.
239 if (case_sensitive == Auto) {
240 /* Auto is for unix extensions and unix
241 * clients, which we don't support here.
242 * Samba needs to do the case changing,
243 * because the filesystem is case
244 * sensitive */
245 return false;
246 } else if (case_sensitive) {
247 /* True means that Samba won't do anything to
248 * change the case of incoming requests.
249 * Essentially this means we trust the file
250 * system to be case insensitive */
251 return true;
252 } else {
253 /* False means that Smaba needs to do the case
254 * changing, because the filesystem is case
255 * sensitive */
256 return false;
260 DEBUG(0,("request for unknown share bool option '%s'\n",
261 opt_name));
263 return defval;
266 static const char **sclassic_string_list_option(TALLOC_CTX *mem_ctx, struct share_config *scfg, const char *opt_name)
268 struct loadparm_service *s = talloc_get_type(scfg->opaque,
269 struct loadparm_service);
270 struct loadparm_context *lp_ctx = talloc_get_type(scfg->ctx->priv_data,
271 struct loadparm_context);
272 char *parm, *val;
273 const char **ret;
275 if (strchr(opt_name, ':')) {
276 parm = talloc_strdup(scfg, opt_name);
277 if (!parm) {
278 return NULL;
280 val = strchr(parm, ':');
281 *val = '\0';
282 val++;
284 ret = lpcfg_parm_string_list(mem_ctx, lp_ctx, s, parm, val, ",;");
285 talloc_free(parm);
286 return ret;
289 if (strcmp(opt_name, SHARE_HOSTS_ALLOW) == 0) {
290 return lpcfg_hostsallow(s, lpcfg_default_service(lp_ctx));
293 if (strcmp(opt_name, SHARE_HOSTS_DENY) == 0) {
294 return lpcfg_hostsdeny(s, lpcfg_default_service(lp_ctx));
297 if (strcmp(opt_name, SHARE_NTVFS_HANDLER) == 0) {
298 return lpcfg_ntvfs_handler(s, lpcfg_default_service(lp_ctx));
301 DEBUG(0,("request for unknown share list option '%s'\n",
302 opt_name));
304 return NULL;
307 static NTSTATUS sclassic_list_all(TALLOC_CTX *mem_ctx,
308 struct share_context *ctx,
309 int *count,
310 const char ***names)
312 int i;
313 int num_services;
314 const char **n;
316 num_services = lpcfg_numservices((struct loadparm_context *)ctx->priv_data);
318 n = talloc_array(mem_ctx, const char *, num_services);
319 if (!n) {
320 DEBUG(0,("ERROR: Out of memory!\n"));
321 return NT_STATUS_NO_MEMORY;
324 for (i = 0; i < num_services; i++) {
325 n[i] = talloc_strdup(n, lpcfg_servicename(lpcfg_servicebynum((struct loadparm_context *)ctx->priv_data, i)));
326 if (!n[i]) {
327 DEBUG(0,("ERROR: Out of memory!\n"));
328 talloc_free(n);
329 return NT_STATUS_NO_MEMORY;
333 *names = n;
334 *count = num_services;
336 return NT_STATUS_OK;
339 static NTSTATUS sclassic_get_config(TALLOC_CTX *mem_ctx,
340 struct share_context *ctx,
341 const char *name,
342 struct share_config **scfg)
344 struct share_config *s;
345 struct loadparm_service *service;
347 service = lpcfg_service((struct loadparm_context *)ctx->priv_data, name);
349 if (service == NULL) {
350 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
353 s = talloc(mem_ctx, struct share_config);
354 if (!s) {
355 DEBUG(0,("ERROR: Out of memory!\n"));
356 return NT_STATUS_NO_MEMORY;
359 s->name = talloc_strdup(s, lpcfg_servicename(service));
360 if (!s->name) {
361 DEBUG(0,("ERROR: Out of memory!\n"));
362 talloc_free(s);
363 return NT_STATUS_NO_MEMORY;
366 s->opaque = (void *)service;
367 s->ctx = ctx;
369 *scfg = s;
371 return NT_STATUS_OK;
374 static const struct share_ops ops = {
375 .name = "classic",
376 .init = sclassic_init,
377 .string_option = sclassic_string_option,
378 .int_option = sclassic_int_option,
379 .bool_option = sclassic_bool_option,
380 .string_list_option = sclassic_string_list_option,
381 .list_all = sclassic_list_all,
382 .get_config = sclassic_get_config
385 NTSTATUS share_classic_init(void)
387 return share_register(&ops);