Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

620 lines
12 KiB

  1. /*++
  2. Copyright (c) 1990-1994 Microsoft Corporation
  3. All rights reserved
  4. Module Name:
  5. Client.h
  6. Abstract:
  7. Holds common winspool.drv header info
  8. Author:
  9. Environment:
  10. User Mode -Win32
  11. Revision History:
  12. --*/
  13. #include <splcom.h>
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. extern HINSTANCE hInst;
  18. extern BOOL bLoadedBySpooler;
  19. extern CRITICAL_SECTION ClientSection;
  20. extern CRITICAL_SECTION ListAccessSem;
  21. extern LPWSTR InterfaceAddress;
  22. extern LPWSTR szEnvironment;
  23. extern CRITICAL_SECTION ProcessHndlCS;
  24. extern HANDLE hSurrogateProcess;
  25. extern DWORD (*fpYReadPrinter)(HANDLE, LPBYTE, DWORD, LPDWORD, BOOL);
  26. extern DWORD (*fpYSplReadPrinter)(HANDLE, LPBYTE *, DWORD, BOOL);
  27. extern DWORD (*fpYWritePrinter)(HANDLE, LPBYTE, DWORD, LPDWORD, BOOL);
  28. extern DWORD (*fpYSeekPrinter)(HANDLE, LARGE_INTEGER, PLARGE_INTEGER, DWORD, BOOL, BOOL);
  29. extern DWORD (*fpYGetPrinterDriver2)(HANDLE, LPWSTR, DWORD, LPBYTE, DWORD, LPDWORD, DWORD, DWORD, PDWORD, PDWORD, BOOL);
  30. extern DWORD (*fpYGetPrinterDriverDirectory)(LPWSTR, LPWSTR, DWORD, LPBYTE, DWORD, LPDWORD, BOOL);
  31. extern VOID (*fpYDriverUnloadComplete)(LPWSTR);
  32. extern DWORD (*fpYFlushPrinter)(HANDLE,LPVOID,DWORD,LPDWORD,DWORD,BOOL);
  33. extern DWORD (*fpYEndDocPrinter)(HANDLE,BOOL);
  34. extern DWORD (*fpYSetPort)(LPWSTR, LPWSTR, LPPORT_CONTAINER, BOOL);
  35. extern DWORD (*fpYSetJob)(HANDLE, DWORD, LPJOB_CONTAINER, DWORD, BOOL);
  36. #define vEnterSem() EnterCriticalSection(&ClientSection)
  37. #define vLeaveSem() LeaveCriticalSection(&ClientSection)
  38. typedef int (FAR WINAPI *INT_FARPROC)();
  39. typedef struct _GENERIC_CONTAINER {
  40. DWORD Level;
  41. LPBYTE pData;
  42. } GENERIC_CONTAINER, *PGENERIC_CONTAINER, *LPGENERIC_CONTAINER ;
  43. typedef struct _SPOOL *PSPOOL;
  44. typedef struct _NOTIFY *PNOTIFY;
  45. typedef struct _NOTIFY {
  46. PNOTIFY pNext;
  47. HANDLE hEvent; // event to trigger on notification
  48. DWORD fdwFlags; // flags to watch for
  49. DWORD fdwOptions; // PRINTER_NOTIFY_*
  50. DWORD dwReturn; // used by WPC when simulating FFPCN
  51. PSPOOL pSpool;
  52. BOOL bHandleInvalid;
  53. } NOTIFY;
  54. typedef struct _SPOOL {
  55. DWORD signature;
  56. HANDLE hPrinter;
  57. HANDLE hFile;
  58. DWORD JobId;
  59. LPBYTE pBuffer;
  60. DWORD cbBuffer;
  61. DWORD Status;
  62. DWORD fdwFlags;
  63. DWORD cCacheWrite;
  64. DWORD cWritePrinters;
  65. DWORD cFlushBuffers;
  66. DWORD dwTickCount;
  67. DWORD dwCheckJobInterval;
  68. PNOTIFY pNotify;
  69. LPTSTR pszPrinter;
  70. PRINTER_DEFAULTS Default;
  71. HANDLE hSplPrinter;
  72. DWORD cActive;
  73. HANDLE hSpoolFile;
  74. DWORD dwSpoolFileAttributes;
  75. DWORD cbFlushPending;
  76. DWORD cOKFlushBuffers;
  77. DWORD Flushed;
  78. PDOCEVENT_FILTER pDoceventFilter;
  79. #ifdef DBG_TRACE_HANDLE
  80. PSPOOL pNext;
  81. PVOID apvBackTrace[32];
  82. #endif
  83. } SPOOL;
  84. #define WIN2000_SPOOLER_VERSION 3
  85. // cActive: There is a non-close call currently active on the handle.
  86. // Any ClosePrinter call should just mark SPOOL_STATUS_PENDING_DELETION
  87. // so that the handle will be closed when the other thread is one.
  88. #define BUFFER_SIZE 0x10000
  89. #define SP_SIGNATURE 0x6767
  90. #define SPOOL_STATUS_STARTDOC 0x00000001
  91. #define SPOOL_STATUS_ADDJOB 0x00000002
  92. #define SPOOL_STATUS_ANSI 0x00000004
  93. #define SPOOL_STATUS_DOCUMENTEVENT_ENABLED 0x00000008
  94. #define SPOOL_STATUS_TRAYICON_NOTIFIED 0x00000010
  95. #define SPOOL_STATUS_NO_COLORPROFILE_HOOK 0x00000020
  96. //
  97. // CLOSE: There is a close call occuring. Everything else should fail.
  98. // PENDING_DELETION: The handle should be closed as soon as any call completes.
  99. // This occurs when ClosePrinter is called but another thread is executing
  100. // a non-close call. In this case, the ClosePrinter doesn't do anything;
  101. // it just marks PENDING_DELETION and returns.
  102. //
  103. #define SPOOL_STATUS_CLOSE 0x00000040
  104. #define SPOOL_STATUS_PENDING_DELETION 0x00000080
  105. #define SPOOL_STATUS_DONT_RECYCLE_HANDLE 0x00000100
  106. #define MAX_STATIC_ALLOC 1024
  107. #define SPOOL_FLAG_FFPCN_FAILED 0x1
  108. #define SPOOL_FLAG_LAZY_CLOSE 0x2
  109. #define NULL_TERMINATED 0
  110. //
  111. // This is the resource id that is used to locate the activation context
  112. // for an image that has funsion version information.
  113. //
  114. #define ACTIVATION_CONTEXT_RESOURCE_ID 123
  115. //
  116. // SPOOL_FILE_INFO_1 trades handles in what amount to a 32 bit interface. The
  117. // central assumption here is that kernel mode handles are 32 bit values (i.e.
  118. // an offset into a table.) This isn't great, but since a 64 bit spooler will
  119. // communicate with a 32 bit client GDI, this assumption is implicite anyway.
  120. //
  121. #define SPOOL_INVALID_HANDLE_VALUE_32BIT ((HANDLE)(ULONG_PTR)0xffffffff)
  122. // Struct for storing loaded driver config file handles
  123. typedef struct _DRVLIBNODE {
  124. struct _DRVLIBNODE *pNext;
  125. LPWSTR pConfigFile;
  126. DWORD dwNumHandles;
  127. HANDLE hLib;
  128. DWORD dwVersion;
  129. BOOL bArtificialIncrement;
  130. } DRVLIBNODE, *PDRVLIBNODE;
  131. //
  132. // Struct for DocumentProperties UI monitoring
  133. //
  134. typedef struct _PUMPTHRDDATA
  135. {
  136. ULONG_PTR hWnd;
  137. LPWSTR PrinterName;
  138. PDWORD TouchedDevModeSize;
  139. PDWORD ClonedDevModeOutSize;
  140. byte** ClonedDevModeOut;
  141. DWORD DevModeInSize;
  142. byte* pDevModeInput;
  143. DWORD fMode;
  144. DWORD fExclusionFlags;
  145. PDWORD dwRet;
  146. PLONG Result;
  147. BOOL ClonedDevModeFill;
  148. } PumpThrdData;
  149. typedef struct _PRTPROPSDATA
  150. {
  151. ULONG_PTR hWnd;
  152. PDWORD dwRet;
  153. LPWSTR PrinterName;
  154. DWORD Flag;
  155. } PrtPropsData;
  156. typedef struct _PRINTERSETUPDATA
  157. {
  158. ULONG_PTR hWnd;
  159. UINT uAction;
  160. UINT cchPrinterName;
  161. UINT PrinterNameSize;
  162. LPWSTR pszPrinterName;
  163. UINT *pcchPrinterName;
  164. LPCWSTR pszServerName;
  165. }PrinterSetupData;
  166. typedef struct _KEYDATA {
  167. DWORD cb;
  168. DWORD cTokens;
  169. LPWSTR pTokens[1];
  170. } KEYDATA, *PKEYDATA;
  171. typedef enum {
  172. kProtectHandleSuccess = 0,
  173. kProtectHandleInvalid = 1,
  174. kProtectHandlePendingDeletion = 2
  175. } EProtectResult;
  176. typedef enum{
  177. RUN32BINVER = 4,
  178. RUN64BINVER = 8
  179. }ClientVersion;
  180. typedef enum{
  181. NATIVEVERSION = 0,
  182. THUNKVERSION = 1
  183. }ServerVersion;
  184. struct SJOBCANCELINFO
  185. {
  186. PSPOOL pSpool;
  187. LPBYTE pInitialBuf;
  188. PDWORD pcbWritten;
  189. PDWORD pcTotalWritten;
  190. DWORD NumOfCmpltWrts;
  191. DWORD cbFlushed;
  192. DWORD ReqTotalDataSize;
  193. DWORD FlushPendingDataSize;
  194. DWORD ReqToWriteDataSize;
  195. BOOL ReturnValue;
  196. };
  197. typedef struct SJOBCANCELINFO SJobCancelInfo, *PSJobCancelInfo;
  198. //
  199. // The list used to maintain created windows waiting on
  200. // end messages from the surrogate process
  201. //
  202. struct WNDHNDLNODE
  203. {
  204. struct WNDHNDLNODE *PrevNode;
  205. struct WNDHNDLNODE *NextNode;
  206. HWND hWnd;
  207. };
  208. typedef struct WNDHNDLNODE WndHndlNode,*LPWndHndlNode;
  209. struct WNDHNDLLIST
  210. {
  211. struct WNDHNDLNODE *Head;
  212. struct WNDHNDLNODE *Tail;
  213. DWORD NumOfHndls;
  214. };
  215. typedef struct WNDHNDLLIST WndHndlList,*LPWndHndlList;
  216. struct MONITORINGTHRDDATA
  217. {
  218. HANDLE* hProcess;
  219. HANDLE hEvent;
  220. };
  221. typedef struct MONITORINGTHRDDATA MonitorThrdData,*LPMonitorThrdData;
  222. typedef struct _MONITORUIDATA
  223. {
  224. HINSTANCE hLibrary;
  225. HANDLE hActCtx;
  226. ULONG_PTR lActCtx;
  227. PWSTR pszMonitorName;
  228. BOOL bDidActivate;
  229. } MONITORUIDATA, *PMONITORUIDATA;
  230. DWORD
  231. TranslateExceptionCode(
  232. DWORD ExceptionCode
  233. );
  234. BOOL
  235. WPCInit(
  236. VOID
  237. );
  238. VOID
  239. WPCDone(
  240. VOID
  241. );
  242. PNOTIFY
  243. WPCWaitFind(
  244. HANDLE hFind
  245. );
  246. BOOL
  247. FlushBuffer(
  248. PSPOOL pSpool,
  249. PDWORD pcbWritten
  250. );
  251. PSECURITY_DESCRIPTOR
  252. BuildInputSD(
  253. PSECURITY_DESCRIPTOR pPrinterSD,
  254. PDWORD pSizeSD
  255. );
  256. PKEYDATA
  257. CreateTokenList(
  258. LPWSTR pKeyData
  259. );
  260. LPWSTR
  261. GetPrinterPortList(
  262. HANDLE hPrinter
  263. );
  264. LPWSTR
  265. FreeUnicodeString(
  266. LPWSTR pUnicodeString
  267. );
  268. LPWSTR
  269. AllocateUnicodeString(
  270. LPSTR pPrinterName
  271. );
  272. LPWSTR
  273. StartDocDlgW(
  274. HANDLE hPrinter,
  275. DOCINFO *pDocInfo
  276. );
  277. LPSTR
  278. StartDocDlgA(
  279. HANDLE hPrinter,
  280. DOCINFOA *pDocInfo
  281. );
  282. HANDLE
  283. LoadPrinterDriver(
  284. HANDLE hPrinter
  285. );
  286. HANDLE
  287. RefCntLoadDriver(
  288. LPTSTR pConfigFile,
  289. DWORD dwFlags,
  290. DWORD dwVersion,
  291. BOOL bUseVersion
  292. );
  293. BOOL
  294. RefCntUnloadDriver(
  295. HANDLE hLib,
  296. BOOL bNotifySpooler
  297. );
  298. BOOL
  299. ForceUnloadDriver(
  300. LPTSTR pConfigFile
  301. );
  302. BOOL
  303. WriteCurDevModeToRegistry(
  304. LPWSTR pPrinterName,
  305. LPDEVMODEW pDevMode
  306. );
  307. BOOL
  308. DeleteCurDevModeFromRegistry(
  309. PWSTR pPrinterName
  310. );
  311. BOOL
  312. bValidDevModeW(
  313. const DEVMODEW *pDevModeW
  314. );
  315. BOOL
  316. bValidDevModeA(
  317. const DEVMODEA *pDevModeA
  318. );
  319. DWORD
  320. FindClosePrinterChangeNotificationWorker(
  321. IN PNOTIFY pNotify,
  322. IN HANDLE hPrinterRPC,
  323. IN BOOL bRevalidate
  324. );
  325. BOOL
  326. ScheduleJobWorker(
  327. PSPOOL pSpool,
  328. DWORD JobId
  329. );
  330. PSPOOL
  331. AllocSpool(
  332. VOID
  333. );
  334. VOID
  335. FreeSpool(
  336. PSPOOL pSpool
  337. );
  338. VOID
  339. CloseSpoolFileHandles(
  340. PSPOOL pSpool
  341. );
  342. EProtectResult
  343. eProtectHandle(
  344. IN HANDLE hPrinter,
  345. IN BOOL bClose
  346. );
  347. VOID
  348. vUnprotectHandle(
  349. IN HANDLE hPrinter
  350. );
  351. BOOL
  352. UpdatePrinterDefaults(
  353. IN OUT PSPOOL pSpool,
  354. IN LPCTSTR pszPrinter, OPTIONAL
  355. IN PPRINTER_DEFAULTS pDefault OPTIONAL
  356. );
  357. BOOL
  358. RevalidateHandle(
  359. PSPOOL pSpool
  360. );
  361. BOOL
  362. UpdateString(
  363. IN LPCTSTR pszString, OPTIONAL
  364. OUT LPTSTR* ppszOut
  365. );
  366. INT
  367. Message(
  368. HWND hwnd,
  369. DWORD Type,
  370. INT CaptionID,
  371. INT TextID,
  372. ...
  373. );
  374. DWORD
  375. ReportFailure(
  376. HWND hwndParent,
  377. DWORD idTitle,
  378. DWORD idDefaultError
  379. );
  380. BOOL
  381. InCSRProcess(
  382. VOID
  383. );
  384. INT
  385. UnicodeToAnsiString(
  386. LPWSTR pUnicode,
  387. LPSTR pAnsi,
  388. DWORD StringLength
  389. );
  390. BOOL
  391. RunInWOW64(
  392. VOID
  393. );
  394. DWORD
  395. AddHandleToList(
  396. HWND hWnd
  397. );
  398. BOOL
  399. DelHandleFromList(
  400. HWND hWnd
  401. );
  402. HRESULT
  403. GetCurrentThreadLastPopup(
  404. OUT HWND *phwnd
  405. );
  406. LPCWSTR
  407. FindFileName(
  408. IN LPCWSTR pPathName
  409. );
  410. VOID
  411. ReleaseAndCleanupWndList(
  412. VOID
  413. );
  414. LONG_PTR
  415. DocumentPropertySheets(
  416. PPROPSHEETUI_INFO pCPSUIInfo,
  417. LPARAM lParam
  418. );
  419. LONG_PTR
  420. DevicePropertySheets(
  421. PPROPSHEETUI_INFO pCPSUIInfo,
  422. LPARAM lParam
  423. );
  424. VOID
  425. vUpdateTrayIcon(
  426. IN HANDLE hPrinter,
  427. IN DWORD JobId
  428. );
  429. HRESULT
  430. SelectFormNameFromDevMode(
  431. HANDLE hPrinter,
  432. PDEVMODEW pDevModeW,
  433. LPWSTR pFormName,
  434. ULONG cchBuffer
  435. );
  436. LPWSTR
  437. IsaFileName(
  438. LPWSTR pOutputFile,
  439. LPWSTR FullPathName,
  440. DWORD cchFullPathName
  441. );
  442. PWSTR
  443. ConstructXcvName(
  444. PCWSTR pServerName,
  445. PCWSTR pObjectName,
  446. PCWSTR pObjectType
  447. );
  448. DWORD
  449. GetMonitorUI(
  450. IN PCWSTR pszMachineName,
  451. IN PCWSTR pszObjectName,
  452. IN PCWSTR pszObjectType,
  453. OUT PMONITORUI *ppMonitorUI,
  454. OUT PMONITORUIDATA *ppMonitorUIData
  455. );
  456. HRESULT
  457. CreateMonitorUIData(
  458. OUT MONITORUIDATA **ppMonitorUIData
  459. );
  460. VOID
  461. FreeMonitorUI(
  462. IN PMONITORUIDATA pMonitorUIData
  463. );
  464. HRESULT
  465. GetMonitorUIActivationContext(
  466. IN PCWSTR pszMonitorName,
  467. IN PMONITORUIDATA pMonitorUIData
  468. );
  469. HRESULT
  470. GetMonitorUIFullName(
  471. IN PCWSTR pszMonitorName,
  472. IN PWSTR *ppszMonitorName
  473. );
  474. DWORD
  475. ConnectToLd64In32ServerWorker(
  476. HANDLE *hProcess,
  477. BOOL bThread
  478. );
  479. DWORD
  480. ConnectToLd64In32Server(
  481. HANDLE *hProcess,
  482. BOOL bThread
  483. );
  484. DWORD
  485. ExternalConnectToLd64In32Server(
  486. HANDLE *hProcess
  487. );
  488. DWORD
  489. GetMonitorUIDll(
  490. PCWSTR pszMachineName,
  491. PCWSTR pszObjectName,
  492. PCWSTR pszObjectType,
  493. PWSTR *pMonitorUIDll
  494. );
  495. HWND
  496. GetForeGroundWindow(
  497. VOID
  498. );
  499. BOOL
  500. JobCanceled(
  501. PSJobCancelInfo
  502. );
  503. BOOL
  504. BuildSpoolerObjectPath(
  505. IN PCWSTR pszPath,
  506. IN PCWSTR pszName,
  507. IN PCWSTR pszEnvironment,
  508. IN DWORD Level,
  509. IN PBYTE pDriverDirectory,
  510. IN DWORD cbBuf,
  511. IN PDWORD pcbNeeded
  512. );
  513. #ifdef __cplusplus
  514. }
  515. #endif