Jump to content

Recommended Posts

I'm trying to detect whether a user in LDAP is expired or not after a bind.

 

LDAP RFC's specify a control (OID: 2.16.840.1.113730.3.4.4) which tells the server to return if a password has expired after a bind.

 

I am using the following code to attempt to enable this control:

 

$ld = ldap_connect( $host );
ldap_set_option( $ld, LDAP_OPT_PROTOCOL_VERSION, 3 );
$ctrl1 = array( "oid" => "2.16.840.1.113730.3.4.4", "iscritical" => false );
ldap_set_option( $ld, LDAP_OPT_SERVER_CONTROLS, array( $ctrl1 ) );

$bind = ldap_bind( $ld, $userDN, $password );
if ( !( $bind ) ) {
   print ldap_errno( $ld )  . " " . ldap_error( $ld ) . "<br>\n";
}

 

This code returns ldap error 49, which is Invalid Credentials, but thats it.  It doesn't specify that the password is expired.

 

The ldap_set_option function returns true, so I'm assuming the server is made aware of the control, but I can't figure out how to retrieve the control or message stating if the password is expired or not.

 

I know how to do this in Perl, but PHP's LDAP implementation is vastly different than Perl's Net::LDAP implementation.

 

Any help would be appreciated!

Link to comment
https://forums.phpfreaks.com/topic/48687-ldap-controls-password-expiration/
Share on other sites

This may help

 


<?php

define(AD_SERVER,   "192.168.1.4");
define(AD_USER,     "bob@testdomain.com");
define(AD_PASSWORD, "Passssss");

// Connect to the directory server.
$ad = ldap_connect("ldap://" . AD_SERVER) 
        or die("Couldn't connect to AD!");

ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ad, LDAP_OPT_REFERRALS, 0);

// Bind to the directory server.
$bd = ldap_bind($ad, AD_USER, AD_PASSWORD)
        or die("Couldn't bind to AD!");


$dn = "CN=Users,DC=testdomain,DC=com";
$attributes = array("displayname");
$filter = "(objectcategory=user)";

$result = ldap_search($ad, $dn, $filter, $attributes)
            or die("Search failed!");

$entries = ldap_get_entries($ad, $result);
var_dump($entries); //<--may help

ldap_unbind($ad);

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.