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/>.
27 #define DBGC_CLASS DBGC_REGISTRY
29 /**********************************************************************
30 for an eventlog, add in the default values
31 *********************************************************************/
33 bool eventlog_init_keys(void)
35 /* Find all of the eventlogs, add keys for each of them */
36 const char **elogs
= lp_eventlog_list();
37 char *evtlogpath
= NULL
;
38 char *evtfilepath
= NULL
;
39 struct regsubkey_ctr
*subkeys
;
40 struct regval_ctr
*values
;
43 uint32 uiCategoryCount
;
45 TALLOC_CTX
*ctx
= talloc_tos();
48 while (elogs
&& *elogs
) {
49 werr
= regsubkey_ctr_init(ctx
, &subkeys
);
50 if (!W_ERROR_IS_OK(werr
)) {
51 DEBUG( 0, ( "talloc() failure!\n" ) );
54 regdb_fetch_keys(KEY_EVENTLOG
, subkeys
);
55 regsubkey_ctr_addkey( subkeys
, *elogs
);
56 if ( !regdb_store_keys( KEY_EVENTLOG
, subkeys
) ) {
62 /* add in the key of form KEY_EVENTLOG/Application */
64 ( "Adding key of [%s] to path of [%s]\n", *elogs
,
67 evtlogpath
= talloc_asprintf(ctx
, "%s\\%s",
68 KEY_EVENTLOG
, *elogs
);
72 /* add in the key of form KEY_EVENTLOG/Application/Application */
74 ( "Adding key of [%s] to path of [%s]\n", *elogs
,
76 werr
= regsubkey_ctr_init(ctx
, &subkeys
);
77 if (!W_ERROR_IS_OK(werr
)) {
78 DEBUG( 0, ( "talloc() failure!\n" ) );
81 regdb_fetch_keys( evtlogpath
, subkeys
);
82 regsubkey_ctr_addkey( subkeys
, *elogs
);
84 if ( !regdb_store_keys( evtlogpath
, subkeys
) ) {
88 TALLOC_FREE( subkeys
);
90 /* now add the values to the KEY_EVENTLOG/Application form key */
91 if (!(values
= TALLOC_ZERO_P(ctx
, struct regval_ctr
))) {
92 DEBUG( 0, ( "talloc() failure!\n" ) );
96 ( "Storing values to eventlog path of [%s]\n",
98 regdb_fetch_values( evtlogpath
, values
);
101 if (!regval_ctr_key_exists(values
, "MaxSize")) {
103 /* assume we have none, add them all */
105 /* hard code some initial values */
107 /* uiDisplayNameId = 0x00000100; */
108 uiMaxSize
= 0x00080000;
109 uiRetention
= 0x93A80;
111 regval_ctr_addvalue(values
, "MaxSize", REG_DWORD
,
115 regval_ctr_addvalue(values
, "Retention", REG_DWORD
,
116 (char *)&uiRetention
,
119 regval_ctr_addvalue_sz(values
, "PrimaryModule", *elogs
);
120 push_reg_sz(talloc_tos(), &data
, *elogs
);
122 regval_ctr_addvalue(values
, "Sources", REG_MULTI_SZ
,
126 evtfilepath
= talloc_asprintf(ctx
,
127 "%%SystemRoot%%\\system32\\config\\%s.tdb",
132 push_reg_sz(talloc_tos(), &data
, evtfilepath
);
133 regval_ctr_addvalue(values
, "File", REG_EXPAND_SZ
, (char *)data
.data
,
135 regdb_store_values(evtlogpath
, values
);
141 /* now do the values under KEY_EVENTLOG/Application/Application */
142 TALLOC_FREE(evtlogpath
);
143 evtlogpath
= talloc_asprintf(ctx
, "%s\\%s\\%s",
144 KEY_EVENTLOG
, *elogs
, *elogs
);
148 if (!(values
= TALLOC_ZERO_P(ctx
, struct regval_ctr
))) {
149 DEBUG( 0, ( "talloc() failure!\n" ) );
153 ( "Storing values to eventlog path of [%s]\n",
155 regdb_fetch_values(evtlogpath
, values
);
156 if (!regval_ctr_key_exists( values
, "CategoryCount")) {
158 /* hard code some initial values */
160 uiCategoryCount
= 0x00000007;
161 regval_ctr_addvalue( values
, "CategoryCount",
163 ( char * ) &uiCategoryCount
,
165 push_reg_sz(talloc_tos(), &data
,
166 "%SystemRoot%\\system32\\eventlog.dll");
168 regval_ctr_addvalue( values
, "CategoryMessageFile",
170 ( char * ) data
.data
,
172 regdb_store_values( evtlogpath
, values
);
181 /*********************************************************************
182 for an eventlog, add in a source name. If the eventlog doesn't
183 exist (not in the list) do nothing. If a source for the log
184 already exists, change the information (remove, replace)
185 *********************************************************************/
187 bool eventlog_add_source( const char *eventlog
, const char *sourcename
,
188 const char *messagefile
)
190 /* Find all of the eventlogs, add keys for each of them */
191 /* need to add to the value KEY_EVENTLOG/<eventlog>/Sources string (Creating if necessary)
192 need to add KEY of source to KEY_EVENTLOG/<eventlog>/<source> */
194 const char **elogs
= lp_eventlog_list( );
195 const char **wrklist
, **wp
;
196 char *evtlogpath
= NULL
;
197 struct regsubkey_ctr
*subkeys
;
198 struct regval_ctr
*values
;
199 struct regval_blob
*rval
;
204 TALLOC_CTX
*ctx
= talloc_tos();
212 for ( i
= 0; elogs
[i
]; i
++ ) {
213 if ( strequal( elogs
[i
], eventlog
) )
219 ( "Eventlog [%s] not found in list of valid event logs\n",
221 return false; /* invalid named passed in */
224 /* have to assume that the evenlog key itself exists at this point */
225 /* add in a key of [sourcename] under the eventlog key */
227 /* todo add to Sources */
229 if (!( values
= TALLOC_ZERO_P(ctx
, struct regval_ctr
))) {
230 DEBUG( 0, ( "talloc() failure!\n" ));
234 evtlogpath
= talloc_asprintf(ctx
, "%s\\%s", KEY_EVENTLOG
, eventlog
);
240 regdb_fetch_values( evtlogpath
, values
);
243 if ( !( rval
= regval_ctr_getvalue( values
, "Sources" ) ) ) {
244 DEBUG( 0, ( "No Sources value for [%s]!\n", eventlog
) );
247 /* perhaps this adding a new string to a multi_sz should be a fn? */
248 /* check to see if it's there already */
250 if ( rval
->type
!= REG_MULTI_SZ
) {
252 ( "Wrong type for Sources, should be REG_MULTI_SZ\n" ) );
255 /* convert to a 'regulah' chars to do some comparisons */
259 dump_data( 1, rval
->data_p
, rval
->size
);
261 blob
= data_blob_const(rval
->data_p
, rval
->size
);
262 if (!pull_reg_multi_sz(talloc_tos(), &blob
, &wrklist
)) {
266 for (ii
=0; wrklist
[ii
]; ii
++) {
270 if (numsources
> 0) {
271 /* see if it's in there already */
275 if ( strequal( *wp
, sourcename
) ) {
277 ( "Source name [%s] already in list for [%s] \n",
278 sourcename
, eventlog
) );
286 ( "Nothing in the sources list, this might be a problem\n" ) );
292 /* make a new list with an additional entry; copy values, add another */
293 wp
= TALLOC_ARRAY(ctx
, const char *, numsources
+ 2 );
296 DEBUG( 0, ( "talloc() failed \n" ) );
299 memcpy( wp
, wrklist
, sizeof( char * ) * numsources
);
300 *( wp
+ numsources
) = ( char * ) sourcename
;
301 *( wp
+ numsources
+ 1 ) = NULL
;
302 if (!push_reg_multi_sz(ctx
, &blob
, wp
)) {
305 dump_data( 1, blob
.data
, blob
.length
);
306 regval_ctr_addvalue( values
, "Sources", REG_MULTI_SZ
,
307 ( char * ) blob
.data
, blob
.length
);
308 regdb_store_values( evtlogpath
, values
);
309 data_blob_free(&blob
);
312 ( "Source name [%s] found in existing list of sources\n",
316 TALLOC_FREE(wrklist
); /* */
318 werr
= regsubkey_ctr_init(ctx
, &subkeys
);
319 if (!W_ERROR_IS_OK(werr
)) {
320 DEBUG( 0, ( "talloc() failure!\n" ) );
323 TALLOC_FREE(evtlogpath
);
324 evtlogpath
= talloc_asprintf(ctx
, "%s\\%s", KEY_EVENTLOG
, eventlog
);
326 TALLOC_FREE(subkeys
);
330 regdb_fetch_keys( evtlogpath
, subkeys
);
332 if ( !regsubkey_ctr_key_exists( subkeys
, sourcename
) ) {
334 ( " Source name [%s] for eventlog [%s] didn't exist, adding \n",
335 sourcename
, eventlog
) );
336 regsubkey_ctr_addkey( subkeys
, sourcename
);
337 if ( !regdb_store_keys( evtlogpath
, subkeys
) )
340 TALLOC_FREE(subkeys
);
342 /* at this point KEY_EVENTLOG/<eventlog>/<sourcename> key is in there. Now need to add EventMessageFile */
344 /* now allocate room for the source's subkeys */
346 werr
= regsubkey_ctr_init(ctx
, &subkeys
);
347 if (!W_ERROR_IS_OK(werr
)) {
348 DEBUG( 0, ( "talloc() failure!\n" ) );
351 TALLOC_FREE(evtlogpath
);
352 evtlogpath
= talloc_asprintf(ctx
, "%s\\%s\\%s",
353 KEY_EVENTLOG
, eventlog
, sourcename
);
355 TALLOC_FREE(subkeys
);
359 regdb_fetch_keys( evtlogpath
, subkeys
);
361 /* now add the values to the KEY_EVENTLOG/Application form key */
362 if ( !( values
= TALLOC_ZERO_P(ctx
, struct regval_ctr
) ) ) {
363 DEBUG( 0, ( "talloc() failure!\n" ) );
367 ( "Storing EventMessageFile [%s] to eventlog path of [%s]\n",
368 messagefile
, evtlogpath
) );
370 regdb_fetch_values( evtlogpath
, values
);
372 regval_ctr_addvalue_sz(values
, "EventMessageFile", messagefile
);
373 regdb_store_values( evtlogpath
, values
);