}
+static
+DWORD
+ScmEncryptPassword(
+ _In_ PCWSTR pClearTextPassword,
+ _Out_ PBYTE *pEncryptedPassword,
+ _Out_ PDWORD pEncryptedPasswordSize)
+{
+ DWORD dwSize;
+ PBYTE pBuffer;
+
+ dwSize = (wcslen(pClearTextPassword) + 1) * sizeof(WCHAR);
+
+ pBuffer = HeapAlloc(GetProcessHeap(), 0, dwSize);
+ if (pBuffer == NULL)
+ return ERROR_OUTOFMEMORY;
+
+ CopyMemory(pBuffer,
+ pClearTextPassword,
+ dwSize);
+
+ *pEncryptedPassword = pBuffer;
+ *pEncryptedPasswordSize = dwSize;
+
+ return ERROR_SUCCESS;
+}
+
+
/**********************************************************************
* ChangeServiceConfig2A
*
DWORD dwDependenciesLength = 0;
SIZE_T cchLength;
LPCSTR lpStr;
- DWORD dwPasswordLength = 0;
+ DWORD dwPasswordSize = 0;
LPWSTR lpPasswordW = NULL;
LPBYTE lpEncryptedPassword = NULL;
TRACE("ChangeServiceConfigA(%p %lu %lu %lu %s %s %p %s %s %s %s)\n",
- dwServiceType, dwStartType, dwErrorControl, debugstr_a(lpBinaryPathName),
+ hService, dwServiceType, dwStartType, dwErrorControl, debugstr_a(lpBinaryPathName),
debugstr_a(lpLoadOrderGroup), lpdwTagId, debugstr_a(lpDependencies),
debugstr_a(lpServiceStartName), debugstr_a(lpPassword), debugstr_a(lpDisplayName));
lpPasswordW,
(int)(strlen(lpPassword) + 1));
- /* FIXME: Encrypt the password */
- lpEncryptedPassword = (LPBYTE)lpPasswordW;
- dwPasswordLength = (wcslen(lpPasswordW) + 1) * sizeof(WCHAR);
+ /* Encrypt the unicode password */
+ dwError = ScmEncryptPassword(lpPasswordW,
+ &lpEncryptedPassword,
+ &dwPasswordSize);
+ if (dwError != ERROR_SUCCESS)
+ goto done;
}
RpcTryExcept
dwDependenciesLength,
(LPSTR)lpServiceStartName,
lpEncryptedPassword,
- dwPasswordLength,
+ dwPasswordSize,
(LPSTR)lpDisplayName);
}
RpcExcept(EXCEPTION_EXECUTE_HANDLER)
}
RpcEndExcept;
+done:
if (lpPasswordW != NULL)
+ {
+ /* Wipe and release the password buffers */
+ ZeroMemory(lpPasswordW, (wcslen(lpPasswordW) + 1) * sizeof(WCHAR));
HeapFree(GetProcessHeap(), 0, lpPasswordW);
+ if (lpEncryptedPassword != NULL)
+ {
+ ZeroMemory(lpEncryptedPassword, dwPasswordSize);
+ HeapFree(GetProcessHeap(), 0, lpEncryptedPassword);
+ }
+ }
+
if (dwError != ERROR_SUCCESS)
{
TRACE("RChangeServiceConfigA() failed (Error %lu)\n", dwError);
DWORD dwDependenciesLength = 0;
SIZE_T cchLength;
LPCWSTR lpStr;
- DWORD dwPasswordLength = 0;
+ DWORD dwPasswordSize = 0;
LPBYTE lpEncryptedPassword = NULL;
TRACE("ChangeServiceConfigW(%p %lu %lu %lu %s %s %p %s %s %s %s)\n",
- dwServiceType, dwStartType, dwErrorControl, debugstr_w(lpBinaryPathName),
+ hService, dwServiceType, dwStartType, dwErrorControl, debugstr_w(lpBinaryPathName),
debugstr_w(lpLoadOrderGroup), lpdwTagId, debugstr_w(lpDependencies),
debugstr_w(lpServiceStartName), debugstr_w(lpPassword), debugstr_w(lpDisplayName));
if (lpPassword != NULL)
{
- /* FIXME: Encrypt the password */
- lpEncryptedPassword = (LPBYTE)lpPassword;
- dwPasswordLength = (wcslen(lpPassword) + 1) * sizeof(WCHAR);
+ dwError = ScmEncryptPassword(lpPassword,
+ &lpEncryptedPassword,
+ &dwPasswordSize);
+ if (dwError != ERROR_SUCCESS)
+ {
+ ERR("ScmEncryptPassword failed (Error %lu)\n", dwError);
+ goto done;
+ }
}
RpcTryExcept
dwDependenciesLength,
(LPWSTR)lpServiceStartName,
lpEncryptedPassword,
- dwPasswordLength,
+ dwPasswordSize,
(LPWSTR)lpDisplayName);
}
RpcExcept(EXCEPTION_EXECUTE_HANDLER)
}
RpcEndExcept;
+done:
+ if (lpEncryptedPassword != NULL)
+ {
+ /* Wipe and release the password buffer */
+ ZeroMemory(lpEncryptedPassword, dwPasswordSize);
+ HeapFree(GetProcessHeap(), 0, lpEncryptedPassword);
+ }
+
if (dwError != ERROR_SUCCESS)
{
TRACE("RChangeServiceConfigW() failed (Error %lu)\n", dwError);
DWORD dwError;
SIZE_T cchLength;
LPCSTR lpStr;
- DWORD dwPasswordLength = 0;
+ DWORD dwPasswordSize = 0;
LPWSTR lpPasswordW = NULL;
LPBYTE lpEncryptedPassword = NULL;
lpPasswordW,
(int)(strlen(lpPassword) + 1));
- /* FIXME: Encrypt the password */
- lpEncryptedPassword = (LPBYTE)lpPasswordW;
- dwPasswordLength = (wcslen(lpPasswordW) + 1) * sizeof(WCHAR);
+ /* Encrypt the password */
+ dwError = ScmEncryptPassword(lpPasswordW,
+ &lpEncryptedPassword,
+ &dwPasswordSize);
+ if (dwError != ERROR_SUCCESS)
+ goto done;
}
RpcTryExcept
dwDependenciesLength,
(LPSTR)lpServiceStartName,
lpEncryptedPassword,
- dwPasswordLength,
+ dwPasswordSize,
(SC_RPC_HANDLE *)&hService);
}
RpcExcept(EXCEPTION_EXECUTE_HANDLER)
}
RpcEndExcept;
+done:
if (lpPasswordW != NULL)
+ {
+ /* Wipe and release the password buffers */
+ ZeroMemory(lpPasswordW, (wcslen(lpPasswordW) + 1) * sizeof(WCHAR));
HeapFree(GetProcessHeap(), 0, lpPasswordW);
+ if (lpEncryptedPassword != NULL)
+ {
+ ZeroMemory(lpEncryptedPassword, dwPasswordSize);
+ HeapFree(GetProcessHeap(), 0, lpEncryptedPassword);
+ }
+ }
+
SetLastError(dwError);
if (dwError != ERROR_SUCCESS)
{
DWORD dwError;
SIZE_T cchLength;
LPCWSTR lpStr;
- DWORD dwPasswordLength = 0;
+ DWORD dwPasswordSize = 0;
LPBYTE lpEncryptedPassword = NULL;
TRACE("CreateServiceW(%p %s %s %lx %lu %lu %lu %s %s %p %s %s %s)\n",
if (lpPassword != NULL)
{
- /* FIXME: Encrypt the password */
- lpEncryptedPassword = (LPBYTE)lpPassword;
- dwPasswordLength = (wcslen(lpPassword) + 1) * sizeof(WCHAR);
+ /* Encrypt the password */
+ dwError = ScmEncryptPassword(lpPassword,
+ &lpEncryptedPassword,
+ &dwPasswordSize);
+ if (dwError != ERROR_SUCCESS)
+ goto done;
}
RpcTryExcept
dwDependenciesLength,
lpServiceStartName,
lpEncryptedPassword,
- dwPasswordLength,
+ dwPasswordSize,
(SC_RPC_HANDLE *)&hService);
}
RpcExcept(EXCEPTION_EXECUTE_HANDLER)
}
RpcEndExcept;
+done:
+ if (lpEncryptedPassword != NULL)
+ {
+ /* Wipe and release the password buffers */
+ ZeroMemory(lpEncryptedPassword, dwPasswordSize);
+ HeapFree(GetProcessHeap(), 0, lpEncryptedPassword);
+ }
+
SetLastError(dwError);
if (dwError != ERROR_SUCCESS)
{