advapi32: Cleanup event log only if create was successful.
[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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21  */
22
23 #include <stdarg.h>
24
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winerror.h"
28 #include "winternl.h"
29 #include "wmistr.h"
30 #include "evntrace.h"
31 #include "evntprov.h"
32
33 #include "wine/unicode.h"
34 #include "wine/debug.h"
35
36 WINE_DEFAULT_DEBUG_CHANNEL(advapi);
37 WINE_DECLARE_DEBUG_CHANNEL(eventlog);
38
39 static inline LPWSTR SERV_dup( LPCSTR str )
40 {
41     UINT len;
42     LPWSTR wstr;
43
44     if( !str )
45         return NULL;
46     len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
47     wstr = HeapAlloc( GetProcessHeap(), 0, len*sizeof (WCHAR) );
48     MultiByteToWideChar( CP_ACP, 0, str, -1, wstr, len );
49     return wstr;
50 }
51
52 /******************************************************************************
53  * BackupEventLogA [ADVAPI32.@]
54  *
55  * Saves the event log to a backup file.
56  *
57  * PARAMS
58  *  hEventLog        [I] Handle to event log to backup.
59  *  lpBackupFileName [I] Name of the backup file.
60  *
61  * RETURNS
62  *  Success: nonzero. File lpBackupFileName will contain the contents of
63  *           hEvenLog.
64  *  Failure: zero.
65  */
66 BOOL WINAPI BackupEventLogA( HANDLE hEventLog, LPCSTR lpBackupFileName )
67 {
68     LPWSTR backupW;
69     BOOL ret;
70
71     backupW = SERV_dup(lpBackupFileName);
72     ret = BackupEventLogW(hEventLog, backupW);
73     HeapFree(GetProcessHeap(), 0, backupW);
74
75     return ret;
76 }
77
78 /******************************************************************************
79  * BackupEventLogW [ADVAPI32.@]
80  *
81  * See BackupEventLogA.
82  */
83 BOOL WINAPI BackupEventLogW( HANDLE hEventLog, LPCWSTR lpBackupFileName )
84 {
85     FIXME("(%p,%s) stub\n", hEventLog, debugstr_w(lpBackupFileName));
86
87     if (!lpBackupFileName)
88     {
89         SetLastError(ERROR_INVALID_PARAMETER);
90         return FALSE;
91     }
92
93     if (!hEventLog)
94     {
95         SetLastError(ERROR_INVALID_HANDLE);
96         return FALSE;
97     }
98
99     if (GetFileAttributesW(lpBackupFileName) != INVALID_FILE_ATTRIBUTES)
100     {
101         SetLastError(ERROR_ALREADY_EXISTS);
102         return FALSE;
103     }
104
105     return TRUE;
106 }
107
108 /******************************************************************************
109  * ClearEventLogA [ADVAPI32.@]
110  *
111  * Clears the event log and optionally saves the log to a backup file.
112  *
113  * PARAMS
114  *  hEvenLog         [I] Handle to event log to clear.
115  *  lpBackupFileName [I] Name of the backup file.
116  *
117  * RETURNS
118  *  Success: nonzero. if lpBackupFileName != NULL, lpBackupFileName will 
119  *           contain the contents of hEvenLog and the log will be cleared.
120  *  Failure: zero. Fails if the event log is empty or if lpBackupFileName
121  *           exists.
122  */
123 BOOL WINAPI ClearEventLogA( HANDLE hEventLog, LPCSTR lpBackupFileName )
124 {
125     LPWSTR backupW;
126     BOOL ret;
127
128     backupW = SERV_dup(lpBackupFileName);
129     ret = ClearEventLogW(hEventLog, backupW);
130     HeapFree(GetProcessHeap(), 0, backupW);
131
132     return ret;
133 }
134
135 /******************************************************************************
136  * ClearEventLogW [ADVAPI32.@]
137  *
138  * See ClearEventLogA.
139  */
140 BOOL WINAPI ClearEventLogW( HANDLE hEventLog, LPCWSTR lpBackupFileName )
141 {
142     FIXME("(%p,%s) stub\n", hEventLog, debugstr_w(lpBackupFileName));
143
144     if (!hEventLog)
145     {
146         SetLastError(ERROR_INVALID_HANDLE);
147         return FALSE;
148     }
149
150     return TRUE;
151 }
152
153 /******************************************************************************
154  * CloseEventLog [ADVAPI32.@]
155  *
156  * Closes a read handle to the event log.
157  *
158  * PARAMS
159  *  hEventLog [I/O] Handle of the event log to close.
160  *
161  * RETURNS
162  *  Success: nonzero
163  *  Failure: zero
164  */
165 BOOL WINAPI CloseEventLog( HANDLE hEventLog )
166 {
167     FIXME("(%p) stub\n", hEventLog);
168
169     if (!hEventLog)
170     {
171         SetLastError(ERROR_INVALID_HANDLE);
172         return FALSE;
173     }
174
175     return TRUE;
176 }
177
178 /******************************************************************************
179  * ControlTraceW [ADVAPI32.@]
180  *
181  * Control a givel event trace session
182  *
183  */
184 ULONG WINAPI ControlTraceW( TRACEHANDLE hSession, LPCWSTR SessionName, PEVENT_TRACE_PROPERTIES Properties, ULONG control )
185 {
186     FIXME("(%s, %s, %p, %d) stub\n", wine_dbgstr_longlong(hSession), debugstr_w(SessionName), Properties, control);
187     return ERROR_SUCCESS;
188 }
189
190 /******************************************************************************
191  * ControlTraceA [ADVAPI32.@]
192  *
193  * See ControlTraceW.
194  *
195  */
196 ULONG WINAPI ControlTraceA( TRACEHANDLE hSession, LPCSTR SessionName, PEVENT_TRACE_PROPERTIES Properties, ULONG control )
197 {
198     FIXME("(%s, %s, %p, %d) stub\n", wine_dbgstr_longlong(hSession), debugstr_a(SessionName), Properties, control);
199     return ERROR_SUCCESS;
200 }
201
202 /******************************************************************************
203  * FlushTraceA [ADVAPI32.@]
204  */
205 ULONG WINAPI FlushTraceA ( TRACEHANDLE hSession, LPCSTR SessionName, PEVENT_TRACE_PROPERTIES Properties )
206 {
207     return ControlTraceA( hSession, SessionName, Properties, EVENT_TRACE_CONTROL_FLUSH );
208 }
209
210 /******************************************************************************
211  * FlushTraceW [ADVAPI32.@]
212  */
213 ULONG WINAPI FlushTraceW ( TRACEHANDLE hSession, LPCWSTR SessionName, PEVENT_TRACE_PROPERTIES Properties )
214 {
215     return ControlTraceW( hSession, SessionName, Properties, EVENT_TRACE_CONTROL_FLUSH );
216 }
217
218
219 /******************************************************************************
220  * DeregisterEventSource [ADVAPI32.@]
221  * 
222  * Closes a write handle to an event log
223  *
224  * PARAMS
225  *  hEventLog [I/O] Handle of the event log.
226  *
227  * RETURNS
228  *  Success: nonzero
229  *  Failure: zero
230  */
231 BOOL WINAPI DeregisterEventSource( HANDLE hEventLog )
232 {
233     FIXME("(%p) stub\n", hEventLog);
234     return TRUE;
235 }
236
237 /******************************************************************************
238  * EnableTraceEx [ADVAPI32.@]
239  */
240 ULONG WINAPI EnableTraceEx( LPCGUID provider, LPCGUID source, TRACEHANDLE hSession, ULONG enable,
241                             UCHAR level, ULONGLONG anykeyword, ULONGLONG allkeyword, ULONG enableprop,
242                             PEVENT_FILTER_DESCRIPTOR filterdesc )
243 {
244     FIXME("(%s, %s, %s, %d, %c, %s, %s, %d, %p): stub\n", debugstr_guid(provider),
245             debugstr_guid(source), wine_dbgstr_longlong(hSession), enable, level,
246             wine_dbgstr_longlong(anykeyword), wine_dbgstr_longlong(allkeyword),
247             enableprop, filterdesc);
248
249     return ERROR_SUCCESS;
250 }
251
252 /******************************************************************************
253  * EnableTrace [ADVAPI32.@]
254  */
255 ULONG WINAPI EnableTrace( ULONG enable, ULONG flag, ULONG level, LPCGUID guid, TRACEHANDLE hSession )
256 {
257     FIXME("(%d, 0x%x, %d, %s, %s): stub\n", enable, flag, level,
258             debugstr_guid(guid), wine_dbgstr_longlong(hSession));
259
260     return ERROR_SUCCESS;
261 }
262
263 /******************************************************************************
264  * GetEventLogInformation [ADVAPI32.@]
265  *
266  * Retrieve some information about an event log.
267  *
268  * PARAMS
269  *  hEventLog      [I]   Handle to an open event log.
270  *  dwInfoLevel    [I]   Level of information (only EVENTLOG_FULL_INFO)
271  *  lpBuffer       [I/O] The buffer for the returned information
272  *  cbBufSize      [I]   The size of the buffer
273  *  pcbBytesNeeded [O]   The needed bytes to hold the information
274  *
275  * RETURNS
276  *  Success: TRUE. lpBuffer will hold the information and pcbBytesNeeded shows
277  *           the needed buffer size.
278  *  Failure: FALSE.
279  */
280 BOOL WINAPI GetEventLogInformation( HANDLE hEventLog, DWORD dwInfoLevel, LPVOID lpBuffer, DWORD cbBufSize, LPDWORD pcbBytesNeeded)
281 {
282     EVENTLOG_FULL_INFORMATION *efi;
283
284     FIXME("(%p, %d, %p, %d, %p) stub\n", hEventLog, dwInfoLevel, lpBuffer, cbBufSize, pcbBytesNeeded);
285
286     if (dwInfoLevel != EVENTLOG_FULL_INFO)
287     {
288         SetLastError(ERROR_INVALID_LEVEL);
289         return FALSE;
290     }
291
292     if (!hEventLog)
293     {
294         SetLastError(ERROR_INVALID_HANDLE);
295         return FALSE;
296     }
297
298     if (!lpBuffer || !pcbBytesNeeded)
299     {
300         /* FIXME: This will be handled properly when eventlog is moved
301          * to a higher level
302          */
303         SetLastError(RPC_X_NULL_REF_POINTER);
304         return FALSE;
305     }
306
307     *pcbBytesNeeded = sizeof(EVENTLOG_FULL_INFORMATION);
308     if (cbBufSize < sizeof(EVENTLOG_FULL_INFORMATION))
309     {
310         SetLastError(ERROR_INSUFFICIENT_BUFFER);
311         return FALSE;
312     }
313
314     /* Pretend the log is not full */
315     efi = (EVENTLOG_FULL_INFORMATION *)lpBuffer;
316     efi->dwFull = 0;
317
318     return TRUE;
319 }
320
321 /******************************************************************************
322  * GetNumberOfEventLogRecords [ADVAPI32.@]
323  *
324  * Retrieves the number of records in an event log.
325  *
326  * PARAMS
327  *  hEventLog       [I] Handle to an open event log.
328  *  NumberOfRecords [O] Number of records in the log.
329  *
330  * RETURNS
331  *  Success: nonzero. NumberOfRecords will contain the number of records in
332  *           the log.
333  *  Failure: zero
334  */
335 BOOL WINAPI GetNumberOfEventLogRecords( HANDLE hEventLog, PDWORD NumberOfRecords )
336 {
337     FIXME("(%p,%p) stub\n", hEventLog, NumberOfRecords);
338
339     if (!NumberOfRecords)
340     {
341         SetLastError(ERROR_INVALID_PARAMETER);
342         return FALSE;
343     }
344
345     if (!hEventLog)
346     {
347         SetLastError(ERROR_INVALID_HANDLE);
348         return FALSE;
349     }
350
351     *NumberOfRecords = 0;
352
353     return TRUE;
354 }
355
356 /******************************************************************************
357  * GetOldestEventLogRecord [ADVAPI32.@]
358  *
359  * Retrieves the absolute record number of the oldest record in an even log.
360  *
361  * PARAMS
362  *  hEventLog    [I] Handle to an open event log.
363  *  OldestRecord [O] Absolute record number of the oldest record.
364  *
365  * RETURNS
366  *  Success: nonzero. OldestRecord contains the record number of the oldest
367  *           record in the log.
368  *  Failure: zero 
369  */
370 BOOL WINAPI GetOldestEventLogRecord( HANDLE hEventLog, PDWORD OldestRecord )
371 {
372     FIXME("(%p,%p) stub\n", hEventLog, OldestRecord);
373
374     if (!OldestRecord)
375     {
376         SetLastError(ERROR_INVALID_PARAMETER);
377         return FALSE;
378     }
379
380     if (!hEventLog)
381     {
382         SetLastError(ERROR_INVALID_HANDLE);
383         return FALSE;
384     }
385
386     *OldestRecord = 0;
387
388     return TRUE;
389 }
390
391 /******************************************************************************
392  * NotifyChangeEventLog [ADVAPI32.@]
393  *
394  * Enables an application to receive notification when an event is written
395  * to an event log.
396  *
397  * PARAMS
398  *  hEventLog [I] Handle to an event log.
399  *  hEvent    [I] Handle to a manual-reset event object.
400  *
401  * RETURNS
402  *  Success: nonzero
403  *  Failure: zero
404  */
405 BOOL WINAPI NotifyChangeEventLog( HANDLE hEventLog, HANDLE hEvent )
406 {
407         FIXME("(%p,%p) stub\n", hEventLog, hEvent);
408         return TRUE;
409 }
410
411 /******************************************************************************
412  * OpenBackupEventLogA [ADVAPI32.@]
413  *
414  * Opens a handle to a backup event log.
415  *
416  * PARAMS
417  *  lpUNCServerName [I] Universal Naming Convention name of the server on which
418  *                      this will be performed.
419  *  lpFileName      [I] Specifies the name of the backup file.
420  *
421  * RETURNS
422  *  Success: Handle to the backup event log.
423  *  Failure: NULL
424  */
425 HANDLE WINAPI OpenBackupEventLogA( LPCSTR lpUNCServerName, LPCSTR lpFileName )
426 {
427     LPWSTR uncnameW, filenameW;
428     HANDLE handle;
429
430     uncnameW = SERV_dup(lpUNCServerName);
431     filenameW = SERV_dup(lpFileName);
432     handle = OpenBackupEventLogW(uncnameW, filenameW);
433     HeapFree(GetProcessHeap(), 0, uncnameW);
434     HeapFree(GetProcessHeap(), 0, filenameW);
435
436     return handle;
437 }
438
439 /******************************************************************************
440  * OpenBackupEventLogW [ADVAPI32.@]
441  *
442  * See OpenBackupEventLogA.
443  */
444 HANDLE WINAPI OpenBackupEventLogW( LPCWSTR lpUNCServerName, LPCWSTR lpFileName )
445 {
446     FIXME("(%s,%s) stub\n", debugstr_w(lpUNCServerName), debugstr_w(lpFileName));
447
448     if (!lpFileName)
449     {
450         SetLastError(ERROR_INVALID_PARAMETER);
451         return NULL;
452     }
453
454     if (lpUNCServerName && lpUNCServerName[0])
455     {
456         FIXME("Remote server not supported\n");
457         SetLastError(RPC_S_SERVER_UNAVAILABLE);
458         return NULL;
459     }
460
461     if (GetFileAttributesW(lpFileName) == INVALID_FILE_ATTRIBUTES)
462     {
463         SetLastError(ERROR_FILE_NOT_FOUND);
464         return NULL;
465     }
466
467     return (HANDLE)0xcafe4242;
468 }
469
470 /******************************************************************************
471  * OpenEventLogA [ADVAPI32.@]
472  *
473  * Opens a handle to the specified event log.
474  *
475  * PARAMS
476  *  lpUNCServerName [I] UNC name of the server on which the event log is
477  *                      opened.
478  *  lpSourceName    [I] Name of the log.
479  *
480  * RETURNS
481  *  Success: Handle to an event log.
482  *  Failure: NULL
483  */
484 HANDLE WINAPI OpenEventLogA( LPCSTR uncname, LPCSTR source )
485 {
486     LPWSTR uncnameW, sourceW;
487     HANDLE handle;
488
489     uncnameW = SERV_dup(uncname);
490     sourceW = SERV_dup(source);
491     handle = OpenEventLogW(uncnameW, sourceW);
492     HeapFree(GetProcessHeap(), 0, uncnameW);
493     HeapFree(GetProcessHeap(), 0, sourceW);
494
495     return handle;
496 }
497
498 /******************************************************************************
499  * OpenEventLogW [ADVAPI32.@]
500  *
501  * See OpenEventLogA.
502  */
503 HANDLE WINAPI OpenEventLogW( LPCWSTR uncname, LPCWSTR source )
504 {
505     FIXME("(%s,%s) stub\n", debugstr_w(uncname), debugstr_w(source));
506
507     if (!source)
508     {
509         SetLastError(ERROR_INVALID_PARAMETER);
510         return NULL;
511     }
512
513     if (uncname && uncname[0])
514     {
515         FIXME("Remote server not supported\n");
516         SetLastError(RPC_S_SERVER_UNAVAILABLE);
517         return NULL;
518     }
519
520     return (HANDLE)0xcafe4242;
521 }
522
523 /******************************************************************************
524  * QueryAllTracesW [ADVAPI32.@]
525  *
526  * Query information for started event trace sessions
527  *
528  */
529 ULONG WINAPI QueryAllTracesW( PEVENT_TRACE_PROPERTIES * parray, ULONG arraycount, PULONG psessioncount )
530 {
531     FIXME("(%p, %d, %p) stub\n", parray, arraycount, psessioncount);
532
533     if (psessioncount) *psessioncount = 0;
534     return ERROR_SUCCESS;
535 }
536
537 /******************************************************************************
538  * QueryAllTracesA [ADVAPI32.@]
539  *
540  * See QueryAllTracesW.
541  */
542 ULONG WINAPI QueryAllTracesA( PEVENT_TRACE_PROPERTIES * parray, ULONG arraycount, PULONG psessioncount )
543 {
544     FIXME("(%p, %d, %p) stub\n", parray, arraycount, psessioncount);
545
546     if (psessioncount) *psessioncount = 0;
547     return ERROR_SUCCESS;
548 }
549
550 /******************************************************************************
551  * ReadEventLogA [ADVAPI32.@]
552  *
553  * Reads a whole number of entries from an event log.
554  *
555  * PARAMS
556  *  hEventLog                [I] Handle of the event log to read.
557  *  dwReadFlags              [I] see MSDN doc.
558  *  dwRecordOffset           [I] Log-entry record number to start at.
559  *  lpBuffer                 [O] Buffer for the data read.
560  *  nNumberOfBytesToRead     [I] Size of lpBuffer.
561  *  pnBytesRead              [O] Receives number of bytes read.
562  *  pnMinNumberOfBytesNeeded [O] Receives number of bytes required for the
563  *                               next log entry.
564  *
565  * RETURNS
566  *  Success: nonzero
567  *  Failure: zero
568  */
569 BOOL WINAPI ReadEventLogA( HANDLE hEventLog, DWORD dwReadFlags, DWORD dwRecordOffset,
570     LPVOID lpBuffer, DWORD nNumberOfBytesToRead, DWORD *pnBytesRead, DWORD *pnMinNumberOfBytesNeeded )
571 {
572     FIXME("(%p,0x%08x,0x%08x,%p,0x%08x,%p,%p) stub\n", hEventLog, dwReadFlags,
573           dwRecordOffset, lpBuffer, nNumberOfBytesToRead, pnBytesRead, pnMinNumberOfBytesNeeded);
574
575     SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
576     return FALSE;
577 }
578
579 /******************************************************************************
580  * ReadEventLogW [ADVAPI32.@]
581  *
582  * See ReadEventLogA.
583  */
584 BOOL WINAPI ReadEventLogW( HANDLE hEventLog, DWORD dwReadFlags, DWORD dwRecordOffset,
585     LPVOID lpBuffer, DWORD nNumberOfBytesToRead, DWORD *pnBytesRead, DWORD *pnMinNumberOfBytesNeeded )
586 {
587     FIXME("(%p,0x%08x,0x%08x,%p,0x%08x,%p,%p) stub\n", hEventLog, dwReadFlags,
588           dwRecordOffset, lpBuffer, nNumberOfBytesToRead, pnBytesRead, pnMinNumberOfBytesNeeded);
589
590     SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
591     return FALSE;
592 }
593
594 /******************************************************************************
595  * RegisterEventSourceA [ADVAPI32.@]
596  *
597  * Returns a registered handle to an event log.
598  *
599  * PARAMS
600  *  lpUNCServerName [I] UNC name of the source server.
601  *  lpSourceName    [I] Specifies the name of the event source to retrieve.
602  *
603  * RETURNS
604  *  Success: Handle to the event log.
605  *  Failure: NULL. Returns ERROR_INVALID_HANDLE if lpSourceName specifies the
606  *           Security event log.
607  */
608 HANDLE WINAPI RegisterEventSourceA( LPCSTR lpUNCServerName, LPCSTR lpSourceName )
609 {
610     UNICODE_STRING lpUNCServerNameW;
611     UNICODE_STRING lpSourceNameW;
612     HANDLE ret;
613
614     FIXME("(%s,%s): stub\n", debugstr_a(lpUNCServerName), debugstr_a(lpSourceName));
615
616     RtlCreateUnicodeStringFromAsciiz(&lpUNCServerNameW, lpUNCServerName);
617     RtlCreateUnicodeStringFromAsciiz(&lpSourceNameW, lpSourceName);
618     ret = RegisterEventSourceW(lpUNCServerNameW.Buffer,lpSourceNameW.Buffer);
619     RtlFreeUnicodeString (&lpUNCServerNameW);
620     RtlFreeUnicodeString (&lpSourceNameW);
621     return ret;
622 }
623
624 /******************************************************************************
625  * RegisterEventSourceW [ADVAPI32.@]
626  *
627  * See RegisterEventSourceA.
628  */
629 HANDLE WINAPI RegisterEventSourceW( LPCWSTR lpUNCServerName, LPCWSTR lpSourceName )
630 {
631     FIXME("(%s,%s): stub\n", debugstr_w(lpUNCServerName), debugstr_w(lpSourceName));
632     return (HANDLE)0xcafe4242;
633 }
634
635 /******************************************************************************
636  * ReportEventA [ADVAPI32.@]
637  *
638  * Writes an entry at the end of an event log.
639  *
640  * PARAMS
641  *  hEventLog   [I] Handle of an event log.
642  *  wType       [I] See MSDN doc.
643  *  wCategory   [I] Event category.
644  *  dwEventID   [I] Event identifier.
645  *  lpUserSid   [I] Current user's security identifier.
646  *  wNumStrings [I] Number of insert strings in lpStrings.
647  *  dwDataSize  [I] Size of event-specific raw data to write.
648  *  lpStrings   [I] Buffer containing an array of string to be merged.
649  *  lpRawData   [I] Buffer containing the binary data.
650  *
651  * RETURNS
652  *  Success: nonzero. Entry was written to the log.
653  *  Failure: zero.
654  *
655  * NOTES
656  *  The ReportEvent function adds the time, the entry's length, and the
657  *  offsets before storing the entry in the log. If lpUserSid != NULL, the
658  *  username is also logged.
659  */
660 BOOL WINAPI ReportEventA ( HANDLE hEventLog, WORD wType, WORD wCategory, DWORD dwEventID,
661     PSID lpUserSid, WORD wNumStrings, DWORD dwDataSize, LPCSTR *lpStrings, LPVOID lpRawData)
662 {
663     LPWSTR *wideStrArray;
664     UNICODE_STRING str;
665     int i;
666     BOOL ret;
667
668     FIXME("(%p,0x%04x,0x%04x,0x%08x,%p,0x%04x,0x%08x,%p,%p): stub\n", hEventLog,
669           wType, wCategory, dwEventID, lpUserSid, wNumStrings, dwDataSize, lpStrings, lpRawData);
670
671     if (wNumStrings == 0) return TRUE;
672     if (!lpStrings) return TRUE;
673
674     wideStrArray = HeapAlloc(GetProcessHeap(), 0, sizeof(LPWSTR) * wNumStrings);
675     for (i = 0; i < wNumStrings; i++)
676     {
677         RtlCreateUnicodeStringFromAsciiz(&str, lpStrings[i]);
678         wideStrArray[i] = str.Buffer;
679     }
680     ret = ReportEventW(hEventLog, wType, wCategory, dwEventID, lpUserSid,
681                        wNumStrings, dwDataSize, (LPCWSTR *)wideStrArray, lpRawData);
682     for (i = 0; i < wNumStrings; i++)
683     {
684         HeapFree( GetProcessHeap(), 0, wideStrArray[i] );
685     }
686     HeapFree(GetProcessHeap(), 0, wideStrArray);
687     return ret;
688 }
689
690 /******************************************************************************
691  * ReportEventW [ADVAPI32.@]
692  *
693  * See ReportEventA.
694  */
695 BOOL WINAPI ReportEventW( HANDLE hEventLog, WORD wType, WORD wCategory, DWORD dwEventID,
696     PSID lpUserSid, WORD wNumStrings, DWORD dwDataSize, LPCWSTR *lpStrings, LPVOID lpRawData )
697 {
698     int i;
699
700     FIXME("(%p,0x%04x,0x%04x,0x%08x,%p,0x%04x,0x%08x,%p,%p): stub\n", hEventLog,
701           wType, wCategory, dwEventID, lpUserSid, wNumStrings, dwDataSize, lpStrings, lpRawData);
702
703     /* partial stub */
704
705     if (wNumStrings == 0) return TRUE;
706     if (!lpStrings) return TRUE;
707
708     for (i = 0; i < wNumStrings; i++)
709     {
710         switch (wType)
711         {
712         case EVENTLOG_SUCCESS:
713             TRACE_(eventlog)("%s\n", debugstr_w(lpStrings[i]));
714             break;
715         case EVENTLOG_ERROR_TYPE:
716             ERR_(eventlog)("%s\n", debugstr_w(lpStrings[i]));
717             break;
718         case EVENTLOG_WARNING_TYPE:
719             WARN_(eventlog)("%s\n", debugstr_w(lpStrings[i]));
720             break;
721         default:
722             TRACE_(eventlog)("%s\n", debugstr_w(lpStrings[i]));
723             break;
724         }
725     }
726     return TRUE;
727 }
728
729 /******************************************************************************
730  * RegisterTraceGuidsW [ADVAPI32.@]
731  *
732  * Register an event trace provider and the event trace classes that it uses
733  * to generate events.
734  *
735  * PARAMS
736  *  RequestAddress     [I]   ControlCallback function
737  *  RequestContext     [I]   Optional provider-defined context
738  *  ControlGuid        [I]   GUID of the registering provider
739  *  GuidCount          [I]   Number of elements in the TraceGuidReg array
740  *  TraceGuidReg       [I/O] Array of TRACE_GUID_REGISTRATION structures
741  *  MofImagePath       [I]   not supported, set to NULL
742  *  MofResourceNmae    [I]   not supported, set to NULL
743  *  RegistrationHandle [O]   Provider's registration handle
744  *
745  * RETURNS
746  *  Success: ERROR_SUCCESS
747  *  Failure: System error code
748  *
749  * FIXME
750  *  Stub.
751  */
752 ULONG WINAPI RegisterTraceGuidsW( WMIDPREQUEST RequestAddress,
753                 PVOID RequestContext, LPCGUID ControlGuid, ULONG GuidCount,
754                 PTRACE_GUID_REGISTRATION TraceGuidReg, LPCWSTR MofImagePath,
755                 LPCWSTR MofResourceName, PTRACEHANDLE RegistrationHandle )
756 {
757     FIXME("(%p, %p, %s, %u, %p, %s, %s, %p,): stub\n", RequestAddress, RequestContext,
758           debugstr_guid(ControlGuid), GuidCount, TraceGuidReg, debugstr_w(MofImagePath),
759           debugstr_w(MofResourceName), RegistrationHandle);
760     return ERROR_SUCCESS;
761 }
762
763 /******************************************************************************
764  * RegisterTraceGuidsA [ADVAPI32.@]
765  *
766  * See RegisterTraceGuidsW.
767  *
768  * FIXME
769  *  Stub.
770  */
771 ULONG WINAPI RegisterTraceGuidsA( WMIDPREQUEST RequestAddress,
772                 PVOID RequestContext, LPCGUID ControlGuid, ULONG GuidCount,
773                 PTRACE_GUID_REGISTRATION TraceGuidReg, LPCSTR MofImagePath,
774                 LPCSTR MofResourceName, PTRACEHANDLE RegistrationHandle )
775 {
776     FIXME("(%p, %p, %s, %u, %p, %s, %s, %p,): stub\n", RequestAddress, RequestContext,
777           debugstr_guid(ControlGuid), GuidCount, TraceGuidReg, debugstr_a(MofImagePath),
778           debugstr_a(MofResourceName), RegistrationHandle);
779     return ERROR_SUCCESS;
780 }
781
782 /******************************************************************************
783  * StartTraceW [ADVAPI32.@]
784  *
785  * Register and start an event trace session
786  *
787  */
788 ULONG WINAPI StartTraceW( PTRACEHANDLE pSessionHandle, LPCWSTR SessionName, PEVENT_TRACE_PROPERTIES Properties )
789 {
790     FIXME("(%p, %s, %p) stub\n", pSessionHandle, debugstr_w(SessionName), Properties);
791     if (pSessionHandle) *pSessionHandle = 0xcafe4242;
792     return ERROR_SUCCESS;
793 }
794
795 /******************************************************************************
796  * StartTraceA [ADVAPI32.@]
797  *
798  * See StartTraceW.
799  *
800  */
801 ULONG WINAPI StartTraceA( PTRACEHANDLE pSessionHandle, LPCSTR SessionName, PEVENT_TRACE_PROPERTIES Properties )
802 {
803     FIXME("(%p, %s, %p) stub\n", pSessionHandle, debugstr_a(SessionName), Properties);
804     if (pSessionHandle) *pSessionHandle = 0xcafe4242;
805     return ERROR_SUCCESS;
806 }
807
808 /******************************************************************************
809  * TraceEvent [ADVAPI32.@]
810  */
811 ULONG WINAPI TraceEvent( TRACEHANDLE SessionHandle, PEVENT_TRACE_HEADER EventTrace )
812 {
813     FIXME("%s %p\n", wine_dbgstr_longlong(SessionHandle), EventTrace);
814     return ERROR_CALL_NOT_IMPLEMENTED;
815 }
816
817 /******************************************************************************
818  * UnregisterTraceGuids [ADVAPI32.@]
819  *
820  * See RegisterTraceGuids
821  *
822  * FIXME
823  *  Stub.
824  */
825 ULONG WINAPI UnregisterTraceGuids( TRACEHANDLE RegistrationHandle )
826 {
827     FIXME("%s: stub\n", wine_dbgstr_longlong(RegistrationHandle));
828     return ERROR_CALL_NOT_IMPLEMENTED;
829 }
830
831 /******************************************************************************
832  * EventRegister [ADVAPI32.@]
833  */
834 ULONG WINAPI EventRegister( LPCGUID provider, PENABLECALLBACK callback, PVOID context, PREGHANDLE handle )
835 {
836     FIXME("%s, %p, %p, %p\n", debugstr_guid(provider), callback, context, handle);
837     return ERROR_CALL_NOT_IMPLEMENTED;
838 }
839
840 /******************************************************************************
841  * EventEnabled [ADVAPI32.@]
842  *
843  */
844 BOOLEAN WINAPI EventEnabled( REGHANDLE handle, PCEVENT_DESCRIPTOR descriptor )
845 {
846     FIXME("(%s, %p): stub\n", wine_dbgstr_longlong(handle), descriptor);
847     return FALSE;
848 }
849
850 /******************************************************************************
851  * QueryTraceW [ADVAPI32.@]
852  */
853 ULONG WINAPI QueryTraceW( TRACEHANDLE handle, LPCWSTR sessionname, PEVENT_TRACE_PROPERTIES properties )
854 {
855     FIXME("%s %s %p: stub\n", wine_dbgstr_longlong(handle), debugstr_w(sessionname), properties);
856     return ERROR_CALL_NOT_IMPLEMENTED;
857 }
858
859 /******************************************************************************
860  * OpenTraceA [ADVAPI32.@]
861  */
862 TRACEHANDLE WINAPI OpenTraceA( PEVENT_TRACE_LOGFILEA logfile )
863 {
864     FIXME("%p: stub\n", logfile);
865     SetLastError(ERROR_ACCESS_DENIED);
866     return INVALID_PROCESSTRACE_HANDLE;
867 }
868
869 /******************************************************************************
870  * OpenTraceW [ADVAPI32.@]
871  */
872 TRACEHANDLE WINAPI OpenTraceW( PEVENT_TRACE_LOGFILEW logfile )
873 {
874     FIXME("%p: stub\n", logfile);
875     SetLastError(ERROR_ACCESS_DENIED);
876     return INVALID_PROCESSTRACE_HANDLE;
877 }
878
879 /******************************************************************************
880  * ProcessTrace [ADVAPI32.@]
881  */
882 ULONG WINAPI ProcessTrace( PTRACEHANDLE HandleArray, ULONG HandleCount, LPFILETIME StartTime, LPFILETIME EndTime)
883 {
884     FIXME("%p %u %p %p: stub\n", HandleArray, HandleCount, StartTime, EndTime);
885     return ERROR_CALL_NOT_IMPLEMENTED;
886 }
887
888 ULONG TraceMessage( TRACEHANDLE SessionHandle, ULONG MessageFlags, LPGUID MessageGuid,
889                     USHORT MessageNumber, ...)
890 {
891     FIXME("(%s %d %s %d) : stub\n", wine_dbgstr_longlong(SessionHandle), MessageFlags,
892                     debugstr_guid(MessageGuid), MessageNumber);
893     return ERROR_SUCCESS;
894 }
895
896 ULONG TraceMessageVa( TRACEHANDLE SessionHandle, ULONG MessageFlags, LPGUID MessageGuid,
897                     USHORT MessageNumber, __ms_va_list args)
898 {
899     FIXME("(%s %d %s %d) : stub\n", wine_dbgstr_longlong(SessionHandle), MessageFlags,
900                     debugstr_guid(MessageGuid), MessageNumber);
901     return ERROR_SUCCESS;
902 }