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"
36 #include "lib/param/loadparm.h"
38 /**********************************************************************
42 **********************************************************************/
44 static int net_conf_list_usage(struct net_context
*c
, int argc
,
47 d_printf("%s net conf list\n", _("Usage:"));
51 static int net_conf_import_usage(struct net_context
*c
, int argc
,
56 _(" net conf import [--test|-T] <filename> "
58 "\t[--test|-T] testmode - do not act, just print "
59 "what would be done\n"
60 "\t<servicename> only import service <servicename>, "
61 "ignore the rest\n"));
65 static int net_conf_listshares_usage(struct net_context
*c
, int argc
,
68 d_printf("%s\nnet conf listshares\n", _("Usage:"));
72 static int net_conf_drop_usage(struct net_context
*c
, int argc
,
75 d_printf("%s\nnet conf drop\n", _("Usage:"));
79 static int net_conf_showshare_usage(struct net_context
*c
, int argc
,
84 _("net conf showshare <sharename>\n"));
88 static int net_conf_addshare_usage(struct net_context
*c
, int argc
,
93 _(" net conf addshare <sharename> <path> "
94 "[writeable={y|N} [guest_ok={y|N} [<comment>]]]\n"
95 "\t<sharename> the new share name.\n"
96 "\t<path> the path on the filesystem to export.\n"
97 "\twriteable={y|N} set \"writeable to \"yes\" or "
98 "\"no\" (default) on this share.\n"
99 "\tguest_ok={y|N} set \"guest ok\" to \"yes\" or "
100 "\"no\" (default) on this share.\n"
101 "\t<comment> optional comment for the new share.\n"));
105 static int net_conf_delshare_usage(struct net_context
*c
, int argc
,
110 _("net conf delshare <sharename>\n"));
114 static int net_conf_setparm_usage(struct net_context
*c
, int argc
,
119 _(" net conf setparm <section> <param> <value>\n"));
123 static int net_conf_getparm_usage(struct net_context
*c
, int argc
,
128 _(" net conf getparm <section> <param>\n"));
132 static int net_conf_delparm_usage(struct net_context
*c
, int argc
,
137 _(" net conf delparm <section> <param>\n"));
141 static int net_conf_getincludes_usage(struct net_context
*c
, int argc
,
146 _(" net conf getincludes <section>\n"));
150 static int net_conf_setincludes_usage(struct net_context
*c
, int argc
,
155 _(" net conf setincludes <section> [<filename>]*\n"));
159 static int net_conf_delincludes_usage(struct net_context
*c
, int argc
,
164 _(" net conf delincludes <section>\n"));
169 /**********************************************************************
173 **********************************************************************/
176 * This functions process a service previously loaded with libsmbconf.
178 static sbcErr
import_process_service(struct net_context
*c
,
179 struct smbconf_ctx
*conf_ctx
,
180 struct smbconf_service
*service
)
182 sbcErr err
= SBC_ERR_OK
;
184 if (c
->opt_testmode
) {
186 const char *indent
= "";
187 if (service
->name
!= NULL
) {
188 d_printf("[%s]\n", service
->name
);
191 for (idx
= 0; idx
< service
->num_params
; idx
++) {
192 d_printf("%s%s = %s\n", indent
,
193 service
->param_names
[idx
],
194 service
->param_values
[idx
]);
200 if (smbconf_share_exists(conf_ctx
, service
->name
)) {
201 err
= smbconf_delete_share(conf_ctx
, service
->name
);
202 if (!SBC_ERROR_IS_OK(err
)) {
207 err
= smbconf_create_set_share(conf_ctx
, service
);
214 /**********************************************************************
216 * the main conf functions
218 **********************************************************************/
220 static int net_conf_list(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
221 int argc
, const char **argv
)
227 uint32_t share_count
, param_count
;
228 struct smbconf_service
**shares
= NULL
;
230 mem_ctx
= talloc_stackframe();
232 if (argc
!= 0 || c
->display_usage
) {
233 net_conf_list_usage(c
, argc
, argv
);
237 err
= smbconf_get_config(conf_ctx
, mem_ctx
, &num_shares
, &shares
);
238 if (!SBC_ERROR_IS_OK(err
)) {
239 d_fprintf(stderr
, _("Error getting config: %s\n"),
240 sbcErrorString(err
));
244 for (share_count
= 0; share_count
< num_shares
; share_count
++) {
245 const char *indent
= "";
246 if (shares
[share_count
]->name
!= NULL
) {
247 d_printf("[%s]\n", shares
[share_count
]->name
);
250 for (param_count
= 0;
251 param_count
< shares
[share_count
]->num_params
;
254 d_printf("%s%s = %s\n",
256 shares
[share_count
]->param_names
[param_count
],
257 shares
[share_count
]->param_values
[param_count
]);
265 TALLOC_FREE(mem_ctx
);
269 static int net_conf_import(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
270 int argc
, const char **argv
)
273 const char *filename
= NULL
;
274 const char *servicename
= NULL
;
275 char *conf_source
= NULL
;
277 struct smbconf_ctx
*txt_ctx
;
280 if (c
->display_usage
)
281 return net_conf_import_usage(c
, argc
, argv
);
283 mem_ctx
= talloc_stackframe();
288 net_conf_import_usage(c
, argc
, argv
);
291 servicename
= talloc_strdup(mem_ctx
, argv
[1]);
292 if (servicename
== NULL
) {
293 d_printf(_("error: out of memory!\n"));
301 DEBUG(3,("net_conf_import: reading configuration from file %s.\n",
304 conf_source
= talloc_asprintf(mem_ctx
, "file:%s", filename
);
305 if (conf_source
== NULL
) {
306 d_printf(_("error: out of memory!\n"));
310 err
= smbconf_init(mem_ctx
, &txt_ctx
, conf_source
);
311 if (!SBC_ERROR_IS_OK(err
)) {
312 d_printf(_("error loading file '%s': %s\n"), filename
,
313 sbcErrorString(err
));
317 if (c
->opt_testmode
) {
318 d_printf(_("\nTEST MODE - "
319 "would import the following configuration:\n\n"));
322 if (servicename
!= NULL
) {
323 struct smbconf_service
*service
= NULL
;
325 err
= smbconf_get_share(txt_ctx
, mem_ctx
,
328 if (!SBC_ERROR_IS_OK(err
)) {
332 err
= smbconf_transaction_start(conf_ctx
);
333 if (!SBC_ERROR_IS_OK(err
)) {
334 d_printf(_("error starting transaction: %s\n"),
335 sbcErrorString(err
));
339 err
= import_process_service(c
, conf_ctx
, service
);
340 if (!SBC_ERROR_IS_OK(err
)) {
344 struct smbconf_service
**services
= NULL
;
345 uint32_t num_shares
, sidx
;
347 err
= smbconf_get_config(txt_ctx
, mem_ctx
,
350 if (!SBC_ERROR_IS_OK(err
)) {
353 if (!c
->opt_testmode
) {
354 if (!SBC_ERROR_IS_OK(smbconf_drop(conf_ctx
))) {
360 * Wrap the importing of shares into a transaction,
361 * but only 100 at a time, in order to save memory.
362 * The allocated memory accumulates across the actions
363 * within the transaction, and for me, some 1500
364 * imported shares, the MAX_TALLOC_SIZE of 256 MB
367 err
= smbconf_transaction_start(conf_ctx
);
368 if (!SBC_ERROR_IS_OK(err
)) {
369 d_printf(_("error starting transaction: %s\n"),
370 sbcErrorString(err
));
374 for (sidx
= 0; sidx
< num_shares
; sidx
++) {
375 err
= import_process_service(c
, conf_ctx
,
377 if (!SBC_ERROR_IS_OK(err
)) {
385 err
= smbconf_transaction_commit(conf_ctx
);
386 if (!SBC_ERROR_IS_OK(err
)) {
387 d_printf(_("error committing transaction: "
389 sbcErrorString(err
));
392 err
= smbconf_transaction_start(conf_ctx
);
393 if (!SBC_ERROR_IS_OK(err
)) {
394 d_printf(_("error starting transaction: %s\n"),
395 sbcErrorString(err
));
401 err
= smbconf_transaction_commit(conf_ctx
);
402 if (!SBC_ERROR_IS_OK(err
)) {
403 d_printf(_("error committing transaction: %s\n"),
404 sbcErrorString(err
));
412 err
= smbconf_transaction_cancel(conf_ctx
);
413 if (!SBC_ERROR_IS_OK(err
)) {
414 d_printf(_("error cancelling transaction: %s\n"),
415 sbcErrorString(err
));
419 TALLOC_FREE(mem_ctx
);
423 static int net_conf_listshares(struct net_context
*c
,
424 struct smbconf_ctx
*conf_ctx
, int argc
,
429 uint32_t count
, num_shares
= 0;
430 char **share_names
= NULL
;
433 mem_ctx
= talloc_stackframe();
435 if (argc
!= 0 || c
->display_usage
) {
436 net_conf_listshares_usage(c
, argc
, argv
);
440 err
= smbconf_get_share_names(conf_ctx
, mem_ctx
, &num_shares
,
442 if (!SBC_ERROR_IS_OK(err
)) {
446 for (count
= 0; count
< num_shares
; count
++)
448 d_printf("%s\n", share_names
[count
]);
454 TALLOC_FREE(mem_ctx
);
458 static int net_conf_drop(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
459 int argc
, const char **argv
)
464 if (argc
!= 0 || c
->display_usage
) {
465 net_conf_drop_usage(c
, argc
, argv
);
469 err
= smbconf_drop(conf_ctx
);
470 if (!SBC_ERROR_IS_OK(err
)) {
471 d_fprintf(stderr
, _("Error deleting configuration: %s\n"),
472 sbcErrorString(err
));
482 static int net_conf_showshare(struct net_context
*c
,
483 struct smbconf_ctx
*conf_ctx
, int argc
,
488 const char *sharename
= NULL
;
491 struct smbconf_service
*service
= NULL
;
493 mem_ctx
= talloc_stackframe();
495 if (argc
!= 1 || c
->display_usage
) {
496 net_conf_showshare_usage(c
, argc
, argv
);
500 sharename
= talloc_strdup(mem_ctx
, argv
[0]);
501 if (sharename
== NULL
) {
502 d_printf("error: out of memory!\n");
506 err
= smbconf_get_share(conf_ctx
, mem_ctx
, sharename
, &service
);
507 if (!SBC_ERROR_IS_OK(err
)) {
508 d_printf(_("error getting share parameters: %s\n"),
509 sbcErrorString(err
));
513 d_printf("[%s]\n", service
->name
);
515 for (count
= 0; count
< service
->num_params
; count
++) {
516 d_printf("\t%s = %s\n", service
->param_names
[count
],
517 service
->param_values
[count
]);
523 TALLOC_FREE(mem_ctx
);
528 * Add a share, with a couple of standard parameters, partly optional.
530 * This is a high level utility function of the net conf utility,
531 * not a direct frontend to the smbconf API.
533 static int net_conf_addshare(struct net_context
*c
,
534 struct smbconf_ctx
*conf_ctx
, int argc
,
539 char *sharename
= NULL
;
540 const char *path
= NULL
;
541 const char *comment
= NULL
;
542 const char *guest_ok
= "no";
543 const char *writeable
= "no";
544 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
546 if (c
->display_usage
) {
547 net_conf_addshare_usage(c
, argc
, argv
);
556 net_conf_addshare_usage(c
, argc
, argv
);
561 if (!strnequal(argv
[3], "guest_ok=", 9)) {
562 net_conf_addshare_usage(c
, argc
, argv
);
565 switch (argv
[3][9]) {
575 net_conf_addshare_usage(c
, argc
, argv
);
579 if (!strnequal(argv
[2], "writeable=", 10)) {
580 net_conf_addshare_usage(c
, argc
, argv
);
583 switch (argv
[2][10]) {
593 net_conf_addshare_usage(c
, argc
, argv
);
598 sharename
= talloc_strdup(mem_ctx
, argv
[0]);
599 if (sharename
== NULL
) {
600 d_printf(_("error: out of memory!\n"));
611 /* validate share name */
613 if (!validate_net_name(sharename
, INVALID_SHARENAME_CHARS
,
616 d_fprintf(stderr
, _("ERROR: share name %s contains "
617 "invalid characters (any of %s)\n"),
618 sharename
, INVALID_SHARENAME_CHARS
);
622 if (strequal(sharename
, GLOBAL_NAME
)) {
624 _("ERROR: 'global' is not a valid share name.\n"));
628 if (smbconf_share_exists(conf_ctx
, sharename
)) {
629 d_fprintf(stderr
, _("ERROR: share %s already exists.\n"),
636 if (path
[0] != '/') {
638 _("Error: path '%s' is not an absolute path.\n"),
644 * start a transaction
647 err
= smbconf_transaction_start(conf_ctx
);
648 if (!SBC_ERROR_IS_OK(err
)) {
649 d_printf("error starting transaction: %s\n",
650 sbcErrorString(err
));
658 err
= smbconf_create_share(conf_ctx
, sharename
);
659 if (!SBC_ERROR_IS_OK(err
)) {
660 d_fprintf(stderr
, _("Error creating share %s: %s\n"),
661 sharename
, sbcErrorString(err
));
666 * fill the share with parameters
669 err
= smbconf_set_parameter(conf_ctx
, sharename
, "path", path
);
670 if (!SBC_ERROR_IS_OK(err
)) {
671 d_fprintf(stderr
, _("Error setting parameter %s: %s\n"),
672 "path", sbcErrorString(err
));
676 if (comment
!= NULL
) {
677 err
= smbconf_set_parameter(conf_ctx
, sharename
, "comment",
679 if (!SBC_ERROR_IS_OK(err
)) {
680 d_fprintf(stderr
, _("Error setting parameter %s: %s\n"),
681 "comment", sbcErrorString(err
));
686 err
= smbconf_set_parameter(conf_ctx
, sharename
, "guest ok", guest_ok
);
687 if (!SBC_ERROR_IS_OK(err
)) {
688 d_fprintf(stderr
, _("Error setting parameter %s: %s\n"),
689 "'guest ok'", sbcErrorString(err
));
693 err
= smbconf_set_parameter(conf_ctx
, sharename
, "writeable",
695 if (!SBC_ERROR_IS_OK(err
)) {
696 d_fprintf(stderr
, _("Error setting parameter %s: %s\n"),
697 "writeable", sbcErrorString(err
));
702 * commit the whole thing
705 err
= smbconf_transaction_commit(conf_ctx
);
706 if (!SBC_ERROR_IS_OK(err
)) {
707 d_printf("error committing transaction: %s\n",
708 sbcErrorString(err
));
716 err
= smbconf_transaction_cancel(conf_ctx
);
717 if (!SBC_ERROR_IS_OK(err
)) {
718 d_printf("error cancelling transaction: %s\n",
719 sbcErrorString(err
));
723 TALLOC_FREE(mem_ctx
);
727 static int net_conf_delshare(struct net_context
*c
,
728 struct smbconf_ctx
*conf_ctx
, int argc
,
732 const char *sharename
= NULL
;
734 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
736 if (argc
!= 1 || c
->display_usage
) {
737 net_conf_delshare_usage(c
, argc
, argv
);
740 sharename
= talloc_strdup(mem_ctx
, argv
[0]);
741 if (sharename
== NULL
) {
742 d_printf(_("error: out of memory!\n"));
746 err
= smbconf_delete_share(conf_ctx
, sharename
);
747 if (!SBC_ERROR_IS_OK(err
)) {
748 d_fprintf(stderr
, _("Error deleting share %s: %s\n"),
749 sharename
, sbcErrorString(err
));
755 TALLOC_FREE(mem_ctx
);
759 static int net_conf_setparm(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
760 int argc
, const char **argv
)
764 char *service
= NULL
;
766 const char *value_str
= NULL
;
767 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
769 if (argc
!= 3 || c
->display_usage
) {
770 net_conf_setparm_usage(c
, argc
, argv
);
774 * NULL service name means "dangling parameters" to libsmbconf.
775 * We use the empty string from the command line for this purpose.
777 if (strlen(argv
[0]) != 0) {
778 service
= talloc_strdup(mem_ctx
, argv
[0]);
779 if (service
== NULL
) {
780 d_printf(_("error: out of memory!\n"));
784 param
= strlower_talloc(mem_ctx
, argv
[1]);
786 d_printf(_("error: out of memory!\n"));
791 err
= smbconf_transaction_start(conf_ctx
);
792 if (!SBC_ERROR_IS_OK(err
)) {
793 d_printf(_("error starting transaction: %s\n"),
794 sbcErrorString(err
));
798 if (!smbconf_share_exists(conf_ctx
, service
)) {
799 err
= smbconf_create_share(conf_ctx
, service
);
800 if (!SBC_ERROR_IS_OK(err
)) {
801 d_fprintf(stderr
, _("Error creating share '%s': %s\n"),
802 service
, sbcErrorString(err
));
807 err
= smbconf_set_parameter(conf_ctx
, service
, param
, value_str
);
808 if (!SBC_ERROR_IS_OK(err
)) {
809 d_fprintf(stderr
, _("Error setting value '%s': %s\n"),
810 param
, sbcErrorString(err
));
814 err
= smbconf_transaction_commit(conf_ctx
);
815 if (!SBC_ERROR_IS_OK(err
)) {
816 d_printf(_("error committing transaction: %s\n"),
817 sbcErrorString(err
));
825 err
= smbconf_transaction_cancel(conf_ctx
);
826 if (!SBC_ERROR_IS_OK(err
)) {
827 d_printf(_("error cancelling transaction: %s\n"),
828 sbcErrorString(err
));
832 TALLOC_FREE(mem_ctx
);
836 static int net_conf_getparm(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
837 int argc
, const char **argv
)
841 char *service
= NULL
;
846 mem_ctx
= talloc_stackframe();
848 if (argc
!= 2 || c
->display_usage
) {
849 net_conf_getparm_usage(c
, argc
, argv
);
853 * NULL service name means "dangling parameters" to libsmbconf.
854 * We use the empty string from the command line for this purpose.
856 if (strlen(argv
[0]) != 0) {
857 service
= talloc_strdup(mem_ctx
, argv
[0]);
858 if (service
== NULL
) {
859 d_printf(_("error: out of memory!\n"));
863 param
= strlower_talloc(mem_ctx
, argv
[1]);
865 d_printf(_("error: out of memory!\n"));
869 err
= smbconf_get_parameter(conf_ctx
, mem_ctx
, service
, param
, &valstr
);
870 if (SBC_ERROR_EQUAL(err
, SBC_ERR_NO_SUCH_SERVICE
)) {
872 _("Error: given service '%s' does not exist.\n"),
875 } else if (SBC_ERROR_EQUAL(err
, SBC_ERR_INVALID_PARAM
)) {
877 _("Error: given parameter '%s' is not set.\n"),
880 } else if (!SBC_ERROR_IS_OK(err
)) {
881 d_fprintf(stderr
, _("Error getting value '%s': %s.\n"),
882 param
, sbcErrorString(err
));
886 d_printf("%s\n", valstr
);
890 TALLOC_FREE(mem_ctx
);
894 static int net_conf_delparm(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
895 int argc
, const char **argv
)
899 char *service
= NULL
;
901 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
903 if (argc
!= 2 || c
->display_usage
) {
904 net_conf_delparm_usage(c
, argc
, argv
);
908 * NULL service name means "dangling parameters" to libsmbconf.
909 * We use the empty string from the command line for this purpose.
911 if (strlen(argv
[0]) != 0) {
912 service
= talloc_strdup(mem_ctx
, argv
[0]);
913 if (service
== NULL
) {
914 d_printf(_("error: out of memory!\n"));
918 param
= strlower_talloc(mem_ctx
, argv
[1]);
920 d_printf("error: out of memory!\n");
924 err
= smbconf_delete_parameter(conf_ctx
, service
, param
);
925 if (SBC_ERROR_EQUAL(err
, SBC_ERR_NO_SUCH_SERVICE
)) {
927 _("Error: given service '%s' does not exist.\n"),
930 } else if (SBC_ERROR_EQUAL(err
, SBC_ERR_INVALID_PARAM
)) {
932 _("Error: given parameter '%s' is not set.\n"),
935 } else if (!SBC_ERROR_IS_OK(err
)) {
936 d_fprintf(stderr
, _("Error deleting value '%s': %s.\n"),
937 param
, sbcErrorString(err
));
944 TALLOC_FREE(mem_ctx
);
948 static int net_conf_getincludes(struct net_context
*c
,
949 struct smbconf_ctx
*conf_ctx
,
950 int argc
, const char **argv
)
953 uint32_t num_includes
;
956 char **includes
= NULL
;
958 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
960 if (argc
!= 1 || c
->display_usage
) {
961 net_conf_getincludes_usage(c
, argc
, argv
);
965 service
= talloc_strdup(mem_ctx
, argv
[0]);
966 if (service
== NULL
) {
967 d_printf(_("error: out of memory!\n"));
971 err
= smbconf_get_includes(conf_ctx
, mem_ctx
, service
,
972 &num_includes
, &includes
);
973 if (!SBC_ERROR_IS_OK(err
)) {
974 d_printf(_("error getting includes: %s\n"), sbcErrorString(err
));
978 for (count
= 0; count
< num_includes
; count
++) {
979 d_printf("include = %s\n", includes
[count
]);
985 TALLOC_FREE(mem_ctx
);
989 static int net_conf_setincludes(struct net_context
*c
,
990 struct smbconf_ctx
*conf_ctx
,
991 int argc
, const char **argv
)
995 uint32_t num_includes
;
996 const char **includes
;
998 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
1000 if (argc
< 1 || c
->display_usage
) {
1001 net_conf_setincludes_usage(c
, argc
, argv
);
1005 service
= talloc_strdup(mem_ctx
, argv
[0]);
1006 if (service
== NULL
) {
1007 d_printf(_("error: out of memory!\n"));
1011 num_includes
= argc
- 1;
1012 if (num_includes
== 0) {
1015 includes
= argv
+ 1;
1018 err
= smbconf_set_includes(conf_ctx
, service
, num_includes
, includes
);
1019 if (!SBC_ERROR_IS_OK(err
)) {
1020 d_printf(_("error setting includes: %s\n"), sbcErrorString(err
));
1027 TALLOC_FREE(mem_ctx
);
1031 static int net_conf_delincludes(struct net_context
*c
,
1032 struct smbconf_ctx
*conf_ctx
,
1033 int argc
, const char **argv
)
1038 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
1040 if (argc
!= 1 || c
->display_usage
) {
1041 net_conf_delincludes_usage(c
, argc
, argv
);
1045 service
= talloc_strdup(mem_ctx
, argv
[0]);
1046 if (service
== NULL
) {
1047 d_printf(_("error: out of memory!\n"));
1051 err
= smbconf_delete_includes(conf_ctx
, service
);
1052 if (!SBC_ERROR_IS_OK(err
)) {
1053 d_printf(_("error deleting includes: %s\n"), sbcErrorString(err
));
1060 TALLOC_FREE(mem_ctx
);
1065 /**********************************************************************
1067 * Wrapper and net_conf_run_function mechanism.
1069 **********************************************************************/
1072 * Wrapper function to call the main conf functions.
1073 * The wrapper calls handles opening and closing of the
1076 static int net_conf_wrap_function(struct net_context
*c
,
1077 int (*fn
)(struct net_context
*,
1078 struct smbconf_ctx
*,
1079 int, const char **),
1080 int argc
, const char **argv
)
1083 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
1084 struct smbconf_ctx
*conf_ctx
;
1087 err
= smbconf_init(mem_ctx
, &conf_ctx
, "registry:");
1088 if (!SBC_ERROR_IS_OK(err
)) {
1089 talloc_free(mem_ctx
);
1093 ret
= fn(c
, conf_ctx
, argc
, argv
);
1095 smbconf_shutdown(conf_ctx
);
1097 talloc_free(mem_ctx
);
1102 * We need a functable struct of our own, because the
1103 * functions are called through a wrapper that handles
1104 * the opening and closing of the configuration, and so on.
1106 struct conf_functable
{
1107 const char *funcname
;
1108 int (*fn
)(struct net_context
*c
, struct smbconf_ctx
*ctx
, int argc
,
1110 int valid_transports
;
1111 const char *description
;
1116 * This imitates net_run_function but calls the main functions
1117 * through the wrapper net_conf_wrap_function().
1119 static int net_conf_run_function(struct net_context
*c
, int argc
,
1120 const char **argv
, const char *whoami
,
1121 struct conf_functable
*table
)
1126 for (i
=0; table
[i
].funcname
; i
++) {
1127 if (strcasecmp_m(argv
[0], table
[i
].funcname
) == 0)
1128 return net_conf_wrap_function(c
, table
[i
].fn
,
1134 d_printf(_("Usage:\n"));
1135 for (i
=0; table
[i
].funcname
; i
++) {
1136 if (c
->display_usage
== false)
1137 d_printf("%s %-15s %s\n", whoami
, table
[i
].funcname
,
1138 table
[i
].description
);
1140 d_printf("%s\n", table
[i
].usage
);
1143 return c
->display_usage
?0:-1;
1147 * Entry-point for all the CONF functions.
1150 int net_conf(struct net_context
*c
, int argc
, const char **argv
)
1153 struct conf_functable func_table
[] = {
1157 NET_TRANSPORT_LOCAL
,
1158 N_("Dump the complete configuration in smb.conf like "
1160 N_("net conf list\n"
1161 " Dump the complete configuration in smb.conf "
1168 NET_TRANSPORT_LOCAL
,
1169 N_("Import configuration from file in smb.conf "
1171 N_("net conf import\n"
1172 " Import configuration from file in smb.conf "
1177 net_conf_listshares
,
1178 NET_TRANSPORT_LOCAL
,
1179 N_("List the share names."),
1180 N_("net conf listshares\n"
1181 " List the share names.")
1186 NET_TRANSPORT_LOCAL
,
1187 N_("Delete the complete configuration."),
1188 N_("net conf drop\n"
1189 " Delete the complete configuration.")
1194 NET_TRANSPORT_LOCAL
,
1195 N_("Show the definition of a share."),
1196 N_("net conf showshare\n"
1197 " Show the definition of a share.")
1202 NET_TRANSPORT_LOCAL
,
1203 N_("Create a new share."),
1204 N_("net conf addshare\n"
1205 " Create a new share.")
1210 NET_TRANSPORT_LOCAL
,
1211 N_("Delete a share."),
1212 N_("net conf delshare\n"
1218 NET_TRANSPORT_LOCAL
,
1219 N_("Store a parameter."),
1220 N_("net conf setparm\n"
1221 " Store a parameter.")
1226 NET_TRANSPORT_LOCAL
,
1227 N_("Retrieve the value of a parameter."),
1228 N_("net conf getparm\n"
1229 " Retrieve the value of a parameter.")
1234 NET_TRANSPORT_LOCAL
,
1235 N_("Delete a parameter."),
1236 N_("net conf delparm\n"
1237 " Delete a parameter.")
1241 net_conf_getincludes
,
1242 NET_TRANSPORT_LOCAL
,
1243 N_("Show the includes of a share definition."),
1244 N_("net conf getincludes\n"
1245 " Show the includes of a share definition.")
1249 net_conf_setincludes
,
1250 NET_TRANSPORT_LOCAL
,
1251 N_("Set includes for a share."),
1252 N_("net conf setincludes\n"
1253 " Set includes for a share.")
1257 net_conf_delincludes
,
1258 NET_TRANSPORT_LOCAL
,
1259 N_("Delete includes from a share definition."),
1260 N_("net conf delincludes\n"
1261 " Delete includes from a share definition.")
1263 {NULL
, NULL
, 0, NULL
, NULL
}
1266 ret
= net_conf_run_function(c
, argc
, argv
, "net conf", func_table
);