build: regroup LIBSMB objects to for a smallest linkable uint (LIBSMB_ERR_OBJ)
[Samba/ekacnet.git] / source3 / registry / reg_init_smbconf.c
blobf76cc2f051f24be176e6d7b3e85ca334e3d25a4b
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"
22 #undef DBGC_CLASS
23 #define DBGC_CLASS DBGC_REGISTRY
25 extern REGISTRY_OPS smbconf_reg_ops;
28 * create a fake token just with enough rights to
29 * locally access the registry:
31 * - builtin administrators sid
32 * - disk operators privilege
34 NTSTATUS registry_create_admin_token(TALLOC_CTX *mem_ctx,
35 NT_USER_TOKEN **ptoken)
37 NTSTATUS status;
38 NT_USER_TOKEN *token = NULL;
40 if (ptoken == NULL) {
41 return NT_STATUS_INVALID_PARAMETER;
44 token = TALLOC_ZERO_P(mem_ctx, NT_USER_TOKEN);
45 if (token == NULL) {
46 DEBUG(1, ("talloc failed\n"));
47 status = NT_STATUS_NO_MEMORY;
48 goto done;
50 token->privileges = se_disk_operators;
51 status = add_sid_to_array(token, &global_sid_Builtin_Administrators,
52 &token->user_sids, &token->num_sids);
53 if (!NT_STATUS_IS_OK(status)) {
54 DEBUG(1, ("Error adding builtin administrators sid "
55 "to fake token.\n"));
56 goto done;
59 *ptoken = token;
61 done:
62 return status;
66 * init the smbconf portion of the registry.
67 * for use in places where not the whole registry is needed,
68 * e.g. utils/net_conf.c and loadparm.c
70 bool registry_init_smbconf(void)
72 bool ret = false;
73 int saved_errno = 0;
74 static REGISTRY_HOOK smbconf_reg_hook = {KEY_SMBCONF, &smbconf_reg_ops};
76 DEBUG(10, ("registry_init_smbconf called\n"));
78 if (!regdb_init()) {
79 saved_errno = errno;
80 DEBUG(1, ("Can't open the registry"));
81 if (saved_errno) {
82 DEBUGADD(1, (": %s", strerror(saved_errno)));
84 DEBUGADD(1, (".\n"));
85 goto done;
87 if (!init_registry_key(KEY_SMBCONF)) {
88 DEBUG(1, ("Could not initialize registry key '%s'\n",
89 KEY_SMBCONF));
90 goto done;
92 reghook_cache_init();
93 if (!reghook_cache_add(&smbconf_reg_hook)) {
94 DEBUG(1, ("Error adding smbconf reghooks to reghook cache.\n"));
95 goto done;
98 ret = true;
100 done:
101 regdb_close();
102 return ret;