2 * Unix SMB/CIFS implementation.
3 * Virtual Windows Registry Layer
4 * Copyright (C) Marcin Krzysztof Porwit 2005.
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.
23 /**********************************************************************
24 handle enumeration of values AT KEY_EVENTLOG
25 *********************************************************************/
27 static int eventlog_topkey_values( char *key, REGVAL_CTR *val )
30 char *keystr, *key2 = NULL;
31 char *base, *new_path;
38 * TODO - callout to get these values...
43 key2 = SMB_STRDUP( key );
45 reg_split_path( keystr, &base, &new_path );
47 iDisplayNameId = 0x00000100;
50 fstrcpy( evtlogname, base );
51 DEBUG(10,("eventlog_topkey_values: subkey root=> [%s] subkey path=>[%s]\n", base,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 );
72 /**********************************************************************
73 handle enumeration of values below KEY_EVENTLOG\<Eventlog>
74 *********************************************************************/
76 static int eventlog_subkey_values( char *key, REGVAL_CTR *val )
79 char *keystr, *key2 = NULL;
80 char *base, *new_path;
88 * TODO - callout to get these values...
94 key2 = SMB_STRDUP( key );
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));
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) );
115 regval_ctr_addvalue( val, "MaxSize", REG_DWORD, (char*)&iMaxSize, sizeof(int));
116 regval_ctr_addvalue( val, "Retention", REG_DWORD, (char *)&iRetention, sizeof(int));
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) );
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 );
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 );
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 )
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));
175 p = path + strlen( KEY_EVENTLOG );
181 return SMB_STRDUP(p);
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( char *key, REGSUBKEY_CTR *subkey_ctr )
192 BOOL top_level = False;
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 */
206 if ( !(evtlog_list = lp_eventlog_list()) ) {
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 */
222 DEBUG(10,("eventlog_subkey_info: Adding subkey =>[%s]\n",*evtlog_list));
223 regsubkey_ctr_addkey( subkey_ctr, *evtlog_list);
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);
242 DEBUG(10,("eventlog_subkey_info: No match on SUBkey=>[%s]\n", path));
249 /**********************************************************************
250 Enumerate registry values given a registry path.
251 Caller is responsible for freeing memory
252 *********************************************************************/
254 static int eventlog_value_info( char *key, REGVAL_CTR *val )
257 BOOL top_level = False;
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 */
269 num_values = eventlog_topkey_values(path,val);
272 DEBUG(10,("eventlog_value_info: SUBkey=>[%s]\n", path));
273 num_values = eventlog_subkey_values(path,val);
278 /**********************************************************************
279 Stub function which always returns failure since we don't want
280 people storing eventlog information directly via registry calls
282 *********************************************************************/
283 static BOOL eventlog_store_subkey( char *key, REGSUBKEY_CTR *subkeys )
288 /**********************************************************************
289 Stub function which always returns failure since we don't want
290 people storing eventlog information directly via registry calls
292 *********************************************************************/
293 static BOOL eventlog_store_value( char *key, REGVAL_CTR *val )
299 * Table of function pointers for accessing eventlog data
301 REGISTRY_OPS eventlog_ops = {
302 eventlog_subkey_info,
304 eventlog_store_subkey,
305 eventlog_store_value,