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
;
39 uint32 uiDisplayNameId
;
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
) )
54 TALLOC_FREE( subkeys
);
56 /* add in the key of form KEY_EVENTLOG/Application */
58 ( "Adding key of [%s] to path of [%s]\n", *elogs
,
61 slprintf( evtlogpath
, sizeof( evtlogpath
) - 1, "%s\\%s",
62 KEY_EVENTLOG
, *elogs
);
63 /* add in the key of form KEY_EVENTLOG/Application/Application */
65 ( "Adding key of [%s] to path of [%s]\n", *elogs
,
67 if ( !( subkeys
= TALLOC_ZERO_P( NULL
, REGSUBKEY_CTR
) ) ) {
68 DEBUG( 0, ( "talloc() failure!\n" ) );
71 regdb_fetch_keys( evtlogpath
, subkeys
);
72 regsubkey_ctr_addkey( subkeys
, *elogs
);
74 if ( !regdb_store_keys( evtlogpath
, subkeys
) )
76 TALLOC_FREE( subkeys
);
78 /* now add the values to the KEY_EVENTLOG/Application form key */
79 if ( !( values
= TALLOC_ZERO_P( NULL
, REGVAL_CTR
) ) ) {
80 DEBUG( 0, ( "talloc() failure!\n" ) );
84 ( "Storing values to eventlog path of [%s]\n",
86 regdb_fetch_values( evtlogpath
, values
);
89 if ( !regval_ctr_key_exists( values
, "MaxSize" ) ) {
91 /* assume we have none, add them all */
93 /* hard code some initial values */
95 uiDisplayNameId
= 0x00000100;
96 uiMaxSize
= 0x00080000;
97 uiRetention
= 0x93A80;
99 regval_ctr_addvalue( values
, "MaxSize", REG_DWORD
,
100 ( char * ) &uiMaxSize
,
103 regval_ctr_addvalue( values
, "Retention", REG_DWORD
,
104 ( char * ) &uiRetention
,
106 init_unistr2( &data
, *elogs
, UNI_STR_TERMINATE
);
108 regval_ctr_addvalue( values
, "PrimaryModule", REG_SZ
,
109 ( char * ) data
.buffer
,
112 init_unistr2( &data
, *elogs
, UNI_STR_TERMINATE
);
114 regval_ctr_addvalue( values
, "Sources", REG_MULTI_SZ
,
115 ( char * ) data
.buffer
,
119 pstr_sprintf( evtfilepath
, "%%SystemRoot%%\\system32\\config\\%s.tdb", *elogs
);
120 init_unistr2( &data
, evtfilepath
, UNI_STR_TERMINATE
);
121 regval_ctr_addvalue( values
, "File", REG_EXPAND_SZ
, ( char * ) data
.buffer
,
122 data
.uni_str_len
* sizeof( uint16
) );
123 regdb_store_values( evtlogpath
, values
);
127 TALLOC_FREE( values
);
129 /* now do the values under KEY_EVENTLOG/Application/Application */
130 slprintf( evtlogpath
, sizeof( evtlogpath
) - 1, "%s\\%s\\%s",
131 KEY_EVENTLOG
, *elogs
, *elogs
);
132 if ( !( values
= TALLOC_ZERO_P( NULL
, REGVAL_CTR
) ) ) {
133 DEBUG( 0, ( "talloc() failure!\n" ) );
137 ( "Storing values to eventlog path of [%s]\n",
139 regdb_fetch_values( evtlogpath
, values
);
140 if ( !regval_ctr_key_exists( values
, "CategoryCount" ) ) {
142 /* hard code some initial values */
144 uiCategoryCount
= 0x00000007;
145 regval_ctr_addvalue( values
, "CategoryCount",
147 ( char * ) &uiCategoryCount
,
150 "%SystemRoot%\\system32\\eventlog.dll",
153 regval_ctr_addvalue( values
, "CategoryMessageFile",
155 ( char * ) data
.buffer
,
158 regdb_store_values( evtlogpath
, values
);
160 TALLOC_FREE( values
);
168 /*********************************************************************
169 for an eventlog, add in a source name. If the eventlog doesn't
170 exist (not in the list) do nothing. If a source for the log
171 already exists, change the information (remove, replace)
172 *********************************************************************/
174 BOOL
eventlog_add_source( const char *eventlog
, const char *sourcename
,
175 const char *messagefile
)
177 /* Find all of the eventlogs, add keys for each of them */
178 /* need to add to the value KEY_EVENTLOG/<eventlog>/Sources string (Creating if necessary)
179 need to add KEY of source to KEY_EVENTLOG/<eventlog>/<source> */
181 const char **elogs
= lp_eventlog_list( );
182 char **wrklist
, **wp
;
184 REGSUBKEY_CTR
*subkeys
;
186 REGISTRY_VALUE
*rval
;
194 for ( i
= 0; elogs
[i
]; i
++ ) {
195 if ( strequal( elogs
[i
], eventlog
) )
201 ( "Eventlog [%s] not found in list of valid event logs\n",
203 return False
; /* invalid named passed in */
206 /* have to assume that the evenlog key itself exists at this point */
207 /* add in a key of [sourcename] under the eventlog key */
209 /* todo add to Sources */
211 if ( !( values
= TALLOC_ZERO_P( NULL
, REGVAL_CTR
) ) ) {
212 DEBUG( 0, ( "talloc() failure!\n" ) );
216 pstr_sprintf( evtlogpath
, "%s\\%s", KEY_EVENTLOG
, eventlog
);
218 regdb_fetch_values( evtlogpath
, values
);
221 if ( !( rval
= regval_ctr_getvalue( values
, "Sources" ) ) ) {
222 DEBUG( 0, ( "No Sources value for [%s]!\n", eventlog
) );
225 /* perhaps this adding a new string to a multi_sz should be a fn? */
226 /* check to see if it's there already */
228 if ( rval
->type
!= REG_MULTI_SZ
) {
230 ( "Wrong type for Sources, should be REG_MULTI_SZ\n" ) );
233 /* convert to a 'regulah' chars to do some comparisons */
237 dump_data( 1, (const char *)rval
->data_p
, rval
->size
);
239 regval_convert_multi_sz( ( uint16
* ) rval
->data_p
, rval
->size
,
243 /* see if it's in there already */
246 while ( ii
&& wp
&& *wp
) {
247 if ( strequal( *wp
, sourcename
) ) {
249 ( "Source name [%s] already in list for [%s] \n",
250 sourcename
, eventlog
) );
258 if ( numsources
< 0 ) {
259 DEBUG( 3, ( "problem in getting the sources\n" ) );
263 ( "Nothing in the sources list, this might be a problem\n" ) );
269 /* make a new list with an additional entry; copy values, add another */
270 wp
= TALLOC_ARRAY( NULL
, char *, numsources
+ 2 );
273 DEBUG( 0, ( "talloc() failed \n" ) );
276 memcpy( wp
, wrklist
, sizeof( char * ) * numsources
);
277 *( wp
+ numsources
) = ( char * ) sourcename
;
278 *( wp
+ numsources
+ 1 ) = NULL
;
279 mbytes
= regval_build_multi_sz( wp
, &msz_wp
);
280 dump_data( 1, ( char * ) msz_wp
, mbytes
);
281 regval_ctr_addvalue( values
, "Sources", REG_MULTI_SZ
,
282 ( char * ) msz_wp
, mbytes
);
283 regdb_store_values( evtlogpath
, values
);
284 TALLOC_FREE( msz_wp
);
287 ( "Source name [%s] found in existing list of sources\n",
290 TALLOC_FREE( values
);
292 TALLOC_FREE( wrklist
); /* */
294 if ( !( subkeys
= TALLOC_ZERO_P( NULL
, REGSUBKEY_CTR
) ) ) {
295 DEBUG( 0, ( "talloc() failure!\n" ) );
298 pstr_sprintf( evtlogpath
, "%s\\%s", KEY_EVENTLOG
, eventlog
);
300 regdb_fetch_keys( evtlogpath
, subkeys
);
302 if ( !regsubkey_ctr_key_exists( subkeys
, sourcename
) ) {
304 ( " Source name [%s] for eventlog [%s] didn't exist, adding \n",
305 sourcename
, eventlog
) );
306 regsubkey_ctr_addkey( subkeys
, sourcename
);
307 if ( !regdb_store_keys( evtlogpath
, subkeys
) )
310 TALLOC_FREE( subkeys
);
312 /* at this point KEY_EVENTLOG/<eventlog>/<sourcename> key is in there. Now need to add EventMessageFile */
314 /* now allocate room for the source's subkeys */
316 if ( !( subkeys
= TALLOC_ZERO_P( NULL
, REGSUBKEY_CTR
) ) ) {
317 DEBUG( 0, ( "talloc() failure!\n" ) );
320 slprintf( evtlogpath
, sizeof( evtlogpath
) - 1, "%s\\%s\\%s",
321 KEY_EVENTLOG
, eventlog
, sourcename
);
323 regdb_fetch_keys( evtlogpath
, subkeys
);
325 /* now add the values to the KEY_EVENTLOG/Application form key */
326 if ( !( values
= TALLOC_ZERO_P( NULL
, REGVAL_CTR
) ) ) {
327 DEBUG( 0, ( "talloc() failure!\n" ) );
331 ( "Storing EventMessageFile [%s] to eventlog path of [%s]\n",
332 messagefile
, evtlogpath
) );
334 regdb_fetch_values( evtlogpath
, values
);
336 init_unistr2( &data
, messagefile
, UNI_STR_TERMINATE
);
338 regval_ctr_addvalue( values
, "EventMessageFile", REG_SZ
,
339 ( char * ) data
.buffer
,
340 data
.uni_str_len
* sizeof( uint16
) );
341 regdb_store_values( evtlogpath
, values
);
343 TALLOC_FREE( values
);