2 * Unix SMB/CIFS implementation.
4 * Eventlog RPC server keys initialization
6 * Copyright (c) 2005 Marcin Krzysztof Porwit
7 * Copyright (c) 2005 Brian Moran
8 * Copyright (c) 2005 Gerald (Jerry) Carter
9 * Copyright (c) 2011 Andreas Schneider <asn@samba.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, see <http://www.gnu.org/licenses/>.
26 #include "../librpc/gen_ndr/ndr_winreg_c.h"
27 #include "rpc_client/cli_winreg_int.h"
28 #include "rpc_client/cli_winreg.h"
29 #include "rpc_server/eventlog/srv_eventlog_reg.h"
32 #define DBGC_CLASS DBGC_REGISTRY
34 #define TOP_LEVEL_EVENTLOG_KEY "SYSTEM\\CurrentControlSet\\Services\\Eventlog"
36 bool eventlog_init_winreg(struct messaging_context *msg_ctx)
38 struct dcerpc_binding_handle *h = NULL;
39 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
40 struct policy_handle hive_hnd, key_hnd;
41 uint32_t uiMaxSize = 0x00080000;
42 uint32_t uiRetention = 0x93A80;
43 const char **elogs = lp_eventlog_list();
44 const char **subkeys = NULL;
45 uint32_t num_subkeys = 0;
49 WERROR result = WERR_OK;
53 tmp_ctx = talloc_stackframe();
54 if (tmp_ctx == NULL) {
58 DEBUG(3, ("Initialise the eventlog registry keys if needed.\n"));
60 key = talloc_strdup(tmp_ctx, TOP_LEVEL_EVENTLOG_KEY);
62 status = dcerpc_winreg_int_hklm_openkey(tmp_ctx,
63 get_server_info_system(),
72 if (!NT_STATUS_IS_OK(status)) {
73 DEBUG(0, ("eventlog_init_winreg: Could not open %s - %s\n",
74 key, nt_errstr(status)));
77 if (!W_ERROR_IS_OK(result)) {
78 DEBUG(0, ("eventlog_init_winreg: Could not open %s - %s\n",
79 key, win_errstr(result)));
83 status = dcerpc_winreg_enum_keys(tmp_ctx,
89 if (!NT_STATUS_IS_OK(status)) {
90 DEBUG(0, ("eventlog_init_winreg: Could enum keys at %s - %s\n",
91 key, nt_errstr(status)));
94 if (!W_ERROR_IS_OK(result)) {
95 DEBUG(0, ("eventlog_init_winreg: Could enum keys at %s - %s\n",
96 key, win_errstr(result)));
100 if (is_valid_policy_hnd(&key_hnd)) {
101 dcerpc_winreg_CloseKey(h, tmp_ctx, &key_hnd, &result);
104 /* create subkeys if they don't exist */
105 while (elogs && *elogs) {
106 enum winreg_CreateAction action = REG_ACTION_NONE;
107 char *evt_tdb = NULL;
108 struct winreg_String wkey;
109 struct winreg_String wkeyclass;
112 for (i = 0; i < num_subkeys; i++) {
113 if (strequal(subkeys[i], *elogs)) {
123 ZERO_STRUCT(key_hnd);
126 wkey.name = talloc_asprintf(tmp_ctx, "%s\\%s", key, *elogs);
127 if (wkey.name == NULL) {
132 ZERO_STRUCT(wkeyclass);
136 status = dcerpc_winreg_CreateKey(h,
147 if (!NT_STATUS_IS_OK(status)) {
148 DEBUG(0, ("eventlog_init_winreg_keys: Could not create key %s: %s\n",
149 wkey.name, nt_errstr(status)));
152 if (!W_ERROR_IS_OK(result)) {
153 DEBUG(0, ("eventlog_init_winreg_keys: Could not create key %s: %s\n",
154 wkey.name, win_errstr(result)));
158 status = dcerpc_winreg_set_dword(tmp_ctx,
165 status = dcerpc_winreg_set_dword(tmp_ctx,
172 status = dcerpc_winreg_set_sz(tmp_ctx,
179 evt_tdb = talloc_asprintf(tmp_ctx,
180 "%%SystemRoot%%\\system32\\config\\%s.tdb",
182 if (evt_tdb == NULL) {
185 status = dcerpc_winreg_set_expand_sz(tmp_ctx,
191 TALLOC_FREE(evt_tdb);
193 status = dcerpc_winreg_add_multi_sz(tmp_ctx,
200 if (is_valid_policy_hnd(&key_hnd)) {
201 dcerpc_winreg_CloseKey(h, tmp_ctx, &key_hnd, &result);
206 uint32_t uiCategoryCount = 0x00000007;
208 wkey.name = talloc_asprintf(tmp_ctx,
211 if (wkey.name == NULL) {
216 status = dcerpc_winreg_CreateKey(h,
227 if (!NT_STATUS_IS_OK(status)) {
228 DEBUG(0, ("eventlog_init_winreg_keys: Could not create key %s: %s\n",
229 wkey.name, nt_errstr(status)));
232 if (!W_ERROR_IS_OK(result)) {
233 DEBUG(0, ("eventlog_init_winreg_keys: Could not create key %s: %s\n",
234 wkey.name, win_errstr(result)));
238 status = dcerpc_winreg_set_dword(tmp_ctx,
245 status = dcerpc_winreg_set_expand_sz(tmp_ctx,
248 "CategoryMessageFile",
249 "%SystemRoot%\\system32\\eventlog.dll",
252 if (is_valid_policy_hnd(&key_hnd)) {
253 dcerpc_winreg_CloseKey(h, tmp_ctx, &key_hnd, &result);
262 TALLOC_FREE(tmp_ctx);
266 /* vim: set ts=8 sw=8 noet cindent syntax=c.doxygen: */