2 * Unix SMB/CIFS implementation.
3 * libsmbconf - Samba configuration library, registry backend
4 * Copyright (C) Michael Adam 2008
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
21 #include "smbconf_private.h"
23 #define INCLUDES_VALNAME "includes"
25 struct reg_private_data
{
27 bool open
; /* did _we_ open the registry? */
30 /**********************************************************************
34 **********************************************************************/
37 * a convenience helper to cast the private data structure
39 static struct reg_private_data
*rpd(struct smbconf_ctx
*ctx
)
41 return (struct reg_private_data
*)(ctx
->data
);
45 * check whether a given value name is forbidden in registry (smbconf)
47 static bool smbconf_reg_valname_forbidden(const char *valname
)
49 /* hard code the list of forbidden names here for now */
50 const char *forbidden_valnames
[] = {
57 const char **forbidden
= NULL
;
59 for (forbidden
= forbidden_valnames
; *forbidden
!= NULL
; forbidden
++) {
60 if (strwicmp(valname
, *forbidden
) == 0) {
67 static bool smbconf_reg_valname_valid(const char *valname
)
69 return (lp_parameter_is_valid(valname
) &&
70 !smbconf_reg_valname_forbidden(valname
));
74 * Open a registry key specified by "path"
76 static WERROR
smbconf_reg_open_path(TALLOC_CTX
*mem_ctx
,
77 struct smbconf_ctx
*ctx
,
79 uint32 desired_access
,
80 struct registry_key
**key
)
82 WERROR werr
= WERR_OK
;
85 DEBUG(1, ("Error: configuration is not open!\n"));
86 werr
= WERR_INVALID_PARAM
;
90 if (rpd(ctx
)->token
== NULL
) {
91 DEBUG(1, ("Error: token missing from smbconf_ctx. "
92 "was smbconf_init() called?\n"));
93 werr
= WERR_INVALID_PARAM
;
97 werr
= ctx
->ops
->open_conf(ctx
);
98 if (!W_ERROR_IS_OK(werr
)) {
99 DEBUG(1, ("Error opening the registry.\n"));
104 DEBUG(1, ("Error: NULL path string given\n"));
105 werr
= WERR_INVALID_PARAM
;
109 werr
= reg_open_path(mem_ctx
, path
, desired_access
, rpd(ctx
)->token
,
112 if (!W_ERROR_IS_OK(werr
)) {
113 DEBUG(1, ("Error opening registry path '%s': %s\n",
114 path
, dos_errstr(werr
)));
122 * Open a subkey of the base key (i.e a service)
124 static WERROR
smbconf_reg_open_service_key(TALLOC_CTX
*mem_ctx
,
125 struct smbconf_ctx
*ctx
,
126 const char *servicename
,
127 uint32 desired_access
,
128 struct registry_key
**key
)
130 WERROR werr
= WERR_OK
;
133 if (servicename
== NULL
) {
134 path
= talloc_strdup(mem_ctx
, ctx
->path
);
136 path
= talloc_asprintf(mem_ctx
, "%s\\%s", ctx
->path
,
144 werr
= smbconf_reg_open_path(mem_ctx
, ctx
, path
, desired_access
, key
);
154 static WERROR
smbconf_reg_open_base_key(TALLOC_CTX
*mem_ctx
,
155 struct smbconf_ctx
*ctx
,
156 uint32 desired_access
,
157 struct registry_key
**key
)
159 return smbconf_reg_open_path(mem_ctx
, ctx
, ctx
->path
, desired_access
,
164 * check if a value exists in a given registry key
166 static bool smbconf_value_exists(struct registry_key
*key
, const char *param
)
169 WERROR werr
= WERR_OK
;
170 TALLOC_CTX
*ctx
= talloc_stackframe();
171 struct registry_value
*value
= NULL
;
173 werr
= reg_queryvalue(ctx
, key
, param
, &value
);
174 if (W_ERROR_IS_OK(werr
)) {
183 * create a subkey of the base key (i.e. a service...)
185 static WERROR
smbconf_reg_create_service_key(TALLOC_CTX
*mem_ctx
,
186 struct smbconf_ctx
*ctx
,
187 const char * subkeyname
,
188 struct registry_key
**newkey
)
190 WERROR werr
= WERR_OK
;
191 struct registry_key
*create_parent
= NULL
;
192 TALLOC_CTX
*create_ctx
;
193 enum winreg_CreateAction action
= REG_ACTION_NONE
;
195 /* create a new talloc ctx for creation. it will hold
196 * the intermediate parent key (SMBCONF) for creation
197 * and will be destroyed when leaving this function... */
198 if (!(create_ctx
= talloc_stackframe())) {
203 werr
= smbconf_reg_open_base_key(create_ctx
, ctx
, REG_KEY_WRITE
,
205 if (!W_ERROR_IS_OK(werr
)) {
209 werr
= reg_createkey(mem_ctx
, create_parent
, subkeyname
,
210 REG_KEY_WRITE
, newkey
, &action
);
211 if (W_ERROR_IS_OK(werr
) && (action
!= REG_CREATED_NEW_KEY
)) {
212 DEBUG(10, ("Key '%s' already exists.\n", subkeyname
));
213 werr
= WERR_ALREADY_EXISTS
;
215 if (!W_ERROR_IS_OK(werr
)) {
216 DEBUG(5, ("Error creating key %s: %s\n",
217 subkeyname
, dos_errstr(werr
)));
221 TALLOC_FREE(create_ctx
);
226 * add a value to a key.
228 static WERROR
smbconf_reg_set_value(struct registry_key
*key
,
232 struct registry_value val
;
233 WERROR werr
= WERR_OK
;
235 const char *canon_valname
;
236 const char *canon_valstr
;
238 if (!lp_canonicalize_parameter_with_value(valname
, valstr
,
242 if (canon_valname
== NULL
) {
243 DEBUG(5, ("invalid parameter '%s' given\n",
246 DEBUG(5, ("invalid value '%s' given for "
247 "parameter '%s'\n", valstr
, valname
));
249 werr
= WERR_INVALID_PARAM
;
253 if (smbconf_reg_valname_forbidden(canon_valname
)) {
254 DEBUG(5, ("Parameter '%s' not allowed in registry.\n",
256 werr
= WERR_INVALID_PARAM
;
260 subkeyname
= strrchr_m(key
->key
->name
, '\\');
261 if ((subkeyname
== NULL
) || (*(subkeyname
+1) == '\0')) {
262 DEBUG(5, ("Invalid registry key '%s' given as "
263 "smbconf section.\n", key
->key
->name
));
264 werr
= WERR_INVALID_PARAM
;
268 if (!strequal(subkeyname
, GLOBAL_NAME
) &&
269 lp_parameter_is_global(valname
))
271 DEBUG(5, ("Global paramter '%s' not allowed in "
272 "service definition ('%s').\n", canon_valname
,
274 werr
= WERR_INVALID_PARAM
;
281 val
.v
.sz
.str
= CONST_DISCARD(char *, canon_valstr
);
282 val
.v
.sz
.len
= strlen(canon_valstr
) + 1;
284 werr
= reg_setvalue(key
, canon_valname
, &val
);
285 if (!W_ERROR_IS_OK(werr
)) {
286 DEBUG(5, ("Error adding value '%s' to "
288 canon_valname
, key
->key
->name
, dos_errstr(werr
)));
295 static WERROR
smbconf_reg_set_multi_sz_value(struct registry_key
*key
,
297 const uint32_t num_strings
,
298 const char **strings
)
301 struct registry_value
*value
;
303 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
305 if (strings
== NULL
) {
306 werr
= WERR_INVALID_PARAM
;
310 value
= TALLOC_ZERO_P(tmp_ctx
, struct registry_value
);
312 value
->type
= REG_MULTI_SZ
;
313 value
->v
.multi_sz
.num_strings
= num_strings
;
314 value
->v
.multi_sz
.strings
= TALLOC_ARRAY(tmp_ctx
, char *, num_strings
);
315 if (value
->v
.multi_sz
.strings
== NULL
) {
319 for (count
= 0; count
< num_strings
; count
++) {
320 value
->v
.multi_sz
.strings
[count
] =
321 talloc_strdup(value
->v
.multi_sz
.strings
,
323 if (value
->v
.multi_sz
.strings
[count
] == NULL
) {
329 werr
= reg_setvalue(key
, valname
, value
);
330 if (!W_ERROR_IS_OK(werr
)) {
331 DEBUG(5, ("Error adding value '%s' to key '%s': %s\n",
332 valname
, key
->key
->name
, dos_errstr(werr
)));
336 TALLOC_FREE(tmp_ctx
);
341 * format a registry_value into a string.
343 * This is intended to be used for smbconf registry values,
344 * which are ar stored as REG_SZ values, so the incomplete
345 * handling should be ok.
347 static char *smbconf_format_registry_value(TALLOC_CTX
*mem_ctx
,
348 struct registry_value
*value
)
352 /* alternatively, create a new talloc context? */
353 if (mem_ctx
== NULL
) {
357 switch (value
->type
) {
359 result
= talloc_asprintf(mem_ctx
, "%d", value
->v
.dword
);
363 result
= talloc_asprintf(mem_ctx
, "%s", value
->v
.sz
.str
);
367 for (j
= 0; j
< value
->v
.multi_sz
.num_strings
; j
++) {
368 result
= talloc_asprintf(mem_ctx
, "%s\"%s\" ",
369 result
? result
: "" ,
370 value
->v
.multi_sz
.strings
[j
]);
371 if (result
== NULL
) {
378 result
= talloc_asprintf(mem_ctx
, "binary (%d bytes)",
379 (int)value
->v
.binary
.length
);
382 result
= talloc_asprintf(mem_ctx
, "<unprintable>");
388 static WERROR
smbconf_reg_get_includes_internal(TALLOC_CTX
*mem_ctx
,
389 struct registry_key
*key
,
390 uint32_t *num_includes
,
395 struct registry_value
*value
= NULL
;
396 char **tmp_includes
= NULL
;
397 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
399 if (!smbconf_value_exists(key
, INCLUDES_VALNAME
)) {
407 werr
= reg_queryvalue(tmp_ctx
, key
, INCLUDES_VALNAME
, &value
);
408 if (!W_ERROR_IS_OK(werr
)) {
412 if (value
->type
!= REG_MULTI_SZ
) {
413 /* wront type -- ignore */
417 for (count
= 0; count
< value
->v
.multi_sz
.num_strings
; count
++)
419 werr
= smbconf_add_string_to_array(tmp_ctx
,
422 value
->v
.multi_sz
.strings
[count
]);
423 if (!W_ERROR_IS_OK(werr
)) {
429 *includes
= talloc_move(mem_ctx
, &tmp_includes
);
430 if (*includes
== NULL
) {
434 *num_includes
= count
;
441 TALLOC_FREE(tmp_ctx
);
446 * Get the values of a key as a list of value names
447 * and a list of value strings (ordered)
449 static WERROR
smbconf_reg_get_values(TALLOC_CTX
*mem_ctx
,
450 struct registry_key
*key
,
451 uint32_t *num_values
,
453 char ***value_strings
)
455 TALLOC_CTX
*tmp_ctx
= NULL
;
456 WERROR werr
= WERR_OK
;
458 struct registry_value
*valvalue
= NULL
;
459 char *valname
= NULL
;
460 uint32_t tmp_num_values
= 0;
461 char **tmp_valnames
= NULL
;
462 char **tmp_valstrings
= NULL
;
463 uint32_t num_includes
= 0;
464 char **includes
= NULL
;
466 if ((num_values
== NULL
) || (value_names
== NULL
) ||
467 (value_strings
== NULL
))
469 werr
= WERR_INVALID_PARAM
;
473 tmp_ctx
= talloc_stackframe();
474 if (tmp_ctx
== NULL
) {
480 werr
= reg_enumvalue(tmp_ctx
, key
, count
, &valname
, &valvalue
),
486 if (!smbconf_reg_valname_valid(valname
)) {
490 werr
= smbconf_add_string_to_array(tmp_ctx
,
492 tmp_num_values
, valname
);
493 if (!W_ERROR_IS_OK(werr
)) {
497 valstring
= smbconf_format_registry_value(tmp_ctx
, valvalue
);
498 werr
= smbconf_add_string_to_array(tmp_ctx
, &tmp_valstrings
,
499 tmp_num_values
, valstring
);
500 if (!W_ERROR_IS_OK(werr
)) {
505 if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS
, werr
)) {
509 /* now add the includes at the end */
510 werr
= smbconf_reg_get_includes_internal(tmp_ctx
, key
, &num_includes
,
512 if (!W_ERROR_IS_OK(werr
)) {
515 for (count
= 0; count
< num_includes
; count
++) {
516 werr
= smbconf_add_string_to_array(tmp_ctx
, &tmp_valnames
,
517 tmp_num_values
, "include");
518 if (!W_ERROR_IS_OK(werr
)) {
522 werr
= smbconf_add_string_to_array(tmp_ctx
, &tmp_valstrings
,
525 if (!W_ERROR_IS_OK(werr
)) {
532 *num_values
= tmp_num_values
;
533 if (tmp_num_values
> 0) {
534 *value_names
= talloc_move(mem_ctx
, &tmp_valnames
);
535 *value_strings
= talloc_move(mem_ctx
, &tmp_valstrings
);
538 *value_strings
= NULL
;
542 TALLOC_FREE(tmp_ctx
);
546 static bool smbconf_reg_key_has_values(struct registry_key
*key
)
549 uint32_t num_subkeys
;
550 uint32_t max_subkeylen
;
551 uint32_t max_subkeysize
;
553 uint32_t max_valnamelen
;
554 uint32_t max_valbufsize
;
555 uint32_t secdescsize
;
556 NTTIME last_changed_time
;
558 werr
= reg_queryinfokey(key
, &num_subkeys
, &max_subkeylen
,
559 &max_subkeysize
, &num_values
, &max_valnamelen
,
560 &max_valbufsize
, &secdescsize
,
562 if (!W_ERROR_IS_OK(werr
)) {
566 return (num_values
!= 0);
570 * delete all values from a key
572 static WERROR
smbconf_reg_delete_values(struct registry_key
*key
)
576 struct registry_value
*valvalue
;
578 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
581 werr
= reg_enumvalue(mem_ctx
, key
, count
, &valname
, &valvalue
),
585 werr
= reg_deletevalue(key
, valname
);
586 if (!W_ERROR_IS_OK(werr
)) {
590 if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS
, werr
)) {
591 DEBUG(1, ("smbconf_reg_delete_values: "
592 "Error enumerating values of %s: %s\n",
601 TALLOC_FREE(mem_ctx
);
605 /**********************************************************************
607 * smbconf operations: registry implementations
609 **********************************************************************/
612 * initialize the registry smbconf backend
614 static WERROR
smbconf_reg_init(struct smbconf_ctx
*ctx
, const char *path
)
616 WERROR werr
= WERR_OK
;
621 ctx
->path
= talloc_strdup(ctx
, path
);
622 if (ctx
->path
== NULL
) {
627 ctx
->data
= TALLOC_ZERO_P(ctx
, struct reg_private_data
);
629 werr
= ntstatus_to_werror(registry_create_admin_token(ctx
,
630 &(rpd(ctx
)->token
)));
631 if (!W_ERROR_IS_OK(werr
)) {
632 DEBUG(1, ("Error creating admin token\n"));
635 rpd(ctx
)->open
= false;
637 werr
= registry_init_smbconf(path
);
638 if (!W_ERROR_IS_OK(werr
)) {
646 static int smbconf_reg_shutdown(struct smbconf_ctx
*ctx
)
648 return ctx
->ops
->close_conf(ctx
);
651 static WERROR
smbconf_reg_open(struct smbconf_ctx
*ctx
)
655 if (rpd(ctx
)->open
) {
660 if (W_ERROR_IS_OK(werr
)) {
661 rpd(ctx
)->open
= true;
666 static int smbconf_reg_close(struct smbconf_ctx
*ctx
)
670 if (!rpd(ctx
)->open
) {
676 rpd(ctx
)->open
= false;
682 * Get the change sequence number of the given service/parameter.
683 * service and parameter strings may be NULL.
685 static void smbconf_reg_get_csn(struct smbconf_ctx
*ctx
,
686 struct smbconf_csn
*csn
,
687 const char *service
, const char *param
)
693 if (!W_ERROR_IS_OK(ctx
->ops
->open_conf(ctx
))) {
697 csn
->csn
= (uint64_t)regdb_get_seqnum();
701 * Drop the whole configuration (restarting empty) - registry version
703 static WERROR
smbconf_reg_drop(struct smbconf_ctx
*ctx
)
706 WERROR werr
= WERR_OK
;
707 struct registry_key
*parent_key
= NULL
;
708 struct registry_key
*new_key
= NULL
;
709 TALLOC_CTX
* mem_ctx
= talloc_stackframe();
710 enum winreg_CreateAction action
;
712 path
= talloc_strdup(mem_ctx
, ctx
->path
);
717 p
= strrchr(path
, '\\');
719 werr
= smbconf_reg_open_path(mem_ctx
, ctx
, path
, REG_KEY_WRITE
,
722 if (!W_ERROR_IS_OK(werr
)) {
726 werr
= reg_deletekey_recursive(mem_ctx
, parent_key
, p
+1);
728 if (!W_ERROR_IS_OK(werr
)) {
732 werr
= reg_createkey(mem_ctx
, parent_key
, p
+1, REG_KEY_WRITE
,
736 TALLOC_FREE(mem_ctx
);
741 * get the list of share names defined in the configuration.
744 static WERROR
smbconf_reg_get_share_names(struct smbconf_ctx
*ctx
,
746 uint32_t *num_shares
,
750 uint32_t added_count
= 0;
751 TALLOC_CTX
*tmp_ctx
= NULL
;
752 WERROR werr
= WERR_OK
;
753 struct registry_key
*key
= NULL
;
754 char *subkey_name
= NULL
;
755 char **tmp_share_names
= NULL
;
757 if ((num_shares
== NULL
) || (share_names
== NULL
)) {
758 werr
= WERR_INVALID_PARAM
;
762 tmp_ctx
= talloc_stackframe();
763 if (tmp_ctx
== NULL
) {
768 /* if there are values in the base key, return NULL as share name */
769 werr
= smbconf_reg_open_base_key(tmp_ctx
, ctx
,
770 SEC_RIGHTS_ENUM_SUBKEYS
, &key
);
771 if (!W_ERROR_IS_OK(werr
)) {
775 if (smbconf_reg_key_has_values(key
)) {
776 werr
= smbconf_add_string_to_array(tmp_ctx
, &tmp_share_names
,
778 if (!W_ERROR_IS_OK(werr
)) {
784 /* make sure "global" is always listed first */
785 if (smbconf_share_exists(ctx
, GLOBAL_NAME
)) {
786 werr
= smbconf_add_string_to_array(tmp_ctx
, &tmp_share_names
,
788 if (!W_ERROR_IS_OK(werr
)) {
795 werr
= reg_enumkey(tmp_ctx
, key
, count
, &subkey_name
, NULL
),
799 if (strequal(subkey_name
, GLOBAL_NAME
)) {
803 werr
= smbconf_add_string_to_array(tmp_ctx
,
807 if (!W_ERROR_IS_OK(werr
)) {
812 if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS
, werr
)) {
817 *num_shares
= added_count
;
818 if (added_count
> 0) {
819 *share_names
= talloc_move(mem_ctx
, &tmp_share_names
);
825 TALLOC_FREE(tmp_ctx
);
830 * check if a share/service of a given name exists - registry version
832 static bool smbconf_reg_share_exists(struct smbconf_ctx
*ctx
,
833 const char *servicename
)
836 WERROR werr
= WERR_OK
;
837 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
838 struct registry_key
*key
= NULL
;
840 werr
= smbconf_reg_open_service_key(mem_ctx
, ctx
, servicename
,
842 if (W_ERROR_IS_OK(werr
)) {
846 TALLOC_FREE(mem_ctx
);
851 * Add a service if it does not already exist - registry version
853 static WERROR
smbconf_reg_create_share(struct smbconf_ctx
*ctx
,
854 const char *servicename
)
857 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
858 struct registry_key
*key
= NULL
;
860 if (servicename
== NULL
) {
861 werr
= smbconf_reg_open_base_key(mem_ctx
, ctx
, REG_KEY_WRITE
,
864 werr
= smbconf_reg_create_service_key(mem_ctx
, ctx
,
868 TALLOC_FREE(mem_ctx
);
873 * get a definition of a share (service) from configuration.
875 static WERROR
smbconf_reg_get_share(struct smbconf_ctx
*ctx
,
877 const char *servicename
,
878 uint32_t *num_params
,
879 char ***param_names
, char ***param_values
)
881 WERROR werr
= WERR_OK
;
882 struct registry_key
*key
= NULL
;
884 werr
= smbconf_reg_open_service_key(mem_ctx
, ctx
, servicename
,
886 if (!W_ERROR_IS_OK(werr
)) {
890 werr
= smbconf_reg_get_values(mem_ctx
, key
, num_params
,
891 param_names
, param_values
);
899 * delete a service from configuration
901 static WERROR
smbconf_reg_delete_share(struct smbconf_ctx
*ctx
,
902 const char *servicename
)
904 WERROR werr
= WERR_OK
;
905 struct registry_key
*key
= NULL
;
906 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
908 werr
= smbconf_reg_open_base_key(mem_ctx
, ctx
, REG_KEY_WRITE
, &key
);
909 if (!W_ERROR_IS_OK(werr
)) {
913 if (servicename
!= NULL
) {
914 werr
= reg_deletekey_recursive(key
, key
, servicename
);
916 werr
= smbconf_reg_delete_values(key
);
920 TALLOC_FREE(mem_ctx
);
925 * set a configuration parameter to the value provided.
927 static WERROR
smbconf_reg_set_parameter(struct smbconf_ctx
*ctx
,
933 struct registry_key
*key
= NULL
;
934 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
936 werr
= smbconf_reg_open_service_key(mem_ctx
, ctx
, service
,
937 REG_KEY_WRITE
, &key
);
938 if (!W_ERROR_IS_OK(werr
)) {
942 werr
= smbconf_reg_set_value(key
, param
, valstr
);
945 TALLOC_FREE(mem_ctx
);
950 * get the value of a configuration parameter as a string
952 static WERROR
smbconf_reg_get_parameter(struct smbconf_ctx
*ctx
,
958 WERROR werr
= WERR_OK
;
959 struct registry_key
*key
= NULL
;
960 struct registry_value
*value
= NULL
;
962 werr
= smbconf_reg_open_service_key(mem_ctx
, ctx
, service
,
964 if (!W_ERROR_IS_OK(werr
)) {
968 if (!smbconf_reg_valname_valid(param
)) {
969 werr
= WERR_INVALID_PARAM
;
973 if (!smbconf_value_exists(key
, param
)) {
974 werr
= WERR_INVALID_PARAM
;
978 werr
= reg_queryvalue(mem_ctx
, key
, param
, &value
);
979 if (!W_ERROR_IS_OK(werr
)) {
983 *valstr
= smbconf_format_registry_value(mem_ctx
, value
);
985 if (*valstr
== NULL
) {
996 * delete a parameter from configuration
998 static WERROR
smbconf_reg_delete_parameter(struct smbconf_ctx
*ctx
,
1002 struct registry_key
*key
= NULL
;
1003 WERROR werr
= WERR_OK
;
1004 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
1006 werr
= smbconf_reg_open_service_key(mem_ctx
, ctx
, service
,
1008 if (!W_ERROR_IS_OK(werr
)) {
1012 if (!smbconf_reg_valname_valid(param
)) {
1013 werr
= WERR_INVALID_PARAM
;
1017 if (!smbconf_value_exists(key
, param
)) {
1018 werr
= WERR_INVALID_PARAM
;
1022 werr
= reg_deletevalue(key
, param
);
1025 TALLOC_FREE(mem_ctx
);
1029 static WERROR
smbconf_reg_get_includes(struct smbconf_ctx
*ctx
,
1030 TALLOC_CTX
*mem_ctx
,
1031 const char *service
,
1032 uint32_t *num_includes
,
1036 struct registry_key
*key
= NULL
;
1037 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
1039 werr
= smbconf_reg_open_service_key(tmp_ctx
, ctx
, service
,
1040 REG_KEY_READ
, &key
);
1041 if (!W_ERROR_IS_OK(werr
)) {
1045 werr
= smbconf_reg_get_includes_internal(mem_ctx
, key
, num_includes
,
1049 TALLOC_FREE(tmp_ctx
);
1053 static WERROR
smbconf_reg_set_includes(struct smbconf_ctx
*ctx
,
1054 const char *service
,
1055 uint32_t num_includes
,
1056 const char **includes
)
1058 WERROR werr
= WERR_OK
;
1059 struct registry_key
*key
= NULL
;
1060 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
1062 werr
= smbconf_reg_open_service_key(tmp_ctx
, ctx
, service
,
1064 if (!W_ERROR_IS_OK(werr
)) {
1068 if (num_includes
== 0) {
1069 if (!smbconf_value_exists(key
, INCLUDES_VALNAME
)) {
1072 werr
= reg_deletevalue(key
, INCLUDES_VALNAME
);
1074 werr
= smbconf_reg_set_multi_sz_value(key
, INCLUDES_VALNAME
,
1075 num_includes
, includes
);
1079 TALLOC_FREE(tmp_ctx
);
1083 static WERROR
smbconf_reg_delete_includes(struct smbconf_ctx
*ctx
,
1084 const char *service
)
1086 WERROR werr
= WERR_OK
;
1087 struct registry_key
*key
= NULL
;
1088 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
1090 werr
= smbconf_reg_open_service_key(tmp_ctx
, ctx
, service
,
1092 if (!W_ERROR_IS_OK(werr
)) {
1096 if (!smbconf_value_exists(key
, INCLUDES_VALNAME
)) {
1100 werr
= reg_deletevalue(key
, INCLUDES_VALNAME
);
1104 TALLOC_FREE(tmp_ctx
);
1108 struct smbconf_ops smbconf_ops_reg
= {
1109 .init
= smbconf_reg_init
,
1110 .shutdown
= smbconf_reg_shutdown
,
1111 .open_conf
= smbconf_reg_open
,
1112 .close_conf
= smbconf_reg_close
,
1113 .get_csn
= smbconf_reg_get_csn
,
1114 .drop
= smbconf_reg_drop
,
1115 .get_share_names
= smbconf_reg_get_share_names
,
1116 .share_exists
= smbconf_reg_share_exists
,
1117 .create_share
= smbconf_reg_create_share
,
1118 .get_share
= smbconf_reg_get_share
,
1119 .delete_share
= smbconf_reg_delete_share
,
1120 .set_parameter
= smbconf_reg_set_parameter
,
1121 .get_parameter
= smbconf_reg_get_parameter
,
1122 .delete_parameter
= smbconf_reg_delete_parameter
,
1123 .get_includes
= smbconf_reg_get_includes
,
1124 .set_includes
= smbconf_reg_set_includes
,
1125 .delete_includes
= smbconf_reg_delete_includes
,
1130 * initialize the smbconf registry backend
1131 * the only function that is exported from this module
1133 WERROR
smbconf_init_reg(TALLOC_CTX
*mem_ctx
, struct smbconf_ctx
**conf_ctx
,
1136 return smbconf_init_internal(mem_ctx
, conf_ctx
, path
, &smbconf_ops_reg
);