ud-generate: deal with users without loginShell
[mirror/userdir-ldap.git] / ud-generate
index 4b589c5..db6770d 100755 (executable)
@@ -32,6 +32,7 @@ from dsa_mq.connection import Connection
 from dsa_mq.config import Config
 
 import string, re, time, ldap, optparse, sys, os, pwd, posix, socket, base64, hashlib, shutil, errno, tarfile, grp, fcntl, dbm
+import subprocess
 from userdir_ldap import *
 from userdir_exceptions import *
 import UDLdap
@@ -184,9 +185,9 @@ def IsInGroup(account, allowed, current_host):
   return False
 
 def Die(File, F, Fdb):
-   if F != None:
+   if F is not None:
       F.close()
-   if Fdb != None:
+   if Fdb is not None:
       Fdb.close()
    try: 
       os.remove(File + ".tmp")
@@ -198,10 +199,10 @@ def Die(File, F, Fdb):
       pass
 
 def Done(File, F, Fdb):
-   if F != None:
+   if F is not None:
       F.close()
       os.rename(File + ".tmp", File)
-   if Fdb != None:
+   if Fdb is not None:
       Fdb.close()
       os.rename(File + ".tdb.tmp", File + ".tdb")
 
@@ -214,6 +215,8 @@ def GenPasswd(accounts, File, HomePrefix, PwdMarker):
       userlist = {}
       i = 0
       for a in accounts:
+         if 'loginShell' not in a:
+             continue
          # Do not let people try to buffer overflow some busted passwd parser.
          if len(a['gecos']) > 100 or len(a['loginShell']) > 50: continue
 
@@ -848,7 +851,7 @@ def GenDNS(accounts, File):
                   F.write(Line)
 
                   Host = Split[0] + DNSZone
-                  if BSMTPCheck.match(Line) != None:
+                  if BSMTPCheck.match(Line) is not None:
                      F.write("; Has BSMTP\n")
 
                   # Write some identification information
@@ -989,7 +992,7 @@ def GenBSMTP(accounts, File, HomePrefix):
                   Line = " ".join(Split) + "\n"
      
                   Host = Split[0] + DNSZone
-                  if BSMTPCheck.match(Line) != None:
+                  if BSMTPCheck.match(Line) is not None:
                       F.write("%s: user=%s group=Debian file=%s%s/bsmtp/%s\n"%(Host,
                                   a['uid'], HomePrefix, a['uid'], Host))
      
@@ -1300,8 +1303,8 @@ def generate_host(host, global_dir, all_accounts, all_hosts, ssh_userkeys):
    DoLink(global_dir, OutDir, "mail-rhsbl")
    DoLink(global_dir, OutDir, "mail-whitelist")
    DoLink(global_dir, OutDir, "all-accounts.json")
-   DoLink(global_dir, Outdir, "default-mail-options.cdb")
-   DoLink(global_dir, Outdir, "default-mail-options.db")
+   DoLink(global_dir, OutDir, "default-mail-options.cdb")
+   DoLink(global_dir, OutDir, "default-mail-options.db")
    GenCDB(accounts, OutDir + "user-forward.cdb", 'emailForward')
    GenDBM(accounts, OutDir + "user-forward.db", 'emailForward')
    GenCDB(accounts, OutDir + "batv-tokens.cdb", 'bATVToken')
@@ -1330,7 +1333,7 @@ def generate_host(host, global_dir, all_accounts, all_hosts, ssh_userkeys):
          v = entry.split('=',1)
          if v[0] != 'GITOLITE' or len(v) != 2: continue
          options = v[1].split(',')
-         group = options.pop(0);
+         group = options.pop(0)
          gitolite_accounts = filter(lambda x: IsInGroup(x, [group], current_host), all_accounts)
          if 'nohosts' not in options:
             gitolite_hosts = filter(lambda x: GitoliteExportHosts.match(x[1]["hostname"][0]), all_hosts)