r7997: Pointers don't kill people, people with pointers kill people...
[Samba/gbeck.git] / source / registry / reg_eventlog.c
blobb20eb046db8034428140b31044b2458e92187c4d
1 /*
2 * Unix SMB/CIFS implementation.
3 * Virtual Windows Registry Layer
4 * Copyright (C) Marcin Krzysztof Porwit 2005.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "includes.h"
23 /**********************************************************************
24 handle enumeration of values AT KEY_EVENTLOG
25 *********************************************************************/
27 static int eventlog_topkey_values( char *key, REGVAL_CTR *val )
29 int num_values = 0;
30 char *keystr, *key2 = NULL;
31 char *base, *new_path;
32 fstring evtlogname;
33 UNISTR2 data;
34 int iDisplayNameId;
35 int iMaxSize;
37 /*
38 * TODO - callout to get these values...
41 if ( key )
43 key2 = SMB_STRDUP( key );
44 keystr = key2;
45 reg_split_path( keystr, &base, &new_path );
47 iDisplayNameId = 0x00000100;
48 iMaxSize= 0x00080000;
50 fstrcpy( evtlogname, base );
51 DEBUG(10,("eventlog_topkey_values: subkey root=> [%s] subkey path=>[%s]\n", base,new_path));
53 if ( !new_path )
55 iDisplayNameId = 0x01;
56 regval_ctr_addvalue( val, "ErrorControl", REG_DWORD, (char*)&iDisplayNameId, sizeof(int) );
58 init_unistr2( &data, "EventLog", UNI_STR_TERMINATE);
59 regval_ctr_addvalue( val, "DisplayName", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );
61 num_values = regval_ctr_numvals( val );
64 num_values = 0;
68 SAFE_FREE( key2 );
69 return num_values;
72 /**********************************************************************
73 handle enumeration of values below KEY_EVENTLOG\<Eventlog>
74 *********************************************************************/
76 static int eventlog_subkey_values( char *key, REGVAL_CTR *val )
78 int num_values = 0;
79 char *keystr, *key2 = NULL;
80 char *base, *new_path;
81 fstring evtlogname;
82 UNISTR2 data;
83 int iDisplayNameId;
84 int iMaxSize;
85 int iRetention;
87 /*
88 * TODO - callout to get these values...
91 if ( !key )
92 return num_values;
94 key2 = SMB_STRDUP( key );
95 keystr = key2;
96 reg_split_path( keystr, &base, &new_path );
98 iDisplayNameId = 0x00000100;
99 /* MaxSize is limited to 0xFFFF0000 (UINT_MAX - USHRT_MAX) as per MSDN documentation */
100 iMaxSize= 0xFFFF0000;
101 /* records in the samba log are not overwritten */
102 iRetention = 0xFFFFFFFF;
104 fstrcpy( evtlogname, base );
105 DEBUG(10,("eventlog_subpath_values_printer: eventlogname [%s]\n", base));
106 DEBUG(10,("eventlog_subpath_values_printer: new_path [%s]\n", new_path));
107 if ( !new_path )
109 #if 0
110 regval_ctr_addvalue( val, "DisplayNameId", REG_DWORD, (char*)&iDisplayNameId, sizeof(int) );
112 init_unistr2( &data, "%SystemRoot%\\system32\\els.dll", UNI_STR_TERMINATE);
113 regval_ctr_addvalue( val, "DisplayNameFile", REG_EXPAND_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );
114 #endif
115 regval_ctr_addvalue( val, "MaxSize", REG_DWORD, (char*)&iMaxSize, sizeof(int));
116 regval_ctr_addvalue( val, "Retention", REG_DWORD, (char *)&iRetention, sizeof(int));
117 #if 0
118 init_unistr2( &data, lp_logfile(), UNI_STR_TERMINATE);
119 regval_ctr_addvalue( val, "File", REG_EXPAND_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );
120 #endif
121 init_unistr2( &data, base, UNI_STR_TERMINATE);
122 regval_ctr_addvalue( val, "PrimaryModule", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );
124 init_unistr2( &data, base, UNI_STR_TERMINATE);
125 regval_ctr_addvalue( val, "Sources", REG_MULTI_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );
127 num_values = regval_ctr_numvals( val );
130 else
132 iDisplayNameId = 0x07;
133 regval_ctr_addvalue( val, "CategoryCount", REG_DWORD, (char*)&iDisplayNameId, sizeof(int) );
135 init_unistr2( &data, "%SystemRoot%\\system32\\eventlog.dll", UNI_STR_TERMINATE);
136 regval_ctr_addvalue( val, "CategoryMessageFile", REG_EXPAND_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );
138 num_values = regval_ctr_numvals( val );
140 num_values = 0;
143 SAFE_FREE( key2 );
144 return num_values;
148 /**********************************************************************
149 It is safe to assume that every registry path passed into on of
150 the exported functions here begins with KEY_EVENTLOG else
151 these functions would have never been called. This is a small utility
152 function to strip the beginning of the path and make a copy that the
153 caller can modify. Note that the caller is responsible for releasing
154 the memory allocated here.
155 **********************************************************************/
157 static char* trim_eventlog_reg_path( const char *path )
159 const char *p;
160 uint16 key_len = strlen(KEY_EVENTLOG);
163 * sanity check...this really should never be True.
164 * It is only here to prevent us from accessing outside
165 * the path buffer in the extreme case.
168 if ( strlen(path) < key_len ) {
169 DEBUG(0,("trim_reg_path: Registry path too short! [%s]\n", path));
170 DEBUG(0,("trim_reg_path: KEY_EVENTLOG => [%s]!\n", KEY_EVENTLOG));
171 return NULL;
175 p = path + strlen( KEY_EVENTLOG );
177 if ( *p == '\\' )
178 p++;
180 if ( *p )
181 return SMB_STRDUP(p);
182 else
183 return NULL;
185 /**********************************************************************
186 Enumerate registry subkey names given a registry path.
187 Caller is responsible for freeing memory to **subkeys
188 *********************************************************************/
189 static int eventlog_subkey_info( const char *key, REGSUBKEY_CTR *subkey_ctr )
191 char *path;
192 BOOL top_level = False;
193 int num_subkeys = 0;
194 const char **evtlog_list;
196 path = trim_eventlog_reg_path( key );
197 DEBUG(10,("eventlog_subkey_info: entire key=>[%s] SUBkey=>[%s]\n", key,path));
199 /* check to see if we are dealing with the top level key */
200 num_subkeys = 0;
202 if ( !path )
203 top_level = True;
205 num_subkeys = 0;
206 if ( !(evtlog_list = lp_eventlog_list()) ) {
207 SAFE_FREE(path);
208 return num_subkeys;
212 if ( top_level )
214 /* todo - get the eventlog subkey values from the smb.conf file
215 for ( num_subkeys=0; num_subkeys<MAX_TOP_LEVEL_KEYS; num_subkeys++ )
216 regsubkey_ctr_addkey( subkey_ctr, top_level_keys[num_subkeys] ); */
217 DEBUG(10,("eventlog_subkey_info: Adding eventlog subkeys from globals\n"));
218 /* TODO - make this from the globals.szEventLogs list */
220 while (*evtlog_list)
222 DEBUG(10,("eventlog_subkey_info: Adding subkey =>[%s]\n",*evtlog_list));
223 regsubkey_ctr_addkey( subkey_ctr, *evtlog_list);
224 evtlog_list++;
225 num_subkeys++;
228 else
230 while (*evtlog_list && (0==num_subkeys) )
232 if (0 == StrCaseCmp(path,*evtlog_list))
234 DEBUG(10,("eventlog_subkey_info: Adding subkey [%s] for key =>[%s]\n",path,*evtlog_list));
235 regsubkey_ctr_addkey( subkey_ctr, *evtlog_list);
236 num_subkeys = 1;
238 evtlog_list++;
241 if (0==num_subkeys)
242 DEBUG(10,("eventlog_subkey_info: No match on SUBkey=>[%s]\n", path));
245 SAFE_FREE( path );
246 return num_subkeys;
249 /**********************************************************************
250 Enumerate registry values given a registry path.
251 Caller is responsible for freeing memory
252 *********************************************************************/
254 static int eventlog_value_info( const char *key, REGVAL_CTR *val )
256 char *path;
257 BOOL top_level = False;
258 int num_values = 0;
260 DEBUG(10,("eventlog_value_info: key=>[%s]\n", key));
262 path = trim_eventlog_reg_path( key );
264 /* check to see if we are dealing with the top level key */
266 if ( !path )
267 top_level = True;
268 if ( top_level )
269 num_values = eventlog_topkey_values(path,val);
270 else
272 DEBUG(10,("eventlog_value_info: SUBkey=>[%s]\n", path));
273 num_values = eventlog_subkey_values(path,val);
275 return num_values;
278 /**********************************************************************
279 Stub function which always returns failure since we don't want
280 people storing eventlog information directly via registry calls
281 (for now at least)
282 *********************************************************************/
283 static BOOL eventlog_store_subkey( const char *key, REGSUBKEY_CTR *subkeys )
285 return False;
288 /**********************************************************************
289 Stub function which always returns failure since we don't want
290 people storing eventlog information directly via registry calls
291 (for now at least)
292 *********************************************************************/
293 static BOOL eventlog_store_value( const char *key, REGVAL_CTR *val )
295 return False;
299 * Table of function pointers for accessing eventlog data
301 REGISTRY_OPS eventlog_ops = {
302 eventlog_subkey_info,
303 eventlog_value_info,
304 eventlog_store_subkey,
305 eventlog_store_value,
306 NULL