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"
36 #include "lib/param/loadparm.h"
38 /**********************************************************************
42 **********************************************************************/
44 static int net_conf_list_usage(struct net_context
*c
, int argc
,
47 d_printf("%s net conf list\n", _("Usage:"));
51 static int net_conf_import_usage(struct net_context
*c
, int argc
,
56 _(" net conf import [--test|-T] <filename> "
58 "\t[--test|-T] testmode - do not act, just print "
59 "what would be done\n"
60 "\t<servicename> only import service <servicename>, "
61 "ignore the rest\n"));
65 static int net_conf_listshares_usage(struct net_context
*c
, int argc
,
68 d_printf("%s\nnet conf listshares\n", _("Usage:"));
72 static int net_conf_drop_usage(struct net_context
*c
, int argc
,
75 d_printf("%s\nnet conf drop\n", _("Usage:"));
79 static int net_conf_showshare_usage(struct net_context
*c
, int argc
,
84 _("net conf showshare <sharename>\n"));
88 static int net_conf_addshare_usage(struct net_context
*c
, int argc
,
93 _(" net conf addshare <sharename> <path> "
94 "[writeable={y|N} [guest_ok={y|N} [<comment>]]]\n"
95 "\t<sharename> the new share name.\n"
96 "\t<path> the path on the filesystem to export.\n"
97 "\twriteable={y|N} set \"writeable to \"yes\" or "
98 "\"no\" (default) on this share.\n"
99 "\tguest_ok={y|N} set \"guest ok\" to \"yes\" or "
100 "\"no\" (default) on this share.\n"
101 "\t<comment> optional comment for the new share.\n"));
105 static int net_conf_delshare_usage(struct net_context
*c
, int argc
,
110 _("net conf delshare <sharename>\n"));
114 static int net_conf_setparm_usage(struct net_context
*c
, int argc
,
119 _(" net conf setparm <section> <param> <value>\n"));
123 static int net_conf_getparm_usage(struct net_context
*c
, int argc
,
128 _(" net conf getparm <section> <param>\n"));
132 static int net_conf_delparm_usage(struct net_context
*c
, int argc
,
137 _(" net conf delparm <section> <param>\n"));
141 static int net_conf_getincludes_usage(struct net_context
*c
, int argc
,
146 _(" net conf getincludes <section>\n"));
150 static int net_conf_setincludes_usage(struct net_context
*c
, int argc
,
155 _(" net conf setincludes <section> [<filename>]*\n"));
159 static int net_conf_delincludes_usage(struct net_context
*c
, int argc
,
164 _(" net conf delincludes <section>\n"));
169 /**********************************************************************
173 **********************************************************************/
176 * This functions process a service previously loaded with libsmbconf.
178 static sbcErr
import_process_service(struct net_context
*c
,
179 struct smbconf_ctx
*conf_ctx
,
180 struct smbconf_service
*service
)
183 sbcErr err
= SBC_ERR_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 err
= smbconf_delete_share(conf_ctx
, service
->name
);
205 if (!SBC_ERROR_IS_OK(err
)) {
209 err
= smbconf_create_share(conf_ctx
, service
->name
);
210 if (!SBC_ERROR_IS_OK(err
)) {
214 for (idx
= 0; idx
< service
->num_params
; idx
++) {
215 if (strequal(service
->param_names
[idx
], "include")) {
216 includes
= talloc_realloc(mem_ctx
,
220 if (includes
== NULL
) {
224 includes
[num_includes
] = talloc_strdup(includes
,
225 service
->param_values
[idx
]);
226 if (includes
[num_includes
] == NULL
) {
232 err
= smbconf_set_parameter(conf_ctx
,
234 service
->param_names
[idx
],
235 service
->param_values
[idx
]);
236 if (!SBC_ERROR_IS_OK(err
)) {
238 _("Error in section [%s], parameter \"%s\": %s\n"),
239 service
->name
, service
->param_names
[idx
],
240 sbcErrorString(err
));
246 err
= smbconf_set_includes(conf_ctx
, service
->name
, num_includes
,
247 (const char **)includes
);
248 if (!SBC_ERROR_IS_OK(err
)) {
254 TALLOC_FREE(mem_ctx
);
259 /**********************************************************************
261 * the main conf functions
263 **********************************************************************/
265 static int net_conf_list(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
266 int argc
, const char **argv
)
272 uint32_t share_count
, param_count
;
273 struct smbconf_service
**shares
= NULL
;
275 mem_ctx
= talloc_stackframe();
277 if (argc
!= 0 || c
->display_usage
) {
278 net_conf_list_usage(c
, argc
, argv
);
282 err
= smbconf_get_config(conf_ctx
, mem_ctx
, &num_shares
, &shares
);
283 if (!SBC_ERROR_IS_OK(err
)) {
284 d_fprintf(stderr
, _("Error getting config: %s\n"),
285 sbcErrorString(err
));
289 for (share_count
= 0; share_count
< num_shares
; share_count
++) {
290 const char *indent
= "";
291 if (shares
[share_count
]->name
!= NULL
) {
292 d_printf("[%s]\n", shares
[share_count
]->name
);
295 for (param_count
= 0;
296 param_count
< shares
[share_count
]->num_params
;
299 d_printf("%s%s = %s\n",
301 shares
[share_count
]->param_names
[param_count
],
302 shares
[share_count
]->param_values
[param_count
]);
310 TALLOC_FREE(mem_ctx
);
314 static int net_conf_import(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
315 int argc
, const char **argv
)
318 const char *filename
= NULL
;
319 const char *servicename
= NULL
;
320 char *conf_source
= NULL
;
322 struct smbconf_ctx
*txt_ctx
;
325 if (c
->display_usage
)
326 return net_conf_import_usage(c
, argc
, argv
);
328 mem_ctx
= talloc_stackframe();
333 net_conf_import_usage(c
, argc
, argv
);
336 servicename
= talloc_strdup(mem_ctx
, argv
[1]);
337 if (servicename
== NULL
) {
338 d_printf(_("error: out of memory!\n"));
346 DEBUG(3,("net_conf_import: reading configuration from file %s.\n",
349 conf_source
= talloc_asprintf(mem_ctx
, "file:%s", filename
);
350 if (conf_source
== NULL
) {
351 d_printf(_("error: out of memory!\n"));
355 err
= smbconf_init(mem_ctx
, &txt_ctx
, conf_source
);
356 if (!SBC_ERROR_IS_OK(err
)) {
357 d_printf(_("error loading file '%s': %s\n"), filename
,
358 sbcErrorString(err
));
362 if (c
->opt_testmode
) {
363 d_printf(_("\nTEST MODE - "
364 "would import the following configuration:\n\n"));
367 if (servicename
!= NULL
) {
368 struct smbconf_service
*service
= NULL
;
370 err
= smbconf_get_share(txt_ctx
, mem_ctx
,
373 if (!SBC_ERROR_IS_OK(err
)) {
377 err
= smbconf_transaction_start(conf_ctx
);
378 if (!SBC_ERROR_IS_OK(err
)) {
379 d_printf(_("error starting transaction: %s\n"),
380 sbcErrorString(err
));
384 err
= import_process_service(c
, conf_ctx
, service
);
385 if (!SBC_ERROR_IS_OK(err
)) {
389 struct smbconf_service
**services
= NULL
;
390 uint32_t num_shares
, sidx
;
392 err
= smbconf_get_config(txt_ctx
, mem_ctx
,
395 if (!SBC_ERROR_IS_OK(err
)) {
398 if (!c
->opt_testmode
) {
399 if (!SBC_ERROR_IS_OK(smbconf_drop(conf_ctx
))) {
405 * Wrap the importing of shares into a transaction,
406 * but only 100 at a time, in order to save memory.
407 * The allocated memory accumulates across the actions
408 * within the transaction, and for me, some 1500
409 * imported shares, the MAX_TALLOC_SIZE of 256 MB
412 err
= smbconf_transaction_start(conf_ctx
);
413 if (!SBC_ERROR_IS_OK(err
)) {
414 d_printf(_("error starting transaction: %s\n"),
415 sbcErrorString(err
));
419 for (sidx
= 0; sidx
< num_shares
; sidx
++) {
420 err
= import_process_service(c
, conf_ctx
,
422 if (!SBC_ERROR_IS_OK(err
)) {
430 err
= smbconf_transaction_commit(conf_ctx
);
431 if (!SBC_ERROR_IS_OK(err
)) {
432 d_printf(_("error committing transaction: "
434 sbcErrorString(err
));
437 err
= smbconf_transaction_start(conf_ctx
);
438 if (!SBC_ERROR_IS_OK(err
)) {
439 d_printf(_("error starting transaction: %s\n"),
440 sbcErrorString(err
));
446 err
= smbconf_transaction_commit(conf_ctx
);
447 if (!SBC_ERROR_IS_OK(err
)) {
448 d_printf(_("error committing transaction: %s\n"),
449 sbcErrorString(err
));
457 err
= smbconf_transaction_cancel(conf_ctx
);
458 if (!SBC_ERROR_IS_OK(err
)) {
459 d_printf(_("error cancelling transaction: %s\n"),
460 sbcErrorString(err
));
464 TALLOC_FREE(mem_ctx
);
468 static int net_conf_listshares(struct net_context
*c
,
469 struct smbconf_ctx
*conf_ctx
, int argc
,
474 uint32_t count
, num_shares
= 0;
475 char **share_names
= NULL
;
478 mem_ctx
= talloc_stackframe();
480 if (argc
!= 0 || c
->display_usage
) {
481 net_conf_listshares_usage(c
, argc
, argv
);
485 err
= smbconf_get_share_names(conf_ctx
, mem_ctx
, &num_shares
,
487 if (!SBC_ERROR_IS_OK(err
)) {
491 for (count
= 0; count
< num_shares
; count
++)
493 d_printf("%s\n", share_names
[count
]);
499 TALLOC_FREE(mem_ctx
);
503 static int net_conf_drop(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
504 int argc
, const char **argv
)
509 if (argc
!= 0 || c
->display_usage
) {
510 net_conf_drop_usage(c
, argc
, argv
);
514 err
= smbconf_drop(conf_ctx
);
515 if (!SBC_ERROR_IS_OK(err
)) {
516 d_fprintf(stderr
, _("Error deleting configuration: %s\n"),
517 sbcErrorString(err
));
527 static int net_conf_showshare(struct net_context
*c
,
528 struct smbconf_ctx
*conf_ctx
, int argc
,
533 const char *sharename
= NULL
;
536 struct smbconf_service
*service
= NULL
;
538 mem_ctx
= talloc_stackframe();
540 if (argc
!= 1 || c
->display_usage
) {
541 net_conf_showshare_usage(c
, argc
, argv
);
545 sharename
= talloc_strdup(mem_ctx
, argv
[0]);
546 if (sharename
== NULL
) {
547 d_printf("error: out of memory!\n");
551 err
= smbconf_get_share(conf_ctx
, mem_ctx
, sharename
, &service
);
552 if (!SBC_ERROR_IS_OK(err
)) {
553 d_printf(_("error getting share parameters: %s\n"),
554 sbcErrorString(err
));
558 d_printf("[%s]\n", service
->name
);
560 for (count
= 0; count
< service
->num_params
; count
++) {
561 d_printf("\t%s = %s\n", service
->param_names
[count
],
562 service
->param_values
[count
]);
568 TALLOC_FREE(mem_ctx
);
573 * Add a share, with a couple of standard parameters, partly optional.
575 * This is a high level utility function of the net conf utility,
576 * not a direct frontend to the smbconf API.
578 static int net_conf_addshare(struct net_context
*c
,
579 struct smbconf_ctx
*conf_ctx
, int argc
,
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 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
591 if (c
->display_usage
) {
592 net_conf_addshare_usage(c
, argc
, argv
);
601 net_conf_addshare_usage(c
, argc
, argv
);
606 if (!strnequal(argv
[3], "guest_ok=", 9)) {
607 net_conf_addshare_usage(c
, argc
, argv
);
610 switch (argv
[3][9]) {
620 net_conf_addshare_usage(c
, argc
, argv
);
624 if (!strnequal(argv
[2], "writeable=", 10)) {
625 net_conf_addshare_usage(c
, argc
, argv
);
628 switch (argv
[2][10]) {
638 net_conf_addshare_usage(c
, argc
, argv
);
643 sharename
= talloc_strdup(mem_ctx
, argv
[0]);
644 if (sharename
== NULL
) {
645 d_printf(_("error: out of memory!\n"));
656 /* validate share name */
658 if (!validate_net_name(sharename
, INVALID_SHARENAME_CHARS
,
661 d_fprintf(stderr
, _("ERROR: share name %s contains "
662 "invalid characters (any of %s)\n"),
663 sharename
, INVALID_SHARENAME_CHARS
);
667 if (strequal(sharename
, GLOBAL_NAME
)) {
669 _("ERROR: 'global' is not a valid share name.\n"));
673 if (smbconf_share_exists(conf_ctx
, sharename
)) {
674 d_fprintf(stderr
, _("ERROR: share %s already exists.\n"),
681 if (path
[0] != '/') {
683 _("Error: path '%s' is not an absolute path.\n"),
689 * start a transaction
692 err
= smbconf_transaction_start(conf_ctx
);
693 if (!SBC_ERROR_IS_OK(err
)) {
694 d_printf("error starting transaction: %s\n",
695 sbcErrorString(err
));
703 err
= smbconf_create_share(conf_ctx
, sharename
);
704 if (!SBC_ERROR_IS_OK(err
)) {
705 d_fprintf(stderr
, _("Error creating share %s: %s\n"),
706 sharename
, sbcErrorString(err
));
711 * fill the share with parameters
714 err
= smbconf_set_parameter(conf_ctx
, sharename
, "path", path
);
715 if (!SBC_ERROR_IS_OK(err
)) {
716 d_fprintf(stderr
, _("Error setting parameter %s: %s\n"),
717 "path", sbcErrorString(err
));
721 if (comment
!= NULL
) {
722 err
= smbconf_set_parameter(conf_ctx
, sharename
, "comment",
724 if (!SBC_ERROR_IS_OK(err
)) {
725 d_fprintf(stderr
, _("Error setting parameter %s: %s\n"),
726 "comment", sbcErrorString(err
));
731 err
= smbconf_set_parameter(conf_ctx
, sharename
, "guest ok", guest_ok
);
732 if (!SBC_ERROR_IS_OK(err
)) {
733 d_fprintf(stderr
, _("Error setting parameter %s: %s\n"),
734 "'guest ok'", sbcErrorString(err
));
738 err
= smbconf_set_parameter(conf_ctx
, sharename
, "writeable",
740 if (!SBC_ERROR_IS_OK(err
)) {
741 d_fprintf(stderr
, _("Error setting parameter %s: %s\n"),
742 "writeable", sbcErrorString(err
));
747 * commit the whole thing
750 err
= smbconf_transaction_commit(conf_ctx
);
751 if (!SBC_ERROR_IS_OK(err
)) {
752 d_printf("error committing transaction: %s\n",
753 sbcErrorString(err
));
761 err
= smbconf_transaction_cancel(conf_ctx
);
762 if (!SBC_ERROR_IS_OK(err
)) {
763 d_printf("error cancelling transaction: %s\n",
764 sbcErrorString(err
));
768 TALLOC_FREE(mem_ctx
);
772 static int net_conf_delshare(struct net_context
*c
,
773 struct smbconf_ctx
*conf_ctx
, int argc
,
777 const char *sharename
= NULL
;
779 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
781 if (argc
!= 1 || c
->display_usage
) {
782 net_conf_delshare_usage(c
, argc
, argv
);
785 sharename
= talloc_strdup(mem_ctx
, argv
[0]);
786 if (sharename
== NULL
) {
787 d_printf(_("error: out of memory!\n"));
791 err
= smbconf_delete_share(conf_ctx
, sharename
);
792 if (!SBC_ERROR_IS_OK(err
)) {
793 d_fprintf(stderr
, _("Error deleting share %s: %s\n"),
794 sharename
, sbcErrorString(err
));
800 TALLOC_FREE(mem_ctx
);
804 static int net_conf_setparm(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
805 int argc
, const char **argv
)
809 char *service
= NULL
;
811 const char *value_str
= NULL
;
812 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
814 if (argc
!= 3 || c
->display_usage
) {
815 net_conf_setparm_usage(c
, argc
, argv
);
819 * NULL service name means "dangling parameters" to libsmbconf.
820 * We use the empty string from the command line for this purpose.
822 if (strlen(argv
[0]) != 0) {
823 service
= talloc_strdup(mem_ctx
, argv
[0]);
824 if (service
== NULL
) {
825 d_printf(_("error: out of memory!\n"));
829 param
= strlower_talloc(mem_ctx
, argv
[1]);
831 d_printf(_("error: out of memory!\n"));
836 err
= smbconf_transaction_start(conf_ctx
);
837 if (!SBC_ERROR_IS_OK(err
)) {
838 d_printf(_("error starting transaction: %s\n"),
839 sbcErrorString(err
));
843 if (!smbconf_share_exists(conf_ctx
, service
)) {
844 err
= smbconf_create_share(conf_ctx
, service
);
845 if (!SBC_ERROR_IS_OK(err
)) {
846 d_fprintf(stderr
, _("Error creating share '%s': %s\n"),
847 service
, sbcErrorString(err
));
852 err
= smbconf_set_parameter(conf_ctx
, service
, param
, value_str
);
853 if (!SBC_ERROR_IS_OK(err
)) {
854 d_fprintf(stderr
, _("Error setting value '%s': %s\n"),
855 param
, sbcErrorString(err
));
859 err
= smbconf_transaction_commit(conf_ctx
);
860 if (!SBC_ERROR_IS_OK(err
)) {
861 d_printf(_("error committing transaction: %s\n"),
862 sbcErrorString(err
));
870 err
= smbconf_transaction_cancel(conf_ctx
);
871 if (!SBC_ERROR_IS_OK(err
)) {
872 d_printf(_("error cancelling transaction: %s\n"),
873 sbcErrorString(err
));
877 TALLOC_FREE(mem_ctx
);
881 static int net_conf_getparm(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
882 int argc
, const char **argv
)
886 char *service
= NULL
;
891 mem_ctx
= talloc_stackframe();
893 if (argc
!= 2 || c
->display_usage
) {
894 net_conf_getparm_usage(c
, argc
, argv
);
898 * NULL service name means "dangling parameters" to libsmbconf.
899 * We use the empty string from the command line for this purpose.
901 if (strlen(argv
[0]) != 0) {
902 service
= talloc_strdup(mem_ctx
, argv
[0]);
903 if (service
== NULL
) {
904 d_printf(_("error: out of memory!\n"));
908 param
= strlower_talloc(mem_ctx
, argv
[1]);
910 d_printf(_("error: out of memory!\n"));
914 err
= smbconf_get_parameter(conf_ctx
, mem_ctx
, service
, param
, &valstr
);
915 if (SBC_ERROR_EQUAL(err
, SBC_ERR_NO_SUCH_SERVICE
)) {
917 _("Error: given service '%s' does not exist.\n"),
920 } else if (SBC_ERROR_EQUAL(err
, SBC_ERR_INVALID_PARAM
)) {
922 _("Error: given parameter '%s' is not set.\n"),
925 } else if (!SBC_ERROR_IS_OK(err
)) {
926 d_fprintf(stderr
, _("Error getting value '%s': %s.\n"),
927 param
, sbcErrorString(err
));
931 d_printf("%s\n", valstr
);
935 TALLOC_FREE(mem_ctx
);
939 static int net_conf_delparm(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
940 int argc
, const char **argv
)
944 char *service
= NULL
;
946 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
948 if (argc
!= 2 || c
->display_usage
) {
949 net_conf_delparm_usage(c
, argc
, argv
);
953 * NULL service name means "dangling parameters" to libsmbconf.
954 * We use the empty string from the command line for this purpose.
956 if (strlen(argv
[0]) != 0) {
957 service
= talloc_strdup(mem_ctx
, argv
[0]);
958 if (service
== NULL
) {
959 d_printf(_("error: out of memory!\n"));
963 param
= strlower_talloc(mem_ctx
, argv
[1]);
965 d_printf("error: out of memory!\n");
969 err
= smbconf_delete_parameter(conf_ctx
, service
, param
);
970 if (SBC_ERROR_EQUAL(err
, SBC_ERR_NO_SUCH_SERVICE
)) {
972 _("Error: given service '%s' does not exist.\n"),
975 } else if (SBC_ERROR_EQUAL(err
, SBC_ERR_INVALID_PARAM
)) {
977 _("Error: given parameter '%s' is not set.\n"),
980 } else if (!SBC_ERROR_IS_OK(err
)) {
981 d_fprintf(stderr
, _("Error deleting value '%s': %s.\n"),
982 param
, sbcErrorString(err
));
989 TALLOC_FREE(mem_ctx
);
993 static int net_conf_getincludes(struct net_context
*c
,
994 struct smbconf_ctx
*conf_ctx
,
995 int argc
, const char **argv
)
998 uint32_t num_includes
;
1001 char **includes
= NULL
;
1003 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
1005 if (argc
!= 1 || c
->display_usage
) {
1006 net_conf_getincludes_usage(c
, argc
, argv
);
1010 service
= talloc_strdup(mem_ctx
, argv
[0]);
1011 if (service
== NULL
) {
1012 d_printf(_("error: out of memory!\n"));
1016 err
= smbconf_get_includes(conf_ctx
, mem_ctx
, service
,
1017 &num_includes
, &includes
);
1018 if (!SBC_ERROR_IS_OK(err
)) {
1019 d_printf(_("error getting includes: %s\n"), sbcErrorString(err
));
1023 for (count
= 0; count
< num_includes
; count
++) {
1024 d_printf("include = %s\n", includes
[count
]);
1030 TALLOC_FREE(mem_ctx
);
1034 static int net_conf_setincludes(struct net_context
*c
,
1035 struct smbconf_ctx
*conf_ctx
,
1036 int argc
, const char **argv
)
1040 uint32_t num_includes
;
1041 const char **includes
;
1043 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
1045 if (argc
< 1 || c
->display_usage
) {
1046 net_conf_setincludes_usage(c
, argc
, argv
);
1050 service
= talloc_strdup(mem_ctx
, argv
[0]);
1051 if (service
== NULL
) {
1052 d_printf(_("error: out of memory!\n"));
1056 num_includes
= argc
- 1;
1057 if (num_includes
== 0) {
1060 includes
= argv
+ 1;
1063 err
= smbconf_set_includes(conf_ctx
, service
, num_includes
, includes
);
1064 if (!SBC_ERROR_IS_OK(err
)) {
1065 d_printf(_("error setting includes: %s\n"), sbcErrorString(err
));
1072 TALLOC_FREE(mem_ctx
);
1076 static int net_conf_delincludes(struct net_context
*c
,
1077 struct smbconf_ctx
*conf_ctx
,
1078 int argc
, const char **argv
)
1083 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
1085 if (argc
!= 1 || c
->display_usage
) {
1086 net_conf_delincludes_usage(c
, argc
, argv
);
1090 service
= talloc_strdup(mem_ctx
, argv
[0]);
1091 if (service
== NULL
) {
1092 d_printf(_("error: out of memory!\n"));
1096 err
= smbconf_delete_includes(conf_ctx
, service
);
1097 if (!SBC_ERROR_IS_OK(err
)) {
1098 d_printf(_("error deleting includes: %s\n"), sbcErrorString(err
));
1105 TALLOC_FREE(mem_ctx
);
1110 /**********************************************************************
1112 * Wrapper and net_conf_run_function mechanism.
1114 **********************************************************************/
1117 * Wrapper function to call the main conf functions.
1118 * The wrapper calls handles opening and closing of the
1121 static int net_conf_wrap_function(struct net_context
*c
,
1122 int (*fn
)(struct net_context
*,
1123 struct smbconf_ctx
*,
1124 int, const char **),
1125 int argc
, const char **argv
)
1128 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
1129 struct smbconf_ctx
*conf_ctx
;
1132 err
= smbconf_init(mem_ctx
, &conf_ctx
, "registry:");
1133 if (!SBC_ERROR_IS_OK(err
)) {
1137 ret
= fn(c
, conf_ctx
, argc
, argv
);
1139 smbconf_shutdown(conf_ctx
);
1145 * We need a functable struct of our own, because the
1146 * functions are called through a wrapper that handles
1147 * the opening and closing of the configuration, and so on.
1149 struct conf_functable
{
1150 const char *funcname
;
1151 int (*fn
)(struct net_context
*c
, struct smbconf_ctx
*ctx
, int argc
,
1153 int valid_transports
;
1154 const char *description
;
1159 * This imitates net_run_function but calls the main functions
1160 * through the wrapper net_conf_wrap_function().
1162 static int net_conf_run_function(struct net_context
*c
, int argc
,
1163 const char **argv
, const char *whoami
,
1164 struct conf_functable
*table
)
1169 for (i
=0; table
[i
].funcname
; i
++) {
1170 if (strcasecmp_m(argv
[0], table
[i
].funcname
) == 0)
1171 return net_conf_wrap_function(c
, table
[i
].fn
,
1177 d_printf(_("Usage:\n"));
1178 for (i
=0; table
[i
].funcname
; i
++) {
1179 if (c
->display_usage
== false)
1180 d_printf("%s %-15s %s\n", whoami
, table
[i
].funcname
,
1181 table
[i
].description
);
1183 d_printf("%s\n", table
[i
].usage
);
1186 return c
->display_usage
?0:-1;
1190 * Entry-point for all the CONF functions.
1193 int net_conf(struct net_context
*c
, int argc
, const char **argv
)
1196 struct conf_functable func_table
[] = {
1200 NET_TRANSPORT_LOCAL
,
1201 N_("Dump the complete configuration in smb.conf like "
1203 N_("net conf list\n"
1204 " Dump the complete configuration in smb.conf "
1211 NET_TRANSPORT_LOCAL
,
1212 N_("Import configuration from file in smb.conf "
1214 N_("net conf import\n"
1215 " Import configuration from file in smb.conf "
1220 net_conf_listshares
,
1221 NET_TRANSPORT_LOCAL
,
1222 N_("List the share names."),
1223 N_("net conf listshares\n"
1224 " List the share names.")
1229 NET_TRANSPORT_LOCAL
,
1230 N_("Delete the complete configuration."),
1231 N_("net conf drop\n"
1232 " Delete the complete configuration.")
1237 NET_TRANSPORT_LOCAL
,
1238 N_("Show the definition of a share."),
1239 N_("net conf showshare\n"
1240 " Show the definition of a share.")
1245 NET_TRANSPORT_LOCAL
,
1246 N_("Create a new share."),
1247 N_("net conf addshare\n"
1248 " Create a new share.")
1253 NET_TRANSPORT_LOCAL
,
1254 N_("Delete a share."),
1255 N_("net conf delshare\n"
1261 NET_TRANSPORT_LOCAL
,
1262 N_("Store a parameter."),
1263 N_("net conf setparm\n"
1264 " Store a parameter.")
1269 NET_TRANSPORT_LOCAL
,
1270 N_("Retrieve the value of a parameter."),
1271 N_("net conf getparm\n"
1272 " Retrieve the value of a parameter.")
1277 NET_TRANSPORT_LOCAL
,
1278 N_("Delete a parameter."),
1279 N_("net conf delparm\n"
1280 " Delete a parameter.")
1284 net_conf_getincludes
,
1285 NET_TRANSPORT_LOCAL
,
1286 N_("Show the includes of a share definition."),
1287 N_("net conf getincludes\n"
1288 " Show the includes of a share definition.")
1292 net_conf_setincludes
,
1293 NET_TRANSPORT_LOCAL
,
1294 N_("Set includes for a share."),
1295 N_("net conf setincludes\n"
1296 " Set includes for a share.")
1300 net_conf_delincludes
,
1301 NET_TRANSPORT_LOCAL
,
1302 N_("Delete includes from a share definition."),
1303 N_("net conf delincludes\n"
1304 " Delete includes from a share definition.")
1306 {NULL
, NULL
, 0, NULL
, NULL
}
1309 ret
= net_conf_run_function(c
, argc
, argv
, "net conf", func_table
);