X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=UDLdap.py;h=90c942d16b2f1a46747f4cc33c703d77d65a544f;hb=89648b4805761b9df8de5c8f8ef000dc42cc5c4b;hp=3dc2b742fec2f3c06eb81bab99bda6cb176b0a83;hpb=a10f6e27cfde5e7cf7fba28f00f73b8d5f52aeb0;p=mirror%2Fuserdir-ldap.git diff --git a/UDLdap.py b/UDLdap.py index 3dc2b74..90c942d 100644 --- a/UDLdap.py +++ b/UDLdap.py @@ -3,8 +3,8 @@ 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', 'uidNumber'] defaults = { 'accountStatus': 'active', 'keyFingerPrint': [] @@ -30,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] @@ -51,8 +55,17 @@ class Account: def pw_active(self): if self['userPassword'] == '{crypt}*LK*': return False + if self['userPassword'].startswith("{crypt}!"): + return False return True + def get_password(self): + p = self['userPassword'] + if not p.startswith('{crypt}') or len(p) > 50: + return p + else: + return p[7:] + # not expired def shadow_active(self): if 'shadowExpire' in self and \ @@ -63,6 +76,9 @@ 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):