【问题标题】:LDAP- ldap.add does not add entries to the LDAP serverLDAP- ldap.add 不向 LDAP 服务器添加条目
【发布时间】:2019-08-19 01:55:55
【问题描述】:

我是使用 LDAP 的新手,非常感谢任何帮助。

我正在编写一个向 LDAP 服务器添加条目的 Ruby 程序。我可以使用终端很好地添加条目。但挑战在于使用 Ruby 使其工作。

这是我要写入的 LDAP 服务器。

# example.org
dn: dc=example,dc=org
objectClass: top
objectClass: dcObject
objectClass: organization
o: Example Inc.
dc: example

# admin, example.org
dn: cn=admin,dc=example,dc=org
objectClass: simpleSecurityObject
objectClass: organizationalRole
cn: admin
description: LDAP administrator
userPassword: mypassword

# people, example.org
dn: ou=people,dc=example,dc=org
objectClass: organizationalUnit
ou: people

这里是 ldap-program.rb 的内容。对于

    require 'rubygems'
    require 'net/ldap'

    ldap = Net::LDAP.new  :host => '127.0.0.1',
                            :port => 1300,
                            :auth => {
                                :method => :simple,
                                :username => 'cn=admin,dc=example,dc=org',
                                :password => 'mypassword'
    }

  dn = "uid=christine,ou=people,dc=example,dc=com"
attr = {
  :cn => "Christine",
  :sn => "Smith",
  :objectClass => "inetOrgPerson",
  :mail => "christine@example.com",
  :uid => "christine"
}

ldap.add(:dn => dn, :attr => attr)

我一直在密切关注 ldap.add 的文档,但在这种情况下,该条目不会添加到 LDAP。谁能给点指点或建议?

【问题讨论】:

标签: ruby database active-directory ldap ldap-query


【解决方案1】:

我不是 Ruby 开发人员,所以我的代码示例可能需要调整。但是如果您使用的是 Active Directory,那么我会发现两个问题:

  1. objectClass 应该是 user
  2. 在 AD 中,uid 属性没有特殊含义。用于登录的用户名是sAMAccountName 属性。
attr = {
  :cn => "Christine",
  :sn => "Smith",
  :objectClass => "user",
  :mail => "christine@example.com",
  :sAMAccountName => "christine"
}

您可能还想设置givenName,这是用户的名字。

如果这不起作用,请告诉我们您遇到了什么错误。

这将创建处于禁用状态的帐户。要启用它,您需要在第二步中通过设置unicodePwd 属性(格式怪异)为其提供密码,并更新userAccountControl 属性以启用它。

使用这些属性再次修改它(其中新密码为"new_password"):

def self.str2unicodePwd(str)
    ('"' + str + '"').encode("utf-16le").force_encoding("utf-8")
end

attr = {
  :unicodePwd, str2unicodePwd("new_password"),
  :userAccountControl, 0x200
}

我从here 借了一些代码作为密码位。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-26
    • 1970-01-01
    • 2010-11-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多