簡體   English   中英

LDAP- ldap.add不會將條目添加到LDAP服務器

[英]LDAP- ldap.add does not add entries to the LDAP server

我是使用LDAP的新手,感謝您的幫助。

我正在編寫一個將條目添加到LDAP服務器的Ruby程序。 我可以使用Terminal添加條目。 但是挑戰在於如何使其能夠使用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開發人員,因此我的代碼示例可能需要調整。 但是,如果您使用的是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
}

我從這里借了一些代碼作為密碼位。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM