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.

573 lines
9.6 KiB

  1. /*++
  2. Copyright (c) 1990-1994 Microsoft Corporation
  3. All rights reserved
  4. Module Name:
  5. Change.c
  6. Abstract:
  7. Handles new WaitForPrinterChange implementation and:
  8. FindFirstPrinterChangeNotification (client and remote)
  9. FindNextPrinterChangeNotification
  10. FindClosePrinterChangeNotification
  11. ReplyOpenPrinter
  12. ReplyClosePrinter
  13. RouterReplyPrinter{Ex}
  14. RefreshPrinterChangeNotification
  15. Author:
  16. Albert Ting (AlbertT) 18-Jan-94
  17. Environment:
  18. User Mode -Win32
  19. Revision History:
  20. --*/
  21. #include "precomp.h"
  22. #include "server.h"
  23. #include "winspl.h"
  24. BOOL
  25. RouterFindFirstPrinterChangeNotification(
  26. HANDLE hPrinter,
  27. DWORD fdwFlags,
  28. DWORD fdwOptions,
  29. DWORD dwPID,
  30. PPRINTER_NOTIFY_OPTIONS pPrinterNotifyOptions,
  31. PHANDLE phEvent);
  32. BOOL
  33. RemoteFindFirstPrinterChangeNotification(
  34. HANDLE hPrinter,
  35. DWORD fdwFlags,
  36. DWORD fdwOptions,
  37. LPWSTR pszLocalMachine,
  38. DWORD dwPrinterRemote,
  39. PPRINTER_NOTIFY_OPTIONS pPrinterNotifyOptions);
  40. BOOL
  41. RouterFindNextPrinterChangeNotification(
  42. HANDLE hPrinter,
  43. DWORD fdwFlags,
  44. LPDWORD pfdwChange,
  45. PVOID pPrinterNotifyRefresh,
  46. PVOID* ppPrinterNotifyInfo);
  47. BOOL
  48. RouterReplyPrinter(
  49. HANDLE hNotify,
  50. DWORD dwColor,
  51. DWORD fdwFlags,
  52. PDWORD pdwResult,
  53. DWORD dwType,
  54. PVOID pBuffer);
  55. BOOL
  56. RouterRefreshPrinterChangeNotification(
  57. HANDLE hPrinter,
  58. DWORD dwColor,
  59. PVOID pPrinterNotifyRefresh,
  60. PPRINTER_NOTIFY_INFO* ppInfo);
  61. BOOL
  62. ReplyOpenPrinter(
  63. DWORD dwPrinterRemote,
  64. PHANDLE phNotify,
  65. DWORD dwType,
  66. DWORD cbBuffer,
  67. LPBYTE pBuffer);
  68. BOOL
  69. ReplyClosePrinter(
  70. HANDLE hNotify);
  71. DWORD
  72. RpcRouterFindFirstPrinterChangeNotificationOld(
  73. HANDLE hPrinter,
  74. DWORD fdwFlags,
  75. DWORD fdwOptions,
  76. LPWSTR pszLocalMachine,
  77. DWORD dwPrinterLocal)
  78. /*++
  79. Routine Description:
  80. This call is only used by beta2 daytona, but we can't remove it
  81. since this will allow beta2 to crash daytona. (Someday, when
  82. beta2 is long gone, we can reuse this slot for something else.)
  83. Arguments:
  84. Return Value:
  85. --*/
  86. {
  87. return ERROR_INVALID_FUNCTION;
  88. }
  89. //
  90. // Old version for Daytona.
  91. //
  92. DWORD
  93. RpcRemoteFindFirstPrinterChangeNotification(
  94. HANDLE hPrinter,
  95. DWORD fdwFlags,
  96. DWORD fdwOptions,
  97. LPWSTR pszLocalMachine,
  98. DWORD dwPrinterLocal,
  99. DWORD cbBuffer,
  100. LPBYTE pBuffer)
  101. /*++
  102. Routine Description:
  103. Arguments:
  104. Return Value:
  105. --*/
  106. {
  107. BOOL bRet;
  108. RPC_STATUS Status;
  109. if ((Status = RpcImpersonateClient(NULL)) != RPC_S_OK)
  110. {
  111. SetLastError(Status);
  112. return FALSE;
  113. }
  114. bRet = RemoteFindFirstPrinterChangeNotification(hPrinter,
  115. fdwFlags,
  116. fdwOptions,
  117. pszLocalMachine,
  118. dwPrinterLocal,
  119. NULL);
  120. RpcRevertToSelf();
  121. if (bRet)
  122. return FALSE;
  123. else
  124. return GetLastError();
  125. }
  126. DWORD
  127. RpcRemoteFindFirstPrinterChangeNotificationEx(
  128. HANDLE hPrinter,
  129. DWORD fdwFlags,
  130. DWORD fdwOptions,
  131. LPWSTR pszLocalMachine,
  132. DWORD dwPrinterLocal,
  133. PRPC_V2_NOTIFY_OPTIONS pRpcV2NotifyOptions)
  134. /*++
  135. Routine Description:
  136. Arguments:
  137. Return Value:
  138. --*/
  139. {
  140. BOOL bRet;
  141. RPC_STATUS Status;
  142. if ((Status = RpcImpersonateClient(NULL)) != RPC_S_OK)
  143. {
  144. SetLastError(Status);
  145. return FALSE;
  146. }
  147. bRet = RemoteFindFirstPrinterChangeNotification(
  148. hPrinter,
  149. fdwFlags,
  150. fdwOptions,
  151. pszLocalMachine,
  152. dwPrinterLocal,
  153. (PPRINTER_NOTIFY_OPTIONS)pRpcV2NotifyOptions);
  154. RpcRevertToSelf();
  155. if (bRet)
  156. return FALSE;
  157. else
  158. return GetLastError();
  159. }
  160. DWORD
  161. RpcClientFindFirstPrinterChangeNotification(
  162. HANDLE hPrinter,
  163. DWORD fdwFlags,
  164. DWORD fdwOptions,
  165. DWORD dwPID,
  166. PRPC_V2_NOTIFY_OPTIONS pRpcV2NotifyOptions,
  167. LPDWORD pdwEvent)
  168. /*++
  169. Routine Description:
  170. Arguments:
  171. Return Value:
  172. --*/
  173. {
  174. BOOL bRet;
  175. RPC_STATUS Status;
  176. HANDLE hEvent = NULL;
  177. if ((Status = RpcImpersonateClient(NULL)) != RPC_S_OK)
  178. {
  179. SetLastError(Status);
  180. return FALSE;
  181. }
  182. bRet = RouterFindFirstPrinterChangeNotification(
  183. hPrinter,
  184. fdwFlags,
  185. fdwOptions,
  186. dwPID,
  187. (PPRINTER_NOTIFY_OPTIONS)pRpcV2NotifyOptions,
  188. &hEvent);
  189. if (pdwEvent && hEvent)
  190. {
  191. *pdwEvent = HandleToLong (hEvent);
  192. }
  193. RpcRevertToSelf();
  194. if (bRet)
  195. return FALSE;
  196. else
  197. return GetLastError();
  198. }
  199. DWORD
  200. RpcFindNextPrinterChangeNotification(
  201. HANDLE hPrinter,
  202. DWORD fdwFlags,
  203. LPDWORD pfdwChange,
  204. PRPC_V2_NOTIFY_OPTIONS pRpcV2NotifyOptions,
  205. PRPC_V2_NOTIFY_INFO* ppInfo)
  206. /*++
  207. Routine Description:
  208. Arguments:
  209. Return Value:
  210. --*/
  211. {
  212. BOOL bRet;
  213. RPC_STATUS Status;
  214. if ((Status = RpcImpersonateClient(NULL)) != RPC_S_OK)
  215. {
  216. SetLastError(Status);
  217. return FALSE;
  218. }
  219. bRet = RouterFindNextPrinterChangeNotification(
  220. hPrinter,
  221. fdwFlags,
  222. pfdwChange,
  223. pRpcV2NotifyOptions,
  224. ppInfo);
  225. RpcRevertToSelf();
  226. if (bRet)
  227. return FALSE;
  228. else
  229. return GetLastError();
  230. }
  231. DWORD
  232. RpcFindClosePrinterChangeNotification(
  233. HANDLE hPrinter)
  234. /*++
  235. Routine Description:
  236. Arguments:
  237. Return Value:
  238. --*/
  239. {
  240. BOOL bRet;
  241. RPC_STATUS Status;
  242. if ((Status = RpcImpersonateClient(NULL)) != RPC_S_OK)
  243. {
  244. SetLastError(Status);
  245. return FALSE;
  246. }
  247. bRet = FindClosePrinterChangeNotification(hPrinter);
  248. RpcRevertToSelf();
  249. if (bRet)
  250. return FALSE;
  251. else
  252. return GetLastError();
  253. }
  254. DWORD
  255. RpcReplyOpenPrinter(
  256. LPWSTR pszLocalMachine,
  257. PHANDLE phNotify,
  258. DWORD dwPrinterRemote,
  259. DWORD dwType,
  260. DWORD cbBuffer,
  261. LPBYTE pBuffer)
  262. /*++
  263. Routine Description:
  264. Arguments:
  265. Return Value:
  266. --*/
  267. {
  268. BOOL bRet;
  269. RPC_STATUS Status;
  270. if ((Status = RpcImpersonateClient(NULL)) != RPC_S_OK)
  271. {
  272. SetLastError(Status);
  273. return FALSE;
  274. }
  275. bRet = ReplyOpenPrinter(dwPrinterRemote,
  276. phNotify,
  277. dwType,
  278. cbBuffer,
  279. pBuffer);
  280. RpcRevertToSelf();
  281. if (bRet)
  282. return FALSE;
  283. else
  284. return GetLastError();
  285. }
  286. DWORD
  287. RpcReplyClosePrinter(
  288. PHANDLE phNotify)
  289. /*++
  290. Routine Description:
  291. Arguments:
  292. Return Value:
  293. --*/
  294. {
  295. BOOL bRet;
  296. RPC_STATUS Status;
  297. if ((Status = RpcImpersonateClient(NULL)) != RPC_S_OK)
  298. {
  299. SetLastError(Status);
  300. return FALSE;
  301. }
  302. bRet = ReplyClosePrinter(*phNotify);
  303. RpcRevertToSelf();
  304. if (bRet) {
  305. *phNotify = NULL;
  306. return ERROR_SUCCESS;
  307. }
  308. else
  309. return GetLastError();
  310. }
  311. DWORD
  312. RpcRouterReplyPrinter(
  313. HANDLE hNotify,
  314. DWORD fdwFlags,
  315. DWORD cbBuffer,
  316. LPBYTE pBuffer)
  317. /*++
  318. Routine Description:
  319. Arguments:
  320. Return Value:
  321. --*/
  322. {
  323. BOOL bRet;
  324. RPC_STATUS Status;
  325. if ((Status = RpcImpersonateClient(NULL)) != RPC_S_OK)
  326. {
  327. SetLastError(Status);
  328. return FALSE;
  329. }
  330. bRet = RouterReplyPrinter(hNotify,
  331. 0,
  332. fdwFlags,
  333. NULL,
  334. 0,
  335. NULL);
  336. RpcRevertToSelf();
  337. if (bRet)
  338. return FALSE;
  339. else
  340. return GetLastError();
  341. }
  342. DWORD
  343. RpcRouterReplyPrinterEx(
  344. HANDLE hNotify,
  345. DWORD dwColor,
  346. DWORD fdwFlags,
  347. PDWORD pdwResult,
  348. DWORD dwReplyType,
  349. RPC_V2_UREPLY_PRINTER Reply)
  350. /*++
  351. Routine Description:
  352. Arguments:
  353. Return Value:
  354. --*/
  355. {
  356. BOOL bRet;
  357. RPC_STATUS Status;
  358. if ((Status = RpcImpersonateClient(NULL)) != RPC_S_OK)
  359. {
  360. SetLastError(Status);
  361. return FALSE;
  362. }
  363. bRet = RouterReplyPrinter(hNotify,
  364. dwColor,
  365. fdwFlags,
  366. pdwResult,
  367. dwReplyType,
  368. Reply.pInfo);
  369. RpcRevertToSelf();
  370. if (bRet)
  371. return FALSE;
  372. else
  373. return GetLastError();
  374. }
  375. DWORD
  376. RpcRouterRefreshPrinterChangeNotification(
  377. HANDLE hPrinter,
  378. DWORD dwColor,
  379. PRPC_V2_NOTIFY_OPTIONS pRpcV2NotifyOptions,
  380. PRPC_V2_NOTIFY_INFO* ppInfo)
  381. /*++
  382. Routine Description:
  383. Updates info.
  384. Arguments:
  385. Return Value:
  386. --*/
  387. {
  388. BOOL bRet;
  389. RPC_STATUS Status;
  390. if ((Status = RpcImpersonateClient(NULL)) != RPC_S_OK)
  391. {
  392. SetLastError(Status);
  393. return FALSE;
  394. }
  395. bRet = RouterRefreshPrinterChangeNotification(
  396. hPrinter,
  397. dwColor,
  398. (PPRINTER_NOTIFY_OPTIONS)pRpcV2NotifyOptions,
  399. (PPRINTER_NOTIFY_INFO*)ppInfo);
  400. RpcRevertToSelf();
  401. if (bRet)
  402. return FALSE;
  403. else
  404. return GetLastError();
  405. }