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