5 array_values = ['keyFingerPrint']
6 int_values = ['shadowExpire']
8 'accountStatus': 'active',
13 def from_search(ldap_connection, base, user):
14 searchresult = ldap_connection.search_s(base, ldap.SCOPE_SUBTREE, 'uid=%s'%(user))
15 if len(searchresult) < 1:
16 sys.stderr.write("No such user: %s\n"%(user))
18 elif len(searchresult) > 1:
19 sys.stderr.write("More than one hit when getting %s\n"%(user))
22 return Account(searchresult[0][0], searchresult[0][1])
24 def __init__(self, dn, attributes):
26 self.attributes = attributes
28 def __getitem__(self, key):
29 if key in self.attributes:
30 if key in self.array_values:
31 return self.attributes[key]
32 elif key in self.int_values:
33 return int(self.attributes[key][0])
35 return self.attributes[key][0]
36 elif key in self.defaults:
37 return self.defaults[key]
41 def __contains__(self, key):
42 return key in self.attributes
45 if 'mailDisableMessage' in self.attributes:
49 # not locked locked, just reset to something invalid like {crypt}*SSLRESET* is still active
51 if self['userPassword'] == '{crypt}*LK*':
56 def shadow_active(self):
57 if 'shadowExpire' in self and \
58 self['shadowExpire'] < (time.time() / 3600 / 24):
63 return len(self['keyFingerPrint'])
65 def verbose_status(self):
67 status.append('mail: %s' %(['disabled', 'active'][ self.has_mail() ]))
68 status.append('pw: %s' %(['locked', 'active'][ self.pw_active() ]))
69 status.append('shadow: %s'%(['expired', 'active'][ self.shadow_active() ]))
70 status.append('keys: %d' %( self.numkeys() ))
71 status.append('status: %s'%( self['accountStatus'] ))
73 return '(%s)'%(', '.join(status))
80 # vim:set shiftwidth=4: