Source code of Windows XP (NT5)
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.

396 lines
9.5 KiB

  1. /*****************************************************************************\
  2. * MODULE: xcv.cxx
  3. *
  4. * The module contains routines for handling the authentication dialog
  5. * for internet priting
  6. *
  7. * Copyright (C) 2000 Microsoft Corporation
  8. *
  9. * History:
  10. * 03/31/00 WeihaiC Created
  11. *
  12. \*****************************************************************************/
  13. #include "precomp.h"
  14. #ifdef WINNT32
  15. #include "priv.h"
  16. #define SZINETPPUI L"InetppUI.dll"
  17. XCV_METHOD gpXcvMethod[] = {
  18. {L"MonitorUI", GetMonitorUI},
  19. {L"AddPort", DoAddPort},
  20. {INET_XCV_DELETE_PORT, DoDeletePort},
  21. {INET_XCV_GET_CONFIGURATION, DoGetConfiguration},
  22. {INET_XCV_SET_CONFIGURATION, DoSetConfiguration},
  23. {NULL, NULL}
  24. };
  25. BOOL
  26. bIsAdmin ()
  27. {
  28. PRINTER_DEFAULTS pd = {NULL, NULL, SERVER_ALL_ACCESS};
  29. HANDLE hServer;
  30. BOOL bRet = FALSE;
  31. if (OpenPrinter (NULL, &hServer, &pd)) {
  32. bRet = TRUE;
  33. ClosePrinter (hServer);
  34. }
  35. return bRet;
  36. }
  37. DWORD
  38. XcvDataPort(
  39. PCINETMONPORT pPort,
  40. LPCWSTR pszDataName,
  41. PBYTE pInputData,
  42. DWORD cbInputData,
  43. PBYTE pOutputData,
  44. DWORD cbOutputData,
  45. PDWORD pcbOutputNeeded
  46. )
  47. {
  48. DWORD dwRet;
  49. DWORD i;
  50. for(i = 0 ; gpXcvMethod[i].pszMethod &&
  51. wcscmp(gpXcvMethod[i].pszMethod, pszDataName) ; ++i)
  52. ;
  53. if (gpXcvMethod[i].pszMethod) {
  54. dwRet = (*gpXcvMethod[i].pfn)( pInputData,
  55. cbInputData,
  56. pOutputData,
  57. cbOutputData,
  58. pcbOutputNeeded,
  59. pPort);
  60. } else {
  61. dwRet = ERROR_INVALID_PARAMETER;
  62. }
  63. return dwRet;
  64. }
  65. BOOL
  66. PPXcvData(
  67. HANDLE hXcv,
  68. LPCWSTR pszDataName,
  69. PBYTE pInputData,
  70. DWORD cbInputData,
  71. PBYTE pOutputData,
  72. DWORD cbOutputData,
  73. PDWORD pcbOutputNeeded,
  74. PDWORD pdwStatus)
  75. {
  76. HANDLE hPort;
  77. LPTSTR pszPortName;
  78. //
  79. // Valid input parameters
  80. //
  81. if (!pszDataName || IsBadStringPtr (pszDataName, MAX_INET_XCV_NAME_LEN) ||
  82. IsBadWritePtr (pdwStatus, sizeof (DWORD))) {
  83. return ERROR_INVALID_PARAMETER;
  84. }
  85. DBG_MSG(DBG_LEV_CALLTREE, (TEXT("Call: PPXcvData: Name(%s)"), pszDataName));
  86. semEnterCrit();
  87. if (pszPortName = utlValidateXcvPrinterHandle(hXcv)) {
  88. if (hPort = gpInetMon->InetmonFindPort (pszPortName)) {
  89. *pdwStatus = XcvDataPort((PCINETMONPORT) hPort, pszDataName, pInputData, cbInputData,
  90. pOutputData, cbOutputData, pcbOutputNeeded);
  91. }
  92. else {
  93. //
  94. // The port may not exit or have been deleted.
  95. //
  96. *pdwStatus = ERROR_NOT_FOUND;
  97. }
  98. }
  99. else
  100. *pdwStatus = ERROR_INVALID_HANDLE;
  101. semLeaveCrit();
  102. DBG_MSG(DBG_LEV_CALLTREE, (TEXT("Call: PPXcvData : Return Value(%d), LastError(%d)"), *pdwStatus, GetLastError()));
  103. return TRUE;
  104. }
  105. DWORD ValidateInputParameters (
  106. PBYTE pInputData,
  107. DWORD cbInputData,
  108. PBYTE pOutputData,
  109. DWORD cbOutputData,
  110. PDWORD pcbOutputNeeded,
  111. CONST DWORD cdwInputDataRequired,
  112. CONST DWORD cdwOutputDataRequired)
  113. {
  114. if (!pInputData || !pcbOutputNeeded ||
  115. (cdwInputDataRequired > 0 && cbInputData != cdwInputDataRequired) ||
  116. IsBadReadPtr (pInputData, cbInputData) ||
  117. (pOutputData && cbOutputData && IsBadWritePtr (pOutputData, cbOutputData)) ||
  118. (pcbOutputNeeded && IsBadWritePtr (pcbOutputNeeded, sizeof (DWORD)))) {
  119. return ERROR_INVALID_PARAMETER;
  120. }
  121. if (cbOutputData < cdwOutputDataRequired) {
  122. *pcbOutputNeeded = cdwOutputDataRequired;
  123. return ERROR_INSUFFICIENT_BUFFER;
  124. }
  125. return ERROR_SUCCESS;
  126. }
  127. DWORD
  128. DoGetConfiguration(
  129. PBYTE pInputData,
  130. DWORD cbInputData,
  131. PBYTE pOutputData,
  132. DWORD cbOutputData,
  133. PDWORD pcbOutputNeeded,
  134. PCINETMONPORT pPort
  135. )
  136. {
  137. PINET_XCV_GETCONFIGURATION_REQ_DATA pReqData = (PINET_XCV_GETCONFIGURATION_REQ_DATA) pInputData;
  138. PBYTE pEncryptedData = NULL;
  139. DWORD dwEncryptedDataSize;
  140. DWORD dwRet;
  141. //
  142. // Valid input parameters
  143. //
  144. dwRet = ValidateInputParameters (pInputData,
  145. cbInputData,
  146. pOutputData,
  147. cbOutputData,
  148. pcbOutputNeeded,
  149. sizeof (INET_XCV_GETCONFIGURATION_REQ_DATA),
  150. 0);
  151. if (dwRet != ERROR_SUCCESS) {
  152. return dwRet;
  153. }
  154. if (pReqData->dwVersion != 1) {
  155. return ERROR_INVALID_PARAMETER;
  156. }
  157. //
  158. // Get Current Configuration
  159. //
  160. INET_XCV_CONFIGURATION ConfigData;
  161. if (pPort->GetCurrentConfiguration (&ConfigData)) {
  162. if (EncryptData ((PBYTE) &ConfigData, sizeof (INET_XCV_CONFIGURATION), &pEncryptedData, &dwEncryptedDataSize)) {
  163. if (cbOutputData < dwEncryptedDataSize) {
  164. *pcbOutputNeeded = dwEncryptedDataSize;
  165. dwRet = ERROR_INSUFFICIENT_BUFFER;
  166. }
  167. else {
  168. CopyMemory (pOutputData, pEncryptedData, dwEncryptedDataSize);
  169. *pcbOutputNeeded = dwEncryptedDataSize;
  170. dwRet = ERROR_SUCCESS;
  171. }
  172. LocalFree (pEncryptedData);
  173. }
  174. else
  175. dwRet = GetLastError ();
  176. }
  177. else
  178. dwRet = GetLastError ();
  179. return dwRet;
  180. }
  181. DWORD
  182. DoSetConfiguration(
  183. PBYTE pInputData,
  184. DWORD cbInputData,
  185. PBYTE pOutputData,
  186. DWORD cbOutputData,
  187. PDWORD pcbOutputNeeded,
  188. PCINETMONPORT pPort
  189. )
  190. {
  191. PINET_XCV_CONFIGURATION pReqData;
  192. DWORD dwRet;
  193. PBYTE pDecryptedData;
  194. DWORD dwDecryptedDataSize;
  195. if (DecryptData (pInputData, cbInputData, &pDecryptedData, &dwDecryptedDataSize)) {
  196. //
  197. // Valid input parameters
  198. //
  199. dwRet = ValidateInputParameters (pDecryptedData,
  200. dwDecryptedDataSize,
  201. pOutputData,
  202. cbOutputData,
  203. pcbOutputNeeded,
  204. sizeof (INET_XCV_CONFIGURATION),
  205. sizeof (INET_CONFIGUREPORT_RESPDATA));
  206. if (dwRet == ERROR_SUCCESS) {
  207. pReqData = (PINET_XCV_CONFIGURATION) pDecryptedData;
  208. if (pReqData->dwVersion != 1) {
  209. dwRet = ERROR_INVALID_PARAMETER;
  210. }
  211. else if (pReqData->bSettingForAll && !bIsAdmin ()) {
  212. //
  213. // If the setting is for per-port, but the caller is not an admin
  214. //
  215. dwRet = ERROR_ACCESS_DENIED;
  216. }
  217. else {
  218. //
  219. // We need to leave critical section before changing configurations,
  220. // before leaving critical section, we need to increase the ref count
  221. // so that other people won't delete it
  222. //
  223. semSafeLeaveCrit (pPort);
  224. //
  225. // Get Current Configuration
  226. //
  227. if (pPort->ConfigurePort (pReqData,
  228. (PINET_CONFIGUREPORT_RESPDATA) pOutputData,
  229. cbOutputData,
  230. pcbOutputNeeded))
  231. dwRet = ERROR_SUCCESS;
  232. else
  233. dwRet = GetLastError ();
  234. semSafeEnterCrit (pPort);
  235. }
  236. }
  237. LocalFree (pDecryptedData);
  238. }
  239. else
  240. dwRet = GetLastError ();
  241. return dwRet;
  242. }
  243. DWORD
  244. DoDeletePort(
  245. PBYTE pInputData,
  246. DWORD cbInputData,
  247. PBYTE pOutputData,
  248. DWORD cbOutputData,
  249. PDWORD pcbOutputNeeded,
  250. PCINETMONPORT pPort
  251. )
  252. {
  253. DWORD dwRet = ERROR_SUCCESS;
  254. DWORD cbNeeded, dwStatus;
  255. BOOL bRet = FALSE;
  256. dwRet = ValidateInputParameters (pInputData,
  257. cbInputData,
  258. pOutputData,
  259. cbOutputData,
  260. pcbOutputNeeded,
  261. 0,
  262. 0);
  263. if (dwRet != ERROR_SUCCESS) {
  264. return dwRet;
  265. }
  266. if (IsBadStringPtr ((LPWSTR) pInputData, cbInputData / sizeof (WCHAR)))
  267. return ERROR_INVALID_PARAMETER;
  268. if (bIsAdmin ()) {
  269. if (!PPDeletePort (NULL, NULL, (LPWSTR) pInputData)) {
  270. dwRet = GetLastError ();
  271. }
  272. }
  273. else
  274. dwRet = ERROR_ACCESS_DENIED;
  275. return dwRet;
  276. }
  277. DWORD
  278. DoAddPort(
  279. PBYTE pInputData,
  280. DWORD cbInputData,
  281. PBYTE pOutputData,
  282. DWORD cbOutputData,
  283. PDWORD pcbOutputNeeded,
  284. PCINETMONPORT pPort
  285. )
  286. {
  287. //
  288. // We don't support AddPort
  289. //
  290. return ERROR_ACCESS_DENIED;
  291. }
  292. DWORD
  293. GetMonitorUI(
  294. PBYTE pInputData,
  295. DWORD cbInputData,
  296. PBYTE pOutputData,
  297. DWORD cbOutputData,
  298. PDWORD pcbOutputNeeded,
  299. PCINETMONPORT pPort
  300. )
  301. {
  302. DWORD dwRet;
  303. *pcbOutputNeeded = sizeof( SZINETPPUI );
  304. if (cbOutputData < *pcbOutputNeeded) {
  305. dwRet = ERROR_INSUFFICIENT_BUFFER;
  306. } else {
  307. wcscpy((PWSTR) pOutputData, SZINETPPUI);
  308. dwRet = ERROR_SUCCESS;
  309. }
  310. return dwRet;
  311. }
  312. #endif