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 |