\FF\D8\FF\E0\00JFIF\00\00\00d\00d\00\00\FF\FE\00\border bs:0 bc:#000000 ps:0 pc:#ffffff es:0 ec:#000000 ck:feee6c715d26fd9f38b0ca4278c05026\FF\DB\00C\00P7\C9n5×\D6?\BDê\9Ds\EBp\9F[`8m\B7)o\B5\E8\E6I\99\FE3]]A2\BA\8Cw\D6E\93\\DEv\C8\009\F2\F1NI?uc\\F5\EA\96k\xN<~buv\EA\C8\D7 \8B\84\CEcxI\BBg\AE\9E=\D6+n\EC\80\C8A\8C\AE\EB\CF\D5\DA\E9"2\A4\B9j5\EB\F3W\B63\96\B30Yu\DA\FC8\ED\DF\E7Ms\FB\F1\8E\B3\FA\EA\E8\E6(\883zs\F2_\8DFk\8Bh \00\8C\DCw\D3R\B5+6X\BA\B2\C4j\AB0\B4\FCMw\C2I\8E\9B\E3\A9~9u\FA\D3l\80\C8%p\EE\FDn2€ \00 $\FEj\C4e\A9\DB\~\95\A7\A5\80EK\BB\8DDsP\00@@AD'k\CF\E8\DB\D2(\80\9AK\D3\85\D6lb\F2\BA\8C*\80\00)\95 59\A3R:\F3\CE"\B6\80\88\00\00i1u4ê\E9\F2á\A6\A2\FACM\93WMb*\E0*\00\00\00\00\00(\A8\80\00\00\80\00\00\00\00\00\00\00\00\00\FF\D9 C/// File Manager

File Manager

Path: /lib64/python2.7/site-packages/gssapi/tests/

Viewing File: _utils.py

import os
import subprocess

from gssapi._utils import import_gssapi_extension


def get_output(*args, **kwargs):
    res = subprocess.check_output(*args, shell=True, **kwargs)
    decoded = res.decode('utf-8')
    return decoded.strip()


def _extension_test(extension_name, extension_text):
    def make_ext_test(func):
        def ext_test(self, *args, **kwargs):
            if import_gssapi_extension(extension_name) is None:
                self.skipTest("The %s GSSAPI extension is not supported by "
                              "your GSSAPI implementation" % extension_text)
            else:
                func(self, *args, **kwargs)

        return ext_test

    return make_ext_test


_KRB_VERSION = None


def _minversion_test(target_version, problem):
    global _KRB_VERSION
    if _KRB_VERSION is None:
        _KRB_VERSION = get_output("krb5-config --version")
        _KRB_VERSION = _KRB_VERSION.split(' ')[-1].split('.')

    def make_ext_test(func):
        def ext_test(self, *args, **kwargs):
            if _KRB_VERSION < target_version.split('.'):
                self.skipTest("Your GSSAPI (version %s) is known to have "
                              "problems with %s" % (_KRB_VERSION, problem))
            else:
                func(self, *args, **kwargs)
        return ext_test

    return make_ext_test


_PLUGIN_DIR = None


def _find_plugin_dir():
    global _PLUGIN_DIR
    if _PLUGIN_DIR is not None:
        return _PLUGIN_DIR

    # if we've set a LD_LIBRARY_PATH, use that first
    ld_path_raw = os.environ.get('LD_LIBRARY_PATH')
    if ld_path_raw is not None:
        # first, try assuming it's just a normal install

        ld_paths = [path for path in ld_path_raw.split(':') if path]

        for ld_path in ld_paths:
            if not os.path.exists(ld_path):
                continue

            _PLUGIN_DIR = _decide_plugin_dir(
                _find_plugin_dirs_installed(ld_path))
            if _PLUGIN_DIR is None:
                _PLUGIN_DIR = _decide_plugin_dir(
                    _find_plugin_dirs_src(ld_path))

            if _PLUGIN_DIR is not None:
                break

    # if there was no LD_LIBRARY_PATH, or the above failed
    if _PLUGIN_DIR is None:
        lib_dir = os.path.join(get_output('krb5-config --prefix'), 'lib64')
        _PLUGIN_DIR = _decide_plugin_dir(_find_plugin_dirs_installed(lib_dir))

    # /usr/lib64 has only been observed on RHEL
    if _PLUGIN_DIR is None:
        lib_dir = os.path.join(get_output('krb5-config --prefix'), 'lib')
        _PLUGIN_DIR = _decide_plugin_dir(_find_plugin_dirs_installed(lib_dir))

    if _PLUGIN_DIR is not None:
        _PLUGIN_DIR = os.path.normpath(_PLUGIN_DIR)
        return _PLUGIN_DIR
    else:
        return None


def _decide_plugin_dir(dirs):
    if dirs is None:
        return None

    # the shortest path is probably more correct
    shortest_first = sorted(dirs, key=len)

    for path in shortest_first:
        # check to see if it actually contains .so files
        if get_output('find %s -name "*.so"' % path):
            return path

    return None


def _find_plugin_dirs_installed(search_path):
    options_raw = get_output('find %s/ -type d '
                             '-path "*/krb5/plugins"' % search_path)

    if options_raw:
        return options_raw.split('\n')
    else:
        return None


def _find_plugin_dirs_src(search_path):
    options_raw = get_output('find %s/../ -type d -name plugins' % search_path)

    if options_raw:
        return options_raw.split('\n')
    else:
        return None


def _requires_krb_plugin(plugin_type, plugin_name):
    plugin_path = os.path.join(_find_plugin_dir(),
                               plugin_type, '%s.so' % plugin_name)

    def make_krb_plugin_test(func):
        def krb_plugin_test(self, *args, **kwargs):
            if not os.path.exists(plugin_path):
                self.skipTest("You do not have the GSSAPI {type}"
                              "plugin {name} installed".format(
                                  type=plugin_type, name=plugin_name))
            else:
                func(self, *args, **kwargs)

        return krb_plugin_test

    return make_krb_plugin_test