Use process uids and usernames on Unix and Windows respectively.
Windows doesn't have EUIDs, so instead we'll check that the usernames match. This doesn't seem the least bit secure to me, but it's Windows so they're probably owned anyway. If anyone knows one of the "proper" ways to determine if another process has the same owner on Windows, I'd love to know about it. * FIXES Issue #58 but I don't have a Windows machine to test so maybe it's still broken. https://github.com/isislovecruft/python-gnupg/issues/58fix/58-win32-uid
parent
cc959c755d
commit
a1e4a8a756
|
@ -75,19 +75,40 @@ class GPGMeta(type):
|
|||
instance containing the gpg-agent process' information to
|
||||
``cls._agent_proc``.
|
||||
|
||||
For Unix systems, we check that the effective UID of this
|
||||
``python-gnupg`` process is also the owner of the gpg-agent
|
||||
process. For Windows, we check that the usernames of the owners are
|
||||
the same. (Sorry Windows users; maybe you should switch to anything
|
||||
else.)
|
||||
|
||||
:returns: True if there exists a gpg-agent process running under the
|
||||
same effective user ID as that of this program. Otherwise,
|
||||
returns None.
|
||||
returns False.
|
||||
"""
|
||||
identity = psutil.Process(os.getpid()).uids
|
||||
this_process = psutil.Process(os.getpid())
|
||||
ownership_match = False
|
||||
|
||||
if _util._running_windows:
|
||||
identity = this_process.username()
|
||||
else:
|
||||
identity = this_process.uids
|
||||
|
||||
for proc in psutil.process_iter():
|
||||
if (proc.name == "gpg-agent") and proc.is_running:
|
||||
log.debug("Found gpg-agent process with pid %d" % proc.pid)
|
||||
if proc.uids == identity:
|
||||
log.debug(
|
||||
"Effective UIDs of this process and gpg-agent match")
|
||||
setattr(cls, '_agent_proc', proc)
|
||||
return True
|
||||
if _util._running_windows:
|
||||
if proc.username() == identity:
|
||||
ownership_match = True
|
||||
else:
|
||||
if proc.uids == identity:
|
||||
ownership_match = True
|
||||
|
||||
if ownership_match:
|
||||
log.debug("Effective UIDs of this process and gpg-agent match")
|
||||
setattr(cls, '_agent_proc', proc)
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
class GPGBase(object):
|
||||
|
|
|
@ -56,6 +56,9 @@ try:
|
|||
except NameError:
|
||||
_py3k = True
|
||||
|
||||
_running_windows = False
|
||||
if "win" in sys.platform:
|
||||
_running_windows = True
|
||||
|
||||
## Directory shortcuts:
|
||||
## we don't want to use this one because it writes to the install dir:
|
||||
|
|
Loading…
Reference in New Issue