[PRINTING]

- Create the actual generic handle in _LocalOpenPrinterHandle.
- Fix _RpcClosePrinter call.
- Enable many more tests in winspool_apitest, GetPrinterData.
- Bail out with ERROR_INVALID_PARAMETER for empty strings in _MakePrinterSubKey as well.
- Add the Name registry value for "Dummy Printer on LPT1" to make a test succeed.

This fixes many basic things.. which only got unnoticed, because Printing is only used in the form of API Tests so far.

CORE-13458
CORE-13459

svn path=/trunk/; revision=75207
This commit is contained in:
Colin Finck 2017-06-26 15:16:46 +00:00
parent 2bd66111fc
commit 1525fa31fc
5 changed files with 30 additions and 30 deletions

View file

@ -444,6 +444,7 @@ HKLM,"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\Dummy Printer
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
HKLM,"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\Dummy Printer On LPT1","Location",,"At Home"
HKLM,"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\Dummy Printer On LPT1","Name",,"Dummy Printer On LPT1"
HKLM,"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\Dummy Printer On LPT1","Port",,"LPT1:"
HKLM,"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\Dummy Printer On LPT1","Print Processor",,"winprint"
HKLM,"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\Dummy Printer On LPT1","Printer Driver",,"Dummy Printer Driver"

View file

@ -235,7 +235,7 @@ ClosePrinter(HANDLE hPrinter)
// Do the RPC call.
RpcTryExcept
{
dwErrorCode = _RpcClosePrinter(pHandle->hPrinter);
dwErrorCode = _RpcClosePrinter(&pHandle->hPrinter);
}
RpcExcept(EXCEPTION_EXECUTE_HANDLER)
{

View file

@ -25,7 +25,7 @@ _MakePrinterSubKey(PLOCAL_PRINTER_HANDLE pPrinterHandle, PCWSTR pKeyName, PWSTR*
PWSTR p;
// Sanity check
if (!pKeyName)
if (!pKeyName || !*pKeyName)
return ERROR_INVALID_PARAMETER;
// Allocate a buffer for the subkey "PrinterName\KeyName".
@ -204,7 +204,7 @@ _LocalGetPrintServerHandleData(PCWSTR pValueName, PDWORD pType, PBYTE pData, DWO
dwErrorCode = DsRoleGetPrimaryDomainInformation(NULL, DsRolePrimaryDomainInfoBasic, (PBYTE*)&pInfo);
if (dwErrorCode != ERROR_SUCCESS)
{
ERR("DsRoleGetPrimaryDomainInformation failed with error %lu!\n", GetLastError());
ERR("DsRoleGetPrimaryDomainInformation failed with error %lu!\n", dwErrorCode);
return dwErrorCode;
}
@ -216,9 +216,9 @@ _LocalGetPrintServerHandleData(PCWSTR pValueName, PDWORD pType, PBYTE pData, DWO
else if (wcsicmp(pValueName, SPLREG_DS_PRESENT_FOR_USER) == 0)
{
DWORD cch;
PWSTR pwszUserSam;
PWSTR p;
WCHAR wszComputerName[MAX_COMPUTERNAME_LENGTH + 1];
WCHAR wszUserSam[UNLEN + 1];
// We want to store a REG_DWORD value.
*pType = REG_DWORD;
@ -230,47 +230,30 @@ _LocalGetPrintServerHandleData(PCWSTR pValueName, PDWORD pType, PBYTE pData, DWO
cch = MAX_COMPUTERNAME_LENGTH + 1;
if (!GetComputerNameW(wszComputerName, &cch))
{
ERR("GetComputerNameW failed with error %lu!\n", GetLastError());
return GetLastError();
dwErrorCode = GetLastError();
ERR("GetComputerNameW failed with error %lu!\n", dwErrorCode);
return dwErrorCode;
}
// Get the User Name in the SAM format.
// This could either be:
// COMPUTERNAME\User
// DOMAINNAME\User
cch = 0;
GetUserNameExW(NameSamCompatible, NULL, &cch);
dwErrorCode = GetLastError();
if (dwErrorCode != ERROR_MORE_DATA)
{
ERR("GetUserNameExW failed with error %lu!\n", dwErrorCode);
return dwErrorCode;
}
pwszUserSam = DllAllocSplMem(cch * sizeof(WCHAR));
if (!pwszUserSam)
{
dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
ERR("DllAllocSplMem failed!\n");
return dwErrorCode;
}
if (!GetUserNameExW(NameSamCompatible, pwszUserSam, &cch))
cch = UNLEN + 1;
if (!GetUserNameExW(NameSamCompatible, wszUserSam, &cch))
{
dwErrorCode = GetLastError();
ERR("GetUserNameExW failed with error %lu!\n", dwErrorCode);
DllFreeSplMem(pwszUserSam);
return dwErrorCode;
}
// Terminate the SAM-formatted User Name at the backslash.
p = wcschr(pwszUserSam, L'\\');
p = wcschr(wszUserSam, L'\\');
*p = 0;
// Compare it with the Computer Name.
// If they differ, this User is part of a domain.
*((PDWORD)pData) = (wcscmp(pwszUserSam, wszComputerName) != 0);
DllFreeSplMem(pwszUserSam);
*((PDWORD)pData) = (wcscmp(wszUserSam, wszComputerName) != 0);
return ERROR_SUCCESS;
}
else if (wcsicmp(pValueName, SPLREG_REMOTE_FAX) == 0)
@ -328,6 +311,7 @@ _LocalGetPrintServerHandleData(PCWSTR pValueName, PDWORD pType, PBYTE pData, DWO
DWORD WINAPI
LocalGetPrinterDataEx(HANDLE hPrinter, PCWSTR pKeyName, PCWSTR pValueName, PDWORD pType, PBYTE pData, DWORD nSize, PDWORD pcbNeeded)
{
BYTE Temp;
DWORD dwErrorCode;
DWORD dwTemp;
PLOCAL_HANDLE pHandle = (PLOCAL_HANDLE)hPrinter;
@ -338,6 +322,12 @@ LocalGetPrinterDataEx(HANDLE hPrinter, PCWSTR pKeyName, PCWSTR pValueName, PDWOR
if (!pType)
pType = &dwTemp;
// pData is later fed to RegQueryValueExW in many cases. When calling it with zero buffer size, RegQueryValueExW returns a
// different error code based on whether pData is NULL or something else.
// Ensure here that ERROR_MORE_DATA is always returned.
if (!pData)
pData = &Temp;
if (!pHandle)
{
dwErrorCode = ERROR_INVALID_HANDLE;

View file

@ -1106,6 +1106,15 @@ _LocalOpenPrinterHandle(PWSTR pwszPrinterName, PWSTR pwszJobParameter, PHANDLE p
goto Failure;
}
// Create a new generic handle.
pHandle = DllAllocSplMem(sizeof(LOCAL_HANDLE));
if (!pHandle)
{
dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
ERR("DllAllocSplMem failed!\n");
goto Failure;
}
// Create a new LOCAL_PRINTER_HANDLE.
pPrinterHandle = DllAllocSplMem(sizeof(LOCAL_PRINTER_HANDLE));
if (!pPrinterHandle)
@ -1192,7 +1201,7 @@ _LocalOpenPrinterHandle(PWSTR pwszPrinterName, PWSTR pwszJobParameter, PHANDLE p
pPrinterHandle->pJob = pJob;
}
// Make the generic handle a Port handle.
// Make the generic handle a Printer handle.
pHandle->HandleType = HandleType_Printer;
pHandle->pSpecificHandle = pPrinterHandle;

View file

@ -28,7 +28,6 @@ typedef struct _SPLREG_VALUE
SPLREG_VALUE, *PSPLREG_VALUE;
SPLREG_VALUE SplRegValues[] = {
#if 0
{ "DefaultSpoolDirectory", L"DefaultSpoolDirectory", REG_SZ, 0xFFFFFFFF, TRUE },
{ "PortThreadPriorityDefault", L"PortThreadPriorityDefault", REG_NONE, 4, FALSE },
{ "PortThreadPriority", L"PortThreadPriority", REG_DWORD, 4, TRUE },
@ -50,6 +49,7 @@ SPLREG_VALUE SplRegValues[] = {
{ "Architecture", L"Architecture", REG_NONE, 0xFFFFFFFF, FALSE },
{ "OSVersion", L"OSVersion", REG_NONE, sizeof(OSVERSIONINFOA), FALSE },
{ "OSVersionEx", L"OSVersionEx", REG_NONE, sizeof(OSVERSIONINFOEXA), FALSE },
#if 0
{ "DsPresent", L"DsPresent", REG_DWORD, 4, FALSE },
{ "DsPresentForUser", L"DsPresentForUser", REG_DWORD, 4, FALSE },
#endif