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.

134 lines
2.5 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name :
  4. customprovider.cxx
  5. Abstract:
  6. Authentication provider for arbitrary user-name/auth-type/token combo
  7. set by ISAPI during call to HSE_REQ_EXEC_URL
  8. Author:
  9. Bilal Alam (balam) 29-Nov-2000
  10. Environment:
  11. Win32 - User Mode
  12. Project:
  13. ULW3.DLL
  14. --*/
  15. #include "precomp.hxx"
  16. #include "customprovider.hxx"
  17. HRESULT
  18. CUSTOM_USER_CONTEXT::Create(
  19. HANDLE hImpersonationToken,
  20. BYTE * pszUserName,
  21. BOOL fIsUnicode,
  22. DWORD dwAuthType
  23. )
  24. /*++
  25. Routine Description:
  26. Initialize custom user context
  27. Arguments:
  28. hImpersonationToken - Impersonation token for the custom user
  29. pszUserName - Custom user name
  30. dwAuthType - Auth type
  31. Return Value:
  32. HRESULT
  33. --*/
  34. {
  35. HRESULT hr;
  36. if ( hImpersonationToken == NULL ||
  37. pszUserName == NULL )
  38. {
  39. DBG_ASSERT( FALSE );
  40. return HRESULT_FROM_WIN32( ERROR_INVALID_PARAMETER );
  41. }
  42. //
  43. // Duplicate the token
  44. //
  45. if ( !DuplicateTokenEx( hImpersonationToken,
  46. TOKEN_ALL_ACCESS,
  47. NULL,
  48. SecurityImpersonation,
  49. TokenImpersonation,
  50. &_hImpersonationToken ) )
  51. {
  52. return HRESULT_FROM_WIN32( GetLastError() );
  53. }
  54. //
  55. // Copy the user name
  56. //
  57. if (fIsUnicode)
  58. {
  59. hr = _strUserName.Copy( (WCHAR *)pszUserName );
  60. }
  61. else
  62. {
  63. hr = _strUserName.CopyA( (CHAR *)pszUserName );
  64. }
  65. if ( FAILED( hr ) )
  66. {
  67. return hr;
  68. }
  69. _dwAuthType = dwAuthType;
  70. return NO_ERROR;
  71. }
  72. HANDLE
  73. CUSTOM_USER_CONTEXT::QueryPrimaryToken(
  74. VOID
  75. )
  76. /*++
  77. Routine Description:
  78. Get the primary token
  79. Arguments:
  80. None
  81. Return Value:
  82. HANDLE to primary token
  83. --*/
  84. {
  85. if ( _hPrimaryToken == NULL )
  86. {
  87. _Lock.WriteLock();
  88. if ( DuplicateTokenEx( _hImpersonationToken,
  89. TOKEN_ALL_ACCESS,
  90. NULL,
  91. SecurityImpersonation,
  92. TokenPrimary,
  93. &_hPrimaryToken ) )
  94. {
  95. DBG_ASSERT( _hPrimaryToken != NULL );
  96. }
  97. _Lock.WriteUnlock();
  98. }
  99. return _hPrimaryToken;
  100. }