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( );
38 REGSUBKEY_CTR *subkeys;
42 uint32 uiCategoryCount;
45 while ( elogs && *elogs ) {
46 if ( !( subkeys = TALLOC_ZERO_P( NULL, REGSUBKEY_CTR ) ) ) {
47 DEBUG( 0, ( "talloc() failure!\n" ) );
50 regdb_fetch_keys( KEY_EVENTLOG, subkeys );
51 regsubkey_ctr_addkey( subkeys, *elogs );
52 if ( !regdb_store_keys( KEY_EVENTLOG, subkeys ) ) {
56 TALLOC_FREE( subkeys );
58 /* add in the key of form KEY_EVENTLOG/Application */
60 ( "Adding key of [%s] to path of [%s]\n", *elogs,
63 slprintf( evtlogpath, sizeof( evtlogpath ) - 1, "%s\\%s",
64 KEY_EVENTLOG, *elogs );
65 /* add in the key of form KEY_EVENTLOG/Application/Application */
67 ( "Adding key of [%s] to path of [%s]\n", *elogs,
69 if ( !( subkeys = TALLOC_ZERO_P( NULL, REGSUBKEY_CTR ) ) ) {
70 DEBUG( 0, ( "talloc() failure!\n" ) );
73 regdb_fetch_keys( evtlogpath, subkeys );
74 regsubkey_ctr_addkey( subkeys, *elogs );
76 if ( !regdb_store_keys( evtlogpath, subkeys ) ) {
80 TALLOC_FREE( subkeys );
82 /* now add the values to the KEY_EVENTLOG/Application form key */
83 if ( !( values = TALLOC_ZERO_P( NULL, REGVAL_CTR ) ) ) {
84 DEBUG( 0, ( "talloc() failure!\n" ) );
88 ( "Storing values to eventlog path of [%s]\n",
90 regdb_fetch_values( evtlogpath, values );
93 if ( !regval_ctr_key_exists( values, "MaxSize" ) ) {
95 /* assume we have none, add them all */
97 /* hard code some initial values */
99 /* uiDisplayNameId = 0x00000100; */
100 uiMaxSize = 0x00080000;
101 uiRetention = 0x93A80;
103 regval_ctr_addvalue( values, "MaxSize", REG_DWORD,
104 ( char * ) &uiMaxSize,
107 regval_ctr_addvalue( values, "Retention", REG_DWORD,
108 ( char * ) &uiRetention,
110 init_unistr2( &data, *elogs, UNI_STR_TERMINATE );
112 regval_ctr_addvalue( values, "PrimaryModule", REG_SZ,
113 ( char * ) data.buffer,
116 init_unistr2( &data, *elogs, UNI_STR_TERMINATE );
118 regval_ctr_addvalue( values, "Sources", REG_MULTI_SZ,
119 ( char * ) data.buffer,
123 pstr_sprintf( evtfilepath, "%%SystemRoot%%\\system32\\config\\%s.tdb", *elogs );
124 init_unistr2( &data, evtfilepath, UNI_STR_TERMINATE );
125 regval_ctr_addvalue( values, "File", REG_EXPAND_SZ, ( char * ) data.buffer,
126 data.uni_str_len * sizeof( uint16 ) );
127 regdb_store_values( evtlogpath, values );
131 TALLOC_FREE( values );
133 /* now do the values under KEY_EVENTLOG/Application/Application */
134 slprintf( evtlogpath, sizeof( evtlogpath ) - 1, "%s\\%s\\%s",
135 KEY_EVENTLOG, *elogs, *elogs );
136 if ( !( values = TALLOC_ZERO_P( NULL, REGVAL_CTR ) ) ) {
137 DEBUG( 0, ( "talloc() failure!\n" ) );
141 ( "Storing values to eventlog path of [%s]\n",
143 regdb_fetch_values( evtlogpath, values );
144 if ( !regval_ctr_key_exists( values, "CategoryCount" ) ) {
146 /* hard code some initial values */
148 uiCategoryCount = 0x00000007;
149 regval_ctr_addvalue( values, "CategoryCount",
151 ( char * ) &uiCategoryCount,
154 "%SystemRoot%\\system32\\eventlog.dll",
157 regval_ctr_addvalue( values, "CategoryMessageFile",
159 ( char * ) data.buffer,
162 regdb_store_values( evtlogpath, values );
164 TALLOC_FREE( values );
172 /*********************************************************************
173 for an eventlog, add in a source name. If the eventlog doesn't
174 exist (not in the list) do nothing. If a source for the log
175 already exists, change the information (remove, replace)
176 *********************************************************************/
178 bool eventlog_add_source( const char *eventlog, const char *sourcename,
179 const char *messagefile )
181 /* Find all of the eventlogs, add keys for each of them */
182 /* need to add to the value KEY_EVENTLOG/<eventlog>/Sources string (Creating if necessary)
183 need to add KEY of source to KEY_EVENTLOG/<eventlog>/<source> */
185 const char **elogs = lp_eventlog_list( );
186 char **wrklist, **wp;
188 REGSUBKEY_CTR *subkeys;
190 REGISTRY_VALUE *rval;
202 for ( i = 0; elogs[i]; i++ ) {
203 if ( strequal( elogs[i], eventlog ) )
209 ( "Eventlog [%s] not found in list of valid event logs\n",
211 return False; /* invalid named passed in */
214 /* have to assume that the evenlog key itself exists at this point */
215 /* add in a key of [sourcename] under the eventlog key */
217 /* todo add to Sources */
219 if ( !( values = TALLOC_ZERO_P( NULL, REGVAL_CTR ) ) ) {
220 DEBUG( 0, ( "talloc() failure!\n" ) );
224 pstr_sprintf( evtlogpath, "%s\\%s", KEY_EVENTLOG, eventlog );
226 regdb_fetch_values( evtlogpath, values );
229 if ( !( rval = regval_ctr_getvalue( values, "Sources" ) ) ) {
230 DEBUG( 0, ( "No Sources value for [%s]!\n", eventlog ) );
233 /* perhaps this adding a new string to a multi_sz should be a fn? */
234 /* check to see if it's there already */
236 if ( rval->type != REG_MULTI_SZ ) {
238 ( "Wrong type for Sources, should be REG_MULTI_SZ\n" ) );
241 /* convert to a 'regulah' chars to do some comparisons */
245 dump_data( 1, rval->data_p, rval->size );
247 regval_convert_multi_sz( ( uint16 * ) rval->data_p, rval->size,
251 /* see if it's in there already */
254 while ( ii && wp && *wp ) {
255 if ( strequal( *wp, sourcename ) ) {
257 ( "Source name [%s] already in list for [%s] \n",
258 sourcename, eventlog ) );
266 if ( numsources < 0 ) {
267 DEBUG( 3, ( "problem in getting the sources\n" ) );
271 ( "Nothing in the sources list, this might be a problem\n" ) );
277 /* make a new list with an additional entry; copy values, add another */
278 wp = TALLOC_ARRAY( NULL, char *, numsources + 2 );
281 DEBUG( 0, ( "talloc() failed \n" ) );
284 memcpy( wp, wrklist, sizeof( char * ) * numsources );
285 *( wp + numsources ) = ( char * ) sourcename;
286 *( wp + numsources + 1 ) = NULL;
287 mbytes = regval_build_multi_sz( wp, &msz_wp );
288 dump_data( 1, ( uint8 * ) msz_wp, mbytes );
289 regval_ctr_addvalue( values, "Sources", REG_MULTI_SZ,
290 ( char * ) msz_wp, mbytes );
291 regdb_store_values( evtlogpath, values );
292 TALLOC_FREE( msz_wp );
295 ( "Source name [%s] found in existing list of sources\n",
298 TALLOC_FREE( values );
299 TALLOC_FREE( wrklist ); /* */
301 if ( !( subkeys = TALLOC_ZERO_P( NULL, REGSUBKEY_CTR ) ) ) {
302 DEBUG( 0, ( "talloc() failure!\n" ) );
305 pstr_sprintf( evtlogpath, "%s\\%s", KEY_EVENTLOG, eventlog );
307 regdb_fetch_keys( evtlogpath, subkeys );
309 if ( !regsubkey_ctr_key_exists( subkeys, sourcename ) ) {
311 ( " Source name [%s] for eventlog [%s] didn't exist, adding \n",
312 sourcename, eventlog ) );
313 regsubkey_ctr_addkey( subkeys, sourcename );
314 if ( !regdb_store_keys( evtlogpath, subkeys ) )
317 TALLOC_FREE( subkeys );
319 /* at this point KEY_EVENTLOG/<eventlog>/<sourcename> key is in there. Now need to add EventMessageFile */
321 /* now allocate room for the source's subkeys */
323 if ( !( subkeys = TALLOC_ZERO_P( NULL, REGSUBKEY_CTR ) ) ) {
324 DEBUG( 0, ( "talloc() failure!\n" ) );
327 slprintf( evtlogpath, sizeof( evtlogpath ) - 1, "%s\\%s\\%s",
328 KEY_EVENTLOG, eventlog, sourcename );
330 regdb_fetch_keys( evtlogpath, subkeys );
332 /* now add the values to the KEY_EVENTLOG/Application form key */
333 if ( !( values = TALLOC_ZERO_P( NULL, REGVAL_CTR ) ) ) {
334 DEBUG( 0, ( "talloc() failure!\n" ) );
338 ( "Storing EventMessageFile [%s] to eventlog path of [%s]\n",
339 messagefile, evtlogpath ) );
341 regdb_fetch_values( evtlogpath, values );
343 init_unistr2( &data, messagefile, UNI_STR_TERMINATE );
345 regval_ctr_addvalue( values, "EventMessageFile", REG_SZ,
346 ( char * ) data.buffer,
347 data.uni_str_len * sizeof( uint16 ) );
348 regdb_store_values( evtlogpath, values );
350 TALLOC_FREE( values );