mirror of
https://github.com/reactos/reactos.git
synced 2024-11-09 08:08:38 +00:00
b3ea65f0e4
NTOSKRNL.NtQuerySystemInformation() and NTOSKRNL.NtSetSystemInformation(). --- Partially implemented (kernel32/process/proc.c) KERNEL32.GetPriorityClass(), KERNEL32.SetPriorityClass() and NTDLL.CsrSetPriorityClass() (stub only). Renamed (in include/csrss/csrss.h) priority class macros: #define CSR_PRIORITY_CLASS_NORMAL (0x10) #define CSR_PRIORITY_CLASS_IDLE (0x20) #define CSR_PRIORITY_CLASS_HIGH (0x40) #define CSR_PRIORITY_CLASS_REALTIME (0x80) --- Implemented (kernel32/misc/error.c) #include <kernel32/error.h> DWORD STDCALL SetLastErrorByStatus ( NTSTATUS Status ); to replace SetLastError(RtlNtStatusToDosError(Status)) in KERNEL32, and fixed KERNEL32.SetLastError() KERNEL32.GetLastError() to use the field in NT_TEB (LastError is per thread not per process). --- Implemented (lib/kernel32/sysinfo.c) GetSystemInfo() (to be completed). --- Fixed rosapps/sysutils/makefile to use ROS import libraries. --- Added QSI to the system utilities set. The target is writing a tool that can be used to query as much system information as possible from user mode (to be finished and tested only under nt4sp4/x86; it was NOT tested under ROS: it crashes immediately and needs NtQuerySystemInformation implemented!). svn path=/trunk/; revision=1137
186 lines
3.8 KiB
C
186 lines
3.8 KiB
C
/* $Id: shutdown.c,v 1.2 2000/04/25 23:22:57 ea Exp $
|
|
*
|
|
* EAU shutdown.c 1.4.1
|
|
*
|
|
* Copyright (C) 1997,1998,1999 Emanuele Aliberti
|
|
*
|
|
* --------------------------------------------------------------------
|
|
*
|
|
* This software is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Library General Public License as
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
* License, or (at your option) any later version.
|
|
*
|
|
* This software is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Library General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Library General Public
|
|
* License along with this software; see the file COPYING.LIB. If
|
|
* not, write to the Free Software Foundation, Inc., 675 Mass Ave,
|
|
* Cambridge, MA 02139, USA.
|
|
*
|
|
* --------------------------------------------------------------------
|
|
* 1999-05-14 (Emanuele Aliberti)
|
|
* Released version 1.4.1 under GNU GPL for the ReactOS project.
|
|
* --------------------------------------------------------------------
|
|
*/
|
|
#define UNICODE
|
|
#define _UNICODE
|
|
#include <windows.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <tchar.h>
|
|
#include "win32err.h"
|
|
|
|
#ifndef SE_PRIVILEGE_ENABLED
|
|
#define NTOS_MODE_USER
|
|
#include <ntos.h>
|
|
#endif
|
|
|
|
|
|
struct _EWX
|
|
{
|
|
CHAR mode;
|
|
UINT id;
|
|
};
|
|
|
|
static
|
|
struct _EWX modes[] =
|
|
{
|
|
{ 'f', EWX_FORCE },
|
|
{ 'l', EWX_LOGOFF },
|
|
{ 'p', EWX_POWEROFF },
|
|
{ 'r', EWX_REBOOT },
|
|
{ 's', EWX_SHUTDOWN },
|
|
{ 0, 0 }
|
|
};
|
|
|
|
|
|
static
|
|
UINT
|
|
DecodeArg( CHAR * modestr )
|
|
{
|
|
register int i;
|
|
|
|
if (modestr[0] != '-' && modestr[0] != '/')
|
|
{
|
|
return (UINT) -1;
|
|
}
|
|
for ( i = 0; modes[i].mode; ++i)
|
|
{
|
|
if (modestr[1] == modes[i].mode)
|
|
{
|
|
return modes[i].id;
|
|
}
|
|
}
|
|
return (UINT) -1;
|
|
}
|
|
|
|
|
|
|
|
static
|
|
const
|
|
char * usage = "\
|
|
Shutdown ver. 1.4.1 (compiled on %s, at %s)\n\
|
|
Copyright (C) 1997-1999 Emanuele Aliberti\n\n\
|
|
usage: %s [-f] [-l] [-p] [-r] [-s]\n\
|
|
f (FORCE) processes are unconditionally terminated\n\
|
|
l (LOGOFF) logs the current user off\n\
|
|
p (POWEROFF) turns off the power, if possibile\n\
|
|
r (REBOOT) reboots the system\n\
|
|
s (SHUTDOWN) shuts down the system to a point at which\n\
|
|
it is safe to turn off the power\n\n\
|
|
Any other letter will print this help message.\n";
|
|
|
|
int
|
|
main(
|
|
int argc,
|
|
char * argv []
|
|
)
|
|
{
|
|
UINT mode;
|
|
HANDLE h;
|
|
TOKEN_PRIVILEGES tp;
|
|
|
|
mode = (argc == 2)
|
|
? DecodeArg(argv[1])
|
|
: DecodeArg("-?");
|
|
if (mode == (UINT) -1)
|
|
{
|
|
fprintf(
|
|
stderr,
|
|
usage,
|
|
__DATE__,
|
|
__TIME__,
|
|
argv[0]
|
|
);
|
|
return EXIT_SUCCESS;
|
|
}
|
|
/*
|
|
* Get the current process token handle
|
|
* so we can get shutdown privilege.
|
|
*/
|
|
if (FALSE == OpenProcessToken(
|
|
GetCurrentProcess(),
|
|
(TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY),
|
|
& h
|
|
)
|
|
) {
|
|
PrintWin32Error(
|
|
L"while opening the process",
|
|
GetLastError()
|
|
);
|
|
return EXIT_FAILURE;
|
|
}
|
|
/*
|
|
* Get the LUID for shutdown privilege.
|
|
*/
|
|
if (FALSE == LookupPrivilegeValue(
|
|
NULL,
|
|
SE_SHUTDOWN_NAME,
|
|
& tp.Privileges[0].Luid
|
|
)
|
|
) {
|
|
PrintWin32Error(
|
|
L"while looking up privileges",
|
|
GetLastError()
|
|
);
|
|
return EXIT_FAILURE;
|
|
}
|
|
tp.PrivilegeCount = 1; /* One privilege to seat */
|
|
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
|
|
/*
|
|
* Get shutdown privilege for this process.
|
|
*/
|
|
if (FALSE == AdjustTokenPrivileges(
|
|
h,
|
|
FALSE,
|
|
& tp,
|
|
0,
|
|
(PTOKEN_PRIVILEGES) NULL,
|
|
0
|
|
)
|
|
) {
|
|
PrintWin32Error(
|
|
L"while adjusting shutdown privilege",
|
|
GetLastError()
|
|
);
|
|
return EXIT_FAILURE;
|
|
}
|
|
/* Now really exit! */
|
|
if (FALSE == ExitWindowsEx(mode, 0))
|
|
{
|
|
PrintWin32Error(
|
|
L"ExitWindowsEx",
|
|
GetLastError()
|
|
);
|
|
return EXIT_FAILURE;
|
|
}
|
|
return EXIT_SUCCESS;
|
|
}
|
|
|
|
|
|
/* EOF */
|
|
|