Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:66326 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 6073 invoked from network); 28 Feb 2013 13:54:56 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Feb 2013 13:54:56 -0000 Authentication-Results: pb1.pair.com header.from=ondra.hosek@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ondra.hosek@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.172 as permitted sender) X-PHP-List-Original-Sender: ondra.hosek@gmail.com X-Host-Fingerprint: 209.85.215.172 mail-ea0-f172.google.com Received: from [209.85.215.172] ([209.85.215.172:41588] helo=mail-ea0-f172.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9F/43-17375-EA16F215 for ; Thu, 28 Feb 2013 08:54:55 -0500 Received: by mail-ea0-f172.google.com with SMTP id f13so173365eaa.31 for ; Thu, 28 Feb 2013 05:54:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:from:date:message-id:subject:to :content-type; bh=dH/r1sA6BM2gfwrYSEDdiyfc6jyjLn64+9XNywO+P04=; b=A04XrcNvwHXPQwpnH31AY0XxJMQz12tGJ1RlTlRG+5M+e7UJZbT+kV22F2e01OKrly JLcF9giW76g0XTex+9hTQaJFfeAqhmipIsMlgzi+5fH/ovEabf5biEmUuAAd/SIjWFH7 t3xaxWpfP+jD5ibw10GjcZUDhBPNhGgrJzDIZdHXB3f+G3QWiutkXiNVVcU39XKtVSFU AI1kOy7xjPmivZTNQDqT6nFTksQDsLZegTNvE1W6HQuFbmyBvNjt5IqTFutThGsLWlk3 xBBM9H0fz9VIKsFCBhmldvW+QhnY/nxOMRUTiVK4CZ1VzpupJaOCTRFZGIlaJJeGuHeZ tRNA== X-Received: by 10.14.223.199 with SMTP id v47mr17056845eep.18.1362059691272; Thu, 28 Feb 2013 05:54:51 -0800 (PST) MIME-Version: 1.0 Received: by 10.14.128.3 with HTTP; Thu, 28 Feb 2013 05:54:30 -0800 (PST) Date: Thu, 28 Feb 2013 14:54:30 +0100 Message-ID: To: PHP Internals List Content-Type: multipart/alternative; boundary=047d7b6704cd0fd07604d6c93ccc Subject: new LDAP function: ldap_modify_batch From: ondra.hosek@gmail.com (=?UTF-8?B?T25kxZllaiBIb8WhZWs=?=) --047d7b6704cd0fd07604d6c93ccc Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi, yesterday, I submitted a patch to add a batch modification function to the LDAP extension: https://bugs.php.net/bug.php?id=3D64317 IMNSHO, this would be a very useful addition to PHP=E2=80=99s LDAP API (and= I think the submitter of bug 31209, among others, would agree with me), so I=E2=80= =99d like to ignite a discussion about it, collect feedback, and have it added to PHP as soon as possible. ;-) This email serves as a description of my motivation and addresses a few points of contention that might arise. =3D=3D Motivation =3D=3D PHP=E2=80=99s LDAP extension already allows many modification operations on= an LDAP-enabled directory service. In fact, all the basic features (create/delete object, add/remove/replace attribute values) are available. However, LDAP itself allows to combine multiple modifications into one request, and some directory services (e.g. Active Directory and, apparently, Novell NDS) require this for more delicate operations such as changing (not resetting) a user=E2=80=99s password. My original motivation was wanting to write a password-changing page for an Active Directory domain. However, I tried to keep the interface as generic as possible, since I obviously can=E2=80=99t think of every possible use ca= se. =3D=3D Interface =3D=3D (This is, of course, subject to change, depending on your feedback.) The API is as follows: bool ldap_modify_batch(resource $connection, string $dn, array $modifications); $connection contains the connection to the LDAP server, as returned by ldap_connect. $dn contains the Distinguished Name of the object to modify. $modifications is an array of modifications. Each modification is an associative array containing values for the keys "attrib" (which attribute to modify), "modtype" (what kind of modification is being performed) and "values" (array of values to add, remove, or use as a replacement). A practical example of an Active Directory password modification is included in the bug report linked above; an example of all the kinds of modifications available is directly in the implementation=E2=80=99s source = code (I used it as a reference during implementation). =3D=3D Points of Discussion =3D=3D * The structure of $modifications. I wouldn=E2=80=99t be surprised if an array-of-arrays-of-arrays structure is frowned upon by the PHP maintainers. I=E2=80=99m also unsure whether the hard-coded key strings ("attrib", "modt= ype" and "values") are the right way to go. (I have defined symbolic constants for them as well, but I think we should ultimately decide whether we want hard-coded strings or symbolic constants [which would then probably be integers and not strings]). * Type inflexibility. Currently, I enforce that both the value of "attrib" and the elements of the "values" array must be strings. Given PHP=E2=80=99s= weak typing, would it make sense to have them automatically converted if they are of any other type? Or should this be left to the user (who is then more motivated to make sure the data they are storing is correctly formatted)? * Validate-then-perform. The function, as I have written it, first performs all the necessary validations and then only assembles all the data for the C API. I chose this approach because it makes cleanup easier: if I perform validation after allocating a few things, I need to keep track of what I have allocated and what not. If I validate first, I can allocate everything more or less at one shot and then have only one code path to free everything again. On the other hand, this division means I have to iterate through each array twice, which might slightly reduce performance. * No documentation. I haven=E2=80=99t written any documentation for ldap_modify_batch. Yet. Once I have received enough feedback, especially on the points above, I=E2=80=99m ready to write a page documenting it as well.= (I=E2=80=99m sure this is an important criterion when deciding whether to accept a new function into the API.) * Utility functions. I have written three utility functions to make my life easier, but I might have duplicated some code in the process. If the Zend API already contains equivalents of _ldap_str_equal_to_const, _ldap_strlen_max or _ldap_hash_fetch, please point me in the right direction. Thanks for reading through all this, and I=E2=80=99m looking forward to you= r feedback! Cheers, ~~ Ondra Ho=C5=A1ek --047d7b6704cd0fd07604d6c93ccc--