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"
32 #include "lib/smbconf/smbconf.h"
33 #include "lib/smbconf/smbconf_init.h"
34 #include "lib/smbconf/smbconf_reg.h"
36 /**********************************************************************
40 **********************************************************************/
42 static int net_conf_list_usage(struct net_context
*c
, int argc
,
45 d_printf("%s net conf list\n", _("Usage:"));
49 static int net_conf_import_usage(struct net_context
*c
, int argc
,
54 _(" net conf import [--test|-T] <filename> "
56 "\t[--test|-T] testmode - do not act, just print "
57 "what would be done\n"
58 "\t<servicename> only import service <servicename>, "
59 "ignore the rest\n"));
63 static int net_conf_listshares_usage(struct net_context
*c
, int argc
,
66 d_printf("%s\nnet conf listshares\n", _("Usage:"));
70 static int net_conf_drop_usage(struct net_context
*c
, int argc
,
73 d_printf("%s\nnet conf drop\n", _("Usage:"));
77 static int net_conf_showshare_usage(struct net_context
*c
, int argc
,
82 _("net conf showshare <sharename>\n"));
86 static int net_conf_addshare_usage(struct net_context
*c
, int argc
,
91 _(" net conf addshare <sharename> <path> "
92 "[writeable={y|N} [guest_ok={y|N} [<comment>]]\n"
93 "\t<sharename> the new share name.\n"
94 "\t<path> the path on the filesystem to export.\n"
95 "\twriteable={y|N} set \"writeable to \"yes\" or "
96 "\"no\" (default) on this share.\n"
97 "\tguest_ok={y|N} set \"guest ok\" to \"yes\" or "
98 "\"no\" (default) on this share.\n"
99 "\t<comment> optional comment for the new share.\n"));
103 static int net_conf_delshare_usage(struct net_context
*c
, int argc
,
108 _("net conf delshare <sharename>\n"));
112 static int net_conf_setparm_usage(struct net_context
*c
, int argc
,
117 _(" net conf setparm <section> <param> <value>\n"));
121 static int net_conf_getparm_usage(struct net_context
*c
, int argc
,
126 _(" net conf getparm <section> <param>\n"));
130 static int net_conf_delparm_usage(struct net_context
*c
, int argc
,
135 _(" net conf delparm <section> <param>\n"));
139 static int net_conf_getincludes_usage(struct net_context
*c
, int argc
,
144 _(" net conf getincludes <section>\n"));
148 static int net_conf_setincludes_usage(struct net_context
*c
, int argc
,
153 _(" net conf setincludes <section> [<filename>]*\n"));
157 static int net_conf_delincludes_usage(struct net_context
*c
, int argc
,
162 _(" net conf delincludes <section>\n"));
167 /**********************************************************************
171 **********************************************************************/
174 * This functions process a service previously loaded with libsmbconf.
176 static WERROR
import_process_service(struct net_context
*c
,
177 struct smbconf_ctx
*conf_ctx
,
178 struct smbconf_service
*service
)
181 WERROR werr
= WERR_OK
;
182 uint32_t num_includes
= 0;
183 char **includes
= NULL
;
184 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
186 if (c
->opt_testmode
) {
187 const char *indent
= "";
188 if (service
->name
!= NULL
) {
189 d_printf("[%s]\n", service
->name
);
192 for (idx
= 0; idx
< service
->num_params
; idx
++) {
193 d_printf("%s%s = %s\n", indent
,
194 service
->param_names
[idx
],
195 service
->param_values
[idx
]);
201 if (smbconf_share_exists(conf_ctx
, service
->name
)) {
202 werr
= smbconf_delete_share(conf_ctx
, service
->name
);
203 if (!W_ERROR_IS_OK(werr
)) {
207 werr
= smbconf_create_share(conf_ctx
, service
->name
);
208 if (!W_ERROR_IS_OK(werr
)) {
212 for (idx
= 0; idx
< service
->num_params
; idx
++) {
213 if (strequal(service
->param_names
[idx
], "include")) {
214 includes
= TALLOC_REALLOC_ARRAY(mem_ctx
,
218 if (includes
== NULL
) {
222 includes
[num_includes
] = talloc_strdup(includes
,
223 service
->param_values
[idx
]);
224 if (includes
[num_includes
] == NULL
) {
230 werr
= smbconf_set_parameter(conf_ctx
,
232 service
->param_names
[idx
],
233 service
->param_values
[idx
]);
234 if (!W_ERROR_IS_OK(werr
)) {
236 _("Error in section [%s], parameter \"%s\": %s\n"),
237 service
->name
, service
->param_names
[idx
],
244 werr
= smbconf_set_includes(conf_ctx
, service
->name
, num_includes
,
245 (const char **)includes
);
248 TALLOC_FREE(mem_ctx
);
253 /**********************************************************************
255 * the main conf functions
257 **********************************************************************/
259 static int net_conf_list(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
260 int argc
, const char **argv
)
262 WERROR werr
= WERR_OK
;
266 uint32_t share_count
, param_count
;
267 struct smbconf_service
**shares
= NULL
;
269 mem_ctx
= talloc_stackframe();
271 if (argc
!= 0 || c
->display_usage
) {
272 net_conf_list_usage(c
, argc
, argv
);
276 werr
= smbconf_get_config(conf_ctx
, mem_ctx
, &num_shares
, &shares
);
277 if (!W_ERROR_IS_OK(werr
)) {
278 d_fprintf(stderr
, _("Error getting config: %s\n"),
283 for (share_count
= 0; share_count
< num_shares
; share_count
++) {
284 const char *indent
= "";
285 if (shares
[share_count
]->name
!= NULL
) {
286 d_printf("[%s]\n", shares
[share_count
]->name
);
289 for (param_count
= 0;
290 param_count
< shares
[share_count
]->num_params
;
293 d_printf("%s%s = %s\n",
295 shares
[share_count
]->param_names
[param_count
],
296 shares
[share_count
]->param_values
[param_count
]);
304 TALLOC_FREE(mem_ctx
);
308 static int net_conf_import(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
309 int argc
, const char **argv
)
312 const char *filename
= NULL
;
313 const char *servicename
= NULL
;
314 char *conf_source
= NULL
;
316 struct smbconf_ctx
*txt_ctx
;
319 if (c
->display_usage
)
320 return net_conf_import_usage(c
, argc
, argv
);
322 mem_ctx
= talloc_stackframe();
327 net_conf_import_usage(c
, argc
, argv
);
330 servicename
= talloc_strdup(mem_ctx
, argv
[1]);
331 if (servicename
== NULL
) {
332 d_printf(_("error: out of memory!\n"));
340 DEBUG(3,("net_conf_import: reading configuration from file %s.\n",
343 conf_source
= talloc_asprintf(mem_ctx
, "file:%s", filename
);
344 if (conf_source
== NULL
) {
345 d_printf(_("error: out of memory!\n"));
349 werr
= smbconf_init(mem_ctx
, &txt_ctx
, conf_source
);
350 if (!W_ERROR_IS_OK(werr
)) {
351 d_printf(_("error loading file '%s': %s\n"), filename
,
356 if (c
->opt_testmode
) {
357 d_printf(_("\nTEST MODE - "
358 "would import the following configuration:\n\n"));
361 if (servicename
!= NULL
) {
362 struct smbconf_service
*service
= NULL
;
364 werr
= smbconf_get_share(txt_ctx
, mem_ctx
,
367 if (!W_ERROR_IS_OK(werr
)) {
371 werr
= smbconf_transaction_start(conf_ctx
);
372 if (!W_ERROR_IS_OK(werr
)) {
373 d_printf(_("error starting transaction: %s\n"),
378 werr
= import_process_service(c
, conf_ctx
, service
);
379 if (!W_ERROR_IS_OK(werr
)) {
383 struct smbconf_service
**services
= NULL
;
384 uint32_t num_shares
, sidx
;
386 werr
= smbconf_get_config(txt_ctx
, mem_ctx
,
389 if (!W_ERROR_IS_OK(werr
)) {
392 if (!c
->opt_testmode
) {
393 werr
= smbconf_drop(conf_ctx
);
394 if (!W_ERROR_IS_OK(werr
)) {
400 * Wrap the importing of shares into a transaction,
401 * but only 100 at a time, in order to serve memory.
402 * The allocated memory accumulates across the actions
403 * within the transaction, and for me, some 1500
404 * imported shares, the MAX_TALLOC_SIZE of 256 MB
407 werr
= smbconf_transaction_start(conf_ctx
);
408 if (!W_ERROR_IS_OK(werr
)) {
409 d_printf(_("error starting transaction: %s\n"),
414 for (sidx
= 0; sidx
< num_shares
; sidx
++) {
415 werr
= import_process_service(c
, conf_ctx
,
417 if (!W_ERROR_IS_OK(werr
)) {
425 werr
= smbconf_transaction_commit(conf_ctx
);
426 if (!W_ERROR_IS_OK(werr
)) {
427 d_printf(_("error committing transaction: "
432 werr
= smbconf_transaction_start(conf_ctx
);
433 if (!W_ERROR_IS_OK(werr
)) {
434 d_printf(_("error starting transaction: %s\n"),
441 werr
= smbconf_transaction_commit(conf_ctx
);
442 if (!W_ERROR_IS_OK(werr
)) {
443 d_printf(_("error committing transaction: %s\n"),
452 werr
= smbconf_transaction_cancel(conf_ctx
);
453 if (!W_ERROR_IS_OK(werr
)) {
454 d_printf(_("error cancelling transaction: %s\n"),
459 TALLOC_FREE(mem_ctx
);
463 static int net_conf_listshares(struct net_context
*c
,
464 struct smbconf_ctx
*conf_ctx
, int argc
,
467 WERROR werr
= WERR_OK
;
469 uint32_t count
, num_shares
= 0;
470 char **share_names
= NULL
;
473 mem_ctx
= talloc_stackframe();
475 if (argc
!= 0 || c
->display_usage
) {
476 net_conf_listshares_usage(c
, argc
, argv
);
480 werr
= smbconf_get_share_names(conf_ctx
, mem_ctx
, &num_shares
,
482 if (!W_ERROR_IS_OK(werr
)) {
486 for (count
= 0; count
< num_shares
; count
++)
488 d_printf("%s\n", share_names
[count
]);
494 TALLOC_FREE(mem_ctx
);
498 static int net_conf_drop(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
499 int argc
, const char **argv
)
504 if (argc
!= 0 || c
->display_usage
) {
505 net_conf_drop_usage(c
, argc
, argv
);
509 werr
= smbconf_drop(conf_ctx
);
510 if (!W_ERROR_IS_OK(werr
)) {
511 d_fprintf(stderr
, _("Error deleting configuration: %s\n"),
522 static int net_conf_showshare(struct net_context
*c
,
523 struct smbconf_ctx
*conf_ctx
, int argc
,
527 WERROR werr
= WERR_OK
;
528 const char *sharename
= NULL
;
531 struct smbconf_service
*service
= NULL
;
533 mem_ctx
= talloc_stackframe();
535 if (argc
!= 1 || c
->display_usage
) {
536 net_conf_showshare_usage(c
, argc
, argv
);
540 sharename
= talloc_strdup(mem_ctx
, argv
[0]);
541 if (sharename
== NULL
) {
542 d_printf("error: out of memory!\n");
546 werr
= smbconf_get_share(conf_ctx
, mem_ctx
, sharename
, &service
);
547 if (!W_ERROR_IS_OK(werr
)) {
548 d_printf(_("error getting share parameters: %s\n"),
553 d_printf("[%s]\n", service
->name
);
555 for (count
= 0; count
< service
->num_params
; count
++) {
556 d_printf("\t%s = %s\n", service
->param_names
[count
],
557 service
->param_values
[count
]);
563 TALLOC_FREE(mem_ctx
);
568 * Add a share, with a couple of standard parameters, partly optional.
570 * This is a high level utility function of the net conf utility,
571 * not a direct frontend to the smbconf API.
573 static int net_conf_addshare(struct net_context
*c
,
574 struct smbconf_ctx
*conf_ctx
, int argc
,
578 WERROR werr
= WERR_OK
;
579 char *sharename
= NULL
;
580 const char *path
= NULL
;
581 const char *comment
= NULL
;
582 const char *guest_ok
= "no";
583 const char *writeable
= "no";
584 SMB_STRUCT_STAT sbuf
;
585 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
587 if (c
->display_usage
) {
588 net_conf_addshare_usage(c
, argc
, argv
);
597 net_conf_addshare_usage(c
, argc
, argv
);
602 if (!strnequal(argv
[3], "guest_ok=", 9)) {
603 net_conf_addshare_usage(c
, argc
, argv
);
606 switch (argv
[3][9]) {
616 net_conf_addshare_usage(c
, argc
, argv
);
620 if (!strnequal(argv
[2], "writeable=", 10)) {
621 net_conf_addshare_usage(c
, argc
, argv
);
624 switch (argv
[2][10]) {
634 net_conf_addshare_usage(c
, argc
, argv
);
639 sharename
= talloc_strdup(mem_ctx
, argv
[0]);
640 if (sharename
== NULL
) {
641 d_printf(_("error: out of memory!\n"));
652 /* validate share name */
654 if (!validate_net_name(sharename
, INVALID_SHARENAME_CHARS
,
657 d_fprintf(stderr
, _("ERROR: share name %s contains "
658 "invalid characters (any of %s)\n"),
659 sharename
, INVALID_SHARENAME_CHARS
);
663 if (strequal(sharename
, GLOBAL_NAME
)) {
665 _("ERROR: 'global' is not a valid share name.\n"));
669 if (smbconf_share_exists(conf_ctx
, sharename
)) {
670 d_fprintf(stderr
, _("ERROR: share %s already exists.\n"),
677 if (path
[0] != '/') {
679 _("Error: path '%s' is not an absolute path.\n"),
684 if (sys_stat(path
, &sbuf
, false) != 0) {
686 _("ERROR: cannot stat path '%s' to ensure "
687 "this is a directory.\n"
688 "Error was '%s'.\n"),
689 path
, strerror(errno
));
693 if (!S_ISDIR(sbuf
.st_ex_mode
)) {
695 _("ERROR: path '%s' is not a directory.\n"),
701 * start a transaction
704 werr
= smbconf_transaction_start(conf_ctx
);
705 if (!W_ERROR_IS_OK(werr
)) {
706 d_printf("error starting transaction: %s\n",
715 werr
= smbconf_create_share(conf_ctx
, sharename
);
716 if (!W_ERROR_IS_OK(werr
)) {
717 d_fprintf(stderr
, _("Error creating share %s: %s\n"),
718 sharename
, win_errstr(werr
));
723 * fill the share with parameters
726 werr
= smbconf_set_parameter(conf_ctx
, sharename
, "path", path
);
727 if (!W_ERROR_IS_OK(werr
)) {
728 d_fprintf(stderr
, _("Error setting parameter %s: %s\n"),
729 "path", win_errstr(werr
));
733 if (comment
!= NULL
) {
734 werr
= smbconf_set_parameter(conf_ctx
, sharename
, "comment",
736 if (!W_ERROR_IS_OK(werr
)) {
737 d_fprintf(stderr
, _("Error setting parameter %s: %s\n"),
738 "comment", win_errstr(werr
));
743 werr
= smbconf_set_parameter(conf_ctx
, sharename
, "guest ok", guest_ok
);
744 if (!W_ERROR_IS_OK(werr
)) {
745 d_fprintf(stderr
, _("Error setting parameter %s: %s\n"),
746 "'guest ok'", win_errstr(werr
));
750 werr
= smbconf_set_parameter(conf_ctx
, sharename
, "writeable",
752 if (!W_ERROR_IS_OK(werr
)) {
753 d_fprintf(stderr
, _("Error setting parameter %s: %s\n"),
754 "writeable", win_errstr(werr
));
759 * commit the whole thing
762 werr
= smbconf_transaction_commit(conf_ctx
);
763 if (!W_ERROR_IS_OK(werr
)) {
764 d_printf("error committing transaction: %s\n",
773 werr
= smbconf_transaction_cancel(conf_ctx
);
774 if (!W_ERROR_IS_OK(werr
)) {
775 d_printf("error cancelling transaction: %s\n",
780 TALLOC_FREE(mem_ctx
);
784 static int net_conf_delshare(struct net_context
*c
,
785 struct smbconf_ctx
*conf_ctx
, int argc
,
789 const char *sharename
= NULL
;
790 WERROR werr
= WERR_OK
;
791 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
793 if (argc
!= 1 || c
->display_usage
) {
794 net_conf_delshare_usage(c
, argc
, argv
);
797 sharename
= talloc_strdup(mem_ctx
, argv
[0]);
798 if (sharename
== NULL
) {
799 d_printf(_("error: out of memory!\n"));
803 werr
= smbconf_delete_share(conf_ctx
, sharename
);
804 if (!W_ERROR_IS_OK(werr
)) {
805 d_fprintf(stderr
, _("Error deleting share %s: %s\n"),
806 sharename
, win_errstr(werr
));
812 TALLOC_FREE(mem_ctx
);
816 static int net_conf_setparm(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
817 int argc
, const char **argv
)
820 WERROR werr
= WERR_OK
;
821 char *service
= NULL
;
823 const char *value_str
= NULL
;
824 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
826 if (argc
!= 3 || c
->display_usage
) {
827 net_conf_setparm_usage(c
, argc
, argv
);
831 * NULL service name means "dangling parameters" to libsmbconf.
832 * We use the empty string from the command line for this purpose.
834 if (strlen(argv
[0]) != 0) {
835 service
= talloc_strdup(mem_ctx
, argv
[0]);
836 if (service
== NULL
) {
837 d_printf(_("error: out of memory!\n"));
841 param
= strlower_talloc(mem_ctx
, argv
[1]);
843 d_printf(_("error: out of memory!\n"));
848 werr
= smbconf_transaction_start(conf_ctx
);
849 if (!W_ERROR_IS_OK(werr
)) {
850 d_printf(_("error starting transaction: %s\n"),
855 if (!smbconf_share_exists(conf_ctx
, service
)) {
856 werr
= smbconf_create_share(conf_ctx
, service
);
857 if (!W_ERROR_IS_OK(werr
)) {
858 d_fprintf(stderr
, _("Error creating share '%s': %s\n"),
859 service
, win_errstr(werr
));
864 werr
= smbconf_set_parameter(conf_ctx
, service
, param
, value_str
);
866 if (!W_ERROR_IS_OK(werr
)) {
867 d_fprintf(stderr
, _("Error setting value '%s': %s\n"),
868 param
, win_errstr(werr
));
872 werr
= smbconf_transaction_commit(conf_ctx
);
873 if (!W_ERROR_IS_OK(werr
)) {
874 d_printf(_("error committing transaction: %s\n"),
883 werr
= smbconf_transaction_cancel(conf_ctx
);
884 if (!W_ERROR_IS_OK(werr
)) {
885 d_printf(_("error cancelling transaction: %s\n"),
890 TALLOC_FREE(mem_ctx
);
894 static int net_conf_getparm(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
895 int argc
, const char **argv
)
898 WERROR werr
= WERR_OK
;
899 char *service
= NULL
;
904 mem_ctx
= talloc_stackframe();
906 if (argc
!= 2 || c
->display_usage
) {
907 net_conf_getparm_usage(c
, argc
, argv
);
911 * NULL service name means "dangling parameters" to libsmbconf.
912 * We use the empty string from the command line for this purpose.
914 if (strlen(argv
[0]) != 0) {
915 service
= talloc_strdup(mem_ctx
, argv
[0]);
916 if (service
== NULL
) {
917 d_printf(_("error: out of memory!\n"));
921 param
= strlower_talloc(mem_ctx
, argv
[1]);
923 d_printf(_("error: out of memory!\n"));
927 werr
= smbconf_get_parameter(conf_ctx
, mem_ctx
, service
, param
, &valstr
);
929 if (W_ERROR_EQUAL(werr
, WERR_NO_SUCH_SERVICE
)) {
931 _("Error: given service '%s' does not exist.\n"),
934 } else if (W_ERROR_EQUAL(werr
, WERR_INVALID_PARAM
)) {
936 _("Error: given parameter '%s' is not set.\n"),
939 } else if (!W_ERROR_IS_OK(werr
)) {
940 d_fprintf(stderr
, _("Error getting value '%s': %s.\n"),
941 param
, win_errstr(werr
));
945 d_printf("%s\n", valstr
);
949 TALLOC_FREE(mem_ctx
);
953 static int net_conf_delparm(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
954 int argc
, const char **argv
)
957 WERROR werr
= WERR_OK
;
958 char *service
= NULL
;
960 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
962 if (argc
!= 2 || c
->display_usage
) {
963 net_conf_delparm_usage(c
, argc
, argv
);
967 * NULL service name means "dangling parameters" to libsmbconf.
968 * We use the empty string from the command line for this purpose.
970 if (strlen(argv
[0]) != 0) {
971 service
= talloc_strdup(mem_ctx
, argv
[0]);
972 if (service
== NULL
) {
973 d_printf(_("error: out of memory!\n"));
977 param
= strlower_talloc(mem_ctx
, argv
[1]);
979 d_printf("error: out of memory!\n");
983 werr
= smbconf_delete_parameter(conf_ctx
, service
, param
);
985 if (W_ERROR_EQUAL(werr
, WERR_NO_SUCH_SERVICE
)) {
987 _("Error: given service '%s' does not exist.\n"),
990 } else if (W_ERROR_EQUAL(werr
, WERR_INVALID_PARAM
)) {
992 _("Error: given parameter '%s' is not set.\n"),
995 } else if (!W_ERROR_IS_OK(werr
)) {
996 d_fprintf(stderr
, _("Error deleting value '%s': %s.\n"),
997 param
, win_errstr(werr
));
1004 TALLOC_FREE(mem_ctx
);
1008 static int net_conf_getincludes(struct net_context
*c
,
1009 struct smbconf_ctx
*conf_ctx
,
1010 int argc
, const char **argv
)
1013 uint32_t num_includes
;
1016 char **includes
= NULL
;
1018 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
1020 if (argc
!= 1 || c
->display_usage
) {
1021 net_conf_getincludes_usage(c
, argc
, argv
);
1025 service
= talloc_strdup(mem_ctx
, argv
[0]);
1026 if (service
== NULL
) {
1027 d_printf(_("error: out of memory!\n"));
1031 werr
= smbconf_get_includes(conf_ctx
, mem_ctx
, service
,
1032 &num_includes
, &includes
);
1033 if (!W_ERROR_IS_OK(werr
)) {
1034 d_printf(_("error getting includes: %s\n"), win_errstr(werr
));
1038 for (count
= 0; count
< num_includes
; count
++) {
1039 d_printf("include = %s\n", includes
[count
]);
1045 TALLOC_FREE(mem_ctx
);
1049 static int net_conf_setincludes(struct net_context
*c
,
1050 struct smbconf_ctx
*conf_ctx
,
1051 int argc
, const char **argv
)
1055 uint32_t num_includes
;
1056 const char **includes
;
1058 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
1060 if (argc
< 1 || c
->display_usage
) {
1061 net_conf_setincludes_usage(c
, argc
, argv
);
1065 service
= talloc_strdup(mem_ctx
, argv
[0]);
1066 if (service
== NULL
) {
1067 d_printf(_("error: out of memory!\n"));
1071 num_includes
= argc
- 1;
1072 if (num_includes
== 0) {
1075 includes
= argv
+ 1;
1078 werr
= smbconf_set_includes(conf_ctx
, service
, num_includes
, includes
);
1079 if (!W_ERROR_IS_OK(werr
)) {
1080 d_printf(_("error setting includes: %s\n"), win_errstr(werr
));
1087 TALLOC_FREE(mem_ctx
);
1091 static int net_conf_delincludes(struct net_context
*c
,
1092 struct smbconf_ctx
*conf_ctx
,
1093 int argc
, const char **argv
)
1098 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
1100 if (argc
!= 1 || c
->display_usage
) {
1101 net_conf_delincludes_usage(c
, argc
, argv
);
1105 service
= talloc_strdup(mem_ctx
, argv
[0]);
1106 if (service
== NULL
) {
1107 d_printf(_("error: out of memory!\n"));
1111 werr
= smbconf_delete_includes(conf_ctx
, service
);
1112 if (!W_ERROR_IS_OK(werr
)) {
1113 d_printf(_("error deleting includes: %s\n"), win_errstr(werr
));
1120 TALLOC_FREE(mem_ctx
);
1125 /**********************************************************************
1127 * Wrapper and net_conf_run_function mechanism.
1129 **********************************************************************/
1132 * Wrapper function to call the main conf functions.
1133 * The wrapper calls handles opening and closing of the
1136 static int net_conf_wrap_function(struct net_context
*c
,
1137 int (*fn
)(struct net_context
*,
1138 struct smbconf_ctx
*,
1139 int, const char **),
1140 int argc
, const char **argv
)
1143 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
1144 struct smbconf_ctx
*conf_ctx
;
1147 werr
= smbconf_init(mem_ctx
, &conf_ctx
, "registry:");
1149 if (!W_ERROR_IS_OK(werr
)) {
1153 ret
= fn(c
, conf_ctx
, argc
, argv
);
1155 smbconf_shutdown(conf_ctx
);
1161 * We need a functable struct of our own, because the
1162 * functions are called through a wrapper that handles
1163 * the opening and closing of the configuration, and so on.
1165 struct conf_functable
{
1166 const char *funcname
;
1167 int (*fn
)(struct net_context
*c
, struct smbconf_ctx
*ctx
, int argc
,
1169 int valid_transports
;
1170 const char *description
;
1175 * This imitates net_run_function but calls the main functions
1176 * through the wrapper net_conf_wrap_function().
1178 static int net_conf_run_function(struct net_context
*c
, int argc
,
1179 const char **argv
, const char *whoami
,
1180 struct conf_functable
*table
)
1185 for (i
=0; table
[i
].funcname
; i
++) {
1186 if (StrCaseCmp(argv
[0], table
[i
].funcname
) == 0)
1187 return net_conf_wrap_function(c
, table
[i
].fn
,
1193 d_printf(_("Usage:\n"));
1194 for (i
=0; table
[i
].funcname
; i
++) {
1195 if (c
->display_usage
== false)
1196 d_printf("%s %-15s %s\n", whoami
, table
[i
].funcname
,
1197 table
[i
].description
);
1199 d_printf("%s\n", table
[i
].usage
);
1202 return c
->display_usage
?0:-1;
1206 * Entry-point for all the CONF functions.
1209 int net_conf(struct net_context
*c
, int argc
, const char **argv
)
1212 struct conf_functable func_table
[] = {
1216 NET_TRANSPORT_LOCAL
,
1217 N_("Dump the complete configuration in smb.conf like "
1219 N_("net conf list\n"
1220 " Dump the complete configuration in smb.conf "
1227 NET_TRANSPORT_LOCAL
,
1228 N_("Import configuration from file in smb.conf "
1230 N_("net conf import\n"
1231 " Import configuration from file in smb.conf "
1236 net_conf_listshares
,
1237 NET_TRANSPORT_LOCAL
,
1238 N_("List the share names."),
1239 N_("net conf listshares\n"
1240 " List the share names.")
1245 NET_TRANSPORT_LOCAL
,
1246 N_("Delete the complete configuration."),
1247 N_("net conf drop\n"
1248 " Delete the complete configuration.")
1253 NET_TRANSPORT_LOCAL
,
1254 N_("Show the definition of a share."),
1255 N_("net conf showshare\n"
1256 " Show the definition of a share.")
1261 NET_TRANSPORT_LOCAL
,
1262 N_("Create a new share."),
1263 N_("net conf addshare\n"
1264 " Create a new share.")
1269 NET_TRANSPORT_LOCAL
,
1270 N_("Delete a share."),
1271 N_("net conf delshare\n"
1277 NET_TRANSPORT_LOCAL
,
1278 N_("Store a parameter."),
1279 N_("net conf setparm\n"
1280 " Store a parameter.")
1285 NET_TRANSPORT_LOCAL
,
1286 N_("Retrieve the value of a parameter."),
1287 N_("net conf getparm\n"
1288 " Retrieve the value of a parameter.")
1293 NET_TRANSPORT_LOCAL
,
1294 N_("Delete a parameter."),
1295 N_("net conf delparm\n"
1296 " Delete a parameter.")
1300 net_conf_getincludes
,
1301 NET_TRANSPORT_LOCAL
,
1302 N_("Show the includes of a share definition."),
1303 N_("net conf getincludes\n"
1304 " Show the includes of a share definition.")
1308 net_conf_setincludes
,
1309 NET_TRANSPORT_LOCAL
,
1310 N_("Set includes for a share."),
1311 N_("net conf setincludes\n"
1312 " Set includes for a share.")
1316 net_conf_delincludes
,
1317 NET_TRANSPORT_LOCAL
,
1318 N_("Delete includes from a share definition."),
1319 N_("net conf setincludes\n"
1320 " Delete includes from a share definition.")
1322 {NULL
, NULL
, 0, NULL
, NULL
}
1325 ret
= net_conf_run_function(c
, argc
, argv
, "net conf", func_table
);