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 sbcErr
import_process_service(struct net_context
*c
,
178 struct smbconf_ctx
*conf_ctx
,
179 struct smbconf_service
*service
)
182 sbcErr err
= SBC_ERR_OK
;
183 uint32_t num_includes
= 0;
184 char **includes
= NULL
;
185 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
187 if (c
->opt_testmode
) {
188 const char *indent
= "";
189 if (service
->name
!= NULL
) {
190 d_printf("[%s]\n", service
->name
);
193 for (idx
= 0; idx
< service
->num_params
; idx
++) {
194 d_printf("%s%s = %s\n", indent
,
195 service
->param_names
[idx
],
196 service
->param_values
[idx
]);
202 if (smbconf_share_exists(conf_ctx
, service
->name
)) {
203 err
= smbconf_delete_share(conf_ctx
, service
->name
);
204 if (!SBC_ERROR_IS_OK(err
)) {
208 err
= smbconf_create_share(conf_ctx
, service
->name
);
209 if (!SBC_ERROR_IS_OK(err
)) {
213 for (idx
= 0; idx
< service
->num_params
; idx
++) {
214 if (strequal(service
->param_names
[idx
], "include")) {
215 includes
= TALLOC_REALLOC_ARRAY(mem_ctx
,
219 if (includes
== NULL
) {
223 includes
[num_includes
] = talloc_strdup(includes
,
224 service
->param_values
[idx
]);
225 if (includes
[num_includes
] == NULL
) {
231 err
= smbconf_set_parameter(conf_ctx
,
233 service
->param_names
[idx
],
234 service
->param_values
[idx
]);
235 if (!SBC_ERROR_IS_OK(err
)) {
237 _("Error in section [%s], parameter \"%s\": %s\n"),
238 service
->name
, service
->param_names
[idx
],
239 sbcErrorString(err
));
245 err
= smbconf_set_includes(conf_ctx
, service
->name
, num_includes
,
246 (const char **)includes
);
247 if (!SBC_ERROR_IS_OK(err
)) {
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
)
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 err
= smbconf_get_config(conf_ctx
, mem_ctx
, &num_shares
, &shares
);
282 if (!SBC_ERROR_IS_OK(err
)) {
283 d_fprintf(stderr
, _("Error getting config: %s\n"),
284 sbcErrorString(err
));
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
;
324 if (c
->display_usage
)
325 return net_conf_import_usage(c
, argc
, argv
);
327 mem_ctx
= talloc_stackframe();
332 net_conf_import_usage(c
, argc
, argv
);
335 servicename
= talloc_strdup(mem_ctx
, argv
[1]);
336 if (servicename
== NULL
) {
337 d_printf(_("error: out of memory!\n"));
345 DEBUG(3,("net_conf_import: reading configuration from file %s.\n",
348 conf_source
= talloc_asprintf(mem_ctx
, "file:%s", filename
);
349 if (conf_source
== NULL
) {
350 d_printf(_("error: out of memory!\n"));
354 err
= smbconf_init(mem_ctx
, &txt_ctx
, conf_source
);
355 if (!SBC_ERROR_IS_OK(err
)) {
356 d_printf(_("error loading file '%s': %s\n"), filename
,
357 sbcErrorString(err
));
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 err
= smbconf_get_share(txt_ctx
, mem_ctx
,
372 if (!SBC_ERROR_IS_OK(err
)) {
376 err
= smbconf_transaction_start(conf_ctx
);
377 if (!SBC_ERROR_IS_OK(err
)) {
378 d_printf(_("error starting transaction: %s\n"),
379 sbcErrorString(err
));
383 err
= import_process_service(c
, conf_ctx
, service
);
384 if (!SBC_ERROR_IS_OK(err
)) {
388 struct smbconf_service
**services
= NULL
;
389 uint32_t num_shares
, sidx
;
391 err
= smbconf_get_config(txt_ctx
, mem_ctx
,
394 if (!SBC_ERROR_IS_OK(err
)) {
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 err
= smbconf_transaction_start(conf_ctx
);
412 if (!SBC_ERROR_IS_OK(err
)) {
413 d_printf(_("error starting transaction: %s\n"),
414 sbcErrorString(err
));
418 for (sidx
= 0; sidx
< num_shares
; sidx
++) {
419 err
= import_process_service(c
, conf_ctx
,
421 if (!SBC_ERROR_IS_OK(err
)) {
429 err
= smbconf_transaction_commit(conf_ctx
);
430 if (!SBC_ERROR_IS_OK(err
)) {
431 d_printf(_("error committing transaction: "
433 sbcErrorString(err
));
436 err
= smbconf_transaction_start(conf_ctx
);
437 if (!SBC_ERROR_IS_OK(err
)) {
438 d_printf(_("error starting transaction: %s\n"),
439 sbcErrorString(err
));
445 err
= smbconf_transaction_commit(conf_ctx
);
446 if (!SBC_ERROR_IS_OK(err
)) {
447 d_printf(_("error committing transaction: %s\n"),
448 sbcErrorString(err
));
456 err
= smbconf_transaction_cancel(conf_ctx
);
457 if (!SBC_ERROR_IS_OK(err
)) {
458 d_printf(_("error cancelling transaction: %s\n"),
459 sbcErrorString(err
));
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
,
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 err
= smbconf_get_share(conf_ctx
, mem_ctx
, sharename
, &service
);
551 if (!SBC_ERROR_IS_OK(err
)) {
552 d_printf(_("error getting share parameters: %s\n"),
553 sbcErrorString(err
));
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
,
583 char *sharename
= NULL
;
584 const char *path
= NULL
;
585 const char *comment
= NULL
;
586 const char *guest_ok
= "no";
587 const char *writeable
= "no";
588 SMB_STRUCT_STAT sbuf
;
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"),
688 if (sys_stat(path
, &sbuf
, false) != 0) {
690 _("ERROR: cannot stat path '%s' to ensure "
691 "this is a directory.\n"
692 "Error was '%s'.\n"),
693 path
, strerror(errno
));
697 if (!S_ISDIR(sbuf
.st_ex_mode
)) {
699 _("ERROR: path '%s' is not a directory.\n"),
705 * start a transaction
708 err
= smbconf_transaction_start(conf_ctx
);
709 if (!SBC_ERROR_IS_OK(err
)) {
710 d_printf("error starting transaction: %s\n",
711 sbcErrorString(err
));
719 err
= smbconf_create_share(conf_ctx
, sharename
);
720 if (!SBC_ERROR_IS_OK(err
)) {
721 d_fprintf(stderr
, _("Error creating share %s: %s\n"),
722 sharename
, sbcErrorString(err
));
727 * fill the share with parameters
730 err
= smbconf_set_parameter(conf_ctx
, sharename
, "path", path
);
731 if (!SBC_ERROR_IS_OK(err
)) {
732 d_fprintf(stderr
, _("Error setting parameter %s: %s\n"),
733 "path", sbcErrorString(err
));
737 if (comment
!= NULL
) {
738 err
= smbconf_set_parameter(conf_ctx
, sharename
, "comment",
740 if (!SBC_ERROR_IS_OK(err
)) {
741 d_fprintf(stderr
, _("Error setting parameter %s: %s\n"),
742 "comment", sbcErrorString(err
));
747 err
= smbconf_set_parameter(conf_ctx
, sharename
, "guest ok", guest_ok
);
748 if (!SBC_ERROR_IS_OK(err
)) {
749 d_fprintf(stderr
, _("Error setting parameter %s: %s\n"),
750 "'guest ok'", sbcErrorString(err
));
754 err
= smbconf_set_parameter(conf_ctx
, sharename
, "writeable",
756 if (!SBC_ERROR_IS_OK(err
)) {
757 d_fprintf(stderr
, _("Error setting parameter %s: %s\n"),
758 "writeable", sbcErrorString(err
));
763 * commit the whole thing
766 err
= smbconf_transaction_commit(conf_ctx
);
767 if (!SBC_ERROR_IS_OK(err
)) {
768 d_printf("error committing transaction: %s\n",
769 sbcErrorString(err
));
777 err
= smbconf_transaction_cancel(conf_ctx
);
778 if (!SBC_ERROR_IS_OK(err
)) {
779 d_printf("error cancelling transaction: %s\n",
780 sbcErrorString(err
));
784 TALLOC_FREE(mem_ctx
);
788 static int net_conf_delshare(struct net_context
*c
,
789 struct smbconf_ctx
*conf_ctx
, int argc
,
793 const char *sharename
= NULL
;
795 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
797 if (argc
!= 1 || c
->display_usage
) {
798 net_conf_delshare_usage(c
, argc
, argv
);
801 sharename
= talloc_strdup(mem_ctx
, argv
[0]);
802 if (sharename
== NULL
) {
803 d_printf(_("error: out of memory!\n"));
807 err
= smbconf_delete_share(conf_ctx
, sharename
);
808 if (!SBC_ERROR_IS_OK(err
)) {
809 d_fprintf(stderr
, _("Error deleting share %s: %s\n"),
810 sharename
, sbcErrorString(err
));
816 TALLOC_FREE(mem_ctx
);
820 static int net_conf_setparm(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
821 int argc
, const char **argv
)
825 char *service
= NULL
;
827 const char *value_str
= NULL
;
828 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
830 if (argc
!= 3 || c
->display_usage
) {
831 net_conf_setparm_usage(c
, argc
, argv
);
835 * NULL service name means "dangling parameters" to libsmbconf.
836 * We use the empty string from the command line for this purpose.
838 if (strlen(argv
[0]) != 0) {
839 service
= talloc_strdup(mem_ctx
, argv
[0]);
840 if (service
== NULL
) {
841 d_printf(_("error: out of memory!\n"));
845 param
= strlower_talloc(mem_ctx
, argv
[1]);
847 d_printf(_("error: out of memory!\n"));
852 err
= smbconf_transaction_start(conf_ctx
);
853 if (!SBC_ERROR_IS_OK(err
)) {
854 d_printf(_("error starting transaction: %s\n"),
855 sbcErrorString(err
));
859 if (!smbconf_share_exists(conf_ctx
, service
)) {
860 err
= smbconf_create_share(conf_ctx
, service
);
861 if (!SBC_ERROR_IS_OK(err
)) {
862 d_fprintf(stderr
, _("Error creating share '%s': %s\n"),
863 service
, sbcErrorString(err
));
868 err
= smbconf_set_parameter(conf_ctx
, service
, param
, value_str
);
869 if (!SBC_ERROR_IS_OK(err
)) {
870 d_fprintf(stderr
, _("Error setting value '%s': %s\n"),
871 param
, sbcErrorString(err
));
875 err
= smbconf_transaction_commit(conf_ctx
);
876 if (!SBC_ERROR_IS_OK(err
)) {
877 d_printf(_("error committing transaction: %s\n"),
878 sbcErrorString(err
));
886 err
= smbconf_transaction_cancel(conf_ctx
);
887 if (!SBC_ERROR_IS_OK(err
)) {
888 d_printf(_("error cancelling transaction: %s\n"),
889 sbcErrorString(err
));
893 TALLOC_FREE(mem_ctx
);
897 static int net_conf_getparm(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
898 int argc
, const char **argv
)
902 char *service
= NULL
;
907 mem_ctx
= talloc_stackframe();
909 if (argc
!= 2 || c
->display_usage
) {
910 net_conf_getparm_usage(c
, argc
, argv
);
914 * NULL service name means "dangling parameters" to libsmbconf.
915 * We use the empty string from the command line for this purpose.
917 if (strlen(argv
[0]) != 0) {
918 service
= talloc_strdup(mem_ctx
, argv
[0]);
919 if (service
== NULL
) {
920 d_printf(_("error: out of memory!\n"));
924 param
= strlower_talloc(mem_ctx
, argv
[1]);
926 d_printf(_("error: out of memory!\n"));
930 err
= smbconf_get_parameter(conf_ctx
, mem_ctx
, service
, param
, &valstr
);
931 if (SBC_ERROR_EQUAL(err
, SBC_ERR_NO_SUCH_SERVICE
)) {
933 _("Error: given service '%s' does not exist.\n"),
936 } else if (SBC_ERROR_EQUAL(err
, SBC_ERR_INVALID_PARAM
)) {
938 _("Error: given parameter '%s' is not set.\n"),
941 } else if (!SBC_ERROR_IS_OK(err
)) {
942 d_fprintf(stderr
, _("Error getting value '%s': %s.\n"),
943 param
, sbcErrorString(err
));
947 d_printf("%s\n", valstr
);
951 TALLOC_FREE(mem_ctx
);
955 static int net_conf_delparm(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
956 int argc
, const char **argv
)
960 char *service
= NULL
;
962 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
964 if (argc
!= 2 || c
->display_usage
) {
965 net_conf_delparm_usage(c
, argc
, argv
);
969 * NULL service name means "dangling parameters" to libsmbconf.
970 * We use the empty string from the command line for this purpose.
972 if (strlen(argv
[0]) != 0) {
973 service
= talloc_strdup(mem_ctx
, argv
[0]);
974 if (service
== NULL
) {
975 d_printf(_("error: out of memory!\n"));
979 param
= strlower_talloc(mem_ctx
, argv
[1]);
981 d_printf("error: out of memory!\n");
985 err
= smbconf_delete_parameter(conf_ctx
, service
, param
);
986 if (SBC_ERROR_EQUAL(err
, SBC_ERR_NO_SUCH_SERVICE
)) {
988 _("Error: given service '%s' does not exist.\n"),
991 } else if (SBC_ERROR_EQUAL(err
, SBC_ERR_INVALID_PARAM
)) {
993 _("Error: given parameter '%s' is not set.\n"),
996 } else if (!SBC_ERROR_IS_OK(err
)) {
997 d_fprintf(stderr
, _("Error deleting value '%s': %s.\n"),
998 param
, sbcErrorString(err
));
1005 TALLOC_FREE(mem_ctx
);
1009 static int net_conf_getincludes(struct net_context
*c
,
1010 struct smbconf_ctx
*conf_ctx
,
1011 int argc
, const char **argv
)
1014 uint32_t num_includes
;
1017 char **includes
= NULL
;
1019 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
1021 if (argc
!= 1 || c
->display_usage
) {
1022 net_conf_getincludes_usage(c
, argc
, argv
);
1026 service
= talloc_strdup(mem_ctx
, argv
[0]);
1027 if (service
== NULL
) {
1028 d_printf(_("error: out of memory!\n"));
1032 err
= smbconf_get_includes(conf_ctx
, mem_ctx
, service
,
1033 &num_includes
, &includes
);
1034 if (!SBC_ERROR_IS_OK(err
)) {
1035 d_printf(_("error getting includes: %s\n"), sbcErrorString(err
));
1039 for (count
= 0; count
< num_includes
; count
++) {
1040 d_printf("include = %s\n", includes
[count
]);
1046 TALLOC_FREE(mem_ctx
);
1050 static int net_conf_setincludes(struct net_context
*c
,
1051 struct smbconf_ctx
*conf_ctx
,
1052 int argc
, const char **argv
)
1056 uint32_t num_includes
;
1057 const char **includes
;
1059 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
1061 if (argc
< 1 || c
->display_usage
) {
1062 net_conf_setincludes_usage(c
, argc
, argv
);
1066 service
= talloc_strdup(mem_ctx
, argv
[0]);
1067 if (service
== NULL
) {
1068 d_printf(_("error: out of memory!\n"));
1072 num_includes
= argc
- 1;
1073 if (num_includes
== 0) {
1076 includes
= argv
+ 1;
1079 err
= smbconf_set_includes(conf_ctx
, service
, num_includes
, includes
);
1080 if (!SBC_ERROR_IS_OK(err
)) {
1081 d_printf(_("error setting includes: %s\n"), sbcErrorString(err
));
1088 TALLOC_FREE(mem_ctx
);
1092 static int net_conf_delincludes(struct net_context
*c
,
1093 struct smbconf_ctx
*conf_ctx
,
1094 int argc
, const char **argv
)
1099 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
1101 if (argc
!= 1 || c
->display_usage
) {
1102 net_conf_delincludes_usage(c
, argc
, argv
);
1106 service
= talloc_strdup(mem_ctx
, argv
[0]);
1107 if (service
== NULL
) {
1108 d_printf(_("error: out of memory!\n"));
1112 err
= smbconf_delete_includes(conf_ctx
, service
);
1113 if (!SBC_ERROR_IS_OK(err
)) {
1114 d_printf(_("error deleting includes: %s\n"), sbcErrorString(err
));
1121 TALLOC_FREE(mem_ctx
);
1126 /**********************************************************************
1128 * Wrapper and net_conf_run_function mechanism.
1130 **********************************************************************/
1133 * Wrapper function to call the main conf functions.
1134 * The wrapper calls handles opening and closing of the
1137 static int net_conf_wrap_function(struct net_context
*c
,
1138 int (*fn
)(struct net_context
*,
1139 struct smbconf_ctx
*,
1140 int, const char **),
1141 int argc
, const char **argv
)
1144 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
1145 struct smbconf_ctx
*conf_ctx
;
1148 err
= smbconf_init(mem_ctx
, &conf_ctx
, "registry:");
1149 if (!SBC_ERROR_IS_OK(err
)) {
1153 ret
= fn(c
, conf_ctx
, argc
, argv
);
1155 smbconf_shutdown(conf_ctx
);
1161 * We need a functable struct of our own, because the
1162 * functions are called through a wrapper that handles
1163 * the opening and closing of the configuration, and so on.
1165 struct conf_functable
{
1166 const char *funcname
;
1167 int (*fn
)(struct net_context
*c
, struct smbconf_ctx
*ctx
, int argc
,
1169 int valid_transports
;
1170 const char *description
;
1175 * This imitates net_run_function but calls the main functions
1176 * through the wrapper net_conf_wrap_function().
1178 static int net_conf_run_function(struct net_context
*c
, int argc
,
1179 const char **argv
, const char *whoami
,
1180 struct conf_functable
*table
)
1185 for (i
=0; table
[i
].funcname
; i
++) {
1186 if (strcasecmp_m(argv
[0], table
[i
].funcname
) == 0)
1187 return net_conf_wrap_function(c
, table
[i
].fn
,
1193 d_printf(_("Usage:\n"));
1194 for (i
=0; table
[i
].funcname
; i
++) {
1195 if (c
->display_usage
== false)
1196 d_printf("%s %-15s %s\n", whoami
, table
[i
].funcname
,
1197 table
[i
].description
);
1199 d_printf("%s\n", table
[i
].usage
);
1202 return c
->display_usage
?0:-1;
1206 * Entry-point for all the CONF functions.
1209 int net_conf(struct net_context
*c
, int argc
, const char **argv
)
1212 struct conf_functable func_table
[] = {
1216 NET_TRANSPORT_LOCAL
,
1217 N_("Dump the complete configuration in smb.conf like "
1219 N_("net conf list\n"
1220 " Dump the complete configuration in smb.conf "
1227 NET_TRANSPORT_LOCAL
,
1228 N_("Import configuration from file in smb.conf "
1230 N_("net conf import\n"
1231 " Import configuration from file in smb.conf "
1236 net_conf_listshares
,
1237 NET_TRANSPORT_LOCAL
,
1238 N_("List the share names."),
1239 N_("net conf listshares\n"
1240 " List the share names.")
1245 NET_TRANSPORT_LOCAL
,
1246 N_("Delete the complete configuration."),
1247 N_("net conf drop\n"
1248 " Delete the complete configuration.")
1253 NET_TRANSPORT_LOCAL
,
1254 N_("Show the definition of a share."),
1255 N_("net conf showshare\n"
1256 " Show the definition of a share.")
1261 NET_TRANSPORT_LOCAL
,
1262 N_("Create a new share."),
1263 N_("net conf addshare\n"
1264 " Create a new share.")
1269 NET_TRANSPORT_LOCAL
,
1270 N_("Delete a share."),
1271 N_("net conf delshare\n"
1277 NET_TRANSPORT_LOCAL
,
1278 N_("Store a parameter."),
1279 N_("net conf setparm\n"
1280 " Store a parameter.")
1285 NET_TRANSPORT_LOCAL
,
1286 N_("Retrieve the value of a parameter."),
1287 N_("net conf getparm\n"
1288 " Retrieve the value of a parameter.")
1293 NET_TRANSPORT_LOCAL
,
1294 N_("Delete a parameter."),
1295 N_("net conf delparm\n"
1296 " Delete a parameter.")
1300 net_conf_getincludes
,
1301 NET_TRANSPORT_LOCAL
,
1302 N_("Show the includes of a share definition."),
1303 N_("net conf getincludes\n"
1304 " Show the includes of a share definition.")
1308 net_conf_setincludes
,
1309 NET_TRANSPORT_LOCAL
,
1310 N_("Set includes for a share."),
1311 N_("net conf setincludes\n"
1312 " Set includes for a share.")
1316 net_conf_delincludes
,
1317 NET_TRANSPORT_LOCAL
,
1318 N_("Delete includes from a share definition."),
1319 N_("net conf setincludes\n"
1320 " Delete includes from a share definition.")
1322 {NULL
, NULL
, 0, NULL
, NULL
}
1325 ret
= net_conf_run_function(c
, argc
, argv
, "net conf", func_table
);