end18 / psutil

Automatically exported from code.google.com/p/psutil
Other
0 stars 0 forks source link

An InsufficientPrivilegesError exception is needed #21

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

Windows:

1. Log in as a limited user (not Administrator)
2. Attempt to fetch some information from a process owned by a
high-privileged user:

>>> import psutil
>>> p = psutil.Process(1016)  # svchost.exe owned by "SYSTEM" 
>>> p.name
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python26\Lib\site-packages\psutil\psutil.py", line 106, in name
    self.deproxy()
  File "C:\Python26\Lib\site-packages\psutil\psutil.py", line 65, in deproxy
    self._procinfo = _platform_impl.get_process_info(self._procinfo.pid)
  File "C:\Python26\Lib\site-packages\psutil\_psmswindows.py", line 17, in
get_process_info
    infoTuple = _psutil_mswindows.get_process_info(pid)
WindowsError: [Error 5] Access denied
>>>

Linux:

1. Log in as a limited user
2. Attempt to kill a process owned by root (fetching process info is
permitted):

user@ubuntu:~$ whoami
user
user@ubuntu:~$ python
Python 2.4.6 (#1, Jan 26 2009, 11:40:33)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import psutil
>>> p = psutil.Process(1)
>>> p.name
'init'
>>> p.kill()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/local/lib/python2.4/site-packages/psutil/psutil.py", line 136,
in kill
    _platform_impl.kill_process(self.pid, sig)
  File "/usr/local/lib/python2.4/site-packages/psutil/_pslinux.py", line
67, in kill_process
    os.kill(pid, sig)
OSError: [Errno 1] Operation not permitted

What is the expected output? What do you see instead?
I expect a unique psutil.InsufficientPrivilegesError exception to be raised
on all systems instead of OSError, WindowsError or anything else.
*When* exactly raising the exception (e.g. when instantiating the class or
when accessing properties) needs to be discussed.

Original issue reported on code.google.com by billiej...@gmail.com on 23 Feb 2009 at 5:11

GoogleCodeExporter commented 9 years ago
You can wrap the call to get_process_info() in deproxy() and just raise the 
exception
from there. That would be easier than having to write the exception into the C 
code
for every platform like we had to do for NoSuchProcess exceptions.

Original comment by jlo...@gmail.com on 23 Feb 2009 at 5:54

GoogleCodeExporter commented 9 years ago
Committed as r154 which adds an InsufficientPermission error class in psutil.py 
and a
"wrap_privileges" decorator around get_process_info() and kill() methods, which
translates system-dependent exceptions signaling insufficient permissions into
InsufficientPermission's psutil exception.

Open issues:

- Do we want an alternative name for InsufficientPermission (e.g.
InsufficientPermissionError, NoSuchPermission/Error, AccessDenied/Error)?

- More test cases would be needed. I've only added a test case for posix 
platforms
based on os.getuid() > 0 to make sure that InsufficientPermission is raised 
when a
limited user attempts to kill PID 1 (init), but there are currently no test 
cases for
Windows.

Original comment by billiej...@gmail.com on 24 Feb 2009 at 1:00

GoogleCodeExporter commented 9 years ago

Original comment by billiej...@gmail.com on 24 Feb 2009 at 5:25

GoogleCodeExporter commented 9 years ago
Per conversation with Jay renamed InsufficientPermission in AccessDenied.

Original comment by billiej...@gmail.com on 24 Feb 2009 at 10:14

GoogleCodeExporter commented 9 years ago

Original comment by billiej...@gmail.com on 24 Feb 2009 at 10:16

GoogleCodeExporter commented 9 years ago
Is this one done now? I think we can close this out since it's implemented on 
all
platforms?

Original comment by jlo...@gmail.com on 25 Feb 2009 at 2:56

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Yes, I can't think of any way to test this on Windows so we can just close this 
one out.

Original comment by billiej...@gmail.com on 25 Feb 2009 at 3:34

GoogleCodeExporter commented 9 years ago

Original comment by billiej...@gmail.com on 17 Mar 2009 at 3:31

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Updated csets after the SVN -> Mercurial migration:
r154 == revision 3b9087cefb58

Original comment by g.rodola on 2 Mar 2013 at 11:44