From: Padraig R. <rya...@it...> - 2000-10-06 14:35:26
|
For those of you interested here is the function to enumerate groups from an ldap server - note the $Search_Base variable needs to be set globally before calling. It calls the secondary search_Ldap() function provided. Thanks to Mark Wilcox for the broader search filter. Padraig. ############################################## ## Function to return All Groups from Ldap ## ############################################## sub Get_Groups { # Arguments to be passed in the following format.. # &Get_Groups; $ldap=Net::LDAP->new($Ldap_Server) or die 'Problem with Ldap $@'; $Filter='(|(objectclass=groupOfUniqueNames)(objectclass=groupOfNames))'; $result=&Search_Ldap($Search_Base, $Filter); @entries = $result->all_entries; #Store all found groups in table, $i = 0; foreach (@entries) { $ptr = $_->get('cn'); foreach $member (@$ptr){ #store each memberid in table @memberData = split(/,/, $member); $Groups[$i] = $memberData[0]; } $i++; } return $Groups; } ################################# ### Function to Search Ldap ##### ################################# sub Search_Ldap { # Arguments to be passed in the following format.. # &Search_Ldap($Search_Base, $Filter); my ($Search_Base, $Filter) = @_; $mesg=$ldap->search (base=>$Search_Base,filter=>$Filter); $mesg->code && die $mesg->error; #on errors, show error mesg and quit return $mesg; } ---------------------------------------------------------------- Padraig Ryan IT Manager Institute of Technology, Sligo Ireland P +353(0)71.55365 F +353(0)71.60475 M +353(0)87.2334062 E rya...@it... W http://www.itsligo.ie/staff/pryan ----- Original Message ----- From: "Mark Wilcox" <mew...@un...> To: "Padraig Ryan" <rya...@it...> Cc: "LDAP Mailing List" <per...@li...> Sent: Friday, October 06, 2000 2:31 PM Subject: Re: enumerating groups > You might want to look at the "printMembers.pl and ismember.pl" scripts in > the contrib directory. > > Mark > > On Fri, 6 Oct 2000, Padraig Ryan wrote: > > > Hi, > > > > Does anyone have a code snippet that will enumerate the groups from an ldap > > server. > > > > I have the follwing but am a bit stuck...Thanks. > > > > Padraig > > > > ############################################## > > ## Funtion to return All Groups from Ldap ## > > ############################################## > > > > sub Get_Groups { > > > > # Arguments to be passed in the following format.. > > # &Get_Groups; > > > > $ldap=Net::LDAP->new($Ldap_Server) or die 'Problem with Ldap $@'; > > $Filter='(&(cn=*)(objectClass=groupOfUniqueNames))'; #search for all > > Groups > > > > $result=&Search_Ldap($Search_Base, $Filter); > > print "<BR>====DEBUG==== result of group search=".$result if $DEBUG; > > > > @entries = $result->all_entries; #Store all found groups in table, > > print "<BR>====DEBUG==== entries=".@entries if $DEBUG; > > > > foreach (@entries) { > > $ptr = $_->get('Name'); > > $i = 0; > > foreach $member (@$ptr){ #store each memberid in table > > @memberData = split(/,/, $member); > > $memberData[0] = substr($memberData[0], 4); > > print "<BR>====DEBUG==== Groups=".$Groups[$i] if $DEBUG; > > > > $Groups[$i] = $memberData[0]; > > $i++; > > } > > } > > return $Groups; > > } > > > > > > ---------------------------------------------------------------- > > Padraig Ryan > > IT Manager > > Institute of Technology, Sligo > > Ireland > > > > P +353(0)71.55365 > > F +353(0)71.60475 > > M +353(0)87.2334062 > > E rya...@it... > > W http://www.itsligo.ie/staff/pryan > > > > > > > |