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.

169 lines
4.2 KiB

  1. /**************************** Module Header ********************************\
  2. * Module Name: logon.c
  3. *
  4. * Copyright (c) 1985 - 1999, Microsoft Corporation
  5. *
  6. * Logon Support Routines
  7. *
  8. * History:
  9. * 01-14-91 JimA Created.
  10. \***************************************************************************/
  11. #include "precomp.h"
  12. #pragma hdrstop
  13. /***************************************************************************\
  14. * _RegisterLogonProcess
  15. *
  16. * Register the logon process and set secure mode flag
  17. *
  18. * History:
  19. * 07-01-91 JimA Created.
  20. \***************************************************************************/
  21. BOOL _RegisterLogonProcess(
  22. DWORD dwProcessId,
  23. BOOL fSecure)
  24. {
  25. UNREFERENCED_PARAMETER(fSecure);
  26. /*
  27. * Allow only one logon process and then only if it has TCB
  28. * privilege.
  29. */
  30. if (gpidLogon != 0 || !IsPrivileged(&psTcb)) {
  31. RIPERR0(ERROR_ACCESS_DENIED,
  32. RIP_WARNING,
  33. "Access denied in _RegisterLogonProcess");
  34. return FALSE;
  35. }
  36. gpidLogon = (HANDLE)LongToHandle( dwProcessId );
  37. return TRUE;
  38. }
  39. /***************************************************************************\
  40. * _LockWindowStation
  41. *
  42. * Locks a windowstation and its desktops and returns the busy status.
  43. *
  44. * History:
  45. * 01-15-91 JimA Created.
  46. \***************************************************************************/
  47. UINT _LockWindowStation(
  48. PWINDOWSTATION pwinsta)
  49. {
  50. PDESKTOP pdesk;
  51. BOOL fBusy = FALSE;
  52. /*
  53. * Make sure the caller is the logon process
  54. */
  55. if (PsGetCurrentProcessId() != gpidLogon) {
  56. RIPERR0(ERROR_ACCESS_DENIED,
  57. RIP_WARNING,
  58. "Access denied in _LockWindowStation");
  59. return WSS_ERROR;
  60. }
  61. /*
  62. * Prevent desktop switches
  63. */
  64. pwinsta->dwWSF_Flags |= WSF_SWITCHLOCK;
  65. /*
  66. * Determine whether the station is busy
  67. */
  68. pdesk = pwinsta->rpdeskList;
  69. while (pdesk != NULL) {
  70. if (pdesk != grpdeskLogon &&
  71. OBJECT_TO_OBJECT_HEADER(pdesk)->HandleCount != 0) {
  72. /*
  73. * This desktop is open, thus the station is busy
  74. */
  75. fBusy = TRUE;
  76. break;
  77. }
  78. pdesk = pdesk->rpdeskNext;
  79. }
  80. if (pwinsta->dwWSF_Flags & WSF_SHUTDOWN)
  81. pwinsta->dwWSF_Flags |= WSF_OPENLOCK;
  82. /*
  83. * Unlock opens if the station is busy and is not in the middle
  84. * of shutting down.
  85. */
  86. if (fBusy)
  87. return WSS_BUSY;
  88. else
  89. return WSS_IDLE;
  90. }
  91. /***************************************************************************\
  92. * _UnlockWindowStation
  93. *
  94. * Unlocks a windowstation locked by LogonLockWindowStation.
  95. *
  96. * History:
  97. * 01-15-91 JimA Created.
  98. \***************************************************************************/
  99. BOOL _UnlockWindowStation(
  100. PWINDOWSTATION pwinsta)
  101. {
  102. /*
  103. * Make sure the caller is the logon process.
  104. */
  105. if (PsGetCurrentProcessId() != gpidLogon) {
  106. RIPERR0(ERROR_ACCESS_DENIED,
  107. RIP_WARNING,
  108. "Access denied in _UnlockWindowStation");
  109. return FALSE;
  110. }
  111. /*
  112. * If shutdown is occuring, only remove the switch lock.
  113. */
  114. if (pwinsta->dwWSF_Flags & WSF_SHUTDOWN) {
  115. pwinsta->dwWSF_Flags &= ~WSF_SWITCHLOCK;
  116. } else {
  117. pwinsta->dwWSF_Flags &= ~(WSF_OPENLOCK | WSF_SWITCHLOCK);
  118. }
  119. return TRUE;
  120. }
  121. /***************************************************************************\
  122. * _SetLogonNotifyWindow
  123. *
  124. * Register the window to notify when logon related events occur.
  125. *
  126. * History:
  127. * 01-13-92 JimA Created.
  128. \***************************************************************************/
  129. BOOL _SetLogonNotifyWindow(
  130. PWND pwnd)
  131. {
  132. /*
  133. * Make sure the caller is the logon process.
  134. */
  135. if (PsGetCurrentProcessId() != gpidLogon) {
  136. RIPERR0(ERROR_ACCESS_DENIED,
  137. RIP_WARNING,
  138. "Access denied in _SetLogonNotifyWindow");
  139. return FALSE;
  140. }
  141. Lock(&gspwndLogonNotify, pwnd);
  142. return TRUE;
  143. }