mirror of
https://github.com/reactos/reactos.git
synced 2024-10-02 07:26:47 +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
|
@ -3241,8 +3241,135 @@ DWORD RCreateServiceA(
|
|||
DWORD dwPwSize,
|
||||
LPSC_RPC_HANDLE lpServiceHandle)
|
||||
{
|
||||
UNIMPLEMENTED;
|
||||
return ERROR_CALL_NOT_IMPLEMENTED;
|
||||
DWORD dwError = ERROR_SUCCESS;
|
||||
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)
|
||||
{
|
||||
case SERVICE_CONFIG_DESCRIPTION:
|
||||
{
|
||||
Info.psd = (LPSERVICE_DESCRIPTIONW)&lpInfo;
|
||||
break;
|
||||
}
|
||||
|
||||
case SERVICE_CONFIG_FAILURE_ACTIONS:
|
||||
Info.psfa = (LPSERVICE_FAILURE_ACTIONSW)&lpInfo;
|
||||
|
@ -596,74 +594,24 @@ CreateServiceA(SC_HANDLE hSCManager,
|
|||
LPCSTR lpServiceStartName,
|
||||
LPCSTR lpPassword)
|
||||
{
|
||||
SC_HANDLE RetVal = NULL;
|
||||
LPWSTR lpServiceNameW = NULL;
|
||||
LPWSTR lpDisplayNameW = NULL;
|
||||
LPWSTR lpBinaryPathNameW = NULL;
|
||||
LPWSTR lpLoadOrderGroupW = NULL;
|
||||
LPWSTR lpDependenciesW = NULL;
|
||||
LPWSTR lpServiceStartNameW = NULL;
|
||||
LPWSTR lpPasswordW = NULL;
|
||||
SC_HANDLE hService = NULL;
|
||||
DWORD dwDependenciesLength = 0;
|
||||
DWORD dwError;
|
||||
DWORD dwLength;
|
||||
int len;
|
||||
LPSTR lpStr;
|
||||
|
||||
TRACE("CreateServiceA() called\n");
|
||||
TRACE("%p %s %s\n", hSCManager,
|
||||
lpServiceName, lpDisplayName);
|
||||
|
||||
if (!hSCManager)
|
||||
{
|
||||
SetLastError(ERROR_INVALID_HANDLE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
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)
|
||||
/* Calculate the Dependencies length*/
|
||||
if (lpDependencies != NULL)
|
||||
{
|
||||
lpStr = (LPSTR)lpDependencies;
|
||||
while (*lpStr)
|
||||
|
@ -673,77 +621,44 @@ CreateServiceA(SC_HANDLE hSCManager,
|
|||
lpStr = lpStr + dwLength;
|
||||
}
|
||||
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);
|
||||
lpServiceStartNameW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
||||
if (!lpServiceStartNameW)
|
||||
{
|
||||
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
||||
goto cleanup;
|
||||
}
|
||||
MultiByteToWideChar(CP_ACP, 0, lpServiceStartName, -1, lpServiceStartNameW, len);
|
||||
/* Call to services.exe using RPC */
|
||||
dwError = RCreateServiceA((SC_RPC_HANDLE)hSCManager,
|
||||
(LPSTR)lpServiceName,
|
||||
(LPSTR)lpDisplayName,
|
||||
dwDesiredAccess,
|
||||
dwServiceType,
|
||||
dwStartType,
|
||||
dwErrorControl,
|
||||
(LPSTR)lpBinaryPathName,
|
||||
(LPSTR)lpLoadOrderGroup,
|
||||
lpdwTagId,
|
||||
(LPBYTE)lpDependencies,
|
||||
dwDependenciesLength,
|
||||
(LPSTR)lpServiceStartName,
|
||||
NULL, /* FIXME: lpPassword */
|
||||
0, /* FIXME: dwPasswordLength */
|
||||
(SC_RPC_HANDLE *)&hService);
|
||||
}
|
||||
|
||||
if (lpPassword)
|
||||
RpcExcept(EXCEPTION_EXECUTE_HANDLER)
|
||||
{
|
||||
len = MultiByteToWideChar(CP_ACP, 0, lpPassword, -1, NULL, 0);
|
||||
lpPasswordW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
||||
if (!lpPasswordW)
|
||||
{
|
||||
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
||||
goto cleanup;
|
||||
}
|
||||
MultiByteToWideChar(CP_ACP, 0, lpPassword, -1, lpPasswordW, len);
|
||||
dwError = ScmRpcStatusToWinError(RpcExceptionCode());
|
||||
}
|
||||
RpcEndExcept;
|
||||
|
||||
if (dwError != ERROR_SUCCESS)
|
||||
{
|
||||
ERR("RCreateServiceA() failed (Error %lu)\n", dwError);
|
||||
SetLastError(dwError);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
RetVal = CreateServiceW(hSCManager,
|
||||
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;
|
||||
return hService;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue