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 2 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, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 /**********************************************************************
28 for an eventlog, add in the default values
29 *********************************************************************/
31 BOOL eventlog_init_keys( void )
33 /* Find all of the eventlogs, add keys for each of them */
34 const char **elogs = lp_eventlog_list( );
37 REGSUBKEY_CTR *subkeys;
41 uint32 uiCategoryCount;
44 while ( elogs && *elogs ) {
45 if ( !( subkeys = TALLOC_ZERO_P( NULL, REGSUBKEY_CTR ) ) ) {
46 DEBUG( 0, ( "talloc() failure!\n" ) );
49 regdb_fetch_keys( KEY_EVENTLOG, subkeys );
50 regsubkey_ctr_addkey( subkeys, *elogs );
51 if ( !regdb_store_keys( KEY_EVENTLOG, subkeys ) ) {
55 TALLOC_FREE( subkeys );
57 /* add in the key of form KEY_EVENTLOG/Application */
59 ( "Adding key of [%s] to path of [%s]\n", *elogs,
62 slprintf( evtlogpath, sizeof( evtlogpath ) - 1, "%s\\%s",
63 KEY_EVENTLOG, *elogs );
64 /* add in the key of form KEY_EVENTLOG/Application/Application */
66 ( "Adding key of [%s] to path of [%s]\n", *elogs,
68 if ( !( subkeys = TALLOC_ZERO_P( NULL, REGSUBKEY_CTR ) ) ) {
69 DEBUG( 0, ( "talloc() failure!\n" ) );
72 regdb_fetch_keys( evtlogpath, subkeys );
73 regsubkey_ctr_addkey( subkeys, *elogs );
75 if ( !regdb_store_keys( evtlogpath, subkeys ) ) {
79 TALLOC_FREE( subkeys );
81 /* now add the values to the KEY_EVENTLOG/Application form key */
82 if ( !( values = TALLOC_ZERO_P( NULL, REGVAL_CTR ) ) ) {
83 DEBUG( 0, ( "talloc() failure!\n" ) );
87 ( "Storing values to eventlog path of [%s]\n",
89 regdb_fetch_values( evtlogpath, values );
92 if ( !regval_ctr_key_exists( values, "MaxSize" ) ) {
94 /* assume we have none, add them all */
96 /* hard code some initial values */
98 /* uiDisplayNameId = 0x00000100; */
99 uiMaxSize = 0x00080000;
100 uiRetention = 0x93A80;
102 regval_ctr_addvalue( values, "MaxSize", REG_DWORD,
103 ( char * ) &uiMaxSize,
106 regval_ctr_addvalue( values, "Retention", REG_DWORD,
107 ( char * ) &uiRetention,
109 init_unistr2( &data, *elogs, UNI_STR_TERMINATE );
111 regval_ctr_addvalue( values, "PrimaryModule", REG_SZ,
112 ( char * ) data.buffer,
115 init_unistr2( &data, *elogs, UNI_STR_TERMINATE );
117 regval_ctr_addvalue( values, "Sources", REG_MULTI_SZ,
118 ( char * ) data.buffer,
122 pstr_sprintf( evtfilepath, "%%SystemRoot%%\\system32\\config\\%s.tdb", *elogs );
123 init_unistr2( &data, evtfilepath, UNI_STR_TERMINATE );
124 regval_ctr_addvalue( values, "File", REG_EXPAND_SZ, ( char * ) data.buffer,
125 data.uni_str_len * sizeof( uint16 ) );
126 regdb_store_values( evtlogpath, values );
130 TALLOC_FREE( values );
132 /* now do the values under KEY_EVENTLOG/Application/Application */
133 slprintf( evtlogpath, sizeof( evtlogpath ) - 1, "%s\\%s\\%s",
134 KEY_EVENTLOG, *elogs, *elogs );
135 if ( !( values = TALLOC_ZERO_P( NULL, REGVAL_CTR ) ) ) {
136 DEBUG( 0, ( "talloc() failure!\n" ) );
140 ( "Storing values to eventlog path of [%s]\n",
142 regdb_fetch_values( evtlogpath, values );
143 if ( !regval_ctr_key_exists( values, "CategoryCount" ) ) {
145 /* hard code some initial values */
147 uiCategoryCount = 0x00000007;
148 regval_ctr_addvalue( values, "CategoryCount",
150 ( char * ) &uiCategoryCount,
153 "%SystemRoot%\\system32\\eventlog.dll",
156 regval_ctr_addvalue( values, "CategoryMessageFile",
158 ( char * ) data.buffer,
161 regdb_store_values( evtlogpath, values );
163 TALLOC_FREE( values );
171 /*********************************************************************
172 for an eventlog, add in a source name. If the eventlog doesn't
173 exist (not in the list) do nothing. If a source for the log
174 already exists, change the information (remove, replace)
175 *********************************************************************/
177 BOOL eventlog_add_source( const char *eventlog, const char *sourcename,
178 const char *messagefile )
180 /* Find all of the eventlogs, add keys for each of them */
181 /* need to add to the value KEY_EVENTLOG/<eventlog>/Sources string (Creating if necessary)
182 need to add KEY of source to KEY_EVENTLOG/<eventlog>/<source> */
184 const char **elogs = lp_eventlog_list( );
185 char **wrklist, **wp;
187 REGSUBKEY_CTR *subkeys;
189 REGISTRY_VALUE *rval;
197 for ( i = 0; elogs[i]; i++ ) {
198 if ( strequal( elogs[i], eventlog ) )
204 ( "Eventlog [%s] not found in list of valid event logs\n",
206 return False; /* invalid named passed in */
209 /* have to assume that the evenlog key itself exists at this point */
210 /* add in a key of [sourcename] under the eventlog key */
212 /* todo add to Sources */
214 if ( !( values = TALLOC_ZERO_P( NULL, REGVAL_CTR ) ) ) {
215 DEBUG( 0, ( "talloc() failure!\n" ) );
219 pstr_sprintf( evtlogpath, "%s\\%s", KEY_EVENTLOG, eventlog );
221 regdb_fetch_values( evtlogpath, values );
224 if ( !( rval = regval_ctr_getvalue( values, "Sources" ) ) ) {
225 DEBUG( 0, ( "No Sources value for [%s]!\n", eventlog ) );
228 /* perhaps this adding a new string to a multi_sz should be a fn? */
229 /* check to see if it's there already */
231 if ( rval->type != REG_MULTI_SZ ) {
233 ( "Wrong type for Sources, should be REG_MULTI_SZ\n" ) );
236 /* convert to a 'regulah' chars to do some comparisons */
240 dump_data( 1, rval->data_p, rval->size );
242 regval_convert_multi_sz( ( uint16 * ) rval->data_p, rval->size,
246 /* see if it's in there already */
249 while ( ii && wp && *wp ) {
250 if ( strequal( *wp, sourcename ) ) {
252 ( "Source name [%s] already in list for [%s] \n",
253 sourcename, eventlog ) );
261 if ( numsources < 0 ) {
262 DEBUG( 3, ( "problem in getting the sources\n" ) );
266 ( "Nothing in the sources list, this might be a problem\n" ) );
272 /* make a new list with an additional entry; copy values, add another */
273 wp = TALLOC_ARRAY( NULL, char *, numsources + 2 );
276 DEBUG( 0, ( "talloc() failed \n" ) );
279 memcpy( wp, wrklist, sizeof( char * ) * numsources );
280 *( wp + numsources ) = ( char * ) sourcename;
281 *( wp + numsources + 1 ) = NULL;
282 mbytes = regval_build_multi_sz( wp, &msz_wp );
283 dump_data( 1, ( uint8 * ) msz_wp, mbytes );
284 regval_ctr_addvalue( values, "Sources", REG_MULTI_SZ,
285 ( char * ) msz_wp, mbytes );
286 regdb_store_values( evtlogpath, values );
287 TALLOC_FREE( msz_wp );
290 ( "Source name [%s] found in existing list of sources\n",
293 TALLOC_FREE( values );
294 TALLOC_FREE( wrklist ); /* */
296 if ( !( subkeys = TALLOC_ZERO_P( NULL, REGSUBKEY_CTR ) ) ) {
297 DEBUG( 0, ( "talloc() failure!\n" ) );
300 pstr_sprintf( evtlogpath, "%s\\%s", KEY_EVENTLOG, eventlog );
302 regdb_fetch_keys( evtlogpath, subkeys );
304 if ( !regsubkey_ctr_key_exists( subkeys, sourcename ) ) {
306 ( " Source name [%s] for eventlog [%s] didn't exist, adding \n",
307 sourcename, eventlog ) );
308 regsubkey_ctr_addkey( subkeys, sourcename );
309 if ( !regdb_store_keys( evtlogpath, subkeys ) )
312 TALLOC_FREE( subkeys );
314 /* at this point KEY_EVENTLOG/<eventlog>/<sourcename> key is in there. Now need to add EventMessageFile */
316 /* now allocate room for the source's subkeys */
318 if ( !( subkeys = TALLOC_ZERO_P( NULL, REGSUBKEY_CTR ) ) ) {
319 DEBUG( 0, ( "talloc() failure!\n" ) );
322 slprintf( evtlogpath, sizeof( evtlogpath ) - 1, "%s\\%s\\%s",
323 KEY_EVENTLOG, eventlog, sourcename );
325 regdb_fetch_keys( evtlogpath, subkeys );
327 /* now add the values to the KEY_EVENTLOG/Application form key */
328 if ( !( values = TALLOC_ZERO_P( NULL, REGVAL_CTR ) ) ) {
329 DEBUG( 0, ( "talloc() failure!\n" ) );
333 ( "Storing EventMessageFile [%s] to eventlog path of [%s]\n",
334 messagefile, evtlogpath ) );
336 regdb_fetch_values( evtlogpath, values );
338 init_unistr2( &data, messagefile, UNI_STR_TERMINATE );
340 regval_ctr_addvalue( values, "EventMessageFile", REG_SZ,
341 ( char * ) data.buffer,
342 data.uni_str_len * sizeof( uint16 ) );
343 regdb_store_values( evtlogpath, values );
345 TALLOC_FREE( values );