*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <advapi32.h>
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(advapi);
-WINE_DECLARE_DEBUG_CHANNEL(eventlog);
-typedef struct _LOG_INFO
+static RPC_UNICODE_STRING EmptyString = { 0, 0, L"" };
+
+static inline LPWSTR SERV_dup( LPCSTR str )
+{
+ UINT len;
+ LPWSTR wstr;
+
+ if( !str )
+ return NULL;
+ len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
+ wstr = HeapAlloc( GetProcessHeap(), 0, len*sizeof (WCHAR) );
+ MultiByteToWideChar( CP_ACP, 0, str, -1, wstr, len );
+ return wstr;
+}
+
+handle_t __RPC_USER
+EVENTLOG_HANDLE_A_bind(EVENTLOG_HANDLE_A UNCServerName)
{
- RPC_BINDING_HANDLE BindingHandle;
- LOGHANDLE LogHandle;
- BOOL bLocal;
-} LOG_INFO, *PLOG_INFO;
+ handle_t hBinding = NULL;
+ UCHAR *pszStringBinding;
+ RPC_STATUS status;
+
+ TRACE("EVENTLOG_HANDLE_A_bind() called\n");
+
+ status = RpcStringBindingComposeA(NULL,
+ (UCHAR *)"ncacn_np",
+ (UCHAR *)UNCServerName,
+ (UCHAR *)"\\pipe\\ntsvcs",
+ NULL,
+ (UCHAR **)&pszStringBinding);
+ if (status)
+ {
+ ERR("RpcStringBindingCompose returned 0x%x\n", status);
+ return NULL;
+ }
+
+ /* Set the binding handle that will be used to bind to the server. */
+ status = RpcBindingFromStringBindingA(pszStringBinding,
+ &hBinding);
+ if (status)
+ {
+ ERR("RpcBindingFromStringBinding returned 0x%x\n", status);
+ }
+
+ status = RpcStringFreeA(&pszStringBinding);
+ if (status)
+ {
+ ERR("RpcStringFree returned 0x%x\n", status);
+ }
+
+ return hBinding;
+}
+
+
+void __RPC_USER
+EVENTLOG_HANDLE_A_unbind(EVENTLOG_HANDLE_A UNCServerName,
+ handle_t hBinding)
+{
+ RPC_STATUS status;
+
+ TRACE("EVENTLOG_HANDLE_A_unbind() called\n");
+
+ status = RpcBindingFree(&hBinding);
+ if (status)
+ {
+ ERR("RpcBindingFree returned 0x%x\n", status);
+ }
+}
+
+
+handle_t __RPC_USER
+EVENTLOG_HANDLE_W_bind(EVENTLOG_HANDLE_W UNCServerName)
+{
+ handle_t hBinding = NULL;
+ LPWSTR pszStringBinding;
+ RPC_STATUS status;
+
+ TRACE("EVENTLOG_HANDLE_W_bind() called\n");
+
+ status = RpcStringBindingComposeW(NULL,
+ L"ncacn_np",
+ (LPWSTR)UNCServerName,
+ L"\\pipe\\EventLog",
+ NULL,
+ &pszStringBinding);
+ if (status)
+ {
+ ERR("RpcStringBindingCompose returned 0x%x\n", status);
+ return NULL;
+ }
+
+ /* Set the binding handle that will be used to bind to the server. */
+ status = RpcBindingFromStringBindingW(pszStringBinding,
+ &hBinding);
+ if (status)
+ {
+ ERR("RpcBindingFromStringBinding returned 0x%x\n", status);
+ }
+
+ status = RpcStringFreeW(&pszStringBinding);
+ if (status)
+ {
+ ERR("RpcStringFree returned 0x%x\n", status);
+ }
+
+ return hBinding;
+}
+
+
+void __RPC_USER
+EVENTLOG_HANDLE_W_unbind(EVENTLOG_HANDLE_W UNCServerName,
+ handle_t hBinding)
+{
+ RPC_STATUS status;
+
+ TRACE("EVENTLOG_HANDLE_W_unbind() called\n");
+
+ status = RpcBindingFree(&hBinding);
+ if (status)
+ {
+ ERR("RpcBindingFree returned 0x%x\n", status);
+ }
+}
+
/******************************************************************************
* BackupEventLogA [ADVAPI32.@]
*/
BOOL WINAPI
-BackupEventLogA(
- IN HANDLE hEventLog,
- IN LPCSTR lpBackupFileName)
+BackupEventLogA(IN HANDLE hEventLog,
+ IN LPCSTR lpBackupFileName)
{
- PLOG_INFO pLog;
+ RPC_STRING BackupFileName;
NTSTATUS Status;
- ANSI_STRING BackupFileName;
TRACE("%p, %s\n", hEventLog, lpBackupFileName);
- RtlInitAnsiString(&BackupFileName, lpBackupFileName);
+ BackupFileName.Buffer = (LPSTR)lpBackupFileName;
+ BackupFileName.Length = BackupFileName.MaximumLength =
+ lpBackupFileName ? strlen(lpBackupFileName) : 0;
+ BackupFileName.MaximumLength += sizeof(CHAR);
- pLog = (PLOG_INFO)hEventLog;
- if (!pLog)
+ RpcTryExcept
{
- SetLastError(ERROR_INVALID_HANDLE);
- return FALSE;
+ Status = ElfrBackupELFA(hEventLog,
+ &BackupFileName);
+ }
+ RpcExcept(EXCEPTION_EXECUTE_HANDLER)
+ {
+ Status = I_RpcMapWin32Status(RpcExceptionCode());
}
- Status = ElfrBackupELFA(
- pLog->BindingHandle,
- pLog->LogHandle,
- BackupFileName.Buffer);
+ RpcEndExcept;
if (!NT_SUCCESS(Status))
{
SetLastError(RtlNtStatusToDosError(Status));
return FALSE;
}
+
return TRUE;
}
* lpBackupFileName []
*/
BOOL WINAPI
-BackupEventLogW(
- IN HANDLE hEventLog,
- IN LPCWSTR lpBackupFileName)
+BackupEventLogW(IN HANDLE hEventLog,
+ IN LPCWSTR lpBackupFileName)
{
- PLOG_INFO pLog;
+ RPC_UNICODE_STRING BackupFileName;
NTSTATUS Status;
- UNICODE_STRING BackupFileName;
- TRACE("%p, %s\n", hEventLog, lpBackupFileName);
+ TRACE("%p, %s\n", hEventLog, debugstr_w(lpBackupFileName));
- RtlInitUnicodeString(&BackupFileName, lpBackupFileName);
+ BackupFileName.Buffer = (LPWSTR)lpBackupFileName;
+ BackupFileName.Length = BackupFileName.MaximumLength =
+ lpBackupFileName ? wcslen(lpBackupFileName) * sizeof(WCHAR) : 0;
+ BackupFileName.MaximumLength += sizeof(WCHAR);
- pLog = (PLOG_INFO)hEventLog;
- if (!pLog)
+ RpcTryExcept
{
- SetLastError(ERROR_INVALID_HANDLE);
- return FALSE;
+ Status = ElfrBackupELFW(hEventLog,
+ &BackupFileName);
}
- Status = ElfrBackupELFW(
- pLog->BindingHandle,
- pLog->LogHandle,
- BackupFileName.Buffer);
+ RpcExcept(EXCEPTION_EXECUTE_HANDLER)
+ {
+ Status = I_RpcMapWin32Status(RpcExceptionCode());
+ }
+ RpcEndExcept;
if (!NT_SUCCESS(Status))
{
SetLastError(RtlNtStatusToDosError(Status));
return FALSE;
}
+
return TRUE;
}
* ClearEventLogA [ADVAPI32.@]
*/
BOOL WINAPI
-ClearEventLogA(
- IN HANDLE hEventLog,
- IN LPCSTR lpBackupFileName)
+ClearEventLogA(IN HANDLE hEventLog,
+ IN LPCSTR lpBackupFileName)
{
- PLOG_INFO pLog;
+ RPC_STRING BackupFileName;
NTSTATUS Status;
- ANSI_STRING BackupFileName;
TRACE("%p, %s\n", hEventLog, lpBackupFileName);
- RtlInitAnsiString(&BackupFileName, lpBackupFileName);
+ BackupFileName.Buffer = (LPSTR)lpBackupFileName;
+ BackupFileName.Length = BackupFileName.MaximumLength =
+ lpBackupFileName ? strlen(lpBackupFileName) : 0;
+ BackupFileName.MaximumLength += sizeof(CHAR);
- pLog = (PLOG_INFO)hEventLog;
- if (!pLog)
+ RpcTryExcept
{
- SetLastError(ERROR_INVALID_HANDLE);
- return FALSE;
+ Status = ElfrClearELFA(hEventLog,
+ &BackupFileName);
}
- Status = ElfrClearELFA(
- pLog->BindingHandle,
- pLog->LogHandle,
- BackupFileName.Buffer);
+ RpcExcept(EXCEPTION_EXECUTE_HANDLER)
+ {
+ Status = I_RpcMapWin32Status(RpcExceptionCode());
+ }
+ RpcEndExcept;
if (!NT_SUCCESS(Status))
{
SetLastError(RtlNtStatusToDosError(Status));
return FALSE;
}
+
return TRUE;
}
* ClearEventLogW [ADVAPI32.@]
*/
BOOL WINAPI
-ClearEventLogW(
- IN HANDLE hEventLog,
- IN LPCWSTR lpBackupFileName)
+ClearEventLogW(IN HANDLE hEventLog,
+ IN LPCWSTR lpBackupFileName)
{
- PLOG_INFO pLog;
+ RPC_UNICODE_STRING BackupFileName;
NTSTATUS Status;
- UNICODE_STRING BackupFileName;
- TRACE("%p, %s\n", hEventLog, lpBackupFileName);
+ TRACE("%p, %s\n", hEventLog, debugstr_w(lpBackupFileName));
- RtlInitUnicodeString(&BackupFileName, lpBackupFileName);
+ BackupFileName.Buffer = (LPWSTR)lpBackupFileName;
+ BackupFileName.Length = BackupFileName.MaximumLength =
+ lpBackupFileName ? wcslen(lpBackupFileName) * sizeof(WCHAR) : 0;
+ BackupFileName.MaximumLength += sizeof(WCHAR);
- pLog = (PLOG_INFO)hEventLog;
- if (!pLog)
+ RpcTryExcept
{
- SetLastError(ERROR_INVALID_HANDLE);
- return FALSE;
+ Status = ElfrClearELFW(hEventLog,
+ &BackupFileName);
+ }
+ RpcExcept(EXCEPTION_EXECUTE_HANDLER)
+ {
+ Status = I_RpcMapWin32Status(RpcExceptionCode());
}
- Status = ElfrClearELFW(
- pLog->BindingHandle,
- pLog->LogHandle,
- BackupFileName.Buffer);
+ RpcEndExcept;
if (!NT_SUCCESS(Status))
{
SetLastError(RtlNtStatusToDosError(Status));
return FALSE;
}
+
return TRUE;
}
* CloseEventLog [ADVAPI32.@]
*/
BOOL WINAPI
-CloseEventLog(
- IN HANDLE hEventLog)
+CloseEventLog(IN HANDLE hEventLog)
{
- PLOG_INFO pLog;
NTSTATUS Status;
- TRACE("%p", hEventLog);
-
- pLog = (PLOG_INFO)hEventLog;
- if (!pLog)
- return TRUE;
+ TRACE("%p\n", hEventLog);
- if (pLog->bLocal == FALSE)
+ RpcTryExcept
{
- if (!EvtUnbindRpc(pLog->BindingHandle))
- {
- SetLastError(ERROR_ACCESS_DENIED);
- return FALSE;
- }
+ Status = ElfrCloseEL(&hEventLog);
}
- else
+ RpcExcept(EXCEPTION_EXECUTE_HANDLER)
{
- Status = ElfrCloseEL(
- pLog->BindingHandle,
- &pLog->LogHandle);
- if (!NT_SUCCESS(Status))
- {
- SetLastError(RtlNtStatusToDosError(Status));
- return FALSE;
- }
+ Status = I_RpcMapWin32Status(RpcExceptionCode());
}
+ RpcEndExcept;
- HeapFree(GetProcessHeap(), 0, pLog);
+ if (!NT_SUCCESS(Status))
+ {
+ SetLastError(RtlNtStatusToDosError(Status));
+ return FALSE;
+ }
return TRUE;
}
* RETURNS STD
*/
BOOL WINAPI
-DeregisterEventSource(
- IN HANDLE hEventLog)
+DeregisterEventSource(IN HANDLE hEventLog)
{
- PLOG_INFO pLog;
NTSTATUS Status;
TRACE("%p\n", hEventLog);
- pLog = (PLOG_INFO)hEventLog;
- if (!pLog)
- return TRUE;
+ RpcTryExcept
+ {
+ Status = ElfrDeregisterEventSource(&hEventLog);
+ }
+ RpcExcept(EXCEPTION_EXECUTE_HANDLER)
+ {
+ Status = I_RpcMapWin32Status(RpcExceptionCode());
+ }
+ RpcEndExcept;
- Status = ElfrDeregisterEventSource(
- pLog->BindingHandle,
- &pLog->LogHandle);
if (!NT_SUCCESS(Status))
{
SetLastError(RtlNtStatusToDosError(Status));
return FALSE;
}
+
return TRUE;
}
+/******************************************************************************
+ * GetEventLogInformation [ADVAPI32.@]
+ *
+ * PARAMS
+ * hEventLog [I] Handle to event log
+ * dwInfoLevel [I] Level of event log information to return
+ * lpBuffer [O] Buffer that receives the event log information
+ * cbBufSize [I] Size of the lpBuffer buffer
+ * pcbBytesNeeded [O] Required buffer size
+ */
+BOOL WINAPI
+GetEventLogInformation(IN HANDLE hEventLog,
+ IN DWORD dwInfoLevel,
+ OUT LPVOID lpBuffer,
+ IN DWORD cbBufSize,
+ OUT LPDWORD pcbBytesNeeded)
+{
+ UNIMPLEMENTED;
+ SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
+ return FALSE;
+}
+
+
/******************************************************************************
* GetNumberOfEventLogRecords [ADVAPI32.@]
*
* NumberOfRecords []
*/
BOOL WINAPI
-GetNumberOfEventLogRecords(
- IN HANDLE hEventLog,
- OUT PDWORD NumberOfRecords)
+GetNumberOfEventLogRecords(IN HANDLE hEventLog,
+ OUT PDWORD NumberOfRecords)
{
- PLOG_INFO pLog;
NTSTATUS Status;
- long Records;
+ DWORD Records;
TRACE("%p, %p\n", hEventLog, NumberOfRecords);
- pLog = (PLOG_INFO)hEventLog;
- if (!pLog)
+ if(!NumberOfRecords)
{
- SetLastError(ERROR_INVALID_HANDLE);
+ SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
- Status = ElfrNumberOfRecords(
- pLog->BindingHandle,
- pLog->LogHandle,
- &Records);
+
+ RpcTryExcept
+ {
+ Status = ElfrNumberOfRecords(hEventLog,
+ &Records);
+ }
+ RpcExcept(EXCEPTION_EXECUTE_HANDLER)
+ {
+ Status = I_RpcMapWin32Status(RpcExceptionCode());
+ }
+ RpcEndExcept;
+
if (!NT_SUCCESS(Status))
{
SetLastError(RtlNtStatusToDosError(Status));
}
*NumberOfRecords = Records;
+
return TRUE;
}
* OldestRecord []
*/
BOOL WINAPI
-GetOldestEventLogRecord(
- IN HANDLE hEventLog,
- OUT PDWORD OldestRecord)
+GetOldestEventLogRecord(IN HANDLE hEventLog,
+ OUT PDWORD OldestRecord)
{
- PLOG_INFO pLog;
NTSTATUS Status;
- long Oldest;
+ DWORD Oldest;
TRACE("%p, %p\n", hEventLog, OldestRecord);
- pLog = (PLOG_INFO)hEventLog;
- if (!pLog)
+ if(!OldestRecord)
{
- SetLastError(ERROR_INVALID_HANDLE);
+ SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
- Status = ElfrOldestRecord(
- pLog->BindingHandle,
- pLog->LogHandle,
- &Oldest);
+
+ RpcTryExcept
+ {
+ Status = ElfrOldestRecord(hEventLog,
+ &Oldest);
+ }
+ RpcExcept(EXCEPTION_EXECUTE_HANDLER)
+ {
+ Status = I_RpcMapWin32Status(RpcExceptionCode());
+ }
+ RpcEndExcept;
+
if (!NT_SUCCESS(Status))
{
SetLastError(RtlNtStatusToDosError(Status));
}
*OldestRecord = Oldest;
+
return TRUE;
}
* hEvent []
*/
BOOL WINAPI
-NotifyChangeEventLog(
- IN HANDLE hEventLog,
- IN HANDLE hEvent)
+NotifyChangeEventLog(IN HANDLE hEventLog,
+ IN HANDLE hEvent)
{
/* Use ElfrChangeNotify */
UNIMPLEMENTED;
* OpenBackupEventLogA [ADVAPI32.@]
*/
HANDLE WINAPI
-OpenBackupEventLogA(
- IN LPCSTR lpUNCServerName,
- IN LPCSTR lpFileName)
+OpenBackupEventLogA(IN LPCSTR lpUNCServerName,
+ IN LPCSTR lpFileName)
{
UNICODE_STRING UNCServerName;
UNICODE_STRING FileName;
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return NULL;
}
+
if (!RtlCreateUnicodeStringFromAsciiz(&FileName, lpFileName))
{
RtlFreeUnicodeString(&UNCServerName);
return NULL;
}
- Handle = OpenBackupEventLogW(
- UNCServerName.Buffer,
- FileName.Buffer);
+ Handle = OpenBackupEventLogW(UNCServerName.Buffer,
+ FileName.Buffer);
RtlFreeUnicodeString(&UNCServerName);
RtlFreeUnicodeString(&FileName);
* lpFileName []
*/
HANDLE WINAPI
-OpenBackupEventLogW(
- IN LPCWSTR lpUNCServerName,
- IN LPCWSTR lpFileName)
+OpenBackupEventLogW(IN LPCWSTR lpUNCServerName,
+ IN LPCWSTR lpFileName)
{
- PLOG_INFO pLog;
+ RPC_UNICODE_STRING FileName;
+ IELF_HANDLE LogHandle;
NTSTATUS Status;
- UNICODE_STRING UNCServerName;
- UNICODE_STRING FileName;
- TRACE("%s, %s\n", lpUNCServerName, lpFileName);
+ TRACE("%s, %s\n", debugstr_w(lpUNCServerName), debugstr_w(lpFileName));
- RtlInitUnicodeString(&UNCServerName, lpUNCServerName);
- RtlInitUnicodeString(&FileName, lpFileName);
+ FileName.Buffer = (LPWSTR)lpFileName;
+ FileName.Length = FileName.MaximumLength =
+ lpFileName ? wcslen(lpFileName) * sizeof(WCHAR) : 0;
+ FileName.MaximumLength += sizeof(WCHAR);
- pLog = HeapAlloc(GetProcessHeap(), 0, sizeof(LOG_INFO));
- if (!pLog)
+ RpcTryExcept
{
- SetLastError(ERROR_NOT_ENOUGH_MEMORY);
- return NULL;
+ Status = ElfrOpenBELW((LPWSTR)lpUNCServerName,
+ &FileName,
+ 1,
+ 1,
+ &LogHandle);
}
- ZeroMemory(pLog, sizeof(LOG_INFO));
-
- if (lpUNCServerName == NULL || *lpUNCServerName == 0)
- {
- pLog->bLocal = TRUE;
-
- if (!EvtGetLocalHandle(&pLog->BindingHandle))
- {
- HeapFree(GetProcessHeap(), 0, pLog);
- SetLastError(ERROR_GEN_FAILURE);
- return NULL;
- }
- }
- else
+ RpcExcept(EXCEPTION_EXECUTE_HANDLER)
{
- pLog->bLocal = FALSE;
-
- if (!EvtBindRpc(lpUNCServerName, &pLog->BindingHandle))
- {
- HeapFree(GetProcessHeap(), 0, pLog);
- SetLastError(ERROR_INVALID_COMPUTERNAME);
- return NULL;
- }
+ Status = I_RpcMapWin32Status(RpcExceptionCode());
}
-
- Status = ElfrOpenBELW(
- pLog->BindingHandle,
- UNCServerName.Buffer,
- FileName.Buffer,
- 0,
- 0,
- &pLog->LogHandle);
+ RpcEndExcept;
if (!NT_SUCCESS(Status))
{
SetLastError(RtlNtStatusToDosError(Status));
- HeapFree(GetProcessHeap(), 0, pLog);
return NULL;
}
- return pLog;
+
+ return (HANDLE)LogHandle;
}
/******************************************************************************
* OpenEventLogA [ADVAPI32.@]
+ *
+ * Opens a handle to the specified event log.
+ *
+ * PARAMS
+ * lpUNCServerName [I] UNC name of the server on which the event log is
+ * opened.
+ * lpSourceName [I] Name of the log.
+ *
+ * RETURNS
+ * Success: Handle to an event log.
+ * Failure: NULL
*/
HANDLE WINAPI
-OpenEventLogA(
- IN LPCSTR lpUNCServerName,
- IN LPCSTR lpSourceName)
+OpenEventLogA(IN LPCSTR uncname,
+ IN LPCSTR source)
{
- UNICODE_STRING UNCServerName;
- UNICODE_STRING SourceName;
- HANDLE Handle;
+ LPWSTR uncnameW, sourceW;
+ HANDLE handle;
- if (!RtlCreateUnicodeStringFromAsciiz(&UNCServerName, lpUNCServerName))
- {
- SetLastError(ERROR_NOT_ENOUGH_MEMORY);
- return NULL;
- }
- if (!RtlCreateUnicodeStringFromAsciiz(&SourceName, lpSourceName))
- {
- RtlFreeUnicodeString(&UNCServerName);
- SetLastError(ERROR_NOT_ENOUGH_MEMORY);
- return NULL;
- }
+ uncnameW = SERV_dup(uncname);
+ sourceW = SERV_dup(source);
+ handle = OpenEventLogW(uncnameW, sourceW);
+ HeapFree(GetProcessHeap(), 0, uncnameW);
+ HeapFree(GetProcessHeap(), 0, sourceW);
- Handle = OpenEventLogW(UNCServerName.Buffer, SourceName.Buffer);
-
- RtlFreeUnicodeString(&UNCServerName);
- RtlFreeUnicodeString(&SourceName);
-
- return Handle;
+ return handle;
}
* lpSourceName []
*/
HANDLE WINAPI
-OpenEventLogW(
- IN LPCWSTR lpUNCServerName,
- IN LPCWSTR lpSourceName)
+OpenEventLogW(IN LPCWSTR lpUNCServerName,
+ IN LPCWSTR lpSourceName)
{
- PLOG_INFO pLog;
+ RPC_UNICODE_STRING SourceName;
+ IELF_HANDLE LogHandle;
NTSTATUS Status;
- UNICODE_STRING UNCServerName;
- UNICODE_STRING SourceName;
- TRACE("%s, %s\n", lpUNCServerName, lpSourceName);
+ TRACE("%s, %s\n", debugstr_w(lpUNCServerName), debugstr_w(lpSourceName));
- RtlInitUnicodeString(&UNCServerName, lpUNCServerName);
- RtlInitUnicodeString(&SourceName, lpSourceName);
+ SourceName.Buffer = (LPWSTR)lpSourceName;
+ SourceName.Length = SourceName.MaximumLength =
+ lpSourceName ? wcslen(lpSourceName) * sizeof(WCHAR) : 0;
+ SourceName.MaximumLength += sizeof(WCHAR);
- pLog = HeapAlloc(GetProcessHeap(), 0, sizeof(LOG_INFO));
- if (!pLog)
+ RpcTryExcept
{
- SetLastError(ERROR_NOT_ENOUGH_MEMORY);
- return NULL;
+ Status = ElfrOpenELW((LPWSTR)lpUNCServerName,
+ &SourceName,
+ &EmptyString,
+ 1,
+ 1,
+ &LogHandle);
}
- ZeroMemory(pLog, sizeof(LOG_INFO));
-
- if (lpUNCServerName == NULL || *lpUNCServerName == 0)
+ RpcExcept(EXCEPTION_EXECUTE_HANDLER)
{
- pLog->bLocal = TRUE;
-
- if (!EvtGetLocalHandle(&pLog->BindingHandle))
- {
- HeapFree(GetProcessHeap(), 0, pLog);
- SetLastError(ERROR_GEN_FAILURE);
- return NULL;
- }
+ Status = I_RpcMapWin32Status(RpcExceptionCode());
}
- else
- {
- pLog->bLocal = FALSE;
-
- if (!EvtBindRpc(lpUNCServerName, &pLog->BindingHandle))
- {
- HeapFree(GetProcessHeap(), 0, pLog);
- SetLastError(ERROR_INVALID_COMPUTERNAME);
- return NULL;
- }
- }
-
- Status = ElfrOpenELW(
- pLog->BindingHandle,
- UNCServerName.Buffer,
- SourceName.Buffer,
- NULL,
- 0,
- 0,
- &pLog->LogHandle);
+ RpcEndExcept;
if (!NT_SUCCESS(Status))
{
SetLastError(RtlNtStatusToDosError(Status));
- HeapFree(GetProcessHeap(), 0, pLog);
return NULL;
}
- return pLog;
+
+ return (HANDLE)LogHandle;
}
* ReadEventLogA [ADVAPI32.@]
*/
BOOL WINAPI
-ReadEventLogA(
- IN HANDLE hEventLog,
- IN DWORD dwReadFlags,
- IN DWORD dwRecordOffset,
- OUT LPVOID lpBuffer,
- IN DWORD nNumberOfBytesToRead,
- OUT DWORD *pnBytesRead,
- OUT DWORD *pnMinNumberOfBytesNeeded)
+ReadEventLogA(IN HANDLE hEventLog,
+ IN DWORD dwReadFlags,
+ IN DWORD dwRecordOffset,
+ OUT LPVOID lpBuffer,
+ IN DWORD nNumberOfBytesToRead,
+ OUT DWORD *pnBytesRead,
+ OUT DWORD *pnMinNumberOfBytesNeeded)
{
- PLOG_INFO pLog;
NTSTATUS Status;
- long bytesRead, minNumberOfBytesNeeded;
+ DWORD bytesRead, minNumberOfBytesNeeded;
TRACE("%p, %lu, %lu, %p, %lu, %p, %p\n",
hEventLog, dwReadFlags, dwRecordOffset, lpBuffer,
nNumberOfBytesToRead, pnBytesRead, pnMinNumberOfBytesNeeded);
- pLog = (PLOG_INFO)hEventLog;
- if (!pLog)
+ if(!pnBytesRead || !pnMinNumberOfBytesNeeded)
{
- SetLastError(ERROR_INVALID_HANDLE);
+ SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
- Status = ElfrReadELA(
- pLog->BindingHandle,
- pLog->LogHandle,
- dwReadFlags,
- dwRecordOffset,
- nNumberOfBytesToRead,
- lpBuffer,
- &bytesRead,
- &minNumberOfBytesNeeded);
+
+ /* If buffer is NULL set nNumberOfBytesToRead to 0 to prevent rpcrt4 from
+ trying to access a null pointer */
+ if (!lpBuffer)
+ {
+ nNumberOfBytesToRead = 0;
+ }
+
+ RpcTryExcept
+ {
+ Status = ElfrReadELA(hEventLog,
+ dwReadFlags,
+ dwRecordOffset,
+ nNumberOfBytesToRead,
+ lpBuffer,
+ &bytesRead,
+ &minNumberOfBytesNeeded);
+ }
+ RpcExcept(EXCEPTION_EXECUTE_HANDLER)
+ {
+ Status = I_RpcMapWin32Status(RpcExceptionCode());
+ }
+ RpcEndExcept;
+
+ *pnBytesRead = (DWORD)bytesRead;
+ *pnMinNumberOfBytesNeeded = (DWORD)minNumberOfBytesNeeded;
+
if (!NT_SUCCESS(Status))
{
SetLastError(RtlNtStatusToDosError(Status));
return FALSE;
}
- *pnBytesRead = (DWORD)bytesRead;
- *pnMinNumberOfBytesNeeded = (DWORD)minNumberOfBytesNeeded;
return TRUE;
}
* pnMinNumberOfBytesNeeded []
*/
BOOL WINAPI
-ReadEventLogW(
- IN HANDLE hEventLog,
- IN DWORD dwReadFlags,
- IN DWORD dwRecordOffset,
- OUT LPVOID lpBuffer,
- IN DWORD nNumberOfBytesToRead,
- OUT DWORD *pnBytesRead,
- OUT DWORD *pnMinNumberOfBytesNeeded)
+ReadEventLogW(IN HANDLE hEventLog,
+ IN DWORD dwReadFlags,
+ IN DWORD dwRecordOffset,
+ OUT LPVOID lpBuffer,
+ IN DWORD nNumberOfBytesToRead,
+ OUT DWORD *pnBytesRead,
+ OUT DWORD *pnMinNumberOfBytesNeeded)
{
- PLOG_INFO pLog;
NTSTATUS Status;
- long bytesRead, minNumberOfBytesNeeded;
+ DWORD bytesRead, minNumberOfBytesNeeded;
TRACE("%p, %lu, %lu, %p, %lu, %p, %p\n",
hEventLog, dwReadFlags, dwRecordOffset, lpBuffer,
nNumberOfBytesToRead, pnBytesRead, pnMinNumberOfBytesNeeded);
- pLog = (PLOG_INFO)hEventLog;
- if (!pLog)
+ if(!pnBytesRead || !pnMinNumberOfBytesNeeded)
{
- SetLastError(ERROR_INVALID_HANDLE);
+ SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
- Status = ElfrReadELW(
- pLog->BindingHandle,
- pLog->LogHandle,
- dwReadFlags,
- dwRecordOffset,
- nNumberOfBytesToRead,
- lpBuffer,
- &bytesRead,
- &minNumberOfBytesNeeded);
+
+ /* If buffer is NULL set nNumberOfBytesToRead to 0 to prevent rpcrt4 from
+ trying to access a null pointer */
+ if (!lpBuffer)
+ {
+ nNumberOfBytesToRead = 0;
+ }
+
+ RpcTryExcept
+ {
+ Status = ElfrReadELW(hEventLog,
+ dwReadFlags,
+ dwRecordOffset,
+ nNumberOfBytesToRead,
+ lpBuffer,
+ &bytesRead,
+ &minNumberOfBytesNeeded);
+ }
+ RpcExcept(EXCEPTION_EXECUTE_HANDLER)
+ {
+ Status = I_RpcMapWin32Status(RpcExceptionCode());
+ }
+ RpcEndExcept;
+
+ *pnBytesRead = (DWORD)bytesRead;
+ *pnMinNumberOfBytesNeeded = (DWORD)minNumberOfBytesNeeded;
+
if (!NT_SUCCESS(Status))
{
SetLastError(RtlNtStatusToDosError(Status));
return FALSE;
}
- *pnBytesRead = (DWORD)bytesRead;
- *pnMinNumberOfBytesNeeded = (DWORD)minNumberOfBytesNeeded;
return TRUE;
}
* RegisterEventSourceA [ADVAPI32.@]
*/
HANDLE WINAPI
-RegisterEventSourceA(
- IN LPCSTR lpUNCServerName,
- IN LPCSTR lpSourceName)
+RegisterEventSourceA(IN LPCSTR lpUNCServerName,
+ IN LPCSTR lpSourceName)
{
UNICODE_STRING UNCServerName;
UNICODE_STRING SourceName;
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return NULL;
}
+
if (!RtlCreateUnicodeStringFromAsciiz(&SourceName, lpSourceName))
{
RtlFreeUnicodeString(&UNCServerName);
return NULL;
}
- Handle = RegisterEventSourceW(UNCServerName.Buffer, SourceName.Buffer);
+ Handle = RegisterEventSourceW(UNCServerName.Buffer,
+ SourceName.Buffer);
RtlFreeUnicodeString(&UNCServerName);
RtlFreeUnicodeString(&SourceName);
* Failure: NULL
*/
HANDLE WINAPI
-RegisterEventSourceW(
- IN LPCWSTR lpUNCServerName,
- IN LPCWSTR lpSourceName)
+RegisterEventSourceW(IN LPCWSTR lpUNCServerName,
+ IN LPCWSTR lpSourceName)
{
- PLOG_INFO pLog;
+ RPC_UNICODE_STRING SourceName;
+ IELF_HANDLE LogHandle;
NTSTATUS Status;
- UNICODE_STRING UNCServerName;
- UNICODE_STRING SourceName;
- TRACE("%s, %s\n", lpUNCServerName, lpSourceName);
+ TRACE("%s, %s\n", debugstr_w(lpUNCServerName), debugstr_w(lpSourceName));
- RtlInitUnicodeString(&UNCServerName, lpUNCServerName);
- RtlInitUnicodeString(&SourceName, lpSourceName);
+ SourceName.Buffer = (LPWSTR)lpSourceName;
+ SourceName.Length = SourceName.MaximumLength =
+ lpSourceName ? wcslen(lpSourceName) * sizeof(WCHAR) : 0;
+ SourceName.MaximumLength += sizeof(WCHAR);
- pLog = HeapAlloc(GetProcessHeap(), 0, sizeof(LOG_INFO));
- if (!pLog)
+ RpcTryExcept
{
- SetLastError(ERROR_NOT_ENOUGH_MEMORY);
- return NULL;
+ Status = ElfrRegisterEventSourceW((LPWSTR)lpUNCServerName,
+ &SourceName,
+ &EmptyString,
+ 1,
+ 1,
+ &LogHandle);
}
- ZeroMemory(pLog, sizeof(LOG_INFO));
-
- if (lpUNCServerName == NULL || *lpUNCServerName == 0)
+ RpcExcept(EXCEPTION_EXECUTE_HANDLER)
{
- pLog->bLocal = TRUE;
-
- if (!EvtGetLocalHandle(&pLog->BindingHandle))
- {
- HeapFree(GetProcessHeap(), 0, pLog);
- SetLastError(ERROR_GEN_FAILURE);
- return NULL;
- }
+ Status = I_RpcMapWin32Status(RpcExceptionCode());
}
- else
- {
- pLog->bLocal = FALSE;
-
- if (!EvtBindRpc(lpUNCServerName, &pLog->BindingHandle))
- {
- HeapFree(GetProcessHeap(), 0, pLog);
- SetLastError(ERROR_INVALID_COMPUTERNAME);
- return NULL;
- }
- }
-
- Status = ElfrRegisterEventSourceW(
- pLog->BindingHandle,
- UNCServerName.Buffer,
- SourceName.Buffer,
- L"",
- 0,
- 0,
- &pLog->LogHandle);
+ RpcEndExcept;
if (!NT_SUCCESS(Status))
{
SetLastError(RtlNtStatusToDosError(Status));
- HeapFree(GetProcessHeap(), 0, pLog);
return NULL;
}
- return pLog;
+
+ return (HANDLE)LogHandle;
}
* ReportEventA [ADVAPI32.@]
*/
BOOL WINAPI
-ReportEventA(
- IN HANDLE hEventLog,
- IN WORD wType,
- IN WORD wCategory,
- IN DWORD dwEventID,
- IN PSID lpUserSid,
- IN WORD wNumStrings,
- IN DWORD dwDataSize,
- IN LPCSTR *lpStrings,
- IN LPVOID lpRawData)
+ReportEventA(IN HANDLE hEventLog,
+ IN WORD wType,
+ IN WORD wCategory,
+ IN DWORD dwEventID,
+ IN PSID lpUserSid,
+ IN WORD wNumStrings,
+ IN DWORD dwDataSize,
+ IN LPCSTR *lpStrings,
+ IN LPVOID lpRawData)
{
LPCWSTR *wideStrArray;
UNICODE_STRING str;
if (lpStrings == NULL)
return TRUE;
- wideStrArray = HeapAlloc(
- GetProcessHeap(),
- HEAP_ZERO_MEMORY,
- sizeof(LPCWSTR) * wNumStrings);
+ wideStrArray = HeapAlloc(GetProcessHeap(),
+ HEAP_ZERO_MEMORY,
+ sizeof(LPCWSTR) * wNumStrings);
for (i = 0; i < wNumStrings; i++)
{
if (i == wNumStrings)
{
- ret = ReportEventW(
- hEventLog,
- wType,
- wCategory,
- dwEventID,
- lpUserSid,
- wNumStrings,
- dwDataSize,
- wideStrArray,
- lpRawData);
+ ret = ReportEventW(hEventLog,
+ wType,
+ wCategory,
+ dwEventID,
+ lpUserSid,
+ wNumStrings,
+ dwDataSize,
+ wideStrArray,
+ lpRawData);
}
else
{
{
if (wideStrArray[i])
{
- HeapFree(
- GetProcessHeap(),
- 0,
- (PVOID)wideStrArray[i]);
+ HeapFree(GetProcessHeap(),
+ 0,
+ (PVOID)wideStrArray[i]);
}
}
- HeapFree(
- GetProcessHeap(),
- 0,
- wideStrArray);
+ HeapFree(GetProcessHeap(),
+ 0,
+ (PVOID)wideStrArray);
return ret;
}
* lpRawData []
*/
BOOL WINAPI
-ReportEventW(
- IN HANDLE hEventLog,
- IN WORD wType,
- IN WORD wCategory,
- IN DWORD dwEventID,
- IN PSID lpUserSid,
- IN WORD wNumStrings,
- IN DWORD dwDataSize,
- IN LPCWSTR *lpStrings,
- IN LPVOID lpRawData)
+ReportEventW(IN HANDLE hEventLog,
+ IN WORD wType,
+ IN WORD wCategory,
+ IN DWORD dwEventID,
+ IN PSID lpUserSid,
+ IN WORD wNumStrings,
+ IN DWORD dwDataSize,
+ IN LPCWSTR *lpStrings,
+ IN LPVOID lpRawData)
{
-#if 0
- PLOG_INFO pLog;
NTSTATUS Status;
UNICODE_STRING *Strings;
+ UNICODE_STRING ComputerName;
WORD i;
TRACE("%p, %u, %u, %lu, %p, %u, %lu, %p, %p\n",
- hEventLog, wType, wCategory, dwEventID, lpUserSid,
- wNumStrings, dwDataSize, lpStrings, lpRawData);
+ hEventLog, wType, wCategory, dwEventID, lpUserSid,
+ wNumStrings, dwDataSize, lpStrings, lpRawData);
- pLog = (PLOG_INFO)hEventLog;
- if (!pLog)
- {
- SetLastError(ERROR_INVALID_HANDLE);
- return FALSE;
- }
-
- Strings = HeapAlloc(
- GetProcessHeap(),
- 0,
- wNumStrings * sizeof(UNICODE_STRING));
+ Strings = HeapAlloc(GetProcessHeap(),
+ 0,
+ wNumStrings * sizeof(UNICODE_STRING));
if (!Strings)
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return FALSE;
}
+
for (i = 0; i < wNumStrings; i++)
RtlInitUnicodeString(&Strings[i], lpStrings[i]);
- Status = ElfrReportEventW(
- pLog->BindingHandle,
- pLog->LogHandle,
- 0, /* FIXME: Time */
- wType,
- wCategory,
- dwEventID,
- wNumStrings,
- dwDataSize,
- L"", /* FIXME: ComputerName */
- lpUserSid,
- (LPWSTR *)lpStrings, /* FIXME: should be Strings */
- lpRawData,
- 0,
- NULL,
- NULL);
+ /*FIXME: ComputerName */
+ RtlInitUnicodeString(&ComputerName, L"");
+
+ RpcTryExcept
+ {
+ Status = ElfrReportEventW(hEventLog,
+ 0, /* FIXME: Time */
+ wType,
+ wCategory,
+ dwEventID,
+ wNumStrings,
+ dwDataSize,
+ (PRPC_UNICODE_STRING) &ComputerName,
+ lpUserSid,
+ (PRPC_UNICODE_STRING*) &Strings,
+ lpRawData,
+ 0,
+ NULL,
+ NULL);
+ }
+ RpcExcept(EXCEPTION_EXECUTE_HANDLER)
+ {
+ Status = I_RpcMapWin32Status(RpcExceptionCode());
+ }
+ RpcEndExcept;
+
HeapFree(GetProcessHeap(), 0, Strings);
if (!NT_SUCCESS(Status))
SetLastError(RtlNtStatusToDosError(Status));
return FALSE;
}
- return TRUE;
-#else
- int i;
-
- /* partial stub */
-
- if (wNumStrings == 0)
- return TRUE;
- if (lpStrings == NULL)
return TRUE;
-
- for (i = 0; i < wNumStrings; i++)
- {
- switch (wType)
- {
- case EVENTLOG_SUCCESS:
- TRACE_(eventlog)("Success: %S\n", lpStrings[i]);
- break;
-
- case EVENTLOG_ERROR_TYPE:
- ERR_(eventlog)("Error: %S\n", lpStrings[i]);
- break;
-
- case EVENTLOG_WARNING_TYPE:
- WARN_(eventlog)("Warning: %S\n", lpStrings[i]);
- break;
-
- case EVENTLOG_INFORMATION_TYPE:
- TRACE_(eventlog)("Info: %S\n", lpStrings[i]);
- break;
-
- default:
- TRACE_(eventlog)("Type %hu: %S\n", wType, lpStrings[i]);
- break;
- }
- }
-
- return TRUE;
-#endif
}