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
)) {
343 werr
= import_process_service(c
, conf_ctx
, service
);
344 if (!W_ERROR_IS_OK(werr
)) {
348 struct smbconf_service
**services
= NULL
;
349 uint32_t num_shares
, sidx
;
351 werr
= smbconf_get_config(txt_ctx
, mem_ctx
,
354 if (!W_ERROR_IS_OK(werr
)) {
357 if (!c
->opt_testmode
) {
358 werr
= smbconf_drop(conf_ctx
);
359 if (!W_ERROR_IS_OK(werr
)) {
365 * Wrap the importing of shares into a transaction,
366 * but only 100 at a time, in order to serve memory.
367 * The allocated memory accumulates across the actions
368 * within the transaction, and for me, some 1500
369 * imported shares, the MAX_TALLOC_SIZE of 256 MB
372 werr
= smbconf_transaction_start(conf_ctx
);
373 if (!W_ERROR_IS_OK(werr
)) {
374 d_printf("error starting transaction: %s\n",
379 for (sidx
= 0; sidx
< num_shares
; sidx
++) {
380 werr
= import_process_service(c
, conf_ctx
,
382 if (!W_ERROR_IS_OK(werr
)) {
390 werr
= smbconf_transaction_commit(conf_ctx
);
391 if (!W_ERROR_IS_OK(werr
)) {
392 d_printf("error committing transaction: %s\n",
396 werr
= smbconf_transaction_start(conf_ctx
);
397 if (!W_ERROR_IS_OK(werr
)) {
398 d_printf("error starting transaction: %s\n",
405 werr
= smbconf_transaction_commit(conf_ctx
);
406 if (!W_ERROR_IS_OK(werr
)) {
407 d_printf("error committing transaction: %s\n",
416 werr
= smbconf_transaction_cancel(conf_ctx
);
417 if (!W_ERROR_IS_OK(werr
)) {
418 d_printf("error cancelling transaction: %s\n",
423 TALLOC_FREE(mem_ctx
);
427 static int net_conf_listshares(struct net_context
*c
,
428 struct smbconf_ctx
*conf_ctx
, int argc
,
431 WERROR werr
= WERR_OK
;
433 uint32_t count
, num_shares
= 0;
434 char **share_names
= NULL
;
437 mem_ctx
= talloc_stackframe();
439 if (argc
!= 0 || c
->display_usage
) {
440 net_conf_listshares_usage(c
, argc
, argv
);
444 werr
= smbconf_get_share_names(conf_ctx
, mem_ctx
, &num_shares
,
446 if (!W_ERROR_IS_OK(werr
)) {
450 for (count
= 0; count
< num_shares
; count
++)
452 d_printf("%s\n", share_names
[count
]);
458 TALLOC_FREE(mem_ctx
);
462 static int net_conf_drop(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
463 int argc
, const char **argv
)
468 if (argc
!= 0 || c
->display_usage
) {
469 net_conf_drop_usage(c
, argc
, argv
);
473 werr
= smbconf_drop(conf_ctx
);
474 if (!W_ERROR_IS_OK(werr
)) {
475 d_fprintf(stderr
, "Error deleting configuration: %s\n",
486 static int net_conf_showshare(struct net_context
*c
,
487 struct smbconf_ctx
*conf_ctx
, int argc
,
491 WERROR werr
= WERR_OK
;
492 const char *sharename
= NULL
;
495 struct smbconf_service
*service
= NULL
;
497 mem_ctx
= talloc_stackframe();
499 if (argc
!= 1 || c
->display_usage
) {
500 net_conf_showshare_usage(c
, argc
, argv
);
504 sharename
= talloc_strdup(mem_ctx
, argv
[0]);
505 if (sharename
== NULL
) {
506 d_printf("error: out of memory!\n");
510 werr
= smbconf_get_share(conf_ctx
, mem_ctx
, sharename
, &service
);
511 if (!W_ERROR_IS_OK(werr
)) {
512 d_printf("error getting share parameters: %s\n",
517 d_printf("[%s]\n", service
->name
);
519 for (count
= 0; count
< service
->num_params
; count
++) {
520 d_printf("\t%s = %s\n", service
->param_names
[count
],
521 service
->param_values
[count
]);
527 TALLOC_FREE(mem_ctx
);
532 * Add a share, with a couple of standard parameters, partly optional.
534 * This is a high level utility function of the net conf utility,
535 * not a direct frontend to the smbconf API.
537 static int net_conf_addshare(struct net_context
*c
,
538 struct smbconf_ctx
*conf_ctx
, int argc
,
542 WERROR werr
= WERR_OK
;
543 char *sharename
= NULL
;
544 const char *path
= NULL
;
545 const char *comment
= NULL
;
546 const char *guest_ok
= "no";
547 const char *writeable
= "no";
548 SMB_STRUCT_STAT sbuf
;
549 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
551 if (c
->display_usage
) {
552 net_conf_addshare_usage(c
, argc
, argv
);
561 net_conf_addshare_usage(c
, argc
, argv
);
566 if (!strnequal(argv
[3], "guest_ok=", 9)) {
567 net_conf_addshare_usage(c
, argc
, argv
);
570 switch (argv
[3][9]) {
580 net_conf_addshare_usage(c
, argc
, argv
);
584 if (!strnequal(argv
[2], "writeable=", 10)) {
585 net_conf_addshare_usage(c
, argc
, argv
);
588 switch (argv
[2][10]) {
598 net_conf_addshare_usage(c
, argc
, argv
);
603 sharename
= talloc_strdup(mem_ctx
, argv
[0]);
604 if (sharename
== NULL
) {
605 d_printf("error: out of memory!\n");
616 /* validate share name */
618 if (!validate_net_name(sharename
, INVALID_SHARENAME_CHARS
,
621 d_fprintf(stderr
, "ERROR: share name %s contains "
622 "invalid characters (any of %s)\n",
623 sharename
, INVALID_SHARENAME_CHARS
);
627 if (strequal(sharename
, GLOBAL_NAME
)) {
629 "ERROR: 'global' is not a valid share name.\n");
633 if (smbconf_share_exists(conf_ctx
, sharename
)) {
634 d_fprintf(stderr
, "ERROR: share %s already exists.\n",
641 if (path
[0] != '/') {
643 "Error: path '%s' is not an absolute path.\n",
648 if (sys_stat(path
, &sbuf
) != 0) {
650 "ERROR: cannot stat path '%s' to ensure "
651 "this is a directory.\n"
653 path
, strerror(errno
));
657 if (!S_ISDIR(sbuf
.st_mode
)) {
659 "ERROR: path '%s' is not a directory.\n",
668 werr
= smbconf_create_share(conf_ctx
, sharename
);
669 if (!W_ERROR_IS_OK(werr
)) {
670 d_fprintf(stderr
, "Error creating share %s: %s\n",
671 sharename
, win_errstr(werr
));
676 * fill the share with parameters
679 werr
= smbconf_set_parameter(conf_ctx
, sharename
, "path", path
);
680 if (!W_ERROR_IS_OK(werr
)) {
681 d_fprintf(stderr
, "Error setting parameter %s: %s\n",
682 "path", win_errstr(werr
));
686 if (comment
!= NULL
) {
687 werr
= smbconf_set_parameter(conf_ctx
, sharename
, "comment",
689 if (!W_ERROR_IS_OK(werr
)) {
690 d_fprintf(stderr
, "Error setting parameter %s: %s\n",
691 "comment", win_errstr(werr
));
696 werr
= smbconf_set_parameter(conf_ctx
, sharename
, "guest ok", guest_ok
);
697 if (!W_ERROR_IS_OK(werr
)) {
698 d_fprintf(stderr
, "Error setting parameter %s: %s\n",
699 "'guest ok'", win_errstr(werr
));
703 werr
= smbconf_set_parameter(conf_ctx
, sharename
, "writeable",
705 if (!W_ERROR_IS_OK(werr
)) {
706 d_fprintf(stderr
, "Error setting parameter %s: %s\n",
707 "writeable", win_errstr(werr
));
714 TALLOC_FREE(mem_ctx
);
718 static int net_conf_delshare(struct net_context
*c
,
719 struct smbconf_ctx
*conf_ctx
, int argc
,
723 const char *sharename
= NULL
;
724 WERROR werr
= WERR_OK
;
725 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
727 if (argc
!= 1 || c
->display_usage
) {
728 net_conf_delshare_usage(c
, argc
, argv
);
731 sharename
= talloc_strdup(mem_ctx
, argv
[0]);
732 if (sharename
== NULL
) {
733 d_printf("error: out of memory!\n");
737 werr
= smbconf_delete_share(conf_ctx
, sharename
);
738 if (!W_ERROR_IS_OK(werr
)) {
739 d_fprintf(stderr
, "Error deleting share %s: %s\n",
740 sharename
, win_errstr(werr
));
746 TALLOC_FREE(mem_ctx
);
750 static int net_conf_setparm(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
751 int argc
, const char **argv
)
754 WERROR werr
= WERR_OK
;
755 char *service
= NULL
;
757 const char *value_str
= NULL
;
758 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
760 if (argc
!= 3 || c
->display_usage
) {
761 net_conf_setparm_usage(c
, argc
, argv
);
764 service
= talloc_strdup(mem_ctx
, argv
[0]);
765 if (service
== NULL
) {
766 d_printf("error: out of memory!\n");
769 param
= talloc_strdup_lower(mem_ctx
, argv
[1]);
771 d_printf("error: out of memory!\n");
776 if (!smbconf_share_exists(conf_ctx
, service
)) {
777 werr
= smbconf_create_share(conf_ctx
, service
);
778 if (!W_ERROR_IS_OK(werr
)) {
779 d_fprintf(stderr
, "Error creating share '%s': %s\n",
780 service
, win_errstr(werr
));
785 werr
= smbconf_set_parameter(conf_ctx
, service
, param
, value_str
);
787 if (!W_ERROR_IS_OK(werr
)) {
788 d_fprintf(stderr
, "Error setting value '%s': %s\n",
789 param
, win_errstr(werr
));
796 TALLOC_FREE(mem_ctx
);
800 static int net_conf_getparm(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
801 int argc
, const char **argv
)
804 WERROR werr
= WERR_OK
;
805 char *service
= NULL
;
810 mem_ctx
= talloc_stackframe();
812 if (argc
!= 2 || c
->display_usage
) {
813 net_conf_getparm_usage(c
, argc
, argv
);
816 service
= talloc_strdup(mem_ctx
, argv
[0]);
817 if (service
== NULL
) {
818 d_printf("error: out of memory!\n");
821 param
= talloc_strdup_lower(mem_ctx
, argv
[1]);
823 d_printf("error: out of memory!\n");
827 werr
= smbconf_get_parameter(conf_ctx
, mem_ctx
, service
, param
, &valstr
);
829 if (W_ERROR_EQUAL(werr
, WERR_NO_SUCH_SERVICE
)) {
831 "Error: given service '%s' does not exist.\n",
834 } else if (W_ERROR_EQUAL(werr
, WERR_INVALID_PARAM
)) {
836 "Error: given parameter '%s' is not set.\n",
839 } else if (!W_ERROR_IS_OK(werr
)) {
840 d_fprintf(stderr
, "Error getting value '%s': %s.\n",
841 param
, win_errstr(werr
));
845 d_printf("%s\n", valstr
);
849 TALLOC_FREE(mem_ctx
);
853 static int net_conf_delparm(struct net_context
*c
, struct smbconf_ctx
*conf_ctx
,
854 int argc
, const char **argv
)
857 WERROR werr
= WERR_OK
;
858 char *service
= NULL
;
860 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
862 if (argc
!= 2 || c
->display_usage
) {
863 net_conf_delparm_usage(c
, argc
, argv
);
866 service
= talloc_strdup(mem_ctx
, argv
[0]);
867 if (service
== NULL
) {
868 d_printf("error: out of memory!\n");
871 param
= talloc_strdup_lower(mem_ctx
, argv
[1]);
873 d_printf("error: out of memory!\n");
877 werr
= smbconf_delete_parameter(conf_ctx
, service
, param
);
879 if (W_ERROR_EQUAL(werr
, WERR_NO_SUCH_SERVICE
)) {
881 "Error: given service '%s' does not exist.\n",
884 } else if (W_ERROR_EQUAL(werr
, WERR_INVALID_PARAM
)) {
886 "Error: given parameter '%s' is not set.\n",
889 } else if (!W_ERROR_IS_OK(werr
)) {
890 d_fprintf(stderr
, "Error deleting value '%s': %s.\n",
891 param
, win_errstr(werr
));
898 TALLOC_FREE(mem_ctx
);
902 static int net_conf_getincludes(struct net_context
*c
,
903 struct smbconf_ctx
*conf_ctx
,
904 int argc
, const char **argv
)
907 uint32_t num_includes
;
910 char **includes
= NULL
;
912 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
914 if (argc
!= 1 || c
->display_usage
) {
915 net_conf_getincludes_usage(c
, argc
, argv
);
919 service
= talloc_strdup(mem_ctx
, argv
[0]);
920 if (service
== NULL
) {
921 d_printf("error: out of memory!\n");
925 werr
= smbconf_get_includes(conf_ctx
, mem_ctx
, service
,
926 &num_includes
, &includes
);
927 if (!W_ERROR_IS_OK(werr
)) {
928 d_printf("error getting includes: %s\n", win_errstr(werr
));
932 for (count
= 0; count
< num_includes
; count
++) {
933 d_printf("include = %s\n", includes
[count
]);
939 TALLOC_FREE(mem_ctx
);
943 static int net_conf_setincludes(struct net_context
*c
,
944 struct smbconf_ctx
*conf_ctx
,
945 int argc
, const char **argv
)
949 uint32_t num_includes
;
950 const char **includes
;
952 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
954 if (argc
< 1 || c
->display_usage
) {
955 net_conf_setincludes_usage(c
, argc
, argv
);
959 service
= talloc_strdup(mem_ctx
, argv
[0]);
960 if (service
== NULL
) {
961 d_printf("error: out of memory!\n");
965 num_includes
= argc
- 1;
966 if (num_includes
== 0) {
972 werr
= smbconf_set_includes(conf_ctx
, service
, num_includes
, includes
);
973 if (!W_ERROR_IS_OK(werr
)) {
974 d_printf("error setting includes: %s\n", win_errstr(werr
));
981 TALLOC_FREE(mem_ctx
);
985 static int net_conf_delincludes(struct net_context
*c
,
986 struct smbconf_ctx
*conf_ctx
,
987 int argc
, const char **argv
)
992 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
994 if (argc
!= 1 || c
->display_usage
) {
995 net_conf_delincludes_usage(c
, argc
, argv
);
999 service
= talloc_strdup(mem_ctx
, argv
[0]);
1000 if (service
== NULL
) {
1001 d_printf("error: out of memory!\n");
1005 werr
= smbconf_delete_includes(conf_ctx
, service
);
1006 if (!W_ERROR_IS_OK(werr
)) {
1007 d_printf("error deleting includes: %s\n", win_errstr(werr
));
1014 TALLOC_FREE(mem_ctx
);
1019 /**********************************************************************
1021 * Wrapper and net_conf_run_function mechanism.
1023 **********************************************************************/
1026 * Wrapper function to call the main conf functions.
1027 * The wrapper calls handles opening and closing of the
1030 static int net_conf_wrap_function(struct net_context
*c
,
1031 int (*fn
)(struct net_context
*,
1032 struct smbconf_ctx
*,
1033 int, const char **),
1034 int argc
, const char **argv
)
1037 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
1038 struct smbconf_ctx
*conf_ctx
;
1041 werr
= smbconf_init(mem_ctx
, &conf_ctx
, "registry:");
1043 if (!W_ERROR_IS_OK(werr
)) {
1047 ret
= fn(c
, conf_ctx
, argc
, argv
);
1049 smbconf_shutdown(conf_ctx
);
1055 * We need a functable struct of our own, because the
1056 * functions are called through a wrapper that handles
1057 * the opening and closing of the configuration, and so on.
1059 struct conf_functable
{
1060 const char *funcname
;
1061 int (*fn
)(struct net_context
*c
, struct smbconf_ctx
*ctx
, int argc
,
1063 int valid_transports
;
1064 const char *description
;
1069 * This imitates net_run_function but calls the main functions
1070 * through the wrapper net_conf_wrap_function().
1072 static int net_conf_run_function(struct net_context
*c
, int argc
,
1073 const char **argv
, const char *whoami
,
1074 struct conf_functable
*table
)
1079 for (i
=0; table
[i
].funcname
; i
++) {
1080 if (StrCaseCmp(argv
[0], table
[i
].funcname
) == 0)
1081 return net_conf_wrap_function(c
, table
[i
].fn
,
1087 d_printf("Usage:\n");
1088 for (i
=0; table
[i
].funcname
; i
++) {
1089 if (c
->display_usage
== false)
1090 d_printf("%s %-15s %s\n", whoami
, table
[i
].funcname
,
1091 table
[i
].description
);
1093 d_printf("%s\n", table
[i
].usage
);
1096 return c
->display_usage
?0:-1;
1100 * Entry-point for all the CONF functions.
1103 int net_conf(struct net_context
*c
, int argc
, const char **argv
)
1106 struct conf_functable func_table
[] = {
1110 NET_TRANSPORT_LOCAL
,
1111 "Dump the complete configuration in smb.conf like "
1114 " Dump the complete configuration in smb.conf like "
1121 NET_TRANSPORT_LOCAL
,
1122 "Import configuration from file in smb.conf format.",
1124 " Import configuration from file in smb.conf format."
1128 net_conf_listshares
,
1129 NET_TRANSPORT_LOCAL
,
1130 "List the share names.",
1131 "net conf listshares\n"
1132 " List the share names."
1137 NET_TRANSPORT_LOCAL
,
1138 "Delete the complete configuration.",
1140 " Delete the complete configuration."
1145 NET_TRANSPORT_LOCAL
,
1146 "Show the definition of a share.",
1147 "net conf showshare\n"
1148 " Show the definition of a share."
1153 NET_TRANSPORT_LOCAL
,
1154 "Create a new share.",
1155 "net conf addshare\n"
1156 " Create a new share."
1161 NET_TRANSPORT_LOCAL
,
1163 "net conf delshare\n"
1169 NET_TRANSPORT_LOCAL
,
1170 "Store a parameter.",
1171 "net conf setparm\n"
1172 " Store a parameter."
1177 NET_TRANSPORT_LOCAL
,
1178 "Retrieve the value of a parameter.",
1179 "net conf getparm\n"
1180 " Retrieve the value of a parameter."
1185 NET_TRANSPORT_LOCAL
,
1186 "Delete a parameter.",
1187 "net conf delparm\n"
1188 " Delete a parameter."
1192 net_conf_getincludes
,
1193 NET_TRANSPORT_LOCAL
,
1194 "Show the includes of a share definition.",
1195 "net conf getincludes\n"
1196 " Show the includes of a share definition."
1200 net_conf_setincludes
,
1201 NET_TRANSPORT_LOCAL
,
1202 "Set includes for a share.",
1203 "net conf setincludes\n"
1204 " Set includes for a share."
1208 net_conf_delincludes
,
1209 NET_TRANSPORT_LOCAL
,
1210 "Delete includes from a share definition.",
1211 "net conf setincludes\n"
1212 " Delete includes from a share definition."
1214 {NULL
, NULL
, 0, NULL
, NULL
}
1217 ret
= net_conf_run_function(c
, argc
, argv
, "net conf", func_table
);