- Implement RCreateServiceA.
[reactos.git] / reactos / dll / win32 / advapi32 / service / eventlog.c
index 0f7c48b..2ad4544 100644 (file)
@@ -18,7 +18,7 @@
  *
  * 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>
@@ -28,6 +28,18 @@ 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;
+}
 
 handle_t __RPC_USER
 EVENTLOG_HANDLE_A_bind(EVENTLOG_HANDLE_A UNCServerName)
@@ -154,6 +166,7 @@ BackupEventLogA(IN HANDLE hEventLog,
     BackupFileName.Buffer = (LPSTR)lpBackupFileName;
     BackupFileName.Length = BackupFileName.MaximumLength =
         lpBackupFileName ? strlen(lpBackupFileName) : 0;
+       BackupFileName.MaximumLength += sizeof(CHAR);
 
     RpcTryExcept
     {
@@ -194,6 +207,7 @@ BackupEventLogW(IN HANDLE hEventLog,
     BackupFileName.Buffer = (LPWSTR)lpBackupFileName;
     BackupFileName.Length = BackupFileName.MaximumLength =
         lpBackupFileName ? wcslen(lpBackupFileName) * sizeof(WCHAR) : 0;
+    BackupFileName.MaximumLength += sizeof(WCHAR);
 
     RpcTryExcept
     {
@@ -231,6 +245,7 @@ ClearEventLogA(IN HANDLE hEventLog,
     BackupFileName.Buffer = (LPSTR)lpBackupFileName;
     BackupFileName.Length = BackupFileName.MaximumLength =
         lpBackupFileName ? strlen(lpBackupFileName) : 0;
+    BackupFileName.MaximumLength += sizeof(CHAR);
 
     RpcTryExcept
     {
@@ -268,6 +283,7 @@ ClearEventLogW(IN HANDLE hEventLog,
     BackupFileName.Buffer = (LPWSTR)lpBackupFileName;
     BackupFileName.Length = BackupFileName.MaximumLength =
         lpBackupFileName ? wcslen(lpBackupFileName) * sizeof(WCHAR) : 0;
+    BackupFileName.MaximumLength += sizeof(WCHAR);
 
     RpcTryExcept
     {
@@ -356,6 +372,29 @@ DeregisterEventSource(IN HANDLE hEventLog)
 }
 
 
+/******************************************************************************
+ * 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.@]
  *
@@ -372,6 +411,12 @@ GetNumberOfEventLogRecords(IN HANDLE hEventLog,
 
     TRACE("%p, %p\n", hEventLog, NumberOfRecords);
 
+    if(!NumberOfRecords)
+    {
+        SetLastError(ERROR_INVALID_PARAMETER);
+        return FALSE;
+    }
+    
     RpcTryExcept
     {
         Status = ElfrNumberOfRecords(hEventLog,
@@ -411,6 +456,12 @@ GetOldestEventLogRecord(IN HANDLE hEventLog,
 
     TRACE("%p, %p\n", hEventLog, OldestRecord);
 
+    if(!OldestRecord)
+    {
+        SetLastError(ERROR_INVALID_PARAMETER);
+        return FALSE;
+    }
+    
     RpcTryExcept
     {
         Status = ElfrOldestRecord(hEventLog,
@@ -508,13 +559,14 @@ OpenBackupEventLogW(IN LPCWSTR lpUNCServerName,
     FileName.Buffer = (LPWSTR)lpFileName;
     FileName.Length = FileName.MaximumLength =
         lpFileName ? wcslen(lpFileName) * sizeof(WCHAR) : 0;
+    FileName.MaximumLength += sizeof(WCHAR);
 
     RpcTryExcept
     {
         Status = ElfrOpenBELW((LPWSTR)lpUNCServerName,
                               &FileName,
-                              0,
-                              0,
+                              1,
+                              1,
                               &LogHandle);
     }
     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
@@ -535,35 +587,32 @@ OpenBackupEventLogW(IN LPCWSTR lpUNCServerName,
 
 /******************************************************************************
  * 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;
-
-    if (!RtlCreateUnicodeStringFromAsciiz(&UNCServerName, lpUNCServerName))
-    {
-        SetLastError(ERROR_NOT_ENOUGH_MEMORY);
-        return NULL;
-    }
+    LPWSTR uncnameW, sourceW;
+    HANDLE handle;
 
-    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;
 }
 
 
@@ -587,14 +636,15 @@ OpenEventLogW(IN LPCWSTR lpUNCServerName,
     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,
-                             0,
-                             0,
+                             1,
+                             1,
                              &LogHandle);
     }
     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
@@ -632,6 +682,12 @@ ReadEventLogA(IN HANDLE hEventLog,
         hEventLog, dwReadFlags, dwRecordOffset, lpBuffer,
         nNumberOfBytesToRead, pnBytesRead, pnMinNumberOfBytesNeeded);
 
+    if(!pnBytesRead || !pnMinNumberOfBytesNeeded)
+    {
+        SetLastError(ERROR_INVALID_PARAMETER);
+        return FALSE;
+    }
+
     /* If buffer is NULL set nNumberOfBytesToRead to 0 to prevent rpcrt4 from
        trying to access a null pointer */
     if (!lpBuffer)
@@ -696,6 +752,12 @@ ReadEventLogW(IN HANDLE hEventLog,
         hEventLog, dwReadFlags, dwRecordOffset, lpBuffer,
         nNumberOfBytesToRead, pnBytesRead, pnMinNumberOfBytesNeeded);
 
+    if(!pnBytesRead || !pnMinNumberOfBytesNeeded)
+    {
+        SetLastError(ERROR_INVALID_PARAMETER);
+        return FALSE;
+    }
+
     /* If buffer is NULL set nNumberOfBytesToRead to 0 to prevent rpcrt4 from
        trying to access a null pointer */
     if (!lpBuffer)
@@ -793,14 +855,15 @@ RegisterEventSourceW(IN LPCWSTR lpUNCServerName,
     SourceName.Buffer = (LPWSTR)lpSourceName;
     SourceName.Length = SourceName.MaximumLength =
         lpSourceName ? wcslen(lpSourceName) * sizeof(WCHAR) : 0;
+    SourceName.MaximumLength += sizeof(WCHAR);
 
     RpcTryExcept
     {
         Status = ElfrRegisterEventSourceW((LPWSTR)lpUNCServerName,
                                           &SourceName,
                                           &EmptyString,
-                                          0,
-                                          0,
+                                          1,
+                                          1,
                                           &LogHandle);
     }
     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
@@ -938,7 +1001,7 @@ ReportEventW(IN HANDLE hEventLog,
         RtlInitUnicodeString(&Strings[i], lpStrings[i]);
 
     /*FIXME: ComputerName */
-    RtlInitEmptyUnicodeString(&ComputerName, NULL, 0);
+    RtlInitUnicodeString(&ComputerName, L"");
 
     RpcTryExcept
     {