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 #define INCLUDES_VALNAME "includes"
25 struct reg_private_data
{
26 struct registry_key
*base_key
;
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
[] = {
55 "includes", /* this has a special meaning internally */
58 const char **forbidden
= NULL
;
60 for (forbidden
= forbidden_valnames
; *forbidden
!= NULL
; forbidden
++) {
61 if (strwicmp(valname
, *forbidden
) == 0) {
68 static bool smbconf_reg_valname_valid(const char *valname
)
70 return (!smbconf_reg_valname_forbidden(valname
) &&
71 lp_parameter_is_valid(valname
));
75 * Open a subkey of the base key (i.e a service)
77 static WERROR
smbconf_reg_open_service_key(TALLOC_CTX
*mem_ctx
,
78 struct smbconf_ctx
*ctx
,
79 const char *servicename
,
80 uint32 desired_access
,
81 struct registry_key
**key
)
85 if (servicename
== NULL
) {
86 *key
= rpd(ctx
)->base_key
;
89 werr
= reg_openkey(mem_ctx
, rpd(ctx
)->base_key
, servicename
,
92 if (W_ERROR_EQUAL(werr
, WERR_BADFILE
)) {
93 werr
= WERR_NO_SUCH_SERVICE
;
100 * check if a value exists in a given registry key
102 static bool smbconf_value_exists(struct registry_key
*key
, const char *param
)
105 WERROR werr
= WERR_OK
;
106 TALLOC_CTX
*ctx
= talloc_stackframe();
107 struct registry_value
*value
= NULL
;
109 werr
= reg_queryvalue(ctx
, key
, param
, &value
);
110 if (W_ERROR_IS_OK(werr
)) {
119 * create a subkey of the base key (i.e. a service...)
121 static WERROR
smbconf_reg_create_service_key(TALLOC_CTX
*mem_ctx
,
122 struct smbconf_ctx
*ctx
,
123 const char * subkeyname
,
124 struct registry_key
**newkey
)
126 WERROR werr
= WERR_OK
;
127 TALLOC_CTX
*create_ctx
;
128 enum winreg_CreateAction action
= REG_ACTION_NONE
;
130 /* create a new talloc ctx for creation. it will hold
131 * the intermediate parent key (SMBCONF) for creation
132 * and will be destroyed when leaving this function... */
133 create_ctx
= talloc_stackframe();
135 werr
= reg_createkey(mem_ctx
, rpd(ctx
)->base_key
, subkeyname
,
136 REG_KEY_WRITE
, newkey
, &action
);
137 if (W_ERROR_IS_OK(werr
) && (action
!= REG_CREATED_NEW_KEY
)) {
138 DEBUG(10, ("Key '%s' already exists.\n", subkeyname
));
139 werr
= WERR_FILE_EXISTS
;
141 if (!W_ERROR_IS_OK(werr
)) {
142 DEBUG(5, ("Error creating key %s: %s\n",
143 subkeyname
, win_errstr(werr
)));
146 talloc_free(create_ctx
);
151 * add a value to a key.
153 static WERROR
smbconf_reg_set_value(struct registry_key
*key
,
157 struct registry_value val
;
158 WERROR werr
= WERR_OK
;
160 const char *canon_valname
;
161 const char *canon_valstr
;
163 if (!lp_canonicalize_parameter_with_value(valname
, valstr
,
167 if (canon_valname
== NULL
) {
168 DEBUG(5, ("invalid parameter '%s' given\n",
171 DEBUG(5, ("invalid value '%s' given for "
172 "parameter '%s'\n", valstr
, valname
));
174 werr
= WERR_INVALID_PARAM
;
178 if (smbconf_reg_valname_forbidden(canon_valname
)) {
179 DEBUG(5, ("Parameter '%s' not allowed in registry.\n",
181 werr
= WERR_INVALID_PARAM
;
185 subkeyname
= strrchr_m(key
->key
->name
, '\\');
186 if ((subkeyname
== NULL
) || (*(subkeyname
+1) == '\0')) {
187 DEBUG(5, ("Invalid registry key '%s' given as "
188 "smbconf section.\n", key
->key
->name
));
189 werr
= WERR_INVALID_PARAM
;
193 if (!strequal(subkeyname
, GLOBAL_NAME
) &&
194 lp_parameter_is_global(valname
))
196 DEBUG(5, ("Global parameter '%s' not allowed in "
197 "service definition ('%s').\n", canon_valname
,
199 werr
= WERR_INVALID_PARAM
;
206 val
.v
.sz
.str
= CONST_DISCARD(char *, canon_valstr
);
207 val
.v
.sz
.len
= strlen(canon_valstr
) + 1;
209 werr
= reg_setvalue(key
, canon_valname
, &val
);
210 if (!W_ERROR_IS_OK(werr
)) {
211 DEBUG(5, ("Error adding value '%s' to "
213 canon_valname
, key
->key
->name
, win_errstr(werr
)));
220 static WERROR
smbconf_reg_set_multi_sz_value(struct registry_key
*key
,
222 const uint32_t num_strings
,
223 const char **strings
)
226 struct registry_value
*value
;
228 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
230 if (strings
== NULL
) {
231 werr
= WERR_INVALID_PARAM
;
235 value
= TALLOC_ZERO_P(tmp_ctx
, struct registry_value
);
237 value
->type
= REG_MULTI_SZ
;
238 value
->v
.multi_sz
.num_strings
= num_strings
;
239 value
->v
.multi_sz
.strings
= TALLOC_ARRAY(tmp_ctx
, char *, num_strings
);
240 if (value
->v
.multi_sz
.strings
== NULL
) {
244 for (count
= 0; count
< num_strings
; count
++) {
245 value
->v
.multi_sz
.strings
[count
] =
246 talloc_strdup(value
->v
.multi_sz
.strings
,
248 if (value
->v
.multi_sz
.strings
[count
] == NULL
) {
254 werr
= reg_setvalue(key
, valname
, value
);
255 if (!W_ERROR_IS_OK(werr
)) {
256 DEBUG(5, ("Error adding value '%s' to key '%s': %s\n",
257 valname
, key
->key
->name
, win_errstr(werr
)));
261 talloc_free(tmp_ctx
);
266 * format a registry_value into a string.
268 * This is intended to be used for smbconf registry values,
269 * which are ar stored as REG_SZ values, so the incomplete
270 * handling should be ok.
272 static char *smbconf_format_registry_value(TALLOC_CTX
*mem_ctx
,
273 struct registry_value
*value
)
277 /* alternatively, create a new talloc context? */
278 if (mem_ctx
== NULL
) {
282 switch (value
->type
) {
284 result
= talloc_asprintf(mem_ctx
, "%d", value
->v
.dword
);
288 result
= talloc_asprintf(mem_ctx
, "%s", value
->v
.sz
.str
);
292 for (j
= 0; j
< value
->v
.multi_sz
.num_strings
; j
++) {
293 result
= talloc_asprintf(mem_ctx
, "%s\"%s\" ",
294 result
? result
: "" ,
295 value
->v
.multi_sz
.strings
[j
]);
296 if (result
== NULL
) {
303 result
= talloc_asprintf(mem_ctx
, "binary (%d bytes)",
304 (int)value
->v
.binary
.length
);
307 result
= talloc_asprintf(mem_ctx
, "<unprintable>");
313 static WERROR
smbconf_reg_get_includes_internal(TALLOC_CTX
*mem_ctx
,
314 struct registry_key
*key
,
315 uint32_t *num_includes
,
320 struct registry_value
*value
= NULL
;
321 char **tmp_includes
= NULL
;
322 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
324 if (!smbconf_value_exists(key
, INCLUDES_VALNAME
)) {
332 werr
= reg_queryvalue(tmp_ctx
, key
, INCLUDES_VALNAME
, &value
);
333 if (!W_ERROR_IS_OK(werr
)) {
337 if (value
->type
!= REG_MULTI_SZ
) {
338 /* wrong type -- ignore */
342 for (count
= 0; count
< value
->v
.multi_sz
.num_strings
; count
++)
344 werr
= smbconf_add_string_to_array(tmp_ctx
,
347 value
->v
.multi_sz
.strings
[count
]);
348 if (!W_ERROR_IS_OK(werr
)) {
354 *includes
= talloc_move(mem_ctx
, &tmp_includes
);
355 if (*includes
== NULL
) {
359 *num_includes
= count
;
366 talloc_free(tmp_ctx
);
371 * Get the values of a key as a list of value names
372 * and a list of value strings (ordered)
374 static WERROR
smbconf_reg_get_values(TALLOC_CTX
*mem_ctx
,
375 struct registry_key
*key
,
376 uint32_t *num_values
,
378 char ***value_strings
)
380 TALLOC_CTX
*tmp_ctx
= NULL
;
381 WERROR werr
= WERR_OK
;
383 struct registry_value
*valvalue
= NULL
;
384 char *valname
= NULL
;
385 uint32_t tmp_num_values
= 0;
386 char **tmp_valnames
= NULL
;
387 char **tmp_valstrings
= NULL
;
388 uint32_t num_includes
= 0;
389 char **includes
= NULL
;
391 if ((num_values
== NULL
) || (value_names
== NULL
) ||
392 (value_strings
== NULL
))
394 werr
= WERR_INVALID_PARAM
;
398 tmp_ctx
= talloc_stackframe();
401 werr
= reg_enumvalue(tmp_ctx
, key
, count
, &valname
, &valvalue
),
407 if (!smbconf_reg_valname_valid(valname
)) {
411 werr
= smbconf_add_string_to_array(tmp_ctx
,
413 tmp_num_values
, valname
);
414 if (!W_ERROR_IS_OK(werr
)) {
418 valstring
= smbconf_format_registry_value(tmp_ctx
, valvalue
);
419 werr
= smbconf_add_string_to_array(tmp_ctx
, &tmp_valstrings
,
420 tmp_num_values
, valstring
);
421 if (!W_ERROR_IS_OK(werr
)) {
426 if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS
, werr
)) {
430 /* now add the includes at the end */
431 werr
= smbconf_reg_get_includes_internal(tmp_ctx
, key
, &num_includes
,
433 if (!W_ERROR_IS_OK(werr
)) {
436 for (count
= 0; count
< num_includes
; count
++) {
437 werr
= smbconf_add_string_to_array(tmp_ctx
, &tmp_valnames
,
438 tmp_num_values
, "include");
439 if (!W_ERROR_IS_OK(werr
)) {
443 werr
= smbconf_add_string_to_array(tmp_ctx
, &tmp_valstrings
,
446 if (!W_ERROR_IS_OK(werr
)) {
453 *num_values
= tmp_num_values
;
454 if (tmp_num_values
> 0) {
455 *value_names
= talloc_move(mem_ctx
, &tmp_valnames
);
456 *value_strings
= talloc_move(mem_ctx
, &tmp_valstrings
);
459 *value_strings
= NULL
;
463 talloc_free(tmp_ctx
);
467 static bool smbconf_reg_key_has_values(struct registry_key
*key
)
470 uint32_t num_subkeys
;
471 uint32_t max_subkeylen
;
472 uint32_t max_subkeysize
;
474 uint32_t max_valnamelen
;
475 uint32_t max_valbufsize
;
476 uint32_t secdescsize
;
477 NTTIME last_changed_time
;
479 werr
= reg_queryinfokey(key
, &num_subkeys
, &max_subkeylen
,
480 &max_subkeysize
, &num_values
, &max_valnamelen
,
481 &max_valbufsize
, &secdescsize
,
483 if (!W_ERROR_IS_OK(werr
)) {
487 return (num_values
!= 0);
491 * delete all values from a key
493 static WERROR
smbconf_reg_delete_values(struct registry_key
*key
)
497 struct registry_value
*valvalue
;
499 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
502 werr
= reg_enumvalue(mem_ctx
, key
, count
, &valname
, &valvalue
),
506 werr
= reg_deletevalue(key
, valname
);
507 if (!W_ERROR_IS_OK(werr
)) {
511 if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS
, werr
)) {
512 DEBUG(1, ("smbconf_reg_delete_values: "
513 "Error enumerating values of %s: %s\n",
522 talloc_free(mem_ctx
);
526 /**********************************************************************
528 * smbconf operations: registry implementations
530 **********************************************************************/
533 * initialize the registry smbconf backend
535 static WERROR
smbconf_reg_init(struct smbconf_ctx
*ctx
, const char *path
)
537 WERROR werr
= WERR_OK
;
538 struct nt_user_token
*token
;
543 ctx
->path
= talloc_strdup(ctx
, path
);
544 if (ctx
->path
== NULL
) {
549 ctx
->data
= TALLOC_ZERO_P(ctx
, struct reg_private_data
);
551 werr
= ntstatus_to_werror(registry_create_admin_token(ctx
, &token
));
552 if (!W_ERROR_IS_OK(werr
)) {
553 DEBUG(1, ("Error creating admin token\n"));
556 rpd(ctx
)->open
= false;
558 werr
= registry_init_smbconf(path
);
559 if (!W_ERROR_IS_OK(werr
)) {
563 werr
= ctx
->ops
->open_conf(ctx
);
564 if (!W_ERROR_IS_OK(werr
)) {
565 DEBUG(1, ("Error opening the registry.\n"));
569 werr
= reg_open_path(ctx
, ctx
->path
,
570 KEY_ENUMERATE_SUB_KEYS
| REG_KEY_WRITE
,
571 token
, &rpd(ctx
)->base_key
);
572 if (!W_ERROR_IS_OK(werr
)) {
580 static int smbconf_reg_shutdown(struct smbconf_ctx
*ctx
)
582 return ctx
->ops
->close_conf(ctx
);
585 static bool smbconf_reg_requires_messaging(struct smbconf_ctx
*ctx
)
587 #ifdef CLUSTER_SUPPORT
588 if (lp_clustering() && lp_parm_bool(-1, "ctdb", "registry.tdb", true)) {
595 static bool smbconf_reg_is_writeable(struct smbconf_ctx
*ctx
)
598 * The backend has write support.
600 * TODO: add access checks whether the concrete
601 * config source is really writeable by the calling user.
606 static WERROR
smbconf_reg_open(struct smbconf_ctx
*ctx
)
610 if (rpd(ctx
)->open
) {
615 if (W_ERROR_IS_OK(werr
)) {
616 rpd(ctx
)->open
= true;
621 static int smbconf_reg_close(struct smbconf_ctx
*ctx
)
625 if (!rpd(ctx
)->open
) {
631 rpd(ctx
)->open
= false;
637 * Get the change sequence number of the given service/parameter.
638 * service and parameter strings may be NULL.
640 static void smbconf_reg_get_csn(struct smbconf_ctx
*ctx
,
641 struct smbconf_csn
*csn
,
642 const char *service
, const char *param
)
648 if (!W_ERROR_IS_OK(ctx
->ops
->open_conf(ctx
))) {
652 csn
->csn
= (uint64_t)regdb_get_seqnum();
656 * Drop the whole configuration (restarting empty) - registry version
658 static WERROR
smbconf_reg_drop(struct smbconf_ctx
*ctx
)
661 WERROR werr
= WERR_OK
;
662 struct registry_key
*parent_key
= NULL
;
663 struct registry_key
*new_key
= NULL
;
664 TALLOC_CTX
* mem_ctx
= talloc_stackframe();
665 enum winreg_CreateAction action
;
666 struct nt_user_token
*token
;
668 werr
= ntstatus_to_werror(registry_create_admin_token(ctx
, &token
));
669 if (!W_ERROR_IS_OK(werr
)) {
670 DEBUG(1, ("Error creating admin token\n"));
674 path
= talloc_strdup(mem_ctx
, ctx
->path
);
679 p
= strrchr(path
, '\\');
681 werr
= reg_open_path(mem_ctx
, path
, REG_KEY_WRITE
, token
,
684 if (!W_ERROR_IS_OK(werr
)) {
688 werr
= reg_deletekey_recursive(mem_ctx
, parent_key
, p
+1);
690 if (!W_ERROR_IS_OK(werr
)) {
694 werr
= reg_createkey(mem_ctx
, parent_key
, p
+1, REG_KEY_WRITE
,
698 talloc_free(mem_ctx
);
703 * get the list of share names defined in the configuration.
706 static WERROR
smbconf_reg_get_share_names(struct smbconf_ctx
*ctx
,
708 uint32_t *num_shares
,
712 uint32_t added_count
= 0;
713 TALLOC_CTX
*tmp_ctx
= NULL
;
714 WERROR werr
= WERR_OK
;
715 char *subkey_name
= NULL
;
716 char **tmp_share_names
= NULL
;
718 if ((num_shares
== NULL
) || (share_names
== NULL
)) {
719 werr
= WERR_INVALID_PARAM
;
723 tmp_ctx
= talloc_stackframe();
725 /* if there are values in the base key, return NULL as share name */
727 if (smbconf_reg_key_has_values(rpd(ctx
)->base_key
)) {
728 werr
= smbconf_add_string_to_array(tmp_ctx
, &tmp_share_names
,
730 if (!W_ERROR_IS_OK(werr
)) {
736 /* make sure "global" is always listed first */
737 if (smbconf_share_exists(ctx
, GLOBAL_NAME
)) {
738 werr
= smbconf_add_string_to_array(tmp_ctx
, &tmp_share_names
,
739 added_count
, GLOBAL_NAME
);
740 if (!W_ERROR_IS_OK(werr
)) {
747 werr
= reg_enumkey(tmp_ctx
, rpd(ctx
)->base_key
, count
,
752 if (strequal(subkey_name
, GLOBAL_NAME
)) {
756 werr
= smbconf_add_string_to_array(tmp_ctx
,
760 if (!W_ERROR_IS_OK(werr
)) {
765 if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS
, werr
)) {
770 *num_shares
= added_count
;
771 if (added_count
> 0) {
772 *share_names
= talloc_move(mem_ctx
, &tmp_share_names
);
778 talloc_free(tmp_ctx
);
783 * check if a share/service of a given name exists - registry version
785 static bool smbconf_reg_share_exists(struct smbconf_ctx
*ctx
,
786 const char *servicename
)
789 WERROR werr
= WERR_OK
;
790 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
791 struct registry_key
*key
= NULL
;
793 werr
= smbconf_reg_open_service_key(mem_ctx
, ctx
, servicename
,
795 if (W_ERROR_IS_OK(werr
)) {
799 talloc_free(mem_ctx
);
804 * Add a service if it does not already exist - registry version
806 static WERROR
smbconf_reg_create_share(struct smbconf_ctx
*ctx
,
807 const char *servicename
)
810 struct registry_key
*key
= NULL
;
812 if (servicename
== NULL
) {
816 werr
= smbconf_reg_create_service_key(talloc_tos(), ctx
,
824 * get a definition of a share (service) from configuration.
826 static WERROR
smbconf_reg_get_share(struct smbconf_ctx
*ctx
,
828 const char *servicename
,
829 struct smbconf_service
**service
)
831 WERROR werr
= WERR_OK
;
832 struct registry_key
*key
= NULL
;
833 struct smbconf_service
*tmp_service
= NULL
;
834 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
836 werr
= smbconf_reg_open_service_key(tmp_ctx
, ctx
, servicename
,
838 if (!W_ERROR_IS_OK(werr
)) {
842 tmp_service
= TALLOC_ZERO_P(tmp_ctx
, struct smbconf_service
);
843 if (tmp_service
== NULL
) {
848 if (servicename
!= NULL
) {
849 tmp_service
->name
= talloc_strdup(tmp_service
, servicename
);
850 if (tmp_service
->name
== NULL
) {
856 werr
= smbconf_reg_get_values(tmp_service
, key
,
857 &(tmp_service
->num_params
),
858 &(tmp_service
->param_names
),
859 &(tmp_service
->param_values
));
861 if (W_ERROR_IS_OK(werr
)) {
862 *service
= talloc_move(mem_ctx
, &tmp_service
);
866 talloc_free(tmp_ctx
);
871 * delete a service from configuration
873 static WERROR
smbconf_reg_delete_share(struct smbconf_ctx
*ctx
,
874 const char *servicename
)
876 WERROR werr
= WERR_OK
;
877 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
879 if (servicename
!= NULL
) {
880 werr
= reg_deletekey_recursive(mem_ctx
, rpd(ctx
)->base_key
,
883 werr
= smbconf_reg_delete_values(rpd(ctx
)->base_key
);
886 talloc_free(mem_ctx
);
891 * set a configuration parameter to the value provided.
893 static WERROR
smbconf_reg_set_parameter(struct smbconf_ctx
*ctx
,
899 struct registry_key
*key
= NULL
;
900 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
902 werr
= smbconf_reg_open_service_key(mem_ctx
, ctx
, service
,
903 REG_KEY_WRITE
, &key
);
904 if (!W_ERROR_IS_OK(werr
)) {
908 werr
= smbconf_reg_set_value(key
, param
, valstr
);
911 talloc_free(mem_ctx
);
916 * get the value of a configuration parameter as a string
918 static WERROR
smbconf_reg_get_parameter(struct smbconf_ctx
*ctx
,
924 WERROR werr
= WERR_OK
;
925 struct registry_key
*key
= NULL
;
926 struct registry_value
*value
= NULL
;
928 werr
= smbconf_reg_open_service_key(mem_ctx
, ctx
, service
,
930 if (!W_ERROR_IS_OK(werr
)) {
934 if (!smbconf_reg_valname_valid(param
)) {
935 werr
= WERR_INVALID_PARAM
;
939 if (!smbconf_value_exists(key
, param
)) {
940 werr
= WERR_INVALID_PARAM
;
944 werr
= reg_queryvalue(mem_ctx
, key
, param
, &value
);
945 if (!W_ERROR_IS_OK(werr
)) {
949 *valstr
= smbconf_format_registry_value(mem_ctx
, value
);
951 if (*valstr
== NULL
) {
962 * delete a parameter from configuration
964 static WERROR
smbconf_reg_delete_parameter(struct smbconf_ctx
*ctx
,
968 struct registry_key
*key
= NULL
;
969 WERROR werr
= WERR_OK
;
970 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
972 werr
= smbconf_reg_open_service_key(mem_ctx
, ctx
, service
,
974 if (!W_ERROR_IS_OK(werr
)) {
978 if (!smbconf_reg_valname_valid(param
)) {
979 werr
= WERR_INVALID_PARAM
;
983 if (!smbconf_value_exists(key
, param
)) {
984 werr
= WERR_INVALID_PARAM
;
988 werr
= reg_deletevalue(key
, param
);
991 talloc_free(mem_ctx
);
995 static WERROR
smbconf_reg_get_includes(struct smbconf_ctx
*ctx
,
998 uint32_t *num_includes
,
1002 struct registry_key
*key
= NULL
;
1003 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
1005 werr
= smbconf_reg_open_service_key(tmp_ctx
, ctx
, service
,
1006 REG_KEY_READ
, &key
);
1007 if (!W_ERROR_IS_OK(werr
)) {
1011 werr
= smbconf_reg_get_includes_internal(mem_ctx
, key
, num_includes
,
1015 talloc_free(tmp_ctx
);
1019 static WERROR
smbconf_reg_set_includes(struct smbconf_ctx
*ctx
,
1020 const char *service
,
1021 uint32_t num_includes
,
1022 const char **includes
)
1024 WERROR werr
= WERR_OK
;
1025 struct registry_key
*key
= NULL
;
1026 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
1028 werr
= smbconf_reg_open_service_key(tmp_ctx
, ctx
, service
,
1030 if (!W_ERROR_IS_OK(werr
)) {
1034 if (num_includes
== 0) {
1035 if (!smbconf_value_exists(key
, INCLUDES_VALNAME
)) {
1038 werr
= reg_deletevalue(key
, INCLUDES_VALNAME
);
1040 werr
= smbconf_reg_set_multi_sz_value(key
, INCLUDES_VALNAME
,
1041 num_includes
, includes
);
1045 talloc_free(tmp_ctx
);
1049 static WERROR
smbconf_reg_delete_includes(struct smbconf_ctx
*ctx
,
1050 const char *service
)
1052 WERROR werr
= WERR_OK
;
1053 struct registry_key
*key
= NULL
;
1054 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
1056 werr
= smbconf_reg_open_service_key(tmp_ctx
, ctx
, service
,
1058 if (!W_ERROR_IS_OK(werr
)) {
1062 if (!smbconf_value_exists(key
, INCLUDES_VALNAME
)) {
1066 werr
= reg_deletevalue(key
, INCLUDES_VALNAME
);
1070 talloc_free(tmp_ctx
);
1074 static WERROR
smbconf_reg_transaction_start(struct smbconf_ctx
*ctx
)
1076 return regdb_transaction_start();
1079 static WERROR
smbconf_reg_transaction_commit(struct smbconf_ctx
*ctx
)
1081 return regdb_transaction_commit();
1084 static WERROR
smbconf_reg_transaction_cancel(struct smbconf_ctx
*ctx
)
1086 return regdb_transaction_cancel();
1089 struct smbconf_ops smbconf_ops_reg
= {
1090 .init
= smbconf_reg_init
,
1091 .shutdown
= smbconf_reg_shutdown
,
1092 .requires_messaging
= smbconf_reg_requires_messaging
,
1093 .is_writeable
= smbconf_reg_is_writeable
,
1094 .open_conf
= smbconf_reg_open
,
1095 .close_conf
= smbconf_reg_close
,
1096 .get_csn
= smbconf_reg_get_csn
,
1097 .drop
= smbconf_reg_drop
,
1098 .get_share_names
= smbconf_reg_get_share_names
,
1099 .share_exists
= smbconf_reg_share_exists
,
1100 .create_share
= smbconf_reg_create_share
,
1101 .get_share
= smbconf_reg_get_share
,
1102 .delete_share
= smbconf_reg_delete_share
,
1103 .set_parameter
= smbconf_reg_set_parameter
,
1104 .get_parameter
= smbconf_reg_get_parameter
,
1105 .delete_parameter
= smbconf_reg_delete_parameter
,
1106 .get_includes
= smbconf_reg_get_includes
,
1107 .set_includes
= smbconf_reg_set_includes
,
1108 .delete_includes
= smbconf_reg_delete_includes
,
1109 .transaction_start
= smbconf_reg_transaction_start
,
1110 .transaction_commit
= smbconf_reg_transaction_commit
,
1111 .transaction_cancel
= smbconf_reg_transaction_cancel
,
1116 * initialize the smbconf registry backend
1117 * the only function that is exported from this module
1119 WERROR
smbconf_init_reg(TALLOC_CTX
*mem_ctx
, struct smbconf_ctx
**conf_ctx
,
1122 return smbconf_init_internal(mem_ctx
, conf_ctx
, path
, &smbconf_ops_reg
);