#!/usr/bin/python ''' Export the username / password db from a given mailman list into Apache's 'AuthDigestFile' format ''' import pickle try: from hashlib import md5 except ImportError: from md5 import md5 ### Begin Variables ### # Realm name for apache auth (used in digest hash generation) realm = 'foomp' # path to dir containing all lists mm_lists_path = "/var/lib/mailman/lists" # the list whose membership will be synced mm_target_list = "blaag" # path to target lists's config pickle mm_target_config = mm_lists_path + "/" + mm_target_list + "/config.pck" # path to export file, in Apache AuthUserFile format authdigestfilepath = "/etc/mailman/AuthDigestFile" ### End Variables ### # open the target list's config pickle f = open(mm_target_config,"r") # read the pickle into a dict p = pickle.load(f) f.close() # extract usernames / passwords from the dict creds = p["passwords"] # new string to buffer output out = '' # iterate all of the username / password pairs for u,p in creds.iteritems(): # Generate the string to enter into the htdigest file # cribbed from: http://trac.edgewall.org/wiki/TracStandalone kd = lambda x: md5(':'.join(x)).hexdigest() out += ':'.join((u, realm, kd([u, realm, p]))) out += "\n" # write out the AuthDigestFile authfile = open (authdigestfilepath, "w") authfile.write(out) authfile.close()