Add comment explaining the previous fix.
[Samba.git] / source / utils / net_conf.c
blob6639b85be96a78634635ff158c653dde4606cd21
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 (strequal(sharename, GLOBAL_NAME)) {
553 d_fprintf(stderr,
554 "ERROR: 'global' is not a valid share name.\n");
555 goto done;
558 if (smbconf_share_exists(conf_ctx, sharename)) {
559 d_fprintf(stderr, "ERROR: share %s already exists.\n",
560 sharename);
561 goto done;
564 /* validate path */
566 if (path[0] != '/') {
567 d_fprintf(stderr,
568 "Error: path '%s' is not an absolute path.\n",
569 path);
570 goto done;
573 if (sys_stat(path, &sbuf) != 0) {
574 d_fprintf(stderr,
575 "ERROR: cannot stat path '%s' to ensure "
576 "this is a directory.\n"
577 "Error was '%s'.\n",
578 path, strerror(errno));
579 goto done;
582 if (!S_ISDIR(sbuf.st_mode)) {
583 d_fprintf(stderr,
584 "ERROR: path '%s' is not a directory.\n",
585 path);
586 goto done;
590 * create the share
593 werr = smbconf_create_share(conf_ctx, sharename);
594 if (!W_ERROR_IS_OK(werr)) {
595 d_fprintf(stderr, "Error creating share %s: %s\n",
596 sharename, dos_errstr(werr));
597 goto done;
601 * fill the share with parameters
604 werr = smbconf_set_parameter(conf_ctx, sharename, "path", path);
605 if (!W_ERROR_IS_OK(werr)) {
606 d_fprintf(stderr, "Error setting parameter %s: %s\n",
607 "path", dos_errstr(werr));
608 goto done;
611 if (comment != NULL) {
612 werr = smbconf_set_parameter(conf_ctx, sharename, "comment",
613 comment);
614 if (!W_ERROR_IS_OK(werr)) {
615 d_fprintf(stderr, "Error setting parameter %s: %s\n",
616 "comment", dos_errstr(werr));
617 goto done;
621 werr = smbconf_set_parameter(conf_ctx, sharename, "guest ok", guest_ok);
622 if (!W_ERROR_IS_OK(werr)) {
623 d_fprintf(stderr, "Error setting parameter %s: %s\n",
624 "'guest ok'", dos_errstr(werr));
625 goto done;
628 werr = smbconf_set_parameter(conf_ctx, sharename, "writeable",
629 writeable);
630 if (!W_ERROR_IS_OK(werr)) {
631 d_fprintf(stderr, "Error setting parameter %s: %s\n",
632 "writeable", dos_errstr(werr));
633 goto done;
636 ret = 0;
638 done:
639 TALLOC_FREE(mem_ctx);
640 return ret;
643 static int net_conf_delshare(struct smbconf_ctx *conf_ctx,
644 int argc, const char **argv)
646 int ret = -1;
647 const char *sharename = NULL;
648 WERROR werr = WERR_OK;
649 TALLOC_CTX *mem_ctx = talloc_stackframe();
651 if (argc != 1) {
652 net_conf_delshare_usage(argc, argv);
653 goto done;
655 sharename = talloc_strdup_lower(mem_ctx, argv[0]);
656 if (sharename == NULL) {
657 d_printf("error: out of memory!\n");
658 goto done;
661 werr = smbconf_delete_share(conf_ctx, sharename);
662 if (!W_ERROR_IS_OK(werr)) {
663 d_fprintf(stderr, "Error deleting share %s: %s\n",
664 sharename, dos_errstr(werr));
665 goto done;
668 ret = 0;
669 done:
670 TALLOC_FREE(mem_ctx);
671 return ret;
674 static int net_conf_setparm(struct smbconf_ctx *conf_ctx,
675 int argc, const char **argv)
677 int ret = -1;
678 WERROR werr = WERR_OK;
679 char *service = NULL;
680 char *param = NULL;
681 const char *value_str = NULL;
682 TALLOC_CTX *mem_ctx = talloc_stackframe();
684 if (argc != 3) {
685 net_conf_setparm_usage(argc, argv);
686 goto done;
688 service = talloc_strdup_lower(mem_ctx, argv[0]);
689 if (service == NULL) {
690 d_printf("error: out of memory!\n");
691 goto done;
693 param = talloc_strdup_lower(mem_ctx, argv[1]);
694 if (param == NULL) {
695 d_printf("error: out of memory!\n");
696 goto done;
698 value_str = argv[2];
700 if (!smbconf_share_exists(conf_ctx, service)) {
701 werr = smbconf_create_share(conf_ctx, service);
702 if (!W_ERROR_IS_OK(werr)) {
703 d_fprintf(stderr, "Error creating share '%s': %s\n",
704 service, dos_errstr(werr));
705 goto done;
709 werr = smbconf_set_parameter(conf_ctx, service, param, value_str);
711 if (!W_ERROR_IS_OK(werr)) {
712 d_fprintf(stderr, "Error setting value '%s': %s\n",
713 param, dos_errstr(werr));
714 goto done;
717 ret = 0;
719 done:
720 TALLOC_FREE(mem_ctx);
721 return ret;
724 static int net_conf_getparm(struct smbconf_ctx *conf_ctx,
725 int argc, const char **argv)
727 int ret = -1;
728 WERROR werr = WERR_OK;
729 char *service = NULL;
730 char *param = NULL;
731 char *valstr = NULL;
732 TALLOC_CTX *mem_ctx;
734 mem_ctx = talloc_stackframe();
736 if (argc != 2) {
737 net_conf_getparm_usage(argc, argv);
738 goto done;
740 service = talloc_strdup_lower(mem_ctx, argv[0]);
741 if (service == NULL) {
742 d_printf("error: out of memory!\n");
743 goto done;
745 param = talloc_strdup_lower(mem_ctx, argv[1]);
746 if (param == NULL) {
747 d_printf("error: out of memory!\n");
748 goto done;
751 werr = smbconf_get_parameter(conf_ctx, mem_ctx, service, param, &valstr);
753 if (W_ERROR_EQUAL(werr, WERR_NO_SUCH_SERVICE)) {
754 d_fprintf(stderr,
755 "Error: given service '%s' does not exist.\n",
756 service);
757 goto done;
758 } else if (W_ERROR_EQUAL(werr, WERR_INVALID_PARAM)) {
759 d_fprintf(stderr,
760 "Error: given parameter '%s' is not set.\n",
761 param);
762 goto done;
763 } else if (!W_ERROR_IS_OK(werr)) {
764 d_fprintf(stderr, "Error getting value '%s': %s.\n",
765 param, dos_errstr(werr));
766 goto done;
769 d_printf("%s\n", valstr);
771 ret = 0;
772 done:
773 TALLOC_FREE(mem_ctx);
774 return ret;
777 static int net_conf_delparm(struct smbconf_ctx *conf_ctx,
778 int argc, const char **argv)
780 int ret = -1;
781 WERROR werr = WERR_OK;
782 char *service = NULL;
783 char *param = NULL;
784 TALLOC_CTX *mem_ctx = talloc_stackframe();
786 if (argc != 2) {
787 net_conf_delparm_usage(argc, argv);
788 goto done;
790 service = talloc_strdup_lower(mem_ctx, argv[0]);
791 if (service == NULL) {
792 d_printf("error: out of memory!\n");
793 goto done;
795 param = talloc_strdup_lower(mem_ctx, argv[1]);
796 if (param == NULL) {
797 d_printf("error: out of memory!\n");
798 goto done;
801 werr = smbconf_delete_parameter(conf_ctx, service, param);
803 if (W_ERROR_EQUAL(werr, WERR_NO_SUCH_SERVICE)) {
804 d_fprintf(stderr,
805 "Error: given service '%s' does not exist.\n",
806 service);
807 goto done;
808 } else if (W_ERROR_EQUAL(werr, WERR_INVALID_PARAM)) {
809 d_fprintf(stderr,
810 "Error: given parameter '%s' is not set.\n",
811 param);
812 goto done;
813 } else if (!W_ERROR_IS_OK(werr)) {
814 d_fprintf(stderr, "Error deleting value '%s': %s.\n",
815 param, dos_errstr(werr));
816 goto done;
819 ret = 0;
821 done:
822 TALLOC_FREE(mem_ctx);
823 return ret;
826 static int net_conf_getincludes(struct smbconf_ctx *conf_ctx,
827 int argc, const char **argv)
829 WERROR werr;
830 uint32_t num_includes;
831 uint32_t count;
832 char *service;
833 char **includes = NULL;
834 int ret = -1;
835 TALLOC_CTX *mem_ctx = talloc_stackframe();
837 if (argc != 1) {
838 net_conf_getincludes_usage(argc, argv);
839 goto done;
842 service = talloc_strdup_lower(mem_ctx, argv[0]);
843 if (service == NULL) {
844 d_printf("error: out of memory!\n");
845 goto done;
848 werr = smbconf_get_includes(conf_ctx, mem_ctx, service,
849 &num_includes, &includes);
850 if (!W_ERROR_IS_OK(werr)) {
851 d_printf("error getting includes: %s\n", dos_errstr(werr));
852 goto done;
855 for (count = 0; count < num_includes; count++) {
856 d_printf("include = %s\n", includes[count]);
859 ret = 0;
861 done:
862 TALLOC_FREE(mem_ctx);
863 return ret;
866 static int net_conf_setincludes(struct smbconf_ctx *conf_ctx,
867 int argc, const char **argv)
869 WERROR werr;
870 char *service;
871 uint32_t num_includes;
872 const char **includes;
873 int ret = -1;
874 TALLOC_CTX *mem_ctx = talloc_stackframe();
876 if (argc < 1) {
877 net_conf_setincludes_usage(argc, argv);
878 goto done;
881 service = talloc_strdup_lower(mem_ctx, argv[0]);
882 if (service == NULL) {
883 d_printf("error: out of memory!\n");
884 goto done;
887 num_includes = argc - 1;
888 if (num_includes == 0) {
889 includes = NULL;
890 } else {
891 includes = argv + 1;
894 werr = smbconf_set_includes(conf_ctx, service, num_includes, includes);
895 if (!W_ERROR_IS_OK(werr)) {
896 d_printf("error setting includes: %s\n", dos_errstr(werr));
897 goto done;
900 ret = 0;
902 done:
903 TALLOC_FREE(mem_ctx);
904 return ret;
907 static int net_conf_delincludes(struct smbconf_ctx *conf_ctx,
908 int argc, const char **argv)
910 WERROR werr;
911 char *service;
912 int ret = -1;
913 TALLOC_CTX *mem_ctx = talloc_stackframe();
915 if (argc != 1) {
916 net_conf_delincludes_usage(argc, argv);
917 goto done;
920 service = talloc_strdup_lower(mem_ctx, argv[0]);
921 if (service == NULL) {
922 d_printf("error: out of memory!\n");
923 goto done;
926 werr = smbconf_delete_includes(conf_ctx, service);
927 if (!W_ERROR_IS_OK(werr)) {
928 d_printf("error deleting includes: %s\n", dos_errstr(werr));
929 goto done;
932 ret = 0;
934 done:
935 TALLOC_FREE(mem_ctx);
936 return ret;
940 /**********************************************************************
942 * Wrapper and net_conf_run_function mechanism.
944 **********************************************************************/
947 * Wrapper function to call the main conf functions.
948 * The wrapper calls handles opening and closing of the
949 * configuration.
951 static int net_conf_wrap_function(int (*fn)(struct smbconf_ctx *,
952 int, const char **),
953 int argc, const char **argv)
955 WERROR werr;
956 TALLOC_CTX *mem_ctx = talloc_stackframe();
957 struct smbconf_ctx *conf_ctx;
958 int ret = -1;
960 werr = smbconf_init(mem_ctx, &conf_ctx, "registry:");
962 if (!W_ERROR_IS_OK(werr)) {
963 return -1;
966 ret = fn(conf_ctx, argc, argv);
968 smbconf_shutdown(conf_ctx);
970 return ret;
974 * We need a functable struct of our own, because the
975 * functions are called through a wrapper that handles
976 * the opening and closing of the configuration, and so on.
978 struct conf_functable {
979 const char *funcname;
980 int (*fn)(struct smbconf_ctx *ctx, int argc, const char **argv);
981 const char *helptext;
985 * This imitates net_run_function2 but calls the main functions
986 * through the wrapper net_conf_wrap_function().
988 static int net_conf_run_function(int argc, const char **argv,
989 const char *whoami,
990 struct conf_functable *table)
992 int i;
994 if (argc != 0) {
995 for (i=0; table[i].funcname; i++) {
996 if (StrCaseCmp(argv[0], table[i].funcname) == 0)
997 return net_conf_wrap_function(table[i].fn,
998 argc-1,
999 argv+1);
1003 for (i=0; table[i].funcname; i++) {
1004 d_printf("%s %-15s %s\n", whoami, table[i].funcname,
1005 table[i].helptext);
1008 return -1;
1012 * Entry-point for all the CONF functions.
1015 int net_conf(int argc, const char **argv)
1017 int ret = -1;
1018 struct conf_functable func_table[] = {
1019 {"list", net_conf_list,
1020 "Dump the complete configuration in smb.conf like format."},
1021 {"import", net_conf_import,
1022 "Import configuration from file in smb.conf format."},
1023 {"listshares", net_conf_listshares,
1024 "List the share names."},
1025 {"drop", net_conf_drop,
1026 "Delete the complete configuration."},
1027 {"showshare", net_conf_showshare,
1028 "Show the definition of a share."},
1029 {"addshare", net_conf_addshare,
1030 "Create a new share."},
1031 {"delshare", net_conf_delshare,
1032 "Delete a share."},
1033 {"setparm", net_conf_setparm,
1034 "Store a parameter."},
1035 {"getparm", net_conf_getparm,
1036 "Retrieve the value of a parameter."},
1037 {"delparm", net_conf_delparm,
1038 "Delete a parameter."},
1039 {"getincludes", net_conf_getincludes,
1040 "Show the includes of a share definition."},
1041 {"setincludes", net_conf_setincludes,
1042 "Set includes for a share."},
1043 {"delincludes", net_conf_delincludes,
1044 "Delete includes from a share definition."},
1045 {NULL, NULL, NULL}
1048 ret = net_conf_run_function(argc, argv, "net conf", func_table);
1050 return ret;