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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

perl ldap "like search"

Status
Not open for further replies.

j0nxuser

Technical User
May 4, 2003
31
0
0
US
What would be the best way to search for a user in LDAP with a "like". I have a list of people that need to verified/validated in our corp. LDAP directory. The problem is if the cn attribute contains anything other "firstname lastname" my search fails (rightly so - I'm looking for an exact match). Now, what can I do when I have a name like "Jay Carnell" and I have the following attributes:

cn = "Jay Carnell II James Carnell II"
sn = "Carnell II"
givenname = "Jay James"

Can you do a like match on cn? (if so, how)

Thank you!
Mark
 
It's not possible to suggest a total solution without more information. However, all I believe your searching for is an exposure to regular expressions:

Code:
[url=http://perldoc.perl.org/functions/my.html][black][b]my[/b][/black][/url] [blue]$cn[/blue] = [red]"[/red][purple]Jay Carnell II James Carnell II[/purple][red]"[/red][red];[/red]

[olive][b]if[/b][/olive] [red]([/red][blue]$cn[/blue] =~ [red]/[/red][purple]Jay Carnell[/purple][red]/[/red][red])[/red] [red]{[/red]
	[url=http://perldoc.perl.org/functions/print.html][black][b]print[/b][/black][/url] [red]"[/red][purple]Matched[purple][b]\n[/b][/purple][/purple][red]"[/red][red];[/red]
[red]}[/red]

- Miller
 
Sorry about that. Let me ask it this way, is there a way to do this exclusively within Net::LDAP?

My ultimate goal is to take a list of names and throw them into LDAP to see if they are valid. The problem that I have is that I only have a first name and a last name. Using some examples below:

1) Pate,Joe
cn= Jj Pate Jr Joe Pate Jr
sn= Pate Jr
givenname= Jj Joe

2) Carnell,Jay
cn= Jay Carnell II James Carnell II
sn= Jay James
givenname= Carnell II


sn=lastname
cn=wholenames
givenname=firstname

With Net::LDAP I would like to see if these users match in the "cn" attribute, however not knowing how to do that, I am guessing that I can match on the last name "sn" and throw all of these results into an array (along with the first name). Then I can loop through all of them until I get a match. But the next problem is that the givenname attribute may say:

Jay James or Mike Michael

Which means that I would have to use regex to split multiple first name matches. All of the said, I was wondering if there was a "like" in Net::LDAP.

Is this possible?
$mesg = $ldap->search(
base => $base_dn,
scope => 'sub',
filter => 'cn=~/Jay Carnell/'
);



I hope that makes sense.

Thanks again, Mark

 
Miller - I started to look at some of these documents and believe that they will be able to help me out.

Thanks again and will keep ya' posted.

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top