Created
November 15, 2013 08:53
-
-
Save shutingrz/7481240 to your computer and use it in GitHub Desktop.
LDAP in ConvivialNet.
deluser.
v0.0.2
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
| #!/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