taskkill: Disallow process self-termination.

This commit is contained in:
Andrew Nguyen 2010-10-11 05:13:43 -05:00 committed by Alexandre Julliard
parent 76e7fcc9d8
commit fbcf44aa23
3 changed files with 32 additions and 0 deletions

View File

@ -38,4 +38,5 @@ STRINGTABLE
STRING_SEARCH_FAILED, "Error: Could not find process \"%s\".\n" STRING_SEARCH_FAILED, "Error: Could not find process \"%s\".\n"
STRING_ENUM_FAILED, "Error: Unable to enumerate the process list.\n" STRING_ENUM_FAILED, "Error: Unable to enumerate the process list.\n"
STRING_TERMINATE_FAILED, "Error: Unable to terminate process \"%s\".\n" STRING_TERMINATE_FAILED, "Error: Unable to terminate process \"%s\".\n"
STRING_SELF_TERMINATION, "Error: Process self-termination is not permitted.\n"
} }

View File

@ -204,6 +204,7 @@ static BOOL get_process_name_from_pid(DWORD pid, WCHAR *buf, DWORD chars)
static int send_close_messages(void) static int send_close_messages(void)
{ {
DWORD *pid_list, pid_list_size; DWORD *pid_list, pid_list_size;
DWORD self_pid = GetCurrentProcessId();
unsigned int i; unsigned int i;
int status_code = 0; int status_code = 0;
@ -234,6 +235,13 @@ static int send_close_messages(void)
DWORD pid = atoiW(task_list[i]); DWORD pid = atoiW(task_list[i]);
struct pid_close_info info = { pid }; struct pid_close_info info = { pid };
if (pid == self_pid)
{
taskkill_message(STRING_SELF_TERMINATION);
status_code = 1;
continue;
}
EnumWindows(pid_enum_proc, (LPARAM)&info); EnumWindows(pid_enum_proc, (LPARAM)&info);
if (info.found) if (info.found)
taskkill_message_printfW(STRING_CLOSE_PID_SEARCH, pid); taskkill_message_printfW(STRING_CLOSE_PID_SEARCH, pid);
@ -258,6 +266,13 @@ static int send_close_messages(void)
struct pid_close_info info = { pid_list[index] }; struct pid_close_info info = { pid_list[index] };
found_process = TRUE; found_process = TRUE;
if (pid_list[index] == self_pid)
{
taskkill_message(STRING_SELF_TERMINATION);
status_code = 1;
continue;
}
EnumWindows(pid_enum_proc, (LPARAM)&info); EnumWindows(pid_enum_proc, (LPARAM)&info);
taskkill_message_printfW(STRING_CLOSE_PROC_SRCH, process_name, pid_list[index]); taskkill_message_printfW(STRING_CLOSE_PROC_SRCH, process_name, pid_list[index]);
} }
@ -278,6 +293,7 @@ static int send_close_messages(void)
static int terminate_processes(void) static int terminate_processes(void)
{ {
DWORD *pid_list, pid_list_size; DWORD *pid_list, pid_list_size;
DWORD self_pid = GetCurrentProcessId();
unsigned int i; unsigned int i;
int status_code = 0; int status_code = 0;
@ -308,6 +324,13 @@ static int terminate_processes(void)
DWORD pid = atoiW(task_list[i]); DWORD pid = atoiW(task_list[i]);
HANDLE process; HANDLE process;
if (pid == self_pid)
{
taskkill_message(STRING_SELF_TERMINATION);
status_code = 1;
continue;
}
process = OpenProcess(PROCESS_TERMINATE, FALSE, pid); process = OpenProcess(PROCESS_TERMINATE, FALSE, pid);
if (!process) if (!process)
{ {
@ -341,6 +364,13 @@ static int terminate_processes(void)
{ {
HANDLE process; HANDLE process;
if (pid_list[index] == self_pid)
{
taskkill_message(STRING_SELF_TERMINATION);
status_code = 1;
continue;
}
process = OpenProcess(PROCESS_TERMINATE, FALSE, pid_list[index]); process = OpenProcess(PROCESS_TERMINATE, FALSE, pid_list[index]);
if (!process) if (!process)
{ {

View File

@ -34,3 +34,4 @@
#define STRING_SEARCH_FAILED 111 #define STRING_SEARCH_FAILED 111
#define STRING_ENUM_FAILED 112 #define STRING_ENUM_FAILED 112
#define STRING_TERMINATE_FAILED 113 #define STRING_TERMINATE_FAILED 113
#define STRING_SELF_TERMINATION 114