Let Account have a constructor that is more useful in generate
authorPeter Palfrader <peter@palfrader.org>
Mon, 2 Aug 2010 19:34:41 +0000 (19:34 +0000)
committerPeter Palfrader <peter@palfrader.org>
Mon, 2 Aug 2010 19:34:41 +0000 (19:34 +0000)
UDLdap.py [new file with mode: 0644]
debian/install
ud-lock

diff --git a/UDLdap.py b/UDLdap.py
new file mode 100644 (file)
index 0000000..ce25bbb
--- /dev/null
+++ b/UDLdap.py
@@ -0,0 +1,59 @@
+
+class Account:
+    def __init__(self, user):
+        searchresult = lc.search_s(BaseDn,ldap.SCOPE_SUBTREE, 'uid=%s'%(user))
+        if len(searchresult) < 1:
+            sys.stderr.write("No such user: %s\n"%(user))
+            return
+        elif len(searchresult) > 1:
+            sys.stderr.write("More than one hit when getting %s\n"%(user))
+            return
+
+        self.dn, self.attributes = searchresult[0]
+
+
+    def has_mail(self):
+        if 'mailDisableMessage' in self.attributes:
+            return False
+        return True
+
+    # not locked locked,  just reset to something invalid like {crypt}*SSLRESET* is still active
+    def pw_active(self):
+        if self.attributes['userPassword'][0] == '{crypt}*LK*':
+            return False
+        return True
+
+    # not expired
+    def shadow_active(self):
+        if 'shadowExpire' in self.attributes and \
+            int(self.attributes['shadowExpire'][0]) < (time.time() / 3600 / 24):
+            return False
+        return True
+
+    def numkeys(self):
+        if 'keyFingerPrint' in self.attributes:
+            return len(self.attributes['keyFingerPrint'])
+        return 0
+
+    def account_status(self):
+        if 'accountStatus' in self.attributes:
+            return self.attributes['accountStatus'][0]
+        return 'active'
+
+
+    def verbose_status(self):
+        status = []
+        status.append('mail: %s'  %(['disabled', 'active'][ self.has_mail() ]))
+        status.append('pw: %s'    %(['locked', 'active'][ self.pw_active() ]))
+        status.append('shadow: %s'%(['expired', 'active'][ self.shadow_active() ]))
+        status.append('keys: %d'  %( self.numkeys() ))
+        status.append('status: %s'%( self.account_status() ))
+
+        return '(%s)'%(', '.join(status))
+
+    def get_dn(self):
+        return self.dn
+
+# vim:set et:
+# vim:set ts=4:
+# vim:set shiftwidth=4:
index 104e1e9..0a06f86 100644 (file)
@@ -1,3 +1,4 @@
+UDLdap.py usr/share/python-support/userdir_ldap/
 userdir_ldap.pth usr/share/python-support/
 userdir_ldap.py usr/share/python-support/userdir_ldap/
 userdir_gpg.py usr/share/python-support/userdir_ldap/
diff --git a/ud-lock b/ud-lock
index 6d56ddb..7035ed0 100755 (executable)
--- a/ud-lock
+++ b/ud-lock
@@ -27,6 +27,7 @@ import os
 import pwd
 import time
 from userdir_ldap import *;
+import UDLdap
 
 dry_run = False
 
@@ -46,64 +47,8 @@ def connect(user):
        sys.exit(1)
     return l
 
-
-class Account:
-    def __init__(self, user):
-        searchresult = lc.search_s(BaseDn,ldap.SCOPE_SUBTREE, 'uid=%s'%(user))
-        if len(searchresult) < 1:
-            sys.stderr.write("No such user: %s\n"%(user))
-            return
-        elif len(searchresult) > 1:
-            sys.stderr.write("More than one hit when getting %s\n"%(user))
-            return
-
-        self.dn, self.attributes = searchresult[0]
-
-
-    def has_mail(self):
-        if 'mailDisableMessage' in self.attributes:
-            return False
-        return True
-
-    # not locked locked,  just reset to something invalid like {crypt}*SSLRESET* is still active
-    def pw_active(self):
-        if self.attributes['userPassword'][0] == '{crypt}*LK*':
-            return False
-        return True
-
-    # not expired
-    def shadow_active(self):
-        if 'shadowExpire' in self.attributes and \
-            int(self.attributes['shadowExpire'][0]) < (time.time() / 3600 / 24):
-            return False
-        return True
-
-    def numkeys(self):
-        if 'keyFingerPrint' in self.attributes:
-            return len(self.attributes['keyFingerPrint'])
-        return 0
-
-    def account_status(self):
-        if 'accountStatus' in self.attributes:
-            return self.attributes['accountStatus'][0]
-        return 'active'
-
-
-    def verbose_status(self):
-        status = []
-        status.append('mail: %s'  %(['disabled', 'active'][ self.has_mail() ]))
-        status.append('pw: %s'    %(['locked', 'active'][ self.pw_active() ]))
-        status.append('shadow: %s'%(['expired', 'active'][ self.shadow_active() ]))
-        status.append('keys: %d'  %( self.numkeys() ))
-        status.append('status: %s'%( self.account_status() ))
-
-        return '(%s)'%(', '.join(status))
-
-    def get_dn(self):
-        return self.dn
-
 def do_one_user(lc, user, ticket):
-    u = Account(user)
+    u = UDLdap.Account(user)
     if not u.account_status() == 'active':
         sys.stderr.write('%s: Account is not active, skipping.  (details: %s)\n'%(user, u.verbose_status()))
         return