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.

142 lines
3.9 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2001 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // SelNodeBasePage.cpp
  7. //
  8. // Maintained By:
  9. // David Potter (DavidP) 30-JAN-2001
  10. //
  11. //////////////////////////////////////////////////////////////////////////////
  12. #include "Pch.h"
  13. #include "SelNodeBasePage.h"
  14. DEFINE_THISCLASS("CSelNodeBasePage");
  15. //////////////////////////////////////////////////////////////////////////////
  16. //++
  17. //
  18. // static
  19. // CSelNodeBasePage::S_HrValidateDnsHostname
  20. //
  21. // Description:
  22. // Validate a hostname with DNS. If the name contains a period (.)
  23. // it will be validated as a full DNS hostname. Otherwise it will be
  24. // validated as a hostname label.
  25. //
  26. // Arguments:
  27. // hwndParentIn
  28. // pcwszHostnameIn
  29. //
  30. // Return Values:
  31. // S_OK - Operation completed successfully
  32. // Other return values from DnsValidateName()
  33. //
  34. // Remarks:
  35. //
  36. //--
  37. //////////////////////////////////////////////////////////////////////////////
  38. CSelNodeBasePage::S_HrValidateDnsHostname(
  39. HWND hwndParentIn
  40. , LPCWSTR pcwszHostnameIn
  41. )
  42. {
  43. TraceFunc1( "pcwszHostnameIn = '%1!ws!", pcwszHostnameIn );
  44. HRESULT hr = S_OK;
  45. DNS_STATUS dnsStatus;
  46. BSTR bstrTitle = NULL;
  47. BSTR bstrOperation = NULL;
  48. BSTR bstrText = NULL;
  49. BSTR bstrFullText = NULL;
  50. UINT nMsgBoxType;
  51. Assert( pcwszHostnameIn != NULL );
  52. //
  53. // If the name contains a dot, validate it as a full DNS name.
  54. // Otherwise validate it as a hostname label.
  55. //
  56. if ( wcschr( pcwszHostnameIn, L'.' ) == NULL )
  57. {
  58. dnsStatus = TW32( DnsValidateName( pcwszHostnameIn, DnsNameHostnameLabel ) );
  59. }
  60. else
  61. {
  62. dnsStatus = TW32( DnsValidateName( pcwszHostnameIn, DnsNameHostnameFull ) );
  63. }
  64. if ( dnsStatus != ERROR_SUCCESS )
  65. {
  66. // Load the title string for the message box.
  67. hr = THR( HrLoadStringIntoBSTR( g_hInstance, IDS_ERR_VALIDATING_COMPUTER_NAME_TITLE, &bstrTitle ) );
  68. if ( FAILED( hr ) )
  69. {
  70. goto Cleanup;
  71. }
  72. // Format the operation string for the message box.
  73. hr = THR( HrFormatStringIntoBSTR( g_hInstance, IDS_ERR_VALIDATING_COMPUTER_NAME_TEXT, &bstrOperation, pcwszHostnameIn ) );
  74. if ( FAILED( hr ) )
  75. {
  76. goto Cleanup;
  77. }
  78. // Format the error message string for the message box.
  79. if ( dnsStatus == ERROR_INVALID_NAME )
  80. {
  81. hr = THR( HrLoadStringIntoBSTR( g_hInstance, IDS_ERR_INVALID_DNS_COMPUTER_NAME_TEXT, &bstrText ) );
  82. nMsgBoxType = MB_ICONSTOP;
  83. }
  84. else
  85. {
  86. hr = THR( HrFormatErrorIntoBSTR( dnsStatus, &bstrText ) );
  87. if ( dnsStatus == DNS_ERROR_NON_RFC_NAME )
  88. {
  89. nMsgBoxType = MB_ICONEXCLAMATION;
  90. }
  91. else
  92. {
  93. nMsgBoxType = MB_ICONSTOP;
  94. }
  95. }
  96. if ( FAILED( hr ) )
  97. {
  98. goto Cleanup;
  99. }
  100. // Construct the message box text.
  101. hr = THR( HrFormatStringIntoBSTR( L"%1!ws!\n\n%2!ws!", &bstrFullText, bstrOperation, bstrText ) );
  102. if ( FAILED( hr ) )
  103. {
  104. goto Cleanup;
  105. }
  106. // Display the error message box.
  107. MessageBox( hwndParentIn, bstrFullText, bstrTitle, nMsgBoxType | MB_OK );
  108. } // if: error in validation
  109. Cleanup:
  110. //
  111. // Ignore a non RFC name error.
  112. // This error should be teated as a warning.
  113. //
  114. if ( ( dnsStatus != ERROR_SUCCESS )
  115. && ( dnsStatus != DNS_ERROR_NON_RFC_NAME ) )
  116. {
  117. hr = HRESULT_FROM_WIN32( dnsStatus );
  118. }
  119. TraceSysFreeString( bstrTitle );
  120. TraceSysFreeString( bstrOperation );
  121. TraceSysFreeString( bstrText );
  122. TraceSysFreeString( bstrFullText );
  123. HRETURN( hr );
  124. } //*** CSelNodeBasePage::S_HrValidateDnsHostname()