ReactOS 0.4.16-dev-250-g3ecd236
printerdata.c File Reference
#include "precomp.h"
Include dependency graph for printerdata.c:

Go to the source code of this file.

Functions

DWORD WINAPI LocalGetPrinterData (HANDLE hPrinter, PWSTR pValueName, PDWORD pType, PBYTE pData, DWORD nSize, PDWORD pcbNeeded)
 
static DWORD _MakePrinterSubKey (PLOCAL_PRINTER_HANDLE pPrinterHandle, PCWSTR pKeyName, PWSTR *ppwszSubKey)
 
static DWORD _LocalGetPrinterHandleData (PLOCAL_PRINTER_HANDLE pPrinterHandle, PCWSTR pKeyName, PCWSTR pValueName, PDWORD pType, PBYTE pData, DWORD nSize, PDWORD pcbNeeded)
 
static DWORD _LocalGetPrintServerHandleData (PCWSTR pValueName, PDWORD pType, PBYTE pData, DWORD nSize, PDWORD pcbNeeded)
 
DWORD WINAPI LocalGetPrinterDataEx (HANDLE hPrinter, PCWSTR pKeyName, PCWSTR pValueName, PDWORD pType, PBYTE pData, DWORD nSize, PDWORD pcbNeeded)
 
DWORD WINAPI LocalSetPrinterData (HANDLE hPrinter, PWSTR pValueName, DWORD Type, PBYTE pData, DWORD cbData)
 
static DWORD _LocalSetPrinterHandleData (PLOCAL_PRINTER_HANDLE pPrinterHandle, PCWSTR pKeyName, PCWSTR pValueName, DWORD Type, PBYTE pData, DWORD cbData)
 
static DWORD _LocalSetPrintServerHandleData (PCWSTR pValueName, DWORD Type, PBYTE pData, DWORD cbData)
 
DWORD WINAPI LocalSetPrinterDataEx (HANDLE hPrinter, PCWSTR pKeyName, PCWSTR pValueName, DWORD Type, PBYTE pData, DWORD cbData)
 

Function Documentation

◆ _LocalGetPrinterHandleData()

static DWORD _LocalGetPrinterHandleData ( PLOCAL_PRINTER_HANDLE  pPrinterHandle,
PCWSTR  pKeyName,
PCWSTR  pValueName,
PDWORD  pType,
PBYTE  pData,
DWORD  nSize,
PDWORD  pcbNeeded 
)
static

Definition at line 49 of file printerdata.c.

50{
51 DWORD dwErrorCode;
52 HKEY hKey = NULL;
53 PWSTR pwszSubKey = NULL;
54
55 dwErrorCode = _MakePrinterSubKey(pPrinterHandle, pKeyName, &pwszSubKey);
56 if (dwErrorCode != ERROR_SUCCESS)
57 goto Cleanup;
58
59 // Open the subkey.
60 dwErrorCode = (DWORD)RegOpenKeyExW(hPrintersKey, pwszSubKey, 0, KEY_READ, &hKey);
61 if (dwErrorCode != ERROR_SUCCESS)
62 {
63 ERR("RegOpenKeyExW failed for \"%S\" with error %lu!\n", pwszSubKey, dwErrorCode);
64 goto Cleanup;
65 }
66
67 // Query the desired value.
69 dwErrorCode = (DWORD)RegQueryValueExW(hKey, pValueName, NULL, pType, pData, pcbNeeded);
70
72 if (hKey)
74
75 if (pwszSubKey)
76 DllFreeSplMem(pwszSubKey);
77
78 return dwErrorCode;
79}
#define ERR(fmt,...)
Definition: precomp.h:57
#define RegCloseKey(hKey)
Definition: registry.h:49
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
static const WCHAR Cleanup[]
Definition: register.c:80
unsigned long DWORD
Definition: ntddk_ex.h:95
FxAutoRegKey hKey
#define KEY_READ
Definition: nt_native.h:1023
#define DWORD
Definition: nt_native.h:44
static DWORD _MakePrinterSubKey(PLOCAL_PRINTER_HANDLE pPrinterHandle, PCWSTR pKeyName, PWSTR *ppwszSubKey)
Definition: printerdata.c:22
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1830
uint16_t * PWSTR
Definition: typedefs.h:56
BOOL WINAPI DllFreeSplMem(PVOID pMem)
Definition: memory.c:112
HKEY hPrintersKey
Definition: main.c:12
*nSize LPSTR _Inout_ LPDWORD nSize
Definition: winbase.h:2109
_In_ DWORD _Out_ PDWORD pcbNeeded
Definition: winddi.h:3828

Referenced by LocalGetPrinterDataEx().

◆ _LocalGetPrintServerHandleData()

static DWORD _LocalGetPrintServerHandleData ( PCWSTR  pValueName,
PDWORD  pType,
PBYTE  pData,
DWORD  nSize,
PDWORD  pcbNeeded 
)
static

Definition at line 82 of file printerdata.c.

83{
84 DWORD dwErrorCode;
85
86 if (_wcsicmp(pValueName, SPLREG_DEFAULT_SPOOL_DIRECTORY) == 0 ||
87 _wcsicmp(pValueName, SPLREG_PORT_THREAD_PRIORITY) == 0 ||
89 _wcsicmp(pValueName, SPLREG_BEEP_ENABLED) == 0 ||
91 {
93 return (DWORD)RegQueryValueExW(hPrintersKey, pValueName, NULL, pType, pData, pcbNeeded);
94 }
95 else if (_wcsicmp(pValueName, SPLREG_PORT_THREAD_PRIORITY_DEFAULT) == 0 ||
97 {
98 // Store a DWORD value as REG_NONE.
99 *pType = REG_NONE;
100 *pcbNeeded = sizeof(DWORD);
101 if (nSize < *pcbNeeded)
102 return ERROR_MORE_DATA;
103
104 // Apparently, these values don't serve a purpose anymore.
105 *((PDWORD)pData) = 0;
106 return ERROR_SUCCESS;
107 }
108 else if (_wcsicmp(pValueName, SPLREG_NET_POPUP) == 0 ||
109 _wcsicmp(pValueName, SPLREG_RETRY_POPUP) == 0 ||
110 _wcsicmp(pValueName, SPLREG_NET_POPUP_TO_COMPUTER) == 0 ||
111 _wcsicmp(pValueName, SPLREG_EVENT_LOG) == 0 ||
112 _wcsicmp(pValueName, SPLREG_RESTART_JOB_ON_POOL_ERROR) == 0 ||
114 {
115 HKEY hKey;
116
117 dwErrorCode = (DWORD)RegOpenKeyExW(hPrintKey, L"Providers", 0, KEY_READ, &hKey);
118 if (dwErrorCode != ERROR_SUCCESS)
119 {
120 ERR("RegOpenKeyExW failed for \"Providers\" with error %lu!\n", dwErrorCode);
121 return dwErrorCode;
122 }
123
124 *pcbNeeded = nSize;
125 dwErrorCode = (DWORD)RegQueryValueExW(hKey, pValueName, NULL, pType, pData, pcbNeeded);
127 return dwErrorCode;
128 }
129 else if (_wcsicmp(pValueName, SPLREG_MAJOR_VERSION) == 0)
130 {
131 // Store a DWORD value as REG_NONE.
132 *pType = REG_NONE;
133 *pcbNeeded = sizeof(DWORD);
134 if (nSize < *pcbNeeded)
135 return ERROR_MORE_DATA;
136
137 // Apparently, these values don't serve a purpose anymore.
139 return ERROR_SUCCESS;
140 }
141 else if (_wcsicmp(pValueName, SPLREG_MINOR_VERSION) == 0)
142 {
143 // Store a DWORD value as REG_NONE.
144 *pType = REG_NONE;
145 *pcbNeeded = sizeof(DWORD);
146 if (nSize < *pcbNeeded)
147 return ERROR_MORE_DATA;
148
149 // Apparently, these values don't serve a purpose anymore.
151 return ERROR_SUCCESS;
152 }
153 else if (_wcsicmp(pValueName, SPLREG_ARCHITECTURE) == 0)
154 {
155 // Store a string as REG_NONE with the length of the environment name string.
156 *pType = REG_NONE;
158 if (nSize < *pcbNeeded)
159 return ERROR_MORE_DATA;
160
161 // Copy the environment name as the output value for SPLREG_ARCHITECTURE.
163 return ERROR_SUCCESS;
164 }
165 else if (_wcsicmp(pValueName, SPLREG_OS_VERSION) == 0)
166 {
168
169 // Store the OSVERSIONINFOW structure as REG_NONE.
170 *pType = REG_NONE;
171 *pcbNeeded = sizeof(OSVERSIONINFOW);
172 if (nSize < *pcbNeeded)
173 return ERROR_MORE_DATA;
174
175 // Return OS version information.
176 pInfo->dwOSVersionInfoSize = sizeof(OSVERSIONINFOW);
177 GetVersionExW(pInfo);
178 return ERROR_SUCCESS;
179 }
180 else if (_wcsicmp(pValueName, SPLREG_OS_VERSIONEX) == 0)
181 {
183
184 // Store the OSVERSIONINFOEXW structure as REG_NONE.
185 *pType = REG_NONE;
186 *pcbNeeded = sizeof(OSVERSIONINFOEXW);
187 if (nSize < *pcbNeeded)
188 return ERROR_MORE_DATA;
189
190 // Return extended OS version information.
191 pInfo->dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW);
193 return ERROR_SUCCESS;
194 }
195 else if (_wcsicmp(pValueName, SPLREG_DS_PRESENT) == 0)
196 {
198
199 // We want to store a REG_DWORD value.
200 *pType = REG_DWORD;
201 *pcbNeeded = sizeof(DWORD);
202 if (nSize < *pcbNeeded)
203 return ERROR_MORE_DATA;
204
205 // Get information about the domain membership of this computer.
207 if (dwErrorCode != ERROR_SUCCESS)
208 {
209 ERR("DsRoleGetPrimaryDomainInformation failed with error %lu!\n", dwErrorCode);
210 return dwErrorCode;
211 }
212
213 // Return whether this computer is a workstation or server inside a domain.
215 DsRoleFreeMemory(pInfo);
216 return ERROR_SUCCESS;
217 }
218 else if (_wcsicmp(pValueName, SPLREG_DS_PRESENT_FOR_USER) == 0)
219 {
220 DWORD cch;
221 PWSTR p;
222 WCHAR wszComputerName[MAX_COMPUTERNAME_LENGTH + 1];
223 WCHAR wszUserSam[UNLEN + 1];
224
225 // We want to store a REG_DWORD value.
226 *pType = REG_DWORD;
227 *pcbNeeded = sizeof(DWORD);
228 if (nSize < *pcbNeeded)
229 return ERROR_MORE_DATA;
230
231 // Get the local Computer Name.
233 if (!GetComputerNameW(wszComputerName, &cch))
234 {
235 dwErrorCode = GetLastError();
236 ERR("GetComputerNameW failed with error %lu!\n", dwErrorCode);
237 return dwErrorCode;
238 }
239
240 // Get the User Name in the SAM format.
241 // This could either be:
242 // COMPUTERNAME\User
243 // DOMAINNAME\User
244 cch = UNLEN + 1;
245 if (!GetUserNameExW(NameSamCompatible, wszUserSam, &cch))
246 {
247 dwErrorCode = GetLastError();
248 ERR("GetUserNameExW failed with error %lu!\n", dwErrorCode);
249 return dwErrorCode;
250 }
251
252 // Terminate the SAM-formatted User Name at the backslash.
253 p = wcschr(wszUserSam, L'\\');
254 *p = 0;
255
256 // Compare it with the Computer Name.
257 // If they differ, this User is part of a domain.
258 *((PDWORD)pData) = (wcscmp(wszUserSam, wszComputerName) != 0);
259 return ERROR_SUCCESS;
260 }
261 else if (_wcsicmp(pValueName, SPLREG_REMOTE_FAX) == 0)
262 {
263 // Store a DWORD value as REG_NONE.
264 *pType = REG_NONE;
265 *pcbNeeded = sizeof(DWORD);
266 if (nSize < *pcbNeeded)
267 return ERROR_MORE_DATA;
268
269 // TODO: We don't support any fax service yet, but let's return the same value as Windows Server 2003 here.
270 *((PDWORD)pData) = 1;
271 return ERROR_SUCCESS;
272 }
273 else if (_wcsicmp(pValueName, SPLREG_DNS_MACHINE_NAME) == 0)
274 {
275 DWORD cchDnsName = 0;
276
277 // Get the length of the fully-qualified computer DNS name.
278 GetComputerNameExW(ComputerNameDnsFullyQualified, NULL, &cchDnsName);
279 dwErrorCode = GetLastError();
280 if (dwErrorCode != ERROR_MORE_DATA)
281 {
282 ERR("GetComputerNameExW failed with error %lu!\n", dwErrorCode);
283 return dwErrorCode;
284 }
285
286 // Check if our supplied buffer is large enough.
287 *pType = REG_SZ;
288 *pcbNeeded = cchDnsName * sizeof(WCHAR);
289 if (nSize < *pcbNeeded)
290 return ERROR_MORE_DATA;
291
292 // Get the actual DNS name.
293 if (!GetComputerNameExW(ComputerNameDnsFullyQualified, (PWSTR)pData, &cchDnsName))
294 {
295 dwErrorCode = GetLastError();
296 ERR("GetComputerNameExW failed with error %lu!\n", dwErrorCode);
297 return dwErrorCode;
298 }
299
300 // Lowercase the output just like Windows does.
302 return ERROR_SUCCESS;
303 }
304 else
305 {
306 // For all other, unknown settings, we just return ERROR_INVALID_PARAMETER.
307 // That also includes SPLREG_WEBSHAREMGMT, which is supported in Windows Server 2003 according to the documentation,
308 // but is actually not!
310 }
311}
const WCHAR wszCurrentEnvironment[]
Definition: prtprocenv.h:11
BOOL WINAPI GetComputerNameExW(COMPUTER_NAME_FORMAT NameType, LPWSTR lpBuffer, LPDWORD nSize)
Definition: compname.c:216
BOOL WINAPI GetComputerNameW(LPWSTR lpBuffer, LPDWORD lpnSize)
Definition: compname.c:446
#define ERROR_MORE_DATA
Definition: dderror.h:13
#define wcschr
Definition: compat.h:17
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
BOOL WINAPI GetVersionExW(IN LPOSVERSIONINFOW lpVersionInformation)
Definition: version.c:37
@ DsRole_RoleMemberWorkstation
Definition: dsrole.h:40
@ DsRole_RoleMemberServer
Definition: dsrole.h:42
@ DsRolePrimaryDomainInfoBasic
Definition: dsrole.h:32
GLfloat GLfloat p
Definition: glext.h:8902
#define REG_SZ
Definition: layer.c:22
static DWORD DWORD void LPSTR DWORD cch
Definition: str.c:202
VOID WINAPI DsRoleFreeMemory(_In_ PVOID Buffer)
Definition: dssetup.c:82
DWORD WINAPI DsRoleGetPrimaryDomainInformation(LPCWSTR lpServer, DSROLE_PRIMARY_DOMAIN_INFO_LEVEL InfoLevel, PBYTE *Buffer)
Definition: dssetup.c:92
#define REG_NONE
Definition: nt_native.h:1492
#define L(x)
Definition: ntvdm.h:50
BYTE * PBYTE
Definition: pedump.c:66
DWORD * PDWORD
Definition: pedump.c:68
#define REG_DWORD
Definition: sdbapi.c:596
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
_CRTIMP wchar_t *__cdecl _wcslwr(_Inout_z_ wchar_t *_String)
#define UNLEN
Definition: sspi.c:28
BOOLEAN WINAPI GetUserNameExW(EXTENDED_NAME_FORMAT NameFormat, LPWSTR lpNameBuffer, PULONG nSize)
Definition: sspi.c:1079
DSROLE_MACHINE_ROLE MachineRole
Definition: dsrole.h:63
ULONG dwOSVersionInfoSize
Definition: rtltypes.h:269
ULONG dwOSVersionInfoSize
Definition: rtltypes.h:246
const DWORD dwSpoolerMajorVersion
Definition: main.c:22
HKEY hPrintKey
Definition: main.c:11
const DWORD dwSpoolerMinorVersion
Definition: main.c:23
const DWORD cbCurrentEnvironment
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define CopyMemory
Definition: winbase.h:1735
#define MAX_COMPUTERNAME_LENGTH
Definition: winbase.h:269
#define SPLREG_ALLOW_USER_MANAGEFORMS
Definition: winspool.h:1363
#define SPLREG_SCHEDULER_THREAD_PRIORITY
Definition: winspool.h:1346
#define SPLREG_RESTART_JOB_ON_POOL_ENABLED
Definition: winspool.h:1361
#define SPLREG_DS_PRESENT_FOR_USER
Definition: winspool.h:1358
#define SPLREG_DNS_MACHINE_NAME
Definition: winspool.h:1362
#define SPLREG_NET_POPUP_TO_COMPUTER
Definition: winspool.h:1350
#define SPLREG_OS_VERSIONEX
Definition: winspool.h:1356
#define SPLREG_ARCHITECTURE
Definition: winspool.h:1354
#define SPLREG_PORT_THREAD_PRIORITY
Definition: winspool.h:1344
#define SPLREG_DEFAULT_SPOOL_DIRECTORY
Definition: winspool.h:1342
#define SPLREG_EVENT_LOG
Definition: winspool.h:1351
#define SPLREG_SCHEDULER_THREAD_PRIORITY_DEFAULT
Definition: winspool.h:1345
#define SPLREG_RESTART_JOB_ON_POOL_ERROR
Definition: winspool.h:1360
#define SPLREG_REMOTE_FAX
Definition: winspool.h:1359
#define SPLREG_OS_VERSION
Definition: winspool.h:1355
#define SPLREG_MINOR_VERSION
Definition: winspool.h:1353
#define SPLREG_NET_POPUP
Definition: winspool.h:1348
#define SPLREG_PORT_THREAD_PRIORITY_DEFAULT
Definition: winspool.h:1343
#define SPLREG_MAJOR_VERSION
Definition: winspool.h:1352
#define SPLREG_BEEP_ENABLED
Definition: winspool.h:1347
#define SPLREG_DS_PRESENT
Definition: winspool.h:1357
#define SPLREG_RETRY_POPUP
Definition: winspool.h:1349
struct _OSVERSIONINFOEXW * POSVERSIONINFOEXW
struct _OSVERSIONINFOW * POSVERSIONINFOW
struct _OSVERSIONINFOW OSVERSIONINFOW
struct _OSVERSIONINFOEXW OSVERSIONINFOEXW
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by LocalGetPrinterDataEx().

◆ _LocalSetPrinterHandleData()

static DWORD _LocalSetPrinterHandleData ( PLOCAL_PRINTER_HANDLE  pPrinterHandle,
PCWSTR  pKeyName,
PCWSTR  pValueName,
DWORD  Type,
PBYTE  pData,
DWORD  cbData 
)
static

Definition at line 372 of file printerdata.c.

373{
374 DWORD dwErrorCode;
375 HKEY hKey = NULL;
376 PWSTR pwszSubKey = NULL;
377
378 dwErrorCode = _MakePrinterSubKey(pPrinterHandle, pKeyName, &pwszSubKey);
379 if (dwErrorCode != ERROR_SUCCESS)
380 goto Cleanup;
381
382 // Open the subkey.
383 dwErrorCode = (DWORD)RegOpenKeyExW(hPrintersKey, pwszSubKey, 0, KEY_SET_VALUE, &hKey);
384 if (dwErrorCode != ERROR_SUCCESS)
385 {
386 ERR("RegOpenKeyExW failed for \"%S\" with error %lu!\n", pwszSubKey, dwErrorCode);
387 goto Cleanup;
388 }
389
390 // Set the value.
391 dwErrorCode = (DWORD)RegSetValueExW(hKey, pValueName, 0, Type, pData, cbData);
392
393Cleanup:
394 if (hKey)
396
397 if (pwszSubKey)
398 DllFreeSplMem(pwszSubKey);
399
400 return dwErrorCode;
401}
Type
Definition: Type.h:7
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4882
#define KEY_SET_VALUE
Definition: nt_native.h:1017

Referenced by LocalSetPrinterDataEx().

◆ _LocalSetPrintServerHandleData()

static DWORD _LocalSetPrintServerHandleData ( PCWSTR  pValueName,
DWORD  Type,
PBYTE  pData,
DWORD  cbData 
)
static

Definition at line 404 of file printerdata.c.

405{
406 DWORD dwErrorCode;
407
408 if (_wcsicmp(pValueName, SPLREG_DEFAULT_SPOOL_DIRECTORY) == 0 ||
409 _wcsicmp(pValueName, SPLREG_PORT_THREAD_PRIORITY) == 0 ||
410 _wcsicmp(pValueName, SPLREG_SCHEDULER_THREAD_PRIORITY) == 0 ||
411 _wcsicmp(pValueName, SPLREG_BEEP_ENABLED) == 0 ||
412 _wcsicmp(pValueName, SPLREG_ALLOW_USER_MANAGEFORMS) == 0)
413 {
414 return (DWORD)RegSetValueExW(hPrintersKey, pValueName, 0, Type, pData, cbData);
415 }
416 else if (_wcsicmp(pValueName, SPLREG_NET_POPUP) == 0 ||
417 _wcsicmp(pValueName, SPLREG_RETRY_POPUP) == 0 ||
418 _wcsicmp(pValueName, SPLREG_NET_POPUP_TO_COMPUTER) == 0 ||
419 _wcsicmp(pValueName, SPLREG_EVENT_LOG) == 0 ||
420 _wcsicmp(pValueName, SPLREG_RESTART_JOB_ON_POOL_ERROR) == 0 ||
422 _wcsicmp(pValueName, L"NoRemotePrinterDrivers") == 0)
423 {
424 HKEY hKey;
425
426 dwErrorCode = (DWORD)RegOpenKeyExW(hPrintKey, L"Providers", 0, KEY_SET_VALUE, &hKey);
427 if (dwErrorCode != ERROR_SUCCESS)
428 {
429 ERR("RegOpenKeyExW failed for \"Providers\" with error %lu!\n", dwErrorCode);
430 return dwErrorCode;
431 }
432
433 dwErrorCode = (DWORD)RegSetValueExW(hKey, pValueName, 0, Type, pData, cbData);
435 return dwErrorCode;
436 }
437 else if (_wcsicmp(pValueName, SPLREG_WEBSHAREMGMT) == 0)
438 {
439 WARN("Attempting to set WebShareMgmt, which is based on IIS and therefore not supported. Returning fake success!\n");
440 return ERROR_SUCCESS;
441 }
442 else
443 {
444 // For all other, unknown settings, we just return ERROR_INVALID_PARAMETER.
446 }
447}
#define WARN(fmt,...)
Definition: precomp.h:61
#define SPLREG_WEBSHAREMGMT
Definition: winspool.h:1364

Referenced by LocalSetPrinterDataEx().

◆ _MakePrinterSubKey()

static DWORD _MakePrinterSubKey ( PLOCAL_PRINTER_HANDLE  pPrinterHandle,
PCWSTR  pKeyName,
PWSTR ppwszSubKey 
)
static

Definition at line 22 of file printerdata.c.

23{
24 const WCHAR wszBackslash[] = L"\\";
25
26 size_t cbSubKey;
27 PWSTR p;
28
29 // Sanity check
30 if (!pKeyName || !*pKeyName)
32
33 // Allocate a buffer for the subkey "PrinterName\KeyName".
34 cbSubKey = (wcslen(pPrinterHandle->pPrinter->pwszPrinterName) + 1 + wcslen(pKeyName) + 1) * sizeof(WCHAR);
35 *ppwszSubKey = DllAllocSplMem(cbSubKey);
36 if (!*ppwszSubKey)
38
39 // Concatenate the subkey.
40 p = *ppwszSubKey;
41 StringCbCopyExW(p, cbSubKey, pPrinterHandle->pPrinter->pwszPrinterName, &p, &cbSubKey, 0);
42 StringCbCopyExW(p, cbSubKey, wszBackslash, &p, &cbSubKey, 0);
43 StringCbCopyExW(p, cbSubKey, pKeyName, &p, &cbSubKey, 0);
44
45 return ERROR_SUCCESS;
46}
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
STRSAFEAPI StringCbCopyExW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc, STRSAFE_LPWSTR *ppszDestEnd, size_t *pcbRemaining, STRSAFE_DWORD dwFlags)
Definition: strsafe.h:210
PLOCAL_PRINTER pPrinter
Definition: precomp.h:171
PWSTR pwszPrinterName
Definition: precomp.h:119
PVOID WINAPI DllAllocSplMem(DWORD dwBytes)
Definition: memory.c:95

Referenced by _LocalGetPrinterHandleData(), and _LocalSetPrinterHandleData().

◆ LocalGetPrinterData()

DWORD WINAPI LocalGetPrinterData ( HANDLE  hPrinter,
PWSTR  pValueName,
PDWORD  pType,
PBYTE  pData,
DWORD  nSize,
PDWORD  pcbNeeded 
)

Definition at line 11 of file printerdata.c.

12{
13 TRACE("LocalGetPrinterData(%p, %S, %p, %p, %lu, %p)\n", hPrinter, pValueName, pType, pData, nSize, pcbNeeded);
14
15 // The ReactOS Printing Stack forwards all GetPrinterData calls to GetPrinterDataEx as soon as possible.
16 // This function may only be called if localspl.dll is used together with Windows Printing Stack components.
17 WARN("This function should never be called!\n");
18 return LocalGetPrinterDataEx(hPrinter, L"PrinterDriverData", pValueName, pType, pData, nSize, pcbNeeded);
19}
DWORD WINAPI LocalGetPrinterDataEx(HANDLE hPrinter, PCWSTR pKeyName, PCWSTR pValueName, PDWORD pType, PBYTE pData, DWORD nSize, PDWORD pcbNeeded)
Definition: printerdata.c:314
#define TRACE(s)
Definition: solgame.cpp:4

◆ LocalGetPrinterDataEx()

DWORD WINAPI LocalGetPrinterDataEx ( HANDLE  hPrinter,
PCWSTR  pKeyName,
PCWSTR  pValueName,
PDWORD  pType,
PBYTE  pData,
DWORD  nSize,
PDWORD  pcbNeeded 
)

Definition at line 314 of file printerdata.c.

315{
316 BYTE Temp;
317 DWORD dwErrorCode;
318 DWORD dwTemp;
319 PLOCAL_HANDLE pHandle = (PLOCAL_HANDLE)hPrinter;
320
321 TRACE("LocalGetPrinterDataEx(%p, %S, %S, %p, %p, %lu, %p)\n", hPrinter, pKeyName, pValueName, pType, pData, nSize, pcbNeeded);
322
323 // Even if GetPrinterDataExW in winspool ensures that the RPC function is never called without a valid pointer for pType,
324 // it's officially optional. Windows' fpGetPrinterDataEx also works with NULL for pType!
325 // Ensure here that it is always set to simplify the code later.
326 if (!pType)
327 pType = &dwTemp;
328
329 // pData is later fed to RegQueryValueExW in many cases. When calling it with zero buffer size, RegQueryValueExW returns a
330 // different error code based on whether pData is NULL or something else.
331 // Ensure here that ERROR_MORE_DATA is always returned.
332 if (!pData)
333 pData = &Temp;
334
335 if (!pHandle)
336 {
337 dwErrorCode = ERROR_INVALID_HANDLE;
338 }
339 else if (!pcbNeeded)
340 {
341 dwErrorCode = ERROR_INVALID_PARAMETER;
342 }
343 else if (pHandle->HandleType == HandleType_Printer)
344 {
345 dwErrorCode = _LocalGetPrinterHandleData(pHandle->pSpecificHandle, pKeyName, pValueName, pType, pData, nSize, pcbNeeded);
346 }
347 else if (pHandle->HandleType == HandleType_PrintServer)
348 {
349 dwErrorCode = _LocalGetPrintServerHandleData(pValueName, pType, pData, nSize, pcbNeeded);
350 }
351 else
352 {
353 dwErrorCode = ERROR_INVALID_HANDLE;
354 }
355
356 SetLastError(dwErrorCode);
357 return dwErrorCode;
358}
#define SetLastError(x)
Definition: compat.h:752
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
static DWORD _LocalGetPrintServerHandleData(PCWSTR pValueName, PDWORD pType, PBYTE pData, DWORD nSize, PDWORD pcbNeeded)
Definition: printerdata.c:82
static DWORD _LocalGetPrinterHandleData(PLOCAL_PRINTER_HANDLE pPrinterHandle, PCWSTR pKeyName, PCWSTR pValueName, PDWORD pType, PBYTE pData, DWORD nSize, PDWORD pcbNeeded)
Definition: printerdata.c:49
PVOID pSpecificHandle
Definition: precomp.h:208
enum _LOCAL_HANDLE::@5125 HandleType
struct _LOCAL_HANDLE * PLOCAL_HANDLE
Definition: precomp.h:56
unsigned char BYTE
Definition: xxhash.c:193

Referenced by LocalGetPrinterData().

◆ LocalSetPrinterData()

DWORD WINAPI LocalSetPrinterData ( HANDLE  hPrinter,
PWSTR  pValueName,
DWORD  Type,
PBYTE  pData,
DWORD  cbData 
)

Definition at line 361 of file printerdata.c.

362{
363 TRACE("LocalSetPrinterData(%p, %S, %lu, %p, %lu)\n", hPrinter, pValueName, Type, pData, cbData);
364
365 // The ReactOS Printing Stack forwards all SetPrinterData calls to SetPrinterDataEx as soon as possible.
366 // This function may only be called if localspl.dll is used together with Windows Printing Stack components.
367 WARN("This function should never be called!\n");
368 return LocalSetPrinterDataEx(hPrinter, L"PrinterDriverData", pValueName, Type, pData, cbData);
369}
DWORD WINAPI LocalSetPrinterDataEx(HANDLE hPrinter, PCWSTR pKeyName, PCWSTR pValueName, DWORD Type, PBYTE pData, DWORD cbData)
Definition: printerdata.c:450

◆ LocalSetPrinterDataEx()

DWORD WINAPI LocalSetPrinterDataEx ( HANDLE  hPrinter,
PCWSTR  pKeyName,
PCWSTR  pValueName,
DWORD  Type,
PBYTE  pData,
DWORD  cbData 
)

Definition at line 450 of file printerdata.c.

451{
452 DWORD dwErrorCode;
453 PLOCAL_HANDLE pHandle = (PLOCAL_HANDLE)hPrinter;
454
455 TRACE("LocalSetPrinterDataEx(%p, %S, %S, %lu, %p, %lu)\n", hPrinter, pKeyName, pValueName, Type, pData, cbData);
456
457 if (!pHandle)
458 {
459 dwErrorCode = ERROR_INVALID_HANDLE;
460 }
461 else if (pHandle->HandleType == HandleType_Printer)
462 {
463 dwErrorCode = _LocalSetPrinterHandleData(pHandle->pSpecificHandle, pKeyName, pValueName, Type, pData, cbData);
464 }
465 else if (pHandle->HandleType == HandleType_PrintServer)
466 {
467 dwErrorCode = _LocalSetPrintServerHandleData(pValueName, Type, pData, cbData);
468 }
469 else
470 {
471 dwErrorCode = ERROR_INVALID_HANDLE;
472 }
473
474 SetLastError(dwErrorCode);
475 return dwErrorCode;
476}
static DWORD _LocalSetPrinterHandleData(PLOCAL_PRINTER_HANDLE pPrinterHandle, PCWSTR pKeyName, PCWSTR pValueName, DWORD Type, PBYTE pData, DWORD cbData)
Definition: printerdata.c:372
static DWORD _LocalSetPrintServerHandleData(PCWSTR pValueName, DWORD Type, PBYTE pData, DWORD cbData)
Definition: printerdata.c:404

Referenced by LocalSetPrinterData().