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.49 2003/07/01 15:21:59 anders Exp $ + // $Id: client.pike,v 1.50 2003/09/01 16:36:47 nilsson 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:133:    catch( out = utf8_to_string(in) );    return out;       }       private array _get_attr_values(int ver, object x) {       array res = ({});       if(!sizeof(x->elements)) -  return(res); +  return res;    foreach(x->elements[1]->elements, object val1)    res += ({ val1->value });    if(ver == 3) {    // deUTF8    res = Array.map(res, utf2s);    } -  return(res); +  return res;    }       private array _New_decode(array ar) {       array res = ({});    array entry1;    mapping attrs;    object oder;       foreach(ar, string raw1) {    oder = (.ldap_privates.ldap_der_decode(raw1)->elements[1]);    attrs = (["dn":({ASN1_DECODE_DN(oder)})]);    if(catch(entry1 = ASN1_GET_ATTR_ARRAY(oder))) continue;    foreach(entry1, object attr1) {    attrs += ([ASN1_GET_ATTR_NAME(attr1):_get_attr_values(ldap_version, attr1)]);    }    res += ({attrs});    }    -  return (res); +  return res;    } // _New_decode       //!    //! You can't create instances of this object yourself.    //! The only way to create it is via a search of a LDAP server.    object|int create(array rawres, int|void stuff) {    // rawres: array of result in raw format, but WITHOUT LDAP PDU !!!    // stuff: 1=bind result; ...       int lastel = sizeof(rawres) - 1;       if (lastel < 0) {    global::seterr (LDAP_LOCAL_ERROR);    THROW(({"LDAP: Internal error.\n",backtrace()})); -  return(-global::ldap_errno); +  return -global::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]);    DWRITE(sprintf("result.create: str=%s\n",resultstring));   #ifdef V3_REFERRALS    // referral (v3 mode)
pike.git/lib/modules/Protocols.pmod/LDAP.pmod/client.pike:209: Inside #if 0
  #if 0    // Context specific proccessing of 'rawres'    switch(stuff) {    case 1: DWRITE("result.create: stuff=1\n");    break;    default: DWRITE(sprintf("result.create: stuff=%d\n", stuff));       }   #endif    -  return(this_object()); +  return this;       }       //!    //! Returns error number of search result.    //!    //! @seealso    //! @[LDAP.client.result.error_string] -  int error_number() { return(resultcode); } +  int error_number() { return resultcode; }       //!    //! Returns error description of search result.    //!    //! @seealso    //! @[LDAP.client.result.error_number]    string error_string() { -  return((stringp(resultstring) && sizeof(resultstring)) ? +  return ((stringp(resultstring) && sizeof(resultstring)) ?    resultstring : ldap_errlist[resultcode]);    }       //!    //! Returns the number of entries.    //!    //! @seealso    //! @[LDAP.client.result.count_entries] -  int num_entries() { return(entrycnt); } +  int num_entries() { return entrycnt; }       //!    //! Returns the number of entries from current cursor    //! possition till end of the list.    //!    //! @seealso    //! @[LDAP.client.result.first], @[LDAP.client.result.next] -  int count_entries() { return(entrycnt - actnum); } +  int count_entries() { return entrycnt - actnum; }       //! Returns a mapping with an entry for each attribute.    //! Each entry is an array of values of the attribute.    //!    //! @param index    //! Optional argument can be used for direct access    //! to the entry other then currently pointed by cursor.    int|mapping(string:array(string)) fetch(int|void idx) {       if (!idx)    idx = actnum + 1;    if ((idx <= num_entries()) && (idx > 0)) {    actnum = idx - 1; -  return(entry[actnum]); +  return entry[actnum];    } -  return(0); +  return 0;    }       //!    //! Returns distinguished name (DN) of the current entry    //! in the result list. Notice that this is the same    //! as fetch()->dn[0]. -  string get_dn() { return(fetch()["dn"][0]); } +  string get_dn() { return fetch()["dn"][0]; }       //!    //! Initialized the result cursor to the first entry    //! in the result list.    //!    //! @seealso    //! @[LDAP.client.result.next]    void first() { actnum = 0; }       //!    //! Moves the result cursor to the next entry    //! in the result list. Returns number of remained entries    //! in the result list. Returns 0 at the end.    //!    //! @seealso    //! @[LDAP.client.result.next]    int next() {    if (actnum < (num_entries()-1)) {    actnum++; -  return(count_entries()); +  return count_entries();    } -  return(0); +  return 0;    }       } // end of class 'result' ---------------       // helper functions       private int chk_ver() {       if ((ldap_version != 2) && (ldap_version != 3)) {    seterr (LDAP_PROTOCOL_ERROR);    THROW(({"LDAP: Unknown/unsupported protocol version.\n",backtrace()})); -  return(-ldap_errno); +  return -ldap_errno;    } -  return(0); +  return 0;    }       private int chk_binded() {    // For version 2: we must be 'binded' first !!!       if ((ldap_version == 2) && !binded) {    seterr (LDAP_PROTOCOL_ERROR);    THROW(({"LDAP: Must binded first.\n",backtrace()})); -  return(-ldap_errno); +  return -ldap_errno;    }    if ((ldap_version == 3) && !binded)    bind(); -  return(0); +  return 0;    }       private int chk_dn(string dn) {       if ((!dn) || (!sizeof(dn))) {    seterr (LDAP_INVALID_DN_SYNTAX);    THROW(({"LDAP: Invalid DN syntax.\n",backtrace()})); -  return(-ldap_errno); +  return -ldap_errno;    } -  return(0); +  return 0;    }       //! Several information about code itself and about active connection too    mapping info;       //! @decl void create()    //! @decl void create(string url)    //! @decl void create(string url, object context)    //!    //! Create object. The first optional argument can be used later
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.49 $"/" ")[1] ]); +  info = ([ "code_revision" : ("$Revision: 1.50 $"/" ")[1] ]);       if(!url || !sizeof(url))    url = LDAP_DEFAULT_URL;       lauth = parse_url(url);       if(!stringp(lauth->scheme) ||    ((lauth->scheme != "ldap")   #if constant(SSL.sslfile)    && (lauth->scheme != "ldaps")
pike.git/lib/modules/Protocols.pmod/LDAP.pmod/client.pike:442:    string pass = password;    password = "censored";       vers = Standards.ASN1.Types.asn1_integer(ldap_version);    namedn = Standards.ASN1.Types.asn1_octet_string(name);    auth = ASN1_CONTEXT_OCTET_STRING(0, pass);    // SASL credentials ommited       msgval = ASN1_APPLICATION_SEQUENCE(0, ({vers, namedn, auth}));    -  return (do_op(msgval)); +  return do_op(msgval);    }       //! @decl int bind()    //! @decl int bind(string dn, string password)    //! @decl int bind(string dn, string password, int version)    //!    //! Authenticates connection to the direcory.    //!    //! First form uses default value previously entered in create.    //!
pike.git/lib/modules/Protocols.pmod/LDAP.pmod/client.pike:487:    int bind (string|void dn, string|void password, int|void version) {       int id;    mixed raw;    string pass = password;    password = "censored";       if (!version)    version = LDAP_DEFAULT_VERSION;    if (chk_ver()) -  return(0); +  return 0;    if (!stringp(dn))    dn = mappingp(lauth->ext) ? lauth->ext->bindname||"" : "";    if (!stringp(pass))    pass = "";    ldap_version = version;    if(ldap_version == 3) {    dn = string_to_utf8(dn);    pass = string_to_utf8(pass);    }    if(intp(raw = send_bind_op(dn, pass))) {    THROW(({error_string()+"\n",backtrace()})); -  return(-ldap_errno); +  return -ldap_errno;    }       binded = 0;    last_rv = result(({raw}),1);    if (!last_rv->error_number())    binded = 1;    DWRITE_HI(sprintf("client.BIND: %s\n", last_rv->error_string()));    seterr (last_rv->error_number());    return binded;       } // bind       private int send_unbind_op() {    // UNBIND operation       writemsg(ASN1_APPLICATION_OCTET_STRING(2, ""));       //ldap::close();    -  return (1); +  return 1;    }       void destroy() {       //send_unbind_op();    destruct(this_object());    }       //!    //! Unbinds from the directory and close the connection.    int unbind () {       if (send_unbind_op() < 1) {    THROW(({error_string()+"\n",backtrace()})); -  return(-ldap_errno); +  return -ldap_errno;    }    binded = 0;    DWRITE_HI("client.UNBIND: OK\n");       } // unbind       private int|string send_op_withdn(int op, string dn) {    // DELETE, ...    -  return (do_op(ASN1_APPLICATION_OCTET_STRING(op, dn))); +  return do_op(ASN1_APPLICATION_OCTET_STRING(op, dn));       }       //!    //! Deletes entry from the LDAP server.    //!    //! @param dn    //! The distinguished name of deleted entry.    //!    //! @returns
pike.git/lib/modules/Protocols.pmod/LDAP.pmod/client.pike:566:    //!    //! @note    //! The API change: the returning code was changed in Pike 7.3+    //! to follow his logic better.    int delete (string dn) {       int id;    mixed raw;       if (chk_ver()) -  return(0); +  return 0;    if (chk_binded()) -  return(0); +  return 0;    if (chk_dn(dn)) -  return(0); +  return 0;    if(ldap_version == 3) {    dn = string_to_utf8(dn);    }    if(intp(raw = send_op_withdn(10, dn))) {    THROW(({error_string()+"\n",backtrace()})); -  return(0); +  return 0;    }       last_rv = result(({raw}));    DWRITE_HI(sprintf("client.DELETE: %s\n", last_rv->error_string())); -  seterr (last_rv->error_number()); -  return (!last_rv->error_number()); +  seterr(last_rv->error_number()); +  return !last_rv->error_number();       } // delete       private int|string send_compare_op(string dn, array(string) aval) {    // COMPARE       object msgval;       msgval = ASN1_APPLICATION_SEQUENCE(14,    ({ Standards.ASN1.Types.asn1_octet_string(dn),    Standards.ASN1.Types.asn1_sequence(    ({ Standards.ASN1.Types.asn1_octet_string(aval[0]),    Standards.ASN1.Types.asn1_octet_string(aval[1])    }))    })    );    -  return (do_op(msgval)); +  return do_op(msgval);    }          //!    //! Compares given attribute value with one in the directory.    //!    //! @param dn    //! The distinguished name of compared entry.    //!    //! @param aval
pike.git/lib/modules/Protocols.pmod/LDAP.pmod/client.pike:627:    //! The API change: the returning code was changed in Pike 7.3+    //! to follow his logic better.    int compare (string dn, array(string) aval) {       int id;    mixed raw;       // if (!aval || sizeof(aval)<2)    // error    if (chk_ver()) -  return(0); +  return 0;    if (chk_binded()) -  return(0); +  return 0;    if (chk_dn(dn)) -  return(0); +  return 0;    if(ldap_version == 3) {    dn = string_to_utf8(dn);    aval = Array.map(aval, string_to_utf8);    }    if(intp(raw = send_compare_op(dn, aval))) {    THROW(({error_string()+"\n",backtrace()})); -  return(0); +  return 0;    }       last_rv = result(({raw}));    DWRITE_HI(sprintf("client.COMPARE: %s\n", last_rv->error_string())); -  seterr (last_rv->error_number()); -  return (!last_rv->error_number()); +  seterr(last_rv->error_number()); +  return !last_rv->error_number();       } // 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:673:    Standards.ASN1.Types.asn1_set(ohlp)    }))    });    }       msgval = ASN1_APPLICATION_SEQUENCE(8,    ({Standards.ASN1.Types.asn1_octet_string(dn),    Standards.ASN1.Types.asn1_sequence(oatt)    }));    -  return (do_op(msgval)); +  return do_op(msgval);    }          //! The Add Operation allows a client to request the addition    //! of an entry into the directory    //!    //! @param dn    //! The Distinguished Name of the entry to be added.    //!    //! @param attrs
pike.git/lib/modules/Protocols.pmod/LDAP.pmod/client.pike:699:    //!    //! @note    //! The API change: the returning code was changed in Pike 7.3+    //! to follow his logic better.    int add (string dn, mapping(string:array(string)) attrs) {       int id;    mixed raw;       if (chk_ver()) -  return(0); +  return 0;    if (chk_binded()) -  return(0); +  return 0;    if (chk_dn(dn)) -  return(0); +  return 0;    if(ldap_version == 3) {    dn = string_to_utf8(dn);    array(string) keys = indices(attrs);    array(array(string)) vals = values(attrs);    attrs = mkmapping(Array.map(keys, string_to_utf8),    Array.map(vals, Array.map, string_to_utf8));    }    if(intp(raw = send_add_op(dn, attrs))) {    THROW(({error_string()+"\n",backtrace()})); -  return(0); +  return 0;    }       last_rv = result(({raw}));    DWRITE_HI(sprintf("client.ADD: %s\n", last_rv->error_string())); -  seterr (last_rv->error_number()); -  return (!last_rv->error_number()); +  seterr(last_rv->error_number()); +  return !last_rv->error_number();       } // add       private static array(string) filter_get_sub1expr(string fstr) {    // returns one-level brackets enclosed expressions       array(string) rvarr = ({});    int leftflg = 0, nskip = 0;       for(int ix=0; ix<sizeof(fstr); ix++)
pike.git/lib/modules/Protocols.pmod/LDAP.pmod/client.pike:752:    rvarr += ({fstr[leftflg..(ix-1)]});    leftflg = 0;    break;    }    } // while    }    if(leftflg) {    ; // silent error: Missed right-enclosed bracket !    }    //DWRITE(sprintf("client.sub1: arr=%O\n",rvarr)); -  return(rvarr); +  return rvarr;    }       /*private*/ object make_simple_filter(string filter) {    // filter expression parser - only simple expressions!       object rv;    int op, ix;       DWRITE(sprintf("client.make_simple_filter: filter: [%s]\n", filter));    if((op = predef::search(filter, ">=")) > 0) { // greater or equal    DWRITE("client.make_simple_filter: [>=]\n"); -  return(ASN1_CONTEXT_SEQUENCE(5, +  return ASN1_CONTEXT_SEQUENCE(5,    ({Standards.ASN1.Types.asn1_octet_string(filter[..(op-1)]),    Standards.ASN1.Types.asn1_octet_string(filter[(op+2)..]) -  }))); +  }));    }    if((op = predef::search(filter, "<=")) > 0) { // less or equal    DWRITE("client.make_simple_filter: [<=]\n"); -  return(ASN1_CONTEXT_SEQUENCE(6, +  return ASN1_CONTEXT_SEQUENCE(6,    ({Standards.ASN1.Types.asn1_octet_string(filter[..(op-1)]),    Standards.ASN1.Types.asn1_octet_string(filter[(op+2)..]) -  }))); +  }));    }    if((op = predef::search(filter, "=")) > 0) { // equal, substring    if((filter[-2] == '=') && (filter[-1] == '*')) // any (=*) -  return(make_simple_filter(filter[..op-1])); +  return make_simple_filter(filter[..op-1]);    ix = predef::search(filter[(op+1)..], "*");    if ((ix != -1) && (filter[op+ix] != '\\')) { // substring    object ohlp;    array oarr = ({}), ahlp = ({});    array filtval = filter[(op+1)..] / "*";       // escape processing    for(int cnt = 0; cnt < sizeof(filtval); cnt++) {    if(cnt) {    if(sizeof(filtval[cnt-1]) && filtval[cnt-1][-1] == '\\')
pike.git/lib/modules/Protocols.pmod/LDAP.pmod/client.pike:813:    if(cnt == ix-1) { // rightmost element    if(sizeof(ahlp[ix-1]))    oarr += ({ASN1_CONTEXT_OCTET_STRING(2, ahlp[ix-1])});    } else { // inside element    if(sizeof(ahlp[cnt]))    oarr += ({ASN1_CONTEXT_OCTET_STRING(1, ahlp[cnt])});    }    // for       DWRITE(sprintf("client.make_simple_filter: substring: [%s]:\n%O\n", filter, ahlp)); -  return(ASN1_CONTEXT_SEQUENCE(4, +  return ASN1_CONTEXT_SEQUENCE(4,    ({Standards.ASN1.Types.asn1_octet_string(filter[..(op-1)]),    Standards.ASN1.Types.asn1_sequence(oarr) -  }))); +  }));    } else { // equal    DWRITE("client.make_simple_filter: [=]\n"); -  return(ASN1_CONTEXT_SEQUENCE(3, +  return ASN1_CONTEXT_SEQUENCE(3,    ({Standards.ASN1.Types.asn1_octet_string(filter[..(op-1)]),    Standards.ASN1.Types.asn1_octet_string(filter[(op+1)..]) -  }))); +  }));    }    } // if equal,substring    // present    DWRITE("client.make_simple_filter: [present]\n"); -  return(ASN1_CONTEXT_OCTET_STRING(7, filter)); +  return ASN1_CONTEXT_OCTET_STRING(7, filter);   }          /*private*/ object|int make_filter(string filter) {    // filter expression parser       object ohlp;    array(object) oarr = ({});    int op ;   
pike.git/lib/modules/Protocols.pmod/LDAP.pmod/client.pike:852:    // strip leading and trailing spaces    filter = String.trim_all_whites(filter);       // strip leading and trailing brackets   #if 1    if(filter[0] == '(') {    int ix;    string f2 = reverse(filter[1..]);    if((ix = predef::search(f2, ")")) > -1) {    filter = reverse(f2[ix+1..]); -  return(make_filter(filter)); +  return make_filter(filter);    } -  return(-1); // error in filter expr. +  return -1; // error in filter expr.    }   #endif       op = -1;       DWRITE(sprintf("client.make_filter: ftype=%c\n",filter[0]));    switch (filter[0]) {    case '&': // and    case '|': // or    foreach(filter_get_sub1expr(filter[1..]), string sub1expr)    if (objectp(ohlp = make_filter(sub1expr)))    oarr += ({ohlp});    else -  return(0); // error: Filter parameter error! +  return 0; // error: Filter parameter error!    DWRITE(sprintf("client.make_filter: expr_cnt=%d\n",sizeof(oarr)));    //ohlp = Standards.ASN1.Encode.asn1_set(@oarr);    op = 0;    if (filter[0] == '|')    op = 1; -  return(ASN1_CONTEXT_SET(op, oarr)); +  return ASN1_CONTEXT_SET(op, oarr);    case '!': // not    if (objectp(ohlp = make_filter(filter_get_sub1expr(filter[1..])[0]))) -  return(ASN1_CONTEXT_SEQUENCE(2, ({ ohlp}) )); +  return ASN1_CONTEXT_SEQUENCE(2, ({ ohlp}) );    else -  return(0); // error: Filter parameter error! +  return 0; // error: Filter parameter error!    break;    default : // we assume simple filter -  return(make_simple_filter(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){    // 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)); +  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,    ({ 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)); +  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:959:    int|void attrsonly) {       int id,nv;    mixed raw;    array(string) rawarr = ({});       filter=filter||lauth->filter; // default from LDAP URI       DWRITE_HI("client.SEARCH: " + (string)filter + "\n");    if (chk_ver()) -  return(0); +  return 0;    if (chk_binded()) -  return(0); +  return 0;    if(ldap_version == 3) {    filter = string_to_utf8(filter);    }   #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))) {    THROW(({error_string()+"\n",backtrace()})); -  return(0); +  return 0;    }   #ifdef LDAP_PROTOCOL_PROFILE    };    DWRITE_PROF("send_search_op: %O\n", _prof_gtim);   #endif       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); +  return 0;    }    rawarr += ({raw});    } // while   #ifdef LDAP_PROTOCOL_PROFILE    };    DWRITE_PROF("rawarr++: %O\n", _prof_gtim);   #endif      #ifdef LDAP_PROTOCOL_PROFILE    _prof_gtim = gauge{ last_rv = result(rawarr); };
pike.git/lib/modules/Protocols.pmod/LDAP.pmod/client.pike:1013:   #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();       DWRITE_HI(sprintf("client.SEARCH: %s (entries: %d)\n",    last_rv->error_string(), last_rv->num_entries())); -  return(last_rv); +  return last_rv;       } // search          //! @param base_dn    //! base DN for search    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 old_dn;    }       //!    //! Sets value of scope for search operation.    //!    //! @param scope    //! Value can be integer or its corresponding string value.    //! 0: base, 1: one, 2: sub    //!    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); +  default: return -1;    }    else    if(scope != 0 && scope != 1 && scope != 2) -  return (-1); +  return -1;       ldap_scope = scope;    DWRITE_HI("client.SET_SCOPE = " + (string)scope + "\n"); -  return(old_scope); +  return old_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    //if (intp(value))    ldap_deref = value;    //else -  // return(-1); +  // return -1;    break;    case 2: // LDAP_OPT_SIZELIMIT    //if (intp(value))    ldap_sizelimit = value;    //else -  // return(-1); +  // return -1;    break;    case 3: // LDAP_OPT_TIMELIMIT    //if (intp(value))    ldap_timelimit = value;    //else -  // return(-1); +  // return -1;    break;    case 4: // LDAP_OPT_REFERRALS -  default: return(-1); +  default: return -1;    }       -  return(0); +  return 0;    }       //! @param option_type    //! LDAP_OPT_xxx    int get_option (int opttype) {          DWRITE_HI("client.GET_OPTION: " + (string)opttype + "\n");    switch (opttype) {    case 1: // LDAP_OPT_DEREF -  return(ldap_deref); +  return ldap_deref;    case 2: // LDAP_OPT_SIZELIMIT -  return(ldap_sizelimit); +  return ldap_sizelimit;    case 3: // LDAP_OPT_TIMELIMIT -  return(ldap_timelimit); +  return ldap_timelimit;    case 4: // LDAP_OPT_REFERRALS    }    -  return(-1); +  return -1;    }       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) {    if(!intp((attropval[atype])[0])) -  return(seterr (LDAP_PROTOCOL_ERROR)); +  return seterr(LDAP_PROTOCOL_ERROR);    attrarr = ({});    for(int ix=1; ix<sizeof(attropval[atype]); ix++)    attrarr += ({Standards.ASN1.Types.asn1_octet_string(    (attropval[atype])[ix])});   // if(sizeof(attrarr)) // attributevalue ?    o = Standards.ASN1.Types.asn1_sequence(    ({Standards.ASN1.Types.asn1_octet_string(atype),    Standards.ASN1.Types.asn1_set(attrarr)    }));   // else
pike.git/lib/modules/Protocols.pmod/LDAP.pmod/client.pike:1148:    ({ASN1_ENUMERATED((attropval[atype])[0]),    o    }))});    } //foreach       msgval = ASN1_APPLICATION_SEQUENCE(6,    ({ Standards.ASN1.Types.asn1_octet_string(dn),    Standards.ASN1.Types.asn1_sequence(oatt)    }));    -  return (do_op(msgval)); +  return do_op(msgval);    }       private int|string send_modifydn_op(string dn, string newrdn,    int deleteoldrdn, string newsuperior) {       object msgval;    array seq=({ Standards.ASN1.Types.asn1_octet_string(dn),    Standards.ASN1.Types.asn1_octet_string(newrdn),    Standards.ASN1.Types.asn1_boolean(deleteoldrdn)    });    if(newsuperior)    seq+=({Standards.ASN1.Types.asn1_octet_string(newsuperior)});       msgval = ASN1_APPLICATION_SEQUENCE(12, seq);    -  return (do_op(msgval)); +  return do_op(msgval);    }       //! The Modify DN Operation allows a client to change the leftmost    //! (least significant) component of the name of an entry in the directory,    //! or to move a subtree of entries to a new location in the directory.    //!    //! @param dn    //! DN of source object    //!    //! @param newrdn
pike.git/lib/modules/Protocols.pmod/LDAP.pmod/client.pike:1198:    //!    //! @note    //! The API change: the returning code was changed in Pike 7.3+    //! to follow his logic better.    int modifydn (string dn, string newrdn, int deleteoldrdn,    string|void newsuperior) {       mixed raw;       if (chk_ver()) -  return(0); +  return 0;    if (chk_binded()) -  return(0); +  return 0;    if (chk_dn(dn)) -  return(0); +  return 0;    if(ldap_version == 3) {    dn = string_to_utf8(dn);    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); +  return 0;    }       last_rv = result(({raw}));    DWRITE_HI(sprintf("client.MODIFYDN: %s\n", last_rv->error_string())); -  seterr (last_rv->error_number()); -  return (!last_rv->error_number()); +  seterr(last_rv->error_number()); +  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.    //!    //! @param attropval
pike.git/lib/modules/Protocols.pmod/LDAP.pmod/client.pike:1258:    //!    //! @note    //! The API change: the returning code was changed in Pike 7.3+    //! to follow his logic better.    int modify (string dn, mapping(string:array(mixed)) attropval) {       int id;    mixed raw;       if (chk_ver()) -  return(0); +  return 0;    if (chk_binded()) -  return(0); +  return 0;    if (chk_dn(dn)) -  return(0); +  return 0;    if(ldap_version == 3) {    dn = string_to_utf8(dn);    array(string) keys = indices(attropval);    array(array(mixed)) vals = values(attropval);    attropval = mkmapping(Array.map(keys, string_to_utf8),    Array.map(vals, Array.map, lambda(mixed x) {    return    (stringp(x)?    string_to_utf8(x) :    x);    }));    }    if(intp(raw = send_modify_op(dn, attropval))) {    THROW(({error_string()+"\n",backtrace()})); -  return(0); +  return 0;    }       last_rv = result(({raw}));    DWRITE_HI(sprintf("client.MODIFY: %s\n", last_rv->error_string())); -  seterr (last_rv->error_number()); -  return (!last_rv->error_number()); +  seterr(last_rv->error_number()); +  return !last_rv->error_number();       } // modify       //! Gets referrals.    //!    //! @returns    //! Returns array of referrals or @expr{0@}.    array|int get_referrals() {    if(last_rv->referrals)    return last_rv->referrals;
pike.git/lib/modules/Protocols.pmod/LDAP.pmod/client.pike:1314:    array ar;    mapping res;       s = (url / ":")[0];    url = url[sizeof(s)..];       res = ([ "scheme" : s ]);      #ifdef LDAP_URL_STRICT    if (url[..2] != "://") -  return(-1); +  return -1;   #endif       s = (url[3..] / "/")[0];    url = url[sizeof(s)+4..];       res += ([ "host" : (s / ":")[0] ]);       if(sizeof(s / ":") > 1)    res += ([ "port" : (int)((s / ":")[1]) ]);   
pike.git/lib/modules/Protocols.pmod/LDAP.pmod/client.pike:1349:    case 4: res += ([ "filter" : ar[3] ]);    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 += ([ "basedn" : ar[0] ]);    }    -  return (res); +  return res;       } //parse_uri      #endif