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"
26 #include "reg_eventlog.h"
27 #include "reg_objects.h"
30 #define DBGC_CLASS DBGC_REGISTRY
32 /**********************************************************************
33 for an eventlog, add in the default values
34 *********************************************************************/
36 bool eventlog_init_keys(void)
38 /* Find all of the eventlogs, add keys for each of them */
39 const char **elogs = lp_eventlog_list();
40 char *evtlogpath = NULL;
41 char *evtfilepath = NULL;
42 struct regsubkey_ctr *subkeys;
43 struct regval_ctr *values;
46 uint32 uiCategoryCount;
48 TALLOC_CTX *ctx = talloc_tos();
51 while (elogs && *elogs) {
52 werr = regsubkey_ctr_init(ctx, &subkeys);
53 if (!W_ERROR_IS_OK(werr)) {
54 DEBUG( 0, ( "talloc() failure!\n" ) );
57 regdb_fetch_keys(KEY_EVENTLOG, subkeys);
58 regsubkey_ctr_addkey( subkeys, *elogs );
59 if ( !regdb_store_keys( KEY_EVENTLOG, subkeys ) ) {
65 /* add in the key of form KEY_EVENTLOG/Application */
67 ( "Adding key of [%s] to path of [%s]\n", *elogs,
70 evtlogpath = talloc_asprintf(ctx, "%s\\%s",
71 KEY_EVENTLOG, *elogs);
75 /* add in the key of form KEY_EVENTLOG/Application/Application */
77 ( "Adding key of [%s] to path of [%s]\n", *elogs,
79 werr = regsubkey_ctr_init(ctx, &subkeys);
80 if (!W_ERROR_IS_OK(werr)) {
81 DEBUG( 0, ( "talloc() failure!\n" ) );
84 regdb_fetch_keys( evtlogpath, subkeys );
85 regsubkey_ctr_addkey( subkeys, *elogs );
87 if ( !regdb_store_keys( evtlogpath, subkeys ) ) {
91 TALLOC_FREE( subkeys );
93 /* now add the values to the KEY_EVENTLOG/Application form key */
95 werr = regval_ctr_init(ctx, &values);
96 if (!W_ERROR_IS_OK(werr)) {
97 DEBUG( 0, ( "talloc() failure!\n" ) );
101 ( "Storing values to eventlog path of [%s]\n",
103 regdb_fetch_values( evtlogpath, values );
106 if (!regval_ctr_key_exists(values, "MaxSize")) {
108 /* assume we have none, add them all */
110 /* hard code some initial values */
112 /* uiDisplayNameId = 0x00000100; */
113 uiMaxSize = 0x00080000;
114 uiRetention = 0x93A80;
116 regval_ctr_addvalue(values, "MaxSize", REG_DWORD,
120 regval_ctr_addvalue(values, "Retention", REG_DWORD,
121 (uint8 *)&uiRetention,
124 regval_ctr_addvalue_sz(values, "PrimaryModule", *elogs);
125 push_reg_sz(talloc_tos(), &data, *elogs);
127 regval_ctr_addvalue(values, "Sources", REG_MULTI_SZ,
131 evtfilepath = talloc_asprintf(ctx,
132 "%%SystemRoot%%\\system32\\config\\%s.tdb",
137 push_reg_sz(talloc_tos(), &data, evtfilepath);
138 regval_ctr_addvalue(values, "File", REG_EXPAND_SZ, data.data,
140 regdb_store_values(evtlogpath, values);
146 /* now do the values under KEY_EVENTLOG/Application/Application */
147 TALLOC_FREE(evtlogpath);
148 evtlogpath = talloc_asprintf(ctx, "%s\\%s\\%s",
149 KEY_EVENTLOG, *elogs, *elogs);
154 werr = regval_ctr_init(ctx, &values);
155 if (!W_ERROR_IS_OK(werr)) {
156 DEBUG( 0, ( "talloc() failure!\n" ) );
160 ( "Storing values to eventlog path of [%s]\n",
162 regdb_fetch_values(evtlogpath, values);
163 if (!regval_ctr_key_exists( values, "CategoryCount")) {
165 /* hard code some initial values */
167 uiCategoryCount = 0x00000007;
168 regval_ctr_addvalue( values, "CategoryCount",
170 (uint8 *) &uiCategoryCount,
172 push_reg_sz(talloc_tos(), &data,
173 "%SystemRoot%\\system32\\eventlog.dll");
175 regval_ctr_addvalue( values, "CategoryMessageFile",
179 regdb_store_values( evtlogpath, values );
188 /*********************************************************************
189 for an eventlog, add in a source name. If the eventlog doesn't
190 exist (not in the list) do nothing. If a source for the log
191 already exists, change the information (remove, replace)
192 *********************************************************************/
194 bool eventlog_add_source( const char *eventlog, const char *sourcename,
195 const char *messagefile )
197 /* Find all of the eventlogs, add keys for each of them */
198 /* need to add to the value KEY_EVENTLOG/<eventlog>/Sources string (Creating if necessary)
199 need to add KEY of source to KEY_EVENTLOG/<eventlog>/<source> */
201 const char **elogs = lp_eventlog_list( );
202 const char **wrklist, **wp;
203 char *evtlogpath = NULL;
204 struct regsubkey_ctr *subkeys;
205 struct regval_ctr *values;
206 struct regval_blob *rval;
211 TALLOC_CTX *ctx = talloc_tos();
219 for ( i = 0; elogs[i]; i++ ) {
220 if ( strequal( elogs[i], eventlog ) )
226 ( "Eventlog [%s] not found in list of valid event logs\n",
228 return false; /* invalid named passed in */
231 /* have to assume that the evenlog key itself exists at this point */
232 /* add in a key of [sourcename] under the eventlog key */
234 /* todo add to Sources */
236 werr = regval_ctr_init(ctx, &values);
237 if(!W_ERROR_IS_OK(werr)) {
238 DEBUG( 0, ( "talloc() failure!\n" ));
242 evtlogpath = talloc_asprintf(ctx, "%s\\%s", KEY_EVENTLOG, eventlog);
248 regdb_fetch_values( evtlogpath, values );
251 if ( !( rval = regval_ctr_getvalue( values, "Sources" ) ) ) {
252 DEBUG( 0, ( "No Sources value for [%s]!\n", eventlog ) );
255 /* perhaps this adding a new string to a multi_sz should be a fn? */
256 /* check to see if it's there already */
258 if ( regval_type(rval) != REG_MULTI_SZ ) {
260 ( "Wrong type for Sources, should be REG_MULTI_SZ\n" ) );
263 /* convert to a 'regulah' chars to do some comparisons */
267 dump_data(1, regval_data_p(rval), regval_size(rval));
269 blob = data_blob_const(regval_data_p(rval), regval_size(rval));
270 if (!pull_reg_multi_sz(talloc_tos(), &blob, &wrklist)) {
274 for (ii=0; wrklist[ii]; ii++) {
278 if (numsources > 0) {
279 /* see if it's in there already */
283 if ( strequal( *wp, sourcename ) ) {
285 ( "Source name [%s] already in list for [%s] \n",
286 sourcename, eventlog ) );
294 ( "Nothing in the sources list, this might be a problem\n" ) );
300 /* make a new list with an additional entry; copy values, add another */
301 wp = TALLOC_ARRAY(ctx, const char *, numsources + 2 );
304 DEBUG( 0, ( "talloc() failed \n" ) );
307 memcpy( wp, wrklist, sizeof( char * ) * numsources );
308 *( wp + numsources ) = ( char * ) sourcename;
309 *( wp + numsources + 1 ) = NULL;
310 if (!push_reg_multi_sz(ctx, &blob, wp)) {
313 dump_data( 1, blob.data, blob.length);
314 regval_ctr_addvalue( values, "Sources", REG_MULTI_SZ,
315 blob.data, blob.length);
316 regdb_store_values( evtlogpath, values );
317 data_blob_free(&blob);
320 ( "Source name [%s] found in existing list of sources\n",
324 TALLOC_FREE(wrklist); /* */
326 werr = regsubkey_ctr_init(ctx, &subkeys);
327 if (!W_ERROR_IS_OK(werr)) {
328 DEBUG( 0, ( "talloc() failure!\n" ) );
331 TALLOC_FREE(evtlogpath);
332 evtlogpath = talloc_asprintf(ctx, "%s\\%s", KEY_EVENTLOG, eventlog );
334 TALLOC_FREE(subkeys);
338 regdb_fetch_keys( evtlogpath, subkeys );
340 if ( !regsubkey_ctr_key_exists( subkeys, sourcename ) ) {
342 ( " Source name [%s] for eventlog [%s] didn't exist, adding \n",
343 sourcename, eventlog ) );
344 regsubkey_ctr_addkey( subkeys, sourcename );
345 if ( !regdb_store_keys( evtlogpath, subkeys ) )
348 TALLOC_FREE(subkeys);
350 /* at this point KEY_EVENTLOG/<eventlog>/<sourcename> key is in there. Now need to add EventMessageFile */
352 /* now allocate room for the source's subkeys */
354 werr = regsubkey_ctr_init(ctx, &subkeys);
355 if (!W_ERROR_IS_OK(werr)) {
356 DEBUG( 0, ( "talloc() failure!\n" ) );
359 TALLOC_FREE(evtlogpath);
360 evtlogpath = talloc_asprintf(ctx, "%s\\%s\\%s",
361 KEY_EVENTLOG, eventlog, sourcename);
363 TALLOC_FREE(subkeys);
367 regdb_fetch_keys( evtlogpath, subkeys );
369 /* now add the values to the KEY_EVENTLOG/Application form key */
370 werr = regval_ctr_init(ctx, &values);
371 if (!W_ERROR_IS_OK(werr)) {
372 DEBUG( 0, ( "talloc() failure!\n" ) );
376 ( "Storing EventMessageFile [%s] to eventlog path of [%s]\n",
377 messagefile, evtlogpath ) );
379 regdb_fetch_values( evtlogpath, values );
381 regval_ctr_addvalue_sz(values, "EventMessageFile", messagefile);
382 regdb_store_values( evtlogpath, values );