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 REGSUBKEY_CTR
*subkeys
;
42 uint32 uiCategoryCount
;
44 TALLOC_CTX
*ctx
= talloc_tos();
46 while (elogs
&& *elogs
) {
47 if (!(subkeys
= TALLOC_ZERO_P(ctx
, REGSUBKEY_CTR
) ) ) {
48 DEBUG( 0, ( "talloc() failure!\n" ) );
51 regdb_fetch_keys(KEY_EVENTLOG
, subkeys
);
52 regsubkey_ctr_addkey( subkeys
, *elogs
);
53 if ( !regdb_store_keys( KEY_EVENTLOG
, subkeys
) ) {
59 /* add in the key of form KEY_EVENTLOG/Application */
61 ( "Adding key of [%s] to path of [%s]\n", *elogs
,
64 evtlogpath
= talloc_asprintf(ctx
, "%s\\%s",
65 KEY_EVENTLOG
, *elogs
);
69 /* add in the key of form KEY_EVENTLOG/Application/Application */
71 ( "Adding key of [%s] to path of [%s]\n", *elogs
,
73 if (!(subkeys
= TALLOC_ZERO_P(ctx
, REGSUBKEY_CTR
))) {
74 DEBUG( 0, ( "talloc() failure!\n" ) );
77 regdb_fetch_keys( evtlogpath
, subkeys
);
78 regsubkey_ctr_addkey( subkeys
, *elogs
);
80 if ( !regdb_store_keys( evtlogpath
, subkeys
) ) {
84 TALLOC_FREE( subkeys
);
86 /* now add the values to the KEY_EVENTLOG/Application form key */
87 if (!(values
= TALLOC_ZERO_P(ctx
, REGVAL_CTR
))) {
88 DEBUG( 0, ( "talloc() failure!\n" ) );
92 ( "Storing values to eventlog path of [%s]\n",
94 regdb_fetch_values( evtlogpath
, values
);
97 if (!regval_ctr_key_exists(values
, "MaxSize")) {
99 /* assume we have none, add them all */
101 /* hard code some initial values */
103 /* uiDisplayNameId = 0x00000100; */
104 uiMaxSize
= 0x00080000;
105 uiRetention
= 0x93A80;
107 regval_ctr_addvalue(values
, "MaxSize", REG_DWORD
,
111 regval_ctr_addvalue(values
, "Retention", REG_DWORD
,
112 (char *)&uiRetention
,
114 init_unistr2(&data
, *elogs
, UNI_STR_TERMINATE
);
116 regval_ctr_addvalue(values
, "PrimaryModule", REG_SZ
,
120 init_unistr2(&data
, *elogs
, UNI_STR_TERMINATE
);
122 regval_ctr_addvalue(values
, "Sources", REG_MULTI_SZ
,
127 evtfilepath
= talloc_asprintf(ctx
,
128 "%%SystemRoot%%\\system32\\config\\%s.tdb",
133 init_unistr2(&data
, evtfilepath
, UNI_STR_TERMINATE
);
134 regval_ctr_addvalue(values
, "File", REG_EXPAND_SZ
, (char *)data
.buffer
,
135 data
.uni_str_len
* sizeof(uint16
));
136 regdb_store_values(evtlogpath
, values
);
142 /* now do the values under KEY_EVENTLOG/Application/Application */
143 TALLOC_FREE(evtlogpath
);
144 evtlogpath
= talloc_asprintf(ctx
, "%s\\%s\\%s",
145 KEY_EVENTLOG
, *elogs
, *elogs
);
149 if (!(values
= TALLOC_ZERO_P(ctx
, REGVAL_CTR
))) {
150 DEBUG( 0, ( "talloc() failure!\n" ) );
154 ( "Storing values to eventlog path of [%s]\n",
156 regdb_fetch_values(evtlogpath
, values
);
157 if (!regval_ctr_key_exists( values
, "CategoryCount")) {
159 /* hard code some initial values */
161 uiCategoryCount
= 0x00000007;
162 regval_ctr_addvalue( values
, "CategoryCount",
164 ( char * ) &uiCategoryCount
,
167 "%SystemRoot%\\system32\\eventlog.dll",
170 regval_ctr_addvalue( values
, "CategoryMessageFile",
172 ( char * ) data
.buffer
,
175 regdb_store_values( evtlogpath
, values
);
184 /*********************************************************************
185 for an eventlog, add in a source name. If the eventlog doesn't
186 exist (not in the list) do nothing. If a source for the log
187 already exists, change the information (remove, replace)
188 *********************************************************************/
190 bool eventlog_add_source( const char *eventlog
, const char *sourcename
,
191 const char *messagefile
)
193 /* Find all of the eventlogs, add keys for each of them */
194 /* need to add to the value KEY_EVENTLOG/<eventlog>/Sources string (Creating if necessary)
195 need to add KEY of source to KEY_EVENTLOG/<eventlog>/<source> */
197 const char **elogs
= lp_eventlog_list( );
198 char **wrklist
, **wp
;
199 char *evtlogpath
= NULL
;
200 REGSUBKEY_CTR
*subkeys
;
202 REGISTRY_VALUE
*rval
;
209 TALLOC_CTX
*ctx
= talloc_tos();
215 for ( i
= 0; elogs
[i
]; i
++ ) {
216 if ( strequal( elogs
[i
], eventlog
) )
222 ( "Eventlog [%s] not found in list of valid event logs\n",
224 return false; /* invalid named passed in */
227 /* have to assume that the evenlog key itself exists at this point */
228 /* add in a key of [sourcename] under the eventlog key */
230 /* todo add to Sources */
232 if (!( values
= TALLOC_ZERO_P(ctx
, REGVAL_CTR
))) {
233 DEBUG( 0, ( "talloc() failure!\n" ));
237 evtlogpath
= talloc_asprintf(ctx
, "%s\\%s", KEY_EVENTLOG
, eventlog
);
243 regdb_fetch_values( evtlogpath
, values
);
246 if ( !( rval
= regval_ctr_getvalue( values
, "Sources" ) ) ) {
247 DEBUG( 0, ( "No Sources value for [%s]!\n", eventlog
) );
250 /* perhaps this adding a new string to a multi_sz should be a fn? */
251 /* check to see if it's there already */
253 if ( rval
->type
!= REG_MULTI_SZ
) {
255 ( "Wrong type for Sources, should be REG_MULTI_SZ\n" ) );
258 /* convert to a 'regulah' chars to do some comparisons */
262 dump_data( 1, rval
->data_p
, rval
->size
);
264 regval_convert_multi_sz( ( uint16
* ) rval
->data_p
, rval
->size
,
268 /* see if it's in there already */
271 while ( ii
&& wp
&& *wp
) {
272 if ( strequal( *wp
, sourcename
) ) {
274 ( "Source name [%s] already in list for [%s] \n",
275 sourcename
, eventlog
) );
283 if ( numsources
< 0 ) {
284 DEBUG( 3, ( "problem in getting the sources\n" ) );
288 ( "Nothing in the sources list, this might be a problem\n" ) );
294 /* make a new list with an additional entry; copy values, add another */
295 wp
= TALLOC_ARRAY(ctx
, char *, numsources
+ 2 );
298 DEBUG( 0, ( "talloc() failed \n" ) );
301 memcpy( wp
, wrklist
, sizeof( char * ) * numsources
);
302 *( wp
+ numsources
) = ( char * ) sourcename
;
303 *( wp
+ numsources
+ 1 ) = NULL
;
304 mbytes
= regval_build_multi_sz( wp
, &msz_wp
);
305 dump_data( 1, ( uint8
* ) msz_wp
, mbytes
);
306 regval_ctr_addvalue( values
, "Sources", REG_MULTI_SZ
,
307 ( char * ) msz_wp
, mbytes
);
308 regdb_store_values( evtlogpath
, values
);
312 ( "Source name [%s] found in existing list of sources\n",
316 TALLOC_FREE(wrklist
); /* */
318 if ( !( subkeys
= TALLOC_ZERO_P(ctx
, REGSUBKEY_CTR
) ) ) {
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 if ( !( subkeys
= TALLOC_ZERO_P(ctx
, REGSUBKEY_CTR
) ) ) {
346 DEBUG( 0, ( "talloc() failure!\n" ) );
349 TALLOC_FREE(evtlogpath
);
350 evtlogpath
= talloc_asprintf(ctx
, "%s\\%s\\%s",
351 KEY_EVENTLOG
, eventlog
, sourcename
);
353 TALLOC_FREE(subkeys
);
357 regdb_fetch_keys( evtlogpath
, subkeys
);
359 /* now add the values to the KEY_EVENTLOG/Application form key */
360 if ( !( values
= TALLOC_ZERO_P(ctx
, REGVAL_CTR
) ) ) {
361 DEBUG( 0, ( "talloc() failure!\n" ) );
365 ( "Storing EventMessageFile [%s] to eventlog path of [%s]\n",
366 messagefile
, evtlogpath
) );
368 regdb_fetch_values( evtlogpath
, values
);
370 init_unistr2( &data
, messagefile
, UNI_STR_TERMINATE
);
372 regval_ctr_addvalue( values
, "EventMessageFile", REG_SZ
,
373 ( char * ) data
.buffer
,
374 data
.uni_str_len
* sizeof( uint16
) );
375 regdb_store_values( evtlogpath
, values
);