projects
/
mirror
/
userdir-ldap.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
A class shouldn't write to stderr on error, it should throw an exception
[mirror/userdir-ldap.git]
/
UDLdap.py
diff --git
a/UDLdap.py
b/UDLdap.py
index
447368d
..
0155345
100644
(file)
--- a/
UDLdap.py
+++ b/
UDLdap.py
@@
-1,9
+1,12
@@
import ldap
import time
import ldap
import time
+import userdir_ldap
class Account:
class Account:
- array_values = ['keyFingerPrint']
- int_values = ['shadowExpire']
+ array_values = ['objectClass', 'keyFingerPrint', 'mailWhitelist', 'mailRBL',
+ 'mailRHSBL', 'supplementaryGid', 'sshRSAAuthKey',
+ 'sudoPassword', 'dnsZoneEntry', 'allowedHost']
+ int_values = ['shadowExpire', 'gidNumber', 'uidNumber']
defaults = {
'accountStatus': 'active',
'keyFingerPrint': []
defaults = {
'accountStatus': 'active',
'keyFingerPrint': []
@@
-13,11
+16,9
@@
class Account:
def from_search(ldap_connection, base, user):
searchresult = ldap_connection.search_s(base, ldap.SCOPE_SUBTREE, 'uid=%s'%(user))
if len(searchresult) < 1:
def from_search(ldap_connection, base, user):
searchresult = ldap_connection.search_s(base, ldap.SCOPE_SUBTREE, 'uid=%s'%(user))
if len(searchresult) < 1:
- sys.stderr.write("No such user: %s\n"%(user))
- return
+ raise IndexError, "No such user: %s\n"%(user)
elif len(searchresult) > 1:
elif len(searchresult) > 1:
- sys.stderr.write("More than one hit when getting %s\n"%(user))
- return
+ raise IndexError, "More than one hit when getting %s\n"%(user)
else:
return Account(searchresult[0][0], searchresult[0][1])
else:
return Account(searchresult[0][0], searchresult[0][1])
@@
-29,7
+30,11
@@
class Account:
if key in self.attributes:
if key in self.array_values:
return self.attributes[key]
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]
return int(self.attributes[key][0])
else:
return self.attributes[key][0]
@@
-50,8
+55,17
@@
class Account:
def pw_active(self):
if self['userPassword'] == '{crypt}*LK*':
return False
def pw_active(self):
if self['userPassword'] == '{crypt}*LK*':
return False
+ if self['userPassword'].startswith("{crypt}!"):
+ return False
return True
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 \
# not expired
def shadow_active(self):
if 'shadowExpire' in self and \
@@
-62,6
+76,14
@@
class Account:
def numkeys(self):
return len(self['keyFingerPrint'])
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() ]))
def verbose_status(self):
status = []
status.append('mail: %s' %(['disabled', 'active'][ self.has_mail() ]))
@@
-72,9
+94,20
@@
class Account:
return '(%s)'%(', '.join(status))
return '(%s)'%(', '.join(status))
+ def delete_mailforward(self):
+ del self.attributes['emailForward']
+
def get_dn(self):
return self.dn
def get_dn(self):
return self.dn
+ def email_address(self):
+ mailbox = "<%s@%s>" % (self['uid'], userdir_ldap.EmailAppend)
+ tokens = []
+ if 'cn' in self: tokens.append(self['cn'])
+ if 'sn' in self: tokens.append(self['sn'])
+ tokens.append(mailbox)
+ return ' '.join(tokens)
+
# vim:set et:
# vim:set ts=4:
# vim:set shiftwidth=4:
# vim:set et:
# vim:set ts=4:
# vim:set shiftwidth=4: