HeapFree(GetProcessHeap(), 0, hManager);
hManager = NULL;
+ *hSCObject = NULL;
+
DPRINT("RCloseServiceHandle() done\n");
return ERROR_SUCCESS;
}
{
DPRINT("Found service handle\n");
+ /* Lock the service database exlusively */
+ ScmLockDatabaseExclusive();
+
/* Get the pointer to the service record */
lpService = hService->ServiceEntry;
if (dwError != ERROR_SUCCESS)
{
DPRINT("Failed to open services key\n");
+ ScmUnlockDatabase();
return dwError;
}
{
DPRINT("Deletion failed due to running dependencies.\n");
RegCloseKey(hServicesKey);
+ ScmUnlockDatabase();
return ERROR_SUCCESS;
}
if (dwError != ERROR_SUCCESS)
{
DPRINT("Failed to Delete the Service Registry key\n");
+ ScmUnlockDatabase();
return dwError;
}
}
}
+ ScmUnlockDatabase();
+
+ *hSCObject = NULL;
+
DPRINT("RCloseServiceHandle() done\n");
return ERROR_SUCCESS;
}
return ERROR_INVALID_HANDLE;
}
- /* FIXME: Acquire service database lock exclusively */
+ /* Lock the service database exclusively */
+ ScmLockDatabaseExclusive();
if (lpService->bDeleted)
{
DPRINT("The service has already been marked for delete!\n");
- return ERROR_SERVICE_MARKED_FOR_DELETE;
+ dwError = ERROR_SERVICE_MARKED_FOR_DELETE;
+ goto Done;
}
/* Mark service for delete */
dwError = ScmMarkServiceForDelete(lpService);
- /* FIXME: Release service database lock */
+Done:;
+ /* Unlock the service database */
+ ScmUnlockDatabase();
DPRINT("RDeleteService() done\n");
return ERROR_INVALID_HANDLE;
}
- if (dwSecurityInformation & (DACL_SECURITY_INFORMATION ||
- GROUP_SECURITY_INFORMATION ||
+ if (dwSecurityInformation & (DACL_SECURITY_INFORMATION |
+ GROUP_SECURITY_INFORMATION |
OWNER_SECURITY_INFORMATION))
DesiredAccess |= READ_CONTROL;
return ERROR_INVALID_HANDLE;
}
+ /* Lock the srevice database shared */
ScmLockDatabaseShared();
/* Return service status information */
&lpService->Status,
sizeof(SERVICE_STATUS));
+ /* Unlock the service database */
ScmUnlockDatabase();
return ERROR_SUCCESS;
return ERROR_INVALID_DATA;
}
+ /* Lock the service database exclusively */
ScmLockDatabaseExclusive();
RtlCopyMemory(&lpService->Status,
lpServiceStatus,
sizeof(SERVICE_STATUS));
+ /* Unlock the service database */
ScmUnlockDatabase();
DPRINT("Set %S to %lu\n", lpService->lpDisplayName, lpService->Status.dwCurrentState);
return ERROR_INVALID_HANDLE;
}
- /* FIXME: Lock database exclusively */
+ /* Lock the service database exclusively */
+ ScmLockDatabaseExclusive();
if (lpService->bDeleted)
{
- /* FIXME: Unlock database */
DPRINT("The service has already been marked for delete!\n");
- return ERROR_SERVICE_MARKED_FOR_DELETE;
+ dwError = ERROR_SERVICE_MARKED_FOR_DELETE;
+ goto done;
}
/* Open the service key */
/* FIXME: Write password */
}
- /* FIXME: Unlock database */
-
done:
if (hServiceKey != NULL)
RegCloseKey(hServiceKey);
+ /* Unlock the service database */
+ ScmUnlockDatabase();
+
DPRINT("RChangeServiceConfigW() done (Error %lu)\n", dwError);
return dwError;
if (lpResumeHandle)
dwLastResumeCount = *lpResumeHandle;
- /* FIXME: Lock the service list shared */
+ /* Lock the service database shared */
+ ScmLockDatabaseShared();
lpService = ScmGetServiceEntryByResumeCount(dwLastResumeCount);
if (lpService == NULL)
}
Done:;
- /* FIXME: Unlock the service list */
+ /* Unlock the service database */
+ ScmUnlockDatabase();
DPRINT("REnumServicesStatusW() done (Error %lu)\n", dwError);
PSERVICE lpService;
PMANAGER_HANDLE hManager;
SC_HANDLE hHandle;
- DWORD dwError;
+ DWORD dwError = ERROR_SUCCESS;
DPRINT("ROpenServiceW() called\n");
DPRINT("hSCManager = %p\n", hSCManager);
if (!lpServiceName)
return ERROR_INVALID_ADDRESS;
- /* FIXME: Lock the service list */
+ /* Lock the service database exclusive */
+ ScmLockDatabaseExclusive();
/* Get service database entry */
lpService = ScmGetServiceEntryByName(lpServiceName);
if (lpService == NULL)
{
DPRINT("Could not find a service!\n");
- return ERROR_SERVICE_DOES_NOT_EXIST;
+ dwError = ERROR_SERVICE_DOES_NOT_EXIST;
+ goto Done;
}
/* Create a service handle */
if (dwError != ERROR_SUCCESS)
{
DPRINT("ScmCreateServiceHandle() failed (Error %lu)\n", dwError);
- return dwError;
+ goto Done;
}
/* Check the desired access */
{
DPRINT("ScmCheckAccess() failed (Error %lu)\n", dwError);
HeapFree(GetProcessHeap(), 0, hHandle);
- return dwError;
+ goto Done;
}
lpService->dwRefCount++;
*lpServiceHandle = (SC_RPC_HANDLE)hHandle;
DPRINT("*hService = %p\n", *lpServiceHandle);
+Done:;
+ /* Unlock the service database */
+ ScmUnlockDatabase();
+
DPRINT("ROpenServiceW() done\n");
- return ERROR_SUCCESS;
+ return dwError;
}
return ERROR_INVALID_HANDLE;
}
- /* FIXME: Lock the service database shared */
+ /* Lock the service database shared */
+ ScmLockDatabaseShared();
dwError = ScmOpenServiceKey(lpService->lpServiceName,
KEY_READ,
*pcbBytesNeeded = dwRequiredSize;
Done:;
+ /* Unlock the service database */
+ ScmUnlockDatabase();
+
if (lpImagePath != NULL)
HeapFree(GetProcessHeap(), 0, lpImagePath);
if (hServiceKey != NULL)
RegCloseKey(hServiceKey);
- /* FIXME: Unlock the service database */
-
DPRINT("RQueryServiceConfigW() done\n");
return dwError;
return ERROR_INVALID_HANDLE;
}
- /* FIXME: Lock database exclusively */
+ /* Lock the service database exclusively */
+ ScmLockDatabaseExclusive();
if (lpService->bDeleted)
{
- /* FIXME: Unlock database */
DPRINT("The service has already been marked for delete!\n");
- return ERROR_SERVICE_MARKED_FOR_DELETE;
+ dwError = ERROR_SERVICE_MARKED_FOR_DELETE;
+ goto done;
}
/* Open the service key */
/* FIXME: Write password */
}
- /* FIXME: Unlock database */
-
done:
+ /* Unlock the service database */
+ ScmUnlockDatabase();
+
if (hServiceKey != NULL)
RegCloseKey(hServiceKey);
return ERROR_INVALID_HANDLE;
}
- /* FIXME: Lock the service database shared */
+ /* Lock the service database shared */
+ ScmLockDatabaseShared();
dwError = ScmOpenServiceKey(lpService->lpServiceName,
KEY_READ,
*pcbBytesNeeded = dwRequiredSize;
Done:;
+ /* Unlock the service database */
+ ScmUnlockDatabase();
+
if (lpImagePath != NULL)
HeapFree(GetProcessHeap(), 0, lpImagePath);
if (hServiceKey != NULL)
RegCloseKey(hServiceKey);
- /* FIXME: Unlock the service database */
-
DPRINT("RQueryServiceConfigA() done\n");
return dwError;
return ERROR_INVALID_HANDLE;
}
- /* FIXME: Lock database exclusively */
+ /* Lock the service database exclusively */
+ ScmLockDatabaseExclusive();
if (lpService->bDeleted)
{
- /* FIXME: Unlock database */
DPRINT("The service has already been marked for delete!\n");
- return ERROR_SERVICE_MARKED_FOR_DELETE;
+ dwError = ERROR_SERVICE_MARKED_FOR_DELETE;
+ goto done;
}
/* Open the service key */
}
done:
- /* FIXME: Unlock database */
+ /* Unlock the service database */
+ ScmUnlockDatabase();
+
if (hServiceKey != NULL)
RegCloseKey(hServiceKey);
return ERROR_INVALID_HANDLE;
}
- /* FIXME: Lock the service database shared */
+ /* Lock the service database shared */
+ ScmLockDatabaseShared();
dwError = ScmOpenServiceKey(lpService->lpServiceName,
KEY_READ,
LPSERVICE_DESCRIPTIONA lpServiceDescription = (LPSERVICE_DESCRIPTIONA)lpBuffer;
LPSTR lpStr;
- *pcbBytesNeeded = sizeof(SERVICE_DESCRIPTIONA);
-
dwError = ScmReadString(hServiceKey,
L"Description",
&lpDescriptionW);
+ if (dwError != ERROR_SUCCESS && dwError != ERROR_FILE_NOT_FOUND)
+ goto done;
+
+ *pcbBytesNeeded = sizeof(SERVICE_DESCRIPTIONA);
if (dwError == ERROR_SUCCESS)
- {
*pcbBytesNeeded += ((wcslen(lpDescriptionW) + 1) * sizeof(WCHAR));
- }
- if (cbBufSize >= *pcbBytesNeeded)
+ if (cbBufSize < *pcbBytesNeeded)
{
+ dwError = ERROR_INSUFFICIENT_BUFFER;
+ goto done;
+ }
- if (dwError == ERROR_SUCCESS)
- {
- lpStr = (LPSTR)(lpServiceDescription + 1);
+ if (dwError == ERROR_SUCCESS)
+ {
+ lpStr = (LPSTR)(lpServiceDescription + 1);
- WideCharToMultiByte(CP_ACP,
- 0,
- lpDescriptionW,
- -1,
- lpStr,
- wcslen(lpDescriptionW),
- NULL,
- NULL);
- lpServiceDescription->lpDescription = (LPSTR)((ULONG_PTR)lpStr - (ULONG_PTR)lpServiceDescription);
- }
- else
- {
- lpServiceDescription->lpDescription = NULL;
- goto done;
- }
+ WideCharToMultiByte(CP_ACP,
+ 0,
+ lpDescriptionW,
+ -1,
+ lpStr,
+ wcslen(lpDescriptionW),
+ NULL,
+ NULL);
+ lpServiceDescription->lpDescription = (LPSTR)((ULONG_PTR)lpStr - (ULONG_PTR)lpServiceDescription);
}
else
{
- dwError = ERROR_INSUFFICIENT_BUFFER;
+ lpServiceDescription->lpDescription = NULL;
+ dwError = ERROR_SUCCESS;
goto done;
}
}
}
done:
+ /* Unlock the service database */
+ ScmUnlockDatabase();
+
if (lpDescription != NULL)
HeapFree(GetProcessHeap(), 0, lpDescription);
if (hServiceKey != NULL)
RegCloseKey(hServiceKey);
- /* FIXME: Unlock database */
-
DPRINT("RQueryServiceConfig2W() done (Error %lu)\n", dwError);
return dwError;
return ERROR_INVALID_HANDLE;
}
- /* FIXME: Lock the service database shared */
+ /* Lock the service database shared */
+ ScmLockDatabaseShared();
dwError = ScmOpenServiceKey(lpService->lpServiceName,
KEY_READ,
dwError = ScmReadString(hServiceKey,
L"Description",
&lpDescription);
- if (dwError != ERROR_SUCCESS)
+ if (dwError != ERROR_SUCCESS && dwError != ERROR_FILE_NOT_FOUND)
goto done;
- dwRequiredSize = sizeof(SERVICE_DESCRIPTIONW) + ((wcslen(lpDescription) + 1) * sizeof(WCHAR));
+ *pcbBytesNeeded = sizeof(SERVICE_DESCRIPTIONW);
+ if (dwError == ERROR_SUCCESS)
+ *pcbBytesNeeded += ((wcslen(lpDescription) + 1) * sizeof(WCHAR));
- if (cbBufSize < dwRequiredSize)
+ if (cbBufSize < *pcbBytesNeeded)
{
- *pcbBytesNeeded = dwRequiredSize;
dwError = ERROR_INSUFFICIENT_BUFFER;
goto done;
}
- lpStr = (LPWSTR)(lpServiceDescription + 1);
- wcscpy(lpStr, lpDescription);
- lpServiceDescription->lpDescription = (LPWSTR)((ULONG_PTR)lpStr - (ULONG_PTR)lpServiceDescription);
+ if (dwError == ERROR_SUCCESS)
+ {
+ lpStr = (LPWSTR)(lpServiceDescription + 1);
+ wcscpy(lpStr, lpDescription);
+ lpServiceDescription->lpDescription = (LPWSTR)((ULONG_PTR)lpStr - (ULONG_PTR)lpServiceDescription);
+ }
+ else
+ {
+ lpServiceDescription->lpDescription = NULL;
+ dwError = ERROR_SUCCESS;
+ }
}
else if (dwInfoLevel == SERVICE_CONFIG_FAILURE_ACTIONS)
{
}
done:
+ /* Unlock the service database */
+ ScmUnlockDatabase();
+
if (lpDescription != NULL)
HeapFree(GetProcessHeap(), 0, lpDescription);
if (hServiceKey != NULL)
RegCloseKey(hServiceKey);
- /* FIXME: Unlock database */
-
DPRINT("RQueryServiceConfig2W() done (Error %lu)\n", dwError);
return dwError;
return ERROR_INVALID_HANDLE;
}
+ /* Lock the service database shared */
+ ScmLockDatabaseShared();
+
lpStatus = (LPSERVICE_STATUS_PROCESS)lpBuffer;
/* Return service status information */
lpStatus->dwProcessId = lpService->ProcessId; /* FIXME */
lpStatus->dwServiceFlags = 0; /* FIXME */
+ /* Unlock the service database */
+ ScmUnlockDatabase();
+
return ERROR_SUCCESS;
}
return ERROR_ACCESS_DENIED;
}
- if (lpResumeIndex) dwLastResumeCount = *lpResumeIndex;
+ if (lpResumeIndex)
+ dwLastResumeCount = *lpResumeIndex;
- /* Lock the service list shared */
+ /* FIXME: Lock the service list shared */
lpService = ScmGetServiceEntryByResumeCount(dwLastResumeCount);
if (lpService == NULL)
}
Done:;
- /* Unlock the service list */
+ /* FIXME: Unlock the service list */
DPRINT("REnumServicesStatusExW() done (Error %lu)\n", dwError);