[sysadmin-bin] Migrate create-homedirs to use the member LDAP field



commit 68aff69f7fe3da8b36256816a8e1547b1a324b08
Author: Andrea Veri <av gnome org>
Date:   Wed Oct 8 15:18:58 2014 +0200

    Migrate create-homedirs to use the member LDAP field

 create-homedirs |   24 +++++++++++++++---------
 1 files changed, 15 insertions(+), 9 deletions(-)
---
diff --git a/create-homedirs b/create-homedirs
index deb8c97..dd385d4 100755
--- a/create-homedirs
+++ b/create-homedirs
@@ -8,8 +8,8 @@ import subprocess
 
 ## first you must open a connection to the server
 try:
-    l = ldap.open("ldap.gnome.org")
-    l.simple_bind("cn=Manager,dc=gnome,dc=org")
+    l = ldap.open("account.gnome.org")
+    l.simple_bind("cn=Directory Manager")
 except ldap.LDAPError, e:
     print e
     sys.exit(1)
@@ -18,7 +18,7 @@ except ldap.LDAPError, e:
 def get_uids_from_group(group):
     filter = "(cn=%s)" % group
     try:
-        ldap_result_id = l.search ("ou=groups,dc=gnome,dc=org",
+        ldap_result_id = l.search ("cn=groups,cn=accounts,dc=gnome,dc=org",
                                    ldap.SCOPE_SUBTREE, filter, None)
         while 1:
             result_type, group_data = l.result(ldap_result_id, 0)
@@ -26,7 +26,16 @@ def get_uids_from_group(group):
                 break
             else:
                 group_info = group_data[0][1]
-                return group_info['memberUid']
+                members = set()
+                for userid in group_info['member']:
+                    splitentry = userid.split(',')
+                    singleentry = splitentry[0]
+                    splitteduid = singleentry.split('=')
+                    uid = splitteduid[1]
+                    members.add(uid)
+
+                return members
+
     except ldap.LDAPError, e:
         print e
         sys.exit(1)
@@ -48,11 +57,8 @@ def create_home_directory (uid):
 
 
 if __name__ == '__main__':
-    # Get our list of ftpadmin members
-    LOGIN_GROUPS = ['ftpadmin', 'gnomeweb', 'gnomecvs', 'gnomevcs', 'bugzilla']
-    user_list = set()
+    LOGIN_GROUPS = ['ftpadmin', 'gnomeweb', 'gnomecvs', 'bugzilla']
     for group in LOGIN_GROUPS:
-        user_list.update(get_uids_from_group(group))
+        user_list = get_uids_from_group(group)
     for user in user_list:
         create_home_directory (user)
-


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