pike.git / lib / modules / Protocols.pmod / DNS.pmod

version» Context lines:

pike.git/lib/modules/Protocols.pmod/DNS.pmod:425:    error("Only T_LOC version 1 is supported");    return sprintf("%1c%1c%1c%1c%4c%4c%4c",    0, // Only version that currently exists    encode_T_LOC_tinyfloat(entry->size? entry->size:100.0), //Default is 1M    encode_T_LOC_tinyfloat(entry->h_prec? entry->h_prec:1000*100.0), // Default is 10KM    encode_T_LOC_tinyfloat(entry->v_prec? entry->v_prec:10*100.0), // Default is 10M    entry->lat?(int)(entry->lat*3600000.0)+(2<<30):2<<30, // Default is 2<<30 which is 0.0    entry->long?(int)(entry->long*3600000.0)+(2<<30):2<<30, // Default is 2<<30 which is 0.0    entry->alt?(int)((entry->alt+100000)*100):100000, // Default to 0 WGS84 (which is 100000)    ); +  case T_CAA: +  if (entry->tag == "" || !entry->tag) +  error("An empty tag is not permitted.\n"); +  return sprintf("%c%H%s", entry->flags | (!!entry->critical << 7), +  entry->tag, entry->value || "");    default:    return "";    }    }       protected private string encode_entries(array(mapping) entries, int pos,    mapping(string:int) comp)    {    string res="";    foreach(entries, mapping entry) {
pike.git/lib/modules/Protocols.pmod/DNS.pmod:690:    //! When receiving decoded DNS data from a client, txta is    //! the array of all strings in the record. When sending    //! multiple strings in a TXT record in a server, please    //! supply an array as "txt" containing the strings, txta    //! will be ignored.    //! @endmapping    //! @value T_SPF    //! @mapping    //! @member string "spf"    //! @endmapping +  //! @value T_CAA +  //! @mapping +  //! @member int "critical" +  //! Sets the critical bit of the flag field. +  //! @member int "flags" +  //! +  //! @member string "tag" +  //! Cannot be empty. +  //! @member string "value" +  //! @endmapping    //! @endint    //! @endarray    array decode_entries(string s,int num, array(int) next)    {    array(string) ret=({});    for(int e=0;e<num && next[0]<sizeof(s);e++)    {    mapping m=([]);    m->name=decode_domain(s,next);    sscanf(s[next[0]..next[0]+10],
pike.git/lib/modules/Protocols.pmod/DNS.pmod:802:    while (tlen < m->len) {    m->txta += ({ decode_string(s, next) });    tlen += sizeof(m->txta[-1]) + 1;    }    m->txt = m->txta[0];    }    break;    case T_SPF:    m->spf = decode_string(s, next);    break; +  case T_CAA: +  { +  string tag; +  +  m->critical = !!((m->flags = decode_byte(s, next)) & 0x80); +  tag = m->tag = decode_string(s, next); +  m->value = s[next[0]..next[0] + m->len - 3 - sizeof(tag)];    } -  +  break; +  }       next[0]=tmp+m->len;    ret+=({m});    }    return ret;    }       mapping decode_res(string s)    {    mapping m=([]);
pike.git/lib/modules/Protocols.pmod/DNS.pmod:1023:    }       //! Handle a query response (stub).    //!    //! Overload this function to handle responses to possible recursive queries.    protected void handle_response(mapping r, mapping m, Stdio.UDP|object udp)    {    // This is a stub intended to simplify servers which allow recursion    }    +  //! Report a failure to decode a DNS request. +  //! +  //! The default implementation writes a backtrace to stderr. This +  //! method exists so that derived servers can replace it with more +  //! appropriate error handling for their environment. +  protected void report_decode_error(mixed err, mapping m, Stdio.UDP|object udp) +  { +  werror("DNS: Failed to read %s packet.\n%s\n", +  udp->tcp_connection ? "TCP" : "UDP", +  describe_backtrace(err)); +  } +  +  //! Respond to a query that cannot be decoded. +  //! +  //! This method exists so that servers can override the default behaviour. +  protected void handle_decode_error(mapping err, mapping m, +  Stdio.UDP|object udp) +  { +  if(m && m->data && sizeof(m->data)>=2) +  send_reply((["rcode":1]), +  mkmapping(({"id"}), array_sscanf(m->data, "%2c")), m, udp); +  } +     //! Low-level DNS-data receiver.    //!    //! This function receives the raw DNS-data from the @[Stdio.UDP] socket    //! or TCP connection object @[udp], decodes it, and dispatches the decoded    //! DNS request to @[handle_query()] and @[handle_response()].    protected void rec_data(mapping m, Stdio.UDP|object udp)    {    mixed err;    mapping q;    if (err = catch {    q=decode_res(m->data);    }) { -  werror("DNS: Failed to read %s packet.\n%s\n", -  udp->tcp_connection ? "TCP" : "UDP", -  describe_backtrace(err)); -  if(m && m->data && sizeof(m->data)>=2) -  send_reply((["rcode":1]), -  mkmapping(({"id"}), array_sscanf(m->data, "%2c")), m, udp); +  report_decode_error(err, m, udp); +  handle_decode_error(err, m, udp);    }    else if(q->qr)    handle_response(q, m, udp);    else    handle_query(q, m, udp);    }       protected void send_reply(mapping r, mapping q, mapping m,    Stdio.UDP|object con);    -  protected void destroy() +  protected void _destruct()    {    if(sizeof(ports))    {    foreach(ports;; object port)    destruct(port);    }    }   }      //! Base class for implementing a Domain Name Service (DNS) server operating
pike.git/lib/modules/Protocols.pmod/DNS.pmod:1213:    if (write_ready) {    int written = con->write(out_buffer);    out_buffer = out_buffer[written..];    write_ready = 0;    }       remove_call_out(c_id);    c_id = call_out(destruct, 120, this);    }    -  void destroy() { +  protected void _destruct() {    if (con) con->close();    destruct(con);    m_delete(connections, this);    }    }       protected int accept(Stdio.Port port) {    connections[Connection(port->accept())] = 1;    }   
pike.git/lib/modules/Protocols.pmod/DNS.pmod:1279:    port = Stdio.Port(args[i+1], accept);    }       port->set_id(port);    // Port objects are stored for destruction when the server    // object is destroyed.    ports += ({ port });    }    }    -  protected void destroy() +  protected void _destruct()    {    foreach (connections; Connection con;) {    destruct(con);    }    -  ::destroy(); +  ::_destruct();    }   }      //! This is both a @[server] and @[tcp_server].   class dual_server {    inherit server : UDP;    inherit tcp_server : TCP;       protected void send_reply(mapping r, mapping q, mapping m,    Connection|Stdio.UDP con) {
pike.git/lib/modules/Protocols.pmod/DNS.pmod:1315:    con->send(m->ip, m->port, rpl);    } else    con->send(rpl);    }       protected void create(int|string|void arg1, string|int ... args)    {    ::create(arg1, @args);    }    -  protected void destroy() +  protected void _destruct()    { -  ::destroy(); +  ::_destruct();    }   }         #define RETRIES 12   #define RETRY_DELAY 5      //! Synchronous DNS client.   class client   {
pike.git/lib/modules/Protocols.pmod/DNS.pmod:1341: Inside #if defined(__NT__)
   array(string) get_tcpip_param(string val, void|string fallbackvalue)    {    array(string) res = ({});    foreach(({    "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters",    "SYSTEM\\CurrentControlSet\\Services\\Tcpip6\\Parameters",    "SYSTEM\\CurrentControlSet\\Services\\VxD\\MSTCP"    }),string key)    {    catch { -  res += ({ RegGetValue(HKEY_LOCAL_MACHINE, key, val) }); +  res += ({ System.RegGetValue(HKEY_LOCAL_MACHINE, key, val) });    };    }    - #if constant(RegGetKeyNames) -  /* Catch if RegGetKeyNames() doesn't find the directory. */ + #if constant(System.RegGetKeyNames) +  /* Catch if System.RegGetKeyNames() doesn't find the directory. */    catch { -  foreach(RegGetKeyNames(HKEY_LOCAL_MACHINE, +  foreach(System.RegGetKeyNames(HKEY_LOCAL_MACHINE,    "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\"    "Parameters\\Interfaces"), string key)    {    catch { -  res += ({ RegGetValue(HKEY_LOCAL_MACHINE, +  res += ({ System.RegGetValue(HKEY_LOCAL_MACHINE,    "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\"    "Parameters\\Interfaces\\" + key, val) });    };    } -  foreach(RegGetKeyNames(HKEY_LOCAL_MACHINE, +  foreach(System.RegGetKeyNames(HKEY_LOCAL_MACHINE,    "SYSTEM\\CurrentControlSet\\Services\\Tcpip6\\"    "Parameters\\Interfaces"), string key)    {    catch { -  res += ({ RegGetValue(HKEY_LOCAL_MACHINE, +  res += ({ System.RegGetValue(HKEY_LOCAL_MACHINE,    "SYSTEM\\CurrentControlSet\\Services\\Tcpip6\\"    "Parameters\\Interfaces\\" + key, val) });    };    }    };   #endif    res -= ({ UNDEFINED });    return sizeof(res) ? res : ({ fallbackvalue });    }   
pike.git/lib/modules/Protocols.pmod/DNS.pmod:1639:    // Restore blocking state for udp->send() on retry.    udp->set_blocking();    }    // Failure.    return 0;    }       protected mapping low_gethostbyname(string s, int type)    {    mapping m; -  if(sizeof(domains) && s[-1] != '.' && sizeof(s/".") < 3) { +  if(sizeof(domains) && sizeof(s) && s[-1] != '.' && sizeof(s/".") < 3) {    mapping m = do_sync_query(mkquery(s, C_IN, type));    if(!m || !m->an || !sizeof(m->an))    foreach(domains, string domain)    {    m = do_sync_query(mkquery(s+"."+domain, C_IN, type));    if(m && m->an && sizeof(m->an))    break;    }    return m;    } else {