Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An InsufficientPrivilegesError exception is needed #21

Closed
giampaolo opened this issue May 23, 2014 · 9 comments
Closed

An InsufficientPrivilegesError exception is needed #21

giampaolo opened this issue May 23, 2014 · 9 comments

Comments

@giampaolo
Copy link
Owner

From billiej...@gmail.com on February 23, 2009 18:11:52

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: http://code.google.com/p/psutil/issues/detail?id=21

@giampaolo
Copy link
Owner Author

From jlo...@gmail.com on February 23, 2009 09:54:35

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

Status: Accepted
Owner: billiejoex

@giampaolo
Copy link
Owner Author

From billiej...@gmail.com on February 24, 2009 05:00:53

Committed as r154 which adds an InsufficientPermission error class in psutil.py 
"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 
based on os.getuid() > 0 to make sure that InsufficientPermission is raised 
limited user attempts to kill PID 1 (init), but there are currently no test 
Windows.

@giampaolo
Copy link
Owner Author

From billiej...@gmail.com on February 24, 2009 09:25:29

Status: Started

@giampaolo
Copy link
Owner Author

From billiej...@gmail.com on February 24, 2009 14:14:06

Per conversation with Jay renamed InsufficientPermission in AccessDenied.

@giampaolo
Copy link
Owner Author

From billiej...@gmail.com on February 24, 2009 14:16:36

Labels: Milestone-0.1.1

@giampaolo
Copy link
Owner Author

From jlo...@gmail.com on February 25, 2009 06:56:44

Is this one done now? I think we can close this out since it's implemented on 
platforms?

@giampaolo
Copy link
Owner Author

From billiej...@gmail.com on February 25, 2009 07:34:41

Yes, I can't think of any way to test this on Windows so we can just close this 

@giampaolo
Copy link
Owner Author

From billiej...@gmail.com on March 17, 2009 08:31:20

Status: Fixed

@giampaolo
Copy link
Owner Author

From g.rodola on March 02, 2013 03:44:09

Updated csets after the SVN -> Mercurial migration: r154 == revision 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant