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!

How do i query a row in an array?

Status
Not open for further replies.

unixb0y

Technical User
Jul 8, 2003
9
0
0
CA
Here is the code
@fields =
(
# Label Field Name Index
['User ID' , 'uid' , 0],
['Account Locked' , 'nsaccountlock' , 0],
);

##
# LDAP query to make for a shorter post
##


foreach $entry ($mesg->all_entries)
{
@dn = map {s/[a-z]+=//gi; $_ = ucfirst}
reverse split /,/, $entry->dn;
shift @dn;
pop @dn;
#Start of question
print ''.(join ' ',
map {get $entry, $_->[1], $_->[2]} @fields)."\n";
#End of question
}

How would i query the row.

eg:

If ('nsaccountlock=true') {
print ''.(join ' ',
map {get $entry, $_->[1], $_->[2]} @fields)."\n";
}

 
Paul,

I think unixboy cut out the LDAP query portion of this script. Here's one that I use, which uses "most" of the same variables. (Just ignore the LDAPFail piece, it's my own error subroutine.)

Code:
my $ldap = Net::LDAP->new($LDAP) or keelover("Cannot connect to LDAP server", "4");
$ldap->bind();

# Do a simple search on a person
my $mesg = $ldap->search(	base => "ou=People,dc=domain,dc=net",
												filter => "(uid=$username)");

$mesg->code && LDAPFail($mesg->error);

# Now log into the LDAP Server
my $entry = $mesg->entry(0);
my $dn = $entry->dn;

my $result = $ldap->bind(	dn  => $dn,
											password => $password);

$result->code && LDAPFail($result->error);

$ldap->unbind;

I'm not too familiar with map, so I couldn't help out more I'm afraid.

- Rieekan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top