Created
January 28, 2010 23:26
-
-
Save anonymous/289267 to your computer and use it in GitHub Desktop.
This file contains 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
def addLdapUser(username, lastname, firstname, email, ldapuser, ldappassword) | |
config = loadConfig('../configuration.yaml') | |
l = LdapConnection.new | |
l.login(ldapuser, ldappassword) | |
uidNumber = l.findNextUIDNumber.to_s | |
gidNumber = config['UserSetup']['DefaultGroupID'].to_s | |
options = { 'cn' => [ lastname ] , | |
'sn' => [ lastname ] , | |
'mail' => [ email ] , | |
'uid' => [ username ] , | |
'uidNumber' => [ uidNumber ] , | |
'gidNumber' => [ gidNumber ] , | |
'gecos' => [ "#{firstname} #{lastname}" ] , | |
'homedirectory' => [ config['UserSetup']['HomePrefix'] + '/' + username ] , | |
'loginshell' => [ config['UserSetup']['LoginShell'] ] , | |
'givenName' => [ firstname ] , | |
'objectclass' => config['UserSetup']['ObjectClasses'] | |
} | |
dn = "uid=#{username},#{config['UserSetup']['AccountOU']},#{config['LDAPInfo']['BaseDN']}" | |
begin | |
l.add(dn, options) | |
# This might be rescuing other types of errors than simply duplicates, but I haven't been able to create any yet | |
rescue LDAP::ResultError | |
puts "Userid '#{username}' already found in LDAP." | |
exit 2 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment