2 # Works with both python2 and python3; please preserve this property
4 # Copyright (C) 2016 mod_auth_gssapi contributors - See COPYING for (C) terms
6 # If one uses both sessions and unique ccache names, then the filesystem will
7 # become littered with ccache files unless the accessed application cleans
8 # them up itself. This script will minimize ccache file proliferation by
9 # removing any ccaches that have expired from the filesystem, and serves as an
10 # example of how this cleaning can be performed.
20 from gssapi.raw import acquire_cred_from
22 print("Your GSSAPI does not provide cred store extension; exiting!")
25 # process file as a ccache and indicate whether it is expired
26 def should_delete(fname, t):
28 # skip directories and other non-files
30 if not stat.S_ISREG(st.st_mode):
33 # ignore files that are newer than 30 minutes
34 if t - st.st_mtime < 30 * 60:
37 creds = acquire_cred_from({b"ccache": fname.encode("UTF-8")})
38 except FileNotFoundError:
39 # someone else did the work for us
41 except Exception as e:
42 print("Not deleting %s due to error %s" % (fname, e))
45 return creds.lifetime == 0
47 if __name__ == "__main__":
50 print("Usage: %s dir1 [dir2...]" % sys.argv[0])
53 print("System looks okay; running sweeper...")
59 print("Sweeping %s" % basedir)
61 for fname in os.listdir(basedir):
62 if should_delete(fname, t):
65 print("Sweeper finished successfully!")