mirror of
https://github.com/reactos/reactos.git
synced 2025-08-06 02:32:57 +00:00
- Implement RCreateServiceA.
- Make CreateServiceA call RCreateServiceA instead of CreateServiceW. svn path=/trunk/; revision=45362
This commit is contained in:
parent
1cca0351e1
commit
d7117cdb17
2 changed files with 168 additions and 126 deletions
|
@ -3241,8 +3241,135 @@ DWORD RCreateServiceA(
|
||||||
DWORD dwPwSize,
|
DWORD dwPwSize,
|
||||||
LPSC_RPC_HANDLE lpServiceHandle)
|
LPSC_RPC_HANDLE lpServiceHandle)
|
||||||
{
|
{
|
||||||
UNIMPLEMENTED;
|
DWORD dwError = ERROR_SUCCESS;
|
||||||
return ERROR_CALL_NOT_IMPLEMENTED;
|
LPWSTR lpServiceNameW = NULL;
|
||||||
|
LPWSTR lpDisplayNameW = NULL;
|
||||||
|
LPWSTR lpBinaryPathNameW = NULL;
|
||||||
|
LPWSTR lpLoadOrderGroupW = NULL;
|
||||||
|
LPWSTR lpDependenciesW = NULL;
|
||||||
|
LPWSTR lpServiceStartNameW = NULL;
|
||||||
|
DWORD dwDependenciesLength = 0;
|
||||||
|
DWORD dwLength;
|
||||||
|
int len;
|
||||||
|
LPSTR lpStr;
|
||||||
|
|
||||||
|
if (lpServiceName)
|
||||||
|
{
|
||||||
|
len = MultiByteToWideChar(CP_ACP, 0, lpServiceName, -1, NULL, 0);
|
||||||
|
lpServiceNameW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
||||||
|
if (!lpServiceNameW)
|
||||||
|
{
|
||||||
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
MultiByteToWideChar(CP_ACP, 0, lpServiceName, -1, lpServiceNameW, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lpDisplayName)
|
||||||
|
{
|
||||||
|
len = MultiByteToWideChar(CP_ACP, 0, lpDisplayName, -1, NULL, 0);
|
||||||
|
lpDisplayNameW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
||||||
|
if (!lpDisplayNameW)
|
||||||
|
{
|
||||||
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
MultiByteToWideChar(CP_ACP, 0, lpDisplayName, -1, lpDisplayNameW, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lpBinaryPathName)
|
||||||
|
{
|
||||||
|
len = MultiByteToWideChar(CP_ACP, 0, lpBinaryPathName, -1, NULL, 0);
|
||||||
|
lpBinaryPathNameW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
||||||
|
if (!lpBinaryPathNameW)
|
||||||
|
{
|
||||||
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
MultiByteToWideChar(CP_ACP, 0, lpBinaryPathName, -1, lpBinaryPathNameW, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lpLoadOrderGroup)
|
||||||
|
{
|
||||||
|
len = MultiByteToWideChar(CP_ACP, 0, lpLoadOrderGroup, -1, NULL, 0);
|
||||||
|
lpLoadOrderGroupW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
||||||
|
if (!lpLoadOrderGroupW)
|
||||||
|
{
|
||||||
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
MultiByteToWideChar(CP_ACP, 0, lpLoadOrderGroup, -1, lpLoadOrderGroupW, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lpDependencies)
|
||||||
|
{
|
||||||
|
lpStr = (LPSTR)lpDependencies;
|
||||||
|
while (*lpStr)
|
||||||
|
{
|
||||||
|
dwLength = strlen(lpStr) + 1;
|
||||||
|
dwDependenciesLength += dwLength;
|
||||||
|
lpStr = lpStr + dwLength;
|
||||||
|
}
|
||||||
|
dwDependenciesLength++;
|
||||||
|
|
||||||
|
lpDependenciesW = HeapAlloc(GetProcessHeap(), 0, dwDependenciesLength * sizeof(WCHAR));
|
||||||
|
if (!lpDependenciesW)
|
||||||
|
{
|
||||||
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
MultiByteToWideChar(CP_ACP, 0, (LPSTR)lpDependencies, dwDependenciesLength, lpDependenciesW, dwDependenciesLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lpServiceStartName)
|
||||||
|
{
|
||||||
|
len = MultiByteToWideChar(CP_ACP, 0, lpServiceStartName, -1, NULL, 0);
|
||||||
|
lpServiceStartNameW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
||||||
|
if (!lpServiceStartNameW)
|
||||||
|
{
|
||||||
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
MultiByteToWideChar(CP_ACP, 0, lpServiceStartName, -1, lpServiceStartNameW, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
dwError = RCreateServiceW(hSCManager,
|
||||||
|
lpServiceNameW,
|
||||||
|
lpDisplayNameW,
|
||||||
|
dwDesiredAccess,
|
||||||
|
dwServiceType,
|
||||||
|
dwStartType,
|
||||||
|
dwErrorControl,
|
||||||
|
lpBinaryPathNameW,
|
||||||
|
lpLoadOrderGroupW,
|
||||||
|
lpdwTagId,
|
||||||
|
(LPBYTE)lpDependenciesW,
|
||||||
|
dwDependenciesLength,
|
||||||
|
lpServiceStartNameW,
|
||||||
|
lpPassword,
|
||||||
|
dwPwSize,
|
||||||
|
lpServiceHandle);
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
if (lpServiceNameW !=NULL)
|
||||||
|
HeapFree(GetProcessHeap(), 0, lpServiceNameW);
|
||||||
|
|
||||||
|
if (lpDisplayNameW != NULL)
|
||||||
|
HeapFree(GetProcessHeap(), 0, lpDisplayNameW);
|
||||||
|
|
||||||
|
if (lpBinaryPathNameW != NULL)
|
||||||
|
HeapFree(GetProcessHeap(), 0, lpBinaryPathNameW);
|
||||||
|
|
||||||
|
if (lpLoadOrderGroupW != NULL)
|
||||||
|
HeapFree(GetProcessHeap(), 0, lpLoadOrderGroupW);
|
||||||
|
|
||||||
|
if (lpDependenciesW != NULL)
|
||||||
|
HeapFree(GetProcessHeap(), 0, lpDependenciesW);
|
||||||
|
|
||||||
|
if (lpServiceStartNameW != NULL)
|
||||||
|
HeapFree(GetProcessHeap(), 0, lpServiceStartNameW);
|
||||||
|
|
||||||
|
return dwError;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -287,10 +287,8 @@ ChangeServiceConfig2W(SC_HANDLE hService,
|
||||||
switch (dwInfoLevel)
|
switch (dwInfoLevel)
|
||||||
{
|
{
|
||||||
case SERVICE_CONFIG_DESCRIPTION:
|
case SERVICE_CONFIG_DESCRIPTION:
|
||||||
{
|
|
||||||
Info.psd = (LPSERVICE_DESCRIPTIONW)&lpInfo;
|
Info.psd = (LPSERVICE_DESCRIPTIONW)&lpInfo;
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
case SERVICE_CONFIG_FAILURE_ACTIONS:
|
case SERVICE_CONFIG_FAILURE_ACTIONS:
|
||||||
Info.psfa = (LPSERVICE_FAILURE_ACTIONSW)&lpInfo;
|
Info.psfa = (LPSERVICE_FAILURE_ACTIONSW)&lpInfo;
|
||||||
|
@ -596,74 +594,24 @@ CreateServiceA(SC_HANDLE hSCManager,
|
||||||
LPCSTR lpServiceStartName,
|
LPCSTR lpServiceStartName,
|
||||||
LPCSTR lpPassword)
|
LPCSTR lpPassword)
|
||||||
{
|
{
|
||||||
SC_HANDLE RetVal = NULL;
|
SC_HANDLE hService = NULL;
|
||||||
LPWSTR lpServiceNameW = NULL;
|
|
||||||
LPWSTR lpDisplayNameW = NULL;
|
|
||||||
LPWSTR lpBinaryPathNameW = NULL;
|
|
||||||
LPWSTR lpLoadOrderGroupW = NULL;
|
|
||||||
LPWSTR lpDependenciesW = NULL;
|
|
||||||
LPWSTR lpServiceStartNameW = NULL;
|
|
||||||
LPWSTR lpPasswordW = NULL;
|
|
||||||
DWORD dwDependenciesLength = 0;
|
DWORD dwDependenciesLength = 0;
|
||||||
|
DWORD dwError;
|
||||||
DWORD dwLength;
|
DWORD dwLength;
|
||||||
int len;
|
|
||||||
LPSTR lpStr;
|
LPSTR lpStr;
|
||||||
|
|
||||||
|
TRACE("CreateServiceA() called\n");
|
||||||
|
TRACE("%p %s %s\n", hSCManager,
|
||||||
|
lpServiceName, lpDisplayName);
|
||||||
|
|
||||||
if (!hSCManager)
|
if (!hSCManager)
|
||||||
{
|
{
|
||||||
SetLastError(ERROR_INVALID_HANDLE);
|
SetLastError(ERROR_INVALID_HANDLE);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lpServiceName)
|
/* Calculate the Dependencies length*/
|
||||||
{
|
if (lpDependencies != NULL)
|
||||||
len = MultiByteToWideChar(CP_ACP, 0, lpServiceName, -1, NULL, 0);
|
|
||||||
lpServiceNameW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
||||||
if (!lpServiceNameW)
|
|
||||||
{
|
|
||||||
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
MultiByteToWideChar(CP_ACP, 0, lpServiceName, -1, lpServiceNameW, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lpDisplayName)
|
|
||||||
{
|
|
||||||
len = MultiByteToWideChar(CP_ACP, 0, lpDisplayName, -1, NULL, 0);
|
|
||||||
lpDisplayNameW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
||||||
if (!lpDisplayNameW)
|
|
||||||
{
|
|
||||||
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
MultiByteToWideChar(CP_ACP, 0, lpDisplayName, -1, lpDisplayNameW, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lpBinaryPathName)
|
|
||||||
{
|
|
||||||
len = MultiByteToWideChar(CP_ACP, 0, lpBinaryPathName, -1, NULL, 0);
|
|
||||||
lpBinaryPathNameW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
||||||
if (!lpBinaryPathNameW)
|
|
||||||
{
|
|
||||||
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
MultiByteToWideChar(CP_ACP, 0, lpBinaryPathName, -1, lpBinaryPathNameW, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lpLoadOrderGroup)
|
|
||||||
{
|
|
||||||
len = MultiByteToWideChar(CP_ACP, 0, lpLoadOrderGroup, -1, NULL, 0);
|
|
||||||
lpLoadOrderGroupW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
||||||
if (!lpLoadOrderGroupW)
|
|
||||||
{
|
|
||||||
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
MultiByteToWideChar(CP_ACP, 0, lpLoadOrderGroup, -1, lpLoadOrderGroupW, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lpDependencies)
|
|
||||||
{
|
{
|
||||||
lpStr = (LPSTR)lpDependencies;
|
lpStr = (LPSTR)lpDependencies;
|
||||||
while (*lpStr)
|
while (*lpStr)
|
||||||
|
@ -673,77 +621,44 @@ CreateServiceA(SC_HANDLE hSCManager,
|
||||||
lpStr = lpStr + dwLength;
|
lpStr = lpStr + dwLength;
|
||||||
}
|
}
|
||||||
dwDependenciesLength++;
|
dwDependenciesLength++;
|
||||||
|
|
||||||
lpDependenciesW = HeapAlloc(GetProcessHeap(), 0, dwDependenciesLength * sizeof(WCHAR));
|
|
||||||
if (!lpDependenciesW)
|
|
||||||
{
|
|
||||||
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
MultiByteToWideChar(CP_ACP, 0, lpDependencies, dwDependenciesLength, lpDependenciesW, dwDependenciesLength);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lpServiceStartName)
|
/* FIXME: Encrypt the password */
|
||||||
|
|
||||||
|
RpcTryExcept
|
||||||
{
|
{
|
||||||
len = MultiByteToWideChar(CP_ACP, 0, lpServiceStartName, -1, NULL, 0);
|
/* Call to services.exe using RPC */
|
||||||
lpServiceStartNameW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
dwError = RCreateServiceA((SC_RPC_HANDLE)hSCManager,
|
||||||
if (!lpServiceStartNameW)
|
(LPSTR)lpServiceName,
|
||||||
{
|
(LPSTR)lpDisplayName,
|
||||||
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
dwDesiredAccess,
|
||||||
goto cleanup;
|
dwServiceType,
|
||||||
}
|
dwStartType,
|
||||||
MultiByteToWideChar(CP_ACP, 0, lpServiceStartName, -1, lpServiceStartNameW, len);
|
dwErrorControl,
|
||||||
|
(LPSTR)lpBinaryPathName,
|
||||||
|
(LPSTR)lpLoadOrderGroup,
|
||||||
|
lpdwTagId,
|
||||||
|
(LPBYTE)lpDependencies,
|
||||||
|
dwDependenciesLength,
|
||||||
|
(LPSTR)lpServiceStartName,
|
||||||
|
NULL, /* FIXME: lpPassword */
|
||||||
|
0, /* FIXME: dwPasswordLength */
|
||||||
|
(SC_RPC_HANDLE *)&hService);
|
||||||
}
|
}
|
||||||
|
RpcExcept(EXCEPTION_EXECUTE_HANDLER)
|
||||||
if (lpPassword)
|
|
||||||
{
|
{
|
||||||
len = MultiByteToWideChar(CP_ACP, 0, lpPassword, -1, NULL, 0);
|
dwError = ScmRpcStatusToWinError(RpcExceptionCode());
|
||||||
lpPasswordW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
}
|
||||||
if (!lpPasswordW)
|
RpcEndExcept;
|
||||||
{
|
|
||||||
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
if (dwError != ERROR_SUCCESS)
|
||||||
goto cleanup;
|
{
|
||||||
}
|
ERR("RCreateServiceA() failed (Error %lu)\n", dwError);
|
||||||
MultiByteToWideChar(CP_ACP, 0, lpPassword, -1, lpPasswordW, len);
|
SetLastError(dwError);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
RetVal = CreateServiceW(hSCManager,
|
return hService;
|
||||||
lpServiceNameW,
|
|
||||||
lpDisplayNameW,
|
|
||||||
dwDesiredAccess,
|
|
||||||
dwServiceType,
|
|
||||||
dwStartType,
|
|
||||||
dwErrorControl,
|
|
||||||
lpBinaryPathNameW,
|
|
||||||
lpLoadOrderGroupW,
|
|
||||||
lpdwTagId,
|
|
||||||
lpDependenciesW,
|
|
||||||
lpServiceStartNameW,
|
|
||||||
lpPasswordW);
|
|
||||||
|
|
||||||
cleanup:
|
|
||||||
if (lpServiceNameW !=NULL)
|
|
||||||
HeapFree(GetProcessHeap(), 0, lpServiceNameW);
|
|
||||||
|
|
||||||
if (lpDisplayNameW != NULL)
|
|
||||||
HeapFree(GetProcessHeap(), 0, lpDisplayNameW);
|
|
||||||
|
|
||||||
if (lpBinaryPathNameW != NULL)
|
|
||||||
HeapFree(GetProcessHeap(), 0, lpBinaryPathNameW);
|
|
||||||
|
|
||||||
if (lpLoadOrderGroupW != NULL)
|
|
||||||
HeapFree(GetProcessHeap(), 0, lpLoadOrderGroupW);
|
|
||||||
|
|
||||||
if (lpDependenciesW != NULL)
|
|
||||||
HeapFree(GetProcessHeap(), 0, lpDependenciesW);
|
|
||||||
|
|
||||||
if (lpServiceStartNameW != NULL)
|
|
||||||
HeapFree(GetProcessHeap(), 0, lpServiceStartNameW);
|
|
||||||
|
|
||||||
if (lpPasswordW != NULL)
|
|
||||||
HeapFree(GetProcessHeap(), 0, lpPasswordW);
|
|
||||||
|
|
||||||
return RetVal;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue