# Buggy code
def _load_libcrypto():
    """
    Load OpenSSL libcrypto
    """
    if sys.platform.startswith("win"):
        # cdll.LoadLibrary on windows requires an 'str' argument
        return cdll.LoadLibrary(
            str("libeay32")
        )  # future lint: disable=blacklisted-function
    elif getattr(sys, "frozen", False) and salt.utils.platform.is_smartos():
        return cdll.LoadLibrary(
            glob.glob(os.path.join(os.path.dirname(sys.executable), "libcrypto.so*"))[0]
        )
    else:
        lib = find_library("crypto")
        if not lib and salt.utils.platform.is_sunos():
            # Solaris-like distribution that use pkgsrc have
            # libraries in a non standard location.
            # (SmartOS, OmniOS, OpenIndiana, ...)
            # This could be /opt/tools/lib (Global Zone)
            # or /opt/local/lib (non-Global Zone), thus the
            # two checks below
            lib = glob.glob("/opt/local/lib/libcrypto.so*") + glob.glob(
                "/opt/tools/lib/libcrypto.so*"
            )
            lib = lib[0] if len(lib) > 0 else None
        if lib:
            return cdll.LoadLibrary(lib)
        raise OSError("Cannot locate OpenSSL libcrypto")


# Traceback (RuntimeError)
root@salt:/root > salt-ssh aixhost mount.active
aixhost:
----------
retcode:
1
stderr:
/bin/sh[14]: python3:  not found.
/bin/sh[14]: python27:  not found.
WARNING: Unable to locate current thin  version: /tmp/.root_3664b7_salt/version.
Traceback (most recent call last):
File "<string>", line 141, in <module>
File "<string>", line 244, in <module>
File "<string>", line 174, in main
File "<string>", line 80, in need_deployment
File "<string>", line 80, in need_deployment
File "<string>", line 80, in need_deployment          ....
....
....
File "<string>", line 80, in need_deployment          ....
File "<string>", line 80, in need_deployment          ....
File "<string>", line 68, in need_deployment
File "/opt/freeware/lib/python2.7/shutil.py", line 228, in rmtree
if os.path.islink(path):
File "/usr/bin/../../opt/freeware/lib/python2.7/posixpath.py", line 145, in islink
return stat.S_ISLNK(st.st_mode)
File "/usr/bin/../../opt/freeware/lib/python2.7/stat.py", line 56, in S_ISLNK
return S_IFMT(mode) == S_IFLNK
RuntimeError: maximum recursion depth exceeded    stdout:
/usr/bin/scp

# Fixed code
def _load_libcrypto():
    """
    Load OpenSSL libcrypto
    """
    if sys.platform.startswith("win"):
        # cdll.LoadLibrary on windows requires an 'str' argument
        return cdll.LoadLibrary(
            str("libeay32")
        )  # future lint: disable=blacklisted-function
    elif getattr(sys, "frozen", False) and salt.utils.platform.is_smartos():
        return cdll.LoadLibrary(
            glob.glob(os.path.join(os.path.dirname(sys.executable), "libcrypto.so*"))[0]
        )
    else:
        lib = find_library("crypto")
        if not lib and salt.utils.platform.is_sunos():
            # Solaris-like distribution that use pkgsrc have
            # libraries in a non standard location.
            # (SmartOS, OmniOS, OpenIndiana, ...)
            # This could be /opt/tools/lib (Global Zone)
            # or /opt/local/lib (non-Global Zone), thus the
            # two checks below
            lib = glob.glob("/opt/local/lib/libcrypto.so*") + glob.glob(
                "/opt/tools/lib/libcrypto.so*"
            )
            lib = lib[0] if len(lib) > 0 else None
        if not lib and salt.utils.platform.is_aix():
            if os.path.isdir("/opt/salt/lib"):
                # preference for Salt installed fileset
                lib = glob.glob("/opt/salt/lib/libcrypto.so*")
                lib = lib[0] if len(lib) > 0 else None
            else:
                lib = glob.glob("/opt/freeware/lib/libcrypto.so*")
                lib = lib[0] if len(lib) > 0 else None
        if lib:
            return cdll.LoadLibrary(lib)
        raise OSError("Cannot locate OpenSSL libcrypto")