summaryrefslogtreecommitdiff
path: root/source3/registry/reg_eventlog.c
blob: bed9e1d59aec33ac8b4be8a801d29f81e8571a8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/* 
 *  Unix SMB/CIFS implementation.
 *  Virtual Windows Registry Layer
 *  Copyright (C) Marcin Krzysztof Porwit    2005,
 *  Copyright (C) Gerald (Jerry) Carter      2005.
 *  
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *  
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License
 *  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.  
*********************************************************************/

static int elog_fetch_keys( const char *key, REGSUBKEY_CTR *subkeys )
{
	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;
	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 ));
		}
	
		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 );
}

/**********************************************************************
*********************************************************************/

static BOOL elog_store_keys( const char *key, REGSUBKEY_CTR *subkeys )
{
	/* cannot create any subkeys here */
	
	return False;
}

/**********************************************************************
 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 );
}

/******************************************************************** 
 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
};