1 | /*
|
---|
2 | * Samba Unix/Linux SMB client library
|
---|
3 | * Distributed SMB/CIFS Server Management Utility
|
---|
4 | * Local configuration interface
|
---|
5 | * Copyright (C) Michael Adam 2007-2008
|
---|
6 | *
|
---|
7 | * This program is free software; you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation; either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * This program is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with this program; if not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 |
|
---|
21 | /*
|
---|
22 | * This is an interface to Samba's configuration as made available
|
---|
23 | * by the libsmbconf interface (source/lib/smbconf/smbconf.c).
|
---|
24 | *
|
---|
25 | * This currently supports local interaction with the configuration
|
---|
26 | * stored in the registry. But other backends and remote access via
|
---|
27 | * rpc might get implemented in the future.
|
---|
28 | */
|
---|
29 |
|
---|
30 | #include "includes.h"
|
---|
31 | #include "utils/net.h"
|
---|
32 |
|
---|
33 | /**********************************************************************
|
---|
34 | *
|
---|
35 | * usage functions
|
---|
36 | *
|
---|
37 | **********************************************************************/
|
---|
38 |
|
---|
39 | static int net_conf_list_usage(struct net_context *c, int argc,
|
---|
40 | const char **argv)
|
---|
41 | {
|
---|
42 | d_printf("%s net conf list\n", _("Usage:"));
|
---|
43 | return -1;
|
---|
44 | }
|
---|
45 |
|
---|
46 | static int net_conf_import_usage(struct net_context *c, int argc,
|
---|
47 | const char**argv)
|
---|
48 | {
|
---|
49 | d_printf("%s\n%s",
|
---|
50 | _("Usage:"),
|
---|
51 | _(" net conf import [--test|-T] <filename> "
|
---|
52 | "[<servicename>]\n"
|
---|
53 | "\t[--test|-T] testmode - do not act, just print "
|
---|
54 | "what would be done\n"
|
---|
55 | "\t<servicename> only import service <servicename>, "
|
---|
56 | "ignore the rest\n"));
|
---|
57 | return -1;
|
---|
58 | }
|
---|
59 |
|
---|
60 | static int net_conf_listshares_usage(struct net_context *c, int argc,
|
---|
61 | const char **argv)
|
---|
62 | {
|
---|
63 | d_printf("%s\nnet conf listshares\n", _("Usage:"));
|
---|
64 | return -1;
|
---|
65 | }
|
---|
66 |
|
---|
67 | static int net_conf_drop_usage(struct net_context *c, int argc,
|
---|
68 | const char **argv)
|
---|
69 | {
|
---|
70 | d_printf("%s\nnet conf drop\n", _("Usage:"));
|
---|
71 | return -1;
|
---|
72 | }
|
---|
73 |
|
---|
74 | static int net_conf_showshare_usage(struct net_context *c, int argc,
|
---|
75 | const char **argv)
|
---|
76 | {
|
---|
77 | d_printf("%s\n%s",
|
---|
78 | _("Usage:"),
|
---|
79 | _("net conf showshare <sharename>\n"));
|
---|
80 | return -1;
|
---|
81 | }
|
---|
82 |
|
---|
83 | static int net_conf_addshare_usage(struct net_context *c, int argc,
|
---|
84 | const char **argv)
|
---|
85 | {
|
---|
86 | d_printf("%s\n%s",
|
---|
87 | _("Usage:"),
|
---|
88 | _(" net conf addshare <sharename> <path> "
|
---|
89 | "[writeable={y|N} [guest_ok={y|N} [<comment>]]\n"
|
---|
90 | "\t<sharename> the new share name.\n"
|
---|
91 | "\t<path> the path on the filesystem to export.\n"
|
---|
92 | "\twriteable={y|N} set \"writeable to \"yes\" or "
|
---|
93 | "\"no\" (default) on this share.\n"
|
---|
94 | "\tguest_ok={y|N} set \"guest ok\" to \"yes\" or "
|
---|
95 | "\"no\" (default) on this share.\n"
|
---|
96 | "\t<comment> optional comment for the new share.\n"));
|
---|
97 | return -1;
|
---|
98 | }
|
---|
99 |
|
---|
100 | static int net_conf_delshare_usage(struct net_context *c, int argc,
|
---|
101 | const char **argv)
|
---|
102 | {
|
---|
103 | d_printf("%s\n%s",
|
---|
104 | _("Usage:"),
|
---|
105 | _("net conf delshare <sharename>\n"));
|
---|
106 | return -1;
|
---|
107 | }
|
---|
108 |
|
---|
109 | static int net_conf_setparm_usage(struct net_context *c, int argc,
|
---|
110 | const char **argv)
|
---|
111 | {
|
---|
112 | d_printf("%s\n%s",
|
---|
113 | _("Usage:"),
|
---|
114 | _(" net conf setparm <section> <param> <value>\n"));
|
---|
115 | return -1;
|
---|
116 | }
|
---|
117 |
|
---|
118 | static int net_conf_getparm_usage(struct net_context *c, int argc,
|
---|
119 | const char **argv)
|
---|
120 | {
|
---|
121 | d_printf("%s\n%s",
|
---|
122 | _("Usage:"),
|
---|
123 | _(" net conf getparm <section> <param>\n"));
|
---|
124 | return -1;
|
---|
125 | }
|
---|
126 |
|
---|
127 | static int net_conf_delparm_usage(struct net_context *c, int argc,
|
---|
128 | const char **argv)
|
---|
129 | {
|
---|
130 | d_printf("%s\n%s",
|
---|
131 | _("Usage:"),
|
---|
132 | _(" net conf delparm <section> <param>\n"));
|
---|
133 | return -1;
|
---|
134 | }
|
---|
135 |
|
---|
136 | static int net_conf_getincludes_usage(struct net_context *c, int argc,
|
---|
137 | const char **argv)
|
---|
138 | {
|
---|
139 | d_printf("%s\n%s",
|
---|
140 | _("Usage:"),
|
---|
141 | _(" net conf getincludes <section>\n"));
|
---|
142 | return -1;
|
---|
143 | }
|
---|
144 |
|
---|
145 | static int net_conf_setincludes_usage(struct net_context *c, int argc,
|
---|
146 | const char **argv)
|
---|
147 | {
|
---|
148 | d_printf("%s\n%s",
|
---|
149 | _("Usage:"),
|
---|
150 | _(" net conf setincludes <section> [<filename>]*\n"));
|
---|
151 | return -1;
|
---|
152 | }
|
---|
153 |
|
---|
154 | static int net_conf_delincludes_usage(struct net_context *c, int argc,
|
---|
155 | const char **argv)
|
---|
156 | {
|
---|
157 | d_printf("%s\n%s",
|
---|
158 | _("Usage:"),
|
---|
159 | _(" net conf delincludes <section>\n"));
|
---|
160 | return -1;
|
---|
161 | }
|
---|
162 |
|
---|
163 |
|
---|
164 | /**********************************************************************
|
---|
165 | *
|
---|
166 | * Helper functions
|
---|
167 | *
|
---|
168 | **********************************************************************/
|
---|
169 |
|
---|
170 | /**
|
---|
171 | * This functions process a service previously loaded with libsmbconf.
|
---|
172 | */
|
---|
173 | static WERROR import_process_service(struct net_context *c,
|
---|
174 | struct smbconf_ctx *conf_ctx,
|
---|
175 | struct smbconf_service *service)
|
---|
176 | {
|
---|
177 | uint32_t idx;
|
---|
178 | WERROR werr = WERR_OK;
|
---|
179 | uint32_t num_includes = 0;
|
---|
180 | char **includes = NULL;
|
---|
181 | TALLOC_CTX *mem_ctx = talloc_stackframe();
|
---|
182 |
|
---|
183 | if (c->opt_testmode) {
|
---|
184 | const char *indent = "";
|
---|
185 | if (service->name != NULL) {
|
---|
186 | d_printf("[%s]\n", service->name);
|
---|
187 | indent = "\t";
|
---|
188 | }
|
---|
189 | for (idx = 0; idx < service->num_params; idx++) {
|
---|
190 | d_printf("%s%s = %s\n", indent,
|
---|
191 | service->param_names[idx],
|
---|
192 | service->param_values[idx]);
|
---|
193 | }
|
---|
194 | d_printf("\n");
|
---|
195 | goto done;
|
---|
196 | }
|
---|
197 |
|
---|
198 | if (smbconf_share_exists(conf_ctx, service->name)) {
|
---|
199 | werr = smbconf_delete_share(conf_ctx, service->name);
|
---|
200 | if (!W_ERROR_IS_OK(werr)) {
|
---|
201 | goto done;
|
---|
202 | }
|
---|
203 | }
|
---|
204 | werr = smbconf_create_share(conf_ctx, service->name);
|
---|
205 | if (!W_ERROR_IS_OK(werr)) {
|
---|
206 | goto done;
|
---|
207 | }
|
---|
208 |
|
---|
209 | for (idx = 0; idx < service->num_params; idx ++) {
|
---|
210 | if (strequal(service->param_names[idx], "include")) {
|
---|
211 | includes = TALLOC_REALLOC_ARRAY(mem_ctx,
|
---|
212 | includes,
|
---|
213 | char *,
|
---|
214 | num_includes+1);
|
---|
215 | if (includes == NULL) {
|
---|
216 | werr = WERR_NOMEM;
|
---|
217 | goto done;
|
---|
218 | }
|
---|
219 | includes[num_includes] = talloc_strdup(includes,
|
---|
220 | service->param_values[idx]);
|
---|
221 | if (includes[num_includes] == NULL) {
|
---|
222 | werr = WERR_NOMEM;
|
---|
223 | goto done;
|
---|
224 | }
|
---|
225 | num_includes++;
|
---|
226 | } else {
|
---|
227 | werr = smbconf_set_parameter(conf_ctx,
|
---|
228 | service->name,
|
---|
229 | service->param_names[idx],
|
---|
230 | service->param_values[idx]);
|
---|
231 | if (!W_ERROR_IS_OK(werr)) {
|
---|
232 | goto done;
|
---|
233 | }
|
---|
234 | }
|
---|
235 | }
|
---|
236 |
|
---|
237 | werr = smbconf_set_includes(conf_ctx, service->name, num_includes,
|
---|
238 | (const char **)includes);
|
---|
239 |
|
---|
240 | done:
|
---|
241 | TALLOC_FREE(mem_ctx);
|
---|
242 | return werr;
|
---|
243 | }
|
---|
244 |
|
---|
245 |
|
---|
246 | /**********************************************************************
|
---|
247 | *
|
---|
248 | * the main conf functions
|
---|
249 | *
|
---|
250 | **********************************************************************/
|
---|
251 |
|
---|
252 | static int net_conf_list(struct net_context *c, struct smbconf_ctx *conf_ctx,
|
---|
253 | int argc, const char **argv)
|
---|
254 | {
|
---|
255 | WERROR werr = WERR_OK;
|
---|
256 | int ret = -1;
|
---|
257 | TALLOC_CTX *mem_ctx;
|
---|
258 | uint32_t num_shares;
|
---|
259 | uint32_t share_count, param_count;
|
---|
260 | struct smbconf_service **shares = NULL;
|
---|
261 |
|
---|
262 | mem_ctx = talloc_stackframe();
|
---|
263 |
|
---|
264 | if (argc != 0 || c->display_usage) {
|
---|
265 | net_conf_list_usage(c, argc, argv);
|
---|
266 | goto done;
|
---|
267 | }
|
---|
268 |
|
---|
269 | werr = smbconf_get_config(conf_ctx, mem_ctx, &num_shares, &shares);
|
---|
270 | if (!W_ERROR_IS_OK(werr)) {
|
---|
271 | d_fprintf(stderr, _("Error getting config: %s\n"),
|
---|
272 | win_errstr(werr));
|
---|
273 | goto done;
|
---|
274 | }
|
---|
275 |
|
---|
276 | for (share_count = 0; share_count < num_shares; share_count++) {
|
---|
277 | const char *indent = "";
|
---|
278 | if (shares[share_count]->name != NULL) {
|
---|
279 | d_printf("[%s]\n", shares[share_count]->name);
|
---|
280 | indent = "\t";
|
---|
281 | }
|
---|
282 | for (param_count = 0;
|
---|
283 | param_count < shares[share_count]->num_params;
|
---|
284 | param_count++)
|
---|
285 | {
|
---|
286 | d_printf("%s%s = %s\n",
|
---|
287 | indent,
|
---|
288 | shares[share_count]->param_names[param_count],
|
---|
289 | shares[share_count]->param_values[param_count]);
|
---|
290 | }
|
---|
291 | d_printf("\n");
|
---|
292 | }
|
---|
293 |
|
---|
294 | ret = 0;
|
---|
295 |
|
---|
296 | done:
|
---|
297 | TALLOC_FREE(mem_ctx);
|
---|
298 | return ret;
|
---|
299 | }
|
---|
300 |
|
---|
301 | static int net_conf_import(struct net_context *c, struct smbconf_ctx *conf_ctx,
|
---|
302 | int argc, const char **argv)
|
---|
303 | {
|
---|
304 | int ret = -1;
|
---|
305 | const char *filename = NULL;
|
---|
306 | const char *servicename = NULL;
|
---|
307 | char *conf_source = NULL;
|
---|
308 | TALLOC_CTX *mem_ctx;
|
---|
309 | struct smbconf_ctx *txt_ctx;
|
---|
310 | WERROR werr;
|
---|
311 |
|
---|
312 | if (c->display_usage)
|
---|
313 | return net_conf_import_usage(c, argc, argv);
|
---|
314 |
|
---|
315 | mem_ctx = talloc_stackframe();
|
---|
316 |
|
---|
317 | switch (argc) {
|
---|
318 | case 0:
|
---|
319 | default:
|
---|
320 | net_conf_import_usage(c, argc, argv);
|
---|
321 | goto done;
|
---|
322 | case 2:
|
---|
323 | servicename = talloc_strdup(mem_ctx, argv[1]);
|
---|
324 | if (servicename == NULL) {
|
---|
325 | d_printf(_("error: out of memory!\n"));
|
---|
326 | goto done;
|
---|
327 | }
|
---|
328 | case 1:
|
---|
329 | filename = argv[0];
|
---|
330 | break;
|
---|
331 | }
|
---|
332 |
|
---|
333 | DEBUG(3,("net_conf_import: reading configuration from file %s.\n",
|
---|
334 | filename));
|
---|
335 |
|
---|
336 | conf_source = talloc_asprintf(mem_ctx, "file:%s", filename);
|
---|
337 | if (conf_source == NULL) {
|
---|
338 | d_printf(_("error: out of memory!\n"));
|
---|
339 | goto done;
|
---|
340 | }
|
---|
341 |
|
---|
342 | werr = smbconf_init(mem_ctx, &txt_ctx, conf_source);
|
---|
343 | if (!W_ERROR_IS_OK(werr)) {
|
---|
344 | d_printf(_("error loading file '%s': %s\n"), filename,
|
---|
345 | win_errstr(werr));
|
---|
346 | goto done;
|
---|
347 | }
|
---|
348 |
|
---|
349 | if (c->opt_testmode) {
|
---|
350 | d_printf(_("\nTEST MODE - "
|
---|
351 | "would import the following configuration:\n\n"));
|
---|
352 | }
|
---|
353 |
|
---|
354 | if (servicename != NULL) {
|
---|
355 | struct smbconf_service *service = NULL;
|
---|
356 |
|
---|
357 | werr = smbconf_get_share(txt_ctx, mem_ctx,
|
---|
358 | servicename,
|
---|
359 | &service);
|
---|
360 | if (!W_ERROR_IS_OK(werr)) {
|
---|
361 | goto cancel;
|
---|
362 | }
|
---|
363 |
|
---|
364 | werr = smbconf_transaction_start(conf_ctx);
|
---|
365 | if (!W_ERROR_IS_OK(werr)) {
|
---|
366 | d_printf(_("error starting transaction: %s\n"),
|
---|
367 | win_errstr(werr));
|
---|
368 | goto done;
|
---|
369 | }
|
---|
370 |
|
---|
371 | werr = import_process_service(c, conf_ctx, service);
|
---|
372 | if (!W_ERROR_IS_OK(werr)) {
|
---|
373 | goto cancel;
|
---|
374 | }
|
---|
375 | } else {
|
---|
376 | struct smbconf_service **services = NULL;
|
---|
377 | uint32_t num_shares, sidx;
|
---|
378 |
|
---|
379 | werr = smbconf_get_config(txt_ctx, mem_ctx,
|
---|
380 | &num_shares,
|
---|
381 | &services);
|
---|
382 | if (!W_ERROR_IS_OK(werr)) {
|
---|
383 | goto cancel;
|
---|
384 | }
|
---|
385 | if (!c->opt_testmode) {
|
---|
386 | werr = smbconf_drop(conf_ctx);
|
---|
387 | if (!W_ERROR_IS_OK(werr)) {
|
---|
388 | goto cancel;
|
---|
389 | }
|
---|
390 | }
|
---|
391 |
|
---|
392 | /*
|
---|
393 | * Wrap the importing of shares into a transaction,
|
---|
394 | * but only 100 at a time, in order to serve memory.
|
---|
395 | * The allocated memory accumulates across the actions
|
---|
396 | * within the transaction, and for me, some 1500
|
---|
397 | * imported shares, the MAX_TALLOC_SIZE of 256 MB
|
---|
398 | * was exceeded.
|
---|
399 | */
|
---|
400 | werr = smbconf_transaction_start(conf_ctx);
|
---|
401 | if (!W_ERROR_IS_OK(werr)) {
|
---|
402 | d_printf(_("error starting transaction: %s\n"),
|
---|
403 | win_errstr(werr));
|
---|
404 | goto done;
|
---|
405 | }
|
---|
406 |
|
---|
407 | for (sidx = 0; sidx < num_shares; sidx++) {
|
---|
408 | werr = import_process_service(c, conf_ctx,
|
---|
409 | services[sidx]);
|
---|
410 | if (!W_ERROR_IS_OK(werr)) {
|
---|
411 | goto cancel;
|
---|
412 | }
|
---|
413 |
|
---|
414 | if (sidx % 100) {
|
---|
415 | continue;
|
---|
416 | }
|
---|
417 |
|
---|
418 | werr = smbconf_transaction_commit(conf_ctx);
|
---|
419 | if (!W_ERROR_IS_OK(werr)) {
|
---|
420 | d_printf(_("error committing transaction: "
|
---|
421 | "%s\n"),
|
---|
422 | win_errstr(werr));
|
---|
423 | goto done;
|
---|
424 | }
|
---|
425 | werr = smbconf_transaction_start(conf_ctx);
|
---|
426 | if (!W_ERROR_IS_OK(werr)) {
|
---|
427 | d_printf(_("error starting transaction: %s\n"),
|
---|
428 | win_errstr(werr));
|
---|
429 | goto done;
|
---|
430 | }
|
---|
431 | }
|
---|
432 | }
|
---|
433 |
|
---|
434 | werr = smbconf_transaction_commit(conf_ctx);
|
---|
435 | if (!W_ERROR_IS_OK(werr)) {
|
---|
436 | d_printf(_("error committing transaction: %s\n"),
|
---|
437 | win_errstr(werr));
|
---|
438 | } else {
|
---|
439 | ret = 0;
|
---|
440 | }
|
---|
441 |
|
---|
442 | goto done;
|
---|
443 |
|
---|
444 | cancel:
|
---|
445 | werr = smbconf_transaction_cancel(conf_ctx);
|
---|
446 | if (!W_ERROR_IS_OK(werr)) {
|
---|
447 | d_printf(_("error cancelling transaction: %s\n"),
|
---|
448 | win_errstr(werr));
|
---|
449 | }
|
---|
450 |
|
---|
451 | done:
|
---|
452 | TALLOC_FREE(mem_ctx);
|
---|
453 | return ret;
|
---|
454 | }
|
---|
455 |
|
---|
456 | static int net_conf_listshares(struct net_context *c,
|
---|
457 | struct smbconf_ctx *conf_ctx, int argc,
|
---|
458 | const char **argv)
|
---|
459 | {
|
---|
460 | WERROR werr = WERR_OK;
|
---|
461 | int ret = -1;
|
---|
462 | uint32_t count, num_shares = 0;
|
---|
463 | char **share_names = NULL;
|
---|
464 | TALLOC_CTX *mem_ctx;
|
---|
465 |
|
---|
466 | mem_ctx = talloc_stackframe();
|
---|
467 |
|
---|
468 | if (argc != 0 || c->display_usage) {
|
---|
469 | net_conf_listshares_usage(c, argc, argv);
|
---|
470 | goto done;
|
---|
471 | }
|
---|
472 |
|
---|
473 | werr = smbconf_get_share_names(conf_ctx, mem_ctx, &num_shares,
|
---|
474 | &share_names);
|
---|
475 | if (!W_ERROR_IS_OK(werr)) {
|
---|
476 | goto done;
|
---|
477 | }
|
---|
478 |
|
---|
479 | for (count = 0; count < num_shares; count++)
|
---|
480 | {
|
---|
481 | d_printf("%s\n", share_names[count]);
|
---|
482 | }
|
---|
483 |
|
---|
484 | ret = 0;
|
---|
485 |
|
---|
486 | done:
|
---|
487 | TALLOC_FREE(mem_ctx);
|
---|
488 | return ret;
|
---|
489 | }
|
---|
490 |
|
---|
491 | static int net_conf_drop(struct net_context *c, struct smbconf_ctx *conf_ctx,
|
---|
492 | int argc, const char **argv)
|
---|
493 | {
|
---|
494 | int ret = -1;
|
---|
495 | WERROR werr;
|
---|
496 |
|
---|
497 | if (argc != 0 || c->display_usage) {
|
---|
498 | net_conf_drop_usage(c, argc, argv);
|
---|
499 | goto done;
|
---|
500 | }
|
---|
501 |
|
---|
502 | werr = smbconf_drop(conf_ctx);
|
---|
503 | if (!W_ERROR_IS_OK(werr)) {
|
---|
504 | d_fprintf(stderr, _("Error deleting configuration: %s\n"),
|
---|
505 | win_errstr(werr));
|
---|
506 | goto done;
|
---|
507 | }
|
---|
508 |
|
---|
509 | ret = 0;
|
---|
510 |
|
---|
511 | done:
|
---|
512 | return ret;
|
---|
513 | }
|
---|
514 |
|
---|
515 | static int net_conf_showshare(struct net_context *c,
|
---|
516 | struct smbconf_ctx *conf_ctx, int argc,
|
---|
517 | const char **argv)
|
---|
518 | {
|
---|
519 | int ret = -1;
|
---|
520 | WERROR werr = WERR_OK;
|
---|
521 | const char *sharename = NULL;
|
---|
522 | TALLOC_CTX *mem_ctx;
|
---|
523 | uint32_t count;
|
---|
524 | struct smbconf_service *service = NULL;
|
---|
525 |
|
---|
526 | mem_ctx = talloc_stackframe();
|
---|
527 |
|
---|
528 | if (argc != 1 || c->display_usage) {
|
---|
529 | net_conf_showshare_usage(c, argc, argv);
|
---|
530 | goto done;
|
---|
531 | }
|
---|
532 |
|
---|
533 | sharename = talloc_strdup(mem_ctx, argv[0]);
|
---|
534 | if (sharename == NULL) {
|
---|
535 | d_printf("error: out of memory!\n");
|
---|
536 | goto done;
|
---|
537 | }
|
---|
538 |
|
---|
539 | werr = smbconf_get_share(conf_ctx, mem_ctx, sharename, &service);
|
---|
540 | if (!W_ERROR_IS_OK(werr)) {
|
---|
541 | d_printf(_("error getting share parameters: %s\n"),
|
---|
542 | win_errstr(werr));
|
---|
543 | goto done;
|
---|
544 | }
|
---|
545 |
|
---|
546 | d_printf("[%s]\n", service->name);
|
---|
547 |
|
---|
548 | for (count = 0; count < service->num_params; count++) {
|
---|
549 | d_printf("\t%s = %s\n", service->param_names[count],
|
---|
550 | service->param_values[count]);
|
---|
551 | }
|
---|
552 |
|
---|
553 | ret = 0;
|
---|
554 |
|
---|
555 | done:
|
---|
556 | TALLOC_FREE(mem_ctx);
|
---|
557 | return ret;
|
---|
558 | }
|
---|
559 |
|
---|
560 | /**
|
---|
561 | * Add a share, with a couple of standard parameters, partly optional.
|
---|
562 | *
|
---|
563 | * This is a high level utility function of the net conf utility,
|
---|
564 | * not a direct frontend to the smbconf API.
|
---|
565 | */
|
---|
566 | static int net_conf_addshare(struct net_context *c,
|
---|
567 | struct smbconf_ctx *conf_ctx, int argc,
|
---|
568 | const char **argv)
|
---|
569 | {
|
---|
570 | int ret = -1;
|
---|
571 | WERROR werr = WERR_OK;
|
---|
572 | char *sharename = NULL;
|
---|
573 | const char *path = NULL;
|
---|
574 | const char *comment = NULL;
|
---|
575 | const char *guest_ok = "no";
|
---|
576 | const char *writeable = "no";
|
---|
577 | SMB_STRUCT_STAT sbuf;
|
---|
578 | TALLOC_CTX *mem_ctx = talloc_stackframe();
|
---|
579 |
|
---|
580 | if (c->display_usage) {
|
---|
581 | net_conf_addshare_usage(c, argc, argv);
|
---|
582 | ret = 0;
|
---|
583 | goto done;
|
---|
584 | }
|
---|
585 |
|
---|
586 | switch (argc) {
|
---|
587 | case 0:
|
---|
588 | case 1:
|
---|
589 | default:
|
---|
590 | net_conf_addshare_usage(c, argc, argv);
|
---|
591 | goto done;
|
---|
592 | case 5:
|
---|
593 | comment = argv[4];
|
---|
594 | case 4:
|
---|
595 | if (!strnequal(argv[3], "guest_ok=", 9)) {
|
---|
596 | net_conf_addshare_usage(c, argc, argv);
|
---|
597 | goto done;
|
---|
598 | }
|
---|
599 | switch (argv[3][9]) {
|
---|
600 | case 'y':
|
---|
601 | case 'Y':
|
---|
602 | guest_ok = "yes";
|
---|
603 | break;
|
---|
604 | case 'n':
|
---|
605 | case 'N':
|
---|
606 | guest_ok = "no";
|
---|
607 | break;
|
---|
608 | default:
|
---|
609 | net_conf_addshare_usage(c, argc, argv);
|
---|
610 | goto done;
|
---|
611 | }
|
---|
612 | case 3:
|
---|
613 | if (!strnequal(argv[2], "writeable=", 10)) {
|
---|
614 | net_conf_addshare_usage(c, argc, argv);
|
---|
615 | goto done;
|
---|
616 | }
|
---|
617 | switch (argv[2][10]) {
|
---|
618 | case 'y':
|
---|
619 | case 'Y':
|
---|
620 | writeable = "yes";
|
---|
621 | break;
|
---|
622 | case 'n':
|
---|
623 | case 'N':
|
---|
624 | writeable = "no";
|
---|
625 | break;
|
---|
626 | default:
|
---|
627 | net_conf_addshare_usage(c, argc, argv);
|
---|
628 | goto done;
|
---|
629 | }
|
---|
630 | case 2:
|
---|
631 | path = argv[1];
|
---|
632 | sharename = talloc_strdup(mem_ctx, argv[0]);
|
---|
633 | if (sharename == NULL) {
|
---|
634 | d_printf(_("error: out of memory!\n"));
|
---|
635 | goto done;
|
---|
636 | }
|
---|
637 |
|
---|
638 | break;
|
---|
639 | }
|
---|
640 |
|
---|
641 | /*
|
---|
642 | * validate arguments
|
---|
643 | */
|
---|
644 |
|
---|
645 | /* validate share name */
|
---|
646 |
|
---|
647 | if (!validate_net_name(sharename, INVALID_SHARENAME_CHARS,
|
---|
648 | strlen(sharename)))
|
---|
649 | {
|
---|
650 | d_fprintf(stderr, _("ERROR: share name %s contains "
|
---|
651 | "invalid characters (any of %s)\n"),
|
---|
652 | sharename, INVALID_SHARENAME_CHARS);
|
---|
653 | goto done;
|
---|
654 | }
|
---|
655 |
|
---|
656 | if (strequal(sharename, GLOBAL_NAME)) {
|
---|
657 | d_fprintf(stderr,
|
---|
658 | _("ERROR: 'global' is not a valid share name.\n"));
|
---|
659 | goto done;
|
---|
660 | }
|
---|
661 |
|
---|
662 | if (smbconf_share_exists(conf_ctx, sharename)) {
|
---|
663 | d_fprintf(stderr, _("ERROR: share %s already exists.\n"),
|
---|
664 | sharename);
|
---|
665 | goto done;
|
---|
666 | }
|
---|
667 |
|
---|
668 | /* validate path */
|
---|
669 |
|
---|
670 | if (path[0] != '/') {
|
---|
671 | d_fprintf(stderr,
|
---|
672 | _("Error: path '%s' is not an absolute path.\n"),
|
---|
673 | path);
|
---|
674 | goto done;
|
---|
675 | }
|
---|
676 |
|
---|
677 | if (sys_stat(path, &sbuf, false) != 0) {
|
---|
678 | d_fprintf(stderr,
|
---|
679 | _("ERROR: cannot stat path '%s' to ensure "
|
---|
680 | "this is a directory.\n"
|
---|
681 | "Error was '%s'.\n"),
|
---|
682 | path, strerror(errno));
|
---|
683 | goto done;
|
---|
684 | }
|
---|
685 |
|
---|
686 | if (!S_ISDIR(sbuf.st_ex_mode)) {
|
---|
687 | d_fprintf(stderr,
|
---|
688 | _("ERROR: path '%s' is not a directory.\n"),
|
---|
689 | path);
|
---|
690 | goto done;
|
---|
691 | }
|
---|
692 |
|
---|
693 | /*
|
---|
694 | * create the share
|
---|
695 | */
|
---|
696 |
|
---|
697 | werr = smbconf_create_share(conf_ctx, sharename);
|
---|
698 | if (!W_ERROR_IS_OK(werr)) {
|
---|
699 | d_fprintf(stderr, _("Error creating share %s: %s\n"),
|
---|
700 | sharename, win_errstr(werr));
|
---|
701 | goto done;
|
---|
702 | }
|
---|
703 |
|
---|
704 | /*
|
---|
705 | * fill the share with parameters
|
---|
706 | */
|
---|
707 |
|
---|
708 | werr = smbconf_set_parameter(conf_ctx, sharename, "path", path);
|
---|
709 | if (!W_ERROR_IS_OK(werr)) {
|
---|
710 | d_fprintf(stderr, _("Error setting parameter %s: %s\n"),
|
---|
711 | "path", win_errstr(werr));
|
---|
712 | goto done;
|
---|
713 | }
|
---|
714 |
|
---|
715 | if (comment != NULL) {
|
---|
716 | werr = smbconf_set_parameter(conf_ctx, sharename, "comment",
|
---|
717 | comment);
|
---|
718 | if (!W_ERROR_IS_OK(werr)) {
|
---|
719 | d_fprintf(stderr, _("Error setting parameter %s: %s\n"),
|
---|
720 | "comment", win_errstr(werr));
|
---|
721 | goto done;
|
---|
722 | }
|
---|
723 | }
|
---|
724 |
|
---|
725 | werr = smbconf_set_parameter(conf_ctx, sharename, "guest ok", guest_ok);
|
---|
726 | if (!W_ERROR_IS_OK(werr)) {
|
---|
727 | d_fprintf(stderr, _("Error setting parameter %s: %s\n"),
|
---|
728 | "'guest ok'", win_errstr(werr));
|
---|
729 | goto done;
|
---|
730 | }
|
---|
731 |
|
---|
732 | werr = smbconf_set_parameter(conf_ctx, sharename, "writeable",
|
---|
733 | writeable);
|
---|
734 | if (!W_ERROR_IS_OK(werr)) {
|
---|
735 | d_fprintf(stderr, _("Error setting parameter %s: %s\n"),
|
---|
736 | "writeable", win_errstr(werr));
|
---|
737 | goto done;
|
---|
738 | }
|
---|
739 |
|
---|
740 | ret = 0;
|
---|
741 |
|
---|
742 | done:
|
---|
743 | TALLOC_FREE(mem_ctx);
|
---|
744 | return ret;
|
---|
745 | }
|
---|
746 |
|
---|
747 | static int net_conf_delshare(struct net_context *c,
|
---|
748 | struct smbconf_ctx *conf_ctx, int argc,
|
---|
749 | const char **argv)
|
---|
750 | {
|
---|
751 | int ret = -1;
|
---|
752 | const char *sharename = NULL;
|
---|
753 | WERROR werr = WERR_OK;
|
---|
754 | TALLOC_CTX *mem_ctx = talloc_stackframe();
|
---|
755 |
|
---|
756 | if (argc != 1 || c->display_usage) {
|
---|
757 | net_conf_delshare_usage(c, argc, argv);
|
---|
758 | goto done;
|
---|
759 | }
|
---|
760 | sharename = talloc_strdup(mem_ctx, argv[0]);
|
---|
761 | if (sharename == NULL) {
|
---|
762 | d_printf(_("error: out of memory!\n"));
|
---|
763 | goto done;
|
---|
764 | }
|
---|
765 |
|
---|
766 | werr = smbconf_delete_share(conf_ctx, sharename);
|
---|
767 | if (!W_ERROR_IS_OK(werr)) {
|
---|
768 | d_fprintf(stderr, _("Error deleting share %s: %s\n"),
|
---|
769 | sharename, win_errstr(werr));
|
---|
770 | goto done;
|
---|
771 | }
|
---|
772 |
|
---|
773 | ret = 0;
|
---|
774 | done:
|
---|
775 | TALLOC_FREE(mem_ctx);
|
---|
776 | return ret;
|
---|
777 | }
|
---|
778 |
|
---|
779 | static int net_conf_setparm(struct net_context *c, struct smbconf_ctx *conf_ctx,
|
---|
780 | int argc, const char **argv)
|
---|
781 | {
|
---|
782 | int ret = -1;
|
---|
783 | WERROR werr = WERR_OK;
|
---|
784 | char *service = NULL;
|
---|
785 | char *param = NULL;
|
---|
786 | const char *value_str = NULL;
|
---|
787 | TALLOC_CTX *mem_ctx = talloc_stackframe();
|
---|
788 |
|
---|
789 | if (argc != 3 || c->display_usage) {
|
---|
790 | net_conf_setparm_usage(c, argc, argv);
|
---|
791 | goto done;
|
---|
792 | }
|
---|
793 | /*
|
---|
794 | * NULL service name means "dangling parameters" to libsmbconf.
|
---|
795 | * We use the empty string from the command line for this purpose.
|
---|
796 | */
|
---|
797 | if (strlen(argv[0]) != 0) {
|
---|
798 | service = talloc_strdup(mem_ctx, argv[0]);
|
---|
799 | if (service == NULL) {
|
---|
800 | d_printf(_("error: out of memory!\n"));
|
---|
801 | goto done;
|
---|
802 | }
|
---|
803 | }
|
---|
804 | param = strlower_talloc(mem_ctx, argv[1]);
|
---|
805 | if (param == NULL) {
|
---|
806 | d_printf(_("error: out of memory!\n"));
|
---|
807 | goto done;
|
---|
808 | }
|
---|
809 | value_str = argv[2];
|
---|
810 |
|
---|
811 | werr = smbconf_transaction_start(conf_ctx);
|
---|
812 | if (!W_ERROR_IS_OK(werr)) {
|
---|
813 | d_printf(_("error starting transaction: %s\n"),
|
---|
814 | win_errstr(werr));
|
---|
815 | goto done;
|
---|
816 | }
|
---|
817 |
|
---|
818 | if (!smbconf_share_exists(conf_ctx, service)) {
|
---|
819 | werr = smbconf_create_share(conf_ctx, service);
|
---|
820 | if (!W_ERROR_IS_OK(werr)) {
|
---|
821 | d_fprintf(stderr, _("Error creating share '%s': %s\n"),
|
---|
822 | service, win_errstr(werr));
|
---|
823 | goto cancel;
|
---|
824 | }
|
---|
825 | }
|
---|
826 |
|
---|
827 | werr = smbconf_set_parameter(conf_ctx, service, param, value_str);
|
---|
828 |
|
---|
829 | if (!W_ERROR_IS_OK(werr)) {
|
---|
830 | d_fprintf(stderr, _("Error setting value '%s': %s\n"),
|
---|
831 | param, win_errstr(werr));
|
---|
832 | goto cancel;
|
---|
833 | }
|
---|
834 |
|
---|
835 | werr = smbconf_transaction_commit(conf_ctx);
|
---|
836 | if (!W_ERROR_IS_OK(werr)) {
|
---|
837 | d_printf(_("error committing transaction: %s\n"),
|
---|
838 | win_errstr(werr));
|
---|
839 | } else {
|
---|
840 | ret = 0;
|
---|
841 | }
|
---|
842 |
|
---|
843 | goto done;
|
---|
844 |
|
---|
845 | cancel:
|
---|
846 | werr = smbconf_transaction_cancel(conf_ctx);
|
---|
847 | if (!W_ERROR_IS_OK(werr)) {
|
---|
848 | d_printf(_("error cancelling transaction: %s\n"),
|
---|
849 | win_errstr(werr));
|
---|
850 | }
|
---|
851 |
|
---|
852 | done:
|
---|
853 | TALLOC_FREE(mem_ctx);
|
---|
854 | return ret;
|
---|
855 | }
|
---|
856 |
|
---|
857 | static int net_conf_getparm(struct net_context *c, struct smbconf_ctx *conf_ctx,
|
---|
858 | int argc, const char **argv)
|
---|
859 | {
|
---|
860 | int ret = -1;
|
---|
861 | WERROR werr = WERR_OK;
|
---|
862 | char *service = NULL;
|
---|
863 | char *param = NULL;
|
---|
864 | char *valstr = NULL;
|
---|
865 | TALLOC_CTX *mem_ctx;
|
---|
866 |
|
---|
867 | mem_ctx = talloc_stackframe();
|
---|
868 |
|
---|
869 | if (argc != 2 || c->display_usage) {
|
---|
870 | net_conf_getparm_usage(c, argc, argv);
|
---|
871 | goto done;
|
---|
872 | }
|
---|
873 | /*
|
---|
874 | * NULL service name means "dangling parameters" to libsmbconf.
|
---|
875 | * We use the empty string from the command line for this purpose.
|
---|
876 | */
|
---|
877 | if (strlen(argv[0]) != 0) {
|
---|
878 | service = talloc_strdup(mem_ctx, argv[0]);
|
---|
879 | if (service == NULL) {
|
---|
880 | d_printf(_("error: out of memory!\n"));
|
---|
881 | goto done;
|
---|
882 | }
|
---|
883 | }
|
---|
884 | param = strlower_talloc(mem_ctx, argv[1]);
|
---|
885 | if (param == NULL) {
|
---|
886 | d_printf(_("error: out of memory!\n"));
|
---|
887 | goto done;
|
---|
888 | }
|
---|
889 |
|
---|
890 | werr = smbconf_get_parameter(conf_ctx, mem_ctx, service, param, &valstr);
|
---|
891 |
|
---|
892 | if (W_ERROR_EQUAL(werr, WERR_NO_SUCH_SERVICE)) {
|
---|
893 | d_fprintf(stderr,
|
---|
894 | _("Error: given service '%s' does not exist.\n"),
|
---|
895 | service);
|
---|
896 | goto done;
|
---|
897 | } else if (W_ERROR_EQUAL(werr, WERR_INVALID_PARAM)) {
|
---|
898 | d_fprintf(stderr,
|
---|
899 | _("Error: given parameter '%s' is not set.\n"),
|
---|
900 | param);
|
---|
901 | goto done;
|
---|
902 | } else if (!W_ERROR_IS_OK(werr)) {
|
---|
903 | d_fprintf(stderr, _("Error getting value '%s': %s.\n"),
|
---|
904 | param, win_errstr(werr));
|
---|
905 | goto done;
|
---|
906 | }
|
---|
907 |
|
---|
908 | d_printf("%s\n", valstr);
|
---|
909 |
|
---|
910 | ret = 0;
|
---|
911 | done:
|
---|
912 | TALLOC_FREE(mem_ctx);
|
---|
913 | return ret;
|
---|
914 | }
|
---|
915 |
|
---|
916 | static int net_conf_delparm(struct net_context *c, struct smbconf_ctx *conf_ctx,
|
---|
917 | int argc, const char **argv)
|
---|
918 | {
|
---|
919 | int ret = -1;
|
---|
920 | WERROR werr = WERR_OK;
|
---|
921 | char *service = NULL;
|
---|
922 | char *param = NULL;
|
---|
923 | TALLOC_CTX *mem_ctx = talloc_stackframe();
|
---|
924 |
|
---|
925 | if (argc != 2 || c->display_usage) {
|
---|
926 | net_conf_delparm_usage(c, argc, argv);
|
---|
927 | goto done;
|
---|
928 | }
|
---|
929 | /*
|
---|
930 | * NULL service name means "dangling parameters" to libsmbconf.
|
---|
931 | * We use the empty string from the command line for this purpose.
|
---|
932 | */
|
---|
933 | if (strlen(argv[0]) != 0) {
|
---|
934 | service = talloc_strdup(mem_ctx, argv[0]);
|
---|
935 | if (service == NULL) {
|
---|
936 | d_printf(_("error: out of memory!\n"));
|
---|
937 | goto done;
|
---|
938 | }
|
---|
939 | }
|
---|
940 | param = strlower_talloc(mem_ctx, argv[1]);
|
---|
941 | if (param == NULL) {
|
---|
942 | d_printf("error: out of memory!\n");
|
---|
943 | goto done;
|
---|
944 | }
|
---|
945 |
|
---|
946 | werr = smbconf_delete_parameter(conf_ctx, service, param);
|
---|
947 |
|
---|
948 | if (W_ERROR_EQUAL(werr, WERR_NO_SUCH_SERVICE)) {
|
---|
949 | d_fprintf(stderr,
|
---|
950 | _("Error: given service '%s' does not exist.\n"),
|
---|
951 | service);
|
---|
952 | goto done;
|
---|
953 | } else if (W_ERROR_EQUAL(werr, WERR_INVALID_PARAM)) {
|
---|
954 | d_fprintf(stderr,
|
---|
955 | _("Error: given parameter '%s' is not set.\n"),
|
---|
956 | param);
|
---|
957 | goto done;
|
---|
958 | } else if (!W_ERROR_IS_OK(werr)) {
|
---|
959 | d_fprintf(stderr, _("Error deleting value '%s': %s.\n"),
|
---|
960 | param, win_errstr(werr));
|
---|
961 | goto done;
|
---|
962 | }
|
---|
963 |
|
---|
964 | ret = 0;
|
---|
965 |
|
---|
966 | done:
|
---|
967 | TALLOC_FREE(mem_ctx);
|
---|
968 | return ret;
|
---|
969 | }
|
---|
970 |
|
---|
971 | static int net_conf_getincludes(struct net_context *c,
|
---|
972 | struct smbconf_ctx *conf_ctx,
|
---|
973 | int argc, const char **argv)
|
---|
974 | {
|
---|
975 | WERROR werr;
|
---|
976 | uint32_t num_includes;
|
---|
977 | uint32_t count;
|
---|
978 | char *service;
|
---|
979 | char **includes = NULL;
|
---|
980 | int ret = -1;
|
---|
981 | TALLOC_CTX *mem_ctx = talloc_stackframe();
|
---|
982 |
|
---|
983 | if (argc != 1 || c->display_usage) {
|
---|
984 | net_conf_getincludes_usage(c, argc, argv);
|
---|
985 | goto done;
|
---|
986 | }
|
---|
987 |
|
---|
988 | service = talloc_strdup(mem_ctx, argv[0]);
|
---|
989 | if (service == NULL) {
|
---|
990 | d_printf(_("error: out of memory!\n"));
|
---|
991 | goto done;
|
---|
992 | }
|
---|
993 |
|
---|
994 | werr = smbconf_get_includes(conf_ctx, mem_ctx, service,
|
---|
995 | &num_includes, &includes);
|
---|
996 | if (!W_ERROR_IS_OK(werr)) {
|
---|
997 | d_printf(_("error getting includes: %s\n"), win_errstr(werr));
|
---|
998 | goto done;
|
---|
999 | }
|
---|
1000 |
|
---|
1001 | for (count = 0; count < num_includes; count++) {
|
---|
1002 | d_printf("include = %s\n", includes[count]);
|
---|
1003 | }
|
---|
1004 |
|
---|
1005 | ret = 0;
|
---|
1006 |
|
---|
1007 | done:
|
---|
1008 | TALLOC_FREE(mem_ctx);
|
---|
1009 | return ret;
|
---|
1010 | }
|
---|
1011 |
|
---|
1012 | static int net_conf_setincludes(struct net_context *c,
|
---|
1013 | struct smbconf_ctx *conf_ctx,
|
---|
1014 | int argc, const char **argv)
|
---|
1015 | {
|
---|
1016 | WERROR werr;
|
---|
1017 | char *service;
|
---|
1018 | uint32_t num_includes;
|
---|
1019 | const char **includes;
|
---|
1020 | int ret = -1;
|
---|
1021 | TALLOC_CTX *mem_ctx = talloc_stackframe();
|
---|
1022 |
|
---|
1023 | if (argc < 1 || c->display_usage) {
|
---|
1024 | net_conf_setincludes_usage(c, argc, argv);
|
---|
1025 | goto done;
|
---|
1026 | }
|
---|
1027 |
|
---|
1028 | service = talloc_strdup(mem_ctx, argv[0]);
|
---|
1029 | if (service == NULL) {
|
---|
1030 | d_printf(_("error: out of memory!\n"));
|
---|
1031 | goto done;
|
---|
1032 | }
|
---|
1033 |
|
---|
1034 | num_includes = argc - 1;
|
---|
1035 | if (num_includes == 0) {
|
---|
1036 | includes = NULL;
|
---|
1037 | } else {
|
---|
1038 | includes = argv + 1;
|
---|
1039 | }
|
---|
1040 |
|
---|
1041 | werr = smbconf_set_includes(conf_ctx, service, num_includes, includes);
|
---|
1042 | if (!W_ERROR_IS_OK(werr)) {
|
---|
1043 | d_printf(_("error setting includes: %s\n"), win_errstr(werr));
|
---|
1044 | goto done;
|
---|
1045 | }
|
---|
1046 |
|
---|
1047 | ret = 0;
|
---|
1048 |
|
---|
1049 | done:
|
---|
1050 | TALLOC_FREE(mem_ctx);
|
---|
1051 | return ret;
|
---|
1052 | }
|
---|
1053 |
|
---|
1054 | static int net_conf_delincludes(struct net_context *c,
|
---|
1055 | struct smbconf_ctx *conf_ctx,
|
---|
1056 | int argc, const char **argv)
|
---|
1057 | {
|
---|
1058 | WERROR werr;
|
---|
1059 | char *service;
|
---|
1060 | int ret = -1;
|
---|
1061 | TALLOC_CTX *mem_ctx = talloc_stackframe();
|
---|
1062 |
|
---|
1063 | if (argc != 1 || c->display_usage) {
|
---|
1064 | net_conf_delincludes_usage(c, argc, argv);
|
---|
1065 | goto done;
|
---|
1066 | }
|
---|
1067 |
|
---|
1068 | service = talloc_strdup(mem_ctx, argv[0]);
|
---|
1069 | if (service == NULL) {
|
---|
1070 | d_printf(_("error: out of memory!\n"));
|
---|
1071 | goto done;
|
---|
1072 | }
|
---|
1073 |
|
---|
1074 | werr = smbconf_delete_includes(conf_ctx, service);
|
---|
1075 | if (!W_ERROR_IS_OK(werr)) {
|
---|
1076 | d_printf(_("error deleting includes: %s\n"), win_errstr(werr));
|
---|
1077 | goto done;
|
---|
1078 | }
|
---|
1079 |
|
---|
1080 | ret = 0;
|
---|
1081 |
|
---|
1082 | done:
|
---|
1083 | TALLOC_FREE(mem_ctx);
|
---|
1084 | return ret;
|
---|
1085 | }
|
---|
1086 |
|
---|
1087 |
|
---|
1088 | /**********************************************************************
|
---|
1089 | *
|
---|
1090 | * Wrapper and net_conf_run_function mechanism.
|
---|
1091 | *
|
---|
1092 | **********************************************************************/
|
---|
1093 |
|
---|
1094 | /**
|
---|
1095 | * Wrapper function to call the main conf functions.
|
---|
1096 | * The wrapper calls handles opening and closing of the
|
---|
1097 | * configuration.
|
---|
1098 | */
|
---|
1099 | static int net_conf_wrap_function(struct net_context *c,
|
---|
1100 | int (*fn)(struct net_context *,
|
---|
1101 | struct smbconf_ctx *,
|
---|
1102 | int, const char **),
|
---|
1103 | int argc, const char **argv)
|
---|
1104 | {
|
---|
1105 | WERROR werr;
|
---|
1106 | TALLOC_CTX *mem_ctx = talloc_stackframe();
|
---|
1107 | struct smbconf_ctx *conf_ctx;
|
---|
1108 | int ret = -1;
|
---|
1109 |
|
---|
1110 | werr = smbconf_init(mem_ctx, &conf_ctx, "registry:");
|
---|
1111 |
|
---|
1112 | if (!W_ERROR_IS_OK(werr)) {
|
---|
1113 | return -1;
|
---|
1114 | }
|
---|
1115 |
|
---|
1116 | ret = fn(c, conf_ctx, argc, argv);
|
---|
1117 |
|
---|
1118 | smbconf_shutdown(conf_ctx);
|
---|
1119 |
|
---|
1120 | return ret;
|
---|
1121 | }
|
---|
1122 |
|
---|
1123 | /*
|
---|
1124 | * We need a functable struct of our own, because the
|
---|
1125 | * functions are called through a wrapper that handles
|
---|
1126 | * the opening and closing of the configuration, and so on.
|
---|
1127 | */
|
---|
1128 | struct conf_functable {
|
---|
1129 | const char *funcname;
|
---|
1130 | int (*fn)(struct net_context *c, struct smbconf_ctx *ctx, int argc,
|
---|
1131 | const char **argv);
|
---|
1132 | int valid_transports;
|
---|
1133 | const char *description;
|
---|
1134 | const char *usage;
|
---|
1135 | };
|
---|
1136 |
|
---|
1137 | /**
|
---|
1138 | * This imitates net_run_function but calls the main functions
|
---|
1139 | * through the wrapper net_conf_wrap_function().
|
---|
1140 | */
|
---|
1141 | static int net_conf_run_function(struct net_context *c, int argc,
|
---|
1142 | const char **argv, const char *whoami,
|
---|
1143 | struct conf_functable *table)
|
---|
1144 | {
|
---|
1145 | int i;
|
---|
1146 |
|
---|
1147 | if (argc != 0) {
|
---|
1148 | for (i=0; table[i].funcname; i++) {
|
---|
1149 | if (StrCaseCmp(argv[0], table[i].funcname) == 0)
|
---|
1150 | return net_conf_wrap_function(c, table[i].fn,
|
---|
1151 | argc-1,
|
---|
1152 | argv+1);
|
---|
1153 | }
|
---|
1154 | }
|
---|
1155 |
|
---|
1156 | d_printf(_("Usage:\n"));
|
---|
1157 | for (i=0; table[i].funcname; i++) {
|
---|
1158 | if (c->display_usage == false)
|
---|
1159 | d_printf("%s %-15s %s\n", whoami, table[i].funcname,
|
---|
1160 | table[i].description);
|
---|
1161 | else
|
---|
1162 | d_printf("%s\n", table[i].usage);
|
---|
1163 | }
|
---|
1164 |
|
---|
1165 | return c->display_usage?0:-1;
|
---|
1166 | }
|
---|
1167 |
|
---|
1168 | /*
|
---|
1169 | * Entry-point for all the CONF functions.
|
---|
1170 | */
|
---|
1171 |
|
---|
1172 | int net_conf(struct net_context *c, int argc, const char **argv)
|
---|
1173 | {
|
---|
1174 | int ret = -1;
|
---|
1175 | struct conf_functable func_table[] = {
|
---|
1176 | {
|
---|
1177 | "list",
|
---|
1178 | net_conf_list,
|
---|
1179 | NET_TRANSPORT_LOCAL,
|
---|
1180 | N_("Dump the complete configuration in smb.conf like "
|
---|
1181 | "format."),
|
---|
1182 | N_("net conf list\n"
|
---|
1183 | " Dump the complete configuration in smb.conf "
|
---|
1184 | "like format.")
|
---|
1185 |
|
---|
1186 | },
|
---|
1187 | {
|
---|
1188 | "import",
|
---|
1189 | net_conf_import,
|
---|
1190 | NET_TRANSPORT_LOCAL,
|
---|
1191 | N_("Import configuration from file in smb.conf "
|
---|
1192 | "format."),
|
---|
1193 | N_("net conf import\n"
|
---|
1194 | " Import configuration from file in smb.conf "
|
---|
1195 | "format.")
|
---|
1196 | },
|
---|
1197 | {
|
---|
1198 | "listshares",
|
---|
1199 | net_conf_listshares,
|
---|
1200 | NET_TRANSPORT_LOCAL,
|
---|
1201 | N_("List the share names."),
|
---|
1202 | N_("net conf listshares\n"
|
---|
1203 | " List the share names.")
|
---|
1204 | },
|
---|
1205 | {
|
---|
1206 | "drop",
|
---|
1207 | net_conf_drop,
|
---|
1208 | NET_TRANSPORT_LOCAL,
|
---|
1209 | N_("Delete the complete configuration."),
|
---|
1210 | N_("net conf drop\n"
|
---|
1211 | " Delete the complete configuration.")
|
---|
1212 | },
|
---|
1213 | {
|
---|
1214 | "showshare",
|
---|
1215 | net_conf_showshare,
|
---|
1216 | NET_TRANSPORT_LOCAL,
|
---|
1217 | N_("Show the definition of a share."),
|
---|
1218 | N_("net conf showshare\n"
|
---|
1219 | " Show the definition of a share.")
|
---|
1220 | },
|
---|
1221 | {
|
---|
1222 | "addshare",
|
---|
1223 | net_conf_addshare,
|
---|
1224 | NET_TRANSPORT_LOCAL,
|
---|
1225 | N_("Create a new share."),
|
---|
1226 | N_("net conf addshare\n"
|
---|
1227 | " Create a new share.")
|
---|
1228 | },
|
---|
1229 | {
|
---|
1230 | "delshare",
|
---|
1231 | net_conf_delshare,
|
---|
1232 | NET_TRANSPORT_LOCAL,
|
---|
1233 | N_("Delete a share."),
|
---|
1234 | N_("net conf delshare\n"
|
---|
1235 | " Delete a share.")
|
---|
1236 | },
|
---|
1237 | {
|
---|
1238 | "setparm",
|
---|
1239 | net_conf_setparm,
|
---|
1240 | NET_TRANSPORT_LOCAL,
|
---|
1241 | N_("Store a parameter."),
|
---|
1242 | N_("net conf setparm\n"
|
---|
1243 | " Store a parameter.")
|
---|
1244 | },
|
---|
1245 | {
|
---|
1246 | "getparm",
|
---|
1247 | net_conf_getparm,
|
---|
1248 | NET_TRANSPORT_LOCAL,
|
---|
1249 | N_("Retrieve the value of a parameter."),
|
---|
1250 | N_("net conf getparm\n"
|
---|
1251 | " Retrieve the value of a parameter.")
|
---|
1252 | },
|
---|
1253 | {
|
---|
1254 | "delparm",
|
---|
1255 | net_conf_delparm,
|
---|
1256 | NET_TRANSPORT_LOCAL,
|
---|
1257 | N_("Delete a parameter."),
|
---|
1258 | N_("net conf delparm\n"
|
---|
1259 | " Delete a parameter.")
|
---|
1260 | },
|
---|
1261 | {
|
---|
1262 | "getincludes",
|
---|
1263 | net_conf_getincludes,
|
---|
1264 | NET_TRANSPORT_LOCAL,
|
---|
1265 | N_("Show the includes of a share definition."),
|
---|
1266 | N_("net conf getincludes\n"
|
---|
1267 | " Show the includes of a share definition.")
|
---|
1268 | },
|
---|
1269 | {
|
---|
1270 | "setincludes",
|
---|
1271 | net_conf_setincludes,
|
---|
1272 | NET_TRANSPORT_LOCAL,
|
---|
1273 | N_("Set includes for a share."),
|
---|
1274 | N_("net conf setincludes\n"
|
---|
1275 | " Set includes for a share.")
|
---|
1276 | },
|
---|
1277 | {
|
---|
1278 | "delincludes",
|
---|
1279 | net_conf_delincludes,
|
---|
1280 | NET_TRANSPORT_LOCAL,
|
---|
1281 | N_("Delete includes from a share definition."),
|
---|
1282 | N_("net conf setincludes\n"
|
---|
1283 | " Delete includes from a share definition.")
|
---|
1284 | },
|
---|
1285 | {NULL, NULL, 0, NULL, NULL}
|
---|
1286 | };
|
---|
1287 |
|
---|
1288 | ret = net_conf_run_function(c, argc, argv, "net conf", func_table);
|
---|
1289 |
|
---|
1290 | return ret;
|
---|
1291 | }
|
---|
1292 |
|
---|