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 "utils/net.h"
33 /**********************************************************************
37 **********************************************************************/
39 static int net_conf_list_usage(struct net_context
*c
, int argc
,
42 d_printf("%s net conf list\n", _("Usage:"));
46 static int net_conf_import_usage(struct net_context
*c
, int argc
,
51 _(" net conf import [--test|-T] <filename> "
53 "\t[--test|-T] testmode - do not act, just print "
54 "what would be done\n"
55 "\t<servicename> only import service <servicename>, "
56 "ignore the rest\n"));
60 static int net_conf_listshares_usage(struct net_context
*c
, int argc
,
63 d_printf("%s\nnet conf listshares\n", _("Usage:"));
67 static int net_conf_drop_usage(struct net_context
*c
, int argc
,
70 d_printf("%s\nnet conf drop\n", _("Usage:"));
74 static int net_conf_showshare_usage(struct net_context
*c
, int argc
,
79 _("net conf showshare <sharename>\n"));
83 static int net_conf_addshare_usage(struct net_context
*c
, int argc
,
88 _(" net conf addshare <sharename> <path> "
89 "[writeable={y|N} [guest_ok={y|N} [<comment>]]\n"
90 "\t<sharename> the new share name.\n"
91 "\t<path> the path on the filesystem to export.\n"
92 "\twriteable={y|N} set \"writeable to \"yes\" or "
93 "\"no\" (default) on this share.\n"
94 "\tguest_ok={y|N} set \"guest ok\" to \"yes\" or "
95 "\"no\" (default) on this share.\n"
96 "\t<comment> optional comment for the new share.\n"));
100 static int net_conf_delshare_usage(struct net_context
*c
, int argc
,
105 _("net conf delshare <sharename>\n"));
109 static int net_conf_setparm_usage(struct net_context
*c
, int argc
,
114 _(" net conf setparm <section> <param> <value>\n"));
118 static int net_conf_getparm_usage(struct net_context
*c
, int argc
,
123 _(" net conf getparm <section> <param>\n"));
127 static int net_conf_delparm_usage(struct net_context
*c
, int argc
,
132 _(" net conf delparm <section> <param>\n"));
136 static int net_conf_getincludes_usage(struct net_context
*c
, int argc
,
141 _(" net conf getincludes <section>\n"));
145 static int net_conf_setincludes_usage(struct net_context
*c
, int argc
,
150 _(" net conf setincludes <section> [<filename>]*\n"));
154 static int net_conf_delincludes_usage(struct net_context
*c
, int argc
,
159 _(" net conf delincludes <section>\n"));
164 /**********************************************************************
168 **********************************************************************/
171 * This functions process a service previously loaded with libsmbconf.
173 static WERROR
import_process_service(struct net_context
*c
,
174 struct smbconf_ctx
*conf_ctx
,
175 struct smbconf_service
*service
)
178 WERROR werr
= WERR_OK
;
179 uint32_t num_includes
= 0;
180 char **includes
= NULL
;
181 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
183 if (c
->opt_testmode
) {
184 const char *indent
= "";
185 if (service
->name
!= NULL
) {
186 d_printf("[%s]\n", service
->name
);
189 for (idx
= 0; idx
< service
->num_params
; idx
++) {
190 d_printf("%s%s = %s\n", indent
,
191 service
->param_names
[idx
],
192 service
->param_values
[idx
]);
198 if (smbconf_share_exists(conf_ctx
, service
->name
)) {
199 werr
= smbconf_delete_share(conf_ctx
, service
->name
);
200 if (!W_ERROR_IS_OK(werr
)) {
204 werr
= smbconf_create_share(conf_ctx
, service
->name
);
205 if (!W_ERROR_IS_OK(werr
)) {
209 for (idx
= 0; idx
< service
->num_params
; idx
++) {
210 if (strequal(service
->param_names
[idx
], "include")) {
211 includes
= TALLOC_REALLOC_ARRAY(mem_ctx
,
215 if (includes
== NULL
) {
219 includes
[num_includes
] = talloc_strdup(includes
,
220 service
->param_values
[idx
]);
221 if (includes
[num_includes
] == NULL
) {
227 werr
= smbconf_set_parameter(conf_ctx
,
229 service
->param_names
[idx
],
230 service
->param_values
[idx
]);
231 if (!W_ERROR_IS_OK(werr
)) {
233 _("Error in section [%s], parameter \"%s\": %s\n"),
234 service
->name
, service
->param_names
[idx
],
241 werr
= smbconf_set_includes(conf_ctx
, service
->name
, num_includes
,
242 (const char **)includes
);
245 TALLOC_FREE(mem_ctx
);
250 /**********************************************************************
252 * the main conf functions
254 **********************************************************************/
256 static int net_conf_list(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
257 int argc
, const char **argv
)
259 WERROR werr
= WERR_OK
;
263 uint32_t share_count
, param_count
;
264 struct smbconf_service
**shares
= NULL
;
266 mem_ctx
= talloc_stackframe();
268 if (argc
!= 0 || c
->display_usage
) {
269 net_conf_list_usage(c
, argc
, argv
);
273 werr
= smbconf_get_config(conf_ctx
, mem_ctx
, &num_shares
, &shares
);
274 if (!W_ERROR_IS_OK(werr
)) {
275 d_fprintf(stderr
, _("Error getting config: %s\n"),
280 for (share_count
= 0; share_count
< num_shares
; share_count
++) {
281 const char *indent
= "";
282 if (shares
[share_count
]->name
!= NULL
) {
283 d_printf("[%s]\n", shares
[share_count
]->name
);
286 for (param_count
= 0;
287 param_count
< shares
[share_count
]->num_params
;
290 d_printf("%s%s = %s\n",
292 shares
[share_count
]->param_names
[param_count
],
293 shares
[share_count
]->param_values
[param_count
]);
301 TALLOC_FREE(mem_ctx
);
305 static int net_conf_import(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
306 int argc
, const char **argv
)
309 const char *filename
= NULL
;
310 const char *servicename
= NULL
;
311 char *conf_source
= NULL
;
313 struct smbconf_ctx
*txt_ctx
;
316 if (c
->display_usage
)
317 return net_conf_import_usage(c
, argc
, argv
);
319 mem_ctx
= talloc_stackframe();
324 net_conf_import_usage(c
, argc
, argv
);
327 servicename
= talloc_strdup(mem_ctx
, argv
[1]);
328 if (servicename
== NULL
) {
329 d_printf(_("error: out of memory!\n"));
337 DEBUG(3,("net_conf_import: reading configuration from file %s.\n",
340 conf_source
= talloc_asprintf(mem_ctx
, "file:%s", filename
);
341 if (conf_source
== NULL
) {
342 d_printf(_("error: out of memory!\n"));
346 werr
= smbconf_init(mem_ctx
, &txt_ctx
, conf_source
);
347 if (!W_ERROR_IS_OK(werr
)) {
348 d_printf(_("error loading file '%s': %s\n"), filename
,
353 if (c
->opt_testmode
) {
354 d_printf(_("\nTEST MODE - "
355 "would import the following configuration:\n\n"));
358 if (servicename
!= NULL
) {
359 struct smbconf_service
*service
= NULL
;
361 werr
= smbconf_get_share(txt_ctx
, mem_ctx
,
364 if (!W_ERROR_IS_OK(werr
)) {
368 werr
= smbconf_transaction_start(conf_ctx
);
369 if (!W_ERROR_IS_OK(werr
)) {
370 d_printf(_("error starting transaction: %s\n"),
375 werr
= import_process_service(c
, conf_ctx
, service
);
376 if (!W_ERROR_IS_OK(werr
)) {
380 struct smbconf_service
**services
= NULL
;
381 uint32_t num_shares
, sidx
;
383 werr
= smbconf_get_config(txt_ctx
, mem_ctx
,
386 if (!W_ERROR_IS_OK(werr
)) {
389 if (!c
->opt_testmode
) {
390 werr
= smbconf_drop(conf_ctx
);
391 if (!W_ERROR_IS_OK(werr
)) {
397 * Wrap the importing of shares into a transaction,
398 * but only 100 at a time, in order to serve memory.
399 * The allocated memory accumulates across the actions
400 * within the transaction, and for me, some 1500
401 * imported shares, the MAX_TALLOC_SIZE of 256 MB
404 werr
= smbconf_transaction_start(conf_ctx
);
405 if (!W_ERROR_IS_OK(werr
)) {
406 d_printf(_("error starting transaction: %s\n"),
411 for (sidx
= 0; sidx
< num_shares
; sidx
++) {
412 werr
= import_process_service(c
, conf_ctx
,
414 if (!W_ERROR_IS_OK(werr
)) {
422 werr
= smbconf_transaction_commit(conf_ctx
);
423 if (!W_ERROR_IS_OK(werr
)) {
424 d_printf(_("error committing transaction: "
429 werr
= smbconf_transaction_start(conf_ctx
);
430 if (!W_ERROR_IS_OK(werr
)) {
431 d_printf(_("error starting transaction: %s\n"),
438 werr
= smbconf_transaction_commit(conf_ctx
);
439 if (!W_ERROR_IS_OK(werr
)) {
440 d_printf(_("error committing transaction: %s\n"),
449 werr
= smbconf_transaction_cancel(conf_ctx
);
450 if (!W_ERROR_IS_OK(werr
)) {
451 d_printf(_("error cancelling transaction: %s\n"),
456 TALLOC_FREE(mem_ctx
);
460 static int net_conf_listshares(struct net_context
*c
,
461 struct smbconf_ctx
*conf_ctx
, int argc
,
464 WERROR werr
= WERR_OK
;
466 uint32_t count
, num_shares
= 0;
467 char **share_names
= NULL
;
470 mem_ctx
= talloc_stackframe();
472 if (argc
!= 0 || c
->display_usage
) {
473 net_conf_listshares_usage(c
, argc
, argv
);
477 werr
= smbconf_get_share_names(conf_ctx
, mem_ctx
, &num_shares
,
479 if (!W_ERROR_IS_OK(werr
)) {
483 for (count
= 0; count
< num_shares
; count
++)
485 d_printf("%s\n", share_names
[count
]);
491 TALLOC_FREE(mem_ctx
);
495 static int net_conf_drop(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
496 int argc
, const char **argv
)
501 if (argc
!= 0 || c
->display_usage
) {
502 net_conf_drop_usage(c
, argc
, argv
);
506 werr
= smbconf_drop(conf_ctx
);
507 if (!W_ERROR_IS_OK(werr
)) {
508 d_fprintf(stderr
, _("Error deleting configuration: %s\n"),
519 static int net_conf_showshare(struct net_context
*c
,
520 struct smbconf_ctx
*conf_ctx
, int argc
,
524 WERROR werr
= WERR_OK
;
525 const char *sharename
= NULL
;
528 struct smbconf_service
*service
= NULL
;
530 mem_ctx
= talloc_stackframe();
532 if (argc
!= 1 || c
->display_usage
) {
533 net_conf_showshare_usage(c
, argc
, argv
);
537 sharename
= talloc_strdup(mem_ctx
, argv
[0]);
538 if (sharename
== NULL
) {
539 d_printf("error: out of memory!\n");
543 werr
= smbconf_get_share(conf_ctx
, mem_ctx
, sharename
, &service
);
544 if (!W_ERROR_IS_OK(werr
)) {
545 d_printf(_("error getting share parameters: %s\n"),
550 d_printf("[%s]\n", service
->name
);
552 for (count
= 0; count
< service
->num_params
; count
++) {
553 d_printf("\t%s = %s\n", service
->param_names
[count
],
554 service
->param_values
[count
]);
560 TALLOC_FREE(mem_ctx
);
565 * Add a share, with a couple of standard parameters, partly optional.
567 * This is a high level utility function of the net conf utility,
568 * not a direct frontend to the smbconf API.
570 static int net_conf_addshare(struct net_context
*c
,
571 struct smbconf_ctx
*conf_ctx
, int argc
,
575 WERROR werr
= WERR_OK
;
576 char *sharename
= NULL
;
577 const char *path
= NULL
;
578 const char *comment
= NULL
;
579 const char *guest_ok
= "no";
580 const char *writeable
= "no";
581 SMB_STRUCT_STAT sbuf
;
582 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
584 if (c
->display_usage
) {
585 net_conf_addshare_usage(c
, argc
, argv
);
594 net_conf_addshare_usage(c
, argc
, argv
);
599 if (!strnequal(argv
[3], "guest_ok=", 9)) {
600 net_conf_addshare_usage(c
, argc
, argv
);
603 switch (argv
[3][9]) {
613 net_conf_addshare_usage(c
, argc
, argv
);
617 if (!strnequal(argv
[2], "writeable=", 10)) {
618 net_conf_addshare_usage(c
, argc
, argv
);
621 switch (argv
[2][10]) {
631 net_conf_addshare_usage(c
, argc
, argv
);
636 sharename
= talloc_strdup(mem_ctx
, argv
[0]);
637 if (sharename
== NULL
) {
638 d_printf(_("error: out of memory!\n"));
649 /* validate share name */
651 if (!validate_net_name(sharename
, INVALID_SHARENAME_CHARS
,
654 d_fprintf(stderr
, _("ERROR: share name %s contains "
655 "invalid characters (any of %s)\n"),
656 sharename
, INVALID_SHARENAME_CHARS
);
660 if (strequal(sharename
, GLOBAL_NAME
)) {
662 _("ERROR: 'global' is not a valid share name.\n"));
666 if (smbconf_share_exists(conf_ctx
, sharename
)) {
667 d_fprintf(stderr
, _("ERROR: share %s already exists.\n"),
674 if (path
[0] != '/') {
676 _("Error: path '%s' is not an absolute path.\n"),
681 if (sys_stat(path
, &sbuf
, false) != 0) {
683 _("ERROR: cannot stat path '%s' to ensure "
684 "this is a directory.\n"
685 "Error was '%s'.\n"),
686 path
, strerror(errno
));
690 if (!S_ISDIR(sbuf
.st_ex_mode
)) {
692 _("ERROR: path '%s' is not a directory.\n"),
698 * start a transaction
701 werr
= smbconf_transaction_start(conf_ctx
);
702 if (!W_ERROR_IS_OK(werr
)) {
703 d_printf("error starting transaction: %s\n",
712 werr
= smbconf_create_share(conf_ctx
, sharename
);
713 if (!W_ERROR_IS_OK(werr
)) {
714 d_fprintf(stderr
, _("Error creating share %s: %s\n"),
715 sharename
, win_errstr(werr
));
720 * fill the share with parameters
723 werr
= smbconf_set_parameter(conf_ctx
, sharename
, "path", path
);
724 if (!W_ERROR_IS_OK(werr
)) {
725 d_fprintf(stderr
, _("Error setting parameter %s: %s\n"),
726 "path", win_errstr(werr
));
730 if (comment
!= NULL
) {
731 werr
= smbconf_set_parameter(conf_ctx
, sharename
, "comment",
733 if (!W_ERROR_IS_OK(werr
)) {
734 d_fprintf(stderr
, _("Error setting parameter %s: %s\n"),
735 "comment", win_errstr(werr
));
740 werr
= smbconf_set_parameter(conf_ctx
, sharename
, "guest ok", guest_ok
);
741 if (!W_ERROR_IS_OK(werr
)) {
742 d_fprintf(stderr
, _("Error setting parameter %s: %s\n"),
743 "'guest ok'", win_errstr(werr
));
747 werr
= smbconf_set_parameter(conf_ctx
, sharename
, "writeable",
749 if (!W_ERROR_IS_OK(werr
)) {
750 d_fprintf(stderr
, _("Error setting parameter %s: %s\n"),
751 "writeable", win_errstr(werr
));
756 * commit the whole thing
759 werr
= smbconf_transaction_commit(conf_ctx
);
760 if (!W_ERROR_IS_OK(werr
)) {
761 d_printf("error committing transaction: %s\n",
770 werr
= smbconf_transaction_cancel(conf_ctx
);
771 if (!W_ERROR_IS_OK(werr
)) {
772 d_printf("error cancelling transaction: %s\n",
777 TALLOC_FREE(mem_ctx
);
781 static int net_conf_delshare(struct net_context
*c
,
782 struct smbconf_ctx
*conf_ctx
, int argc
,
786 const char *sharename
= NULL
;
787 WERROR werr
= WERR_OK
;
788 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
790 if (argc
!= 1 || c
->display_usage
) {
791 net_conf_delshare_usage(c
, argc
, argv
);
794 sharename
= talloc_strdup(mem_ctx
, argv
[0]);
795 if (sharename
== NULL
) {
796 d_printf(_("error: out of memory!\n"));
800 werr
= smbconf_delete_share(conf_ctx
, sharename
);
801 if (!W_ERROR_IS_OK(werr
)) {
802 d_fprintf(stderr
, _("Error deleting share %s: %s\n"),
803 sharename
, win_errstr(werr
));
809 TALLOC_FREE(mem_ctx
);
813 static int net_conf_setparm(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
814 int argc
, const char **argv
)
817 WERROR werr
= WERR_OK
;
818 char *service
= NULL
;
820 const char *value_str
= NULL
;
821 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
823 if (argc
!= 3 || c
->display_usage
) {
824 net_conf_setparm_usage(c
, argc
, argv
);
828 * NULL service name means "dangling parameters" to libsmbconf.
829 * We use the empty string from the command line for this purpose.
831 if (strlen(argv
[0]) != 0) {
832 service
= talloc_strdup(mem_ctx
, argv
[0]);
833 if (service
== NULL
) {
834 d_printf(_("error: out of memory!\n"));
838 param
= strlower_talloc(mem_ctx
, argv
[1]);
840 d_printf(_("error: out of memory!\n"));
845 werr
= smbconf_transaction_start(conf_ctx
);
846 if (!W_ERROR_IS_OK(werr
)) {
847 d_printf(_("error starting transaction: %s\n"),
852 if (!smbconf_share_exists(conf_ctx
, service
)) {
853 werr
= smbconf_create_share(conf_ctx
, service
);
854 if (!W_ERROR_IS_OK(werr
)) {
855 d_fprintf(stderr
, _("Error creating share '%s': %s\n"),
856 service
, win_errstr(werr
));
861 werr
= smbconf_set_parameter(conf_ctx
, service
, param
, value_str
);
863 if (!W_ERROR_IS_OK(werr
)) {
864 d_fprintf(stderr
, _("Error setting value '%s': %s\n"),
865 param
, win_errstr(werr
));
869 werr
= smbconf_transaction_commit(conf_ctx
);
870 if (!W_ERROR_IS_OK(werr
)) {
871 d_printf(_("error committing transaction: %s\n"),
880 werr
= smbconf_transaction_cancel(conf_ctx
);
881 if (!W_ERROR_IS_OK(werr
)) {
882 d_printf(_("error cancelling transaction: %s\n"),
887 TALLOC_FREE(mem_ctx
);
891 static int net_conf_getparm(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
892 int argc
, const char **argv
)
895 WERROR werr
= WERR_OK
;
896 char *service
= NULL
;
901 mem_ctx
= talloc_stackframe();
903 if (argc
!= 2 || c
->display_usage
) {
904 net_conf_getparm_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 werr
= smbconf_get_parameter(conf_ctx
, mem_ctx
, service
, param
, &valstr
);
926 if (W_ERROR_EQUAL(werr
, WERR_NO_SUCH_SERVICE
)) {
928 _("Error: given service '%s' does not exist.\n"),
931 } else if (W_ERROR_EQUAL(werr
, WERR_INVALID_PARAM
)) {
933 _("Error: given parameter '%s' is not set.\n"),
936 } else if (!W_ERROR_IS_OK(werr
)) {
937 d_fprintf(stderr
, _("Error getting value '%s': %s.\n"),
938 param
, win_errstr(werr
));
942 d_printf("%s\n", valstr
);
946 TALLOC_FREE(mem_ctx
);
950 static int net_conf_delparm(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
951 int argc
, const char **argv
)
954 WERROR werr
= WERR_OK
;
955 char *service
= NULL
;
957 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
959 if (argc
!= 2 || c
->display_usage
) {
960 net_conf_delparm_usage(c
, argc
, argv
);
964 * NULL service name means "dangling parameters" to libsmbconf.
965 * We use the empty string from the command line for this purpose.
967 if (strlen(argv
[0]) != 0) {
968 service
= talloc_strdup(mem_ctx
, argv
[0]);
969 if (service
== NULL
) {
970 d_printf(_("error: out of memory!\n"));
974 param
= strlower_talloc(mem_ctx
, argv
[1]);
976 d_printf("error: out of memory!\n");
980 werr
= smbconf_delete_parameter(conf_ctx
, service
, param
);
982 if (W_ERROR_EQUAL(werr
, WERR_NO_SUCH_SERVICE
)) {
984 _("Error: given service '%s' does not exist.\n"),
987 } else if (W_ERROR_EQUAL(werr
, WERR_INVALID_PARAM
)) {
989 _("Error: given parameter '%s' is not set.\n"),
992 } else if (!W_ERROR_IS_OK(werr
)) {
993 d_fprintf(stderr
, _("Error deleting value '%s': %s.\n"),
994 param
, win_errstr(werr
));
1001 TALLOC_FREE(mem_ctx
);
1005 static int net_conf_getincludes(struct net_context
*c
,
1006 struct smbconf_ctx
*conf_ctx
,
1007 int argc
, const char **argv
)
1010 uint32_t num_includes
;
1013 char **includes
= NULL
;
1015 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
1017 if (argc
!= 1 || c
->display_usage
) {
1018 net_conf_getincludes_usage(c
, argc
, argv
);
1022 service
= talloc_strdup(mem_ctx
, argv
[0]);
1023 if (service
== NULL
) {
1024 d_printf(_("error: out of memory!\n"));
1028 werr
= smbconf_get_includes(conf_ctx
, mem_ctx
, service
,
1029 &num_includes
, &includes
);
1030 if (!W_ERROR_IS_OK(werr
)) {
1031 d_printf(_("error getting includes: %s\n"), win_errstr(werr
));
1035 for (count
= 0; count
< num_includes
; count
++) {
1036 d_printf("include = %s\n", includes
[count
]);
1042 TALLOC_FREE(mem_ctx
);
1046 static int net_conf_setincludes(struct net_context
*c
,
1047 struct smbconf_ctx
*conf_ctx
,
1048 int argc
, const char **argv
)
1052 uint32_t num_includes
;
1053 const char **includes
;
1055 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
1057 if (argc
< 1 || c
->display_usage
) {
1058 net_conf_setincludes_usage(c
, argc
, argv
);
1062 service
= talloc_strdup(mem_ctx
, argv
[0]);
1063 if (service
== NULL
) {
1064 d_printf(_("error: out of memory!\n"));
1068 num_includes
= argc
- 1;
1069 if (num_includes
== 0) {
1072 includes
= argv
+ 1;
1075 werr
= smbconf_set_includes(conf_ctx
, service
, num_includes
, includes
);
1076 if (!W_ERROR_IS_OK(werr
)) {
1077 d_printf(_("error setting includes: %s\n"), win_errstr(werr
));
1084 TALLOC_FREE(mem_ctx
);
1088 static int net_conf_delincludes(struct net_context
*c
,
1089 struct smbconf_ctx
*conf_ctx
,
1090 int argc
, const char **argv
)
1095 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
1097 if (argc
!= 1 || c
->display_usage
) {
1098 net_conf_delincludes_usage(c
, argc
, argv
);
1102 service
= talloc_strdup(mem_ctx
, argv
[0]);
1103 if (service
== NULL
) {
1104 d_printf(_("error: out of memory!\n"));
1108 werr
= smbconf_delete_includes(conf_ctx
, service
);
1109 if (!W_ERROR_IS_OK(werr
)) {
1110 d_printf(_("error deleting includes: %s\n"), win_errstr(werr
));
1117 TALLOC_FREE(mem_ctx
);
1122 /**********************************************************************
1124 * Wrapper and net_conf_run_function mechanism.
1126 **********************************************************************/
1129 * Wrapper function to call the main conf functions.
1130 * The wrapper calls handles opening and closing of the
1133 static int net_conf_wrap_function(struct net_context
*c
,
1134 int (*fn
)(struct net_context
*,
1135 struct smbconf_ctx
*,
1136 int, const char **),
1137 int argc
, const char **argv
)
1140 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
1141 struct smbconf_ctx
*conf_ctx
;
1144 werr
= smbconf_init(mem_ctx
, &conf_ctx
, "registry:");
1146 if (!W_ERROR_IS_OK(werr
)) {
1150 ret
= fn(c
, conf_ctx
, argc
, argv
);
1152 smbconf_shutdown(conf_ctx
);
1158 * We need a functable struct of our own, because the
1159 * functions are called through a wrapper that handles
1160 * the opening and closing of the configuration, and so on.
1162 struct conf_functable
{
1163 const char *funcname
;
1164 int (*fn
)(struct net_context
*c
, struct smbconf_ctx
*ctx
, int argc
,
1166 int valid_transports
;
1167 const char *description
;
1172 * This imitates net_run_function but calls the main functions
1173 * through the wrapper net_conf_wrap_function().
1175 static int net_conf_run_function(struct net_context
*c
, int argc
,
1176 const char **argv
, const char *whoami
,
1177 struct conf_functable
*table
)
1182 for (i
=0; table
[i
].funcname
; i
++) {
1183 if (StrCaseCmp(argv
[0], table
[i
].funcname
) == 0)
1184 return net_conf_wrap_function(c
, table
[i
].fn
,
1190 d_printf(_("Usage:\n"));
1191 for (i
=0; table
[i
].funcname
; i
++) {
1192 if (c
->display_usage
== false)
1193 d_printf("%s %-15s %s\n", whoami
, table
[i
].funcname
,
1194 table
[i
].description
);
1196 d_printf("%s\n", table
[i
].usage
);
1199 return c
->display_usage
?0:-1;
1203 * Entry-point for all the CONF functions.
1206 int net_conf(struct net_context
*c
, int argc
, const char **argv
)
1209 struct conf_functable func_table
[] = {
1213 NET_TRANSPORT_LOCAL
,
1214 N_("Dump the complete configuration in smb.conf like "
1216 N_("net conf list\n"
1217 " Dump the complete configuration in smb.conf "
1224 NET_TRANSPORT_LOCAL
,
1225 N_("Import configuration from file in smb.conf "
1227 N_("net conf import\n"
1228 " Import configuration from file in smb.conf "
1233 net_conf_listshares
,
1234 NET_TRANSPORT_LOCAL
,
1235 N_("List the share names."),
1236 N_("net conf listshares\n"
1237 " List the share names.")
1242 NET_TRANSPORT_LOCAL
,
1243 N_("Delete the complete configuration."),
1244 N_("net conf drop\n"
1245 " Delete the complete configuration.")
1250 NET_TRANSPORT_LOCAL
,
1251 N_("Show the definition of a share."),
1252 N_("net conf showshare\n"
1253 " Show the definition of a share.")
1258 NET_TRANSPORT_LOCAL
,
1259 N_("Create a new share."),
1260 N_("net conf addshare\n"
1261 " Create a new share.")
1266 NET_TRANSPORT_LOCAL
,
1267 N_("Delete a share."),
1268 N_("net conf delshare\n"
1274 NET_TRANSPORT_LOCAL
,
1275 N_("Store a parameter."),
1276 N_("net conf setparm\n"
1277 " Store a parameter.")
1282 NET_TRANSPORT_LOCAL
,
1283 N_("Retrieve the value of a parameter."),
1284 N_("net conf getparm\n"
1285 " Retrieve the value of a parameter.")
1290 NET_TRANSPORT_LOCAL
,
1291 N_("Delete a parameter."),
1292 N_("net conf delparm\n"
1293 " Delete a parameter.")
1297 net_conf_getincludes
,
1298 NET_TRANSPORT_LOCAL
,
1299 N_("Show the includes of a share definition."),
1300 N_("net conf getincludes\n"
1301 " Show the includes of a share definition.")
1305 net_conf_setincludes
,
1306 NET_TRANSPORT_LOCAL
,
1307 N_("Set includes for a share."),
1308 N_("net conf setincludes\n"
1309 " Set includes for a share.")
1313 net_conf_delincludes
,
1314 NET_TRANSPORT_LOCAL
,
1315 N_("Delete includes from a share definition."),
1316 N_("net conf setincludes\n"
1317 " Delete includes from a share definition.")
1319 {NULL
, NULL
, 0, NULL
, NULL
}
1322 ret
= net_conf_run_function(c
, argc
, argv
, "net conf", func_table
);