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 err
= smbconf_delete_share(conf_ctx
, service
->name
);
205 if (!SBC_ERROR_IS_OK(err
)) {
206 werr
= WERR_GENERAL_FAILURE
;
210 err
= smbconf_create_share(conf_ctx
, service
->name
);
211 if (!SBC_ERROR_IS_OK(err
)) {
212 werr
= WERR_GENERAL_FAILURE
;
216 for (idx
= 0; idx
< service
->num_params
; idx
++) {
217 if (strequal(service
->param_names
[idx
], "include")) {
218 includes
= TALLOC_REALLOC_ARRAY(mem_ctx
,
222 if (includes
== NULL
) {
226 includes
[num_includes
] = talloc_strdup(includes
,
227 service
->param_values
[idx
]);
228 if (includes
[num_includes
] == NULL
) {
234 err
= smbconf_set_parameter(conf_ctx
,
236 service
->param_names
[idx
],
237 service
->param_values
[idx
]);
238 if (!SBC_ERROR_IS_OK(err
)) {
240 _("Error in section [%s], parameter \"%s\": %s\n"),
241 service
->name
, service
->param_names
[idx
],
242 sbcErrorString(err
));
249 werr
= smbconf_set_includes(conf_ctx
, service
->name
, num_includes
,
250 (const char **)includes
);
253 TALLOC_FREE(mem_ctx
);
258 /**********************************************************************
260 * the main conf functions
262 **********************************************************************/
264 static int net_conf_list(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
265 int argc
, const char **argv
)
267 WERROR werr
= WERR_OK
;
271 uint32_t share_count
, param_count
;
272 struct smbconf_service
**shares
= NULL
;
274 mem_ctx
= talloc_stackframe();
276 if (argc
!= 0 || c
->display_usage
) {
277 net_conf_list_usage(c
, argc
, argv
);
281 werr
= smbconf_get_config(conf_ctx
, mem_ctx
, &num_shares
, &shares
);
282 if (!W_ERROR_IS_OK(werr
)) {
283 d_fprintf(stderr
, _("Error getting config: %s\n"),
288 for (share_count
= 0; share_count
< num_shares
; share_count
++) {
289 const char *indent
= "";
290 if (shares
[share_count
]->name
!= NULL
) {
291 d_printf("[%s]\n", shares
[share_count
]->name
);
294 for (param_count
= 0;
295 param_count
< shares
[share_count
]->num_params
;
298 d_printf("%s%s = %s\n",
300 shares
[share_count
]->param_names
[param_count
],
301 shares
[share_count
]->param_values
[param_count
]);
309 TALLOC_FREE(mem_ctx
);
313 static int net_conf_import(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
314 int argc
, const char **argv
)
317 const char *filename
= NULL
;
318 const char *servicename
= NULL
;
319 char *conf_source
= NULL
;
321 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
));
359 werr
= WERR_NO_SUCH_SERVICE
;
363 if (c
->opt_testmode
) {
364 d_printf(_("\nTEST MODE - "
365 "would import the following configuration:\n\n"));
368 if (servicename
!= NULL
) {
369 struct smbconf_service
*service
= NULL
;
371 err
= smbconf_get_share(txt_ctx
, mem_ctx
,
374 if (!SBC_ERROR_IS_OK(err
)) {
378 werr
= smbconf_transaction_start(conf_ctx
);
379 if (!W_ERROR_IS_OK(werr
)) {
380 d_printf(_("error starting transaction: %s\n"),
385 werr
= import_process_service(c
, conf_ctx
, service
);
386 if (!W_ERROR_IS_OK(werr
)) {
390 struct smbconf_service
**services
= NULL
;
391 uint32_t num_shares
, sidx
;
393 werr
= smbconf_get_config(txt_ctx
, mem_ctx
,
396 if (!W_ERROR_IS_OK(werr
)) {
399 if (!c
->opt_testmode
) {
400 if (!SBC_ERROR_IS_OK(smbconf_drop(conf_ctx
))) {
406 * Wrap the importing of shares into a transaction,
407 * but only 100 at a time, in order to save memory.
408 * The allocated memory accumulates across the actions
409 * within the transaction, and for me, some 1500
410 * imported shares, the MAX_TALLOC_SIZE of 256 MB
413 werr
= smbconf_transaction_start(conf_ctx
);
414 if (!W_ERROR_IS_OK(werr
)) {
415 d_printf(_("error starting transaction: %s\n"),
420 for (sidx
= 0; sidx
< num_shares
; sidx
++) {
421 werr
= import_process_service(c
, conf_ctx
,
423 if (!W_ERROR_IS_OK(werr
)) {
431 werr
= smbconf_transaction_commit(conf_ctx
);
432 if (!W_ERROR_IS_OK(werr
)) {
433 d_printf(_("error committing transaction: "
438 werr
= smbconf_transaction_start(conf_ctx
);
439 if (!W_ERROR_IS_OK(werr
)) {
440 d_printf(_("error starting transaction: %s\n"),
447 werr
= smbconf_transaction_commit(conf_ctx
);
448 if (!W_ERROR_IS_OK(werr
)) {
449 d_printf(_("error committing transaction: %s\n"),
458 werr
= smbconf_transaction_cancel(conf_ctx
);
459 if (!W_ERROR_IS_OK(werr
)) {
460 d_printf(_("error cancelling transaction: %s\n"),
465 TALLOC_FREE(mem_ctx
);
469 static int net_conf_listshares(struct net_context
*c
,
470 struct smbconf_ctx
*conf_ctx
, int argc
,
475 uint32_t count
, num_shares
= 0;
476 char **share_names
= NULL
;
479 mem_ctx
= talloc_stackframe();
481 if (argc
!= 0 || c
->display_usage
) {
482 net_conf_listshares_usage(c
, argc
, argv
);
486 err
= smbconf_get_share_names(conf_ctx
, mem_ctx
, &num_shares
,
488 if (!SBC_ERROR_IS_OK(err
)) {
492 for (count
= 0; count
< num_shares
; count
++)
494 d_printf("%s\n", share_names
[count
]);
500 TALLOC_FREE(mem_ctx
);
504 static int net_conf_drop(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
505 int argc
, const char **argv
)
510 if (argc
!= 0 || c
->display_usage
) {
511 net_conf_drop_usage(c
, argc
, argv
);
515 err
= smbconf_drop(conf_ctx
);
516 if (!SBC_ERROR_IS_OK(err
)) {
517 d_fprintf(stderr
, _("Error deleting configuration: %s\n"),
518 sbcErrorString(err
));
528 static int net_conf_showshare(struct net_context
*c
,
529 struct smbconf_ctx
*conf_ctx
, int argc
,
534 const char *sharename
= NULL
;
537 struct smbconf_service
*service
= NULL
;
539 mem_ctx
= talloc_stackframe();
541 if (argc
!= 1 || c
->display_usage
) {
542 net_conf_showshare_usage(c
, argc
, argv
);
546 sharename
= talloc_strdup(mem_ctx
, argv
[0]);
547 if (sharename
== NULL
) {
548 d_printf("error: out of memory!\n");
552 err
= smbconf_get_share(conf_ctx
, mem_ctx
, sharename
, &service
);
553 if (!SBC_ERROR_IS_OK(err
)) {
554 d_printf(_("error getting share parameters: %s\n"),
555 sbcErrorString(err
));
559 d_printf("[%s]\n", service
->name
);
561 for (count
= 0; count
< service
->num_params
; count
++) {
562 d_printf("\t%s = %s\n", service
->param_names
[count
],
563 service
->param_values
[count
]);
569 TALLOC_FREE(mem_ctx
);
574 * Add a share, with a couple of standard parameters, partly optional.
576 * This is a high level utility function of the net conf utility,
577 * not a direct frontend to the smbconf API.
579 static int net_conf_addshare(struct net_context
*c
,
580 struct smbconf_ctx
*conf_ctx
, int argc
,
584 WERROR werr
= WERR_OK
;
586 char *sharename
= NULL
;
587 const char *path
= NULL
;
588 const char *comment
= NULL
;
589 const char *guest_ok
= "no";
590 const char *writeable
= "no";
591 SMB_STRUCT_STAT sbuf
;
592 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
594 if (c
->display_usage
) {
595 net_conf_addshare_usage(c
, argc
, argv
);
604 net_conf_addshare_usage(c
, argc
, argv
);
609 if (!strnequal(argv
[3], "guest_ok=", 9)) {
610 net_conf_addshare_usage(c
, argc
, argv
);
613 switch (argv
[3][9]) {
623 net_conf_addshare_usage(c
, argc
, argv
);
627 if (!strnequal(argv
[2], "writeable=", 10)) {
628 net_conf_addshare_usage(c
, argc
, argv
);
631 switch (argv
[2][10]) {
641 net_conf_addshare_usage(c
, argc
, argv
);
646 sharename
= talloc_strdup(mem_ctx
, argv
[0]);
647 if (sharename
== NULL
) {
648 d_printf(_("error: out of memory!\n"));
659 /* validate share name */
661 if (!validate_net_name(sharename
, INVALID_SHARENAME_CHARS
,
664 d_fprintf(stderr
, _("ERROR: share name %s contains "
665 "invalid characters (any of %s)\n"),
666 sharename
, INVALID_SHARENAME_CHARS
);
670 if (strequal(sharename
, GLOBAL_NAME
)) {
672 _("ERROR: 'global' is not a valid share name.\n"));
676 if (smbconf_share_exists(conf_ctx
, sharename
)) {
677 d_fprintf(stderr
, _("ERROR: share %s already exists.\n"),
684 if (path
[0] != '/') {
686 _("Error: path '%s' is not an absolute path.\n"),
691 if (sys_stat(path
, &sbuf
, false) != 0) {
693 _("ERROR: cannot stat path '%s' to ensure "
694 "this is a directory.\n"
695 "Error was '%s'.\n"),
696 path
, strerror(errno
));
700 if (!S_ISDIR(sbuf
.st_ex_mode
)) {
702 _("ERROR: path '%s' is not a directory.\n"),
708 * start a transaction
711 werr
= smbconf_transaction_start(conf_ctx
);
712 if (!W_ERROR_IS_OK(werr
)) {
713 d_printf("error starting transaction: %s\n",
722 err
= smbconf_create_share(conf_ctx
, sharename
);
723 if (!SBC_ERROR_IS_OK(err
)) {
724 d_fprintf(stderr
, _("Error creating share %s: %s\n"),
725 sharename
, sbcErrorString(err
));
730 * fill the share with parameters
733 err
= smbconf_set_parameter(conf_ctx
, sharename
, "path", path
);
734 if (!SBC_ERROR_IS_OK(err
)) {
735 d_fprintf(stderr
, _("Error setting parameter %s: %s\n"),
736 "path", sbcErrorString(err
));
740 if (comment
!= NULL
) {
741 err
= smbconf_set_parameter(conf_ctx
, sharename
, "comment",
743 if (!SBC_ERROR_IS_OK(err
)) {
744 d_fprintf(stderr
, _("Error setting parameter %s: %s\n"),
745 "comment", sbcErrorString(err
));
750 err
= smbconf_set_parameter(conf_ctx
, sharename
, "guest ok", guest_ok
);
751 if (!SBC_ERROR_IS_OK(err
)) {
752 d_fprintf(stderr
, _("Error setting parameter %s: %s\n"),
753 "'guest ok'", sbcErrorString(err
));
757 err
= smbconf_set_parameter(conf_ctx
, sharename
, "writeable",
759 if (!SBC_ERROR_IS_OK(err
)) {
760 d_fprintf(stderr
, _("Error setting parameter %s: %s\n"),
761 "writeable", sbcErrorString(err
));
766 * commit the whole thing
769 werr
= smbconf_transaction_commit(conf_ctx
);
770 if (!W_ERROR_IS_OK(werr
)) {
771 d_printf("error committing transaction: %s\n",
780 werr
= smbconf_transaction_cancel(conf_ctx
);
781 if (!W_ERROR_IS_OK(werr
)) {
782 d_printf("error cancelling transaction: %s\n",
787 TALLOC_FREE(mem_ctx
);
791 static int net_conf_delshare(struct net_context
*c
,
792 struct smbconf_ctx
*conf_ctx
, int argc
,
796 const char *sharename
= NULL
;
798 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
800 if (argc
!= 1 || c
->display_usage
) {
801 net_conf_delshare_usage(c
, argc
, argv
);
804 sharename
= talloc_strdup(mem_ctx
, argv
[0]);
805 if (sharename
== NULL
) {
806 d_printf(_("error: out of memory!\n"));
810 err
= smbconf_delete_share(conf_ctx
, sharename
);
811 if (!SBC_ERROR_IS_OK(err
)) {
812 d_fprintf(stderr
, _("Error deleting share %s: %s\n"),
813 sharename
, sbcErrorString(err
));
819 TALLOC_FREE(mem_ctx
);
823 static int net_conf_setparm(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
824 int argc
, const char **argv
)
827 WERROR werr
= WERR_OK
;
829 char *service
= NULL
;
831 const char *value_str
= NULL
;
832 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
834 if (argc
!= 3 || c
->display_usage
) {
835 net_conf_setparm_usage(c
, argc
, argv
);
839 * NULL service name means "dangling parameters" to libsmbconf.
840 * We use the empty string from the command line for this purpose.
842 if (strlen(argv
[0]) != 0) {
843 service
= talloc_strdup(mem_ctx
, argv
[0]);
844 if (service
== NULL
) {
845 d_printf(_("error: out of memory!\n"));
849 param
= strlower_talloc(mem_ctx
, argv
[1]);
851 d_printf(_("error: out of memory!\n"));
856 werr
= smbconf_transaction_start(conf_ctx
);
857 if (!W_ERROR_IS_OK(werr
)) {
858 d_printf(_("error starting transaction: %s\n"),
863 if (!smbconf_share_exists(conf_ctx
, service
)) {
864 err
= smbconf_create_share(conf_ctx
, service
);
865 if (!SBC_ERROR_IS_OK(err
)) {
866 d_fprintf(stderr
, _("Error creating share '%s': %s\n"),
867 service
, sbcErrorString(err
));
872 err
= smbconf_set_parameter(conf_ctx
, service
, param
, value_str
);
873 if (!SBC_ERROR_IS_OK(err
)) {
874 d_fprintf(stderr
, _("Error setting value '%s': %s\n"),
875 param
, sbcErrorString(err
));
879 werr
= smbconf_transaction_commit(conf_ctx
);
880 if (!W_ERROR_IS_OK(werr
)) {
881 d_printf(_("error committing transaction: %s\n"),
890 werr
= smbconf_transaction_cancel(conf_ctx
);
891 if (!W_ERROR_IS_OK(werr
)) {
892 d_printf(_("error cancelling transaction: %s\n"),
897 TALLOC_FREE(mem_ctx
);
901 static int net_conf_getparm(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
902 int argc
, const char **argv
)
906 char *service
= NULL
;
911 mem_ctx
= talloc_stackframe();
913 if (argc
!= 2 || c
->display_usage
) {
914 net_conf_getparm_usage(c
, argc
, argv
);
918 * NULL service name means "dangling parameters" to libsmbconf.
919 * We use the empty string from the command line for this purpose.
921 if (strlen(argv
[0]) != 0) {
922 service
= talloc_strdup(mem_ctx
, argv
[0]);
923 if (service
== NULL
) {
924 d_printf(_("error: out of memory!\n"));
928 param
= strlower_talloc(mem_ctx
, argv
[1]);
930 d_printf(_("error: out of memory!\n"));
934 err
= smbconf_get_parameter(conf_ctx
, mem_ctx
, service
, param
, &valstr
);
935 if (SBC_ERROR_EQUAL(err
, SBC_ERR_NO_SUCH_SERVICE
)) {
937 _("Error: given service '%s' does not exist.\n"),
940 } else if (SBC_ERROR_EQUAL(err
, SBC_ERR_INVALID_PARAM
)) {
942 _("Error: given parameter '%s' is not set.\n"),
945 } else if (!SBC_ERROR_IS_OK(err
)) {
946 d_fprintf(stderr
, _("Error getting value '%s': %s.\n"),
947 param
, sbcErrorString(err
));
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
)
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 err
= smbconf_delete_parameter(conf_ctx
, service
, param
);
990 if (SBC_ERROR_EQUAL(err
, SBC_ERR_NO_SUCH_SERVICE
)) {
992 _("Error: given service '%s' does not exist.\n"),
995 } else if (SBC_ERROR_EQUAL(err
, SBC_ERR_INVALID_PARAM
)) {
997 _("Error: given parameter '%s' is not set.\n"),
1000 } else if (!SBC_ERROR_IS_OK(err
)) {
1001 d_fprintf(stderr
, _("Error deleting value '%s': %s.\n"),
1002 param
, sbcErrorString(err
));
1009 TALLOC_FREE(mem_ctx
);
1013 static int net_conf_getincludes(struct net_context
*c
,
1014 struct smbconf_ctx
*conf_ctx
,
1015 int argc
, const char **argv
)
1018 uint32_t num_includes
;
1021 char **includes
= NULL
;
1023 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
1025 if (argc
!= 1 || c
->display_usage
) {
1026 net_conf_getincludes_usage(c
, argc
, argv
);
1030 service
= talloc_strdup(mem_ctx
, argv
[0]);
1031 if (service
== NULL
) {
1032 d_printf(_("error: out of memory!\n"));
1036 werr
= smbconf_get_includes(conf_ctx
, mem_ctx
, service
,
1037 &num_includes
, &includes
);
1038 if (!W_ERROR_IS_OK(werr
)) {
1039 d_printf(_("error getting includes: %s\n"), win_errstr(werr
));
1043 for (count
= 0; count
< num_includes
; count
++) {
1044 d_printf("include = %s\n", includes
[count
]);
1050 TALLOC_FREE(mem_ctx
);
1054 static int net_conf_setincludes(struct net_context
*c
,
1055 struct smbconf_ctx
*conf_ctx
,
1056 int argc
, const char **argv
)
1060 uint32_t num_includes
;
1061 const char **includes
;
1063 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
1065 if (argc
< 1 || c
->display_usage
) {
1066 net_conf_setincludes_usage(c
, argc
, argv
);
1070 service
= talloc_strdup(mem_ctx
, argv
[0]);
1071 if (service
== NULL
) {
1072 d_printf(_("error: out of memory!\n"));
1076 num_includes
= argc
- 1;
1077 if (num_includes
== 0) {
1080 includes
= argv
+ 1;
1083 werr
= smbconf_set_includes(conf_ctx
, service
, num_includes
, includes
);
1084 if (!W_ERROR_IS_OK(werr
)) {
1085 d_printf(_("error setting includes: %s\n"), win_errstr(werr
));
1092 TALLOC_FREE(mem_ctx
);
1096 static int net_conf_delincludes(struct net_context
*c
,
1097 struct smbconf_ctx
*conf_ctx
,
1098 int argc
, const char **argv
)
1103 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
1105 if (argc
!= 1 || c
->display_usage
) {
1106 net_conf_delincludes_usage(c
, argc
, argv
);
1110 service
= talloc_strdup(mem_ctx
, argv
[0]);
1111 if (service
== NULL
) {
1112 d_printf(_("error: out of memory!\n"));
1116 werr
= smbconf_delete_includes(conf_ctx
, service
);
1117 if (!W_ERROR_IS_OK(werr
)) {
1118 d_printf(_("error deleting includes: %s\n"), win_errstr(werr
));
1125 TALLOC_FREE(mem_ctx
);
1130 /**********************************************************************
1132 * Wrapper and net_conf_run_function mechanism.
1134 **********************************************************************/
1137 * Wrapper function to call the main conf functions.
1138 * The wrapper calls handles opening and closing of the
1141 static int net_conf_wrap_function(struct net_context
*c
,
1142 int (*fn
)(struct net_context
*,
1143 struct smbconf_ctx
*,
1144 int, const char **),
1145 int argc
, const char **argv
)
1148 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
1149 struct smbconf_ctx
*conf_ctx
;
1152 err
= smbconf_init(mem_ctx
, &conf_ctx
, "registry:");
1153 if (!SBC_ERROR_IS_OK(err
)) {
1157 ret
= fn(c
, conf_ctx
, argc
, argv
);
1159 smbconf_shutdown(conf_ctx
);
1165 * We need a functable struct of our own, because the
1166 * functions are called through a wrapper that handles
1167 * the opening and closing of the configuration, and so on.
1169 struct conf_functable
{
1170 const char *funcname
;
1171 int (*fn
)(struct net_context
*c
, struct smbconf_ctx
*ctx
, int argc
,
1173 int valid_transports
;
1174 const char *description
;
1179 * This imitates net_run_function but calls the main functions
1180 * through the wrapper net_conf_wrap_function().
1182 static int net_conf_run_function(struct net_context
*c
, int argc
,
1183 const char **argv
, const char *whoami
,
1184 struct conf_functable
*table
)
1189 for (i
=0; table
[i
].funcname
; i
++) {
1190 if (StrCaseCmp(argv
[0], table
[i
].funcname
) == 0)
1191 return net_conf_wrap_function(c
, table
[i
].fn
,
1197 d_printf(_("Usage:\n"));
1198 for (i
=0; table
[i
].funcname
; i
++) {
1199 if (c
->display_usage
== false)
1200 d_printf("%s %-15s %s\n", whoami
, table
[i
].funcname
,
1201 table
[i
].description
);
1203 d_printf("%s\n", table
[i
].usage
);
1206 return c
->display_usage
?0:-1;
1210 * Entry-point for all the CONF functions.
1213 int net_conf(struct net_context
*c
, int argc
, const char **argv
)
1216 struct conf_functable func_table
[] = {
1220 NET_TRANSPORT_LOCAL
,
1221 N_("Dump the complete configuration in smb.conf like "
1223 N_("net conf list\n"
1224 " Dump the complete configuration in smb.conf "
1231 NET_TRANSPORT_LOCAL
,
1232 N_("Import configuration from file in smb.conf "
1234 N_("net conf import\n"
1235 " Import configuration from file in smb.conf "
1240 net_conf_listshares
,
1241 NET_TRANSPORT_LOCAL
,
1242 N_("List the share names."),
1243 N_("net conf listshares\n"
1244 " List the share names.")
1249 NET_TRANSPORT_LOCAL
,
1250 N_("Delete the complete configuration."),
1251 N_("net conf drop\n"
1252 " Delete the complete configuration.")
1257 NET_TRANSPORT_LOCAL
,
1258 N_("Show the definition of a share."),
1259 N_("net conf showshare\n"
1260 " Show the definition of a share.")
1265 NET_TRANSPORT_LOCAL
,
1266 N_("Create a new share."),
1267 N_("net conf addshare\n"
1268 " Create a new share.")
1273 NET_TRANSPORT_LOCAL
,
1274 N_("Delete a share."),
1275 N_("net conf delshare\n"
1281 NET_TRANSPORT_LOCAL
,
1282 N_("Store a parameter."),
1283 N_("net conf setparm\n"
1284 " Store a parameter.")
1289 NET_TRANSPORT_LOCAL
,
1290 N_("Retrieve the value of a parameter."),
1291 N_("net conf getparm\n"
1292 " Retrieve the value of a parameter.")
1297 NET_TRANSPORT_LOCAL
,
1298 N_("Delete a parameter."),
1299 N_("net conf delparm\n"
1300 " Delete a parameter.")
1304 net_conf_getincludes
,
1305 NET_TRANSPORT_LOCAL
,
1306 N_("Show the includes of a share definition."),
1307 N_("net conf getincludes\n"
1308 " Show the includes of a share definition.")
1312 net_conf_setincludes
,
1313 NET_TRANSPORT_LOCAL
,
1314 N_("Set includes for a share."),
1315 N_("net conf setincludes\n"
1316 " Set includes for a share.")
1320 net_conf_delincludes
,
1321 NET_TRANSPORT_LOCAL
,
1322 N_("Delete includes from a share definition."),
1323 N_("net conf setincludes\n"
1324 " Delete includes from a share definition.")
1326 {NULL
, NULL
, 0, NULL
, NULL
}
1329 ret
= net_conf_run_function(c
, argc
, argv
, "net conf", func_table
);