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 "lib/smbconf/smbconf_private.h"
23 #include "registry/reg_backend_db.h"
24 #include "lib/smbconf/smbconf_init.h"
25 #include "lib/smbconf/smbconf_reg.h"
27 #define INCLUDES_VALNAME "includes"
29 struct reg_private_data
{
30 struct registry_key
*base_key
;
31 bool open
; /* did _we_ open the registry? */
34 /**********************************************************************
38 **********************************************************************/
41 * a convenience helper to cast the private data structure
43 static struct reg_private_data
*rpd(struct smbconf_ctx
*ctx
)
45 return (struct reg_private_data
*)(ctx
->data
);
49 * check whether a given value name is forbidden in registry (smbconf)
51 static bool smbconf_reg_valname_forbidden(const char *valname
)
53 /* hard code the list of forbidden names here for now */
54 const char *forbidden_valnames
[] = {
59 "includes", /* this has a special meaning internally */
62 const char **forbidden
= NULL
;
64 for (forbidden
= forbidden_valnames
; *forbidden
!= NULL
; forbidden
++) {
65 if (strwicmp(valname
, *forbidden
) == 0) {
72 static bool smbconf_reg_valname_valid(const char *valname
)
74 return (!smbconf_reg_valname_forbidden(valname
) &&
75 lp_parameter_is_valid(valname
));
79 * Open a subkey of the base key (i.e a service)
81 static WERROR
smbconf_reg_open_service_key(TALLOC_CTX
*mem_ctx
,
82 struct smbconf_ctx
*ctx
,
83 const char *servicename
,
84 uint32 desired_access
,
85 struct registry_key
**key
)
89 if (servicename
== NULL
) {
90 *key
= rpd(ctx
)->base_key
;
93 werr
= reg_openkey(mem_ctx
, rpd(ctx
)->base_key
, servicename
,
96 if (W_ERROR_EQUAL(werr
, WERR_BADFILE
)) {
97 werr
= WERR_NO_SUCH_SERVICE
;
104 * check if a value exists in a given registry key
106 static bool smbconf_value_exists(struct registry_key
*key
, const char *param
)
109 WERROR werr
= WERR_OK
;
110 TALLOC_CTX
*ctx
= talloc_stackframe();
111 struct registry_value
*value
= NULL
;
113 werr
= reg_queryvalue(ctx
, key
, param
, &value
);
114 if (W_ERROR_IS_OK(werr
)) {
123 * create a subkey of the base key (i.e. a service...)
125 static WERROR
smbconf_reg_create_service_key(TALLOC_CTX
*mem_ctx
,
126 struct smbconf_ctx
*ctx
,
127 const char * subkeyname
,
128 struct registry_key
**newkey
)
130 WERROR werr
= WERR_OK
;
131 TALLOC_CTX
*create_ctx
;
132 enum winreg_CreateAction action
= REG_ACTION_NONE
;
134 /* create a new talloc ctx for creation. it will hold
135 * the intermediate parent key (SMBCONF) for creation
136 * and will be destroyed when leaving this function... */
137 create_ctx
= talloc_stackframe();
139 werr
= reg_createkey(mem_ctx
, rpd(ctx
)->base_key
, subkeyname
,
140 REG_KEY_WRITE
, newkey
, &action
);
141 if (W_ERROR_IS_OK(werr
) && (action
!= REG_CREATED_NEW_KEY
)) {
142 DEBUG(10, ("Key '%s' already exists.\n", subkeyname
));
143 werr
= WERR_FILE_EXISTS
;
145 if (!W_ERROR_IS_OK(werr
)) {
146 DEBUG(5, ("Error creating key %s: %s\n",
147 subkeyname
, win_errstr(werr
)));
150 talloc_free(create_ctx
);
155 * add a value to a key.
157 static WERROR
smbconf_reg_set_value(struct registry_key
*key
,
161 struct registry_value val
;
162 WERROR werr
= WERR_OK
;
164 const char *canon_valname
;
165 const char *canon_valstr
;
167 if (!lp_canonicalize_parameter_with_value(valname
, valstr
,
171 if (canon_valname
== NULL
) {
172 DEBUG(5, ("invalid parameter '%s' given\n",
175 DEBUG(5, ("invalid value '%s' given for "
176 "parameter '%s'\n", valstr
, valname
));
178 werr
= WERR_INVALID_PARAM
;
182 if (smbconf_reg_valname_forbidden(canon_valname
)) {
183 DEBUG(5, ("Parameter '%s' not allowed in registry.\n",
185 werr
= WERR_INVALID_PARAM
;
189 subkeyname
= strrchr_m(key
->key
->name
, '\\');
190 if ((subkeyname
== NULL
) || (*(subkeyname
+1) == '\0')) {
191 DEBUG(5, ("Invalid registry key '%s' given as "
192 "smbconf section.\n", key
->key
->name
));
193 werr
= WERR_INVALID_PARAM
;
197 if (!strequal(subkeyname
, GLOBAL_NAME
) &&
198 lp_parameter_is_global(valname
))
200 DEBUG(5, ("Global parameter '%s' not allowed in "
201 "service definition ('%s').\n", canon_valname
,
203 werr
= WERR_INVALID_PARAM
;
210 val
.v
.sz
.str
= CONST_DISCARD(char *, canon_valstr
);
211 val
.v
.sz
.len
= strlen(canon_valstr
) + 1;
213 werr
= reg_setvalue(key
, canon_valname
, &val
);
214 if (!W_ERROR_IS_OK(werr
)) {
215 DEBUG(5, ("Error adding value '%s' to "
217 canon_valname
, key
->key
->name
, win_errstr(werr
)));
224 static WERROR
smbconf_reg_set_multi_sz_value(struct registry_key
*key
,
226 const uint32_t num_strings
,
227 const char **strings
)
230 struct registry_value
*value
;
232 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
234 if (strings
== NULL
) {
235 werr
= WERR_INVALID_PARAM
;
239 value
= TALLOC_ZERO_P(tmp_ctx
, struct registry_value
);
241 value
->type
= REG_MULTI_SZ
;
242 value
->v
.multi_sz
.num_strings
= num_strings
;
243 value
->v
.multi_sz
.strings
= TALLOC_ARRAY(tmp_ctx
, char *, num_strings
);
244 if (value
->v
.multi_sz
.strings
== NULL
) {
248 for (count
= 0; count
< num_strings
; count
++) {
249 value
->v
.multi_sz
.strings
[count
] =
250 talloc_strdup(value
->v
.multi_sz
.strings
,
252 if (value
->v
.multi_sz
.strings
[count
] == NULL
) {
258 werr
= reg_setvalue(key
, valname
, value
);
259 if (!W_ERROR_IS_OK(werr
)) {
260 DEBUG(5, ("Error adding value '%s' to key '%s': %s\n",
261 valname
, key
->key
->name
, win_errstr(werr
)));
265 talloc_free(tmp_ctx
);
270 * format a registry_value into a string.
272 * This is intended to be used for smbconf registry values,
273 * which are ar stored as REG_SZ values, so the incomplete
274 * handling should be ok.
276 static char *smbconf_format_registry_value(TALLOC_CTX
*mem_ctx
,
277 struct registry_value
*value
)
281 /* alternatively, create a new talloc context? */
282 if (mem_ctx
== NULL
) {
286 switch (value
->type
) {
288 result
= talloc_asprintf(mem_ctx
, "%d", value
->v
.dword
);
292 result
= talloc_asprintf(mem_ctx
, "%s", value
->v
.sz
.str
);
296 for (j
= 0; j
< value
->v
.multi_sz
.num_strings
; j
++) {
297 result
= talloc_asprintf(mem_ctx
, "%s\"%s\" ",
298 result
? result
: "" ,
299 value
->v
.multi_sz
.strings
[j
]);
300 if (result
== NULL
) {
307 result
= talloc_asprintf(mem_ctx
, "binary (%d bytes)",
308 (int)value
->v
.binary
.length
);
311 result
= talloc_asprintf(mem_ctx
, "<unprintable>");
317 static WERROR
smbconf_reg_get_includes_internal(TALLOC_CTX
*mem_ctx
,
318 struct registry_key
*key
,
319 uint32_t *num_includes
,
324 struct registry_value
*value
= NULL
;
325 char **tmp_includes
= NULL
;
326 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
328 if (!smbconf_value_exists(key
, INCLUDES_VALNAME
)) {
336 werr
= reg_queryvalue(tmp_ctx
, key
, INCLUDES_VALNAME
, &value
);
337 if (!W_ERROR_IS_OK(werr
)) {
341 if (value
->type
!= REG_MULTI_SZ
) {
342 /* wrong type -- ignore */
346 for (count
= 0; count
< value
->v
.multi_sz
.num_strings
; count
++)
348 werr
= smbconf_add_string_to_array(tmp_ctx
,
351 value
->v
.multi_sz
.strings
[count
]);
352 if (!W_ERROR_IS_OK(werr
)) {
358 *includes
= talloc_move(mem_ctx
, &tmp_includes
);
359 if (*includes
== NULL
) {
363 *num_includes
= count
;
370 talloc_free(tmp_ctx
);
375 * Get the values of a key as a list of value names
376 * and a list of value strings (ordered)
378 static WERROR
smbconf_reg_get_values(TALLOC_CTX
*mem_ctx
,
379 struct registry_key
*key
,
380 uint32_t *num_values
,
382 char ***value_strings
)
384 TALLOC_CTX
*tmp_ctx
= NULL
;
385 WERROR werr
= WERR_OK
;
387 struct registry_value
*valvalue
= NULL
;
388 char *valname
= NULL
;
389 uint32_t tmp_num_values
= 0;
390 char **tmp_valnames
= NULL
;
391 char **tmp_valstrings
= NULL
;
392 uint32_t num_includes
= 0;
393 char **includes
= NULL
;
395 if ((num_values
== NULL
) || (value_names
== NULL
) ||
396 (value_strings
== NULL
))
398 werr
= WERR_INVALID_PARAM
;
402 tmp_ctx
= talloc_stackframe();
405 werr
= reg_enumvalue(tmp_ctx
, key
, count
, &valname
, &valvalue
),
411 if (!smbconf_reg_valname_valid(valname
)) {
415 werr
= smbconf_add_string_to_array(tmp_ctx
,
417 tmp_num_values
, valname
);
418 if (!W_ERROR_IS_OK(werr
)) {
422 valstring
= smbconf_format_registry_value(tmp_ctx
, valvalue
);
423 werr
= smbconf_add_string_to_array(tmp_ctx
, &tmp_valstrings
,
424 tmp_num_values
, valstring
);
425 if (!W_ERROR_IS_OK(werr
)) {
430 if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS
, werr
)) {
434 /* now add the includes at the end */
435 werr
= smbconf_reg_get_includes_internal(tmp_ctx
, key
, &num_includes
,
437 if (!W_ERROR_IS_OK(werr
)) {
440 for (count
= 0; count
< num_includes
; count
++) {
441 werr
= smbconf_add_string_to_array(tmp_ctx
, &tmp_valnames
,
442 tmp_num_values
, "include");
443 if (!W_ERROR_IS_OK(werr
)) {
447 werr
= smbconf_add_string_to_array(tmp_ctx
, &tmp_valstrings
,
450 if (!W_ERROR_IS_OK(werr
)) {
457 *num_values
= tmp_num_values
;
458 if (tmp_num_values
> 0) {
459 *value_names
= talloc_move(mem_ctx
, &tmp_valnames
);
460 *value_strings
= talloc_move(mem_ctx
, &tmp_valstrings
);
463 *value_strings
= NULL
;
467 talloc_free(tmp_ctx
);
471 static bool smbconf_reg_key_has_values(struct registry_key
*key
)
474 uint32_t num_subkeys
;
475 uint32_t max_subkeylen
;
476 uint32_t max_subkeysize
;
478 uint32_t max_valnamelen
;
479 uint32_t max_valbufsize
;
480 uint32_t secdescsize
;
481 NTTIME last_changed_time
;
483 werr
= reg_queryinfokey(key
, &num_subkeys
, &max_subkeylen
,
484 &max_subkeysize
, &num_values
, &max_valnamelen
,
485 &max_valbufsize
, &secdescsize
,
487 if (!W_ERROR_IS_OK(werr
)) {
491 return (num_values
!= 0);
495 * delete all values from a key
497 static WERROR
smbconf_reg_delete_values(struct registry_key
*key
)
501 struct registry_value
*valvalue
;
503 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
506 werr
= reg_enumvalue(mem_ctx
, key
, count
, &valname
, &valvalue
),
510 werr
= reg_deletevalue(key
, valname
);
511 if (!W_ERROR_IS_OK(werr
)) {
515 if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS
, werr
)) {
516 DEBUG(1, ("smbconf_reg_delete_values: "
517 "Error enumerating values of %s: %s\n",
526 talloc_free(mem_ctx
);
530 /**********************************************************************
532 * smbconf operations: registry implementations
534 **********************************************************************/
537 * initialize the registry smbconf backend
539 static WERROR
smbconf_reg_init(struct smbconf_ctx
*ctx
, const char *path
)
541 WERROR werr
= WERR_OK
;
542 struct nt_user_token
*token
;
547 ctx
->path
= talloc_strdup(ctx
, path
);
548 if (ctx
->path
== NULL
) {
553 ctx
->data
= TALLOC_ZERO_P(ctx
, struct reg_private_data
);
555 werr
= ntstatus_to_werror(registry_create_admin_token(ctx
, &token
));
556 if (!W_ERROR_IS_OK(werr
)) {
557 DEBUG(1, ("Error creating admin token\n"));
560 rpd(ctx
)->open
= false;
562 werr
= registry_init_smbconf(path
);
563 if (!W_ERROR_IS_OK(werr
)) {
567 werr
= ctx
->ops
->open_conf(ctx
);
568 if (!W_ERROR_IS_OK(werr
)) {
569 DEBUG(1, ("Error opening the registry.\n"));
573 werr
= reg_open_path(ctx
, ctx
->path
,
574 KEY_ENUMERATE_SUB_KEYS
| REG_KEY_WRITE
,
575 token
, &rpd(ctx
)->base_key
);
576 if (!W_ERROR_IS_OK(werr
)) {
584 static int smbconf_reg_shutdown(struct smbconf_ctx
*ctx
)
586 return ctx
->ops
->close_conf(ctx
);
589 static bool smbconf_reg_requires_messaging(struct smbconf_ctx
*ctx
)
591 #ifdef CLUSTER_SUPPORT
592 if (lp_clustering() && lp_parm_bool(-1, "ctdb", "registry.tdb", true)) {
599 static bool smbconf_reg_is_writeable(struct smbconf_ctx
*ctx
)
602 * The backend has write support.
604 * TODO: add access checks whether the concrete
605 * config source is really writeable by the calling user.
610 static WERROR
smbconf_reg_open(struct smbconf_ctx
*ctx
)
614 if (rpd(ctx
)->open
) {
619 if (W_ERROR_IS_OK(werr
)) {
620 rpd(ctx
)->open
= true;
625 static int smbconf_reg_close(struct smbconf_ctx
*ctx
)
629 if (!rpd(ctx
)->open
) {
635 rpd(ctx
)->open
= false;
641 * Get the change sequence number of the given service/parameter.
642 * service and parameter strings may be NULL.
644 static void smbconf_reg_get_csn(struct smbconf_ctx
*ctx
,
645 struct smbconf_csn
*csn
,
646 const char *service
, const char *param
)
652 if (!W_ERROR_IS_OK(ctx
->ops
->open_conf(ctx
))) {
656 csn
->csn
= (uint64_t)regdb_get_seqnum();
660 * Drop the whole configuration (restarting empty) - registry version
662 static WERROR
smbconf_reg_drop(struct smbconf_ctx
*ctx
)
665 WERROR werr
= WERR_OK
;
666 struct registry_key
*parent_key
= NULL
;
667 struct registry_key
*new_key
= NULL
;
668 TALLOC_CTX
* mem_ctx
= talloc_stackframe();
669 enum winreg_CreateAction action
;
670 struct nt_user_token
*token
;
672 werr
= ntstatus_to_werror(registry_create_admin_token(ctx
, &token
));
673 if (!W_ERROR_IS_OK(werr
)) {
674 DEBUG(1, ("Error creating admin token\n"));
678 path
= talloc_strdup(mem_ctx
, ctx
->path
);
683 p
= strrchr(path
, '\\');
685 werr
= reg_open_path(mem_ctx
, path
, REG_KEY_WRITE
, token
,
688 if (!W_ERROR_IS_OK(werr
)) {
692 werr
= reg_deletekey_recursive(mem_ctx
, parent_key
, p
+1);
694 if (!W_ERROR_IS_OK(werr
)) {
698 werr
= reg_createkey(mem_ctx
, parent_key
, p
+1, REG_KEY_WRITE
,
702 talloc_free(mem_ctx
);
707 * get the list of share names defined in the configuration.
710 static WERROR
smbconf_reg_get_share_names(struct smbconf_ctx
*ctx
,
712 uint32_t *num_shares
,
716 uint32_t added_count
= 0;
717 TALLOC_CTX
*tmp_ctx
= NULL
;
718 WERROR werr
= WERR_OK
;
719 char *subkey_name
= NULL
;
720 char **tmp_share_names
= NULL
;
722 if ((num_shares
== NULL
) || (share_names
== NULL
)) {
723 werr
= WERR_INVALID_PARAM
;
727 tmp_ctx
= talloc_stackframe();
729 /* if there are values in the base key, return NULL as share name */
731 if (smbconf_reg_key_has_values(rpd(ctx
)->base_key
)) {
732 werr
= smbconf_add_string_to_array(tmp_ctx
, &tmp_share_names
,
734 if (!W_ERROR_IS_OK(werr
)) {
740 /* make sure "global" is always listed first */
741 if (smbconf_share_exists(ctx
, GLOBAL_NAME
)) {
742 werr
= smbconf_add_string_to_array(tmp_ctx
, &tmp_share_names
,
743 added_count
, GLOBAL_NAME
);
744 if (!W_ERROR_IS_OK(werr
)) {
751 werr
= reg_enumkey(tmp_ctx
, rpd(ctx
)->base_key
, count
,
756 if (strequal(subkey_name
, GLOBAL_NAME
)) {
760 werr
= smbconf_add_string_to_array(tmp_ctx
,
764 if (!W_ERROR_IS_OK(werr
)) {
769 if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS
, werr
)) {
774 *num_shares
= added_count
;
775 if (added_count
> 0) {
776 *share_names
= talloc_move(mem_ctx
, &tmp_share_names
);
782 talloc_free(tmp_ctx
);
787 * check if a share/service of a given name exists - registry version
789 static bool smbconf_reg_share_exists(struct smbconf_ctx
*ctx
,
790 const char *servicename
)
793 WERROR werr
= WERR_OK
;
794 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
795 struct registry_key
*key
= NULL
;
797 werr
= smbconf_reg_open_service_key(mem_ctx
, ctx
, servicename
,
799 if (W_ERROR_IS_OK(werr
)) {
803 talloc_free(mem_ctx
);
808 * Add a service if it does not already exist - registry version
810 static WERROR
smbconf_reg_create_share(struct smbconf_ctx
*ctx
,
811 const char *servicename
)
814 struct registry_key
*key
= NULL
;
816 if (servicename
== NULL
) {
820 werr
= smbconf_reg_create_service_key(talloc_tos(), ctx
,
828 * get a definition of a share (service) from configuration.
830 static WERROR
smbconf_reg_get_share(struct smbconf_ctx
*ctx
,
832 const char *servicename
,
833 struct smbconf_service
**service
)
835 WERROR werr
= WERR_OK
;
836 struct registry_key
*key
= NULL
;
837 struct smbconf_service
*tmp_service
= NULL
;
838 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
840 werr
= smbconf_reg_open_service_key(tmp_ctx
, ctx
, servicename
,
842 if (!W_ERROR_IS_OK(werr
)) {
846 tmp_service
= TALLOC_ZERO_P(tmp_ctx
, struct smbconf_service
);
847 if (tmp_service
== NULL
) {
852 if (servicename
!= NULL
) {
853 tmp_service
->name
= talloc_strdup(tmp_service
, servicename
);
854 if (tmp_service
->name
== NULL
) {
860 werr
= smbconf_reg_get_values(tmp_service
, key
,
861 &(tmp_service
->num_params
),
862 &(tmp_service
->param_names
),
863 &(tmp_service
->param_values
));
865 if (W_ERROR_IS_OK(werr
)) {
866 *service
= talloc_move(mem_ctx
, &tmp_service
);
870 talloc_free(tmp_ctx
);
875 * delete a service from configuration
877 static WERROR
smbconf_reg_delete_share(struct smbconf_ctx
*ctx
,
878 const char *servicename
)
880 WERROR werr
= WERR_OK
;
881 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
883 if (servicename
!= NULL
) {
884 werr
= reg_deletekey_recursive(mem_ctx
, rpd(ctx
)->base_key
,
887 werr
= smbconf_reg_delete_values(rpd(ctx
)->base_key
);
890 talloc_free(mem_ctx
);
895 * set a configuration parameter to the value provided.
897 static WERROR
smbconf_reg_set_parameter(struct smbconf_ctx
*ctx
,
903 struct registry_key
*key
= NULL
;
904 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
906 werr
= smbconf_reg_open_service_key(mem_ctx
, ctx
, service
,
907 REG_KEY_WRITE
, &key
);
908 if (!W_ERROR_IS_OK(werr
)) {
912 werr
= smbconf_reg_set_value(key
, param
, valstr
);
915 talloc_free(mem_ctx
);
920 * get the value of a configuration parameter as a string
922 static WERROR
smbconf_reg_get_parameter(struct smbconf_ctx
*ctx
,
928 WERROR werr
= WERR_OK
;
929 struct registry_key
*key
= NULL
;
930 struct registry_value
*value
= NULL
;
932 werr
= smbconf_reg_open_service_key(mem_ctx
, ctx
, service
,
934 if (!W_ERROR_IS_OK(werr
)) {
938 if (!smbconf_reg_valname_valid(param
)) {
939 werr
= WERR_INVALID_PARAM
;
943 if (!smbconf_value_exists(key
, param
)) {
944 werr
= WERR_INVALID_PARAM
;
948 werr
= reg_queryvalue(mem_ctx
, key
, param
, &value
);
949 if (!W_ERROR_IS_OK(werr
)) {
953 *valstr
= smbconf_format_registry_value(mem_ctx
, value
);
955 if (*valstr
== NULL
) {
966 * delete a parameter from configuration
968 static WERROR
smbconf_reg_delete_parameter(struct smbconf_ctx
*ctx
,
972 struct registry_key
*key
= NULL
;
973 WERROR werr
= WERR_OK
;
974 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
976 werr
= smbconf_reg_open_service_key(mem_ctx
, ctx
, service
,
978 if (!W_ERROR_IS_OK(werr
)) {
982 if (!smbconf_reg_valname_valid(param
)) {
983 werr
= WERR_INVALID_PARAM
;
987 if (!smbconf_value_exists(key
, param
)) {
988 werr
= WERR_INVALID_PARAM
;
992 werr
= reg_deletevalue(key
, param
);
995 talloc_free(mem_ctx
);
999 static WERROR
smbconf_reg_get_includes(struct smbconf_ctx
*ctx
,
1000 TALLOC_CTX
*mem_ctx
,
1001 const char *service
,
1002 uint32_t *num_includes
,
1006 struct registry_key
*key
= NULL
;
1007 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
1009 werr
= smbconf_reg_open_service_key(tmp_ctx
, ctx
, service
,
1010 REG_KEY_READ
, &key
);
1011 if (!W_ERROR_IS_OK(werr
)) {
1015 werr
= smbconf_reg_get_includes_internal(mem_ctx
, key
, num_includes
,
1019 talloc_free(tmp_ctx
);
1023 static WERROR
smbconf_reg_set_includes(struct smbconf_ctx
*ctx
,
1024 const char *service
,
1025 uint32_t num_includes
,
1026 const char **includes
)
1028 WERROR werr
= WERR_OK
;
1029 struct registry_key
*key
= NULL
;
1030 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
1032 werr
= smbconf_reg_open_service_key(tmp_ctx
, ctx
, service
,
1034 if (!W_ERROR_IS_OK(werr
)) {
1038 if (num_includes
== 0) {
1039 if (!smbconf_value_exists(key
, INCLUDES_VALNAME
)) {
1042 werr
= reg_deletevalue(key
, INCLUDES_VALNAME
);
1044 werr
= smbconf_reg_set_multi_sz_value(key
, INCLUDES_VALNAME
,
1045 num_includes
, includes
);
1049 talloc_free(tmp_ctx
);
1053 static WERROR
smbconf_reg_delete_includes(struct smbconf_ctx
*ctx
,
1054 const char *service
)
1056 WERROR werr
= WERR_OK
;
1057 struct registry_key
*key
= NULL
;
1058 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
1060 werr
= smbconf_reg_open_service_key(tmp_ctx
, ctx
, service
,
1062 if (!W_ERROR_IS_OK(werr
)) {
1066 if (!smbconf_value_exists(key
, INCLUDES_VALNAME
)) {
1070 werr
= reg_deletevalue(key
, INCLUDES_VALNAME
);
1074 talloc_free(tmp_ctx
);
1078 static WERROR
smbconf_reg_transaction_start(struct smbconf_ctx
*ctx
)
1080 return regdb_transaction_start();
1083 static WERROR
smbconf_reg_transaction_commit(struct smbconf_ctx
*ctx
)
1085 return regdb_transaction_commit();
1088 static WERROR
smbconf_reg_transaction_cancel(struct smbconf_ctx
*ctx
)
1090 return regdb_transaction_cancel();
1093 struct smbconf_ops smbconf_ops_reg
= {
1094 .init
= smbconf_reg_init
,
1095 .shutdown
= smbconf_reg_shutdown
,
1096 .requires_messaging
= smbconf_reg_requires_messaging
,
1097 .is_writeable
= smbconf_reg_is_writeable
,
1098 .open_conf
= smbconf_reg_open
,
1099 .close_conf
= smbconf_reg_close
,
1100 .get_csn
= smbconf_reg_get_csn
,
1101 .drop
= smbconf_reg_drop
,
1102 .get_share_names
= smbconf_reg_get_share_names
,
1103 .share_exists
= smbconf_reg_share_exists
,
1104 .create_share
= smbconf_reg_create_share
,
1105 .get_share
= smbconf_reg_get_share
,
1106 .delete_share
= smbconf_reg_delete_share
,
1107 .set_parameter
= smbconf_reg_set_parameter
,
1108 .get_parameter
= smbconf_reg_get_parameter
,
1109 .delete_parameter
= smbconf_reg_delete_parameter
,
1110 .get_includes
= smbconf_reg_get_includes
,
1111 .set_includes
= smbconf_reg_set_includes
,
1112 .delete_includes
= smbconf_reg_delete_includes
,
1113 .transaction_start
= smbconf_reg_transaction_start
,
1114 .transaction_commit
= smbconf_reg_transaction_commit
,
1115 .transaction_cancel
= smbconf_reg_transaction_cancel
,
1120 * initialize the smbconf registry backend
1121 * the only function that is exported from this module
1123 WERROR
smbconf_init_reg(TALLOC_CTX
*mem_ctx
, struct smbconf_ctx
**conf_ctx
,
1126 return smbconf_init_internal(mem_ctx
, conf_ctx
, path
, &smbconf_ops_reg
);