r7648: adding REGISTRY_HOOK->reg_access_check() for authprization checks on RegOpenKe...
[amitay/samba.git] / source3 / registry / reg_eventlog.c
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.
10  *  
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.
15  *  
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.
19  */
20  
21 #include "includes.h"
22
23 /**********************************************************************
24  handle enumeration of values AT KEY_EVENTLOG
25  *********************************************************************/
26  
27 static int eventlog_topkey_values( char *key, REGVAL_CTR *val )
28 {
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;
36     
37     /* 
38      *  TODO - callout to get these values...
39      */
40     
41     if ( key ) 
42     {
43         key2 = SMB_STRDUP( key );
44         keystr = key2;
45         reg_split_path( keystr, &base, &new_path );
46         
47         iDisplayNameId = 0x00000100;
48         iMaxSize=        0x00080000;
49         
50         fstrcpy( evtlogname, base );
51         DEBUG(10,("eventlog_topkey_values: subkey root=> [%s] subkey path=>[%s]\n", base,new_path));
52         
53         if ( !new_path ) 
54         {
55             iDisplayNameId = 0x01;
56             regval_ctr_addvalue( val, "ErrorControl",    REG_DWORD, (char*)&iDisplayNameId,       sizeof(int) ); 
57             
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) );
60             
61             num_values = regval_ctr_numvals( val );     
62             
63             
64             num_values = 0;
65         }
66     }
67     
68     SAFE_FREE( key2 ); 
69     return num_values;
70 }
71
72 /**********************************************************************
73  handle enumeration of values below KEY_EVENTLOG\<Eventlog>
74  *********************************************************************/
75  
76 static int eventlog_subkey_values( char *key, REGVAL_CTR *val )
77 {
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;
86     
87     /* 
88      *  TODO - callout to get these values...
89      */
90     
91     if ( !key ) 
92         return num_values;
93     
94     key2 = SMB_STRDUP( key );
95     keystr = key2;
96     reg_split_path( keystr, &base, &new_path );
97     
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;
103     
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 ) 
108     {
109 #if 0
110         regval_ctr_addvalue( val, "DisplayNameId",    REG_DWORD, (char*)&iDisplayNameId,       sizeof(int) ); 
111         
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) );
123         
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) );
126         
127         num_values = regval_ctr_numvals( val ); 
128         
129     } 
130     else
131     {
132         iDisplayNameId = 0x07;
133         regval_ctr_addvalue( val, "CategoryCount",    REG_DWORD, (char*)&iDisplayNameId,       sizeof(int) ); 
134         
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) );
137         
138         num_values = regval_ctr_numvals( val ); 
139         
140         num_values = 0;
141     }
142     
143     SAFE_FREE( key2 ); 
144     return num_values;
145 }
146
147
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  **********************************************************************/
156
157 static char* trim_eventlog_reg_path( char *path )
158 {
159         char *p;
160         uint16 key_len = strlen(KEY_EVENTLOG);
161         
162         /* 
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.
166          */
167         
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;
172         }
173         
174         
175         p = path + strlen( KEY_EVENTLOG );
176         
177         if ( *p == '\\' )
178                 p++;
179         
180         if ( *p )
181                 return SMB_STRDUP(p);
182         else
183                 return NULL;
184 }
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 )
190 {
191     char        *path;
192     BOOL        top_level = False;
193     int         num_subkeys = 0;
194     const char        **evtlog_list;
195     
196     path = trim_eventlog_reg_path( key );
197     DEBUG(10,("eventlog_subkey_info: entire key=>[%s] SUBkey=>[%s]\n", key,path));      
198     
199     /* check to see if we are dealing with the top level key */
200     num_subkeys = 0;
201     
202     if ( !path )
203         top_level = True;
204     
205     num_subkeys = 0;
206     if ( !(evtlog_list = lp_eventlog_list()) ) {
207         SAFE_FREE(path);
208         return num_subkeys;
209     }
210
211     
212     if ( top_level )
213     { 
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 */
219         
220         while (*evtlog_list) 
221         {
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++;
226         }
227     }
228     else 
229     {
230         while (*evtlog_list && (0==num_subkeys) ) 
231         {
232             if (0 == StrCaseCmp(path,*evtlog_list)) 
233             {
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;
237             }
238             evtlog_list++;
239         }
240         
241         if (0==num_subkeys) 
242             DEBUG(10,("eventlog_subkey_info: No match on SUBkey=>[%s]\n", path));
243     }
244     
245     SAFE_FREE( path );
246     return num_subkeys;
247 }
248
249 /**********************************************************************
250  Enumerate registry values given a registry path.  
251  Caller is responsible for freeing memory 
252  *********************************************************************/
253
254 static int eventlog_value_info( char *key, REGVAL_CTR *val )
255 {
256         char            *path;
257         BOOL            top_level = False;
258         int             num_values = 0;
259         
260         DEBUG(10,("eventlog_value_info: key=>[%s]\n", key));
261         
262         path = trim_eventlog_reg_path( key );
263         
264         /* check to see if we are dealing with the top level key */
265         
266         if ( !path )
267             top_level = True;
268         if ( top_level )
269             num_values = eventlog_topkey_values(path,val);
270         else 
271         {
272             DEBUG(10,("eventlog_value_info: SUBkey=>[%s]\n", path));
273             num_values = eventlog_subkey_values(path,val);
274         }
275         return num_values;
276 }
277
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( char *key, REGSUBKEY_CTR *subkeys )
284 {
285         return False;
286 }
287
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( char *key, REGVAL_CTR *val )
294 {
295         return False;
296 }
297
298 /* 
299  * Table of function pointers for accessing eventlog data
300  */
301 REGISTRY_OPS eventlog_ops = {
302         eventlog_subkey_info,
303         eventlog_value_info,
304         eventlog_store_subkey,
305         eventlog_store_value,
306         NULL
307 };