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.

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