pike.git / lib / modules / Protocols.pmod / LDAP.pmod / client.pike

version» Context lines:

pike.git/lib/modules/Protocols.pmod/LDAP.pmod/client.pike:1:   #pike __REAL_VERSION__      // LDAP client protocol implementation for Pike.   // - // $Id: client.pike,v 1.57 2004/05/26 16:18:16 grubba Exp $ + // $Id: client.pike,v 1.58 2004/06/18 13:05:50 grubba Exp $   //   // Honza Petrous, hop@unibase.cz   //   // ----------------------------------------------------------------------   //   // History:   //   // v0.0 1998-05-25 Starting up!   // v1.0 1998-06-21 Core functions (open, bind, unbind, delete, add,   // compare, search), only V2 operations,
pike.git/lib/modules/Protocols.pmod/LDAP.pmod/client.pike:363:    //! @expr{"ldap://hostname/basedn?attrlist?scope?ext"@}    //!    //! @param context    //! TLS context of connection    //!    //! @seealso    //! @[LDAP.client.bind], @[LDAP.client.search]    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;       lauth = parse_url(url);       if(!stringp(lauth->scheme) ||    ((lauth->scheme != "ldap")   #if constant(SSL.Cipher.CipherAlgorithm)    && (lauth->scheme != "ldaps")
pike.git/lib/modules/Protocols.pmod/LDAP.pmod/client.pike:991:    if(intp(search_request)) {    THROW(({error_string()+"\n",backtrace()}));    return 0;    }       object cookie = Standards.ASN1.Types.asn1_octet_string("");    rawarr = ({});    do {    PROFILE("send_search_op", {    IF_ELSE_PAGED_SEARCH( +  object controls = +  .ldap_privates.asn1_sequence(0, ({ +  // LDAP_SERVER_DOMAIN_SCOPE_OID +  // "Tells server not to generate referrals" (NtLdap.h) +  Standards.ASN1.Types.asn1_sequence(({ +  // controlType +  Standards.ASN1.Types.asn1_octet_string("1.2.840.113556.1.4.1339"), +  ASN1_BOOLEAN(0), // criticality (FALSE) +  // controlValue +  Standards.ASN1.Types.asn1_octet_string(""), +  })), +     // LDAP Control Extension for Simple Paged Results Manipulation    // RFC 2696. -  object controls = -  .ldap_privates.asn1_sequence(({ -  // RFC 2696 2. -  .ldap_privates.asn1_sequence(({ +  Standards.ASN1.Types.asn1_sequence(({    // controlType    Standards.ASN1.Types.asn1_octet_string("1.2.840.113556.1.4.319"), -  //ASN1_BOOLEAN(0), // criticality (FALSE) +  ASN1_BOOLEAN(sizeof(cookie->value)?0:0xff), // criticality    // controlValue    Standards.ASN1.Types.asn1_octet_string( -  .ldap_privates.asn1_sequence(({ +  Standards.ASN1.Types.asn1_sequence(({    // size    Standards.ASN1.Types.asn1_integer(0x7fffffff),    cookie, // cookie    }))->get_der()),    })),    })),);       if(intp(raw = do_op(search_request,    IF_ELSE_PAGED_SEARCH(controls, 0)))) {    THROW(({error_string()+"\n",backtrace()}));
pike.git/lib/modules/Protocols.pmod/LDAP.pmod/client.pike:1033:    return 0;    }    rawarr += ({raw});    } // while    });       // At this point @[raw] contains a SearchResultDone.    cookie = 0;    IF_ELSE_PAGED_SEARCH({    if ((ASN1_DECODE_RESULTCODE(raw) != 10) && -  (sizeof(.ldap_privates.ldap_der_decode(raw)->elements[1]->elements) > 3)) { -  cookie = ASN1_DECODE_RESULTREFS(raw)->elements[2]->elements[1]; -  if (!sizeof(cookie)) { -  // End marker. -  cookie = 0; -  } else { +  (sizeof(.ldap_privates.ldap_der_decode(raw)->elements) > 2)) { +  object controls = .ldap_privates.ldap_der_decode(raw)->elements[2]; +  foreach(controls->elements, object control) { +  if (!control->constructed || +  !sizeof(control) || +  control->elements[0]->type_name != "OCTET STRING") { +  //werror("Protocol error in control %O\n", control); +  // FIXME: Fail? +  continue; +  } +  if (control->elements[0]->value != "1.2.840.113556.1.4.319") { +  //werror("Unknown control %O\n", control->elements[0]->value); +  // FIXME: Should look at criticallity flag. +  continue; +  } +  if (sizeof(control) == 1) continue; +  int pos = 1; +  if (control->elements[1]->type_name == "BOOLEAN") { +  if (sizeof(control) == 2) continue; +  pos = 2; +  } +  if (control->elements[pos]->type_name != "OCTET STRING") { +  // FIXME: Error? +  continue; +  } +  object control_info = +  .ldap_privates.ldap_der_decode(control->elements[pos]->value); +  if (!control_info->constructed || +  sizeof(control_info) < 2 || +  control_info->elements[1]->type_name != "OCTET STRING") { +  // Unexpected control information. +  continue; +  } +  if (sizeof(control_info->elements[1]->value)) { +  cookie = control_info->elements[1]; +  } +  } +  if (cookie) {    // Remove the extra end marker.    rawarr = rawarr[..sizeof(rawarr)-2];    }    } -  +     },);    } while (cookie);       PROFILE("result", last_rv = result(rawarr));    if(objectp(last_rv))    seterr (last_rv->error_number());    //if (rv->error_number() || !rv->num_entries()) // if error or entries=0    // rv = rv->error_number();       DWRITE_HI(sprintf("client.SEARCH: %s (entries: %d)\n",