s4-netlogon: implement dcesrv_netr_DsRAddressToSitenamesExW
[Samba/aatanasov.git] / source4 / param / share_classic.c
blobd732372f450b26fe89b3bcb6e901216ddfffea52
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 static NTSTATUS sclassic_init(TALLOC_CTX *mem_ctx,
27 const struct share_ops *ops,
28 struct tevent_context *event_ctx,
29 struct loadparm_context *lp_ctx,
30 struct share_context **ctx)
32 *ctx = talloc(mem_ctx, struct share_context);
33 if (!*ctx) {
34 DEBUG(0, ("ERROR: Out of memory!\n"));
35 return NT_STATUS_NO_MEMORY;
38 (*ctx)->ops = ops;
39 (*ctx)->priv_data = lp_ctx;
41 return NT_STATUS_OK;
44 static const char *sclassic_string_option(struct share_config *scfg,
45 const char *opt_name,
46 const char *defval)
48 struct loadparm_service *s = talloc_get_type(scfg->opaque,
49 struct loadparm_service);
50 struct loadparm_context *lp_ctx = talloc_get_type(scfg->ctx->priv_data,
51 struct loadparm_context);
52 char *parm, *val;
53 const char *ret;
55 if (strchr(opt_name, ':')) {
56 parm = talloc_strdup(scfg, opt_name);
57 if (!parm) {
58 return NULL;
60 val = strchr(parm, ':');
61 *val = '\0';
62 val++;
64 ret = lp_parm_string(lp_ctx, s, parm, val);
65 if (!ret) {
66 ret = defval;
68 talloc_free(parm);
69 return ret;
72 if (strcmp(opt_name, SHARE_NAME) == 0) {
73 return scfg->name;
76 if (strcmp(opt_name, SHARE_PATH) == 0) {
77 return lp_pathname(s, lp_default_service(lp_ctx));
80 if (strcmp(opt_name, SHARE_COMMENT) == 0) {
81 return lp_comment(s, lp_default_service(lp_ctx));
84 if (strcmp(opt_name, SHARE_VOLUME) == 0) {
85 return volume_label(s, lp_default_service(lp_ctx));
88 if (strcmp(opt_name, SHARE_TYPE) == 0) {
89 if (lp_print_ok(s, lp_default_service(lp_ctx))) {
90 return "PRINTER";
92 if (strcmp("NTFS", lp_fstype(s, lp_default_service(lp_ctx))) == 0) {
93 return "DISK";
95 return lp_fstype(s, lp_default_service(lp_ctx));
98 if (strcmp(opt_name, SHARE_PASSWORD) == 0) {
99 return defval;
102 DEBUG(0,("request for unknown share string option '%s'\n",
103 opt_name));
105 return defval;
108 static int sclassic_int_option(struct share_config *scfg, const char *opt_name, int defval)
110 struct loadparm_service *s = talloc_get_type(scfg->opaque,
111 struct loadparm_service);
112 struct loadparm_context *lp_ctx = talloc_get_type(scfg->ctx->priv_data,
113 struct loadparm_context);
114 char *parm, *val;
115 int ret;
117 if (strchr(opt_name, ':')) {
118 parm = talloc_strdup(scfg, opt_name);
119 if (!parm) {
120 return -1;
122 val = strchr(parm, ':');
123 *val = '\0';
124 val++;
126 ret = lp_parm_int(lp_ctx, s, parm, val, defval);
127 if (!ret) {
128 ret = defval;
130 talloc_free(parm);
131 return ret;
134 if (strcmp(opt_name, SHARE_CSC_POLICY) == 0) {
135 return lp_csc_policy(s, lp_default_service(lp_ctx));
138 if (strcmp(opt_name, SHARE_MAX_CONNECTIONS) == 0) {
139 return lp_max_connections(s, lp_default_service(lp_ctx));
142 if (strcmp(opt_name, SHARE_CREATE_MASK) == 0) {
143 return lp_create_mask(s, lp_default_service(lp_ctx));
146 if (strcmp(opt_name, SHARE_DIR_MASK) == 0) {
147 return lp_dir_mask(s, lp_default_service(lp_ctx));
150 if (strcmp(opt_name, SHARE_FORCE_DIR_MODE) == 0) {
151 return lp_force_dir_mode(s, lp_default_service(lp_ctx));
154 if (strcmp(opt_name, SHARE_FORCE_CREATE_MODE) == 0) {
155 return lp_force_create_mode(s, lp_default_service(lp_ctx));
159 DEBUG(0,("request for unknown share int option '%s'\n",
160 opt_name));
162 return defval;
165 static bool sclassic_bool_option(struct share_config *scfg, const char *opt_name,
166 bool defval)
168 struct loadparm_service *s = talloc_get_type(scfg->opaque,
169 struct loadparm_service);
170 struct loadparm_context *lp_ctx = talloc_get_type(scfg->ctx->priv_data,
171 struct loadparm_context);
172 char *parm, *val;
173 bool ret;
175 if (strchr(opt_name, ':')) {
176 parm = talloc_strdup(scfg, opt_name);
177 if(!parm) {
178 return false;
180 val = strchr(parm, ':');
181 *val = '\0';
182 val++;
184 ret = lp_parm_bool(lp_ctx, s, parm, val, defval);
185 talloc_free(parm);
186 return ret;
189 if (strcmp(opt_name, SHARE_AVAILABLE) == 0) {
190 return s != NULL;
193 if (strcmp(opt_name, SHARE_BROWSEABLE) == 0) {
194 return lp_browseable(s, lp_default_service(lp_ctx));
197 if (strcmp(opt_name, SHARE_READONLY) == 0) {
198 return lp_readonly(s, lp_default_service(lp_ctx));
201 if (strcmp(opt_name, SHARE_MAP_SYSTEM) == 0) {
202 return lp_map_system(s, lp_default_service(lp_ctx));
205 if (strcmp(opt_name, SHARE_MAP_HIDDEN) == 0) {
206 return lp_map_hidden(s, lp_default_service(lp_ctx));
209 if (strcmp(opt_name, SHARE_MAP_ARCHIVE) == 0) {
210 return lp_map_archive(s, lp_default_service(lp_ctx));
213 if (strcmp(opt_name, SHARE_STRICT_LOCKING) == 0) {
214 return lp_strict_locking(s, lp_default_service(lp_ctx));
217 if (strcmp(opt_name, SHARE_OPLOCKS) == 0) {
218 return lp_oplocks(s, lp_default_service(lp_ctx));
221 if (strcmp(opt_name, SHARE_STRICT_SYNC) == 0) {
222 return lp_strict_sync(s, lp_default_service(lp_ctx));
225 if (strcmp(opt_name, SHARE_MSDFS_ROOT) == 0) {
226 return lp_msdfs_root(s, lp_default_service(lp_ctx));
229 if (strcmp(opt_name, SHARE_CI_FILESYSTEM) == 0) {
230 return lp_ci_filesystem(s, lp_default_service(lp_ctx));
233 DEBUG(0,("request for unknown share bool option '%s'\n",
234 opt_name));
236 return defval;
239 static const char **sclassic_string_list_option(TALLOC_CTX *mem_ctx, struct share_config *scfg, const char *opt_name)
241 struct loadparm_service *s = talloc_get_type(scfg->opaque,
242 struct loadparm_service);
243 struct loadparm_context *lp_ctx = talloc_get_type(scfg->ctx->priv_data,
244 struct loadparm_context);
245 char *parm, *val;
246 const char **ret;
248 if (strchr(opt_name, ':')) {
249 parm = talloc_strdup(scfg, opt_name);
250 if (!parm) {
251 return NULL;
253 val = strchr(parm, ':');
254 *val = '\0';
255 val++;
257 ret = lp_parm_string_list(mem_ctx, lp_ctx, s, parm, val, ",;");
258 talloc_free(parm);
259 return ret;
262 if (strcmp(opt_name, SHARE_HOSTS_ALLOW) == 0) {
263 return lp_hostsallow(s, lp_default_service(lp_ctx));
266 if (strcmp(opt_name, SHARE_HOSTS_DENY) == 0) {
267 return lp_hostsdeny(s, lp_default_service(lp_ctx));
270 if (strcmp(opt_name, SHARE_NTVFS_HANDLER) == 0) {
271 return lp_ntvfs_handler(s, lp_default_service(lp_ctx));
274 DEBUG(0,("request for unknown share list option '%s'\n",
275 opt_name));
277 return NULL;
280 static NTSTATUS sclassic_list_all(TALLOC_CTX *mem_ctx,
281 struct share_context *ctx,
282 int *count,
283 const char ***names)
285 int i;
286 int num_services;
287 const char **n;
289 num_services = lp_numservices((struct loadparm_context *)ctx->priv_data);
291 n = talloc_array(mem_ctx, const char *, num_services);
292 if (!n) {
293 DEBUG(0,("ERROR: Out of memory!\n"));
294 return NT_STATUS_NO_MEMORY;
297 for (i = 0; i < num_services; i++) {
298 n[i] = talloc_strdup(n, lp_servicename(lp_servicebynum((struct loadparm_context *)ctx->priv_data, i)));
299 if (!n[i]) {
300 DEBUG(0,("ERROR: Out of memory!\n"));
301 talloc_free(n);
302 return NT_STATUS_NO_MEMORY;
306 *names = n;
307 *count = num_services;
309 return NT_STATUS_OK;
312 static NTSTATUS sclassic_get_config(TALLOC_CTX *mem_ctx,
313 struct share_context *ctx,
314 const char *name,
315 struct share_config **scfg)
317 struct share_config *s;
318 struct loadparm_service *service;
320 service = lp_service((struct loadparm_context *)ctx->priv_data, name);
322 if (service == NULL) {
323 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
326 s = talloc(mem_ctx, struct share_config);
327 if (!s) {
328 DEBUG(0,("ERROR: Out of memory!\n"));
329 return NT_STATUS_NO_MEMORY;
332 s->name = talloc_strdup(s, lp_servicename(service));
333 if (!s->name) {
334 DEBUG(0,("ERROR: Out of memory!\n"));
335 talloc_free(s);
336 return NT_STATUS_NO_MEMORY;
339 s->opaque = (void *)service;
340 s->ctx = ctx;
342 *scfg = s;
344 return NT_STATUS_OK;
347 static const struct share_ops ops = {
348 .name = "classic",
349 .init = sclassic_init,
350 .string_option = sclassic_string_option,
351 .int_option = sclassic_int_option,
352 .bool_option = sclassic_bool_option,
353 .string_list_option = sclassic_string_list_option,
354 .list_all = sclassic_list_all,
355 .get_config = sclassic_get_config
358 NTSTATUS share_classic_init(void)
360 return share_register(&ops);