r25041: Use context in more places, fix warnings.
[Samba.git] / source / param / share_classic.c
blobdf86e2be4fca4a4636260945e1218e2e7dbe756e
1 /*
2 Unix SMB/CIFS implementation.
4 Classic file based services 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 static NTSTATUS sclassic_init(TALLOC_CTX *mem_ctx, const struct share_ops *ops, struct share_context **ctx)
28 *ctx = talloc(mem_ctx, struct share_context);
29 if (!*ctx) {
30 DEBUG(0, ("ERROR: Out of memory!\n"));
31 return NT_STATUS_NO_MEMORY;
34 (*ctx)->ops = ops;
35 (*ctx)->priv_data = NULL;
37 return NT_STATUS_OK;
40 static const char *sclassic_string_option(struct share_config *scfg, const char *opt_name, const char *defval)
42 struct loadparm_service *s = talloc_get_type(scfg->opaque,
43 struct loadparm_service);
44 char *parm, *val;
45 const char *ret;
47 if (strchr(opt_name, ':')) {
48 parm = talloc_strdup(scfg, opt_name);
49 if (!parm) {
50 return NULL;
52 val = strchr(parm, ':');
53 *val = '\0';
54 val++;
56 ret = lp_parm_string(s, parm, val);
57 if (!ret) {
58 ret = defval;
60 talloc_free(parm);
61 return ret;
64 if (strcmp(opt_name, SHARE_NAME) == 0) {
65 return scfg->name;
68 if (strcmp(opt_name, SHARE_PATH) == 0) {
69 return lp_pathname(s);
72 if (strcmp(opt_name, SHARE_COMMENT) == 0) {
73 return lp_comment(s);
76 if (strcmp(opt_name, SHARE_VOLUME) == 0) {
77 return volume_label(s);
80 if (strcmp(opt_name, SHARE_TYPE) == 0) {
81 if (lp_print_ok(s)) {
82 return "PRINTER";
84 if (strcmp("NTFS", lp_fstype(s)) == 0) {
85 return "DISK";
87 return lp_fstype(s);
90 if (strcmp(opt_name, SHARE_PASSWORD) == 0) {
91 return defval;
94 DEBUG(0,("request for unknown share string option '%s'\n",
95 opt_name));
97 return defval;
100 static int sclassic_int_option(struct share_config *scfg, const char *opt_name, int defval)
102 struct loadparm_service *s = talloc_get_type(scfg->opaque,
103 struct loadparm_service);
104 char *parm, *val;
105 int ret;
107 if (strchr(opt_name, ':')) {
108 parm = talloc_strdup(scfg, opt_name);
109 if (!parm) {
110 return -1;
112 val = strchr(parm, ':');
113 *val = '\0';
114 val++;
116 ret = lp_parm_int(s, parm, val, defval);
117 if (!ret) {
118 ret = defval;
120 talloc_free(parm);
121 return ret;
124 if (strcmp(opt_name, SHARE_CSC_POLICY) == 0) {
125 return lp_csc_policy(s);
128 if (strcmp(opt_name, SHARE_MAX_CONNECTIONS) == 0) {
129 return lp_max_connections(s);
132 if (strcmp(opt_name, SHARE_CREATE_MASK) == 0) {
133 return lp_create_mask(s);
136 if (strcmp(opt_name, SHARE_DIR_MASK) == 0) {
137 return lp_dir_mask(s);
140 if (strcmp(opt_name, SHARE_FORCE_DIR_MODE) == 0) {
141 return lp_force_dir_mode(s);
144 if (strcmp(opt_name, SHARE_FORCE_CREATE_MODE) == 0) {
145 return lp_force_create_mode(s);
149 DEBUG(0,("request for unknown share int option '%s'\n",
150 opt_name));
152 return defval;
155 static bool sclassic_bool_option(struct share_config *scfg, const char *opt_name,
156 bool defval)
158 struct loadparm_service *s = talloc_get_type(scfg->opaque,
159 struct loadparm_service);
160 char *parm, *val;
161 BOOL ret;
163 if (strchr(opt_name, ':')) {
164 parm = talloc_strdup(scfg, opt_name);
165 if(!parm) {
166 return False;
168 val = strchr(parm, ':');
169 *val = '\0';
170 val++;
172 ret = lp_parm_bool(s, parm, val, defval);
173 talloc_free(parm);
174 return ret;
177 if (strcmp(opt_name, SHARE_AVAILABLE) == 0) {
178 return s != NULL;
181 if (strcmp(opt_name, SHARE_BROWSEABLE) == 0) {
182 return lp_browseable(s);
185 if (strcmp(opt_name, SHARE_READONLY) == 0) {
186 return lp_readonly(s);
189 if (strcmp(opt_name, SHARE_MAP_SYSTEM) == 0) {
190 return lp_map_system(s);
193 if (strcmp(opt_name, SHARE_MAP_HIDDEN) == 0) {
194 return lp_map_hidden(s);
197 if (strcmp(opt_name, SHARE_MAP_ARCHIVE) == 0) {
198 return lp_map_archive(s);
201 if (strcmp(opt_name, SHARE_STRICT_LOCKING) == 0) {
202 return lp_strict_locking(s);
205 if (strcmp(opt_name, SHARE_STRICT_SYNC) == 0) {
206 return lp_strict_sync(s);
209 if (strcmp(opt_name, SHARE_MSDFS_ROOT) == 0) {
210 return lp_msdfs_root(s);
213 if (strcmp(opt_name, SHARE_CI_FILESYSTEM) == 0) {
214 return lp_ci_filesystem(s);
217 DEBUG(0,("request for unknown share bool option '%s'\n",
218 opt_name));
220 return defval;
223 static const char **sclassic_string_list_option(TALLOC_CTX *mem_ctx, struct share_config *scfg, const char *opt_name)
225 struct loadparm_service *s = talloc_get_type(scfg->opaque,
226 struct loadparm_service);
227 char *parm, *val;
228 const char **ret;
230 if (strchr(opt_name, ':')) {
231 parm = talloc_strdup(scfg, opt_name);
232 if (!parm) {
233 return NULL;
235 val = strchr(parm, ':');
236 *val = '\0';
237 val++;
239 ret = lp_parm_string_list(s, parm, val, ",;");
240 talloc_free(parm);
241 return ret;
244 if (strcmp(opt_name, SHARE_HOSTS_ALLOW) == 0) {
245 return lp_hostsallow(s);
248 if (strcmp(opt_name, SHARE_HOSTS_DENY) == 0) {
249 return lp_hostsdeny(s);
252 if (strcmp(opt_name, SHARE_NTVFS_HANDLER) == 0) {
253 return lp_ntvfs_handler(s);
256 DEBUG(0,("request for unknown share list option '%s'\n",
257 opt_name));
259 return NULL;
262 static NTSTATUS sclassic_list_all(TALLOC_CTX *mem_ctx,
263 struct share_context *ctx,
264 int *count,
265 const char ***names)
267 int i;
268 int num_services;
269 const char **n;
271 num_services = lp_numservices();
273 n = talloc_array(mem_ctx, const char *, num_services);
274 if (!n) {
275 DEBUG(0,("ERROR: Out of memory!\n"));
276 return NT_STATUS_NO_MEMORY;
279 for (i = 0; i < num_services; i++) {
280 n[i] = talloc_strdup(n, lp_servicename(lp_servicebynum(i)));
281 if (!n[i]) {
282 DEBUG(0,("ERROR: Out of memory!\n"));
283 talloc_free(n);
284 return NT_STATUS_NO_MEMORY;
288 *names = n;
289 *count = num_services;
291 return NT_STATUS_OK;
294 static NTSTATUS sclassic_get_config(TALLOC_CTX *mem_ctx,
295 struct share_context *ctx,
296 const char *name,
297 struct share_config **scfg)
299 struct share_config *s;
300 struct loadparm_service *service;
302 service = lp_service(name);
304 if (service == NULL) {
305 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
308 s = talloc(mem_ctx, struct share_config);
309 if (!s) {
310 DEBUG(0,("ERROR: Out of memory!\n"));
311 return NT_STATUS_NO_MEMORY;
314 s->name = talloc_strdup(s, lp_servicename(service));
315 if (!s->name) {
316 DEBUG(0,("ERROR: Out of memory!\n"));
317 talloc_free(s);
318 return NT_STATUS_NO_MEMORY;
321 s->opaque = (void *)service;
322 s->ctx = ctx;
324 *scfg = s;
326 return NT_STATUS_OK;
329 static const struct share_ops ops = {
330 .name = "classic",
331 .init = sclassic_init,
332 .string_option = sclassic_string_option,
333 .int_option = sclassic_int_option,
334 .bool_option = sclassic_bool_option,
335 .string_list_option = sclassic_string_list_option,
336 .list_all = sclassic_list_all,
337 .get_config = sclassic_get_config
340 NTSTATUS share_classic_init(void)
342 return share_register(&ops);