Created
December 2, 2017 01:59
-
-
Save wolsen/9158cb71238914564cfa177c82adfc41 to your computer and use it in GitHub Desktop.
Create lots of users for an openldap server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ldap | |
import ldap.modlist | |
con = ldap.initialize('ldap://10.5.0.15') | |
con.simple_bind_s('cn=admin,dc=test,dc=com', 'crapper') | |
ldap_base = 'dc=test,dc=com' | |
query = '(uid=johndoe)' | |
result = con.search_s(ldap_base, ldap.SCOPE_SUBTREE, query) | |
for i in xrange(12500): | |
user_num = '{0:0>5}'.format(i) | |
uid = 'testuser{user_num}'.format(user_num=user_num) | |
dn = 'uid={uid},ou=users,dc=test,dc=com'.format(uid=uid) | |
if i % 100 == 0: | |
print("... current user = {}".format(user_num)) | |
modlist = { | |
'objectClass': ['inetOrgPerson', 'posixAccount', 'shadowAccount'], | |
'uid': [uid], | |
'sn': ['Test User {}'.format(user_num)], | |
'givenName': ['Test'], | |
'cn': [uid], | |
'displayName': ['Test User 00001'], | |
'uidNumber': ['{}'.format(5000+i)], | |
'gidNumber': ['{}'.format(600+i)], | |
'loginShell': ['/bin/sh'], | |
'homeDirectory': ['/home/{}'.format(uid)], | |
'userPassword': ['{MD5}X03MO1qnZdYdgyfeuILPmQ=='], # password | |
} | |
con.add_s(dn, ldap.modlist.addModlist(modlist)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment