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

Search Active Directory

Status
Not open for further replies.

rbri

Programmer
Jun 27, 2002
84
US
Hello Everyone

I wrote a program that searches our Active Directory. It works great as long as I hard code all the variables into the program. I wanted to add the ability to allow a user other than myself to run the program so I added code to prompt a user to enter there loginID there password and the usersID they want to search for however when this code is added the program will not work it just hangs and nothing happens. Any help I can get will be greatly appreciated. Thanks inadvance for any help. Below is my code.

use strict;
use Net::LDAP;

### Newly added code#

system("clear");
print("Enter your ZID: ");
my $sMyZid = <STDIN>;
chop $sMyZid;
print("Enter your northamerica PW: ");
my $sPw = <STDIN>;
chop $sPw;
system("clear");
print("Enter ZID to search for: ");
my $sZid = <STDIN>;
chop $sZid;

####



# Connection and binding parameters
my $dc = 'my domain';
my $user = 'my loginID'; #hard coded
my $passwd = 'my password'; #hard coded
my $port = '3268';
my $host = 'my hostname';


# Search parameters
my $base = "dc=delphiauto,dc=net";
my $scope = "subtree";
my $filter = "(&(objectclass=user)(objectcategory=user)(sAMAccountName=loginIDtoSearchFor))"; #hard coded
my @attrs = qw(cn mail telephoneNumber physicalDeliveryOfficeName l co);

my $ldap = Net::LDAP->new($dc, hostname => $host, port => $port) or die $@;

my $rc = $ldap->bind( $user, password => $passwd,);
die $rc->error if $rc->code;

#----------------#
# Callout A
#----------------#
my $search = $ldap->search (
base => $base,
scope => $scope,
filter => $filter,
attrs => [@attrs]
);
die $search->error if $search->code;

#----------------#
# Callout B
#----------------#
foreach my $entry ($search->entries) {
$entry->dump;
}

$ldap->unbind;
 
Check whether other users have permission to search the directory.
 
Hello

I thought about that also so I tried just asking for a loginID to search for and left my loginID and password hard coded in the program but, that doesn't work either. I am not sure what the problem is I can't seem to find any documentation on this every example I find always shows all the variable hard coded into the program. There must be away I just can't find it.

Thanks Randy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top