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 sbcErr smbconf_reg_set_value(struct registry_key *key,
170 struct registry_value val;
171 WERROR werr = WERR_OK;
174 const char *canon_valname;
175 const char *canon_valstr;
177 if (!lp_canonicalize_parameter_with_value(valname, valstr,
181 if (canon_valname == NULL) {
182 DEBUG(5, ("invalid parameter '%s' given\n",
185 DEBUG(5, ("invalid value '%s' given for "
186 "parameter '%s'\n", valstr, valname));
188 err = SBC_ERR_INVALID_PARAM;
192 if (smbconf_reg_valname_forbidden(canon_valname)) {
193 DEBUG(5, ("Parameter '%s' not allowed in registry.\n",
195 err = SBC_ERR_INVALID_PARAM;
199 subkeyname = strrchr_m(key->key->name, '\\');
200 if ((subkeyname == NULL) || (*(subkeyname +1) == '\0')) {
201 DEBUG(5, ("Invalid registry key '%s' given as "
202 "smbconf section.\n", key->key->name));
203 err = SBC_ERR_INVALID_PARAM;
207 if (!strequal(subkeyname, GLOBAL_NAME) &&
208 lp_parameter_is_global(valname))
210 DEBUG(5, ("Global parameter '%s' not allowed in "
211 "service definition ('%s').\n", canon_valname,
213 err = SBC_ERR_INVALID_PARAM;
220 if (!push_reg_sz(talloc_tos(), &val.data, canon_valstr)) {
225 werr = reg_setvalue(key, canon_valname, &val);
226 if (!W_ERROR_IS_OK(werr)) {
227 DEBUG(5, ("Error adding value '%s' to "
229 canon_valname, key->key->name, win_errstr(werr)));
239 static WERROR smbconf_reg_set_multi_sz_value(struct registry_key *key,
241 const uint32_t num_strings,
242 const char **strings)
245 struct registry_value *value;
247 TALLOC_CTX *tmp_ctx = talloc_stackframe();
250 if (strings == NULL) {
251 werr = WERR_INVALID_PARAM;
255 array = talloc_zero_array(tmp_ctx, const char *, num_strings + 1);
261 value = TALLOC_ZERO_P(tmp_ctx, struct registry_value);
267 value->type = REG_MULTI_SZ;
269 for (count = 0; count < num_strings; count++) {
270 array[count] = talloc_strdup(value, strings[count]);
271 if (array[count] == NULL) {
277 if (!push_reg_multi_sz(value, &value->data, array)) {
282 werr = reg_setvalue(key, valname, value);
283 if (!W_ERROR_IS_OK(werr)) {
284 DEBUG(5, ("Error adding value '%s' to key '%s': %s\n",
285 valname, key->key->name, win_errstr(werr)));
289 talloc_free(tmp_ctx);
294 * format a registry_value into a string.
296 * This is intended to be used for smbconf registry values,
297 * which are ar stored as REG_SZ values, so the incomplete
298 * handling should be ok.
300 static char *smbconf_format_registry_value(TALLOC_CTX *mem_ctx,
301 struct registry_value *value)
305 /* alternatively, create a new talloc context? */
306 if (mem_ctx == NULL) {
310 switch (value->type) {
312 if (value->data.length >= 4) {
313 uint32_t v = IVAL(value->data.data, 0);
314 result = talloc_asprintf(mem_ctx, "%d", v);
318 case REG_EXPAND_SZ: {
320 if (!pull_reg_sz(mem_ctx, &value->data, &s)) {
323 result = talloc_strdup(mem_ctx, s);
328 const char **a = NULL;
329 if (!pull_reg_multi_sz(mem_ctx, &value->data, &a)) {
332 for (j = 0; a[j] != NULL; j++) {
333 result = talloc_asprintf(mem_ctx, "%s\"%s\" ",
334 result ? result : "" ,
336 if (result == NULL) {
343 result = talloc_asprintf(mem_ctx, "binary (%d bytes)",
344 (int)value->data.length);
347 result = talloc_asprintf(mem_ctx, "<unprintable>");
353 static sbcErr smbconf_reg_get_includes_internal(TALLOC_CTX *mem_ctx,
354 struct registry_key *key,
355 uint32_t *num_includes,
361 struct registry_value *value = NULL;
362 char **tmp_includes = NULL;
363 const char **array = NULL;
364 TALLOC_CTX *tmp_ctx = talloc_stackframe();
366 if (!smbconf_value_exists(key, INCLUDES_VALNAME)) {
374 werr = reg_queryvalue(tmp_ctx, key, INCLUDES_VALNAME, &value);
375 if (!W_ERROR_IS_OK(werr)) {
376 err = SBC_ERR_ACCESS_DENIED;
380 if (value->type != REG_MULTI_SZ) {
381 /* wrong type -- ignore */
386 if (!pull_reg_multi_sz(tmp_ctx, &value->data, &array)) {
391 for (count = 0; array[count] != NULL; count++) {
392 err = smbconf_add_string_to_array(tmp_ctx,
396 if (!SBC_ERROR_IS_OK(err)) {
403 *includes = talloc_move(mem_ctx, &tmp_includes);
404 if (*includes == NULL) {
408 *num_includes = count;
415 talloc_free(tmp_ctx);
420 * Get the values of a key as a list of value names
421 * and a list of value strings (ordered)
423 static sbcErr smbconf_reg_get_values(TALLOC_CTX *mem_ctx,
424 struct registry_key *key,
425 uint32_t *num_values,
427 char ***value_strings)
429 TALLOC_CTX *tmp_ctx = NULL;
430 WERROR werr = WERR_OK;
433 struct registry_value *valvalue = NULL;
434 char *valname = NULL;
435 uint32_t tmp_num_values = 0;
436 char **tmp_valnames = NULL;
437 char **tmp_valstrings = NULL;
438 uint32_t num_includes = 0;
439 char **includes = NULL;
441 if ((num_values == NULL) || (value_names == NULL) ||
442 (value_strings == NULL))
444 err = SBC_ERR_INVALID_PARAM;
448 tmp_ctx = talloc_stackframe();
451 werr = reg_enumvalue(tmp_ctx, key, count, &valname, &valvalue),
457 if (!smbconf_reg_valname_valid(valname)) {
461 err = smbconf_add_string_to_array(tmp_ctx,
463 tmp_num_values, valname);
464 if (!SBC_ERROR_IS_OK(err)) {
468 valstring = smbconf_format_registry_value(tmp_ctx, valvalue);
469 err = smbconf_add_string_to_array(tmp_ctx, &tmp_valstrings,
470 tmp_num_values, valstring);
471 if (!SBC_ERROR_IS_OK(err)) {
476 if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) {
481 /* now add the includes at the end */
482 err = smbconf_reg_get_includes_internal(tmp_ctx, key, &num_includes,
484 if (!SBC_ERROR_IS_OK(err)) {
488 for (count = 0; count < num_includes; count++) {
489 err = smbconf_add_string_to_array(tmp_ctx, &tmp_valnames,
490 tmp_num_values, "include");
491 if (!SBC_ERROR_IS_OK(err)) {
495 err = smbconf_add_string_to_array(tmp_ctx, &tmp_valstrings,
498 if (!SBC_ERROR_IS_OK(err)) {
505 *num_values = tmp_num_values;
506 if (tmp_num_values > 0) {
507 *value_names = talloc_move(mem_ctx, &tmp_valnames);
508 *value_strings = talloc_move(mem_ctx, &tmp_valstrings);
511 *value_strings = NULL;
515 talloc_free(tmp_ctx);
519 static bool smbconf_reg_key_has_values(struct registry_key *key)
522 uint32_t num_subkeys;
523 uint32_t max_subkeylen;
524 uint32_t max_subkeysize;
526 uint32_t max_valnamelen;
527 uint32_t max_valbufsize;
528 uint32_t secdescsize;
529 NTTIME last_changed_time;
531 werr = reg_queryinfokey(key, &num_subkeys, &max_subkeylen,
532 &max_subkeysize, &num_values, &max_valnamelen,
533 &max_valbufsize, &secdescsize,
535 if (!W_ERROR_IS_OK(werr)) {
539 return (num_values != 0);
543 * delete all values from a key
545 static sbcErr smbconf_reg_delete_values(struct registry_key *key)
550 struct registry_value *valvalue;
552 TALLOC_CTX *mem_ctx = talloc_stackframe();
555 werr = reg_enumvalue(mem_ctx, key, count, &valname, &valvalue),
559 werr = reg_deletevalue(key, valname);
560 if (!W_ERROR_IS_OK(werr)) {
561 err = SBC_ERR_ACCESS_DENIED;
565 if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) {
566 DEBUG(1, ("smbconf_reg_delete_values: "
567 "Error enumerating values of %s: %s\n",
570 err = SBC_ERR_ACCESS_DENIED;
577 talloc_free(mem_ctx);
581 /**********************************************************************
583 * smbconf operations: registry implementations
585 **********************************************************************/
588 * initialize the registry smbconf backend
590 static sbcErr smbconf_reg_init(struct smbconf_ctx *ctx, const char *path)
592 WERROR werr = WERR_OK;
594 struct security_token *token;
599 ctx->path = talloc_strdup(ctx, path);
600 if (ctx->path == NULL) {
605 ctx->data = TALLOC_ZERO_P(ctx, struct reg_private_data);
607 werr = ntstatus_to_werror(registry_create_admin_token(ctx, &token));
608 if (!W_ERROR_IS_OK(werr)) {
609 DEBUG(1, ("Error creating admin token\n"));
610 err = SBC_ERR_UNKNOWN_FAILURE;
613 rpd(ctx)->open = false;
615 werr = registry_init_smbconf(path);
616 if (!W_ERROR_IS_OK(werr)) {
617 err = SBC_ERR_BADFILE;
621 err = ctx->ops->open_conf(ctx);
622 if (!SBC_ERROR_IS_OK(err)) {
623 DEBUG(1, ("Error opening the registry.\n"));
627 werr = reg_open_path(ctx, ctx->path,
628 KEY_ENUMERATE_SUB_KEYS | REG_KEY_WRITE,
629 token, &rpd(ctx)->base_key);
630 if (!W_ERROR_IS_OK(werr)) {
631 err = SBC_ERR_UNKNOWN_FAILURE;
639 static int smbconf_reg_shutdown(struct smbconf_ctx *ctx)
641 return ctx->ops->close_conf(ctx);
644 static bool smbconf_reg_requires_messaging(struct smbconf_ctx *ctx)
646 #ifdef CLUSTER_SUPPORT
647 if (lp_clustering() && lp_parm_bool(-1, "ctdb", "registry.tdb", true)) {
654 static bool smbconf_reg_is_writeable(struct smbconf_ctx *ctx)
657 * The backend has write support.
659 * TODO: add access checks whether the concrete
660 * config source is really writeable by the calling user.
665 static sbcErr smbconf_reg_open(struct smbconf_ctx *ctx)
669 if (rpd(ctx)->open) {
674 if (!W_ERROR_IS_OK(werr)) {
675 return SBC_ERR_BADFILE;
678 rpd(ctx)->open = true;
682 static int smbconf_reg_close(struct smbconf_ctx *ctx)
686 if (!rpd(ctx)->open) {
692 rpd(ctx)->open = false;
698 * Get the change sequence number of the given service/parameter.
699 * service and parameter strings may be NULL.
701 static void smbconf_reg_get_csn(struct smbconf_ctx *ctx,
702 struct smbconf_csn *csn,
703 const char *service, const char *param)
709 if (!SBC_ERROR_IS_OK(ctx->ops->open_conf(ctx))) {
713 csn->csn = (uint64_t)regdb_get_seqnum();
717 * Drop the whole configuration (restarting empty) - registry version
719 static sbcErr smbconf_reg_drop(struct smbconf_ctx *ctx)
722 WERROR werr = WERR_OK;
723 sbcErr err = SBC_ERR_OK;
724 struct registry_key *parent_key = NULL;
725 struct registry_key *new_key = NULL;
726 TALLOC_CTX* mem_ctx = talloc_stackframe();
727 enum winreg_CreateAction action;
728 struct security_token *token;
730 werr = ntstatus_to_werror(registry_create_admin_token(ctx, &token));
731 if (!W_ERROR_IS_OK(werr)) {
732 DEBUG(1, ("Error creating admin token\n"));
733 err = SBC_ERR_UNKNOWN_FAILURE;
737 path = talloc_strdup(mem_ctx, ctx->path);
742 p = strrchr(path, '\\');
744 err = SBC_ERR_INVALID_PARAM;
748 werr = reg_open_path(mem_ctx, path, REG_KEY_WRITE, token,
750 if (!W_ERROR_IS_OK(werr)) {
751 err = SBC_ERR_IO_FAILURE;
755 werr = reg_deletekey_recursive(parent_key, p+1);
756 if (!W_ERROR_IS_OK(werr)) {
757 err = SBC_ERR_IO_FAILURE;
761 werr = reg_createkey(mem_ctx, parent_key, p+1, REG_KEY_WRITE,
763 if (!W_ERROR_IS_OK(werr)) {
764 err = SBC_ERR_IO_FAILURE;
769 talloc_free(mem_ctx);
774 * get the list of share names defined in the configuration.
777 static sbcErr smbconf_reg_get_share_names(struct smbconf_ctx *ctx,
779 uint32_t *num_shares,
783 uint32_t added_count = 0;
784 TALLOC_CTX *tmp_ctx = NULL;
786 sbcErr err = SBC_ERR_OK;
787 char *subkey_name = NULL;
788 char **tmp_share_names = NULL;
790 if ((num_shares == NULL) || (share_names == NULL)) {
791 return SBC_ERR_INVALID_PARAM;
794 tmp_ctx = talloc_stackframe();
796 /* if there are values in the base key, return NULL as share name */
798 if (smbconf_reg_key_has_values(rpd(ctx)->base_key)) {
799 err = smbconf_add_string_to_array(tmp_ctx, &tmp_share_names,
801 if (!SBC_ERROR_IS_OK(err)) {
807 /* make sure "global" is always listed first */
808 if (smbconf_share_exists(ctx, GLOBAL_NAME)) {
809 err = smbconf_add_string_to_array(tmp_ctx, &tmp_share_names,
810 added_count, GLOBAL_NAME);
811 if (!SBC_ERROR_IS_OK(err)) {
818 werr = reg_enumkey(tmp_ctx, rpd(ctx)->base_key, count,
823 if (strequal(subkey_name, GLOBAL_NAME)) {
827 err = smbconf_add_string_to_array(tmp_ctx,
831 if (!SBC_ERROR_IS_OK(err)) {
836 if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) {
837 err = SBC_ERR_NO_MORE_ITEMS;
842 *num_shares = added_count;
843 if (added_count > 0) {
844 *share_names = talloc_move(mem_ctx, &tmp_share_names);
850 talloc_free(tmp_ctx);
855 * check if a share/service of a given name exists - registry version
857 static bool smbconf_reg_share_exists(struct smbconf_ctx *ctx,
858 const char *servicename)
862 TALLOC_CTX *mem_ctx = talloc_stackframe();
863 struct registry_key *key = NULL;
865 err = smbconf_reg_open_service_key(mem_ctx, ctx, servicename,
867 if (SBC_ERROR_IS_OK(err)) {
871 talloc_free(mem_ctx);
876 * Add a service if it does not already exist - registry version
878 static sbcErr smbconf_reg_create_share(struct smbconf_ctx *ctx,
879 const char *servicename)
882 struct registry_key *key = NULL;
884 if (servicename == NULL) {
888 err = smbconf_reg_create_service_key(talloc_tos(), ctx,
896 * get a definition of a share (service) from configuration.
898 static sbcErr smbconf_reg_get_share(struct smbconf_ctx *ctx,
900 const char *servicename,
901 struct smbconf_service **service)
904 struct registry_key *key = NULL;
905 struct smbconf_service *tmp_service = NULL;
906 TALLOC_CTX *tmp_ctx = talloc_stackframe();
908 err = smbconf_reg_open_service_key(tmp_ctx, ctx, servicename,
910 if (!SBC_ERROR_IS_OK(err)) {
914 tmp_service = TALLOC_ZERO_P(tmp_ctx, struct smbconf_service);
915 if (tmp_service == NULL) {
920 if (servicename != NULL) {
921 tmp_service->name = talloc_strdup(tmp_service, servicename);
922 if (tmp_service->name == NULL) {
928 err = smbconf_reg_get_values(tmp_service, key,
929 &(tmp_service->num_params),
930 &(tmp_service->param_names),
931 &(tmp_service->param_values));
932 if (SBC_ERROR_IS_OK(err)) {
933 *service = talloc_move(mem_ctx, &tmp_service);
937 talloc_free(tmp_ctx);
942 * delete a service from configuration
944 static sbcErr smbconf_reg_delete_share(struct smbconf_ctx *ctx,
945 const char *servicename)
948 sbcErr err = SBC_ERR_OK;
949 TALLOC_CTX *mem_ctx = talloc_stackframe();
951 if (servicename != NULL) {
952 werr = reg_deletekey_recursive(rpd(ctx)->base_key, servicename);
953 if (!W_ERROR_IS_OK(werr)) {
954 err = SBC_ERR_ACCESS_DENIED;
957 err = smbconf_reg_delete_values(rpd(ctx)->base_key);
960 talloc_free(mem_ctx);
965 * set a configuration parameter to the value provided.
967 static sbcErr smbconf_reg_set_parameter(struct smbconf_ctx *ctx,
973 struct registry_key *key = NULL;
974 TALLOC_CTX *mem_ctx = talloc_stackframe();
976 err = smbconf_reg_open_service_key(mem_ctx, ctx, service,
977 REG_KEY_WRITE, &key);
978 if (!SBC_ERROR_IS_OK(err)) {
982 err = smbconf_reg_set_value(key, param, valstr);
985 talloc_free(mem_ctx);
990 * get the value of a configuration parameter as a string
992 static WERROR smbconf_reg_get_parameter(struct smbconf_ctx *ctx,
998 WERROR werr = WERR_OK;
1000 struct registry_key *key = NULL;
1001 struct registry_value *value = NULL;
1003 err = smbconf_reg_open_service_key(mem_ctx, ctx, service,
1004 REG_KEY_READ, &key);
1005 if (!SBC_ERROR_IS_OK(err)) {
1010 if (!smbconf_reg_valname_valid(param)) {
1011 werr = WERR_INVALID_PARAM;
1015 if (!smbconf_value_exists(key, param)) {
1016 werr = WERR_INVALID_PARAM;
1020 werr = reg_queryvalue(mem_ctx, key, param, &value);
1021 if (!W_ERROR_IS_OK(werr)) {
1025 *valstr = smbconf_format_registry_value(mem_ctx, value);
1027 if (*valstr == NULL) {
1038 * delete a parameter from configuration
1040 static WERROR smbconf_reg_delete_parameter(struct smbconf_ctx *ctx,
1041 const char *service,
1044 struct registry_key *key = NULL;
1045 WERROR werr = WERR_OK;
1047 TALLOC_CTX *mem_ctx = talloc_stackframe();
1049 err = smbconf_reg_open_service_key(mem_ctx, ctx, service,
1051 if (!SBC_ERROR_IS_OK(err)) {
1056 if (!smbconf_reg_valname_valid(param)) {
1057 werr = WERR_INVALID_PARAM;
1061 if (!smbconf_value_exists(key, param)) {
1062 werr = WERR_INVALID_PARAM;
1066 werr = reg_deletevalue(key, param);
1069 talloc_free(mem_ctx);
1073 static WERROR smbconf_reg_get_includes(struct smbconf_ctx *ctx,
1074 TALLOC_CTX *mem_ctx,
1075 const char *service,
1076 uint32_t *num_includes,
1081 struct registry_key *key = NULL;
1082 TALLOC_CTX *tmp_ctx = talloc_stackframe();
1084 err = smbconf_reg_open_service_key(tmp_ctx, ctx, service,
1085 REG_KEY_READ, &key);
1086 if (!SBC_ERROR_IS_OK(err)) {
1091 err = smbconf_reg_get_includes_internal(mem_ctx, key, num_includes,
1093 if (!SBC_ERROR_IS_OK(err)) {
1099 talloc_free(tmp_ctx);
1103 static WERROR smbconf_reg_set_includes(struct smbconf_ctx *ctx,
1104 const char *service,
1105 uint32_t num_includes,
1106 const char **includes)
1108 WERROR werr = WERR_OK;
1110 struct registry_key *key = NULL;
1111 TALLOC_CTX *tmp_ctx = talloc_stackframe();
1113 err = smbconf_reg_open_service_key(tmp_ctx, ctx, service,
1115 if (!SBC_ERROR_IS_OK(err)) {
1120 if (num_includes == 0) {
1121 if (!smbconf_value_exists(key, INCLUDES_VALNAME)) {
1124 werr = reg_deletevalue(key, INCLUDES_VALNAME);
1126 werr = smbconf_reg_set_multi_sz_value(key, INCLUDES_VALNAME,
1127 num_includes, includes);
1131 talloc_free(tmp_ctx);
1135 static WERROR smbconf_reg_delete_includes(struct smbconf_ctx *ctx,
1136 const char *service)
1138 WERROR werr = WERR_OK;
1140 struct registry_key *key = NULL;
1141 TALLOC_CTX *tmp_ctx = talloc_stackframe();
1143 err = smbconf_reg_open_service_key(tmp_ctx, ctx, service,
1145 if (!SBC_ERROR_IS_OK(err)) {
1150 if (!smbconf_value_exists(key, INCLUDES_VALNAME)) {
1154 werr = reg_deletevalue(key, INCLUDES_VALNAME);
1158 talloc_free(tmp_ctx);
1162 static WERROR smbconf_reg_transaction_start(struct smbconf_ctx *ctx)
1164 return regdb_transaction_start();
1167 static WERROR smbconf_reg_transaction_commit(struct smbconf_ctx *ctx)
1169 return regdb_transaction_commit();
1172 static WERROR smbconf_reg_transaction_cancel(struct smbconf_ctx *ctx)
1174 return regdb_transaction_cancel();
1177 struct smbconf_ops smbconf_ops_reg = {
1178 .init = smbconf_reg_init,
1179 .shutdown = smbconf_reg_shutdown,
1180 .requires_messaging = smbconf_reg_requires_messaging,
1181 .is_writeable = smbconf_reg_is_writeable,
1182 .open_conf = smbconf_reg_open,
1183 .close_conf = smbconf_reg_close,
1184 .get_csn = smbconf_reg_get_csn,
1185 .drop = smbconf_reg_drop,
1186 .get_share_names = smbconf_reg_get_share_names,
1187 .share_exists = smbconf_reg_share_exists,
1188 .create_share = smbconf_reg_create_share,
1189 .get_share = smbconf_reg_get_share,
1190 .delete_share = smbconf_reg_delete_share,
1191 .set_parameter = smbconf_reg_set_parameter,
1192 .get_parameter = smbconf_reg_get_parameter,
1193 .delete_parameter = smbconf_reg_delete_parameter,
1194 .get_includes = smbconf_reg_get_includes,
1195 .set_includes = smbconf_reg_set_includes,
1196 .delete_includes = smbconf_reg_delete_includes,
1197 .transaction_start = smbconf_reg_transaction_start,
1198 .transaction_commit = smbconf_reg_transaction_commit,
1199 .transaction_cancel = smbconf_reg_transaction_cancel,
1204 * initialize the smbconf registry backend
1205 * the only function that is exported from this module
1207 sbcErr smbconf_init_reg(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx,
1210 return smbconf_init_internal(mem_ctx, conf_ctx, path, &smbconf_ops_reg);