Fix signed/unsigned comparison warnings.
[wine] / dlls / advapi32 / eventlog.c
1 /*
2  * Win32 advapi functions
3  *
4  * Copyright 1995 Sven Verdoolaege
5  * Copyright 1998 Juergen Schmied
6  * Copyright 2003 Mike Hearn
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 #include <stdarg.h>
24
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winerror.h"
28 #include "winreg.h"
29 #include "winternl.h"
30
31 #include "wine/debug.h"
32
33 WINE_DEFAULT_DEBUG_CHANNEL(advapi);
34 WINE_DECLARE_DEBUG_CHANNEL(eventlog);
35
36 /******************************************************************************
37  * BackupEventLogA [ADVAPI32.@]
38  *
39  * Saves the event log to a backup file.
40  *
41  * PARAMS
42  *  hEventLog        [I] Handle to event log to backup.
43  *  lpBackupFileName [I] Name of the backup file.
44  *
45  * RETURNS
46  *  Success: nonzero. File lpBackupFileName will contain the contents of
47  *           hEvenLog.
48  *  Failure: zero.
49  */
50 BOOL WINAPI BackupEventLogA( HANDLE hEventLog, LPCSTR lpBackupFileName )
51 {
52         FIXME("stub\n");
53         return TRUE;
54 }
55
56 /******************************************************************************
57  * BackupEventLogW [ADVAPI32.@]
58  *
59  * see BackupEventLogA
60  */
61 BOOL WINAPI
62 BackupEventLogW( HANDLE hEventLog, LPCWSTR lpBackupFileName )
63 {
64         FIXME("stub\n");
65         return TRUE;
66 }
67
68 /******************************************************************************
69  * ClearEventLogA [ADVAPI32.@]
70  *
71  * Clears the event log and/or saves the log to a backup file.
72  *
73  * PARAMS
74  *  hEvenLog         [I] Handle to event log to clear.
75  *  lpBackupFileName [I] Name of the backup file.
76  *
77  * RETURNS
78  *  Success: nonzero. if lpBackupFileName != NULL, lpBackupFileName will 
79  *           contain the contents of hEvenLog and the log will be cleared.
80  *  Failure: zero. Fails if the event log is empty or if lpBackupFileName
81  *           exists.
82  */
83 BOOL WINAPI ClearEventLogA ( HANDLE hEventLog, LPCSTR lpBackupFileName )
84 {
85         FIXME("stub\n");
86         return TRUE;
87 }
88
89 /******************************************************************************
90  * ClearEventLogW [ADVAPI32.@]
91  *
92  * see ClearEventLogA
93  */
94 BOOL WINAPI ClearEventLogW ( HANDLE hEventLog, LPCWSTR lpBackupFileName )
95 {
96         FIXME("stub\n");
97         return TRUE;
98 }
99
100 /******************************************************************************
101  * CloseEventLog [ADVAPI32.@]
102  *
103  * Closes a read handle to the event log.
104  *
105  * PARAMS
106  *  hEventLog [I/O] Handle of the event log to close.
107  *
108  * RETURNS
109  *  Success: nonzero
110  *  Failure: zero
111  */
112 BOOL WINAPI CloseEventLog ( HANDLE hEventLog )
113 {
114         FIXME("stub\n");
115         return TRUE;
116 }
117
118 /******************************************************************************
119  * DeregisterEventSource [ADVAPI32.@]
120  * 
121  * Closes a write handle to an event log
122  *
123  * PARAMS
124  *  hEventLog [I/O] Handle of the event log.
125  *
126  * RETURNS
127  *  Success: nonzero
128  *  Failure: zero
129  */
130 BOOL WINAPI DeregisterEventSource( HANDLE hEventLog )
131 {
132     FIXME("(%p): stub\n",hEventLog);
133     return TRUE;
134 }
135
136 /******************************************************************************
137  * GetNumberOfEventLogRecords [ADVAPI32.@]
138  *
139  * Retrieves the number of records in an event log.
140  *
141  * PARAMS
142  *  hEventLog       [I] Handle to an open event log.
143  *  NumberOfRecords [O] Number of records in the log.
144  *
145  * RETURNS
146  *  Success: nonzero. NumberOfRecords will contain the number of records in
147  *           the log.
148  *  Failure: zero
149  */
150 BOOL WINAPI
151 GetNumberOfEventLogRecords( HANDLE hEventLog, PDWORD NumberOfRecords )
152 {
153         FIXME("stub\n");
154         return TRUE;
155 }
156
157 /******************************************************************************
158  * GetOldestEventLogRecord [ADVAPI32.@]
159  *
160  * Retrieves the absolute record number of the oldest record in an even log.
161  *
162  * PARAMS
163  *  hEventLog    [I] Handle to an open event log.
164  *  OldestRecord [O] Absolute record number of the oldest record.
165  *
166  * RETURNS
167  *  Success: nonzero. OldestRecord contains the record number of the oldest
168  *           record in the log.
169  *  Failure: zero 
170  */
171 BOOL WINAPI
172 GetOldestEventLogRecord( HANDLE hEventLog, PDWORD OldestRecord )
173 {
174         FIXME(":stub\n");
175         return TRUE;
176 }
177
178 /******************************************************************************
179  * NotifyChangeEventLog [ADVAPI32.@]
180  *
181  * Enables an application to receive notification when an event is written
182  * to an event log.
183  *
184  * PARAMS
185  *  hEventLog [I] Handle to an event log.
186  *  hEvent    [I] Handle to a manual-reset event object.
187  *
188  * RETURNS
189  *  Success: nonzero
190  *  Failure: zero
191  */
192 BOOL WINAPI NotifyChangeEventLog( HANDLE hEventLog, HANDLE hEvent )
193 {
194         FIXME("stub\n");
195         return TRUE;
196 }
197
198 /******************************************************************************
199  * OpenBackupEventLogA [ADVAPI32.@]
200  *
201  * Opens a handle to a backup event log.
202  *
203  * PARAMS
204  *  lpUNCServerName [I] Universal Naming Convention name of the server on which
205  *                      this will be performed.
206  *  lpFileName      [I] Specifies the name of the backup file.
207  *
208  * RETURNS
209  *  Success: Handle to the backup event log.
210  *  Failure: NULL
211  */
212 HANDLE WINAPI
213 OpenBackupEventLogA( LPCSTR lpUNCServerName, LPCSTR lpFileName )
214 {
215         FIXME("stub\n");
216         return (HANDLE)1;
217 }
218
219 /******************************************************************************
220  * OpenBackupEventLogW [ADVAPI32.@]
221  *
222  * see OpenBackupEventLogA
223  */
224 HANDLE WINAPI
225 OpenBackupEventLogW( LPCWSTR lpUNCServerName, LPCWSTR lpFileName )
226 {
227         FIXME("stub\n");
228         return (HANDLE)1;
229 }
230
231 /******************************************************************************
232  * OpenEventLogA [ADVAPI32.@]
233  *
234  * Opens a handle to the specified event log.
235  *
236  * PARAMS
237  *  lpUNCServerName [I] UNC name of the server on which the event log is
238  *                      opened.
239  *  lpSourceName    [I] Name of the log.
240  *
241  * RETURNS
242  *  Success: Handle to an event log.
243  *  Failure: NULL
244  */
245 HANDLE WINAPI OpenEventLogA(LPCSTR uncname,LPCSTR source)
246 {
247         FIXME("(%s,%s),stub!\n",uncname,source);
248         return (HANDLE)0xcafe4242;
249 }
250
251 /******************************************************************************
252  * OpenEventLogW [ADVAPI32.@]
253  *
254  * see OpenEventLogA
255  */
256 HANDLE WINAPI
257 OpenEventLogW( LPCWSTR uncname, LPCWSTR source )
258 {
259         FIXME("stub\n");
260         return (HANDLE)1;
261 }
262
263 /******************************************************************************
264  * ReadEventLogA [ADVAPI32.@]
265  *
266  * Reads a whole number of entries from an event log.
267  *
268  * PARAMS
269  *  hEventLog                [I] Handle of the event log to read.
270  *  dwReadFlags              [I] see MSDN doc.
271  *  dwRecordOffset           [I] Log-entry record number to start at.
272  *  lpBuffer                 [O] Buffer for the data read.
273  *  nNumberOfBytesToRead     [I] Size of lpBuffer.
274  *  pnBytesRead              [O] Receives number of bytes read.
275  *  pnMinNumberOfBytesNeeded [O] Receives number of bytes required for the
276  *                               next log entry.
277  *
278  * RETURNS
279  *  Success: nonzero
280  *  Failure: zero
281  */
282 BOOL WINAPI ReadEventLogA( HANDLE hEventLog, DWORD dwReadFlags, DWORD dwRecordOffset,
283     LPVOID lpBuffer, DWORD nNumberOfBytesToRead, DWORD *pnBytesRead, DWORD *pnMinNumberOfBytesNeeded )
284 {
285         FIXME("stub\n");
286         return TRUE;
287 }
288
289 /******************************************************************************
290  * ReadEventLogW [ADVAPI32.@]
291  *
292  * see ReadEventLogA
293  */
294 BOOL WINAPI
295 ReadEventLogW( HANDLE hEventLog, DWORD dwReadFlags, DWORD dwRecordOffset,
296                  LPVOID lpBuffer, DWORD nNumberOfBytesToRead,
297                  DWORD *pnBytesRead, DWORD *pnMinNumberOfBytesNeeded )
298 {
299         FIXME("stub\n");
300         return TRUE;
301 }
302
303 /******************************************************************************
304  * RegisterEventSourceA [ADVAPI32.@]
305  *
306  * Returns a registered handle to an event log.
307  *
308  * PARAMS
309  *  lpUNCServerName [I] UNC name of the source server.
310  *  lpSourceName    [I] Specifies the name of the event source to retrieve.
311  *
312  * RETURNS
313  *  Success: Handle to the event log.
314  *  Failure: NULL. Returns ERROR_INVALID_HANDLE if lpSourceName specifies the
315  *           Security event log.
316  */
317 HANDLE WINAPI RegisterEventSourceA( LPCSTR lpUNCServerName, LPCSTR lpSourceName )
318 {
319     
320     UNICODE_STRING lpUNCServerNameW;
321     UNICODE_STRING lpSourceNameW;
322     HANDLE ret;
323     RtlCreateUnicodeStringFromAsciiz(&lpUNCServerNameW, lpUNCServerName);
324     RtlCreateUnicodeStringFromAsciiz(&lpSourceNameW, lpSourceName);
325     ret = RegisterEventSourceW(lpUNCServerNameW.Buffer,lpSourceNameW.Buffer);
326     RtlFreeUnicodeString (&lpUNCServerNameW);
327     RtlFreeUnicodeString (&lpSourceNameW);
328     return ret;
329 }
330
331 /******************************************************************************
332  * RegisterEventSourceW [ADVAPI32.@]
333  *
334  * see RegisterEventSourceA
335  */
336 HANDLE WINAPI
337 RegisterEventSourceW( LPCWSTR lpUNCServerName, LPCWSTR lpSourceName )
338 {
339     FIXME("(%s,%s): stub\n", debugstr_w(lpUNCServerName),
340           debugstr_w(lpSourceName));
341     return (HANDLE)1;
342 }
343
344 /******************************************************************************
345  * ReportEventA [ADVAPI32.@]
346  *
347  * Writes an entry at the end of an event log.
348  *
349  * PARAMS
350  *  hEventLog   [I] Handle of an event log.
351  *  wType       [I] See MSDN doc.
352  *  wCategory   [I] Event category.
353  *  dwEventID   [I] Event identifier.
354  *  lpUserSid   [I] Current user's security identifier.
355  *  wNumStrings [I] Number of insert strings in lpStrings.
356  *  dwDataSize  [I] Size of event-specific raw data to write.
357  *  lpStrings   [I] Buffer containing an array of string to be merged.
358  *  lpRawData   [I] Buffer containing the binary data.
359  *
360  * RETURNS
361  *  Success: nonzero. Entry was written to the log.
362  *  Failure: zero.
363  *
364  * NOTES
365  *  The ReportEvent function adds the time, the entry's length, and the
366  *  offsets before storing the entry in the log. If lpUserSid != NULL, the
367  *  username is also logged.
368  */
369 BOOL WINAPI ReportEventA ( HANDLE hEventLog, WORD wType, WORD wCategory, DWORD dwEventID,
370     PSID lpUserSid, WORD wNumStrings, DWORD dwDataSize, LPCSTR *lpStrings, LPVOID lpRawData)
371 {
372     LPCWSTR *wideStrArray;
373     UNICODE_STRING str;
374     int i;
375     BOOL ret;
376
377     if (wNumStrings == 0) return TRUE;
378     if (!lpStrings) return TRUE;
379
380     wideStrArray = HeapAlloc(GetProcessHeap(), 0, sizeof(LPCWSTR) * wNumStrings);
381     for (i = 0; i < wNumStrings; i++)
382     {
383         RtlCreateUnicodeStringFromAsciiz(&str, lpStrings[i]);
384         wideStrArray[i] = str.Buffer;
385     }
386     ret = ReportEventW(hEventLog, wType, wCategory, dwEventID, lpUserSid,
387                        wNumStrings, dwDataSize, wideStrArray, lpRawData);
388     for (i = 0; i < wNumStrings; i++)
389     {
390         if (wideStrArray[i]) HeapFree( GetProcessHeap(), 0, (LPSTR)wideStrArray[i] );
391     }
392     HeapFree(GetProcessHeap(), 0, wideStrArray);
393     return ret;
394 }
395
396 /******************************************************************************
397  * ReportEventW [ADVAPI32.@]
398  *
399  * see ReportEventA
400  */
401 BOOL WINAPI
402 ReportEventW( HANDLE hEventLog, WORD wType, WORD wCategory,
403                 DWORD dwEventID, PSID lpUserSid, WORD wNumStrings,
404                 DWORD dwDataSize, LPCWSTR *lpStrings, LPVOID lpRawData )
405 {
406     int i;
407
408     /* partial stub */
409
410     if (wNumStrings == 0) return TRUE;
411     if (!lpStrings) return TRUE;
412
413     for (i = 0; i < wNumStrings; i++)
414     {
415         switch (wType)
416         {
417         case EVENTLOG_SUCCESS:
418             TRACE_(eventlog)("%s\n", debugstr_w(lpStrings[i]));
419             break;
420         case EVENTLOG_ERROR_TYPE:
421             ERR_(eventlog)("%s\n", debugstr_w(lpStrings[i]));
422             break;
423         case EVENTLOG_WARNING_TYPE:
424             WARN_(eventlog)("%s\n", debugstr_w(lpStrings[i]));
425             break;
426         default:
427             TRACE_(eventlog)("%s\n", debugstr_w(lpStrings[i]));
428             break;
429         }
430     }
431     return TRUE;
432
433 }