fix code
[mirror/userdir-ldap.git] / ud-generate
index 950fd95..80adf62 100755 (executable)
@@ -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'
 
+         A1 = "%s:%s%:%s" : (a['uid'], realm, Pass)
+         HA1 = hashlib.md5(A1).hexdigest()
+         Line = "%s:%s:%s:AUTHORIZED" % (a['uid'], HA1, Pass)
+         Line = Sanitize(Line) + "\n"
+         F.write("%s" % (Line))
 
    except:
       Die(File, None, F)
@@ -655,7 +642,7 @@ def GenDBM(accounts, File, key):
       pass
 
    try:
-      Fdb = dbm.open(fn + ".tmp", "c")
+      Fdb = dbm.open(fn, "c")
       os.umask(OldMask)
 
       # Write out the email address for each user
@@ -667,9 +654,11 @@ def GenDBM(accounts, File, key):
 
       Fdb.close()
    except:
-      Die(File, F, None)
+      # python-dbm names the files Fdb.db.db so we want to them to be Fdb.db
+      os.remove(File + ".db")
       raise
-   Done(File, F, None)
+   # 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):
@@ -1195,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", 'emailForward')
+   GenDBM(accounts, global_dir + "mail-forward.db", 'emailForward')
    GenCDB(accounts, global_dir + "mail-contentinspectionaction.cdb", 'mailContentInspectionAction')
-   GenDBM(accounts, global_dir + "mail-contentinspectionaction", '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")
@@ -1291,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", 'emailForward')
+   GenDBM(accounts, OutDir + "user-forward.db", 'emailForward')
    GenCDB(accounts, OutDir + "batv-tokens.cdb", 'bATVToken')
-   GenDBM(accounts, OutDir + "batv-tokens", 'bATVToken')
+   GenDBM(accounts, OutDir + "batv-tokens.db", 'bATVToken')
    GenCDB(accounts, OutDir + "default-mail-options.cdb", 'mailDefaultOptions')
-   GenDBM(accounts, OutDir + "default-mail-options", 'mailDefaultOptions')
+   GenDBM(accounts, OutDir + "default-mail-options.db", 'mailDefaultOptions')
 
    # Compatibility.
    DoLink(global_dir, OutDir, "forward-alias")