ReactOS 0.4.15-dev-8100-g1887773
main.c File Reference
#include "precomp.h"
#include <prtprocenv.h>
Include dependency graph for main.c:

Go to the source code of this file.

Functions

static BOOL _InitializeLocalSpooler (void)
 
BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
 
BOOL WINAPI InitializePrintProvidor (LPPRINTPROVIDOR pPrintProvidor, DWORD cbPrintProvidor, LPWSTR pFullRegistryPath)
 

Variables

HKEY hPrintKey = NULL
 
HKEY hPrintersKey = NULL
 
WCHAR wszJobDirectory [MAX_PATH]
 
DWORD cchJobDirectory
 
WCHAR wszSpoolDirectory [MAX_PATH]
 
DWORD cchSpoolDirectory
 
const DWORD dwSpoolerMajorVersion = 3
 
const DWORD dwSpoolerMinorVersion = 0
 
const WCHAR wszDefaultDocumentName [] = L"Local Downlevel Document"
 
PCWSTR wszPrintProviderInfo [3]
 
static const PRINTPROVIDOR _PrintProviderFunctions
 

Function Documentation

◆ _InitializeLocalSpooler()

static BOOL _InitializeLocalSpooler ( void  )
static

Definition at line 124 of file main.c.

125{
126 const WCHAR wszPrintersPath[] = L"\\PRINTERS";
127 const DWORD cchPrintersPath = _countof(wszPrintersPath) - 1;
128 const WCHAR wszSpoolPath[] = L"\\spool";
129 const DWORD cchSpoolPath = _countof(wszSpoolPath) - 1;
130 const WCHAR wszSymbolicLinkValue[] = L"\\REGISTRY\\MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Print\\Printers";
131 const DWORD cbSymbolicLinkValue = sizeof(wszSymbolicLinkValue) - sizeof(WCHAR);
132
133 BOOL bReturnValue = FALSE;
134 DWORD cbData;
135 DWORD dwErrorCode;
136 HKEY hKey = NULL;
137
138 // On startup, always create a volatile symbolic link in the registry if it doesn't exist yet.
139 // "SYSTEM\CurrentControlSet\Control\Print\Printers" -> "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers"
140 //
141 // According to https://social.technet.microsoft.com/Forums/windowsserver/en-US/a683ab54-c43c-4ebe-af8f-1f7a65af2a51
142 // this is needed when having >900 printers to work around a size limit of the SYSTEM registry hive.
143 dwErrorCode = (DWORD)RegCreateKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\Print\\Printers", 0, NULL, REG_OPTION_VOLATILE | REG_OPTION_CREATE_LINK, KEY_CREATE_LINK | KEY_SET_VALUE, NULL, &hKey, NULL);
144 if (dwErrorCode == ERROR_SUCCESS)
145 {
146 // Note that wszSymbolicLink has to be stored WITHOUT the terminating null character for the symbolic link to work!
147 // See cbSymbolicLinkValue above.
148 dwErrorCode = (DWORD)RegSetValueExW(hKey, L"SymbolicLinkValue", 0, REG_LINK, (PBYTE)wszSymbolicLinkValue, cbSymbolicLinkValue);
149 if (dwErrorCode != ERROR_SUCCESS)
150 {
151 ERR("RegSetValueExW failed for the Printers symlink with error %lu!\n", dwErrorCode);
152 goto Cleanup;
153 }
154 }
155 else if (dwErrorCode != ERROR_ALREADY_EXISTS)
156 {
157 ERR("RegCreateKeyExW failed for the Printers symlink with error %lu!\n", dwErrorCode);
158 goto Cleanup;
159 }
160
161 // Open some registry keys and leave them open. We need them multiple times throughout the Local Spooler.
162 dwErrorCode = (DWORD)RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\Print", 0, KEY_ALL_ACCESS, &hPrintKey);
163 if (dwErrorCode != ERROR_SUCCESS)
164 {
165 ERR("RegOpenKeyExW failed for \"Print\" with error %lu!\n", dwErrorCode);
166 goto Cleanup;
167 }
168
169 dwErrorCode = (DWORD)RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Print\\Printers", 0, KEY_ALL_ACCESS, &hPrintersKey);
170 if (dwErrorCode != ERROR_SUCCESS)
171 {
172 ERR("RegOpenKeyExW failed for \"Printers\" with error %lu!\n", dwErrorCode);
173 goto Cleanup;
174 }
175
176 // Construct the path to "%SystemRoot%\system32\spool".
177 // Forget about length checks here. If this doesn't fit into MAX_PATH, our OS has more serious problems...
179 CopyMemory(&wszSpoolDirectory[cchSpoolDirectory], wszSpoolPath, (cchSpoolPath + 1) * sizeof(WCHAR));
180 cchSpoolDirectory += cchSpoolPath;
181
182 // Query the job directory.
183 cbData = sizeof(wszJobDirectory);
185 if (dwErrorCode == ERROR_SUCCESS)
186 {
187 cchJobDirectory = cbData / sizeof(WCHAR) - 1;
188 }
189 else if (dwErrorCode == ERROR_FILE_NOT_FOUND)
190 {
191 // Use the default "%SystemRoot%\system32\spool\PRINTERS".
193 CopyMemory(&wszJobDirectory[cchSpoolDirectory], wszPrintersPath, (cchPrintersPath + 1) * sizeof(WCHAR));
194 cchJobDirectory = cchSpoolDirectory + cchPrintersPath;
195
196 // Save this for next time.
198 }
199 else
200 {
201 ERR("RegQueryValueExW failed for \"%S\" with error %lu!\n", SPLREG_DEFAULT_SPOOL_DIRECTORY, dwErrorCode);
202 goto Cleanup;
203 }
204
205 // Initialize all lists.
207 goto Cleanup;
208
209 if (!InitializePortList())
210 goto Cleanup;
211
213 goto Cleanup;
214
216 goto Cleanup;
217
219 goto Cleanup;
220
221 if (!InitializeFormList())
222 goto Cleanup;
223
225 goto Cleanup;
226
227 // Local Spooler Initialization finished successfully!
228 bReturnValue = TRUE;
229
230Cleanup:
231 if (hKey)
233
234 return bReturnValue;
235}
#define ERR(fmt,...)
Definition: debug.h:113
#define RegCloseKey(hKey)
Definition: registry.h:49
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
LONG WINAPI RegCreateKeyExW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey, _In_ DWORD Reserved, _In_opt_ LPWSTR lpClass, _In_ DWORD dwOptions, _In_ REGSAM samDesired, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Out_ PHKEY phkResult, _Out_opt_ LPDWORD lpdwDisposition)
Definition: reg.c:1096
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
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
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
#define MAX_PATH
Definition: compat.h:34
UINT WINAPI GetSystemDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2313
static const WCHAR Cleanup[]
Definition: register.c:80
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
FxAutoRegKey hKey
#define REG_SZ
Definition: layer.c:22
#define ERROR_ALREADY_EXISTS
Definition: disk.h:80
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
#define REG_OPTION_CREATE_LINK
Definition: nt_native.h:1063
#define REG_LINK
Definition: nt_native.h:1500
#define DWORD
Definition: nt_native.h:44
#define KEY_CREATE_LINK
Definition: nt_native.h:1021
#define REG_OPTION_VOLATILE
Definition: nt_native.h:1060
#define KEY_SET_VALUE
Definition: nt_native.h:1017
#define L(x)
Definition: ntvdm.h:50
BYTE * PBYTE
Definition: pedump.c:66
BOOL InitializeFormList(VOID)
Definition: forms.c:228
BOOL InitializeGlobalJobList(void)
Definition: jobs.c:161
BOOL InitializePrintMonitorList(void)
Definition: monitors.c:126
#define _countof(array)
Definition: sndvol32.h:70
DWORD cchJobDirectory
Definition: main.c:14
WCHAR wszJobDirectory[MAX_PATH]
Definition: main.c:13
HKEY hPrintKey
Definition: main.c:11
HKEY hPrintersKey
Definition: main.c:12
DWORD cchSpoolDirectory
Definition: main.c:16
WCHAR wszSpoolDirectory[MAX_PATH]
Definition: main.c:15
BOOL InitializePortList(void)
Definition: ports.c:60
BOOL InitializePrintProcessorList(void)
BOOL InitializePrinterList(void)
Definition: printers.c:107
BOOL InitializePrinterDrivers(VOID)
#define CopyMemory
Definition: winbase.h:1710
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define SPLREG_DEFAULT_SPOOL_DIRECTORY
Definition: winspool.h:1342
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by DllMain().

◆ DllMain()

BOOL WINAPI DllMain ( HINSTANCE  hinstDLL,
DWORD  fdwReason,
LPVOID  lpvReserved 
)

Definition at line 238 of file main.c.

239{
240 switch (fdwReason)
241 {
245
246 default:
247 return TRUE;
248 }
249}
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
static BOOL _InitializeLocalSpooler(void)
Definition: main.c:124

◆ InitializePrintProvidor()

BOOL WINAPI InitializePrintProvidor ( LPPRINTPROVIDOR  pPrintProvidor,
DWORD  cbPrintProvidor,
LPWSTR  pFullRegistryPath 
)

Definition at line 252 of file main.c.

253{
254 TRACE("InitializePrintProvidor(%p, %lu, %S)\n", pPrintProvidor, cbPrintProvidor, pFullRegistryPath);
255
256 CopyMemory(pPrintProvidor, &_PrintProviderFunctions, min(cbPrintProvidor, sizeof(PRINTPROVIDOR)));
257
259 return TRUE;
260}
#define SetLastError(x)
Definition: compat.h:752
#define min(a, b)
Definition: monoChain.cc:55
#define TRACE(s)
Definition: solgame.cpp:4
static const PRINTPROVIDOR _PrintProviderFunctions
Definition: main.c:34

Variable Documentation

◆ _PrintProviderFunctions

const PRINTPROVIDOR _PrintProviderFunctions
static

Definition at line 34 of file main.c.

Referenced by InitializePrintProvidor().

◆ cchJobDirectory

DWORD cchJobDirectory

Definition at line 14 of file main.c.

Referenced by _InitializeLocalSpooler(), GetJobFilePath(), and InitializeGlobalJobList().

◆ cchSpoolDirectory

DWORD cchSpoolDirectory

Definition at line 16 of file main.c.

Referenced by _InitializeLocalSpooler(), and LocalGetPrintProcessorDirectory().

◆ dwSpoolerMajorVersion

const DWORD dwSpoolerMajorVersion = 3

This is what the Spooler of Windows Server 2003 returns (for example using GetPrinterDataExW, SPLREG_MAJOR_VERSION/SPLREG_MINOR_VERSION)

Definition at line 22 of file main.c.

Referenced by _LocalGetPrintServerHandleData().

◆ dwSpoolerMinorVersion

const DWORD dwSpoolerMinorVersion = 0

Definition at line 23 of file main.c.

Referenced by _LocalGetPrintServerHandleData().

◆ hPrintersKey

◆ hPrintKey

◆ wszDefaultDocumentName

const WCHAR wszDefaultDocumentName[] = L"Local Downlevel Document"

Definition at line 25 of file main.c.

Referenced by CreateJob().

◆ wszJobDirectory

WCHAR wszJobDirectory[MAX_PATH]

Definition at line 13 of file main.c.

Referenced by _InitializeLocalSpooler(), GetJobFilePath(), and InitializeGlobalJobList().

◆ wszPrintProviderInfo

PCWSTR wszPrintProviderInfo[3]
Initial value:
= {
L"Windows NT Local Print Providor",
L"Locally connected Printers",
L"Windows NT Local Printers"
}

Definition at line 27 of file main.c.

Referenced by _DumpLevel1PrintProviderInformation(), _LocalEnumPrintersCheckName(), _LocalGetPrinterDriverLevel6(), and _LocalGetPrinterDriverLevel8().

◆ wszSpoolDirectory

WCHAR wszSpoolDirectory[MAX_PATH]

Definition at line 15 of file main.c.

Referenced by _InitializeLocalSpooler(), and LocalGetPrintProcessorDirectory().