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.85 2005/03/23 19:23:03 mast Exp $ + // $Id: client.pike,v 1.86 2005/03/24 14:46:54 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:100:       //! Contains the client implementation of the LDAP protocol.    //! All of the version 2 protocol features are implemented    //! but only the base parts of the version 3.       inherit .protocol;       private {    int binded = 0; // flag for v2 operations    string ldap_basedn = ""; // baseDN -  int ldap_scope = 0; // 0: base, 1: onelevel, 2: subtree +  int ldap_scope = 0; // SCOPE_*    int ldap_deref = 0; // 0: ...    int ldap_sizelimit = 0;    int ldap_timelimit = 0;    mapping lauth = ([]);    object last_rv = 0; // last returned value    }      static constant supported_extensions = (<"bindname">);      static function(string:string) get_attr_decoder (string attr,
pike.git/lib/modules/Protocols.pmod/LDAP.pmod/client.pike:480: Inside #if undefined(PARSE_RFCS)
   //! 2255.    //!    //! @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.85 $"/" ")[1] ]); +  info = ([ "code_revision" : ("$Revision: 1.86 $"/" ")[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:1638:    // Get the value regardless of the case of the attribute name that    // the server used in the response.    return get_iterator (res)->value();    }    return 0;   }      //! Return the LDAP protocol version in use.   int get_protocol_version() {return ldap_version;}    -  //! @param base_dn -  //! base DN for search +  //! Sets the base DN for searches using @[search] and schema queries +  //! using @[get_attr_type_descr]. +  //! +  //! @note +  //! For compatibility, the old base DN is returned. However, if +  //! LDAPv3 is used, the value is UTF-8 encoded. Use @[get_basedn] +  //! separately instead.    string set_basedn (string base_dn) {       string old_dn = ldap_basedn;       if(ldap_version == 3) {    base_dn = string_to_utf8(base_dn);    }    ldap_basedn = base_dn;    DWRITE_HI("client.SET_BASEDN = " + base_dn + "\n");    return old_dn;    }    - //! Return the current base DN for searching. + //! Returns the current base DN for searches using @[search] and + //! schema queries using @[get_attr_type_descr].   string get_basedn() {return utf8_to_string (ldap_basedn);}       //!    //! Sets value of scope for search operation.    //!    //! @param scope -  //! Value can be integer or its corresponding string value. -  //! 0: base, 1: one, 2: sub +  //! The value can be one of the @expr{SCOPE_*@} constants or a +  //! string @expr{"base"@}, @expr{"one"@} or @expr{"sub"@}.    //! -  +  //! @returns +  //! Returns the @expr{SCOPE_*@} constant for the old scope.    int set_scope (int|string scope) {       int old_scope = ldap_scope;       // support for string based values    if(stringp(scope))    switch (lower_case(scope)) { -  case "sub": scope = 2; break; -  case "one": scope = 1; break; -  case "base": scope = 0; break; -  default: return -1; +  case "sub": scope = SCOPE_SUB; break; +  case "one": scope = SCOPE_ONE; break; +  case "base": scope = SCOPE_BASE; break; +  default: ERROR ("Invalid scope %O.\n", scope);    }    else -  if(scope != 0 && scope != 1 && scope != 2) -  return -1; +  if (!(<SCOPE_BASE, SCOPE_ONE, SCOPE_SUB>)[scope]) +  ERROR ("Invalid scope %O.\n", scope);       ldap_scope = scope;    DWRITE_HI("client.SET_SCOPE = " + (string)scope + "\n");    return old_scope;    }      //! Return the currently set scope as a string @expr{"base"@},   //! @expr{"one"@}, or @expr{"sub"@}. - string get_scope() {return ([0: "base", 1: "one", 2: "sub"])[ldap_scope];} + string get_scope() +  {return ([SCOPE_BASE: "base", SCOPE_ONE: "one", SCOPE_SUB: "sub"])[ldap_scope];}       //! @param option_type    //! LDAP_OPT_xxx    //! @param value    //! new value for option    int set_option (int opttype, int value) {       DWRITE_HI("client.SET_OPTION: " + (string)opttype + " = " + (string)value + "\n");    switch (opttype) {    case 1: // LDAP_OPT_DEREF
pike.git/lib/modules/Protocols.pmod/LDAP.pmod/client.pike:1740:    case 2: // LDAP_OPT_SIZELIMIT    return ldap_sizelimit;    case 3: // LDAP_OPT_TIMELIMIT    return ldap_timelimit;    case 4: // LDAP_OPT_REFERRALS    }       return -1;    }    + mapping(string:mixed) get_parsed_url() {return lauth;} + //! Returns a mapping containing the data parsed from the LDAP URL + //! passed to @[create]. The mapping has the same format as the return + //! value from @[parse_url]. Don't be destructive on the returned + //! value. +     private int|string send_modify_op(string dn,    mapping(string:array(mixed)) attropval) {    // MODIFY       object o, msgval;    string atype;    array(object) oatt = ({}), attrarr;          foreach(indices(attropval), atype) {
pike.git/lib/modules/Protocols.pmod/LDAP.pmod/client.pike:1934:    //! Gets referrals.    //!    //! @returns    //! Returns array of referrals or @expr{0@}.    array|int get_referrals() {    if(last_rv->referrals)    return last_rv->referrals;    return 0;    }    -  //! @param ldapuri -  //! LDAP URL -  mapping|int parse_url (string ldapuri) { +  //! Parses an LDAP URL and returns its fields in a mapping. +  //! +  //! @returns +  //! The returned mapping contains these fields: +  //! +  //! @mapping +  //! @member string scheme +  //! The URL scheme, either @expr{"ldap"@} or @expr{"ldaps"@}. +  //! @member string host +  //! @member int port +  //! @member string basedn +  //! Self-explanatory. +  //! @member array(string) attributes +  //! Array containing the attributes. Undefined if none was +  //! specified. +  //! @member int scope +  //! The scope as one of the @expr{SEARCH_*@} constants. +  //! Undefined if none was specified. +  //! @member string filter +  //! The search filter. Undefined if none was specified. +  //! @member mapping(string:string|int(1..1)) extensions +  //! The extensions. Undefined if none was specified. The mapping +  //! values are @expr{1@} for extensions without values. Critical +  //! extensions are checked and the leading @expr{"!"@} do not +  //! remain in the mapping indices. +  //! @endmapping +  //! +  //! @seealso +  //! @[get_parsed_url] +  mapping(string:mixed) parse_url (string ldapuri) {       // ldap://machine.at.home.cz:123/c=cz?attr1,attr2,attr3?sub?(uid=*)?!bindname=uid=hop,dc=unibase,dc=cz"       string url=ldapuri;    array ar;    mapping(string:mixed) res = ([]);       if (sscanf (url, "%[^:]://%s", res->scheme, url) != 2)    ERROR ("Failed to parse scheme from ldap url.\n");   
pike.git/lib/modules/Protocols.pmod/LDAP.pmod/client.pike:1974:    ERROR ("Critical extension %s is not supported.\n", extype);    }    if (extype == "")    ERROR ("Failed to parse extension type from %O.\n", ext);    extensions[extype] =    exvalue ? _Roxen.http_decode_string (exvalue) : 1;    }    res->ext = extensions;    }    case 4: res->filter = _Roxen.http_decode_string (ar[3]); -  case 3: res->scope = (["base": 0, "one": 1, "sub": 2])[ar[2]]; +  case 3: res->scope = (["base": SCOPE_BASE, +  "one": SCOPE_ONE, +  "sub": SCOPE_SUB])[ar[2]];    case 2: if (sizeof(ar[1])) res->attributes =    map (ar[1] / ",", _Roxen.http_decode_string);    case 1: res->basedn = _Roxen.http_decode_string (ar[0]);    }       return res;       } //parse_uri