Table of Contents

PHP RFC: LDAP EXOP

Introduction

LDAP is a broad-use standard for storing information in a tree-style manner and access it efficiently. It is especially famous for storing user accounts. EXOP are extended operations which goes further than reading/writing LDAP nodes. PHP have php-ldap module for connecting to an LDAP server and read/write datas but no way of doing EXOP operations.

Proposal

This RFC intends to add support for EXOP in php-ldap. It is based on a patch for php-ldap which is more than 10 years old and we are trying to adapt it for current code base.

New functions

In all these functions $link should be a valid LDAP connection object with a user bound to it already.

mixed ldap_exop(resource $link, string $reqoid [, string $reqdata [, string &$retdata [, string &$retoid]]])

Returns FALSE upon failure, TRUE upon success if $retdata is provided, and a result object otherwise (success with 3 params or less). Either fills $retoid and $retdata or returns a result object.

bool ldap_parse_exop(resource $link, resource $result [, string &$retdata [, string &$retoid]])

Returns TRUE upon success and FALSE upon failure. Fills $retoid and $retdata with the data from $result object.

Note that $retoid is useless in most cases, EXOPs usually leave it empty or fill it with $reqoid. This is why it’s in last position.

This RFC also wish to introduce helper functions for common EXOP usage:

bool|string ldap_exop_whoami(resource $link)
bool|string ldap_exop_passwd(resource $link, [string $user, [string $oldpw, [string $newpw]]])

The first one would call whoami EXOP and returns the result. Returns FALSE upon failure. The second one would call passwd EXOP and return TRUE or FALSE upon failure. If $newpw is empty, returns the generated password for the user. If $user is empty, it affects the bound user.

The author of the original patch stated that technically ldap_start_tls is an exop helper and therefore could be renamed ldap_exop_start_tls. We feel this would be a useless BC.

The original patch (and current code) provided a possibility to get a result object from helpers as well, and provided ldap_parse_exop_* helpers to parse the result objects from these operations. We feel this is too complex and does not add anything to the RFC so we intend to leave them out.

For consistency with existing ldap functions, theses function may produce E_WARNING in case of error or failure. The safe way to use them is to use @ when calling them. ldap_error() can be used to get the last LDAP error in cases where it makes sense.

Examples

// Call EXOP whoami and store the result in $identity
if (ldap_exop($link, LDAP_EXOP_WHO_AM_I, NULL, $identity)) {
  echo "Connected as $identity\n";
} else {
  echo "Operation failed\n";
}
// Same thing using a result object
$r = ldap_exop($link, LDAP_EXOP_WHO_AM_I);
if (($r !== FALSE) && ldap_parse_exop($link, $r, $retdata)) {
  echo "Connected as $retdata\n";
} else {
  echo "Operation failed\n";
}
// Same thing with the helper
if (ldap_exop_whoami($link, $identity)) {
  echo "Connected as $identity\n";
} else {
  echo "Operation failed\n";
}
// Changing password with the helper
if (ldap_exop_passwd($link, 'uid=johndoe,dc=example,dc=com', '', 'newpassword')) {
  echo "Password changed\n";
} else {
  echo "Operation failed\n";
}

Backward Incompatible Changes

None

Proposed PHP Version(s)

Next PHP 7.x release

RFC Impact

To SAPIs

No impact

To Existing Extensions

Only php-ldap will be affected.

New Constants

The following constants will be added, containing string OIDs for the following extended operations:

Open Issues

  1. Should we include a constant for LDAP_EXOP_CANCEL, for the sake of completeness, even if this EXOP won’t be used by PHP code as all PHP LDAP operations are synchrone (in the current code state).

Unaffected PHP Functionality

All already existing ldap related methods stays the same. This RFC only adds new ones.

Future Scope

Support for more EXOP could be added by adding other helper methods or other oid constants. Support for clients/servers controls should be added but will be part of an other RFC.

Proposed Voting Choices

Include these so readers know where you are heading and can discuss the proposed voting options.

State whether this project requires a 2/3 or 50%+1 majority (see voting)

Patches and Tests

https://github.com/MCMic/php-src/tree/ldap_exop

Implementation

Merged in PHP 7.2 https://github.com/php/php-src/pull/2608

  1. a link to the PHP manual entry for the feature

References

http://grokbase.com/t/php/php-internals/05bn5vc440/discussion-of-ldap-api-extensions https://bugs.php.net/bug.php?id=69445

Rejected Features

None