libads/cldap: store client sitename also keyed by dns domain name.
[Samba.git] / source / utils / net_conf.c
blob08a06eabd41b2cb2230aeab5eb9de750d7d65af8
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
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.
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.
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/>.
22 * This is an interface to Samba's configuration as made available
23 * by the libsmbconf interface (source/lib/smbconf/smbconf.c).
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.
30 #include "includes.h"
31 #include "utils/net.h"
33 /**********************************************************************
35 * usage functions
37 **********************************************************************/
39 static int net_conf_list_usage(int argc, const char **argv)
41 d_printf("USAGE: net conf list\n");
42 return -1;
45 static int net_conf_import_usage(int argc, const char**argv)
47 d_printf("USAGE: net conf import [--test|-T] <filename> "
48 "[<servicename>]\n"
49 "\t[--test|-T] testmode - do not act, just print "
50 "what would be done\n"
51 "\t<servicename> only import service <servicename>, "
52 "ignore the rest\n");
53 return -1;
56 static int net_conf_listshares_usage(int argc, const char **argv)
58 d_printf("USAGE: net conf listshares\n");
59 return -1;
62 static int net_conf_drop_usage(int argc, const char **argv)
64 d_printf("USAGE: net conf drop\n");
65 return -1;
68 static int net_conf_showshare_usage(int argc, const char **argv)
70 d_printf("USAGE: net conf showshare <sharename>\n");
71 return -1;
74 static int net_conf_addshare_usage(int argc, const char **argv)
76 d_printf("USAGE: net conf addshare <sharename> <path> "
77 "[writeable={y|N} [guest_ok={y|N} [<comment>]]\n"
78 "\t<sharename> the new share name.\n"
79 "\t<path> the path on the filesystem to export.\n"
80 "\twriteable={y|N} set \"writeable to \"yes\" or "
81 "\"no\" (default) on this share.\n"
82 "\tguest_ok={y|N} set \"guest ok\" to \"yes\" or "
83 "\"no\" (default) on this share.\n"
84 "\t<comment> optional comment for the new share.\n");
85 return -1;
88 static int net_conf_delshare_usage(int argc, const char **argv)
90 d_printf("USAGE: net conf delshare <sharename>\n");
91 return -1;
94 static int net_conf_setparm_usage(int argc, const char **argv)
96 d_printf("USAGE: net conf setparm <section> <param> <value>\n");
97 return -1;
100 static int net_conf_getparm_usage(int argc, const char **argv)
102 d_printf("USAGE: net conf getparm <section> <param>\n");
103 return -1;
106 static int net_conf_delparm_usage(int argc, const char **argv)
108 d_printf("USAGE: net conf delparm <section> <param>\n");
109 return -1;
112 static int net_conf_getincludes_usage(int argc, const char **argv)
114 d_printf("USAGE: net conf getincludes <section>\n");
115 return -1;
118 static int net_conf_setincludes_usage(int argc, const char **argv)
120 d_printf("USAGE: net conf setincludes <section> [<filename>]*\n");
121 return -1;
124 static int net_conf_delincludes_usage(int argc, const char **argv)
126 d_printf("USAGE: net conf delincludes <section>\n");
127 return -1;
131 /**********************************************************************
133 * Helper functions
135 **********************************************************************/
138 * This functions process a service previously loaded with libsmbconf.
140 static WERROR import_process_service(struct smbconf_ctx *conf_ctx,
141 struct smbconf_service *service)
143 uint32_t idx;
144 WERROR werr = WERR_OK;
145 uint32_t num_includes = 0;
146 char **includes = NULL;
147 TALLOC_CTX *mem_ctx = talloc_stackframe();
149 if (opt_testmode) {
150 const char *indent = "";
151 if (service->name != NULL) {
152 d_printf("[%s]\n", service->name);
153 indent = "\t";
155 for (idx = 0; idx < service->num_params; idx++) {
156 d_printf("%s%s = %s\n", indent,
157 service->param_names[idx],
158 service->param_values[idx]);
160 d_printf("\n");
161 goto done;
164 if (smbconf_share_exists(conf_ctx, service->name)) {
165 werr = smbconf_delete_share(conf_ctx, service->name);
166 if (!W_ERROR_IS_OK(werr)) {
167 goto done;
170 werr = smbconf_create_share(conf_ctx, service->name);
171 if (!W_ERROR_IS_OK(werr)) {
172 goto done;
175 for (idx = 0; idx < service->num_params; idx ++) {
176 if (strequal(service->param_names[idx], "include")) {
177 includes = TALLOC_REALLOC_ARRAY(mem_ctx,
178 includes,
179 char *,
180 num_includes+1);
181 if (includes == NULL) {
182 werr = WERR_NOMEM;
183 goto done;
185 includes[num_includes] = talloc_strdup(includes,
186 service->param_values[idx]);
187 if (includes[num_includes] == NULL) {
188 werr = WERR_NOMEM;
189 goto done;
191 num_includes++;
192 } else {
193 werr = smbconf_set_parameter(conf_ctx,
194 service->name,
195 service->param_names[idx],
196 service->param_values[idx]);
197 if (!W_ERROR_IS_OK(werr)) {
198 goto done;
203 werr = smbconf_set_includes(conf_ctx, service->name, num_includes,
204 (const char **)includes);
206 done:
207 TALLOC_FREE(mem_ctx);
208 return werr;
212 /**********************************************************************
214 * the main conf functions
216 **********************************************************************/
218 static int net_conf_list(struct smbconf_ctx *conf_ctx,
219 int argc, const char **argv)
221 WERROR werr = WERR_OK;
222 int ret = -1;
223 TALLOC_CTX *mem_ctx;
224 uint32_t num_shares;
225 uint32_t share_count, param_count;
226 struct smbconf_service **shares = NULL;
228 mem_ctx = talloc_stackframe();
230 if (argc != 0) {
231 net_conf_list_usage(argc, argv);
232 goto done;
235 werr = smbconf_get_config(conf_ctx, mem_ctx, &num_shares, &shares);
236 if (!W_ERROR_IS_OK(werr)) {
237 d_fprintf(stderr, "Error getting config: %s\n",
238 dos_errstr(werr));
239 goto done;
242 for (share_count = 0; share_count < num_shares; share_count++) {
243 const char *indent = "";
244 if (shares[share_count]->name != NULL) {
245 d_printf("[%s]\n", shares[share_count]->name);
246 indent = "\t";
248 for (param_count = 0;
249 param_count < shares[share_count]->num_params;
250 param_count++)
252 d_printf("%s%s = %s\n",
253 indent,
254 shares[share_count]->param_names[param_count],
255 shares[share_count]->param_values[param_count]);
257 d_printf("\n");
260 ret = 0;
262 done:
263 TALLOC_FREE(mem_ctx);
264 return ret;
267 static int net_conf_import(struct smbconf_ctx *conf_ctx,
268 int argc, const char **argv)
270 int ret = -1;
271 const char *filename = NULL;
272 const char *servicename = NULL;
273 char *conf_source = NULL;
274 TALLOC_CTX *mem_ctx;
275 struct smbconf_ctx *txt_ctx;
276 WERROR werr;
278 mem_ctx = talloc_stackframe();
280 switch (argc) {
281 case 0:
282 default:
283 net_conf_import_usage(argc, argv);
284 goto done;
285 case 2:
286 servicename = talloc_strdup_lower(mem_ctx, argv[1]);
287 if (servicename == NULL) {
288 d_printf("error: out of memory!\n");
289 goto done;
291 case 1:
292 filename = argv[0];
293 break;
296 DEBUG(3,("net_conf_import: reading configuration from file %s.\n",
297 filename));
299 conf_source = talloc_asprintf(mem_ctx, "file:%s", filename);
300 if (conf_source == NULL) {
301 d_printf("error: out of memory!\n");
302 goto done;
305 werr = smbconf_init(mem_ctx, &txt_ctx, conf_source);
306 if (!W_ERROR_IS_OK(werr)) {
307 d_printf("error loading file '%s': %s\n", filename,
308 dos_errstr(werr));
309 goto done;
312 if (opt_testmode) {
313 d_printf("\nTEST MODE - "
314 "would import the following configuration:\n\n");
317 if (servicename != NULL) {
318 struct smbconf_service *service = NULL;
320 werr = smbconf_get_share(txt_ctx, mem_ctx,
321 servicename,
322 &service);
323 if (!W_ERROR_IS_OK(werr)) {
324 goto done;
326 werr = import_process_service(conf_ctx, service);
327 if (!W_ERROR_IS_OK(werr)) {
328 goto done;
330 } else {
331 struct smbconf_service **services = NULL;
332 uint32_t num_shares, sidx;
334 werr = smbconf_get_config(txt_ctx, mem_ctx,
335 &num_shares,
336 &services);
337 if (!W_ERROR_IS_OK(werr)) {
338 goto done;
340 if (!opt_testmode) {
341 werr = smbconf_drop(conf_ctx);
342 if (!W_ERROR_IS_OK(werr)) {
343 goto done;
346 for (sidx = 0; sidx < num_shares; sidx++) {
347 werr = import_process_service(conf_ctx, services[sidx]);
348 if (!W_ERROR_IS_OK(werr)) {
349 goto done;
354 ret = 0;
356 done:
357 TALLOC_FREE(mem_ctx);
358 return ret;
361 static int net_conf_listshares(struct smbconf_ctx *conf_ctx,
362 int argc, const char **argv)
364 WERROR werr = WERR_OK;
365 int ret = -1;
366 uint32_t count, num_shares = 0;
367 char **share_names = NULL;
368 TALLOC_CTX *mem_ctx;
370 mem_ctx = talloc_stackframe();
372 if (argc != 0) {
373 net_conf_listshares_usage(argc, argv);
374 goto done;
377 werr = smbconf_get_share_names(conf_ctx, mem_ctx, &num_shares,
378 &share_names);
379 if (!W_ERROR_IS_OK(werr)) {
380 goto done;
383 for (count = 0; count < num_shares; count++)
385 d_printf("%s\n", share_names[count]);
388 ret = 0;
390 done:
391 TALLOC_FREE(mem_ctx);
392 return ret;
395 static int net_conf_drop(struct smbconf_ctx *conf_ctx,
396 int argc, const char **argv)
398 int ret = -1;
399 WERROR werr;
401 if (argc != 0) {
402 net_conf_drop_usage(argc, argv);
403 goto done;
406 werr = smbconf_drop(conf_ctx);
407 if (!W_ERROR_IS_OK(werr)) {
408 d_fprintf(stderr, "Error deleting configuration: %s\n",
409 dos_errstr(werr));
410 goto done;
413 ret = 0;
415 done:
416 return ret;
419 static int net_conf_showshare(struct smbconf_ctx *conf_ctx,
420 int argc, const char **argv)
422 int ret = -1;
423 WERROR werr = WERR_OK;
424 const char *sharename = NULL;
425 TALLOC_CTX *mem_ctx;
426 uint32_t count;
427 struct smbconf_service *service = NULL;
429 mem_ctx = talloc_stackframe();
431 if (argc != 1) {
432 net_conf_showshare_usage(argc, argv);
433 goto done;
436 sharename = talloc_strdup_lower(mem_ctx, argv[0]);
437 if (sharename == NULL) {
438 d_printf("error: out of memory!\n");
439 goto done;
442 werr = smbconf_get_share(conf_ctx, mem_ctx, sharename, &service);
443 if (!W_ERROR_IS_OK(werr)) {
444 d_printf("error getting share parameters: %s\n",
445 dos_errstr(werr));
446 goto done;
449 d_printf("[%s]\n", sharename);
451 for (count = 0; count < service->num_params; count++) {
452 d_printf("\t%s = %s\n", service->param_names[count],
453 service->param_values[count]);
456 ret = 0;
458 done:
459 TALLOC_FREE(mem_ctx);
460 return ret;
464 * Add a share, with a couple of standard parameters, partly optional.
466 * This is a high level utility function of the net conf utility,
467 * not a direct frontend to the smbconf API.
469 static int net_conf_addshare(struct smbconf_ctx *conf_ctx,
470 int argc, const char **argv)
472 int ret = -1;
473 WERROR werr = WERR_OK;
474 char *sharename = NULL;
475 const char *path = NULL;
476 const char *comment = NULL;
477 const char *guest_ok = "no";
478 const char *writeable = "no";
479 SMB_STRUCT_STAT sbuf;
480 TALLOC_CTX *mem_ctx = talloc_stackframe();
482 switch (argc) {
483 case 0:
484 case 1:
485 default:
486 net_conf_addshare_usage(argc, argv);
487 goto done;
488 case 5:
489 comment = argv[4];
490 case 4:
491 if (!strnequal(argv[3], "guest_ok=", 9)) {
492 net_conf_addshare_usage(argc, argv);
493 goto done;
495 switch (argv[3][9]) {
496 case 'y':
497 case 'Y':
498 guest_ok = "yes";
499 break;
500 case 'n':
501 case 'N':
502 guest_ok = "no";
503 break;
504 default:
505 net_conf_addshare_usage(argc, argv);
506 goto done;
508 case 3:
509 if (!strnequal(argv[2], "writeable=", 10)) {
510 net_conf_addshare_usage(argc, argv);
511 goto done;
513 switch (argv[2][10]) {
514 case 'y':
515 case 'Y':
516 writeable = "yes";
517 break;
518 case 'n':
519 case 'N':
520 writeable = "no";
521 break;
522 default:
523 net_conf_addshare_usage(argc, argv);
524 goto done;
526 case 2:
527 path = argv[1];
528 sharename = talloc_strdup_lower(mem_ctx, argv[0]);
529 if (sharename == NULL) {
530 d_printf("error: out of memory!\n");
531 goto done;
534 break;
538 * validate arguments
541 /* validate share name */
543 if (!validate_net_name(sharename, INVALID_SHARENAME_CHARS,
544 strlen(sharename)))
546 d_fprintf(stderr, "ERROR: share name %s contains "
547 "invalid characters (any of %s)\n",
548 sharename, INVALID_SHARENAME_CHARS);
549 goto done;
552 if (getpwnam(sharename)) {
553 d_fprintf(stderr, "ERROR: share name %s is already a valid "
554 "system user name.\n", sharename);
555 goto done;
558 if (strequal(sharename, GLOBAL_NAME)) {
559 d_fprintf(stderr,
560 "ERROR: 'global' is not a valid share name.\n");
561 goto done;
564 if (smbconf_share_exists(conf_ctx, sharename)) {
565 d_fprintf(stderr, "ERROR: share %s already exists.\n",
566 sharename);
567 goto done;
570 /* validate path */
572 if (path[0] != '/') {
573 d_fprintf(stderr,
574 "Error: path '%s' is not an absolute path.\n",
575 path);
576 goto done;
579 if (sys_stat(path, &sbuf) != 0) {
580 d_fprintf(stderr,
581 "ERROR: cannot stat path '%s' to ensure "
582 "this is a directory.\n"
583 "Error was '%s'.\n",
584 path, strerror(errno));
585 goto done;
588 if (!S_ISDIR(sbuf.st_mode)) {
589 d_fprintf(stderr,
590 "ERROR: path '%s' is not a directory.\n",
591 path);
592 goto done;
596 * create the share
599 werr = smbconf_create_share(conf_ctx, sharename);
600 if (!W_ERROR_IS_OK(werr)) {
601 d_fprintf(stderr, "Error creating share %s: %s\n",
602 sharename, dos_errstr(werr));
603 goto done;
607 * fill the share with parameters
610 werr = smbconf_set_parameter(conf_ctx, sharename, "path", path);
611 if (!W_ERROR_IS_OK(werr)) {
612 d_fprintf(stderr, "Error setting parameter %s: %s\n",
613 "path", dos_errstr(werr));
614 goto done;
617 if (comment != NULL) {
618 werr = smbconf_set_parameter(conf_ctx, sharename, "comment",
619 comment);
620 if (!W_ERROR_IS_OK(werr)) {
621 d_fprintf(stderr, "Error setting parameter %s: %s\n",
622 "comment", dos_errstr(werr));
623 goto done;
627 werr = smbconf_set_parameter(conf_ctx, sharename, "guest ok", guest_ok);
628 if (!W_ERROR_IS_OK(werr)) {
629 d_fprintf(stderr, "Error setting parameter %s: %s\n",
630 "'guest ok'", dos_errstr(werr));
631 goto done;
634 werr = smbconf_set_parameter(conf_ctx, sharename, "writeable",
635 writeable);
636 if (!W_ERROR_IS_OK(werr)) {
637 d_fprintf(stderr, "Error setting parameter %s: %s\n",
638 "writeable", dos_errstr(werr));
639 goto done;
642 ret = 0;
644 done:
645 TALLOC_FREE(mem_ctx);
646 return ret;
649 static int net_conf_delshare(struct smbconf_ctx *conf_ctx,
650 int argc, const char **argv)
652 int ret = -1;
653 const char *sharename = NULL;
654 WERROR werr = WERR_OK;
655 TALLOC_CTX *mem_ctx = talloc_stackframe();
657 if (argc != 1) {
658 net_conf_delshare_usage(argc, argv);
659 goto done;
661 sharename = talloc_strdup_lower(mem_ctx, argv[0]);
662 if (sharename == NULL) {
663 d_printf("error: out of memory!\n");
664 goto done;
667 werr = smbconf_delete_share(conf_ctx, sharename);
668 if (!W_ERROR_IS_OK(werr)) {
669 d_fprintf(stderr, "Error deleting share %s: %s\n",
670 sharename, dos_errstr(werr));
671 goto done;
674 ret = 0;
675 done:
676 TALLOC_FREE(mem_ctx);
677 return ret;
680 static int net_conf_setparm(struct smbconf_ctx *conf_ctx,
681 int argc, const char **argv)
683 int ret = -1;
684 WERROR werr = WERR_OK;
685 char *service = NULL;
686 char *param = NULL;
687 const char *value_str = NULL;
688 TALLOC_CTX *mem_ctx = talloc_stackframe();
690 if (argc != 3) {
691 net_conf_setparm_usage(argc, argv);
692 goto done;
694 service = talloc_strdup_lower(mem_ctx, argv[0]);
695 if (service == NULL) {
696 d_printf("error: out of memory!\n");
697 goto done;
699 param = talloc_strdup_lower(mem_ctx, argv[1]);
700 if (param == NULL) {
701 d_printf("error: out of memory!\n");
702 goto done;
704 value_str = argv[2];
706 if (!smbconf_share_exists(conf_ctx, service)) {
707 werr = smbconf_create_share(conf_ctx, service);
708 if (!W_ERROR_IS_OK(werr)) {
709 d_fprintf(stderr, "Error creating share '%s': %s\n",
710 service, dos_errstr(werr));
711 goto done;
715 werr = smbconf_set_parameter(conf_ctx, service, param, value_str);
717 if (!W_ERROR_IS_OK(werr)) {
718 d_fprintf(stderr, "Error setting value '%s': %s\n",
719 param, dos_errstr(werr));
720 goto done;
723 ret = 0;
725 done:
726 TALLOC_FREE(mem_ctx);
727 return ret;
730 static int net_conf_getparm(struct smbconf_ctx *conf_ctx,
731 int argc, const char **argv)
733 int ret = -1;
734 WERROR werr = WERR_OK;
735 char *service = NULL;
736 char *param = NULL;
737 char *valstr = NULL;
738 TALLOC_CTX *mem_ctx;
740 mem_ctx = talloc_stackframe();
742 if (argc != 2) {
743 net_conf_getparm_usage(argc, argv);
744 goto done;
746 service = talloc_strdup_lower(mem_ctx, argv[0]);
747 if (service == NULL) {
748 d_printf("error: out of memory!\n");
749 goto done;
751 param = talloc_strdup_lower(mem_ctx, argv[1]);
752 if (param == NULL) {
753 d_printf("error: out of memory!\n");
754 goto done;
757 werr = smbconf_get_parameter(conf_ctx, mem_ctx, service, param, &valstr);
759 if (W_ERROR_EQUAL(werr, WERR_NO_SUCH_SERVICE)) {
760 d_fprintf(stderr,
761 "Error: given service '%s' does not exist.\n",
762 service);
763 goto done;
764 } else if (W_ERROR_EQUAL(werr, WERR_INVALID_PARAM)) {
765 d_fprintf(stderr,
766 "Error: given parameter '%s' is not set.\n",
767 param);
768 goto done;
769 } else if (!W_ERROR_IS_OK(werr)) {
770 d_fprintf(stderr, "Error getting value '%s': %s.\n",
771 param, dos_errstr(werr));
772 goto done;
775 d_printf("%s\n", valstr);
777 ret = 0;
778 done:
779 TALLOC_FREE(mem_ctx);
780 return ret;
783 static int net_conf_delparm(struct smbconf_ctx *conf_ctx,
784 int argc, const char **argv)
786 int ret = -1;
787 WERROR werr = WERR_OK;
788 char *service = NULL;
789 char *param = NULL;
790 TALLOC_CTX *mem_ctx = talloc_stackframe();
792 if (argc != 2) {
793 net_conf_delparm_usage(argc, argv);
794 goto done;
796 service = talloc_strdup_lower(mem_ctx, argv[0]);
797 if (service == NULL) {
798 d_printf("error: out of memory!\n");
799 goto done;
801 param = talloc_strdup_lower(mem_ctx, argv[1]);
802 if (param == NULL) {
803 d_printf("error: out of memory!\n");
804 goto done;
807 werr = smbconf_delete_parameter(conf_ctx, service, param);
809 if (W_ERROR_EQUAL(werr, WERR_NO_SUCH_SERVICE)) {
810 d_fprintf(stderr,
811 "Error: given service '%s' does not exist.\n",
812 service);
813 goto done;
814 } else if (W_ERROR_EQUAL(werr, WERR_INVALID_PARAM)) {
815 d_fprintf(stderr,
816 "Error: given parameter '%s' is not set.\n",
817 param);
818 goto done;
819 } else if (!W_ERROR_IS_OK(werr)) {
820 d_fprintf(stderr, "Error deleting value '%s': %s.\n",
821 param, dos_errstr(werr));
822 goto done;
825 ret = 0;
827 done:
828 TALLOC_FREE(mem_ctx);
829 return ret;
832 static int net_conf_getincludes(struct smbconf_ctx *conf_ctx,
833 int argc, const char **argv)
835 WERROR werr;
836 uint32_t num_includes;
837 uint32_t count;
838 char *service;
839 char **includes = NULL;
840 int ret = -1;
841 TALLOC_CTX *mem_ctx = talloc_stackframe();
843 if (argc != 1) {
844 net_conf_getincludes_usage(argc, argv);
845 goto done;
848 service = talloc_strdup_lower(mem_ctx, argv[0]);
849 if (service == NULL) {
850 d_printf("error: out of memory!\n");
851 goto done;
854 werr = smbconf_get_includes(conf_ctx, mem_ctx, service,
855 &num_includes, &includes);
856 if (!W_ERROR_IS_OK(werr)) {
857 d_printf("error getting includes: %s\n", dos_errstr(werr));
858 goto done;
861 for (count = 0; count < num_includes; count++) {
862 d_printf("include = %s\n", includes[count]);
865 ret = 0;
867 done:
868 TALLOC_FREE(mem_ctx);
869 return ret;
872 static int net_conf_setincludes(struct smbconf_ctx *conf_ctx,
873 int argc, const char **argv)
875 WERROR werr;
876 char *service;
877 uint32_t num_includes;
878 const char **includes;
879 int ret = -1;
880 TALLOC_CTX *mem_ctx = talloc_stackframe();
882 if (argc < 1) {
883 net_conf_setincludes_usage(argc, argv);
884 goto done;
887 service = talloc_strdup_lower(mem_ctx, argv[0]);
888 if (service == NULL) {
889 d_printf("error: out of memory!\n");
890 goto done;
893 num_includes = argc - 1;
894 if (num_includes == 0) {
895 includes = NULL;
896 } else {
897 includes = argv + 1;
900 werr = smbconf_set_includes(conf_ctx, service, num_includes, includes);
901 if (!W_ERROR_IS_OK(werr)) {
902 d_printf("error setting includes: %s\n", dos_errstr(werr));
903 goto done;
906 ret = 0;
908 done:
909 TALLOC_FREE(mem_ctx);
910 return ret;
913 static int net_conf_delincludes(struct smbconf_ctx *conf_ctx,
914 int argc, const char **argv)
916 WERROR werr;
917 char *service;
918 int ret = -1;
919 TALLOC_CTX *mem_ctx = talloc_stackframe();
921 if (argc != 1) {
922 net_conf_delincludes_usage(argc, argv);
923 goto done;
926 service = talloc_strdup_lower(mem_ctx, argv[0]);
927 if (service == NULL) {
928 d_printf("error: out of memory!\n");
929 goto done;
932 werr = smbconf_delete_includes(conf_ctx, service);
933 if (!W_ERROR_IS_OK(werr)) {
934 d_printf("error deleting includes: %s\n", dos_errstr(werr));
935 goto done;
938 ret = 0;
940 done:
941 TALLOC_FREE(mem_ctx);
942 return ret;
946 /**********************************************************************
948 * Wrapper and net_conf_run_function mechanism.
950 **********************************************************************/
953 * Wrapper function to call the main conf functions.
954 * The wrapper calls handles opening and closing of the
955 * configuration.
957 static int net_conf_wrap_function(int (*fn)(struct smbconf_ctx *,
958 int, const char **),
959 int argc, const char **argv)
961 WERROR werr;
962 TALLOC_CTX *mem_ctx = talloc_stackframe();
963 struct smbconf_ctx *conf_ctx;
964 int ret = -1;
966 werr = smbconf_init(mem_ctx, &conf_ctx, "registry:");
968 if (!W_ERROR_IS_OK(werr)) {
969 return -1;
972 ret = fn(conf_ctx, argc, argv);
974 smbconf_shutdown(conf_ctx);
976 return ret;
980 * We need a functable struct of our own, because the
981 * functions are called through a wrapper that handles
982 * the opening and closing of the configuration, and so on.
984 struct conf_functable {
985 const char *funcname;
986 int (*fn)(struct smbconf_ctx *ctx, int argc, const char **argv);
987 const char *helptext;
991 * This imitates net_run_function2 but calls the main functions
992 * through the wrapper net_conf_wrap_function().
994 static int net_conf_run_function(int argc, const char **argv,
995 const char *whoami,
996 struct conf_functable *table)
998 int i;
1000 if (argc != 0) {
1001 for (i=0; table[i].funcname; i++) {
1002 if (StrCaseCmp(argv[0], table[i].funcname) == 0)
1003 return net_conf_wrap_function(table[i].fn,
1004 argc-1,
1005 argv+1);
1009 for (i=0; table[i].funcname; i++) {
1010 d_printf("%s %-15s %s\n", whoami, table[i].funcname,
1011 table[i].helptext);
1014 return -1;
1018 * Entry-point for all the CONF functions.
1021 int net_conf(int argc, const char **argv)
1023 int ret = -1;
1024 struct conf_functable func_table[] = {
1025 {"list", net_conf_list,
1026 "Dump the complete configuration in smb.conf like format."},
1027 {"import", net_conf_import,
1028 "Import configuration from file in smb.conf format."},
1029 {"listshares", net_conf_listshares,
1030 "List the share names."},
1031 {"drop", net_conf_drop,
1032 "Delete the complete configuration."},
1033 {"showshare", net_conf_showshare,
1034 "Show the definition of a share."},
1035 {"addshare", net_conf_addshare,
1036 "Create a new share."},
1037 {"delshare", net_conf_delshare,
1038 "Delete a share."},
1039 {"setparm", net_conf_setparm,
1040 "Store a parameter."},
1041 {"getparm", net_conf_getparm,
1042 "Retrieve the value of a parameter."},
1043 {"delparm", net_conf_delparm,
1044 "Delete a parameter."},
1045 {"getincludes", net_conf_getincludes,
1046 "Show the includes of a share definition."},
1047 {"setincludes", net_conf_setincludes,
1048 "Set includes for a share."},
1049 {"delincludes", net_conf_delincludes,
1050 "Delete includes from a share definition."},
1051 {NULL, NULL, NULL}
1054 ret = net_conf_run_function(argc, argv, "net conf", func_table);
1056 return ret;