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
)) {
237 werr
= smbconf_set_includes(conf_ctx
, service
->name
, num_includes
,
238 (const char **)includes
);
241 TALLOC_FREE(mem_ctx
);
246 /**********************************************************************
248 * the main conf functions
250 **********************************************************************/
252 static int net_conf_list(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
253 int argc
, const char **argv
)
255 WERROR werr
= WERR_OK
;
259 uint32_t share_count
, param_count
;
260 struct smbconf_service
**shares
= NULL
;
262 mem_ctx
= talloc_stackframe();
264 if (argc
!= 0 || c
->display_usage
) {
265 net_conf_list_usage(c
, argc
, argv
);
269 werr
= smbconf_get_config(conf_ctx
, mem_ctx
, &num_shares
, &shares
);
270 if (!W_ERROR_IS_OK(werr
)) {
271 d_fprintf(stderr
, _("Error getting config: %s\n"),
276 for (share_count
= 0; share_count
< num_shares
; share_count
++) {
277 const char *indent
= "";
278 if (shares
[share_count
]->name
!= NULL
) {
279 d_printf("[%s]\n", shares
[share_count
]->name
);
282 for (param_count
= 0;
283 param_count
< shares
[share_count
]->num_params
;
286 d_printf("%s%s = %s\n",
288 shares
[share_count
]->param_names
[param_count
],
289 shares
[share_count
]->param_values
[param_count
]);
297 TALLOC_FREE(mem_ctx
);
301 static int net_conf_import(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
302 int argc
, const char **argv
)
305 const char *filename
= NULL
;
306 const char *servicename
= NULL
;
307 char *conf_source
= NULL
;
309 struct smbconf_ctx
*txt_ctx
;
312 if (c
->display_usage
)
313 return net_conf_import_usage(c
, argc
, argv
);
315 mem_ctx
= talloc_stackframe();
320 net_conf_import_usage(c
, argc
, argv
);
323 servicename
= talloc_strdup(mem_ctx
, argv
[1]);
324 if (servicename
== NULL
) {
325 d_printf(_("error: out of memory!\n"));
333 DEBUG(3,("net_conf_import: reading configuration from file %s.\n",
336 conf_source
= talloc_asprintf(mem_ctx
, "file:%s", filename
);
337 if (conf_source
== NULL
) {
338 d_printf(_("error: out of memory!\n"));
342 werr
= smbconf_init(mem_ctx
, &txt_ctx
, conf_source
);
343 if (!W_ERROR_IS_OK(werr
)) {
344 d_printf(_("error loading file '%s': %s\n"), filename
,
349 if (c
->opt_testmode
) {
350 d_printf(_("\nTEST MODE - "
351 "would import the following configuration:\n\n"));
354 if (servicename
!= NULL
) {
355 struct smbconf_service
*service
= NULL
;
357 werr
= smbconf_get_share(txt_ctx
, mem_ctx
,
360 if (!W_ERROR_IS_OK(werr
)) {
364 werr
= smbconf_transaction_start(conf_ctx
);
365 if (!W_ERROR_IS_OK(werr
)) {
366 d_printf(_("error starting transaction: %s\n"),
371 werr
= import_process_service(c
, conf_ctx
, service
);
372 if (!W_ERROR_IS_OK(werr
)) {
376 struct smbconf_service
**services
= NULL
;
377 uint32_t num_shares
, sidx
;
379 werr
= smbconf_get_config(txt_ctx
, mem_ctx
,
382 if (!W_ERROR_IS_OK(werr
)) {
385 if (!c
->opt_testmode
) {
386 werr
= smbconf_drop(conf_ctx
);
387 if (!W_ERROR_IS_OK(werr
)) {
393 * Wrap the importing of shares into a transaction,
394 * but only 100 at a time, in order to serve memory.
395 * The allocated memory accumulates across the actions
396 * within the transaction, and for me, some 1500
397 * imported shares, the MAX_TALLOC_SIZE of 256 MB
400 werr
= smbconf_transaction_start(conf_ctx
);
401 if (!W_ERROR_IS_OK(werr
)) {
402 d_printf(_("error starting transaction: %s\n"),
407 for (sidx
= 0; sidx
< num_shares
; sidx
++) {
408 werr
= import_process_service(c
, conf_ctx
,
410 if (!W_ERROR_IS_OK(werr
)) {
418 werr
= smbconf_transaction_commit(conf_ctx
);
419 if (!W_ERROR_IS_OK(werr
)) {
420 d_printf(_("error committing transaction: "
425 werr
= smbconf_transaction_start(conf_ctx
);
426 if (!W_ERROR_IS_OK(werr
)) {
427 d_printf(_("error starting transaction: %s\n"),
434 werr
= smbconf_transaction_commit(conf_ctx
);
435 if (!W_ERROR_IS_OK(werr
)) {
436 d_printf(_("error committing transaction: %s\n"),
445 werr
= smbconf_transaction_cancel(conf_ctx
);
446 if (!W_ERROR_IS_OK(werr
)) {
447 d_printf(_("error cancelling transaction: %s\n"),
452 TALLOC_FREE(mem_ctx
);
456 static int net_conf_listshares(struct net_context
*c
,
457 struct smbconf_ctx
*conf_ctx
, int argc
,
460 WERROR werr
= WERR_OK
;
462 uint32_t count
, num_shares
= 0;
463 char **share_names
= NULL
;
466 mem_ctx
= talloc_stackframe();
468 if (argc
!= 0 || c
->display_usage
) {
469 net_conf_listshares_usage(c
, argc
, argv
);
473 werr
= smbconf_get_share_names(conf_ctx
, mem_ctx
, &num_shares
,
475 if (!W_ERROR_IS_OK(werr
)) {
479 for (count
= 0; count
< num_shares
; count
++)
481 d_printf("%s\n", share_names
[count
]);
487 TALLOC_FREE(mem_ctx
);
491 static int net_conf_drop(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
492 int argc
, const char **argv
)
497 if (argc
!= 0 || c
->display_usage
) {
498 net_conf_drop_usage(c
, argc
, argv
);
502 werr
= smbconf_drop(conf_ctx
);
503 if (!W_ERROR_IS_OK(werr
)) {
504 d_fprintf(stderr
, _("Error deleting configuration: %s\n"),
515 static int net_conf_showshare(struct net_context
*c
,
516 struct smbconf_ctx
*conf_ctx
, int argc
,
520 WERROR werr
= WERR_OK
;
521 const char *sharename
= NULL
;
524 struct smbconf_service
*service
= NULL
;
526 mem_ctx
= talloc_stackframe();
528 if (argc
!= 1 || c
->display_usage
) {
529 net_conf_showshare_usage(c
, argc
, argv
);
533 sharename
= talloc_strdup(mem_ctx
, argv
[0]);
534 if (sharename
== NULL
) {
535 d_printf("error: out of memory!\n");
539 werr
= smbconf_get_share(conf_ctx
, mem_ctx
, sharename
, &service
);
540 if (!W_ERROR_IS_OK(werr
)) {
541 d_printf(_("error getting share parameters: %s\n"),
546 d_printf("[%s]\n", service
->name
);
548 for (count
= 0; count
< service
->num_params
; count
++) {
549 d_printf("\t%s = %s\n", service
->param_names
[count
],
550 service
->param_values
[count
]);
556 TALLOC_FREE(mem_ctx
);
561 * Add a share, with a couple of standard parameters, partly optional.
563 * This is a high level utility function of the net conf utility,
564 * not a direct frontend to the smbconf API.
566 static int net_conf_addshare(struct net_context
*c
,
567 struct smbconf_ctx
*conf_ctx
, int argc
,
571 WERROR werr
= WERR_OK
;
572 char *sharename
= NULL
;
573 const char *path
= NULL
;
574 const char *comment
= NULL
;
575 const char *guest_ok
= "no";
576 const char *writeable
= "no";
577 SMB_STRUCT_STAT sbuf
;
578 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
580 if (c
->display_usage
) {
581 net_conf_addshare_usage(c
, argc
, argv
);
590 net_conf_addshare_usage(c
, argc
, argv
);
595 if (!strnequal(argv
[3], "guest_ok=", 9)) {
596 net_conf_addshare_usage(c
, argc
, argv
);
599 switch (argv
[3][9]) {
609 net_conf_addshare_usage(c
, argc
, argv
);
613 if (!strnequal(argv
[2], "writeable=", 10)) {
614 net_conf_addshare_usage(c
, argc
, argv
);
617 switch (argv
[2][10]) {
627 net_conf_addshare_usage(c
, argc
, argv
);
632 sharename
= talloc_strdup(mem_ctx
, argv
[0]);
633 if (sharename
== NULL
) {
634 d_printf(_("error: out of memory!\n"));
645 /* validate share name */
647 if (!validate_net_name(sharename
, INVALID_SHARENAME_CHARS
,
650 d_fprintf(stderr
, _("ERROR: share name %s contains "
651 "invalid characters (any of %s)\n"),
652 sharename
, INVALID_SHARENAME_CHARS
);
656 if (strequal(sharename
, GLOBAL_NAME
)) {
658 _("ERROR: 'global' is not a valid share name.\n"));
662 if (smbconf_share_exists(conf_ctx
, sharename
)) {
663 d_fprintf(stderr
, _("ERROR: share %s already exists.\n"),
670 if (path
[0] != '/') {
672 _("Error: path '%s' is not an absolute path.\n"),
677 if (sys_stat(path
, &sbuf
, false) != 0) {
679 _("ERROR: cannot stat path '%s' to ensure "
680 "this is a directory.\n"
681 "Error was '%s'.\n"),
682 path
, strerror(errno
));
686 if (!S_ISDIR(sbuf
.st_ex_mode
)) {
688 _("ERROR: path '%s' is not a directory.\n"),
694 * start a transaction
697 werr
= smbconf_transaction_start(conf_ctx
);
698 if (!W_ERROR_IS_OK(werr
)) {
699 d_printf("error starting transaction: %s\n",
708 werr
= smbconf_create_share(conf_ctx
, sharename
);
709 if (!W_ERROR_IS_OK(werr
)) {
710 d_fprintf(stderr
, _("Error creating share %s: %s\n"),
711 sharename
, win_errstr(werr
));
716 * fill the share with parameters
719 werr
= smbconf_set_parameter(conf_ctx
, sharename
, "path", path
);
720 if (!W_ERROR_IS_OK(werr
)) {
721 d_fprintf(stderr
, _("Error setting parameter %s: %s\n"),
722 "path", win_errstr(werr
));
726 if (comment
!= NULL
) {
727 werr
= smbconf_set_parameter(conf_ctx
, sharename
, "comment",
729 if (!W_ERROR_IS_OK(werr
)) {
730 d_fprintf(stderr
, _("Error setting parameter %s: %s\n"),
731 "comment", win_errstr(werr
));
736 werr
= smbconf_set_parameter(conf_ctx
, sharename
, "guest ok", guest_ok
);
737 if (!W_ERROR_IS_OK(werr
)) {
738 d_fprintf(stderr
, _("Error setting parameter %s: %s\n"),
739 "'guest ok'", win_errstr(werr
));
743 werr
= smbconf_set_parameter(conf_ctx
, sharename
, "writeable",
745 if (!W_ERROR_IS_OK(werr
)) {
746 d_fprintf(stderr
, _("Error setting parameter %s: %s\n"),
747 "writeable", win_errstr(werr
));
752 * commit the whole thing
755 werr
= smbconf_transaction_commit(conf_ctx
);
756 if (!W_ERROR_IS_OK(werr
)) {
757 d_printf("error committing transaction: %s\n",
766 werr
= smbconf_transaction_cancel(conf_ctx
);
767 if (!W_ERROR_IS_OK(werr
)) {
768 d_printf("error cancelling transaction: %s\n",
773 TALLOC_FREE(mem_ctx
);
777 static int net_conf_delshare(struct net_context
*c
,
778 struct smbconf_ctx
*conf_ctx
, int argc
,
782 const char *sharename
= NULL
;
783 WERROR werr
= WERR_OK
;
784 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
786 if (argc
!= 1 || c
->display_usage
) {
787 net_conf_delshare_usage(c
, argc
, argv
);
790 sharename
= talloc_strdup(mem_ctx
, argv
[0]);
791 if (sharename
== NULL
) {
792 d_printf(_("error: out of memory!\n"));
796 werr
= smbconf_delete_share(conf_ctx
, sharename
);
797 if (!W_ERROR_IS_OK(werr
)) {
798 d_fprintf(stderr
, _("Error deleting share %s: %s\n"),
799 sharename
, win_errstr(werr
));
805 TALLOC_FREE(mem_ctx
);
809 static int net_conf_setparm(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
810 int argc
, const char **argv
)
813 WERROR werr
= WERR_OK
;
814 char *service
= NULL
;
816 const char *value_str
= NULL
;
817 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
819 if (argc
!= 3 || c
->display_usage
) {
820 net_conf_setparm_usage(c
, argc
, argv
);
824 * NULL service name means "dangling parameters" to libsmbconf.
825 * We use the empty string from the command line for this purpose.
827 if (strlen(argv
[0]) != 0) {
828 service
= talloc_strdup(mem_ctx
, argv
[0]);
829 if (service
== NULL
) {
830 d_printf(_("error: out of memory!\n"));
834 param
= strlower_talloc(mem_ctx
, argv
[1]);
836 d_printf(_("error: out of memory!\n"));
841 werr
= smbconf_transaction_start(conf_ctx
);
842 if (!W_ERROR_IS_OK(werr
)) {
843 d_printf(_("error starting transaction: %s\n"),
848 if (!smbconf_share_exists(conf_ctx
, service
)) {
849 werr
= smbconf_create_share(conf_ctx
, service
);
850 if (!W_ERROR_IS_OK(werr
)) {
851 d_fprintf(stderr
, _("Error creating share '%s': %s\n"),
852 service
, win_errstr(werr
));
857 werr
= smbconf_set_parameter(conf_ctx
, service
, param
, value_str
);
859 if (!W_ERROR_IS_OK(werr
)) {
860 d_fprintf(stderr
, _("Error setting value '%s': %s\n"),
861 param
, win_errstr(werr
));
865 werr
= smbconf_transaction_commit(conf_ctx
);
866 if (!W_ERROR_IS_OK(werr
)) {
867 d_printf(_("error committing transaction: %s\n"),
876 werr
= smbconf_transaction_cancel(conf_ctx
);
877 if (!W_ERROR_IS_OK(werr
)) {
878 d_printf(_("error cancelling transaction: %s\n"),
883 TALLOC_FREE(mem_ctx
);
887 static int net_conf_getparm(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
888 int argc
, const char **argv
)
891 WERROR werr
= WERR_OK
;
892 char *service
= NULL
;
897 mem_ctx
= talloc_stackframe();
899 if (argc
!= 2 || c
->display_usage
) {
900 net_conf_getparm_usage(c
, argc
, argv
);
904 * NULL service name means "dangling parameters" to libsmbconf.
905 * We use the empty string from the command line for this purpose.
907 if (strlen(argv
[0]) != 0) {
908 service
= talloc_strdup(mem_ctx
, argv
[0]);
909 if (service
== NULL
) {
910 d_printf(_("error: out of memory!\n"));
914 param
= strlower_talloc(mem_ctx
, argv
[1]);
916 d_printf(_("error: out of memory!\n"));
920 werr
= smbconf_get_parameter(conf_ctx
, mem_ctx
, service
, param
, &valstr
);
922 if (W_ERROR_EQUAL(werr
, WERR_NO_SUCH_SERVICE
)) {
924 _("Error: given service '%s' does not exist.\n"),
927 } else if (W_ERROR_EQUAL(werr
, WERR_INVALID_PARAM
)) {
929 _("Error: given parameter '%s' is not set.\n"),
932 } else if (!W_ERROR_IS_OK(werr
)) {
933 d_fprintf(stderr
, _("Error getting value '%s': %s.\n"),
934 param
, win_errstr(werr
));
938 d_printf("%s\n", valstr
);
942 TALLOC_FREE(mem_ctx
);
946 static int net_conf_delparm(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
947 int argc
, const char **argv
)
950 WERROR werr
= WERR_OK
;
951 char *service
= NULL
;
953 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
955 if (argc
!= 2 || c
->display_usage
) {
956 net_conf_delparm_usage(c
, argc
, argv
);
960 * NULL service name means "dangling parameters" to libsmbconf.
961 * We use the empty string from the command line for this purpose.
963 if (strlen(argv
[0]) != 0) {
964 service
= talloc_strdup(mem_ctx
, argv
[0]);
965 if (service
== NULL
) {
966 d_printf(_("error: out of memory!\n"));
970 param
= strlower_talloc(mem_ctx
, argv
[1]);
972 d_printf("error: out of memory!\n");
976 werr
= smbconf_delete_parameter(conf_ctx
, service
, param
);
978 if (W_ERROR_EQUAL(werr
, WERR_NO_SUCH_SERVICE
)) {
980 _("Error: given service '%s' does not exist.\n"),
983 } else if (W_ERROR_EQUAL(werr
, WERR_INVALID_PARAM
)) {
985 _("Error: given parameter '%s' is not set.\n"),
988 } else if (!W_ERROR_IS_OK(werr
)) {
989 d_fprintf(stderr
, _("Error deleting value '%s': %s.\n"),
990 param
, win_errstr(werr
));
997 TALLOC_FREE(mem_ctx
);
1001 static int net_conf_getincludes(struct net_context
*c
,
1002 struct smbconf_ctx
*conf_ctx
,
1003 int argc
, const char **argv
)
1006 uint32_t num_includes
;
1009 char **includes
= NULL
;
1011 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
1013 if (argc
!= 1 || c
->display_usage
) {
1014 net_conf_getincludes_usage(c
, argc
, argv
);
1018 service
= talloc_strdup(mem_ctx
, argv
[0]);
1019 if (service
== NULL
) {
1020 d_printf(_("error: out of memory!\n"));
1024 werr
= smbconf_get_includes(conf_ctx
, mem_ctx
, service
,
1025 &num_includes
, &includes
);
1026 if (!W_ERROR_IS_OK(werr
)) {
1027 d_printf(_("error getting includes: %s\n"), win_errstr(werr
));
1031 for (count
= 0; count
< num_includes
; count
++) {
1032 d_printf("include = %s\n", includes
[count
]);
1038 TALLOC_FREE(mem_ctx
);
1042 static int net_conf_setincludes(struct net_context
*c
,
1043 struct smbconf_ctx
*conf_ctx
,
1044 int argc
, const char **argv
)
1048 uint32_t num_includes
;
1049 const char **includes
;
1051 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
1053 if (argc
< 1 || c
->display_usage
) {
1054 net_conf_setincludes_usage(c
, argc
, argv
);
1058 service
= talloc_strdup(mem_ctx
, argv
[0]);
1059 if (service
== NULL
) {
1060 d_printf(_("error: out of memory!\n"));
1064 num_includes
= argc
- 1;
1065 if (num_includes
== 0) {
1068 includes
= argv
+ 1;
1071 werr
= smbconf_set_includes(conf_ctx
, service
, num_includes
, includes
);
1072 if (!W_ERROR_IS_OK(werr
)) {
1073 d_printf(_("error setting includes: %s\n"), win_errstr(werr
));
1080 TALLOC_FREE(mem_ctx
);
1084 static int net_conf_delincludes(struct net_context
*c
,
1085 struct smbconf_ctx
*conf_ctx
,
1086 int argc
, const char **argv
)
1091 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
1093 if (argc
!= 1 || c
->display_usage
) {
1094 net_conf_delincludes_usage(c
, argc
, argv
);
1098 service
= talloc_strdup(mem_ctx
, argv
[0]);
1099 if (service
== NULL
) {
1100 d_printf(_("error: out of memory!\n"));
1104 werr
= smbconf_delete_includes(conf_ctx
, service
);
1105 if (!W_ERROR_IS_OK(werr
)) {
1106 d_printf(_("error deleting includes: %s\n"), win_errstr(werr
));
1113 TALLOC_FREE(mem_ctx
);
1118 /**********************************************************************
1120 * Wrapper and net_conf_run_function mechanism.
1122 **********************************************************************/
1125 * Wrapper function to call the main conf functions.
1126 * The wrapper calls handles opening and closing of the
1129 static int net_conf_wrap_function(struct net_context
*c
,
1130 int (*fn
)(struct net_context
*,
1131 struct smbconf_ctx
*,
1132 int, const char **),
1133 int argc
, const char **argv
)
1136 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
1137 struct smbconf_ctx
*conf_ctx
;
1140 werr
= smbconf_init(mem_ctx
, &conf_ctx
, "registry:");
1142 if (!W_ERROR_IS_OK(werr
)) {
1146 ret
= fn(c
, conf_ctx
, argc
, argv
);
1148 smbconf_shutdown(conf_ctx
);
1154 * We need a functable struct of our own, because the
1155 * functions are called through a wrapper that handles
1156 * the opening and closing of the configuration, and so on.
1158 struct conf_functable
{
1159 const char *funcname
;
1160 int (*fn
)(struct net_context
*c
, struct smbconf_ctx
*ctx
, int argc
,
1162 int valid_transports
;
1163 const char *description
;
1168 * This imitates net_run_function but calls the main functions
1169 * through the wrapper net_conf_wrap_function().
1171 static int net_conf_run_function(struct net_context
*c
, int argc
,
1172 const char **argv
, const char *whoami
,
1173 struct conf_functable
*table
)
1178 for (i
=0; table
[i
].funcname
; i
++) {
1179 if (StrCaseCmp(argv
[0], table
[i
].funcname
) == 0)
1180 return net_conf_wrap_function(c
, table
[i
].fn
,
1186 d_printf(_("Usage:\n"));
1187 for (i
=0; table
[i
].funcname
; i
++) {
1188 if (c
->display_usage
== false)
1189 d_printf("%s %-15s %s\n", whoami
, table
[i
].funcname
,
1190 table
[i
].description
);
1192 d_printf("%s\n", table
[i
].usage
);
1195 return c
->display_usage
?0:-1;
1199 * Entry-point for all the CONF functions.
1202 int net_conf(struct net_context
*c
, int argc
, const char **argv
)
1205 struct conf_functable func_table
[] = {
1209 NET_TRANSPORT_LOCAL
,
1210 N_("Dump the complete configuration in smb.conf like "
1212 N_("net conf list\n"
1213 " Dump the complete configuration in smb.conf "
1220 NET_TRANSPORT_LOCAL
,
1221 N_("Import configuration from file in smb.conf "
1223 N_("net conf import\n"
1224 " Import configuration from file in smb.conf "
1229 net_conf_listshares
,
1230 NET_TRANSPORT_LOCAL
,
1231 N_("List the share names."),
1232 N_("net conf listshares\n"
1233 " List the share names.")
1238 NET_TRANSPORT_LOCAL
,
1239 N_("Delete the complete configuration."),
1240 N_("net conf drop\n"
1241 " Delete the complete configuration.")
1246 NET_TRANSPORT_LOCAL
,
1247 N_("Show the definition of a share."),
1248 N_("net conf showshare\n"
1249 " Show the definition of a share.")
1254 NET_TRANSPORT_LOCAL
,
1255 N_("Create a new share."),
1256 N_("net conf addshare\n"
1257 " Create a new share.")
1262 NET_TRANSPORT_LOCAL
,
1263 N_("Delete a share."),
1264 N_("net conf delshare\n"
1270 NET_TRANSPORT_LOCAL
,
1271 N_("Store a parameter."),
1272 N_("net conf setparm\n"
1273 " Store a parameter.")
1278 NET_TRANSPORT_LOCAL
,
1279 N_("Retrieve the value of a parameter."),
1280 N_("net conf getparm\n"
1281 " Retrieve the value of a parameter.")
1286 NET_TRANSPORT_LOCAL
,
1287 N_("Delete a parameter."),
1288 N_("net conf delparm\n"
1289 " Delete a parameter.")
1293 net_conf_getincludes
,
1294 NET_TRANSPORT_LOCAL
,
1295 N_("Show the includes of a share definition."),
1296 N_("net conf getincludes\n"
1297 " Show the includes of a share definition.")
1301 net_conf_setincludes
,
1302 NET_TRANSPORT_LOCAL
,
1303 N_("Set includes for a share."),
1304 N_("net conf setincludes\n"
1305 " Set includes for a share.")
1309 net_conf_delincludes
,
1310 NET_TRANSPORT_LOCAL
,
1311 N_("Delete includes from a share definition."),
1312 N_("net conf setincludes\n"
1313 " Delete includes from a share definition.")
1315 {NULL
, NULL
, 0, NULL
, NULL
}
1318 ret
= net_conf_run_function(c
, argc
, argv
, "net conf", func_table
);