2 * Samba Unix/Linux SMB client library
3 * Distributed SMB/CIFS Server Management Utility
4 * Local configuration interface
5 * Copyright (C) Michael Adam 2007
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 2 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, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 * This is an interface to the configuration stored inside the
24 * samba registry. In the future there might be support for other
25 * configuration backends as well.
29 #include "utils/net.h"
35 static int net_conf_list_usage(int argc
, const char **argv
)
37 d_printf("USAGE: net conf list\n");
41 static int net_conf_import_usage(int argc
, const char**argv
)
43 d_printf("USAGE: net conf import [--test|-T] <filename> [<servicename>]\n"
44 "\t[--test|-T] testmode - do not act, just print "
45 "what would be done\n"
46 "\t<servicename> only import service <servicename>, "
51 static int net_conf_listshares_usage(int argc
, const char **argv
)
53 d_printf("USAGE: net conf listshares\n");
57 static int net_conf_drop_usage(int argc
, const char **argv
)
59 d_printf("USAGE: net conf drop\n");
63 static int net_conf_showshare_usage(int argc
, const char **argv
)
65 d_printf("USAGE: net conf showshare <sharename>\n");
69 static int net_conf_addshare_usage(int argc
, const char **argv
)
71 d_printf("USAGE: net conf addshare <sharename> <path> "
72 "[writeable={y|N} [guest_ok={y|N} [<comment>]]\n"
73 "\t<sharename> the new share name.\n"
74 "\t<path> the path on the filesystem to export.\n"
75 "\twriteable={y|N} set \"writeable to \"yes\" or "
76 "\"no\" (default) on this share.\n"
77 "\tguest_ok={y|N} set \"guest ok\" to \"yes\" or "
78 "\"no\" (default) on this share.\n"
79 "\t<comment> optional comment for the new share.\n");
83 static int net_conf_delshare_usage(int argc
, const char **argv
)
85 d_printf("USAGE: net conf delshare <sharename>\n");
89 static int net_conf_setparm_usage(int argc
, const char **argv
)
91 d_printf("USAGE: net conf setparm <section> <param> <value>\n");
95 static int net_conf_getparm_usage(int argc
, const char **argv
)
97 d_printf("USAGE: net conf getparm <section> <param>\n");
101 static int net_conf_delparm_usage(int argc
, const char **argv
)
103 d_printf("USAGE: net conf delparm <section> <param>\n");
112 static char *format_value(TALLOC_CTX
*mem_ctx
, struct registry_value
*value
)
116 /* what if mem_ctx = NULL? */
118 switch (value
->type
) {
120 result
= talloc_asprintf(mem_ctx
, "%d", value
->v
.dword
);
124 result
= talloc_asprintf(mem_ctx
, "%s", value
->v
.sz
.str
);
128 for (j
= 0; j
< value
->v
.multi_sz
.num_strings
; j
++) {
129 result
= talloc_asprintf(mem_ctx
, "\"%s\" ",
130 value
->v
.multi_sz
.strings
[j
]);
135 result
= talloc_asprintf(mem_ctx
, "binary (%d bytes)",
136 (int)value
->v
.binary
.length
);
139 result
= talloc_asprintf(mem_ctx
, "<unprintable>");
146 * add a value to a key.
148 static WERROR
reg_setvalue_internal(struct registry_key
*key
,
153 struct registry_value val
;
154 WERROR werr
= WERR_OK
;
158 if (strequal(valtype
, "dword")) {
159 val
.type
= REG_DWORD
;
160 val
.v
.dword
= strtoul(valstr
, NULL
, 10);
162 else if (strequal(valtype
, "sz")) {
164 val
.v
.sz
.str
= CONST_DISCARD(char *, valstr
);
165 val
.v
.sz
.len
= strlen(valstr
) + 1;
168 d_fprintf(stderr
, "Only value types DWORD and SZ are"
169 "currently implemented for setting values.\n");
170 werr
= WERR_INVALID_PARAM
;
174 if (!lp_parameter_is_valid(valname
)) {
175 d_fprintf(stderr
, "Invalid parameter '%s' given.\n", valname
);
176 werr
= WERR_INVALID_PARAM
;
180 if (registry_smbconf_valname_forbidden(valname
)) {
181 d_fprintf(stderr
, "Parameter '%s' not allowed in registry.\n",
183 werr
= WERR_INVALID_PARAM
;
187 if (!strequal(key
->key
->name
, GLOBAL_NAME
) &&
188 lp_parameter_is_global(valname
))
190 d_fprintf(stderr
, "Global paramter '%s' not allowed in "
191 "service definition.\n", valname
);
192 werr
= WERR_INVALID_PARAM
;
196 werr
= reg_setvalue(key
, valname
, &val
);
197 if (!W_ERROR_IS_OK(werr
)) {
199 "Error adding value '%s' to "
201 valname
, key
->key
->name
, dos_errstr(werr
));
209 * Open a subkey of KEY_SMBCONF (i.e a service)
210 * - variant without error output (q = quiet)-
212 static WERROR
smbconf_open_path_q(TALLOC_CTX
*ctx
, const char *subkeyname
,
213 uint32 desired_access
,
214 struct registry_key
**key
)
216 WERROR werr
= WERR_OK
;
218 NT_USER_TOKEN
*token
;
220 if (!(token
= registry_create_admin_token(ctx
))) {
221 DEBUG(1, ("Error creating admin token\n"));
225 if (subkeyname
== NULL
) {
226 path
= talloc_strdup(ctx
, KEY_SMBCONF
);
229 path
= talloc_asprintf(ctx
, "%s\\%s", KEY_SMBCONF
, subkeyname
);
232 werr
= reg_open_path(ctx
, path
, desired_access
,
241 * Open a subkey of KEY_SMBCONF (i.e a service)
242 * - variant with error output -
244 static WERROR
smbconf_open_path(TALLOC_CTX
*ctx
, const char *subkeyname
,
245 uint32 desired_access
,
246 struct registry_key
**key
)
248 WERROR werr
= WERR_OK
;
250 werr
= smbconf_open_path_q(ctx
, subkeyname
, desired_access
, key
);
251 if (!W_ERROR_IS_OK(werr
)) {
252 d_fprintf(stderr
, "Error opening registry path '%s\\%s': %s\n",
254 (subkeyname
== NULL
) ? "" : subkeyname
,
262 * open the base key KEY_SMBCONF
264 static WERROR
smbconf_open_basepath(TALLOC_CTX
*ctx
, uint32 desired_access
,
265 struct registry_key
**key
)
267 return smbconf_open_path(ctx
, NULL
, desired_access
, key
);
271 * delete a subkey of KEY_SMBCONF
273 static WERROR
reg_delkey_internal(TALLOC_CTX
*ctx
, const char *keyname
)
275 WERROR werr
= WERR_OK
;
276 struct registry_key
*key
= NULL
;
278 werr
= smbconf_open_basepath(ctx
, REG_KEY_WRITE
, &key
);
279 if (!W_ERROR_IS_OK(werr
)) {
283 werr
= reg_deletekey_recursive(key
, key
, keyname
);
284 if (!W_ERROR_IS_OK(werr
)) {
285 d_fprintf(stderr
, "Error deleting registry key %s\\%s: %s\n",
286 KEY_SMBCONF
, keyname
, dos_errstr(werr
));
295 * create a subkey of KEY_SMBCONF
297 static WERROR
reg_createkey_internal(TALLOC_CTX
*ctx
,
298 const char * subkeyname
,
299 struct registry_key
**newkey
)
301 WERROR werr
= WERR_OK
;
302 struct registry_key
*create_parent
= NULL
;
303 TALLOC_CTX
*create_ctx
;
304 enum winreg_CreateAction action
= REG_ACTION_NONE
;
306 /* create a new talloc ctx for creation. it will hold
307 * the intermediate parent key (SMBCONF) for creation
308 * and will be destroyed when leaving this function... */
309 if (!(create_ctx
= talloc_new(ctx
))) {
314 werr
= smbconf_open_basepath(create_ctx
, REG_KEY_WRITE
, &create_parent
);
315 if (!W_ERROR_IS_OK(werr
)) {
319 werr
= reg_createkey(ctx
, create_parent
, subkeyname
,
320 REG_KEY_WRITE
, newkey
, &action
);
321 if (W_ERROR_IS_OK(werr
) && (action
!= REG_CREATED_NEW_KEY
)) {
322 d_fprintf(stderr
, "Key '%s' already exists.\n", subkeyname
);
323 werr
= WERR_ALREADY_EXISTS
;
325 if (!W_ERROR_IS_OK(werr
)) {
326 d_fprintf(stderr
, "Error creating key %s: %s\n",
327 subkeyname
, dos_errstr(werr
));
331 TALLOC_FREE(create_ctx
);
336 * check if a subkey of KEY_SMBCONF of a given name exists
338 static BOOL
smbconf_key_exists(TALLOC_CTX
*ctx
, const char *subkeyname
)
341 WERROR werr
= WERR_OK
;
343 struct registry_key
*key
;
345 if (!(mem_ctx
= talloc_new(ctx
))) {
346 d_fprintf(stderr
, "ERROR: Out of memory...!\n");
350 werr
= smbconf_open_path_q(mem_ctx
, subkeyname
, REG_KEY_READ
, &key
);
351 if (W_ERROR_IS_OK(werr
)) {
356 TALLOC_FREE(mem_ctx
);
360 static BOOL
smbconf_value_exists(TALLOC_CTX
*ctx
, struct registry_key
*key
,
364 WERROR werr
= WERR_OK
;
365 struct registry_value
*value
= NULL
;
367 werr
= reg_queryvalue(ctx
, key
, param
, &value
);
368 if (W_ERROR_IS_OK(werr
)) {
376 static WERROR
list_values(TALLOC_CTX
*ctx
, struct registry_key
*key
)
378 WERROR werr
= WERR_OK
;
380 struct registry_value
*valvalue
= NULL
;
381 char *valname
= NULL
;
384 W_ERROR_IS_OK(werr
= reg_enumvalue(ctx
, key
, idx
, &valname
,
388 d_printf("\t%s = %s\n", valname
, format_value(ctx
, valvalue
));
390 if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS
, werr
)) {
391 d_fprintf(stderr
, "Error enumerating values: %s\n",
401 static WERROR
drop_smbconf_internal(TALLOC_CTX
*ctx
)
404 WERROR werr
= WERR_OK
;
405 NT_USER_TOKEN
*token
;
406 struct registry_key
*parent_key
= NULL
;
407 struct registry_key
*new_key
= NULL
;
408 TALLOC_CTX
* tmp_ctx
= NULL
;
409 enum winreg_CreateAction action
;
411 tmp_ctx
= talloc_new(ctx
);
412 if (tmp_ctx
== NULL
) {
417 if (!(token
= registry_create_admin_token(tmp_ctx
))) {
418 /* what is the appropriate error code here? */
419 werr
= WERR_CAN_NOT_COMPLETE
;
423 path
= talloc_strdup(tmp_ctx
, KEY_SMBCONF
);
425 d_fprintf(stderr
, "ERROR: out of memory!\n");
429 p
= strrchr(path
, '\\');
431 werr
= reg_open_path(tmp_ctx
, path
, REG_KEY_WRITE
, token
, &parent_key
);
433 if (!W_ERROR_IS_OK(werr
)) {
437 werr
= reg_deletekey_recursive(tmp_ctx
, parent_key
, p
+1);
439 if (!W_ERROR_IS_OK(werr
)) {
443 werr
= reg_createkey(tmp_ctx
, parent_key
, p
+1, REG_KEY_WRITE
,
447 TALLOC_FREE(tmp_ctx
);
451 static int import_process_service(TALLOC_CTX
*ctx
,
452 struct share_params
*share
)
455 struct parm_struct
*parm
;
457 const char *servicename
;
458 struct registry_key
*key
;
460 const char *valtype
= NULL
;
463 servicename
= (share
->service
== GLOBAL_SECTION_SNUM
)?
464 GLOBAL_NAME
: lp_servicename(share
->service
);
467 d_printf("[%s]\n", servicename
);
470 if (smbconf_key_exists(ctx
, servicename
)) {
471 werr
= reg_delkey_internal(ctx
, servicename
);
472 if (!W_ERROR_IS_OK(werr
)) {
476 werr
= reg_createkey_internal(ctx
, servicename
, &key
);
477 if (!W_ERROR_IS_OK(werr
)) {
482 while ((parm
= lp_next_parameter(share
->service
, &pnum
, 0)))
484 void *ptr
= parm
->ptr
;
487 if ((share
->service
< 0 && parm
->p_class
== P_LOCAL
)
488 && !(parm
->flags
& FLAG_GLOBAL
))
491 if (parm
->p_class
== P_LOCAL
&& share
->service
>= 0) {
492 ptr
= lp_local_ptr(share
->service
, ptr
);
497 switch (parm
->type
) {
499 valstr
= talloc_asprintf(ctx
, "%c", *(char *)ptr
);
503 valstr
= talloc_asprintf(ctx
, "%s", *(char **)ptr
);
507 valstr
= talloc_asprintf(ctx
, "%s", (char *)ptr
);
510 valstr
= talloc_asprintf(ctx
, "%s",
511 BOOLSTR(*(BOOL
*)ptr
));
514 valstr
= talloc_asprintf(ctx
, "%s",
515 BOOLSTR(!*(BOOL
*)ptr
));
518 for (i
= 0; parm
->enum_list
[i
].name
; i
++) {
520 parm
->enum_list
[i
].value
)
522 valstr
= talloc_asprintf(ctx
, "%s",
523 parm
->enum_list
[i
].name
);
529 talloc_asprintf(ctx
, "%s", octal_string(*(int *)ptr
));
532 valstr
= talloc_strdup(ctx
, "");
533 if ((char ***)ptr
&& *(char ***)ptr
) {
534 char **list
= *(char ***)ptr
;
535 for (; *list
; list
++) {
536 /* surround strings with whitespace
537 * in double quotes */
538 if (strchr_m(*list
, ' '))
540 valstr
= talloc_asprintf_append(
543 ((*(list
+1))?", ":""));
546 valstr
= talloc_asprintf_append(
547 valstr
, "%s%s", *list
,
548 ((*(list
+1))?", ":""));
555 talloc_asprintf(ctx
, "%d", *(int *)ptr
);
560 valstr
= talloc_asprintf(ctx
, "<type unimplemented>\n");
564 if (parm
->type
!= P_SEP
) {
566 d_printf("\t%s = %s\n", parm
->label
, valstr
);
569 werr
= reg_setvalue_internal(key
, parm
->label
,
571 if (!W_ERROR_IS_OK(werr
)) {
592 int net_conf_list(int argc
, const char **argv
)
594 WERROR werr
= WERR_OK
;
597 struct registry_key
*base_key
= NULL
;
598 struct registry_key
*sub_key
= NULL
;
600 char *subkey_name
= NULL
;
602 ctx
= talloc_init("list");
605 net_conf_list_usage(argc
, argv
);
609 werr
= smbconf_open_basepath(ctx
, REG_KEY_READ
, &base_key
);
610 if (!W_ERROR_IS_OK(werr
)) {
614 if (smbconf_key_exists(ctx
, GLOBAL_NAME
)) {
615 werr
= reg_openkey(ctx
, base_key
, GLOBAL_NAME
,
616 REG_KEY_READ
, &sub_key
);
617 if (!W_ERROR_IS_OK(werr
)) {
618 d_fprintf(stderr
, "Error opening subkey '%s' : %s\n",
619 subkey_name
, dos_errstr(werr
));
622 d_printf("[%s]\n", GLOBAL_NAME
);
623 if (!W_ERROR_IS_OK(list_values(ctx
, sub_key
))) {
630 W_ERROR_IS_OK(werr
= reg_enumkey(ctx
, base_key
, idx_key
,
631 &subkey_name
, NULL
));
634 if (strequal(subkey_name
, GLOBAL_NAME
)) {
637 d_printf("[%s]\n", subkey_name
);
639 werr
= reg_openkey(ctx
, base_key
, subkey_name
,
640 REG_KEY_READ
, &sub_key
);
641 if (!W_ERROR_IS_OK(werr
)) {
643 "Error opening subkey '%s': %s\n",
644 subkey_name
, dos_errstr(werr
));
647 if (!W_ERROR_IS_OK(list_values(ctx
, sub_key
))) {
652 if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS
, werr
)) {
653 d_fprintf(stderr
, "Error enumerating subkeys: %s\n",
665 int net_conf_import(int argc
, const char **argv
)
668 const char *filename
= NULL
;
669 const char *servicename
= NULL
;
670 BOOL service_found
= False
;
672 struct share_iterator
*shares
;
673 struct share_params
*share
;
674 struct share_params global_share
= { GLOBAL_SECTION_SNUM
};
676 ctx
= talloc_init("net_conf_import");
681 net_conf_import_usage(argc
, argv
);
684 servicename
= argv
[1];
690 DEBUG(3,("net_conf_import: reading configuration from file %s.\n",
693 if (!lp_load(filename
,
694 False
, /* global_only */
695 True
, /* save_defaults */
697 True
)) /* initialize_globals */
699 d_fprintf(stderr
, "Error parsing configuration file.\n");
704 d_printf("\nTEST MODE - would import the following configuration:\n\n");
707 if ((servicename
== NULL
) || strequal(servicename
, GLOBAL_NAME
)) {
708 service_found
= True
;
709 if (import_process_service(ctx
, &global_share
) != 0) {
714 if (service_found
&& (servicename
!= NULL
)) {
719 if (!(shares
= share_list_all(ctx
))) {
720 d_fprintf(stderr
, "Could not list shares...\n");
723 while ((share
= next_share(shares
)) != NULL
) {
724 if ((servicename
== NULL
)
725 || strequal(servicename
, lp_servicename(share
->service
)))
727 service_found
= True
;
728 if (import_process_service(ctx
, share
)!= 0) {
734 if ((servicename
!= NULL
) && !service_found
) {
735 d_printf("Share %s not found in file %s\n",
736 servicename
, filename
);
748 int net_conf_listshares(int argc
, const char **argv
)
750 WERROR werr
= WERR_OK
;
752 struct registry_key
*key
;
754 char *subkey_name
= NULL
;
757 ctx
= talloc_init("listshares");
760 net_conf_listshares_usage(argc
, argv
);
764 werr
= smbconf_open_basepath(ctx
, SEC_RIGHTS_ENUM_SUBKEYS
, &key
);
765 if (!W_ERROR_IS_OK(werr
)) {
770 W_ERROR_IS_OK(werr
= reg_enumkey(ctx
, key
, idx
,
771 &subkey_name
, NULL
));
774 d_printf("%s\n", subkey_name
);
776 if (! W_ERROR_EQUAL(WERR_NO_MORE_ITEMS
, werr
)) {
777 d_fprintf(stderr
, "Error enumerating subkeys: %s\n",
789 int net_conf_drop(int argc
, const char **argv
)
795 net_conf_drop_usage(argc
, argv
);
799 werr
= drop_smbconf_internal(NULL
);
800 if (!W_ERROR_IS_OK(werr
)) {
801 d_fprintf(stderr
, "Error deleting configuration: %s\n",
812 int net_conf_showshare(int argc
, const char **argv
)
815 WERROR werr
= WERR_OK
;
816 struct registry_key
*key
= NULL
;
819 ctx
= talloc_init("showshare");
822 net_conf_showshare_usage(argc
, argv
);
826 werr
= smbconf_open_path(ctx
, argv
[0], REG_KEY_READ
, &key
);
827 if (!W_ERROR_IS_OK(werr
)) {
831 d_printf("[%s]\n", argv
[0]);
833 if (!W_ERROR_IS_OK(list_values(ctx
, key
))) {
844 int net_conf_addshare(int argc
, const char **argv
)
847 WERROR werr
= WERR_OK
;
848 struct registry_key
*newkey
= NULL
;
849 char *sharename
= NULL
;
850 const char *path
= NULL
;
851 const char *comment
= NULL
;
852 const char *guest_ok
= "no";
853 const char *writeable
= "no";
854 SMB_STRUCT_STAT sbuf
;
860 net_conf_addshare_usage(argc
, argv
);
865 if (!strnequal(argv
[3], "guest_ok=", 9)) {
866 net_conf_addshare_usage(argc
, argv
);
869 switch (argv
[3][9]) {
879 net_conf_addshare_usage(argc
, argv
);
883 if (!strnequal(argv
[2], "writeable=", 10)) {
884 net_conf_addshare_usage(argc
, argv
);
887 switch (argv
[2][10]) {
897 net_conf_addshare_usage(argc
, argv
);
903 sharename
= strdup_lower(argv
[0]);
911 /* validate share name */
913 if (!validate_net_name(sharename
, INVALID_SHARENAME_CHARS
,
916 d_fprintf(stderr
, "ERROR: share name %s contains "
917 "invalid characters (any of %s)\n",
918 sharename
, INVALID_SHARENAME_CHARS
);
922 if (getpwnam(sharename
)) {
923 d_fprintf(stderr
, "ERROR: share name %s is already a valid "
924 "system user name.\n", sharename
);
928 if (strequal(sharename
, GLOBAL_NAME
)) {
930 "ERROR: 'global' is not a valid share name.\n");
936 if (path
[0] != '/') {
938 "Error: path '%s' is not an absolute path.\n",
943 if (sys_stat(path
, &sbuf
) != 0) {
945 "ERROR: cannot stat path '%s' to ensure "
946 "this is a directory.\n"
948 path
, strerror(errno
));
952 if (!S_ISDIR(sbuf
.st_mode
)) {
954 "ERROR: path '%s' is not a directory.\n",
963 werr
= reg_createkey_internal(NULL
, argv
[0], &newkey
);
964 if (!W_ERROR_IS_OK(werr
)) {
968 /* add config params as values */
970 werr
= reg_setvalue_internal(newkey
, "path", "sz", path
);
971 if (!W_ERROR_IS_OK(werr
))
974 if (comment
!= NULL
) {
975 werr
= reg_setvalue_internal(newkey
, "comment", "sz", comment
);
976 if (!W_ERROR_IS_OK(werr
))
980 werr
= reg_setvalue_internal(newkey
, "guest ok", "sz", guest_ok
);
981 if (!W_ERROR_IS_OK(werr
))
984 werr
= reg_setvalue_internal(newkey
, "writeable", "sz", writeable
);
985 if (!W_ERROR_IS_OK(werr
))
992 SAFE_FREE(sharename
);
996 int net_conf_delshare(int argc
, const char **argv
)
999 const char *sharename
= NULL
;
1002 net_conf_delshare_usage(argc
, argv
);
1005 sharename
= argv
[0];
1007 if (W_ERROR_IS_OK(reg_delkey_internal(NULL
, sharename
))) {
1014 static int net_conf_setparm(int argc
, const char **argv
)
1017 WERROR werr
= WERR_OK
;
1018 struct registry_key
*key
= NULL
;
1019 char *service
= NULL
;
1021 const char *value_str
= NULL
;
1024 ctx
= talloc_init("setparm");
1027 net_conf_setparm_usage(argc
, argv
);
1030 service
= strdup_lower(argv
[0]);
1031 param
= strdup_lower(argv
[1]);
1032 value_str
= argv
[2];
1034 if (!smbconf_key_exists(ctx
, service
)) {
1035 werr
= reg_createkey_internal(ctx
, service
, &key
);
1038 werr
= smbconf_open_path(ctx
, service
, REG_KEY_READ
, &key
);
1040 if (!W_ERROR_IS_OK(werr
)) {
1044 werr
= reg_setvalue_internal(key
, param
, "sz", value_str
);
1045 if (!W_ERROR_IS_OK(werr
)) {
1046 d_fprintf(stderr
, "Error setting value '%s': %s\n",
1047 param
, dos_errstr(werr
));
1060 static int net_conf_getparm(int argc
, const char **argv
)
1063 WERROR werr
= WERR_OK
;
1064 struct registry_key
*key
= NULL
;
1065 char *service
= NULL
;
1067 struct registry_value
*value
= NULL
;
1070 ctx
= talloc_init("getparm");
1073 net_conf_getparm_usage(argc
, argv
);
1076 service
= strdup_lower(argv
[0]);
1077 param
= strdup_lower(argv
[1]);
1079 if (!smbconf_key_exists(ctx
, service
)) {
1081 "ERROR: given service '%s' does not exist.\n",
1086 werr
= smbconf_open_path(ctx
, service
, REG_KEY_READ
, &key
);
1087 if (!W_ERROR_IS_OK(werr
)) {
1091 werr
= reg_queryvalue(ctx
, key
, param
, &value
);
1092 if (!W_ERROR_IS_OK(werr
)) {
1093 d_fprintf(stderr
, "Error querying value '%s': %s.\n",
1094 param
, dos_errstr(werr
));
1098 d_printf("%s\n", format_value(ctx
, value
));
1108 static int net_conf_delparm(int argc
, const char **argv
)
1111 WERROR werr
= WERR_OK
;
1112 struct registry_key
*key
= NULL
;
1113 char *service
= NULL
;
1117 ctx
= talloc_init("delparm");
1120 net_conf_delparm_usage(argc
, argv
);
1123 service
= strdup_lower(argv
[0]);
1124 param
= strdup_lower(argv
[1]);
1126 if (!smbconf_key_exists(ctx
, service
)) {
1128 "Error: given service '%s' does not exist.\n",
1133 werr
= smbconf_open_path(ctx
, service
, REG_KEY_READ
, &key
);
1134 if (!W_ERROR_IS_OK(werr
)) {
1138 if (!smbconf_value_exists(ctx
, key
, param
)) {
1140 "Error: given parameter '%s' is not set.\n",
1144 werr
= reg_deletevalue(key
, param
);
1145 if (!W_ERROR_IS_OK(werr
)) {
1146 d_fprintf(stderr
, "Error deleting value '%s': %s.\n",
1147 param
, dos_errstr(werr
));
1158 * Entry-point for all the CONF functions.
1161 int net_conf(int argc
, const char **argv
)
1164 struct functable2 func
[] = {
1165 {"list", net_conf_list
,
1166 "Dump the complete configuration in smb.conf like format."},
1167 {"import", net_conf_import
,
1168 "Import configuration from file in smb.conf format."},
1169 {"listshares", net_conf_listshares
,
1170 "List the registry shares."},
1171 {"drop", net_conf_drop
,
1172 "Delete the complete configuration from registry."},
1173 {"showshare", net_conf_showshare
,
1174 "Show the definition of a registry share."},
1175 {"addshare", net_conf_addshare
,
1176 "Create a new registry share."},
1177 {"delshare", net_conf_delshare
,
1178 "Delete a registry share."},
1179 {"setparm", net_conf_setparm
,
1180 "Store a parameter."},
1181 {"getparm", net_conf_getparm
,
1182 "Retrieve the value of a parameter."},
1183 {"delparm", net_conf_delparm
,
1184 "Delete a parameter."},
1188 if (!registry_init_regdb()) {
1189 d_fprintf(stderr
, "Error initializing the registry!\n");
1193 ret
= net_run_function2(argc
, argv
, "net conf", func
);