projects
/
mirror
/
userdir-ldap.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
57fc92f
)
A class shouldn't write to stderr on error, it should throw an exception
author
Peter Palfrader
<peter@palfrader.org>
Mon, 2 Aug 2010 23:48:02 +0000
(23:48 +0000)
committer
Peter Palfrader
<peter@palfrader.org>
Mon, 2 Aug 2010 23:48:02 +0000
(23:48 +0000)
UDLdap.py
patch
|
blob
|
history
ud-lock
patch
|
blob
|
history
diff --git
a/UDLdap.py
b/UDLdap.py
index
2e45092
..
0155345
100644
(file)
--- a/
UDLdap.py
+++ b/
UDLdap.py
@@
-16,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])
diff --git
a/ud-lock
b/ud-lock
index
a274274
..
7e8725d
100755
(executable)
--- a/
ud-lock
+++ b/
ud-lock
@@
-48,7
+48,11
@@
def connect(user):
return l
def do_one_user(lc, user, ticket):
return l
def do_one_user(lc, user, ticket):
- u = UDLdap.Account.from_search(lc, BaseDn, user)
+ try:
+ u = UDLdap.Account.from_search(lc, BaseDn, user)
+ except IndexError, e:
+ sys.stderr.write("Cannot instantiate account from LDAP: %s"%(str(e)))
+ return
if not u['accountStatus'] == 'active':
sys.stderr.write('%s: Account is not active, skipping. (details: %s)\n'%(user, u.verbose_status()))
return
if not u['accountStatus'] == 'active':
sys.stderr.write('%s: Account is not active, skipping. (details: %s)\n'%(user, u.verbose_status()))
return