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 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
590 if (c
->display_usage
) {
591 net_conf_addshare_usage(c
, argc
, argv
);
600 net_conf_addshare_usage(c
, argc
, argv
);
605 if (!strnequal(argv
[3], "guest_ok=", 9)) {
606 net_conf_addshare_usage(c
, argc
, argv
);
609 switch (argv
[3][9]) {
619 net_conf_addshare_usage(c
, argc
, argv
);
623 if (!strnequal(argv
[2], "writeable=", 10)) {
624 net_conf_addshare_usage(c
, argc
, argv
);
627 switch (argv
[2][10]) {
637 net_conf_addshare_usage(c
, argc
, argv
);
642 sharename
= talloc_strdup(mem_ctx
, argv
[0]);
643 if (sharename
== NULL
) {
644 d_printf(_("error: out of memory!\n"));
655 /* validate share name */
657 if (!validate_net_name(sharename
, INVALID_SHARENAME_CHARS
,
660 d_fprintf(stderr
, _("ERROR: share name %s contains "
661 "invalid characters (any of %s)\n"),
662 sharename
, INVALID_SHARENAME_CHARS
);
666 if (strequal(sharename
, GLOBAL_NAME
)) {
668 _("ERROR: 'global' is not a valid share name.\n"));
672 if (smbconf_share_exists(conf_ctx
, sharename
)) {
673 d_fprintf(stderr
, _("ERROR: share %s already exists.\n"),
680 if (path
[0] != '/') {
682 _("Error: path '%s' is not an absolute path.\n"),
688 * start a transaction
691 err
= smbconf_transaction_start(conf_ctx
);
692 if (!SBC_ERROR_IS_OK(err
)) {
693 d_printf("error starting transaction: %s\n",
694 sbcErrorString(err
));
702 err
= smbconf_create_share(conf_ctx
, sharename
);
703 if (!SBC_ERROR_IS_OK(err
)) {
704 d_fprintf(stderr
, _("Error creating share %s: %s\n"),
705 sharename
, sbcErrorString(err
));
710 * fill the share with parameters
713 err
= smbconf_set_parameter(conf_ctx
, sharename
, "path", path
);
714 if (!SBC_ERROR_IS_OK(err
)) {
715 d_fprintf(stderr
, _("Error setting parameter %s: %s\n"),
716 "path", sbcErrorString(err
));
720 if (comment
!= NULL
) {
721 err
= smbconf_set_parameter(conf_ctx
, sharename
, "comment",
723 if (!SBC_ERROR_IS_OK(err
)) {
724 d_fprintf(stderr
, _("Error setting parameter %s: %s\n"),
725 "comment", sbcErrorString(err
));
730 err
= smbconf_set_parameter(conf_ctx
, sharename
, "guest ok", guest_ok
);
731 if (!SBC_ERROR_IS_OK(err
)) {
732 d_fprintf(stderr
, _("Error setting parameter %s: %s\n"),
733 "'guest ok'", sbcErrorString(err
));
737 err
= smbconf_set_parameter(conf_ctx
, sharename
, "writeable",
739 if (!SBC_ERROR_IS_OK(err
)) {
740 d_fprintf(stderr
, _("Error setting parameter %s: %s\n"),
741 "writeable", sbcErrorString(err
));
746 * commit the whole thing
749 err
= smbconf_transaction_commit(conf_ctx
);
750 if (!SBC_ERROR_IS_OK(err
)) {
751 d_printf("error committing transaction: %s\n",
752 sbcErrorString(err
));
760 err
= smbconf_transaction_cancel(conf_ctx
);
761 if (!SBC_ERROR_IS_OK(err
)) {
762 d_printf("error cancelling transaction: %s\n",
763 sbcErrorString(err
));
767 TALLOC_FREE(mem_ctx
);
771 static int net_conf_delshare(struct net_context
*c
,
772 struct smbconf_ctx
*conf_ctx
, int argc
,
776 const char *sharename
= NULL
;
778 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
780 if (argc
!= 1 || c
->display_usage
) {
781 net_conf_delshare_usage(c
, argc
, argv
);
784 sharename
= talloc_strdup(mem_ctx
, argv
[0]);
785 if (sharename
== NULL
) {
786 d_printf(_("error: out of memory!\n"));
790 err
= smbconf_delete_share(conf_ctx
, sharename
);
791 if (!SBC_ERROR_IS_OK(err
)) {
792 d_fprintf(stderr
, _("Error deleting share %s: %s\n"),
793 sharename
, sbcErrorString(err
));
799 TALLOC_FREE(mem_ctx
);
803 static int net_conf_setparm(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
804 int argc
, const char **argv
)
808 char *service
= NULL
;
810 const char *value_str
= NULL
;
811 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
813 if (argc
!= 3 || c
->display_usage
) {
814 net_conf_setparm_usage(c
, argc
, argv
);
818 * NULL service name means "dangling parameters" to libsmbconf.
819 * We use the empty string from the command line for this purpose.
821 if (strlen(argv
[0]) != 0) {
822 service
= talloc_strdup(mem_ctx
, argv
[0]);
823 if (service
== NULL
) {
824 d_printf(_("error: out of memory!\n"));
828 param
= strlower_talloc(mem_ctx
, argv
[1]);
830 d_printf(_("error: out of memory!\n"));
835 err
= smbconf_transaction_start(conf_ctx
);
836 if (!SBC_ERROR_IS_OK(err
)) {
837 d_printf(_("error starting transaction: %s\n"),
838 sbcErrorString(err
));
842 if (!smbconf_share_exists(conf_ctx
, service
)) {
843 err
= smbconf_create_share(conf_ctx
, service
);
844 if (!SBC_ERROR_IS_OK(err
)) {
845 d_fprintf(stderr
, _("Error creating share '%s': %s\n"),
846 service
, sbcErrorString(err
));
851 err
= smbconf_set_parameter(conf_ctx
, service
, param
, value_str
);
852 if (!SBC_ERROR_IS_OK(err
)) {
853 d_fprintf(stderr
, _("Error setting value '%s': %s\n"),
854 param
, sbcErrorString(err
));
858 err
= smbconf_transaction_commit(conf_ctx
);
859 if (!SBC_ERROR_IS_OK(err
)) {
860 d_printf(_("error committing transaction: %s\n"),
861 sbcErrorString(err
));
869 err
= smbconf_transaction_cancel(conf_ctx
);
870 if (!SBC_ERROR_IS_OK(err
)) {
871 d_printf(_("error cancelling transaction: %s\n"),
872 sbcErrorString(err
));
876 TALLOC_FREE(mem_ctx
);
880 static int net_conf_getparm(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
881 int argc
, const char **argv
)
885 char *service
= NULL
;
890 mem_ctx
= talloc_stackframe();
892 if (argc
!= 2 || c
->display_usage
) {
893 net_conf_getparm_usage(c
, argc
, argv
);
897 * NULL service name means "dangling parameters" to libsmbconf.
898 * We use the empty string from the command line for this purpose.
900 if (strlen(argv
[0]) != 0) {
901 service
= talloc_strdup(mem_ctx
, argv
[0]);
902 if (service
== NULL
) {
903 d_printf(_("error: out of memory!\n"));
907 param
= strlower_talloc(mem_ctx
, argv
[1]);
909 d_printf(_("error: out of memory!\n"));
913 err
= smbconf_get_parameter(conf_ctx
, mem_ctx
, service
, param
, &valstr
);
914 if (SBC_ERROR_EQUAL(err
, SBC_ERR_NO_SUCH_SERVICE
)) {
916 _("Error: given service '%s' does not exist.\n"),
919 } else if (SBC_ERROR_EQUAL(err
, SBC_ERR_INVALID_PARAM
)) {
921 _("Error: given parameter '%s' is not set.\n"),
924 } else if (!SBC_ERROR_IS_OK(err
)) {
925 d_fprintf(stderr
, _("Error getting value '%s': %s.\n"),
926 param
, sbcErrorString(err
));
930 d_printf("%s\n", valstr
);
934 TALLOC_FREE(mem_ctx
);
938 static int net_conf_delparm(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
939 int argc
, const char **argv
)
943 char *service
= NULL
;
945 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
947 if (argc
!= 2 || c
->display_usage
) {
948 net_conf_delparm_usage(c
, argc
, argv
);
952 * NULL service name means "dangling parameters" to libsmbconf.
953 * We use the empty string from the command line for this purpose.
955 if (strlen(argv
[0]) != 0) {
956 service
= talloc_strdup(mem_ctx
, argv
[0]);
957 if (service
== NULL
) {
958 d_printf(_("error: out of memory!\n"));
962 param
= strlower_talloc(mem_ctx
, argv
[1]);
964 d_printf("error: out of memory!\n");
968 err
= smbconf_delete_parameter(conf_ctx
, service
, param
);
969 if (SBC_ERROR_EQUAL(err
, SBC_ERR_NO_SUCH_SERVICE
)) {
971 _("Error: given service '%s' does not exist.\n"),
974 } else if (SBC_ERROR_EQUAL(err
, SBC_ERR_INVALID_PARAM
)) {
976 _("Error: given parameter '%s' is not set.\n"),
979 } else if (!SBC_ERROR_IS_OK(err
)) {
980 d_fprintf(stderr
, _("Error deleting value '%s': %s.\n"),
981 param
, sbcErrorString(err
));
988 TALLOC_FREE(mem_ctx
);
992 static int net_conf_getincludes(struct net_context
*c
,
993 struct smbconf_ctx
*conf_ctx
,
994 int argc
, const char **argv
)
997 uint32_t num_includes
;
1000 char **includes
= NULL
;
1002 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
1004 if (argc
!= 1 || c
->display_usage
) {
1005 net_conf_getincludes_usage(c
, argc
, argv
);
1009 service
= talloc_strdup(mem_ctx
, argv
[0]);
1010 if (service
== NULL
) {
1011 d_printf(_("error: out of memory!\n"));
1015 err
= smbconf_get_includes(conf_ctx
, mem_ctx
, service
,
1016 &num_includes
, &includes
);
1017 if (!SBC_ERROR_IS_OK(err
)) {
1018 d_printf(_("error getting includes: %s\n"), sbcErrorString(err
));
1022 for (count
= 0; count
< num_includes
; count
++) {
1023 d_printf("include = %s\n", includes
[count
]);
1029 TALLOC_FREE(mem_ctx
);
1033 static int net_conf_setincludes(struct net_context
*c
,
1034 struct smbconf_ctx
*conf_ctx
,
1035 int argc
, const char **argv
)
1039 uint32_t num_includes
;
1040 const char **includes
;
1042 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
1044 if (argc
< 1 || c
->display_usage
) {
1045 net_conf_setincludes_usage(c
, argc
, argv
);
1049 service
= talloc_strdup(mem_ctx
, argv
[0]);
1050 if (service
== NULL
) {
1051 d_printf(_("error: out of memory!\n"));
1055 num_includes
= argc
- 1;
1056 if (num_includes
== 0) {
1059 includes
= argv
+ 1;
1062 err
= smbconf_set_includes(conf_ctx
, service
, num_includes
, includes
);
1063 if (!SBC_ERROR_IS_OK(err
)) {
1064 d_printf(_("error setting includes: %s\n"), sbcErrorString(err
));
1071 TALLOC_FREE(mem_ctx
);
1075 static int net_conf_delincludes(struct net_context
*c
,
1076 struct smbconf_ctx
*conf_ctx
,
1077 int argc
, const char **argv
)
1082 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
1084 if (argc
!= 1 || c
->display_usage
) {
1085 net_conf_delincludes_usage(c
, argc
, argv
);
1089 service
= talloc_strdup(mem_ctx
, argv
[0]);
1090 if (service
== NULL
) {
1091 d_printf(_("error: out of memory!\n"));
1095 err
= smbconf_delete_includes(conf_ctx
, service
);
1096 if (!SBC_ERROR_IS_OK(err
)) {
1097 d_printf(_("error deleting includes: %s\n"), sbcErrorString(err
));
1104 TALLOC_FREE(mem_ctx
);
1109 /**********************************************************************
1111 * Wrapper and net_conf_run_function mechanism.
1113 **********************************************************************/
1116 * Wrapper function to call the main conf functions.
1117 * The wrapper calls handles opening and closing of the
1120 static int net_conf_wrap_function(struct net_context
*c
,
1121 int (*fn
)(struct net_context
*,
1122 struct smbconf_ctx
*,
1123 int, const char **),
1124 int argc
, const char **argv
)
1127 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
1128 struct smbconf_ctx
*conf_ctx
;
1131 err
= smbconf_init(mem_ctx
, &conf_ctx
, "registry:");
1132 if (!SBC_ERROR_IS_OK(err
)) {
1136 ret
= fn(c
, conf_ctx
, argc
, argv
);
1138 smbconf_shutdown(conf_ctx
);
1144 * We need a functable struct of our own, because the
1145 * functions are called through a wrapper that handles
1146 * the opening and closing of the configuration, and so on.
1148 struct conf_functable
{
1149 const char *funcname
;
1150 int (*fn
)(struct net_context
*c
, struct smbconf_ctx
*ctx
, int argc
,
1152 int valid_transports
;
1153 const char *description
;
1158 * This imitates net_run_function but calls the main functions
1159 * through the wrapper net_conf_wrap_function().
1161 static int net_conf_run_function(struct net_context
*c
, int argc
,
1162 const char **argv
, const char *whoami
,
1163 struct conf_functable
*table
)
1168 for (i
=0; table
[i
].funcname
; i
++) {
1169 if (StrCaseCmp(argv
[0], table
[i
].funcname
) == 0)
1170 return net_conf_wrap_function(c
, table
[i
].fn
,
1176 d_printf(_("Usage:\n"));
1177 for (i
=0; table
[i
].funcname
; i
++) {
1178 if (c
->display_usage
== false)
1179 d_printf("%s %-15s %s\n", whoami
, table
[i
].funcname
,
1180 table
[i
].description
);
1182 d_printf("%s\n", table
[i
].usage
);
1185 return c
->display_usage
?0:-1;
1189 * Entry-point for all the CONF functions.
1192 int net_conf(struct net_context
*c
, int argc
, const char **argv
)
1195 struct conf_functable func_table
[] = {
1199 NET_TRANSPORT_LOCAL
,
1200 N_("Dump the complete configuration in smb.conf like "
1202 N_("net conf list\n"
1203 " Dump the complete configuration in smb.conf "
1210 NET_TRANSPORT_LOCAL
,
1211 N_("Import configuration from file in smb.conf "
1213 N_("net conf import\n"
1214 " Import configuration from file in smb.conf "
1219 net_conf_listshares
,
1220 NET_TRANSPORT_LOCAL
,
1221 N_("List the share names."),
1222 N_("net conf listshares\n"
1223 " List the share names.")
1228 NET_TRANSPORT_LOCAL
,
1229 N_("Delete the complete configuration."),
1230 N_("net conf drop\n"
1231 " Delete the complete configuration.")
1236 NET_TRANSPORT_LOCAL
,
1237 N_("Show the definition of a share."),
1238 N_("net conf showshare\n"
1239 " Show the definition of a share.")
1244 NET_TRANSPORT_LOCAL
,
1245 N_("Create a new share."),
1246 N_("net conf addshare\n"
1247 " Create a new share.")
1252 NET_TRANSPORT_LOCAL
,
1253 N_("Delete a share."),
1254 N_("net conf delshare\n"
1260 NET_TRANSPORT_LOCAL
,
1261 N_("Store a parameter."),
1262 N_("net conf setparm\n"
1263 " Store a parameter.")
1268 NET_TRANSPORT_LOCAL
,
1269 N_("Retrieve the value of a parameter."),
1270 N_("net conf getparm\n"
1271 " Retrieve the value of a parameter.")
1276 NET_TRANSPORT_LOCAL
,
1277 N_("Delete a parameter."),
1278 N_("net conf delparm\n"
1279 " Delete a parameter.")
1283 net_conf_getincludes
,
1284 NET_TRANSPORT_LOCAL
,
1285 N_("Show the includes of a share definition."),
1286 N_("net conf getincludes\n"
1287 " Show the includes of a share definition.")
1291 net_conf_setincludes
,
1292 NET_TRANSPORT_LOCAL
,
1293 N_("Set includes for a share."),
1294 N_("net conf setincludes\n"
1295 " Set includes for a share.")
1299 net_conf_delincludes
,
1300 NET_TRANSPORT_LOCAL
,
1301 N_("Delete includes from a share definition."),
1302 N_("net conf setincludes\n"
1303 " Delete includes from a share definition.")
1305 {NULL
, NULL
, 0, NULL
, NULL
}
1308 ret
= net_conf_run_function(c
, argc
, argv
, "net conf", func_table
);