Sync aclui, advapi32, atl, authz, kernel32, msi, oledlg, powrprof, qmgr, riched20...
[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 * ControlTraceW [ADVAPI32.@]
317 *
318 * Control a givel event trace session
319 *
320 */
321 ULONG WINAPI ControlTraceW( TRACEHANDLE hSession, LPCWSTR SessionName, PEVENT_TRACE_PROPERTIES Properties, ULONG control )
322 {
323 FIXME("(%s, %s, %p, %d) stub\n", wine_dbgstr_longlong(hSession), debugstr_w(SessionName), Properties, control);
324 return ERROR_SUCCESS;
325 }
326
327 /******************************************************************************
328 * ControlTraceA [ADVAPI32.@]
329 *
330 * See ControlTraceW.
331 *
332 */
333 ULONG WINAPI ControlTraceA( TRACEHANDLE hSession, LPCSTR SessionName, PEVENT_TRACE_PROPERTIES Properties, ULONG control )
334 {
335 FIXME("(%s, %s, %p, %d) stub\n", wine_dbgstr_longlong(hSession), debugstr_a(SessionName), Properties, control);
336 return ERROR_SUCCESS;
337 }
338
339 /******************************************************************************
340 * DeregisterEventSource [ADVAPI32.@]
341 * Closes a handle to the specified event log
342 *
343 * PARAMS
344 * hEventLog [I] Handle to event log
345 *
346 * RETURNS STD
347 */
348 BOOL WINAPI
349 DeregisterEventSource(IN HANDLE hEventLog)
350 {
351 NTSTATUS Status;
352
353 TRACE("%p\n", hEventLog);
354
355 RpcTryExcept
356 {
357 Status = ElfrDeregisterEventSource(&hEventLog);
358 }
359 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
360 {
361 Status = I_RpcMapWin32Status(RpcExceptionCode());
362 }
363 RpcEndExcept;
364
365 if (!NT_SUCCESS(Status))
366 {
367 SetLastError(RtlNtStatusToDosError(Status));
368 return FALSE;
369 }
370
371 return TRUE;
372 }
373
374 /******************************************************************************
375 * EnableTrace [ADVAPI32.@]
376 */
377 ULONG WINAPI EnableTrace( ULONG enable, ULONG flag, ULONG level, LPCGUID guid, TRACEHANDLE hSession )
378 {
379 FIXME("(%d, 0x%x, %d, %s, %s): stub\n", enable, flag, level,
380 debugstr_guid(guid), wine_dbgstr_longlong(hSession));
381
382 return ERROR_SUCCESS;
383 }
384
385 /******************************************************************************
386 * GetEventLogInformation [ADVAPI32.@]
387 *
388 * PARAMS
389 * hEventLog [I] Handle to event log
390 * dwInfoLevel [I] Level of event log information to return
391 * lpBuffer [O] Buffer that receives the event log information
392 * cbBufSize [I] Size of the lpBuffer buffer
393 * pcbBytesNeeded [O] Required buffer size
394 */
395 BOOL WINAPI
396 GetEventLogInformation(IN HANDLE hEventLog,
397 IN DWORD dwInfoLevel,
398 OUT LPVOID lpBuffer,
399 IN DWORD cbBufSize,
400 OUT LPDWORD pcbBytesNeeded)
401 {
402 NTSTATUS Status;
403
404 if (dwInfoLevel != EVENTLOG_FULL_INFO)
405 {
406 SetLastError(ERROR_INVALID_LEVEL);
407 return FALSE;
408 }
409
410 RpcTryExcept
411 {
412 Status = ElfrGetLogInformation(hEventLog,
413 dwInfoLevel,
414 (LPBYTE)lpBuffer,
415 cbBufSize,
416 pcbBytesNeeded);
417 }
418 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
419 {
420 Status = I_RpcMapWin32Status(RpcExceptionCode());
421 }
422 RpcEndExcept;
423
424 if (!NT_SUCCESS(Status))
425 {
426 SetLastError(RtlNtStatusToDosError(Status));
427 return FALSE;
428 }
429
430 return TRUE;
431 }
432
433
434 /******************************************************************************
435 * GetNumberOfEventLogRecords [ADVAPI32.@]
436 *
437 * PARAMS
438 * hEventLog []
439 * NumberOfRecords []
440 */
441 BOOL WINAPI
442 GetNumberOfEventLogRecords(IN HANDLE hEventLog,
443 OUT PDWORD NumberOfRecords)
444 {
445 NTSTATUS Status;
446 DWORD Records;
447
448 TRACE("%p, %p\n", hEventLog, NumberOfRecords);
449
450 if(!NumberOfRecords)
451 {
452 SetLastError(ERROR_INVALID_PARAMETER);
453 return FALSE;
454 }
455
456 RpcTryExcept
457 {
458 Status = ElfrNumberOfRecords(hEventLog,
459 &Records);
460 }
461 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
462 {
463 Status = I_RpcMapWin32Status(RpcExceptionCode());
464 }
465 RpcEndExcept;
466
467 if (!NT_SUCCESS(Status))
468 {
469 SetLastError(RtlNtStatusToDosError(Status));
470 return FALSE;
471 }
472
473 *NumberOfRecords = Records;
474
475 return TRUE;
476 }
477
478
479 /******************************************************************************
480 * GetOldestEventLogRecord [ADVAPI32.@]
481 *
482 * PARAMS
483 * hEventLog []
484 * OldestRecord []
485 */
486 BOOL WINAPI
487 GetOldestEventLogRecord(IN HANDLE hEventLog,
488 OUT PDWORD OldestRecord)
489 {
490 NTSTATUS Status;
491 DWORD Oldest;
492
493 TRACE("%p, %p\n", hEventLog, OldestRecord);
494
495 if(!OldestRecord)
496 {
497 SetLastError(ERROR_INVALID_PARAMETER);
498 return FALSE;
499 }
500
501 RpcTryExcept
502 {
503 Status = ElfrOldestRecord(hEventLog,
504 &Oldest);
505 }
506 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
507 {
508 Status = I_RpcMapWin32Status(RpcExceptionCode());
509 }
510 RpcEndExcept;
511
512 if (!NT_SUCCESS(Status))
513 {
514 SetLastError(RtlNtStatusToDosError(Status));
515 return FALSE;
516 }
517
518 *OldestRecord = Oldest;
519
520 return TRUE;
521 }
522
523
524 /******************************************************************************
525 * NotifyChangeEventLog [ADVAPI32.@]
526 *
527 * PARAMS
528 * hEventLog []
529 * hEvent []
530 */
531 BOOL WINAPI
532 NotifyChangeEventLog(IN HANDLE hEventLog,
533 IN HANDLE hEvent)
534 {
535 /* Use ElfrChangeNotify */
536 UNIMPLEMENTED;
537 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
538 return FALSE;
539 }
540
541
542 /******************************************************************************
543 * OpenBackupEventLogA [ADVAPI32.@]
544 */
545 HANDLE WINAPI
546 OpenBackupEventLogA(IN LPCSTR lpUNCServerName,
547 IN LPCSTR lpFileName)
548 {
549 ANSI_STRING FileName;
550 IELF_HANDLE LogHandle;
551 NTSTATUS Status;
552
553 TRACE("%s, %s\n", lpUNCServerName, lpFileName);
554
555 RtlInitAnsiString(&FileName, lpFileName);
556
557 RpcTryExcept
558 {
559 Status = ElfrOpenBELA((LPSTR)lpUNCServerName,
560 (PRPC_STRING)&FileName,
561 1,
562 1,
563 &LogHandle);
564 }
565 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
566 {
567 Status = I_RpcMapWin32Status(RpcExceptionCode());
568 }
569 RpcEndExcept;
570
571 if (!NT_SUCCESS(Status))
572 {
573 SetLastError(RtlNtStatusToDosError(Status));
574 return NULL;
575 }
576
577 return (HANDLE)LogHandle;
578 }
579
580
581 /******************************************************************************
582 * OpenBackupEventLogW [ADVAPI32.@]
583 *
584 * PARAMS
585 * lpUNCServerName []
586 * lpFileName []
587 */
588 HANDLE WINAPI
589 OpenBackupEventLogW(IN LPCWSTR lpUNCServerName,
590 IN LPCWSTR lpFileName)
591 {
592 UNICODE_STRING FileName;
593 IELF_HANDLE LogHandle;
594 NTSTATUS Status;
595
596 TRACE("%s, %s\n", debugstr_w(lpUNCServerName), debugstr_w(lpFileName));
597
598 RtlInitUnicodeString(&FileName, lpFileName);
599
600 RpcTryExcept
601 {
602 Status = ElfrOpenBELW((LPWSTR)lpUNCServerName,
603 (PRPC_UNICODE_STRING)&FileName,
604 1,
605 1,
606 &LogHandle);
607 }
608 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
609 {
610 Status = I_RpcMapWin32Status(RpcExceptionCode());
611 }
612 RpcEndExcept;
613
614 if (!NT_SUCCESS(Status))
615 {
616 SetLastError(RtlNtStatusToDosError(Status));
617 return NULL;
618 }
619
620 return (HANDLE)LogHandle;
621 }
622
623
624 /******************************************************************************
625 * OpenEventLogA [ADVAPI32.@]
626 *
627 * Opens a handle to the specified event log.
628 *
629 * PARAMS
630 * lpUNCServerName [I] UNC name of the server on which the event log is
631 * opened.
632 * lpSourceName [I] Name of the log.
633 *
634 * RETURNS
635 * Success: Handle to an event log.
636 * Failure: NULL
637 */
638 HANDLE WINAPI
639 OpenEventLogA(IN LPCSTR lpUNCServerName,
640 IN LPCSTR lpSourceName)
641 {
642 LPSTR UNCServerName;
643 ANSI_STRING SourceName;
644 IELF_HANDLE LogHandle = NULL;
645 NTSTATUS Status;
646
647 TRACE("%s, %s\n", lpUNCServerName, lpSourceName);
648
649 if (lpSourceName == NULL)
650 {
651 SetLastError(ERROR_INVALID_PARAMETER);
652 return NULL;
653 }
654
655 if (lpUNCServerName == NULL || *lpUNCServerName == 0)
656 UNCServerName = NULL;
657 else
658 UNCServerName = (LPSTR)lpUNCServerName;
659
660 RtlInitAnsiString(&SourceName, lpSourceName);
661
662 RpcTryExcept
663 {
664 Status = ElfrOpenELA(UNCServerName,
665 (PRPC_STRING)&SourceName,
666 &EmptyStringA,
667 1,
668 1,
669 &LogHandle);
670 }
671 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
672 {
673 Status = I_RpcMapWin32Status(RpcExceptionCode());
674 }
675 RpcEndExcept;
676
677 if (!NT_SUCCESS(Status))
678 {
679 SetLastError(RtlNtStatusToDosError(Status));
680 return NULL;
681 }
682
683 return (HANDLE)LogHandle;
684 }
685
686
687 /******************************************************************************
688 * OpenEventLogW [ADVAPI32.@]
689 *
690 * PARAMS
691 * lpUNCServerName []
692 * lpSourceName []
693 */
694 HANDLE WINAPI
695 OpenEventLogW(IN LPCWSTR lpUNCServerName,
696 IN LPCWSTR lpSourceName)
697 {
698 LPWSTR UNCServerName;
699 UNICODE_STRING SourceName;
700 IELF_HANDLE LogHandle;
701 NTSTATUS Status;
702
703 TRACE("%s, %s\n", debugstr_w(lpUNCServerName), debugstr_w(lpSourceName));
704
705 if (lpSourceName == NULL)
706 {
707 SetLastError(ERROR_INVALID_PARAMETER);
708 return NULL;
709 }
710
711 if (lpUNCServerName == NULL || *lpUNCServerName == 0)
712 UNCServerName = NULL;
713 else
714 UNCServerName = (LPWSTR)lpUNCServerName;
715
716 RtlInitUnicodeString(&SourceName, lpSourceName);
717
718 RpcTryExcept
719 {
720 Status = ElfrOpenELW(UNCServerName,
721 (PRPC_UNICODE_STRING)&SourceName,
722 &EmptyStringU,
723 1,
724 1,
725 &LogHandle);
726 }
727 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
728 {
729 Status = I_RpcMapWin32Status(RpcExceptionCode());
730 }
731 RpcEndExcept;
732
733 if (!NT_SUCCESS(Status))
734 {
735 SetLastError(RtlNtStatusToDosError(Status));
736 return NULL;
737 }
738
739 return (HANDLE)LogHandle;
740 }
741
742 /******************************************************************************
743 * QueryAllTracesW [ADVAPI32.@]
744 *
745 * Query information for started event trace sessions
746 *
747 */
748 ULONG WINAPI QueryAllTracesW( PEVENT_TRACE_PROPERTIES * parray, ULONG arraycount, PULONG psessioncount )
749 {
750 FIXME("(%p, %d, %p) stub\n", parray, arraycount, psessioncount);
751
752 if (psessioncount) *psessioncount = 0;
753 return ERROR_SUCCESS;
754 }
755
756 /******************************************************************************
757 * QueryAllTracesA [ADVAPI32.@]
758 *
759 * See QueryAllTracesW.
760 */
761 ULONG WINAPI QueryAllTracesA( PEVENT_TRACE_PROPERTIES * parray, ULONG arraycount, PULONG psessioncount )
762 {
763 FIXME("(%p, %d, %p) stub\n", parray, arraycount, psessioncount);
764
765 if (psessioncount) *psessioncount = 0;
766 return ERROR_SUCCESS;
767 }
768
769 /******************************************************************************
770 * ReadEventLogA [ADVAPI32.@]
771 */
772 BOOL WINAPI
773 ReadEventLogA(IN HANDLE hEventLog,
774 IN DWORD dwReadFlags,
775 IN DWORD dwRecordOffset,
776 OUT LPVOID lpBuffer,
777 IN DWORD nNumberOfBytesToRead,
778 OUT DWORD *pnBytesRead,
779 OUT DWORD *pnMinNumberOfBytesNeeded)
780 {
781 NTSTATUS Status;
782 DWORD bytesRead, minNumberOfBytesNeeded;
783
784 TRACE("%p, %lu, %lu, %p, %lu, %p, %p\n",
785 hEventLog, dwReadFlags, dwRecordOffset, lpBuffer,
786 nNumberOfBytesToRead, pnBytesRead, pnMinNumberOfBytesNeeded);
787
788 if(!pnBytesRead || !pnMinNumberOfBytesNeeded)
789 {
790 SetLastError(ERROR_INVALID_PARAMETER);
791 return FALSE;
792 }
793
794 /* If buffer is NULL set nNumberOfBytesToRead to 0 to prevent rpcrt4 from
795 trying to access a null pointer */
796 if (!lpBuffer)
797 {
798 nNumberOfBytesToRead = 0;
799 }
800
801 RpcTryExcept
802 {
803 Status = ElfrReadELA(hEventLog,
804 dwReadFlags,
805 dwRecordOffset,
806 nNumberOfBytesToRead,
807 lpBuffer,
808 &bytesRead,
809 &minNumberOfBytesNeeded);
810 }
811 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
812 {
813 Status = I_RpcMapWin32Status(RpcExceptionCode());
814 }
815 RpcEndExcept;
816
817 *pnBytesRead = (DWORD)bytesRead;
818 *pnMinNumberOfBytesNeeded = (DWORD)minNumberOfBytesNeeded;
819
820 if (!NT_SUCCESS(Status))
821 {
822 SetLastError(RtlNtStatusToDosError(Status));
823 return FALSE;
824 }
825
826 return TRUE;
827 }
828
829
830 /******************************************************************************
831 * ReadEventLogW [ADVAPI32.@]
832 *
833 * PARAMS
834 * hEventLog []
835 * dwReadFlags []
836 * dwRecordOffset []
837 * lpBuffer []
838 * nNumberOfBytesToRead []
839 * pnBytesRead []
840 * pnMinNumberOfBytesNeeded []
841 */
842 BOOL WINAPI
843 ReadEventLogW(IN HANDLE hEventLog,
844 IN DWORD dwReadFlags,
845 IN DWORD dwRecordOffset,
846 OUT LPVOID lpBuffer,
847 IN DWORD nNumberOfBytesToRead,
848 OUT DWORD *pnBytesRead,
849 OUT DWORD *pnMinNumberOfBytesNeeded)
850 {
851 NTSTATUS Status;
852 DWORD bytesRead, minNumberOfBytesNeeded;
853
854 TRACE("%p, %lu, %lu, %p, %lu, %p, %p\n",
855 hEventLog, dwReadFlags, dwRecordOffset, lpBuffer,
856 nNumberOfBytesToRead, pnBytesRead, pnMinNumberOfBytesNeeded);
857
858 if(!pnBytesRead || !pnMinNumberOfBytesNeeded)
859 {
860 SetLastError(ERROR_INVALID_PARAMETER);
861 return FALSE;
862 }
863
864 /* If buffer is NULL set nNumberOfBytesToRead to 0 to prevent rpcrt4 from
865 trying to access a null pointer */
866 if (!lpBuffer)
867 {
868 nNumberOfBytesToRead = 0;
869 }
870
871 RpcTryExcept
872 {
873 Status = ElfrReadELW(hEventLog,
874 dwReadFlags,
875 dwRecordOffset,
876 nNumberOfBytesToRead,
877 lpBuffer,
878 &bytesRead,
879 &minNumberOfBytesNeeded);
880 }
881 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
882 {
883 Status = I_RpcMapWin32Status(RpcExceptionCode());
884 }
885 RpcEndExcept;
886
887 *pnBytesRead = (DWORD)bytesRead;
888 *pnMinNumberOfBytesNeeded = (DWORD)minNumberOfBytesNeeded;
889
890 if (!NT_SUCCESS(Status))
891 {
892 SetLastError(RtlNtStatusToDosError(Status));
893 return FALSE;
894 }
895
896 return TRUE;
897 }
898
899
900 /******************************************************************************
901 * RegisterEventSourceA [ADVAPI32.@]
902 */
903 HANDLE WINAPI
904 RegisterEventSourceA(IN LPCSTR lpUNCServerName,
905 IN LPCSTR lpSourceName)
906 {
907 ANSI_STRING SourceName;
908 IELF_HANDLE LogHandle;
909 NTSTATUS Status;
910
911 TRACE("%s, %s\n", lpUNCServerName, lpSourceName);
912
913 RtlInitAnsiString(&SourceName, lpSourceName);
914
915 RpcTryExcept
916 {
917 Status = ElfrRegisterEventSourceA((LPSTR)lpUNCServerName,
918 (PRPC_STRING)&SourceName,
919 &EmptyStringA,
920 1,
921 1,
922 &LogHandle);
923 }
924 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
925 {
926 Status = I_RpcMapWin32Status(RpcExceptionCode());
927 }
928 RpcEndExcept;
929
930 if (!NT_SUCCESS(Status))
931 {
932 SetLastError(RtlNtStatusToDosError(Status));
933 return NULL;
934 }
935
936 return (HANDLE)LogHandle;
937 }
938
939
940 /******************************************************************************
941 * RegisterEventSourceW [ADVAPI32.@]
942 * Returns a registered handle to an event log
943 *
944 * PARAMS
945 * lpUNCServerName [I] Server name for source
946 * lpSourceName [I] Source name for registered handle
947 *
948 * RETURNS
949 * Success: Handle
950 * Failure: NULL
951 */
952 HANDLE WINAPI
953 RegisterEventSourceW(IN LPCWSTR lpUNCServerName,
954 IN LPCWSTR lpSourceName)
955 {
956 UNICODE_STRING SourceName;
957 IELF_HANDLE LogHandle;
958 NTSTATUS Status;
959
960 TRACE("%s, %s\n", debugstr_w(lpUNCServerName), debugstr_w(lpSourceName));
961
962 RtlInitUnicodeString(&SourceName, lpSourceName);
963
964 RpcTryExcept
965 {
966 Status = ElfrRegisterEventSourceW((LPWSTR)lpUNCServerName,
967 (PRPC_UNICODE_STRING)&SourceName,
968 &EmptyStringU,
969 1,
970 1,
971 &LogHandle);
972 }
973 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
974 {
975 Status = I_RpcMapWin32Status(RpcExceptionCode());
976 }
977 RpcEndExcept;
978
979 if (!NT_SUCCESS(Status))
980 {
981 SetLastError(RtlNtStatusToDosError(Status));
982 return NULL;
983 }
984
985 return (HANDLE)LogHandle;
986 }
987
988
989 /******************************************************************************
990 * ReportEventA [ADVAPI32.@]
991 */
992 BOOL WINAPI
993 ReportEventA(IN HANDLE hEventLog,
994 IN WORD wType,
995 IN WORD wCategory,
996 IN DWORD dwEventID,
997 IN PSID lpUserSid,
998 IN WORD wNumStrings,
999 IN DWORD dwDataSize,
1000 IN LPCSTR *lpStrings,
1001 IN LPVOID lpRawData)
1002 {
1003 NTSTATUS Status;
1004 ANSI_STRING *Strings;
1005 ANSI_STRING ComputerName;
1006 WORD i;
1007 CHAR szComputerName[MAX_COMPUTERNAME_LENGTH + 1];
1008 DWORD dwSize;
1009
1010 TRACE("%p, %u, %u, %lu, %p, %u, %lu, %p, %p\n",
1011 hEventLog, wType, wCategory, dwEventID, lpUserSid,
1012 wNumStrings, dwDataSize, lpStrings, lpRawData);
1013
1014 Strings = HeapAlloc(GetProcessHeap(),
1015 0,
1016 wNumStrings * sizeof(ANSI_STRING));
1017 if (!Strings)
1018 {
1019 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1020 return FALSE;
1021 }
1022
1023 for (i = 0; i < wNumStrings; i++)
1024 RtlInitAnsiString(&Strings[i], lpStrings[i]);
1025
1026 dwSize = MAX_COMPUTERNAME_LENGTH + 1;
1027 GetComputerNameA(szComputerName, &dwSize);
1028 RtlInitAnsiString(&ComputerName, szComputerName);
1029
1030 RpcTryExcept
1031 {
1032 Status = ElfrReportEventA(hEventLog,
1033 0, /* FIXME: Time */
1034 wType,
1035 wCategory,
1036 dwEventID,
1037 wNumStrings,
1038 dwDataSize,
1039 (PRPC_STRING) &ComputerName,
1040 lpUserSid,
1041 (PRPC_STRING*) &Strings,
1042 lpRawData,
1043 0,
1044 NULL,
1045 NULL);
1046 }
1047 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1048 {
1049 Status = I_RpcMapWin32Status(RpcExceptionCode());
1050 }
1051 RpcEndExcept;
1052
1053 HeapFree(GetProcessHeap(), 0, Strings);
1054
1055 if (!NT_SUCCESS(Status))
1056 {
1057 SetLastError(RtlNtStatusToDosError(Status));
1058 return FALSE;
1059 }
1060
1061 return TRUE;
1062 }
1063
1064
1065 /******************************************************************************
1066 * ReportEventW [ADVAPI32.@]
1067 *
1068 * PARAMS
1069 * hEventLog []
1070 * wType []
1071 * wCategory []
1072 * dwEventID []
1073 * lpUserSid []
1074 * wNumStrings []
1075 * dwDataSize []
1076 * lpStrings []
1077 * lpRawData []
1078 */
1079 BOOL WINAPI
1080 ReportEventW(IN HANDLE hEventLog,
1081 IN WORD wType,
1082 IN WORD wCategory,
1083 IN DWORD dwEventID,
1084 IN PSID lpUserSid,
1085 IN WORD wNumStrings,
1086 IN DWORD dwDataSize,
1087 IN LPCWSTR *lpStrings,
1088 IN LPVOID lpRawData)
1089 {
1090 NTSTATUS Status;
1091 UNICODE_STRING *Strings;
1092 UNICODE_STRING ComputerName;
1093 WORD i;
1094 WCHAR szComputerName[MAX_COMPUTERNAME_LENGTH + 1];
1095 DWORD dwSize;
1096
1097 TRACE("%p, %u, %u, %lu, %p, %u, %lu, %p, %p\n",
1098 hEventLog, wType, wCategory, dwEventID, lpUserSid,
1099 wNumStrings, dwDataSize, lpStrings, lpRawData);
1100
1101 Strings = HeapAlloc(GetProcessHeap(),
1102 0,
1103 wNumStrings * sizeof(UNICODE_STRING));
1104 if (!Strings)
1105 {
1106 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1107 return FALSE;
1108 }
1109
1110 for (i = 0; i < wNumStrings; i++)
1111 RtlInitUnicodeString(&Strings[i], lpStrings[i]);
1112
1113 dwSize = MAX_COMPUTERNAME_LENGTH + 1;
1114 GetComputerNameW(szComputerName, &dwSize);
1115 RtlInitUnicodeString(&ComputerName, szComputerName);
1116
1117 RpcTryExcept
1118 {
1119 Status = ElfrReportEventW(hEventLog,
1120 0, /* FIXME: Time */
1121 wType,
1122 wCategory,
1123 dwEventID,
1124 wNumStrings,
1125 dwDataSize,
1126 (PRPC_UNICODE_STRING) &ComputerName,
1127 lpUserSid,
1128 (PRPC_UNICODE_STRING*) &Strings,
1129 lpRawData,
1130 0,
1131 NULL,
1132 NULL);
1133 }
1134 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1135 {
1136 Status = I_RpcMapWin32Status(RpcExceptionCode());
1137 }
1138 RpcEndExcept;
1139
1140 HeapFree(GetProcessHeap(), 0, Strings);
1141
1142 if (!NT_SUCCESS(Status))
1143 {
1144 SetLastError(RtlNtStatusToDosError(Status));
1145 return FALSE;
1146 }
1147
1148 return TRUE;
1149 }
1150