r24665: Close file handles properly.
[metze/samba/wip.git] / source4 / lib / registry / samba.c
1 /* 
2    Unix SMB/CIFS implementation.
3    Copyright (C) Jelmer Vernooij                        2004-2007.
4
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 3 of the License, or
8    (at your option) any later version.
9
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include "includes.h"
20 #include "registry.h"
21
22 /**
23  * @file
24  * @brief Samba-specific registry functions
25  */
26
27 WERROR mount_samba_hive(struct registry_context *ctx,
28                                                 struct auth_session_info *auth_info,
29                                                 struct cli_credentials *creds,
30                                                 const char *name, 
31                                                 uint32_t hive_id)
32 {
33         WERROR error;
34         struct hive_key *hive;
35         const char *location;
36
37         location = talloc_asprintf(ctx, "%s/%s.ldb", lp_private_dir(), name);
38
39         error = reg_open_hive(ctx, location, auth_info, creds, &hive);
40         if (!W_ERROR_IS_OK(error))
41                 return error;
42
43         return reg_mount_hive(ctx, hive, hive_id, NULL);
44 }
45
46
47 _PUBLIC_ WERROR reg_open_samba (TALLOC_CTX *mem_ctx, 
48                                 struct registry_context **ctx, 
49                                 struct auth_session_info *session_info, 
50                                 struct cli_credentials *credentials)
51 {
52         WERROR result;
53
54         result = reg_open_local(mem_ctx, ctx, session_info, credentials);
55         if (!W_ERROR_IS_OK(result)) {
56                 return result;
57         }
58
59         mount_samba_hive(*ctx, session_info, credentials, 
60                                          "hklm", HKEY_LOCAL_MACHINE);
61
62         mount_samba_hive(*ctx, session_info, credentials, 
63                                          "hkcr", HKEY_CLASSES_ROOT);
64
65         /* FIXME: Should be mounted from NTUSER.DAT in the home directory of the 
66          * current user */
67         mount_samba_hive(*ctx, session_info, credentials, 
68                                          "hkcu", HKEY_CURRENT_USER);
69
70         mount_samba_hive(*ctx, session_info, credentials, 
71                                          "hku", HKEY_USERS);
72
73         /* FIXME: Different hive backend for HKEY_CLASSES_ROOT: merged view of HKEY_LOCAL_MACHINE\Software\Classes
74          * and HKEY_CURRENT_USER\Software\Classes */
75
76         /* FIXME: HKEY_CURRENT_CONFIG is an alias for HKEY_LOCAL_MACHINE\System\CurrentControlSet\Hardware Profiles\Current */
77
78         /* FIXME: HKEY_PERFORMANCE_DATA is dynamically generated */
79
80         /* FIXME: HKEY_LOCAL_MACHINE\Hardware is autogenerated */
81
82         /* FIXME: HKEY_LOCAL_MACHINE\Security\SAM is an alias for HKEY_LOCAL_MACHINE\SAM */
83         
84         return WERR_OK;
85 }