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 parameter name is valid in the
55 * smbconf registry backend.
57 bool smbconf_reg_parameter_is_valid(const char *param_name)
59 /* hard code the list of forbidden names here for now */
60 const char *forbidden_names[] = {
67 * "includes" has a special meaning internally.
68 * It is currently not necessary to list it here since it is
69 * not a valid parameter. But for clarity and safety, we keep
75 const char **forbidden = NULL;
77 if (!lp_parameter_is_valid(param_name)) {
81 for (forbidden = forbidden_names; *forbidden != NULL; forbidden++) {
82 if (strwicmp(param_name, *forbidden) == 0) {
91 * Open a subkey of the base key (i.e a service)
93 static sbcErr smbconf_reg_open_service_key(TALLOC_CTX *mem_ctx,
94 struct smbconf_ctx *ctx,
95 const char *servicename,
96 uint32_t desired_access,
97 struct registry_key **key)
101 if (servicename == NULL) {
102 *key = rpd(ctx)->base_key;
105 werr = reg_openkey(mem_ctx, rpd(ctx)->base_key, servicename,
106 desired_access, key);
107 if (W_ERROR_EQUAL(werr, WERR_FILE_NOT_FOUND)) {
108 return SBC_ERR_NO_SUCH_SERVICE;
110 if (!W_ERROR_IS_OK(werr)) {
111 return SBC_ERR_NOMEM;
118 * check if a value exists in a given registry key
120 static bool smbconf_value_exists(struct registry_key *key, const char *param)
124 TALLOC_CTX *ctx = talloc_stackframe();
125 struct registry_value *value = NULL;
127 werr = reg_queryvalue(ctx, key, param, &value);
128 if (W_ERROR_IS_OK(werr)) {
137 * create a subkey of the base key (i.e. a service...)
139 static sbcErr smbconf_reg_create_service_key(TALLOC_CTX *mem_ctx,
140 struct smbconf_ctx *ctx,
141 const char * subkeyname,
142 struct registry_key **newkey)
145 sbcErr err = SBC_ERR_OK;
146 TALLOC_CTX *create_ctx;
147 enum winreg_CreateAction action = REG_ACTION_NONE;
149 /* create a new talloc ctx for creation. it will hold
150 * the intermediate parent key (SMBCONF) for creation
151 * and will be destroyed when leaving this function... */
152 create_ctx = talloc_stackframe();
154 werr = reg_createkey(mem_ctx, rpd(ctx)->base_key, subkeyname,
155 REG_KEY_WRITE, newkey, &action);
156 if (W_ERROR_IS_OK(werr) && (action != REG_CREATED_NEW_KEY)) {
157 DEBUG(10, ("Key '%s' already exists.\n", subkeyname));
158 err = SBC_ERR_FILE_EXISTS;
160 if (!W_ERROR_IS_OK(werr)) {
161 DEBUG(5, ("Error creating key %s: %s\n",
162 subkeyname, win_errstr(werr)));
163 err = SBC_ERR_UNKNOWN_FAILURE;
166 talloc_free(create_ctx);
171 * add a value to a key.
173 static sbcErr smbconf_reg_set_value(struct registry_key *key,
177 struct registry_value val;
181 const char *canon_valname;
182 const char *canon_valstr;
184 if (!lp_parameter_is_valid(valname)) {
185 DEBUG(5, ("Invalid parameter '%s' given.\n", valname));
186 err = SBC_ERR_INVALID_PARAM;
190 if (!smbconf_reg_parameter_is_valid(valname)) {
191 DEBUG(5, ("Parameter '%s' not allowed in registry.\n",
193 err = SBC_ERR_INVALID_PARAM;
197 subkeyname = strrchr_m(key->key->name, '\\');
198 if ((subkeyname == NULL) || (*(subkeyname +1) == '\0')) {
199 DEBUG(5, ("Invalid registry key '%s' given as "
200 "smbconf section.\n", key->key->name));
201 err = SBC_ERR_INVALID_PARAM;
205 if (!strequal(subkeyname, GLOBAL_NAME) &&
206 lp_parameter_is_global(valname))
208 DEBUG(5, ("Global parameter '%s' not allowed in "
209 "service definition ('%s').\n", valname,
211 err = SBC_ERR_INVALID_PARAM;
215 if (!lp_canonicalize_parameter_with_value(valname, valstr,
220 * We already know the parameter name is valid.
221 * So the value must be invalid.
223 DEBUG(5, ("invalid value '%s' given for parameter '%s'\n",
225 err = SBC_ERR_INVALID_PARAM;
232 if (!push_reg_sz(talloc_tos(), &val.data, canon_valstr)) {
237 werr = reg_setvalue(key, canon_valname, &val);
238 if (!W_ERROR_IS_OK(werr)) {
239 DEBUG(5, ("Error adding value '%s' to "
241 canon_valname, key->key->name, win_errstr(werr)));
251 static sbcErr smbconf_reg_set_multi_sz_value(struct registry_key *key,
253 const uint32_t num_strings,
254 const char **strings)
257 sbcErr err = SBC_ERR_OK;
258 struct registry_value *value;
260 TALLOC_CTX *tmp_ctx = talloc_stackframe();
263 if (strings == NULL) {
264 err = SBC_ERR_INVALID_PARAM;
268 array = talloc_zero_array(tmp_ctx, const char *, num_strings + 1);
274 value = talloc_zero(tmp_ctx, struct registry_value);
280 value->type = REG_MULTI_SZ;
282 for (count = 0; count < num_strings; count++) {
283 array[count] = talloc_strdup(value, strings[count]);
284 if (array[count] == NULL) {
290 if (!push_reg_multi_sz(value, &value->data, array)) {
295 werr = reg_setvalue(key, valname, value);
296 if (!W_ERROR_IS_OK(werr)) {
297 DEBUG(5, ("Error adding value '%s' to key '%s': %s\n",
298 valname, key->key->name, win_errstr(werr)));
299 err = SBC_ERR_ACCESS_DENIED;
303 talloc_free(tmp_ctx);
308 * format a registry_value into a string.
310 * This is intended to be used for smbconf registry values,
311 * which are ar stored as REG_SZ values, so the incomplete
312 * handling should be ok.
314 static char *smbconf_format_registry_value(TALLOC_CTX *mem_ctx,
315 struct registry_value *value)
319 /* alternatively, create a new talloc context? */
320 if (mem_ctx == NULL) {
324 switch (value->type) {
326 if (value->data.length >= 4) {
327 uint32_t v = IVAL(value->data.data, 0);
328 result = talloc_asprintf(mem_ctx, "%d", v);
332 case REG_EXPAND_SZ: {
334 if (!pull_reg_sz(mem_ctx, &value->data, &s)) {
337 result = talloc_strdup(mem_ctx, s);
342 const char **a = NULL;
343 if (!pull_reg_multi_sz(mem_ctx, &value->data, &a)) {
346 for (j = 0; a[j] != NULL; j++) {
347 result = talloc_asprintf(mem_ctx, "%s\"%s\" ",
348 result ? result : "" ,
350 if (result == NULL) {
357 result = talloc_asprintf(mem_ctx, "binary (%d bytes)",
358 (int)value->data.length);
361 result = talloc_asprintf(mem_ctx, "<unprintable>");
367 static sbcErr smbconf_reg_get_includes_internal(TALLOC_CTX *mem_ctx,
368 struct registry_key *key,
369 uint32_t *num_includes,
375 struct registry_value *value = NULL;
376 char **tmp_includes = NULL;
377 const char **array = NULL;
378 TALLOC_CTX *tmp_ctx = talloc_stackframe();
380 if (!smbconf_value_exists(key, INCLUDES_VALNAME)) {
388 werr = reg_queryvalue(tmp_ctx, key, INCLUDES_VALNAME, &value);
389 if (!W_ERROR_IS_OK(werr)) {
390 err = SBC_ERR_ACCESS_DENIED;
394 if (value->type != REG_MULTI_SZ) {
395 /* wrong type -- ignore */
400 if (!pull_reg_multi_sz(tmp_ctx, &value->data, &array)) {
405 for (count = 0; array[count] != NULL; count++) {
406 err = smbconf_add_string_to_array(tmp_ctx,
410 if (!SBC_ERROR_IS_OK(err)) {
416 *includes = talloc_move(mem_ctx, &tmp_includes);
417 if (*includes == NULL) {
421 *num_includes = count;
429 talloc_free(tmp_ctx);
434 * Get the values of a key as a list of value names
435 * and a list of value strings (ordered)
437 static sbcErr smbconf_reg_get_values(TALLOC_CTX *mem_ctx,
438 struct registry_key *key,
439 uint32_t *num_values,
441 char ***value_strings)
443 TALLOC_CTX *tmp_ctx = NULL;
447 struct registry_value *valvalue = NULL;
448 char *valname = NULL;
449 uint32_t tmp_num_values = 0;
450 char **tmp_valnames = NULL;
451 char **tmp_valstrings = NULL;
452 uint32_t num_includes = 0;
453 char **includes = NULL;
455 if ((num_values == NULL) || (value_names == NULL) ||
456 (value_strings == NULL))
458 err = SBC_ERR_INVALID_PARAM;
462 tmp_ctx = talloc_stackframe();
465 werr = reg_enumvalue(tmp_ctx, key, count, &valname, &valvalue),
471 if (!smbconf_reg_parameter_is_valid(valname)) {
475 err = smbconf_add_string_to_array(tmp_ctx,
477 tmp_num_values, valname);
478 if (!SBC_ERROR_IS_OK(err)) {
482 valstring = smbconf_format_registry_value(tmp_ctx, valvalue);
483 err = smbconf_add_string_to_array(tmp_ctx, &tmp_valstrings,
484 tmp_num_values, valstring);
485 if (!SBC_ERROR_IS_OK(err)) {
490 if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) {
495 /* now add the includes at the end */
496 err = smbconf_reg_get_includes_internal(tmp_ctx, key, &num_includes,
498 if (!SBC_ERROR_IS_OK(err)) {
502 for (count = 0; count < num_includes; count++) {
503 err = smbconf_add_string_to_array(tmp_ctx, &tmp_valnames,
504 tmp_num_values, "include");
505 if (!SBC_ERROR_IS_OK(err)) {
509 err = smbconf_add_string_to_array(tmp_ctx, &tmp_valstrings,
512 if (!SBC_ERROR_IS_OK(err)) {
519 *num_values = tmp_num_values;
520 if (tmp_num_values > 0) {
521 *value_names = talloc_move(mem_ctx, &tmp_valnames);
522 *value_strings = talloc_move(mem_ctx, &tmp_valstrings);
525 *value_strings = NULL;
529 talloc_free(tmp_ctx);
534 * delete all values from a key
536 static sbcErr smbconf_reg_delete_values(struct registry_key *key)
541 struct registry_value *valvalue;
543 TALLOC_CTX *mem_ctx = talloc_stackframe();
546 werr = reg_enumvalue(mem_ctx, key, count, &valname, &valvalue),
550 werr = reg_deletevalue(key, valname);
551 if (!W_ERROR_IS_OK(werr)) {
552 err = SBC_ERR_ACCESS_DENIED;
556 if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) {
557 DEBUG(1, ("smbconf_reg_delete_values: "
558 "Error enumerating values of %s: %s\n",
561 err = SBC_ERR_ACCESS_DENIED;
568 talloc_free(mem_ctx);
572 /**********************************************************************
574 * smbconf operations: registry implementations
576 **********************************************************************/
579 * initialize the registry smbconf backend
581 static sbcErr smbconf_reg_init(struct smbconf_ctx *ctx, const char *path)
585 struct security_token *token;
590 ctx->path = talloc_strdup(ctx, path);
591 if (ctx->path == NULL) {
596 ctx->data = talloc_zero(ctx, struct reg_private_data);
598 werr = ntstatus_to_werror(registry_create_admin_token(ctx, &token));
599 if (!W_ERROR_IS_OK(werr)) {
600 DEBUG(1, ("Error creating admin token\n"));
601 err = SBC_ERR_UNKNOWN_FAILURE;
604 rpd(ctx)->open = false;
606 werr = registry_init_smbconf(path);
607 if (!W_ERROR_IS_OK(werr)) {
608 err = SBC_ERR_BADFILE;
612 err = ctx->ops->open_conf(ctx);
613 if (!SBC_ERROR_IS_OK(err)) {
614 DEBUG(1, ("Error opening the registry.\n"));
618 werr = reg_open_path(ctx, ctx->path,
619 KEY_ENUMERATE_SUB_KEYS | REG_KEY_WRITE,
620 token, &rpd(ctx)->base_key);
621 if (!W_ERROR_IS_OK(werr)) {
622 err = SBC_ERR_UNKNOWN_FAILURE;
630 static int smbconf_reg_shutdown(struct smbconf_ctx *ctx)
632 return ctx->ops->close_conf(ctx);
635 static bool smbconf_reg_requires_messaging(struct smbconf_ctx *ctx)
637 if (lp_clustering() && lp_parm_bool(-1, "ctdb", "registry.tdb", true)) {
644 static bool smbconf_reg_is_writeable(struct smbconf_ctx *ctx)
647 * The backend has write support.
649 * TODO: add access checks whether the concrete
650 * config source is really writeable by the calling user.
655 static sbcErr smbconf_reg_open(struct smbconf_ctx *ctx)
659 if (rpd(ctx)->open) {
664 if (!W_ERROR_IS_OK(werr)) {
665 return SBC_ERR_BADFILE;
668 rpd(ctx)->open = true;
672 static int smbconf_reg_close(struct smbconf_ctx *ctx)
676 if (!rpd(ctx)->open) {
682 rpd(ctx)->open = false;
688 * Get the change sequence number of the given service/parameter.
689 * service and parameter strings may be NULL.
691 static void smbconf_reg_get_csn(struct smbconf_ctx *ctx,
692 struct smbconf_csn *csn,
693 const char *service, const char *param)
699 if (!SBC_ERROR_IS_OK(ctx->ops->open_conf(ctx))) {
703 csn->csn = (uint64_t)regdb_get_seqnum();
707 * Drop the whole configuration (restarting empty) - registry version
709 static sbcErr smbconf_reg_drop(struct smbconf_ctx *ctx)
713 sbcErr err = SBC_ERR_OK;
714 struct registry_key *parent_key = NULL;
715 struct registry_key *new_key = NULL;
716 TALLOC_CTX* mem_ctx = talloc_stackframe();
717 enum winreg_CreateAction action;
718 struct security_token *token;
720 werr = ntstatus_to_werror(registry_create_admin_token(ctx, &token));
721 if (!W_ERROR_IS_OK(werr)) {
722 DEBUG(1, ("Error creating admin token\n"));
723 err = SBC_ERR_UNKNOWN_FAILURE;
727 path = talloc_strdup(mem_ctx, ctx->path);
732 p = strrchr(path, '\\');
734 err = SBC_ERR_INVALID_PARAM;
738 werr = reg_open_path(mem_ctx, path, REG_KEY_WRITE, token,
740 if (!W_ERROR_IS_OK(werr)) {
741 err = SBC_ERR_IO_FAILURE;
745 werr = reg_deletesubkeys_recursive(parent_key, p+1);
746 if (!W_ERROR_IS_OK(werr)) {
747 err = SBC_ERR_IO_FAILURE;
751 werr = reg_createkey(mem_ctx, parent_key, p+1, REG_KEY_WRITE,
753 if (!W_ERROR_IS_OK(werr)) {
754 err = SBC_ERR_IO_FAILURE;
759 talloc_free(mem_ctx);
764 * get the list of share names defined in the configuration.
767 static sbcErr smbconf_reg_get_share_names(struct smbconf_ctx *ctx,
769 uint32_t *num_shares,
773 uint32_t added_count = 0;
774 TALLOC_CTX *tmp_ctx = NULL;
776 sbcErr err = SBC_ERR_OK;
777 char *subkey_name = NULL;
778 char **tmp_share_names = NULL;
780 if ((num_shares == NULL) || (share_names == NULL)) {
781 return SBC_ERR_INVALID_PARAM;
784 tmp_ctx = talloc_stackframe();
786 /* make sure "global" is always listed first */
787 if (smbconf_share_exists(ctx, GLOBAL_NAME)) {
788 err = smbconf_add_string_to_array(tmp_ctx, &tmp_share_names,
789 added_count, GLOBAL_NAME);
790 if (!SBC_ERROR_IS_OK(err)) {
797 werr = reg_enumkey(tmp_ctx, rpd(ctx)->base_key, count,
802 if (strequal(subkey_name, GLOBAL_NAME)) {
806 err = smbconf_add_string_to_array(tmp_ctx,
810 if (!SBC_ERROR_IS_OK(err)) {
815 if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) {
816 err = SBC_ERR_NO_MORE_ITEMS;
821 *num_shares = added_count;
822 if (added_count > 0) {
823 *share_names = talloc_move(mem_ctx, &tmp_share_names);
829 talloc_free(tmp_ctx);
834 * check if a share/service of a given name exists - registry version
836 static bool smbconf_reg_share_exists(struct smbconf_ctx *ctx,
837 const char *servicename)
841 TALLOC_CTX *mem_ctx = talloc_stackframe();
842 struct registry_key *key = NULL;
844 err = smbconf_reg_open_service_key(mem_ctx, ctx, servicename,
846 if (SBC_ERROR_IS_OK(err)) {
850 talloc_free(mem_ctx);
855 * Add a service if it does not already exist - registry version
857 static sbcErr smbconf_reg_create_share(struct smbconf_ctx *ctx,
858 const char *servicename)
861 struct registry_key *key = NULL;
863 if (servicename == NULL) {
867 err = smbconf_reg_create_service_key(talloc_tos(), ctx,
875 * get a definition of a share (service) from configuration.
877 static sbcErr smbconf_reg_get_share(struct smbconf_ctx *ctx,
879 const char *servicename,
880 struct smbconf_service **service)
883 struct registry_key *key = NULL;
884 struct smbconf_service *tmp_service = NULL;
885 TALLOC_CTX *tmp_ctx = talloc_stackframe();
887 err = smbconf_reg_open_service_key(tmp_ctx, ctx, servicename,
889 if (!SBC_ERROR_IS_OK(err)) {
893 tmp_service = talloc_zero(tmp_ctx, struct smbconf_service);
894 if (tmp_service == NULL) {
899 if (servicename != NULL) {
905 * Determine correct upper/lowercase.
908 werr = reg_enumkey(tmp_ctx, rpd(ctx)->base_key, count,
912 if (!strequal(name, servicename)) {
916 tmp_service->name = talloc_strdup(tmp_service, name);
917 if (tmp_service->name == NULL) {
925 err = smbconf_reg_get_values(tmp_service, key,
926 &(tmp_service->num_params),
927 &(tmp_service->param_names),
928 &(tmp_service->param_values));
929 if (SBC_ERROR_IS_OK(err)) {
930 *service = talloc_move(mem_ctx, &tmp_service);
934 talloc_free(tmp_ctx);
939 * delete a service from configuration
941 static sbcErr smbconf_reg_delete_share(struct smbconf_ctx *ctx,
942 const char *servicename)
945 sbcErr err = SBC_ERR_OK;
946 TALLOC_CTX *mem_ctx = talloc_stackframe();
948 if (servicename != NULL) {
949 werr = reg_deletekey_recursive(rpd(ctx)->base_key, servicename);
950 if (!W_ERROR_IS_OK(werr)) {
951 err = SBC_ERR_ACCESS_DENIED;
954 err = smbconf_reg_delete_values(rpd(ctx)->base_key);
957 talloc_free(mem_ctx);
962 * set a configuration parameter to the value provided.
964 static sbcErr smbconf_reg_set_parameter(struct smbconf_ctx *ctx,
970 struct registry_key *key = NULL;
971 TALLOC_CTX *mem_ctx = talloc_stackframe();
973 err = smbconf_reg_open_service_key(mem_ctx, ctx, service,
974 REG_KEY_WRITE, &key);
975 if (!SBC_ERROR_IS_OK(err)) {
979 err = smbconf_reg_set_value(key, param, valstr);
982 talloc_free(mem_ctx);
987 * get the value of a configuration parameter as a string
989 static sbcErr smbconf_reg_get_parameter(struct smbconf_ctx *ctx,
997 struct registry_key *key = NULL;
998 struct registry_value *value = NULL;
1000 err = smbconf_reg_open_service_key(mem_ctx, ctx, service,
1001 REG_KEY_READ, &key);
1002 if (!SBC_ERROR_IS_OK(err)) {
1006 if (!smbconf_reg_parameter_is_valid(param)) {
1007 err = SBC_ERR_INVALID_PARAM;
1011 if (!smbconf_value_exists(key, param)) {
1012 err = SBC_ERR_INVALID_PARAM;
1016 werr = reg_queryvalue(mem_ctx, key, param, &value);
1017 if (!W_ERROR_IS_OK(werr)) {
1018 err = SBC_ERR_NOMEM;
1022 *valstr = smbconf_format_registry_value(mem_ctx, value);
1023 if (*valstr == NULL) {
1024 err = SBC_ERR_NOMEM;
1034 * delete a parameter from configuration
1036 static sbcErr smbconf_reg_delete_parameter(struct smbconf_ctx *ctx,
1037 const char *service,
1040 struct registry_key *key = NULL;
1043 TALLOC_CTX *mem_ctx = talloc_stackframe();
1045 err = smbconf_reg_open_service_key(mem_ctx, ctx, service,
1047 if (!SBC_ERROR_IS_OK(err)) {
1051 if (!smbconf_reg_parameter_is_valid(param)) {
1052 err = SBC_ERR_INVALID_PARAM;
1056 if (!smbconf_value_exists(key, param)) {
1061 werr = reg_deletevalue(key, param);
1062 if (!W_ERROR_IS_OK(werr)) {
1063 err = SBC_ERR_ACCESS_DENIED;
1067 talloc_free(mem_ctx);
1071 static sbcErr smbconf_reg_get_includes(struct smbconf_ctx *ctx,
1072 TALLOC_CTX *mem_ctx,
1073 const char *service,
1074 uint32_t *num_includes,
1078 struct registry_key *key = NULL;
1079 TALLOC_CTX *tmp_ctx = talloc_stackframe();
1081 err = smbconf_reg_open_service_key(tmp_ctx, ctx, service,
1082 REG_KEY_READ, &key);
1083 if (!SBC_ERROR_IS_OK(err)) {
1087 err = smbconf_reg_get_includes_internal(mem_ctx, key, num_includes,
1089 if (!SBC_ERROR_IS_OK(err)) {
1094 talloc_free(tmp_ctx);
1098 static sbcErr smbconf_reg_set_includes(struct smbconf_ctx *ctx,
1099 const char *service,
1100 uint32_t num_includes,
1101 const char **includes)
1104 struct registry_key *key = NULL;
1105 TALLOC_CTX *tmp_ctx = talloc_stackframe();
1107 err = smbconf_reg_open_service_key(tmp_ctx, ctx, service,
1109 if (!SBC_ERROR_IS_OK(err)) {
1113 if (num_includes == 0) {
1115 if (!smbconf_value_exists(key, INCLUDES_VALNAME)) {
1119 werr = reg_deletevalue(key, INCLUDES_VALNAME);
1120 if (!W_ERROR_IS_OK(werr)) {
1121 err = SBC_ERR_ACCESS_DENIED;
1125 err = smbconf_reg_set_multi_sz_value(key, INCLUDES_VALNAME,
1126 num_includes, includes);
1130 talloc_free(tmp_ctx);
1134 static sbcErr smbconf_reg_delete_includes(struct smbconf_ctx *ctx,
1135 const char *service)
1139 struct registry_key *key = NULL;
1140 TALLOC_CTX *tmp_ctx = talloc_stackframe();
1142 err = smbconf_reg_open_service_key(tmp_ctx, ctx, service,
1144 if (!SBC_ERROR_IS_OK(err)) {
1148 if (!smbconf_value_exists(key, INCLUDES_VALNAME)) {
1153 werr = reg_deletevalue(key, INCLUDES_VALNAME);
1154 if (!W_ERROR_IS_OK(werr)) {
1155 err = SBC_ERR_ACCESS_DENIED;
1161 talloc_free(tmp_ctx);
1165 static sbcErr smbconf_reg_transaction_start(struct smbconf_ctx *ctx)
1169 werr = regdb_transaction_start();
1170 if (!W_ERROR_IS_OK(werr)) {
1171 return SBC_ERR_IO_FAILURE;
1177 static sbcErr smbconf_reg_transaction_commit(struct smbconf_ctx *ctx)
1181 werr = regdb_transaction_commit();
1182 if (!W_ERROR_IS_OK(werr)) {
1183 return SBC_ERR_IO_FAILURE;
1189 static sbcErr smbconf_reg_transaction_cancel(struct smbconf_ctx *ctx)
1193 werr = regdb_transaction_cancel();
1194 if (!W_ERROR_IS_OK(werr)) {
1195 return SBC_ERR_IO_FAILURE;
1201 struct smbconf_ops smbconf_ops_reg = {
1202 .init = smbconf_reg_init,
1203 .shutdown = smbconf_reg_shutdown,
1204 .requires_messaging = smbconf_reg_requires_messaging,
1205 .is_writeable = smbconf_reg_is_writeable,
1206 .open_conf = smbconf_reg_open,
1207 .close_conf = smbconf_reg_close,
1208 .get_csn = smbconf_reg_get_csn,
1209 .drop = smbconf_reg_drop,
1210 .get_share_names = smbconf_reg_get_share_names,
1211 .share_exists = smbconf_reg_share_exists,
1212 .create_share = smbconf_reg_create_share,
1213 .get_share = smbconf_reg_get_share,
1214 .delete_share = smbconf_reg_delete_share,
1215 .set_parameter = smbconf_reg_set_parameter,
1216 .get_parameter = smbconf_reg_get_parameter,
1217 .delete_parameter = smbconf_reg_delete_parameter,
1218 .get_includes = smbconf_reg_get_includes,
1219 .set_includes = smbconf_reg_set_includes,
1220 .delete_includes = smbconf_reg_delete_includes,
1221 .transaction_start = smbconf_reg_transaction_start,
1222 .transaction_commit = smbconf_reg_transaction_commit,
1223 .transaction_cancel = smbconf_reg_transaction_cancel,
1228 * initialize the smbconf registry backend
1229 * the only function that is exported from this module
1231 sbcErr smbconf_init_reg(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx,
1234 return smbconf_init_internal(mem_ctx, conf_ctx, path, &smbconf_ops_reg);