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 struct regsubkey_ctr *subkeys;
39 struct regval_ctr *values;
42 uint32 uiCategoryCount;
44 TALLOC_CTX *ctx = talloc_tos();
47 while (elogs && *elogs) {
48 werr = regsubkey_ctr_init(ctx, &subkeys);
49 if (!W_ERROR_IS_OK(werr)) {
50 DEBUG( 0, ( "talloc() failure!\n" ) );
53 regdb_fetch_keys(KEY_EVENTLOG, subkeys);
54 regsubkey_ctr_addkey( subkeys, *elogs );
55 if ( !regdb_store_keys( KEY_EVENTLOG, subkeys ) ) {
61 /* add in the key of form KEY_EVENTLOG/Application */
63 ( "Adding key of [%s] to path of [%s]\n", *elogs,
66 evtlogpath = talloc_asprintf(ctx, "%s\\%s",
67 KEY_EVENTLOG, *elogs);
71 /* add in the key of form KEY_EVENTLOG/Application/Application */
73 ( "Adding key of [%s] to path of [%s]\n", *elogs,
75 werr = regsubkey_ctr_init(ctx, &subkeys);
76 if (!W_ERROR_IS_OK(werr)) {
77 DEBUG( 0, ( "talloc() failure!\n" ) );
80 regdb_fetch_keys( evtlogpath, subkeys );
81 regsubkey_ctr_addkey( subkeys, *elogs );
83 if ( !regdb_store_keys( evtlogpath, subkeys ) ) {
87 TALLOC_FREE( subkeys );
89 /* now add the values to the KEY_EVENTLOG/Application form key */
90 if (!(values = TALLOC_ZERO_P(ctx, struct regval_ctr))) {
91 DEBUG( 0, ( "talloc() failure!\n" ) );
95 ( "Storing values to eventlog path of [%s]\n",
97 regdb_fetch_values( evtlogpath, values );
100 if (!regval_ctr_key_exists(values, "MaxSize")) {
102 /* assume we have none, add them all */
104 /* hard code some initial values */
106 /* uiDisplayNameId = 0x00000100; */
107 uiMaxSize = 0x00080000;
108 uiRetention = 0x93A80;
110 regval_ctr_addvalue(values, "MaxSize", REG_DWORD,
114 regval_ctr_addvalue(values, "Retention", REG_DWORD,
115 (char *)&uiRetention,
118 regval_ctr_addvalue_sz(values, "PrimaryModule", *elogs);
119 push_reg_sz(talloc_tos(), &data, *elogs);
121 regval_ctr_addvalue(values, "Sources", REG_MULTI_SZ,
125 evtfilepath = talloc_asprintf(ctx,
126 "%%SystemRoot%%\\system32\\config\\%s.tdb",
131 push_reg_sz(talloc_tos(), &data, evtfilepath);
132 regval_ctr_addvalue(values, "File", REG_EXPAND_SZ, (char *)data.data,
134 regdb_store_values(evtlogpath, values);
140 /* now do the values under KEY_EVENTLOG/Application/Application */
141 TALLOC_FREE(evtlogpath);
142 evtlogpath = talloc_asprintf(ctx, "%s\\%s\\%s",
143 KEY_EVENTLOG, *elogs, *elogs);
147 if (!(values = TALLOC_ZERO_P(ctx, struct regval_ctr))) {
148 DEBUG( 0, ( "talloc() failure!\n" ) );
152 ( "Storing values to eventlog path of [%s]\n",
154 regdb_fetch_values(evtlogpath, values);
155 if (!regval_ctr_key_exists( values, "CategoryCount")) {
157 /* hard code some initial values */
159 uiCategoryCount = 0x00000007;
160 regval_ctr_addvalue( values, "CategoryCount",
162 ( char * ) &uiCategoryCount,
164 push_reg_sz(talloc_tos(), &data,
165 "%SystemRoot%\\system32\\eventlog.dll");
167 regval_ctr_addvalue( values, "CategoryMessageFile",
169 ( char * ) data.data,
171 regdb_store_values( evtlogpath, values );
180 /*********************************************************************
181 for an eventlog, add in a source name. If the eventlog doesn't
182 exist (not in the list) do nothing. If a source for the log
183 already exists, change the information (remove, replace)
184 *********************************************************************/
186 bool eventlog_add_source( const char *eventlog, const char *sourcename,
187 const char *messagefile )
189 /* Find all of the eventlogs, add keys for each of them */
190 /* need to add to the value KEY_EVENTLOG/<eventlog>/Sources string (Creating if necessary)
191 need to add KEY of source to KEY_EVENTLOG/<eventlog>/<source> */
193 const char **elogs = lp_eventlog_list( );
194 const char **wrklist, **wp;
195 char *evtlogpath = NULL;
196 struct regsubkey_ctr *subkeys;
197 struct regval_ctr *values;
198 struct regval_blob *rval;
203 TALLOC_CTX *ctx = talloc_tos();
210 for ( i = 0; elogs[i]; i++ ) {
211 if ( strequal( elogs[i], eventlog ) )
217 ( "Eventlog [%s] not found in list of valid event logs\n",
219 return false; /* invalid named passed in */
222 /* have to assume that the evenlog key itself exists at this point */
223 /* add in a key of [sourcename] under the eventlog key */
225 /* todo add to Sources */
227 if (!( values = TALLOC_ZERO_P(ctx, struct regval_ctr))) {
228 DEBUG( 0, ( "talloc() failure!\n" ));
232 evtlogpath = talloc_asprintf(ctx, "%s\\%s", KEY_EVENTLOG, eventlog);
238 regdb_fetch_values( evtlogpath, values );
241 if ( !( rval = regval_ctr_getvalue( values, "Sources" ) ) ) {
242 DEBUG( 0, ( "No Sources value for [%s]!\n", eventlog ) );
245 /* perhaps this adding a new string to a multi_sz should be a fn? */
246 /* check to see if it's there already */
248 if ( rval->type != REG_MULTI_SZ ) {
250 ( "Wrong type for Sources, should be REG_MULTI_SZ\n" ) );
253 /* convert to a 'regulah' chars to do some comparisons */
257 dump_data( 1, rval->data_p, rval->size );
259 regval_convert_multi_sz( ( uint16 * ) rval->data_p, rval->size,
263 /* see if it's in there already */
266 while ( ii && wp && *wp ) {
267 if ( strequal( *wp, sourcename ) ) {
269 ( "Source name [%s] already in list for [%s] \n",
270 sourcename, eventlog ) );
278 if ( numsources < 0 ) {
279 DEBUG( 3, ( "problem in getting the sources\n" ) );
283 ( "Nothing in the sources list, this might be a problem\n" ) );
290 /* make a new list with an additional entry; copy values, add another */
291 wp = TALLOC_ARRAY(ctx, const char *, numsources + 2 );
294 DEBUG( 0, ( "talloc() failed \n" ) );
297 memcpy( wp, wrklist, sizeof( char * ) * numsources );
298 *( wp + numsources ) = ( char * ) sourcename;
299 *( wp + numsources + 1 ) = NULL;
300 if (!push_reg_multi_sz(ctx, &blob, wp)) {
303 dump_data( 1, blob.data, blob.length);
304 regval_ctr_addvalue( values, "Sources", REG_MULTI_SZ,
305 ( char * ) blob.data, blob.length);
306 regdb_store_values( evtlogpath, values );
307 data_blob_free(&blob);
310 ( "Source name [%s] found in existing list of sources\n",
314 TALLOC_FREE(wrklist); /* */
316 werr = regsubkey_ctr_init(ctx, &subkeys);
317 if (!W_ERROR_IS_OK(werr)) {
318 DEBUG( 0, ( "talloc() failure!\n" ) );
321 TALLOC_FREE(evtlogpath);
322 evtlogpath = talloc_asprintf(ctx, "%s\\%s", KEY_EVENTLOG, eventlog );
324 TALLOC_FREE(subkeys);
328 regdb_fetch_keys( evtlogpath, subkeys );
330 if ( !regsubkey_ctr_key_exists( subkeys, sourcename ) ) {
332 ( " Source name [%s] for eventlog [%s] didn't exist, adding \n",
333 sourcename, eventlog ) );
334 regsubkey_ctr_addkey( subkeys, sourcename );
335 if ( !regdb_store_keys( evtlogpath, subkeys ) )
338 TALLOC_FREE(subkeys);
340 /* at this point KEY_EVENTLOG/<eventlog>/<sourcename> key is in there. Now need to add EventMessageFile */
342 /* now allocate room for the source's subkeys */
344 werr = regsubkey_ctr_init(ctx, &subkeys);
345 if (!W_ERROR_IS_OK(werr)) {
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, struct 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 regval_ctr_addvalue_sz(values, "EventMessageFile", messagefile);
371 regdb_store_values( evtlogpath, values );