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.92 2005/04/06 16:49:16 mast Exp $ + // $Id: client.pike,v 1.93 2005/04/06 19:45:51 mast 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:66:   // 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" -  +    #if constant(SSL.Cipher.CipherAlgorithm)   import SSL.Constants;   #endif      import ".";      // ------------------------      // ASN.1 decode macros   
pike.git/lib/modules/Protocols.pmod/LDAP.pmod/client.pike:125: Inside #if defined(DEBUG)
   return decoder;   #ifdef DEBUG    else if (!get_constant_name (attr_descr->syntax_oid))    werror ("Warning: Unknown syntax %O for attribute %O - "    "binary content assumed.\n", attr_descr->syntax_oid, attr);   #endif    }   #ifdef DEBUG    else if (!nowarn && !has_suffix (attr, ";binary") && !has_value (attr, ";binary;"))    werror ("Warning: Couldn't fetch attribute description for %O - " -  "binary content assumed.\n", attr); +  "binary content assumed.\n%s", attr, describe_backtrace(backtrace()));   #endif    return 0;   }   //! @endignore      static function(string:string) get_attr_encoder (string attr)   {    if (mapping(string:mixed) attr_descr = get_attr_type_descr (attr)) {    if (function(string:string) encoder =    syntax_encode_fns[attr_descr->syntax_oid])
pike.git/lib/modules/Protocols.pmod/LDAP.pmod/client.pike:299:    seterr (LDAP_LOCAL_ERROR);    THROW(({"LDAP: Internal error.\n",backtrace()}));    return -ldap_errno;    }    DWRITE(sprintf("result.create: rawres=%O\n",rawres[lastel]));       // The last element of 'rawres' is result itself    resultcode = ASN1_DECODE_RESULTCODE(rawres[lastel]);    DWRITE(sprintf("result.create: code=%d\n",resultcode));    resultstring = ASN1_DECODE_RESULTSTRING(rawres[lastel]); +  if (resultstring == "") +  resultstring = 0; +  else if (ldap_version >= 3) +  resultstring = utf8_to_string (resultstring);    DWRITE(sprintf("result.create: str=%s\n",resultstring));   #ifdef V3_REFERRALS    // referral (v3 mode)    if(resultcode == 10) {    referrals = ({});    foreach(ASN1_DECODE_RESULTREFS(rawres[lastel]), object ref1)    referrals += ({ ref1->value });    DWRITE(sprintf("result.create: refs=%O\n",referrals));    }   #endif
pike.git/lib/modules/Protocols.pmod/LDAP.pmod/client.pike:331: Inside #if 0
   default: DWRITE(sprintf("result.create: stuff=%d\n", stuff));       }   #endif       return this;       }       //! -  //! Returns error number of search result. +  //! Returns the error number in the search result.    //!    //! @seealso -  //! @[LDAP.client.result.error_string] +  //! @[error_string], @[server_error_string]    int error_number() { return resultcode; }       //! -  //! Returns error description of search result. +  //! Returns the description of the error in the search result. +  //! This is the error string from the server, or a standard error +  //! message corresponding to the error number if the server didn't +  //! provide any description.    //!    //! @seealso -  //! @[LDAP.client.result.error_number] +  //! @[server_error_string], @[error_number]    string error_string() { -  return ((stringp(resultstring) && sizeof(resultstring)) ? -  resultstring : ldap_errlist[resultcode]); +  return resultstring || ldap_error_strings[resultcode];    }    -  +  //! Returns the error string from the server, or zero if the +  //! server didn't provide any.    //! -  +  //! @seealso +  //! @[error_string], @[error_number] +  string server_error_string() {return resultstring;} +  +  //!    //! Returns the number of entries.    //!    //! @seealso    //! @[LDAP.client.result.count_entries]    int num_entries() { return sizeof (entry); }       //!    //! Returns the number of entries from current cursor    //! possition till end of the list.    //!
pike.git/lib/modules/Protocols.pmod/LDAP.pmod/client.pike:541: Inside #if undefined(PARSE_RFCS)
   //! @[Protocol.LDAP.parse_ldap_url].    //!    //! @param context    //! TLS context of connection    //!    //! @seealso    //! @[LDAP.client.bind], @[LDAP.client.search]    void create(string|mapping(string:mixed)|void url, object|void context)    {    -  info = ([ "code_revision" : ("$Revision: 1.92 $"/" ")[1] ]); +  info = ([ "code_revision" : ("$Revision: 1.93 $"/" ")[1] ]);       if(!url || !sizeof(url))    url = LDAP_DEFAULT_URL;       if (mappingp (url))    lauth = url;    else    lauth = parse_ldap_url(url);       if(!stringp(lauth->scheme) ||
pike.git/lib/modules/Protocols.pmod/LDAP.pmod/client.pike:775:    if(intp(raw = send_bind_op(dn, pass))) {    THROW(({error_string()+"\n",backtrace()}));    return 0;    }       bound_dn = 0;    last_rv = result(({raw}),1);    if (!last_rv->error_number())    bound_dn = dn;    DWRITE_HI(sprintf("client.BIND: %s\n", last_rv->error_string())); -  seterr (last_rv->error_number()); +  seterr (last_rv->error_number(), last_rv->error_string());    return !!bound_dn;       } // bind          private int send_unbind_op() {    // UNBIND operation       writemsg(ASN1_APPLICATION_OCTET_STRING(2, ""));   
pike.git/lib/modules/Protocols.pmod/LDAP.pmod/client.pike:854:    if(ldap_version == 3) {    dn = string_to_utf8(dn);    }    if(intp(raw = send_op_withdn(10, dn))) {    THROW(({error_string()+"\n",backtrace()}));    return 0;    }       last_rv = result(({raw}));    DWRITE_HI(sprintf("client.DELETE: %s\n", last_rv->error_string())); -  seterr(last_rv->error_number()); +  seterr (last_rv->error_number(), last_rv->error_string());    return !last_rv->error_number();       } // delete       private int|string send_compare_op(string dn, string attr, string value) {    // COMPARE       object msgval;       msgval = ASN1_APPLICATION_SEQUENCE(14,
pike.git/lib/modules/Protocols.pmod/LDAP.pmod/client.pike:930:    if (function(string:string) encoder = get_attr_encoder (attr))    value = encoder (value);    }    if(intp(raw = send_compare_op(dn, attr, value))) {    THROW(({error_string()+"\n",backtrace()}));    return 0;    }       last_rv = result(({raw}));    DWRITE_HI(sprintf("client.COMPARE: %s\n", last_rv->error_string())); -  seterr(last_rv->error_number()); +  seterr (last_rv->error_number(), last_rv->error_string());    return last_rv->error_number() == LDAP_COMPARE_TRUE;       } // compare       private int|string send_add_op(string dn, mapping(string:array(string)) attrs) {    // ADD       object msgval;    string atype;    array(object) oatt = ({});
pike.git/lib/modules/Protocols.pmod/LDAP.pmod/client.pike:1009:    if (function(string:string) encoder = get_attr_encoder (attr))    attrs[attr] = map (attrs[attr], encoder);    }    if(intp(raw = send_add_op(dn, attrs))) {    THROW(({error_string()+"\n",backtrace()}));    return 0;    }       last_rv = result(({raw}));    DWRITE_HI(sprintf("client.ADD: %s\n", last_rv->error_string())); -  seterr(last_rv->error_number()); +  seterr (last_rv->error_number(), last_rv->error_string());    return !last_rv->error_number();       } // add      static mapping(string:array(string)) simple_read (string object_name,    string filter,    array attrs)   // Makes a base object search for object_name. The result is returned   // as a mapping where the attribute types have been lowercased and the   // string values are unprocessed.
pike.git/lib/modules/Protocols.pmod/LDAP.pmod/client.pike:1599:    // Remove the extra end marker.    rawarr = rawarr[..sizeof(rawarr)-2];    }    }       },);    } while (cookie);       PROFILE("result", last_rv = result (rawarr, 0, flags));    if(objectp(last_rv)) -  seterr (last_rv->error_number()); +  seterr (last_rv->error_number(), last_rv->error_string());    //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",    last_rv->error_string(), last_rv->num_entries()));    return last_rv;       } // search      mapping(string:string|array(string)) read (
pike.git/lib/modules/Protocols.pmod/LDAP.pmod/client.pike:1685:    PROFILE("readmsg", raw = readmsg(0));    if (intp(raw)) {    THROW(({error_string()+"\n",backtrace()}));    return 0;    }    rawarr += ({raw});    } // while    });       PROFILE ("result", last_rv = result (rawarr, 0, flags)); -  seterr (last_rv->error_number()); +  seterr (last_rv->error_number(), last_rv->error_string());       if (ldap_errno != LDAP_SUCCESS) return 0;    return last_rv->fetch();   }      string|array(string) read_attr (string object_name,    string attr,    void|string filter,    void|mapping(string:array(int|string)) controls)   //! Reads a specified attribute of a specified object in the LDAP
pike.git/lib/modules/Protocols.pmod/LDAP.pmod/client.pike:1951:    newrdn = string_to_utf8(newrdn);    if(newsuperior) newsuperior = string_to_utf8(newsuperior);    }    if(intp(raw = send_modifydn_op(dn, newrdn, deleteoldrdn, newsuperior))) {    THROW(({error_string()+"\n",backtrace()}));    return 0;    }       last_rv = result(({raw}));    DWRITE_HI(sprintf("client.MODIFYDN: %s\n", last_rv->error_string())); -  seterr(last_rv->error_number()); +  seterr (last_rv->error_number(), last_rv->error_string());    return !last_rv->error_number();       } //modifydn       //! The Modify Operation allows a client to request that a modification    //! of an entry be performed on its behalf by a server.    //!    //! @param dn    //! The distinguished name of modified entry.    //!
pike.git/lib/modules/Protocols.pmod/LDAP.pmod/client.pike:2028:    attropval[attr] = op;    }    }    if(intp(raw = send_modify_op(dn, attropval))) {    THROW(({error_string()+"\n",backtrace()}));    return 0;    }       last_rv = result(({raw}));    DWRITE_HI(sprintf("client.MODIFY: %s\n", last_rv->error_string())); -  seterr(last_rv->error_number()); +  seterr (last_rv->error_number(), last_rv->error_string());    return !last_rv->error_number();       } // modify       //! Gets referrals.    //!    //! @returns    //! Returns array of referrals or @expr{0@}.    array|int get_referrals() {    if(last_rv->referrals)