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
,
152 struct registry_value val
;
153 WERROR werr
= WERR_OK
;
158 val
.v
.sz
.str
= CONST_DISCARD(char *, valstr
);
159 val
.v
.sz
.len
= strlen(valstr
) + 1;
161 if (!lp_parameter_is_valid(valname
)) {
162 d_fprintf(stderr
, "Invalid parameter '%s' given.\n", valname
);
163 werr
= WERR_INVALID_PARAM
;
167 if (registry_smbconf_valname_forbidden(valname
)) {
168 d_fprintf(stderr
, "Parameter '%s' not allowed in registry.\n",
170 werr
= WERR_INVALID_PARAM
;
174 if (!strequal(strrchr_m(key
->key
->name
, '\\')+1, GLOBAL_NAME
) &&
175 lp_parameter_is_global(valname
))
177 d_fprintf(stderr
, "Global paramter '%s' not allowed in "
178 "service definition ('%s').\n", valname
,
179 strrchr_m(key
->key
->name
, '\\')+1);
180 werr
= WERR_INVALID_PARAM
;
184 werr
= reg_setvalue(key
, valname
, &val
);
185 if (!W_ERROR_IS_OK(werr
)) {
187 "Error adding value '%s' to "
189 valname
, key
->key
->name
, dos_errstr(werr
));
197 * Open a subkey of KEY_SMBCONF (i.e a service)
198 * - variant without error output (q = quiet)-
200 static WERROR
smbconf_open_path_q(TALLOC_CTX
*ctx
, const char *subkeyname
,
201 uint32 desired_access
,
202 struct registry_key
**key
)
204 WERROR werr
= WERR_OK
;
206 NT_USER_TOKEN
*token
;
208 if (!(token
= registry_create_admin_token(ctx
))) {
209 DEBUG(1, ("Error creating admin token\n"));
213 if (subkeyname
== NULL
) {
214 path
= talloc_strdup(ctx
, KEY_SMBCONF
);
217 path
= talloc_asprintf(ctx
, "%s\\%s", KEY_SMBCONF
, subkeyname
);
220 werr
= reg_open_path(ctx
, path
, desired_access
,
229 * Open a subkey of KEY_SMBCONF (i.e a service)
230 * - variant with error output -
232 static WERROR
smbconf_open_path(TALLOC_CTX
*ctx
, const char *subkeyname
,
233 uint32 desired_access
,
234 struct registry_key
**key
)
236 WERROR werr
= WERR_OK
;
238 werr
= smbconf_open_path_q(ctx
, subkeyname
, desired_access
, key
);
239 if (!W_ERROR_IS_OK(werr
)) {
240 d_fprintf(stderr
, "Error opening registry path '%s\\%s': %s\n",
242 (subkeyname
== NULL
) ? "" : subkeyname
,
250 * open the base key KEY_SMBCONF
252 static WERROR
smbconf_open_basepath(TALLOC_CTX
*ctx
, uint32 desired_access
,
253 struct registry_key
**key
)
255 return smbconf_open_path(ctx
, NULL
, desired_access
, key
);
259 * delete a subkey of KEY_SMBCONF
261 static WERROR
reg_delkey_internal(TALLOC_CTX
*ctx
, const char *keyname
)
263 WERROR werr
= WERR_OK
;
264 struct registry_key
*key
= NULL
;
266 werr
= smbconf_open_basepath(ctx
, REG_KEY_WRITE
, &key
);
267 if (!W_ERROR_IS_OK(werr
)) {
271 werr
= reg_deletekey_recursive(key
, key
, keyname
);
272 if (!W_ERROR_IS_OK(werr
)) {
273 d_fprintf(stderr
, "Error deleting registry key %s\\%s: %s\n",
274 KEY_SMBCONF
, keyname
, dos_errstr(werr
));
283 * create a subkey of KEY_SMBCONF
285 static WERROR
reg_createkey_internal(TALLOC_CTX
*ctx
,
286 const char * subkeyname
,
287 struct registry_key
**newkey
)
289 WERROR werr
= WERR_OK
;
290 struct registry_key
*create_parent
= NULL
;
291 TALLOC_CTX
*create_ctx
;
292 enum winreg_CreateAction action
= REG_ACTION_NONE
;
294 /* create a new talloc ctx for creation. it will hold
295 * the intermediate parent key (SMBCONF) for creation
296 * and will be destroyed when leaving this function... */
297 if (!(create_ctx
= talloc_new(ctx
))) {
302 werr
= smbconf_open_basepath(create_ctx
, REG_KEY_WRITE
, &create_parent
);
303 if (!W_ERROR_IS_OK(werr
)) {
307 werr
= reg_createkey(ctx
, create_parent
, subkeyname
,
308 REG_KEY_WRITE
, newkey
, &action
);
309 if (W_ERROR_IS_OK(werr
) && (action
!= REG_CREATED_NEW_KEY
)) {
310 d_fprintf(stderr
, "Key '%s' already exists.\n", subkeyname
);
311 werr
= WERR_ALREADY_EXISTS
;
313 if (!W_ERROR_IS_OK(werr
)) {
314 d_fprintf(stderr
, "Error creating key %s: %s\n",
315 subkeyname
, dos_errstr(werr
));
319 TALLOC_FREE(create_ctx
);
324 * check if a subkey of KEY_SMBCONF of a given name exists
326 static BOOL
smbconf_key_exists(TALLOC_CTX
*ctx
, const char *subkeyname
)
329 WERROR werr
= WERR_OK
;
331 struct registry_key
*key
;
333 if (!(mem_ctx
= talloc_new(ctx
))) {
334 d_fprintf(stderr
, "ERROR: Out of memory...!\n");
338 werr
= smbconf_open_path_q(mem_ctx
, subkeyname
, REG_KEY_READ
, &key
);
339 if (W_ERROR_IS_OK(werr
)) {
344 TALLOC_FREE(mem_ctx
);
348 static BOOL
smbconf_value_exists(TALLOC_CTX
*ctx
, struct registry_key
*key
,
352 WERROR werr
= WERR_OK
;
353 struct registry_value
*value
= NULL
;
355 werr
= reg_queryvalue(ctx
, key
, param
, &value
);
356 if (W_ERROR_IS_OK(werr
)) {
364 static WERROR
list_values(TALLOC_CTX
*ctx
, struct registry_key
*key
)
366 WERROR werr
= WERR_OK
;
368 struct registry_value
*valvalue
= NULL
;
369 char *valname
= NULL
;
372 W_ERROR_IS_OK(werr
= reg_enumvalue(ctx
, key
, idx
, &valname
,
376 d_printf("\t%s = %s\n", valname
, format_value(ctx
, valvalue
));
378 if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS
, werr
)) {
379 d_fprintf(stderr
, "Error enumerating values: %s\n",
389 static WERROR
drop_smbconf_internal(TALLOC_CTX
*ctx
)
392 WERROR werr
= WERR_OK
;
393 NT_USER_TOKEN
*token
;
394 struct registry_key
*parent_key
= NULL
;
395 struct registry_key
*new_key
= NULL
;
396 TALLOC_CTX
* tmp_ctx
= NULL
;
397 enum winreg_CreateAction action
;
399 tmp_ctx
= talloc_new(ctx
);
400 if (tmp_ctx
== NULL
) {
405 if (!(token
= registry_create_admin_token(tmp_ctx
))) {
406 /* what is the appropriate error code here? */
407 werr
= WERR_CAN_NOT_COMPLETE
;
411 path
= talloc_strdup(tmp_ctx
, KEY_SMBCONF
);
413 d_fprintf(stderr
, "ERROR: out of memory!\n");
417 p
= strrchr(path
, '\\');
419 werr
= reg_open_path(tmp_ctx
, path
, REG_KEY_WRITE
, token
, &parent_key
);
421 if (!W_ERROR_IS_OK(werr
)) {
425 werr
= reg_deletekey_recursive(tmp_ctx
, parent_key
, p
+1);
427 if (!W_ERROR_IS_OK(werr
)) {
431 werr
= reg_createkey(tmp_ctx
, parent_key
, p
+1, REG_KEY_WRITE
,
435 TALLOC_FREE(tmp_ctx
);
439 static char *parm_valstr(TALLOC_CTX
*ctx
, struct parm_struct
*parm
,
440 struct share_params
*share
)
444 void *ptr
= parm
->ptr
;
446 if (parm
->p_class
== P_LOCAL
&& share
->service
>= 0) {
447 ptr
= lp_local_ptr(share
->service
, ptr
);
450 switch (parm
->type
) {
452 valstr
= talloc_asprintf(ctx
, "%c", *(char *)ptr
);
456 valstr
= talloc_asprintf(ctx
, "%s", *(char **)ptr
);
460 valstr
= talloc_asprintf(ctx
, "%s", (char *)ptr
);
463 valstr
= talloc_asprintf(ctx
, "%s", BOOLSTR(*(BOOL
*)ptr
));
466 valstr
= talloc_asprintf(ctx
, "%s", BOOLSTR(!*(BOOL
*)ptr
));
469 for (i
= 0; parm
->enum_list
[i
].name
; i
++) {
470 if (*(int *)ptr
== parm
->enum_list
[i
].value
)
472 valstr
= talloc_asprintf(ctx
, "%s",
473 parm
->enum_list
[i
].name
);
479 valstr
= talloc_asprintf(ctx
, "%s", octal_string(*(int *)ptr
));
482 valstr
= talloc_strdup(ctx
, "");
483 if ((char ***)ptr
&& *(char ***)ptr
) {
484 char **list
= *(char ***)ptr
;
485 for (; *list
; list
++) {
486 /* surround strings with whitespace
487 * in double quotes */
488 if (strchr_m(*list
, ' '))
490 valstr
= talloc_asprintf_append(
493 ((*(list
+1))?", ":""));
496 valstr
= talloc_asprintf_append(
497 valstr
, "%s%s", *list
,
498 ((*(list
+1))?", ":""));
504 valstr
= talloc_asprintf(ctx
, "%d", *(int *)ptr
);
509 valstr
= talloc_asprintf(ctx
, "<type unimplemented>\n");
516 static int import_process_service(TALLOC_CTX
*ctx
,
517 struct share_params
*share
)
520 struct parm_struct
*parm
;
522 const char *servicename
;
523 struct registry_key
*key
;
526 TALLOC_CTX
*tmp_ctx
= NULL
;
528 tmp_ctx
= talloc_new(ctx
);
529 if (tmp_ctx
== NULL
) {
534 servicename
= (share
->service
== GLOBAL_SECTION_SNUM
)?
535 GLOBAL_NAME
: lp_servicename(share
->service
);
538 d_printf("[%s]\n", servicename
);
541 if (smbconf_key_exists(tmp_ctx
, servicename
)) {
542 werr
= reg_delkey_internal(tmp_ctx
, servicename
);
543 if (!W_ERROR_IS_OK(werr
)) {
547 werr
= reg_createkey_internal(tmp_ctx
, servicename
, &key
);
548 if (!W_ERROR_IS_OK(werr
)) {
553 while ((parm
= lp_next_parameter(share
->service
, &pnum
, 0)))
555 if ((share
->service
< 0 && parm
->p_class
== P_LOCAL
)
556 && !(parm
->flags
& FLAG_GLOBAL
))
559 valstr
= parm_valstr(tmp_ctx
, parm
, share
);
561 if (parm
->type
!= P_SEP
) {
563 d_printf("\t%s = %s\n", parm
->label
, valstr
);
566 werr
= reg_setvalue_internal(key
, parm
->label
,
568 if (!W_ERROR_IS_OK(werr
)) {
582 TALLOC_FREE(tmp_ctx
);
591 int net_conf_list(int argc
, const char **argv
)
593 WERROR werr
= WERR_OK
;
596 struct registry_key
*base_key
= NULL
;
597 struct registry_key
*sub_key
= NULL
;
599 char *subkey_name
= NULL
;
601 ctx
= talloc_init("list");
604 net_conf_list_usage(argc
, argv
);
608 werr
= smbconf_open_basepath(ctx
, REG_KEY_READ
, &base_key
);
609 if (!W_ERROR_IS_OK(werr
)) {
613 if (smbconf_key_exists(ctx
, GLOBAL_NAME
)) {
614 werr
= reg_openkey(ctx
, base_key
, GLOBAL_NAME
,
615 REG_KEY_READ
, &sub_key
);
616 if (!W_ERROR_IS_OK(werr
)) {
617 d_fprintf(stderr
, "Error opening subkey '%s' : %s\n",
618 subkey_name
, dos_errstr(werr
));
621 d_printf("[%s]\n", GLOBAL_NAME
);
622 if (!W_ERROR_IS_OK(list_values(ctx
, sub_key
))) {
629 W_ERROR_IS_OK(werr
= reg_enumkey(ctx
, base_key
, idx_key
,
630 &subkey_name
, NULL
));
633 if (strequal(subkey_name
, GLOBAL_NAME
)) {
636 d_printf("[%s]\n", subkey_name
);
638 werr
= reg_openkey(ctx
, base_key
, subkey_name
,
639 REG_KEY_READ
, &sub_key
);
640 if (!W_ERROR_IS_OK(werr
)) {
642 "Error opening subkey '%s': %s\n",
643 subkey_name
, dos_errstr(werr
));
646 if (!W_ERROR_IS_OK(list_values(ctx
, sub_key
))) {
651 if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS
, werr
)) {
652 d_fprintf(stderr
, "Error enumerating subkeys: %s\n",
664 int net_conf_import(int argc
, const char **argv
)
667 const char *filename
= NULL
;
668 const char *servicename
= NULL
;
669 BOOL service_found
= False
;
671 struct share_iterator
*shares
;
672 struct share_params
*share
;
673 struct share_params global_share
= { GLOBAL_SECTION_SNUM
};
675 ctx
= talloc_init("net_conf_import");
680 net_conf_import_usage(argc
, argv
);
683 servicename
= argv
[1];
689 DEBUG(3,("net_conf_import: reading configuration from file %s.\n",
692 if (!lp_load(filename
,
693 False
, /* global_only */
694 True
, /* save_defaults */
696 True
)) /* initialize_globals */
698 d_fprintf(stderr
, "Error parsing configuration file.\n");
703 d_printf("\nTEST MODE - would import the following configuration:\n\n");
706 if ((servicename
== NULL
) || strequal(servicename
, GLOBAL_NAME
)) {
707 service_found
= True
;
708 if (import_process_service(ctx
, &global_share
) != 0) {
713 if (service_found
&& (servicename
!= NULL
)) {
718 if (!(shares
= share_list_all(ctx
))) {
719 d_fprintf(stderr
, "Could not list shares...\n");
722 while ((share
= next_share(shares
)) != NULL
) {
723 if ((servicename
== NULL
)
724 || strequal(servicename
, lp_servicename(share
->service
)))
726 service_found
= True
;
727 if (import_process_service(ctx
, share
)!= 0) {
733 if ((servicename
!= NULL
) && !service_found
) {
734 d_printf("Share %s not found in file %s\n",
735 servicename
, filename
);
747 int net_conf_listshares(int argc
, const char **argv
)
749 WERROR werr
= WERR_OK
;
751 struct registry_key
*key
;
753 char *subkey_name
= NULL
;
756 ctx
= talloc_init("listshares");
759 net_conf_listshares_usage(argc
, argv
);
763 werr
= smbconf_open_basepath(ctx
, SEC_RIGHTS_ENUM_SUBKEYS
, &key
);
764 if (!W_ERROR_IS_OK(werr
)) {
769 W_ERROR_IS_OK(werr
= reg_enumkey(ctx
, key
, idx
,
770 &subkey_name
, NULL
));
773 d_printf("%s\n", subkey_name
);
775 if (! W_ERROR_EQUAL(WERR_NO_MORE_ITEMS
, werr
)) {
776 d_fprintf(stderr
, "Error enumerating subkeys: %s\n",
788 int net_conf_drop(int argc
, const char **argv
)
794 net_conf_drop_usage(argc
, argv
);
798 werr
= drop_smbconf_internal(NULL
);
799 if (!W_ERROR_IS_OK(werr
)) {
800 d_fprintf(stderr
, "Error deleting configuration: %s\n",
811 int net_conf_showshare(int argc
, const char **argv
)
814 WERROR werr
= WERR_OK
;
815 struct registry_key
*key
= NULL
;
818 ctx
= talloc_init("showshare");
821 net_conf_showshare_usage(argc
, argv
);
825 werr
= smbconf_open_path(ctx
, argv
[0], REG_KEY_READ
, &key
);
826 if (!W_ERROR_IS_OK(werr
)) {
830 d_printf("[%s]\n", argv
[0]);
832 if (!W_ERROR_IS_OK(list_values(ctx
, key
))) {
843 int net_conf_addshare(int argc
, const char **argv
)
846 WERROR werr
= WERR_OK
;
847 struct registry_key
*newkey
= NULL
;
848 char *sharename
= NULL
;
849 const char *path
= NULL
;
850 const char *comment
= NULL
;
851 const char *guest_ok
= "no";
852 const char *writeable
= "no";
853 SMB_STRUCT_STAT sbuf
;
859 net_conf_addshare_usage(argc
, argv
);
864 if (!strnequal(argv
[3], "guest_ok=", 9)) {
865 net_conf_addshare_usage(argc
, argv
);
868 switch (argv
[3][9]) {
878 net_conf_addshare_usage(argc
, argv
);
882 if (!strnequal(argv
[2], "writeable=", 10)) {
883 net_conf_addshare_usage(argc
, argv
);
886 switch (argv
[2][10]) {
896 net_conf_addshare_usage(argc
, argv
);
902 sharename
= strdup_lower(argv
[0]);
910 /* validate share name */
912 if (!validate_net_name(sharename
, INVALID_SHARENAME_CHARS
,
915 d_fprintf(stderr
, "ERROR: share name %s contains "
916 "invalid characters (any of %s)\n",
917 sharename
, INVALID_SHARENAME_CHARS
);
921 if (getpwnam(sharename
)) {
922 d_fprintf(stderr
, "ERROR: share name %s is already a valid "
923 "system user name.\n", sharename
);
927 if (strequal(sharename
, GLOBAL_NAME
)) {
929 "ERROR: 'global' is not a valid share name.\n");
935 if (path
[0] != '/') {
937 "Error: path '%s' is not an absolute path.\n",
942 if (sys_stat(path
, &sbuf
) != 0) {
944 "ERROR: cannot stat path '%s' to ensure "
945 "this is a directory.\n"
947 path
, strerror(errno
));
951 if (!S_ISDIR(sbuf
.st_mode
)) {
953 "ERROR: path '%s' is not a directory.\n",
962 werr
= reg_createkey_internal(NULL
, argv
[0], &newkey
);
963 if (!W_ERROR_IS_OK(werr
)) {
967 /* add config params as values */
969 werr
= reg_setvalue_internal(newkey
, "path", path
);
970 if (!W_ERROR_IS_OK(werr
))
973 if (comment
!= NULL
) {
974 werr
= reg_setvalue_internal(newkey
, "comment", comment
);
975 if (!W_ERROR_IS_OK(werr
))
979 werr
= reg_setvalue_internal(newkey
, "guest ok", guest_ok
);
980 if (!W_ERROR_IS_OK(werr
))
983 werr
= reg_setvalue_internal(newkey
, "writeable", writeable
);
984 if (!W_ERROR_IS_OK(werr
))
991 SAFE_FREE(sharename
);
995 int net_conf_delshare(int argc
, const char **argv
)
998 const char *sharename
= NULL
;
1001 net_conf_delshare_usage(argc
, argv
);
1004 sharename
= argv
[0];
1006 if (W_ERROR_IS_OK(reg_delkey_internal(NULL
, sharename
))) {
1013 static int net_conf_setparm(int argc
, const char **argv
)
1016 WERROR werr
= WERR_OK
;
1017 struct registry_key
*key
= NULL
;
1018 char *service
= NULL
;
1020 const char *value_str
= NULL
;
1023 ctx
= talloc_init("setparm");
1026 net_conf_setparm_usage(argc
, argv
);
1029 service
= strdup_lower(argv
[0]);
1030 param
= strdup_lower(argv
[1]);
1031 value_str
= argv
[2];
1033 if (!smbconf_key_exists(ctx
, service
)) {
1034 werr
= reg_createkey_internal(ctx
, service
, &key
);
1037 werr
= smbconf_open_path(ctx
, service
, REG_KEY_READ
, &key
);
1039 if (!W_ERROR_IS_OK(werr
)) {
1043 werr
= reg_setvalue_internal(key
, param
, value_str
);
1044 if (!W_ERROR_IS_OK(werr
)) {
1045 d_fprintf(stderr
, "Error setting value '%s': %s\n",
1046 param
, dos_errstr(werr
));
1059 static int net_conf_getparm(int argc
, const char **argv
)
1062 WERROR werr
= WERR_OK
;
1063 struct registry_key
*key
= NULL
;
1064 char *service
= NULL
;
1066 struct registry_value
*value
= NULL
;
1069 ctx
= talloc_init("getparm");
1072 net_conf_getparm_usage(argc
, argv
);
1075 service
= strdup_lower(argv
[0]);
1076 param
= strdup_lower(argv
[1]);
1078 if (!smbconf_key_exists(ctx
, service
)) {
1080 "ERROR: given service '%s' does not exist.\n",
1085 werr
= smbconf_open_path(ctx
, service
, REG_KEY_READ
, &key
);
1086 if (!W_ERROR_IS_OK(werr
)) {
1090 werr
= reg_queryvalue(ctx
, key
, param
, &value
);
1091 if (!W_ERROR_IS_OK(werr
)) {
1092 d_fprintf(stderr
, "Error querying value '%s': %s.\n",
1093 param
, dos_errstr(werr
));
1097 d_printf("%s\n", format_value(ctx
, value
));
1107 static int net_conf_delparm(int argc
, const char **argv
)
1110 WERROR werr
= WERR_OK
;
1111 struct registry_key
*key
= NULL
;
1112 char *service
= NULL
;
1116 ctx
= talloc_init("delparm");
1119 net_conf_delparm_usage(argc
, argv
);
1122 service
= strdup_lower(argv
[0]);
1123 param
= strdup_lower(argv
[1]);
1125 if (!smbconf_key_exists(ctx
, service
)) {
1127 "Error: given service '%s' does not exist.\n",
1132 werr
= smbconf_open_path(ctx
, service
, REG_KEY_READ
, &key
);
1133 if (!W_ERROR_IS_OK(werr
)) {
1137 if (!smbconf_value_exists(ctx
, key
, param
)) {
1139 "Error: given parameter '%s' is not set.\n",
1143 werr
= reg_deletevalue(key
, param
);
1144 if (!W_ERROR_IS_OK(werr
)) {
1145 d_fprintf(stderr
, "Error deleting value '%s': %s.\n",
1146 param
, dos_errstr(werr
));
1157 * Entry-point for all the CONF functions.
1160 int net_conf(int argc
, const char **argv
)
1163 struct functable2 func
[] = {
1164 {"list", net_conf_list
,
1165 "Dump the complete configuration in smb.conf like format."},
1166 {"import", net_conf_import
,
1167 "Import configuration from file in smb.conf format."},
1168 {"listshares", net_conf_listshares
,
1169 "List the registry shares."},
1170 {"drop", net_conf_drop
,
1171 "Delete the complete configuration from registry."},
1172 {"showshare", net_conf_showshare
,
1173 "Show the definition of a registry share."},
1174 {"addshare", net_conf_addshare
,
1175 "Create a new registry share."},
1176 {"delshare", net_conf_delshare
,
1177 "Delete a registry share."},
1178 {"setparm", net_conf_setparm
,
1179 "Store a parameter."},
1180 {"getparm", net_conf_getparm
,
1181 "Retrieve the value of a parameter."},
1182 {"delparm", net_conf_delparm
,
1183 "Delete a parameter."},
1187 if (!registry_init_regdb()) {
1188 d_fprintf(stderr
, "Error initializing the registry!\n");
1192 ret
= net_run_function2(argc
, argv
, "net conf", func
);