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;
320 if (c->display_usage)
321 return net_conf_import_usage(c, argc, argv);
323 mem_ctx = talloc_stackframe();
328 net_conf_import_usage(c, argc, argv);
331 servicename = talloc_strdup(mem_ctx, argv[1]);
332 if (servicename == NULL) {
333 d_printf(_("error: out of memory!\n"));
341 DEBUG(3,("net_conf_import: reading configuration from file %s.\n",
344 conf_source = talloc_asprintf(mem_ctx, "file:%s", filename);
345 if (conf_source == NULL) {
346 d_printf(_("error: out of memory!\n"));
350 werr = smbconf_init(mem_ctx, &txt_ctx, conf_source);
351 if (!W_ERROR_IS_OK(werr)) {
352 d_printf(_("error loading file '%s': %s\n"), filename,
357 if (c->opt_testmode) {
358 d_printf(_("\nTEST MODE - "
359 "would import the following configuration:\n\n"));
362 if (servicename != NULL) {
363 struct smbconf_service *service = NULL;
365 werr = smbconf_get_share(txt_ctx, mem_ctx,
368 if (!W_ERROR_IS_OK(werr)) {
372 werr = smbconf_transaction_start(conf_ctx);
373 if (!W_ERROR_IS_OK(werr)) {
374 d_printf(_("error starting transaction: %s\n"),
379 werr = import_process_service(c, conf_ctx, service);
380 if (!W_ERROR_IS_OK(werr)) {
384 struct smbconf_service **services = NULL;
385 uint32_t num_shares, sidx;
387 werr = smbconf_get_config(txt_ctx, mem_ctx,
390 if (!W_ERROR_IS_OK(werr)) {
393 if (!c->opt_testmode) {
394 werr = smbconf_drop(conf_ctx);
395 if (!W_ERROR_IS_OK(werr)) {
401 * Wrap the importing of shares into a transaction,
402 * but only 100 at a time, in order to save memory.
403 * The allocated memory accumulates across the actions
404 * within the transaction, and for me, some 1500
405 * imported shares, the MAX_TALLOC_SIZE of 256 MB
408 werr = smbconf_transaction_start(conf_ctx);
409 if (!W_ERROR_IS_OK(werr)) {
410 d_printf(_("error starting transaction: %s\n"),
415 for (sidx = 0; sidx < num_shares; sidx++) {
416 werr = import_process_service(c, conf_ctx,
418 if (!W_ERROR_IS_OK(werr)) {
426 werr = smbconf_transaction_commit(conf_ctx);
427 if (!W_ERROR_IS_OK(werr)) {
428 d_printf(_("error committing transaction: "
433 werr = smbconf_transaction_start(conf_ctx);
434 if (!W_ERROR_IS_OK(werr)) {
435 d_printf(_("error starting transaction: %s\n"),
442 werr = smbconf_transaction_commit(conf_ctx);
443 if (!W_ERROR_IS_OK(werr)) {
444 d_printf(_("error committing transaction: %s\n"),
453 werr = smbconf_transaction_cancel(conf_ctx);
454 if (!W_ERROR_IS_OK(werr)) {
455 d_printf(_("error cancelling transaction: %s\n"),
460 TALLOC_FREE(mem_ctx);
464 static int net_conf_listshares(struct net_context *c,
465 struct smbconf_ctx *conf_ctx, int argc,
468 WERROR werr = WERR_OK;
470 uint32_t count, num_shares = 0;
471 char **share_names = NULL;
474 mem_ctx = talloc_stackframe();
476 if (argc != 0 || c->display_usage) {
477 net_conf_listshares_usage(c, argc, argv);
481 werr = smbconf_get_share_names(conf_ctx, mem_ctx, &num_shares,
483 if (!W_ERROR_IS_OK(werr)) {
487 for (count = 0; count < num_shares; count++)
489 d_printf("%s\n", share_names[count]);
495 TALLOC_FREE(mem_ctx);
499 static int net_conf_drop(struct net_context *c, struct smbconf_ctx *conf_ctx,
500 int argc, const char **argv)
505 if (argc != 0 || c->display_usage) {
506 net_conf_drop_usage(c, argc, argv);
510 werr = smbconf_drop(conf_ctx);
511 if (!W_ERROR_IS_OK(werr)) {
512 d_fprintf(stderr, _("Error deleting configuration: %s\n"),
523 static int net_conf_showshare(struct net_context *c,
524 struct smbconf_ctx *conf_ctx, int argc,
528 WERROR werr = WERR_OK;
529 const char *sharename = NULL;
532 struct smbconf_service *service = NULL;
534 mem_ctx = talloc_stackframe();
536 if (argc != 1 || c->display_usage) {
537 net_conf_showshare_usage(c, argc, argv);
541 sharename = talloc_strdup(mem_ctx, argv[0]);
542 if (sharename == NULL) {
543 d_printf("error: out of memory!\n");
547 werr = smbconf_get_share(conf_ctx, mem_ctx, sharename, &service);
548 if (!W_ERROR_IS_OK(werr)) {
549 d_printf(_("error getting share parameters: %s\n"),
554 d_printf("[%s]\n", service->name);
556 for (count = 0; count < service->num_params; count++) {
557 d_printf("\t%s = %s\n", service->param_names[count],
558 service->param_values[count]);
564 TALLOC_FREE(mem_ctx);
569 * Add a share, with a couple of standard parameters, partly optional.
571 * This is a high level utility function of the net conf utility,
572 * not a direct frontend to the smbconf API.
574 static int net_conf_addshare(struct net_context *c,
575 struct smbconf_ctx *conf_ctx, int argc,
579 WERROR werr = WERR_OK;
580 char *sharename = NULL;
581 const char *path = NULL;
582 const char *comment = NULL;
583 const char *guest_ok = "no";
584 const char *writeable = "no";
585 SMB_STRUCT_STAT sbuf;
586 TALLOC_CTX *mem_ctx = talloc_stackframe();
588 if (c->display_usage) {
589 net_conf_addshare_usage(c, argc, argv);
598 net_conf_addshare_usage(c, argc, argv);
603 if (!strnequal(argv[3], "guest_ok=", 9)) {
604 net_conf_addshare_usage(c, argc, argv);
607 switch (argv[3][9]) {
617 net_conf_addshare_usage(c, argc, argv);
621 if (!strnequal(argv[2], "writeable=", 10)) {
622 net_conf_addshare_usage(c, argc, argv);
625 switch (argv[2][10]) {
635 net_conf_addshare_usage(c, argc, argv);
640 sharename = talloc_strdup(mem_ctx, argv[0]);
641 if (sharename == NULL) {
642 d_printf(_("error: out of memory!\n"));
653 /* validate share name */
655 if (!validate_net_name(sharename, INVALID_SHARENAME_CHARS,
658 d_fprintf(stderr, _("ERROR: share name %s contains "
659 "invalid characters (any of %s)\n"),
660 sharename, INVALID_SHARENAME_CHARS);
664 if (strequal(sharename, GLOBAL_NAME)) {
666 _("ERROR: 'global' is not a valid share name.\n"));
670 if (smbconf_share_exists(conf_ctx, sharename)) {
671 d_fprintf(stderr, _("ERROR: share %s already exists.\n"),
678 if (path[0] != '/') {
680 _("Error: path '%s' is not an absolute path.\n"),
685 if (sys_stat(path, &sbuf, false) != 0) {
687 _("ERROR: cannot stat path '%s' to ensure "
688 "this is a directory.\n"
689 "Error was '%s'.\n"),
690 path, strerror(errno));
694 if (!S_ISDIR(sbuf.st_ex_mode)) {
696 _("ERROR: path '%s' is not a directory.\n"),
702 * start a transaction
705 werr = smbconf_transaction_start(conf_ctx);
706 if (!W_ERROR_IS_OK(werr)) {
707 d_printf("error starting transaction: %s\n",
716 werr = smbconf_create_share(conf_ctx, sharename);
717 if (!W_ERROR_IS_OK(werr)) {
718 d_fprintf(stderr, _("Error creating share %s: %s\n"),
719 sharename, win_errstr(werr));
724 * fill the share with parameters
727 werr = smbconf_set_parameter(conf_ctx, sharename, "path", path);
728 if (!W_ERROR_IS_OK(werr)) {
729 d_fprintf(stderr, _("Error setting parameter %s: %s\n"),
730 "path", win_errstr(werr));
734 if (comment != NULL) {
735 werr = smbconf_set_parameter(conf_ctx, sharename, "comment",
737 if (!W_ERROR_IS_OK(werr)) {
738 d_fprintf(stderr, _("Error setting parameter %s: %s\n"),
739 "comment", win_errstr(werr));
744 werr = smbconf_set_parameter(conf_ctx, sharename, "guest ok", guest_ok);
745 if (!W_ERROR_IS_OK(werr)) {
746 d_fprintf(stderr, _("Error setting parameter %s: %s\n"),
747 "'guest ok'", win_errstr(werr));
751 werr = smbconf_set_parameter(conf_ctx, sharename, "writeable",
753 if (!W_ERROR_IS_OK(werr)) {
754 d_fprintf(stderr, _("Error setting parameter %s: %s\n"),
755 "writeable", win_errstr(werr));
760 * commit the whole thing
763 werr = smbconf_transaction_commit(conf_ctx);
764 if (!W_ERROR_IS_OK(werr)) {
765 d_printf("error committing transaction: %s\n",
774 werr = smbconf_transaction_cancel(conf_ctx);
775 if (!W_ERROR_IS_OK(werr)) {
776 d_printf("error cancelling transaction: %s\n",
781 TALLOC_FREE(mem_ctx);
785 static int net_conf_delshare(struct net_context *c,
786 struct smbconf_ctx *conf_ctx, int argc,
790 const char *sharename = NULL;
791 WERROR werr = WERR_OK;
792 TALLOC_CTX *mem_ctx = talloc_stackframe();
794 if (argc != 1 || c->display_usage) {
795 net_conf_delshare_usage(c, argc, argv);
798 sharename = talloc_strdup(mem_ctx, argv[0]);
799 if (sharename == NULL) {
800 d_printf(_("error: out of memory!\n"));
804 werr = smbconf_delete_share(conf_ctx, sharename);
805 if (!W_ERROR_IS_OK(werr)) {
806 d_fprintf(stderr, _("Error deleting share %s: %s\n"),
807 sharename, win_errstr(werr));
813 TALLOC_FREE(mem_ctx);
817 static int net_conf_setparm(struct net_context *c, struct smbconf_ctx *conf_ctx,
818 int argc, const char **argv)
821 WERROR werr = WERR_OK;
822 char *service = NULL;
824 const char *value_str = NULL;
825 TALLOC_CTX *mem_ctx = talloc_stackframe();
827 if (argc != 3 || c->display_usage) {
828 net_conf_setparm_usage(c, argc, argv);
832 * NULL service name means "dangling parameters" to libsmbconf.
833 * We use the empty string from the command line for this purpose.
835 if (strlen(argv[0]) != 0) {
836 service = talloc_strdup(mem_ctx, argv[0]);
837 if (service == NULL) {
838 d_printf(_("error: out of memory!\n"));
842 param = strlower_talloc(mem_ctx, argv[1]);
844 d_printf(_("error: out of memory!\n"));
849 werr = smbconf_transaction_start(conf_ctx);
850 if (!W_ERROR_IS_OK(werr)) {
851 d_printf(_("error starting transaction: %s\n"),
856 if (!smbconf_share_exists(conf_ctx, service)) {
857 werr = smbconf_create_share(conf_ctx, service);
858 if (!W_ERROR_IS_OK(werr)) {
859 d_fprintf(stderr, _("Error creating share '%s': %s\n"),
860 service, win_errstr(werr));
865 werr = smbconf_set_parameter(conf_ctx, service, param, value_str);
867 if (!W_ERROR_IS_OK(werr)) {
868 d_fprintf(stderr, _("Error setting value '%s': %s\n"),
869 param, win_errstr(werr));
873 werr = smbconf_transaction_commit(conf_ctx);
874 if (!W_ERROR_IS_OK(werr)) {
875 d_printf(_("error committing transaction: %s\n"),
884 werr = smbconf_transaction_cancel(conf_ctx);
885 if (!W_ERROR_IS_OK(werr)) {
886 d_printf(_("error cancelling transaction: %s\n"),
891 TALLOC_FREE(mem_ctx);
895 static int net_conf_getparm(struct net_context *c, struct smbconf_ctx *conf_ctx,
896 int argc, const char **argv)
899 WERROR werr = WERR_OK;
900 char *service = NULL;
905 mem_ctx = talloc_stackframe();
907 if (argc != 2 || c->display_usage) {
908 net_conf_getparm_usage(c, argc, argv);
912 * NULL service name means "dangling parameters" to libsmbconf.
913 * We use the empty string from the command line for this purpose.
915 if (strlen(argv[0]) != 0) {
916 service = talloc_strdup(mem_ctx, argv[0]);
917 if (service == NULL) {
918 d_printf(_("error: out of memory!\n"));
922 param = strlower_talloc(mem_ctx, argv[1]);
924 d_printf(_("error: out of memory!\n"));
928 werr = smbconf_get_parameter(conf_ctx, mem_ctx, service, param, &valstr);
930 if (W_ERROR_EQUAL(werr, WERR_NO_SUCH_SERVICE)) {
932 _("Error: given service '%s' does not exist.\n"),
935 } else if (W_ERROR_EQUAL(werr, WERR_INVALID_PARAM)) {
937 _("Error: given parameter '%s' is not set.\n"),
940 } else if (!W_ERROR_IS_OK(werr)) {
941 d_fprintf(stderr, _("Error getting value '%s': %s.\n"),
942 param, win_errstr(werr));
946 d_printf("%s\n", valstr);
950 TALLOC_FREE(mem_ctx);
954 static int net_conf_delparm(struct net_context *c, struct smbconf_ctx *conf_ctx,
955 int argc, const char **argv)
958 WERROR werr = WERR_OK;
959 char *service = NULL;
961 TALLOC_CTX *mem_ctx = talloc_stackframe();
963 if (argc != 2 || c->display_usage) {
964 net_conf_delparm_usage(c, argc, argv);
968 * NULL service name means "dangling parameters" to libsmbconf.
969 * We use the empty string from the command line for this purpose.
971 if (strlen(argv[0]) != 0) {
972 service = talloc_strdup(mem_ctx, argv[0]);
973 if (service == NULL) {
974 d_printf(_("error: out of memory!\n"));
978 param = strlower_talloc(mem_ctx, argv[1]);
980 d_printf("error: out of memory!\n");
984 werr = smbconf_delete_parameter(conf_ctx, service, param);
986 if (W_ERROR_EQUAL(werr, WERR_NO_SUCH_SERVICE)) {
988 _("Error: given service '%s' does not exist.\n"),
991 } else if (W_ERROR_EQUAL(werr, WERR_INVALID_PARAM)) {
993 _("Error: given parameter '%s' is not set.\n"),
996 } else if (!W_ERROR_IS_OK(werr)) {
997 d_fprintf(stderr, _("Error deleting value '%s': %s.\n"),
998 param, win_errstr(werr));
1005 TALLOC_FREE(mem_ctx);
1009 static int net_conf_getincludes(struct net_context *c,
1010 struct smbconf_ctx *conf_ctx,
1011 int argc, const char **argv)
1014 uint32_t num_includes;
1017 char **includes = NULL;
1019 TALLOC_CTX *mem_ctx = talloc_stackframe();
1021 if (argc != 1 || c->display_usage) {
1022 net_conf_getincludes_usage(c, argc, argv);
1026 service = talloc_strdup(mem_ctx, argv[0]);
1027 if (service == NULL) {
1028 d_printf(_("error: out of memory!\n"));
1032 werr = smbconf_get_includes(conf_ctx, mem_ctx, service,
1033 &num_includes, &includes);
1034 if (!W_ERROR_IS_OK(werr)) {
1035 d_printf(_("error getting includes: %s\n"), win_errstr(werr));
1039 for (count = 0; count < num_includes; count++) {
1040 d_printf("include = %s\n", includes[count]);
1046 TALLOC_FREE(mem_ctx);
1050 static int net_conf_setincludes(struct net_context *c,
1051 struct smbconf_ctx *conf_ctx,
1052 int argc, const char **argv)
1056 uint32_t num_includes;
1057 const char **includes;
1059 TALLOC_CTX *mem_ctx = talloc_stackframe();
1061 if (argc < 1 || c->display_usage) {
1062 net_conf_setincludes_usage(c, argc, argv);
1066 service = talloc_strdup(mem_ctx, argv[0]);
1067 if (service == NULL) {
1068 d_printf(_("error: out of memory!\n"));
1072 num_includes = argc - 1;
1073 if (num_includes == 0) {
1076 includes = argv + 1;
1079 werr = smbconf_set_includes(conf_ctx, service, num_includes, includes);
1080 if (!W_ERROR_IS_OK(werr)) {
1081 d_printf(_("error setting includes: %s\n"), win_errstr(werr));
1088 TALLOC_FREE(mem_ctx);
1092 static int net_conf_delincludes(struct net_context *c,
1093 struct smbconf_ctx *conf_ctx,
1094 int argc, const char **argv)
1099 TALLOC_CTX *mem_ctx = talloc_stackframe();
1101 if (argc != 1 || c->display_usage) {
1102 net_conf_delincludes_usage(c, argc, argv);
1106 service = talloc_strdup(mem_ctx, argv[0]);
1107 if (service == NULL) {
1108 d_printf(_("error: out of memory!\n"));
1112 werr = smbconf_delete_includes(conf_ctx, service);
1113 if (!W_ERROR_IS_OK(werr)) {
1114 d_printf(_("error deleting includes: %s\n"), win_errstr(werr));
1121 TALLOC_FREE(mem_ctx);
1126 /**********************************************************************
1128 * Wrapper and net_conf_run_function mechanism.
1130 **********************************************************************/
1133 * Wrapper function to call the main conf functions.
1134 * The wrapper calls handles opening and closing of the
1137 static int net_conf_wrap_function(struct net_context *c,
1138 int (*fn)(struct net_context *,
1139 struct smbconf_ctx *,
1140 int, const char **),
1141 int argc, const char **argv)
1144 TALLOC_CTX *mem_ctx = talloc_stackframe();
1145 struct smbconf_ctx *conf_ctx;
1148 werr = smbconf_init(mem_ctx, &conf_ctx, "registry:");
1150 if (!W_ERROR_IS_OK(werr)) {
1154 ret = fn(c, conf_ctx, argc, argv);
1156 smbconf_shutdown(conf_ctx);
1162 * We need a functable struct of our own, because the
1163 * functions are called through a wrapper that handles
1164 * the opening and closing of the configuration, and so on.
1166 struct conf_functable {
1167 const char *funcname;
1168 int (*fn)(struct net_context *c, struct smbconf_ctx *ctx, int argc,
1170 int valid_transports;
1171 const char *description;
1176 * This imitates net_run_function but calls the main functions
1177 * through the wrapper net_conf_wrap_function().
1179 static int net_conf_run_function(struct net_context *c, int argc,
1180 const char **argv, const char *whoami,
1181 struct conf_functable *table)
1186 for (i=0; table[i].funcname; i++) {
1187 if (StrCaseCmp(argv[0], table[i].funcname) == 0)
1188 return net_conf_wrap_function(c, table[i].fn,
1194 d_printf(_("Usage:\n"));
1195 for (i=0; table[i].funcname; i++) {
1196 if (c->display_usage == false)
1197 d_printf("%s %-15s %s\n", whoami, table[i].funcname,
1198 table[i].description);
1200 d_printf("%s\n", table[i].usage);
1203 return c->display_usage?0:-1;
1207 * Entry-point for all the CONF functions.
1210 int net_conf(struct net_context *c, int argc, const char **argv)
1213 struct conf_functable func_table[] = {
1217 NET_TRANSPORT_LOCAL,
1218 N_("Dump the complete configuration in smb.conf like "
1220 N_("net conf list\n"
1221 " Dump the complete configuration in smb.conf "
1228 NET_TRANSPORT_LOCAL,
1229 N_("Import configuration from file in smb.conf "
1231 N_("net conf import\n"
1232 " Import configuration from file in smb.conf "
1237 net_conf_listshares,
1238 NET_TRANSPORT_LOCAL,
1239 N_("List the share names."),
1240 N_("net conf listshares\n"
1241 " List the share names.")
1246 NET_TRANSPORT_LOCAL,
1247 N_("Delete the complete configuration."),
1248 N_("net conf drop\n"
1249 " Delete the complete configuration.")
1254 NET_TRANSPORT_LOCAL,
1255 N_("Show the definition of a share."),
1256 N_("net conf showshare\n"
1257 " Show the definition of a share.")
1262 NET_TRANSPORT_LOCAL,
1263 N_("Create a new share."),
1264 N_("net conf addshare\n"
1265 " Create a new share.")
1270 NET_TRANSPORT_LOCAL,
1271 N_("Delete a share."),
1272 N_("net conf delshare\n"
1278 NET_TRANSPORT_LOCAL,
1279 N_("Store a parameter."),
1280 N_("net conf setparm\n"
1281 " Store a parameter.")
1286 NET_TRANSPORT_LOCAL,
1287 N_("Retrieve the value of a parameter."),
1288 N_("net conf getparm\n"
1289 " Retrieve the value of a parameter.")
1294 NET_TRANSPORT_LOCAL,
1295 N_("Delete a parameter."),
1296 N_("net conf delparm\n"
1297 " Delete a parameter.")
1301 net_conf_getincludes,
1302 NET_TRANSPORT_LOCAL,
1303 N_("Show the includes of a share definition."),
1304 N_("net conf getincludes\n"
1305 " Show the includes of a share definition.")
1309 net_conf_setincludes,
1310 NET_TRANSPORT_LOCAL,
1311 N_("Set includes for a share."),
1312 N_("net conf setincludes\n"
1313 " Set includes for a share.")
1317 net_conf_delincludes,
1318 NET_TRANSPORT_LOCAL,
1319 N_("Delete includes from a share definition."),
1320 N_("net conf setincludes\n"
1321 " Delete includes from a share definition.")
1323 {NULL, NULL, 0, NULL, NULL}
1326 ret = net_conf_run_function(c, argc, argv, "net conf", func_table);