通过 CGI 将对象添加到 LDAP
我有一个 Web 表单,用于收集信息并将其提交给尝试将数据插入 LDAP 的 cgi。问题是我试图将变量与 ::ldap::add 一起使用,但它不起作用。代码如下:
if {[string length env(QUERY_STRING)] != 0} {
set handle [::ldap::connect localhost]
set dn "cn=admin,dc=mycompany,dc=com"
set pw "myPassword"
::ldap::bind $handle $dn $pw
set dn "cn=[ncgi::value givenName] [ncgi::value sn],ou=people,dc=mycompany,dc=com"
set formValues [
puts "cn {{[ncgi::value givenName] [ncgi::value sn]}}"
puts "displayName [ncgi::value givenName] [ncgi::value sn]"
foreach {key value} [ncgi::nvlist] {
if {[string length $value] != 0} {
puts "$key $value"
}
}
puts "objectClass top"
puts "objectClass person"
puts "objectClass organizationalPerson"
puts "objectClass inetOrgPerson"
]
::ldap::add $handle $dn {
$formValues
}
ldap::unbind $handle
}
但是,如果我将 $formValues 替换为我想要插入到 LDAP 中的实际条目,它们就会被很好地添加。
我是 TCL 的新手,所以如果这段代码中存在一些明显的错误,我不会感到惊讶。
提前致谢!
I have a web form that collects information and submits it to a cgi that attempts to insert the data into LDAP. The problem is that I'm trying to use a variable with ::ldap::add and it's just not working. Here's the code:
if {[string length env(QUERY_STRING)] != 0} {
set handle [::ldap::connect localhost]
set dn "cn=admin,dc=mycompany,dc=com"
set pw "myPassword"
::ldap::bind $handle $dn $pw
set dn "cn=[ncgi::value givenName] [ncgi::value sn],ou=people,dc=mycompany,dc=com"
set formValues [
puts "cn {{[ncgi::value givenName] [ncgi::value sn]}}"
puts "displayName [ncgi::value givenName] [ncgi::value sn]"
foreach {key value} [ncgi::nvlist] {
if {[string length $value] != 0} {
puts "$key $value"
}
}
puts "objectClass top"
puts "objectClass person"
puts "objectClass organizationalPerson"
puts "objectClass inetOrgPerson"
]
::ldap::add $handle $dn {
$formValues
}
ldap::unbind $handle
}
However, if I replace $formValues with the actual entries that I want to insert into LDAP, they get added just fine.
I'm new to TCL so I wouldn't be surprised if there were some glaring errors in this snippet.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最大的错误:
修复方法是使用列表命令来构建与 ldap::add 一起使用的描述。例如:
此外,如果这些密钥来自表单,您应该添加更多验证以阻止恶意用户添加意外的额外内容,例如额外的
objectClass
es。一盎司的预防胜过一英担的治疗。The big mistakes:
puts
commands sends strings to stdout (or a file) and doesn't save them for processing later.The fixes are to use list commands to build the description to use with
ldap::add
. For example:Also, if those keys are coming from a form, you should add more validation to stop malicious users from adding unexpected extras like additional
objectClass
es. An ounce of prevention is worth a hundredweight of cure.