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.

160 lines
5.5 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1998.
  5. //
  6. // File: cisvc.cxx
  7. //
  8. // Contents: CI service
  9. //
  10. // History: 17-Sep-96 dlee Created
  11. //
  12. //--------------------------------------------------------------------------
  13. #include <pch.cxx>
  14. #pragma hdrstop
  15. #include <cievtmsg.h>
  16. #include <cisvcex.hxx>
  17. #include <ciregkey.hxx>
  18. #include <regacc.hxx>
  19. DECLARE_INFOLEVEL(ci)
  20. //+-------------------------------------------------------------------------
  21. //
  22. // Function: main, public
  23. //
  24. // Purpose: Call into CI to start the service
  25. //
  26. // Arguments: [argc] - number of arguments passed
  27. // [argv] - arguments
  28. //
  29. // History: 05-Jan-97 dlee Created
  30. //
  31. //--------------------------------------------------------------------------
  32. extern "C" int __cdecl wmain( int argc, WCHAR *argv[] )
  33. {
  34. #if CIDBG == 1
  35. ciInfoLevel = DEB_ERROR | DEB_WARN | DEB_IWARN | DEB_IERROR;
  36. #endif
  37. static SERVICE_TABLE_ENTRY _aServiceTableEntry[2] =
  38. {
  39. { wcsCiSvcName, CiSvcMain },
  40. { NULL, NULL }
  41. };
  42. ciDebugOut( (DEB_ITRACE, "Ci Service: Attempting to start Ci service\n" ));
  43. // Turn off system popups
  44. CNoErrorMode noErrors;
  45. // Translate system exceptions into C++ exceptions
  46. CTranslateSystemExceptions translate;
  47. TRY
  48. {
  49. //
  50. // Turn off privileges that we don't need
  51. //
  52. NTSTATUS status = STATUS_SUCCESS;
  53. HANDLE hProcessToken;
  54. PTOKEN_PRIVILEGES pTokenPrivs;
  55. BYTE PrivilegeBuffer[sizeof(TOKEN_PRIVILEGES) + 12 * sizeof(LUID_AND_ATTRIBUTES)];
  56. pTokenPrivs = (PTOKEN_PRIVILEGES) PrivilegeBuffer;
  57. status = NtOpenProcessToken(NtCurrentProcess(),
  58. TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
  59. &hProcessToken);
  60. if (!NT_SUCCESS(status))
  61. {
  62. THROW( CException( status ));
  63. }
  64. pTokenPrivs->PrivilegeCount = 13;
  65. pTokenPrivs->Privileges[0].Luid = RtlConvertLongToLuid(SE_TAKE_OWNERSHIP_PRIVILEGE);
  66. pTokenPrivs->Privileges[0].Attributes = SE_PRIVILEGE_REMOVED;
  67. pTokenPrivs->Privileges[1].Luid = RtlConvertLongToLuid(SE_CREATE_PAGEFILE_PRIVILEGE);
  68. pTokenPrivs->Privileges[1].Attributes = SE_PRIVILEGE_REMOVED;
  69. pTokenPrivs->Privileges[2].Luid = RtlConvertLongToLuid(SE_LOCK_MEMORY_PRIVILEGE);
  70. pTokenPrivs->Privileges[2].Attributes = SE_PRIVILEGE_REMOVED;
  71. pTokenPrivs->Privileges[3].Luid = RtlConvertLongToLuid(SE_ASSIGNPRIMARYTOKEN_PRIVILEGE);
  72. pTokenPrivs->Privileges[3].Attributes = SE_PRIVILEGE_REMOVED;
  73. pTokenPrivs->Privileges[4].Luid = RtlConvertLongToLuid(SE_INCREASE_QUOTA_PRIVILEGE);
  74. pTokenPrivs->Privileges[4].Attributes = SE_PRIVILEGE_REMOVED;
  75. pTokenPrivs->Privileges[5].Luid = RtlConvertLongToLuid(SE_INC_BASE_PRIORITY_PRIVILEGE);
  76. pTokenPrivs->Privileges[5].Attributes = SE_PRIVILEGE_REMOVED;
  77. pTokenPrivs->Privileges[6].Luid = RtlConvertLongToLuid(SE_CREATE_PERMANENT_PRIVILEGE);
  78. pTokenPrivs->Privileges[6].Attributes = SE_PRIVILEGE_REMOVED;
  79. pTokenPrivs->Privileges[7].Luid = RtlConvertLongToLuid(SE_SYSTEM_ENVIRONMENT_PRIVILEGE);
  80. pTokenPrivs->Privileges[7].Attributes = SE_PRIVILEGE_REMOVED;
  81. pTokenPrivs->Privileges[8].Luid = RtlConvertLongToLuid(SE_SYSTEMTIME_PRIVILEGE);
  82. pTokenPrivs->Privileges[8].Attributes = SE_PRIVILEGE_REMOVED;
  83. pTokenPrivs->Privileges[9].Luid = RtlConvertLongToLuid(SE_UNDOCK_PRIVILEGE);
  84. pTokenPrivs->Privileges[9].Attributes = SE_PRIVILEGE_REMOVED;
  85. pTokenPrivs->Privileges[10].Luid = RtlConvertLongToLuid(SE_LOAD_DRIVER_PRIVILEGE);
  86. pTokenPrivs->Privileges[10].Attributes = SE_PRIVILEGE_REMOVED;
  87. pTokenPrivs->Privileges[11].Luid = RtlConvertLongToLuid(SE_PROF_SINGLE_PROCESS_PRIVILEGE);
  88. pTokenPrivs->Privileges[11].Attributes = SE_PRIVILEGE_REMOVED;
  89. pTokenPrivs->Privileges[12].Luid = RtlConvertLongToLuid(SE_MANAGE_VOLUME_PRIVILEGE);
  90. pTokenPrivs->Privileges[12].Attributes = SE_PRIVILEGE_REMOVED;
  91. status = NtAdjustPrivilegesToken(hProcessToken,
  92. FALSE,
  93. pTokenPrivs,
  94. sizeof(PrivilegeBuffer),
  95. NULL,
  96. NULL);
  97. NtClose(hProcessToken);
  98. if (!NT_SUCCESS(status))
  99. {
  100. THROW( CException( status ));
  101. }
  102. //
  103. // Inform the service control dispatcher the address of our start
  104. // routine. This routine will not return if it is successful,
  105. // until service shutdown.
  106. //
  107. if ( !StartServiceCtrlDispatcher( _aServiceTableEntry ) )
  108. {
  109. ciDebugOut( (DEB_ITRACE, "Ci Service: Failed to start service, rc=0x%x\n", GetLastError() ));
  110. THROW( CException() );
  111. }
  112. }
  113. CATCH (CException, e)
  114. {
  115. ciDebugOut(( DEB_ERROR,
  116. "Ci Service exception in main(): 0x%x\n",
  117. e.GetErrorCode() ));
  118. }
  119. END_CATCH
  120. ciDebugOut( (DEB_ITRACE, "Ci Service: Leaving CIServiceMain()\n" ));
  121. return 0;
  122. } //main