Merge remote-tracking branch 'drebs/bug/fix-os.getresuid-not-supported-on-os-x' into develop

hotfix/pin-psutil-version
Isis Lovecruft 2013-12-02 23:30:02 +00:00
commit b1bc36e718
No known key found for this signature in database
GPG Key ID: 5C17776E27F7E84D
5 changed files with 21 additions and 13 deletions

View File

@ -75,7 +75,7 @@ class GPGMeta(type):
same effective user ID as that of this program. Otherwise,
returns None.
"""
identity = os.getresuid()
identity = psutil.Process(os.getpid()).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)

View File

@ -298,7 +298,7 @@ def _sanitise(*args):
values = value.split(' ')
for v in values:
## these can be handled separately, without _fix_unsafe(),
## because they are only allowed if the pass the regex
## because they are only allowed if they pass the regex
if (flag in none_options) and (v is None):
continue
@ -332,8 +332,11 @@ def _sanitise(*args):
if flag in ['--encrypt', '--encrypt-files', '--decrypt',
'--decrypt-files', '--import', '--verify']:
if _util._is_file(val): checked += (val + " ")
else: log.debug("%s not file: %s" % (flag, val))
if _util._is_file(val) or \
(flag == '--verify' and val == '-'):
checked += (val + " ")
else:
log.debug("%s not file: %s" % (flag, val))
elif flag in ['--cipher-algo', '--personal-cipher-prefs',
'--personal-cipher-preferences']:
@ -372,7 +375,8 @@ def _sanitise(*args):
groups[last] = str(filo.pop())
## accept the read-from-stdin arg:
if len(filo) >= 1 and filo[len(filo)-1] == '-':
groups[last] += str(' - \'\'') ## gross hack
groups[last] += str(' - ') ## gross hack
filo.pop()
else:
groups[last] = str()
while len(filo) > 1 and not is_flag(filo[len(filo)-1]):

View File

@ -31,6 +31,7 @@ from time import mktime
import codecs
import encodings
import os
import psutil
import threading
import random
import re
@ -270,6 +271,8 @@ def _find_binary(binary=None):
except IndexError as ie:
log.info("Could not determine absolute path of binary: '%s'"
% binary)
elif os.access(binary, os.X_OK):
found = binary
if found is None:
try: found = _which('gpg')[0]
except IndexError as ie:
@ -393,7 +396,7 @@ def _make_passphrase(length=None, save=False, file=None):
passphrase = _make_random_string(length)
if save:
ruid, euid, suid = os.getresuid()
ruid, euid, suid = psutil.Process(os.getpid()).uids
gid = os.getgid()
now = mktime(localtime())

View File

@ -557,18 +557,20 @@ class GPG(GPGBase):
fpr = str(key.fingerprint)
if len(fpr) == 20:
if self.temp_keyring or self.temp_secring:
if not os.path.exists(self._keys_dir):
os.makedirs(self._keys_dir)
prefix = os.path.join(self._keys_dir, fpr)
for d in map(lambda x: os.path.dirname(x),
[self.temp_keyring, self.temp_secring]):
if not os.path.exists(d):
os.makedirs(d)
if self.temp_keyring:
if os.path.isfile(self.temp_keyring):
prefix = os.path.join(self.temp_keyring, fpr)
try: os.rename(self.temp_keyring, prefix+".pubring")
except OSError as ose: log.error(ose.message)
if self.temp_secring:
if os.path.isfile(self.temp_secring):
prefix = os.path.join(self.temp_secring, fpr)
try: os.rename(self.temp_secring, prefix+".secring")
except OSError as ose: log.error(ose.message)

View File

@ -173,7 +173,6 @@ class GPGTestCase(unittest.TestCase):
self.keyring = self.gpg.keyring
self.secring = self.gpg.secring
self.insecure_prng = False
self.gpg._keys_dir = os.path.join(_files, 'generated-keys')
def tearDown(self):
"""This is called once per self.test_* method after the test run."""
@ -523,7 +522,7 @@ class GPGTestCase(unittest.TestCase):
self.assertIsNotNone(key)
self.assertNotEquals(key, "")
self.assertGreater(len(str(key)), 0)
keyfile = os.path.join(self.gpg._keys_dir, 'test_key_3.pub')
keyfile = os.path.join(_files, 'test_key_3.pub')
log.debug("Storing downloaded key as %s" % keyfile)
with open(keyfile, 'w') as fh:
fh.write(str(key))