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

use krb5-config to get the kerberos installation PREFIX #31

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion k5test/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def _decide_plugin_dir(dirs):
def _find_plugin_dirs_installed(search_path):
try:
options_raw = get_output(
"find %s/ -type d \( ! -executable -o ! -readable \) "
"find %s/ -type d \\( ! -executable -o ! -readable \\) "
"-prune -o "
'-type d -path "*/krb5/plugins" -print' % search_path,
stderr=subprocess.STDOUT,
Expand Down
65 changes: 40 additions & 25 deletions k5test/realm.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ def __new__(cls, *args, **kwargs):
provider_cls = cls

if provider_cls == K5Realm:
krb5_config = _discover_path("krb5-config", "/usr/bin/krb5-config", kwargs)
krb5_config = os.environ.get(
"KRB5CONFIG",
_discover_path("krb5-config", "/usr/bin/krb5-config", kwargs),
)

try:
krb5_version = subprocess.check_output(
Expand Down Expand Up @@ -152,7 +155,23 @@ def __init__(

self._daemons = []

self._init_paths(**paths)
krb5_config = os.environ.get(
"KRB5CONFIG", _discover_path("krb5-config", "/usr/bin/krb5-config", paths)
)
try:
self._krb5_prefix = (
subprocess.check_output([krb5_config, "--prefix"])
.decode(sys.getfilesystemencoding() or sys.getdefaultencoding())
.strip()
)
except Exception as e:
self._krb5_prefix = "/usr"
_LOG.warning(
f"Failed to determine krb5 installation PREFIX, defaulting to '{self._krb5_prefix}'."
)

for attr, value in self._default_paths:
setattr(self, attr, value)

if existing is None:
self._create_conf(_cfg_merge(self._krb5_conf, krb5_conf), krb5_conf_path)
Expand Down Expand Up @@ -246,11 +265,6 @@ def start_kdc(self, args=None, env=None):
def start_kadmind(self, env=None):
pass

def _init_paths(self, **paths):
for attr, name, default in self._default_paths:
value = _discover_path(name, default, paths)
setattr(self, attr, value)

def _create_conf(self, profile, filename):
with open(filename, "w") as conf_file:
for section, contents in profile.items():
Expand Down Expand Up @@ -456,14 +470,14 @@ def provider(self):
@property
def _default_paths(self):
return [
("kdb5_util", "kdb5_util", "/usr/sbin/kdb5_util"),
("krb5kdc", "krb5kdc", "/usr/sbin/krb5kdc"),
("kadmin", "kadmin", "/usr/bin/kadmin"),
("kadmin_local", "kadmin.local", "/usr/sbin/kadmin.local"),
("kadmind", "kadmind", "/usr/sbin/kadmind"),
("kprop", "kprop", "/usr/sbin/kprop"),
("_kinit", "kinit", "/usr/bin/kinit"),
("_klist", "klist", "/usr/bin/klist"),
("kdb5_util", self._krb5_prefix + "/sbin/kdb5_util"),
("krb5kdc", self._krb5_prefix + "/sbin/krb5kdc"),
("kadmin", self._krb5_prefix + "/bin/kadmin"),
("kadmin_local", self._krb5_prefix + "/sbin/kadmin.local"),
("kadmind", self._krb5_prefix + "/sbin/kadmind"),
("kprop", self._krb5_prefix + "/sbin/kprop"),
("_kinit", self._krb5_prefix + "/bin/kinit"),
("_klist", self._krb5_prefix + "/bin/klist"),
]

@property
Expand Down Expand Up @@ -619,18 +633,19 @@ def provider(self):

@property
def _default_paths(self):
base = "/System/Library/PrivateFrameworks/Heimdal.framework/Helpers"
if sys.platform != "darwin":
base = "/usr/libexec"
if sys.platform == "darwin":
libexec = "/System/Library/PrivateFrameworks/Heimdal.framework/Helpers"
else:
libexec = self._krb5_prefix + "/libexec"

return [
("krb5kdc", "kdc", os.path.join(base, "kdc")),
("kadmin", "kadmin", "/usr/bin/kadmin"),
("kadmin_local", "kadmin", "/usr/bin/kadmin"),
("kadmind", "kadmind", os.path.join(base, "kadmind")),
("_kinit", "kinit", "/usr/bin/kinit"),
("_klist", "klist", "/usr/bin/klist"),
("_ktutil", "ktutil", "/usr/bin/ktutil"),
("krb5kdc", libexec + "/kdc"),
("kadmind", libexec + "/kadmind"),
("kadmin", self._krb5_prefix + "/bin/kadmin"),
("kadmin_local", self._krb5_prefix + "/bin/kadmin"),
("_kinit", self._krb5_prefix + "/bin/kinit"),
("_klist", self._krb5_prefix + "/bin/klist"),
("_ktutil", self._krb5_prefix + "/bin/ktutil"),
]

@property
Expand Down
Loading