Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding objects to LDAP via CGI

Status
Not open for further replies.

musashiXXX

Programmer
Mar 27, 2010
1
US
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:

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 {
                [COLOR=red]$formValues[/color]
        }

        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!
 
One issue is that you've called the proc
Code:
::ldap::add $handle $dn {
                $formValues
        }

The curly braces prevent the variable from expanding. You need to lose them and the line breaks.

Code:
::ldap::add $handle $dn $formValues

That should do it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top