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.

202 lines
4.5 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1997.
  5. //
  6. // File: sunlogon.c
  7. //
  8. // Contents: Intermediate startup app for sundown to keep going
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 3-03-98 RichardW Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #include <nt.h>
  18. #include <ntrtl.h>
  19. #include <nturtl.h>
  20. #include <windows.h>
  21. #include <winbasep.h>
  22. #include <winuserp.h>
  23. #include <userenv.h>
  24. #include <userenvp.h>
  25. HANDLE WindowStation ;
  26. HANDLE DefaultDesktop ;
  27. HANDLE WinlogonDesktop ;
  28. BOOL
  29. CreatePrimaryTerminal(
  30. VOID)
  31. {
  32. //
  33. // Create the window station
  34. //
  35. WindowStation = CreateWindowStationW(
  36. TEXT("WinSta0"),
  37. 0,
  38. MAXIMUM_ALLOWED,
  39. NULL);
  40. if ( !WindowStation ) {
  41. DbgPrint( "Failed to create WindowStation in win32k/user\n" );
  42. goto failCreateTerminal;
  43. }
  44. SetProcessWindowStation( WindowStation );
  45. //
  46. // Create the application desktop
  47. //
  48. DefaultDesktop = CreateDesktopW(
  49. TEXT("Default"),
  50. NULL,
  51. NULL,
  52. 0,
  53. MAXIMUM_ALLOWED,
  54. NULL );
  55. if ( !DefaultDesktop ) {
  56. DbgPrint( "Could not create Default desktop\n" );
  57. goto failCreateTerminal;
  58. }
  59. return TRUE ;
  60. failCreateTerminal:
  61. //
  62. // Cleanup
  63. //
  64. return FALSE;
  65. }
  66. int
  67. WINAPI
  68. WinMain(
  69. HINSTANCE hInstance,
  70. HINSTANCE hPrevInstance,
  71. LPSTR lpCmdLine,
  72. int nCmdShow)
  73. {
  74. STARTUPINFO si ;
  75. PROCESS_INFORMATION pi ;
  76. BOOL Result ;
  77. WCHAR InitialCommand[ MAX_PATH ];
  78. WCHAR szComputerName[ 18 ];
  79. DWORD dwComputerNameSize = 18 ;
  80. DWORD dwSize ;
  81. LUID luidNone = { 0, 0 };
  82. NTSTATUS Status ;
  83. HANDLE Token ;
  84. //
  85. // Get a copy of the computer name in *my* environment, so that we
  86. // can look at it later.
  87. //
  88. if (GetComputerName (szComputerName, &dwComputerNameSize)) {
  89. SetEnvironmentVariable(
  90. TEXT("COMPUTERNAME"),
  91. (LPTSTR) szComputerName);
  92. }
  93. //
  94. // Set the default USERPROFILE location
  95. //
  96. dwSize = MAX_PATH ;
  97. if ( GetDefaultUserProfileDirectory( InitialCommand, &dwSize ) )
  98. {
  99. SetEnvironmentVariable( TEXT("USERPROFILE" ), InitialCommand );
  100. }
  101. if (!RegisterLogonProcess(
  102. HandleToUlong(NtCurrentTeb()->ClientId.UniqueProcess),
  103. TRUE)) {
  104. DbgPrint( "Failed to register with win32/user as the logon process\n" );
  105. return 0;
  106. }
  107. if ( !CreatePrimaryTerminal() )
  108. {
  109. DbgPrint( "Failed to create terminal\n" );
  110. return 0 ;
  111. }
  112. SwitchDesktop( DefaultDesktop );
  113. SetThreadDesktop( DefaultDesktop );
  114. //
  115. // Whack system as current user:
  116. //
  117. SetWindowStationUser( WindowStation, &luidNone, NULL, 0 );
  118. Status = NtOpenProcessToken(
  119. NtCurrentProcess(),
  120. MAXIMUM_ALLOWED,
  121. &Token );
  122. if ( NT_SUCCESS( Status ) )
  123. {
  124. UpdatePerUserSystemParameters( Token, UPUSP_USERLOGGEDON );
  125. }
  126. //
  127. // At this stage, we're mostly set.
  128. //
  129. wcscpy( InitialCommand, TEXT("cmd.exe") );
  130. do
  131. {
  132. ZeroMemory(&si, sizeof(STARTUPINFO));
  133. si.cb = sizeof(STARTUPINFO);
  134. si.lpTitle = InitialCommand ;
  135. si.dwFlags = 0 ;
  136. si.wShowWindow = SW_SHOW; // at least let the guy see it
  137. si.lpDesktop = TEXT("Winsta0\\Default");
  138. Result = CreateProcessW(
  139. NULL,
  140. InitialCommand,
  141. NULL,
  142. NULL,
  143. FALSE,
  144. 0,
  145. NULL,
  146. NULL,
  147. &si,
  148. &pi );
  149. if ( !Result )
  150. {
  151. DbgPrint(" Failed to start initial command\n" );
  152. return 0;
  153. }
  154. CloseHandle( pi.hThread );
  155. WaitForSingleObjectEx( pi.hProcess, INFINITE, FALSE );
  156. } while ( 1 );
  157. }