pike.git / lib / modules / Sql.pmod / tds.pike

version» Context lines:

pike.git/lib/modules/Sql.pmod/tds.pike:247:    int last_packet;    int len;    // NOTE: Network byteorder!!    sscanf(header, "%-1c%-1c%2c", packet_type, last_packet, len);    len -= 8;       busy = !(done = last_packet);       string data = socket->read(len);    if (!data || sizeof(data) < len) { -  tds_error("Failed to read packet data (%d bytes), got %O (%d bytes), %s\n", +  tds_error("Failed to read packet data (%d bytes), got %O (%d bytes), %s.\n",    len, data, sizeof(data||""), strerror(socket->errno()));    }    TDS_WERROR("Read packet with %d bytes.\n%s\n",    sizeof(data), hex_dump(data));    inbuf = inbuf[inpos..] + data;    inpos = 0;    }    -  protected void destroy() +  protected void _destruct()    {    // Return the connection to the idle state.    while (!done) {    inbuf = "";    inpos = 0;    fill_buf();    }    }       string get_raw(int bytes)
pike.git/lib/modules/Sql.pmod/tds.pike:335:       protected void create()    {    if (busy) {    tds_error("Creating InPacket on busy connection!\n");    }    busy = 1;    }    }    -  //static InPacket login_answer; +  //protected InPacket login_answer;       //! An outgoing packet to the TDS server.    class Packet    {    array(string|int) segments = ({});    array(string) strings = ({});    int flags;       protected void create(int|void flags)    { -  this_program::flags = flags; +  this::flags = flags;    }       void put_int8(int i)    {    segments += ({ sprintf("%-8c", i) });    }    void put_int(int i)    {    segments += ({ sprintf("%-4c", i) });    }
pike.git/lib/modules/Sql.pmod/tds.pike:413:    1, 0xb201,    sizeof(domain), sizeof(domain),    32 + sizeof(hostname),    sizeof(hostname), sizeof(hostname),    32,    hostname, domain);    segments += ({ sizeof(strings) });    strings += ({ raw });    }    -  mixed cast(string s) +  protected string cast(string type)    { -  +  if( type!="string" ) return UNDEFINED; +     int trailer_start = flags && 4;    foreach(segments, string|int seg) {    trailer_start += stringp(seg)?sizeof(seg):(seg<0)?8:4;    }    foreach(segments; int i; string|int seg) {    if (intp(seg)) {    if (seg < 0) {    seg = ~seg;    segments[i] = sprintf("%-2c%-2c%-4c",    sizeof(strings[seg]),
pike.git/lib/modules/Sql.pmod/tds.pike:571:    passwd = upper_case((passwd + "\0"*14)[..13]);    string hash =    ecb_encrypt(magic, passwd[..6]) +    ecb_encrypt(magic, passwd[7..]);    return encrypt_answer(hash, nonce);    }       string answer_nt_challenge(string passwd, string nonce)    {    string nt_passwd = string_to_utf16(passwd); - #if constant(Crypto.MD4) -  Crypto.MD4 md4 = Crypto.MD4(); - #else - #if constant(Crypto.md4) -  Crypto.md4 md4 = Crypto.md4(); - #else -  predef::error("MD4 hashes not supported in this Pike.\n"); -  mixed md4; - #endif - #endif -  md4->update(nt_passwd); -  return encrypt_answer(md4->digest() + "\0"*16, nonce); +  return encrypt_answer(Crypto.MD4.hash(nt_passwd) + "\0"*16, nonce);    }       protected void send_auth(string nonce)    {    int out_flag = 0x11;    Packet p = Packet();    p->put_raw("NTLMSSP\0", 8);    p->put_int(3); /* sequence 3 */    p->put_long_raw_string(answer_lan_mgr_challenge(password, nonce));    p->put_long_raw_string(answer_nt_challenge(password, nonce));
pike.git/lib/modules/Sql.pmod/tds.pike:1174:    if (val < 0) {    sgn = "-";    val = -val;    }    int cents = (val + 50)/100;    string res = sprintf("%s%d.%02d", sgn, cents/100, cents%100);    TDS_CONV_WERROR("%O ==> %O\n", raw, res);    return res;    }    case SYBNUMERIC: +  case SYBDECIMAL:    {    string res =    sprintf("%d", array_sscanf(raw[1..],    "%-" + (sizeof(raw)-1) + "c")[0]);       // Move decimal point @[scale] positions.    int scale = info->column_scale;    if (sizeof(res) < scale) {    res = "0." + ("0" * (scale - sizeof(res))) + res;    } else if (sizeof(res) == scale) {    res = "0." + res;    } else if (scale) {    res = res[..sizeof(res)-2] + "." +    res[sizeof(res)-scale..];    }       // Fix the sign. -  if (!res[0]) { +  if (!raw[0]) {    res = "-" + res;    }    TDS_CONV_WERROR("%O (scale: %d) ==> %O\n",    raw, scale, res);    return res;    } -  case SYBDECIMAL: +  case SYBUNIQUE: +  { +  string res = Standards.UUID.UUID(raw)->str(); +  TDS_CONV_WERROR("%O ==> %O\n", raw, res); +  return res; +  } +  case SYBFLTN: +  { +  string res = +  sprintf("%g", @array_sscanf(raw, "%-" + sizeof(raw) + "F")); +  TDS_CONV_WERROR("%O ==> %O\n", raw, res); +  return res; +  }    case SYBREAL:    case SYBFLT8: -  case SYBUNIQUE: +     default:    // FIXME:    TDS_CONV_WERROR("Not yet supported: %d (%O)\n",    info->cardinal_type, raw);    werror("TDS: WARNING: Datatype %d not yet supported. raw: %O\n",    info->cardinal_type, raw);    return raw;    case SYBBIT:    case SYBBITN:    TDS_CONV_WERROR("%O ==> \"%d\"", raw, !!raw[0]);
pike.git/lib/modules/Sql.pmod/tds.pike:1424:    string username, string auth)    {    string domain;    array(string) tmp = username/"\\";    if (sizeof(tmp) > 1) {    // Domain login.    domain = tmp[0];    username = tmp[1..]*"\\";    }    -  this_program::server = server; -  this_program::port = port; -  this_program::database = database; -  this_program::username = username; -  this_program::password = auth; -  this_program::domain = domain; +  this::server = server; +  this::port = port; +  this::database = database; +  this::username = username; +  this::password = auth; +  this::domain = domain;       TDS_WERROR("Connecting to %s:%d with TDS version %d.%d\n",    server, port, major_version, minor_version);       socket = Stdio.File();    if (!socket->connect(server, port)) {    socket = 0;    tds_error("Failed to connect to %s:%d\n", server, port);    }    process_login_tokens(send_login());