export webPassword
[mirror/userdir-ldap.git] / ud-generate
index f00cf6e..c3eff77 100755 (executable)
@@ -91,10 +91,10 @@ def safe_rmtree(dir):
 
 def get_lock(fn, wait=5*60, max_age=3600*6):
    try:
-      stat = os.stat(fn)
-      if stat[ST_MTIME] < time.time() - max_age:
-         sys.stderr.write("Removing stale lock %s"%(fn))
-         os.unlink(fn)
+      stat = os.stat(fn + '.lock')
+      if stat.st_mtime < time.time() - max_age:
+         sys.stderr.write("Removing stale lock %s"%(fn + '.lock'))
+         os.unlink(fn + '.lock')
    except OSError, error:
       if error.errno == errno.ENOENT:
          pass
@@ -374,6 +374,27 @@ def GenSSHShadow(global_dir, accounts):
 
    return userfiles
 
+# Generate the webPassword list
+def GenWebPassword(accounts, File):
+   F = None
+   try:
+      OldMask = os.umask(0077)
+      F = open(File, "w", 0600)
+      os.umask(OldMask)
+
+      for a in accounts:
+         if not 'webPassword' in a: continue
+         if not a.pw_active(): continue
+
+         Pass = str(a['webPassword'])
+         Line = "%s:%s" % (a['uid'], Pass)
+         Line = Sanitize(Line) + "\n"
+         F.write("%s" % (Line))
+
+   except:
+      Die(File, None, F)
+      raise
+
 def GenSSHtarballs(global_dir, userlist, SSHFiles, grouprevmap, target):
    OldMask = os.umask(0077)
    tf = tarfile.open(name=os.path.join(global_dir, 'ssh-keys-%s.tar.gz' % CurrentHost), mode='w:gz')
@@ -1006,7 +1027,7 @@ def get_accounts(ldap_conn):
                     "keyFingerPrint", "privateSub", "mailDisableMessage",\
                     "mailGreylisting", "mailCallout", "mailRBL", "mailRHSBL",\
                     "mailWhitelist", "sudoPassword", "objectClass", "accountStatus",\
-                    "mailContentInspectionAction"])
+                    "mailContentInspectionAction", "webPassword"])
 
    if passwd_attrs is None:
       raise UDEmptyList, "No Users"
@@ -1067,6 +1088,7 @@ def generate_all(global_dir, ldap_conn):
    GenMailList(accounts, global_dir + "mail-rbl", "mailRBL")
    GenMailList(accounts, global_dir + "mail-rhsbl", "mailRHSBL")
    GenMailList(accounts, global_dir + "mail-whitelist", "mailWhitelist")
+   GenWebPassword(accounts, global_dir + "web-passwords")
    GenKeyrings(global_dir)
 
    # Compatibility.
@@ -1171,6 +1193,9 @@ def generate_host(host, global_dir, accounts, ssh_files):
    if 'PRIVATE' in ExtraList:
       DoLink(global_dir, OutDir, "debian-private")
 
+   if 'WEB-PASSWORDS' in ExtraList:
+      DoLink(global_dir, OutDir, "web-passwords")
+
    if 'KEYRING' in ExtraList:
       for k in Keyrings:
          bn = os.path.basename(k)
@@ -1242,17 +1267,18 @@ for x in attrs:
    if x[1].has_key("subGroup") != 0:
       SubGroupMap.setdefault(x[1]["gid"][0], []).extend(x[1]["subGroup"])
 
+lock = None
 try:
-   lockfile = os.path.join(GenerateDir, 'ud-generate.lock')
-   lock = get_lock( lockfile )
+   lockf = os.path.join(GenerateDir, 'ud-generate.lock')
+   lock = get_lock( lockf )
    if lock is None:
-      sys.stderr.write("Could not acquire lock %s.\n"%(lockfile))
+      sys.stderr.write("Could not acquire lock %s.\n"%(lockf))
       sys.exit(1)
 
    generate_all(GenerateDir, l)
 
 finally:
-   if not lock is None:
+   if lock is not None:
       lock.release()
 
 # vim:set et: