update Net::LDAP import
[mirror/userdir-ldap.git] / ud-generate
index 5abadf6..6c69928 100755 (executable)
@@ -28,7 +28,7 @@
 #   along with this program; if not, write to the Free Software
 #   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-import string, re, time, ldap, getopt, sys, os, pwd, posix, socket, base64, sha, shutil, errno, tarfile, grp
+import string, re, time, ldap, getopt, sys, os, pwd, posix, socket, base64, hashlib, shutil, errno, tarfile, grp
 import lockfile
 from userdir_ldap import *
 from userdir_exceptions import *
@@ -781,7 +781,7 @@ def ExtractDNSInfo(x):
             Algorithm = 2
          if Algorithm == None:
             continue
-         Fingerprint = sha.new(base64.decodestring(Split[1])).hexdigest()
+         Fingerprint = hashlib.new('sha1', base64.decodestring(Split[1])).hexdigest()
          DNSInfo.append("%sIN\tSSHFP\t%u 1 %s" % (TTLprefix, Algorithm, Fingerprint))
 
    if 'architecture' in x[1]:
@@ -981,14 +981,23 @@ def GenHosts(host_attrs, File):
       raise
    Done(File, F, None)
 
+def replaceTree(src, dst_basedir):
+   bn = os.path.basename(src)
+   dst = os.path.join(dst_basedir, bn)
+   safe_rmtree(dst)
+   shutil.copytree(src, dst)
+
 def GenKeyrings(OutDir):
    for k in Keyrings:
-      shutil.copy(k, OutDir)
+      if os.path.isdir(k):
+         replaceTree(k, OutDir)
+      else:
+         shutil.copy(k, OutDir)
 
 
 def get_accounts(ldap_conn):
    # Fetch all the users
-   passwd_attrs = ldap_conn.search_s(BaseDn, ldap.SCOPE_ONELEVEL, "(&(uid=*)(!(uidNumber=0)))",\
+   passwd_attrs = ldap_conn.search_s(BaseDn, ldap.SCOPE_ONELEVEL, "(&(uid=*)(!(uidNumber=0))(objectClass=shadowAccount))",\
                    ["uid", "uidNumber", "gidNumber", "supplementaryGid",\
                     "gecos", "loginShell", "userPassword", "shadowLastChange",\
                     "shadowMin", "shadowMax", "shadowWarning", "shadowInactive",
@@ -1164,11 +1173,21 @@ def generate_host(host, global_dir, accounts, ssh_files):
 
    if 'KEYRING' in ExtraList:
       for k in Keyrings:
-        DoLink(global_dir, OutDir, os.path.basename(k))
+         bn = os.path.basename(k)
+         if os.path.isdir(k):
+            src = os.path.join(global_dir, bn)
+            replaceTree(src, OutDir)
+         else:
+            DoLink(global_dir, OutDir, bn)
    else:
       for k in Keyrings:
          try:
-            posix.remove(OutDir + os.path.basename(k))
+            bn = os.path.basename(k)
+            target = os.path.join(OutDir, bn)
+            if os.path.isdir(target):
+               safe_rmtree(dst)
+            else:
+               posix.remove(target)
          except:
             pass