Skip to content

Commit b649060

Browse files
committed
Honor path when retrieving K5Test utilities
This commit makes k5test.py honor the setting $PATH when calling the various utilities it uses to set up its environment (technically it uses `which`, so if your `which` binary does something else, you may have a problem).
1 parent dec88d0 commit b649060

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

gssapi/tests/k5test.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import signal
3131
import socket
3232
import string
33+
import sys
3334
import subprocess
3435
import tempfile
3536
import unittest
@@ -150,15 +151,36 @@ def __init__(self, realm='KRBTEST.COM', portbase=61000,
150151
self.kinit(self.user_princ, self.password('user'))
151152
self.klist()
152153

154+
def _discover_path(self, name, default, paths):
155+
stderr_out = getattr(subprocess, 'DEVNULL', subprocess.PIPE)
156+
try:
157+
path = subprocess.check_output(['which', name],
158+
stderr=stderr_out).strip()
159+
path = path.decode(sys.getfilesystemencoding() or
160+
sys.getdefaultencoding())
161+
print("Using discovered path for {name} ({path}".format(
162+
name=name, path=path))
163+
return path
164+
except subprocess.CalledProcessError as e:
165+
path = paths.get(name, default)
166+
print("Using default path for {name} ({path}): {err}".format(
167+
name=name, path=path, err=e))
168+
return path
169+
153170
def _init_paths(self, **paths):
154-
self.kdb5_util = paths.get('kdb5_util', '/usr/sbin/kdb5_util')
155-
self.krb5kdc = paths.get('krb5kdc', '/usr/sbin/krb5kdc')
156-
self.kadmin_local = paths.get('kadmin_local', '/usr/sbin/kadmin.local')
157-
self.kprop = paths.get('kprop', '/usr/sbin/kprop')
158-
self.kadmind = paths.get('kadmind', '/usr/sbin/kadmind')
159-
160-
self._kinit = paths.get('kinit', '/usr/bin/kinit')
161-
self._klist = paths.get('klist', '/usr/bin/klist')
171+
self.kdb5_util = self._discover_path('kdb5_util',
172+
'/usr/sbin/kdb5_util', paths)
173+
self.krb5kdc = self._discover_path('krb5kdc',
174+
'/usr/sbin/krb5kdc', paths)
175+
self.kadmin_local = self._discover_path('kadmin_local',
176+
'/usr/sbin/kadmin.local',
177+
paths)
178+
self.kprop = self._discover_path('kprop', '/usr/sbin/kprop', paths)
179+
self.kadmind = self._discover_path('kadmind',
180+
'/usr/sbin/kadmind', paths)
181+
182+
self._kinit = self._discover_path('kinit', '/usr/bin/kinit', paths)
183+
self._klist = self._discover_path('klist', '/usr/bin/klist', paths)
162184

163185
def _create_conf(self, profile, filename):
164186
with open(filename, 'w') as conf_file:

0 commit comments

Comments
 (0)