2015-06-22 14:31:47 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS Print Spooler Service
|
2017-09-29 17:18:19 +00:00
|
|
|
* LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
|
2015-06-22 14:31:47 +00:00
|
|
|
* PURPOSE: Functions for managing print jobs
|
2018-01-17 11:52:12 +00:00
|
|
|
* COPYRIGHT: Copyright 2015-2018 Colin Finck (colin@reactos.org)
|
2015-06-22 14:31:47 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "precomp.h"
|
2018-01-17 11:52:12 +00:00
|
|
|
#include <marshalling/jobs.h>
|
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))
|
|
|
|
{
|
|
|
|
// Replace absolute pointer addresses in the output by relative offsets.
|
2018-01-17 11:52:12 +00:00
|
|
|
MarshallDownStructure(pAddJobAligned, AddJobInfo1Marshalling.pInfo, AddJobInfo1Marshalling.cbStructureSize, TRUE);
|
2017-07-05 15:29:13 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
{
|
2018-01-17 11:52:12 +00:00
|
|
|
// Replace absolute pointer addresses in the output by relative offsets for JOB_INFO_1W and JOB_INFO_2W.
|
|
|
|
if (Level <= 2)
|
|
|
|
{
|
|
|
|
ASSERT(Level >= 1);
|
|
|
|
MarshallDownStructuresArray(pJobAligned, *pcReturned, pJobInfoMarshalling[Level]->pInfo, pJobInfoMarshalling[Level]->cbStructureSize, TRUE);
|
|
|
|
}
|
2017-07-05 15:29:13 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
{
|
|
|
|
// Replace absolute pointer addresses in the output by relative offsets.
|
2018-01-17 11:52:12 +00:00
|
|
|
ASSERT(Level >= 1 && Level <= 2);
|
|
|
|
MarshallDownStructure(pJobAligned, pJobInfoMarshalling[Level]->pInfo, pJobInfoMarshalling[Level]->cbStructureSize, TRUE);
|
2017-07-05 15:29:13 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
}
|