ReactOS 0.4.15-dev-8102-g108db8f
jobs.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Print Spooler Service
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Functions for managing print jobs
5 * COPYRIGHT: Copyright 2015-2018 Colin Finck (colin@reactos.org)
6 */
7
8#include "precomp.h"
9#include <marshalling/jobs.h>
10
13{
14 DWORD dwErrorCode;
15 PBYTE pAddJobAligned;
16
17 dwErrorCode = RpcImpersonateClient(NULL);
18 if (dwErrorCode != ERROR_SUCCESS)
19 {
20 ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
21 return dwErrorCode;
22 }
23
24 pAddJobAligned = AlignRpcPtr(pAddJob, &cbBuf);
25
26 if (AddJobW(hPrinter, Level, pAddJobAligned, cbBuf, pcbNeeded))
27 {
28 // Replace absolute pointer addresses in the output by relative offsets.
30 }
31 else
32 {
33 dwErrorCode = GetLastError();
34 }
35
37 UndoAlignRpcPtr(pAddJob, pAddJobAligned, cbBuf, pcbNeeded);
38
39 return dwErrorCode;
40}
41
43_RpcEnumJobs(WINSPOOL_PRINTER_HANDLE hPrinter, DWORD FirstJob, DWORD NoJobs, DWORD Level, BYTE* pJob, DWORD cbBuf, DWORD* pcbNeeded, DWORD* pcReturned)
44{
45 DWORD dwErrorCode;
46 PBYTE pJobAligned;
47
48 dwErrorCode = RpcImpersonateClient(NULL);
49 if (dwErrorCode != ERROR_SUCCESS)
50 {
51 ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
52 return dwErrorCode;
53 }
54
55 pJobAligned = AlignRpcPtr(pJob, &cbBuf);
56
57 if (EnumJobsW(hPrinter, FirstJob, NoJobs, Level, pJobAligned, cbBuf, pcbNeeded, pcReturned))
58 {
59 // Replace absolute pointer addresses in the output by relative offsets for JOB_INFO_1W and JOB_INFO_2W.
60 if (Level <= 2)
61 {
62 ASSERT(Level >= 1);
63 MarshallDownStructuresArray(pJobAligned, *pcReturned, pJobInfoMarshalling[Level]->pInfo, pJobInfoMarshalling[Level]->cbStructureSize, TRUE);
64 }
65 }
66 else
67 {
68 dwErrorCode = GetLastError();
69 }
70
72 UndoAlignRpcPtr(pJob, pJobAligned, cbBuf, pcbNeeded);
73
74 return dwErrorCode;
75}
76
79{
80 DWORD dwErrorCode;
81 PBYTE pJobAligned;
82
83 dwErrorCode = RpcImpersonateClient(NULL);
84 if (dwErrorCode != ERROR_SUCCESS)
85 {
86 ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
87 return dwErrorCode;
88 }
89
90 pJobAligned = AlignRpcPtr(pJob, &cbBuf);
91
92 if (GetJobW(hPrinter, JobId, Level, pJobAligned, cbBuf, pcbNeeded))
93 {
94 // Replace absolute pointer addresses in the output by relative offsets.
95 ASSERT(Level >= 1 && Level <= 2);
96 MarshallDownStructure(pJobAligned, pJobInfoMarshalling[Level]->pInfo, pJobInfoMarshalling[Level]->cbStructureSize, TRUE);
97 }
98 else
99 {
100 dwErrorCode = GetLastError();
101 }
102
104 UndoAlignRpcPtr(pJob, pJobAligned, cbBuf, pcbNeeded);
105
106 return dwErrorCode;
107}
108
109DWORD
111{
112 DWORD dwErrorCode;
113
114 dwErrorCode = RpcImpersonateClient(NULL);
115 if (dwErrorCode != ERROR_SUCCESS)
116 {
117 ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
118 return dwErrorCode;
119 }
120
121 if (!ScheduleJob(hPrinter, JobId))
122 dwErrorCode = GetLastError();
123
125 return dwErrorCode;
126}
127
128DWORD
130{
131 DWORD dwErrorCode;
132
133 dwErrorCode = RpcImpersonateClient(NULL);
134 if (dwErrorCode != ERROR_SUCCESS)
135 {
136 ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
137 return dwErrorCode;
138 }
139
140 // pJobContainer->JobInfo is a union of pointers, so we can just convert any element to our BYTE pointer.
141 if (!SetJobW(hPrinter, JobId, pJobContainer->Level, (PBYTE)pJobContainer->JobInfo.Level1, Command))
142 dwErrorCode = GetLastError();
143
145 return dwErrorCode;
146}
BOOL WINAPI EnumJobsW(HANDLE hPrinter, DWORD FirstJob, DWORD NoJobs, DWORD Level, PBYTE pJob, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
Definition: jobs.c:26
BOOL WINAPI GetJobW(HANDLE hPrinter, DWORD JobId, DWORD Level, PBYTE pJob, DWORD cbBuf, PDWORD pcbNeeded)
Definition: jobs.c:41
BOOL WINAPI ScheduleJob(HANDLE hPrinter, DWORD dwJobID)
Definition: jobs.c:56
BOOL WINAPI SetJobW(HANDLE hPrinter, DWORD JobId, DWORD Level, PBYTE pJobInfo, DWORD Command)
Definition: jobs.c:71
BOOL WINAPI AddJobW(HANDLE hPrinter, DWORD Level, PBYTE pData, DWORD cbBuf, PDWORD pcbNeeded)
Definition: jobs.c:11
DWORD _RpcSetJob(WINSPOOL_PRINTER_HANDLE hPrinter, DWORD JobId, WINSPOOL_JOB_CONTAINER *pJobContainer, DWORD Command)
Definition: jobs.c:129
DWORD _RpcAddJob(WINSPOOL_PRINTER_HANDLE hPrinter, DWORD Level, BYTE *pAddJob, DWORD cbBuf, DWORD *pcbNeeded)
Definition: jobs.c:12
DWORD _RpcGetJob(WINSPOOL_PRINTER_HANDLE hPrinter, DWORD JobId, DWORD Level, BYTE *pJob, DWORD cbBuf, DWORD *pcbNeeded)
Definition: jobs.c:78
DWORD _RpcEnumJobs(WINSPOOL_PRINTER_HANDLE hPrinter, DWORD FirstJob, DWORD NoJobs, DWORD Level, BYTE *pJob, DWORD cbBuf, DWORD *pcbNeeded, DWORD *pcReturned)
Definition: jobs.c:43
DWORD _RpcScheduleJob(WINSPOOL_PRINTER_HANDLE hPrinter, DWORD JobId)
Definition: jobs.c:110
#define ERR(fmt,...)
Definition: debug.h:113
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
unsigned long DWORD
Definition: ntddk_ex.h:95
static const MARSHALLING AddJobInfo1Marshalling
Definition: jobs.h:8
static const MARSHALLING * pJobInfoMarshalling[]
Definition: jobs.h:67
BOOL WINAPI MarshallDownStructure(PVOID pStructure, const MARSHALLING_INFO *pInfo, DWORD cbStructureSize, BOOL bSomeBoolean)
Definition: marshalling.c:38
BOOL WINAPI MarshallDownStructuresArray(PVOID pStructuresArray, DWORD cElements, const MARSHALLING_INFO *pInfo, DWORD cbStructureSize, BOOL bSomeBoolean)
Definition: marshalling.c:91
#define ASSERT(a)
Definition: mode.c:44
BYTE * PBYTE
Definition: pedump.c:66
RPC_STATUS WINAPI RpcRevertToSelf(void)
Definition: rpc_binding.c:1463
RPC_STATUS WINAPI RpcImpersonateClient(RPC_BINDING_HANDLE BindingHandle)
Definition: rpc_binding.c:1056
Definition: shell.h:41
MARSHALLING_INFO pInfo[]
Definition: marshalling.h:26
DWORD cbStructureSize
Definition: marshalling.h:25
WINSPOOL_JOB_INFO_1 * Level1
Definition: winspool.idl:635
union _WINSPOOL_JOB_CONTAINER::@3447 JobInfo
PVOID WINAPI AlignRpcPtr(PVOID pBuffer, PDWORD pcbBuffer)
Definition: memory.c:29
PDWORD WINAPI UndoAlignRpcPtr(PVOID pDestinationBuffer, PVOID pSourceBuffer, DWORD cbBuffer, PDWORD pcbNeeded)
Definition: memory.c:239
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
_In_ DWORD _Out_ PDWORD pcbNeeded
Definition: winddi.h:3828
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:56
unsigned char BYTE
Definition: xxhash.c:193