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.

172 lines
4.1 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. #ifdef WINNT32
  14. #include "priv.h"
  15. const DWORD cdwDialogTimeout = 4000000;
  16. COtherConnection::COtherConnection (
  17. BOOL bSecure,
  18. INTERNET_PORT nServerPort,
  19. LPCTSTR lpszUserName,
  20. LPCTSTR lpszPassword,
  21. BOOL bIgnoreSecurityDlg):
  22. CAnyConnection (bSecure, nServerPort, bIgnoreSecurityDlg, AUTH_OTHER)
  23. {
  24. m_bValid = AssignString (m_lpszUserName, lpszUserName) &&
  25. AssignString (m_lpszPassword, lpszPassword);
  26. }
  27. COtherConnection::~COtherConnection ()
  28. {
  29. }
  30. HINTERNET
  31. COtherConnection::OpenRequest (
  32. LPTSTR lpszUrl)
  33. {
  34. return CAnyConnection::OpenRequest (lpszUrl);
  35. #if 0
  36. // This is not necessary since we have force auth. For those IPP servers that do not support
  37. // force authentication. Although it is possible to submit a job with anonymous user even if the
  38. // connection is established with a credential, it does not prevent the user from
  39. // performing any actions that requires the credential since any denied access will be resolved
  40. // in SendRequest() using the correct credential.
  41. //
  42. HINTERNET hReq = CAnyConnection::OpenRequest (lpszUrl);
  43. if (hReq && _FindAndSetPassword (hReq, FALSE)) {
  44. return hReq;
  45. }
  46. return NULL;
  47. #endif
  48. }
  49. BOOL
  50. COtherConnection::SendRequest(
  51. HINTERNET hReq,
  52. LPCTSTR lpszHdr,
  53. DWORD cbHdr,
  54. LPBYTE pidi)
  55. {
  56. static const DWORD dwMaxRetry = 2;
  57. BOOL bRet = FALSE;
  58. DWORD i;
  59. HANDLE hToken;
  60. //
  61. // We have to revert to the local system account to prevent wininet from sending
  62. // the logon user credential automatically to the remote machine.
  63. //
  64. if (hToken = RevertToPrinterSelf()) {
  65. for (i = 0; i < dwMaxRetry; i++ ) {
  66. if (SetPassword (hReq, m_lpszUserName, m_lpszPassword)) {
  67. bRet = CAnyConnection:: SendRequest (hReq,
  68. lpszHdr,
  69. cbHdr,
  70. pidi);
  71. if (bRet || GetLastError () != ERROR_ACCESS_DENIED) {
  72. break;
  73. }
  74. }
  75. }
  76. if (!ImpersonatePrinterClient(hToken)) {
  77. bRet = FALSE;
  78. }
  79. }
  80. return bRet;
  81. }
  82. BOOL
  83. COtherConnection::SendRequest(
  84. HINTERNET hReq,
  85. LPCTSTR lpszHdr,
  86. CStream *pStream)
  87. {
  88. static const DWORD dwMaxRetry = 2;
  89. BOOL bRet = FALSE;
  90. DWORD i;
  91. HANDLE hToken;
  92. //
  93. // We have to revert to the local system account to prevent wininet from sending
  94. // the logon user credential automatically to the remote machine.
  95. //
  96. if (hToken = RevertToPrinterSelf()) {
  97. for (i = 0; i < dwMaxRetry; i++ ) {
  98. if (SetPassword (hReq, m_lpszUserName, m_lpszPassword)) {
  99. bRet = CAnyConnection:: SendRequest (hReq,
  100. lpszHdr,
  101. pStream);
  102. if (bRet || GetLastError () != ERROR_ACCESS_DENIED) {
  103. break;
  104. }
  105. }
  106. }
  107. if (!ImpersonatePrinterClient(hToken)) {
  108. bRet = FALSE;
  109. }
  110. }
  111. return bRet;
  112. }
  113. BOOL
  114. COtherConnection::ReadFile (
  115. HINTERNET hReq,
  116. LPVOID lpvBuffer,
  117. DWORD cbBuffer,
  118. LPDWORD lpcbRd)
  119. {
  120. BOOL bRet = FALSE;
  121. HANDLE hToken;
  122. if (hToken = RevertToPrinterSelf()) {
  123. bRet = CAnyConnection::ReadFile (hReq, lpvBuffer, cbBuffer, lpcbRd);
  124. if (!ImpersonatePrinterClient(hToken)) {
  125. bRet = FALSE;
  126. }
  127. }
  128. return bRet;
  129. }
  130. #endif