From: Jim H. <ha...@us...> - 2002-02-13 15:24:12
|
I haven't seen a request for this before, but here is the strategy you want to use: $mesg = $ldap->search ( base => $wholeorg, filter => "email=$mailaddr", attrs => ['Foo']); if ($mesg->entry(0)->get_value('Foo') eq 'bar') { dogoodstuff() } else { @dnstuff = split /\,/,$mesg->entry(0)->dn); whlie ($#dnstuff > 1) { $newbase = join ',', (shift @dnstuff); $mesg = $ldap->search ( base => $newbase, filter => 'Foo=*', attrs => ['Foo']); foreach $entry ($mesg->all_entries) { if ($entry->get_value('Foo') eq 'bar') { dogoodstuff() } } } --Jim Harle On Wed, 13 Feb 2002, Pop Melfi wrote: > > Apologies if this is a FAQ -- I searched the archives but couldn't see > anything quite like what I wanted to do. > > I want to write a routine that returns the value of attribute 'Foo' > for a given dn (which I'll find by setting a filter like > "email=$mailaddr"). > > If the attribute doesn't exist, I want to take the dn and search in > it's parent for the same attribute. (Now of course the filter will > be different, presumably "Foo=*".) And so on up the directory tree > until I find it. > > Sounds like an exercise in recursion, but I only got the shrink-wrap > off of perl::ldap an hour ago and it sounds like it might be a common > requirement for other people. > > Has anyone cracked this and got sample code they'd be willing to share? > > TIA, > > --herb > |