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.
31 #include "system/filesys.h"
32 #include "utils/net.h"
33 #include "lib/smbconf/smbconf.h"
34 #include "lib/smbconf/smbconf_init.h"
35 #include "lib/smbconf/smbconf_reg.h"
37 /**********************************************************************
41 **********************************************************************/
43 static int net_conf_list_usage(struct net_context *c, int argc,
46 d_printf("%s net conf list\n", _("Usage:"));
50 static int net_conf_import_usage(struct net_context *c, int argc,
55 _(" net conf import [--test|-T] <filename> "
57 "\t[--test|-T] testmode - do not act, just print "
58 "what would be done\n"
59 "\t<servicename> only import service <servicename>, "
60 "ignore the rest\n"));
64 static int net_conf_listshares_usage(struct net_context *c, int argc,
67 d_printf("%s\nnet conf listshares\n", _("Usage:"));
71 static int net_conf_drop_usage(struct net_context *c, int argc,
74 d_printf("%s\nnet conf drop\n", _("Usage:"));
78 static int net_conf_showshare_usage(struct net_context *c, int argc,
83 _("net conf showshare <sharename>\n"));
87 static int net_conf_addshare_usage(struct net_context *c, int argc,
92 _(" net conf addshare <sharename> <path> "
93 "[writeable={y|N} [guest_ok={y|N} [<comment>]]\n"
94 "\t<sharename> the new share name.\n"
95 "\t<path> the path on the filesystem to export.\n"
96 "\twriteable={y|N} set \"writeable to \"yes\" or "
97 "\"no\" (default) on this share.\n"
98 "\tguest_ok={y|N} set \"guest ok\" to \"yes\" or "
99 "\"no\" (default) on this share.\n"
100 "\t<comment> optional comment for the new share.\n"));
104 static int net_conf_delshare_usage(struct net_context *c, int argc,
109 _("net conf delshare <sharename>\n"));
113 static int net_conf_setparm_usage(struct net_context *c, int argc,
118 _(" net conf setparm <section> <param> <value>\n"));
122 static int net_conf_getparm_usage(struct net_context *c, int argc,
127 _(" net conf getparm <section> <param>\n"));
131 static int net_conf_delparm_usage(struct net_context *c, int argc,
136 _(" net conf delparm <section> <param>\n"));
140 static int net_conf_getincludes_usage(struct net_context *c, int argc,
145 _(" net conf getincludes <section>\n"));
149 static int net_conf_setincludes_usage(struct net_context *c, int argc,
154 _(" net conf setincludes <section> [<filename>]*\n"));
158 static int net_conf_delincludes_usage(struct net_context *c, int argc,
163 _(" net conf delincludes <section>\n"));
168 /**********************************************************************
172 **********************************************************************/
175 * This functions process a service previously loaded with libsmbconf.
177 static WERROR import_process_service(struct net_context *c,
178 struct smbconf_ctx *conf_ctx,
179 struct smbconf_service *service)
182 WERROR werr = WERR_OK;
183 uint32_t num_includes = 0;
184 char **includes = NULL;
185 TALLOC_CTX *mem_ctx = talloc_stackframe();
187 if (c->opt_testmode) {
188 const char *indent = "";
189 if (service->name != NULL) {
190 d_printf("[%s]\n", service->name);
193 for (idx = 0; idx < service->num_params; idx++) {
194 d_printf("%s%s = %s\n", indent,
195 service->param_names[idx],
196 service->param_values[idx]);
202 if (smbconf_share_exists(conf_ctx, service->name)) {
203 werr = smbconf_delete_share(conf_ctx, service->name);
204 if (!W_ERROR_IS_OK(werr)) {
208 werr = smbconf_create_share(conf_ctx, service->name);
209 if (!W_ERROR_IS_OK(werr)) {
213 for (idx = 0; idx < service->num_params; idx ++) {
214 if (strequal(service->param_names[idx], "include")) {
215 includes = TALLOC_REALLOC_ARRAY(mem_ctx,
219 if (includes == NULL) {
223 includes[num_includes] = talloc_strdup(includes,
224 service->param_values[idx]);
225 if (includes[num_includes] == NULL) {
231 werr = smbconf_set_parameter(conf_ctx,
233 service->param_names[idx],
234 service->param_values[idx]);
235 if (!W_ERROR_IS_OK(werr)) {
237 _("Error in section [%s], parameter \"%s\": %s\n"),
238 service->name, service->param_names[idx],
245 werr = smbconf_set_includes(conf_ctx, service->name, num_includes,
246 (const char **)includes);
249 TALLOC_FREE(mem_ctx);
254 /**********************************************************************
256 * the main conf functions
258 **********************************************************************/
260 static int net_conf_list(struct net_context *c, struct smbconf_ctx *conf_ctx,
261 int argc, const char **argv)
263 WERROR werr = WERR_OK;
267 uint32_t share_count, param_count;
268 struct smbconf_service **shares = NULL;
270 mem_ctx = talloc_stackframe();
272 if (argc != 0 || c->display_usage) {
273 net_conf_list_usage(c, argc, argv);
277 werr = smbconf_get_config(conf_ctx, mem_ctx, &num_shares, &shares);
278 if (!W_ERROR_IS_OK(werr)) {
279 d_fprintf(stderr, _("Error getting config: %s\n"),
284 for (share_count = 0; share_count < num_shares; share_count++) {
285 const char *indent = "";
286 if (shares[share_count]->name != NULL) {
287 d_printf("[%s]\n", shares[share_count]->name);
290 for (param_count = 0;
291 param_count < shares[share_count]->num_params;
294 d_printf("%s%s = %s\n",
296 shares[share_count]->param_names[param_count],
297 shares[share_count]->param_values[param_count]);
305 TALLOC_FREE(mem_ctx);
309 static int net_conf_import(struct net_context *c, struct smbconf_ctx *conf_ctx,
310 int argc, const char **argv)
313 const char *filename = NULL;
314 const char *servicename = NULL;
315 char *conf_source = NULL;
317 struct smbconf_ctx *txt_ctx;
321 if (c->display_usage)
322 return net_conf_import_usage(c, argc, argv);
324 mem_ctx = talloc_stackframe();
329 net_conf_import_usage(c, argc, argv);
332 servicename = talloc_strdup(mem_ctx, argv[1]);
333 if (servicename == NULL) {
334 d_printf(_("error: out of memory!\n"));
342 DEBUG(3,("net_conf_import: reading configuration from file %s.\n",
345 conf_source = talloc_asprintf(mem_ctx, "file:%s", filename);
346 if (conf_source == NULL) {
347 d_printf(_("error: out of memory!\n"));
351 err = smbconf_init(mem_ctx, &txt_ctx, conf_source);
352 if (!SBC_ERROR_IS_OK(err)) {
353 d_printf(_("error loading file '%s': %s\n"), filename,
354 sbcErrorString(err));
355 werr = WERR_NO_SUCH_SERVICE;
359 if (c->opt_testmode) {
360 d_printf(_("\nTEST MODE - "
361 "would import the following configuration:\n\n"));
364 if (servicename != NULL) {
365 struct smbconf_service *service = NULL;
367 werr = smbconf_get_share(txt_ctx, mem_ctx,
370 if (!W_ERROR_IS_OK(werr)) {
374 werr = smbconf_transaction_start(conf_ctx);
375 if (!W_ERROR_IS_OK(werr)) {
376 d_printf(_("error starting transaction: %s\n"),
381 werr = import_process_service(c, conf_ctx, service);
382 if (!W_ERROR_IS_OK(werr)) {
386 struct smbconf_service **services = NULL;
387 uint32_t num_shares, sidx;
389 werr = smbconf_get_config(txt_ctx, mem_ctx,
392 if (!W_ERROR_IS_OK(werr)) {
395 if (!c->opt_testmode) {
396 werr = smbconf_drop(conf_ctx);
397 if (!W_ERROR_IS_OK(werr)) {
403 * Wrap the importing of shares into a transaction,
404 * but only 100 at a time, in order to save memory.
405 * The allocated memory accumulates across the actions
406 * within the transaction, and for me, some 1500
407 * imported shares, the MAX_TALLOC_SIZE of 256 MB
410 werr = smbconf_transaction_start(conf_ctx);
411 if (!W_ERROR_IS_OK(werr)) {
412 d_printf(_("error starting transaction: %s\n"),
417 for (sidx = 0; sidx < num_shares; sidx++) {
418 werr = import_process_service(c, conf_ctx,
420 if (!W_ERROR_IS_OK(werr)) {
428 werr = smbconf_transaction_commit(conf_ctx);
429 if (!W_ERROR_IS_OK(werr)) {
430 d_printf(_("error committing transaction: "
435 werr = smbconf_transaction_start(conf_ctx);
436 if (!W_ERROR_IS_OK(werr)) {
437 d_printf(_("error starting transaction: %s\n"),
444 werr = smbconf_transaction_commit(conf_ctx);
445 if (!W_ERROR_IS_OK(werr)) {
446 d_printf(_("error committing transaction: %s\n"),
455 werr = smbconf_transaction_cancel(conf_ctx);
456 if (!W_ERROR_IS_OK(werr)) {
457 d_printf(_("error cancelling transaction: %s\n"),
462 TALLOC_FREE(mem_ctx);
466 static int net_conf_listshares(struct net_context *c,
467 struct smbconf_ctx *conf_ctx, int argc,
470 WERROR werr = WERR_OK;
472 uint32_t count, num_shares = 0;
473 char **share_names = NULL;
476 mem_ctx = talloc_stackframe();
478 if (argc != 0 || c->display_usage) {
479 net_conf_listshares_usage(c, argc, argv);
483 werr = smbconf_get_share_names(conf_ctx, mem_ctx, &num_shares,
485 if (!W_ERROR_IS_OK(werr)) {
489 for (count = 0; count < num_shares; count++)
491 d_printf("%s\n", share_names[count]);
497 TALLOC_FREE(mem_ctx);
501 static int net_conf_drop(struct net_context *c, struct smbconf_ctx *conf_ctx,
502 int argc, const char **argv)
507 if (argc != 0 || c->display_usage) {
508 net_conf_drop_usage(c, argc, argv);
512 werr = smbconf_drop(conf_ctx);
513 if (!W_ERROR_IS_OK(werr)) {
514 d_fprintf(stderr, _("Error deleting configuration: %s\n"),
525 static int net_conf_showshare(struct net_context *c,
526 struct smbconf_ctx *conf_ctx, int argc,
530 WERROR werr = WERR_OK;
531 const char *sharename = NULL;
534 struct smbconf_service *service = NULL;
536 mem_ctx = talloc_stackframe();
538 if (argc != 1 || c->display_usage) {
539 net_conf_showshare_usage(c, argc, argv);
543 sharename = talloc_strdup(mem_ctx, argv[0]);
544 if (sharename == NULL) {
545 d_printf("error: out of memory!\n");
549 werr = smbconf_get_share(conf_ctx, mem_ctx, sharename, &service);
550 if (!W_ERROR_IS_OK(werr)) {
551 d_printf(_("error getting share parameters: %s\n"),
556 d_printf("[%s]\n", service->name);
558 for (count = 0; count < service->num_params; count++) {
559 d_printf("\t%s = %s\n", service->param_names[count],
560 service->param_values[count]);
566 TALLOC_FREE(mem_ctx);
571 * Add a share, with a couple of standard parameters, partly optional.
573 * This is a high level utility function of the net conf utility,
574 * not a direct frontend to the smbconf API.
576 static int net_conf_addshare(struct net_context *c,
577 struct smbconf_ctx *conf_ctx, int argc,
581 WERROR werr = WERR_OK;
582 char *sharename = NULL;
583 const char *path = NULL;
584 const char *comment = NULL;
585 const char *guest_ok = "no";
586 const char *writeable = "no";
587 SMB_STRUCT_STAT sbuf;
588 TALLOC_CTX *mem_ctx = talloc_stackframe();
590 if (c->display_usage) {
591 net_conf_addshare_usage(c, argc, argv);
600 net_conf_addshare_usage(c, argc, argv);
605 if (!strnequal(argv[3], "guest_ok=", 9)) {
606 net_conf_addshare_usage(c, argc, argv);
609 switch (argv[3][9]) {
619 net_conf_addshare_usage(c, argc, argv);
623 if (!strnequal(argv[2], "writeable=", 10)) {
624 net_conf_addshare_usage(c, argc, argv);
627 switch (argv[2][10]) {
637 net_conf_addshare_usage(c, argc, argv);
642 sharename = talloc_strdup(mem_ctx, argv[0]);
643 if (sharename == NULL) {
644 d_printf(_("error: out of memory!\n"));
655 /* validate share name */
657 if (!validate_net_name(sharename, INVALID_SHARENAME_CHARS,
660 d_fprintf(stderr, _("ERROR: share name %s contains "
661 "invalid characters (any of %s)\n"),
662 sharename, INVALID_SHARENAME_CHARS);
666 if (strequal(sharename, GLOBAL_NAME)) {
668 _("ERROR: 'global' is not a valid share name.\n"));
672 if (smbconf_share_exists(conf_ctx, sharename)) {
673 d_fprintf(stderr, _("ERROR: share %s already exists.\n"),
680 if (path[0] != '/') {
682 _("Error: path '%s' is not an absolute path.\n"),
687 if (sys_stat(path, &sbuf, false) != 0) {
689 _("ERROR: cannot stat path '%s' to ensure "
690 "this is a directory.\n"
691 "Error was '%s'.\n"),
692 path, strerror(errno));
696 if (!S_ISDIR(sbuf.st_ex_mode)) {
698 _("ERROR: path '%s' is not a directory.\n"),
704 * start a transaction
707 werr = smbconf_transaction_start(conf_ctx);
708 if (!W_ERROR_IS_OK(werr)) {
709 d_printf("error starting transaction: %s\n",
718 werr = smbconf_create_share(conf_ctx, sharename);
719 if (!W_ERROR_IS_OK(werr)) {
720 d_fprintf(stderr, _("Error creating share %s: %s\n"),
721 sharename, win_errstr(werr));
726 * fill the share with parameters
729 werr = smbconf_set_parameter(conf_ctx, sharename, "path", path);
730 if (!W_ERROR_IS_OK(werr)) {
731 d_fprintf(stderr, _("Error setting parameter %s: %s\n"),
732 "path", win_errstr(werr));
736 if (comment != NULL) {
737 werr = smbconf_set_parameter(conf_ctx, sharename, "comment",
739 if (!W_ERROR_IS_OK(werr)) {
740 d_fprintf(stderr, _("Error setting parameter %s: %s\n"),
741 "comment", win_errstr(werr));
746 werr = smbconf_set_parameter(conf_ctx, sharename, "guest ok", guest_ok);
747 if (!W_ERROR_IS_OK(werr)) {
748 d_fprintf(stderr, _("Error setting parameter %s: %s\n"),
749 "'guest ok'", win_errstr(werr));
753 werr = smbconf_set_parameter(conf_ctx, sharename, "writeable",
755 if (!W_ERROR_IS_OK(werr)) {
756 d_fprintf(stderr, _("Error setting parameter %s: %s\n"),
757 "writeable", win_errstr(werr));
762 * commit the whole thing
765 werr = smbconf_transaction_commit(conf_ctx);
766 if (!W_ERROR_IS_OK(werr)) {
767 d_printf("error committing transaction: %s\n",
776 werr = smbconf_transaction_cancel(conf_ctx);
777 if (!W_ERROR_IS_OK(werr)) {
778 d_printf("error cancelling transaction: %s\n",
783 TALLOC_FREE(mem_ctx);
787 static int net_conf_delshare(struct net_context *c,
788 struct smbconf_ctx *conf_ctx, int argc,
792 const char *sharename = NULL;
793 WERROR werr = WERR_OK;
794 TALLOC_CTX *mem_ctx = talloc_stackframe();
796 if (argc != 1 || c->display_usage) {
797 net_conf_delshare_usage(c, argc, argv);
800 sharename = talloc_strdup(mem_ctx, argv[0]);
801 if (sharename == NULL) {
802 d_printf(_("error: out of memory!\n"));
806 werr = smbconf_delete_share(conf_ctx, sharename);
807 if (!W_ERROR_IS_OK(werr)) {
808 d_fprintf(stderr, _("Error deleting share %s: %s\n"),
809 sharename, win_errstr(werr));
815 TALLOC_FREE(mem_ctx);
819 static int net_conf_setparm(struct net_context *c, struct smbconf_ctx *conf_ctx,
820 int argc, const char **argv)
823 WERROR werr = WERR_OK;
824 char *service = NULL;
826 const char *value_str = NULL;
827 TALLOC_CTX *mem_ctx = talloc_stackframe();
829 if (argc != 3 || c->display_usage) {
830 net_conf_setparm_usage(c, argc, argv);
834 * NULL service name means "dangling parameters" to libsmbconf.
835 * We use the empty string from the command line for this purpose.
837 if (strlen(argv[0]) != 0) {
838 service = talloc_strdup(mem_ctx, argv[0]);
839 if (service == NULL) {
840 d_printf(_("error: out of memory!\n"));
844 param = strlower_talloc(mem_ctx, argv[1]);
846 d_printf(_("error: out of memory!\n"));
851 werr = smbconf_transaction_start(conf_ctx);
852 if (!W_ERROR_IS_OK(werr)) {
853 d_printf(_("error starting transaction: %s\n"),
858 if (!smbconf_share_exists(conf_ctx, service)) {
859 werr = smbconf_create_share(conf_ctx, service);
860 if (!W_ERROR_IS_OK(werr)) {
861 d_fprintf(stderr, _("Error creating share '%s': %s\n"),
862 service, win_errstr(werr));
867 werr = smbconf_set_parameter(conf_ctx, service, param, value_str);
869 if (!W_ERROR_IS_OK(werr)) {
870 d_fprintf(stderr, _("Error setting value '%s': %s\n"),
871 param, win_errstr(werr));
875 werr = smbconf_transaction_commit(conf_ctx);
876 if (!W_ERROR_IS_OK(werr)) {
877 d_printf(_("error committing transaction: %s\n"),
886 werr = smbconf_transaction_cancel(conf_ctx);
887 if (!W_ERROR_IS_OK(werr)) {
888 d_printf(_("error cancelling transaction: %s\n"),
893 TALLOC_FREE(mem_ctx);
897 static int net_conf_getparm(struct net_context *c, struct smbconf_ctx *conf_ctx,
898 int argc, const char **argv)
901 WERROR werr = WERR_OK;
902 char *service = NULL;
907 mem_ctx = talloc_stackframe();
909 if (argc != 2 || c->display_usage) {
910 net_conf_getparm_usage(c, argc, argv);
914 * NULL service name means "dangling parameters" to libsmbconf.
915 * We use the empty string from the command line for this purpose.
917 if (strlen(argv[0]) != 0) {
918 service = talloc_strdup(mem_ctx, argv[0]);
919 if (service == NULL) {
920 d_printf(_("error: out of memory!\n"));
924 param = strlower_talloc(mem_ctx, argv[1]);
926 d_printf(_("error: out of memory!\n"));
930 werr = smbconf_get_parameter(conf_ctx, mem_ctx, service, param, &valstr);
932 if (W_ERROR_EQUAL(werr, WERR_NO_SUCH_SERVICE)) {
934 _("Error: given service '%s' does not exist.\n"),
937 } else if (W_ERROR_EQUAL(werr, WERR_INVALID_PARAM)) {
939 _("Error: given parameter '%s' is not set.\n"),
942 } else if (!W_ERROR_IS_OK(werr)) {
943 d_fprintf(stderr, _("Error getting value '%s': %s.\n"),
944 param, win_errstr(werr));
948 d_printf("%s\n", valstr);
952 TALLOC_FREE(mem_ctx);
956 static int net_conf_delparm(struct net_context *c, struct smbconf_ctx *conf_ctx,
957 int argc, const char **argv)
960 WERROR werr = WERR_OK;
961 char *service = NULL;
963 TALLOC_CTX *mem_ctx = talloc_stackframe();
965 if (argc != 2 || c->display_usage) {
966 net_conf_delparm_usage(c, argc, argv);
970 * NULL service name means "dangling parameters" to libsmbconf.
971 * We use the empty string from the command line for this purpose.
973 if (strlen(argv[0]) != 0) {
974 service = talloc_strdup(mem_ctx, argv[0]);
975 if (service == NULL) {
976 d_printf(_("error: out of memory!\n"));
980 param = strlower_talloc(mem_ctx, argv[1]);
982 d_printf("error: out of memory!\n");
986 werr = smbconf_delete_parameter(conf_ctx, service, param);
988 if (W_ERROR_EQUAL(werr, WERR_NO_SUCH_SERVICE)) {
990 _("Error: given service '%s' does not exist.\n"),
993 } else if (W_ERROR_EQUAL(werr, WERR_INVALID_PARAM)) {
995 _("Error: given parameter '%s' is not set.\n"),
998 } else if (!W_ERROR_IS_OK(werr)) {
999 d_fprintf(stderr, _("Error deleting value '%s': %s.\n"),
1000 param, win_errstr(werr));
1007 TALLOC_FREE(mem_ctx);
1011 static int net_conf_getincludes(struct net_context *c,
1012 struct smbconf_ctx *conf_ctx,
1013 int argc, const char **argv)
1016 uint32_t num_includes;
1019 char **includes = NULL;
1021 TALLOC_CTX *mem_ctx = talloc_stackframe();
1023 if (argc != 1 || c->display_usage) {
1024 net_conf_getincludes_usage(c, argc, argv);
1028 service = talloc_strdup(mem_ctx, argv[0]);
1029 if (service == NULL) {
1030 d_printf(_("error: out of memory!\n"));
1034 werr = smbconf_get_includes(conf_ctx, mem_ctx, service,
1035 &num_includes, &includes);
1036 if (!W_ERROR_IS_OK(werr)) {
1037 d_printf(_("error getting includes: %s\n"), win_errstr(werr));
1041 for (count = 0; count < num_includes; count++) {
1042 d_printf("include = %s\n", includes[count]);
1048 TALLOC_FREE(mem_ctx);
1052 static int net_conf_setincludes(struct net_context *c,
1053 struct smbconf_ctx *conf_ctx,
1054 int argc, const char **argv)
1058 uint32_t num_includes;
1059 const char **includes;
1061 TALLOC_CTX *mem_ctx = talloc_stackframe();
1063 if (argc < 1 || c->display_usage) {
1064 net_conf_setincludes_usage(c, argc, argv);
1068 service = talloc_strdup(mem_ctx, argv[0]);
1069 if (service == NULL) {
1070 d_printf(_("error: out of memory!\n"));
1074 num_includes = argc - 1;
1075 if (num_includes == 0) {
1078 includes = argv + 1;
1081 werr = smbconf_set_includes(conf_ctx, service, num_includes, includes);
1082 if (!W_ERROR_IS_OK(werr)) {
1083 d_printf(_("error setting includes: %s\n"), win_errstr(werr));
1090 TALLOC_FREE(mem_ctx);
1094 static int net_conf_delincludes(struct net_context *c,
1095 struct smbconf_ctx *conf_ctx,
1096 int argc, const char **argv)
1101 TALLOC_CTX *mem_ctx = talloc_stackframe();
1103 if (argc != 1 || c->display_usage) {
1104 net_conf_delincludes_usage(c, argc, argv);
1108 service = talloc_strdup(mem_ctx, argv[0]);
1109 if (service == NULL) {
1110 d_printf(_("error: out of memory!\n"));
1114 werr = smbconf_delete_includes(conf_ctx, service);
1115 if (!W_ERROR_IS_OK(werr)) {
1116 d_printf(_("error deleting includes: %s\n"), win_errstr(werr));
1123 TALLOC_FREE(mem_ctx);
1128 /**********************************************************************
1130 * Wrapper and net_conf_run_function mechanism.
1132 **********************************************************************/
1135 * Wrapper function to call the main conf functions.
1136 * The wrapper calls handles opening and closing of the
1139 static int net_conf_wrap_function(struct net_context *c,
1140 int (*fn)(struct net_context *,
1141 struct smbconf_ctx *,
1142 int, const char **),
1143 int argc, const char **argv)
1146 TALLOC_CTX *mem_ctx = talloc_stackframe();
1147 struct smbconf_ctx *conf_ctx;
1150 err = smbconf_init(mem_ctx, &conf_ctx, "registry:");
1151 if (!SBC_ERROR_IS_OK(err)) {
1155 ret = fn(c, conf_ctx, argc, argv);
1157 smbconf_shutdown(conf_ctx);
1163 * We need a functable struct of our own, because the
1164 * functions are called through a wrapper that handles
1165 * the opening and closing of the configuration, and so on.
1167 struct conf_functable {
1168 const char *funcname;
1169 int (*fn)(struct net_context *c, struct smbconf_ctx *ctx, int argc,
1171 int valid_transports;
1172 const char *description;
1177 * This imitates net_run_function but calls the main functions
1178 * through the wrapper net_conf_wrap_function().
1180 static int net_conf_run_function(struct net_context *c, int argc,
1181 const char **argv, const char *whoami,
1182 struct conf_functable *table)
1187 for (i=0; table[i].funcname; i++) {
1188 if (StrCaseCmp(argv[0], table[i].funcname) == 0)
1189 return net_conf_wrap_function(c, table[i].fn,
1195 d_printf(_("Usage:\n"));
1196 for (i=0; table[i].funcname; i++) {
1197 if (c->display_usage == false)
1198 d_printf("%s %-15s %s\n", whoami, table[i].funcname,
1199 table[i].description);
1201 d_printf("%s\n", table[i].usage);
1204 return c->display_usage?0:-1;
1208 * Entry-point for all the CONF functions.
1211 int net_conf(struct net_context *c, int argc, const char **argv)
1214 struct conf_functable func_table[] = {
1218 NET_TRANSPORT_LOCAL,
1219 N_("Dump the complete configuration in smb.conf like "
1221 N_("net conf list\n"
1222 " Dump the complete configuration in smb.conf "
1229 NET_TRANSPORT_LOCAL,
1230 N_("Import configuration from file in smb.conf "
1232 N_("net conf import\n"
1233 " Import configuration from file in smb.conf "
1238 net_conf_listshares,
1239 NET_TRANSPORT_LOCAL,
1240 N_("List the share names."),
1241 N_("net conf listshares\n"
1242 " List the share names.")
1247 NET_TRANSPORT_LOCAL,
1248 N_("Delete the complete configuration."),
1249 N_("net conf drop\n"
1250 " Delete the complete configuration.")
1255 NET_TRANSPORT_LOCAL,
1256 N_("Show the definition of a share."),
1257 N_("net conf showshare\n"
1258 " Show the definition of a share.")
1263 NET_TRANSPORT_LOCAL,
1264 N_("Create a new share."),
1265 N_("net conf addshare\n"
1266 " Create a new share.")
1271 NET_TRANSPORT_LOCAL,
1272 N_("Delete a share."),
1273 N_("net conf delshare\n"
1279 NET_TRANSPORT_LOCAL,
1280 N_("Store a parameter."),
1281 N_("net conf setparm\n"
1282 " Store a parameter.")
1287 NET_TRANSPORT_LOCAL,
1288 N_("Retrieve the value of a parameter."),
1289 N_("net conf getparm\n"
1290 " Retrieve the value of a parameter.")
1295 NET_TRANSPORT_LOCAL,
1296 N_("Delete a parameter."),
1297 N_("net conf delparm\n"
1298 " Delete a parameter.")
1302 net_conf_getincludes,
1303 NET_TRANSPORT_LOCAL,
1304 N_("Show the includes of a share definition."),
1305 N_("net conf getincludes\n"
1306 " Show the includes of a share definition.")
1310 net_conf_setincludes,
1311 NET_TRANSPORT_LOCAL,
1312 N_("Set includes for a share."),
1313 N_("net conf setincludes\n"
1314 " Set includes for a share.")
1318 net_conf_delincludes,
1319 NET_TRANSPORT_LOCAL,
1320 N_("Delete includes from a share definition."),
1321 N_("net conf setincludes\n"
1322 " Delete includes from a share definition.")
1324 {NULL, NULL, 0, NULL, NULL}
1327 ret = net_conf_run_function(c, argc, argv, "net conf", func_table);