b8a35a639b37f99a93a40deb90a03ac4ac4e8e30
[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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24 #include <advapi32.h>
25 #include "wine/debug.h"
26
27 WINE_DEFAULT_DEBUG_CHANNEL(advapi);
28
29 static RPC_UNICODE_STRING EmptyStringU = { 0, 0, L"" };
30 static RPC_STRING EmptyStringA = { 0, 0, "" };
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\\EventLog",
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 ANSI_STRING BackupFileName;
151 NTSTATUS Status;
152
153 TRACE("%p, %s\n", hEventLog, lpBackupFileName);
154
155 RtlInitAnsiString(&BackupFileName, lpBackupFileName);
156
157 RpcTryExcept
158 {
159 Status = ElfrBackupELFA(hEventLog,
160 (PRPC_STRING)&BackupFileName);
161 }
162 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
163 {
164 Status = I_RpcMapWin32Status(RpcExceptionCode());
165 }
166 RpcEndExcept;
167
168 if (!NT_SUCCESS(Status))
169 {
170 SetLastError(RtlNtStatusToDosError(Status));
171 return FALSE;
172 }
173
174 return TRUE;
175 }
176
177 /******************************************************************************
178 * BackupEventLogW [ADVAPI32.@]
179 *
180 * PARAMS
181 * hEventLog []
182 * lpBackupFileName []
183 */
184 BOOL WINAPI
185 BackupEventLogW(IN HANDLE hEventLog,
186 IN LPCWSTR lpBackupFileName)
187 {
188 UNICODE_STRING BackupFileName;
189 NTSTATUS Status;
190
191 TRACE("%p, %s\n", hEventLog, debugstr_w(lpBackupFileName));
192
193 RtlInitUnicodeString(&BackupFileName, lpBackupFileName);
194
195 RpcTryExcept
196 {
197 Status = ElfrBackupELFW(hEventLog,
198 (PRPC_UNICODE_STRING)&BackupFileName);
199 }
200 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
201 {
202 Status = I_RpcMapWin32Status(RpcExceptionCode());
203 }
204 RpcEndExcept;
205
206 if (!NT_SUCCESS(Status))
207 {
208 SetLastError(RtlNtStatusToDosError(Status));
209 return FALSE;
210 }
211
212 return TRUE;
213 }
214
215
216 /******************************************************************************
217 * ClearEventLogA [ADVAPI32.@]
218 */
219 BOOL WINAPI
220 ClearEventLogA(IN HANDLE hEventLog,
221 IN LPCSTR lpBackupFileName)
222 {
223 ANSI_STRING BackupFileName;
224 NTSTATUS Status;
225
226 TRACE("%p, %s\n", hEventLog, lpBackupFileName);
227
228 RtlInitAnsiString(&BackupFileName, lpBackupFileName);
229
230 RpcTryExcept
231 {
232 Status = ElfrClearELFA(hEventLog,
233 (PRPC_STRING)&BackupFileName);
234 }
235 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
236 {
237 Status = I_RpcMapWin32Status(RpcExceptionCode());
238 }
239 RpcEndExcept;
240
241 if (!NT_SUCCESS(Status))
242 {
243 SetLastError(RtlNtStatusToDosError(Status));
244 return FALSE;
245 }
246
247 return TRUE;
248 }
249
250
251 /******************************************************************************
252 * ClearEventLogW [ADVAPI32.@]
253 */
254 BOOL WINAPI
255 ClearEventLogW(IN HANDLE hEventLog,
256 IN LPCWSTR lpBackupFileName)
257 {
258 UNICODE_STRING BackupFileName;
259 NTSTATUS Status;
260
261 TRACE("%p, %s\n", hEventLog, debugstr_w(lpBackupFileName));
262
263 RtlInitUnicodeString(&BackupFileName,lpBackupFileName);
264
265 RpcTryExcept
266 {
267 Status = ElfrClearELFW(hEventLog,
268 (PRPC_UNICODE_STRING)&BackupFileName);
269 }
270 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
271 {
272 Status = I_RpcMapWin32Status(RpcExceptionCode());
273 }
274 RpcEndExcept;
275
276 if (!NT_SUCCESS(Status))
277 {
278 SetLastError(RtlNtStatusToDosError(Status));
279 return FALSE;
280 }
281
282 return TRUE;
283 }
284
285
286 /******************************************************************************
287 * CloseEventLog [ADVAPI32.@]
288 */
289 BOOL WINAPI
290 CloseEventLog(IN HANDLE hEventLog)
291 {
292 NTSTATUS Status;
293
294 TRACE("%p\n", hEventLog);
295
296 RpcTryExcept
297 {
298 Status = ElfrCloseEL(&hEventLog);
299 }
300 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
301 {
302 Status = I_RpcMapWin32Status(RpcExceptionCode());
303 }
304 RpcEndExcept;
305
306 if (!NT_SUCCESS(Status))
307 {
308 SetLastError(RtlNtStatusToDosError(Status));
309 return FALSE;
310 }
311
312 return TRUE;
313 }
314
315
316 /******************************************************************************
317 * DeregisterEventSource [ADVAPI32.@]
318 * Closes a handle to the specified event log
319 *
320 * PARAMS
321 * hEventLog [I] Handle to event log
322 *
323 * RETURNS STD
324 */
325 BOOL WINAPI
326 DeregisterEventSource(IN HANDLE hEventLog)
327 {
328 NTSTATUS Status;
329
330 TRACE("%p\n", hEventLog);
331
332 RpcTryExcept
333 {
334 Status = ElfrDeregisterEventSource(&hEventLog);
335 }
336 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
337 {
338 Status = I_RpcMapWin32Status(RpcExceptionCode());
339 }
340 RpcEndExcept;
341
342 if (!NT_SUCCESS(Status))
343 {
344 SetLastError(RtlNtStatusToDosError(Status));
345 return FALSE;
346 }
347
348 return TRUE;
349 }
350
351
352 /******************************************************************************
353 * GetEventLogInformation [ADVAPI32.@]
354 *
355 * PARAMS
356 * hEventLog [I] Handle to event log
357 * dwInfoLevel [I] Level of event log information to return
358 * lpBuffer [O] Buffer that receives the event log information
359 * cbBufSize [I] Size of the lpBuffer buffer
360 * pcbBytesNeeded [O] Required buffer size
361 */
362 BOOL WINAPI
363 GetEventLogInformation(IN HANDLE hEventLog,
364 IN DWORD dwInfoLevel,
365 OUT LPVOID lpBuffer,
366 IN DWORD cbBufSize,
367 OUT LPDWORD pcbBytesNeeded)
368 {
369 NTSTATUS Status;
370
371 if (dwInfoLevel != EVENTLOG_FULL_INFO)
372 {
373 SetLastError(ERROR_INVALID_LEVEL);
374 return FALSE;
375 }
376
377 RpcTryExcept
378 {
379 Status = ElfrGetLogInformation(hEventLog,
380 dwInfoLevel,
381 (LPBYTE)lpBuffer,
382 cbBufSize,
383 pcbBytesNeeded);
384 }
385 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
386 {
387 Status = I_RpcMapWin32Status(RpcExceptionCode());
388 }
389 RpcEndExcept;
390
391 if (!NT_SUCCESS(Status))
392 {
393 SetLastError(RtlNtStatusToDosError(Status));
394 return FALSE;
395 }
396
397 return TRUE;
398 }
399
400
401 /******************************************************************************
402 * GetNumberOfEventLogRecords [ADVAPI32.@]
403 *
404 * PARAMS
405 * hEventLog []
406 * NumberOfRecords []
407 */
408 BOOL WINAPI
409 GetNumberOfEventLogRecords(IN HANDLE hEventLog,
410 OUT PDWORD NumberOfRecords)
411 {
412 NTSTATUS Status;
413 DWORD Records;
414
415 TRACE("%p, %p\n", hEventLog, NumberOfRecords);
416
417 if(!NumberOfRecords)
418 {
419 SetLastError(ERROR_INVALID_PARAMETER);
420 return FALSE;
421 }
422
423 RpcTryExcept
424 {
425 Status = ElfrNumberOfRecords(hEventLog,
426 &Records);
427 }
428 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
429 {
430 Status = I_RpcMapWin32Status(RpcExceptionCode());
431 }
432 RpcEndExcept;
433
434 if (!NT_SUCCESS(Status))
435 {
436 SetLastError(RtlNtStatusToDosError(Status));
437 return FALSE;
438 }
439
440 *NumberOfRecords = Records;
441
442 return TRUE;
443 }
444
445
446 /******************************************************************************
447 * GetOldestEventLogRecord [ADVAPI32.@]
448 *
449 * PARAMS
450 * hEventLog []
451 * OldestRecord []
452 */
453 BOOL WINAPI
454 GetOldestEventLogRecord(IN HANDLE hEventLog,
455 OUT PDWORD OldestRecord)
456 {
457 NTSTATUS Status;
458 DWORD Oldest;
459
460 TRACE("%p, %p\n", hEventLog, OldestRecord);
461
462 if(!OldestRecord)
463 {
464 SetLastError(ERROR_INVALID_PARAMETER);
465 return FALSE;
466 }
467
468 RpcTryExcept
469 {
470 Status = ElfrOldestRecord(hEventLog,
471 &Oldest);
472 }
473 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
474 {
475 Status = I_RpcMapWin32Status(RpcExceptionCode());
476 }
477 RpcEndExcept;
478
479 if (!NT_SUCCESS(Status))
480 {
481 SetLastError(RtlNtStatusToDosError(Status));
482 return FALSE;
483 }
484
485 *OldestRecord = Oldest;
486
487 return TRUE;
488 }
489
490
491 /******************************************************************************
492 * NotifyChangeEventLog [ADVAPI32.@]
493 *
494 * PARAMS
495 * hEventLog []
496 * hEvent []
497 */
498 BOOL WINAPI
499 NotifyChangeEventLog(IN HANDLE hEventLog,
500 IN HANDLE hEvent)
501 {
502 /* Use ElfrChangeNotify */
503 UNIMPLEMENTED;
504 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
505 return FALSE;
506 }
507
508
509 /******************************************************************************
510 * OpenBackupEventLogA [ADVAPI32.@]
511 */
512 HANDLE WINAPI
513 OpenBackupEventLogA(IN LPCSTR lpUNCServerName,
514 IN LPCSTR lpFileName)
515 {
516 ANSI_STRING FileName;
517 IELF_HANDLE LogHandle;
518 NTSTATUS Status;
519
520 TRACE("%s, %s\n", lpUNCServerName, lpFileName);
521
522 RtlInitAnsiString(&FileName, lpFileName);
523
524 RpcTryExcept
525 {
526 Status = ElfrOpenBELA((LPSTR)lpUNCServerName,
527 (PRPC_STRING)&FileName,
528 1,
529 1,
530 &LogHandle);
531 }
532 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
533 {
534 Status = I_RpcMapWin32Status(RpcExceptionCode());
535 }
536 RpcEndExcept;
537
538 if (!NT_SUCCESS(Status))
539 {
540 SetLastError(RtlNtStatusToDosError(Status));
541 return NULL;
542 }
543
544 return (HANDLE)LogHandle;
545 }
546
547
548 /******************************************************************************
549 * OpenBackupEventLogW [ADVAPI32.@]
550 *
551 * PARAMS
552 * lpUNCServerName []
553 * lpFileName []
554 */
555 HANDLE WINAPI
556 OpenBackupEventLogW(IN LPCWSTR lpUNCServerName,
557 IN LPCWSTR lpFileName)
558 {
559 UNICODE_STRING FileName;
560 IELF_HANDLE LogHandle;
561 NTSTATUS Status;
562
563 TRACE("%s, %s\n", debugstr_w(lpUNCServerName), debugstr_w(lpFileName));
564
565 RtlInitUnicodeString(&FileName, lpFileName);
566
567 RpcTryExcept
568 {
569 Status = ElfrOpenBELW((LPWSTR)lpUNCServerName,
570 (PRPC_UNICODE_STRING)&FileName,
571 1,
572 1,
573 &LogHandle);
574 }
575 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
576 {
577 Status = I_RpcMapWin32Status(RpcExceptionCode());
578 }
579 RpcEndExcept;
580
581 if (!NT_SUCCESS(Status))
582 {
583 SetLastError(RtlNtStatusToDosError(Status));
584 return NULL;
585 }
586
587 return (HANDLE)LogHandle;
588 }
589
590
591 /******************************************************************************
592 * OpenEventLogA [ADVAPI32.@]
593 *
594 * Opens a handle to the specified event log.
595 *
596 * PARAMS
597 * lpUNCServerName [I] UNC name of the server on which the event log is
598 * opened.
599 * lpSourceName [I] Name of the log.
600 *
601 * RETURNS
602 * Success: Handle to an event log.
603 * Failure: NULL
604 */
605 HANDLE WINAPI
606 OpenEventLogA(IN LPCSTR lpUNCServerName,
607 IN LPCSTR lpSourceName)
608 {
609 LPSTR UNCServerName;
610 ANSI_STRING SourceName;
611 IELF_HANDLE LogHandle = NULL;
612 NTSTATUS Status;
613
614 TRACE("%s, %s\n", lpUNCServerName, lpSourceName);
615
616 if (lpSourceName == NULL)
617 {
618 SetLastError(ERROR_INVALID_PARAMETER);
619 return NULL;
620 }
621
622 if (lpUNCServerName == NULL || *lpUNCServerName == 0)
623 UNCServerName = NULL;
624 else
625 UNCServerName = (LPSTR)lpUNCServerName;
626
627 RtlInitAnsiString(&SourceName, lpSourceName);
628
629 RpcTryExcept
630 {
631 Status = ElfrOpenELA(UNCServerName,
632 (PRPC_STRING)&SourceName,
633 &EmptyStringA,
634 1,
635 1,
636 &LogHandle);
637 }
638 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
639 {
640 Status = I_RpcMapWin32Status(RpcExceptionCode());
641 }
642 RpcEndExcept;
643
644 if (!NT_SUCCESS(Status))
645 {
646 SetLastError(RtlNtStatusToDosError(Status));
647 return NULL;
648 }
649
650 return (HANDLE)LogHandle;
651 }
652
653
654 /******************************************************************************
655 * OpenEventLogW [ADVAPI32.@]
656 *
657 * PARAMS
658 * lpUNCServerName []
659 * lpSourceName []
660 */
661 HANDLE WINAPI
662 OpenEventLogW(IN LPCWSTR lpUNCServerName,
663 IN LPCWSTR lpSourceName)
664 {
665 LPWSTR UNCServerName;
666 UNICODE_STRING SourceName;
667 IELF_HANDLE LogHandle;
668 NTSTATUS Status;
669
670 TRACE("%s, %s\n", debugstr_w(lpUNCServerName), debugstr_w(lpSourceName));
671
672 if (lpSourceName == NULL)
673 {
674 SetLastError(ERROR_INVALID_PARAMETER);
675 return NULL;
676 }
677
678 if (lpUNCServerName == NULL || *lpUNCServerName == 0)
679 UNCServerName = NULL;
680 else
681 UNCServerName = (LPWSTR)lpUNCServerName;
682
683 RtlInitUnicodeString(&SourceName, lpSourceName);
684
685 RpcTryExcept
686 {
687 Status = ElfrOpenELW(UNCServerName,
688 (PRPC_UNICODE_STRING)&SourceName,
689 &EmptyStringU,
690 1,
691 1,
692 &LogHandle);
693 }
694 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
695 {
696 Status = I_RpcMapWin32Status(RpcExceptionCode());
697 }
698 RpcEndExcept;
699
700 if (!NT_SUCCESS(Status))
701 {
702 SetLastError(RtlNtStatusToDosError(Status));
703 return NULL;
704 }
705
706 return (HANDLE)LogHandle;
707 }
708
709
710 /******************************************************************************
711 * ReadEventLogA [ADVAPI32.@]
712 */
713 BOOL WINAPI
714 ReadEventLogA(IN HANDLE hEventLog,
715 IN DWORD dwReadFlags,
716 IN DWORD dwRecordOffset,
717 OUT LPVOID lpBuffer,
718 IN DWORD nNumberOfBytesToRead,
719 OUT DWORD *pnBytesRead,
720 OUT DWORD *pnMinNumberOfBytesNeeded)
721 {
722 NTSTATUS Status;
723 DWORD bytesRead, minNumberOfBytesNeeded;
724
725 TRACE("%p, %lu, %lu, %p, %lu, %p, %p\n",
726 hEventLog, dwReadFlags, dwRecordOffset, lpBuffer,
727 nNumberOfBytesToRead, pnBytesRead, pnMinNumberOfBytesNeeded);
728
729 if(!pnBytesRead || !pnMinNumberOfBytesNeeded)
730 {
731 SetLastError(ERROR_INVALID_PARAMETER);
732 return FALSE;
733 }
734
735 /* If buffer is NULL set nNumberOfBytesToRead to 0 to prevent rpcrt4 from
736 trying to access a null pointer */
737 if (!lpBuffer)
738 {
739 nNumberOfBytesToRead = 0;
740 }
741
742 RpcTryExcept
743 {
744 Status = ElfrReadELA(hEventLog,
745 dwReadFlags,
746 dwRecordOffset,
747 nNumberOfBytesToRead,
748 lpBuffer,
749 &bytesRead,
750 &minNumberOfBytesNeeded);
751 }
752 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
753 {
754 Status = I_RpcMapWin32Status(RpcExceptionCode());
755 }
756 RpcEndExcept;
757
758 *pnBytesRead = (DWORD)bytesRead;
759 *pnMinNumberOfBytesNeeded = (DWORD)minNumberOfBytesNeeded;
760
761 if (!NT_SUCCESS(Status))
762 {
763 SetLastError(RtlNtStatusToDosError(Status));
764 return FALSE;
765 }
766
767 return TRUE;
768 }
769
770
771 /******************************************************************************
772 * ReadEventLogW [ADVAPI32.@]
773 *
774 * PARAMS
775 * hEventLog []
776 * dwReadFlags []
777 * dwRecordOffset []
778 * lpBuffer []
779 * nNumberOfBytesToRead []
780 * pnBytesRead []
781 * pnMinNumberOfBytesNeeded []
782 */
783 BOOL WINAPI
784 ReadEventLogW(IN HANDLE hEventLog,
785 IN DWORD dwReadFlags,
786 IN DWORD dwRecordOffset,
787 OUT LPVOID lpBuffer,
788 IN DWORD nNumberOfBytesToRead,
789 OUT DWORD *pnBytesRead,
790 OUT DWORD *pnMinNumberOfBytesNeeded)
791 {
792 NTSTATUS Status;
793 DWORD bytesRead, minNumberOfBytesNeeded;
794
795 TRACE("%p, %lu, %lu, %p, %lu, %p, %p\n",
796 hEventLog, dwReadFlags, dwRecordOffset, lpBuffer,
797 nNumberOfBytesToRead, pnBytesRead, pnMinNumberOfBytesNeeded);
798
799 if(!pnBytesRead || !pnMinNumberOfBytesNeeded)
800 {
801 SetLastError(ERROR_INVALID_PARAMETER);
802 return FALSE;
803 }
804
805 /* If buffer is NULL set nNumberOfBytesToRead to 0 to prevent rpcrt4 from
806 trying to access a null pointer */
807 if (!lpBuffer)
808 {
809 nNumberOfBytesToRead = 0;
810 }
811
812 RpcTryExcept
813 {
814 Status = ElfrReadELW(hEventLog,
815 dwReadFlags,
816 dwRecordOffset,
817 nNumberOfBytesToRead,
818 lpBuffer,
819 &bytesRead,
820 &minNumberOfBytesNeeded);
821 }
822 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
823 {
824 Status = I_RpcMapWin32Status(RpcExceptionCode());
825 }
826 RpcEndExcept;
827
828 *pnBytesRead = (DWORD)bytesRead;
829 *pnMinNumberOfBytesNeeded = (DWORD)minNumberOfBytesNeeded;
830
831 if (!NT_SUCCESS(Status))
832 {
833 SetLastError(RtlNtStatusToDosError(Status));
834 return FALSE;
835 }
836
837 return TRUE;
838 }
839
840
841 /******************************************************************************
842 * RegisterEventSourceA [ADVAPI32.@]
843 */
844 HANDLE WINAPI
845 RegisterEventSourceA(IN LPCSTR lpUNCServerName,
846 IN LPCSTR lpSourceName)
847 {
848 ANSI_STRING SourceName;
849 IELF_HANDLE LogHandle;
850 NTSTATUS Status;
851
852 TRACE("%s, %s\n", lpUNCServerName, lpSourceName);
853
854 RtlInitAnsiString(&SourceName, lpSourceName);
855
856 RpcTryExcept
857 {
858 Status = ElfrRegisterEventSourceA((LPSTR)lpUNCServerName,
859 (PRPC_STRING)&SourceName,
860 &EmptyStringA,
861 1,
862 1,
863 &LogHandle);
864 }
865 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
866 {
867 Status = I_RpcMapWin32Status(RpcExceptionCode());
868 }
869 RpcEndExcept;
870
871 if (!NT_SUCCESS(Status))
872 {
873 SetLastError(RtlNtStatusToDosError(Status));
874 return NULL;
875 }
876
877 return (HANDLE)LogHandle;
878 }
879
880
881 /******************************************************************************
882 * RegisterEventSourceW [ADVAPI32.@]
883 * Returns a registered handle to an event log
884 *
885 * PARAMS
886 * lpUNCServerName [I] Server name for source
887 * lpSourceName [I] Source name for registered handle
888 *
889 * RETURNS
890 * Success: Handle
891 * Failure: NULL
892 */
893 HANDLE WINAPI
894 RegisterEventSourceW(IN LPCWSTR lpUNCServerName,
895 IN LPCWSTR lpSourceName)
896 {
897 UNICODE_STRING SourceName;
898 IELF_HANDLE LogHandle;
899 NTSTATUS Status;
900
901 TRACE("%s, %s\n", debugstr_w(lpUNCServerName), debugstr_w(lpSourceName));
902
903 RtlInitUnicodeString(&SourceName, lpSourceName);
904
905 RpcTryExcept
906 {
907 Status = ElfrRegisterEventSourceW((LPWSTR)lpUNCServerName,
908 (PRPC_UNICODE_STRING)&SourceName,
909 &EmptyStringU,
910 1,
911 1,
912 &LogHandle);
913 }
914 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
915 {
916 Status = I_RpcMapWin32Status(RpcExceptionCode());
917 }
918 RpcEndExcept;
919
920 if (!NT_SUCCESS(Status))
921 {
922 SetLastError(RtlNtStatusToDosError(Status));
923 return NULL;
924 }
925
926 return (HANDLE)LogHandle;
927 }
928
929
930 /******************************************************************************
931 * ReportEventA [ADVAPI32.@]
932 */
933 BOOL WINAPI
934 ReportEventA(IN HANDLE hEventLog,
935 IN WORD wType,
936 IN WORD wCategory,
937 IN DWORD dwEventID,
938 IN PSID lpUserSid,
939 IN WORD wNumStrings,
940 IN DWORD dwDataSize,
941 IN LPCSTR *lpStrings,
942 IN LPVOID lpRawData)
943 {
944 NTSTATUS Status;
945 ANSI_STRING *Strings;
946 ANSI_STRING ComputerName;
947 WORD i;
948 CHAR szComputerName[MAX_COMPUTERNAME_LENGTH + 1];
949 DWORD dwSize;
950
951 TRACE("%p, %u, %u, %lu, %p, %u, %lu, %p, %p\n",
952 hEventLog, wType, wCategory, dwEventID, lpUserSid,
953 wNumStrings, dwDataSize, lpStrings, lpRawData);
954
955 Strings = HeapAlloc(GetProcessHeap(),
956 0,
957 wNumStrings * sizeof(ANSI_STRING));
958 if (!Strings)
959 {
960 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
961 return FALSE;
962 }
963
964 for (i = 0; i < wNumStrings; i++)
965 RtlInitAnsiString(&Strings[i], lpStrings[i]);
966
967 dwSize = MAX_COMPUTERNAME_LENGTH + 1;
968 GetComputerNameA(szComputerName, &dwSize);
969 RtlInitAnsiString(&ComputerName, szComputerName);
970
971 RpcTryExcept
972 {
973 Status = ElfrReportEventA(hEventLog,
974 0, /* FIXME: Time */
975 wType,
976 wCategory,
977 dwEventID,
978 wNumStrings,
979 dwDataSize,
980 (PRPC_STRING) &ComputerName,
981 lpUserSid,
982 (PRPC_STRING*) &Strings,
983 lpRawData,
984 0,
985 NULL,
986 NULL);
987 }
988 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
989 {
990 Status = I_RpcMapWin32Status(RpcExceptionCode());
991 }
992 RpcEndExcept;
993
994 HeapFree(GetProcessHeap(), 0, Strings);
995
996 if (!NT_SUCCESS(Status))
997 {
998 SetLastError(RtlNtStatusToDosError(Status));
999 return FALSE;
1000 }
1001
1002 return TRUE;
1003 }
1004
1005
1006 /******************************************************************************
1007 * ReportEventW [ADVAPI32.@]
1008 *
1009 * PARAMS
1010 * hEventLog []
1011 * wType []
1012 * wCategory []
1013 * dwEventID []
1014 * lpUserSid []
1015 * wNumStrings []
1016 * dwDataSize []
1017 * lpStrings []
1018 * lpRawData []
1019 */
1020 BOOL WINAPI
1021 ReportEventW(IN HANDLE hEventLog,
1022 IN WORD wType,
1023 IN WORD wCategory,
1024 IN DWORD dwEventID,
1025 IN PSID lpUserSid,
1026 IN WORD wNumStrings,
1027 IN DWORD dwDataSize,
1028 IN LPCWSTR *lpStrings,
1029 IN LPVOID lpRawData)
1030 {
1031 NTSTATUS Status;
1032 UNICODE_STRING *Strings;
1033 UNICODE_STRING ComputerName;
1034 WORD i;
1035 WCHAR szComputerName[MAX_COMPUTERNAME_LENGTH + 1];
1036 DWORD dwSize;
1037
1038 TRACE("%p, %u, %u, %lu, %p, %u, %lu, %p, %p\n",
1039 hEventLog, wType, wCategory, dwEventID, lpUserSid,
1040 wNumStrings, dwDataSize, lpStrings, lpRawData);
1041
1042 Strings = HeapAlloc(GetProcessHeap(),
1043 0,
1044 wNumStrings * sizeof(UNICODE_STRING));
1045 if (!Strings)
1046 {
1047 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1048 return FALSE;
1049 }
1050
1051 for (i = 0; i < wNumStrings; i++)
1052 RtlInitUnicodeString(&Strings[i], lpStrings[i]);
1053
1054 dwSize = MAX_COMPUTERNAME_LENGTH + 1;
1055 GetComputerNameW(szComputerName, &dwSize);
1056 RtlInitUnicodeString(&ComputerName, szComputerName);
1057
1058 RpcTryExcept
1059 {
1060 Status = ElfrReportEventW(hEventLog,
1061 0, /* FIXME: Time */
1062 wType,
1063 wCategory,
1064 dwEventID,
1065 wNumStrings,
1066 dwDataSize,
1067 (PRPC_UNICODE_STRING) &ComputerName,
1068 lpUserSid,
1069 (PRPC_UNICODE_STRING*) &Strings,
1070 lpRawData,
1071 0,
1072 NULL,
1073 NULL);
1074 }
1075 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1076 {
1077 Status = I_RpcMapWin32Status(RpcExceptionCode());
1078 }
1079 RpcEndExcept;
1080
1081 HeapFree(GetProcessHeap(), 0, Strings);
1082
1083 if (!NT_SUCCESS(Status))
1084 {
1085 SetLastError(RtlNtStatusToDosError(Status));
1086 return FALSE;
1087 }
1088
1089 return TRUE;
1090 }