r24915: Try to quiet down this warning - the 'classic' share code doesn't
[kai/samba.git] / source4 / param / share_classic.c
1 /* 
2    Unix SMB/CIFS implementation.
3    
4    Classic file based services configuration
5    
6    Copyright (C) Simo Sorce     2006
7    
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.
12    
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.
17    
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/>.
20 */
21
22 #include "includes.h"
23 #include "param/share.h"
24
25 struct sclassic_snum {
26         int snum;
27 };
28
29 static NTSTATUS sclassic_init(TALLOC_CTX *mem_ctx, const struct share_ops *ops, struct share_context **ctx)
30 {
31         *ctx = talloc(mem_ctx, struct share_context);
32         if (!*ctx) {
33                 DEBUG(0, ("ERROR: Out of memory!\n"));
34                 return NT_STATUS_NO_MEMORY;
35         }
36
37         (*ctx)->ops = ops;
38         (*ctx)->priv_data = NULL;
39
40         return NT_STATUS_OK;
41 }
42
43 static const char *sclassic_string_option(struct share_config *scfg, const char *opt_name, const char *defval)
44 {
45         struct sclassic_snum *s = talloc_get_type(scfg->opaque, struct sclassic_snum);
46         char *parm, *val;
47         const char *ret;
48
49         if (strchr(opt_name, ':')) {
50                 parm = talloc_strdup(scfg, opt_name);
51                 if (!parm) {
52                         return NULL;
53                 }
54                 val = strchr(parm, ':');
55                 *val = '\0';
56                 val++;
57
58                 ret = lp_parm_string(s->snum, parm, val);
59                 if (!ret) {
60                         ret = defval;
61                 }
62                 talloc_free(parm);
63                 return ret;
64         }
65
66         if (strcmp(opt_name, SHARE_NAME) == 0) {
67                 return scfg->name;
68         }
69
70         if (strcmp(opt_name, SHARE_PATH) == 0) {
71                 return lp_pathname(s->snum);
72         }
73
74         if (strcmp(opt_name, SHARE_COMMENT) == 0) {
75                 return lp_comment(s->snum);
76         }
77
78         if (strcmp(opt_name, SHARE_VOLUME) == 0) {
79                 return volume_label(s->snum);
80         }
81
82         if (strcmp(opt_name, SHARE_TYPE) == 0) {
83                 if (lp_print_ok(s->snum)) {
84                         return "PRINTER";
85                 }
86                 if (strcmp("NTFS", lp_fstype(s->snum)) == 0) {
87                         return "DISK";
88                 }
89                 return lp_fstype(s->snum);
90         }
91
92         if (strcmp(opt_name, SHARE_PASSWORD) == 0) {
93                 return defval;
94         }
95
96         DEBUG(0,("request for unknown share string option '%s'\n",
97                  opt_name));
98
99         return defval;
100 }
101
102 int sclassic_int_option(struct share_config *scfg, const char *opt_name, int defval)
103 {
104         struct sclassic_snum *s = talloc_get_type(scfg->opaque, struct sclassic_snum);
105         char *parm, *val;
106         int ret;
107
108         if (strchr(opt_name, ':')) {
109                 parm = talloc_strdup(scfg, opt_name);
110                 if (!parm) {
111                         return -1;
112                 }
113                 val = strchr(parm, ':');
114                 *val = '\0';
115                 val++;
116
117                 ret = lp_parm_int(s->snum, parm, val, defval);
118                 if (!ret) {
119                         ret = defval;
120                 }
121                 talloc_free(parm);
122                 return ret;
123         }
124
125         if (strcmp(opt_name, SHARE_CSC_POLICY) == 0) {
126                 return lp_csc_policy(s->snum);
127         }
128
129         if (strcmp(opt_name, SHARE_MAX_CONNECTIONS) == 0) {
130                 return lp_max_connections(s->snum);
131         }
132
133         if (strcmp(opt_name, SHARE_CREATE_MASK) == 0) {
134                 return lp_create_mask(s->snum);
135         }
136
137         if (strcmp(opt_name, SHARE_DIR_MASK) == 0) {
138                 return lp_dir_mask(s->snum);
139         }
140
141         if (strcmp(opt_name, SHARE_FORCE_DIR_MODE) == 0) {
142                 return lp_force_dir_mode(s->snum);
143         }
144
145         if (strcmp(opt_name, SHARE_FORCE_CREATE_MODE) == 0) {
146                 return lp_force_create_mode(s->snum);
147         }
148
149
150         DEBUG(0,("request for unknown share int option '%s'\n",
151                  opt_name));
152
153         return defval;
154 }
155
156 BOOL sclassic_bool_option(struct share_config *scfg, const char *opt_name, BOOL defval)
157 {
158         struct sclassic_snum *s = talloc_get_type(scfg->opaque, struct sclassic_snum);
159         char *parm, *val;
160         BOOL ret;
161
162         if (strchr(opt_name, ':')) {
163                 parm = talloc_strdup(scfg, opt_name);
164                 if(!parm) {
165                         return False;
166                 }
167                 val = strchr(parm, ':');
168                 *val = '\0';
169                 val++;
170
171                 ret = lp_parm_bool(s->snum, parm, val, defval);
172                 talloc_free(parm);
173                 return ret;
174         }
175
176         if (strcmp(opt_name, SHARE_AVAILABLE) == 0) {
177                 return lp_snum_ok(s->snum);
178         }
179
180         if (strcmp(opt_name, SHARE_BROWSEABLE) == 0) {
181                 return lp_browseable(s->snum);
182         }
183
184         if (strcmp(opt_name, SHARE_READONLY) == 0) {
185                 return lp_readonly(s->snum);
186         }
187
188         if (strcmp(opt_name, SHARE_MAP_SYSTEM) == 0) {
189                 return lp_map_system(s->snum);
190         }
191
192         if (strcmp(opt_name, SHARE_MAP_HIDDEN) == 0) {
193                 return lp_map_hidden(s->snum);
194         }
195
196         if (strcmp(opt_name, SHARE_MAP_ARCHIVE) == 0) {
197                 return lp_map_archive(s->snum);
198         }
199
200         if (strcmp(opt_name, SHARE_STRICT_LOCKING) == 0) {
201                 return lp_strict_locking(s->snum);
202         }
203
204         if (strcmp(opt_name, SHARE_STRICT_SYNC) == 0) {
205                 return lp_strict_sync(s->snum);
206         }
207
208         if (strcmp(opt_name, SHARE_MSDFS_ROOT) == 0) {
209                 return lp_msdfs_root(s->snum);
210         }
211
212         if (strcmp(opt_name, SHARE_CI_FILESYSTEM) == 0) {
213                 return lp_ci_filesystem(s->snum);
214         }
215
216         DEBUG(0,("request for unknown share bool option '%s'\n",
217                  opt_name));
218
219         return defval;
220 }
221
222 const char **sclassic_string_list_option(TALLOC_CTX *mem_ctx, struct share_config *scfg, const char *opt_name)
223 {
224         struct sclassic_snum *s = talloc_get_type(scfg->opaque, struct sclassic_snum);
225         char *parm, *val;
226         const char **ret;
227
228         if (strchr(opt_name, ':')) {
229                 parm = talloc_strdup(scfg, opt_name);
230                 if (!parm) {
231                         return NULL;
232                 }
233                 val = strchr(parm, ':');
234                 *val = '\0';
235                 val++;
236
237                 ret = lp_parm_string_list(s->snum, parm, val, ",;");
238                 talloc_free(parm);
239                 return ret;
240         }
241
242         if (strcmp(opt_name, SHARE_HOSTS_ALLOW) == 0) {
243                 return lp_hostsallow(s->snum);
244         }
245
246         if (strcmp(opt_name, SHARE_HOSTS_DENY) == 0) {
247                 return lp_hostsdeny(s->snum);
248         }
249
250         if (strcmp(opt_name, SHARE_NTVFS_HANDLER) == 0) {
251                 return lp_ntvfs_handler(s->snum);
252         }
253
254         DEBUG(0,("request for unknown share list option '%s'\n",
255                  opt_name));
256
257         return NULL;
258 }
259
260 NTSTATUS sclassic_list_all(TALLOC_CTX *mem_ctx,
261                                      struct share_context *ctx,
262                                      int *count,
263                                      const char ***names)
264 {
265         int i;
266         int num_services;
267         const char **n;
268        
269         num_services = lp_numservices();
270
271         n = talloc_array(mem_ctx, const char *, num_services);
272         if (!n) {
273                 DEBUG(0,("ERROR: Out of memory!\n"));
274                 return NT_STATUS_NO_MEMORY;
275         }
276
277         for (i = 0; i < num_services; i++) {
278                 n[i] = talloc_strdup(n, lp_servicename(i));
279                 if (!n[i]) {
280                         DEBUG(0,("ERROR: Out of memory!\n"));
281                         talloc_free(n);
282                         return NT_STATUS_NO_MEMORY;
283                 }
284         }
285
286         *names = n;
287         *count = num_services;
288
289         return NT_STATUS_OK;
290 }
291
292 NTSTATUS sclassic_get_config(TALLOC_CTX *mem_ctx,
293                              struct share_context *ctx,
294                              const char *name,
295                              struct share_config **scfg)
296 {
297         int i, snum;
298         struct share_config *s;
299         struct sclassic_snum *scnum;
300
301         snum = -1;
302         for (i = 0; i < lp_numservices(); i++) {
303                 if (strcasecmp_m(name, lp_servicename(i)) == 0) {
304                         snum = i;
305                         break;
306                 }
307         }
308
309         if (snum < 0) {
310                 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
311         }
312
313         s = talloc(mem_ctx, struct share_config);
314         if (!s) {
315                 DEBUG(0,("ERROR: Out of memory!\n"));
316                 return NT_STATUS_NO_MEMORY;
317         }
318
319         s->name = talloc_strdup(s, lp_servicename(snum));
320         if (!s->name) {
321                 DEBUG(0,("ERROR: Out of memory!\n"));
322                 talloc_free(s);
323                 return NT_STATUS_NO_MEMORY;
324         }
325
326         scnum = talloc(s, struct sclassic_snum);
327         if (!scnum) {
328                 DEBUG(0,("ERROR: Out of memory!\n"));
329                 talloc_free(s);
330                 return NT_STATUS_NO_MEMORY;
331         }
332         scnum->snum = snum;
333
334         s->opaque = (void *)scnum;
335         s->ctx = ctx;
336         
337         *scfg = s;
338
339         return NT_STATUS_OK;
340 }
341
342 NTSTATUS share_classic_init(void)
343 {
344         static struct share_ops ops = {
345                 .name = "classic",
346                 .init = sclassic_init,
347                 .string_option = sclassic_string_option,
348                 .int_option = sclassic_int_option,
349                 .bool_option = sclassic_bool_option,
350                 .string_list_option = sclassic_string_list_option,
351                 .list_all = sclassic_list_all,
352                 .get_config = sclassic_get_config
353         };
354
355         return share_register(&ops);
356 }
357