2 * Win32 advapi functions
4 * Copyright 1995 Sven Verdoolaege
5 * Copyright 1998 Juergen Schmied
6 * Copyright 2003 Mike Hearn
7 * Copyright 2007 Hervé Poussineau
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.
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.
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
25 #include "wine/debug.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(advapi
);
28 WINE_DECLARE_DEBUG_CHANNEL(eventlog
);
30 typedef struct _LOG_INFO
32 RPC_BINDING_HANDLE BindingHandle
;
35 } LOG_INFO
, *PLOG_INFO
;
37 /******************************************************************************
38 * BackupEventLogA [ADVAPI32.@]
43 IN LPCSTR lpBackupFileName
)
47 ANSI_STRING BackupFileName
;
49 TRACE("%p, %s\n", hEventLog
, lpBackupFileName
);
51 RtlInitAnsiString(&BackupFileName
, lpBackupFileName
);
53 pLog
= (PLOG_INFO
)hEventLog
;
56 SetLastError(ERROR_INVALID_HANDLE
);
59 Status
= ElfrBackupELFA(
62 BackupFileName
.Buffer
);
64 if (!NT_SUCCESS(Status
))
66 SetLastError(RtlNtStatusToDosError(Status
));
72 /******************************************************************************
73 * BackupEventLogW [ADVAPI32.@]
82 IN LPCWSTR lpBackupFileName
)
86 UNICODE_STRING BackupFileName
;
88 TRACE("%p, %s\n", hEventLog
, lpBackupFileName
);
90 RtlInitUnicodeString(&BackupFileName
, lpBackupFileName
);
92 pLog
= (PLOG_INFO
)hEventLog
;
95 SetLastError(ERROR_INVALID_HANDLE
);
98 Status
= ElfrBackupELFW(
101 BackupFileName
.Buffer
);
103 if (!NT_SUCCESS(Status
))
105 SetLastError(RtlNtStatusToDosError(Status
));
112 /******************************************************************************
113 * ClearEventLogA [ADVAPI32.@]
118 IN LPCSTR lpBackupFileName
)
122 ANSI_STRING BackupFileName
;
124 TRACE("%p, %s\n", hEventLog
, lpBackupFileName
);
126 RtlInitAnsiString(&BackupFileName
, lpBackupFileName
);
128 pLog
= (PLOG_INFO
)hEventLog
;
131 SetLastError(ERROR_INVALID_HANDLE
);
134 Status
= ElfrClearELFA(
137 BackupFileName
.Buffer
);
139 if (!NT_SUCCESS(Status
))
141 SetLastError(RtlNtStatusToDosError(Status
));
148 /******************************************************************************
149 * ClearEventLogW [ADVAPI32.@]
154 IN LPCWSTR lpBackupFileName
)
158 UNICODE_STRING BackupFileName
;
160 TRACE("%p, %s\n", hEventLog
, lpBackupFileName
);
162 RtlInitUnicodeString(&BackupFileName
, lpBackupFileName
);
164 pLog
= (PLOG_INFO
)hEventLog
;
167 SetLastError(ERROR_INVALID_HANDLE
);
170 Status
= ElfrClearELFW(
173 BackupFileName
.Buffer
);
175 if (!NT_SUCCESS(Status
))
177 SetLastError(RtlNtStatusToDosError(Status
));
184 /******************************************************************************
185 * CloseEventLog [ADVAPI32.@]
194 TRACE("%p", hEventLog
);
196 pLog
= (PLOG_INFO
)hEventLog
;
200 if (pLog
->bLocal
== FALSE
)
202 if (!EvtUnbindRpc(pLog
->BindingHandle
))
204 SetLastError(ERROR_ACCESS_DENIED
);
210 Status
= ElfrCloseEL(
213 if (!NT_SUCCESS(Status
))
215 SetLastError(RtlNtStatusToDosError(Status
));
220 HeapFree(GetProcessHeap(), 0, pLog
);
226 /******************************************************************************
227 * DeregisterEventSource [ADVAPI32.@]
228 * Closes a handle to the specified event log
231 * hEventLog [I] Handle to event log
236 DeregisterEventSource(
242 TRACE("%p\n", hEventLog
);
244 pLog
= (PLOG_INFO
)hEventLog
;
248 Status
= ElfrDeregisterEventSource(
251 if (!NT_SUCCESS(Status
))
253 SetLastError(RtlNtStatusToDosError(Status
));
260 /******************************************************************************
261 * GetNumberOfEventLogRecords [ADVAPI32.@]
268 GetNumberOfEventLogRecords(
270 OUT PDWORD NumberOfRecords
)
276 TRACE("%p, %p\n", hEventLog
, NumberOfRecords
);
278 pLog
= (PLOG_INFO
)hEventLog
;
281 SetLastError(ERROR_INVALID_HANDLE
);
284 Status
= ElfrNumberOfRecords(
288 if (!NT_SUCCESS(Status
))
290 SetLastError(RtlNtStatusToDosError(Status
));
294 *NumberOfRecords
= Records
;
299 /******************************************************************************
300 * GetOldestEventLogRecord [ADVAPI32.@]
307 GetOldestEventLogRecord(
309 OUT PDWORD OldestRecord
)
315 TRACE("%p, %p\n", hEventLog
, OldestRecord
);
317 pLog
= (PLOG_INFO
)hEventLog
;
320 SetLastError(ERROR_INVALID_HANDLE
);
323 Status
= ElfrOldestRecord(
327 if (!NT_SUCCESS(Status
))
329 SetLastError(RtlNtStatusToDosError(Status
));
333 *OldestRecord
= Oldest
;
338 /******************************************************************************
339 * NotifyChangeEventLog [ADVAPI32.@]
346 NotifyChangeEventLog(
350 /* Use ElfrChangeNotify */
352 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
357 /******************************************************************************
358 * OpenBackupEventLogA [ADVAPI32.@]
362 IN LPCSTR lpUNCServerName
,
363 IN LPCSTR lpFileName
)
365 UNICODE_STRING UNCServerName
;
366 UNICODE_STRING FileName
;
369 TRACE("%s, %s\n", lpUNCServerName
, lpFileName
);
371 if (!RtlCreateUnicodeStringFromAsciiz(&UNCServerName
, lpUNCServerName
))
373 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
376 if (!RtlCreateUnicodeStringFromAsciiz(&FileName
, lpFileName
))
378 RtlFreeUnicodeString(&UNCServerName
);
379 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
383 Handle
= OpenBackupEventLogW(
384 UNCServerName
.Buffer
,
387 RtlFreeUnicodeString(&UNCServerName
);
388 RtlFreeUnicodeString(&FileName
);
394 /******************************************************************************
395 * OpenBackupEventLogW [ADVAPI32.@]
403 IN LPCWSTR lpUNCServerName
,
404 IN LPCWSTR lpFileName
)
408 UNICODE_STRING UNCServerName
;
409 UNICODE_STRING FileName
;
411 TRACE("%s, %s\n", lpUNCServerName
, lpFileName
);
413 RtlInitUnicodeString(&UNCServerName
, lpUNCServerName
);
414 RtlInitUnicodeString(&FileName
, lpFileName
);
416 pLog
= HeapAlloc(GetProcessHeap(), 0, sizeof(LOG_INFO
));
419 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
422 ZeroMemory(pLog
, sizeof(LOG_INFO
));
424 if (lpUNCServerName
== NULL
|| *lpUNCServerName
== 0)
428 if (!EvtGetLocalHandle(&pLog
->BindingHandle
))
430 HeapFree(GetProcessHeap(), 0, pLog
);
431 SetLastError(ERROR_GEN_FAILURE
);
437 pLog
->bLocal
= FALSE
;
439 if (!EvtBindRpc(lpUNCServerName
, &pLog
->BindingHandle
))
441 HeapFree(GetProcessHeap(), 0, pLog
);
442 SetLastError(ERROR_INVALID_COMPUTERNAME
);
447 Status
= ElfrOpenBELW(
449 UNCServerName
.Buffer
,
455 if (!NT_SUCCESS(Status
))
457 SetLastError(RtlNtStatusToDosError(Status
));
458 HeapFree(GetProcessHeap(), 0, pLog
);
465 /******************************************************************************
466 * OpenEventLogA [ADVAPI32.@]
470 IN LPCSTR lpUNCServerName
,
471 IN LPCSTR lpSourceName
)
473 UNICODE_STRING UNCServerName
;
474 UNICODE_STRING SourceName
;
477 if (!RtlCreateUnicodeStringFromAsciiz(&UNCServerName
, lpUNCServerName
))
479 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
482 if (!RtlCreateUnicodeStringFromAsciiz(&SourceName
, lpSourceName
))
484 RtlFreeUnicodeString(&UNCServerName
);
485 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
489 Handle
= OpenEventLogW(UNCServerName
.Buffer
, SourceName
.Buffer
);
491 RtlFreeUnicodeString(&UNCServerName
);
492 RtlFreeUnicodeString(&SourceName
);
498 /******************************************************************************
499 * OpenEventLogW [ADVAPI32.@]
507 IN LPCWSTR lpUNCServerName
,
508 IN LPCWSTR lpSourceName
)
512 UNICODE_STRING UNCServerName
;
513 UNICODE_STRING SourceName
;
515 TRACE("%s, %s\n", lpUNCServerName
, lpSourceName
);
517 RtlInitUnicodeString(&UNCServerName
, lpUNCServerName
);
518 RtlInitUnicodeString(&SourceName
, lpSourceName
);
520 pLog
= HeapAlloc(GetProcessHeap(), 0, sizeof(LOG_INFO
));
523 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
526 ZeroMemory(pLog
, sizeof(LOG_INFO
));
528 if (lpUNCServerName
== NULL
|| *lpUNCServerName
== 0)
532 if (!EvtGetLocalHandle(&pLog
->BindingHandle
))
534 HeapFree(GetProcessHeap(), 0, pLog
);
535 SetLastError(ERROR_GEN_FAILURE
);
541 pLog
->bLocal
= FALSE
;
543 if (!EvtBindRpc(lpUNCServerName
, &pLog
->BindingHandle
))
545 HeapFree(GetProcessHeap(), 0, pLog
);
546 SetLastError(ERROR_INVALID_COMPUTERNAME
);
551 Status
= ElfrOpenELW(
553 UNCServerName
.Buffer
,
560 if (!NT_SUCCESS(Status
))
562 SetLastError(RtlNtStatusToDosError(Status
));
563 HeapFree(GetProcessHeap(), 0, pLog
);
570 /******************************************************************************
571 * ReadEventLogA [ADVAPI32.@]
576 IN DWORD dwReadFlags
,
577 IN DWORD dwRecordOffset
,
579 IN DWORD nNumberOfBytesToRead
,
580 OUT DWORD
*pnBytesRead
,
581 OUT DWORD
*pnMinNumberOfBytesNeeded
)
585 long bytesRead
, minNumberOfBytesNeeded
;
587 TRACE("%p, %lu, %lu, %p, %lu, %p, %p\n",
588 hEventLog
, dwReadFlags
, dwRecordOffset
, lpBuffer
,
589 nNumberOfBytesToRead
, pnBytesRead
, pnMinNumberOfBytesNeeded
);
591 pLog
= (PLOG_INFO
)hEventLog
;
594 SetLastError(ERROR_INVALID_HANDLE
);
597 Status
= ElfrReadELA(
602 nNumberOfBytesToRead
,
605 &minNumberOfBytesNeeded
);
606 if (!NT_SUCCESS(Status
))
608 SetLastError(RtlNtStatusToDosError(Status
));
612 *pnBytesRead
= (DWORD
)bytesRead
;
613 *pnMinNumberOfBytesNeeded
= (DWORD
)minNumberOfBytesNeeded
;
618 /******************************************************************************
619 * ReadEventLogW [ADVAPI32.@]
626 * nNumberOfBytesToRead []
628 * pnMinNumberOfBytesNeeded []
633 IN DWORD dwReadFlags
,
634 IN DWORD dwRecordOffset
,
636 IN DWORD nNumberOfBytesToRead
,
637 OUT DWORD
*pnBytesRead
,
638 OUT DWORD
*pnMinNumberOfBytesNeeded
)
642 long bytesRead
, minNumberOfBytesNeeded
;
644 TRACE("%p, %lu, %lu, %p, %lu, %p, %p\n",
645 hEventLog
, dwReadFlags
, dwRecordOffset
, lpBuffer
,
646 nNumberOfBytesToRead
, pnBytesRead
, pnMinNumberOfBytesNeeded
);
648 pLog
= (PLOG_INFO
)hEventLog
;
651 SetLastError(ERROR_INVALID_HANDLE
);
654 Status
= ElfrReadELW(
659 nNumberOfBytesToRead
,
662 &minNumberOfBytesNeeded
);
663 if (!NT_SUCCESS(Status
))
665 SetLastError(RtlNtStatusToDosError(Status
));
669 *pnBytesRead
= (DWORD
)bytesRead
;
670 *pnMinNumberOfBytesNeeded
= (DWORD
)minNumberOfBytesNeeded
;
675 /******************************************************************************
676 * RegisterEventSourceA [ADVAPI32.@]
679 RegisterEventSourceA(
680 IN LPCSTR lpUNCServerName
,
681 IN LPCSTR lpSourceName
)
683 UNICODE_STRING UNCServerName
;
684 UNICODE_STRING SourceName
;
687 TRACE("%s, %s\n", lpUNCServerName
, lpSourceName
);
689 if (!RtlCreateUnicodeStringFromAsciiz(&UNCServerName
, lpUNCServerName
))
691 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
694 if (!RtlCreateUnicodeStringFromAsciiz(&SourceName
, lpSourceName
))
696 RtlFreeUnicodeString(&UNCServerName
);
697 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
701 Handle
= RegisterEventSourceW(UNCServerName
.Buffer
, SourceName
.Buffer
);
703 RtlFreeUnicodeString(&UNCServerName
);
704 RtlFreeUnicodeString(&SourceName
);
710 /******************************************************************************
711 * RegisterEventSourceW [ADVAPI32.@]
712 * Returns a registered handle to an event log
715 * lpUNCServerName [I] Server name for source
716 * lpSourceName [I] Source name for registered handle
723 RegisterEventSourceW(
724 IN LPCWSTR lpUNCServerName
,
725 IN LPCWSTR lpSourceName
)
729 UNICODE_STRING UNCServerName
;
730 UNICODE_STRING SourceName
;
732 TRACE("%s, %s\n", lpUNCServerName
, lpSourceName
);
734 RtlInitUnicodeString(&UNCServerName
, lpUNCServerName
);
735 RtlInitUnicodeString(&SourceName
, lpSourceName
);
737 pLog
= HeapAlloc(GetProcessHeap(), 0, sizeof(LOG_INFO
));
740 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
743 ZeroMemory(pLog
, sizeof(LOG_INFO
));
745 if (lpUNCServerName
== NULL
|| *lpUNCServerName
== 0)
749 if (!EvtGetLocalHandle(&pLog
->BindingHandle
))
751 HeapFree(GetProcessHeap(), 0, pLog
);
752 SetLastError(ERROR_GEN_FAILURE
);
758 pLog
->bLocal
= FALSE
;
760 if (!EvtBindRpc(lpUNCServerName
, &pLog
->BindingHandle
))
762 HeapFree(GetProcessHeap(), 0, pLog
);
763 SetLastError(ERROR_INVALID_COMPUTERNAME
);
768 Status
= ElfrRegisterEventSourceW(
770 UNCServerName
.Buffer
,
777 if (!NT_SUCCESS(Status
))
779 SetLastError(RtlNtStatusToDosError(Status
));
780 HeapFree(GetProcessHeap(), 0, pLog
);
787 /******************************************************************************
788 * ReportEventA [ADVAPI32.@]
799 IN LPCSTR
*lpStrings
,
802 LPCWSTR
*wideStrArray
;
807 if (wNumStrings
== 0)
810 if (lpStrings
== NULL
)
813 wideStrArray
= HeapAlloc(
816 sizeof(LPCWSTR
) * wNumStrings
);
818 for (i
= 0; i
< wNumStrings
; i
++)
820 if (!RtlCreateUnicodeStringFromAsciiz(&str
, (PSTR
)lpStrings
[i
]))
822 wideStrArray
[i
] = str
.Buffer
;
825 if (i
== wNumStrings
)
840 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
844 for (i
= 0; i
< wNumStrings
; i
++)
851 (PVOID
)wideStrArray
[i
]);
864 /******************************************************************************
865 * ReportEventW [ADVAPI32.@]
887 IN LPCWSTR
*lpStrings
,
893 UNICODE_STRING
*Strings
;
896 TRACE("%p, %u, %u, %lu, %p, %u, %lu, %p, %p\n",
897 hEventLog
, wType
, wCategory
, dwEventID
, lpUserSid
,
898 wNumStrings
, dwDataSize
, lpStrings
, lpRawData
);
900 pLog
= (PLOG_INFO
)hEventLog
;
903 SetLastError(ERROR_INVALID_HANDLE
);
910 wNumStrings
* sizeof(UNICODE_STRING
));
913 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
916 for (i
= 0; i
< wNumStrings
; i
++)
917 RtlInitUnicodeString(&Strings
[i
], lpStrings
[i
]);
919 Status
= ElfrReportEventW(
928 L
"", /* FIXME: ComputerName */
930 (LPWSTR
*)lpStrings
, /* FIXME: should be Strings */
935 HeapFree(GetProcessHeap(), 0, Strings
);
937 if (!NT_SUCCESS(Status
))
939 SetLastError(RtlNtStatusToDosError(Status
));
948 if (wNumStrings
== 0)
951 if (lpStrings
== NULL
)
954 for (i
= 0; i
< wNumStrings
; i
++)
958 case EVENTLOG_SUCCESS
:
959 TRACE_(eventlog
)("Success: %S\n", lpStrings
[i
]);
962 case EVENTLOG_ERROR_TYPE
:
963 ERR_(eventlog
)("Error: %S\n", lpStrings
[i
]);
966 case EVENTLOG_WARNING_TYPE
:
967 WARN_(eventlog
)("Warning: %S\n", lpStrings
[i
]);
970 case EVENTLOG_INFORMATION_TYPE
:
971 TRACE_(eventlog
)("Info: %S\n", lpStrings
[i
]);
975 TRACE_(eventlog
)("Type %hu: %S\n", wType
, lpStrings
[i
]);