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, same effective user ID as that of this program. Otherwise,
returns None. returns None.
""" """
identity = os.getresuid() identity = psutil.Process(os.getpid()).uids
for proc in psutil.process_iter(): for proc in psutil.process_iter():
if (proc.name == "gpg-agent") and proc.is_running: if (proc.name == "gpg-agent") and proc.is_running:
log.debug("Found gpg-agent process with pid %d" % proc.pid) log.debug("Found gpg-agent process with pid %d" % proc.pid)

View File

@ -298,7 +298,7 @@ def _sanitise(*args):
values = value.split(' ') values = value.split(' ')
for v in values: for v in values:
## these can be handled separately, without _fix_unsafe(), ## 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): if (flag in none_options) and (v is None):
continue continue
@ -332,8 +332,11 @@ def _sanitise(*args):
if flag in ['--encrypt', '--encrypt-files', '--decrypt', if flag in ['--encrypt', '--encrypt-files', '--decrypt',
'--decrypt-files', '--import', '--verify']: '--decrypt-files', '--import', '--verify']:
if _util._is_file(val): checked += (val + " ") if _util._is_file(val) or \
else: log.debug("%s not file: %s" % (flag, val)) (flag == '--verify' and val == '-'):
checked += (val + " ")
else:
log.debug("%s not file: %s" % (flag, val))
elif flag in ['--cipher-algo', '--personal-cipher-prefs', elif flag in ['--cipher-algo', '--personal-cipher-prefs',
'--personal-cipher-preferences']: '--personal-cipher-preferences']:
@ -372,7 +375,8 @@ def _sanitise(*args):
groups[last] = str(filo.pop()) groups[last] = str(filo.pop())
## accept the read-from-stdin arg: ## accept the read-from-stdin arg:
if len(filo) >= 1 and filo[len(filo)-1] == '-': if len(filo) >= 1 and filo[len(filo)-1] == '-':
groups[last] += str(' - \'\'') ## gross hack groups[last] += str(' - ') ## gross hack
filo.pop()
else: else:
groups[last] = str() groups[last] = str()
while len(filo) > 1 and not is_flag(filo[len(filo)-1]): 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 codecs
import encodings import encodings
import os import os
import psutil
import threading import threading
import random import random
import re import re
@ -270,6 +271,8 @@ def _find_binary(binary=None):
except IndexError as ie: except IndexError as ie:
log.info("Could not determine absolute path of binary: '%s'" log.info("Could not determine absolute path of binary: '%s'"
% binary) % binary)
elif os.access(binary, os.X_OK):
found = binary
if found is None: if found is None:
try: found = _which('gpg')[0] try: found = _which('gpg')[0]
except IndexError as ie: except IndexError as ie:
@ -393,7 +396,7 @@ def _make_passphrase(length=None, save=False, file=None):
passphrase = _make_random_string(length) passphrase = _make_random_string(length)
if save: if save:
ruid, euid, suid = os.getresuid() ruid, euid, suid = psutil.Process(os.getpid()).uids
gid = os.getgid() gid = os.getgid()
now = mktime(localtime()) now = mktime(localtime())

View File

@ -308,7 +308,7 @@ class GPG(GPGBase):
sig_fh = None sig_fh = None
try: try:
sig_fh = open(sig_file) sig_fh = open(sig_file)
args = ["--verify %s - " % sig_fh.name] args = ["--verify %s -" % sig_fh.name]
proc = self._open_subprocess(args) proc = self._open_subprocess(args)
writer = _util._threaded_copy_data(file, proc.stdin) writer = _util._threaded_copy_data(file, proc.stdin)
self._collect_output(proc, result, stdin=proc.stdin) self._collect_output(proc, result, stdin=proc.stdin)
@ -557,18 +557,20 @@ class GPG(GPGBase):
fpr = str(key.fingerprint) fpr = str(key.fingerprint)
if len(fpr) == 20: if len(fpr) == 20:
if self.temp_keyring or self.temp_secring: for d in map(lambda x: os.path.dirname(x),
if not os.path.exists(self._keys_dir): [self.temp_keyring, self.temp_secring]):
os.makedirs(self._keys_dir) if not os.path.exists(d):
prefix = os.path.join(self._keys_dir, fpr) os.makedirs(d)
if self.temp_keyring: if self.temp_keyring:
if os.path.isfile(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") try: os.rename(self.temp_keyring, prefix+".pubring")
except OSError as ose: log.error(ose.message) except OSError as ose: log.error(ose.message)
if self.temp_secring: if self.temp_secring:
if os.path.isfile(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") try: os.rename(self.temp_secring, prefix+".secring")
except OSError as ose: log.error(ose.message) except OSError as ose: log.error(ose.message)

View File

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