SEH protect all remote calls to the Eventlog Service.
[reactos.git] / reactos / dll / win32 / advapi32 / service / eventlog.c
1 /*
2 * Win32 advapi functions
3 *
4 * Copyright 1995 Sven Verdoolaege
5 * Copyright 1998 Juergen Schmied
6 * Copyright 2003 Mike Hearn
7 * Copyright 2007 Hervé Poussineau
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24 #include <advapi32.h>
25 #include "wine/debug.h"
26
27 WINE_DEFAULT_DEBUG_CHANNEL(advapi);
28 WINE_DECLARE_DEBUG_CHANNEL(eventlog);
29
30 static RPC_UNICODE_STRING EmptyString = { 0, 0, L"" };
31
32
33 handle_t __RPC_USER
34 EVENTLOG_HANDLE_A_bind(EVENTLOG_HANDLE_A UNCServerName)
35 {
36 handle_t hBinding = NULL;
37 UCHAR *pszStringBinding;
38 RPC_STATUS status;
39
40 TRACE("EVENTLOG_HANDLE_A_bind() called\n");
41
42 status = RpcStringBindingComposeA(NULL,
43 (UCHAR *)"ncacn_np",
44 (UCHAR *)UNCServerName,
45 (UCHAR *)"\\pipe\\ntsvcs",
46 NULL,
47 (UCHAR **)&pszStringBinding);
48 if (status)
49 {
50 ERR("RpcStringBindingCompose returned 0x%x\n", status);
51 return NULL;
52 }
53
54 /* Set the binding handle that will be used to bind to the server. */
55 status = RpcBindingFromStringBindingA(pszStringBinding,
56 &hBinding);
57 if (status)
58 {
59 ERR("RpcBindingFromStringBinding returned 0x%x\n", status);
60 }
61
62 status = RpcStringFreeA(&pszStringBinding);
63 if (status)
64 {
65 ERR("RpcStringFree returned 0x%x\n", status);
66 }
67
68 return hBinding;
69 }
70
71
72 void __RPC_USER
73 EVENTLOG_HANDLE_A_unbind(EVENTLOG_HANDLE_A UNCServerName,
74 handle_t hBinding)
75 {
76 RPC_STATUS status;
77
78 TRACE("EVENTLOG_HANDLE_A_unbind() called\n");
79
80 status = RpcBindingFree(&hBinding);
81 if (status)
82 {
83 ERR("RpcBindingFree returned 0x%x\n", status);
84 }
85 }
86
87
88 handle_t __RPC_USER
89 EVENTLOG_HANDLE_W_bind(EVENTLOG_HANDLE_W UNCServerName)
90 {
91 handle_t hBinding = NULL;
92 LPWSTR pszStringBinding;
93 RPC_STATUS status;
94
95 TRACE("EVENTLOG_HANDLE_W_bind() called\n");
96
97 status = RpcStringBindingComposeW(NULL,
98 L"ncacn_np",
99 (LPWSTR)UNCServerName,
100 L"\\pipe\\EventLog",
101 NULL,
102 &pszStringBinding);
103 if (status)
104 {
105 ERR("RpcStringBindingCompose returned 0x%x\n", status);
106 return NULL;
107 }
108
109 /* Set the binding handle that will be used to bind to the server. */
110 status = RpcBindingFromStringBindingW(pszStringBinding,
111 &hBinding);
112 if (status)
113 {
114 ERR("RpcBindingFromStringBinding returned 0x%x\n", status);
115 }
116
117 status = RpcStringFreeW(&pszStringBinding);
118 if (status)
119 {
120 ERR("RpcStringFree returned 0x%x\n", status);
121 }
122
123 return hBinding;
124 }
125
126
127 void __RPC_USER
128 EVENTLOG_HANDLE_W_unbind(EVENTLOG_HANDLE_W UNCServerName,
129 handle_t hBinding)
130 {
131 RPC_STATUS status;
132
133 TRACE("EVENTLOG_HANDLE_W_unbind() called\n");
134
135 status = RpcBindingFree(&hBinding);
136 if (status)
137 {
138 ERR("RpcBindingFree returned 0x%x\n", status);
139 }
140 }
141
142
143 /******************************************************************************
144 * BackupEventLogA [ADVAPI32.@]
145 */
146 BOOL WINAPI
147 BackupEventLogA(IN HANDLE hEventLog,
148 IN LPCSTR lpBackupFileName)
149 {
150 RPC_STRING BackupFileName;
151 NTSTATUS Status;
152
153 TRACE("%p, %s\n", hEventLog, lpBackupFileName);
154
155 BackupFileName.Buffer = (LPSTR)lpBackupFileName;
156 BackupFileName.Length = BackupFileName.MaximumLength =
157 lpBackupFileName ? strlen(lpBackupFileName) : 0;
158
159 _SEH_TRY
160 {
161 Status = ElfrBackupELFA(hEventLog,
162 &BackupFileName);
163 }
164 _SEH_HANDLE
165 {
166 Status = I_RpcMapWin32Status(RpcExceptionCode());
167 }
168 _SEH_END;
169
170 if (!NT_SUCCESS(Status))
171 {
172 SetLastError(RtlNtStatusToDosError(Status));
173 return FALSE;
174 }
175
176 return TRUE;
177 }
178
179 /******************************************************************************
180 * BackupEventLogW [ADVAPI32.@]
181 *
182 * PARAMS
183 * hEventLog []
184 * lpBackupFileName []
185 */
186 BOOL WINAPI
187 BackupEventLogW(IN HANDLE hEventLog,
188 IN LPCWSTR lpBackupFileName)
189 {
190 RPC_UNICODE_STRING BackupFileName;
191 NTSTATUS Status;
192
193 TRACE("%p, %s\n", hEventLog, debugstr_w(lpBackupFileName));
194
195 BackupFileName.Buffer = (LPWSTR)lpBackupFileName;
196 BackupFileName.Length = BackupFileName.MaximumLength =
197 lpBackupFileName ? wcslen(lpBackupFileName) * sizeof(WCHAR) : 0;
198
199 _SEH_TRY
200 {
201 Status = ElfrBackupELFW(hEventLog,
202 &BackupFileName);
203 }
204 _SEH_HANDLE
205 {
206 Status = I_RpcMapWin32Status(RpcExceptionCode());
207 }
208 _SEH_END;
209
210 if (!NT_SUCCESS(Status))
211 {
212 SetLastError(RtlNtStatusToDosError(Status));
213 return FALSE;
214 }
215
216 return TRUE;
217 }
218
219
220 /******************************************************************************
221 * ClearEventLogA [ADVAPI32.@]
222 */
223 BOOL WINAPI
224 ClearEventLogA(IN HANDLE hEventLog,
225 IN LPCSTR lpBackupFileName)
226 {
227 RPC_STRING BackupFileName;
228 NTSTATUS Status;
229
230 TRACE("%p, %s\n", hEventLog, lpBackupFileName);
231
232 BackupFileName.Buffer = (LPSTR)lpBackupFileName;
233 BackupFileName.Length = BackupFileName.MaximumLength =
234 lpBackupFileName ? strlen(lpBackupFileName) : 0;
235
236 _SEH_TRY
237 {
238 Status = ElfrClearELFA(hEventLog,
239 &BackupFileName);
240 }
241 _SEH_HANDLE
242 {
243 Status = I_RpcMapWin32Status(RpcExceptionCode());
244 }
245 _SEH_END;
246
247 if (!NT_SUCCESS(Status))
248 {
249 SetLastError(RtlNtStatusToDosError(Status));
250 return FALSE;
251 }
252
253 return TRUE;
254 }
255
256
257 /******************************************************************************
258 * ClearEventLogW [ADVAPI32.@]
259 */
260 BOOL WINAPI
261 ClearEventLogW(IN HANDLE hEventLog,
262 IN LPCWSTR lpBackupFileName)
263 {
264 RPC_UNICODE_STRING BackupFileName;
265 NTSTATUS Status;
266
267 TRACE("%p, %s\n", hEventLog, debugstr_w(lpBackupFileName));
268
269 BackupFileName.Buffer = (LPWSTR)lpBackupFileName;
270 BackupFileName.Length = BackupFileName.MaximumLength =
271 lpBackupFileName ? wcslen(lpBackupFileName) * sizeof(WCHAR) : 0;
272
273 _SEH_TRY
274 {
275 Status = ElfrClearELFW(hEventLog,
276 &BackupFileName);
277 }
278 _SEH_HANDLE
279 {
280 Status = I_RpcMapWin32Status(RpcExceptionCode());
281 }
282 _SEH_END;
283
284 if (!NT_SUCCESS(Status))
285 {
286 SetLastError(RtlNtStatusToDosError(Status));
287 return FALSE;
288 }
289
290 return TRUE;
291 }
292
293
294 /******************************************************************************
295 * CloseEventLog [ADVAPI32.@]
296 */
297 BOOL WINAPI
298 CloseEventLog(IN HANDLE hEventLog)
299 {
300 NTSTATUS Status;
301
302 TRACE("%p\n", hEventLog);
303
304 _SEH_TRY
305 {
306 Status = ElfrCloseEL(&hEventLog);
307 }
308 _SEH_HANDLE
309 {
310 Status = I_RpcMapWin32Status(RpcExceptionCode());
311 }
312 _SEH_END;
313
314 if (!NT_SUCCESS(Status))
315 {
316 SetLastError(RtlNtStatusToDosError(Status));
317 return FALSE;
318 }
319
320 return TRUE;
321 }
322
323
324 /******************************************************************************
325 * DeregisterEventSource [ADVAPI32.@]
326 * Closes a handle to the specified event log
327 *
328 * PARAMS
329 * hEventLog [I] Handle to event log
330 *
331 * RETURNS STD
332 */
333 BOOL WINAPI
334 DeregisterEventSource(IN HANDLE hEventLog)
335 {
336 NTSTATUS Status;
337
338 TRACE("%p\n", hEventLog);
339
340 _SEH_TRY
341 {
342 Status = ElfrDeregisterEventSource(&hEventLog);
343 }
344 _SEH_HANDLE
345 {
346 Status = I_RpcMapWin32Status(RpcExceptionCode());
347 }
348 _SEH_END;
349
350 if (!NT_SUCCESS(Status))
351 {
352 SetLastError(RtlNtStatusToDosError(Status));
353 return FALSE;
354 }
355
356 return TRUE;
357 }
358
359
360 /******************************************************************************
361 * GetNumberOfEventLogRecords [ADVAPI32.@]
362 *
363 * PARAMS
364 * hEventLog []
365 * NumberOfRecords []
366 */
367 BOOL WINAPI
368 GetNumberOfEventLogRecords(IN HANDLE hEventLog,
369 OUT PDWORD NumberOfRecords)
370 {
371 NTSTATUS Status;
372 DWORD Records;
373
374 TRACE("%p, %p\n", hEventLog, NumberOfRecords);
375
376 _SEH_TRY
377 {
378 Status = ElfrNumberOfRecords(hEventLog,
379 &Records);
380 }
381 _SEH_HANDLE
382 {
383 Status = I_RpcMapWin32Status(RpcExceptionCode());
384 }
385 _SEH_END;
386
387 if (!NT_SUCCESS(Status))
388 {
389 SetLastError(RtlNtStatusToDosError(Status));
390 return FALSE;
391 }
392
393 *NumberOfRecords = Records;
394
395 return TRUE;
396 }
397
398
399 /******************************************************************************
400 * GetOldestEventLogRecord [ADVAPI32.@]
401 *
402 * PARAMS
403 * hEventLog []
404 * OldestRecord []
405 */
406 BOOL WINAPI
407 GetOldestEventLogRecord(IN HANDLE hEventLog,
408 OUT PDWORD OldestRecord)
409 {
410 NTSTATUS Status;
411 DWORD Oldest;
412
413 TRACE("%p, %p\n", hEventLog, OldestRecord);
414
415 _SEH_TRY
416 {
417 Status = ElfrOldestRecord(hEventLog,
418 &Oldest);
419 }
420 _SEH_HANDLE
421 {
422 Status = I_RpcMapWin32Status(RpcExceptionCode());
423 }
424 _SEH_END;
425
426 if (!NT_SUCCESS(Status))
427 {
428 SetLastError(RtlNtStatusToDosError(Status));
429 return FALSE;
430 }
431
432 *OldestRecord = Oldest;
433
434 return TRUE;
435 }
436
437
438 /******************************************************************************
439 * NotifyChangeEventLog [ADVAPI32.@]
440 *
441 * PARAMS
442 * hEventLog []
443 * hEvent []
444 */
445 BOOL WINAPI
446 NotifyChangeEventLog(IN HANDLE hEventLog,
447 IN HANDLE hEvent)
448 {
449 /* Use ElfrChangeNotify */
450 UNIMPLEMENTED;
451 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
452 return FALSE;
453 }
454
455
456 /******************************************************************************
457 * OpenBackupEventLogA [ADVAPI32.@]
458 */
459 HANDLE WINAPI
460 OpenBackupEventLogA(IN LPCSTR lpUNCServerName,
461 IN LPCSTR lpFileName)
462 {
463 UNICODE_STRING UNCServerName;
464 UNICODE_STRING FileName;
465 HANDLE Handle;
466
467 TRACE("%s, %s\n", lpUNCServerName, lpFileName);
468
469 if (!RtlCreateUnicodeStringFromAsciiz(&UNCServerName, lpUNCServerName))
470 {
471 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
472 return NULL;
473 }
474
475 if (!RtlCreateUnicodeStringFromAsciiz(&FileName, lpFileName))
476 {
477 RtlFreeUnicodeString(&UNCServerName);
478 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
479 return NULL;
480 }
481
482 Handle = OpenBackupEventLogW(UNCServerName.Buffer,
483 FileName.Buffer);
484
485 RtlFreeUnicodeString(&UNCServerName);
486 RtlFreeUnicodeString(&FileName);
487
488 return Handle;
489 }
490
491
492 /******************************************************************************
493 * OpenBackupEventLogW [ADVAPI32.@]
494 *
495 * PARAMS
496 * lpUNCServerName []
497 * lpFileName []
498 */
499 HANDLE WINAPI
500 OpenBackupEventLogW(IN LPCWSTR lpUNCServerName,
501 IN LPCWSTR lpFileName)
502 {
503 RPC_UNICODE_STRING FileName;
504 IELF_HANDLE LogHandle;
505 NTSTATUS Status;
506
507 TRACE("%s, %s\n", debugstr_w(lpUNCServerName), debugstr_w(lpFileName));
508
509 FileName.Buffer = (LPWSTR)lpFileName;
510 FileName.Length = FileName.MaximumLength =
511 lpFileName ? wcslen(lpFileName) * sizeof(WCHAR) : 0;
512
513 _SEH_TRY
514 {
515 Status = ElfrOpenBELW((LPWSTR)lpUNCServerName,
516 &FileName,
517 0,
518 0,
519 &LogHandle);
520 }
521 _SEH_HANDLE
522 {
523 Status = I_RpcMapWin32Status(RpcExceptionCode());
524 }
525 _SEH_END;
526
527 if (!NT_SUCCESS(Status))
528 {
529 SetLastError(RtlNtStatusToDosError(Status));
530 return NULL;
531 }
532
533 return (HANDLE)LogHandle;
534 }
535
536
537 /******************************************************************************
538 * OpenEventLogA [ADVAPI32.@]
539 */
540 HANDLE WINAPI
541 OpenEventLogA(IN LPCSTR lpUNCServerName,
542 IN LPCSTR lpSourceName)
543 {
544 UNICODE_STRING UNCServerName;
545 UNICODE_STRING SourceName;
546 HANDLE Handle;
547
548 if (!RtlCreateUnicodeStringFromAsciiz(&UNCServerName, lpUNCServerName))
549 {
550 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
551 return NULL;
552 }
553
554 if (!RtlCreateUnicodeStringFromAsciiz(&SourceName, lpSourceName))
555 {
556 RtlFreeUnicodeString(&UNCServerName);
557 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
558 return NULL;
559 }
560
561 Handle = OpenEventLogW(UNCServerName.Buffer,
562 SourceName.Buffer);
563
564 RtlFreeUnicodeString(&UNCServerName);
565 RtlFreeUnicodeString(&SourceName);
566
567 return Handle;
568 }
569
570
571 /******************************************************************************
572 * OpenEventLogW [ADVAPI32.@]
573 *
574 * PARAMS
575 * lpUNCServerName []
576 * lpSourceName []
577 */
578 HANDLE WINAPI
579 OpenEventLogW(IN LPCWSTR lpUNCServerName,
580 IN LPCWSTR lpSourceName)
581 {
582 RPC_UNICODE_STRING SourceName;
583 IELF_HANDLE LogHandle;
584 NTSTATUS Status;
585
586 TRACE("%s, %s\n", debugstr_w(lpUNCServerName), debugstr_w(lpSourceName));
587
588 SourceName.Buffer = (LPWSTR)lpSourceName;
589 SourceName.Length = SourceName.MaximumLength =
590 lpSourceName ? wcslen(lpSourceName) * sizeof(WCHAR) : 0;
591
592 _SEH_TRY
593 {
594 Status = ElfrOpenELW((LPWSTR)lpUNCServerName,
595 &SourceName,
596 &EmptyString,
597 0,
598 0,
599 &LogHandle);
600 }
601 _SEH_HANDLE
602 {
603 Status = I_RpcMapWin32Status(RpcExceptionCode());
604 }
605 _SEH_END;
606
607 if (!NT_SUCCESS(Status))
608 {
609 SetLastError(RtlNtStatusToDosError(Status));
610 return NULL;
611 }
612
613 return (HANDLE)LogHandle;
614 }
615
616
617 /******************************************************************************
618 * ReadEventLogA [ADVAPI32.@]
619 */
620 BOOL WINAPI
621 ReadEventLogA(IN HANDLE hEventLog,
622 IN DWORD dwReadFlags,
623 IN DWORD dwRecordOffset,
624 OUT LPVOID lpBuffer,
625 IN DWORD nNumberOfBytesToRead,
626 OUT DWORD *pnBytesRead,
627 OUT DWORD *pnMinNumberOfBytesNeeded)
628 {
629 NTSTATUS Status;
630 DWORD bytesRead, minNumberOfBytesNeeded;
631
632 TRACE("%p, %lu, %lu, %p, %lu, %p, %p\n",
633 hEventLog, dwReadFlags, dwRecordOffset, lpBuffer,
634 nNumberOfBytesToRead, pnBytesRead, pnMinNumberOfBytesNeeded);
635
636 _SEH_TRY
637 {
638 Status = ElfrReadELA(hEventLog,
639 dwReadFlags,
640 dwRecordOffset,
641 nNumberOfBytesToRead,
642 lpBuffer,
643 &bytesRead,
644 &minNumberOfBytesNeeded);
645 }
646 _SEH_HANDLE
647 {
648 Status = I_RpcMapWin32Status(RpcExceptionCode());
649 }
650 _SEH_END;
651
652 if (!NT_SUCCESS(Status))
653 {
654 SetLastError(RtlNtStatusToDosError(Status));
655 return FALSE;
656 }
657
658 *pnBytesRead = (DWORD)bytesRead;
659 *pnMinNumberOfBytesNeeded = (DWORD)minNumberOfBytesNeeded;
660
661 return TRUE;
662 }
663
664
665 /******************************************************************************
666 * ReadEventLogW [ADVAPI32.@]
667 *
668 * PARAMS
669 * hEventLog []
670 * dwReadFlags []
671 * dwRecordOffset []
672 * lpBuffer []
673 * nNumberOfBytesToRead []
674 * pnBytesRead []
675 * pnMinNumberOfBytesNeeded []
676 */
677 BOOL WINAPI
678 ReadEventLogW(IN HANDLE hEventLog,
679 IN DWORD dwReadFlags,
680 IN DWORD dwRecordOffset,
681 OUT LPVOID lpBuffer,
682 IN DWORD nNumberOfBytesToRead,
683 OUT DWORD *pnBytesRead,
684 OUT DWORD *pnMinNumberOfBytesNeeded)
685 {
686 NTSTATUS Status;
687 DWORD bytesRead, minNumberOfBytesNeeded;
688
689 TRACE("%p, %lu, %lu, %p, %lu, %p, %p\n",
690 hEventLog, dwReadFlags, dwRecordOffset, lpBuffer,
691 nNumberOfBytesToRead, pnBytesRead, pnMinNumberOfBytesNeeded);
692
693 _SEH_TRY
694 {
695 Status = ElfrReadELW(hEventLog,
696 dwReadFlags,
697 dwRecordOffset,
698 nNumberOfBytesToRead,
699 lpBuffer,
700 &bytesRead,
701 &minNumberOfBytesNeeded);
702 }
703 _SEH_HANDLE
704 {
705 Status = I_RpcMapWin32Status(RpcExceptionCode());
706 }
707 _SEH_END;
708
709 if (!NT_SUCCESS(Status))
710 {
711 SetLastError(RtlNtStatusToDosError(Status));
712 return FALSE;
713 }
714
715 *pnBytesRead = (DWORD)bytesRead;
716 *pnMinNumberOfBytesNeeded = (DWORD)minNumberOfBytesNeeded;
717
718 return TRUE;
719 }
720
721
722 /******************************************************************************
723 * RegisterEventSourceA [ADVAPI32.@]
724 */
725 HANDLE WINAPI
726 RegisterEventSourceA(IN LPCSTR lpUNCServerName,
727 IN LPCSTR lpSourceName)
728 {
729 UNICODE_STRING UNCServerName;
730 UNICODE_STRING SourceName;
731 HANDLE Handle;
732
733 TRACE("%s, %s\n", lpUNCServerName, lpSourceName);
734
735 if (!RtlCreateUnicodeStringFromAsciiz(&UNCServerName, lpUNCServerName))
736 {
737 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
738 return NULL;
739 }
740
741 if (!RtlCreateUnicodeStringFromAsciiz(&SourceName, lpSourceName))
742 {
743 RtlFreeUnicodeString(&UNCServerName);
744 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
745 return NULL;
746 }
747
748 Handle = RegisterEventSourceW(UNCServerName.Buffer,
749 SourceName.Buffer);
750
751 RtlFreeUnicodeString(&UNCServerName);
752 RtlFreeUnicodeString(&SourceName);
753
754 return Handle;
755 }
756
757
758 /******************************************************************************
759 * RegisterEventSourceW [ADVAPI32.@]
760 * Returns a registered handle to an event log
761 *
762 * PARAMS
763 * lpUNCServerName [I] Server name for source
764 * lpSourceName [I] Source name for registered handle
765 *
766 * RETURNS
767 * Success: Handle
768 * Failure: NULL
769 */
770 HANDLE WINAPI
771 RegisterEventSourceW(IN LPCWSTR lpUNCServerName,
772 IN LPCWSTR lpSourceName)
773 {
774 RPC_UNICODE_STRING SourceName;
775 IELF_HANDLE LogHandle;
776 NTSTATUS Status;
777
778 TRACE("%s, %s\n", debugstr_w(lpUNCServerName), debugstr_w(lpSourceName));
779
780 SourceName.Buffer = (LPWSTR)lpSourceName;
781 SourceName.Length = SourceName.MaximumLength =
782 lpSourceName ? wcslen(lpSourceName) * sizeof(WCHAR) : 0;
783
784 _SEH_TRY
785 {
786 Status = ElfrRegisterEventSourceW((LPWSTR)lpUNCServerName,
787 &SourceName,
788 &EmptyString,
789 0,
790 0,
791 &LogHandle);
792 }
793 _SEH_HANDLE
794 {
795 Status = I_RpcMapWin32Status(RpcExceptionCode());
796 }
797 _SEH_END;
798
799 if (!NT_SUCCESS(Status))
800 {
801 SetLastError(RtlNtStatusToDosError(Status));
802 return NULL;
803 }
804
805 return (HANDLE)LogHandle;
806 }
807
808
809 /******************************************************************************
810 * ReportEventA [ADVAPI32.@]
811 */
812 BOOL WINAPI
813 ReportEventA(IN HANDLE hEventLog,
814 IN WORD wType,
815 IN WORD wCategory,
816 IN DWORD dwEventID,
817 IN PSID lpUserSid,
818 IN WORD wNumStrings,
819 IN DWORD dwDataSize,
820 IN LPCSTR *lpStrings,
821 IN LPVOID lpRawData)
822 {
823 LPCWSTR *wideStrArray;
824 UNICODE_STRING str;
825 WORD i;
826 BOOL ret;
827
828 if (wNumStrings == 0)
829 return TRUE;
830
831 if (lpStrings == NULL)
832 return TRUE;
833
834 wideStrArray = HeapAlloc(GetProcessHeap(),
835 HEAP_ZERO_MEMORY,
836 sizeof(LPCWSTR) * wNumStrings);
837
838 for (i = 0; i < wNumStrings; i++)
839 {
840 if (!RtlCreateUnicodeStringFromAsciiz(&str, (PSTR)lpStrings[i]))
841 break;
842 wideStrArray[i] = str.Buffer;
843 }
844
845 if (i == wNumStrings)
846 {
847 ret = ReportEventW(hEventLog,
848 wType,
849 wCategory,
850 dwEventID,
851 lpUserSid,
852 wNumStrings,
853 dwDataSize,
854 wideStrArray,
855 lpRawData);
856 }
857 else
858 {
859 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
860 ret = FALSE;
861 }
862
863 for (i = 0; i < wNumStrings; i++)
864 {
865 if (wideStrArray[i])
866 {
867 HeapFree(GetProcessHeap(),
868 0,
869 (PVOID)wideStrArray[i]);
870 }
871 }
872
873 HeapFree(GetProcessHeap(),
874 0,
875 wideStrArray);
876
877 return ret;
878 }
879
880
881 /******************************************************************************
882 * ReportEventW [ADVAPI32.@]
883 *
884 * PARAMS
885 * hEventLog []
886 * wType []
887 * wCategory []
888 * dwEventID []
889 * lpUserSid []
890 * wNumStrings []
891 * dwDataSize []
892 * lpStrings []
893 * lpRawData []
894 */
895 BOOL WINAPI
896 ReportEventW(IN HANDLE hEventLog,
897 IN WORD wType,
898 IN WORD wCategory,
899 IN DWORD dwEventID,
900 IN PSID lpUserSid,
901 IN WORD wNumStrings,
902 IN DWORD dwDataSize,
903 IN LPCWSTR *lpStrings,
904 IN LPVOID lpRawData)
905 {
906 #if 0
907 NTSTATUS Status;
908 UNICODE_STRING *Strings;
909 WORD i;
910
911 TRACE("%p, %u, %u, %lu, %p, %u, %lu, %p, %p\n",
912 hEventLog, wType, wCategory, dwEventID, lpUserSid,
913 wNumStrings, dwDataSize, lpStrings, lpRawData);
914
915 Strings = HeapAlloc(GetProcessHeap(),
916 0,
917 wNumStrings * sizeof(UNICODE_STRING));
918 if (!Strings)
919 {
920 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
921 return FALSE;
922 }
923
924 for (i = 0; i < wNumStrings; i++)
925 RtlInitUnicodeString(&Strings[i], lpStrings[i]);
926
927 _SEH_TRY
928 {
929 Status = ElfrReportEventW(hEventLog,
930 0, /* FIXME: Time */
931 wType,
932 wCategory,
933 dwEventID,
934 wNumStrings,
935 dwDataSize,
936 L"", /* FIXME: ComputerName */
937 lpUserSid,
938 (LPWSTR *)lpStrings, /* FIXME: should be Strings */
939 lpRawData,
940 0,
941 NULL,
942 NULL);
943 }
944 _SEH_HANDLE
945 {
946 Status = I_RpcMapWin32Status(RpcExceptionCode());
947 }
948 _SEH_END;
949
950 HeapFree(GetProcessHeap(), 0, Strings);
951
952 if (!NT_SUCCESS(Status))
953 {
954 SetLastError(RtlNtStatusToDosError(Status));
955 return FALSE;
956 }
957
958 return TRUE;
959 #else
960 int i;
961
962 /* partial stub */
963
964 if (wNumStrings == 0)
965 return TRUE;
966
967 if (lpStrings == NULL)
968 return TRUE;
969
970 for (i = 0; i < wNumStrings; i++)
971 {
972 switch (wType)
973 {
974 case EVENTLOG_SUCCESS:
975 TRACE_(eventlog)("Success: %S\n", lpStrings[i]);
976 break;
977
978 case EVENTLOG_ERROR_TYPE:
979 ERR_(eventlog)("Error: %S\n", lpStrings[i]);
980 break;
981
982 case EVENTLOG_WARNING_TYPE:
983 WARN_(eventlog)("Warning: %S\n", lpStrings[i]);
984 break;
985
986 case EVENTLOG_INFORMATION_TYPE:
987 TRACE_(eventlog)("Info: %S\n", lpStrings[i]);
988 break;
989
990 default:
991 TRACE_(eventlog)("Type %hu: %S\n", wType, lpStrings[i]);
992 break;
993 }
994 }
995
996 return TRUE;
997 #endif
998 }