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.

152 lines
3.5 KiB

  1. /*****************************************************************************\
  2. * MODULE: iecon.cxx
  3. *
  4. * The module contains class for connections using IE's default configuration
  5. *
  6. * Copyright (C) 1997-1998 Microsoft Corporation
  7. *
  8. * History:
  9. * 07/31/98 Weihaic Created
  10. *
  11. \*****************************************************************************/
  12. #include "precomp.h"
  13. #include "priv.h"
  14. const DWORD cdwDialogTimeout = 4000000;
  15. COtherConnection::COtherConnection (
  16. BOOL bSecure,
  17. INTERNET_PORT nServerPort,
  18. LPCTSTR lpszUserName,
  19. LPCTSTR lpszPassword,
  20. BOOL bIgnoreSecurityDlg):
  21. CAnyConnection (bSecure, nServerPort, bIgnoreSecurityDlg, AUTH_OTHER)
  22. {
  23. m_bValid = AssignString (m_lpszUserName, lpszUserName) &&
  24. AssignString (m_lpszPassword, lpszPassword);
  25. }
  26. COtherConnection::~COtherConnection ()
  27. {
  28. }
  29. HINTERNET
  30. COtherConnection::OpenRequest (
  31. LPTSTR lpszUrl)
  32. {
  33. return CAnyConnection::OpenRequest (lpszUrl);
  34. }
  35. BOOL
  36. COtherConnection::SendRequest(
  37. HINTERNET hReq,
  38. LPCTSTR lpszHdr,
  39. DWORD cbHdr,
  40. LPBYTE pidi)
  41. {
  42. static const DWORD dwMaxRetry = 2;
  43. BOOL bRet = FALSE;
  44. DWORD i;
  45. HANDLE hToken;
  46. //
  47. // We have to revert to the local system account to prevent wininet from sending
  48. // the logon user credential automatically to the remote machine.
  49. //
  50. if (hToken = RevertToPrinterSelf()) {
  51. for (i = 0; i < dwMaxRetry; i++ ) {
  52. if (SetPassword (hReq, m_lpszUserName, m_lpszPassword)) {
  53. bRet = CAnyConnection:: SendRequest (hReq,
  54. lpszHdr,
  55. cbHdr,
  56. pidi);
  57. if (bRet || GetLastError () != ERROR_ACCESS_DENIED) {
  58. break;
  59. }
  60. }
  61. }
  62. if (!ImpersonatePrinterClient(hToken)) {
  63. bRet = FALSE;
  64. }
  65. }
  66. return bRet;
  67. }
  68. BOOL
  69. COtherConnection::SendRequest(
  70. HINTERNET hReq,
  71. LPCTSTR lpszHdr,
  72. CStream *pStream)
  73. {
  74. static const DWORD dwMaxRetry = 2;
  75. BOOL bRet = FALSE;
  76. DWORD i;
  77. HANDLE hToken;
  78. //
  79. // We have to revert to the local system account to prevent wininet from sending
  80. // the logon user credential automatically to the remote machine.
  81. //
  82. if (hToken = RevertToPrinterSelf()) {
  83. for (i = 0; i < dwMaxRetry; i++ ) {
  84. if (SetPassword (hReq, m_lpszUserName, m_lpszPassword)) {
  85. bRet = CAnyConnection:: SendRequest (hReq,
  86. lpszHdr,
  87. pStream);
  88. if (bRet || GetLastError () != ERROR_ACCESS_DENIED) {
  89. break;
  90. }
  91. }
  92. }
  93. if (!ImpersonatePrinterClient(hToken)) {
  94. bRet = FALSE;
  95. }
  96. }
  97. return bRet;
  98. }
  99. BOOL
  100. COtherConnection::ReadFile (
  101. HINTERNET hReq,
  102. LPVOID lpvBuffer,
  103. DWORD cbBuffer,
  104. LPDWORD lpcbRd)
  105. {
  106. BOOL bRet = FALSE;
  107. HANDLE hToken;
  108. if (hToken = RevertToPrinterSelf()) {
  109. bRet = CAnyConnection::ReadFile (hReq, lpvBuffer, cbBuffer, lpcbRd);
  110. if (!ImpersonatePrinterClient(hToken)) {
  111. bRet = FALSE;
  112. }
  113. }
  114. return bRet;
  115. }