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 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 the configuration stored inside the
23 * samba registry. In the future there might be support for other
24 * configuration backends as well.
28 #include "utils/net.h"
34 static int net_conf_list_usage(int argc
, const char **argv
)
36 d_printf("USAGE: net conf list\n");
40 static int net_conf_import_usage(int argc
, const char**argv
)
42 d_printf("USAGE: net conf import [--test|-T] <filename> "
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
;
155 const char *canon_valname
;
156 const char *canon_valstr
;
158 if (!lp_canonicalize_parameter_with_value(valname
, valstr
,
162 if (canon_valname
== NULL
) {
163 d_fprintf(stderr
, "invalid parameter '%s' given\n",
166 d_fprintf(stderr
, "invalid value '%s' given for "
167 "parameter '%s'\n", valstr
, valname
);
169 werr
= WERR_INVALID_PARAM
;
176 val
.v
.sz
.str
= CONST_DISCARD(char *, canon_valstr
);
177 val
.v
.sz
.len
= strlen(canon_valstr
) + 1;
179 if (registry_smbconf_valname_forbidden(canon_valname
)) {
180 d_fprintf(stderr
, "Parameter '%s' not allowed in registry.\n",
182 werr
= WERR_INVALID_PARAM
;
186 subkeyname
= strrchr_m(key
->key
->name
, '\\');
187 if ((subkeyname
== NULL
) || (*(subkeyname
+1) == '\0')) {
188 d_fprintf(stderr
, "Invalid registry key '%s' given as "
189 "smbconf section.\n", key
->key
->name
);
190 werr
= WERR_INVALID_PARAM
;
194 if (!strequal(subkeyname
, GLOBAL_NAME
) &&
195 lp_parameter_is_global(valname
))
197 d_fprintf(stderr
, "Global paramter '%s' not allowed in "
198 "service definition ('%s').\n", canon_valname
,
200 werr
= WERR_INVALID_PARAM
;
204 werr
= reg_setvalue(key
, canon_valname
, &val
);
205 if (!W_ERROR_IS_OK(werr
)) {
207 "Error adding value '%s' to "
209 canon_valname
, key
->key
->name
, dos_errstr(werr
));
217 * Open a subkey of KEY_SMBCONF (i.e a service)
218 * - variant without error output (q = quiet)-
220 static WERROR
smbconf_open_path_q(TALLOC_CTX
*ctx
, const char *subkeyname
,
221 uint32 desired_access
,
222 struct registry_key
**key
)
224 WERROR werr
= WERR_OK
;
226 NT_USER_TOKEN
*token
;
228 if (!(token
= registry_create_admin_token(ctx
))) {
229 DEBUG(1, ("Error creating admin token\n"));
233 if (subkeyname
== NULL
) {
234 path
= talloc_strdup(ctx
, KEY_SMBCONF
);
236 path
= talloc_asprintf(ctx
, "%s\\%s", KEY_SMBCONF
, subkeyname
);
239 werr
= reg_open_path(ctx
, path
, desired_access
,
248 * Open a subkey of KEY_SMBCONF (i.e a service)
249 * - variant with error output -
251 static WERROR
smbconf_open_path(TALLOC_CTX
*ctx
, const char *subkeyname
,
252 uint32 desired_access
,
253 struct registry_key
**key
)
255 WERROR werr
= WERR_OK
;
257 werr
= smbconf_open_path_q(ctx
, subkeyname
, desired_access
, key
);
258 if (!W_ERROR_IS_OK(werr
)) {
259 d_fprintf(stderr
, "Error opening registry path '%s\\%s': %s\n",
261 (subkeyname
== NULL
) ? "" : subkeyname
,
269 * open the base key KEY_SMBCONF
271 static WERROR
smbconf_open_basepath(TALLOC_CTX
*ctx
, uint32 desired_access
,
272 struct registry_key
**key
)
274 return smbconf_open_path(ctx
, NULL
, desired_access
, key
);
278 * delete a subkey of KEY_SMBCONF
280 static WERROR
reg_delkey_internal(TALLOC_CTX
*ctx
, const char *keyname
)
282 WERROR werr
= WERR_OK
;
283 struct registry_key
*key
= NULL
;
285 werr
= smbconf_open_basepath(ctx
, REG_KEY_WRITE
, &key
);
286 if (!W_ERROR_IS_OK(werr
)) {
290 werr
= reg_deletekey_recursive(key
, key
, keyname
);
291 if (!W_ERROR_IS_OK(werr
)) {
292 d_fprintf(stderr
, "Error deleting registry key %s\\%s: %s\n",
293 KEY_SMBCONF
, keyname
, dos_errstr(werr
));
302 * create a subkey of KEY_SMBCONF
304 static WERROR
reg_createkey_internal(TALLOC_CTX
*ctx
,
305 const char * subkeyname
,
306 struct registry_key
**newkey
)
308 WERROR werr
= WERR_OK
;
309 struct registry_key
*create_parent
= NULL
;
310 TALLOC_CTX
*create_ctx
;
311 enum winreg_CreateAction action
= REG_ACTION_NONE
;
313 /* create a new talloc ctx for creation. it will hold
314 * the intermediate parent key (SMBCONF) for creation
315 * and will be destroyed when leaving this function... */
316 if (!(create_ctx
= talloc_new(ctx
))) {
321 werr
= smbconf_open_basepath(create_ctx
, REG_KEY_WRITE
, &create_parent
);
322 if (!W_ERROR_IS_OK(werr
)) {
326 werr
= reg_createkey(ctx
, create_parent
, subkeyname
,
327 REG_KEY_WRITE
, newkey
, &action
);
328 if (W_ERROR_IS_OK(werr
) && (action
!= REG_CREATED_NEW_KEY
)) {
329 d_fprintf(stderr
, "Key '%s' already exists.\n", subkeyname
);
330 werr
= WERR_ALREADY_EXISTS
;
332 if (!W_ERROR_IS_OK(werr
)) {
333 d_fprintf(stderr
, "Error creating key %s: %s\n",
334 subkeyname
, dos_errstr(werr
));
338 TALLOC_FREE(create_ctx
);
343 * check if a subkey of KEY_SMBCONF of a given name exists
345 static bool smbconf_key_exists(TALLOC_CTX
*ctx
, const char *subkeyname
)
348 WERROR werr
= WERR_OK
;
350 struct registry_key
*key
;
352 if (!(mem_ctx
= talloc_new(ctx
))) {
353 d_fprintf(stderr
, "ERROR: Out of memory...!\n");
357 werr
= smbconf_open_path_q(mem_ctx
, subkeyname
, REG_KEY_READ
, &key
);
358 if (W_ERROR_IS_OK(werr
)) {
363 TALLOC_FREE(mem_ctx
);
367 static bool smbconf_value_exists(TALLOC_CTX
*ctx
, struct registry_key
*key
,
371 WERROR werr
= WERR_OK
;
372 struct registry_value
*value
= NULL
;
374 werr
= reg_queryvalue(ctx
, key
, param
, &value
);
375 if (W_ERROR_IS_OK(werr
)) {
383 static WERROR
list_values(TALLOC_CTX
*ctx
, struct registry_key
*key
)
385 WERROR werr
= WERR_OK
;
387 struct registry_value
*valvalue
= NULL
;
388 char *valname
= NULL
;
391 W_ERROR_IS_OK(werr
= reg_enumvalue(ctx
, key
, idx
, &valname
,
395 d_printf("\t%s = %s\n", valname
, format_value(ctx
, valvalue
));
397 if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS
, werr
)) {
398 d_fprintf(stderr
, "Error enumerating values: %s\n",
408 static WERROR
drop_smbconf_internal(TALLOC_CTX
*ctx
)
411 WERROR werr
= WERR_OK
;
412 NT_USER_TOKEN
*token
;
413 struct registry_key
*parent_key
= NULL
;
414 struct registry_key
*new_key
= NULL
;
415 TALLOC_CTX
* tmp_ctx
= NULL
;
416 enum winreg_CreateAction action
;
418 tmp_ctx
= talloc_new(ctx
);
419 if (tmp_ctx
== NULL
) {
424 if (!(token
= registry_create_admin_token(tmp_ctx
))) {
425 /* what is the appropriate error code here? */
426 werr
= WERR_CAN_NOT_COMPLETE
;
430 path
= talloc_strdup(tmp_ctx
, KEY_SMBCONF
);
432 d_fprintf(stderr
, "ERROR: out of memory!\n");
436 p
= strrchr(path
, '\\');
438 werr
= reg_open_path(tmp_ctx
, path
, REG_KEY_WRITE
, token
, &parent_key
);
440 if (!W_ERROR_IS_OK(werr
)) {
444 werr
= reg_deletekey_recursive(tmp_ctx
, parent_key
, p
+1);
446 if (!W_ERROR_IS_OK(werr
)) {
450 werr
= reg_createkey(tmp_ctx
, parent_key
, p
+1, REG_KEY_WRITE
,
454 TALLOC_FREE(tmp_ctx
);
458 static char *parm_valstr(TALLOC_CTX
*ctx
, struct parm_struct
*parm
,
459 struct share_params
*share
)
463 void *ptr
= parm
->ptr
;
465 if (parm
->p_class
== P_LOCAL
&& share
->service
>= 0) {
466 ptr
= lp_local_ptr(share
->service
, ptr
);
469 switch (parm
->type
) {
471 valstr
= talloc_asprintf(ctx
, "%c", *(char *)ptr
);
475 valstr
= talloc_asprintf(ctx
, "%s", *(char **)ptr
);
479 valstr
= talloc_asprintf(ctx
, "%s", (char *)ptr
);
482 valstr
= talloc_asprintf(ctx
, "%s", BOOLSTR(*(bool *)ptr
));
485 valstr
= talloc_asprintf(ctx
, "%s", BOOLSTR(!*(bool *)ptr
));
488 for (i
= 0; parm
->enum_list
[i
].name
; i
++) {
489 if (*(int *)ptr
== parm
->enum_list
[i
].value
)
491 valstr
= talloc_asprintf(ctx
, "%s",
492 parm
->enum_list
[i
].name
);
498 char *o
= octal_string(*(int *)ptr
);
499 valstr
= talloc_move(ctx
, &o
);
503 valstr
= talloc_strdup(ctx
, "");
504 if ((char ***)ptr
&& *(char ***)ptr
) {
505 char **list
= *(char ***)ptr
;
506 for (; *list
; list
++) {
507 /* surround strings with whitespace
508 * in double quotes */
509 if (strchr_m(*list
, ' '))
511 valstr
= talloc_asprintf_append(
514 ((*(list
+1))?", ":""));
516 valstr
= talloc_asprintf_append(
517 valstr
, "%s%s", *list
,
518 ((*(list
+1))?", ":""));
524 valstr
= talloc_asprintf(ctx
, "%d", *(int *)ptr
);
529 valstr
= talloc_asprintf(ctx
, "<type unimplemented>\n");
536 static int import_process_service(TALLOC_CTX
*ctx
,
537 struct share_params
*share
)
540 struct parm_struct
*parm
;
542 const char *servicename
;
543 struct registry_key
*key
;
546 TALLOC_CTX
*tmp_ctx
= NULL
;
548 tmp_ctx
= talloc_new(ctx
);
549 if (tmp_ctx
== NULL
) {
554 servicename
= (share
->service
== GLOBAL_SECTION_SNUM
)?
555 GLOBAL_NAME
: lp_servicename(share
->service
);
558 d_printf("[%s]\n", servicename
);
560 if (smbconf_key_exists(tmp_ctx
, servicename
)) {
561 werr
= reg_delkey_internal(tmp_ctx
, servicename
);
562 if (!W_ERROR_IS_OK(werr
)) {
566 werr
= reg_createkey_internal(tmp_ctx
, servicename
, &key
);
567 if (!W_ERROR_IS_OK(werr
)) {
572 while ((parm
= lp_next_parameter(share
->service
, &pnum
, 0)))
574 if ((share
->service
< 0 && parm
->p_class
== P_LOCAL
)
575 && !(parm
->flags
& FLAG_GLOBAL
))
578 valstr
= parm_valstr(tmp_ctx
, parm
, share
);
580 if (parm
->type
!= P_SEP
) {
582 d_printf("\t%s = %s\n", parm
->label
, valstr
);
584 werr
= reg_setvalue_internal(key
, parm
->label
,
586 if (!W_ERROR_IS_OK(werr
)) {
600 TALLOC_FREE(tmp_ctx
);
604 /* return True iff there are nondefault globals */
605 static bool globals_exist(void)
608 struct parm_struct
*parm
;
610 while ((parm
= lp_next_parameter(GLOBAL_SECTION_SNUM
, &i
, 0)) != NULL
) {
611 if (parm
->type
!= P_SEP
) {
622 int net_conf_list(int argc
, const char **argv
)
624 WERROR werr
= WERR_OK
;
627 struct registry_key
*base_key
= NULL
;
628 struct registry_key
*sub_key
= NULL
;
630 char *subkey_name
= NULL
;
632 ctx
= talloc_init("list");
635 net_conf_list_usage(argc
, argv
);
639 werr
= smbconf_open_basepath(ctx
, REG_KEY_READ
, &base_key
);
640 if (!W_ERROR_IS_OK(werr
)) {
644 if (smbconf_key_exists(ctx
, GLOBAL_NAME
)) {
645 werr
= reg_openkey(ctx
, base_key
, GLOBAL_NAME
,
646 REG_KEY_READ
, &sub_key
);
647 if (!W_ERROR_IS_OK(werr
)) {
648 d_fprintf(stderr
, "Error opening subkey '%s' : %s\n",
649 subkey_name
, dos_errstr(werr
));
652 d_printf("[%s]\n", GLOBAL_NAME
);
653 if (!W_ERROR_IS_OK(list_values(ctx
, sub_key
))) {
660 W_ERROR_IS_OK(werr
= reg_enumkey(ctx
, base_key
, idx_key
,
661 &subkey_name
, NULL
));
664 if (strequal(subkey_name
, GLOBAL_NAME
)) {
667 d_printf("[%s]\n", subkey_name
);
669 werr
= reg_openkey(ctx
, base_key
, subkey_name
,
670 REG_KEY_READ
, &sub_key
);
671 if (!W_ERROR_IS_OK(werr
)) {
673 "Error opening subkey '%s': %s\n",
674 subkey_name
, dos_errstr(werr
));
677 if (!W_ERROR_IS_OK(list_values(ctx
, sub_key
))) {
682 if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS
, werr
)) {
683 d_fprintf(stderr
, "Error enumerating subkeys: %s\n",
695 int net_conf_import(int argc
, const char **argv
)
698 const char *filename
= NULL
;
699 const char *servicename
= NULL
;
700 bool service_found
= False
;
702 struct share_iterator
*shares
;
703 struct share_params
*share
;
704 struct share_params global_share
= { GLOBAL_SECTION_SNUM
};
706 ctx
= talloc_init("net_conf_import");
711 net_conf_import_usage(argc
, argv
);
714 servicename
= argv
[1];
720 DEBUG(3,("net_conf_import: reading configuration from file %s.\n",
723 if (!lp_load(filename
,
724 False
, /* global_only */
725 True
, /* save_defaults */
727 True
)) /* initialize_globals */
729 d_fprintf(stderr
, "Error parsing configuration file.\n");
734 d_printf("\nTEST MODE - "
735 "would import the following configuration:\n\n");
738 if (((servicename
== NULL
) && globals_exist()) ||
739 strequal(servicename
, GLOBAL_NAME
))
741 service_found
= True
;
742 if (import_process_service(ctx
, &global_share
) != 0) {
747 if (service_found
&& (servicename
!= NULL
)) {
752 if (!(shares
= share_list_all(ctx
))) {
753 d_fprintf(stderr
, "Could not list shares...\n");
756 while ((share
= next_share(shares
)) != NULL
) {
757 if ((servicename
== NULL
)
758 || strequal(servicename
, lp_servicename(share
->service
)))
760 service_found
= True
;
761 if (import_process_service(ctx
, share
)!= 0) {
767 if ((servicename
!= NULL
) && !service_found
) {
768 d_printf("Share %s not found in file %s\n",
769 servicename
, filename
);
781 int net_conf_listshares(int argc
, const char **argv
)
783 WERROR werr
= WERR_OK
;
785 struct registry_key
*key
;
787 char *subkey_name
= NULL
;
790 ctx
= talloc_init("listshares");
793 net_conf_listshares_usage(argc
, argv
);
797 werr
= smbconf_open_basepath(ctx
, SEC_RIGHTS_ENUM_SUBKEYS
, &key
);
798 if (!W_ERROR_IS_OK(werr
)) {
803 W_ERROR_IS_OK(werr
= reg_enumkey(ctx
, key
, idx
,
804 &subkey_name
, NULL
));
807 d_printf("%s\n", subkey_name
);
809 if (! W_ERROR_EQUAL(WERR_NO_MORE_ITEMS
, werr
)) {
810 d_fprintf(stderr
, "Error enumerating subkeys: %s\n",
822 int net_conf_drop(int argc
, const char **argv
)
828 net_conf_drop_usage(argc
, argv
);
832 werr
= drop_smbconf_internal(NULL
);
833 if (!W_ERROR_IS_OK(werr
)) {
834 d_fprintf(stderr
, "Error deleting configuration: %s\n",
845 int net_conf_showshare(int argc
, const char **argv
)
848 WERROR werr
= WERR_OK
;
849 struct registry_key
*key
= NULL
;
852 ctx
= talloc_init("showshare");
855 net_conf_showshare_usage(argc
, argv
);
859 werr
= smbconf_open_path(ctx
, argv
[0], REG_KEY_READ
, &key
);
860 if (!W_ERROR_IS_OK(werr
)) {
864 d_printf("[%s]\n", argv
[0]);
866 if (!W_ERROR_IS_OK(list_values(ctx
, key
))) {
877 int net_conf_addshare(int argc
, const char **argv
)
880 WERROR werr
= WERR_OK
;
881 struct registry_key
*newkey
= NULL
;
882 char *sharename
= NULL
;
883 const char *path
= NULL
;
884 const char *comment
= NULL
;
885 const char *guest_ok
= "no";
886 const char *writeable
= "no";
887 SMB_STRUCT_STAT sbuf
;
893 net_conf_addshare_usage(argc
, argv
);
898 if (!strnequal(argv
[3], "guest_ok=", 9)) {
899 net_conf_addshare_usage(argc
, argv
);
902 switch (argv
[3][9]) {
912 net_conf_addshare_usage(argc
, argv
);
916 if (!strnequal(argv
[2], "writeable=", 10)) {
917 net_conf_addshare_usage(argc
, argv
);
920 switch (argv
[2][10]) {
930 net_conf_addshare_usage(argc
, argv
);
936 sharename
= strdup_lower(argv
[0]);
944 /* validate share name */
946 if (!validate_net_name(sharename
, INVALID_SHARENAME_CHARS
,
949 d_fprintf(stderr
, "ERROR: share name %s contains "
950 "invalid characters (any of %s)\n",
951 sharename
, INVALID_SHARENAME_CHARS
);
955 if (getpwnam(sharename
)) {
956 d_fprintf(stderr
, "ERROR: share name %s is already a valid "
957 "system user name.\n", sharename
);
961 if (strequal(sharename
, GLOBAL_NAME
)) {
963 "ERROR: 'global' is not a valid share name.\n");
969 if (path
[0] != '/') {
971 "Error: path '%s' is not an absolute path.\n",
976 if (sys_stat(path
, &sbuf
) != 0) {
978 "ERROR: cannot stat path '%s' to ensure "
979 "this is a directory.\n"
981 path
, strerror(errno
));
985 if (!S_ISDIR(sbuf
.st_mode
)) {
987 "ERROR: path '%s' is not a directory.\n",
996 werr
= reg_createkey_internal(NULL
, argv
[0], &newkey
);
997 if (!W_ERROR_IS_OK(werr
)) {
1001 /* add config params as values */
1003 werr
= reg_setvalue_internal(newkey
, "path", path
);
1004 if (!W_ERROR_IS_OK(werr
))
1007 if (comment
!= NULL
) {
1008 werr
= reg_setvalue_internal(newkey
, "comment", comment
);
1009 if (!W_ERROR_IS_OK(werr
))
1013 werr
= reg_setvalue_internal(newkey
, "guest ok", guest_ok
);
1014 if (!W_ERROR_IS_OK(werr
))
1017 werr
= reg_setvalue_internal(newkey
, "writeable", writeable
);
1018 if (!W_ERROR_IS_OK(werr
))
1024 TALLOC_FREE(newkey
);
1025 SAFE_FREE(sharename
);
1029 int net_conf_delshare(int argc
, const char **argv
)
1032 const char *sharename
= NULL
;
1035 net_conf_delshare_usage(argc
, argv
);
1038 sharename
= argv
[0];
1040 if (W_ERROR_IS_OK(reg_delkey_internal(NULL
, sharename
))) {
1047 static int net_conf_setparm(int argc
, const char **argv
)
1050 WERROR werr
= WERR_OK
;
1051 struct registry_key
*key
= NULL
;
1052 char *service
= NULL
;
1054 const char *value_str
= NULL
;
1057 ctx
= talloc_init("setparm");
1060 net_conf_setparm_usage(argc
, argv
);
1063 service
= strdup_lower(argv
[0]);
1064 param
= strdup_lower(argv
[1]);
1065 value_str
= argv
[2];
1067 if (!smbconf_key_exists(ctx
, service
)) {
1068 werr
= reg_createkey_internal(ctx
, service
, &key
);
1070 werr
= smbconf_open_path(ctx
, service
, REG_KEY_READ
, &key
);
1072 if (!W_ERROR_IS_OK(werr
)) {
1076 werr
= reg_setvalue_internal(key
, param
, value_str
);
1077 if (!W_ERROR_IS_OK(werr
)) {
1078 d_fprintf(stderr
, "Error setting value '%s': %s\n",
1079 param
, dos_errstr(werr
));
1092 static int net_conf_getparm(int argc
, const char **argv
)
1095 WERROR werr
= WERR_OK
;
1096 struct registry_key
*key
= NULL
;
1097 char *service
= NULL
;
1099 struct registry_value
*value
= NULL
;
1102 ctx
= talloc_init("getparm");
1105 net_conf_getparm_usage(argc
, argv
);
1108 service
= strdup_lower(argv
[0]);
1109 param
= strdup_lower(argv
[1]);
1111 if (!smbconf_key_exists(ctx
, service
)) {
1113 "ERROR: given service '%s' does not exist.\n",
1118 werr
= smbconf_open_path(ctx
, service
, REG_KEY_READ
, &key
);
1119 if (!W_ERROR_IS_OK(werr
)) {
1123 werr
= reg_queryvalue(ctx
, key
, param
, &value
);
1124 if (!W_ERROR_IS_OK(werr
)) {
1125 d_fprintf(stderr
, "Error querying value '%s': %s.\n",
1126 param
, dos_errstr(werr
));
1130 d_printf("%s\n", format_value(ctx
, value
));
1140 static int net_conf_delparm(int argc
, const char **argv
)
1143 WERROR werr
= WERR_OK
;
1144 struct registry_key
*key
= NULL
;
1145 char *service
= NULL
;
1149 ctx
= talloc_init("delparm");
1152 net_conf_delparm_usage(argc
, argv
);
1155 service
= strdup_lower(argv
[0]);
1156 param
= strdup_lower(argv
[1]);
1158 if (!smbconf_key_exists(ctx
, service
)) {
1160 "Error: given service '%s' does not exist.\n",
1165 werr
= smbconf_open_path(ctx
, service
, REG_KEY_READ
, &key
);
1166 if (!W_ERROR_IS_OK(werr
)) {
1170 if (!smbconf_value_exists(ctx
, key
, param
)) {
1172 "Error: given parameter '%s' is not set.\n",
1176 werr
= reg_deletevalue(key
, param
);
1177 if (!W_ERROR_IS_OK(werr
)) {
1178 d_fprintf(stderr
, "Error deleting value '%s': %s.\n",
1179 param
, dos_errstr(werr
));
1190 * Entry-point for all the CONF functions.
1193 int net_conf(int argc
, const char **argv
)
1196 struct functable2 func
[] = {
1197 {"list", net_conf_list
,
1198 "Dump the complete configuration in smb.conf like format."},
1199 {"import", net_conf_import
,
1200 "Import configuration from file in smb.conf format."},
1201 {"listshares", net_conf_listshares
,
1202 "List the registry shares."},
1203 {"drop", net_conf_drop
,
1204 "Delete the complete configuration from registry."},
1205 {"showshare", net_conf_showshare
,
1206 "Show the definition of a registry share."},
1207 {"addshare", net_conf_addshare
,
1208 "Create a new registry share."},
1209 {"delshare", net_conf_delshare
,
1210 "Delete a registry share."},
1211 {"setparm", net_conf_setparm
,
1212 "Store a parameter."},
1213 {"getparm", net_conf_getparm
,
1214 "Retrieve the value of a parameter."},
1215 {"delparm", net_conf_delparm
,
1216 "Delete a parameter."},
1220 if (!registry_init_regdb()) {
1221 d_fprintf(stderr
, "Error initializing the registry!\n");
1225 ret
= net_run_function2(argc
, argv
, "net conf", func
);