libsmbconf: implement get_includes() and set_includes() for registry backend.
[Samba.git] / source / lib / smbconf / smbconf_reg.c
blobe604a608e16b19d47372688ac8033d93c6410847
1 /*
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/>.
20 #include "includes.h"
21 #include "smbconf_private.h"
23 #define INCLUDES_VALNAME "includes"
25 struct reg_private_data {
26 NT_USER_TOKEN *token;
27 bool open; /* did _we_ open the registry? */
30 /**********************************************************************
32 * helper functions
34 **********************************************************************/
36 /**
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);
44 /**
45 * Open a registry key specified by "path"
47 static WERROR smbconf_reg_open_path(TALLOC_CTX *mem_ctx,
48 struct smbconf_ctx *ctx,
49 const char *path,
50 uint32 desired_access,
51 struct registry_key **key)
53 WERROR werr = WERR_OK;
55 if (ctx == NULL) {
56 DEBUG(1, ("Error: configuration is not open!\n"));
57 werr = WERR_INVALID_PARAM;
58 goto done;
61 if (rpd(ctx)->token == NULL) {
62 DEBUG(1, ("Error: token missing from smbconf_ctx. "
63 "was smbconf_init() called?\n"));
64 werr = WERR_INVALID_PARAM;
65 goto done;
68 werr = ctx->ops->open_conf(ctx);
69 if (!W_ERROR_IS_OK(werr)) {
70 DEBUG(1, ("Error opening the registry.\n"));
71 goto done;
74 if (path == NULL) {
75 DEBUG(1, ("Error: NULL path string given\n"));
76 werr = WERR_INVALID_PARAM;
77 goto done;
80 werr = reg_open_path(mem_ctx, path, desired_access, rpd(ctx)->token,
81 key);
83 if (!W_ERROR_IS_OK(werr)) {
84 DEBUG(1, ("Error opening registry path '%s': %s\n",
85 path, dos_errstr(werr)));
88 done:
89 return werr;
92 /**
93 * Open a subkey of the base key (i.e a service)
95 static WERROR smbconf_reg_open_service_key(TALLOC_CTX *mem_ctx,
96 struct smbconf_ctx *ctx,
97 const char *servicename,
98 uint32 desired_access,
99 struct registry_key **key)
101 WERROR werr = WERR_OK;
102 char *path = NULL;
104 if (servicename == NULL) {
105 DEBUG(3, ("Error: NULL servicename given.\n"));
106 werr = WERR_INVALID_PARAM;
107 goto done;
110 path = talloc_asprintf(mem_ctx, "%s\\%s", ctx->path, servicename);
111 if (path == NULL) {
112 werr = WERR_NOMEM;
113 goto done;
116 werr = smbconf_reg_open_path(mem_ctx, ctx, path, desired_access, key);
118 done:
119 TALLOC_FREE(path);
120 return werr;
124 * open the base key
126 static WERROR smbconf_reg_open_base_key(TALLOC_CTX *mem_ctx,
127 struct smbconf_ctx *ctx,
128 uint32 desired_access,
129 struct registry_key **key)
131 return smbconf_reg_open_path(mem_ctx, ctx, ctx->path, desired_access,
132 key);
136 * check if a value exists in a given registry key
138 static bool smbconf_value_exists(struct registry_key *key, const char *param)
140 bool ret = false;
141 WERROR werr = WERR_OK;
142 TALLOC_CTX *ctx = talloc_stackframe();
143 struct registry_value *value = NULL;
145 werr = reg_queryvalue(ctx, key, param, &value);
146 if (W_ERROR_IS_OK(werr)) {
147 ret = true;
150 TALLOC_FREE(ctx);
151 return ret;
155 * create a subkey of the base key (i.e. a service...)
157 static WERROR smbconf_reg_create_service_key(TALLOC_CTX *mem_ctx,
158 struct smbconf_ctx *ctx,
159 const char * subkeyname,
160 struct registry_key **newkey)
162 WERROR werr = WERR_OK;
163 struct registry_key *create_parent = NULL;
164 TALLOC_CTX *create_ctx;
165 enum winreg_CreateAction action = REG_ACTION_NONE;
167 /* create a new talloc ctx for creation. it will hold
168 * the intermediate parent key (SMBCONF) for creation
169 * and will be destroyed when leaving this function... */
170 if (!(create_ctx = talloc_stackframe())) {
171 werr = WERR_NOMEM;
172 goto done;
175 werr = smbconf_reg_open_base_key(create_ctx, ctx, REG_KEY_WRITE,
176 &create_parent);
177 if (!W_ERROR_IS_OK(werr)) {
178 goto done;
181 werr = reg_createkey(mem_ctx, create_parent, subkeyname,
182 REG_KEY_WRITE, newkey, &action);
183 if (W_ERROR_IS_OK(werr) && (action != REG_CREATED_NEW_KEY)) {
184 DEBUG(10, ("Key '%s' already exists.\n", subkeyname));
185 werr = WERR_ALREADY_EXISTS;
187 if (!W_ERROR_IS_OK(werr)) {
188 DEBUG(5, ("Error creating key %s: %s\n",
189 subkeyname, dos_errstr(werr)));
192 done:
193 TALLOC_FREE(create_ctx);
194 return werr;
198 * add a value to a key.
200 static WERROR smbconf_reg_set_value(struct registry_key *key,
201 const char *valname,
202 const char *valstr)
204 struct registry_value val;
205 WERROR werr = WERR_OK;
206 char *subkeyname;
207 const char *canon_valname;
208 const char *canon_valstr;
210 if (!lp_canonicalize_parameter_with_value(valname, valstr,
211 &canon_valname,
212 &canon_valstr))
214 if (canon_valname == NULL) {
215 DEBUG(5, ("invalid parameter '%s' given\n",
216 valname));
217 } else {
218 DEBUG(5, ("invalid value '%s' given for "
219 "parameter '%s'\n", valstr, valname));
221 werr = WERR_INVALID_PARAM;
222 goto done;
225 if (registry_smbconf_valname_forbidden(canon_valname)) {
226 DEBUG(5, ("Parameter '%s' not allowed in registry.\n",
227 canon_valname));
228 werr = WERR_INVALID_PARAM;
229 goto done;
232 subkeyname = strrchr_m(key->key->name, '\\');
233 if ((subkeyname == NULL) || (*(subkeyname +1) == '\0')) {
234 DEBUG(5, ("Invalid registry key '%s' given as "
235 "smbconf section.\n", key->key->name));
236 werr = WERR_INVALID_PARAM;
237 goto done;
239 subkeyname++;
240 if (!strequal(subkeyname, GLOBAL_NAME) &&
241 lp_parameter_is_global(valname))
243 DEBUG(5, ("Global paramter '%s' not allowed in "
244 "service definition ('%s').\n", canon_valname,
245 subkeyname));
246 werr = WERR_INVALID_PARAM;
247 goto done;
250 ZERO_STRUCT(val);
252 val.type = REG_SZ;
253 val.v.sz.str = CONST_DISCARD(char *, canon_valstr);
254 val.v.sz.len = strlen(canon_valstr) + 1;
256 werr = reg_setvalue(key, canon_valname, &val);
257 if (!W_ERROR_IS_OK(werr)) {
258 DEBUG(5, ("Error adding value '%s' to "
259 "key '%s': %s\n",
260 canon_valname, key->key->name, dos_errstr(werr)));
263 done:
264 return werr;
267 static WERROR smbconf_reg_set_multi_sz_value(struct registry_key *key,
268 const char *valname,
269 const uint32_t num_strings,
270 const char **strings)
272 WERROR werr;
273 struct registry_value *value;
274 uint32_t count;
275 TALLOC_CTX *tmp_ctx = talloc_stackframe();
277 if (strings == NULL) {
278 werr = WERR_INVALID_PARAM;
279 goto done;
282 value = TALLOC_ZERO_P(tmp_ctx, struct registry_value);
284 value->type = REG_MULTI_SZ;
285 value->v.multi_sz.num_strings = num_strings;
286 value->v.multi_sz.strings = TALLOC_ARRAY(tmp_ctx, char *, num_strings);
287 if (value->v.multi_sz.strings == NULL) {
288 werr = WERR_NOMEM;
289 goto done;
291 for (count = 0; count < num_strings; count++) {
292 value->v.multi_sz.strings[count] =
293 talloc_strdup(value->v.multi_sz.strings,
294 strings[count]);
295 if (value->v.multi_sz.strings[count] == NULL) {
296 werr = WERR_NOMEM;
297 goto done;
301 werr = reg_setvalue(key, valname, value);
302 if (!W_ERROR_IS_OK(werr)) {
303 DEBUG(5, ("Error adding value '%s' to key '%s': %s\n",
304 valname, key->key->name, dos_errstr(werr)));
307 done:
308 TALLOC_FREE(tmp_ctx);
309 return werr;
313 * format a registry_value into a string.
315 * This is intended to be used for smbconf registry values,
316 * which are ar stored as REG_SZ values, so the incomplete
317 * handling should be ok.
319 static char *smbconf_format_registry_value(TALLOC_CTX *mem_ctx,
320 struct registry_value *value)
322 char *result = NULL;
324 /* alternatively, create a new talloc context? */
325 if (mem_ctx == NULL) {
326 return result;
329 switch (value->type) {
330 case REG_DWORD:
331 result = talloc_asprintf(mem_ctx, "%d", value->v.dword);
332 break;
333 case REG_SZ:
334 case REG_EXPAND_SZ:
335 result = talloc_asprintf(mem_ctx, "%s", value->v.sz.str);
336 break;
337 case REG_MULTI_SZ: {
338 uint32 j;
339 for (j = 0; j < value->v.multi_sz.num_strings; j++) {
340 result = talloc_asprintf(mem_ctx, "%s \"%s\" ",
341 result,
342 value->v.multi_sz.strings[j]);
343 if (result == NULL) {
344 break;
347 break;
349 case REG_BINARY:
350 result = talloc_asprintf(mem_ctx, "binary (%d bytes)",
351 (int)value->v.binary.length);
352 break;
353 default:
354 result = talloc_asprintf(mem_ctx, "<unprintable>");
355 break;
357 return result;
361 * Get the values of a key as a list of value names
362 * and a list of value strings (ordered)
364 static WERROR smbconf_reg_get_values(TALLOC_CTX *mem_ctx,
365 struct registry_key *key,
366 uint32_t *num_values,
367 char ***value_names,
368 char ***value_strings)
370 TALLOC_CTX *tmp_ctx = NULL;
371 WERROR werr = WERR_OK;
372 uint32_t count;
373 struct registry_value *valvalue = NULL;
374 char *valname = NULL;
375 char **tmp_valnames = NULL;
376 char **tmp_valstrings = NULL;
378 if ((num_values == NULL) || (value_names == NULL) ||
379 (value_strings == NULL))
381 werr = WERR_INVALID_PARAM;
382 goto done;
385 tmp_ctx = talloc_stackframe();
386 if (tmp_ctx == NULL) {
387 werr = WERR_NOMEM;
388 goto done;
391 for (count = 0;
392 werr = reg_enumvalue(tmp_ctx, key, count, &valname, &valvalue),
393 W_ERROR_IS_OK(werr);
394 count++)
396 char *valstring;
398 werr = smbconf_add_string_to_array(tmp_ctx,
399 &tmp_valnames,
400 count, valname);
401 if (!W_ERROR_IS_OK(werr)) {
402 goto done;
405 valstring = smbconf_format_registry_value(tmp_ctx, valvalue);
406 werr = smbconf_add_string_to_array(tmp_ctx, &tmp_valstrings,
407 count, valstring);
408 if (!W_ERROR_IS_OK(werr)) {
409 goto done;
412 if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) {
413 goto done;
416 werr = WERR_OK;
418 *num_values = count;
419 if (count > 0) {
420 *value_names = talloc_move(mem_ctx, &tmp_valnames);
421 *value_strings = talloc_move(mem_ctx, &tmp_valstrings);
422 } else {
423 *value_names = NULL;
424 *value_strings = NULL;
427 done:
428 TALLOC_FREE(tmp_ctx);
429 return werr;
432 /**********************************************************************
434 * smbconf operations: registry implementations
436 **********************************************************************/
439 * initialize the registry smbconf backend
441 static WERROR smbconf_reg_init(struct smbconf_ctx *ctx, const char *path)
443 WERROR werr = WERR_OK;
445 if (path == NULL) {
446 path = KEY_SMBCONF;
448 ctx->path = talloc_strdup(ctx, path);
449 if (ctx->path == NULL) {
450 werr = WERR_NOMEM;
451 goto done;
454 ctx->data = TALLOC_ZERO_P(ctx, struct reg_private_data);
456 werr = ntstatus_to_werror(registry_create_admin_token(ctx,
457 &(rpd(ctx)->token)));
458 if (!W_ERROR_IS_OK(werr)) {
459 DEBUG(1, ("Error creating admin token\n"));
460 goto done;
462 rpd(ctx)->open = false;
464 if (!registry_init_smbconf()) {
465 werr = WERR_REG_IO_FAILURE;
466 goto done;
469 done:
470 return werr;
473 static int smbconf_reg_shutdown(struct smbconf_ctx *ctx)
475 return ctx->ops->close_conf(ctx);
478 static WERROR smbconf_reg_open(struct smbconf_ctx *ctx)
480 WERROR werr;
482 if (rpd(ctx)->open) {
483 return WERR_OK;
486 werr = regdb_open();
487 if (W_ERROR_IS_OK(werr)) {
488 rpd(ctx)->open = true;
490 return werr;
493 static int smbconf_reg_close(struct smbconf_ctx *ctx)
495 int ret;
497 if (!rpd(ctx)->open) {
498 return 0;
501 ret = regdb_close();
502 if (ret == 0) {
503 rpd(ctx)->open = false;
505 return ret;
509 * Get the change sequence number of the given service/parameter.
510 * service and parameter strings may be NULL.
512 static void smbconf_reg_get_csn(struct smbconf_ctx *ctx,
513 struct smbconf_csn *csn,
514 const char *service, const char *param)
516 if (csn == NULL) {
517 return;
520 if (!W_ERROR_IS_OK(ctx->ops->open_conf(ctx))) {
521 return;
524 csn->csn = (uint64_t)regdb_get_seqnum();
528 * Drop the whole configuration (restarting empty) - registry version
530 static WERROR smbconf_reg_drop(struct smbconf_ctx *ctx)
532 char *path, *p;
533 WERROR werr = WERR_OK;
534 struct registry_key *parent_key = NULL;
535 struct registry_key *new_key = NULL;
536 TALLOC_CTX* mem_ctx = talloc_stackframe();
537 enum winreg_CreateAction action;
539 path = talloc_strdup(mem_ctx, ctx->path);
540 if (path == NULL) {
541 werr = WERR_NOMEM;
542 goto done;
544 p = strrchr(path, '\\');
545 *p = '\0';
546 werr = smbconf_reg_open_path(mem_ctx, ctx, path, REG_KEY_WRITE,
547 &parent_key);
549 if (!W_ERROR_IS_OK(werr)) {
550 goto done;
553 werr = reg_deletekey_recursive(mem_ctx, parent_key, p+1);
555 if (!W_ERROR_IS_OK(werr)) {
556 goto done;
559 werr = reg_createkey(mem_ctx, parent_key, p+1, REG_KEY_WRITE,
560 &new_key, &action);
562 done:
563 TALLOC_FREE(mem_ctx);
564 return werr;
568 * get the list of share names defined in the configuration.
569 * registry version.
571 static WERROR smbconf_reg_get_share_names(struct smbconf_ctx *ctx,
572 TALLOC_CTX *mem_ctx,
573 uint32_t *num_shares,
574 char ***share_names)
576 uint32_t count;
577 uint32_t added_count = 0;
578 TALLOC_CTX *tmp_ctx = NULL;
579 WERROR werr = WERR_OK;
580 struct registry_key *key = NULL;
581 char *subkey_name = NULL;
582 char **tmp_share_names = NULL;
584 if ((num_shares == NULL) || (share_names == NULL)) {
585 werr = WERR_INVALID_PARAM;
586 goto done;
589 tmp_ctx = talloc_stackframe();
590 if (tmp_ctx == NULL) {
591 werr = WERR_NOMEM;
592 goto done;
595 /* make sure "global" is always listed first */
596 if (smbconf_share_exists(ctx, GLOBAL_NAME)) {
597 werr = smbconf_add_string_to_array(tmp_ctx, &tmp_share_names,
598 0, GLOBAL_NAME);
599 if (!W_ERROR_IS_OK(werr)) {
600 goto done;
602 added_count++;
605 werr = smbconf_reg_open_base_key(tmp_ctx, ctx,
606 SEC_RIGHTS_ENUM_SUBKEYS, &key);
607 if (!W_ERROR_IS_OK(werr)) {
608 goto done;
611 for (count = 0;
612 werr = reg_enumkey(tmp_ctx, key, count, &subkey_name, NULL),
613 W_ERROR_IS_OK(werr);
614 count++)
616 if (strequal(subkey_name, GLOBAL_NAME)) {
617 continue;
620 werr = smbconf_add_string_to_array(tmp_ctx,
621 &tmp_share_names,
622 added_count,
623 subkey_name);
624 if (!W_ERROR_IS_OK(werr)) {
625 goto done;
627 added_count++;
629 if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) {
630 goto done;
632 werr = WERR_OK;
634 *num_shares = added_count;
635 if (added_count > 0) {
636 *share_names = talloc_move(mem_ctx, &tmp_share_names);
637 } else {
638 *share_names = NULL;
641 done:
642 TALLOC_FREE(tmp_ctx);
643 return werr;
647 * check if a share/service of a given name exists - registry version
649 static bool smbconf_reg_share_exists(struct smbconf_ctx *ctx,
650 const char *servicename)
652 bool ret = false;
653 WERROR werr = WERR_OK;
654 TALLOC_CTX *mem_ctx = talloc_stackframe();
655 struct registry_key *key = NULL;
657 werr = smbconf_reg_open_service_key(mem_ctx, ctx, servicename,
658 REG_KEY_READ, &key);
659 if (W_ERROR_IS_OK(werr)) {
660 ret = true;
663 TALLOC_FREE(mem_ctx);
664 return ret;
668 * Add a service if it does not already exist - registry version
670 static WERROR smbconf_reg_create_share(struct smbconf_ctx *ctx,
671 const char *servicename)
673 WERROR werr;
674 TALLOC_CTX *mem_ctx = talloc_stackframe();
675 struct registry_key *key = NULL;
677 werr = smbconf_reg_create_service_key(mem_ctx, ctx, servicename, &key);
679 TALLOC_FREE(mem_ctx);
680 return werr;
684 * get a definition of a share (service) from configuration.
686 static WERROR smbconf_reg_get_share(struct smbconf_ctx *ctx,
687 TALLOC_CTX *mem_ctx,
688 const char *servicename,
689 uint32_t *num_params,
690 char ***param_names, char ***param_values)
692 WERROR werr = WERR_OK;
693 struct registry_key *key = NULL;
695 werr = smbconf_reg_open_service_key(mem_ctx, ctx, servicename,
696 REG_KEY_READ, &key);
697 if (!W_ERROR_IS_OK(werr)) {
698 goto done;
701 werr = smbconf_reg_get_values(mem_ctx, key, num_params,
702 param_names, param_values);
704 done:
705 TALLOC_FREE(key);
706 return werr;
710 * delete a service from configuration
712 static WERROR smbconf_reg_delete_share(struct smbconf_ctx *ctx,
713 const char *servicename)
715 WERROR werr = WERR_OK;
716 struct registry_key *key = NULL;
717 TALLOC_CTX *mem_ctx = talloc_stackframe();
719 werr = smbconf_reg_open_base_key(mem_ctx, ctx, REG_KEY_WRITE, &key);
720 if (!W_ERROR_IS_OK(werr)) {
721 goto done;
724 werr = reg_deletekey_recursive(key, key, servicename);
726 done:
727 TALLOC_FREE(mem_ctx);
728 return werr;
732 * set a configuration parameter to the value provided.
734 static WERROR smbconf_reg_set_parameter(struct smbconf_ctx *ctx,
735 const char *service,
736 const char *param,
737 const char *valstr)
739 WERROR werr;
740 struct registry_key *key = NULL;
741 TALLOC_CTX *mem_ctx = talloc_stackframe();
743 werr = smbconf_reg_open_service_key(mem_ctx, ctx, service,
744 REG_KEY_WRITE, &key);
745 if (!W_ERROR_IS_OK(werr)) {
746 goto done;
749 werr = smbconf_reg_set_value(key, param, valstr);
751 done:
752 TALLOC_FREE(mem_ctx);
753 return werr;
757 * get the value of a configuration parameter as a string
759 static WERROR smbconf_reg_get_parameter(struct smbconf_ctx *ctx,
760 TALLOC_CTX *mem_ctx,
761 const char *service,
762 const char *param,
763 char **valstr)
765 WERROR werr = WERR_OK;
766 struct registry_key *key = NULL;
767 struct registry_value *value = NULL;
769 werr = smbconf_reg_open_service_key(mem_ctx, ctx, service,
770 REG_KEY_READ, &key);
771 if (!W_ERROR_IS_OK(werr)) {
772 goto done;
775 if (!smbconf_value_exists(key, param)) {
776 werr = WERR_INVALID_PARAM;
777 goto done;
780 werr = reg_queryvalue(mem_ctx, key, param, &value);
781 if (!W_ERROR_IS_OK(werr)) {
782 goto done;
785 *valstr = smbconf_format_registry_value(mem_ctx, value);
787 if (*valstr == NULL) {
788 werr = WERR_NOMEM;
791 done:
792 TALLOC_FREE(key);
793 TALLOC_FREE(value);
794 return werr;
798 * delete a parameter from configuration
800 static WERROR smbconf_reg_delete_parameter(struct smbconf_ctx *ctx,
801 const char *service,
802 const char *param)
804 struct registry_key *key = NULL;
805 WERROR werr = WERR_OK;
806 TALLOC_CTX *mem_ctx = talloc_stackframe();
808 werr = smbconf_reg_open_service_key(mem_ctx, ctx, service,
809 REG_KEY_ALL, &key);
810 if (!W_ERROR_IS_OK(werr)) {
811 goto done;
814 if (!smbconf_value_exists(key, param)) {
815 werr = WERR_INVALID_PARAM;
816 goto done;
819 werr = reg_deletevalue(key, param);
821 done:
822 TALLOC_FREE(mem_ctx);
823 return werr;
826 static WERROR smbconf_reg_get_includes(struct smbconf_ctx *ctx,
827 TALLOC_CTX *mem_ctx,
828 const char *service,
829 uint32_t *num_includes,
830 char ***includes)
832 WERROR werr;
833 uint32_t count;
834 struct registry_key *key = NULL;
835 struct registry_value *value = NULL;
836 char **tmp_includes = NULL;
837 TALLOC_CTX *tmp_ctx = talloc_stackframe();
839 werr = smbconf_reg_open_service_key(tmp_ctx, ctx, service,
840 REG_KEY_READ, &key);
841 if (!W_ERROR_IS_OK(werr)) {
842 goto done;
845 if (!smbconf_value_exists(key, INCLUDES_VALNAME)) {
846 /* no includes */
847 goto done;
850 werr = reg_queryvalue(tmp_ctx, key, INCLUDES_VALNAME, &value);
851 if (!W_ERROR_IS_OK(werr)) {
852 goto done;
855 if (value->type != REG_MULTI_SZ) {
856 /* wront type -- ignore */
857 goto done;
860 for (count = 0; count < value->v.multi_sz.num_strings; count++)
862 werr = smbconf_add_string_to_array(tmp_ctx,
863 &tmp_includes,
864 count,
865 value->v.multi_sz.strings[count]);
866 if (!W_ERROR_IS_OK(werr)) {
867 goto done;
871 if (count > 0) {
872 *includes = talloc_move(mem_ctx, &tmp_includes);
873 if (*includes == NULL) {
874 werr = WERR_NOMEM;
875 goto done;
877 *num_includes = count;
878 } else {
879 *num_includes = 0;
880 *includes = NULL;
883 done:
884 TALLOC_FREE(tmp_ctx);
885 return werr;
888 static WERROR smbconf_reg_set_includes(struct smbconf_ctx *ctx,
889 const char *service,
890 uint32_t num_includes,
891 const char **includes)
893 WERROR werr = WERR_OK;
894 struct registry_key *key = NULL;
895 TALLOC_CTX *tmp_ctx = talloc_stackframe();
897 werr = smbconf_reg_open_service_key(tmp_ctx, ctx, service,
898 REG_KEY_ALL, &key);
899 if (!W_ERROR_IS_OK(werr)) {
900 goto done;
903 werr = smbconf_reg_set_multi_sz_value(key, INCLUDES_VALNAME,
904 num_includes, includes);
906 done:
907 TALLOC_FREE(tmp_ctx);
908 return werr;
912 struct smbconf_ops smbconf_ops_reg = {
913 .init = smbconf_reg_init,
914 .shutdown = smbconf_reg_shutdown,
915 .open_conf = smbconf_reg_open,
916 .close_conf = smbconf_reg_close,
917 .get_csn = smbconf_reg_get_csn,
918 .drop = smbconf_reg_drop,
919 .get_share_names = smbconf_reg_get_share_names,
920 .share_exists = smbconf_reg_share_exists,
921 .create_share = smbconf_reg_create_share,
922 .get_share = smbconf_reg_get_share,
923 .delete_share = smbconf_reg_delete_share,
924 .set_parameter = smbconf_reg_set_parameter,
925 .get_parameter = smbconf_reg_get_parameter,
926 .delete_parameter = smbconf_reg_delete_parameter,
927 .get_includes = smbconf_reg_get_includes,
928 .set_includes = smbconf_reg_set_includes,
933 * initialize the smbconf registry backend
934 * the only function that is exported from this module
936 WERROR smbconf_init_reg(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx,
937 const char *path)
939 return smbconf_init(mem_ctx, conf_ctx, path, &smbconf_ops_reg);