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;
184 uint32_t num_includes = 0;
185 char **includes = NULL;
186 TALLOC_CTX *mem_ctx = talloc_stackframe();
188 if (c->opt_testmode) {
189 const char *indent = "";
190 if (service->name != NULL) {
191 d_printf("[%s]\n", service->name);
194 for (idx = 0; idx < service->num_params; idx++) {
195 d_printf("%s%s = %s\n", indent,
196 service->param_names[idx],
197 service->param_values[idx]);
203 if (smbconf_share_exists(conf_ctx, service->name)) {
204 err = smbconf_delete_share(conf_ctx, service->name);
205 if (!SBC_ERROR_IS_OK(err)) {
206 werr = WERR_GENERAL_FAILURE;
210 err = smbconf_create_share(conf_ctx, service->name);
211 if (!SBC_ERROR_IS_OK(err)) {
212 werr = WERR_GENERAL_FAILURE;
216 for (idx = 0; idx < service->num_params; idx ++) {
217 if (strequal(service->param_names[idx], "include")) {
218 includes = TALLOC_REALLOC_ARRAY(mem_ctx,
222 if (includes == NULL) {
226 includes[num_includes] = talloc_strdup(includes,
227 service->param_values[idx]);
228 if (includes[num_includes] == NULL) {
234 err = smbconf_set_parameter(conf_ctx,
236 service->param_names[idx],
237 service->param_values[idx]);
238 if (!SBC_ERROR_IS_OK(err)) {
240 _("Error in section [%s], parameter \"%s\": %s\n"),
241 service->name, service->param_names[idx],
242 sbcErrorString(err));
249 err = smbconf_set_includes(conf_ctx, service->name, num_includes,
250 (const char **)includes);
251 if (!SBC_ERROR_IS_OK(err)) {
258 TALLOC_FREE(mem_ctx);
263 /**********************************************************************
265 * the main conf functions
267 **********************************************************************/
269 static int net_conf_list(struct net_context *c, struct smbconf_ctx *conf_ctx,
270 int argc, const char **argv)
272 WERROR werr = WERR_OK;
276 uint32_t share_count, param_count;
277 struct smbconf_service **shares = NULL;
279 mem_ctx = talloc_stackframe();
281 if (argc != 0 || c->display_usage) {
282 net_conf_list_usage(c, argc, argv);
286 werr = smbconf_get_config(conf_ctx, mem_ctx, &num_shares, &shares);
287 if (!W_ERROR_IS_OK(werr)) {
288 d_fprintf(stderr, _("Error getting config: %s\n"),
293 for (share_count = 0; share_count < num_shares; share_count++) {
294 const char *indent = "";
295 if (shares[share_count]->name != NULL) {
296 d_printf("[%s]\n", shares[share_count]->name);
299 for (param_count = 0;
300 param_count < shares[share_count]->num_params;
303 d_printf("%s%s = %s\n",
305 shares[share_count]->param_names[param_count],
306 shares[share_count]->param_values[param_count]);
314 TALLOC_FREE(mem_ctx);
318 static int net_conf_import(struct net_context *c, struct smbconf_ctx *conf_ctx,
319 int argc, const char **argv)
322 const char *filename = NULL;
323 const char *servicename = NULL;
324 char *conf_source = NULL;
326 struct smbconf_ctx *txt_ctx;
330 if (c->display_usage)
331 return net_conf_import_usage(c, argc, argv);
333 mem_ctx = talloc_stackframe();
338 net_conf_import_usage(c, argc, argv);
341 servicename = talloc_strdup(mem_ctx, argv[1]);
342 if (servicename == NULL) {
343 d_printf(_("error: out of memory!\n"));
351 DEBUG(3,("net_conf_import: reading configuration from file %s.\n",
354 conf_source = talloc_asprintf(mem_ctx, "file:%s", filename);
355 if (conf_source == NULL) {
356 d_printf(_("error: out of memory!\n"));
360 err = smbconf_init(mem_ctx, &txt_ctx, conf_source);
361 if (!SBC_ERROR_IS_OK(err)) {
362 d_printf(_("error loading file '%s': %s\n"), filename,
363 sbcErrorString(err));
364 werr = WERR_NO_SUCH_SERVICE;
368 if (c->opt_testmode) {
369 d_printf(_("\nTEST MODE - "
370 "would import the following configuration:\n\n"));
373 if (servicename != NULL) {
374 struct smbconf_service *service = NULL;
376 err = smbconf_get_share(txt_ctx, mem_ctx,
379 if (!SBC_ERROR_IS_OK(err)) {
383 werr = smbconf_transaction_start(conf_ctx);
384 if (!W_ERROR_IS_OK(werr)) {
385 d_printf(_("error starting transaction: %s\n"),
390 werr = import_process_service(c, conf_ctx, service);
391 if (!W_ERROR_IS_OK(werr)) {
395 struct smbconf_service **services = NULL;
396 uint32_t num_shares, sidx;
398 werr = smbconf_get_config(txt_ctx, mem_ctx,
401 if (!W_ERROR_IS_OK(werr)) {
404 if (!c->opt_testmode) {
405 if (!SBC_ERROR_IS_OK(smbconf_drop(conf_ctx))) {
411 * Wrap the importing of shares into a transaction,
412 * but only 100 at a time, in order to save memory.
413 * The allocated memory accumulates across the actions
414 * within the transaction, and for me, some 1500
415 * imported shares, the MAX_TALLOC_SIZE of 256 MB
418 werr = smbconf_transaction_start(conf_ctx);
419 if (!W_ERROR_IS_OK(werr)) {
420 d_printf(_("error starting transaction: %s\n"),
425 for (sidx = 0; sidx < num_shares; sidx++) {
426 werr = import_process_service(c, conf_ctx,
428 if (!W_ERROR_IS_OK(werr)) {
436 werr = smbconf_transaction_commit(conf_ctx);
437 if (!W_ERROR_IS_OK(werr)) {
438 d_printf(_("error committing transaction: "
443 werr = smbconf_transaction_start(conf_ctx);
444 if (!W_ERROR_IS_OK(werr)) {
445 d_printf(_("error starting transaction: %s\n"),
452 werr = smbconf_transaction_commit(conf_ctx);
453 if (!W_ERROR_IS_OK(werr)) {
454 d_printf(_("error committing transaction: %s\n"),
463 werr = smbconf_transaction_cancel(conf_ctx);
464 if (!W_ERROR_IS_OK(werr)) {
465 d_printf(_("error cancelling transaction: %s\n"),
470 TALLOC_FREE(mem_ctx);
474 static int net_conf_listshares(struct net_context *c,
475 struct smbconf_ctx *conf_ctx, int argc,
480 uint32_t count, num_shares = 0;
481 char **share_names = NULL;
484 mem_ctx = talloc_stackframe();
486 if (argc != 0 || c->display_usage) {
487 net_conf_listshares_usage(c, argc, argv);
491 err = smbconf_get_share_names(conf_ctx, mem_ctx, &num_shares,
493 if (!SBC_ERROR_IS_OK(err)) {
497 for (count = 0; count < num_shares; count++)
499 d_printf("%s\n", share_names[count]);
505 TALLOC_FREE(mem_ctx);
509 static int net_conf_drop(struct net_context *c, struct smbconf_ctx *conf_ctx,
510 int argc, const char **argv)
515 if (argc != 0 || c->display_usage) {
516 net_conf_drop_usage(c, argc, argv);
520 err = smbconf_drop(conf_ctx);
521 if (!SBC_ERROR_IS_OK(err)) {
522 d_fprintf(stderr, _("Error deleting configuration: %s\n"),
523 sbcErrorString(err));
533 static int net_conf_showshare(struct net_context *c,
534 struct smbconf_ctx *conf_ctx, int argc,
539 const char *sharename = NULL;
542 struct smbconf_service *service = NULL;
544 mem_ctx = talloc_stackframe();
546 if (argc != 1 || c->display_usage) {
547 net_conf_showshare_usage(c, argc, argv);
551 sharename = talloc_strdup(mem_ctx, argv[0]);
552 if (sharename == NULL) {
553 d_printf("error: out of memory!\n");
557 err = smbconf_get_share(conf_ctx, mem_ctx, sharename, &service);
558 if (!SBC_ERROR_IS_OK(err)) {
559 d_printf(_("error getting share parameters: %s\n"),
560 sbcErrorString(err));
564 d_printf("[%s]\n", service->name);
566 for (count = 0; count < service->num_params; count++) {
567 d_printf("\t%s = %s\n", service->param_names[count],
568 service->param_values[count]);
574 TALLOC_FREE(mem_ctx);
579 * Add a share, with a couple of standard parameters, partly optional.
581 * This is a high level utility function of the net conf utility,
582 * not a direct frontend to the smbconf API.
584 static int net_conf_addshare(struct net_context *c,
585 struct smbconf_ctx *conf_ctx, int argc,
589 WERROR werr = WERR_OK;
591 char *sharename = NULL;
592 const char *path = NULL;
593 const char *comment = NULL;
594 const char *guest_ok = "no";
595 const char *writeable = "no";
596 SMB_STRUCT_STAT sbuf;
597 TALLOC_CTX *mem_ctx = talloc_stackframe();
599 if (c->display_usage) {
600 net_conf_addshare_usage(c, argc, argv);
609 net_conf_addshare_usage(c, argc, argv);
614 if (!strnequal(argv[3], "guest_ok=", 9)) {
615 net_conf_addshare_usage(c, argc, argv);
618 switch (argv[3][9]) {
628 net_conf_addshare_usage(c, argc, argv);
632 if (!strnequal(argv[2], "writeable=", 10)) {
633 net_conf_addshare_usage(c, argc, argv);
636 switch (argv[2][10]) {
646 net_conf_addshare_usage(c, argc, argv);
651 sharename = talloc_strdup(mem_ctx, argv[0]);
652 if (sharename == NULL) {
653 d_printf(_("error: out of memory!\n"));
664 /* validate share name */
666 if (!validate_net_name(sharename, INVALID_SHARENAME_CHARS,
669 d_fprintf(stderr, _("ERROR: share name %s contains "
670 "invalid characters (any of %s)\n"),
671 sharename, INVALID_SHARENAME_CHARS);
675 if (strequal(sharename, GLOBAL_NAME)) {
677 _("ERROR: 'global' is not a valid share name.\n"));
681 if (smbconf_share_exists(conf_ctx, sharename)) {
682 d_fprintf(stderr, _("ERROR: share %s already exists.\n"),
689 if (path[0] != '/') {
691 _("Error: path '%s' is not an absolute path.\n"),
696 if (sys_stat(path, &sbuf, false) != 0) {
698 _("ERROR: cannot stat path '%s' to ensure "
699 "this is a directory.\n"
700 "Error was '%s'.\n"),
701 path, strerror(errno));
705 if (!S_ISDIR(sbuf.st_ex_mode)) {
707 _("ERROR: path '%s' is not a directory.\n"),
713 * start a transaction
716 werr = smbconf_transaction_start(conf_ctx);
717 if (!W_ERROR_IS_OK(werr)) {
718 d_printf("error starting transaction: %s\n",
727 err = smbconf_create_share(conf_ctx, sharename);
728 if (!SBC_ERROR_IS_OK(err)) {
729 d_fprintf(stderr, _("Error creating share %s: %s\n"),
730 sharename, sbcErrorString(err));
735 * fill the share with parameters
738 err = smbconf_set_parameter(conf_ctx, sharename, "path", path);
739 if (!SBC_ERROR_IS_OK(err)) {
740 d_fprintf(stderr, _("Error setting parameter %s: %s\n"),
741 "path", sbcErrorString(err));
745 if (comment != NULL) {
746 err = smbconf_set_parameter(conf_ctx, sharename, "comment",
748 if (!SBC_ERROR_IS_OK(err)) {
749 d_fprintf(stderr, _("Error setting parameter %s: %s\n"),
750 "comment", sbcErrorString(err));
755 err = smbconf_set_parameter(conf_ctx, sharename, "guest ok", guest_ok);
756 if (!SBC_ERROR_IS_OK(err)) {
757 d_fprintf(stderr, _("Error setting parameter %s: %s\n"),
758 "'guest ok'", sbcErrorString(err));
762 err = smbconf_set_parameter(conf_ctx, sharename, "writeable",
764 if (!SBC_ERROR_IS_OK(err)) {
765 d_fprintf(stderr, _("Error setting parameter %s: %s\n"),
766 "writeable", sbcErrorString(err));
771 * commit the whole thing
774 werr = smbconf_transaction_commit(conf_ctx);
775 if (!W_ERROR_IS_OK(werr)) {
776 d_printf("error committing transaction: %s\n",
785 werr = smbconf_transaction_cancel(conf_ctx);
786 if (!W_ERROR_IS_OK(werr)) {
787 d_printf("error cancelling transaction: %s\n",
792 TALLOC_FREE(mem_ctx);
796 static int net_conf_delshare(struct net_context *c,
797 struct smbconf_ctx *conf_ctx, int argc,
801 const char *sharename = NULL;
803 TALLOC_CTX *mem_ctx = talloc_stackframe();
805 if (argc != 1 || c->display_usage) {
806 net_conf_delshare_usage(c, argc, argv);
809 sharename = talloc_strdup(mem_ctx, argv[0]);
810 if (sharename == NULL) {
811 d_printf(_("error: out of memory!\n"));
815 err = smbconf_delete_share(conf_ctx, sharename);
816 if (!SBC_ERROR_IS_OK(err)) {
817 d_fprintf(stderr, _("Error deleting share %s: %s\n"),
818 sharename, sbcErrorString(err));
824 TALLOC_FREE(mem_ctx);
828 static int net_conf_setparm(struct net_context *c, struct smbconf_ctx *conf_ctx,
829 int argc, const char **argv)
832 WERROR werr = WERR_OK;
834 char *service = NULL;
836 const char *value_str = NULL;
837 TALLOC_CTX *mem_ctx = talloc_stackframe();
839 if (argc != 3 || c->display_usage) {
840 net_conf_setparm_usage(c, argc, argv);
844 * NULL service name means "dangling parameters" to libsmbconf.
845 * We use the empty string from the command line for this purpose.
847 if (strlen(argv[0]) != 0) {
848 service = talloc_strdup(mem_ctx, argv[0]);
849 if (service == NULL) {
850 d_printf(_("error: out of memory!\n"));
854 param = strlower_talloc(mem_ctx, argv[1]);
856 d_printf(_("error: out of memory!\n"));
861 werr = smbconf_transaction_start(conf_ctx);
862 if (!W_ERROR_IS_OK(werr)) {
863 d_printf(_("error starting transaction: %s\n"),
868 if (!smbconf_share_exists(conf_ctx, service)) {
869 err = smbconf_create_share(conf_ctx, service);
870 if (!SBC_ERROR_IS_OK(err)) {
871 d_fprintf(stderr, _("Error creating share '%s': %s\n"),
872 service, sbcErrorString(err));
877 err = smbconf_set_parameter(conf_ctx, service, param, value_str);
878 if (!SBC_ERROR_IS_OK(err)) {
879 d_fprintf(stderr, _("Error setting value '%s': %s\n"),
880 param, sbcErrorString(err));
884 werr = smbconf_transaction_commit(conf_ctx);
885 if (!W_ERROR_IS_OK(werr)) {
886 d_printf(_("error committing transaction: %s\n"),
895 werr = smbconf_transaction_cancel(conf_ctx);
896 if (!W_ERROR_IS_OK(werr)) {
897 d_printf(_("error cancelling transaction: %s\n"),
902 TALLOC_FREE(mem_ctx);
906 static int net_conf_getparm(struct net_context *c, struct smbconf_ctx *conf_ctx,
907 int argc, const char **argv)
911 char *service = NULL;
916 mem_ctx = talloc_stackframe();
918 if (argc != 2 || c->display_usage) {
919 net_conf_getparm_usage(c, argc, argv);
923 * NULL service name means "dangling parameters" to libsmbconf.
924 * We use the empty string from the command line for this purpose.
926 if (strlen(argv[0]) != 0) {
927 service = talloc_strdup(mem_ctx, argv[0]);
928 if (service == NULL) {
929 d_printf(_("error: out of memory!\n"));
933 param = strlower_talloc(mem_ctx, argv[1]);
935 d_printf(_("error: out of memory!\n"));
939 err = smbconf_get_parameter(conf_ctx, mem_ctx, service, param, &valstr);
940 if (SBC_ERROR_EQUAL(err, SBC_ERR_NO_SUCH_SERVICE)) {
942 _("Error: given service '%s' does not exist.\n"),
945 } else if (SBC_ERROR_EQUAL(err, SBC_ERR_INVALID_PARAM)) {
947 _("Error: given parameter '%s' is not set.\n"),
950 } else if (!SBC_ERROR_IS_OK(err)) {
951 d_fprintf(stderr, _("Error getting value '%s': %s.\n"),
952 param, sbcErrorString(err));
956 d_printf("%s\n", valstr);
960 TALLOC_FREE(mem_ctx);
964 static int net_conf_delparm(struct net_context *c, struct smbconf_ctx *conf_ctx,
965 int argc, const char **argv)
969 char *service = NULL;
971 TALLOC_CTX *mem_ctx = talloc_stackframe();
973 if (argc != 2 || c->display_usage) {
974 net_conf_delparm_usage(c, argc, argv);
978 * NULL service name means "dangling parameters" to libsmbconf.
979 * We use the empty string from the command line for this purpose.
981 if (strlen(argv[0]) != 0) {
982 service = talloc_strdup(mem_ctx, argv[0]);
983 if (service == NULL) {
984 d_printf(_("error: out of memory!\n"));
988 param = strlower_talloc(mem_ctx, argv[1]);
990 d_printf("error: out of memory!\n");
994 err = smbconf_delete_parameter(conf_ctx, service, param);
995 if (SBC_ERROR_EQUAL(err, SBC_ERR_NO_SUCH_SERVICE)) {
997 _("Error: given service '%s' does not exist.\n"),
1000 } else if (SBC_ERROR_EQUAL(err, SBC_ERR_INVALID_PARAM)) {
1002 _("Error: given parameter '%s' is not set.\n"),
1005 } else if (!SBC_ERROR_IS_OK(err)) {
1006 d_fprintf(stderr, _("Error deleting value '%s': %s.\n"),
1007 param, sbcErrorString(err));
1014 TALLOC_FREE(mem_ctx);
1018 static int net_conf_getincludes(struct net_context *c,
1019 struct smbconf_ctx *conf_ctx,
1020 int argc, const char **argv)
1023 uint32_t num_includes;
1026 char **includes = NULL;
1028 TALLOC_CTX *mem_ctx = talloc_stackframe();
1030 if (argc != 1 || c->display_usage) {
1031 net_conf_getincludes_usage(c, argc, argv);
1035 service = talloc_strdup(mem_ctx, argv[0]);
1036 if (service == NULL) {
1037 d_printf(_("error: out of memory!\n"));
1041 err = smbconf_get_includes(conf_ctx, mem_ctx, service,
1042 &num_includes, &includes);
1043 if (!SBC_ERROR_IS_OK(err)) {
1044 d_printf(_("error getting includes: %s\n"), sbcErrorString(err));
1048 for (count = 0; count < num_includes; count++) {
1049 d_printf("include = %s\n", includes[count]);
1055 TALLOC_FREE(mem_ctx);
1059 static int net_conf_setincludes(struct net_context *c,
1060 struct smbconf_ctx *conf_ctx,
1061 int argc, const char **argv)
1065 uint32_t num_includes;
1066 const char **includes;
1068 TALLOC_CTX *mem_ctx = talloc_stackframe();
1070 if (argc < 1 || c->display_usage) {
1071 net_conf_setincludes_usage(c, argc, argv);
1075 service = talloc_strdup(mem_ctx, argv[0]);
1076 if (service == NULL) {
1077 d_printf(_("error: out of memory!\n"));
1081 num_includes = argc - 1;
1082 if (num_includes == 0) {
1085 includes = argv + 1;
1088 err = smbconf_set_includes(conf_ctx, service, num_includes, includes);
1089 if (!SBC_ERROR_IS_OK(err)) {
1090 d_printf(_("error setting includes: %s\n"), sbcErrorString(err));
1097 TALLOC_FREE(mem_ctx);
1101 static int net_conf_delincludes(struct net_context *c,
1102 struct smbconf_ctx *conf_ctx,
1103 int argc, const char **argv)
1108 TALLOC_CTX *mem_ctx = talloc_stackframe();
1110 if (argc != 1 || c->display_usage) {
1111 net_conf_delincludes_usage(c, argc, argv);
1115 service = talloc_strdup(mem_ctx, argv[0]);
1116 if (service == NULL) {
1117 d_printf(_("error: out of memory!\n"));
1121 err = smbconf_delete_includes(conf_ctx, service);
1122 if (!SBC_ERROR_IS_OK(err)) {
1123 d_printf(_("error deleting includes: %s\n"), sbcErrorString(err));
1130 TALLOC_FREE(mem_ctx);
1135 /**********************************************************************
1137 * Wrapper and net_conf_run_function mechanism.
1139 **********************************************************************/
1142 * Wrapper function to call the main conf functions.
1143 * The wrapper calls handles opening and closing of the
1146 static int net_conf_wrap_function(struct net_context *c,
1147 int (*fn)(struct net_context *,
1148 struct smbconf_ctx *,
1149 int, const char **),
1150 int argc, const char **argv)
1153 TALLOC_CTX *mem_ctx = talloc_stackframe();
1154 struct smbconf_ctx *conf_ctx;
1157 err = smbconf_init(mem_ctx, &conf_ctx, "registry:");
1158 if (!SBC_ERROR_IS_OK(err)) {
1162 ret = fn(c, conf_ctx, argc, argv);
1164 smbconf_shutdown(conf_ctx);
1170 * We need a functable struct of our own, because the
1171 * functions are called through a wrapper that handles
1172 * the opening and closing of the configuration, and so on.
1174 struct conf_functable {
1175 const char *funcname;
1176 int (*fn)(struct net_context *c, struct smbconf_ctx *ctx, int argc,
1178 int valid_transports;
1179 const char *description;
1184 * This imitates net_run_function but calls the main functions
1185 * through the wrapper net_conf_wrap_function().
1187 static int net_conf_run_function(struct net_context *c, int argc,
1188 const char **argv, const char *whoami,
1189 struct conf_functable *table)
1194 for (i=0; table[i].funcname; i++) {
1195 if (StrCaseCmp(argv[0], table[i].funcname) == 0)
1196 return net_conf_wrap_function(c, table[i].fn,
1202 d_printf(_("Usage:\n"));
1203 for (i=0; table[i].funcname; i++) {
1204 if (c->display_usage == false)
1205 d_printf("%s %-15s %s\n", whoami, table[i].funcname,
1206 table[i].description);
1208 d_printf("%s\n", table[i].usage);
1211 return c->display_usage?0:-1;
1215 * Entry-point for all the CONF functions.
1218 int net_conf(struct net_context *c, int argc, const char **argv)
1221 struct conf_functable func_table[] = {
1225 NET_TRANSPORT_LOCAL,
1226 N_("Dump the complete configuration in smb.conf like "
1228 N_("net conf list\n"
1229 " Dump the complete configuration in smb.conf "
1236 NET_TRANSPORT_LOCAL,
1237 N_("Import configuration from file in smb.conf "
1239 N_("net conf import\n"
1240 " Import configuration from file in smb.conf "
1245 net_conf_listshares,
1246 NET_TRANSPORT_LOCAL,
1247 N_("List the share names."),
1248 N_("net conf listshares\n"
1249 " List the share names.")
1254 NET_TRANSPORT_LOCAL,
1255 N_("Delete the complete configuration."),
1256 N_("net conf drop\n"
1257 " Delete the complete configuration.")
1262 NET_TRANSPORT_LOCAL,
1263 N_("Show the definition of a share."),
1264 N_("net conf showshare\n"
1265 " Show the definition of a share.")
1270 NET_TRANSPORT_LOCAL,
1271 N_("Create a new share."),
1272 N_("net conf addshare\n"
1273 " Create a new share.")
1278 NET_TRANSPORT_LOCAL,
1279 N_("Delete a share."),
1280 N_("net conf delshare\n"
1286 NET_TRANSPORT_LOCAL,
1287 N_("Store a parameter."),
1288 N_("net conf setparm\n"
1289 " Store a parameter.")
1294 NET_TRANSPORT_LOCAL,
1295 N_("Retrieve the value of a parameter."),
1296 N_("net conf getparm\n"
1297 " Retrieve the value of a parameter.")
1302 NET_TRANSPORT_LOCAL,
1303 N_("Delete a parameter."),
1304 N_("net conf delparm\n"
1305 " Delete a parameter.")
1309 net_conf_getincludes,
1310 NET_TRANSPORT_LOCAL,
1311 N_("Show the includes of a share definition."),
1312 N_("net conf getincludes\n"
1313 " Show the includes of a share definition.")
1317 net_conf_setincludes,
1318 NET_TRANSPORT_LOCAL,
1319 N_("Set includes for a share."),
1320 N_("net conf setincludes\n"
1321 " Set includes for a share.")
1325 net_conf_delincludes,
1326 NET_TRANSPORT_LOCAL,
1327 N_("Delete includes from a share definition."),
1328 N_("net conf setincludes\n"
1329 " Delete includes from a share definition.")
1331 {NULL, NULL, 0, NULL, NULL}
1334 ret = net_conf_run_function(c, argc, argv, "net conf", func_table);