summaryrefslogtreecommitdiff
path: root/source4/param/share_classic.c
blob: 3d5bef91e1784ef572da402fed0c49435608f357 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
/* 
   Unix SMB/CIFS implementation.
   
   Classic file based shares configuration
   
   Copyright (C) Simo Sorce	2006
   
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.
   
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   
   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "includes.h"
#include "param/share.h"
#include "param/param.h"

NTSTATUS share_classic_init(void);

static NTSTATUS sclassic_init(TALLOC_CTX *mem_ctx, 
			      const struct share_ops *ops, 
			      struct tevent_context *event_ctx,
			      struct loadparm_context *lp_ctx,
			      struct share_context **ctx)
{
	*ctx = talloc(mem_ctx, struct share_context);
	if (!*ctx) {
		DEBUG(0, ("ERROR: Out of memory!\n"));
		return NT_STATUS_NO_MEMORY;
	}

	(*ctx)->ops = ops;
	(*ctx)->priv_data = lp_ctx;

	return NT_STATUS_OK;
}

static const char *sclassic_string_option(struct share_config *scfg, 
					  const char *opt_name, 
					  const char *defval)
{
	struct loadparm_service *s = talloc_get_type(scfg->opaque, 
						     struct loadparm_service);
	struct loadparm_context *lp_ctx = talloc_get_type(scfg->ctx->priv_data,
							  struct loadparm_context);
	char *parm, *val;
	const char *ret;

	if (strchr(opt_name, ':')) {
		parm = talloc_strdup(scfg, opt_name);
		if (!parm) {
			return NULL;
		}
		val = strchr(parm, ':');
		*val = '\0';
		val++;

		ret = lpcfg_parm_string(lp_ctx, s, parm, val);
		if (!ret) {
			ret = defval;
		}
		talloc_free(parm);
		return ret;
	}

	if (strcmp(opt_name, SHARE_NAME) == 0) {
		return scfg->name;
	}

	if (strcmp(opt_name, SHARE_PATH) == 0) {
		return lpcfg_pathname(s, lpcfg_default_service(lp_ctx));
	}

	if (strcmp(opt_name, SHARE_COMMENT) == 0) {
		return lpcfg_comment(s, lpcfg_default_service(lp_ctx));
	}

	if (strcmp(opt_name, SHARE_VOLUME) == 0) {
		return volume_label(s, lpcfg_default_service(lp_ctx));
	}

	if (strcmp(opt_name, SHARE_TYPE) == 0) {
		if (lpcfg_print_ok(s, lpcfg_default_service(lp_ctx))) {
			return "PRINTER";
		}
		if (strcmp("NTFS", lpcfg_fstype(s, lpcfg_default_service(lp_ctx))) == 0) {
			return "DISK";
		}
		return lpcfg_fstype(s, lpcfg_default_service(lp_ctx));
	}

	if (strcmp(opt_name, SHARE_PASSWORD) == 0) {
		return defval;
	}

	DEBUG(0,("request for unknown share string option '%s'\n",
		 opt_name));

	return defval;
}

static int sclassic_int_option(struct share_config *scfg, const char *opt_name, int defval)
{
	struct loadparm_service *s = talloc_get_type(scfg->opaque, 
						     struct loadparm_service);
	struct loadparm_context *lp_ctx = talloc_get_type(scfg->ctx->priv_data,
							  struct loadparm_context);
	char *parm, *val;
	int ret;

	if (strchr(opt_name, ':')) {
		parm = talloc_strdup(scfg, opt_name);
		if (!parm) {
			return -1;
		}
		val = strchr(parm, ':');
		*val = '\0';
		val++;

		ret = lpcfg_parm_int(lp_ctx, s, parm, val, defval);
		if (!ret) {
			ret = defval;
		}
		talloc_free(parm);
		return ret;
	}

	if (strcmp(opt_name, SHARE_CSC_POLICY) == 0) {
		return lpcfg_csc_policy(s, lpcfg_default_service(lp_ctx));
	}

	if (strcmp(opt_name, SHARE_MAX_CONNECTIONS) == 0) {
		return lpcfg_max_connections(s, lpcfg_default_service(lp_ctx));
	}

	if (strcmp(opt_name, SHARE_CREATE_MASK) == 0) {
		return lpcfg_create_mask(s, lpcfg_default_service(lp_ctx));
	}

	if (strcmp(opt_name, SHARE_DIR_MASK) == 0) {
		return lpcfg_dir_mask(s, lpcfg_default_service(lp_ctx));
	}

	if (strcmp(opt_name, SHARE_FORCE_DIR_MODE) == 0) {
		return lpcfg_force_dir_mode(s, lpcfg_default_service(lp_ctx));
	}

	if (strcmp(opt_name, SHARE_FORCE_CREATE_MODE) == 0) {
		return lpcfg_force_create_mode(s, lpcfg_default_service(lp_ctx));
	}


	DEBUG(0,("request for unknown share int option '%s'\n",
		 opt_name));

	return defval;
}

static bool sclassic_bool_option(struct share_config *scfg, const char *opt_name, 
			  bool defval)
{
	struct loadparm_service *s = talloc_get_type(scfg->opaque, 
						     struct loadparm_service);
	struct loadparm_context *lp_ctx = talloc_get_type(scfg->ctx->priv_data,
							  struct loadparm_context);
	char *parm, *val;
	bool ret;

	if (strchr(opt_name, ':')) {
		parm = talloc_strdup(scfg, opt_name);
		if(!parm) {
			return false;
		}
		val = strchr(parm, ':');
		*val = '\0';
		val++;

		ret = lpcfg_parm_bool(lp_ctx, s, parm, val, defval);
		talloc_free(parm);
		return ret;
	}

	if (strcmp(opt_name, SHARE_AVAILABLE) == 0) {
		return s != NULL;
	}

	if (strcmp(opt_name, SHARE_BROWSEABLE) == 0) {
		return lpcfg_browseable(s, lpcfg_default_service(lp_ctx));
	}

	if (strcmp(opt_name, SHARE_READONLY) == 0) {
		return lpcfg_readonly(s, lpcfg_default_service(lp_ctx));
	}

	if (strcmp(opt_name, SHARE_MAP_SYSTEM) == 0) {
		return lpcfg_map_system(s, lpcfg_default_service(lp_ctx));
	}

	if (strcmp(opt_name, SHARE_MAP_HIDDEN) == 0) {
		return lpcfg_map_hidden(s, lpcfg_default_service(lp_ctx));
	}

	if (strcmp(opt_name, SHARE_MAP_ARCHIVE) == 0) {
		return lpcfg_map_archive(s, lpcfg_default_service(lp_ctx));
	}

	if (strcmp(opt_name, SHARE_STRICT_LOCKING) == 0) {
		return lpcfg_strict_locking(s, lpcfg_default_service(lp_ctx));
	}

	if (strcmp(opt_name, SHARE_OPLOCKS) == 0) {
		return lpcfg_oplocks(s, lpcfg_default_service(lp_ctx));
	}

	if (strcmp(opt_name, SHARE_STRICT_SYNC) == 0) {
		return lpcfg_strict_sync(s, lpcfg_default_service(lp_ctx));
	}

	if (strcmp(opt_name, SHARE_MSDFS_ROOT) == 0) {
		return lpcfg_msdfs_root(s, lpcfg_default_service(lp_ctx));
	}

	if (strcmp(opt_name, SHARE_CI_FILESYSTEM) == 0) {
		return lpcfg_ci_filesystem(s, lpcfg_default_service(lp_ctx));
	}

	DEBUG(0,("request for unknown share bool option '%s'\n",
		 opt_name));

	return defval;
}

static const char **sclassic_string_list_option(TALLOC_CTX *mem_ctx, struct share_config *scfg, const char *opt_name)
{
	struct loadparm_service *s = talloc_get_type(scfg->opaque, 
						     struct loadparm_service);
	struct loadparm_context *lp_ctx = talloc_get_type(scfg->ctx->priv_data,
							  struct loadparm_context);
	char *parm, *val;
	const char **ret;

	if (strchr(opt_name, ':')) {
		parm = talloc_strdup(scfg, opt_name);
		if (!parm) {
			return NULL;
		}
		val = strchr(parm, ':');
		*val = '\0';
		val++;

		ret = lpcfg_parm_string_list(mem_ctx, lp_ctx, s, parm, val, ",;");
		talloc_free(parm);
		return ret;
	}

	if (strcmp(opt_name, SHARE_HOSTS_ALLOW) == 0) {
		return lpcfg_hostsallow(s, lpcfg_default_service(lp_ctx));
	}

	if (strcmp(opt_name, SHARE_HOSTS_DENY) == 0) {
		return lpcfg_hostsdeny(s, lpcfg_default_service(lp_ctx));
	}

	if (strcmp(opt_name, SHARE_NTVFS_HANDLER) == 0) {
		return lpcfg_ntvfs_handler(s, lpcfg_default_service(lp_ctx));
	}

	DEBUG(0,("request for unknown share list option '%s'\n",
		 opt_name));

	return NULL;
}

static NTSTATUS sclassic_list_all(TALLOC_CTX *mem_ctx,
				  struct share_context *ctx,
				  int *count,
				  const char ***names)
{
	int i;
	int num_services;
	const char **n;
       
	num_services = lpcfg_numservices((struct loadparm_context *)ctx->priv_data);

	n = talloc_array(mem_ctx, const char *, num_services);
	if (!n) {
		DEBUG(0,("ERROR: Out of memory!\n"));
		return NT_STATUS_NO_MEMORY;
	}

	for (i = 0; i < num_services; i++) {
		n[i] = talloc_strdup(n, lpcfg_servicename(lpcfg_servicebynum((struct loadparm_context *)ctx->priv_data, i)));
		if (!n[i]) {
			DEBUG(0,("ERROR: Out of memory!\n"));
			talloc_free(n);
			return NT_STATUS_NO_MEMORY;
		}
	}

	*names = n;
	*count = num_services;

	return NT_STATUS_OK;
}

static NTSTATUS sclassic_get_config(TALLOC_CTX *mem_ctx,
				    struct share_context *ctx,
				    const char *name,
				    struct share_config **scfg)
{
	struct share_config *s;
	struct loadparm_service *service;

	service = lpcfg_service((struct loadparm_context *)ctx->priv_data, name);

	if (service == NULL) {
		return NT_STATUS_OBJECT_NAME_NOT_FOUND;
	}

	s = talloc(mem_ctx, struct share_config);
	if (!s) {
		DEBUG(0,("ERROR: Out of memory!\n"));
		return NT_STATUS_NO_MEMORY;
	}

	s->name = talloc_strdup(s, lpcfg_servicename(service));
	if (!s->name) {
		DEBUG(0,("ERROR: Out of memory!\n"));
		talloc_free(s);
		return NT_STATUS_NO_MEMORY;
	}

	s->opaque = (void *)service;
	s->ctx = ctx;
	
	*scfg = s;

	return NT_STATUS_OK;
}

static const struct share_ops ops = {
	.name = "classic",
	.init = sclassic_init,
	.string_option = sclassic_string_option,
	.int_option = sclassic_int_option,
	.bool_option = sclassic_bool_option,
	.string_list_option = sclassic_string_list_option,
	.list_all = sclassic_list_all,
	.get_config = sclassic_get_config
};

NTSTATUS share_classic_init(void)
{
	return share_register(&ops);
}