[Date Prev][Date Next] [Chronological] [Thread] [Top]

RE : (ITS#7149) Back-perl, Back-shell and Binary Data



Now the new patch encode the binary data to base64 by using slap_ad_is_binary to check if it's binary data, and using lutil_b64_ntop for the encode.


*** ../openldap-2.4.28.org/servers/slapd/back-perl/modify.c     2011-11-25 19:52:29.000000000 +0100
--- servers/slapd/back-perl/modify.c    2012-02-06 17:41:44.638861010 +0100
***************
*** 16,21 ****
--- 16,22 ----
   */

  #include "perl_back.h"
+ #include "lutil.h"

  int
  perl_back_modify(
***************
*** 26,31 ****
--- 27,33 ----
        Modifications *modlist = op->orm_modlist;
        int count;
        int i;
+       struct berval b64_data;

        PERL_SET_CONTEXT( PERL_INTERPRETER );
        ldap_pvt_thread_mutex_lock( &perl_interpreter_mutex );
***************
*** 61,67 ****
                                mods->sm_values != NULL && mods->sm_values[i].bv_val != NULL;
                                i++ )
                        {
!                               XPUSHs(sv_2mortal(newSVpv( mods->sm_values[i].bv_val, 0 )));
                        }

                        /* Fix delete attrib without value. */
--- 63,80 ----
                                mods->sm_values != NULL && mods->sm_values[i].bv_val != NULL;
                                i++ )
                        {
!                               if ( slap_ad_is_binary(mods->sm_desc) ) {
!                                       b64_data.bv_len = LUTIL_BASE64_ENCODE_LEN(mods->sm_values[i].bv_len) + 1;
!                                       b64_data.bv_val = ber_memalloc( b64_data.bv_len + 1 );
!                                       b64_data.bv_len = lutil_b64_ntop(
!                                                       (unsigned char *) mods->sm_values[i].bv_val,
!                                                       mods->sm_values[i].bv_len,
!                                                       b64_data.bv_val, b64_data.bv_len );
!                                       XPUSHs(sv_2mortal(newSVpv( b64_data.bv_val, 0 )));
!                                       ber_memfree( b64_data.bv_val );
!                               } else {
!                                       XPUSHs(sv_2mortal(newSVpv( mods->sm_values[i].bv_val, 0 )));
!                               }
                        }

                        /* Fix delete attrib without value. */


*** ../openldap-2.4.28.org/servers/slapd/back-shell/modify.c    2011-11-25 19:52:29.000000000 +0100
--- servers/slapd/back-shell/modify.c   2012-02-06 17:40:14.861837487 +0100
***************
*** 37,42 ****
--- 37,43 ----

  #include "slap.h"
  #include "shell.h"
+ #include "lutil.h"

  int
  shell_back_modify(
***************
*** 50,55 ****
--- 51,57 ----
        Entry e;
        FILE                    *rfp, *wfp;
        int                     i;
+       struct berval           b64_data;

        if ( si->si_modify == NULL ) {
                send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
***************
*** 105,112 ****

                if( mod->sm_values != NULL ) {
                        for ( i = 0; mod->sm_values[i].bv_val != NULL; i++ ) {
!                               fprintf( wfp, "%s: %s\n", mod->sm_desc->ad_cname.bv_val,
!                                       mod->sm_values[i].bv_val /* binary! */ );
                        }
                }

--- 107,126 ----

                if( mod->sm_values != NULL ) {
                        for ( i = 0; mod->sm_values[i].bv_val != NULL; i++ ) {
!                               if ( slap_ad_is_binary(mod->sm_desc) ) {
!                                       b64_data.bv_len = LUTIL_BASE64_ENCODE_LEN(mod->sm_values[i].bv_len) + 1;
!                                       b64_data.bv_val = ber_memalloc( b64_data.bv_len + 1 );
!                                       b64_data.bv_len = lutil_b64_ntop(
!                                                       (unsigned char *) mod->sm_values[i].bv_val,
!                                                       mod->sm_values[i].bv_len,
!                                                       b64_data.bv_val, b64_data.bv_len );
!                                       fprintf( wfp, "%s: %s\n", mod->sm_desc->ad_cname.bv_val,
!                                               b64_data.bv_val );
!                                       ber_memfree( b64_data.bv_val );
!                               } else {
!                                       fprintf( wfp, "%s: %s\n", mod->sm_desc->ad_cname.bv_val,
!                                               mod->sm_values[i].bv_val );
!                               }
                        }
                }


________________________________________
De : openldap-bugs-bounces@OpenLDAP.org [openldap-bugs-bounces@OpenLDAP.org] de la part de hyc@symas.com [hyc@symas.com]
Date d'envoi : jeudi 2 février 2012 21:44
À : openldap-its@openldap.org
Objet : Re: (ITS#7149) Back-perl, Back-shell and Binary Data

llg@portaildulibre.fr wrote:
> Le 02/02/2012 20:32, hyc@symas.com a écrit :
>> jiashun.qian@atos.net wrote:
>>> Full_Name: Jiashun QIAN
>>> Version: 2.4.28
>>> OS: CentOS 6
>>> URL: ftp://ftp.openldap.org/incoming/
>>> Submission from: (NULL) (85.115.60.180)
>>>
>>>
>>> The backend shell and the backend perl can't handle some binary data.
>>>
>>> This occurs only with MODIFY because when ADD the binary data is encoded in
>>> base64 but not MODIFY.
>>>
>>> The binary data is truncated when if it contains \0. In fact, data is stored in
>>> a linked list of char * and treated as characters.
>>>
>>> ---
>>> servers/slapd/back-perl/modify.c
>>> XPUSHs(sv_2mortal(newSVpv( mods->sm_values[i].bv_val, 0 )));
>>> ---
>>>
>>> The type of mods->sm_values[i].bv_val is char*.
>>>
>>> To handle the binary data, for back-perl, just change another function mXPUSHp,
>>> which we can put the exacte length of mod->sm_values[i].bv_val as parameter,
>>> it's mod->sm_values[i].bv_len. So it will push the total data.
>> That is obviously the wrong approach. Since these backends communicate using
>> LDIF, binary values should be base64 encoded according to the LDIF rules.
> The input LDIF file for ldap_modify contains base64 encoded
> usercertificate, but back-perl receives binary data.
> This behaviour only occured with modification action : with add action,
> certificate is received base64 encoded.

Yes, I already understood that. You're still not understanding what I said.
Your patch should do the appropriate checks for binary data and do the proper
base64 encoding for the modify values that back-perl (or back-shell) sends to
the perl module (or shell script).

This has nothing to do with the input LDIF file, this is about how slapd
transmits internal data from a backend to the external perl or shell scripts.

>> Thanks for the patch, but we can't merge it since the provided solution is wrong.

--
   -- Howard Chu
   CTO, Symas Corp.           http://www.symas.com
   Director, Highland Sun     http://highlandsun.com/hyc/
   Chief Architect, OpenLDAP  http://www.openldap.org/project/



________________________________


Ce message et les pièces jointes sont confidentiels et réservés à l'usage exclusif de ses destinataires. Il peut également être protégé par le secret professionnel. Si vous recevez ce message par erreur, merci d'en avertir immédiatement l'expéditeur et de le détruire. L'intégrité du message ne pouvant être assurée sur Internet, la responsabilité du groupe Atos ne pourra être engagée quant au contenu de ce message. Bien que les meilleurs efforts soient faits pour maintenir cette transmission exempte de tout virus, l'expéditeur ne donne aucune garantie à cet égard et sa responsabilité ne saurait être engagée pour tout dommage résultant d'un virus transmis.

This e-mail and the documents attached are confidential and intended solely for the addressee; it may also be privileged. If you receive this e-mail in error, please notify the sender immediately and destroy it. As its integrity cannot be secured on the Internet, the Atos group liability cannot be triggered for the message content. Although the sender endeavors to maintain a computer virus-free network, the sender does not warrant that this transmission is virus-free and will not be liable for any damages resulting from any virus transmitted.