xcorp::When it rains, it pours.

"The nice thing about rain," said Eeyore, "is that it always stops. Eventually."

忘れないうちにメモ

LDAP で dn を変更することがあったりするんだが、Ruby/LDAP でそれを実現しちゃうためにはコレ。

#!/usr/bin/ruby --

require 'ldap'

conn = LDAP::Conn.new('localhost', LDAP::LDAP_PORT)
conn.set_option(LDAP::LDAP_OPT_PROTOCOL_VERSION, 3)
conn.bind('cn=root,dc=localhost,dc=localdomain', 'password')

begin
  conn.modrdn("o=hoge,dc=localhost,dc=localdomain", # old RDN
              "o=fuga",                             # new RDN
              true)                                 # remove old RDN if true
rescue => e
  warn(e.inspect)
end

conn.unbind

クラス化していい塩梅にしといたヽ(´ー`)ノ