[ADVAPI32]
authorEric Kohl <eric.kohl@reactos.org>
Sun, 8 Jan 2012 10:08:33 +0000 (10:08 +0000)
committerEric Kohl <eric.kohl@reactos.org>
Sun, 8 Jan 2012 10:08:33 +0000 (10:08 +0000)
Pass an NT path to ElfrOpenBELW.

svn path=/trunk/; revision=54878

reactos/dll/win32/advapi32/service/eventlog.c

index 29073ec..58154b6 100644 (file)
@@ -551,35 +551,63 @@ HANDLE WINAPI
 OpenBackupEventLogA(IN LPCSTR lpUNCServerName,
                     IN LPCSTR lpFileName)
 {
-    ANSI_STRING FileName;
-    IELF_HANDLE LogHandle;
+    ANSI_STRING UNCServerNameA;
+    UNICODE_STRING UNCServerNameW;
+    ANSI_STRING FileNameA;
+    UNICODE_STRING FileNameW;
+    HANDLE LogHandle;
     NTSTATUS Status;
 
     TRACE("%s, %s\n", lpUNCServerName, lpFileName);
 
-    RtlInitAnsiString(&FileName, lpFileName);
-
-    RpcTryExcept
+    /* Convert the server name to unicode */
+    if (lpUNCServerName == NULL)
     {
-        Status = ElfrOpenBELA((LPSTR)lpUNCServerName,
-                              (PRPC_STRING)&FileName,
-                              1,
-                              1,
-                              &LogHandle);
+        RtlInitUnicodeString(&UNCServerNameW, NULL);
     }
-    RpcExcept(EXCEPTION_EXECUTE_HANDLER)
+    else
     {
-        Status = I_RpcMapWin32Status(RpcExceptionCode());
+        RtlInitAnsiString(&UNCServerNameA, lpUNCServerName);
+
+        Status = RtlAnsiStringToUnicodeString(&UNCServerNameW,
+                                              &UNCServerNameA,
+                                              TRUE);
+        if (!NT_SUCCESS(Status))
+        {
+            SetLastError(RtlNtStatusToDosError(Status));
+            return NULL;
+        }
     }
-    RpcEndExcept;
 
-    if (!NT_SUCCESS(Status))
+    /* Convert the file name to unicode */
+    if (lpFileName == NULL)
     {
-        SetLastError(RtlNtStatusToDosError(Status));
-        return NULL;
+        RtlInitUnicodeString(&FileNameW, NULL);
     }
+    else
+    {
+        RtlInitAnsiString(&FileNameA, lpFileName);
 
-    return (HANDLE)LogHandle;
+        Status = RtlAnsiStringToUnicodeString(&FileNameW,
+                                              &FileNameA,
+                                              TRUE);
+        if (!NT_SUCCESS(Status))
+        {
+            RtlFreeUnicodeString(&UNCServerNameW);
+            SetLastError(RtlNtStatusToDosError(Status));
+            return NULL;
+        }
+    }
+
+    /* Call the unicode function */
+    LogHandle = OpenBackupEventLogW(UNCServerNameW.Buffer,
+                                    FileNameW.Buffer);
+
+    /* Free the unicode strings */
+    RtlFreeUnicodeString(&UNCServerNameW);
+    RtlFreeUnicodeString(&FileNameW);
+
+    return LogHandle;
 }
 
 
@@ -594,18 +622,30 @@ HANDLE WINAPI
 OpenBackupEventLogW(IN LPCWSTR lpUNCServerName,
                     IN LPCWSTR lpFileName)
 {
-    UNICODE_STRING FileName;
+    UNICODE_STRING FileNameW;
     IELF_HANDLE LogHandle;
     NTSTATUS Status;
 
     TRACE("%s, %s\n", debugstr_w(lpUNCServerName), debugstr_w(lpFileName));
 
-    RtlInitUnicodeString(&FileName, lpFileName);
+    if (lpFileName == NULL)
+    {
+        RtlInitUnicodeString(&FileNameW, NULL);
+    }
+    else
+    {
+        if (!RtlDosPathNameToNtPathName_U(lpFileName, &FileNameW,
+                                          NULL, NULL))
+        {
+            SetLastError(ERROR_INVALID_PARAMETER);
+            return NULL;
+        }
+    }
 
     RpcTryExcept
     {
         Status = ElfrOpenBELW((LPWSTR)lpUNCServerName,
-                              (PRPC_UNICODE_STRING)&FileName,
+                              (PRPC_UNICODE_STRING)&FileNameW,
                               1,
                               1,
                               &LogHandle);
@@ -616,6 +656,9 @@ OpenBackupEventLogW(IN LPCWSTR lpUNCServerName,
     }
     RpcEndExcept;
 
+    if (FileNameW.Buffer != NULL)
+        RtlFreeHeap(RtlGetProcessHeap(), 0, FileNameW.Buffer);
+
     if (!NT_SUCCESS(Status))
     {
         SetLastError(RtlNtStatusToDosError(Status));