[rob2: Re: killing processes owned by others with kill.exe]

Christopher Faylor cgf@redhat.com
Fri Mar 12 23:43:00 GMT 2004


Corinna, Pierre,

I've regenned this as a diff -up patch.

Does it make make any sense at all?

cgf

----- Forwarded message from "Rob S.i.k.l.o.s" <rob2> -----

From: "Rob S.i.k.l.o.s"
Subject: Re: killing processes owned by others with kill.exe
Date: Tue, 9 Mar 2004 13:28:54 -0500
X-IsSubscribed: yes

Hello,

patch attached (diff kill.orig.cc kill.new.cc > kill.cc.patch)

It's taken from the latest source that I got from setup.exe (sorry, no
access to cvs behind firewall).

Just a note, when I tried to make from /usr/src/cygwin-1.5.7-1, I get the
following error:
  make[3]: Entering directory
`/usr/src/cygwin-1.5.7-1/i686-pc-cygwin/winsup/cygserver'
  make[3]: *** No rule to make target
`/src/cygwin-1.5.7-1/winsup/cygwin/winsup.h', needed by `libclient.o'.
Stop.


Rob.

----- End forwarded message -----
-------------- next part --------------
Index: kill.cc
===================================================================
RCS file: /cvs/uberbaum/winsup/utils/kill.cc,v
retrieving revision 1.22
diff -u -p -r1.22 kill.cc
--- kill.cc	20 Sep 2003 20:24:33 -0000	1.22
+++ kill.cc	9 Mar 2004 22:01:51 -0000
@@ -125,9 +125,38 @@ listsig (const char *in_sig)
     }
 }
 
+static void
+getDebugPriv( void )
+{
+  HANDLE hToken;
+  LUID sedebugnameValue;
+  TOKEN_PRIVILEGES tkp;
+
+  if ( ! OpenProcessToken( GetCurrentProcess(),
+    TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken ) )
+    return;
+
+  if ( !LookupPrivilegeValue( NULL, SE_DEBUG_NAME, &sedebugnameValue ) )
+  {
+    CloseHandle( hToken );
+    return;
+  }
+
+  tkp.PrivilegeCount = 1;
+  tkp.Privileges[0].Luid = sedebugnameValue;
+  tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
+
+  AdjustTokenPrivileges( hToken, FALSE, &tkp, sizeof tkp, NULL, NULL );
+
+  CloseHandle( hToken );
+}
+
 static void __stdcall
 forcekill (int pid, int sig, int wait)
 {
+  // try to acquire SeDebugPrivilege
+  getDebugPriv();
+
   external_pinfo *p = (external_pinfo *) cygwin_internal (CW_GETPINFO_FULL, pid);
   DWORD dwpid = p ? p->dwProcessId : (DWORD) pid;
   HANDLE h = OpenProcess (PROCESS_TERMINATE, FALSE, (DWORD) dwpid);
@@ -254,3 +283,4 @@ out:
     }
   return ret;
 }
+


More information about the Cygwin-developers mailing list