branch update for HEAD-2003091401
[reactos.git] / lib / advapi32 / service / scm.c
index f1198fa..69a138f 100644 (file)
@@ -25,6 +25,8 @@
 
 /**********************************************************************
  *  ChangeServiceConfigA
+ *
+ * @unimplemented
  */
 BOOL
 STDCALL
@@ -48,6 +50,8 @@ ChangeServiceConfigA(
 
 /**********************************************************************
  *  ChangeServiceConfigW
+ *
+ * @unimplemented
  */
 BOOL
 STDCALL
@@ -71,6 +75,8 @@ ChangeServiceConfigW(
 
 /**********************************************************************
  *  CloseServiceHandle
+ *
+ * @implemented
  */
 BOOL 
 STDCALL
@@ -90,6 +96,8 @@ CloseServiceHandle(SC_HANDLE hSCObject)
 
 /**********************************************************************
  *  ControlService
+ *
+ * @unimplemented
  */
 BOOL
 STDCALL
@@ -104,6 +112,8 @@ ControlService(SC_HANDLE        hService,
 
 /**********************************************************************
  *  CreateServiceA
+ *
+ * @unimplemented
  */
 SC_HANDLE
 STDCALL
@@ -129,6 +139,8 @@ CreateServiceA(
 
 /**********************************************************************
  *  CreateServiceW
+ *
+ * @unimplemented
  */
 SC_HANDLE
 STDCALL
@@ -154,6 +166,8 @@ CreateServiceW(
 
 /**********************************************************************
  *  DeleteService
+ *
+ * @unimplemented
  */
 BOOL
 STDCALL
@@ -166,6 +180,8 @@ DeleteService(SC_HANDLE hService)
 
 /**********************************************************************
  *  EnumDependentServicesA
+ *
+ * @unimplemented
  */
 BOOL
 STDCALL
@@ -184,6 +200,8 @@ EnumDependentServicesA(
 
 /**********************************************************************
  *  EnumDependentServicesW
+ *
+ * @unimplemented
  */
 BOOL
 STDCALL
@@ -203,7 +221,7 @@ EnumDependentServicesW(
 /**********************************************************************
  *  EnumServiceGroupW
  *
- * (unknown)
+ * @unimplemented
  */
 BOOL
 STDCALL
@@ -225,6 +243,8 @@ EnumServiceGroupW (
 
 /**********************************************************************
  *  EnumServicesStatusA
+ *
+ * @unimplemented
  */
 BOOL
 STDCALL
@@ -245,6 +265,8 @@ EnumServicesStatusA (
 
 /**********************************************************************
  *  EnumServicesStatusExA
+ *
+ * @unimplemented
  */
 BOOL
 STDCALL
@@ -266,6 +288,8 @@ EnumServicesStatusExA(SC_HANDLE  hSCManager,
 
 /**********************************************************************
  *  EnumServicesStatusExW
+ *
+ * @unimplemented
  */
 BOOL
 STDCALL
@@ -287,6 +311,8 @@ EnumServicesStatusExW(SC_HANDLE  hSCManager,
 
 /**********************************************************************
  *  EnumServicesStatusW
+ *
+ * @unimplemented
  */
 BOOL
 STDCALL
@@ -307,6 +333,8 @@ EnumServicesStatusW(
 
 /**********************************************************************
  *  GetServiceDisplayNameA
+ *
+ * @unimplemented
  */
 BOOL
 STDCALL
@@ -323,6 +351,8 @@ GetServiceDisplayNameA(
 
 /**********************************************************************
  *  GetServiceDisplayNameW
+ *
+ * @unimplemented
  */
 BOOL
 STDCALL
@@ -339,6 +369,8 @@ GetServiceDisplayNameW(
 
 /**********************************************************************
  *  GetServiceKeyNameA
+ *
+ * @unimplemented
  */
 BOOL
 STDCALL
@@ -355,6 +387,8 @@ GetServiceKeyNameA(
 
 /**********************************************************************
  *  GetServiceKeyNameW
+ *
+ * @unimplemented
  */
 BOOL
 STDCALL
@@ -370,6 +404,8 @@ GetServiceKeyNameW(
 
 /**********************************************************************
  *  LockServiceDatabase
+ *
+ * @unimplemented
  */
 SC_LOCK
 STDCALL
@@ -382,6 +418,8 @@ LockServiceDatabase(SC_HANDLE   hSCManager)
 
 /**********************************************************************
  *  OpenSCManagerA
+ *
+ * @unplemented
  */
 SC_HANDLE STDCALL
 OpenSCManagerA(LPCSTR lpMachineName,
@@ -413,168 +451,190 @@ OpenSCManagerA(LPCSTR lpMachineName,
 
 /**********************************************************************
  *  OpenSCManagerW
+ *
+ * @unimplemented
  */
 SC_HANDLE STDCALL OpenSCManagerW(LPCWSTR lpMachineName,
                                  LPCWSTR lpDatabaseName,
                                  DWORD dwDesiredAccess)
 {
-    HANDLE hPipe;
-    DWORD dwMode;
-    DWORD dwWait;
-    BOOL fSuccess;
-    HANDLE hStartEvent;
-    LPWSTR lpszPipeName = L"\\\\.\\pipe\\Ntsvcs";
-    
-    DPRINT("OpenSCManagerW(%x, %x, %d)\n", lpMachineName, lpDatabaseName, dwDesiredAccess);
+  HANDLE hPipe;
+  DWORD dwMode;
+  DWORD dwWait;
+  BOOL fSuccess;
+  HANDLE hStartEvent;
+  LPWSTR lpszPipeName = L"\\\\.\\pipe\\Ntsvcs";
+
+  DPRINT("OpenSCManagerW(%x, %x, %d)\n", lpMachineName, lpDatabaseName, dwDesiredAccess);
 
-    if (lpMachineName == NULL || wcslen(lpMachineName) == 0) {
-        if (lpDatabaseName != NULL && wcscmp(lpDatabaseName, SERVICES_ACTIVE_DATABASEW) != 0) { 
-            DPRINT("OpenSCManagerW() - Invalid parameters.\n");
-            return NULL; 
-        }
+  if (lpMachineName == NULL || wcslen(lpMachineName) == 0)
+    {
+      if (lpDatabaseName != NULL && wcscmp(lpDatabaseName, SERVICES_ACTIVE_DATABASEW) != 0)
+       {
+         DPRINT("OpenSCManagerW() - Invalid parameters.\n");
+         return NULL; 
+       }
 
-        DPRINT("OpenSCManagerW() - OpenEvent(\"SvcctrlStartEvent_A3725DX\")\n");
+      DPRINT("OpenSCManagerW() - OpenEvent(\"SvcctrlStartEvent_A3725DX\")\n");
 
-        // Only connect to scm when event "SvcctrlStartEvent_A3725DX" is signaled
-        hStartEvent = OpenEvent(SYNCHRONIZE, FALSE, _T("SvcctrlStartEvent_A3725DX"));
-        if (hStartEvent == NULL) {
-            SetLastError(ERROR_DATABASE_DOES_NOT_EXIST);
-            DPRINT("OpenSCManagerW() - Failed to Open Event \"SvcctrlStartEvent_A3725DX\".\n");
-            return NULL;
-        }
+      // Only connect to scm when event "SvcctrlStartEvent_A3725DX" is signaled
+      hStartEvent = OpenEventW(SYNCHRONIZE, FALSE, L"SvcctrlStartEvent_A3725DX");
+      if (hStartEvent == NULL)
+       {
+         SetLastError(ERROR_DATABASE_DOES_NOT_EXIST);
+         DPRINT("OpenSCManagerW() - Failed to Open Event \"SvcctrlStartEvent_A3725DX\".\n");
+         return NULL;
+       }
 
-        DPRINT("OpenSCManagerW() - Waiting forever on event handle: %x\n", hStartEvent);
+      DPRINT("OpenSCManagerW() - Waiting forever on event handle: %x\n", hStartEvent);
 
 #if 1
-        dwWait = WaitForSingleObject(hStartEvent, INFINITE);
-        if (dwWait == WAIT_FAILED) {
-            DPRINT("OpenSCManagerW() - Wait For Start Event failed.\n");
-            SetLastError(ERROR_ACCESS_DENIED);
-            return NULL;
-        }
+      dwWait = WaitForSingleObject(hStartEvent, INFINITE);
+      if (dwWait == WAIT_FAILED)
+       {
+         DPRINT("OpenSCManagerW() - Wait For Start Event failed.\n");
+         SetLastError(ERROR_ACCESS_DENIED);
+         return NULL;
+       }
 #else
-        {
-            DWORD Count;
-
-   /* wait for event creation (by SCM) for max. 20 seconds */
-   for (Count = 0; Count < 20; Count++)
-     {
-        dwWait = WaitForSingleObject(hStartEvent, 1000);
-        if (dwWait == WAIT_FAILED) {
-            DPRINT("OpenSCManagerW() - Wait For Start Event failed.\n");
-            Sleep(1000);
-        } else {
-            break;
-        }
-     }
-   
-   if (dwWait == WAIT_FAILED)
-     {
-       DbgPrint("WL: Failed to wait on event \"SvcctrlStartEvent_A3725DX\"\n");
-     }
-
-        }
+       {
+          DWORD Count;
+
+         /* wait for event creation (by SCM) for max. 20 seconds */
+         for (Count = 0; Count < 20; Count++)
+           {
+             dwWait = WaitForSingleObject(hStartEvent, 1000);
+             if (dwWait == WAIT_FAILED)
+               {
+                 DPRINT("OpenSCManagerW() - Wait For Start Event failed.\n");
+                 Sleep(1000);
+               }
+             else
+               {
+                 break;
+               }
+           }
+
+         if (dwWait == WAIT_FAILED)
+           {
+             DbgPrint("WL: Failed to wait on event \"SvcctrlStartEvent_A3725DX\"\n");
+           }
+
+       }
 #endif
 
-        DPRINT("OpenSCManagerW() - Closing handle to event...\n");
-        
-        CloseHandle(hStartEvent);
-        
-        // Try to open a named pipe; wait for it, if necessary
-        while (1) {
-            DWORD dwLastError;
-            DPRINT("OpenSCManagerW() - attempting to open named pipe to SCM.\n");
-            hPipe = CreateFileW(lpszPipeName,     // pipe name
-                dwDesiredAccess,
-                0,                // no sharing
-                NULL,             // no security attributes
-                OPEN_EXISTING,    // opens existing pipe
-                0,                // default attributes
-                NULL);            // no template file
-            
-            DPRINT("OpenSCManagerW() - handle to named pipe: %x\n", hPipe);
-            // Break if the pipe handle is valid
-            if (hPipe != INVALID_HANDLE_VALUE) {
-                break;
-            }
-            
-            // Exit if an error other than ERROR_PIPE_BUSY occurs
-            dwLastError = GetLastError();
-            if (dwLastError != ERROR_PIPE_BUSY) { 
-                DPRINT("OpenSCManagerW() - returning at 4, dwLastError %d\n", dwLastError);
-                return NULL;
-            }
-            
-            // All pipe instances are busy, so wait for 20 seconds
-            if (!WaitNamedPipeW(lpszPipeName, 20000)) { 
-                DPRINT("OpenSCManagerW() - Failed on WaitNamedPipeW(...).\n");
-                return NULL;
-            }
-        }
-        
-        // The pipe connected; change to message-read mode
-        dwMode = PIPE_READMODE_MESSAGE;
-        fSuccess = SetNamedPipeHandleState(
-            hPipe,    // pipe handle
-            &dwMode,  // new pipe mode
-            NULL,     // don't set maximum bytes
-            NULL);    // don't set maximum time
-        if (!fSuccess) {
-            CloseHandle(hPipe);
-            DPRINT("OpenSCManagerW() - Failed on SetNamedPipeHandleState(...).\n");
-            return NULL;
-        }
+      DPRINT("OpenSCManagerW() - Closing handle to event...\n");
+      
+      CloseHandle(hStartEvent);
+      
+      // Try to open a named pipe; wait for it, if necessary
+      while (1)
+      {
+       DWORD dwLastError;
+       DPRINT("OpenSCManagerW() - attempting to open named pipe to SCM.\n");
+       hPipe = CreateFileW(lpszPipeName,     // pipe name
+           dwDesiredAccess,
+           0,                // no sharing
+           NULL,             // no security attributes
+           OPEN_EXISTING,    // opens existing pipe
+           0,                // default attributes
+           NULL);            // no template file
+       
+       DPRINT("OpenSCManagerW() - handle to named pipe: %x\n", hPipe);
+       // Break if the pipe handle is valid
+       if (hPipe != INVALID_HANDLE_VALUE)
+         {
+           break;
+         }
+       
+       // Exit if an error other than ERROR_PIPE_BUSY occurs
+       dwLastError = GetLastError();
+       if (dwLastError != ERROR_PIPE_BUSY)
+         {
+           DPRINT("OpenSCManagerW() - returning at 4, dwLastError %d\n", dwLastError);
+           return NULL;
+         }
+       
+       // All pipe instances are busy, so wait for 20 seconds
+       if (!WaitNamedPipeW(lpszPipeName, 20000))
+         {
+           DPRINT("OpenSCManagerW() - Failed on WaitNamedPipeW(...).\n");
+           return NULL;
+         }
+      }
+    
+      // The pipe connected; change to message-read mode
+      dwMode = PIPE_READMODE_MESSAGE;
+      fSuccess = SetNamedPipeHandleState(
+         hPipe,    // pipe handle
+         &dwMode,  // new pipe mode
+         NULL,     // don't set maximum bytes
+         NULL);    // don't set maximum time
+      if (!fSuccess)
+       {
+         CloseHandle(hPipe);
+         DPRINT("OpenSCManagerW() - Failed on SetNamedPipeHandleState(...).\n");
+         return NULL;
+       }
 #if 0
-        // Send a message to the pipe server
-        lpvMessage = (argc > 1) ? argv[1] : "default message";
-        
-        fSuccess = WriteFile(
-            hPipe,                  // pipe handle
-            lpvMessage,             // message
-            strlen(lpvMessage) + 1, // message length
-            &cbWritten,             // bytes written
-            NULL);                  // not overlapped
-        if (!fSuccess) {
-            CloseHandle(hPipe);
-            DPRINT("OpenSCManagerW() - Failed to write to pipe.\n");
-            return NULL;
-        }
-        
-        do {
-            DPRINT("OpenSCManagerW() - in I/O loop to SCM...\n");
-            // Read from the pipe
-            fSuccess = ReadFile(
-                hPipe,    // pipe handle
-                chBuf,    // buffer to receive reply
-                512,      // size of buffer
-                &cbRead,  // number of bytes read
-                NULL);    // not overlapped
-            
-            if (!fSuccess && GetLastError() != ERROR_MORE_DATA) {
-                break;
-            }
-            
-            // Reply from the pipe is written to STDOUT.
-            if (!WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), chBuf, cbRead, &cbWritten, NULL)) {
-                break;
-            }
-        } while(!fSuccess);  // repeat loop if ERROR_MORE_DATA
-        
-        DPRINT("OpenSCManagerW() - I/O loop completed.\n");
-        //CloseHandle(hPipe);
+      // Send a message to the pipe server
+      lpvMessage = (argc > 1) ? argv[1] : "default message";
+      
+      fSuccess = WriteFile(
+         hPipe,                  // pipe handle
+         lpvMessage,             // message
+         strlen(lpvMessage) + 1, // message length
+         &cbWritten,             // bytes written
+         NULL);                  // not overlapped
+      if (!fSuccess)
+       {
+         CloseHandle(hPipe);
+         DPRINT("OpenSCManagerW() - Failed to write to pipe.\n");
+         return NULL;
+       }
+      
+      do
+       {
+         DPRINT("OpenSCManagerW() - in I/O loop to SCM...\n");
+         // Read from the pipe
+         fSuccess = ReadFile(
+             hPipe,    // pipe handle
+             chBuf,    // buffer to receive reply
+             512,      // size of buffer
+             &cbRead,  // number of bytes read
+             NULL);    // not overlapped
+         
+         if (!fSuccess && GetLastError() != ERROR_MORE_DATA)
+           {
+             break;
+           }
+         
+         // Reply from the pipe is written to STDOUT.
+         if (!WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), chBuf, cbRead, &cbWritten, NULL))
+           {
+             break;
+           }
+       } while(!fSuccess);  // repeat loop if ERROR_MORE_DATA
+      
+      DPRINT("OpenSCManagerW() - I/O loop completed.\n");
+      //CloseHandle(hPipe);
 #endif
-        DPRINT("OpenSCManagerW() - success, returning handle to pipe %x\n", hPipe);
-        return hPipe;
-    } else {
-        /* FIXME: Connect to remote SCM */
-        DPRINT("OpenSCManagerW() - FIXME: Connect to remote SCM not implemented.\n");
-        return NULL;
+      DPRINT("OpenSCManagerW() - success, returning handle to pipe %x\n", hPipe);
+      return hPipe;
+    }
+  else
+    {
+      /* FIXME: Connect to remote SCM */
+      DPRINT("OpenSCManagerW() - FIXME: Connect to remote SCM not implemented.\n");
+      return NULL;
     }
 }
 
 
 /**********************************************************************
  *  OpenServiceA
+ *
+ * @unimplemented
  */
 SC_HANDLE STDCALL
 OpenServiceA(SC_HANDLE hSCManager,
@@ -588,6 +648,8 @@ OpenServiceA(SC_HANDLE hSCManager,
 
 /**********************************************************************
  *  OpenServiceW
+ *
+ * @unimplemented
  */
 SC_HANDLE
 STDCALL
@@ -603,41 +665,9 @@ OpenServiceW(
 
 
 /**********************************************************************
- *  PrivilegedServiceAuditAlarmA
- */
-BOOL
-STDCALL
-PrivilegedServiceAuditAlarmA(
-    LPCSTR      SubsystemName,
-    LPCSTR      ServiceName,
-    HANDLE      ClientToken,
-    PPRIVILEGE_SET  Privileges,
-    BOOL        AccessGranted)
-{
-    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
-    return FALSE;
-}
-
-
-/**********************************************************************
- *  PrivilegedServiceAuditAlarmW
- */
-BOOL
-STDCALL
-PrivilegedServiceAuditAlarmW(
-    LPCWSTR     SubsystemName,
-    LPCWSTR     ServiceName,
-    HANDLE      ClientToken,
-    PPRIVILEGE_SET  Privileges,
-    BOOL        AccessGranted)
-{
-    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
-    return 1;
-}
-
-
-/**********************************************************************
  *  QueryServiceConfigA
+ *
+ * @unimplemented
  */
 BOOL
 STDCALL
@@ -654,6 +684,8 @@ QueryServiceConfigA(
 
 /**********************************************************************
  *  QueryServiceConfigW
+ *
+ * @unimplemented
  */
 BOOL
 STDCALL
@@ -670,6 +702,8 @@ QueryServiceConfigW(
 
 /**********************************************************************
  *  QueryServiceLockStatusA
+ *
+ * @unimplemented
  */
 BOOL
 STDCALL
@@ -686,6 +720,8 @@ QueryServiceLockStatusA(
 
 /**********************************************************************
  *  QueryServiceLockStatusW
+ *
+ * @unimplemented
  */
 BOOL
 STDCALL
@@ -702,6 +738,8 @@ QueryServiceLockStatusW(
 
 /**********************************************************************
  *  QueryServiceObjectSecurity
+ *
+ * @unimplemented
  */
 BOOL
 STDCALL
@@ -719,6 +757,8 @@ QueryServiceObjectSecurity(
 
 /**********************************************************************
  *  QueryServiceStatus
+ *
+ * @unimplemented
  */
 BOOL
 STDCALL
@@ -733,6 +773,8 @@ QueryServiceStatus(
 
 /**********************************************************************
  *  QueryServiceStatusEx
+ *
+ * @unimplemented
  */
 BOOL
 STDCALL
@@ -749,6 +791,8 @@ QueryServiceStatusEx(SC_HANDLE  hService,
 
 /**********************************************************************
  *  StartServiceA
+ *
+ * @unimplemented
  */
 BOOL
 STDCALL
@@ -766,6 +810,8 @@ StartServiceA(
 
 /**********************************************************************
  *  StartServiceW
+ *
+ * @unimplemented
  */
 BOOL
 STDCALL
@@ -781,6 +827,8 @@ StartServiceW(
 
 /**********************************************************************
  *  UnlockServiceDatabase
+ *
+ * @unimplemented
  */
 BOOL
 STDCALL