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.

111 lines
2.3 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. blksec.c
  5. Abstract:
  6. This module implements routines for managing security tokens.
  7. Author
  8. David Kruse (dkruse) 24-Apr-2002
  9. Revision History:
  10. --*/
  11. #include "precomp.h"
  12. #pragma hdrstop
  13. #ifdef ALLOC_PRAGMA
  14. #pragma alloc_text( PAGE, SrvAllocateSecurityContext )
  15. #pragma alloc_text( PAGE, SrvSetSecurityContext )
  16. #pragma alloc_text( PAGE, SrvReferenceSecurityContext )
  17. #pragma alloc_text( PAGE, SrvDereferenceSecurityContext )
  18. #endif
  19. PSECURITY_CONTEXT
  20. SrvAllocateSecurityContext()
  21. {
  22. PSECURITY_CONTEXT Context;
  23. Context = ALLOCATE_HEAP( sizeof(SECURITY_CONTEXT), BlockTypeSession );
  24. if( !Context )
  25. {
  26. return NULL;
  27. }
  28. RtlZeroMemory( Context, sizeof(SECURITY_CONTEXT) );
  29. Context->BlockHeader.ReferenceCount = 1;
  30. SET_BLOCK_TYPE_STATE_SIZE( Context, BlockTypeSecurityContext, BlockStateActive, sizeof(SECURITY_CONTEXT) );
  31. INVALIDATE_SECURITY_HANDLE( Context->UserHandle );
  32. return Context;
  33. }
  34. VOID
  35. SrvSetSecurityContext(
  36. PSECURITY_CONTEXT Context,
  37. PCtxtHandle handle
  38. )
  39. {
  40. Context->UserHandle = *handle;
  41. }
  42. VOID
  43. SrvReferenceSecurityContext(
  44. PSECURITY_CONTEXT Context
  45. )
  46. {
  47. InterlockedIncrement( &Context->BlockHeader.ReferenceCount );
  48. }
  49. VOID
  50. SrvDereferenceSecurityContext(
  51. PSECURITY_CONTEXT Context
  52. )
  53. {
  54. ULONG Count = InterlockedDecrement( &Context->BlockHeader.ReferenceCount );
  55. if( Count == 0 )
  56. {
  57. if( !CONTEXT_EQUAL( SrvNullSessionToken, Context->UserHandle ) )
  58. {
  59. DeleteSecurityContext( &Context->UserHandle );
  60. }
  61. FREE_HEAP( Context );
  62. }
  63. }
  64. VOID
  65. SrvReplaceSessionSecurityContext(
  66. PSESSION Session,
  67. PSECURITY_CONTEXT Context,
  68. OPTIONAL PWORK_CONTEXT WorkContext
  69. )
  70. {
  71. if( Session->SecurityContext != NULL )
  72. {
  73. SrvDereferenceSecurityContext( Session->SecurityContext );
  74. }
  75. Session->SecurityContext = Context;
  76. if( WorkContext )
  77. {
  78. if( WorkContext->SecurityContext != NULL )
  79. {
  80. SrvDereferenceSecurityContext( WorkContext->SecurityContext );
  81. }
  82. WorkContext->SecurityContext = Context;
  83. SrvReferenceSecurityContext( Context );
  84. }
  85. }