X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=ud-generate;h=3cbe113fff23146e797ae222ebc274dfec50fb4e;hb=5c58925b8883cedd82f2d3f43c6905040be4df6c;hp=1a22954ec88dba28448eed8799a9bd288f3061d1;hpb=c09ffb50e51b942e83c0ef2952ae0a2edd396adc;p=mirror%2Fuserdir-ldap.git diff --git a/ud-generate b/ud-generate index 1a22954..3cbe113 100755 --- a/ud-generate +++ b/ud-generate @@ -418,31 +418,18 @@ def GenVoipPassword(accounts, File): F = open(File, "w", 0600) os.umask(OldMask) - root = Element('include') - for a in accounts: if not 'voipPassword' in a: continue if not a.pw_active(): continue Pass = str(a['voipPassword']) - user = Element('user') - user.attrib['id'] = "%s" % (a['uid']) - root.append(user) - params = Element('params') - user.append(params) - param = Element('param') - params.append(param) - param.attrib['name'] = "a1-hash" - param.attrib['value'] = "%s" % (Pass) - variables = Element('variables') - user.append(variables) - variable = Element('variable') - variable.attrib['name'] = "toll_allow" - variable.attrib['value'] = "domestic,international,local" - variables.append(variable) - - F.write("%s" % (prettify(root))) + realm = 'sip.debian.org' + HA1 = "%s:%s%:%s" : (a['uid'], realm, Pass) + hashlib.md5(HA1).hexdigest() + Line = "%s:%s:%s:AUTHORIZED" % (a['uid'], realm, Pass) + Line = Sanitize(Line) + "\n" + F.write("%s" % (Line)) except: Die(File, None, F) @@ -647,17 +634,15 @@ def GenCDB(accounts, File, key): def GenDBM(accounts, File, key): Fdb = None + OldMask = os.umask(0022) + fn = os.path.join(File).encode('ascii', 'ignore') try: - OldMask = os.umask(0022) - # nothing else does the fsync stuff, so why do it here? - fn = os.path.join(prefix,File).encode('ascii', 'ignore') - fntmp = os.path.join(prefix,File + '.tmp').encode('ascii', 'ignore') - try: - posix.remove(fntmp) - except: - pass + posix.remove(fn) + except: + pass - Fdb = dbm.open(fntmp, "c") + try: + Fdb = dbm.open(fn, "c") os.umask(OldMask) # Write out the email address for each user @@ -668,11 +653,12 @@ def GenDBM(accounts, File, key): Fdb[user] = value Fdb.close() - posix.rename(fntmp,fn) - # Oops, something unspeakable happened. except: - Fdb.close() + # python-dbm names the files Fdb.db.db so we want to them to be Fdb.db + os.remove(File + ".db") raise + # python-dbm names the files Fdb.db.db so we want to them to be Fdb.db + os.rename (File + ".db", File) # Generate the anon XEarth marker file def GenMarkers(accounts, File): @@ -1198,9 +1184,9 @@ def generate_all(global_dir, ldap_conn): GenMailDisable(accounts, global_dir + "mail-disable") GenCDB(accounts, global_dir + "mail-forward.cdb", 'emailForward') - GenDBM(accounts, global_dir + "mail-forward.dbm", 'emailForward') + GenDBM(accounts, global_dir + "mail-forward.db", 'emailForward') GenCDB(accounts, global_dir + "mail-contentinspectionaction.cdb", 'mailContentInspectionAction') - GenDBM(accounts, global_dir + "mail-contentinspectionaction.dbm", 'mailContentInspectionAction') + GenDBM(accounts, global_dir + "mail-contentinspectionaction.db", 'mailContentInspectionAction') GenPrivate(accounts, global_dir + "debian-private") GenSSHKnown(host_attrs, global_dir+"authorized_keys", 'authorized_keys', global_dir+'ud-generate.lock') GenMailBool(accounts, global_dir + "mail-greylist", "mailGreylisting") @@ -1283,9 +1269,9 @@ def generate_host(host, global_dir, all_accounts, all_hosts, ssh_userkeys): if not 'NOMARKERS' in ExtraList: DoLink(global_dir, OutDir, "markers") DoLink(global_dir, OutDir, "mail-forward.cdb") - DoLink(global_dir, OutDir, "mail-forward.dbm") + DoLink(global_dir, OutDir, "mail-forward.db") DoLink(global_dir, OutDir, "mail-contentinspectionaction.cdb") - DoLink(global_dir, OutDir, "mail-contentinspectionaction.dbm") + DoLink(global_dir, OutDir, "mail-contentinspectionaction.db") DoLink(global_dir, OutDir, "mail-disable") DoLink(global_dir, OutDir, "mail-greylist") DoLink(global_dir, OutDir, "mail-callout") @@ -1294,11 +1280,11 @@ def generate_host(host, global_dir, all_accounts, all_hosts, ssh_userkeys): DoLink(global_dir, OutDir, "mail-whitelist") DoLink(global_dir, OutDir, "all-accounts.json") GenCDB(accounts, OutDir + "user-forward.cdb", 'emailForward') - GenDBM(accounts, OutDir + "user-forward.dbm", 'emailForward') + GenDBM(accounts, OutDir + "user-forward.db", 'emailForward') GenCDB(accounts, OutDir + "batv-tokens.cdb", 'bATVToken') - GenDBM(accounts, OutDir + "batv-tokens.dbm", 'bATVToken') + GenDBM(accounts, OutDir + "batv-tokens.db", 'bATVToken') GenCDB(accounts, OutDir + "default-mail-options.cdb", 'mailDefaultOptions') - GenDBM(accounts, OutDir + "default-mail-options.dbm", 'mailDefaultOptions') + GenDBM(accounts, OutDir + "default-mail-options.db", 'mailDefaultOptions') # Compatibility. DoLink(global_dir, OutDir, "forward-alias")