我对LDAP的工作非常陌生,任何帮助我都很感激。
我正在编写一个Ruby程序,用于向LDAP服务器添加条目。我可以使用终端添加条目。但挑战在于如何使用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中。有没有人能给点建议呢?
发布于 2019-08-21 02:28:03
我不是Ruby开发人员,所以我的代码示例可能需要调整。但是,如果您使用的是Active Directory,那么我看到两个问题:
objectClass应该是 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借了一些代码来实现密码位。
https://stackoverflow.com/questions/57549697
复制相似问题