-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathad_modify.pl
More file actions
58 lines (42 loc) · 1.21 KB
/
ad_modify.pl
File metadata and controls
58 lines (42 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/perl
#
use warnings;
use Net::LDAP;
use Net::LDAP::Bind;
use Net::LDAP::Extra qw(AD);
$ad = Net::LDAP->new( 'ldaps://kdc.eng.cam.ac.uk',
) or die "$@";
$result = $ad->bind( 'AD\gmj33',
password => 'etherline'
);
$ad->debug(12);
sub LDAPsearch
{
my ($ldap,$searchString,$attrs,$base) = @_;
# if they don't pass a base, set it for them
if (!$base ) { $base = "dc=ad,dc=eng,dc=cam,dc=ac,dc=uk"; }
# if they don't pass an array of attributes...
# set up something for them
if (!$attrs ) { $attrs = [ 'cn', 'uidNumber' ]; }
my $result = $ldap->search (
base => "$base",
scope => "sub",
filter => "$searchString",
attrs => $attrs
);
}
my @Attrs = ( );
$result = LDAPsearch( $ad, "sn=Sloan test", \@Attrs );
$result->code && die $result->error;
if ($result->entries != 1 ) { die "ERROR: User not found in AD: " };
my $entry = $result->entry(0); # there can be only one
my $dn = $entry->get_value('distinguishedName');
$result = $ad->modify(
$dn,
replace => {
givenName => 'testname2',
}
);
$result->code && die $result->error;
print "AD : SUCCESS: ${dn} name changes.\n";
$ad->unbind();