Re: PHP 4.0 Bug #10143 Updated: need a tweak to ldap_add to set a binary flag
| From: | Brian S. Craigie | Date: | Tue, 03 Apr 2001 22:01:33 +0000 |
| Subject: | Re: PHP 4.0 Bug #10143 Updated: need a tweak to ldap_add to set a binary flag | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-50773@lists.php.net to get a copy of this message | ||
Hi,
Uhm, how about the example I gave? ;-) (note: the bug screen must have stripped off my backslashes
from the example).
Example:-
$info["postalAddress"] = base64_encode("address line\r\naddress line 2\r\n");
ldap_add($ds,"cn=something", $info);
Aha! I understand things. The light dawns (slap on forehead). I simply don't base64 encode
it. My problem was that I was assuming the attribute value worked the same as in an ldif file;
"ldapadd" command line utility which imports ldif files doesn't permit/recognise a
carriage return or linefeed as part of the data element because they are record [attribute]
terminators. So the string had to be base64 encoded and then you had to tell ldap that it is a
binary field so it could decode it before it stored it.
Because php4 bypasses the ldif parser, of course it knows how to store the data as-is.
Silly me! I never thought to try it without encoding it first.
Working example:
$info["postalAddress"] = "address line\r\naddress line 2\r\n";
ldap_add($ds,"cn=something", $info);
Thanks and sorry for being so stupid. Time for a coffee or ten. ;-)
Best Regards,
Brian
Bug Database wrote:
> ID: 10143
> Updated by: sniper
> Reported By: brianc@suk.neceur.com
> Old-Status: Open
> Status: Feedback
> Bug Type: Feature/Change Request
> Assigned To:
> Comments:
>
> I can add binary data with PHP4.0.5-dev and ldap_add(). e.g. Photos, certificates and sounds.
> Do you have any example code (short!) which would clarify what you mean?
>
> --Jani
>
> Previous Comments:
> ---------------------------------------------------------------------------
>
> [2001-04-03 13:30:33] brianc@suk.neceur.com
> [actually the version is 4.0.5-dev but that isn't listed]
>
> Adding binary data to an ldap entry isn't possible at present because there is no
> capability in the [php] ldap code to do it.
>
> It would be very nice if some clever person could allow the following syntax to be used
> attributename;binary .
>
> A simple example to encode cr+lf into a string so that clients display the entry over two
> lines:-
>
> $info["postalAddress;binary"] = base64_encode("address line 1rnaddress line
> 2rn");
>
> The extra ;binary would then signify (as in an ldif file) that the data is to be treated as
> binary. This syntax seems to be standard. I've also seen postaladdress:: in an ldif file (the
> double colon signifying binary) but use of that would be less clear/obvious imho.
>
> Then a change would be needed to ext/ldap/ldap.c to do the following when the ;binary appears
> in an attribute name
>
> (from the openldap man page on ldap_modify)
>
> OpenLDAP 2.0.7-Rel Last change: 22 September 1998
> If you need to specify a non-string value (e.g., to add a
> photo or audio attribute value), you should set mod_op to the logical OR of the operation as
> above (e.g.,
> LDAP_MOD_REPLACE) and the constant LDAP_MOD_BVALUES. In this case, mod_bvalues should be used
> instead of mod_values, and it should point to a null-terminated array of struct bervals, as defined
> in <lber.h>.
>
> I'm no great c programmer and would get stuck at the first hurdle, but this would be a
> great addition for ldap and in the hands of an expert doesn't look like it would take too long
> to implement.
>
> Many thanks once again for... well, everything!
>
> Best Regards,
>
> Brian
>
> ---------------------------------------------------------------------------
>
> ATTENTION! Do NOT reply to this email!
> To reply, use the web interface found at
> http://bugs.php.net/?id=10143&edit=2