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.

149 lines
4.2 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) Microsoft Corp. All rights reserved.
  4. //
  5. // FILE
  6. //
  7. // ExternalAuthNames.cpp
  8. //
  9. // SYNOPSIS
  10. //
  11. // This file defines the class ExternalAuthNames.
  12. //
  13. ///////////////////////////////////////////////////////////////////////////////
  14. #include "ias.h"
  15. #include "externalauthnames.h"
  16. #include "samutil.h"
  17. #include "iastlutl.h"
  18. #include <Sddl.h>
  19. ExternalAuthNames::ExternalAuthNames()
  20. : NameMapper(true),
  21. externalProvider(true)
  22. {
  23. externalProvider->dwId = IAS_ATTRIBUTE_PROVIDER_TYPE;
  24. externalProvider->Value.itType = IASTYPE_ENUM;
  25. externalProvider->Value.Enumerator = IAS_PROVIDER_EXTERNAL_AUTH;
  26. }
  27. IASREQUESTSTATUS ExternalAuthNames::onSyncRequest(IRequest* pRequest) throw ()
  28. {
  29. HRESULT hr = S_OK;
  30. wchar_t* stringSid = NULL;
  31. try
  32. {
  33. IASRequest request(pRequest);
  34. IASAttribute attr;
  35. if (!attr.load(
  36. request,
  37. IAS_ATTRIBUTE_REMOTE_RADIUS_TO_WINDOWS_USER_MAPPING,
  38. IASTYPE_BOOLEAN
  39. ) ||
  40. ( attr->Value.Boolean == VARIANT_FALSE) )
  41. {
  42. // Nothing to do
  43. return IAS_REQUEST_STATUS_HANDLED;
  44. }
  45. // set the new provider type
  46. DWORD providerID = IAS_ATTRIBUTE_PROVIDER_TYPE;
  47. request.RemoveAttributesByType(1, &providerID);
  48. externalProvider.store(request);
  49. // load will throw if more than one attribute is present
  50. // this is what we want
  51. if (!attr.load(
  52. request,
  53. MS_ATTRIBUTE_USER_SECURITY_IDENTITY,
  54. IASTYPE_OCTET_STRING
  55. ))
  56. {
  57. // no UPN: normal name mapping (will use UserName...)
  58. return NameMapper::onSyncRequest(pRequest);
  59. }
  60. if (!ConvertSidToStringSidW(
  61. (PSID)attr->Value.OctetString.lpValue,
  62. &stringSid)
  63. )
  64. {
  65. IASTracePrintf("Error ConvertSidToStringSid failed %x",
  66. GetLastError());
  67. _com_issue_error(IAS_NO_SUCH_USER);
  68. }
  69. // get the suffix if any.
  70. IASAttribute upnSuffix;
  71. upnSuffix.load(
  72. request,
  73. IAS_ATTRIBUTE_PASSPORT_USER_MAPPING_UPN_SUFFIX,
  74. IASTYPE_STRING
  75. );
  76. // get the SID cracked and the result inserted into the request
  77. IASAttribute nt4Name(true);
  78. nt4Name->dwId = IAS_ATTRIBUTE_NT4_ACCOUNT_NAME;
  79. IASTracePrintf("SID received %s", stringSid);
  80. mapName(
  81. stringSid,
  82. nt4Name,
  83. DS_SID_OR_SID_HISTORY_NAME,
  84. upnSuffix? upnSuffix->Value.String.pszWide : NULL
  85. );
  86. if(nt4Name->Value.String.pszWide != NULL)
  87. {
  88. // Convert the domain name to uppercase.
  89. PWCHAR delim = wcschr(nt4Name->Value.String.pszWide, L'\\');
  90. *delim = L'\0';
  91. _wcsupr(nt4Name->Value.String.pszWide);
  92. *delim = L'\\';
  93. }
  94. nt4Name.store(request);
  95. // For now, we'll use this as the FQDN as well.
  96. IASStoreFQUserName(
  97. request,
  98. DS_NT4_ACCOUNT_NAME,
  99. nt4Name->Value.String.pszWide
  100. );
  101. IASTracePrintf("SAM-Account-Name is \"%S\".",
  102. nt4Name->Value.String.pszWide);
  103. // Remove MS-User-Security-Identity attribute.
  104. DWORD securityAttrType = MS_ATTRIBUTE_USER_SECURITY_IDENTITY;
  105. request.RemoveAttributesByType(1, &securityAttrType);
  106. }
  107. catch (const _com_error& ce)
  108. {
  109. IASTraceExcept();
  110. hr = ce.Error();
  111. if (hr == 0x80070234)
  112. {
  113. // HRESULT_FROM_WIN32(ERROR_MORE_DATA)
  114. hr = IAS_PROXY_MALFORMED_RESPONSE;
  115. }
  116. }
  117. if (stringSid != 0)
  118. {
  119. LocalFree(stringSid);
  120. }
  121. if ( FAILED(hr) || ((hr != S_OK) && (hr < 0x0000ffff)) )
  122. {
  123. return IASProcessFailure(pRequest, hr);
  124. }
  125. else
  126. {
  127. return IAS_REQUEST_STATUS_HANDLED;
  128. }
  129. }