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.

187 lines
5.7 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright(C) 2000 Microsoft Corporation all rights reserved.
  4. //
  5. // Module: updatemschap.cpp
  6. //
  7. // Project: Windows 2000 IAS
  8. //
  9. // Description: add the authentication types RAS_AT_MSCHAPPASS and
  10. // RAS_AT_MSCHAP2PASS when RAS_AT_MSCHAP and RAS_AT_MSCHAP2
  11. // are in the profiles.
  12. //
  13. // Author: tperraut 11/30/2000
  14. //
  15. // Revision
  16. //
  17. /////////////////////////////////////////////////////////////////////////////
  18. #include "stdafx.h"
  19. #include "GlobalData.h"
  20. #include "updatemschap.h"
  21. #include "Objects.h"
  22. #include "Properties.h"
  23. #include "sdoias.h"
  24. void CUpdateMSCHAP::UpdateProperties(const LONG CurrentProfileIdentity)
  25. {
  26. _bstr_t AuthenticationName = L"msNPAuthenticationType2";
  27. // Now get the properties for the current profile
  28. _bstr_t PropertyName;
  29. _bstr_t PropertyValue;
  30. LONG Type = 0;
  31. bool ChapSet = false;
  32. bool Chap2Set = false;
  33. bool ChapPassSet = false;
  34. bool Chap2PassSet = false;
  35. LONG IndexProperty = 0;
  36. HRESULT hr = m_GlobalData.m_pProperties->GetProperty(
  37. CurrentProfileIdentity,
  38. PropertyName,
  39. Type,
  40. PropertyValue
  41. );
  42. while ( SUCCEEDED(hr) )
  43. {
  44. // msNPAuthenticationType2 property found
  45. if ( PropertyName == AuthenticationName )
  46. {
  47. if ( Type != VT_I4 )
  48. {
  49. _com_issue_error(E_UNEXPECTED);
  50. }
  51. LONG AuthenticationType = _wtol(static_cast<wchar_t*>(PropertyValue));
  52. switch (AuthenticationType)
  53. {
  54. case IAS_AUTH_MSCHAP:
  55. {
  56. ChapSet = true;
  57. break;
  58. }
  59. case IAS_AUTH_MSCHAP2:
  60. {
  61. Chap2Set = true;
  62. break;
  63. }
  64. case IAS_AUTH_MSCHAP_CPW:
  65. {
  66. ChapPassSet = true;
  67. break;
  68. }
  69. case IAS_AUTH_MSCHAP2_CPW:
  70. {
  71. Chap2PassSet = true;
  72. break;
  73. }
  74. default:
  75. {
  76. break;
  77. }
  78. }
  79. }
  80. ++IndexProperty;
  81. hr = m_GlobalData.m_pProperties->GetNextProperty(
  82. CurrentProfileIdentity,
  83. PropertyName,
  84. Type,
  85. PropertyValue,
  86. IndexProperty
  87. );
  88. }
  89. // No property or no more properties for this profile
  90. // Insert the newproperties if necessary
  91. if ( ChapSet && !ChapPassSet )
  92. {
  93. // RAS_AT_MSCHAPPASS = 9
  94. wchar_t buffer[34]; // can convert 33 char max
  95. _ltow(IAS_AUTH_MSCHAP_CPW, buffer, 10); // radix 10
  96. _bstr_t ChapPasswordValue(buffer);
  97. // now insert the new properties if needed
  98. m_GlobalData.m_pProperties->InsertProperty(
  99. CurrentProfileIdentity,
  100. AuthenticationName,
  101. VT_I4,
  102. ChapPasswordValue
  103. );
  104. }
  105. if ( Chap2Set && !Chap2PassSet )
  106. {
  107. // RAS_AT_MSCHAP2PASS = 10
  108. wchar_t buffer[34]; // can convert 33 char max
  109. _ltow(IAS_AUTH_MSCHAP2_CPW, buffer, 10); // radix 10
  110. _bstr_t Chap2PasswordValue(buffer);
  111. // now insert the new properties if needed
  112. m_GlobalData.m_pProperties->InsertProperty(
  113. CurrentProfileIdentity,
  114. AuthenticationName,
  115. VT_I4,
  116. Chap2PasswordValue
  117. );
  118. }
  119. }
  120. //////////////////////////////////////////////////////////////////////////////
  121. // Execute
  122. //
  123. // For each profile, if msNPAuthenticationType2 is RAS_AT_MSCHAP then add the
  124. // msNPAuthenticationType2 RAS_AT_MSCHAPPASS
  125. // if msNPAuthenticationType2 is RAS_AT_MSCHAP2 then add the
  126. // msNPAuthenticationType2 RAS_AT_MSCHAP2PASS
  127. //
  128. //////////////////////////////////////////////////////////////////////////////
  129. void CUpdateMSCHAP::Execute()
  130. {
  131. // Get the Profiles container identity
  132. const WCHAR ProfilesPath[] =
  133. L"Root\0"
  134. L"Microsoft Internet Authentication Service\0"
  135. L"RadiusProfiles\0";
  136. LONG ProfilesIdentity;
  137. m_GlobalData.m_pObjects->WalkPath(ProfilesPath, ProfilesIdentity);
  138. // Get the first Profile (if any)
  139. _bstr_t CurrentProfileName;
  140. LONG CurrentProfileIdentity;
  141. HRESULT hr = m_GlobalData.m_pObjects->GetObject(
  142. CurrentProfileName,
  143. CurrentProfileIdentity,
  144. ProfilesIdentity
  145. );
  146. // for each profiles in ias.mdb, execute the changes.
  147. LONG IndexObject = 0;
  148. // if hr is not S_OK, there's no profile, nothing to do
  149. while ( SUCCEEDED(hr) )
  150. {
  151. UpdateProperties(CurrentProfileIdentity);
  152. // now get the next profile
  153. ++IndexObject;
  154. hr = m_GlobalData.m_pObjects->GetNextObject(
  155. CurrentProfileName,
  156. CurrentProfileIdentity,
  157. ProfilesIdentity,
  158. IndexObject
  159. );
  160. }
  161. }