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_api.h"
24 #include "registry/reg_backend_db.h"
25 #include "registry/reg_util_token.h"
26 #include "registry/reg_api_util.h"
27 #include "registry/reg_init_smbconf.h"
28 #include "lib/smbconf/smbconf_init.h"
29 #include "lib/smbconf/smbconf_reg.h"
30 #include "../libcli/registry/util_reg.h"
32 #define INCLUDES_VALNAME "includes"
34 struct reg_private_data
{
35 struct registry_key
*base_key
;
36 bool open
; /* did _we_ open the registry? */
39 /**********************************************************************
43 **********************************************************************/
46 * a convenience helper to cast the private data structure
48 static struct reg_private_data
*rpd(struct smbconf_ctx
*ctx
)
50 return (struct reg_private_data
*)(ctx
->data
);
54 * check whether a given value name is forbidden in registry (smbconf)
56 static bool smbconf_reg_valname_forbidden(const char *valname
)
58 /* hard code the list of forbidden names here for now */
59 const char *forbidden_valnames
[] = {
64 "includes", /* this has a special meaning internally */
67 const char **forbidden
= NULL
;
69 for (forbidden
= forbidden_valnames
; *forbidden
!= NULL
; forbidden
++) {
70 if (strwicmp(valname
, *forbidden
) == 0) {
77 static bool smbconf_reg_valname_valid(const char *valname
)
79 return (!smbconf_reg_valname_forbidden(valname
) &&
80 lp_parameter_is_valid(valname
));
84 * Open a subkey of the base key (i.e a service)
86 static sbcErr
smbconf_reg_open_service_key(TALLOC_CTX
*mem_ctx
,
87 struct smbconf_ctx
*ctx
,
88 const char *servicename
,
89 uint32 desired_access
,
90 struct registry_key
**key
)
94 if (servicename
== NULL
) {
95 *key
= rpd(ctx
)->base_key
;
98 werr
= reg_openkey(mem_ctx
, rpd(ctx
)->base_key
, servicename
,
100 if (W_ERROR_EQUAL(werr
, WERR_BADFILE
)) {
101 return SBC_ERR_NO_SUCH_SERVICE
;
103 if (!W_ERROR_IS_OK(werr
)) {
104 return SBC_ERR_NOMEM
;
111 * check if a value exists in a given registry key
113 static bool smbconf_value_exists(struct registry_key
*key
, const char *param
)
116 WERROR werr
= WERR_OK
;
117 TALLOC_CTX
*ctx
= talloc_stackframe();
118 struct registry_value
*value
= NULL
;
120 werr
= reg_queryvalue(ctx
, key
, param
, &value
);
121 if (W_ERROR_IS_OK(werr
)) {
130 * create a subkey of the base key (i.e. a service...)
132 static sbcErr
smbconf_reg_create_service_key(TALLOC_CTX
*mem_ctx
,
133 struct smbconf_ctx
*ctx
,
134 const char * subkeyname
,
135 struct registry_key
**newkey
)
138 sbcErr err
= SBC_ERR_OK
;
139 TALLOC_CTX
*create_ctx
;
140 enum winreg_CreateAction action
= REG_ACTION_NONE
;
142 /* create a new talloc ctx for creation. it will hold
143 * the intermediate parent key (SMBCONF) for creation
144 * and will be destroyed when leaving this function... */
145 create_ctx
= talloc_stackframe();
147 werr
= reg_createkey(mem_ctx
, rpd(ctx
)->base_key
, subkeyname
,
148 REG_KEY_WRITE
, newkey
, &action
);
149 if (W_ERROR_IS_OK(werr
) && (action
!= REG_CREATED_NEW_KEY
)) {
150 DEBUG(10, ("Key '%s' already exists.\n", subkeyname
));
151 err
= SBC_ERR_FILE_EXISTS
;
153 if (!W_ERROR_IS_OK(werr
)) {
154 DEBUG(5, ("Error creating key %s: %s\n",
155 subkeyname
, win_errstr(werr
)));
156 err
= SBC_ERR_UNKNOWN_FAILURE
;
159 talloc_free(create_ctx
);
164 * add a value to a key.
166 static WERROR
smbconf_reg_set_value(struct registry_key
*key
,
170 struct registry_value val
;
171 WERROR werr
= WERR_OK
;
173 const char *canon_valname
;
174 const char *canon_valstr
;
176 if (!lp_canonicalize_parameter_with_value(valname
, valstr
,
180 if (canon_valname
== NULL
) {
181 DEBUG(5, ("invalid parameter '%s' given\n",
184 DEBUG(5, ("invalid value '%s' given for "
185 "parameter '%s'\n", valstr
, valname
));
187 werr
= WERR_INVALID_PARAM
;
191 if (smbconf_reg_valname_forbidden(canon_valname
)) {
192 DEBUG(5, ("Parameter '%s' not allowed in registry.\n",
194 werr
= WERR_INVALID_PARAM
;
198 subkeyname
= strrchr_m(key
->key
->name
, '\\');
199 if ((subkeyname
== NULL
) || (*(subkeyname
+1) == '\0')) {
200 DEBUG(5, ("Invalid registry key '%s' given as "
201 "smbconf section.\n", key
->key
->name
));
202 werr
= WERR_INVALID_PARAM
;
206 if (!strequal(subkeyname
, GLOBAL_NAME
) &&
207 lp_parameter_is_global(valname
))
209 DEBUG(5, ("Global parameter '%s' not allowed in "
210 "service definition ('%s').\n", canon_valname
,
212 werr
= WERR_INVALID_PARAM
;
219 if (!push_reg_sz(talloc_tos(), &val
.data
, canon_valstr
)) {
224 werr
= reg_setvalue(key
, canon_valname
, &val
);
225 if (!W_ERROR_IS_OK(werr
)) {
226 DEBUG(5, ("Error adding value '%s' to "
228 canon_valname
, key
->key
->name
, win_errstr(werr
)));
235 static WERROR
smbconf_reg_set_multi_sz_value(struct registry_key
*key
,
237 const uint32_t num_strings
,
238 const char **strings
)
241 struct registry_value
*value
;
243 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
246 if (strings
== NULL
) {
247 werr
= WERR_INVALID_PARAM
;
251 array
= talloc_zero_array(tmp_ctx
, const char *, num_strings
+ 1);
257 value
= TALLOC_ZERO_P(tmp_ctx
, struct registry_value
);
263 value
->type
= REG_MULTI_SZ
;
265 for (count
= 0; count
< num_strings
; count
++) {
266 array
[count
] = talloc_strdup(value
, strings
[count
]);
267 if (array
[count
] == NULL
) {
273 if (!push_reg_multi_sz(value
, &value
->data
, array
)) {
278 werr
= reg_setvalue(key
, valname
, value
);
279 if (!W_ERROR_IS_OK(werr
)) {
280 DEBUG(5, ("Error adding value '%s' to key '%s': %s\n",
281 valname
, key
->key
->name
, win_errstr(werr
)));
285 talloc_free(tmp_ctx
);
290 * format a registry_value into a string.
292 * This is intended to be used for smbconf registry values,
293 * which are ar stored as REG_SZ values, so the incomplete
294 * handling should be ok.
296 static char *smbconf_format_registry_value(TALLOC_CTX
*mem_ctx
,
297 struct registry_value
*value
)
301 /* alternatively, create a new talloc context? */
302 if (mem_ctx
== NULL
) {
306 switch (value
->type
) {
308 if (value
->data
.length
>= 4) {
309 uint32_t v
= IVAL(value
->data
.data
, 0);
310 result
= talloc_asprintf(mem_ctx
, "%d", v
);
314 case REG_EXPAND_SZ
: {
316 if (!pull_reg_sz(mem_ctx
, &value
->data
, &s
)) {
319 result
= talloc_strdup(mem_ctx
, s
);
324 const char **a
= NULL
;
325 if (!pull_reg_multi_sz(mem_ctx
, &value
->data
, &a
)) {
328 for (j
= 0; a
[j
] != NULL
; j
++) {
329 result
= talloc_asprintf(mem_ctx
, "%s\"%s\" ",
330 result
? result
: "" ,
332 if (result
== NULL
) {
339 result
= talloc_asprintf(mem_ctx
, "binary (%d bytes)",
340 (int)value
->data
.length
);
343 result
= talloc_asprintf(mem_ctx
, "<unprintable>");
349 static sbcErr
smbconf_reg_get_includes_internal(TALLOC_CTX
*mem_ctx
,
350 struct registry_key
*key
,
351 uint32_t *num_includes
,
357 struct registry_value
*value
= NULL
;
358 char **tmp_includes
= NULL
;
359 const char **array
= NULL
;
360 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
362 if (!smbconf_value_exists(key
, INCLUDES_VALNAME
)) {
370 werr
= reg_queryvalue(tmp_ctx
, key
, INCLUDES_VALNAME
, &value
);
371 if (!W_ERROR_IS_OK(werr
)) {
372 err
= SBC_ERR_ACCESS_DENIED
;
376 if (value
->type
!= REG_MULTI_SZ
) {
377 /* wrong type -- ignore */
382 if (!pull_reg_multi_sz(tmp_ctx
, &value
->data
, &array
)) {
387 for (count
= 0; array
[count
] != NULL
; count
++) {
388 err
= smbconf_add_string_to_array(tmp_ctx
,
392 if (!SBC_ERROR_IS_OK(err
)) {
399 *includes
= talloc_move(mem_ctx
, &tmp_includes
);
400 if (*includes
== NULL
) {
404 *num_includes
= count
;
411 talloc_free(tmp_ctx
);
416 * Get the values of a key as a list of value names
417 * and a list of value strings (ordered)
419 static sbcErr
smbconf_reg_get_values(TALLOC_CTX
*mem_ctx
,
420 struct registry_key
*key
,
421 uint32_t *num_values
,
423 char ***value_strings
)
425 TALLOC_CTX
*tmp_ctx
= NULL
;
426 WERROR werr
= WERR_OK
;
429 struct registry_value
*valvalue
= NULL
;
430 char *valname
= NULL
;
431 uint32_t tmp_num_values
= 0;
432 char **tmp_valnames
= NULL
;
433 char **tmp_valstrings
= NULL
;
434 uint32_t num_includes
= 0;
435 char **includes
= NULL
;
437 if ((num_values
== NULL
) || (value_names
== NULL
) ||
438 (value_strings
== NULL
))
440 err
= SBC_ERR_INVALID_PARAM
;
444 tmp_ctx
= talloc_stackframe();
447 werr
= reg_enumvalue(tmp_ctx
, key
, count
, &valname
, &valvalue
),
453 if (!smbconf_reg_valname_valid(valname
)) {
457 err
= smbconf_add_string_to_array(tmp_ctx
,
459 tmp_num_values
, valname
);
460 if (!SBC_ERROR_IS_OK(err
)) {
464 valstring
= smbconf_format_registry_value(tmp_ctx
, valvalue
);
465 err
= smbconf_add_string_to_array(tmp_ctx
, &tmp_valstrings
,
466 tmp_num_values
, valstring
);
467 if (!SBC_ERROR_IS_OK(err
)) {
472 if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS
, werr
)) {
477 /* now add the includes at the end */
478 err
= smbconf_reg_get_includes_internal(tmp_ctx
, key
, &num_includes
,
480 if (!SBC_ERROR_IS_OK(err
)) {
484 for (count
= 0; count
< num_includes
; count
++) {
485 err
= smbconf_add_string_to_array(tmp_ctx
, &tmp_valnames
,
486 tmp_num_values
, "include");
487 if (!SBC_ERROR_IS_OK(err
)) {
491 err
= smbconf_add_string_to_array(tmp_ctx
, &tmp_valstrings
,
494 if (!SBC_ERROR_IS_OK(err
)) {
501 *num_values
= tmp_num_values
;
502 if (tmp_num_values
> 0) {
503 *value_names
= talloc_move(mem_ctx
, &tmp_valnames
);
504 *value_strings
= talloc_move(mem_ctx
, &tmp_valstrings
);
507 *value_strings
= NULL
;
511 talloc_free(tmp_ctx
);
515 static bool smbconf_reg_key_has_values(struct registry_key
*key
)
518 uint32_t num_subkeys
;
519 uint32_t max_subkeylen
;
520 uint32_t max_subkeysize
;
522 uint32_t max_valnamelen
;
523 uint32_t max_valbufsize
;
524 uint32_t secdescsize
;
525 NTTIME last_changed_time
;
527 werr
= reg_queryinfokey(key
, &num_subkeys
, &max_subkeylen
,
528 &max_subkeysize
, &num_values
, &max_valnamelen
,
529 &max_valbufsize
, &secdescsize
,
531 if (!W_ERROR_IS_OK(werr
)) {
535 return (num_values
!= 0);
539 * delete all values from a key
541 static WERROR
smbconf_reg_delete_values(struct registry_key
*key
)
545 struct registry_value
*valvalue
;
547 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
550 werr
= reg_enumvalue(mem_ctx
, key
, count
, &valname
, &valvalue
),
554 werr
= reg_deletevalue(key
, valname
);
555 if (!W_ERROR_IS_OK(werr
)) {
559 if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS
, werr
)) {
560 DEBUG(1, ("smbconf_reg_delete_values: "
561 "Error enumerating values of %s: %s\n",
570 talloc_free(mem_ctx
);
574 /**********************************************************************
576 * smbconf operations: registry implementations
578 **********************************************************************/
581 * initialize the registry smbconf backend
583 static sbcErr
smbconf_reg_init(struct smbconf_ctx
*ctx
, const char *path
)
585 WERROR werr
= WERR_OK
;
587 struct security_token
*token
;
592 ctx
->path
= talloc_strdup(ctx
, path
);
593 if (ctx
->path
== NULL
) {
598 ctx
->data
= TALLOC_ZERO_P(ctx
, struct reg_private_data
);
600 werr
= ntstatus_to_werror(registry_create_admin_token(ctx
, &token
));
601 if (!W_ERROR_IS_OK(werr
)) {
602 DEBUG(1, ("Error creating admin token\n"));
603 err
= SBC_ERR_UNKNOWN_FAILURE
;
606 rpd(ctx
)->open
= false;
608 werr
= registry_init_smbconf(path
);
609 if (!W_ERROR_IS_OK(werr
)) {
610 err
= SBC_ERR_BADFILE
;
614 err
= ctx
->ops
->open_conf(ctx
);
615 if (!SBC_ERROR_IS_OK(err
)) {
616 DEBUG(1, ("Error opening the registry.\n"));
620 werr
= reg_open_path(ctx
, ctx
->path
,
621 KEY_ENUMERATE_SUB_KEYS
| REG_KEY_WRITE
,
622 token
, &rpd(ctx
)->base_key
);
623 if (!W_ERROR_IS_OK(werr
)) {
624 err
= SBC_ERR_UNKNOWN_FAILURE
;
632 static int smbconf_reg_shutdown(struct smbconf_ctx
*ctx
)
634 return ctx
->ops
->close_conf(ctx
);
637 static bool smbconf_reg_requires_messaging(struct smbconf_ctx
*ctx
)
639 #ifdef CLUSTER_SUPPORT
640 if (lp_clustering() && lp_parm_bool(-1, "ctdb", "registry.tdb", true)) {
647 static bool smbconf_reg_is_writeable(struct smbconf_ctx
*ctx
)
650 * The backend has write support.
652 * TODO: add access checks whether the concrete
653 * config source is really writeable by the calling user.
658 static sbcErr
smbconf_reg_open(struct smbconf_ctx
*ctx
)
662 if (rpd(ctx
)->open
) {
667 if (!W_ERROR_IS_OK(werr
)) {
668 return SBC_ERR_BADFILE
;
671 rpd(ctx
)->open
= true;
675 static int smbconf_reg_close(struct smbconf_ctx
*ctx
)
679 if (!rpd(ctx
)->open
) {
685 rpd(ctx
)->open
= false;
691 * Get the change sequence number of the given service/parameter.
692 * service and parameter strings may be NULL.
694 static void smbconf_reg_get_csn(struct smbconf_ctx
*ctx
,
695 struct smbconf_csn
*csn
,
696 const char *service
, const char *param
)
702 if (!SBC_ERROR_IS_OK(ctx
->ops
->open_conf(ctx
))) {
706 csn
->csn
= (uint64_t)regdb_get_seqnum();
710 * Drop the whole configuration (restarting empty) - registry version
712 static sbcErr
smbconf_reg_drop(struct smbconf_ctx
*ctx
)
715 WERROR werr
= WERR_OK
;
716 sbcErr err
= SBC_ERR_OK
;
717 struct registry_key
*parent_key
= NULL
;
718 struct registry_key
*new_key
= NULL
;
719 TALLOC_CTX
* mem_ctx
= talloc_stackframe();
720 enum winreg_CreateAction action
;
721 struct security_token
*token
;
723 werr
= ntstatus_to_werror(registry_create_admin_token(ctx
, &token
));
724 if (!W_ERROR_IS_OK(werr
)) {
725 DEBUG(1, ("Error creating admin token\n"));
726 err
= SBC_ERR_UNKNOWN_FAILURE
;
730 path
= talloc_strdup(mem_ctx
, ctx
->path
);
735 p
= strrchr(path
, '\\');
737 err
= SBC_ERR_INVALID_PARAM
;
741 werr
= reg_open_path(mem_ctx
, path
, REG_KEY_WRITE
, token
,
743 if (!W_ERROR_IS_OK(werr
)) {
744 err
= SBC_ERR_IO_FAILURE
;
748 werr
= reg_deletekey_recursive(parent_key
, p
+1);
749 if (!W_ERROR_IS_OK(werr
)) {
750 err
= SBC_ERR_IO_FAILURE
;
754 werr
= reg_createkey(mem_ctx
, parent_key
, p
+1, REG_KEY_WRITE
,
756 if (!W_ERROR_IS_OK(werr
)) {
757 err
= SBC_ERR_IO_FAILURE
;
762 talloc_free(mem_ctx
);
767 * get the list of share names defined in the configuration.
770 static sbcErr
smbconf_reg_get_share_names(struct smbconf_ctx
*ctx
,
772 uint32_t *num_shares
,
776 uint32_t added_count
= 0;
777 TALLOC_CTX
*tmp_ctx
= NULL
;
779 sbcErr err
= SBC_ERR_OK
;
780 char *subkey_name
= NULL
;
781 char **tmp_share_names
= NULL
;
783 if ((num_shares
== NULL
) || (share_names
== NULL
)) {
784 return SBC_ERR_INVALID_PARAM
;
787 tmp_ctx
= talloc_stackframe();
789 /* if there are values in the base key, return NULL as share name */
791 if (smbconf_reg_key_has_values(rpd(ctx
)->base_key
)) {
792 err
= smbconf_add_string_to_array(tmp_ctx
, &tmp_share_names
,
794 if (!SBC_ERROR_IS_OK(err
)) {
800 /* make sure "global" is always listed first */
801 if (smbconf_share_exists(ctx
, GLOBAL_NAME
)) {
802 err
= smbconf_add_string_to_array(tmp_ctx
, &tmp_share_names
,
803 added_count
, GLOBAL_NAME
);
804 if (!SBC_ERROR_IS_OK(err
)) {
811 werr
= reg_enumkey(tmp_ctx
, rpd(ctx
)->base_key
, count
,
816 if (strequal(subkey_name
, GLOBAL_NAME
)) {
820 err
= smbconf_add_string_to_array(tmp_ctx
,
824 if (!SBC_ERROR_IS_OK(err
)) {
829 if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS
, werr
)) {
830 err
= SBC_ERR_NO_MORE_ITEMS
;
835 *num_shares
= added_count
;
836 if (added_count
> 0) {
837 *share_names
= talloc_move(mem_ctx
, &tmp_share_names
);
843 talloc_free(tmp_ctx
);
848 * check if a share/service of a given name exists - registry version
850 static bool smbconf_reg_share_exists(struct smbconf_ctx
*ctx
,
851 const char *servicename
)
855 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
856 struct registry_key
*key
= NULL
;
858 err
= smbconf_reg_open_service_key(mem_ctx
, ctx
, servicename
,
860 if (SBC_ERROR_IS_OK(err
)) {
864 talloc_free(mem_ctx
);
869 * Add a service if it does not already exist - registry version
871 static sbcErr
smbconf_reg_create_share(struct smbconf_ctx
*ctx
,
872 const char *servicename
)
875 struct registry_key
*key
= NULL
;
877 if (servicename
== NULL
) {
881 err
= smbconf_reg_create_service_key(talloc_tos(), ctx
,
889 * get a definition of a share (service) from configuration.
891 static sbcErr
smbconf_reg_get_share(struct smbconf_ctx
*ctx
,
893 const char *servicename
,
894 struct smbconf_service
**service
)
897 struct registry_key
*key
= NULL
;
898 struct smbconf_service
*tmp_service
= NULL
;
899 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
901 err
= smbconf_reg_open_service_key(tmp_ctx
, ctx
, servicename
,
903 if (!SBC_ERROR_IS_OK(err
)) {
907 tmp_service
= TALLOC_ZERO_P(tmp_ctx
, struct smbconf_service
);
908 if (tmp_service
== NULL
) {
913 if (servicename
!= NULL
) {
914 tmp_service
->name
= talloc_strdup(tmp_service
, servicename
);
915 if (tmp_service
->name
== NULL
) {
921 err
= smbconf_reg_get_values(tmp_service
, key
,
922 &(tmp_service
->num_params
),
923 &(tmp_service
->param_names
),
924 &(tmp_service
->param_values
));
925 if (SBC_ERROR_IS_OK(err
)) {
926 *service
= talloc_move(mem_ctx
, &tmp_service
);
930 talloc_free(tmp_ctx
);
935 * delete a service from configuration
937 static WERROR
smbconf_reg_delete_share(struct smbconf_ctx
*ctx
,
938 const char *servicename
)
940 WERROR werr
= WERR_OK
;
941 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
943 if (servicename
!= NULL
) {
944 werr
= reg_deletekey_recursive(rpd(ctx
)->base_key
, servicename
);
946 werr
= smbconf_reg_delete_values(rpd(ctx
)->base_key
);
949 talloc_free(mem_ctx
);
954 * set a configuration parameter to the value provided.
956 static WERROR
smbconf_reg_set_parameter(struct smbconf_ctx
*ctx
,
963 struct registry_key
*key
= NULL
;
964 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
966 err
= smbconf_reg_open_service_key(mem_ctx
, ctx
, service
,
967 REG_KEY_WRITE
, &key
);
968 if (!SBC_ERROR_IS_OK(err
)) {
973 werr
= smbconf_reg_set_value(key
, param
, valstr
);
976 talloc_free(mem_ctx
);
981 * get the value of a configuration parameter as a string
983 static WERROR
smbconf_reg_get_parameter(struct smbconf_ctx
*ctx
,
989 WERROR werr
= WERR_OK
;
991 struct registry_key
*key
= NULL
;
992 struct registry_value
*value
= NULL
;
994 err
= smbconf_reg_open_service_key(mem_ctx
, ctx
, service
,
996 if (!SBC_ERROR_IS_OK(err
)) {
1001 if (!smbconf_reg_valname_valid(param
)) {
1002 werr
= WERR_INVALID_PARAM
;
1006 if (!smbconf_value_exists(key
, param
)) {
1007 werr
= WERR_INVALID_PARAM
;
1011 werr
= reg_queryvalue(mem_ctx
, key
, param
, &value
);
1012 if (!W_ERROR_IS_OK(werr
)) {
1016 *valstr
= smbconf_format_registry_value(mem_ctx
, value
);
1018 if (*valstr
== NULL
) {
1029 * delete a parameter from configuration
1031 static WERROR
smbconf_reg_delete_parameter(struct smbconf_ctx
*ctx
,
1032 const char *service
,
1035 struct registry_key
*key
= NULL
;
1036 WERROR werr
= WERR_OK
;
1038 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
1040 err
= smbconf_reg_open_service_key(mem_ctx
, ctx
, service
,
1042 if (!SBC_ERROR_IS_OK(err
)) {
1047 if (!smbconf_reg_valname_valid(param
)) {
1048 werr
= WERR_INVALID_PARAM
;
1052 if (!smbconf_value_exists(key
, param
)) {
1053 werr
= WERR_INVALID_PARAM
;
1057 werr
= reg_deletevalue(key
, param
);
1060 talloc_free(mem_ctx
);
1064 static WERROR
smbconf_reg_get_includes(struct smbconf_ctx
*ctx
,
1065 TALLOC_CTX
*mem_ctx
,
1066 const char *service
,
1067 uint32_t *num_includes
,
1072 struct registry_key
*key
= NULL
;
1073 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
1075 err
= smbconf_reg_open_service_key(tmp_ctx
, ctx
, service
,
1076 REG_KEY_READ
, &key
);
1077 if (!SBC_ERROR_IS_OK(err
)) {
1082 err
= smbconf_reg_get_includes_internal(mem_ctx
, key
, num_includes
,
1084 if (!SBC_ERROR_IS_OK(err
)) {
1090 talloc_free(tmp_ctx
);
1094 static WERROR
smbconf_reg_set_includes(struct smbconf_ctx
*ctx
,
1095 const char *service
,
1096 uint32_t num_includes
,
1097 const char **includes
)
1099 WERROR werr
= WERR_OK
;
1101 struct registry_key
*key
= NULL
;
1102 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
1104 err
= smbconf_reg_open_service_key(tmp_ctx
, ctx
, service
,
1106 if (!SBC_ERROR_IS_OK(err
)) {
1111 if (num_includes
== 0) {
1112 if (!smbconf_value_exists(key
, INCLUDES_VALNAME
)) {
1115 werr
= reg_deletevalue(key
, INCLUDES_VALNAME
);
1117 werr
= smbconf_reg_set_multi_sz_value(key
, INCLUDES_VALNAME
,
1118 num_includes
, includes
);
1122 talloc_free(tmp_ctx
);
1126 static WERROR
smbconf_reg_delete_includes(struct smbconf_ctx
*ctx
,
1127 const char *service
)
1129 WERROR werr
= WERR_OK
;
1131 struct registry_key
*key
= NULL
;
1132 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
1134 err
= smbconf_reg_open_service_key(tmp_ctx
, ctx
, service
,
1136 if (!SBC_ERROR_IS_OK(err
)) {
1141 if (!smbconf_value_exists(key
, INCLUDES_VALNAME
)) {
1145 werr
= reg_deletevalue(key
, INCLUDES_VALNAME
);
1149 talloc_free(tmp_ctx
);
1153 static WERROR
smbconf_reg_transaction_start(struct smbconf_ctx
*ctx
)
1155 return regdb_transaction_start();
1158 static WERROR
smbconf_reg_transaction_commit(struct smbconf_ctx
*ctx
)
1160 return regdb_transaction_commit();
1163 static WERROR
smbconf_reg_transaction_cancel(struct smbconf_ctx
*ctx
)
1165 return regdb_transaction_cancel();
1168 struct smbconf_ops smbconf_ops_reg
= {
1169 .init
= smbconf_reg_init
,
1170 .shutdown
= smbconf_reg_shutdown
,
1171 .requires_messaging
= smbconf_reg_requires_messaging
,
1172 .is_writeable
= smbconf_reg_is_writeable
,
1173 .open_conf
= smbconf_reg_open
,
1174 .close_conf
= smbconf_reg_close
,
1175 .get_csn
= smbconf_reg_get_csn
,
1176 .drop
= smbconf_reg_drop
,
1177 .get_share_names
= smbconf_reg_get_share_names
,
1178 .share_exists
= smbconf_reg_share_exists
,
1179 .create_share
= smbconf_reg_create_share
,
1180 .get_share
= smbconf_reg_get_share
,
1181 .delete_share
= smbconf_reg_delete_share
,
1182 .set_parameter
= smbconf_reg_set_parameter
,
1183 .get_parameter
= smbconf_reg_get_parameter
,
1184 .delete_parameter
= smbconf_reg_delete_parameter
,
1185 .get_includes
= smbconf_reg_get_includes
,
1186 .set_includes
= smbconf_reg_set_includes
,
1187 .delete_includes
= smbconf_reg_delete_includes
,
1188 .transaction_start
= smbconf_reg_transaction_start
,
1189 .transaction_commit
= smbconf_reg_transaction_commit
,
1190 .transaction_cancel
= smbconf_reg_transaction_cancel
,
1195 * initialize the smbconf registry backend
1196 * the only function that is exported from this module
1198 sbcErr
smbconf_init_reg(TALLOC_CTX
*mem_ctx
, struct smbconf_ctx
**conf_ctx
,
1201 return smbconf_init_internal(mem_ctx
, conf_ctx
, path
, &smbconf_ops_reg
);