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 "utils/net.h"
33 /**********************************************************************
37 **********************************************************************/
39 static int net_conf_list_usage(struct net_context
*c
, int argc
,
42 d_printf("USAGE: net conf list\n");
46 static int net_conf_import_usage(struct net_context
*c
, int argc
,
49 d_printf("USAGE: net conf import [--test|-T] <filename> "
51 "\t[--test|-T] testmode - do not act, just print "
52 "what would be done\n"
53 "\t<servicename> only import service <servicename>, "
58 static int net_conf_listshares_usage(struct net_context
*c
, int argc
,
61 d_printf("USAGE: net conf listshares\n");
65 static int net_conf_drop_usage(struct net_context
*c
, int argc
,
68 d_printf("USAGE: net conf drop\n");
72 static int net_conf_showshare_usage(struct net_context
*c
, int argc
,
75 d_printf("USAGE: net conf showshare <sharename>\n");
79 static int net_conf_addshare_usage(struct net_context
*c
, int argc
,
82 d_printf("USAGE: net conf addshare <sharename> <path> "
83 "[writeable={y|N} [guest_ok={y|N} [<comment>]]\n"
84 "\t<sharename> the new share name.\n"
85 "\t<path> the path on the filesystem to export.\n"
86 "\twriteable={y|N} set \"writeable to \"yes\" or "
87 "\"no\" (default) on this share.\n"
88 "\tguest_ok={y|N} set \"guest ok\" to \"yes\" or "
89 "\"no\" (default) on this share.\n"
90 "\t<comment> optional comment for the new share.\n");
94 static int net_conf_delshare_usage(struct net_context
*c
, int argc
,
97 d_printf("USAGE: net conf delshare <sharename>\n");
101 static int net_conf_setparm_usage(struct net_context
*c
, int argc
,
104 d_printf("USAGE: net conf setparm <section> <param> <value>\n");
108 static int net_conf_getparm_usage(struct net_context
*c
, int argc
,
111 d_printf("USAGE: net conf getparm <section> <param>\n");
115 static int net_conf_delparm_usage(struct net_context
*c
, int argc
,
118 d_printf("USAGE: net conf delparm <section> <param>\n");
122 static int net_conf_getincludes_usage(struct net_context
*c
, int argc
,
125 d_printf("USAGE: net conf getincludes <section>\n");
129 static int net_conf_setincludes_usage(struct net_context
*c
, int argc
,
132 d_printf("USAGE: net conf setincludes <section> [<filename>]*\n");
136 static int net_conf_delincludes_usage(struct net_context
*c
, int argc
,
139 d_printf("USAGE: net conf delincludes <section>\n");
144 /**********************************************************************
148 **********************************************************************/
151 * This functions process a service previously loaded with libsmbconf.
153 static WERROR
import_process_service(struct net_context
*c
,
154 struct smbconf_ctx
*conf_ctx
,
155 struct smbconf_service
*service
)
158 WERROR werr
= WERR_OK
;
159 uint32_t num_includes
= 0;
160 char **includes
= NULL
;
161 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
163 if (c
->opt_testmode
) {
164 const char *indent
= "";
165 if (service
->name
!= NULL
) {
166 d_printf("[%s]\n", service
->name
);
169 for (idx
= 0; idx
< service
->num_params
; idx
++) {
170 d_printf("%s%s = %s\n", indent
,
171 service
->param_names
[idx
],
172 service
->param_values
[idx
]);
178 if (smbconf_share_exists(conf_ctx
, service
->name
)) {
179 werr
= smbconf_delete_share(conf_ctx
, service
->name
);
180 if (!W_ERROR_IS_OK(werr
)) {
184 werr
= smbconf_create_share(conf_ctx
, service
->name
);
185 if (!W_ERROR_IS_OK(werr
)) {
189 for (idx
= 0; idx
< service
->num_params
; idx
++) {
190 if (strequal(service
->param_names
[idx
], "include")) {
191 includes
= TALLOC_REALLOC_ARRAY(mem_ctx
,
195 if (includes
== NULL
) {
199 includes
[num_includes
] = talloc_strdup(includes
,
200 service
->param_values
[idx
]);
201 if (includes
[num_includes
] == NULL
) {
207 werr
= smbconf_set_parameter(conf_ctx
,
209 service
->param_names
[idx
],
210 service
->param_values
[idx
]);
211 if (!W_ERROR_IS_OK(werr
)) {
217 werr
= smbconf_set_includes(conf_ctx
, service
->name
, num_includes
,
218 (const char **)includes
);
221 TALLOC_FREE(mem_ctx
);
226 /**********************************************************************
228 * the main conf functions
230 **********************************************************************/
232 static int net_conf_list(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
233 int argc
, const char **argv
)
235 WERROR werr
= WERR_OK
;
239 uint32_t share_count
, param_count
;
240 struct smbconf_service
**shares
= NULL
;
242 mem_ctx
= talloc_stackframe();
244 if (argc
!= 0 || c
->display_usage
) {
245 net_conf_list_usage(c
, argc
, argv
);
249 werr
= smbconf_get_config(conf_ctx
, mem_ctx
, &num_shares
, &shares
);
250 if (!W_ERROR_IS_OK(werr
)) {
251 d_fprintf(stderr
, "Error getting config: %s\n",
256 for (share_count
= 0; share_count
< num_shares
; share_count
++) {
257 const char *indent
= "";
258 if (shares
[share_count
]->name
!= NULL
) {
259 d_printf("[%s]\n", shares
[share_count
]->name
);
262 for (param_count
= 0;
263 param_count
< shares
[share_count
]->num_params
;
266 d_printf("%s%s = %s\n",
268 shares
[share_count
]->param_names
[param_count
],
269 shares
[share_count
]->param_values
[param_count
]);
277 TALLOC_FREE(mem_ctx
);
281 static int net_conf_import(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
282 int argc
, const char **argv
)
285 const char *filename
= NULL
;
286 const char *servicename
= NULL
;
287 char *conf_source
= NULL
;
289 struct smbconf_ctx
*txt_ctx
;
292 if (c
->display_usage
)
293 return net_conf_import_usage(c
, argc
, argv
);
295 mem_ctx
= talloc_stackframe();
300 net_conf_import_usage(c
, argc
, argv
);
303 servicename
= talloc_strdup(mem_ctx
, argv
[1]);
304 if (servicename
== NULL
) {
305 d_printf("error: out of memory!\n");
313 DEBUG(3,("net_conf_import: reading configuration from file %s.\n",
316 conf_source
= talloc_asprintf(mem_ctx
, "file:%s", filename
);
317 if (conf_source
== NULL
) {
318 d_printf("error: out of memory!\n");
322 werr
= smbconf_init(mem_ctx
, &txt_ctx
, conf_source
);
323 if (!W_ERROR_IS_OK(werr
)) {
324 d_printf("error loading file '%s': %s\n", filename
,
329 if (c
->opt_testmode
) {
330 d_printf("\nTEST MODE - "
331 "would import the following configuration:\n\n");
334 if (servicename
!= NULL
) {
335 struct smbconf_service
*service
= NULL
;
337 werr
= smbconf_get_share(txt_ctx
, mem_ctx
,
340 if (!W_ERROR_IS_OK(werr
)) {
344 werr
= smbconf_transaction_start(conf_ctx
);
345 if (!W_ERROR_IS_OK(werr
)) {
346 d_printf("error starting transaction: %s\n",
351 werr
= import_process_service(c
, conf_ctx
, service
);
352 if (!W_ERROR_IS_OK(werr
)) {
356 struct smbconf_service
**services
= NULL
;
357 uint32_t num_shares
, sidx
;
359 werr
= smbconf_get_config(txt_ctx
, mem_ctx
,
362 if (!W_ERROR_IS_OK(werr
)) {
365 if (!c
->opt_testmode
) {
366 werr
= smbconf_drop(conf_ctx
);
367 if (!W_ERROR_IS_OK(werr
)) {
373 * Wrap the importing of shares into a transaction,
374 * but only 100 at a time, in order to serve memory.
375 * The allocated memory accumulates across the actions
376 * within the transaction, and for me, some 1500
377 * imported shares, the MAX_TALLOC_SIZE of 256 MB
380 werr
= smbconf_transaction_start(conf_ctx
);
381 if (!W_ERROR_IS_OK(werr
)) {
382 d_printf("error starting transaction: %s\n",
387 for (sidx
= 0; sidx
< num_shares
; sidx
++) {
388 werr
= import_process_service(c
, conf_ctx
,
390 if (!W_ERROR_IS_OK(werr
)) {
398 werr
= smbconf_transaction_commit(conf_ctx
);
399 if (!W_ERROR_IS_OK(werr
)) {
400 d_printf("error committing transaction: %s\n",
404 werr
= smbconf_transaction_start(conf_ctx
);
405 if (!W_ERROR_IS_OK(werr
)) {
406 d_printf("error starting transaction: %s\n",
413 werr
= smbconf_transaction_commit(conf_ctx
);
414 if (!W_ERROR_IS_OK(werr
)) {
415 d_printf("error committing transaction: %s\n",
424 werr
= smbconf_transaction_cancel(conf_ctx
);
425 if (!W_ERROR_IS_OK(werr
)) {
426 d_printf("error cancelling transaction: %s\n",
431 TALLOC_FREE(mem_ctx
);
435 static int net_conf_listshares(struct net_context
*c
,
436 struct smbconf_ctx
*conf_ctx
, int argc
,
439 WERROR werr
= WERR_OK
;
441 uint32_t count
, num_shares
= 0;
442 char **share_names
= NULL
;
445 mem_ctx
= talloc_stackframe();
447 if (argc
!= 0 || c
->display_usage
) {
448 net_conf_listshares_usage(c
, argc
, argv
);
452 werr
= smbconf_get_share_names(conf_ctx
, mem_ctx
, &num_shares
,
454 if (!W_ERROR_IS_OK(werr
)) {
458 for (count
= 0; count
< num_shares
; count
++)
460 d_printf("%s\n", share_names
[count
]);
466 TALLOC_FREE(mem_ctx
);
470 static int net_conf_drop(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
471 int argc
, const char **argv
)
476 if (argc
!= 0 || c
->display_usage
) {
477 net_conf_drop_usage(c
, argc
, argv
);
481 werr
= smbconf_drop(conf_ctx
);
482 if (!W_ERROR_IS_OK(werr
)) {
483 d_fprintf(stderr
, "Error deleting configuration: %s\n",
494 static int net_conf_showshare(struct net_context
*c
,
495 struct smbconf_ctx
*conf_ctx
, int argc
,
499 WERROR werr
= WERR_OK
;
500 const char *sharename
= NULL
;
503 struct smbconf_service
*service
= NULL
;
505 mem_ctx
= talloc_stackframe();
507 if (argc
!= 1 || c
->display_usage
) {
508 net_conf_showshare_usage(c
, argc
, argv
);
512 sharename
= talloc_strdup(mem_ctx
, argv
[0]);
513 if (sharename
== NULL
) {
514 d_printf("error: out of memory!\n");
518 werr
= smbconf_get_share(conf_ctx
, mem_ctx
, sharename
, &service
);
519 if (!W_ERROR_IS_OK(werr
)) {
520 d_printf("error getting share parameters: %s\n",
525 d_printf("[%s]\n", service
->name
);
527 for (count
= 0; count
< service
->num_params
; count
++) {
528 d_printf("\t%s = %s\n", service
->param_names
[count
],
529 service
->param_values
[count
]);
535 TALLOC_FREE(mem_ctx
);
540 * Add a share, with a couple of standard parameters, partly optional.
542 * This is a high level utility function of the net conf utility,
543 * not a direct frontend to the smbconf API.
545 static int net_conf_addshare(struct net_context
*c
,
546 struct smbconf_ctx
*conf_ctx
, int argc
,
550 WERROR werr
= WERR_OK
;
551 char *sharename
= NULL
;
552 const char *path
= NULL
;
553 const char *comment
= NULL
;
554 const char *guest_ok
= "no";
555 const char *writeable
= "no";
556 SMB_STRUCT_STAT sbuf
;
557 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
559 if (c
->display_usage
) {
560 net_conf_addshare_usage(c
, argc
, argv
);
569 net_conf_addshare_usage(c
, argc
, argv
);
574 if (!strnequal(argv
[3], "guest_ok=", 9)) {
575 net_conf_addshare_usage(c
, argc
, argv
);
578 switch (argv
[3][9]) {
588 net_conf_addshare_usage(c
, argc
, argv
);
592 if (!strnequal(argv
[2], "writeable=", 10)) {
593 net_conf_addshare_usage(c
, argc
, argv
);
596 switch (argv
[2][10]) {
606 net_conf_addshare_usage(c
, argc
, argv
);
611 sharename
= talloc_strdup(mem_ctx
, argv
[0]);
612 if (sharename
== NULL
) {
613 d_printf("error: out of memory!\n");
624 /* validate share name */
626 if (!validate_net_name(sharename
, INVALID_SHARENAME_CHARS
,
629 d_fprintf(stderr
, "ERROR: share name %s contains "
630 "invalid characters (any of %s)\n",
631 sharename
, INVALID_SHARENAME_CHARS
);
635 if (strequal(sharename
, GLOBAL_NAME
)) {
637 "ERROR: 'global' is not a valid share name.\n");
641 if (smbconf_share_exists(conf_ctx
, sharename
)) {
642 d_fprintf(stderr
, "ERROR: share %s already exists.\n",
649 if (path
[0] != '/') {
651 "Error: path '%s' is not an absolute path.\n",
656 if (sys_stat(path
, &sbuf
) != 0) {
658 "ERROR: cannot stat path '%s' to ensure "
659 "this is a directory.\n"
661 path
, strerror(errno
));
665 if (!S_ISDIR(sbuf
.st_mode
)) {
667 "ERROR: path '%s' is not a directory.\n",
676 werr
= smbconf_create_share(conf_ctx
, sharename
);
677 if (!W_ERROR_IS_OK(werr
)) {
678 d_fprintf(stderr
, "Error creating share %s: %s\n",
679 sharename
, win_errstr(werr
));
684 * fill the share with parameters
687 werr
= smbconf_set_parameter(conf_ctx
, sharename
, "path", path
);
688 if (!W_ERROR_IS_OK(werr
)) {
689 d_fprintf(stderr
, "Error setting parameter %s: %s\n",
690 "path", win_errstr(werr
));
694 if (comment
!= NULL
) {
695 werr
= smbconf_set_parameter(conf_ctx
, sharename
, "comment",
697 if (!W_ERROR_IS_OK(werr
)) {
698 d_fprintf(stderr
, "Error setting parameter %s: %s\n",
699 "comment", win_errstr(werr
));
704 werr
= smbconf_set_parameter(conf_ctx
, sharename
, "guest ok", guest_ok
);
705 if (!W_ERROR_IS_OK(werr
)) {
706 d_fprintf(stderr
, "Error setting parameter %s: %s\n",
707 "'guest ok'", win_errstr(werr
));
711 werr
= smbconf_set_parameter(conf_ctx
, sharename
, "writeable",
713 if (!W_ERROR_IS_OK(werr
)) {
714 d_fprintf(stderr
, "Error setting parameter %s: %s\n",
715 "writeable", win_errstr(werr
));
722 TALLOC_FREE(mem_ctx
);
726 static int net_conf_delshare(struct net_context
*c
,
727 struct smbconf_ctx
*conf_ctx
, int argc
,
731 const char *sharename
= NULL
;
732 WERROR werr
= WERR_OK
;
733 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
735 if (argc
!= 1 || c
->display_usage
) {
736 net_conf_delshare_usage(c
, argc
, argv
);
739 sharename
= talloc_strdup(mem_ctx
, argv
[0]);
740 if (sharename
== NULL
) {
741 d_printf("error: out of memory!\n");
745 werr
= smbconf_delete_share(conf_ctx
, sharename
);
746 if (!W_ERROR_IS_OK(werr
)) {
747 d_fprintf(stderr
, "Error deleting share %s: %s\n",
748 sharename
, win_errstr(werr
));
754 TALLOC_FREE(mem_ctx
);
758 static int net_conf_setparm(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
759 int argc
, const char **argv
)
762 WERROR werr
= WERR_OK
;
763 char *service
= NULL
;
765 const char *value_str
= NULL
;
766 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
768 if (argc
!= 3 || c
->display_usage
) {
769 net_conf_setparm_usage(c
, argc
, argv
);
773 * NULL service name means "dangling parameters" to libsmbconf.
774 * We use the empty string from the command line for this purpose.
776 if (strlen(argv
[0]) != 0) {
777 service
= talloc_strdup(mem_ctx
, argv
[0]);
778 if (service
== NULL
) {
779 d_printf("error: out of memory!\n");
783 param
= strlower_talloc(mem_ctx
, argv
[1]);
785 d_printf("error: out of memory!\n");
790 if (!smbconf_share_exists(conf_ctx
, service
)) {
791 werr
= smbconf_create_share(conf_ctx
, service
);
792 if (!W_ERROR_IS_OK(werr
)) {
793 d_fprintf(stderr
, "Error creating share '%s': %s\n",
794 service
, win_errstr(werr
));
799 werr
= smbconf_set_parameter(conf_ctx
, service
, param
, value_str
);
801 if (!W_ERROR_IS_OK(werr
)) {
802 d_fprintf(stderr
, "Error setting value '%s': %s\n",
803 param
, win_errstr(werr
));
810 TALLOC_FREE(mem_ctx
);
814 static int net_conf_getparm(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
815 int argc
, const char **argv
)
818 WERROR werr
= WERR_OK
;
819 char *service
= NULL
;
824 mem_ctx
= talloc_stackframe();
826 if (argc
!= 2 || c
->display_usage
) {
827 net_conf_getparm_usage(c
, argc
, argv
);
831 * NULL service name means "dangling parameters" to libsmbconf.
832 * We use the empty string from the command line for this purpose.
834 if (strlen(argv
[0]) != 0) {
835 service
= talloc_strdup(mem_ctx
, argv
[0]);
836 if (service
== NULL
) {
837 d_printf("error: out of memory!\n");
841 param
= strlower_talloc(mem_ctx
, argv
[1]);
843 d_printf("error: out of memory!\n");
847 werr
= smbconf_get_parameter(conf_ctx
, mem_ctx
, service
, param
, &valstr
);
849 if (W_ERROR_EQUAL(werr
, WERR_NO_SUCH_SERVICE
)) {
851 "Error: given service '%s' does not exist.\n",
854 } else if (W_ERROR_EQUAL(werr
, WERR_INVALID_PARAM
)) {
856 "Error: given parameter '%s' is not set.\n",
859 } else if (!W_ERROR_IS_OK(werr
)) {
860 d_fprintf(stderr
, "Error getting value '%s': %s.\n",
861 param
, win_errstr(werr
));
865 d_printf("%s\n", valstr
);
869 TALLOC_FREE(mem_ctx
);
873 static int net_conf_delparm(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
874 int argc
, const char **argv
)
877 WERROR werr
= WERR_OK
;
878 char *service
= NULL
;
880 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
882 if (argc
!= 2 || c
->display_usage
) {
883 net_conf_delparm_usage(c
, argc
, argv
);
887 * NULL service name means "dangling parameters" to libsmbconf.
888 * We use the empty string from the command line for this purpose.
890 if (strlen(argv
[0]) != 0) {
891 service
= talloc_strdup(mem_ctx
, argv
[0]);
892 if (service
== NULL
) {
893 d_printf("error: out of memory!\n");
897 param
= strlower_talloc(mem_ctx
, argv
[1]);
899 d_printf("error: out of memory!\n");
903 werr
= smbconf_delete_parameter(conf_ctx
, service
, param
);
905 if (W_ERROR_EQUAL(werr
, WERR_NO_SUCH_SERVICE
)) {
907 "Error: given service '%s' does not exist.\n",
910 } else if (W_ERROR_EQUAL(werr
, WERR_INVALID_PARAM
)) {
912 "Error: given parameter '%s' is not set.\n",
915 } else if (!W_ERROR_IS_OK(werr
)) {
916 d_fprintf(stderr
, "Error deleting value '%s': %s.\n",
917 param
, win_errstr(werr
));
924 TALLOC_FREE(mem_ctx
);
928 static int net_conf_getincludes(struct net_context
*c
,
929 struct smbconf_ctx
*conf_ctx
,
930 int argc
, const char **argv
)
933 uint32_t num_includes
;
936 char **includes
= NULL
;
938 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
940 if (argc
!= 1 || c
->display_usage
) {
941 net_conf_getincludes_usage(c
, argc
, argv
);
945 service
= talloc_strdup(mem_ctx
, argv
[0]);
946 if (service
== NULL
) {
947 d_printf("error: out of memory!\n");
951 werr
= smbconf_get_includes(conf_ctx
, mem_ctx
, service
,
952 &num_includes
, &includes
);
953 if (!W_ERROR_IS_OK(werr
)) {
954 d_printf("error getting includes: %s\n", win_errstr(werr
));
958 for (count
= 0; count
< num_includes
; count
++) {
959 d_printf("include = %s\n", includes
[count
]);
965 TALLOC_FREE(mem_ctx
);
969 static int net_conf_setincludes(struct net_context
*c
,
970 struct smbconf_ctx
*conf_ctx
,
971 int argc
, const char **argv
)
975 uint32_t num_includes
;
976 const char **includes
;
978 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
980 if (argc
< 1 || c
->display_usage
) {
981 net_conf_setincludes_usage(c
, argc
, argv
);
985 service
= talloc_strdup(mem_ctx
, argv
[0]);
986 if (service
== NULL
) {
987 d_printf("error: out of memory!\n");
991 num_includes
= argc
- 1;
992 if (num_includes
== 0) {
998 werr
= smbconf_set_includes(conf_ctx
, service
, num_includes
, includes
);
999 if (!W_ERROR_IS_OK(werr
)) {
1000 d_printf("error setting includes: %s\n", win_errstr(werr
));
1007 TALLOC_FREE(mem_ctx
);
1011 static int net_conf_delincludes(struct net_context
*c
,
1012 struct smbconf_ctx
*conf_ctx
,
1013 int argc
, const char **argv
)
1018 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
1020 if (argc
!= 1 || c
->display_usage
) {
1021 net_conf_delincludes_usage(c
, argc
, argv
);
1025 service
= talloc_strdup(mem_ctx
, argv
[0]);
1026 if (service
== NULL
) {
1027 d_printf("error: out of memory!\n");
1031 werr
= smbconf_delete_includes(conf_ctx
, service
);
1032 if (!W_ERROR_IS_OK(werr
)) {
1033 d_printf("error deleting includes: %s\n", win_errstr(werr
));
1040 TALLOC_FREE(mem_ctx
);
1045 /**********************************************************************
1047 * Wrapper and net_conf_run_function mechanism.
1049 **********************************************************************/
1052 * Wrapper function to call the main conf functions.
1053 * The wrapper calls handles opening and closing of the
1056 static int net_conf_wrap_function(struct net_context
*c
,
1057 int (*fn
)(struct net_context
*,
1058 struct smbconf_ctx
*,
1059 int, const char **),
1060 int argc
, const char **argv
)
1063 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
1064 struct smbconf_ctx
*conf_ctx
;
1067 werr
= smbconf_init(mem_ctx
, &conf_ctx
, "registry:");
1069 if (!W_ERROR_IS_OK(werr
)) {
1073 ret
= fn(c
, conf_ctx
, argc
, argv
);
1075 smbconf_shutdown(conf_ctx
);
1081 * We need a functable struct of our own, because the
1082 * functions are called through a wrapper that handles
1083 * the opening and closing of the configuration, and so on.
1085 struct conf_functable
{
1086 const char *funcname
;
1087 int (*fn
)(struct net_context
*c
, struct smbconf_ctx
*ctx
, int argc
,
1089 int valid_transports
;
1090 const char *description
;
1095 * This imitates net_run_function but calls the main functions
1096 * through the wrapper net_conf_wrap_function().
1098 static int net_conf_run_function(struct net_context
*c
, int argc
,
1099 const char **argv
, const char *whoami
,
1100 struct conf_functable
*table
)
1105 for (i
=0; table
[i
].funcname
; i
++) {
1106 if (StrCaseCmp(argv
[0], table
[i
].funcname
) == 0)
1107 return net_conf_wrap_function(c
, table
[i
].fn
,
1113 d_printf("Usage:\n");
1114 for (i
=0; table
[i
].funcname
; i
++) {
1115 if (c
->display_usage
== false)
1116 d_printf("%s %-15s %s\n", whoami
, table
[i
].funcname
,
1117 table
[i
].description
);
1119 d_printf("%s\n", table
[i
].usage
);
1122 return c
->display_usage
?0:-1;
1126 * Entry-point for all the CONF functions.
1129 int net_conf(struct net_context
*c
, int argc
, const char **argv
)
1132 struct conf_functable func_table
[] = {
1136 NET_TRANSPORT_LOCAL
,
1137 "Dump the complete configuration in smb.conf like "
1140 " Dump the complete configuration in smb.conf like "
1147 NET_TRANSPORT_LOCAL
,
1148 "Import configuration from file in smb.conf format.",
1150 " Import configuration from file in smb.conf format."
1154 net_conf_listshares
,
1155 NET_TRANSPORT_LOCAL
,
1156 "List the share names.",
1157 "net conf listshares\n"
1158 " List the share names."
1163 NET_TRANSPORT_LOCAL
,
1164 "Delete the complete configuration.",
1166 " Delete the complete configuration."
1171 NET_TRANSPORT_LOCAL
,
1172 "Show the definition of a share.",
1173 "net conf showshare\n"
1174 " Show the definition of a share."
1179 NET_TRANSPORT_LOCAL
,
1180 "Create a new share.",
1181 "net conf addshare\n"
1182 " Create a new share."
1187 NET_TRANSPORT_LOCAL
,
1189 "net conf delshare\n"
1195 NET_TRANSPORT_LOCAL
,
1196 "Store a parameter.",
1197 "net conf setparm\n"
1198 " Store a parameter."
1203 NET_TRANSPORT_LOCAL
,
1204 "Retrieve the value of a parameter.",
1205 "net conf getparm\n"
1206 " Retrieve the value of a parameter."
1211 NET_TRANSPORT_LOCAL
,
1212 "Delete a parameter.",
1213 "net conf delparm\n"
1214 " Delete a parameter."
1218 net_conf_getincludes
,
1219 NET_TRANSPORT_LOCAL
,
1220 "Show the includes of a share definition.",
1221 "net conf getincludes\n"
1222 " Show the includes of a share definition."
1226 net_conf_setincludes
,
1227 NET_TRANSPORT_LOCAL
,
1228 "Set includes for a share.",
1229 "net conf setincludes\n"
1230 " Set includes for a share."
1234 net_conf_delincludes
,
1235 NET_TRANSPORT_LOCAL
,
1236 "Delete includes from a share definition.",
1237 "net conf setincludes\n"
1238 " Delete includes from a share definition."
1240 {NULL
, NULL
, 0, NULL
, NULL
}
1243 ret
= net_conf_run_function(c
, argc
, argv
, "net conf", func_table
);