2 * Samba Unix/Linux SMB client library
3 * Distributed SMB/CIFS Server Management Utility
4 * Local configuration interface
5 * Copyright (C) Michael Adam 2007-2008
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, see <http://www.gnu.org/licenses/>.
22 * This is an interface to Samba's configuration as made available
23 * by the libsmbconf interface (source/lib/smbconf/smbconf.c).
25 * This currently supports local interaction with the configuration
26 * stored in the registry. But other backends and remote access via
27 * rpc might get implemented in the future.
31 #include "system/filesys.h"
32 #include "utils/net.h"
33 #include "lib/smbconf/smbconf.h"
34 #include "lib/smbconf/smbconf_init.h"
35 #include "lib/smbconf/smbconf_reg.h"
37 /**********************************************************************
41 **********************************************************************/
43 static int net_conf_list_usage(struct net_context
*c
, int argc
,
46 d_printf("%s net conf list\n", _("Usage:"));
50 static int net_conf_import_usage(struct net_context
*c
, int argc
,
55 _(" net conf import [--test|-T] <filename> "
57 "\t[--test|-T] testmode - do not act, just print "
58 "what would be done\n"
59 "\t<servicename> only import service <servicename>, "
60 "ignore the rest\n"));
64 static int net_conf_listshares_usage(struct net_context
*c
, int argc
,
67 d_printf("%s\nnet conf listshares\n", _("Usage:"));
71 static int net_conf_drop_usage(struct net_context
*c
, int argc
,
74 d_printf("%s\nnet conf drop\n", _("Usage:"));
78 static int net_conf_showshare_usage(struct net_context
*c
, int argc
,
83 _("net conf showshare <sharename>\n"));
87 static int net_conf_addshare_usage(struct net_context
*c
, int argc
,
92 _(" net conf addshare <sharename> <path> "
93 "[writeable={y|N} [guest_ok={y|N} [<comment>]]\n"
94 "\t<sharename> the new share name.\n"
95 "\t<path> the path on the filesystem to export.\n"
96 "\twriteable={y|N} set \"writeable to \"yes\" or "
97 "\"no\" (default) on this share.\n"
98 "\tguest_ok={y|N} set \"guest ok\" to \"yes\" or "
99 "\"no\" (default) on this share.\n"
100 "\t<comment> optional comment for the new share.\n"));
104 static int net_conf_delshare_usage(struct net_context
*c
, int argc
,
109 _("net conf delshare <sharename>\n"));
113 static int net_conf_setparm_usage(struct net_context
*c
, int argc
,
118 _(" net conf setparm <section> <param> <value>\n"));
122 static int net_conf_getparm_usage(struct net_context
*c
, int argc
,
127 _(" net conf getparm <section> <param>\n"));
131 static int net_conf_delparm_usage(struct net_context
*c
, int argc
,
136 _(" net conf delparm <section> <param>\n"));
140 static int net_conf_getincludes_usage(struct net_context
*c
, int argc
,
145 _(" net conf getincludes <section>\n"));
149 static int net_conf_setincludes_usage(struct net_context
*c
, int argc
,
154 _(" net conf setincludes <section> [<filename>]*\n"));
158 static int net_conf_delincludes_usage(struct net_context
*c
, int argc
,
163 _(" net conf delincludes <section>\n"));
168 /**********************************************************************
172 **********************************************************************/
175 * This functions process a service previously loaded with libsmbconf.
177 static WERROR
import_process_service(struct net_context
*c
,
178 struct smbconf_ctx
*conf_ctx
,
179 struct smbconf_service
*service
)
182 WERROR werr
= WERR_OK
;
184 uint32_t num_includes
= 0;
185 char **includes
= NULL
;
186 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
188 if (c
->opt_testmode
) {
189 const char *indent
= "";
190 if (service
->name
!= NULL
) {
191 d_printf("[%s]\n", service
->name
);
194 for (idx
= 0; idx
< service
->num_params
; idx
++) {
195 d_printf("%s%s = %s\n", indent
,
196 service
->param_names
[idx
],
197 service
->param_values
[idx
]);
203 if (smbconf_share_exists(conf_ctx
, service
->name
)) {
204 werr
= smbconf_delete_share(conf_ctx
, service
->name
);
205 if (!W_ERROR_IS_OK(werr
)) {
209 err
= smbconf_create_share(conf_ctx
, service
->name
);
210 if (!SBC_ERROR_IS_OK(err
)) {
211 werr
= WERR_GENERAL_FAILURE
;
215 for (idx
= 0; idx
< service
->num_params
; idx
++) {
216 if (strequal(service
->param_names
[idx
], "include")) {
217 includes
= TALLOC_REALLOC_ARRAY(mem_ctx
,
221 if (includes
== NULL
) {
225 includes
[num_includes
] = talloc_strdup(includes
,
226 service
->param_values
[idx
]);
227 if (includes
[num_includes
] == NULL
) {
233 werr
= smbconf_set_parameter(conf_ctx
,
235 service
->param_names
[idx
],
236 service
->param_values
[idx
]);
237 if (!W_ERROR_IS_OK(werr
)) {
239 _("Error in section [%s], parameter \"%s\": %s\n"),
240 service
->name
, service
->param_names
[idx
],
247 werr
= smbconf_set_includes(conf_ctx
, service
->name
, num_includes
,
248 (const char **)includes
);
251 TALLOC_FREE(mem_ctx
);
256 /**********************************************************************
258 * the main conf functions
260 **********************************************************************/
262 static int net_conf_list(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
263 int argc
, const char **argv
)
265 WERROR werr
= WERR_OK
;
269 uint32_t share_count
, param_count
;
270 struct smbconf_service
**shares
= NULL
;
272 mem_ctx
= talloc_stackframe();
274 if (argc
!= 0 || c
->display_usage
) {
275 net_conf_list_usage(c
, argc
, argv
);
279 werr
= smbconf_get_config(conf_ctx
, mem_ctx
, &num_shares
, &shares
);
280 if (!W_ERROR_IS_OK(werr
)) {
281 d_fprintf(stderr
, _("Error getting config: %s\n"),
286 for (share_count
= 0; share_count
< num_shares
; share_count
++) {
287 const char *indent
= "";
288 if (shares
[share_count
]->name
!= NULL
) {
289 d_printf("[%s]\n", shares
[share_count
]->name
);
292 for (param_count
= 0;
293 param_count
< shares
[share_count
]->num_params
;
296 d_printf("%s%s = %s\n",
298 shares
[share_count
]->param_names
[param_count
],
299 shares
[share_count
]->param_values
[param_count
]);
307 TALLOC_FREE(mem_ctx
);
311 static int net_conf_import(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
312 int argc
, const char **argv
)
315 const char *filename
= NULL
;
316 const char *servicename
= NULL
;
317 char *conf_source
= NULL
;
319 struct smbconf_ctx
*txt_ctx
;
323 if (c
->display_usage
)
324 return net_conf_import_usage(c
, argc
, argv
);
326 mem_ctx
= talloc_stackframe();
331 net_conf_import_usage(c
, argc
, argv
);
334 servicename
= talloc_strdup(mem_ctx
, argv
[1]);
335 if (servicename
== NULL
) {
336 d_printf(_("error: out of memory!\n"));
344 DEBUG(3,("net_conf_import: reading configuration from file %s.\n",
347 conf_source
= talloc_asprintf(mem_ctx
, "file:%s", filename
);
348 if (conf_source
== NULL
) {
349 d_printf(_("error: out of memory!\n"));
353 err
= smbconf_init(mem_ctx
, &txt_ctx
, conf_source
);
354 if (!SBC_ERROR_IS_OK(err
)) {
355 d_printf(_("error loading file '%s': %s\n"), filename
,
356 sbcErrorString(err
));
357 werr
= WERR_NO_SUCH_SERVICE
;
361 if (c
->opt_testmode
) {
362 d_printf(_("\nTEST MODE - "
363 "would import the following configuration:\n\n"));
366 if (servicename
!= NULL
) {
367 struct smbconf_service
*service
= NULL
;
369 werr
= smbconf_get_share(txt_ctx
, mem_ctx
,
372 if (!W_ERROR_IS_OK(werr
)) {
376 werr
= smbconf_transaction_start(conf_ctx
);
377 if (!W_ERROR_IS_OK(werr
)) {
378 d_printf(_("error starting transaction: %s\n"),
383 werr
= import_process_service(c
, conf_ctx
, service
);
384 if (!W_ERROR_IS_OK(werr
)) {
388 struct smbconf_service
**services
= NULL
;
389 uint32_t num_shares
, sidx
;
391 werr
= smbconf_get_config(txt_ctx
, mem_ctx
,
394 if (!W_ERROR_IS_OK(werr
)) {
397 if (!c
->opt_testmode
) {
398 if (!SBC_ERROR_IS_OK(smbconf_drop(conf_ctx
))) {
404 * Wrap the importing of shares into a transaction,
405 * but only 100 at a time, in order to save memory.
406 * The allocated memory accumulates across the actions
407 * within the transaction, and for me, some 1500
408 * imported shares, the MAX_TALLOC_SIZE of 256 MB
411 werr
= smbconf_transaction_start(conf_ctx
);
412 if (!W_ERROR_IS_OK(werr
)) {
413 d_printf(_("error starting transaction: %s\n"),
418 for (sidx
= 0; sidx
< num_shares
; sidx
++) {
419 werr
= import_process_service(c
, conf_ctx
,
421 if (!W_ERROR_IS_OK(werr
)) {
429 werr
= smbconf_transaction_commit(conf_ctx
);
430 if (!W_ERROR_IS_OK(werr
)) {
431 d_printf(_("error committing transaction: "
436 werr
= smbconf_transaction_start(conf_ctx
);
437 if (!W_ERROR_IS_OK(werr
)) {
438 d_printf(_("error starting transaction: %s\n"),
445 werr
= smbconf_transaction_commit(conf_ctx
);
446 if (!W_ERROR_IS_OK(werr
)) {
447 d_printf(_("error committing transaction: %s\n"),
456 werr
= smbconf_transaction_cancel(conf_ctx
);
457 if (!W_ERROR_IS_OK(werr
)) {
458 d_printf(_("error cancelling transaction: %s\n"),
463 TALLOC_FREE(mem_ctx
);
467 static int net_conf_listshares(struct net_context
*c
,
468 struct smbconf_ctx
*conf_ctx
, int argc
,
473 uint32_t count
, num_shares
= 0;
474 char **share_names
= NULL
;
477 mem_ctx
= talloc_stackframe();
479 if (argc
!= 0 || c
->display_usage
) {
480 net_conf_listshares_usage(c
, argc
, argv
);
484 err
= smbconf_get_share_names(conf_ctx
, mem_ctx
, &num_shares
,
486 if (!SBC_ERROR_IS_OK(err
)) {
490 for (count
= 0; count
< num_shares
; count
++)
492 d_printf("%s\n", share_names
[count
]);
498 TALLOC_FREE(mem_ctx
);
502 static int net_conf_drop(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
503 int argc
, const char **argv
)
508 if (argc
!= 0 || c
->display_usage
) {
509 net_conf_drop_usage(c
, argc
, argv
);
513 err
= smbconf_drop(conf_ctx
);
514 if (!SBC_ERROR_IS_OK(err
)) {
515 d_fprintf(stderr
, _("Error deleting configuration: %s\n"),
516 sbcErrorString(err
));
526 static int net_conf_showshare(struct net_context
*c
,
527 struct smbconf_ctx
*conf_ctx
, int argc
,
531 WERROR werr
= WERR_OK
;
532 const char *sharename
= NULL
;
535 struct smbconf_service
*service
= NULL
;
537 mem_ctx
= talloc_stackframe();
539 if (argc
!= 1 || c
->display_usage
) {
540 net_conf_showshare_usage(c
, argc
, argv
);
544 sharename
= talloc_strdup(mem_ctx
, argv
[0]);
545 if (sharename
== NULL
) {
546 d_printf("error: out of memory!\n");
550 werr
= smbconf_get_share(conf_ctx
, mem_ctx
, sharename
, &service
);
551 if (!W_ERROR_IS_OK(werr
)) {
552 d_printf(_("error getting share parameters: %s\n"),
557 d_printf("[%s]\n", service
->name
);
559 for (count
= 0; count
< service
->num_params
; count
++) {
560 d_printf("\t%s = %s\n", service
->param_names
[count
],
561 service
->param_values
[count
]);
567 TALLOC_FREE(mem_ctx
);
572 * Add a share, with a couple of standard parameters, partly optional.
574 * This is a high level utility function of the net conf utility,
575 * not a direct frontend to the smbconf API.
577 static int net_conf_addshare(struct net_context
*c
,
578 struct smbconf_ctx
*conf_ctx
, int argc
,
582 WERROR werr
= WERR_OK
;
584 char *sharename
= NULL
;
585 const char *path
= NULL
;
586 const char *comment
= NULL
;
587 const char *guest_ok
= "no";
588 const char *writeable
= "no";
589 SMB_STRUCT_STAT sbuf
;
590 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
592 if (c
->display_usage
) {
593 net_conf_addshare_usage(c
, argc
, argv
);
602 net_conf_addshare_usage(c
, argc
, argv
);
607 if (!strnequal(argv
[3], "guest_ok=", 9)) {
608 net_conf_addshare_usage(c
, argc
, argv
);
611 switch (argv
[3][9]) {
621 net_conf_addshare_usage(c
, argc
, argv
);
625 if (!strnequal(argv
[2], "writeable=", 10)) {
626 net_conf_addshare_usage(c
, argc
, argv
);
629 switch (argv
[2][10]) {
639 net_conf_addshare_usage(c
, argc
, argv
);
644 sharename
= talloc_strdup(mem_ctx
, argv
[0]);
645 if (sharename
== NULL
) {
646 d_printf(_("error: out of memory!\n"));
657 /* validate share name */
659 if (!validate_net_name(sharename
, INVALID_SHARENAME_CHARS
,
662 d_fprintf(stderr
, _("ERROR: share name %s contains "
663 "invalid characters (any of %s)\n"),
664 sharename
, INVALID_SHARENAME_CHARS
);
668 if (strequal(sharename
, GLOBAL_NAME
)) {
670 _("ERROR: 'global' is not a valid share name.\n"));
674 if (smbconf_share_exists(conf_ctx
, sharename
)) {
675 d_fprintf(stderr
, _("ERROR: share %s already exists.\n"),
682 if (path
[0] != '/') {
684 _("Error: path '%s' is not an absolute path.\n"),
689 if (sys_stat(path
, &sbuf
, false) != 0) {
691 _("ERROR: cannot stat path '%s' to ensure "
692 "this is a directory.\n"
693 "Error was '%s'.\n"),
694 path
, strerror(errno
));
698 if (!S_ISDIR(sbuf
.st_ex_mode
)) {
700 _("ERROR: path '%s' is not a directory.\n"),
706 * start a transaction
709 werr
= smbconf_transaction_start(conf_ctx
);
710 if (!W_ERROR_IS_OK(werr
)) {
711 d_printf("error starting transaction: %s\n",
720 err
= smbconf_create_share(conf_ctx
, sharename
);
721 if (!SBC_ERROR_IS_OK(err
)) {
722 d_fprintf(stderr
, _("Error creating share %s: %s\n"),
723 sharename
, sbcErrorString(err
));
728 * fill the share with parameters
731 werr
= smbconf_set_parameter(conf_ctx
, sharename
, "path", path
);
732 if (!W_ERROR_IS_OK(werr
)) {
733 d_fprintf(stderr
, _("Error setting parameter %s: %s\n"),
734 "path", win_errstr(werr
));
738 if (comment
!= NULL
) {
739 werr
= smbconf_set_parameter(conf_ctx
, sharename
, "comment",
741 if (!W_ERROR_IS_OK(werr
)) {
742 d_fprintf(stderr
, _("Error setting parameter %s: %s\n"),
743 "comment", win_errstr(werr
));
748 werr
= smbconf_set_parameter(conf_ctx
, sharename
, "guest ok", guest_ok
);
749 if (!W_ERROR_IS_OK(werr
)) {
750 d_fprintf(stderr
, _("Error setting parameter %s: %s\n"),
751 "'guest ok'", win_errstr(werr
));
755 werr
= smbconf_set_parameter(conf_ctx
, sharename
, "writeable",
757 if (!W_ERROR_IS_OK(werr
)) {
758 d_fprintf(stderr
, _("Error setting parameter %s: %s\n"),
759 "writeable", win_errstr(werr
));
764 * commit the whole thing
767 werr
= smbconf_transaction_commit(conf_ctx
);
768 if (!W_ERROR_IS_OK(werr
)) {
769 d_printf("error committing transaction: %s\n",
778 werr
= smbconf_transaction_cancel(conf_ctx
);
779 if (!W_ERROR_IS_OK(werr
)) {
780 d_printf("error cancelling transaction: %s\n",
785 TALLOC_FREE(mem_ctx
);
789 static int net_conf_delshare(struct net_context
*c
,
790 struct smbconf_ctx
*conf_ctx
, int argc
,
794 const char *sharename
= NULL
;
795 WERROR werr
= WERR_OK
;
796 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
798 if (argc
!= 1 || c
->display_usage
) {
799 net_conf_delshare_usage(c
, argc
, argv
);
802 sharename
= talloc_strdup(mem_ctx
, argv
[0]);
803 if (sharename
== NULL
) {
804 d_printf(_("error: out of memory!\n"));
808 werr
= smbconf_delete_share(conf_ctx
, sharename
);
809 if (!W_ERROR_IS_OK(werr
)) {
810 d_fprintf(stderr
, _("Error deleting share %s: %s\n"),
811 sharename
, win_errstr(werr
));
817 TALLOC_FREE(mem_ctx
);
821 static int net_conf_setparm(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
822 int argc
, const char **argv
)
825 WERROR werr
= WERR_OK
;
827 char *service
= NULL
;
829 const char *value_str
= NULL
;
830 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
832 if (argc
!= 3 || c
->display_usage
) {
833 net_conf_setparm_usage(c
, argc
, argv
);
837 * NULL service name means "dangling parameters" to libsmbconf.
838 * We use the empty string from the command line for this purpose.
840 if (strlen(argv
[0]) != 0) {
841 service
= talloc_strdup(mem_ctx
, argv
[0]);
842 if (service
== NULL
) {
843 d_printf(_("error: out of memory!\n"));
847 param
= strlower_talloc(mem_ctx
, argv
[1]);
849 d_printf(_("error: out of memory!\n"));
854 werr
= smbconf_transaction_start(conf_ctx
);
855 if (!W_ERROR_IS_OK(werr
)) {
856 d_printf(_("error starting transaction: %s\n"),
861 if (!smbconf_share_exists(conf_ctx
, service
)) {
862 err
= smbconf_create_share(conf_ctx
, service
);
863 if (!SBC_ERROR_IS_OK(err
)) {
864 d_fprintf(stderr
, _("Error creating share '%s': %s\n"),
865 service
, sbcErrorString(err
));
870 werr
= smbconf_set_parameter(conf_ctx
, service
, param
, value_str
);
872 if (!W_ERROR_IS_OK(werr
)) {
873 d_fprintf(stderr
, _("Error setting value '%s': %s\n"),
874 param
, win_errstr(werr
));
878 werr
= smbconf_transaction_commit(conf_ctx
);
879 if (!W_ERROR_IS_OK(werr
)) {
880 d_printf(_("error committing transaction: %s\n"),
889 werr
= smbconf_transaction_cancel(conf_ctx
);
890 if (!W_ERROR_IS_OK(werr
)) {
891 d_printf(_("error cancelling transaction: %s\n"),
896 TALLOC_FREE(mem_ctx
);
900 static int net_conf_getparm(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
901 int argc
, const char **argv
)
904 WERROR werr
= WERR_OK
;
905 char *service
= NULL
;
910 mem_ctx
= talloc_stackframe();
912 if (argc
!= 2 || c
->display_usage
) {
913 net_conf_getparm_usage(c
, argc
, argv
);
917 * NULL service name means "dangling parameters" to libsmbconf.
918 * We use the empty string from the command line for this purpose.
920 if (strlen(argv
[0]) != 0) {
921 service
= talloc_strdup(mem_ctx
, argv
[0]);
922 if (service
== NULL
) {
923 d_printf(_("error: out of memory!\n"));
927 param
= strlower_talloc(mem_ctx
, argv
[1]);
929 d_printf(_("error: out of memory!\n"));
933 werr
= smbconf_get_parameter(conf_ctx
, mem_ctx
, service
, param
, &valstr
);
935 if (W_ERROR_EQUAL(werr
, WERR_NO_SUCH_SERVICE
)) {
937 _("Error: given service '%s' does not exist.\n"),
940 } else if (W_ERROR_EQUAL(werr
, WERR_INVALID_PARAM
)) {
942 _("Error: given parameter '%s' is not set.\n"),
945 } else if (!W_ERROR_IS_OK(werr
)) {
946 d_fprintf(stderr
, _("Error getting value '%s': %s.\n"),
947 param
, win_errstr(werr
));
951 d_printf("%s\n", valstr
);
955 TALLOC_FREE(mem_ctx
);
959 static int net_conf_delparm(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
960 int argc
, const char **argv
)
963 WERROR werr
= WERR_OK
;
964 char *service
= NULL
;
966 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
968 if (argc
!= 2 || c
->display_usage
) {
969 net_conf_delparm_usage(c
, argc
, argv
);
973 * NULL service name means "dangling parameters" to libsmbconf.
974 * We use the empty string from the command line for this purpose.
976 if (strlen(argv
[0]) != 0) {
977 service
= talloc_strdup(mem_ctx
, argv
[0]);
978 if (service
== NULL
) {
979 d_printf(_("error: out of memory!\n"));
983 param
= strlower_talloc(mem_ctx
, argv
[1]);
985 d_printf("error: out of memory!\n");
989 werr
= smbconf_delete_parameter(conf_ctx
, service
, param
);
991 if (W_ERROR_EQUAL(werr
, WERR_NO_SUCH_SERVICE
)) {
993 _("Error: given service '%s' does not exist.\n"),
996 } else if (W_ERROR_EQUAL(werr
, WERR_INVALID_PARAM
)) {
998 _("Error: given parameter '%s' is not set.\n"),
1001 } else if (!W_ERROR_IS_OK(werr
)) {
1002 d_fprintf(stderr
, _("Error deleting value '%s': %s.\n"),
1003 param
, win_errstr(werr
));
1010 TALLOC_FREE(mem_ctx
);
1014 static int net_conf_getincludes(struct net_context
*c
,
1015 struct smbconf_ctx
*conf_ctx
,
1016 int argc
, const char **argv
)
1019 uint32_t num_includes
;
1022 char **includes
= NULL
;
1024 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
1026 if (argc
!= 1 || c
->display_usage
) {
1027 net_conf_getincludes_usage(c
, argc
, argv
);
1031 service
= talloc_strdup(mem_ctx
, argv
[0]);
1032 if (service
== NULL
) {
1033 d_printf(_("error: out of memory!\n"));
1037 werr
= smbconf_get_includes(conf_ctx
, mem_ctx
, service
,
1038 &num_includes
, &includes
);
1039 if (!W_ERROR_IS_OK(werr
)) {
1040 d_printf(_("error getting includes: %s\n"), win_errstr(werr
));
1044 for (count
= 0; count
< num_includes
; count
++) {
1045 d_printf("include = %s\n", includes
[count
]);
1051 TALLOC_FREE(mem_ctx
);
1055 static int net_conf_setincludes(struct net_context
*c
,
1056 struct smbconf_ctx
*conf_ctx
,
1057 int argc
, const char **argv
)
1061 uint32_t num_includes
;
1062 const char **includes
;
1064 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
1066 if (argc
< 1 || c
->display_usage
) {
1067 net_conf_setincludes_usage(c
, argc
, argv
);
1071 service
= talloc_strdup(mem_ctx
, argv
[0]);
1072 if (service
== NULL
) {
1073 d_printf(_("error: out of memory!\n"));
1077 num_includes
= argc
- 1;
1078 if (num_includes
== 0) {
1081 includes
= argv
+ 1;
1084 werr
= smbconf_set_includes(conf_ctx
, service
, num_includes
, includes
);
1085 if (!W_ERROR_IS_OK(werr
)) {
1086 d_printf(_("error setting includes: %s\n"), win_errstr(werr
));
1093 TALLOC_FREE(mem_ctx
);
1097 static int net_conf_delincludes(struct net_context
*c
,
1098 struct smbconf_ctx
*conf_ctx
,
1099 int argc
, const char **argv
)
1104 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
1106 if (argc
!= 1 || c
->display_usage
) {
1107 net_conf_delincludes_usage(c
, argc
, argv
);
1111 service
= talloc_strdup(mem_ctx
, argv
[0]);
1112 if (service
== NULL
) {
1113 d_printf(_("error: out of memory!\n"));
1117 werr
= smbconf_delete_includes(conf_ctx
, service
);
1118 if (!W_ERROR_IS_OK(werr
)) {
1119 d_printf(_("error deleting includes: %s\n"), win_errstr(werr
));
1126 TALLOC_FREE(mem_ctx
);
1131 /**********************************************************************
1133 * Wrapper and net_conf_run_function mechanism.
1135 **********************************************************************/
1138 * Wrapper function to call the main conf functions.
1139 * The wrapper calls handles opening and closing of the
1142 static int net_conf_wrap_function(struct net_context
*c
,
1143 int (*fn
)(struct net_context
*,
1144 struct smbconf_ctx
*,
1145 int, const char **),
1146 int argc
, const char **argv
)
1149 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
1150 struct smbconf_ctx
*conf_ctx
;
1153 err
= smbconf_init(mem_ctx
, &conf_ctx
, "registry:");
1154 if (!SBC_ERROR_IS_OK(err
)) {
1158 ret
= fn(c
, conf_ctx
, argc
, argv
);
1160 smbconf_shutdown(conf_ctx
);
1166 * We need a functable struct of our own, because the
1167 * functions are called through a wrapper that handles
1168 * the opening and closing of the configuration, and so on.
1170 struct conf_functable
{
1171 const char *funcname
;
1172 int (*fn
)(struct net_context
*c
, struct smbconf_ctx
*ctx
, int argc
,
1174 int valid_transports
;
1175 const char *description
;
1180 * This imitates net_run_function but calls the main functions
1181 * through the wrapper net_conf_wrap_function().
1183 static int net_conf_run_function(struct net_context
*c
, int argc
,
1184 const char **argv
, const char *whoami
,
1185 struct conf_functable
*table
)
1190 for (i
=0; table
[i
].funcname
; i
++) {
1191 if (StrCaseCmp(argv
[0], table
[i
].funcname
) == 0)
1192 return net_conf_wrap_function(c
, table
[i
].fn
,
1198 d_printf(_("Usage:\n"));
1199 for (i
=0; table
[i
].funcname
; i
++) {
1200 if (c
->display_usage
== false)
1201 d_printf("%s %-15s %s\n", whoami
, table
[i
].funcname
,
1202 table
[i
].description
);
1204 d_printf("%s\n", table
[i
].usage
);
1207 return c
->display_usage
?0:-1;
1211 * Entry-point for all the CONF functions.
1214 int net_conf(struct net_context
*c
, int argc
, const char **argv
)
1217 struct conf_functable func_table
[] = {
1221 NET_TRANSPORT_LOCAL
,
1222 N_("Dump the complete configuration in smb.conf like "
1224 N_("net conf list\n"
1225 " Dump the complete configuration in smb.conf "
1232 NET_TRANSPORT_LOCAL
,
1233 N_("Import configuration from file in smb.conf "
1235 N_("net conf import\n"
1236 " Import configuration from file in smb.conf "
1241 net_conf_listshares
,
1242 NET_TRANSPORT_LOCAL
,
1243 N_("List the share names."),
1244 N_("net conf listshares\n"
1245 " List the share names.")
1250 NET_TRANSPORT_LOCAL
,
1251 N_("Delete the complete configuration."),
1252 N_("net conf drop\n"
1253 " Delete the complete configuration.")
1258 NET_TRANSPORT_LOCAL
,
1259 N_("Show the definition of a share."),
1260 N_("net conf showshare\n"
1261 " Show the definition of a share.")
1266 NET_TRANSPORT_LOCAL
,
1267 N_("Create a new share."),
1268 N_("net conf addshare\n"
1269 " Create a new share.")
1274 NET_TRANSPORT_LOCAL
,
1275 N_("Delete a share."),
1276 N_("net conf delshare\n"
1282 NET_TRANSPORT_LOCAL
,
1283 N_("Store a parameter."),
1284 N_("net conf setparm\n"
1285 " Store a parameter.")
1290 NET_TRANSPORT_LOCAL
,
1291 N_("Retrieve the value of a parameter."),
1292 N_("net conf getparm\n"
1293 " Retrieve the value of a parameter.")
1298 NET_TRANSPORT_LOCAL
,
1299 N_("Delete a parameter."),
1300 N_("net conf delparm\n"
1301 " Delete a parameter.")
1305 net_conf_getincludes
,
1306 NET_TRANSPORT_LOCAL
,
1307 N_("Show the includes of a share definition."),
1308 N_("net conf getincludes\n"
1309 " Show the includes of a share definition.")
1313 net_conf_setincludes
,
1314 NET_TRANSPORT_LOCAL
,
1315 N_("Set includes for a share."),
1316 N_("net conf setincludes\n"
1317 " Set includes for a share.")
1321 net_conf_delincludes
,
1322 NET_TRANSPORT_LOCAL
,
1323 N_("Delete includes from a share definition."),
1324 N_("net conf setincludes\n"
1325 " Delete includes from a share definition.")
1327 {NULL
, NULL
, 0, NULL
, NULL
}
1330 ret
= net_conf_run_function(c
, argc
, argv
, "net conf", func_table
);