ReactOS  0.4.14-dev-368-gfa26425
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 
11 DWORD
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 
42 DWORD
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 
77 DWORD
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 
103  RpcRevertToSelf();
104  UndoAlignRpcPtr(pJob, pJobAligned, cbBuf, pcbNeeded);
105 
106  return dwErrorCode;
107 }
108 
109 DWORD
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 
124  RpcRevertToSelf();
125  return dwErrorCode;
126 }
127 
128 DWORD
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 
144  RpcRevertToSelf();
145  return dwErrorCode;
146 }
DWORD cbStructureSize
Definition: marshalling.h:25
MARSHALLING_INFO pInfo[]
Definition: marshalling.h:26
BOOL WINAPI EnumJobsW(HANDLE hPrinter, DWORD FirstJob, DWORD NoJobs, DWORD Level, PBYTE pJob, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
Definition: jobs.c:26
#define TRUE
Definition: types.h:120
static const MARSHALLING AddJobInfo1Marshalling
Definition: jobs.h:8
#define ERROR_SUCCESS
Definition: deptool.c:10
BOOL WINAPI SetJobW(HANDLE hPrinter, DWORD JobId, DWORD Level, PBYTE pJobInfo, DWORD Command)
Definition: jobs.c:71
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:55
Definition: shell.h:41
static const MARSHALLING * pJobInfoMarshalling[]
Definition: jobs.h:67
DWORD _RpcSetJob(WINSPOOL_PRINTER_HANDLE hPrinter, DWORD JobId, WINSPOOL_JOB_CONTAINER *pJobContainer, DWORD Command)
Definition: jobs.c:129
smooth NULL
Definition: ftsmooth.c:416
DWORD _RpcGetJob(WINSPOOL_PRINTER_HANDLE hPrinter, DWORD JobId, DWORD Level, BYTE *pJob, DWORD cbBuf, DWORD *pcbNeeded)
Definition: jobs.c:78
BOOL WINAPI AddJobW(HANDLE hPrinter, DWORD Level, PBYTE pData, DWORD cbBuf, PDWORD pcbNeeded)
Definition: jobs.c:11
WINSPOOL_JOB_INFO_1 * Level1
Definition: winspool.idl:635
RPC_STATUS WINAPI RpcRevertToSelf(void)
Definition: rpc_binding.c:1460
DWORD _RpcScheduleJob(WINSPOOL_PRINTER_HANDLE hPrinter, DWORD JobId)
Definition: jobs.c:110
unsigned long DWORD
Definition: ntddk_ex.h:95
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
BOOL WINAPI MarshallDownStructure(PVOID pStructure, const MARSHALLING_INFO *pInfo, DWORD cbStructureSize, BOOL bSomeBoolean)
Definition: marshalling.c:38
DWORD _RpcEnumJobs(WINSPOOL_PRINTER_HANDLE hPrinter, DWORD FirstJob, DWORD NoJobs, DWORD Level, BYTE *pJob, DWORD cbBuf, DWORD *pcbNeeded, DWORD *pcReturned)
Definition: jobs.c:43
unsigned char BYTE
Definition: mem.h:68
#define ERR(fmt,...)
Definition: debug.h:109
PVOID WINAPI AlignRpcPtr(PVOID pBuffer, PDWORD pcbBuffer)
Definition: memory.c:29
_In_ DWORD _Out_ PDWORD pcbNeeded
Definition: winddi.h:3827
PDWORD WINAPI UndoAlignRpcPtr(PVOID pDestinationBuffer, PVOID pSourceBuffer, DWORD cbBuffer, PDWORD pcbNeeded)
Definition: memory.c:236
RPC_STATUS WINAPI RpcImpersonateClient(RPC_BINDING_HANDLE BindingHandle)
Definition: rpc_binding.c:1053
BOOL WINAPI GetJobW(HANDLE hPrinter, DWORD JobId, DWORD Level, PBYTE pJob, DWORD cbBuf, PDWORD pcbNeeded)
Definition: jobs.c:41
union _WINSPOOL_JOB_CONTAINER::@3307 JobInfo
BYTE * PBYTE
Definition: pedump.c:66
BOOL WINAPI MarshallDownStructuresArray(PVOID pStructuresArray, DWORD cElements, const MARSHALLING_INFO *pInfo, DWORD cbStructureSize, BOOL bSomeBoolean)
Definition: marshalling.c:91
BOOL WINAPI ScheduleJob(HANDLE hPrinter, DWORD dwJobID)
Definition: jobs.c:56
DWORD _RpcAddJob(WINSPOOL_PRINTER_HANDLE hPrinter, DWORD Level, BYTE *pAddJob, DWORD cbBuf, DWORD *pcbNeeded)
Definition: jobs.c:12