2015-06-22 14:31:47 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS Print Spooler Service
|
|
|
|
* LICENSE: GNU GPLv2 or any later version as published by the Free Software Foundation
|
|
|
|
* PURPOSE: Functions for managing print jobs
|
2017-07-05 15:29:13 +00:00
|
|
|
* COPYRIGHT: Copyright 2015-2017 Colin Finck <colin@reactos.org>
|
2015-06-22 14:31:47 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "precomp.h"
|
|
|
|
|
2015-07-17 15:09:31 +00:00
|
|
|
static void
|
2017-07-05 15:29:13 +00:00
|
|
|
_MarshallDownAddJobInfo(PADDJOB_INFO_1W* ppAddJobInfo1)
|
2015-07-17 15:09:31 +00:00
|
|
|
{
|
|
|
|
// Replace absolute pointer addresses in the output by relative offsets.
|
2017-07-05 15:29:13 +00:00
|
|
|
PADDJOB_INFO_1W pAddJobInfo1 = *ppAddJobInfo1;
|
2015-07-17 15:09:31 +00:00
|
|
|
pAddJobInfo1->Path = (PWSTR)((ULONG_PTR)pAddJobInfo1->Path - (ULONG_PTR)pAddJobInfo1);
|
2017-07-05 15:29:13 +00:00
|
|
|
|
|
|
|
*ppAddJobInfo1 += sizeof(ADDJOB_INFO_1W);
|
2015-07-17 15:09:31 +00:00
|
|
|
}
|
|
|
|
|
2015-06-27 12:36:45 +00:00
|
|
|
static void
|
2017-07-05 15:29:13 +00:00
|
|
|
_MarshallDownJobInfo(PBYTE* ppJobInfo, DWORD Level)
|
2015-06-27 12:36:45 +00:00
|
|
|
{
|
|
|
|
// Replace absolute pointer addresses in the output by relative offsets.
|
|
|
|
if (Level == 1)
|
|
|
|
{
|
2017-07-05 15:29:13 +00:00
|
|
|
PJOB_INFO_1W pJobInfo1 = (PJOB_INFO_1W)(*ppJobInfo);
|
|
|
|
|
2015-06-27 12:36:45 +00:00
|
|
|
pJobInfo1->pDatatype = (PWSTR)((ULONG_PTR)pJobInfo1->pDatatype - (ULONG_PTR)pJobInfo1);
|
|
|
|
pJobInfo1->pDocument = (PWSTR)((ULONG_PTR)pJobInfo1->pDocument - (ULONG_PTR)pJobInfo1);
|
|
|
|
pJobInfo1->pMachineName = (PWSTR)((ULONG_PTR)pJobInfo1->pMachineName - (ULONG_PTR)pJobInfo1);
|
|
|
|
pJobInfo1->pPrinterName = (PWSTR)((ULONG_PTR)pJobInfo1->pPrinterName - (ULONG_PTR)pJobInfo1);
|
|
|
|
|
|
|
|
if (pJobInfo1->pStatus)
|
|
|
|
pJobInfo1->pStatus = (PWSTR)((ULONG_PTR)pJobInfo1->pStatus - (ULONG_PTR)pJobInfo1);
|
|
|
|
|
|
|
|
pJobInfo1->pUserName = (PWSTR)((ULONG_PTR)pJobInfo1->pUserName - (ULONG_PTR)pJobInfo1);
|
2017-07-05 15:29:13 +00:00
|
|
|
|
|
|
|
*ppJobInfo += sizeof(JOB_INFO_1W);
|
2015-06-27 12:36:45 +00:00
|
|
|
}
|
|
|
|
else if (Level == 2)
|
|
|
|
{
|
2017-07-05 15:29:13 +00:00
|
|
|
PJOB_INFO_2W pJobInfo2 = (PJOB_INFO_2W)(*ppJobInfo);
|
|
|
|
|
2015-06-27 12:36:45 +00:00
|
|
|
pJobInfo2->pDatatype = (PWSTR)((ULONG_PTR)pJobInfo2->pDatatype - (ULONG_PTR)pJobInfo2);
|
|
|
|
pJobInfo2->pDevMode = (PDEVMODEW)((ULONG_PTR)pJobInfo2->pDevMode - (ULONG_PTR)pJobInfo2);
|
|
|
|
pJobInfo2->pDocument = (PWSTR)((ULONG_PTR)pJobInfo2->pDocument - (ULONG_PTR)pJobInfo2);
|
|
|
|
pJobInfo2->pDriverName = (PWSTR)((ULONG_PTR)pJobInfo2->pDriverName - (ULONG_PTR)pJobInfo2);
|
|
|
|
pJobInfo2->pMachineName = (PWSTR)((ULONG_PTR)pJobInfo2->pMachineName - (ULONG_PTR)pJobInfo2);
|
|
|
|
pJobInfo2->pNotifyName = (PWSTR)((ULONG_PTR)pJobInfo2->pNotifyName - (ULONG_PTR)pJobInfo2);
|
|
|
|
pJobInfo2->pPrinterName = (PWSTR)((ULONG_PTR)pJobInfo2->pPrinterName - (ULONG_PTR)pJobInfo2);
|
|
|
|
pJobInfo2->pPrintProcessor = (PWSTR)((ULONG_PTR)pJobInfo2->pPrintProcessor - (ULONG_PTR)pJobInfo2);
|
|
|
|
|
|
|
|
if (pJobInfo2->pParameters)
|
|
|
|
pJobInfo2->pParameters = (PWSTR)((ULONG_PTR)pJobInfo2->pParameters - (ULONG_PTR)pJobInfo2);
|
|
|
|
|
|
|
|
if (pJobInfo2->pStatus)
|
|
|
|
pJobInfo2->pStatus = (PWSTR)((ULONG_PTR)pJobInfo2->pStatus - (ULONG_PTR)pJobInfo2);
|
|
|
|
|
|
|
|
pJobInfo2->pUserName = (PWSTR)((ULONG_PTR)pJobInfo2->pUserName - (ULONG_PTR)pJobInfo2);
|
2017-07-05 15:29:13 +00:00
|
|
|
|
|
|
|
*ppJobInfo += sizeof(JOB_INFO_2W);
|
2015-06-27 12:36:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-22 14:31:47 +00:00
|
|
|
DWORD
|
|
|
|
_RpcAddJob(WINSPOOL_PRINTER_HANDLE hPrinter, DWORD Level, BYTE* pAddJob, DWORD cbBuf, DWORD* pcbNeeded)
|
|
|
|
{
|
|
|
|
DWORD dwErrorCode;
|
2017-07-05 15:29:13 +00:00
|
|
|
PBYTE pAddJobAligned;
|
2015-06-22 14:31:47 +00:00
|
|
|
|
|
|
|
dwErrorCode = RpcImpersonateClient(NULL);
|
|
|
|
if (dwErrorCode != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
|
|
|
|
return dwErrorCode;
|
|
|
|
}
|
|
|
|
|
2017-07-05 15:29:13 +00:00
|
|
|
pAddJobAligned = AlignRpcPtr(pAddJob, &cbBuf);
|
2015-06-22 14:31:47 +00:00
|
|
|
|
2017-07-05 15:29:13 +00:00
|
|
|
if (AddJobW(hPrinter, Level, pAddJobAligned, cbBuf, pcbNeeded))
|
|
|
|
{
|
|
|
|
PBYTE p = pAddJobAligned;
|
|
|
|
|
|
|
|
// Replace absolute pointer addresses in the output by relative offsets.
|
|
|
|
_MarshallDownAddJobInfo((PADDJOB_INFO_1W*)&p);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dwErrorCode = GetLastError();
|
|
|
|
}
|
2015-06-27 12:36:45 +00:00
|
|
|
|
|
|
|
RpcRevertToSelf();
|
2017-07-05 15:29:13 +00:00
|
|
|
UndoAlignRpcPtr(pAddJob, pAddJobAligned, cbBuf, pcbNeeded);
|
|
|
|
|
2015-06-27 12:36:45 +00:00
|
|
|
return dwErrorCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD
|
|
|
|
_RpcEnumJobs(WINSPOOL_PRINTER_HANDLE hPrinter, DWORD FirstJob, DWORD NoJobs, DWORD Level, BYTE* pJob, DWORD cbBuf, DWORD* pcbNeeded, DWORD* pcReturned)
|
|
|
|
{
|
|
|
|
DWORD dwErrorCode;
|
2017-07-05 15:29:13 +00:00
|
|
|
PBYTE pJobAligned;
|
2015-06-27 12:36:45 +00:00
|
|
|
|
|
|
|
dwErrorCode = RpcImpersonateClient(NULL);
|
|
|
|
if (dwErrorCode != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
|
|
|
|
return dwErrorCode;
|
|
|
|
}
|
|
|
|
|
2017-07-05 15:29:13 +00:00
|
|
|
pJobAligned = AlignRpcPtr(pJob, &cbBuf);
|
2015-06-27 12:36:45 +00:00
|
|
|
|
2017-07-05 15:29:13 +00:00
|
|
|
if (EnumJobsW(hPrinter, FirstJob, NoJobs, Level, pJobAligned, cbBuf, pcbNeeded, pcReturned))
|
2015-06-27 12:36:45 +00:00
|
|
|
{
|
2017-07-05 15:29:13 +00:00
|
|
|
DWORD i;
|
|
|
|
PBYTE p = pJobAligned;
|
|
|
|
|
2015-06-27 12:36:45 +00:00
|
|
|
// Replace absolute pointer addresses in the output by relative offsets.
|
|
|
|
for (i = 0; i < *pcReturned; i++)
|
2017-07-05 15:29:13 +00:00
|
|
|
_MarshallDownJobInfo(&p, Level);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dwErrorCode = GetLastError();
|
2015-06-27 12:36:45 +00:00
|
|
|
}
|
|
|
|
|
2015-06-23 13:46:14 +00:00
|
|
|
RpcRevertToSelf();
|
2017-07-05 15:29:13 +00:00
|
|
|
UndoAlignRpcPtr(pJob, pJobAligned, cbBuf, pcbNeeded);
|
|
|
|
|
2015-06-23 13:46:14 +00:00
|
|
|
return dwErrorCode;
|
2015-06-22 14:31:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DWORD
|
|
|
|
_RpcGetJob(WINSPOOL_PRINTER_HANDLE hPrinter, DWORD JobId, DWORD Level, BYTE* pJob, DWORD cbBuf, DWORD* pcbNeeded)
|
|
|
|
{
|
|
|
|
DWORD dwErrorCode;
|
2017-07-05 15:29:13 +00:00
|
|
|
PBYTE pJobAligned;
|
2015-06-22 14:31:47 +00:00
|
|
|
|
|
|
|
dwErrorCode = RpcImpersonateClient(NULL);
|
|
|
|
if (dwErrorCode != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
|
|
|
|
return dwErrorCode;
|
|
|
|
}
|
|
|
|
|
2017-07-05 15:29:13 +00:00
|
|
|
pJobAligned = AlignRpcPtr(pJob, &cbBuf);
|
2015-06-22 14:31:47 +00:00
|
|
|
|
2017-07-05 15:29:13 +00:00
|
|
|
if (GetJobW(hPrinter, JobId, Level, pJobAligned, cbBuf, pcbNeeded))
|
2015-06-27 12:36:45 +00:00
|
|
|
{
|
2017-07-05 15:29:13 +00:00
|
|
|
PBYTE p = pJobAligned;
|
|
|
|
|
2015-06-27 12:36:45 +00:00
|
|
|
// Replace absolute pointer addresses in the output by relative offsets.
|
2017-07-05 15:29:13 +00:00
|
|
|
_MarshallDownJobInfo(&p, Level);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dwErrorCode = GetLastError();
|
2015-06-27 12:36:45 +00:00
|
|
|
}
|
|
|
|
|
2015-06-23 13:46:14 +00:00
|
|
|
RpcRevertToSelf();
|
2017-07-05 15:29:13 +00:00
|
|
|
UndoAlignRpcPtr(pJob, pJobAligned, cbBuf, pcbNeeded);
|
|
|
|
|
2015-06-23 13:46:14 +00:00
|
|
|
return dwErrorCode;
|
2015-06-22 14:31:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DWORD
|
|
|
|
_RpcScheduleJob(WINSPOOL_PRINTER_HANDLE hPrinter, DWORD JobId)
|
|
|
|
{
|
2015-06-28 15:51:32 +00:00
|
|
|
DWORD dwErrorCode;
|
|
|
|
|
|
|
|
dwErrorCode = RpcImpersonateClient(NULL);
|
|
|
|
if (dwErrorCode != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
|
|
|
|
return dwErrorCode;
|
|
|
|
}
|
|
|
|
|
2017-07-05 15:29:13 +00:00
|
|
|
if (!ScheduleJob(hPrinter, JobId))
|
|
|
|
dwErrorCode = GetLastError();
|
2015-06-28 15:51:32 +00:00
|
|
|
|
|
|
|
RpcRevertToSelf();
|
|
|
|
return dwErrorCode;
|
2015-06-22 14:31:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DWORD
|
|
|
|
_RpcSetJob(WINSPOOL_PRINTER_HANDLE hPrinter, DWORD JobId, WINSPOOL_JOB_CONTAINER* pJobContainer, DWORD Command)
|
|
|
|
{
|
2015-06-27 12:36:45 +00:00
|
|
|
DWORD dwErrorCode;
|
|
|
|
|
|
|
|
dwErrorCode = RpcImpersonateClient(NULL);
|
|
|
|
if (dwErrorCode != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
|
|
|
|
return dwErrorCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
// pJobContainer->JobInfo is a union of pointers, so we can just convert any element to our BYTE pointer.
|
2017-07-05 15:29:13 +00:00
|
|
|
if (!SetJobW(hPrinter, JobId, pJobContainer->Level, (PBYTE)pJobContainer->JobInfo.Level1, Command))
|
|
|
|
dwErrorCode = GetLastError();
|
2015-06-27 12:36:45 +00:00
|
|
|
|
|
|
|
RpcRevertToSelf();
|
|
|
|
return dwErrorCode;
|
2015-06-22 14:31:47 +00:00
|
|
|
}
|