xref: /reactos/win32ss/printing/base/spoolsv/forms.c (revision 62c4b828)
1c2c66affSColin Finck /*
2c2c66affSColin Finck  * PROJECT:     ReactOS Print Spooler Service
3c2c66affSColin Finck  * LICENSE:     GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4c2c66affSColin Finck  * PURPOSE:     Functions related to Forms
5c2c66affSColin Finck  * COPYRIGHT:   Copyright 2015 Colin Finck (colin@reactos.org)
6c2c66affSColin Finck  */
7c2c66affSColin Finck 
8c2c66affSColin Finck #include "precomp.h"
9*62c4b828SJames Tabor #include <marshalling/forms.h>
10c2c66affSColin Finck 
11c2c66affSColin Finck DWORD
_RpcAddForm(WINSPOOL_PRINTER_HANDLE hPrinter,WINSPOOL_FORM_CONTAINER * pFormInfoContainer)12c2c66affSColin Finck _RpcAddForm(WINSPOOL_PRINTER_HANDLE hPrinter, WINSPOOL_FORM_CONTAINER* pFormInfoContainer)
13c2c66affSColin Finck {
14*62c4b828SJames Tabor     DWORD dwErrorCode;
15*62c4b828SJames Tabor 
16*62c4b828SJames Tabor     dwErrorCode = RpcImpersonateClient(NULL);
17*62c4b828SJames Tabor     if (dwErrorCode != ERROR_SUCCESS)
18*62c4b828SJames Tabor     {
19*62c4b828SJames Tabor         ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
20*62c4b828SJames Tabor         return dwErrorCode;
21*62c4b828SJames Tabor     }
22*62c4b828SJames Tabor 
23*62c4b828SJames Tabor     if (!AddFormW(hPrinter, pFormInfoContainer->Level, (PBYTE)pFormInfoContainer->FormInfo.pFormInfo1))
24*62c4b828SJames Tabor         dwErrorCode = GetLastError();
25*62c4b828SJames Tabor 
26*62c4b828SJames Tabor     RpcRevertToSelf();
27*62c4b828SJames Tabor     return dwErrorCode;
28c2c66affSColin Finck }
29c2c66affSColin Finck 
30c2c66affSColin Finck DWORD
_RpcDeleteForm(WINSPOOL_PRINTER_HANDLE hPrinter,WCHAR * pFormName)31c2c66affSColin Finck _RpcDeleteForm(WINSPOOL_PRINTER_HANDLE hPrinter, WCHAR* pFormName)
32c2c66affSColin Finck {
33*62c4b828SJames Tabor     DWORD dwErrorCode;
34*62c4b828SJames Tabor 
35*62c4b828SJames Tabor     dwErrorCode = RpcImpersonateClient(NULL);
36*62c4b828SJames Tabor     if (dwErrorCode != ERROR_SUCCESS)
37*62c4b828SJames Tabor     {
38*62c4b828SJames Tabor         ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
39*62c4b828SJames Tabor         return dwErrorCode;
40*62c4b828SJames Tabor     }
41*62c4b828SJames Tabor 
42*62c4b828SJames Tabor     if (!DeleteFormW(hPrinter, pFormName))
43*62c4b828SJames Tabor         dwErrorCode = GetLastError();
44*62c4b828SJames Tabor 
45*62c4b828SJames Tabor     RpcRevertToSelf();
46*62c4b828SJames Tabor     return dwErrorCode;
47c2c66affSColin Finck }
48c2c66affSColin Finck 
49c2c66affSColin Finck DWORD
_RpcEnumForms(WINSPOOL_PRINTER_HANDLE hPrinter,DWORD Level,BYTE * pForm,DWORD cbBuf,DWORD * pcbNeeded,DWORD * pcReturned)50c2c66affSColin Finck _RpcEnumForms(WINSPOOL_PRINTER_HANDLE hPrinter, DWORD Level, BYTE* pForm, DWORD cbBuf, DWORD* pcbNeeded, DWORD* pcReturned)
51c2c66affSColin Finck {
52*62c4b828SJames Tabor     DWORD dwErrorCode;
53*62c4b828SJames Tabor     PBYTE pFormsEnumAligned;
54*62c4b828SJames Tabor 
55*62c4b828SJames Tabor     dwErrorCode = RpcImpersonateClient(NULL);
56*62c4b828SJames Tabor     if (dwErrorCode != ERROR_SUCCESS)
57*62c4b828SJames Tabor     {
58*62c4b828SJames Tabor         ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
59*62c4b828SJames Tabor         return dwErrorCode;
60*62c4b828SJames Tabor     }
61*62c4b828SJames Tabor 
62*62c4b828SJames Tabor     pFormsEnumAligned = AlignRpcPtr(pForm, &cbBuf);
63*62c4b828SJames Tabor 
64*62c4b828SJames Tabor     if (EnumFormsW(hPrinter, Level, pFormsEnumAligned, cbBuf, pcbNeeded, pcReturned))
65*62c4b828SJames Tabor     {
66*62c4b828SJames Tabor         // Replace absolute pointer addresses in the output by relative offsets.
67*62c4b828SJames Tabor         ASSERT(Level >= 1 && Level <= 2);
68*62c4b828SJames Tabor         MarshallDownStructuresArray(pFormsEnumAligned, *pcReturned, pFormInfoMarshalling[Level]->pInfo, pFormInfoMarshalling[Level]->cbStructureSize, TRUE);
69*62c4b828SJames Tabor     }
70*62c4b828SJames Tabor     else
71*62c4b828SJames Tabor     {
72*62c4b828SJames Tabor         dwErrorCode = GetLastError();
73*62c4b828SJames Tabor     }
74*62c4b828SJames Tabor 
75*62c4b828SJames Tabor     RpcRevertToSelf();
76*62c4b828SJames Tabor     UndoAlignRpcPtr(pForm, pFormsEnumAligned, cbBuf, pcbNeeded);
77*62c4b828SJames Tabor 
78*62c4b828SJames Tabor     return dwErrorCode;
79c2c66affSColin Finck }
80c2c66affSColin Finck 
81c2c66affSColin Finck DWORD
_RpcGetForm(WINSPOOL_PRINTER_HANDLE hPrinter,WCHAR * pFormName,DWORD Level,BYTE * pForm,DWORD cbBuf,DWORD * pcbNeeded)82c2c66affSColin Finck _RpcGetForm(WINSPOOL_PRINTER_HANDLE hPrinter, WCHAR* pFormName, DWORD Level, BYTE* pForm, DWORD cbBuf, DWORD* pcbNeeded)
83c2c66affSColin Finck {
84*62c4b828SJames Tabor     DWORD dwErrorCode;
85*62c4b828SJames Tabor     PBYTE pFormAligned;
86*62c4b828SJames Tabor 
87*62c4b828SJames Tabor     dwErrorCode = RpcImpersonateClient(NULL);
88*62c4b828SJames Tabor     if (dwErrorCode != ERROR_SUCCESS)
89*62c4b828SJames Tabor     {
90*62c4b828SJames Tabor         ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
91*62c4b828SJames Tabor         return dwErrorCode;
92*62c4b828SJames Tabor     }
93*62c4b828SJames Tabor 
94*62c4b828SJames Tabor     pFormAligned = AlignRpcPtr(pForm, &cbBuf);
95*62c4b828SJames Tabor 
96*62c4b828SJames Tabor     if (GetFormW(hPrinter, pFormName, Level, pFormAligned, cbBuf, pcbNeeded))
97*62c4b828SJames Tabor     {
98*62c4b828SJames Tabor         // Replace absolute pointer addresses in the output by relative offsets.
99*62c4b828SJames Tabor         ASSERT(Level >= 1 && Level <= 2);
100*62c4b828SJames Tabor         MarshallDownStructure(pFormAligned, pFormInfoMarshalling[Level]->pInfo, pFormInfoMarshalling[Level]->cbStructureSize, TRUE);
101*62c4b828SJames Tabor     }
102*62c4b828SJames Tabor     else
103*62c4b828SJames Tabor     {
104*62c4b828SJames Tabor         dwErrorCode = GetLastError();
105*62c4b828SJames Tabor     }
106*62c4b828SJames Tabor 
107*62c4b828SJames Tabor     RpcRevertToSelf();
108*62c4b828SJames Tabor     UndoAlignRpcPtr(pForm, pFormAligned, cbBuf, pcbNeeded);
109*62c4b828SJames Tabor 
110*62c4b828SJames Tabor     return dwErrorCode;
111c2c66affSColin Finck }
112c2c66affSColin Finck 
113c2c66affSColin Finck DWORD
_RpcSetForm(WINSPOOL_PRINTER_HANDLE hPrinter,WCHAR * pFormName,WINSPOOL_FORM_CONTAINER * pFormInfoContainer)114c2c66affSColin Finck _RpcSetForm(WINSPOOL_PRINTER_HANDLE hPrinter, WCHAR* pFormName, WINSPOOL_FORM_CONTAINER* pFormInfoContainer)
115c2c66affSColin Finck {
116*62c4b828SJames Tabor     DWORD dwErrorCode;
117*62c4b828SJames Tabor 
118*62c4b828SJames Tabor     dwErrorCode = RpcImpersonateClient(NULL);
119*62c4b828SJames Tabor     if (dwErrorCode != ERROR_SUCCESS)
120*62c4b828SJames Tabor     {
121*62c4b828SJames Tabor         ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
122*62c4b828SJames Tabor         return dwErrorCode;
123*62c4b828SJames Tabor     }
124*62c4b828SJames Tabor 
125*62c4b828SJames Tabor     if (!SetFormW(hPrinter, pFormName, pFormInfoContainer->Level, (PBYTE)pFormInfoContainer->FormInfo.pFormInfo1))
126*62c4b828SJames Tabor         dwErrorCode = GetLastError();
127*62c4b828SJames Tabor 
128*62c4b828SJames Tabor     RpcRevertToSelf();
129*62c4b828SJames Tabor     return dwErrorCode;
130c2c66affSColin Finck }
131