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;
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;