[sysadmin-bin] Let create_homedirs make use of gnome_ldap_utils as well



commit 39143900132666ff21033e9dcf37d231db263786
Author: Andrea Veri <averi redhat com>
Date:   Thu Oct 12 18:27:10 2017 +0200

    Let create_homedirs make use of gnome_ldap_utils as well

 create-homedirs |   47 ++++++-----------------------------------------
 1 files changed, 6 insertions(+), 41 deletions(-)
---
diff --git a/create-homedirs b/create-homedirs
index dfa20e6..70b78e3 100755
--- a/create-homedirs
+++ b/create-homedirs
@@ -1,60 +1,25 @@
 #!/usr/bin/python
-import ldap
 import grp
 import os
 import sys
 import shutil
 import subprocess
 
-execfile('/home/admin/secret/freeipa')
-
-## first you must open a connection to the server
-try:
-    l = ldap.open('view.gnome.org')
-    l.simple_bind("cn=Directory Manager", ldap_password)
-except ldap.LDAPError, e:
-    print >>sys.stderr, e
-    sys.exit(1)
-
-def get_uids_from_group(group):
-    filter = "(cn=%s)" % group
-    try:
-        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)
-            if (group_data == []):
-                break
-            else:
-                group_info = group_data[0][1]
-                members = set()
-                try:
-                    for userid in group_info['member']:
-                        splitentry = userid.split(',')
-                        singleentry = splitentry[0]
-                        splitteduid = singleentry.split('=')
-                        uid = splitteduid[1]
-                        members.add(uid)
-                except KeyError:
-                    pass
+from gnome_ldap_utils import *
 
-                return members
-
-    except ldap.LDAPError, e:
-        print e
-        sys.exit(1)
+execfile('/home/admin/secret/freeipa')
 
-    return {}
+glu = Gnome_ldap_utils(LDAP_GROUP_BASE, 'view.gnome.org', LDAP_USER_BASE, 'cn=Directory Manager', 
ldap_password)
 
 
-def create_home_directory (uid):
+def create_home_directory(uid):
     src = '/etc/skel'
     dst = "/home/users/%s" % uid
     if os.path.isdir("/home/users/%s" % uid):
         return
 
     shutil.copytree(src, dst, True)
-    subprocess.call(['/bin/chown', '-R', '%s:%s' % (uid, uid), dst ])
+    subprocess.call(['/bin/chown', '-R', '%s:%s' % (uid, uid), dst])
     print "Created home directory for '%s'" % uid
 
     return
@@ -63,6 +28,6 @@ def create_home_directory (uid):
 if __name__ == '__main__':
     LOGIN_GROUPS = ['ftpadmin', 'gnomeweb', 'gnomecvs', 'bugzilla', 'giapprentice', 'webusers']
     for group in LOGIN_GROUPS:
-        user_list = get_uids_from_group(group)
+        user_list = glu.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]