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/>.
25 #include "reg_backend_db.h"
28 #define DBGC_CLASS DBGC_REGISTRY
30 /**********************************************************************
31 for an eventlog, add in the default values
32 *********************************************************************/
34 bool eventlog_init_keys(void)
36 /* Find all of the eventlogs, add keys for each of them */
37 const char **elogs = lp_eventlog_list();
38 char *evtlogpath = NULL;
39 char *evtfilepath = NULL;
40 struct regsubkey_ctr *subkeys;
41 struct regval_ctr *values;
44 uint32 uiCategoryCount;
46 TALLOC_CTX *ctx = talloc_tos();
49 while (elogs && *elogs) {
50 werr = regsubkey_ctr_init(ctx, &subkeys);
51 if (!W_ERROR_IS_OK(werr)) {
52 DEBUG( 0, ( "talloc() failure!\n" ) );
55 regdb_fetch_keys(KEY_EVENTLOG, subkeys);
56 regsubkey_ctr_addkey( subkeys, *elogs );
57 if ( !regdb_store_keys( KEY_EVENTLOG, subkeys ) ) {
63 /* add in the key of form KEY_EVENTLOG/Application */
65 ( "Adding key of [%s] to path of [%s]\n", *elogs,
68 evtlogpath = talloc_asprintf(ctx, "%s\\%s",
69 KEY_EVENTLOG, *elogs);
73 /* add in the key of form KEY_EVENTLOG/Application/Application */
75 ( "Adding key of [%s] to path of [%s]\n", *elogs,
77 werr = regsubkey_ctr_init(ctx, &subkeys);
78 if (!W_ERROR_IS_OK(werr)) {
79 DEBUG( 0, ( "talloc() failure!\n" ) );
82 regdb_fetch_keys( evtlogpath, subkeys );
83 regsubkey_ctr_addkey( subkeys, *elogs );
85 if ( !regdb_store_keys( evtlogpath, subkeys ) ) {
89 TALLOC_FREE( subkeys );
91 /* now add the values to the KEY_EVENTLOG/Application form key */
92 if (!(values = TALLOC_ZERO_P(ctx, struct regval_ctr))) {
93 DEBUG( 0, ( "talloc() failure!\n" ) );
97 ( "Storing values to eventlog path of [%s]\n",
99 regdb_fetch_values( evtlogpath, values );
102 if (!regval_ctr_key_exists(values, "MaxSize")) {
104 /* assume we have none, add them all */
106 /* hard code some initial values */
108 /* uiDisplayNameId = 0x00000100; */
109 uiMaxSize = 0x00080000;
110 uiRetention = 0x93A80;
112 regval_ctr_addvalue(values, "MaxSize", REG_DWORD,
116 regval_ctr_addvalue(values, "Retention", REG_DWORD,
117 (uint8 *)&uiRetention,
120 regval_ctr_addvalue_sz(values, "PrimaryModule", *elogs);
121 push_reg_sz(talloc_tos(), &data, *elogs);
123 regval_ctr_addvalue(values, "Sources", REG_MULTI_SZ,
127 evtfilepath = talloc_asprintf(ctx,
128 "%%SystemRoot%%\\system32\\config\\%s.tdb",
133 push_reg_sz(talloc_tos(), &data, evtfilepath);
134 regval_ctr_addvalue(values, "File", REG_EXPAND_SZ, data.data,
136 regdb_store_values(evtlogpath, values);
142 /* now do the values under KEY_EVENTLOG/Application/Application */
143 TALLOC_FREE(evtlogpath);
144 evtlogpath = talloc_asprintf(ctx, "%s\\%s\\%s",
145 KEY_EVENTLOG, *elogs, *elogs);
149 if (!(values = TALLOC_ZERO_P(ctx, struct regval_ctr))) {
150 DEBUG( 0, ( "talloc() failure!\n" ) );
154 ( "Storing values to eventlog path of [%s]\n",
156 regdb_fetch_values(evtlogpath, values);
157 if (!regval_ctr_key_exists( values, "CategoryCount")) {
159 /* hard code some initial values */
161 uiCategoryCount = 0x00000007;
162 regval_ctr_addvalue( values, "CategoryCount",
164 (uint8 *) &uiCategoryCount,
166 push_reg_sz(talloc_tos(), &data,
167 "%SystemRoot%\\system32\\eventlog.dll");
169 regval_ctr_addvalue( values, "CategoryMessageFile",
173 regdb_store_values( evtlogpath, values );
182 /*********************************************************************
183 for an eventlog, add in a source name. If the eventlog doesn't
184 exist (not in the list) do nothing. If a source for the log
185 already exists, change the information (remove, replace)
186 *********************************************************************/
188 bool eventlog_add_source( const char *eventlog, const char *sourcename,
189 const char *messagefile )
191 /* Find all of the eventlogs, add keys for each of them */
192 /* need to add to the value KEY_EVENTLOG/<eventlog>/Sources string (Creating if necessary)
193 need to add KEY of source to KEY_EVENTLOG/<eventlog>/<source> */
195 const char **elogs = lp_eventlog_list( );
196 const char **wrklist, **wp;
197 char *evtlogpath = NULL;
198 struct regsubkey_ctr *subkeys;
199 struct regval_ctr *values;
200 struct regval_blob *rval;
205 TALLOC_CTX *ctx = talloc_tos();
213 for ( i = 0; elogs[i]; i++ ) {
214 if ( strequal( elogs[i], eventlog ) )
220 ( "Eventlog [%s] not found in list of valid event logs\n",
222 return false; /* invalid named passed in */
225 /* have to assume that the evenlog key itself exists at this point */
226 /* add in a key of [sourcename] under the eventlog key */
228 /* todo add to Sources */
230 if (!( values = TALLOC_ZERO_P(ctx, struct regval_ctr))) {
231 DEBUG( 0, ( "talloc() failure!\n" ));
235 evtlogpath = talloc_asprintf(ctx, "%s\\%s", KEY_EVENTLOG, eventlog);
241 regdb_fetch_values( evtlogpath, values );
244 if ( !( rval = regval_ctr_getvalue( values, "Sources" ) ) ) {
245 DEBUG( 0, ( "No Sources value for [%s]!\n", eventlog ) );
248 /* perhaps this adding a new string to a multi_sz should be a fn? */
249 /* check to see if it's there already */
251 if ( rval->type != REG_MULTI_SZ ) {
253 ( "Wrong type for Sources, should be REG_MULTI_SZ\n" ) );
256 /* convert to a 'regulah' chars to do some comparisons */
260 dump_data( 1, rval->data_p, rval->size );
262 blob = data_blob_const(rval->data_p, rval->size);
263 if (!pull_reg_multi_sz(talloc_tos(), &blob, &wrklist)) {
267 for (ii=0; wrklist[ii]; ii++) {
271 if (numsources > 0) {
272 /* see if it's in there already */
276 if ( strequal( *wp, sourcename ) ) {
278 ( "Source name [%s] already in list for [%s] \n",
279 sourcename, eventlog ) );
287 ( "Nothing in the sources list, this might be a problem\n" ) );
293 /* make a new list with an additional entry; copy values, add another */
294 wp = TALLOC_ARRAY(ctx, const char *, numsources + 2 );
297 DEBUG( 0, ( "talloc() failed \n" ) );
300 memcpy( wp, wrklist, sizeof( char * ) * numsources );
301 *( wp + numsources ) = ( char * ) sourcename;
302 *( wp + numsources + 1 ) = NULL;
303 if (!push_reg_multi_sz(ctx, &blob, wp)) {
306 dump_data( 1, blob.data, blob.length);
307 regval_ctr_addvalue( values, "Sources", REG_MULTI_SZ,
308 blob.data, blob.length);
309 regdb_store_values( evtlogpath, values );
310 data_blob_free(&blob);
313 ( "Source name [%s] found in existing list of sources\n",
317 TALLOC_FREE(wrklist); /* */
319 werr = regsubkey_ctr_init(ctx, &subkeys);
320 if (!W_ERROR_IS_OK(werr)) {
321 DEBUG( 0, ( "talloc() failure!\n" ) );
324 TALLOC_FREE(evtlogpath);
325 evtlogpath = talloc_asprintf(ctx, "%s\\%s", KEY_EVENTLOG, eventlog );
327 TALLOC_FREE(subkeys);
331 regdb_fetch_keys( evtlogpath, subkeys );
333 if ( !regsubkey_ctr_key_exists( subkeys, sourcename ) ) {
335 ( " Source name [%s] for eventlog [%s] didn't exist, adding \n",
336 sourcename, eventlog ) );
337 regsubkey_ctr_addkey( subkeys, sourcename );
338 if ( !regdb_store_keys( evtlogpath, subkeys ) )
341 TALLOC_FREE(subkeys);
343 /* at this point KEY_EVENTLOG/<eventlog>/<sourcename> key is in there. Now need to add EventMessageFile */
345 /* now allocate room for the source's subkeys */
347 werr = regsubkey_ctr_init(ctx, &subkeys);
348 if (!W_ERROR_IS_OK(werr)) {
349 DEBUG( 0, ( "talloc() failure!\n" ) );
352 TALLOC_FREE(evtlogpath);
353 evtlogpath = talloc_asprintf(ctx, "%s\\%s\\%s",
354 KEY_EVENTLOG, eventlog, sourcename);
356 TALLOC_FREE(subkeys);
360 regdb_fetch_keys( evtlogpath, subkeys );
362 /* now add the values to the KEY_EVENTLOG/Application form key */
363 if ( !( values = TALLOC_ZERO_P(ctx, struct regval_ctr ) ) ) {
364 DEBUG( 0, ( "talloc() failure!\n" ) );
368 ( "Storing EventMessageFile [%s] to eventlog path of [%s]\n",
369 messagefile, evtlogpath ) );
371 regdb_fetch_values( evtlogpath, values );
373 regval_ctr_addvalue_sz(values, "EventMessageFile", messagefile);
374 regdb_store_values( evtlogpath, values );