[sysadmin-bin] Do not fail when the user has no LDAP description field set on the account



commit 5baa5d3fc6d4a1ac4d6e0ab0f44b5c5aa272d619
Author: Andrea Veri <av gnome org>
Date:   Sat Oct 31 18:54:15 2015 +0100

    Do not fail when the user has no LDAP description field set on the account

 cleanup-inactive-ldap-accounts.py |   14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)
---
diff --git a/cleanup-inactive-ldap-accounts.py b/cleanup-inactive-ldap-accounts.py
index bd1a74d..dfd1dcf 100755
--- a/cleanup-inactive-ldap-accounts.py
+++ b/cleanup-inactive-ldap-accounts.py
@@ -106,11 +106,19 @@ def add_remove_comment_to_user(username, group):
         # Something went very wrong here...
         return False
 
-    current_comment = results[0][1]['description'][0]
+    try:
+        current_comment = results[0][1]['description'][0]
+    except KeyError:
+        has_description = False
+
     comment = '%s %s' % (current_comment, new_comment)
 
-    update_comment = [(ldap.MOD_REPLACE, 'description', comment)]
-    l.modify_s('uid=%s,%s' % (username, LDAP_USER_BASE), update_comment)
+    if has_description == False:
+        update_comment = [(ldap.MOD_ADD, 'description', comment)]
+        l.modify_s('uid=%s,%s' % (username, LDAP_USER_BASE), update_comment)
+    else:
+        update_comment = [(ldap.MOD_REPLACE, 'description', comment)]
+        l.modify_s('uid=%s,%s' % (username, LDAP_USER_BASE), update_comment)
 
     name = results[0][1]['cn'][0]
     mail = results[0][1]['mail'][0]


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]