s3-waf: ndr string functions moved to top level
[Samba/ekacnet.git] / source3 / registry / reg_init_smbconf.c
blob632ac3b53470905ad34bb86f01eb9b72e949e689
1 /*
2 * Unix SMB/CIFS implementation.
3 * Registry helper routines
4 * Copyright (C) Michael Adam 2007
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 3 of the License, or (at your option)
9 * any later version.
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, see <http://www.gnu.org/licenses/>.
20 #include "includes.h"
21 #include "registry.h"
23 #undef DBGC_CLASS
24 #define DBGC_CLASS DBGC_REGISTRY
26 extern struct registry_ops smbconf_reg_ops;
29 * create a fake token just with enough rights to
30 * locally access the registry:
32 * - builtin administrators sid
33 * - disk operators privilege
35 NTSTATUS registry_create_admin_token(TALLOC_CTX *mem_ctx,
36 NT_USER_TOKEN **ptoken)
38 NTSTATUS status;
39 NT_USER_TOKEN *token = NULL;
41 if (ptoken == NULL) {
42 return NT_STATUS_INVALID_PARAMETER;
45 token = TALLOC_ZERO_P(mem_ctx, NT_USER_TOKEN);
46 if (token == NULL) {
47 DEBUG(1, ("talloc failed\n"));
48 status = NT_STATUS_NO_MEMORY;
49 goto done;
51 token->privileges = se_disk_operators;
52 status = add_sid_to_array(token, &global_sid_Builtin_Administrators,
53 &token->user_sids, &token->num_sids);
54 if (!NT_STATUS_IS_OK(status)) {
55 DEBUG(1, ("Error adding builtin administrators sid "
56 "to fake token.\n"));
57 goto done;
60 *ptoken = token;
62 done:
63 return status;
67 * init the smbconf portion of the registry.
68 * for use in places where not the whole registry is needed,
69 * e.g. utils/net_conf.c and loadparm.c
71 WERROR registry_init_smbconf(const char *keyname)
73 WERROR werr;
75 DEBUG(10, ("registry_init_smbconf called\n"));
77 if (keyname == NULL) {
78 DEBUG(10, ("registry_init_smbconf: defaulting to key '%s'\n",
79 KEY_SMBCONF));
80 keyname = KEY_SMBCONF;
83 werr = registry_init_common();
84 if (!W_ERROR_IS_OK(werr)) {
85 goto done;
88 werr = init_registry_key(keyname);
89 if (!W_ERROR_IS_OK(werr)) {
90 DEBUG(1, ("Failed to initialize registry key '%s': %s\n",
91 keyname, win_errstr(werr)));
92 goto done;
95 werr = reghook_cache_add(keyname, &smbconf_reg_ops);
96 if (!W_ERROR_IS_OK(werr)) {
97 DEBUG(1, ("Failed to add smbconf reghooks to reghook cache: "
98 "%s\n", win_errstr(werr)));
99 goto done;
102 done:
103 regdb_close();
104 return werr;