Make service RPC interface more compatible with MS Windows

svn path=/trunk/; revision=32906
This commit is contained in:
Hervé Poussineau
2008-04-10 14:49:04 +00:00
parent 9601e9d478
commit 4e1f93f6eb
6 changed files with 1374 additions and 868 deletions
+20 -16
View File
@@ -612,7 +612,8 @@ ScmControlService(PSERVICE Service,
static DWORD
ScmSendStartCommand(PSERVICE Service,
LPWSTR Arguments)
DWORD argc,
LPWSTR *argv)
{
PSCM_CONTROL_PACKET ControlPacket;
DWORD TotalLength;
@@ -625,16 +626,14 @@ ScmSendStartCommand(PSERVICE Service,
/* Calculate the total length of the start command line */
TotalLength = wcslen(Service->lpServiceName) + 1;
if (Arguments != NULL)
if (argc > 0)
{
Ptr = Arguments;
while (*Ptr)
for (Count = 0; Count < argc; Count++)
{
Length = wcslen(Ptr) + 1;
DPRINT("Arg: %S\n", argv[Count]);
Length = wcslen(argv[Count]) + 1;
TotalLength += Length;
ArgsLength += Length;
Ptr += Length;
DPRINT("Arg: %S\n", Ptr);
}
}
TotalLength++;
@@ -655,10 +654,14 @@ ScmSendStartCommand(PSERVICE Service,
Ptr += (wcslen(Service->lpServiceName) + 1);
/* Copy argument list */
if (Arguments != NULL)
if (argc > 0)
{
UNIMPLEMENTED;
DPRINT1("Arguments sent to service ignored!\n");
#if 0
memcpy(Ptr, Arguments, ArgsLength);
Ptr += ArgsLength;
#endif
}
/* Terminate the argument list */
@@ -686,7 +689,8 @@ ScmSendStartCommand(PSERVICE Service,
static DWORD
ScmStartUserModeService(PSERVICE Service,
LPWSTR lpArgs)
DWORD argc,
LPWSTR *argv)
{
RTL_QUERY_REGISTRY_TABLE QueryTable[3];
PROCESS_INFORMATION ProcessInformation;
@@ -855,7 +859,7 @@ ScmStartUserModeService(PSERVICE Service,
DPRINT("Received service status %lu\n", Service->hClient);
/* Send start command */
dwError = ScmSendStartCommand(Service, lpArgs);
dwError = ScmSendStartCommand(Service, argc, argv);
}
}
else
@@ -878,7 +882,7 @@ ScmStartUserModeService(PSERVICE Service,
DWORD
ScmStartService(PSERVICE Service, LPWSTR lpArgs)
ScmStartService(PSERVICE Service, DWORD argc, LPWSTR *argv)
{
PSERVICE_GROUP Group = Service->lpGroup;
DWORD dwError = ERROR_SUCCESS;
@@ -898,7 +902,7 @@ ScmStartService(PSERVICE Service, LPWSTR lpArgs)
else
{
/* Start user-mode service */
dwError = ScmStartUserModeService(Service, lpArgs);
dwError = ScmStartUserModeService(Service, argc, argv);
}
DPRINT("ScmStartService() done (Error %lu)\n", dwError);
@@ -985,7 +989,7 @@ ScmAutoStartServices(VOID)
(CurrentService->dwTag == CurrentGroup->TagArray[i]))
{
CurrentService->ServiceVisited = TRUE;
ScmStartService(CurrentService, NULL);
ScmStartService(CurrentService, 0, NULL);
}
ServiceEntry = ServiceEntry->Flink;
@@ -1003,7 +1007,7 @@ ScmAutoStartServices(VOID)
(CurrentService->ServiceVisited == FALSE))
{
CurrentService->ServiceVisited = TRUE;
ScmStartService(CurrentService, NULL);
ScmStartService(CurrentService, 0, NULL);
}
ServiceEntry = ServiceEntry->Flink;
@@ -1023,7 +1027,7 @@ ScmAutoStartServices(VOID)
(CurrentService->ServiceVisited == FALSE))
{
CurrentService->ServiceVisited = TRUE;
ScmStartService(CurrentService, NULL);
ScmStartService(CurrentService, 0, NULL);
}
ServiceEntry = ServiceEntry->Flink;
@@ -1040,7 +1044,7 @@ ScmAutoStartServices(VOID)
(CurrentService->ServiceVisited == FALSE))
{
CurrentService->ServiceVisited = TRUE;
ScmStartService(CurrentService, NULL);
ScmStartService(CurrentService, 0, NULL);
}
ServiceEntry = ServiceEntry->Flink;
File diff suppressed because it is too large Load Diff
+2 -1
View File
@@ -100,7 +100,8 @@ VOID ScmGetBootAndSystemDriverState(VOID);
VOID ScmAutoStartServices(VOID);
VOID ScmAutoShutdownServices(VOID);
DWORD ScmStartService(PSERVICE Service,
LPWSTR lpArgs);
DWORD argc,
LPWSTR *argv);
PSERVICE ScmGetServiceEntryByName(LPWSTR lpServiceName);
PSERVICE ScmGetServiceEntryByDisplayName(LPWSTR lpDisplayName);
+37 -126
View File
@@ -88,20 +88,21 @@ ChangeServiceConfig2A(SC_HANDLE hService,
DWORD dwInfoLevel,
LPVOID lpInfo)
{
DWORD lpInfoSize;
SC_RPC_CONFIG_INFOA Info;
DWORD dwError;
TRACE("ChangeServiceConfig2A() called\n");
/* Determine the length of the lpInfo parameter */
/* Fill relevent field of the Info structure */
Info.dwInfoLevel = dwInfoLevel;
switch (dwInfoLevel)
{
case SERVICE_CONFIG_DESCRIPTION:
lpInfoSize = sizeof(SERVICE_DESCRIPTIONA);
Info.psd = (LPSERVICE_DESCRIPTIONA)&lpInfo;
break;
case SERVICE_CONFIG_FAILURE_ACTIONS:
lpInfoSize = sizeof(SERVICE_FAILURE_ACTIONSA);
Info.psfa = (LPSERVICE_FAILURE_ACTIONSA)&lpInfo;
break;
default:
@@ -116,10 +117,8 @@ ChangeServiceConfig2A(SC_HANDLE hService,
HandleBind();
dwError = ScmrChangeServiceConfig2A(BindingHandle,
(unsigned int)hService,
dwInfoLevel,
lpInfo,
lpInfoSize);
(SC_RPC_HANDLE)hService,
Info);
if (dwError != ERROR_SUCCESS)
{
ERR("ScmrChangeServiceConfig2A() failed (Error %lu)\n", dwError);
@@ -141,42 +140,23 @@ ChangeServiceConfig2W(SC_HANDLE hService,
DWORD dwInfoLevel,
LPVOID lpInfo)
{
LPBYTE lpSendData = NULL;
DWORD dwInfoSize;
SC_RPC_CONFIG_INFOW Info;
DWORD dwError;
TRACE("ChangeServiceConfig2W() called\n");
/* Fill relevent field of the Info structure */
Info.dwInfoLevel = dwInfoLevel;
switch (dwInfoLevel)
{
case SERVICE_CONFIG_DESCRIPTION:
{
LPSERVICE_DESCRIPTIONW lpServiceDescription = lpInfo;
DWORD dwStringSize;
dwInfoSize = sizeof(SERVICE_DESCRIPTIONW);
dwStringSize = (wcslen(lpServiceDescription->lpDescription) + 1) * sizeof(WCHAR);
dwInfoSize += dwStringSize;
lpSendData = HeapAlloc(GetProcessHeap(), 0, dwInfoSize);
if (lpSendData)
{
LPBYTE pt = lpSendData;
CopyMemory(pt, lpInfo, sizeof(SERVICE_DESCRIPTIONW));
pt += sizeof(SERVICE_DESCRIPTIONW);
CopyMemory(pt, lpServiceDescription->lpDescription, dwStringSize);
}
else
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return FALSE;
}
Info.psd = (LPSERVICE_DESCRIPTIONW)&lpInfo;
break;
}
case SERVICE_CONFIG_FAILURE_ACTIONS:
dwInfoSize = sizeof(SERVICE_FAILURE_ACTIONSW);
Info.psfa = (LPSERVICE_FAILURE_ACTIONSW)&lpInfo;
break;
default:
@@ -186,15 +166,13 @@ ChangeServiceConfig2W(SC_HANDLE hService,
}
if (lpInfo == NULL)
goto done;
return TRUE;
HandleBind();
dwError = ScmrChangeServiceConfig2W(BindingHandle,
(unsigned int)hService,
dwInfoLevel,
lpSendData,
dwInfoSize);
(SC_RPC_HANDLE)hService,
Info);
if (dwError != ERROR_SUCCESS)
{
ERR("ScmrChangeServiceConfig2W() failed (Error %lu)\n", dwError);
@@ -202,12 +180,6 @@ ChangeServiceConfig2W(SC_HANDLE hService,
return FALSE;
}
done:
if (lpSendData != NULL)
HeapFree(GetProcessHeap(), 0, lpSendData);
TRACE("ChangeServiceConfig2W() done\n");
return TRUE;
}
@@ -324,14 +296,14 @@ ChangeServiceConfigW(SC_HANDLE hService,
/* Call to services.exe using RPC */
dwError = ScmrChangeServiceConfigW(BindingHandle,
(unsigned int)hService,
(SC_RPC_HANDLE)hService,
dwServiceType,
dwStartType,
dwErrorControl,
(LPWSTR)lpBinaryPathName,
(LPWSTR)lpLoadOrderGroup,
lpdwTagId,
(LPWSTR)lpDependencies,
(LPBYTE)lpDependencies,
dwDependenciesLength,
(LPWSTR)lpServiceStartName,
NULL, /* FIXME: lpPassword */
@@ -364,7 +336,7 @@ CloseServiceHandle(SC_HANDLE hSCObject)
/* Call to services.exe using RPC */
dwError = ScmrCloseServiceHandle(BindingHandle,
(unsigned int)hSCObject);
(LPSC_RPC_HANDLE)&hSCObject);
if (dwError)
{
ERR("ScmrCloseServiceHandle() failed (Error %lu)\n", dwError);
@@ -644,7 +616,7 @@ CreateServiceW(SC_HANDLE hSCManager,
/* Call to services.exe using RPC */
dwError = ScmrCreateServiceW(BindingHandle,
(unsigned int)hSCManager,
(SC_RPC_HANDLE)hSCManager,
(LPWSTR)lpServiceName,
(LPWSTR)lpDisplayName,
dwDesiredAccess,
@@ -654,12 +626,12 @@ CreateServiceW(SC_HANDLE hSCManager,
(LPWSTR)lpBinaryPathName,
(LPWSTR)lpLoadOrderGroup,
lpdwTagId,
(LPWSTR)lpDependencies,
(LPBYTE)lpDependencies,
dwDependenciesLength,
(LPWSTR)lpServiceStartName,
NULL, /* FIXME: lpPassword */
0, /* FIXME: dwPasswordLength */
(unsigned long *)&hService);
(SC_RPC_HANDLE *)&hService);
if (dwError != ERROR_SUCCESS)
{
ERR("ScmrCreateServiceW() failed (Error %lu)\n", dwError);
@@ -1256,8 +1228,8 @@ LockServiceDatabase(SC_HANDLE hSCManager)
/* Call to services.exe using RPC */
dwError = ScmrLockServiceDatabase(BindingHandle,
(unsigned int)hSCManager,
(unsigned int *)&hLock);
(SC_RPC_HANDLE)hSCManager,
(SC_RPC_LOCK *)&hLock);
if (dwError != ERROR_SUCCESS)
{
ERR("ScmrLockServiceDatabase() failed (Error %lu)\n", dwError);
@@ -1483,8 +1455,8 @@ QueryServiceConfigA(SC_HANDLE hService,
/* Call to services.exe using RPC */
dwError = ScmrQueryServiceConfigA(BindingHandle,
(unsigned int)hService,
(unsigned char *)lpServiceConfig,
(SC_RPC_HANDLE)hService,
lpServiceConfig,
cbBufSize,
pcbBytesNeeded);
if (dwError != ERROR_SUCCESS)
@@ -1546,8 +1518,8 @@ QueryServiceConfigW(SC_HANDLE hService,
/* Call to services.exe using RPC */
dwError = ScmrQueryServiceConfigW(BindingHandle,
(unsigned int)hService,
(unsigned char *)lpServiceConfig,
(SC_RPC_HANDLE)hService,
(LPBYTE)lpServiceConfig,
cbBufSize,
pcbBytesNeeded);
if (dwError != ERROR_SUCCESS)
@@ -1758,8 +1730,8 @@ QueryServiceLockStatusA(SC_HANDLE hSCManager,
/* Call to services.exe using RPC */
dwError = ScmrQueryServiceLockStatusA(BindingHandle,
(unsigned int)hSCManager,
(unsigned char *)lpLockStatus,
(SC_RPC_HANDLE)hSCManager,
lpLockStatus,
cbBufSize,
pcbBytesNeeded);
if (dwError != ERROR_SUCCESS)
@@ -1800,8 +1772,8 @@ QueryServiceLockStatusW(SC_HANDLE hSCManager,
/* Call to services.exe using RPC */
dwError = ScmrQueryServiceLockStatusW(BindingHandle,
(unsigned int)hSCManager,
(unsigned char *)lpLockStatus,
(SC_RPC_HANDLE)hSCManager,
lpLockStatus,
cbBufSize,
pcbBytesNeeded);
if (dwError != ERROR_SUCCESS)
@@ -2000,45 +1972,13 @@ StartServiceA(SC_HANDLE hService,
DWORD dwNumServiceArgs,
LPCSTR *lpServiceArgVectors)
{
LPSTR lpBuffer = NULL;
LPSTR lpStr;
DWORD dwError;
DWORD dwBufSize = 0;
DWORD i;
if (dwNumServiceArgs > 0)
{
for (i = 0; i < dwNumServiceArgs; i++)
{
dwBufSize += (strlen(lpServiceArgVectors[i]) + 1);
}
dwBufSize++;
TRACE("dwBufSize: %lu\n", dwBufSize);
lpBuffer = HeapAlloc(GetProcessHeap(), 0, dwBufSize);
if (lpBuffer == NULL)
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return FALSE;
}
lpStr = lpBuffer;
for (i = 0; i < dwNumServiceArgs; i++)
{
strcpy(lpStr, lpServiceArgVectors[i]);
lpStr += (strlen(lpServiceArgVectors[i]) + 1);
}
*lpStr = 0;
}
dwError = ScmrStartServiceA(BindingHandle,
(unsigned int)hService,
(SC_RPC_HANDLE)hService,
dwNumServiceArgs,
(unsigned char *)lpBuffer,
dwBufSize);
(LPSTRING_PTRSA)lpServiceArgVectors);
if (lpBuffer != NULL)
HeapFree(GetProcessHeap(), 0, lpBuffer);
if (dwError != ERROR_SUCCESS)
{
@@ -2061,42 +2001,12 @@ StartServiceW(SC_HANDLE hService,
DWORD dwNumServiceArgs,
LPCWSTR *lpServiceArgVectors)
{
LPWSTR lpBuffer;
LPWSTR lpStr;
DWORD dwError;
DWORD dwBufSize;
DWORD i;
dwBufSize = 0;
for (i = 0; i < dwNumServiceArgs; i++)
{
dwBufSize += ((wcslen(lpServiceArgVectors[i]) + 1) * sizeof(WCHAR));
}
dwBufSize += sizeof(WCHAR);
TRACE("dwBufSize: %lu\n", dwBufSize);
lpBuffer = HeapAlloc(GetProcessHeap(), 0, dwBufSize);
if (lpBuffer == NULL)
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return FALSE;
}
lpStr = lpBuffer;
for (i = 0; i < dwNumServiceArgs; i++)
{
wcscpy(lpStr, lpServiceArgVectors[i]);
lpStr += (wcslen(lpServiceArgVectors[i]) + 1);
}
*lpStr = 0;
dwError = ScmrStartServiceW(BindingHandle,
(unsigned int)hService,
(SC_RPC_HANDLE)hService,
dwNumServiceArgs,
(unsigned char *)lpBuffer,
dwBufSize);
HeapFree(GetProcessHeap(), 0, lpBuffer);
(LPSTRING_PTRSW)lpServiceArgVectors);
if (dwError != ERROR_SUCCESS)
{
@@ -2125,7 +2035,7 @@ UnlockServiceDatabase(SC_LOCK ScLock)
/* Call to services.exe using RPC */
dwError = ScmrUnlockServiceDatabase(BindingHandle,
(unsigned int)ScLock);
(SC_RPC_LOCK)ScLock);
if (dwError != ERROR_SUCCESS)
{
ERR("ScmrUnlockServiceDatabase() failed (Error %lu)\n", dwError);
@@ -2153,6 +2063,7 @@ NotifyBootConfigStatus(BOOL BootAcceptable)
/* Call to services.exe using RPC */
dwError = ScmrNotifyBootConfigStatus(BindingHandle,
NULL,
BootAcceptable);
if (dwError != ERROR_SUCCESS)
{
File diff suppressed because it is too large Load Diff
+21 -9
View File
@@ -1,14 +1,26 @@
#define BYTE unsigned char
#define UCHAR unsigned char
#define WORD unsigned short
#define DWORD unsigned long
#define ULONG unsigned long
#define BOOL int
#define LPSTR char*
#define LPCSTR char*
#define LPWSTR wchar_t*
#define LPCWSTR wchar_t*
#define LPBYTE unsigned char*
#define LPDWORD unsigned long*
#define PBOOL unsigned long*
typedef wchar_t WCHAR;
typedef char CHAR;
typedef void *PVOID;
typedef BOOL *PBOOL;
typedef unsigned char *LPBYTE;
typedef unsigned long DWORD, *LPDWORD;
typedef CHAR *LPSTR;
typedef WCHAR *LPWSTR;
#define LPCSTR LPSTR
#define LPCWSTR LPWSTR
#define ULONG unsigned long
#define PBYTE unsigned char*
#define PWSTR wchar_t*
#define NTSTATUS long
cpp_quote("#if 0")
typedef int GUID;
typedef unsigned long ULONGLONG;
cpp_quote("#endif")