Author: ekohl
Date: Wed Feb 3 21:46:21 2010
New Revision: 45401
URL:
http://svn.reactos.org/svn/reactos?rev=45401&view=rev
Log:
- Implement GetEventLogInformation.
- OpenBackupEventLogA, OpenEventLogA, RegisterEventSourceA and ReportEventA: Call the ANSI
RPC-Server Function directly instead of converting arguments to Unicode and calling the
matching Unicode Function.
- OpenEventLogW: Fix argument checks.
Modified:
trunk/reactos/dll/win32/advapi32/service/eventlog.c
Modified: trunk/reactos/dll/win32/advapi32/service/eventlog.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/advapi32/service…
==============================================================================
--- trunk/reactos/dll/win32/advapi32/service/eventlog.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/advapi32/service/eventlog.c [iso-8859-1] Wed Feb 3 21:46:21
2010
@@ -26,20 +26,9 @@
WINE_DEFAULT_DEBUG_CHANNEL(advapi);
-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;
-}
+static RPC_UNICODE_STRING EmptyStringU = { 0, 0, L"" };
+static RPC_STRING EmptyStringA = { 0, 0, "" };
+
handle_t __RPC_USER
EVENTLOG_HANDLE_A_bind(EVENTLOG_HANDLE_A UNCServerName)
@@ -166,7 +155,7 @@
BackupFileName.Buffer = (LPSTR)lpBackupFileName;
BackupFileName.Length = BackupFileName.MaximumLength =
lpBackupFileName ? strlen(lpBackupFileName) : 0;
- BackupFileName.MaximumLength += sizeof(CHAR);
+ BackupFileName.MaximumLength += sizeof(CHAR);
RpcTryExcept
{
@@ -389,9 +378,29 @@
IN DWORD cbBufSize,
OUT LPDWORD pcbBytesNeeded)
{
- UNIMPLEMENTED;
- SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
- return FALSE;
+ NTSTATUS Status;
+
+ RpcTryExcept
+ {
+ Status = ElfrGetLogInformation(hEventLog,
+ dwInfoLevel,
+ (LPBYTE)lpBuffer,
+ cbBufSize,
+ pcbBytesNeeded);
+ }
+ RpcExcept(EXCEPTION_EXECUTE_HANDLER)
+ {
+ Status = I_RpcMapWin32Status(RpcExceptionCode());
+ }
+ RpcEndExcept;
+
+ if (!NT_SUCCESS(Status))
+ {
+ SetLastError(RtlNtStatusToDosError(Status));
+ return FALSE;
+ }
+
+ return TRUE;
}
@@ -416,7 +425,7 @@
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
-
+
RpcTryExcept
{
Status = ElfrNumberOfRecords(hEventLog,
@@ -461,7 +470,7 @@
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
-
+
RpcTryExcept
{
Status = ElfrOldestRecord(hEventLog,
@@ -510,32 +519,35 @@
OpenBackupEventLogA(IN LPCSTR lpUNCServerName,
IN LPCSTR lpFileName)
{
- UNICODE_STRING UNCServerName;
- UNICODE_STRING FileName;
- HANDLE Handle;
+ ANSI_STRING FileName;
+ IELF_HANDLE LogHandle;
+ NTSTATUS Status;
TRACE("%s, %s\n", lpUNCServerName, lpFileName);
- if (!RtlCreateUnicodeStringFromAsciiz(&UNCServerName, lpUNCServerName))
- {
- SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+ RtlInitAnsiString(&FileName, lpFileName);
+
+ RpcTryExcept
+ {
+ Status = ElfrOpenBELA((LPSTR)lpUNCServerName,
+ (PRPC_STRING)&FileName,
+ 1,
+ 1,
+ &LogHandle);
+ }
+ RpcExcept(EXCEPTION_EXECUTE_HANDLER)
+ {
+ Status = I_RpcMapWin32Status(RpcExceptionCode());
+ }
+ RpcEndExcept;
+
+ if (!NT_SUCCESS(Status))
+ {
+ SetLastError(RtlNtStatusToDosError(Status));
return NULL;
}
- if (!RtlCreateUnicodeStringFromAsciiz(&FileName, lpFileName))
- {
- RtlFreeUnicodeString(&UNCServerName);
- SetLastError(ERROR_NOT_ENOUGH_MEMORY);
- return NULL;
- }
-
- Handle = OpenBackupEventLogW(UNCServerName.Buffer,
- FileName.Buffer);
-
- RtlFreeUnicodeString(&UNCServerName);
- RtlFreeUnicodeString(&FileName);
-
- return Handle;
+ return (HANDLE)LogHandle;
}
@@ -600,19 +612,51 @@
* Failure: NULL
*/
HANDLE WINAPI
-OpenEventLogA(IN LPCSTR uncname,
- IN LPCSTR source)
-{
- LPWSTR uncnameW, sourceW;
- HANDLE handle;
-
- uncnameW = SERV_dup(uncname);
- sourceW = SERV_dup(source);
- handle = OpenEventLogW(uncnameW, sourceW);
- HeapFree(GetProcessHeap(), 0, uncnameW);
- HeapFree(GetProcessHeap(), 0, sourceW);
-
- return handle;
+OpenEventLogA(IN LPCSTR lpUNCServerName,
+ IN LPCSTR lpSourceName)
+{
+ LPSTR UNCServerName;
+ ANSI_STRING SourceName;
+ IELF_HANDLE LogHandle = NULL;
+ NTSTATUS Status;
+
+ TRACE("%s, %s\n", lpUNCServerName, lpSourceName);
+
+ if (lpSourceName == NULL)
+ {
+ SetLastError(ERROR_INVALID_PARAMETER);
+ return NULL;
+ }
+
+ if (lpUNCServerName == NULL || *lpUNCServerName == 0)
+ UNCServerName = NULL;
+ else
+ UNCServerName = (LPSTR)lpUNCServerName;
+
+ RtlInitAnsiString(&SourceName, lpSourceName);
+
+ RpcTryExcept
+ {
+ Status = ElfrOpenELA(UNCServerName,
+ (PRPC_STRING)&SourceName,
+ &EmptyStringA,
+ 1,
+ 1,
+ &LogHandle);
+ }
+ RpcExcept(EXCEPTION_EXECUTE_HANDLER)
+ {
+ Status = I_RpcMapWin32Status(RpcExceptionCode());
+ }
+ RpcEndExcept;
+
+ if (!NT_SUCCESS(Status))
+ {
+ SetLastError(RtlNtStatusToDosError(Status));
+ return NULL;
+ }
+
+ return (HANDLE)LogHandle;
}
@@ -627,22 +671,31 @@
OpenEventLogW(IN LPCWSTR lpUNCServerName,
IN LPCWSTR lpSourceName)
{
- RPC_UNICODE_STRING SourceName;
+ LPWSTR UNCServerName;
+ UNICODE_STRING SourceName;
IELF_HANDLE LogHandle;
NTSTATUS Status;
TRACE("%s, %s\n", debugstr_w(lpUNCServerName), debugstr_w(lpSourceName));
- SourceName.Buffer = (LPWSTR)lpSourceName;
- SourceName.Length = SourceName.MaximumLength =
- lpSourceName ? wcslen(lpSourceName) * sizeof(WCHAR) : 0;
- SourceName.MaximumLength += sizeof(WCHAR);
-
- RpcTryExcept
- {
- Status = ElfrOpenELW((LPWSTR)lpUNCServerName,
- &SourceName,
- &EmptyString,
+ if (lpSourceName == NULL)
+ {
+ SetLastError(ERROR_INVALID_PARAMETER);
+ return NULL;
+ }
+
+ if (lpUNCServerName == NULL || *lpUNCServerName == 0)
+ UNCServerName = NULL;
+ else
+ UNCServerName = (LPWSTR)lpUNCServerName;
+
+ RtlInitUnicodeString(&SourceName, lpSourceName);
+
+ RpcTryExcept
+ {
+ Status = ElfrOpenELW(UNCServerName,
+ (PRPC_UNICODE_STRING)&SourceName,
+ &EmptyStringU,
1,
1,
&LogHandle);
@@ -801,32 +854,36 @@
RegisterEventSourceA(IN LPCSTR lpUNCServerName,
IN LPCSTR lpSourceName)
{
- UNICODE_STRING UNCServerName;
- UNICODE_STRING SourceName;
- HANDLE Handle;
+ ANSI_STRING SourceName;
+ IELF_HANDLE LogHandle;
+ NTSTATUS Status;
TRACE("%s, %s\n", lpUNCServerName, lpSourceName);
- if (!RtlCreateUnicodeStringFromAsciiz(&UNCServerName, lpUNCServerName))
- {
- SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+ RtlInitAnsiString(&SourceName, lpSourceName);
+
+ RpcTryExcept
+ {
+ Status = ElfrRegisterEventSourceA((LPSTR)lpUNCServerName,
+ (PRPC_STRING)&SourceName,
+ &EmptyStringA,
+ 1,
+ 1,
+ &LogHandle);
+ }
+ RpcExcept(EXCEPTION_EXECUTE_HANDLER)
+ {
+ Status = I_RpcMapWin32Status(RpcExceptionCode());
+ }
+ RpcEndExcept;
+
+ if (!NT_SUCCESS(Status))
+ {
+ SetLastError(RtlNtStatusToDosError(Status));
return NULL;
}
- if (!RtlCreateUnicodeStringFromAsciiz(&SourceName, lpSourceName))
- {
- RtlFreeUnicodeString(&UNCServerName);
- SetLastError(ERROR_NOT_ENOUGH_MEMORY);
- return NULL;
- }
-
- Handle = RegisterEventSourceW(UNCServerName.Buffer,
- SourceName.Buffer);
-
- RtlFreeUnicodeString(&UNCServerName);
- RtlFreeUnicodeString(&SourceName);
-
- return Handle;
+ return (HANDLE)LogHandle;
}
@@ -861,7 +918,7 @@
{
Status = ElfrRegisterEventSourceW((LPWSTR)lpUNCServerName,
&SourceName,
- &EmptyString,
+ &EmptyStringU,
1,
1,
&LogHandle);
@@ -896,61 +953,62 @@
IN LPCSTR *lpStrings,
IN LPVOID lpRawData)
{
- LPCWSTR *wideStrArray;
- UNICODE_STRING str;
+ NTSTATUS Status;
+ ANSI_STRING *Strings;
+ ANSI_STRING ComputerName;
WORD i;
- BOOL ret;
-
- if (wNumStrings == 0)
- return TRUE;
-
- if (lpStrings == NULL)
- return TRUE;
-
- wideStrArray = HeapAlloc(GetProcessHeap(),
- HEAP_ZERO_MEMORY,
- sizeof(LPCWSTR) * wNumStrings);
+
+ TRACE("%p, %u, %u, %lu, %p, %u, %lu, %p, %p\n",
+ hEventLog, wType, wCategory, dwEventID, lpUserSid,
+ wNumStrings, dwDataSize, lpStrings, lpRawData);
+
+ Strings = HeapAlloc(GetProcessHeap(),
+ 0,
+ wNumStrings * sizeof(ANSI_STRING));
+ if (!Strings)
+ {
+ SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+ return FALSE;
+ }
for (i = 0; i < wNumStrings; i++)
- {
- if (!RtlCreateUnicodeStringFromAsciiz(&str, (PSTR)lpStrings[i]))
- break;
- wideStrArray[i] = str.Buffer;
- }
-
- if (i == wNumStrings)
- {
- ret = ReportEventW(hEventLog,
- wType,
- wCategory,
- dwEventID,
- lpUserSid,
- wNumStrings,
- dwDataSize,
- wideStrArray,
- lpRawData);
- }
- else
- {
- SetLastError(ERROR_NOT_ENOUGH_MEMORY);
- ret = FALSE;
- }
-
- for (i = 0; i < wNumStrings; i++)
- {
- if (wideStrArray[i])
- {
- HeapFree(GetProcessHeap(),
- 0,
- (PVOID)wideStrArray[i]);
- }
- }
-
- HeapFree(GetProcessHeap(),
- 0,
- (PVOID)wideStrArray);
-
- return ret;
+ RtlInitAnsiString(&Strings[i], lpStrings[i]);
+
+ /*FIXME: ComputerName */
+ RtlInitAnsiString(&ComputerName, "");
+
+ RpcTryExcept
+ {
+ Status = ElfrReportEventA(hEventLog,
+ 0, /* FIXME: Time */
+ wType,
+ wCategory,
+ dwEventID,
+ wNumStrings,
+ dwDataSize,
+ (PRPC_STRING) &ComputerName,
+ lpUserSid,
+ (PRPC_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;
}