Skip to content

Instantly share code, notes, and snippets.

@tiran
Created January 4, 2021 15:24
Show Gist options
  • Save tiran/4b56faf5a8b14b9828ef8ba2ad9292ba to your computer and use it in GitHub Desktop.
Save tiran/4b56faf5a8b14b9828ef8ba2ad9292ba to your computer and use it in GitHub Desktop.

Revisions

  1. tiran created this gist Jan 4, 2021.
    51 changes: 51 additions & 0 deletions saslprof.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,51 @@
    #!/usr/bin/python3
    import collections
    import configparser
    import time
    import socket

    import ldap
    import ldap.sasl

    SASL_GSSAPI = ldap.sasl.sasl({}, 'GSSAPI')
    SASL_GSS_SPNEGO = ldap.sasl.sasl({}, 'GSS-SPNEGO')

    METH = SASL_GSSAPI

    with open("/etc/ipa/default.conf") as f:
    cfg = configparser.RawConfigParser()
    cfg.read_file(f)

    URI = cfg.get("global", "ldap_uri")
    assert URI.startswith("ldapi://")

    def profile(uri, meth):
    conn = ldap.initialize(uri)
    conn.whoami_s() # start connection
    start = time.perf_counter()
    try:
    conn.sasl_interactive_bind_s('', meth)
    return time.perf_counter() - start
    finally:
    conn.unbind()

    # acquire service ticket
    profile(URI, METH)

    ctr = collections.Counter()
    for i in range(2000):
    dur = profile(URI, METH)
    dur = round(dur * 1000)
    ctr.update({dur: 1})
    # print(f"{dur}ms")
    if dur > 500:
    c = "O"
    elif dur > 20:
    c = "x"
    else:
    c = "."
    print(c, end="", flush=True)

    print()
    for dur, count in sorted(ctr.items()):
    print(f"{dur}ms\t{count}")