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.

129 lines
2.9 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. security.c
  5. Abstract:
  6. This code handles impersonating and reverting for the user mode
  7. reflector library. This implements UMReflectorImpersonate and
  8. UMReflectorRevert.
  9. Author:
  10. Andy Herron (andyhe) 20-Apr-1999
  11. Environment:
  12. User Mode - Win32
  13. Revision History:
  14. --*/
  15. #include "precomp.h"
  16. #pragma hdrstop
  17. ULONG
  18. UMReflectorImpersonate(
  19. PUMRX_USERMODE_WORKITEM_HEADER IncomingWorkItem,
  20. HANDLE ImpersonationToken
  21. )
  22. /*++
  23. Routine Description:
  24. This routine impersonates the calling thread.
  25. Arguments:
  26. IncomingWorkItem - The workitem being handled by the thread.
  27. ImpersonationToken - The handle used to impersonate.
  28. Return Value:
  29. ERROR_SUCCESS or the appropriate error value.
  30. --*/
  31. {
  32. PUMRX_USERMODE_WORKITEM_ADDON workItem = NULL;
  33. ULONG rc = STATUS_SUCCESS;
  34. BOOL ReturnVal;
  35. if (IncomingWorkItem == NULL || ImpersonationToken == NULL) {
  36. rc = ERROR_INVALID_PARAMETER;
  37. return rc;
  38. }
  39. //
  40. // We get back to our item by subtracting off of the item passed to us.
  41. // This is safe because we fully control allocation.
  42. //
  43. workItem = (PUMRX_USERMODE_WORKITEM_ADDON)(PCHAR)((PCHAR) IncomingWorkItem -
  44. FIELD_OFFSET(UMRX_USERMODE_WORKITEM_ADDON, Header));
  45. ASSERT(workItem->WorkItemState != WorkItemStateFree);
  46. ASSERT(workItem->WorkItemState != WorkItemStateAvailable);
  47. ReturnVal = ImpersonateLoggedOnUser(ImpersonationToken);
  48. if (!ReturnVal) {
  49. rc = GetLastError();
  50. RlDavDbgPrint(("%ld: ERROR: UMReflectorImpersonate/ImpersonateLoggedOnUser: "
  51. "WStatus = %08lx.\n", GetCurrentThreadId(), rc));
  52. }
  53. return rc;
  54. }
  55. ULONG
  56. UMReflectorRevert(
  57. PUMRX_USERMODE_WORKITEM_HEADER IncomingWorkItem
  58. )
  59. /*++
  60. Routine Description:
  61. This routine reverts the calling thread which was impersonated earlier.
  62. Arguments:
  63. IncomingWorkItem - The workitem being handled by the thread.
  64. Return Value:
  65. ERROR_SUCCESS or the appropriate error value.
  66. --*/
  67. {
  68. PUMRX_USERMODE_WORKITEM_ADDON workItem = NULL;
  69. ULONG rc = STATUS_SUCCESS;
  70. BOOL ReturnVal;
  71. if (IncomingWorkItem == NULL) {
  72. rc = ERROR_INVALID_PARAMETER;
  73. return rc;
  74. }
  75. //
  76. // We get back to our item by subtracting off of the item passed to us.
  77. // This is safe because we fully control allocation.
  78. //
  79. workItem = (PUMRX_USERMODE_WORKITEM_ADDON)(PCHAR)((PCHAR) IncomingWorkItem -
  80. FIELD_OFFSET(UMRX_USERMODE_WORKITEM_ADDON, Header));
  81. ReturnVal = RevertToSelf();
  82. if (!ReturnVal) {
  83. rc = GetLastError();
  84. RlDavDbgPrint(("%ld: ERROR: UMReflectorRevert/RevertToSelf: "
  85. "WStatus = %08lx.\n", GetCurrentThreadId(), rc));
  86. }
  87. return rc;
  88. }
  89. // security.c eof.