From: Philip L. <pl...@ar...> - 2002-01-07 23:34:46
|
I hope you'll all excuse what's probably a really basic error on my part, but I'm having trouble with any search filter that includes givenName or commonName as a term. Both these attribs are indexed sub, eq and pres. We're using Netscape Directory 4.12 here. My script loops through a .csv file which includes the First and Last Name of a user on each line. What I'm trying to do is match against either First AND Last Name or Full Name (cn) on the Directory. It does work if I only include the Last Name (although the result of such a search is pretty much useless for my purposes). Here's my code (excuse the poor programming style, Until a year ago I was just an NT desktop guy -- better to be embaressed than to continue in ignorance though): use strict; use Net::LDAP; use Text::ParseWords; # Global variables for bind my $host = 'ldap.arrow.com'; my $ldap = new Net::LDAP($host); my $mesg = $ldap->bind('cn=Directory Manager', password=> 'xxxxxxx'); die ("failed to bind with ",$mesg->code(),"\n") if $mesg->code(); # Open the data files open INFILE, '<users.csv' or die $!; open OUTFILE, '>users-uid.csv' or die $!; # Print a header in the outfile print OUTFILE "LanId,LName,FName,Guid,Email\n"; # Parse infile, format: LanId, LName, FName while (<INFILE>) { chomp; my ($LanId, $LName, $FName ) = ( &parse_line(',',0,$_)); my $CName = "$FName $LName"; # Set up search variables my $attrs = "uid,sn,givenname,mail,cn"; my $basedn = "o=company"; my $query = "(cn=$CName)"; # Or this which also doesn't work # my $query = "(&(sn=$LName)(givenname=$FName))"; $mesg = $ldap->search( base => $basedn, scope => 'sub', filter => $query, attr => $attrs ); die "Failed to search with ",$mesg->error(),"\n" if $mesg->code(); # Get values from LDAP while (my $entry = $mesg->shift_entry()) { my $Guid = $entry->get_value('uid'); my $Email = $entry->get_value('mail'); # Print results to file print OUTFILE "$LanId"; print OUTFILE ","; print OUTFILE "\"$LName\""; print OUTFILE ","; print OUTFILE "\"$FName\""; print OUTFILE ","; print OUTFILE "$Guid"; print OUTFILE ","; print OUTFILE "$Email"; print OUTFILE "\n"; } } $ldap->unbind(); close INFILE; close OUTFILE; __END__; -- PHILIP LEMBO Systems Engineer Arrow Electronics, Inc. e-mail: pl...@ar... voice: 631 847 5355 |
From: Philip L. <pl...@ar...> - 2002-01-08 16:21:14
|
All: Someone was kind enough to show me how to debug this. I inserted a print "$query\n" after the search set up and got back 39 lines before it choked (there are over 1000 lines in the file). The line it choked on had a "comment" in the first name field consisting of the user's business group name surrounded by parens. Once I removed these comments from the 5 records that had them the script ran fine. Just another unexciting instance of G-I-G-O. Thanks for everyone's help on this. Phil |
From: Chris R. <chr...@me...> - 2002-01-08 10:33:01
|
Philip Lembo <pl...@ar...> wrote: > I hope you'll all excuse what's probably a really basic error on my part, > but I'm having trouble with any search filter that includes givenName or > commonName as a term. Both these attribs are indexed sub, eq and pres. > We're using Netscape Directory 4.12 here. > > My script loops through a .csv file which includes the First and Last Name > of a user on each line. What I'm trying to do is match against either > First AND Last Name or Full Name (cn) on the Directory. It does work if I > only include the Last Name (although the result of such a search is > pretty much useless for my purposes). > > Here's my code (excuse the poor programming style, Until a year ago I was > just an NT desktop guy -- better to be embaressed than to continue in > ignorance though): > > use strict; > use Net::LDAP; > use Text::ParseWords; > > # Global variables for bind > my $host = 'ldap.arrow.com'; > my $ldap = new Net::LDAP($host); > my $mesg = $ldap->bind('cn=Directory Manager', password=> 'xxxxxxx'); > die ("failed to bind with ",$mesg->code(),"\n") if $mesg->code(); > > # Open the data files > open INFILE, '<users.csv' or die $!; > open OUTFILE, '>users-uid.csv' or die $!; > > # Print a header in the outfile > print OUTFILE "LanId,LName,FName,Guid,Email\n"; > > # Parse infile, format: LanId, LName, FName > while (<INFILE>) { > chomp; > my ($LanId, > $LName, > $FName > ) > = ( &parse_line(',',0,$_)); > > my $CName = "$FName $LName"; > > # Set up search variables > my $attrs = "uid,sn,givenname,mail,cn"; Ah, that should be: my $attrs = ["uid", "sn", "givenname", "mail", "cn"] because the attr argument to search takes a reference to a list as the parameter. (Which is what the [ and ] construct.) As it stands, you're asking the server to return a single attribute called "uid,sn,givenname,mail,cn", which probably won't exist. What result code is returned from the searches, and how many results come back from each one? Cheers, Chris |
From: Philip L. <pl...@ar...> - 2002-01-08 15:36:03
|
Chris: Thanks for the quick reply. I made the changes suggested, but it still doesn't seem to be working. My return code is "255" with the text message, "Failed to search with Bad filter". No results are returned, so it looks like it's failing immediately. Are there some things I should be checking on the server (other than the indexing, although can I really be sure that the indexes are really "working"?)? Phil -----Original Message----- From: Chris Ridd [mailto:chr...@me...] Sent: Tuesday, January 08, 2002 5:33 AM To: Philip Lembo; per...@li... Subject: Re: Search Filter Problem - Can't Search on cn or givenName Philip Lembo <pl...@ar...> wrote: > I hope you'll all excuse what's probably a really basic error on my part, > but I'm having trouble with any search filter that includes givenName or > commonName as a term. Both these attribs are indexed sub, eq and pres. > We're using Netscape Directory 4.12 here. > > My script loops through a .csv file which includes the First and Last Name > of a user on each line. What I'm trying to do is match against either > First AND Last Name or Full Name (cn) on the Directory. It does work if I > only include the Last Name (although the result of such a search is > pretty much useless for my purposes). > > Here's my code (excuse the poor programming style, Until a year ago I was > just an NT desktop guy -- better to be embaressed than to continue in > ignorance though): > > use strict; > use Net::LDAP; > use Text::ParseWords; > > # Global variables for bind > my $host = 'ldap.arrow.com'; > my $ldap = new Net::LDAP($host); > my $mesg = $ldap->bind('cn=Directory Manager', password=> 'xxxxxxx'); > die ("failed to bind with ",$mesg->code(),"\n") if $mesg->code(); > > # Open the data files > open INFILE, '<users.csv' or die $!; > open OUTFILE, '>users-uid.csv' or die $!; > > # Print a header in the outfile > print OUTFILE "LanId,LName,FName,Guid,Email\n"; > > # Parse infile, format: LanId, LName, FName > while (<INFILE>) { > chomp; > my ($LanId, > $LName, > $FName > ) > = ( &parse_line(',',0,$_)); > > my $CName = "$FName $LName"; > > # Set up search variables > my $attrs = "uid,sn,givenname,mail,cn"; Ah, that should be: my $attrs = ["uid", "sn", "givenname", "mail", "cn"] because the attr argument to search takes a reference to a list as the parameter. (Which is what the [ and ] construct.) As it stands, you're asking the server to return a single attribute called "uid,sn,givenname,mail,cn", which probably won't exist. What result code is returned from the searches, and how many results come back from each one? Cheers, Chris |