Branch: Tag:

2005-03-14

2005-03-14 16:07:23 by Martin Stjernholm <mast@lysator.liu.se>

UTF-8 decode the "dn" field from result.fetch only if we're talking
LDAPv3.

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

2:      // LDAP client protocol implementation for Pike.   // - // $Id: client.pike,v 1.80 2005/03/13 13:21:17 mast Exp $ + // $Id: client.pike,v 1.81 2005/03/14 16:07:23 mast Exp $   //   // Honza Petrous, hop@unibase.cz   //
86:   // ASN.1 decode macros      #define ASN1_GET_RESULTAPP(X) ((X)->elements[1]->get_tag()) + #define ASN1_GET_DN(X) ((X)->elements[0]->value)   #define ASN1_GET_ATTR_ARRAY(X) (sizeof ((X)->elements) > 1 && \    (array) ((X)->elements[1]->elements))   #define ASN1_GET_ATTR_NAME(X) ((X)->elements[0]->value)
95:   #define ASN1_DECODE_RESULTCODE(X) (int)(.ldap_privates.ldap_der_decode(X)->elements[1]->elements[0]->value->cast_to_int())   #define ASN1_DECODE_RESULTSTRING(X) (.ldap_privates.ldap_der_decode(X)->elements[1]->elements[2]->value)   #define ASN1_DECODE_RESULTREFS(X) (.ldap_privates.ldap_der_decode(X)->elements[1]->elements[3]->elements) - #define ASN1_DECODE_DN(X) utf8_to_string ((X)->elements[0]->value) +    #define ASN1_DECODE_RAWDEBUG(X) (.ldap_privates.ldap_der_decode(X)->debug_string())       //! Contains the client implementation of the LDAP protocol.
177:    {    array(mapping(string:array(string))) res = ({});    - #define DECODE_ENTRIES(SET_ATTR) do { \ + #define DECODE_ENTRIES(SET_DN, SET_ATTR) do { \    foreach (rawres, string rawent) { \    object derent = .ldap_privates.ldap_der_decode (rawent)->elements[1]; \    if (array(object) derattribs = ASN1_GET_ATTR_ARRAY (derent)) { \ -  mapping(string:array) attrs = (["dn": ({ASN1_DECODE_DN (derent)})]); \ +  mapping(string:array) attrs = (["dn": ({SET_DN})]); \    foreach (derattribs, object derattr) \    {SET_ATTR;} \    res += ({attrs}); \
192:    if (ldap_version < 3) {    // Use the values raw.    if (flags & SEARCH_LOWER_ATTRS) -  DECODE_ENTRIES ({ +  DECODE_ENTRIES (ASN1_GET_DN (derent), {    attrs[lower_case (ASN1_GET_ATTR_NAME (derattr))] =    ASN1_GET_ATTR_VALUES (derattr);    });    else -  DECODE_ENTRIES ({ +  DECODE_ENTRIES (ASN1_GET_DN (derent), {    attrs[ASN1_GET_ATTR_NAME (derattr)] =    ASN1_GET_ATTR_VALUES (derattr);    });
209:    // won't be matched by get_attr_type_descr and are therefore    // left untouched.    if (flags & SEARCH_LOWER_ATTRS) -  DECODE_ENTRIES ({ +  DECODE_ENTRIES (utf8_to_string (ASN1_GET_DN (derent)), {    string attr = lower_case (ASN1_GET_ATTR_NAME (derattr));    if (function(string:string) decoder = get_attr_decoder (attr))    attrs[attr] = map (ASN1_GET_ATTR_VALUES (derattr), decoder);
217:    attrs[attr] = ASN1_GET_ATTR_VALUES (derattr);    });    else -  DECODE_ENTRIES ({ +  DECODE_ENTRIES (utf8_to_string (ASN1_GET_DN (derent)), {    string attr = ASN1_GET_ATTR_NAME (derattr);    if (function(string:string) decoder = get_attr_decoder (attr))    attrs[attr] = map (ASN1_GET_ATTR_VALUES (derattr), decoder);
482: Inside #if undefined(PARSE_RFCS)
   void create(string|void url, object|void context)    {    -  info = ([ "code_revision" : ("$Revision: 1.80 $"/" ")[1] ]); +  info = ([ "code_revision" : ("$Revision: 1.81 $"/" ")[1] ]);       if(!url || !sizeof(url))    url = LDAP_DEFAULT_URL;