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.

144 lines
2.9 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1997.
  5. //
  6. // File: userctxt.c
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 3-26-97 RichardW Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #include "xtcbpkg.h"
  18. LIST_ENTRY XtcbContextList ;
  19. CRITICAL_SECTION XtcbContextListLock ;
  20. #define LockContextList() EnterCriticalSection( &XtcbContextListLock )
  21. #define UnlockContextList() LeaveCriticalSection( &XtcbContextListLock )
  22. BOOL
  23. XtcbUserContextInit(
  24. VOID
  25. )
  26. {
  27. InitializeListHead( &XtcbContextList );
  28. InitializeCriticalSection( &XtcbContextListLock );
  29. return TRUE ;
  30. }
  31. SECURITY_STATUS
  32. XtcbAddUserContext(
  33. IN LSA_SEC_HANDLE LsaHandle,
  34. IN PSecBuffer ContextData)
  35. {
  36. DWORD Size;
  37. PXTCB_USER_CONTEXT Context ;
  38. Context = XtcbFindUserContext( LsaHandle );
  39. if ( Context )
  40. {
  41. DebugLog(( DEB_TRACE, "Replacing existing context!\n" ));
  42. }
  43. if ( ContextData->cbBuffer < sizeof( XTCB_CONTEXT_CORE ) )
  44. {
  45. return( SEC_E_INVALID_TOKEN );
  46. }
  47. Size = sizeof( XTCB_CONTEXT_CORE );
  48. Context = LocalAlloc( LMEM_FIXED | LMEM_ZEROINIT,
  49. sizeof( XTCB_USER_CONTEXT ) + Size );
  50. if ( !Context )
  51. {
  52. return( SEC_E_INSUFFICIENT_MEMORY );
  53. }
  54. Context->LsaHandle = LsaHandle ;
  55. CopyMemory( &Context->Context,
  56. ContextData->pvBuffer,
  57. ContextData->cbBuffer );
  58. LockContextList();
  59. InsertTailList( &XtcbContextList, &Context->List );
  60. UnlockContextList();
  61. return( SEC_E_OK );
  62. }
  63. PXTCB_USER_CONTEXT
  64. XtcbFindUserContext(
  65. IN LSA_SEC_HANDLE LsaHandle
  66. )
  67. {
  68. PLIST_ENTRY List ;
  69. PXTCB_USER_CONTEXT Context = NULL ;
  70. LockContextList();
  71. List = XtcbContextList.Flink ;
  72. while ( List != &XtcbContextList )
  73. {
  74. Context = CONTAINING_RECORD( List, XTCB_USER_CONTEXT, List.Flink );
  75. if ( Context->LsaHandle == LsaHandle )
  76. {
  77. break;
  78. }
  79. Context = NULL ;
  80. List = List->Flink ;
  81. }
  82. UnlockContextList();
  83. return( Context );
  84. }
  85. VOID
  86. XtcbDeleteUserContext(
  87. IN LSA_SEC_HANDLE LsaHandle
  88. )
  89. {
  90. PXTCB_USER_CONTEXT Context ;
  91. Context = XtcbFindUserContext( LsaHandle );
  92. if ( Context )
  93. {
  94. LockContextList();
  95. RemoveEntryList( &Context->List );
  96. UnlockContextList();
  97. DebugLog(( DEB_TRACE, "Deleting user mode context %x, handle = %x\n",
  98. Context, LsaHandle ));
  99. LocalFree( Context );
  100. }
  101. else
  102. {
  103. DebugLog(( DEB_TRACE, "No context found for handle %x\n", LsaHandle ));
  104. }
  105. }