Branch: Tag:

2004-08-23

2004-08-23 20:34:44 by Martin Stjernholm <mast@lysator.liu.se>

Fixed a bug in the handling of escaped "*" in the filter parser. Fixed
dequoting of values in filters according to rfc 2254.

Rev: lib/modules/Protocols.pmod/LDAP.pmod/client.pike:1.58

2:      // LDAP client protocol implementation for Pike.   // - // $Id: client.pike,v 1.57 2004/07/08 15:24:36 marcus Exp $ + // $Id: client.pike,v 1.58 2004/08/23 20:34:44 mast Exp $   //   // Honza Petrous, hop@unibase.cz   //
370:    void create(string|void url, object|void context)    {    -  info = ([ "code_revision" : ("$Revision: 1.57 $"/" ")[1] ]); +  info = ([ "code_revision" : ("$Revision: 1.58 $"/" ")[1] ]);       if(!url || !sizeof(url))    url = LDAP_DEFAULT_URL;
740:       } // add    +  static string unescape_filter_value (string val) +  // Decodes escapes in val according to section 4 in RFC 2254 and +  // section 3 in the older RFC 1960. +  { +  string res = ""; +  while (sscanf (val, "%s\\%s", string pre, val) == 2) { +  res += pre; +  if (sscanf (val, "%2x%s", int chr, val) == 2) +  res += sprintf ("%c", chr); +  else { +  res += val[..0]; +  val = val[1..]; +  } +  } +  return res + val; +  } +     private static array(string) filter_get_sub1expr(string fstr) {    // returns one-level brackets enclosed expressions   
806:    for(int cnt = 0; cnt < sizeof(filtval); cnt++) {    if(cnt) {    if(sizeof(filtval[cnt-1]) && filtval[cnt-1][-1] == '\\') -  ahlp[-1] = reverse(reverse(ahlp[-1])[1..]) + filtval[cnt]; +  ahlp[-1] = ahlp[-1][..sizeof (ahlp[-1]) - 2] + "*" + filtval[cnt];    else    ahlp += ({ filtval[cnt] });    } else
818:    for (int cnt = 0; cnt < ix; cnt++)    if(!cnt) { // leftmost element    if(sizeof(ahlp[0])) -  oarr = ({ASN1_CONTEXT_OCTET_STRING(0, ahlp[0])}); +  oarr = ({ASN1_CONTEXT_OCTET_STRING( +  0, unescape_filter_value (ahlp[0]))});    } else    if(cnt == ix-1) { // rightmost element    if(sizeof(ahlp[ix-1])) -  oarr += ({ASN1_CONTEXT_OCTET_STRING(2, ahlp[ix-1])}); +  oarr += ({ASN1_CONTEXT_OCTET_STRING( +  2, unescape_filter_value (ahlp[ix-1]))});    } else { // inside element    if(sizeof(ahlp[cnt])) -  oarr += ({ASN1_CONTEXT_OCTET_STRING(1, ahlp[cnt])}); +  oarr += ({ASN1_CONTEXT_OCTET_STRING( +  1, unescape_filter_value (ahlp[cnt]))});    }    // for   
838:    DWRITE("client.make_simple_filter: [=]\n");    return ASN1_CONTEXT_SEQUENCE(3,    ({Standards.ASN1.Types.asn1_octet_string(filter[..(op-1)]), -  Standards.ASN1.Types.asn1_octet_string(filter[(op+1)..]) +  Standards.ASN1.Types.asn1_octet_string( +  unescape_filter_value (filter[(op+1)..]))    }));    }    } // if equal,substring