3
* Unix SMB/CIFS implementation.
4
* Virtual Windows Registry Layer
5
* Copyright (C) Marcin Krzysztof Porwit 2005,
6
* Copyright (C) Brian Moran 2005.
7
* Copyright (C) Gerald (Jerry) Carter 2005.
9
* This program is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation; either version 3 of the License, or
12
* (at your option) any later version.
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
19
* You should have received a copy of the GNU General Public License
20
* along with this program; if not, see <http://www.gnu.org/licenses/>.
26
#define DBGC_CLASS DBGC_REGISTRY
28
/**********************************************************************
29
for an eventlog, add in the default values
30
*********************************************************************/
32
bool eventlog_init_keys(void)
34
/* Find all of the eventlogs, add keys for each of them */
35
const char **elogs = lp_eventlog_list();
36
char *evtlogpath = NULL;
37
char *evtfilepath = NULL;
38
struct regsubkey_ctr *subkeys;
39
struct regval_ctr *values;
42
uint32 uiCategoryCount;
44
TALLOC_CTX *ctx = talloc_tos();
47
while (elogs && *elogs) {
48
werr = regsubkey_ctr_init(ctx, &subkeys);
49
if (!W_ERROR_IS_OK(werr)) {
50
DEBUG( 0, ( "talloc() failure!\n" ) );
53
regdb_fetch_keys(KEY_EVENTLOG, subkeys);
54
regsubkey_ctr_addkey( subkeys, *elogs );
55
if ( !regdb_store_keys( KEY_EVENTLOG, subkeys ) ) {
61
/* add in the key of form KEY_EVENTLOG/Application */
63
( "Adding key of [%s] to path of [%s]\n", *elogs,
66
evtlogpath = talloc_asprintf(ctx, "%s\\%s",
67
KEY_EVENTLOG, *elogs);
71
/* add in the key of form KEY_EVENTLOG/Application/Application */
73
( "Adding key of [%s] to path of [%s]\n", *elogs,
75
werr = regsubkey_ctr_init(ctx, &subkeys);
76
if (!W_ERROR_IS_OK(werr)) {
77
DEBUG( 0, ( "talloc() failure!\n" ) );
80
regdb_fetch_keys( evtlogpath, subkeys );
81
regsubkey_ctr_addkey( subkeys, *elogs );
83
if ( !regdb_store_keys( evtlogpath, subkeys ) ) {
87
TALLOC_FREE( subkeys );
89
/* now add the values to the KEY_EVENTLOG/Application form key */
90
if (!(values = TALLOC_ZERO_P(ctx, struct regval_ctr))) {
91
DEBUG( 0, ( "talloc() failure!\n" ) );
95
( "Storing values to eventlog path of [%s]\n",
97
regdb_fetch_values( evtlogpath, values );
100
if (!regval_ctr_key_exists(values, "MaxSize")) {
102
/* assume we have none, add them all */
104
/* hard code some initial values */
106
/* uiDisplayNameId = 0x00000100; */
107
uiMaxSize = 0x00080000;
108
uiRetention = 0x93A80;
110
regval_ctr_addvalue(values, "MaxSize", REG_DWORD,
114
regval_ctr_addvalue(values, "Retention", REG_DWORD,
115
(char *)&uiRetention,
118
regval_ctr_addvalue_sz(values, "PrimaryModule", *elogs);
119
push_reg_sz(talloc_tos(), &data, *elogs);
121
regval_ctr_addvalue(values, "Sources", REG_MULTI_SZ,
125
evtfilepath = talloc_asprintf(ctx,
126
"%%SystemRoot%%\\system32\\config\\%s.tdb",
131
push_reg_sz(talloc_tos(), &data, evtfilepath);
132
regval_ctr_addvalue(values, "File", REG_EXPAND_SZ, (char *)data.data,
134
regdb_store_values(evtlogpath, values);
140
/* now do the values under KEY_EVENTLOG/Application/Application */
141
TALLOC_FREE(evtlogpath);
142
evtlogpath = talloc_asprintf(ctx, "%s\\%s\\%s",
143
KEY_EVENTLOG, *elogs, *elogs);
147
if (!(values = TALLOC_ZERO_P(ctx, struct regval_ctr))) {
148
DEBUG( 0, ( "talloc() failure!\n" ) );
152
( "Storing values to eventlog path of [%s]\n",
154
regdb_fetch_values(evtlogpath, values);
155
if (!regval_ctr_key_exists( values, "CategoryCount")) {
157
/* hard code some initial values */
159
uiCategoryCount = 0x00000007;
160
regval_ctr_addvalue( values, "CategoryCount",
162
( char * ) &uiCategoryCount,
164
push_reg_sz(talloc_tos(), &data,
165
"%SystemRoot%\\system32\\eventlog.dll");
167
regval_ctr_addvalue( values, "CategoryMessageFile",
169
( char * ) data.data,
171
regdb_store_values( evtlogpath, values );
180
/*********************************************************************
181
for an eventlog, add in a source name. If the eventlog doesn't
182
exist (not in the list) do nothing. If a source for the log
183
already exists, change the information (remove, replace)
184
*********************************************************************/
186
bool eventlog_add_source( const char *eventlog, const char *sourcename,
187
const char *messagefile )
189
/* Find all of the eventlogs, add keys for each of them */
190
/* need to add to the value KEY_EVENTLOG/<eventlog>/Sources string (Creating if necessary)
191
need to add KEY of source to KEY_EVENTLOG/<eventlog>/<source> */
193
const char **elogs = lp_eventlog_list( );
194
const char **wrklist, **wp;
195
char *evtlogpath = NULL;
196
struct regsubkey_ctr *subkeys;
197
struct regval_ctr *values;
198
struct regval_blob *rval;
203
TALLOC_CTX *ctx = talloc_tos();
211
for ( i = 0; elogs[i]; i++ ) {
212
if ( strequal( elogs[i], eventlog ) )
218
( "Eventlog [%s] not found in list of valid event logs\n",
220
return false; /* invalid named passed in */
223
/* have to assume that the evenlog key itself exists at this point */
224
/* add in a key of [sourcename] under the eventlog key */
226
/* todo add to Sources */
228
if (!( values = TALLOC_ZERO_P(ctx, struct regval_ctr))) {
229
DEBUG( 0, ( "talloc() failure!\n" ));
233
evtlogpath = talloc_asprintf(ctx, "%s\\%s", KEY_EVENTLOG, eventlog);
239
regdb_fetch_values( evtlogpath, values );
242
if ( !( rval = regval_ctr_getvalue( values, "Sources" ) ) ) {
243
DEBUG( 0, ( "No Sources value for [%s]!\n", eventlog ) );
246
/* perhaps this adding a new string to a multi_sz should be a fn? */
247
/* check to see if it's there already */
249
if ( rval->type != REG_MULTI_SZ ) {
251
( "Wrong type for Sources, should be REG_MULTI_SZ\n" ) );
254
/* convert to a 'regulah' chars to do some comparisons */
258
dump_data( 1, rval->data_p, rval->size );
260
blob = data_blob_const(rval->data_p, rval->size);
261
if (!pull_reg_multi_sz(talloc_tos(), &blob, &wrklist)) {
265
for (ii=0; wrklist[ii]; ii++) {
269
if (numsources > 0) {
270
/* see if it's in there already */
274
if ( strequal( *wp, sourcename ) ) {
276
( "Source name [%s] already in list for [%s] \n",
277
sourcename, eventlog ) );
285
( "Nothing in the sources list, this might be a problem\n" ) );
291
/* make a new list with an additional entry; copy values, add another */
292
wp = TALLOC_ARRAY(ctx, const char *, numsources + 2 );
295
DEBUG( 0, ( "talloc() failed \n" ) );
298
memcpy( wp, wrklist, sizeof( char * ) * numsources );
299
*( wp + numsources ) = ( char * ) sourcename;
300
*( wp + numsources + 1 ) = NULL;
301
if (!push_reg_multi_sz(ctx, &blob, wp)) {
304
dump_data( 1, blob.data, blob.length);
305
regval_ctr_addvalue( values, "Sources", REG_MULTI_SZ,
306
( char * ) blob.data, blob.length);
307
regdb_store_values( evtlogpath, values );
308
data_blob_free(&blob);
311
( "Source name [%s] found in existing list of sources\n",
315
TALLOC_FREE(wrklist); /* */
317
werr = regsubkey_ctr_init(ctx, &subkeys);
318
if (!W_ERROR_IS_OK(werr)) {
319
DEBUG( 0, ( "talloc() failure!\n" ) );
322
TALLOC_FREE(evtlogpath);
323
evtlogpath = talloc_asprintf(ctx, "%s\\%s", KEY_EVENTLOG, eventlog );
325
TALLOC_FREE(subkeys);
329
regdb_fetch_keys( evtlogpath, subkeys );
331
if ( !regsubkey_ctr_key_exists( subkeys, sourcename ) ) {
333
( " Source name [%s] for eventlog [%s] didn't exist, adding \n",
334
sourcename, eventlog ) );
335
regsubkey_ctr_addkey( subkeys, sourcename );
336
if ( !regdb_store_keys( evtlogpath, subkeys ) )
339
TALLOC_FREE(subkeys);
341
/* at this point KEY_EVENTLOG/<eventlog>/<sourcename> key is in there. Now need to add EventMessageFile */
343
/* now allocate room for the source's subkeys */
345
werr = regsubkey_ctr_init(ctx, &subkeys);
346
if (!W_ERROR_IS_OK(werr)) {
347
DEBUG( 0, ( "talloc() failure!\n" ) );
350
TALLOC_FREE(evtlogpath);
351
evtlogpath = talloc_asprintf(ctx, "%s\\%s\\%s",
352
KEY_EVENTLOG, eventlog, sourcename);
354
TALLOC_FREE(subkeys);
358
regdb_fetch_keys( evtlogpath, subkeys );
360
/* now add the values to the KEY_EVENTLOG/Application form key */
361
if ( !( values = TALLOC_ZERO_P(ctx, struct regval_ctr ) ) ) {
362
DEBUG( 0, ( "talloc() failure!\n" ) );
366
( "Storing EventMessageFile [%s] to eventlog path of [%s]\n",
367
messagefile, evtlogpath ) );
369
regdb_fetch_values( evtlogpath, values );
371
regval_ctr_addvalue_sz(values, "EventMessageFile", messagefile);
372
regdb_store_values( evtlogpath, values );