| 706 | | TCPConnection tc; |
| 707 | | tc.fd=dc->d_socket; |
| 708 | | tc.state=TCPConnection::BYTE0; |
| 709 | | tc.remote=dc->d_remote; |
| 710 | | Utility::gettimeofday(&g_now, 0); // needs to be updated |
| 711 | | tc.startTime=g_now.tv_sec; |
| 712 | | t_fdm->addReadFD(tc.fd, handleRunningTCPQuestion, tc); |
| 713 | | t_fdm->setReadTTD(tc.fd, g_now, g_tcpTimeout); |
| | 708 | TCPConnection tc; |
| | 709 | tc.fd=dc->d_socket; |
| | 710 | tc.state=TCPConnection::BYTE0; |
| | 711 | tc.remote=dc->d_remote; |
| | 712 | Utility::gettimeofday(&g_now, 0); // needs to be updated |
| | 713 | tc.startTime=g_now.tv_sec; |
| | 714 | t_fdm->addReadFD(tc.fd, handleRunningTCPQuestion, tc); |
| | 715 | t_fdm->setReadTTD(tc.fd, g_now, g_tcpTimeout); |
| | 1724 | |
| | 1725 | void parseACLs() |
| | 1726 | { |
| | 1727 | static bool l_initialized; |
| | 1728 | if(l_initialized) { |
| | 1729 | string configname=::arg()["config-dir"]+"/recursor.conf"; |
| | 1730 | cleanSlashes(configname); |
| | 1731 | |
| | 1732 | if(!::arg().preParseFile(configname.c_str(), "allow-from-file")) |
| | 1733 | L<<Logger::Warning<<"Unable to re-parse configuration file '"<<configname<<"'"<<endl; |
| | 1734 | |
| | 1735 | ::arg().preParseFile(configname.c_str(), "allow-from"); |
| | 1736 | } |
| | 1737 | l_initialized = true; |
| | 1738 | if(!::arg()["allow-from-file"].empty()) { |
| | 1739 | string line; |
| | 1740 | NetmaskGroup* allowFrom=new NetmaskGroup; |
| | 1741 | ifstream ifs(::arg()["allow-from-file"].c_str()); |
| | 1742 | if(!ifs) { |
| | 1743 | throw AhuException("Could not open '"+::arg()["allow-from-file"]+"': "+stringerror()); |
| | 1744 | } |
| | 1745 | |
| | 1746 | string::size_type pos; |
| | 1747 | while(getline(ifs,line)) { |
| | 1748 | pos=line.find('#'); |
| | 1749 | if(pos!=string::npos) |
| | 1750 | line.resize(pos); |
| | 1751 | trim(line); |
| | 1752 | if(line.empty()) |
| | 1753 | continue; |
| | 1754 | |
| | 1755 | allowFrom->addMask(line); |
| | 1756 | } |
| | 1757 | g_allowFrom = allowFrom; |
| | 1758 | L<<Logger::Warning<<"Done parsing " << g_allowFrom->size() <<" allow-from ranges from file '"<<::arg()["allow-from-file"]<<"' - overriding 'allow-from' setting"<<endl; |
| | 1759 | } |
| | 1760 | else if(!::arg()["allow-from"].empty()) { |
| | 1761 | NetmaskGroup* allowFrom=new NetmaskGroup; |
| | 1762 | vector<string> ips; |
| | 1763 | stringtok(ips, ::arg()["allow-from"], ", "); |
| | 1764 | L<<Logger::Warning<<"Only allowing queries from: "; |
| | 1765 | for(vector<string>::const_iterator i = ips.begin(); i!= ips.end(); ++i) { |
| | 1766 | allowFrom->addMask(*i); |
| | 1767 | if(i!=ips.begin()) |
| | 1768 | L<<Logger::Warning<<", "; |
| | 1769 | L<<Logger::Warning<<*i; |
| | 1770 | } |
| | 1771 | L<<Logger::Warning<<endl; |
| | 1772 | g_allowFrom = allowFrom; |
| | 1773 | } |
| | 1774 | else if(::arg()["local-address"]!="127.0.0.1" && ::arg().asNum("local-port")==53) |
| | 1775 | L<<Logger::Error<<"WARNING: Allowing queries from all IP addresses - this can be a security risk!"<<endl; |
| | 1776 | } |
| 1757 | | if(!::arg()["allow-from-file"].empty()) { |
| 1758 | | string line; |
| 1759 | | g_allowFrom=new NetmaskGroup; |
| 1760 | | ifstream ifs(::arg()["allow-from-file"].c_str()); |
| 1761 | | if(!ifs) { |
| 1762 | | throw AhuException("Could not open '"+::arg()["allow-from-file"]+"': "+stringerror()); |
| 1763 | | } |
| 1764 | | |
| 1765 | | string::size_type pos; |
| 1766 | | while(getline(ifs,line)) { |
| 1767 | | pos=line.find('#'); |
| 1768 | | if(pos!=string::npos) |
| 1769 | | line.resize(pos); |
| 1770 | | trim(line); |
| 1771 | | if(line.empty()) |
| 1772 | | continue; |
| 1773 | | |
| 1774 | | g_allowFrom->addMask(line); |
| 1775 | | } |
| 1776 | | L<<Logger::Warning<<"Done parsing " << g_allowFrom->size() <<" allow-from ranges from file '"<<::arg()["allow-from-file"]<<"' - overriding 'allow-from' setting"<<endl; |
| 1777 | | } |
| 1778 | | else if(!::arg()["allow-from"].empty()) { |
| 1779 | | g_allowFrom=new NetmaskGroup; |
| 1780 | | vector<string> ips; |
| 1781 | | stringtok(ips, ::arg()["allow-from"], ", "); |
| 1782 | | L<<Logger::Warning<<"Only allowing queries from: "; |
| 1783 | | for(vector<string>::const_iterator i = ips.begin(); i!= ips.end(); ++i) { |
| 1784 | | g_allowFrom->addMask(*i); |
| 1785 | | if(i!=ips.begin()) |
| 1786 | | L<<Logger::Warning<<", "; |
| 1787 | | L<<Logger::Warning<<*i; |
| 1788 | | } |
| 1789 | | L<<Logger::Warning<<endl; |
| 1790 | | } |
| 1791 | | else if(::arg()["local-address"]!="127.0.0.1" && ::arg().asNum("local-port")==53) |
| 1792 | | L<<Logger::Error<<"WARNING: Allowing queries from all IP addresses - this can be a security risk!"<<endl; |
| 1793 | | |
| 1794 | | |
| | 1809 | parseACLs(); |
| | 1810 | |