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.55 2004/04/14 20:21:16 nilsson Exp $ + // $Id: client.pike,v 1.56 2004/05/25 13:59:55 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:55:   // - corrected deUTF8 values in result   // -   //   // Specifications:   //   // RFC 1558 (search filter representations)   // RFC 1777,1778,1779 (version2 spec)   // RFC 1823 (v2 API)   // RFC 2251,2252,2253,2254,2255,2256 (version3 spec)   // draft-ietf-asid-ldap-c-api-00.txt (v3 API) - // RFC2279 (UTF-8) + // RFC 2279 (UTF-8) + // RFC 2696 (paged requests)   //   // Interesting, applicable   // RFC 2307 (LDAP as network information services; draft?)         #if constant(.ldap_privates)      #include "ldap_globals.h"      #include "ldap_errors.h"
pike.git/lib/modules/Protocols.pmod/LDAP.pmod/client.pike:353:    //! @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.55 $"/" ")[1] ]); +  info = ([ "code_revision" : ("$Revision: 1.56 $"/" ")[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:886:    if (objectp(ohlp = make_filter(filter_get_sub1expr(filter[1..])[0])))    return ASN1_CONTEXT_SEQUENCE(2, ({ ohlp}) );    else    return 0; // error: Filter parameter error!    break;    default : // we assume simple filter    return make_simple_filter(filter);    }   }    -  private int|string send_search_op(string basedn, int scope, int deref, -  int sizelimit, int timelimit, int attrsonly, -  string filter, void|array(string) attrs){ +  private object|int make_search_op(string basedn, int scope, int deref, +  int sizelimit, int timelimit, +  int attrsonly, string filter, +  void|array(string) attrs) +  {    // SEARCH    // limitations: !!! sizelimit and timelimit should be unsigned int !!!       object msgval, ofilt;    array(object) ohlp;       if(!objectp(ofilt = make_filter(filter))) {    return -seterr(LDAP_FILTER_ERROR);    }    ohlp = ({ofilt});    if (arrayp(attrs)) { //explicitly defined attributes    array(object) o2 = ({});    foreach(attrs, string s2)    o2 += ({Standards.ASN1.Types.asn1_octet_string(s2)});    ohlp += ({Standards.ASN1.Types.asn1_sequence(o2)});    } else    ohlp += ({Standards.ASN1.Types.asn1_sequence(({}))});    -  msgval = ASN1_APPLICATION_SEQUENCE(3, +  return ASN1_APPLICATION_SEQUENCE(3,    ({ Standards.ASN1.Types.asn1_octet_string(basedn),    ASN1_ENUMERATED(scope),    ASN1_ENUMERATED(deref),    Standards.ASN1.Types.asn1_integer(sizelimit),    Standards.ASN1.Types.asn1_integer(timelimit),    ASN1_BOOLEAN(attrsonly ? -1 : 0),    @ohlp    })) ; -  -  return do_op(msgval); +     }          //! Search LDAP directory.    //!    //! @param filter    //! Search filter used when searching directory objects.    //!    //! @param attrs    //! The array of attribute names which will be returned by server.
pike.git/lib/modules/Protocols.pmod/LDAP.pmod/client.pike:965:    filter=filter||lauth->filter; // default from LDAP URI       DWRITE_HI("client.SEARCH: " + (string)filter + "\n");    if (chk_ver())    return 0;    if (chk_binded())    return 0;    if(ldap_version == 3) {    filter = string_to_utf8(filter);    } +  +  object|int search_request = +  make_search_op(ldap_basedn, ldap_scope, ldap_deref, +  ldap_sizelimit, ldap_timelimit, attrsonly, filter, +  attrs||lauth->attributes); +  +  if(intp(search_request)) { +  THROW(({error_string()+"\n",backtrace()})); +  return 0; +  } +  +  object cookie = Standards.ASN1.Types.asn1_octet_string(""); +  object controls = + #ifdef ENABLE_PAGED_SEARCH +  Standards.ASN1.Types.asn1_sequence(({ +  // RFC 2696 2. +  Standards.ASN1.Types.asn1_sequence(({ +  // controlType +  Standards.ASN1.Types.asn1_octet_string("1.2.840.113556.1.4.319"), +  ASN1_BOOLEAN(0), // criticality (FALSE) +  Standards.ASN1.Types.asn1_sequence(({ // controlValue +  0x7fffffff, // size +  cookie, // cookie +  })), +  })), +  })) + #else /* !ENABLE_PAGED_SEARCH */ +  0 + #endif /* ENABLE_PAGED_SEARCH */ +  ; +  +  rawarr = ({}); +  do {   #ifdef LDAP_PROTOCOL_PROFILE    _prof_gtim = gauge{   #endif -  if(intp(raw = send_search_op(ldap_basedn, ldap_scope, ldap_deref, -  ldap_sizelimit, ldap_timelimit, attrsonly, filter, -  attrs||lauth->attributes))) { +  if(intp(raw = do_op(search_request, controls))) {    THROW(({error_string()+"\n",backtrace()}));    return 0;    }   #ifdef LDAP_PROTOCOL_PROFILE    };    DWRITE_PROF("send_search_op: %O\n", _prof_gtim);   #endif    -  rawarr = ({raw}); +  rawarr += ({raw});   #ifdef LDAP_PROTOCOL_PROFILE    _prof_gtim = gauge{   #endif    while (ASN1_DECODE_RESULTAPP(raw) != 5) {   #ifdef LDAP_PROTOCOL_PROFILEx    DWRITE_PROF("readmsg: %O\n", gauge { raw = readmsg(id); });   #else    raw = readmsg(id);   #endif    if (intp(raw)) {    THROW(({error_string()+"\n",backtrace()}));    return 0;    }    rawarr += ({raw});    } // while   #ifdef LDAP_PROTOCOL_PROFILE    };    DWRITE_PROF("rawarr++: %O\n", _prof_gtim);   #endif -  +  // At this point @[raw] contains a SearchResultDone. + #ifdef LDAP_DEBUG +  werror("searchResultDone: %O\n", ASN1_DECODE_RAWDEBUG(raw)); + #endif /* LDAP_DEBUG */ +  cookie = 0; + #ifdef ENABLE_PAGED_SEARCH +  if ((ASN1_DECODE_RESULTCODE(raw) != 10) && +  (sizeof(.ldap_privates.ldap_der_decode(X)->elements[1]->elements) > 2)) { +  cookie = ASN1_DECODE_RESULTREFS(raw)->elements[2]->elements[1]; +  controls->elements[0]->elements[0]->elements[2]->elements[1] = cookie; +  if (!sizeof(cookie)) { +  // End marker. +  cookie = 0; +  } else { + #ifdef LDAP_DEBUG +  werror("Got cookie: %O\n", cookie); + #endif /* LDAP_DEBUG */ +  } +  } + #endif /* ENABLE_PAGED_SEARCH */ +  } while (cookie);   #ifdef LDAP_PROTOCOL_PROFILE    _prof_gtim = gauge{ last_rv = result(rawarr); };    DWRITE_PROF("result: %O\n", _prof_gtim);   #else    last_rv = result(rawarr);   #endif    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();