Branch: Tag:

2000-07-20

2000-07-20 14:54:41 by Honza Petrous <hop@unibase.cz>

Increased default LDAP version number to v3

Rev: lib/modules/Protocols.pmod/LDAP.pmod/client.pike:1.16
Rev: lib/modules/Protocols.pmod/LDAP.pmod/ldap_globals.h:1.3

1:   // LDAP client protocol implementation for Pike.   // - // $Id: client.pike,v 1.15 2000/07/14 15:29:39 hop Exp $ + // $Id: client.pike,v 1.16 2000/07/20 14:54:41 hop Exp $   //   // Honza Petrous, hop@unibase.cz   //
50:   //   // newer versions - see CVS at roxen.com (hop)   // + // - corrected deUTF8 values in result + // - + //   // Specifications:   //   // RFC 1558 (search filter representations)
89:    private int ldap_deref = 0; // 0: ...    private int ldap_sizelimit = 0;    private int ldap_timelimit = 0; +  private mapping lauth = ([]);         
110:    int count_entries() { return(entrycnt - actnum); }       -  private array _get_attr_values(object x) { +  private array _get_attr_values(int ver, object x) {       array res = ({});   
118:    return(res);    foreach(x->elements[1]->elements, object val1)    res += ({ val1->value }); +  if(ver == 3) { +  // deUTF8 +  res = Array.map(res, utf8_to_string); +  }    return(res);    }   
131:    attrs = (["dn":({ASN1_DECODE_DN(raw1)})]);    entry1 = ASN1_GET_ATTR_ARRAY(raw1);    foreach(entry1, object attr1) { -  attrs += ([ASN1_GET_ATTR_NAME(attr1):_get_attr_values(attr1)]); +  attrs += ([ASN1_GET_ATTR_NAME(attr1):_get_attr_values(ldap_version, attr1)]);    }    res += ({attrs});    }    -  if(ldap_version == 3) { -  // deUTF8 -  res = Array.map(res, utf8_to_string); -  } -  +     return (res);    } // _New_decode   
232:    THROW(({"LDAP: Must binded first.\n",backtrace()}));    return(-ldap_errno);    } +  if ((ldap_version == 3) && !binded) +  bind();    return(0);    }   
249:    //    // create(string|void server)    // -  // server: server name (hostname or IP, default: 127.0.0.1) -  // with optional port number (default: 389) +  // server: server URL in form "ldap://hostname/basedn???!bindname=    void create(string|void server)    { -  int port = LDAP_DEFAULT_PORT; +        if(!server || !sizeof(server))    server = (string)LDAP_DEFAULT_HOST; -  else -  if(predef::search(server,":")>0) { -  port = (int)((server / ":")[1]); -  server = (server / ":")[0]; +  +  lauth = parse_url(server); +  +  if(!stringp(lauth->scheme) || (lauth->scheme != "ldap")) { +  THROW(({"Unknown scheme in server URL.\n",backtrace()}));    }    -  ::create(server, port); -  if(!::connected) -  { +  ::create(lauth->host||LDAP_DEFAULT_HOST, lauth->port||LDAP_DEFAULT_PORT); +  if(!::connected) {    THROW(({"Failed to connect to LDAP server.\n",backtrace()}));    }    DWRITE(sprintf("client.create: remote = %s\n", query_address())); -  DWRITE_HI("client.OPEN: " + server + " - OK\n"); +  DWRITE_HI("client.OPEN: " + lauth->host||LDAP_DEFAULT_HOST + (string)(lauth->port||LDAP_DEFAULT_PORT) + " - OK\n");       binded = 0;    -  +  if(lauth->scope) +  set_scope(lauth->scope); +  if(lauth->basedn) +  set_basedn(lauth->basedn); +     } // create       private mixed send_bind_op(string name, string password) {
308:    if (chk_ver())    return(-ldap_errno);    if (!stringp(name)) -  name = ""; +  name = mappingp(lauth->ext) ? lauth->ext->bindname||"" : "";    if (!stringp(password))    password = "";    ldap_version = proto;
977:    ar = url / "?";       switch (sizeof(ar)) { -  case 5: res += ([ "ext" : ar[4] ]); +  case 5: if (sizeof(ar[4])) { +  mapping extensions = ([]); +  foreach(ar[4] / ",", string ext) { +  int ix = predef::search(ext, "="); +  if(ix) +  extensions += ([ ext[..(ix-1)] : replace(ext[ix+1..],QUOTED_COMMA, ",") ]); +  } +  if (sizeof(extensions)) +  res += ([ "ext" : extensions ]); +  } +  //case 5: res += ([ "ext" : ar[4] ]);    case 4: res += ([ "filter" : ar[3] ]); -  case 3: res += ([ "scope" : ar[2] ]); +  case 3: switch (ar[2]) { +  case "sub": res += ([ "scope" : 2 ]); break; +  case "one": res += ([ "scope" : 1 ]); break; +  default: res += ([ "scope" : 0]); // = "base" +  }    case 2: res += sizeof(ar[1]) ? ([ "attributes" : ar[1] / "," ]) : ([]); -  case 1: res += ([ "dn" : ar[0] ]); +  case 1: res += ([ "basedn" : ar[0] ]);    }    -  //write("DEB: mapping: [%O] \n", res); -  +     return (res);       } //parse_uri         #endif