GenShadowSudo
[mirror/userdir-ldap.git] / UDLdap.py
index 447368d..096f117 100644 (file)
--- a/UDLdap.py
+++ b/UDLdap.py
@@ -1,9 +1,10 @@
 import ldap
 import time
+import userdir_ldap
 
 class Account:
-    array_values = ['keyFingerPrint']
-    int_values = ['shadowExpire']
+    array_values = ['keyFingerPrint', 'mailWhitelist', 'mailRBL', 'mailRHSBL', 'supplementaryGid', 'sshRSAAuthKey', 'sudoPassword']
+    int_values = ['shadowExpire', 'gidNumber']
     defaults = {
                  'accountStatus': 'active',
                  'keyFingerPrint': []
@@ -29,7 +30,11 @@ class Account:
         if key in self.attributes:
             if key in self.array_values:
                 return self.attributes[key]
-            elif key in self.int_values:
+
+            if not len(self.attributes[key]) == 1:
+                raise ValueError, 'non-array value has not exactly one value'
+
+            if key in self.int_values:
                 return int(self.attributes[key][0])
             else:
                 return self.attributes[key][0]
@@ -50,6 +55,8 @@ class Account:
     def pw_active(self):
         if self['userPassword'] == '{crypt}*LK*':
             return False
+        if self['userPassword'].startswith("!"):
+            return False
         return True
 
     # not expired
@@ -62,6 +69,14 @@ class Account:
     def numkeys(self):
         return len(self['keyFingerPrint'])
 
+    def is_active_user(self):
+        return self['accountStatus'] == 'active' and self.numkeys() != 0
+
+    def latitude_dec(self, anonymized=False):
+        return userdir_ldap.DecDegree(self['latitude'], anonymized)
+    def longitude_dec(self, anonymized=False):
+        return userdir_ldap.DecDegree(self['longitude'], anonymized)
+
     def verbose_status(self):
         status = []
         status.append('mail: %s'  %(['disabled', 'active'][ self.has_mail() ]))