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