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.

189 lines
5.2 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. eaphlp.cpp
  7. FILE HISTORY:
  8. */
  9. #include <precompiled.h>
  10. #include <afxtempl.h>
  11. #include <winldap.h>
  12. #include "eaphlp.h"
  13. #include "resource.h"
  14. #include "lm.h"
  15. #include "dsrole.h"
  16. #include "lmserver.h"
  17. #include "tregkey.h"
  18. /*!--------------------------------------------------------------------------
  19. HrIsStandaloneServer
  20. Returns S_OK if the machine name passed in is a standalone server,
  21. or if pszMachineName is S_FALSE.
  22. Returns FALSE otherwise.
  23. Author: WeiJiang
  24. ---------------------------------------------------------------------------*/
  25. HRESULT HrIsStandaloneServer(LPCWSTR pMachineName)
  26. {
  27. DWORD netRet = 0;
  28. HRESULT hr = S_OK;
  29. DSROLE_PRIMARY_DOMAIN_INFO_BASIC* pdsRole = NULL;
  30. netRet = DsRoleGetPrimaryDomainInformation(pMachineName, DsRolePrimaryDomainInfoBasic, (LPBYTE*)&pdsRole);
  31. if(netRet != 0)
  32. {
  33. hr = HRESULT_FROM_WIN32(netRet);
  34. goto L_ERR;
  35. }
  36. ASSERT(pdsRole);
  37. // if the machine is not a standalone server
  38. if(pdsRole->MachineRole != DsRole_RoleStandaloneServer)
  39. {
  40. hr = S_FALSE;
  41. }
  42. L_ERR:
  43. if(pdsRole)
  44. DsRoleFreeMemory(pdsRole);
  45. return hr;
  46. }
  47. #undef CONST_STRING
  48. #undef CONST_STRINGA
  49. #undef CONST_STRINGW
  50. #define _STRINGS_DEFINE_STRINGS
  51. #ifdef _STRINGS_DEFINE_STRINGS
  52. #define CONST_STRING(rg,s) const TCHAR rg[] = TEXT(s);
  53. #define CONST_STRINGA(rg,s) const char rg[] = s;
  54. #define CONST_STRINGW(rg,s) const WCHAR rg[] = s;
  55. #else
  56. #define CONST_STRING(rg,s) extern const TCHAR rg[];
  57. #define CONST_STRINGA(rg,s) extern const char rg[];
  58. #define CONST_STRINGW(rg,s) extern const WCHAR rg[];
  59. #endif
  60. CONST_STRING(c_szRasmanPPPKey, "System\\CurrentControlSet\\Services\\Rasman\\PPP")
  61. CONST_STRING(c_szEAP, "EAP")
  62. CONST_STRING(c_szConfigCLSID, "ConfigCLSID")
  63. CONST_STRING(c_szFriendlyName, "FriendlyName")
  64. CONST_STRING(c_szMPPEEncryptionSupported, "MPPEEncryptionSupported")
  65. CONST_STRING(c_szStandaloneSupported, "StandaloneSupported")
  66. // EAP helper functions
  67. HRESULT LoadEapProviders(HKEY hkeyBase, AuthProviderArray *pProvList, BOOL bStandAlone);
  68. HRESULT GetEapProviders(LPCTSTR pServerName, AuthProviderArray *pProvList)
  69. {
  70. RegKey m_regkeyRasmanPPP;
  71. RegKey regkeyEap;
  72. DWORD dwErr = ERROR_SUCCESS;
  73. HRESULT hr = S_OK;
  74. BOOL bStandAlone = ( S_OK == HrIsStandaloneServer(pServerName));
  75. // Get the list of EAP providers
  76. // ----------------------------------------------------------------
  77. dwErr = m_regkeyRasmanPPP.Open(HKEY_LOCAL_MACHINE,c_szRasmanPPPKey,KEY_ALL_ACCESS,pServerName);
  78. if ( ERROR_SUCCESS == dwErr )
  79. {
  80. if ( ERROR_SUCCESS == regkeyEap.Open(m_regkeyRasmanPPP, c_szEAP) )
  81. hr = LoadEapProviders(regkeyEap, pProvList, bStandAlone);
  82. }
  83. else
  84. hr = HRESULT_FROM_WIN32(dwErr);
  85. return hr;
  86. }
  87. /*!--------------------------------------------------------------------------
  88. DATA_SRV_AUTH::LoadEapProviders
  89. -
  90. Author: KennT
  91. ---------------------------------------------------------------------------*/
  92. HRESULT LoadEapProviders(HKEY hkeyBase, AuthProviderArray *pProvList, BOOL bStandAlone)
  93. {
  94. RegKey regkeyProviders;
  95. HRESULT hr = S_OK;
  96. HRESULT hrIter;
  97. RegKeyIterator regkeyIter;
  98. CString stKey;
  99. RegKey regkeyProv;
  100. AuthProviderData data;
  101. DWORD dwErr;
  102. DWORD dwData;
  103. ASSERT(hkeyBase);
  104. ASSERT(pProvList);
  105. // Open the providers key
  106. // ----------------------------------------------------------------
  107. regkeyProviders.Attach(hkeyBase);
  108. hr = regkeyIter.Init(&regkeyProviders);
  109. if (hr != S_OK)
  110. goto L_ERR;
  111. for ( hrIter=regkeyIter.Next(&stKey); hrIter == S_OK;
  112. hrIter=regkeyIter.Next(&stKey), regkeyProv.Close() )
  113. {
  114. // Open the key
  115. // ------------------------------------------------------------
  116. dwErr = regkeyProv.Open(regkeyProviders, stKey, KEY_READ);
  117. if ( dwErr != ERROR_SUCCESS )
  118. continue;
  119. // Initialize the data structure
  120. // ------------------------------------------------------------
  121. data.m_stKey = stKey;
  122. data.m_stTitle.Empty();
  123. data.m_stConfigCLSID.Empty();
  124. data.m_stGuid.Empty();
  125. data.m_fSupportsEncryption = FALSE;
  126. data.m_dwStandaloneSupported = 0;
  127. // Read in the values that we require
  128. // ------------------------------------------------------------
  129. regkeyProv.QueryValue(c_szFriendlyName, data.m_stTitle);
  130. regkeyProv.QueryValue(c_szConfigCLSID, data.m_stConfigCLSID);
  131. regkeyProv.QueryValue(c_szMPPEEncryptionSupported, dwData);
  132. data.m_fSupportsEncryption = (dwData != 0);
  133. // Read in the standalone supported value.
  134. // ------------------------------------------------------------
  135. if (S_OK != regkeyProv.QueryValue(c_szStandaloneSupported, dwData))
  136. dwData = 1; // the default
  137. data.m_dwStandaloneSupported = dwData;
  138. if(dwData == 0 /* standalone not supported */ && bStandAlone)
  139. ;
  140. else
  141. pProvList->Add(data);
  142. }
  143. L_ERR:
  144. regkeyProviders.Detach();
  145. return hr;
  146. }