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.

126 lines
2.3 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. CHAR * pszUserName,
  21. DWORD dwAuthType
  22. )
  23. /*++
  24. Routine Description:
  25. Initialize custom user context
  26. Arguments:
  27. hImpersonationToken - Impersonation token for the custom user
  28. pszUserName - Custom user name
  29. dwAuthType - Auth type
  30. Return Value:
  31. HRESULT
  32. --*/
  33. {
  34. HRESULT hr;
  35. if ( hImpersonationToken == NULL ||
  36. pszUserName == NULL )
  37. {
  38. DBG_ASSERT( FALSE );
  39. return HRESULT_FROM_WIN32( ERROR_INVALID_PARAMETER );
  40. }
  41. //
  42. // Duplicate the token
  43. //
  44. if ( !DuplicateTokenEx( hImpersonationToken,
  45. TOKEN_ALL_ACCESS,
  46. NULL,
  47. SecurityImpersonation,
  48. TokenImpersonation,
  49. &_hImpersonationToken ) )
  50. {
  51. return HRESULT_FROM_WIN32( GetLastError() );
  52. }
  53. //
  54. // Copy the user name
  55. //
  56. hr = _strUserName.CopyA( pszUserName );
  57. if ( FAILED( hr ) )
  58. {
  59. return hr;
  60. }
  61. _dwAuthType = dwAuthType;
  62. return NO_ERROR;
  63. }
  64. HANDLE
  65. CUSTOM_USER_CONTEXT::QueryPrimaryToken(
  66. VOID
  67. )
  68. /*++
  69. Routine Description:
  70. Get the primary token
  71. Arguments:
  72. None
  73. Return Value:
  74. HANDLE to primary token
  75. --*/
  76. {
  77. if ( _hPrimaryToken == NULL )
  78. {
  79. _Lock.WriteLock();
  80. if ( DuplicateTokenEx( _hImpersonationToken,
  81. TOKEN_ALL_ACCESS,
  82. NULL,
  83. SecurityImpersonation,
  84. TokenPrimary,
  85. &_hPrimaryToken ) )
  86. {
  87. DBG_ASSERT( _hPrimaryToken != NULL );
  88. }
  89. _Lock.WriteUnlock();
  90. }
  91. return _hPrimaryToken;
  92. }