r6369: update release notes
[Samba.git] / source / registry / reg_eventlog.c
blobcc2ffb5a0578c77044c6729aafa6e02485180c18
1 /*
2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
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 = 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( char *path )
159 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 int eventlog_subkey_info( 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 evtlog_list = lp_eventlog_list();
206 num_subkeys = 0;
208 if ( top_level )
210 /* todo - get the eventlog subkey values from the smb.conf file
211 for ( num_subkeys=0; num_subkeys<MAX_TOP_LEVEL_KEYS; num_subkeys++ )
212 regsubkey_ctr_addkey( subkey_ctr, top_level_keys[num_subkeys] ); */
213 DEBUG(10,("eventlog_subkey_info: Adding eventlog subkeys from globals\n"));
214 /* TODO - make this from the globals.szEventLogs list */
216 while (*evtlog_list)
218 DEBUG(10,("eventlog_subkey_info: Adding subkey =>[%s]\n",*evtlog_list));
219 regsubkey_ctr_addkey( subkey_ctr, *evtlog_list);
220 evtlog_list++;
221 num_subkeys++;
224 else
226 while (*evtlog_list && (0==num_subkeys) )
228 if (0 == StrCaseCmp(path,*evtlog_list))
230 DEBUG(10,("eventlog_subkey_info: Adding subkey [%s] for key =>[%s]\n",path,*evtlog_list));
231 regsubkey_ctr_addkey( subkey_ctr, *evtlog_list);
232 num_subkeys = 1;
234 evtlog_list++;
237 if (0==num_subkeys)
238 DEBUG(10,("eventlog_subkey_info: No match on SUBkey=>[%s]\n", path));
241 SAFE_FREE( path );
242 return num_subkeys;
245 /**********************************************************************
246 Enumerate registry values given a registry path.
247 Caller is responsible for freeing memory
248 *********************************************************************/
250 int eventlog_value_info( char *key, REGVAL_CTR *val )
252 char *path;
253 BOOL top_level = False;
254 int num_values = 0;
256 DEBUG(10,("eventlog_value_info: key=>[%s]\n", key));
258 path = trim_eventlog_reg_path( key );
260 /* check to see if we are dealing with the top level key */
262 if ( !path )
263 top_level = True;
264 if ( top_level )
265 num_values = eventlog_topkey_values(path,val);
266 else
268 DEBUG(10,("eventlog_value_info: SUBkey=>[%s]\n", path));
269 num_values = eventlog_subkey_values(path,val);
271 return num_values;
274 /**********************************************************************
275 Stub function which always returns failure since we don't want
276 people storing eventlog information directly via registry calls
277 (for now at least)
278 *********************************************************************/
279 BOOL eventlog_store_subkey( char *key, REGSUBKEY_CTR *subkeys )
281 return False;
284 /**********************************************************************
285 Stub function which always returns failure since we don't want
286 people storing eventlog information directly via registry calls
287 (for now at least)
288 *********************************************************************/
289 BOOL eventlog_store_value( char *key, REGVAL_CTR *val )
291 return False;
295 * Table of function pointers for accessing eventlog data
297 REGISTRY_OPS eventlog_ops = {
298 eventlog_subkey_info,
299 eventlog_value_info,
300 eventlog_store_subkey,
301 eventlog_store_value