-don't cast const char to char

-handle RPC_X_ENUM_VALUE_OUT_OF_RANGE and RPC_X_BYTE_COUNT_TOO_SMALL in ScmRpcStatusToWinError
-add some traces
-don't write to NULL pointers, don't do strlen on a NULL pointer

svn path=/trunk/; revision=38603
This commit is contained in:
Christoph von Wittich 2009-01-06 07:53:04 +00:00
parent 76f5148d89
commit 38418a1b4c
7 changed files with 99 additions and 78 deletions

View file

@ -48,7 +48,7 @@ ScmOpenServiceKey(LPWSTR lpServiceName,
DWORD
ScmCreateServiceKey(LPWSTR lpServiceName,
ScmCreateServiceKey(LPCWSTR lpServiceName,
REGSAM samDesired,
PHKEY phKey)
{

View file

@ -30,7 +30,7 @@ static DWORD dwResumeCount = 1;
PSERVICE
ScmGetServiceEntryByName(LPWSTR lpServiceName)
ScmGetServiceEntryByName(LPCWSTR lpServiceName)
{
PLIST_ENTRY ServiceEntry;
PSERVICE CurrentService;
@ -59,7 +59,7 @@ ScmGetServiceEntryByName(LPWSTR lpServiceName)
PSERVICE
ScmGetServiceEntryByDisplayName(LPWSTR lpDisplayName)
ScmGetServiceEntryByDisplayName(LPCWSTR lpDisplayName)
{
PLIST_ENTRY ServiceEntry;
PSERVICE CurrentService;
@ -148,7 +148,7 @@ ScmGetServiceEntryByClientHandle(HANDLE Handle)
DWORD
ScmCreateNewServiceRecord(LPWSTR lpServiceName,
ScmCreateNewServiceRecord(LPCWSTR lpServiceName,
PSERVICE *lpServiceRecord)
{
PSERVICE lpService = NULL;
@ -225,7 +225,7 @@ ScmDeleteServiceRecord(PSERVICE lpService)
static DWORD
CreateServiceListEntry(LPWSTR lpServiceName,
CreateServiceListEntry(LPCWSTR lpServiceName,
HKEY hServiceKey)
{
PSERVICE lpService = NULL;

View file

@ -25,7 +25,7 @@ LIST_ENTRY UnknownGroupListHead;
DWORD
ScmSetServiceGroup(PSERVICE lpService,
LPWSTR lpGroupName)
LPCWSTR lpGroupName)
{
PLIST_ENTRY GroupEntry;
PSERVICE_GROUP lpGroup;

View file

@ -1571,13 +1571,13 @@ ScmConvertToBootPathName(wchar_t *CanonName, wchar_t **RelativeName)
DWORD
ScmCanonDriverImagePath(DWORD dwStartType,
wchar_t *lpServiceName,
const wchar_t *lpServiceName,
wchar_t **lpCanonName)
{
DWORD ServiceNameLen, Result;
UNICODE_STRING NtServiceName;
WCHAR *RelativeName;
WCHAR *SourceName = lpServiceName;
const WCHAR *SourceName = lpServiceName;
/* Calculate the length of the service's name */
ServiceNameLen = wcslen(lpServiceName);
@ -1703,18 +1703,18 @@ ScmCanonDriverImagePath(DWORD dwStartType,
/* Function 12 */
DWORD RCreateServiceW(
SC_RPC_HANDLE hSCManager,
LPWSTR lpServiceName,
LPWSTR lpDisplayName,
LPCWSTR lpServiceName,
LPCWSTR lpDisplayName,
DWORD dwDesiredAccess,
DWORD dwServiceType,
DWORD dwStartType,
DWORD dwErrorControl,
LPWSTR lpBinaryPathName,
LPWSTR lpLoadOrderGroup,
LPCWSTR lpBinaryPathName,
LPCWSTR lpLoadOrderGroup,
LPDWORD lpdwTagId,
LPBYTE lpDependencies,
DWORD dwDependSize,
LPWSTR lpServiceStartName,
LPCWSTR lpServiceStartName,
LPBYTE lpPassword,
DWORD dwPwSize,
LPSC_RPC_HANDLE lpServiceHandle)
@ -2740,7 +2740,7 @@ DWORD RStartServiceW(
/* Function 20 */
DWORD RGetServiceDisplayNameW(
SC_RPC_HANDLE hSCManager,
LPWSTR lpServiceName,
LPCWSTR lpServiceName,
LPWSTR lpDisplayName,
DWORD *lpcchBuffer)
{
@ -2773,7 +2773,10 @@ DWORD RGetServiceDisplayNameW(
if (*lpcchBuffer == 0)
{
*lpcchBuffer = 1;
*lpDisplayName = '\0';
if (lpDisplayName != NULL)
{
*lpDisplayName = '\0';
}
}
return ERROR_SERVICE_DOES_NOT_EXIST;
@ -2783,7 +2786,7 @@ DWORD RGetServiceDisplayNameW(
{
dwLength = wcslen(lpService->lpServiceName);
if (lpServiceName != NULL &&
if (lpDisplayName != NULL &&
*lpcchBuffer > dwLength)
{
wcscpy(lpDisplayName, lpService->lpServiceName);
@ -2811,7 +2814,7 @@ DWORD RGetServiceDisplayNameW(
/* Function 21 */
DWORD RGetServiceKeyNameW(
SC_RPC_HANDLE hSCManager,
LPWSTR lpDisplayName,
LPCWSTR lpDisplayName,
LPWSTR lpServiceName,
DWORD *lpcchBuffer)
{
@ -2844,7 +2847,10 @@ DWORD RGetServiceKeyNameW(
if (*lpcchBuffer == 0)
{
*lpcchBuffer = 2;
*lpServiceName = '\0';
if (lpServiceName != NULL)
{
*lpServiceName = '\0';
}
}
return ERROR_SERVICE_DOES_NOT_EXIST;
@ -3774,12 +3780,12 @@ DWORD RStartServiceA(
/* Function 32 */
DWORD RGetServiceDisplayNameA(
SC_RPC_HANDLE hSCManager,
LPSTR lpServiceName,
LPCSTR lpServiceName,
LPSTR lpDisplayName,
LPBOUNDED_DWORD_4K lpcchBuffer)
{
// PMANAGER_HANDLE hManager;
PSERVICE lpService;
PSERVICE lpService = NULL;
DWORD dwLength;
DWORD dwError;
LPWSTR lpServiceNameW;
@ -3797,23 +3803,26 @@ DWORD RGetServiceDisplayNameA(
// return ERROR_INVALID_HANDLE;
// }
dwLength = strlen(lpServiceName) + 1;
lpServiceNameW = HeapAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY,
dwLength * sizeof(WCHAR));
if (!lpServiceNameW)
return ERROR_NOT_ENOUGH_MEMORY;
if (lpServiceName != NULL)
{
dwLength = strlen(lpServiceName) + 1;
lpServiceNameW = HeapAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY,
dwLength * sizeof(WCHAR));
if (!lpServiceNameW)
return ERROR_NOT_ENOUGH_MEMORY;
MultiByteToWideChar(CP_ACP,
0,
lpServiceName,
strlen(lpServiceName),
lpServiceNameW,
dwLength);
MultiByteToWideChar(CP_ACP,
0,
lpServiceName,
-1,
lpServiceNameW,
dwLength);
lpService = ScmGetServiceEntryByName(lpServiceNameW);
lpService = ScmGetServiceEntryByName(lpServiceNameW);
HeapFree(GetProcessHeap(), 0, lpServiceNameW);
HeapFree(GetProcessHeap(), 0, lpServiceNameW);
}
if (lpService == NULL)
{
@ -3824,7 +3833,10 @@ DWORD RGetServiceDisplayNameA(
if (*lpcchBuffer == 0)
{
*lpcchBuffer = 1;
*lpDisplayName = '\0';
if (lpDisplayName != NULL)
{
*lpDisplayName = '\0';
}
}
return ERROR_SERVICE_DOES_NOT_EXIST;
}
@ -3832,7 +3844,7 @@ DWORD RGetServiceDisplayNameA(
if (!lpService->lpDisplayName)
{
dwLength = wcslen(lpService->lpServiceName);
if (lpServiceName != NULL &&
if (lpDisplayName != NULL &&
*lpcchBuffer > dwLength)
{
WideCharToMultiByte(CP_ACP,
@ -3840,7 +3852,7 @@ DWORD RGetServiceDisplayNameA(
lpService->lpServiceName,
wcslen(lpService->lpServiceName),
lpDisplayName,
*lpcchBuffer,
dwLength + 1,
NULL,
NULL);
return ERROR_SUCCESS;
@ -3857,7 +3869,7 @@ DWORD RGetServiceDisplayNameA(
lpService->lpDisplayName,
wcslen(lpService->lpDisplayName),
lpDisplayName,
*lpcchBuffer,
dwLength + 1,
NULL,
NULL);
return ERROR_SUCCESS;
@ -3875,7 +3887,7 @@ DWORD RGetServiceDisplayNameA(
/* Function 33 */
DWORD RGetServiceKeyNameA(
SC_RPC_HANDLE hSCManager,
LPSTR lpDisplayName,
LPCSTR lpDisplayName,
LPSTR lpServiceName,
LPBOUNDED_DWORD_4K lpcchBuffer)
{
@ -3900,7 +3912,7 @@ DWORD RGetServiceKeyNameA(
MultiByteToWideChar(CP_ACP,
0,
lpDisplayName,
strlen(lpDisplayName),
-1,
lpDisplayNameW,
dwLength);
@ -3917,21 +3929,24 @@ DWORD RGetServiceKeyNameA(
if (*lpcchBuffer == 0)
{
*lpcchBuffer = 1;
*lpServiceName = '\0';
if (lpServiceName != NULL)
{
*lpServiceName = '\0';
}
}
return ERROR_SERVICE_DOES_NOT_EXIST;
}
dwLength = wcslen(lpService->lpServiceName);
if (lpService != NULL &&
if (lpServiceName != NULL &&
*lpcchBuffer > dwLength)
{
WideCharToMultiByte(CP_ACP,
0,
lpService->lpServiceName,
wcslen(lpService->lpServiceName),
lpServiceName,
lpServiceName + 1,
dwLength,
NULL,
NULL);

View file

@ -77,7 +77,7 @@ DWORD ScmOpenServiceKey(LPWSTR lpServiceName,
REGSAM samDesired,
PHKEY phKey);
DWORD ScmCreateServiceKey(LPWSTR lpServiceName,
DWORD ScmCreateServiceKey(LPCWSTR lpServiceName,
REGSAM samDesired,
PHKEY phKey);
@ -104,11 +104,11 @@ DWORD ScmStartService(PSERVICE Service,
DWORD argc,
LPWSTR *argv);
PSERVICE ScmGetServiceEntryByName(LPWSTR lpServiceName);
PSERVICE ScmGetServiceEntryByDisplayName(LPWSTR lpDisplayName);
PSERVICE ScmGetServiceEntryByName(LPCWSTR lpServiceName);
PSERVICE ScmGetServiceEntryByDisplayName(LPCWSTR lpDisplayName);
PSERVICE ScmGetServiceEntryByResumeCount(DWORD dwResumeCount);
PSERVICE ScmGetServiceEntryByClientHandle(HANDLE Handle);
DWORD ScmCreateNewServiceRecord(LPWSTR lpServiceName,
DWORD ScmCreateNewServiceRecord(LPCWSTR lpServiceName,
PSERVICE *lpServiceRecord);
VOID ScmDeleteServiceRecord(PSERVICE lpService);
DWORD ScmMarkServiceForDelete(PSERVICE pService);
@ -130,7 +130,7 @@ DWORD ScmControlDriver(PSERVICE lpService,
DWORD ScmCreateGroupList(VOID);
DWORD ScmSetServiceGroup(PSERVICE lpService,
LPWSTR lpGroupName);
LPCWSTR lpGroupName);
/* rpcserver.c */

View file

@ -36,7 +36,7 @@ SVCCTL_HANDLEA_bind(SVCCTL_HANDLEA szMachineName)
(UCHAR *)"\\pipe\\ntsvcs",
NULL,
(UCHAR **)&pszStringBinding);
if (status)
if (status != RPC_S_OK)
{
ERR("RpcStringBindingCompose returned 0x%x\n", status);
return NULL;
@ -45,13 +45,13 @@ SVCCTL_HANDLEA_bind(SVCCTL_HANDLEA szMachineName)
/* Set the binding handle that will be used to bind to the server. */
status = RpcBindingFromStringBindingA(pszStringBinding,
&hBinding);
if (status)
if (status != RPC_S_OK)
{
ERR("RpcBindingFromStringBinding returned 0x%x\n", status);
}
status = RpcStringFreeA(&pszStringBinding);
if (status)
if (status != RPC_S_OK)
{
ERR("RpcStringFree returned 0x%x\n", status);
}
@ -69,7 +69,7 @@ SVCCTL_HANDLEA_unbind(SVCCTL_HANDLEA szMachineName,
TRACE("SVCCTL_HANDLEA_unbind() called\n");
status = RpcBindingFree(&hBinding);
if (status)
if (status != RPC_S_OK)
{
ERR("RpcBindingFree returned 0x%x\n", status);
}
@ -91,7 +91,7 @@ SVCCTL_HANDLEW_bind(SVCCTL_HANDLEW szMachineName)
L"\\pipe\\ntsvcs",
NULL,
&pszStringBinding);
if (status)
if (status != RPC_S_OK)
{
ERR("RpcStringBindingCompose returned 0x%x\n", status);
return NULL;
@ -100,13 +100,13 @@ SVCCTL_HANDLEW_bind(SVCCTL_HANDLEW szMachineName)
/* Set the binding handle that will be used to bind to the server. */
status = RpcBindingFromStringBindingW(pszStringBinding,
&hBinding);
if (status)
if (status != RPC_S_OK)
{
ERR("RpcBindingFromStringBinding returned 0x%x\n", status);
}
status = RpcStringFreeW(&pszStringBinding);
if (status)
if (status != RPC_S_OK)
{
ERR("RpcStringFree returned 0x%x\n", status);
}
@ -124,7 +124,7 @@ SVCCTL_HANDLEW_unbind(SVCCTL_HANDLEW szMachineName,
TRACE("SVCCTL_HANDLEW_unbind() called\n");
status = RpcBindingFree(&hBinding);
if (status)
if (status != RPC_S_OK)
{
ERR("RpcBindingFree returned 0x%x\n", status);
}
@ -146,7 +146,7 @@ RPC_SERVICE_STATUS_HANDLE_bind(RPC_SERVICE_STATUS_HANDLE hServiceStatus)
L"\\pipe\\ntsvcs",
NULL,
&pszStringBinding);
if (status)
if (status != RPC_S_OK)
{
ERR("RpcStringBindingCompose returned 0x%x\n", status);
return NULL;
@ -155,13 +155,13 @@ RPC_SERVICE_STATUS_HANDLE_bind(RPC_SERVICE_STATUS_HANDLE hServiceStatus)
/* Set the binding handle that will be used to bind to the server. */
status = RpcBindingFromStringBindingW(pszStringBinding,
&hBinding);
if (status)
if (status != RPC_S_OK)
{
ERR("RpcBindingFromStringBinding returned 0x%x\n", status);
}
status = RpcStringFreeW(&pszStringBinding);
if (status)
if (status != RPC_S_OK)
{
ERR("RpcStringFree returned 0x%x\n", status);
}
@ -179,7 +179,7 @@ RPC_SERVICE_STATUS_HANDLE_unbind(RPC_SERVICE_STATUS_HANDLE hServiceStatus,
TRACE("RPC_SERVICE_STATUS_HANDLE_unbind() called\n");
status = RpcBindingFree(&hBinding);
if (status)
if (status != RPC_S_OK)
{
ERR("RpcBindingFree returned 0x%x\n", status);
}
@ -195,6 +195,8 @@ ScmRpcStatusToWinError(RPC_STATUS Status)
return ERROR_INVALID_HANDLE;
case RPC_X_NULL_REF_POINTER:
case RPC_X_ENUM_VALUE_OUT_OF_RANGE:
case RPC_X_BYTE_COUNT_TOO_SMALL:
return ERROR_INVALID_PARAMETER;
case STATUS_ACCESS_VIOLATION:
@ -759,6 +761,8 @@ CreateServiceW(SC_HANDLE hSCManager,
LPWSTR lpStr;
TRACE("CreateServiceW() called\n");
TRACE("%p %S %S\n", hSCManager,
lpServiceName, lpDisplayName);
/* Calculate the Dependencies length*/
if (lpDependencies != NULL)
@ -781,18 +785,18 @@ CreateServiceW(SC_HANDLE hSCManager,
{
/* Call to services.exe using RPC */
dwError = RCreateServiceW((SC_RPC_HANDLE)hSCManager,
(LPWSTR)lpServiceName,
(LPWSTR)lpDisplayName,
lpServiceName,
lpDisplayName,
dwDesiredAccess,
dwServiceType,
dwStartType,
dwErrorControl,
(LPWSTR)lpBinaryPathName,
(LPWSTR)lpLoadOrderGroup,
lpBinaryPathName,
lpLoadOrderGroup,
lpdwTagId,
(LPBYTE)lpDependencies,
dwDependenciesLength,
(LPWSTR)lpServiceStartName,
lpServiceStartName,
NULL, /* FIXME: lpPassword */
0, /* FIXME: dwPasswordLength */
(SC_RPC_HANDLE *)&hService);
@ -1292,6 +1296,8 @@ GetServiceDisplayNameA(SC_HANDLE hSCManager,
DWORD dwError;
TRACE("GetServiceDisplayNameA() called\n");
TRACE("%p %s %p %p\n", hSCManager,
debugstr_a(lpServiceName), lpDisplayName, lpcchBuffer);
if (!lpDisplayName)
*lpcchBuffer = 0;
@ -1299,7 +1305,7 @@ GetServiceDisplayNameA(SC_HANDLE hSCManager,
_SEH2_TRY
{
dwError = RGetServiceDisplayNameA((SC_RPC_HANDLE)hSCManager,
(LPSTR)lpServiceName,
lpServiceName,
lpDisplayName,
lpcchBuffer);
}
@ -1344,7 +1350,7 @@ GetServiceDisplayNameW(SC_HANDLE hSCManager,
_SEH2_TRY
{
dwError = RGetServiceDisplayNameW((SC_RPC_HANDLE)hSCManager,
(LPWSTR)lpServiceName,
lpServiceName,
lpDisplayName,
lpcchBuffer);
}
@ -1386,7 +1392,7 @@ GetServiceKeyNameA(SC_HANDLE hSCManager,
_SEH2_TRY
{
dwError = RGetServiceKeyNameA((SC_RPC_HANDLE)hSCManager,
(LPSTR)lpDisplayName,
lpDisplayName,
lpServiceName,
lpcchBuffer);
}
@ -1428,7 +1434,7 @@ GetServiceKeyNameW(SC_HANDLE hSCManager,
_SEH2_TRY
{
dwError = RGetServiceKeyNameW((SC_RPC_HANDLE)hSCManager,
(LPWSTR)lpDisplayName,
lpDisplayName,
lpServiceName,
lpcchBuffer);
}

View file

@ -380,18 +380,18 @@ interface svcctl
/* Function 12 */
DWORD RCreateServiceW(
[in] SC_RPC_HANDLE hSCManager,
[in, string, range(0, SC_MAX_NAME_LENGTH)] LPWSTR lpServiceName,
[in, string, unique, range(0, SC_MAX_NAME_LENGTH)] LPWSTR lpDisplayName,
[in, string, range(0, SC_MAX_NAME_LENGTH)] LPCWSTR lpServiceName,
[in, string, unique, range(0, SC_MAX_NAME_LENGTH)] LPCWSTR lpDisplayName,
[in] DWORD dwDesiredAccess,
[in] DWORD dwServiceType,
[in] DWORD dwStartType,
[in] DWORD dwErrorControl,
[in, string, range(0, SC_MAX_PATH_LENGTH)] LPWSTR lpBinaryPathName,
[in, string, unique, range(0, SC_MAX_NAME_LENGTH)] LPWSTR lpLoadOrderGroup,
[in, string, range(0, SC_MAX_PATH_LENGTH)] LPCWSTR lpBinaryPathName,
[in, string, unique, range(0, SC_MAX_NAME_LENGTH)] LPCWSTR lpLoadOrderGroup,
[in, out, unique] LPDWORD lpdwTagId,
[in, unique, size_is(dwDependSize)] LPBYTE lpDependencies,
[in, range(0, SC_MAX_DEPEND_SIZE)] DWORD dwDependSize,
[in, string, unique, range(0, SC_MAX_ACCOUNT_NAME_LENGTH)] LPWSTR lpServiceStartName,
[in, string, unique, range(0, SC_MAX_ACCOUNT_NAME_LENGTH)] LPCWSTR lpServiceStartName,
[in, unique, size_is(dwPwSize)] LPBYTE lpPassword,
[in, range(0, SC_MAX_PWD_SIZE)] DWORD dwPwSize,
[out] LPSC_RPC_HANDLE lpServiceHandle);
@ -454,14 +454,14 @@ interface svcctl
/* Function 20 */
DWORD RGetServiceDisplayNameW(
[in] SC_RPC_HANDLE hSCManager,
[in, string, range(0, SC_MAX_NAME_LENGTH)] LPWSTR lpServiceName,
[in, string, range(0, SC_MAX_NAME_LENGTH)] LPCWSTR lpServiceName,
[out, string, range(1, 4*1024+1), size_is(*lpcchBuffer + 1)] LPWSTR lpDisplayName,
[in, out] DWORD* lpcchBuffer);
/* Function 21 */
DWORD RGetServiceKeyNameW(
[in] SC_RPC_HANDLE hSCManager,
[in, string, range(0, SC_MAX_NAME_LENGTH)] LPWSTR lpDisplayName,
[in, string, range(0, SC_MAX_NAME_LENGTH)] LPCWSTR lpDisplayName,
[out, string, range(1, 4*1024+1), size_is(*lpcchBuffer + 1)] LPWSTR lpServiceName,
[in, out] DWORD* lpcchBuffer);
@ -566,14 +566,14 @@ interface svcctl
/* Function 32 */
DWORD RGetServiceDisplayNameA(
[in] SC_RPC_HANDLE hSCManager,
[in, string, range(0, SC_MAX_NAME_LENGTH)] LPSTR lpServiceName,
[in, string, range(0, SC_MAX_NAME_LENGTH)] LPCSTR lpServiceName,
[out, string, size_is(*lpcchBuffer)] LPSTR lpDisplayName,
[in, out] LPBOUNDED_DWORD_4K lpcchBuffer);
/* Function 33 */
DWORD RGetServiceKeyNameA(
[in] SC_RPC_HANDLE hSCManager,
[in, string, range(0, SC_MAX_NAME_LENGTH)] LPSTR lpDisplayName,
[in, string, range(0, SC_MAX_NAME_LENGTH)] LPCSTR lpDisplayName,
[out, string, size_is(*lpcchBuffer)] LPSTR lpKeyName,
[in, out] LPBOUNDED_DWORD_4K lpcchBuffer);