3e02902a38ee7aa6d88add9912b5c2bc628ce8b7
[reactos.git] / win32ss / printing / base / spoolsv / monitors.c
1 /*
2 * PROJECT: ReactOS Print Spooler Service
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Functions related to Print Monitors
5 * COPYRIGHT: Copyright 2015-2017 Colin Finck (colin@reactos.org)
6 */
7
8 #include "precomp.h"
9
10 static void
11 _MarshallDownMonitorInfo(PBYTE* ppMonitorInfo, DWORD Level)
12 {
13 PMONITOR_INFO_2W pMonitorInfo2 = (PMONITOR_INFO_2W)(*ppMonitorInfo); // MONITOR_INFO_1W is a subset of MONITOR_INFO_2W
14
15 // Replace absolute pointer addresses in the output by relative offsets.
16 pMonitorInfo2->pName = (PWSTR)((ULONG_PTR)pMonitorInfo2->pName - (ULONG_PTR)pMonitorInfo2);
17
18 if (Level == 1)
19 {
20 *ppMonitorInfo += sizeof(MONITOR_INFO_1W);
21 }
22 else
23 {
24 pMonitorInfo2->pDLLName = (PWSTR)((ULONG_PTR)pMonitorInfo2->pDLLName - (ULONG_PTR)pMonitorInfo2);
25 pMonitorInfo2->pEnvironment = (PWSTR)((ULONG_PTR)pMonitorInfo2->pEnvironment - (ULONG_PTR)pMonitorInfo2);
26 *ppMonitorInfo += sizeof(MONITOR_INFO_2W);
27 }
28 }
29
30 DWORD
31 _RpcAddMonitor(WINSPOOL_HANDLE pName, WINSPOOL_MONITOR_CONTAINER* pMonitorContainer)
32 {
33 UNIMPLEMENTED;
34 return ERROR_INVALID_FUNCTION;
35 }
36
37 DWORD
38 _RpcDeleteMonitor(WINSPOOL_HANDLE pName, WCHAR* pEnvironment, WCHAR* pMonitorName)
39 {
40 UNIMPLEMENTED;
41 return ERROR_INVALID_FUNCTION;
42 }
43
44 DWORD
45 _RpcEnumMonitors(WINSPOOL_HANDLE pName, DWORD Level, BYTE* pMonitor, DWORD cbBuf, DWORD* pcbNeeded, DWORD* pcReturned)
46 {
47 DWORD dwErrorCode;
48 PBYTE pMonitorAligned;
49
50 dwErrorCode = RpcImpersonateClient(NULL);
51 if (dwErrorCode != ERROR_SUCCESS)
52 {
53 ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
54 return dwErrorCode;
55 }
56
57 pMonitorAligned = AlignRpcPtr(pMonitor, &cbBuf);
58
59 if(EnumMonitorsW(pName, Level, pMonitorAligned, cbBuf, pcbNeeded, pcReturned))
60 {
61 // Replace absolute pointer addresses in the output by relative offsets.
62 DWORD i;
63 PBYTE p = pMonitorAligned;
64
65 for (i = 0; i < *pcReturned; i++)
66 _MarshallDownMonitorInfo(&p, Level);
67 }
68 else
69 {
70 dwErrorCode = GetLastError();
71 }
72
73 RpcRevertToSelf();
74 UndoAlignRpcPtr(pMonitor, pMonitorAligned, cbBuf, pcbNeeded);
75
76 return dwErrorCode;
77 }