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 "utils/net_conf_util.h"
34 #include "lib/smbconf/smbconf.h"
35 #include "lib/smbconf/smbconf_init.h"
36 #include "lib/smbconf/smbconf_reg.h"
37 #include "lib/param/loadparm.h"
39 /**********************************************************************
43 **********************************************************************/
45 static int net_conf_list_usage(struct net_context
*c
, int argc
,
48 d_printf("%s net conf list\n", _("Usage:"));
52 static int net_conf_import_usage(struct net_context
*c
, int argc
,
57 _(" net conf import [--test|-T] <filename> "
59 "\t[--test|-T] testmode - do not act, just print "
60 "what would be done\n"
61 "\t<servicename> only import service <servicename>, "
62 "ignore the rest\n"));
66 static int net_conf_listshares_usage(struct net_context
*c
, int argc
,
69 d_printf("%s\nnet conf listshares\n", _("Usage:"));
73 static int net_conf_drop_usage(struct net_context
*c
, int argc
,
76 d_printf("%s\nnet conf drop\n", _("Usage:"));
80 static int net_conf_showshare_usage(struct net_context
*c
, int argc
,
85 _("net conf showshare <sharename>\n"));
89 static int net_conf_addshare_usage(struct net_context
*c
, int argc
,
94 _(" net conf addshare <sharename> <path> "
95 "[writeable={y|N} [guest_ok={y|N} [<comment>]]]\n"
96 "\t<sharename> the new share name.\n"
97 "\t<path> the path on the filesystem to export.\n"
98 "\twriteable={y|N} set \"writeable to \"yes\" or "
99 "\"no\" (default) on this share.\n"
100 "\tguest_ok={y|N} set \"guest ok\" to \"yes\" or "
101 "\"no\" (default) on this share.\n"
102 "\t<comment> optional comment for the new share.\n"));
106 static int net_conf_delshare_usage(struct net_context
*c
, int argc
,
111 _("net conf delshare <sharename>\n"));
115 static int net_conf_setparm_usage(struct net_context
*c
, int argc
,
120 _(" net conf setparm <section> <param> <value>\n"));
124 static int net_conf_getparm_usage(struct net_context
*c
, int argc
,
129 _(" net conf getparm <section> <param>\n"));
133 static int net_conf_delparm_usage(struct net_context
*c
, int argc
,
138 _(" net conf delparm <section> <param>\n"));
142 static int net_conf_getincludes_usage(struct net_context
*c
, int argc
,
147 _(" net conf getincludes <section>\n"));
151 static int net_conf_setincludes_usage(struct net_context
*c
, int argc
,
156 _(" net conf setincludes <section> [<filename>]*\n"));
160 static int net_conf_delincludes_usage(struct net_context
*c
, int argc
,
165 _(" net conf delincludes <section>\n"));
170 /**********************************************************************
174 **********************************************************************/
177 * This functions process a service previously loaded with libsmbconf.
179 static sbcErr
import_process_service(struct net_context
*c
,
180 struct smbconf_ctx
*conf_ctx
,
181 struct smbconf_service
*service
)
183 sbcErr err
= SBC_ERR_OK
;
185 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 err
= smbconf_delete_share(conf_ctx
, service
->name
);
203 if (!SBC_ERROR_IS_OK(err
)) {
208 err
= smbconf_create_set_share(conf_ctx
, service
);
215 /**********************************************************************
217 * the main conf functions
219 **********************************************************************/
221 static int net_conf_list(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
222 int argc
, const char **argv
)
228 uint32_t share_count
, param_count
;
229 struct smbconf_service
**shares
= NULL
;
231 mem_ctx
= talloc_stackframe();
233 if (argc
!= 0 || c
->display_usage
) {
234 net_conf_list_usage(c
, argc
, argv
);
238 err
= smbconf_get_config(conf_ctx
, mem_ctx
, &num_shares
, &shares
);
239 if (!SBC_ERROR_IS_OK(err
)) {
240 d_fprintf(stderr
, _("Error getting config: %s\n"),
241 sbcErrorString(err
));
245 for (share_count
= 0; share_count
< num_shares
; share_count
++) {
246 const char *indent
= "";
247 if (shares
[share_count
]->name
!= NULL
) {
248 d_printf("[%s]\n", shares
[share_count
]->name
);
251 for (param_count
= 0;
252 param_count
< shares
[share_count
]->num_params
;
255 d_printf("%s%s = %s\n",
257 shares
[share_count
]->param_names
[param_count
],
258 shares
[share_count
]->param_values
[param_count
]);
266 TALLOC_FREE(mem_ctx
);
270 static int net_conf_import(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
271 int argc
, const char **argv
)
274 const char *filename
= NULL
;
275 const char *servicename
= NULL
;
276 char *conf_source
= NULL
;
278 struct smbconf_ctx
*txt_ctx
;
281 if (c
->display_usage
)
282 return net_conf_import_usage(c
, argc
, argv
);
284 mem_ctx
= talloc_stackframe();
289 net_conf_import_usage(c
, argc
, argv
);
292 servicename
= talloc_strdup(mem_ctx
, argv
[1]);
293 if (servicename
== NULL
) {
294 d_printf(_("error: out of memory!\n"));
304 DEBUG(3,("net_conf_import: reading configuration from file %s.\n",
307 conf_source
= talloc_asprintf(mem_ctx
, "file:%s", filename
);
308 if (conf_source
== NULL
) {
309 d_printf(_("error: out of memory!\n"));
313 err
= smbconf_init(mem_ctx
, &txt_ctx
, conf_source
);
314 if (!SBC_ERROR_IS_OK(err
)) {
315 d_printf(_("error loading file '%s': %s\n"), filename
,
316 sbcErrorString(err
));
320 if (c
->opt_testmode
) {
321 d_printf(_("\nTEST MODE - "
322 "would import the following configuration:\n\n"));
325 if (servicename
!= NULL
) {
326 struct smbconf_service
*service
= NULL
;
328 err
= smbconf_get_share(txt_ctx
, mem_ctx
,
331 if (!SBC_ERROR_IS_OK(err
)) {
335 err
= smbconf_transaction_start(conf_ctx
);
336 if (!SBC_ERROR_IS_OK(err
)) {
337 d_printf(_("error starting transaction: %s\n"),
338 sbcErrorString(err
));
342 err
= import_process_service(c
, conf_ctx
, service
);
343 if (!SBC_ERROR_IS_OK(err
)) {
344 d_printf(_("error importing service %s: %s\n"),
345 servicename
, sbcErrorString(err
));
349 struct smbconf_service
**services
= NULL
;
350 uint32_t num_shares
, sidx
;
352 err
= smbconf_get_config(txt_ctx
, mem_ctx
,
355 if (!SBC_ERROR_IS_OK(err
)) {
358 if (!c
->opt_testmode
) {
359 if (!SBC_ERROR_IS_OK(smbconf_drop(conf_ctx
))) {
365 * Wrap the importing of shares into a transaction,
366 * but only 100 at a time, in order to save memory.
367 * The allocated memory accumulates across the actions
368 * within the transaction, and for me, some 1500
369 * imported shares, the MAX_TALLOC_SIZE of 256 MB
372 err
= smbconf_transaction_start(conf_ctx
);
373 if (!SBC_ERROR_IS_OK(err
)) {
374 d_printf(_("error starting transaction: %s\n"),
375 sbcErrorString(err
));
379 for (sidx
= 0; sidx
< num_shares
; sidx
++) {
380 err
= import_process_service(c
, conf_ctx
,
382 if (!SBC_ERROR_IS_OK(err
)) {
383 d_printf(_("error importing service %s: %s\n"),
384 services
[sidx
]->name
,
385 sbcErrorString(err
));
393 err
= smbconf_transaction_commit(conf_ctx
);
394 if (!SBC_ERROR_IS_OK(err
)) {
395 d_printf(_("error committing transaction: "
397 sbcErrorString(err
));
400 err
= smbconf_transaction_start(conf_ctx
);
401 if (!SBC_ERROR_IS_OK(err
)) {
402 d_printf(_("error starting transaction: %s\n"),
403 sbcErrorString(err
));
409 err
= smbconf_transaction_commit(conf_ctx
);
410 if (!SBC_ERROR_IS_OK(err
)) {
411 d_printf(_("error committing transaction: %s\n"),
412 sbcErrorString(err
));
420 err
= smbconf_transaction_cancel(conf_ctx
);
421 if (!SBC_ERROR_IS_OK(err
)) {
422 d_printf(_("error cancelling transaction: %s\n"),
423 sbcErrorString(err
));
427 TALLOC_FREE(mem_ctx
);
431 static int net_conf_listshares(struct net_context
*c
,
432 struct smbconf_ctx
*conf_ctx
, int argc
,
437 uint32_t count
, num_shares
= 0;
438 char **share_names
= NULL
;
441 mem_ctx
= talloc_stackframe();
443 if (argc
!= 0 || c
->display_usage
) {
444 net_conf_listshares_usage(c
, argc
, argv
);
448 err
= smbconf_get_share_names(conf_ctx
, mem_ctx
, &num_shares
,
450 if (!SBC_ERROR_IS_OK(err
)) {
454 for (count
= 0; count
< num_shares
; count
++)
456 d_printf("%s\n", share_names
[count
]);
462 TALLOC_FREE(mem_ctx
);
466 static int net_conf_drop(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
467 int argc
, const char **argv
)
472 if (argc
!= 0 || c
->display_usage
) {
473 net_conf_drop_usage(c
, argc
, argv
);
477 err
= smbconf_drop(conf_ctx
);
478 if (!SBC_ERROR_IS_OK(err
)) {
479 d_fprintf(stderr
, _("Error deleting configuration: %s\n"),
480 sbcErrorString(err
));
490 static int net_conf_showshare(struct net_context
*c
,
491 struct smbconf_ctx
*conf_ctx
, int argc
,
496 const char *sharename
= NULL
;
499 struct smbconf_service
*service
= NULL
;
501 mem_ctx
= talloc_stackframe();
503 if (argc
!= 1 || c
->display_usage
) {
504 net_conf_showshare_usage(c
, argc
, argv
);
508 sharename
= talloc_strdup(mem_ctx
, argv
[0]);
509 if (sharename
== NULL
) {
510 d_printf("error: out of memory!\n");
514 err
= smbconf_get_share(conf_ctx
, mem_ctx
, sharename
, &service
);
515 if (!SBC_ERROR_IS_OK(err
)) {
516 d_printf(_("error getting share parameters: %s\n"),
517 sbcErrorString(err
));
521 d_printf("[%s]\n", service
->name
);
523 for (count
= 0; count
< service
->num_params
; count
++) {
524 d_printf("\t%s = %s\n", service
->param_names
[count
],
525 service
->param_values
[count
]);
531 TALLOC_FREE(mem_ctx
);
536 * Add a share, with a couple of standard parameters, partly optional.
538 * This is a high level utility function of the net conf utility,
539 * not a direct frontend to the smbconf API.
541 static int net_conf_addshare(struct net_context
*c
,
542 struct smbconf_ctx
*conf_ctx
, int argc
,
547 char *sharename
= NULL
;
548 const char *path
= NULL
;
549 const char *comment
= NULL
;
550 const char *guest_ok
= "no";
551 const char *writeable
= "no";
552 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
554 if (c
->display_usage
) {
555 net_conf_addshare_usage(c
, argc
, argv
);
564 net_conf_addshare_usage(c
, argc
, argv
);
571 if (!strnequal(argv
[3], "guest_ok=", 9)) {
572 net_conf_addshare_usage(c
, argc
, argv
);
575 switch (argv
[3][9]) {
585 net_conf_addshare_usage(c
, argc
, argv
);
591 if (!strnequal(argv
[2], "writeable=", 10)) {
592 net_conf_addshare_usage(c
, argc
, argv
);
595 switch (argv
[2][10]) {
605 net_conf_addshare_usage(c
, argc
, argv
);
612 sharename
= talloc_strdup(mem_ctx
, argv
[0]);
613 if (sharename
== NULL
) {
614 d_printf(_("error: out of memory!\n"));
625 /* validate share name */
627 if (!validate_net_name(sharename
, INVALID_SHARENAME_CHARS
,
630 d_fprintf(stderr
, _("ERROR: share name %s contains "
631 "invalid characters (any of %s)\n"),
632 sharename
, INVALID_SHARENAME_CHARS
);
636 if (strequal(sharename
, GLOBAL_NAME
)) {
638 _("ERROR: 'global' is not a valid share name.\n"));
642 if (smbconf_share_exists(conf_ctx
, sharename
)) {
643 d_fprintf(stderr
, _("ERROR: share %s already exists.\n"),
650 if (path
[0] != '/') {
652 _("Error: path '%s' is not an absolute path.\n"),
658 * start a transaction
661 err
= smbconf_transaction_start(conf_ctx
);
662 if (!SBC_ERROR_IS_OK(err
)) {
663 d_printf("error starting transaction: %s\n",
664 sbcErrorString(err
));
672 err
= smbconf_create_share(conf_ctx
, sharename
);
673 if (!SBC_ERROR_IS_OK(err
)) {
674 d_fprintf(stderr
, _("Error creating share %s: %s\n"),
675 sharename
, sbcErrorString(err
));
680 * fill the share with parameters
683 err
= smbconf_set_parameter(conf_ctx
, sharename
, "path", path
);
684 if (!SBC_ERROR_IS_OK(err
)) {
685 d_fprintf(stderr
, _("Error setting parameter %s: %s\n"),
686 "path", sbcErrorString(err
));
690 if (comment
!= NULL
) {
691 err
= smbconf_set_parameter(conf_ctx
, sharename
, "comment",
693 if (!SBC_ERROR_IS_OK(err
)) {
694 d_fprintf(stderr
, _("Error setting parameter %s: %s\n"),
695 "comment", sbcErrorString(err
));
700 err
= smbconf_set_parameter(conf_ctx
, sharename
, "guest ok", guest_ok
);
701 if (!SBC_ERROR_IS_OK(err
)) {
702 d_fprintf(stderr
, _("Error setting parameter %s: %s\n"),
703 "'guest ok'", sbcErrorString(err
));
707 err
= smbconf_set_parameter(conf_ctx
, sharename
, "writeable",
709 if (!SBC_ERROR_IS_OK(err
)) {
710 d_fprintf(stderr
, _("Error setting parameter %s: %s\n"),
711 "writeable", sbcErrorString(err
));
716 * commit the whole thing
719 err
= smbconf_transaction_commit(conf_ctx
);
720 if (!SBC_ERROR_IS_OK(err
)) {
721 d_printf("error committing transaction: %s\n",
722 sbcErrorString(err
));
730 err
= smbconf_transaction_cancel(conf_ctx
);
731 if (!SBC_ERROR_IS_OK(err
)) {
732 d_printf("error cancelling transaction: %s\n",
733 sbcErrorString(err
));
737 TALLOC_FREE(mem_ctx
);
741 static int net_conf_delshare(struct net_context
*c
,
742 struct smbconf_ctx
*conf_ctx
, int argc
,
746 const char *sharename
= NULL
;
749 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
751 if (argc
!= 1 || c
->display_usage
) {
752 net_conf_delshare_usage(c
, argc
, argv
);
755 sharename
= talloc_strdup(mem_ctx
, argv
[0]);
756 if (sharename
== NULL
) {
757 d_printf(_("error: out of memory!\n"));
761 err
= smbconf_delete_share(conf_ctx
, sharename
);
762 if (!SBC_ERROR_IS_OK(err
)) {
763 d_fprintf(stderr
, _("Error deleting share %s: %s\n"),
764 sharename
, sbcErrorString(err
));
768 status
= delete_share_security(sharename
);
769 if (!NT_STATUS_IS_OK(status
) &&
770 !NT_STATUS_EQUAL(status
, NT_STATUS_NOT_FOUND
)) {
771 d_fprintf(stderr
, _("deleting share acl failed for %s: %s\n"),
772 sharename
, nt_errstr(status
));
778 TALLOC_FREE(mem_ctx
);
782 static int net_conf_setparm(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
783 int argc
, const char **argv
)
787 char *service
= NULL
;
789 const char *value_str
= NULL
;
790 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
792 if (argc
!= 3 || c
->display_usage
) {
793 net_conf_setparm_usage(c
, argc
, argv
);
797 * NULL service name means "dangling parameters" to libsmbconf.
798 * We use the empty string from the command line for this purpose.
800 if (strlen(argv
[0]) != 0) {
801 service
= talloc_strdup(mem_ctx
, argv
[0]);
802 if (service
== NULL
) {
803 d_printf(_("error: out of memory!\n"));
807 param
= strlower_talloc(mem_ctx
, argv
[1]);
809 d_printf(_("error: out of memory!\n"));
814 if (!net_conf_param_valid(service
,param
, value_str
)) {
818 err
= smbconf_transaction_start(conf_ctx
);
819 if (!SBC_ERROR_IS_OK(err
)) {
820 d_printf(_("error starting transaction: %s\n"),
821 sbcErrorString(err
));
825 if (!smbconf_share_exists(conf_ctx
, service
)) {
826 err
= smbconf_create_share(conf_ctx
, service
);
827 if (!SBC_ERROR_IS_OK(err
)) {
828 d_fprintf(stderr
, _("Error creating share '%s': %s\n"),
829 service
, sbcErrorString(err
));
834 err
= smbconf_set_parameter(conf_ctx
, service
, param
, value_str
);
835 if (!SBC_ERROR_IS_OK(err
)) {
836 d_fprintf(stderr
, _("Error setting value '%s': %s\n"),
837 param
, sbcErrorString(err
));
841 err
= smbconf_transaction_commit(conf_ctx
);
842 if (!SBC_ERROR_IS_OK(err
)) {
843 d_printf(_("error committing transaction: %s\n"),
844 sbcErrorString(err
));
852 err
= smbconf_transaction_cancel(conf_ctx
);
853 if (!SBC_ERROR_IS_OK(err
)) {
854 d_printf(_("error cancelling transaction: %s\n"),
855 sbcErrorString(err
));
859 TALLOC_FREE(mem_ctx
);
863 static int net_conf_getparm(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
864 int argc
, const char **argv
)
868 char *service
= NULL
;
873 mem_ctx
= talloc_stackframe();
875 if (argc
!= 2 || c
->display_usage
) {
876 net_conf_getparm_usage(c
, argc
, argv
);
880 * NULL service name means "dangling parameters" to libsmbconf.
881 * We use the empty string from the command line for this purpose.
883 if (strlen(argv
[0]) != 0) {
884 service
= talloc_strdup(mem_ctx
, argv
[0]);
885 if (service
== NULL
) {
886 d_printf(_("error: out of memory!\n"));
890 param
= strlower_talloc(mem_ctx
, argv
[1]);
892 d_printf(_("error: out of memory!\n"));
896 err
= smbconf_get_parameter(conf_ctx
, mem_ctx
, service
, param
, &valstr
);
897 if (SBC_ERROR_EQUAL(err
, SBC_ERR_NO_SUCH_SERVICE
)) {
899 _("Error: given service '%s' does not exist.\n"),
902 } else if (SBC_ERROR_EQUAL(err
, SBC_ERR_INVALID_PARAM
)) {
904 _("Error: given parameter '%s' is not set.\n"),
907 } else if (!SBC_ERROR_IS_OK(err
)) {
908 d_fprintf(stderr
, _("Error getting value '%s': %s.\n"),
909 param
, sbcErrorString(err
));
913 d_printf("%s\n", valstr
);
917 TALLOC_FREE(mem_ctx
);
921 static int net_conf_delparm(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
922 int argc
, const char **argv
)
926 char *service
= NULL
;
928 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
930 if (argc
!= 2 || c
->display_usage
) {
931 net_conf_delparm_usage(c
, argc
, argv
);
935 * NULL service name means "dangling parameters" to libsmbconf.
936 * We use the empty string from the command line for this purpose.
938 if (strlen(argv
[0]) != 0) {
939 service
= talloc_strdup(mem_ctx
, argv
[0]);
940 if (service
== NULL
) {
941 d_printf(_("error: out of memory!\n"));
945 param
= strlower_talloc(mem_ctx
, argv
[1]);
947 d_printf("error: out of memory!\n");
951 err
= smbconf_delete_parameter(conf_ctx
, service
, param
);
952 if (SBC_ERROR_EQUAL(err
, SBC_ERR_NO_SUCH_SERVICE
)) {
954 _("Error: given service '%s' does not exist.\n"),
957 } else if (SBC_ERROR_EQUAL(err
, SBC_ERR_INVALID_PARAM
)) {
959 _("Error: given parameter '%s' is not set.\n"),
962 } else if (!SBC_ERROR_IS_OK(err
)) {
963 d_fprintf(stderr
, _("Error deleting value '%s': %s.\n"),
964 param
, sbcErrorString(err
));
971 TALLOC_FREE(mem_ctx
);
975 static int net_conf_getincludes(struct net_context
*c
,
976 struct smbconf_ctx
*conf_ctx
,
977 int argc
, const char **argv
)
980 uint32_t num_includes
;
983 char **includes
= NULL
;
985 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
987 if (argc
!= 1 || c
->display_usage
) {
988 net_conf_getincludes_usage(c
, argc
, argv
);
992 service
= talloc_strdup(mem_ctx
, argv
[0]);
993 if (service
== NULL
) {
994 d_printf(_("error: out of memory!\n"));
998 err
= smbconf_get_includes(conf_ctx
, mem_ctx
, service
,
999 &num_includes
, &includes
);
1000 if (!SBC_ERROR_IS_OK(err
)) {
1001 d_printf(_("error getting includes: %s\n"), sbcErrorString(err
));
1005 for (count
= 0; count
< num_includes
; count
++) {
1006 d_printf("include = %s\n", includes
[count
]);
1012 TALLOC_FREE(mem_ctx
);
1016 static int net_conf_setincludes(struct net_context
*c
,
1017 struct smbconf_ctx
*conf_ctx
,
1018 int argc
, const char **argv
)
1022 uint32_t num_includes
;
1023 const char **includes
;
1025 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
1027 if (argc
< 1 || c
->display_usage
) {
1028 net_conf_setincludes_usage(c
, argc
, argv
);
1032 service
= talloc_strdup(mem_ctx
, argv
[0]);
1033 if (service
== NULL
) {
1034 d_printf(_("error: out of memory!\n"));
1038 num_includes
= argc
- 1;
1039 if (num_includes
== 0) {
1042 includes
= argv
+ 1;
1045 err
= smbconf_set_includes(conf_ctx
, service
, num_includes
, includes
);
1046 if (!SBC_ERROR_IS_OK(err
)) {
1047 d_printf(_("error setting includes: %s\n"), sbcErrorString(err
));
1054 TALLOC_FREE(mem_ctx
);
1058 static int net_conf_delincludes(struct net_context
*c
,
1059 struct smbconf_ctx
*conf_ctx
,
1060 int argc
, const char **argv
)
1065 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
1067 if (argc
!= 1 || c
->display_usage
) {
1068 net_conf_delincludes_usage(c
, argc
, argv
);
1072 service
= talloc_strdup(mem_ctx
, argv
[0]);
1073 if (service
== NULL
) {
1074 d_printf(_("error: out of memory!\n"));
1078 err
= smbconf_delete_includes(conf_ctx
, service
);
1079 if (!SBC_ERROR_IS_OK(err
)) {
1080 d_printf(_("error deleting includes: %s\n"), sbcErrorString(err
));
1087 TALLOC_FREE(mem_ctx
);
1092 /**********************************************************************
1094 * Wrapper and net_conf_run_function mechanism.
1096 **********************************************************************/
1099 * Wrapper function to call the main conf functions.
1100 * The wrapper calls handles opening and closing of the
1103 static int net_conf_wrap_function(struct net_context
*c
,
1104 int (*fn
)(struct net_context
*,
1105 struct smbconf_ctx
*,
1106 int, const char **),
1107 int argc
, const char **argv
)
1110 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
1111 struct smbconf_ctx
*conf_ctx
;
1114 err
= smbconf_init(mem_ctx
, &conf_ctx
, "registry:");
1115 if (!SBC_ERROR_IS_OK(err
)) {
1116 talloc_free(mem_ctx
);
1120 ret
= fn(c
, conf_ctx
, argc
, argv
);
1122 smbconf_shutdown(conf_ctx
);
1124 talloc_free(mem_ctx
);
1129 * We need a functable struct of our own, because the
1130 * functions are called through a wrapper that handles
1131 * the opening and closing of the configuration, and so on.
1133 struct conf_functable
{
1134 const char *funcname
;
1135 int (*fn
)(struct net_context
*c
, struct smbconf_ctx
*ctx
, int argc
,
1137 int valid_transports
;
1138 const char *description
;
1143 * This imitates net_run_function but calls the main functions
1144 * through the wrapper net_conf_wrap_function().
1146 static int net_conf_run_function(struct net_context
*c
, int argc
,
1147 const char **argv
, const char *whoami
,
1148 struct conf_functable
*table
)
1153 for (i
=0; table
[i
].funcname
; i
++) {
1154 if (strcasecmp_m(argv
[0], table
[i
].funcname
) == 0)
1155 return net_conf_wrap_function(c
, table
[i
].fn
,
1161 d_printf(_("Usage:\n"));
1162 for (i
=0; table
[i
].funcname
; i
++) {
1163 if (c
->display_usage
== false)
1164 d_printf("%s %-15s %s\n", whoami
, table
[i
].funcname
,
1165 table
[i
].description
);
1167 d_printf("%s\n", table
[i
].usage
);
1170 return c
->display_usage
?0:-1;
1174 * Entry-point for all the CONF functions.
1177 int net_conf(struct net_context
*c
, int argc
, const char **argv
)
1180 struct conf_functable func_table
[] = {
1184 NET_TRANSPORT_LOCAL
,
1185 N_("Dump the complete configuration in smb.conf like "
1187 N_("net conf list\n"
1188 " Dump the complete configuration in smb.conf "
1195 NET_TRANSPORT_LOCAL
,
1196 N_("Import configuration from file in smb.conf "
1198 N_("net conf import\n"
1199 " Import configuration from file in smb.conf "
1204 net_conf_listshares
,
1205 NET_TRANSPORT_LOCAL
,
1206 N_("List the share names."),
1207 N_("net conf listshares\n"
1208 " List the share names.")
1213 NET_TRANSPORT_LOCAL
,
1214 N_("Delete the complete configuration."),
1215 N_("net conf drop\n"
1216 " Delete the complete configuration.")
1221 NET_TRANSPORT_LOCAL
,
1222 N_("Show the definition of a share."),
1223 N_("net conf showshare\n"
1224 " Show the definition of a share.")
1229 NET_TRANSPORT_LOCAL
,
1230 N_("Create a new share."),
1231 N_("net conf addshare\n"
1232 " Create a new share.")
1237 NET_TRANSPORT_LOCAL
,
1238 N_("Delete a share."),
1239 N_("net conf delshare\n"
1245 NET_TRANSPORT_LOCAL
,
1246 N_("Store a parameter."),
1247 N_("net conf setparm\n"
1248 " Store a parameter.")
1253 NET_TRANSPORT_LOCAL
,
1254 N_("Retrieve the value of a parameter."),
1255 N_("net conf getparm\n"
1256 " Retrieve the value of a parameter.")
1261 NET_TRANSPORT_LOCAL
,
1262 N_("Delete a parameter."),
1263 N_("net conf delparm\n"
1264 " Delete a parameter.")
1268 net_conf_getincludes
,
1269 NET_TRANSPORT_LOCAL
,
1270 N_("Show the includes of a share definition."),
1271 N_("net conf getincludes\n"
1272 " Show the includes of a share definition.")
1276 net_conf_setincludes
,
1277 NET_TRANSPORT_LOCAL
,
1278 N_("Set includes for a share."),
1279 N_("net conf setincludes\n"
1280 " Set includes for a share.")
1284 net_conf_delincludes
,
1285 NET_TRANSPORT_LOCAL
,
1286 N_("Delete includes from a share definition."),
1287 N_("net conf delincludes\n"
1288 " Delete includes from a share definition.")
1290 {NULL
, NULL
, 0, NULL
, NULL
}
1293 ret
= net_conf_run_function(c
, argc
, argv
, "net conf", func_table
);