Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

AD.pm: add methods is_AD & is_ADAM

Add methods to determine whether an LDAP server is an AD,
so that the AD specific methods can be used.
  • Loading branch information...
commit b23ae5f79e79ec83f8a3613fec855cf035ee15b7 1 parent 8da9113
Peter Marschall marschap authored

Showing 1 changed file with 40 additions and 3 deletions. Show diff stats Hide diff stats

  1. +40 3 lib/Net/LDAP/Extra/AD.pm
43 lib/Net/LDAP/Extra/AD.pm
@@ -4,11 +4,30 @@ use strict;
4 4 use vars qw($VERSION @EXPORT);
5 5 use Encode;
6 6 use Exporter qw(import);
  7 +use Net::LDAP::RootDSE;
7 8
8   -$VERSION = "0.01";
9   -@EXPORT = qw(reset_ADpassword change_ADpassword);
  9 +$VERSION = "0.02";
  10 +@EXPORT = qw(is_AD is_ADAM reset_ADpassword change_ADpassword);
10 11
11 12
  13 +sub is_AD {
  14 + my $self = shift;
  15 + my $rootdse = $self->root_dse(attrs => [ qw/supportedCapabilities/ ])
  16 + or return undef;
  17 +
  18 + return (grep { $_ eq '1.2.840.113556.1.4.800' } $rootdse->get_value('supportedCapabilities'))
  19 + ? 1 : 0;
  20 +}
  21 +
  22 +sub is_ADAM {
  23 + my $self = shift;
  24 + my $rootdse = $self->root_dse(attrs => [ qw/supportedCapabilities/ ])
  25 + or return undef;
  26 +
  27 + return (grep { $_ eq '1.2.840.113556.1.4.1851' } $rootdse->get_value('supportedCapabilities'))
  28 + ? 1 : 0;
  29 +}
  30 +
12 31 sub reset_ADpassword {
13 32 my ($self, $dn, $newpw, %opt) = @_;
14 33 my %attrs;
@@ -45,7 +64,9 @@ Net::LDAP::Extra:AD -- AD convenience methods
45 64
46 65 ...
47 66
48   - $ldap->change_ADpassword($dn, $old_password, $new_password);
  67 + if ($ldap->is_AD || $ldap->is_ADAM) {
  68 + $ldap->change_ADpassword($dn, $old_password, $new_password);
  69 + }
49 70
50 71 =head1 DESCRIPTION
51 72
@@ -60,6 +81,22 @@ To do so, it provides the following methods:
60 81
61 82 =over 4
62 83
  84 +=item is_AD ( )
  85 +
  86 +Tell if the LDAP server queried is an Active Directory Domain Controller.
  87 +
  88 +As the check is done by querying the root DSE of the directory,
  89 +it works without being bound to the directory.
  90 +
  91 +=item is_ADAM ( )
  92 +
  93 +Tell if the LDAP server queried is running AD LDS
  94 +(Active Directory Lightweight Directory Services),
  95 +previously known as ADAM (Active Directoy Application Mode).
  96 +
  97 +As the check is done by querying the root DSE of the directory,
  98 +it works without being bound to the directory.
  99 +
63 100 =item change_ADpassword ( DN, OLD_PASSWORD, NEW_PASSWORD )
64 101
65 102 Change the password of the account given by I<DN> from

0 comments on commit b23ae5f

Please sign in to comment.
Something went wrong with that request. Please try again.