X-Git-Url: https://git.reactos.org/?p=reactos.git;a=blobdiff_plain;f=reactos%2Fdll%2Fwin32%2Fadvapi32%2Fservice%2Fscm.c;h=9aa422cd3c9d908fcc42fb061eefb245320d4581;hp=b1b1dc9f78ed3a50126d363dcd98a80b2de0ead7;hb=d7117cdb17c53beabd4e30365158661d0574d17e;hpb=1cca0351e1ce1bb5da6a34539fa648d251f4e259;ds=sidebyside diff --git a/reactos/dll/win32/advapi32/service/scm.c b/reactos/dll/win32/advapi32/service/scm.c index b1b1dc9f78e..9aa422cd3c9 100644 --- a/reactos/dll/win32/advapi32/service/scm.c +++ b/reactos/dll/win32/advapi32/service/scm.c @@ -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; - 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); + if (dwError != ERROR_SUCCESS) + { + ERR("RCreateServiceA() failed (Error %lu)\n", dwError); + SetLastError(dwError); + return NULL; + } - return RetVal; + return hService; }