diff options
Diffstat (limited to 'source3/registry/reg_eventlog.c')
-rw-r--r-- | source3/registry/reg_eventlog.c | 273 |
1 files changed, 119 insertions, 154 deletions
diff --git a/source3/registry/reg_eventlog.c b/source3/registry/reg_eventlog.c index bed9e1d59a..204c4c6e1c 100644 --- a/source3/registry/reg_eventlog.c +++ b/source3/registry/reg_eventlog.c @@ -2,6 +2,7 @@ * Unix SMB/CIFS implementation. * Virtual Windows Registry Layer * Copyright (C) Marcin Krzysztof Porwit 2005, + * Copyright (C) Brian Moran 2005. * Copyright (C) Gerald (Jerry) Carter 2005. * * This program is free software; you can redistribute it and/or modify @@ -18,171 +19,135 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - + #include "includes.h" /********************************************************************** - Enumerate registry subkey names given a registry path. + for an eventlog, add in the default values *********************************************************************/ -static int elog_fetch_keys( const char *key, REGSUBKEY_CTR *subkeys ) +BOOL eventlog_init_keys( void ) { - const char **elogs = lp_eventlog_list(); - char *path; - int i; - - path = reg_remaining_path( key + strlen(KEY_EVENTLOG) ); - - DEBUG(10,("elog_fetch_keys: entire key => [%s], subkey => [%s]\n", - key, path)); - - if ( !path ) { - - if ( !elogs || !*elogs ) - return 0; - - DEBUG(10,("elog_fetch_keys: Adding eventlog subkeys from smb.conf\n")); - - for ( i=0; elogs[i]; i++ ) - regsubkey_ctr_addkey( subkeys, elogs[i] ); - - return regsubkey_ctr_numkeys( subkeys ); - } - - /* if we get <logname>/<logname> then we don't add anymore */ - - if ( strchr( path, '\\' ) ) { - DEBUG(10,("elog_fetch_keys: Not adding subkey to %s\n",path)); - return 0; - } - - /* add in a subkey with the same name as the eventlog... */ - - DEBUG(10,("elog_fetch_keys: Looking to add eventlog subkey to %s\n",path)); - - /* look for a match */ - - if ( !elogs ) - return -1; - - for ( i=0; elogs[i]; i++ ) { - /* just verify that the keyname is a valid log name */ - if ( strequal( path, elogs[i] ) ) - return 0; - } - - return -1; -} - -/********************************************************************** - Enumerate registry values given a registry path. - Caller is responsible for freeing memory -*********************************************************************/ - -static int elog_fetch_values( const char *key, REGVAL_CTR *values ) -{ - char *path; - uint32 uiDisplayNameId, uiMaxSize, uiRetention; - char *base, *new_path; + /* Find all of the eventlogs, add keys for each of them */ + const char **elogs = lp_eventlog_list( ); + pstring evtlogpath; + REGSUBKEY_CTR *subkeys; + REGVAL_CTR *values; + uint32 uiDisplayNameId; + uint32 uiMaxSize; + uint32 uiRetention; + uint32 uiCategoryCount; UNISTR2 data; - - DEBUG(10,("elog_fetch_values: key=>[%s]\n", key)); - - path = reg_remaining_path( key + strlen(KEY_EVENTLOG) ); - - /* check to see if we are dealing with the top level key */ - - if ( !path ) - return regdb_fetch_values( KEY_EVENTLOG, values ); - - /* deal with a log name */ - - reg_split_path( path, &base, &new_path ); - - /* MaxSize is limited to 0xFFFF0000 (UINT_MAX - USHRT_MAX) as per MSDN documentation */ - - - if ( !new_path ) { - - /* try to fetch from the registry */ - - regdb_fetch_values( key, values ); - - /* just verify one of the important keys. If this - fails, then assume the values have not been initialized */ - - if ( regval_ctr_getvalue( values, "Retention" ) ) - return regval_ctr_numvals( values ); - - /* hard code some initial values */ - - uiDisplayNameId = 0x00000100; - uiMaxSize = 0x00080000; - uiRetention = 0x93A80; - - regval_ctr_addvalue( values, "MaxSize", REG_DWORD, (char*)&uiMaxSize, sizeof(uint32)); - regval_ctr_addvalue( values, "Retention", REG_DWORD, (char *)&uiRetention, sizeof(uint32)); - - init_unistr2( &data, base, UNI_STR_TERMINATE); - regval_ctr_addvalue( values, "PrimaryModule", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) ); - - init_unistr2( &data, base, UNI_STR_TERMINATE); - regval_ctr_addvalue( values, "Sources", REG_MULTI_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) ); - - /* store them for later updates. Complain if this fails but continue on */ - - if ( !regdb_store_values( key, values ) ) { - DEBUG(0,("elog_fetch_values: Failed to store initial values for log [%s]\n", - base )); + + while ( elogs && *elogs ) { + if ( !( subkeys = TALLOC_ZERO_P( NULL, REGSUBKEY_CTR ) ) ) { + DEBUG( 0, ( "talloc() failure!\n" ) ); + return False; } - - return regval_ctr_numvals( values ); - } - -#if 0 - /* hmmm....what to do here? A subkey underneath the log name ? */ - - uiDisplayNameId = 0x07; - regval_ctr_addvalue( values, "CategoryCount", REG_DWORD, (char*)&uiDisplayNameId, sizeof(uint32) ); - - init_unistr2( &data, "%SystemRoot%\\system32\\eventlog.dll", UNI_STR_TERMINATE); - regval_ctr_addvalue( values, "CategoryMessageFile", REG_EXPAND_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) ); -#endif - - return regval_ctr_numvals( values ); -} + regdb_fetch_keys( KEY_EVENTLOG, subkeys ); + regsubkey_ctr_addkey( subkeys, *elogs ); + if ( !regdb_store_keys( KEY_EVENTLOG, subkeys ) ) + return False; + TALLOC_FREE( subkeys ); + + /* add in the key of form KEY_EVENTLOG/Application */ + DEBUG( 5, + ( "Adding key of [%s] to path of [%s]\n", *elogs, + KEY_EVENTLOG ) ); + + slprintf( evtlogpath, sizeof( evtlogpath ) - 1, "%s\\%s", + KEY_EVENTLOG, *elogs ); + /* add in the key of form KEY_EVENTLOG/Application/Application */ + DEBUG( 5, + ( "Adding key of [%s] to path of [%s]\n", *elogs, + evtlogpath ) ); + if ( !( subkeys = TALLOC_ZERO_P( NULL, REGSUBKEY_CTR ) ) ) { + DEBUG( 0, ( "talloc() failure!\n" ) ); + return False; + } + regdb_fetch_keys( evtlogpath, subkeys ); + regsubkey_ctr_addkey( subkeys, *elogs ); -/********************************************************************** -*********************************************************************/ + if ( !regdb_store_keys( evtlogpath, subkeys ) ) + return False; + TALLOC_FREE( subkeys ); -static BOOL elog_store_keys( const char *key, REGSUBKEY_CTR *subkeys ) -{ - /* cannot create any subkeys here */ - - return False; -} + /* now add the values to the KEY_EVENTLOG/Application form key */ + if ( !( values = TALLOC_ZERO_P( NULL, REGVAL_CTR ) ) ) { + DEBUG( 0, ( "talloc() failure!\n" ) ); + return False; + } + DEBUG( 5, + ( "Storing values to eventlog path of [%s]\n", + evtlogpath ) ); + regdb_fetch_values( evtlogpath, values ); + + if ( !regval_ctr_key_exists( values, "MaxSize" ) ) { + /* assume we have none, add them all */ + + /* hard code some initial values */ + + uiDisplayNameId = 0x00000100; + uiMaxSize = 0x00080000; + uiRetention = 0x93A80; + + regval_ctr_addvalue( values, "MaxSize", REG_DWORD, + ( char * ) &uiMaxSize, + sizeof( uint32 ) ); + regval_ctr_addvalue( values, "Retention", REG_DWORD, + ( char * ) &uiRetention, + sizeof( uint32 ) ); + init_unistr2( &data, *elogs, UNI_STR_TERMINATE ); + regval_ctr_addvalue( values, "PrimaryModule", REG_SZ, + ( char * ) data.buffer, + data.uni_str_len * + sizeof( uint16 ) ); + init_unistr2( &data, *elogs, UNI_STR_TERMINATE ); + + regval_ctr_addvalue( values, "Sources", REG_MULTI_SZ, + ( char * ) data.buffer, + data.uni_str_len * + sizeof( uint16 ) ); + regdb_store_values( evtlogpath, values ); -/********************************************************************** - Allow storing of particular values related to eventlog operation. -*********************************************************************/ + } -static BOOL elog_store_value( const char *key, REGVAL_CTR *values ) -{ - /* the client had to have a valid handle to get here - so just hand off to the registry tdb */ - - return regdb_store_values( key, values ); -} + TALLOC_FREE( values ); -/******************************************************************** - Table of function pointers for accessing eventlog data - *******************************************************************/ - -REGISTRY_OPS eventlog_ops = { - elog_fetch_keys, - elog_fetch_values, - elog_store_keys, - elog_store_value, - NULL -}; + /* now do the values under KEY_EVENTLOG/Application/Application */ + slprintf( evtlogpath, sizeof( evtlogpath ) - 1, "%s\\%s\\%s", + KEY_EVENTLOG, *elogs, *elogs ); + if ( !( values = TALLOC_ZERO_P( NULL, REGVAL_CTR ) ) ) { + DEBUG( 0, ( "talloc() failure!\n" ) ); + return False; + } + DEBUG( 5, + ( "Storing values to eventlog path of [%s]\n", + evtlogpath ) ); + regdb_fetch_values( evtlogpath, values ); + if ( !regval_ctr_key_exists( values, "CategoryCount" ) ) { + + /* hard code some initial values */ + + uiCategoryCount = 0x00000007; + regval_ctr_addvalue( values, "CategoryCount", + REG_DWORD, + ( char * ) &uiCategoryCount, + sizeof( uint32 ) ); + init_unistr2( &data, + "%SystemRoot%\\system32\\eventlog.dll", + UNI_STR_TERMINATE ); + + regval_ctr_addvalue( values, "CategoryMessageFile", + REG_EXPAND_SZ, + ( char * ) data.buffer, + data.uni_str_len * + sizeof( uint16 ) ); + regdb_store_values( evtlogpath, values ); + } + TALLOC_FREE( values ); + elogs++; + } + return True; +} |