pike.git / lib / modules / Protocols.pmod / LDAP.pmod / protocol.pike

version» Context lines:

pike.git/lib/modules/Protocols.pmod/LDAP.pmod/protocol.pike:1:   #pike __REAL_VERSION__      // LDAP client protocol implementation for Pike.   // - // $Id: protocol.pike,v 1.13 2004/05/25 12:06:11 grubba Exp $ + // $Id: protocol.pike,v 1.14 2004/06/18 13:05:50 grubba Exp $   //   // Honza Petrous, hop@unibase.cz   //   // ----------------------------------------------------------------------   //   // History:   //   // v1.9 1999-02-19 created separate file   // - improved checking of readed bytes in 'readmsg'   // v1.9.1.1
pike.git/lib/modules/Protocols.pmod/LDAP.pmod/protocol.pike:75:    // ----------------------    // Reads LDAP PDU (with defined msgid) from the server       int msglen = 0, ix, ofs;    string s, shlp;       if(sizeof(readbuf) < 2)    readbuf = ldapfd->read(2); // 1. byte = 0x0C, 2. byte = msglen    if (intp(readbuf) || (sizeof(readbuf) < 2)) {    seterr (LDAP_TIMEOUT); -  DWRITE_HI("protocol.read_anwer: ERROR: connection timeout.\n"); -  THROW(({"LDAP: connection timeout.\n",backtrace()})); +  DWRITE_HI("protocol.read_answer: ERROR: connection closed.\n"); +  THROW(({"LDAP: connection closed.\n",backtrace()}));    //return -ldap_errno;    return;    }    if (readbuf[0] != '0') {    seterr (LDAP_PROTOCOL_ERROR); -  DWRITE_HI("protocol.read_anwer: ERROR: retv=<"+sprintf("%O",readbuf)+">\n"); +  DWRITE_HI("protocol.read_answer: ERROR: retv=<"+sprintf("%O",readbuf)+">\n");    THROW(({"LDAP: Protocol mismatch.\n",backtrace()}));    //return -ldap_errno;    return;    } -  DWRITE(sprintf("protocol.read_anwer: sizeof = %d\n", sizeof(readbuf))); +  DWRITE(sprintf("protocol.read_answer: sizeof = %d\n", sizeof(readbuf)));       msglen = readbuf[1];    ofs = 2;    if (msglen & 0x80) { // > 0x7f    if (msglen == 0x80) { // RFC not allows unexplicitly defined length    seterr (LDAP_PROTOCOL_ERROR);    THROW(({"LDAP: Protocol mismatch.\n",backtrace()}));    //return -ldap_errno;    return;    }
pike.git/lib/modules/Protocols.pmod/LDAP.pmod/protocol.pike:125:    ix = (ofs + msglen) - sizeof(readbuf);    if(ix > 0)    s = ldapfd->read(ix);    if (!s || (sizeof(s) < ix)) {    seterr (LDAP_SERVER_DOWN);    THROW(({"LDAP: connection closed by server.\n",backtrace()}));    //return -ldap_errno;    return;    }    readbuf += s; -  //DWRITE(sprintf("protocol.read_anwer: %s\n", .ldap_privates.ldap_der_decode(readbuf)->debug_string())); -  DWRITE("protocol.read_anwer: ok=1.\n"); +  //DWRITE(sprintf("protocol.read_answer: %s\n", .ldap_privates.ldap_der_decode(readbuf)->debug_string())); +  DWRITE("protocol.read_answer: ok=1.\n");    ok = 1;       if(con_ok)    con_ok(this, @extra_args);    }       static int is_whole_pdu() {    // ----------------------    // Check if LDAP PDU is complete in 'readbuf'   
pike.git/lib/modules/Protocols.pmod/LDAP.pmod/protocol.pike:230:   /* ------------ legacy support -----------------*/       string|int readmsg(int msgid) {    // Reads LDAP PDU (with defined msgid) from server, checks msgid ...       int msglen = 0, ix;    string|int retv;    string s, shlp;       retv = ldapfd->read(2); // 1. byte = 0x0C, 2. byte = msglen -  if (intp(retv) && (retv == -1)) { +  if (retv == -1) {    seterr (LDAP_TIMEOUT);    DWRITE_HI("protocol.readmsg: ERROR: connection timeout.\n");    THROW(({"LDAP: connection timeout.\n",backtrace()}));    return -ldap_errno;    }    if (!retv || (sizeof(retv) != 2) || (retv[0] != '0')) {    seterr (LDAP_PROTOCOL_ERROR);    DWRITE_HI("protocol.readmsg: ERROR: retv=<"+sprintf("%O",retv)+">\n");    THROW(({"LDAP: Protocol mismatch.\n",backtrace()}));    return -ldap_errno;    }    DWRITE(sprintf("protocol.readmsg: sizeof = %d\n", sizeof(retv)));       msglen = retv[1];    if (msglen & 0x80) { // > 0x7f -  if (msglen == 0x80) { // RFC not allows unexplicitly defined length +  if (msglen == 0x80) { // RFC does not allow implicitly defined length    seterr (LDAP_PROTOCOL_ERROR);    THROW(({"LDAP: Protocol mismatch.\n",backtrace()}));    return -ldap_errno;    }    s = ldapfd->read(msglen & 0x7f);    if (!s) {    seterr (LDAP_PROTOCOL_ERROR);    THROW(({"LDAP: Protocol mismatch.\n",backtrace()}));    return -ldap_errno;    }    retv += s;    msglen = 0; // !!! RESTRICTION: 2^32 !!!    shlp = reverse(s);    for (ix=0; ix<sizeof(shlp); ix++) {    msglen += shlp[ix]*(1<<(ix*8));    }    } -  +  DWRITE(sprintf("protocol.readmsg: reading %d bytes.\n", msglen));    s = ldapfd->read(msglen);    if (!s | (sizeof(s) < msglen)) {    seterr (LDAP_SERVER_DOWN);    THROW(({"LDAP: connection closed by server.\n",backtrace()}));    return -ldap_errno;    }    retv += s;    DWRITE(sprintf("protocol.readmsg: %s\n", .ldap_privates.ldap_der_decode(retv)->debug_string()));    return retv;    }