python: validate kerberos ticket

Joshua  picture Joshua · Jun 29, 2010 · Viewed 7.5k times · Source

I'm wondering - if anyone has an elegant solution to checking for a valid Kerberos ticket using Python. I'm not seeing anyway with kinit or klist that will show if a ticket is expired with a return code but I could run klist and use a regex for the output .

Answer

Mikhail picture Mikhail · Mar 12, 2014

Another option is to check exit status of 'klist -s' looks shorter and does not use krbV:

import subprocess

def has_kerberos_ticket():
    return True if subprocess.call(['klist', '-s']) == 0 else False