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!

Global symbol "$ldap" requires explicit package name error

Status
Not open for further replies.

williey

Technical User
Jan 21, 2004
242
Currently, I'm working on adding, changing, deleting and searching the Active Directory using Perl.

But I get the following error when I try to add.

Code:
Global symbol "$ldap" requires explicit package name at  bind.pl line 44, <DATA> line 225.

Line 44 is
Code:
$results = $ldap->add('cn=Jane Doe, ou=retail, ou=users, ou=level2, dc=test, dc=lab',
                   attr=>['cn' => 'Jane Doe',
                          'sn' => 'Doe',
                          'mail' => 'jdoe@cnb.lab',
                          'objectclass' => ['top', 'person', 'organizationalPerson', 'user'],
                          ]);

Here is the compelte code.
Code:
use Net::LDAP;
use strict;

my $connect=Net::LDAP->new('server01.test.lab') 
         or die("Could not connect to LDAP server");

#Connect to server

my $mesg=$connect->bind("admin\@test.lab", password=>"pass");

#What is the search base?

my $base='ou=retail,ou=users,ou=level2,DC=test,DC=lab';

my $scope="subtree";

#What are we searching for?

my $filter="(&(objectclass=User))";

#What attributes should be returned?
   
my $attrs="sn";

#Execute the search


my $results=$connect->search(base=>$base, scope=>$scope, filter=>$filter, attrs=>$attrs);

my $count=$results->count;

print("Total entries returned: $count\n");

#Display entries
my $entry;

for (my $i=0; $i<$count; $i++)
  {
    $entry=$results->entry($i);
    print $entry->get_value('sn') . ", " . 
          $entry->get_value('givenname') . " " . 
          $entry->get_value('userprincipalname') . " " .
          $entry->get_value('sAMAccountname') . "\n";
  }


$results = $ldap->add('cn=Jane Doe, ou=retail, ou=users, ou=level2, dc=test, dc=lab',
                   attr=>['cn' => 'Jane Doe',
                          'sn' => 'Doe',
                          'mail' => 'jdoe@cnb.lab',
                          'objectclass' => ['top', 'person', 'organizationalPerson', 'user'],
                          ]);

$results->code && warn "failed to add entry: ", $results->error;
 
#Unbind from server
$mesg=$connect->unbind;


 
Remove strict from the header and try again to run the script.

Or declare at the beginning of the script the variable $ldap.

Cheers

dmazzini
GSM System and Telecomm Consultant

 
Thanks! Got it to work.

Is there a way to enable the account after inserting it?
Or the only way is to manually enable it?
 
don't remove strict as it will save your behind from plenty of problems. Predeclare $ldap if you have to just like the list of variables you have at the beginning of the script.
 
williey,

That code should read

$results = $connect->add('cn=Jane Doe, ou=retail (etc)

and not

$results = $ldap->add('cn=Jane Doe, ou=retail (etc)

Don't get ride of the "use strict" whatever you do :)

Mike

You cannot really appreciate Dilbert unless you've read it in the
original Klingon.

Want great answers to your Tek-Tips questions? Have a look at faq219-2884

 
Thanks for the reply. I had figure it out. Initially, I had problems trying to understand how to set the OU, DC, etc.

By using the ldp.exe program, the application pretty much provided all the information. Since I'm not an AD administrator, there are information I'm not priviledge to.

AD looks much similar to IMS DB.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top