r23801: The FSF has moved around a lot. This fixes their Mass Ave address.
[kai/samba.git] / source3 / lib / util_reg_smbconf.c
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.
10  * 
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.
15  * 
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/>.
18  */
19
20 #include "includes.h"
21
22 extern REGISTRY_OPS smbconf_reg_ops;
23
24 /*
25  * create a fake token just with enough rights to
26  * locally access the registry.
27  */
28 NT_USER_TOKEN *registry_create_admin_token(TALLOC_CTX *mem_ctx)
29 {
30         NT_USER_TOKEN *token = NULL;
31
32         /* fake a user token: builtin administrators sid and the
33          * disk operators privilege is all we need to access the 
34          * registry... */
35         if (!(token = TALLOC_ZERO_P(mem_ctx, NT_USER_TOKEN))) {
36                 DEBUG(1, ("talloc failed\n"));
37                 goto done;
38         }
39         token->privileges = se_disk_operators;
40         if (!add_sid_to_array(token, &global_sid_Builtin_Administrators,
41                          &token->user_sids, &token->num_sids)) {
42                 DEBUG(1, ("Error adding builtin administrators sid "
43                           "to fake token.\n"));
44                 goto done;
45         }
46 done:
47         return token;
48 }
49
50 /*
51  * init the smbconf portion of the registry.
52  * for use in places where not the whole registry is needed,
53  * e.g. utils/net_conf.c and loadparm.c
54  */
55 BOOL registry_init_regdb(void)
56 {
57         BOOL ret = False;
58         int saved_errno = 0;
59         static REGISTRY_HOOK smbconf_reg_hook = {KEY_SMBCONF, &smbconf_reg_ops};
60
61         DEBUG(10, ("registry_init_regdb called\n"));
62
63         if (!regdb_init()) {
64                 saved_errno = errno;
65                 DEBUG(1, ("Can't open the registry"));
66                 if (saved_errno) {
67                         DEBUGADD(1, (": %s", strerror(saved_errno)));
68                 }
69                 DEBUGADD(1, (".\n"));
70                 goto done;
71         }
72         reghook_cache_init();
73         if (!reghook_cache_add(&smbconf_reg_hook)) {
74                 DEBUG(1, ("Error adding smbconf reghooks to reghook cache.\n"));
75                 goto done;
76         }
77
78         ret = True;
79
80 done:
81         return ret;
82 }