Skip to content

Instantly share code, notes, and snippets.

@shutingrz
Created November 15, 2013 08:53
Show Gist options
  • Select an option

  • Save shutingrz/7481240 to your computer and use it in GitHub Desktop.

Select an option

Save shutingrz/7481240 to your computer and use it in GitHub Desktop.
LDAP in ConvivialNet. deluser. v0.0.2
#!/usr/bin/env ruby
#
#version 0.0.1
# author alvise
# description
# "first version."
#
#version 0.0.2
# author shu
#****** change log ************************
#
# +add rootdn input.
# ++add rootdn validation
#
#******************************************
require "rubygems"
require "ldap"
require "optparse"
Version = "0.0.2"
opt = OptionParser.new
opt.banner = "Usage: ldap_deluser.rb [option] uid"
opt.on_tail("-h", "--help", "Show this message") do
puts opt
exit
end
opt.on_tail("--version", "Show Version") do
puts Version
exit
end
uid = opt.order!(ARGV)
uid = uid[0]
if ARGV == nil or ARGV.length <= 0 then
puts opt.help
exit
end
#rootdn validation
begin
system "stty -echo"
print "rootdn Password:"
rootdnpassword = STDIN.gets
system "stty echo"
puts
@validrootdn= LDAP::Conn.new('localhost', 389)
@validrootdn.set_option(LDAP::LDAP_OPT_PROTOCOL_VERSION,3)
@validrootdn.bind("cn=Manager,dc=convivial,dc=ne,dc=jp", rootdnpassword.chomp)
rescue LDAP::ResultError
print "rootdn Password is not match. Please again.\n\n"
retry
ensure
@validrootdn.unbind()
end
dn = "uid=#{uid},ou=People,dc=convivial,dc=ne,dc=jp"
@conn = LDAP::Conn.new('localhost', 389)
@conn.set_option(LDAP::LDAP_OPT_PROTOCOL_VERSION,3)
begin
@conn.bind("cn=Manager,dc=convivial,dc=ne,dc=jp", rootdnpassword.chomp)
@conn.delete(dn)
rescue => e
p e
ensure
@conn.unbind()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment