You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
730 B

#!/usr/bin/env ruby
require 'simple_ldap_authenticator'
raise 'Error: 2 arguments required => email + password' if ARGV.length != 2
email = ARGV.shift
password = ARGV.shift
# puts "email=#{email}"
user = email.split('@').first
fqdn = email.split('@')[1]
fqdn_items = fqdn.split('.')
tld = fqdn_items.last
domain = fqdn_items[0..-2].join('.')
# puts "user=#{user}"
# puts "domain=#{domain}"
# puts "tld=#{tld}"
#
SimpleLdapAuthenticator.servers = ['127.0.0.1']
SimpleLdapAuthenticator.port = 1389
SimpleLdapAuthenticator.use_ssl = false
# SimpleLdapAuthenticator.login_format = '%s@mydomain.com'
SimpleLdapAuthenticator.login_format = "uid=%s,ou=Users,dc=#{domain},dc=#{tld}"
p SimpleLdapAuthenticator.valid?(user, password)