Changeset b9498ef in nscp


Ignore:
Timestamp:
08/15/11 18:40:17 (21 months ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2
Children:
fe75eff
Parents:
2c95d22
Message:

2011-08-15 MickeM

  • Readded allowed hosts function
  • Moved default socket options to /settings/default/socket
  • Added more default socket options
Files:
2 added
21 edited

Legend:

Unmodified
Added
Removed
  • changelog

    r2c95d22 rb9498ef  
    33 * Fix configuration GUI (low priority) 
    44 * Add API for rehashing the daemon (or implement it the API is there but does nothing) 
    5  * Improved socket performance (would be nice if we could be used as a "hub") 
    65 * Fixa dependonservice LanManWorkStation (old win) 
    76 * Fix RtlStringFromGUID problem on NT4 
     7 
     82011-08-15 MickeM 
     9 * Readded allowed hosts function 
     10 * Moved default socket options to /settings/default/socket 
     11 * Added more default socket options 
    812 
    9132011-08-14 MickeM 
  • include/NSCAPI.h

    r2c95d22 rb9498ef  
    116116    std::wstring msg_; 
    117117    nscapi_exception(std::wstring msg) : msg_(msg) {} 
     118 
     119 
     120    virtual ~nscapi_exception() throw() {} 
    118121    std::string what() { 
    119122      return utf8::cvt<std::string>(msg_); 
  • include/check_nt/server/server.cpp

    re1d9a58 rb9498ef  
    1414 
    1515 
    16     const int server::connection_info::backlog_default = 0; 
    17  
    18     server::server(connection_info info) 
    19       : thread_pool_size_(info.thread_pool_size) 
     16    server::server(connection_info infoo) 
     17      : info_(infoo) 
    2018      , acceptor_(io_service_) 
    2119      , accept_strand_(io_service_) 
    22       , request_handler_(info.request_handler) // nrpe::length::get_payload_length()) 
     20      , request_handler_(infoo.request_handler) // nrpe::length::get_payload_length()) 
    2321      , context_(io_service_, boost::asio::ssl::context::sslv23) 
    24       , use_ssl_(info.use_ssl) 
    2522    { 
    2623      if (!request_handler_) 
     
    2926      ip::tcp::resolver resolver(io_service_); 
    3027      ip::tcp::resolver::iterator endpoint_iterator; 
    31       if (info.address.empty()) { 
    32         endpoint_iterator = resolver.resolve(ip::tcp::resolver::query(info.get_port())); 
     28      if (info_.address.empty()) { 
     29        endpoint_iterator = resolver.resolve(ip::tcp::resolver::query(info_.get_port())); 
    3330      } else { 
    34         endpoint_iterator = resolver.resolve(ip::tcp::resolver::query(info.get_address(), info.get_port())); 
     31        endpoint_iterator = resolver.resolve(ip::tcp::resolver::query(info_.get_address(), info_.get_port())); 
    3532      } 
    3633      ip::tcp::resolver::iterator end; 
    3734      if (endpoint_iterator == end) { 
    38         request_handler_->log_error(__FILE__, __LINE__, std::wstring(_T("Failed to lookup: ")) + info.get_endpoint_str()); 
     35        request_handler_->log_error(__FILE__, __LINE__, std::wstring(_T("Failed to lookup: ")) + info_.get_endpoint_str()); 
    3936        return; 
    4037      } 
    41       if (info.use_ssl) { 
     38      if (info_.use_ssl) { 
    4239        SSL_CTX_set_cipher_list(context_.impl(), "ADH"); 
    43         request_handler_->log_debug(__FILE__, __LINE__, _T("Using cert: ") + to_wstring(info.certificate)); 
    44         context_.use_tmp_dh_file(to_string(info.certificate)); 
     40        request_handler_->log_debug(__FILE__, __LINE__, _T("Using cert: ") + to_wstring(info_.certificate)); 
     41        context_.use_tmp_dh_file(to_string(info_.certificate)); 
    4542        context_.set_verify_mode(boost::asio::ssl::context::verify_none); 
    4643      } 
    4744 
    48       new_connection_.reset(check_nt::server::factories::create(io_service_, context_, request_handler_, use_ssl_)); 
     45      new_connection_.reset(check_nt::server::factories::create(io_service_, context_, request_handler_, info_.use_ssl)); 
    4946 
    5047      ip::tcp::endpoint endpoint = *endpoint_iterator; 
    5148      acceptor_.open(endpoint.protocol()); 
    5249      acceptor_.set_option(ip::tcp::acceptor::reuse_address(true)); 
    53       request_handler_->log_debug(__FILE__, __LINE__, _T("Attempting to bind to: ") + info.get_endpoint_str()); 
     50      request_handler_->log_debug(__FILE__, __LINE__, _T("Attempting to bind to: ") + info_.get_endpoint_str()); 
    5451      acceptor_.bind(endpoint); 
    55       if (info.back_log == connection_info::backlog_default) 
     52      if (info_.back_log == connection_info::backlog_default) 
    5653        acceptor_.listen(); 
    5754      else 
    58         acceptor_.listen(info.back_log); 
     55        acceptor_.listen(info_.back_log); 
    5956 
    6057      acceptor_.async_accept(new_connection_->socket(), 
     
    6360          ) 
    6461        ); 
    65       request_handler_->log_debug(__FILE__, __LINE__, _T("Bound to: ") + info.get_endpoint_str()); 
     62      request_handler_->log_debug(__FILE__, __LINE__, _T("Bound to: ") + info_.get_endpoint_str()); 
    6663 
    6764      //io_service_.post(boost::bind(&Server::startAccept, this)); 
     
    7370    void server::start() { 
    7471      // Create a pool of threads to run all of the io_services. 
    75       for (std::size_t i = 0; i < thread_pool_size_; ++i) { 
     72      for (std::size_t i = 0; i < info_.thread_pool_size; ++i) { 
    7673        boost::shared_ptr<boost::thread> thread( 
    7774          new boost::thread( boost::bind(&boost::asio::io_service::run, &io_service_) )); 
    7875        threads_.push_back(thread); 
    7976      } 
    80       request_handler_->log_debug(__FILE__, __LINE__, _T("Thredpool containes: ") + to_wstring(thread_pool_size_)); 
     77      request_handler_->log_debug(__FILE__, __LINE__, _T("Thredpool containes: ") + to_wstring(info_.thread_pool_size)); 
    8178 
    8279      // Wait for all threads in the pool to exit. 
     
    9390    void server::handle_accept(const boost::system::error_code& e) { 
    9491      if (!e) { 
     92        std::list<std::string> errors; 
    9593        std::string s = new_connection_->socket().remote_endpoint().address().to_string(); 
    96         request_handler_->log_debug(__FILE__, __LINE__, _T("Accepting connection from: ") + to_wstring(s)); 
     94        if (info_.allowed_hosts.is_allowed(new_connection_->socket().remote_endpoint().address().to_v4().to_ulong(), errors)) { 
     95          request_handler_->log_debug(__FILE__, __LINE__, _T("Accepting connection from: ") + to_wstring(s)); 
     96          new_connection_->start(); 
     97        } else { 
     98          BOOST_FOREACH(const std::string &e, errors) { 
     99            request_handler_->log_error(__FILE__, __LINE__, utf8::cvt<std::wstring>(e)); 
     100          } 
     101          request_handler_->log_error(__FILE__, __LINE__, _T("Rejcted connection from: ") + to_wstring(s)); 
     102          new_connection_->stop(); 
     103        } 
    97104 
    98         new_connection_->start(); 
    99         new_connection_.reset(check_nt::server::factories::create(io_service_, context_, request_handler_, use_ssl_)); 
     105        new_connection_.reset(check_nt::server::factories::create(io_service_, context_, request_handler_, info_.use_ssl)); 
    100106 
    101107        acceptor_.async_accept(new_connection_->socket(), 
  • include/check_nt/server/server.hpp

    re1d9a58 rb9498ef  
    11#pragma once 
    22 
    3 #include <boost/asio.hpp> 
    43#include <string> 
    54#include <vector> 
     5 
    66#include <boost/noncopyable.hpp> 
    77#include <boost/shared_ptr.hpp> 
    88#include <boost/thread.hpp> 
     9#include <boost/asio.hpp> 
     10 
     11#include <socket/socket_helpers.hpp> 
    912#include <check_nt/server/connection.hpp> 
    1013#include "handler.hpp" 
     
    3538    class server : private boost::noncopyable { 
    3639    public: 
    37       struct connection_info { 
    38         static const int backlog_default; 
    39         connection_info(boost::shared_ptr<check_nt::server::handler> request_handler_) : request_handler(request_handler_), back_log(backlog_default) {} 
    40         std::string address; 
    41         unsigned int port; 
    42         std::string get_port() { return to_string(port); } 
    43         std::string get_address() { return to_string(address); } 
    44         unsigned int thread_pool_size; 
    45         int back_log; 
    46         bool use_ssl; 
    47         bool allow_args; 
    48         bool allow_nasty; 
    49         unsigned int timeout; 
     40      struct connection_info  : public socket_helpers::connection_info { 
     41        connection_info(boost::shared_ptr<check_nt::server::handler> request_handler_) : request_handler(request_handler_) {} 
     42        connection_info(const connection_info &other)  
     43          : socket_helpers::connection_info(other) 
     44          , request_handler(other.request_handler) 
     45        {} 
     46        connection_info& operator=(const connection_info &other) { 
     47          socket_helpers::connection_info::operator=(other); 
     48          request_handler = other.request_handler; 
     49          return *this; 
     50        } 
     51 
    5052        boost::shared_ptr<check_nt::server::handler> request_handler; 
    51         std::wstring certificate; 
    52         std::wstring get_endpoint_str() { 
    53           return to_wstring(address) + _T(":") + to_wstring(port); 
    54         } 
    5553      }; 
    5654 
     
    7371      void handle_accept(const boost::system::error_code& e); 
    7472 
    75       /// The number of threads that will call io_service::run(). 
    76       std::size_t thread_pool_size_; 
    77  
    7873      /// The io_service used to perform asynchronous operations. 
    7974      boost::asio::io_service io_service_; 
     
    9388      boost::asio::ssl::context context_; 
    9489 
    95       bool use_ssl_; 
    96  
    9790      /// The strand for handleTcpAccept(), handleSslAccept() and handleStop() 
    9891      boost::asio::strand accept_strand_; 
     92 
     93      connection_info info_; 
    9994 
    10095    }; 
  • include/nrpe/client/socket.hpp

    r65a2940 rb9498ef  
    33#include <boost/shared_ptr.hpp> 
    44 
    5 #include <socket_helpers.hpp> 
     5#include <socket/socket_helpers.hpp> 
    66#include <nsca/nsca_packet.hpp> 
    77 
     
    6969    } 
    7070    virtual void read_with_timeout(std::vector<char> &buf, boost::posix_time::seconds timeout) { 
    71       socketHelpers::io::read_with_timeout(*socket_, get_socket(), boost::asio::buffer(buf), timeout); 
     71      socket_helpers::io::read_with_timeout(*socket_, get_socket(), boost::asio::buffer(buf), timeout); 
    7272    } 
    7373    virtual void write_with_timeout(std::vector<char> &buf, boost::posix_time::seconds timeout) { 
    74       socketHelpers::io::write_with_timeout(*socket_, get_socket(), boost::asio::buffer(buf), timeout); 
     74      socket_helpers::io::write_with_timeout(*socket_, get_socket(), boost::asio::buffer(buf), timeout); 
    7575    } 
    7676  }; 
     
    106106 
    107107    virtual void write_with_timeout(std::vector<char> &buf, boost::posix_time::seconds timeout) { 
    108       socketHelpers::io::write_with_timeout(*ssl_socket_, get_socket(), boost::asio::buffer(buf), timeout); 
     108      socket_helpers::io::write_with_timeout(*ssl_socket_, get_socket(), boost::asio::buffer(buf), timeout); 
    109109    } 
    110110 
    111111    virtual void read_with_timeout(std::vector<char> &buf, boost::posix_time::seconds timeout) { 
    112       socketHelpers::io::read_with_timeout(*ssl_socket_, get_socket(), boost::asio::buffer(buf), timeout); 
     112      socket_helpers::io::read_with_timeout(*ssl_socket_, get_socket(), boost::asio::buffer(buf), timeout); 
    113113    } 
    114114  }; 
  • include/nrpe/server/server.cpp

    r1f24a1c rb9498ef  
    1414 
    1515 
    16     const int server::connection_info::backlog_default = 0; 
    17  
    1816    server::server(connection_info info) 
    19       : thread_pool_size_(info.thread_pool_size) 
    20       , acceptor_(io_service_) 
     17      : acceptor_(io_service_) 
    2118      , accept_strand_(io_service_) 
    2219      , request_handler_(info.request_handler) // nrpe::length::get_payload_length()) 
    2320      , context_(io_service_, boost::asio::ssl::context::sslv23) 
    24       , use_ssl_(info.use_ssl) 
     21      , info_(info) 
    2522    { 
    2623      if (!request_handler_) 
     
    2926      ip::tcp::resolver resolver(io_service_); 
    3027      ip::tcp::resolver::iterator endpoint_iterator; 
    31       if (info.address.empty()) { 
    32         endpoint_iterator = resolver.resolve(ip::tcp::resolver::query(info.get_port())); 
     28      if (info_.address.empty()) { 
     29        endpoint_iterator = resolver.resolve(ip::tcp::resolver::query(info_.get_port())); 
    3330      } else { 
    34         endpoint_iterator = resolver.resolve(ip::tcp::resolver::query(info.get_address(), info.get_port())); 
     31        endpoint_iterator = resolver.resolve(ip::tcp::resolver::query(info_.get_address(), info_.get_port())); 
    3532      } 
    3633      ip::tcp::resolver::iterator end; 
    3734      if (endpoint_iterator == end) { 
    38         request_handler_->log_error(__FILE__, __LINE__, std::wstring(_T("Failed to lookup: ")) + info.get_endpoint_str()); 
     35        request_handler_->log_error(__FILE__, __LINE__, std::wstring(_T("Failed to lookup: ")) + info_.get_endpoint_str()); 
    3936        return; 
    4037      } 
    41       if (info.use_ssl) { 
     38      if (info_.use_ssl) { 
    4239        SSL_CTX_set_cipher_list(context_.impl(), "ADH"); 
    43         request_handler_->log_debug(__FILE__, __LINE__, _T("Using cert: ") + to_wstring(info.certificate)); 
    44         context_.use_tmp_dh_file(to_string(info.certificate)); 
     40        request_handler_->log_debug(__FILE__, __LINE__, _T("Using cert: ") + to_wstring(info_.certificate)); 
     41        context_.use_tmp_dh_file(to_string(info_.certificate)); 
    4542        context_.set_verify_mode(boost::asio::ssl::context::verify_none); 
    4643      } 
    4744 
    48       new_connection_.reset(nrpe::server::factories::create(io_service_, context_, request_handler_, use_ssl_)); 
     45      new_connection_.reset(nrpe::server::factories::create(io_service_, context_, request_handler_, info_.use_ssl)); 
    4946 
    5047      ip::tcp::endpoint endpoint = *endpoint_iterator; 
    5148      acceptor_.open(endpoint.protocol()); 
    5249      acceptor_.set_option(ip::tcp::acceptor::reuse_address(true)); 
    53       request_handler_->log_debug(__FILE__, __LINE__, _T("Attempting to bind to: ") + info.get_endpoint_str()); 
     50      request_handler_->log_debug(__FILE__, __LINE__, _T("Attempting to bind to: ") + info_.get_endpoint_str()); 
    5451      acceptor_.bind(endpoint); 
    55       if (info.back_log == connection_info::backlog_default) 
     52      if (info_.back_log == connection_info::backlog_default) 
    5653        acceptor_.listen(); 
    5754      else 
    58         acceptor_.listen(info.back_log); 
     55        acceptor_.listen(info_.back_log); 
    5956 
    6057      acceptor_.async_accept(new_connection_->socket(), 
     
    6360          ) 
    6461        ); 
    65       request_handler_->log_debug(__FILE__, __LINE__, _T("Bound to: ") + info.get_endpoint_str()); 
     62      request_handler_->log_debug(__FILE__, __LINE__, _T("Bound to: ") + info_.get_endpoint_str()); 
    6663 
    6764      //io_service_.post(boost::bind(&Server::startAccept, this)); 
     
    7370    void server::start() { 
    7471      // Create a pool of threads to run all of the io_services. 
    75       for (std::size_t i = 0; i < thread_pool_size_; ++i) { 
     72      for (std::size_t i = 0; i < info_.thread_pool_size; ++i) { 
    7673        boost::shared_ptr<boost::thread> thread( 
    7774          new boost::thread( boost::bind(&boost::asio::io_service::run, &io_service_) )); 
    7875        threads_.push_back(thread); 
    7976      } 
    80       request_handler_->log_debug(__FILE__, __LINE__, _T("Thredpool containes: ") + to_wstring(thread_pool_size_)); 
     77      request_handler_->log_debug(__FILE__, __LINE__, _T("Thredpool containes: ") + to_wstring(info_.thread_pool_size)); 
    8178 
    8279      // Wait for all threads in the pool to exit. 
     
    9390    void server::handle_accept(const boost::system::error_code& e) { 
    9491      if (!e) { 
     92        std::list<std::string> errors; 
    9593        std::string s = new_connection_->socket().remote_endpoint().address().to_string(); 
    96         request_handler_->log_debug(__FILE__, __LINE__, _T("Accepting connection from: ") + to_wstring(s)); 
     94        if (info_.allowed_hosts.is_allowed(new_connection_->socket().remote_endpoint().address().to_v4().to_ulong(), errors)) { 
     95          request_handler_->log_debug(__FILE__, __LINE__, _T("Accepting connection from: ") + to_wstring(s)); 
     96          new_connection_->start(); 
     97        } else { 
     98          BOOST_FOREACH(const std::string &e, errors) { 
     99            request_handler_->log_error(__FILE__, __LINE__, utf8::cvt<std::wstring>(e)); 
     100          } 
     101          request_handler_->log_error(__FILE__, __LINE__, _T("Rejcted connection from: ") + to_wstring(s)); 
     102          new_connection_->stop(); 
     103        } 
    97104 
    98         new_connection_->start(); 
    99         new_connection_.reset(nrpe::server::factories::create(io_service_, context_, request_handler_, use_ssl_)); 
     105        new_connection_.reset(nrpe::server::factories::create(io_service_, context_, request_handler_, info_.use_ssl)); 
    100106 
    101107        acceptor_.async_accept(new_connection_->socket(), 
  • include/nrpe/server/server.hpp

    r497b779 rb9498ef  
    44#include <string> 
    55#include <vector> 
     6 
    67#include <boost/noncopyable.hpp> 
    78#include <boost/shared_ptr.hpp> 
    89#include <boost/thread.hpp> 
     10 
     11#include <socket/socket_helpers.hpp> 
    912#include <nrpe/server/connection.hpp> 
     13 
    1014#include "handler.hpp" 
    1115 
     
    3337    }; 
    3438 
    35     class server : private boost::noncopyable { 
     39    class server : boost::noncopyable { 
    3640    public: 
    37       struct connection_info { 
    38         static const int backlog_default; 
    39         connection_info(boost::shared_ptr<nrpe::server::handler> request_handler_) : request_handler(request_handler_), back_log(backlog_default) {} 
    40         std::string address; 
    41         unsigned int port; 
    42         std::string get_port() { return to_string(port); } 
    43         std::string get_address() { return to_string(address); } 
    44         unsigned int thread_pool_size; 
    45         int back_log; 
    46         bool use_ssl; 
     41      struct connection_info : public socket_helpers::connection_info { 
     42        connection_info(boost::shared_ptr<nrpe::server::handler> request_handler) : request_handler(request_handler) {} 
     43        connection_info(const connection_info &other)  
     44          : socket_helpers::connection_info(other) 
     45          , allow_args(other.allow_args) 
     46          , allow_nasty(other.allow_nasty) 
     47          , request_handler(other.request_handler) 
     48        {} 
     49        connection_info& operator=(const connection_info &other) { 
     50          socket_helpers::connection_info::operator=(other); 
     51          allow_args = other.allow_args; 
     52          allow_nasty = other.allow_nasty; 
     53          request_handler = other.request_handler; 
     54          return *this; 
     55        } 
    4756        bool allow_args; 
    4857        bool allow_nasty; 
    49         unsigned int timeout; 
    5058        boost::shared_ptr<nrpe::server::handler> request_handler; 
    51         std::wstring certificate; 
    52         std::wstring get_endpoint_str() { 
    53           return to_wstring(address) + _T(":") + to_wstring(port); 
    54         } 
    5559      }; 
    5660 
     
    7478 
    7579      /// The number of threads that will call io_service::run(). 
    76       std::size_t thread_pool_size_; 
     80      //std::size_t thread_pool_size_; 
    7781 
    7882      /// The io_service used to perform asynchronous operations. 
     
    9397      boost::asio::ssl::context context_; 
    9498 
    95       bool use_ssl_; 
     99      //bool use_ssl_; 
    96100 
    97101      /// The strand for handleTcpAccept(), handleSslAccept() and handleStop() 
    98102      boost::asio::strand accept_strand_; 
     103      connection_info info_; 
    99104 
    100105    }; 
  • include/nsca/nsca_socket.hpp

    rd66ccee rb9498ef  
    33#include <boost/shared_ptr.hpp> 
    44 
    5 #include <socket_helpers.hpp> 
     5#include <socket/socket_helpers.hpp> 
    66 
    77#include <nsca/nsca_packet.hpp> 
     
    6767    } 
    6868    virtual void read_with_timeout(std::vector<char> &buf, boost::posix_time::seconds timeout) { 
    69       socketHelpers::io::read_with_timeout(*socket_, get_socket(), boost::asio::buffer(buf), timeout); 
     69      socket_helpers::io::read_with_timeout(*socket_, get_socket(), boost::asio::buffer(buf), timeout); 
    7070    } 
    7171    virtual void write_with_timeout(std::string &buf, boost::posix_time::seconds timeout) { 
    72       socketHelpers::io::write_with_timeout(*socket_, get_socket(), boost::asio::buffer(buf), timeout); 
     72      socket_helpers::io::write_with_timeout(*socket_, get_socket(), boost::asio::buffer(buf), timeout); 
    7373    } 
    7474    /* 
     
    107107 
    108108    virtual void write_with_timeout(std::vector<char> &buf, boost::posix_time::seconds timeout) { 
    109       socketHelpers::io::write_with_timeout(*ssl_socket_, get_socket(), boost::asio::buffer(buf), timeout); 
     109      socket_helpers::io::write_with_timeout(*ssl_socket_, get_socket(), boost::asio::buffer(buf), timeout); 
    110110    } 
    111111 
    112112    virtual void read_with_timeout(std::vector<char> &buf, boost::posix_time::seconds timeout) { 
    113       socketHelpers::io::read_with_timeout(*ssl_socket_, get_socket(), boost::asio::buffer(buf), timeout); 
     113      socket_helpers::io::read_with_timeout(*ssl_socket_, get_socket(), boost::asio::buffer(buf), timeout); 
    114114    } 
    115115  }; 
  • include/socket_helpers.hpp

    r04ef932 rb9498ef  
    44#include <boost/bind.hpp> 
    55#include <boost/optional.hpp> 
    6  
    7 namespace socketHelpers { 
    8   class allowedHosts { 
    9     struct host_record { 
    10       host_record() : mask(0) {} 
    11       host_record(std::wstring r) : mask(0), record(r) {} 
    12       std::wstring record; 
    13       std::wstring host; 
    14       u_long in_addr; 
    15       unsigned long mask; 
    16     }; 
    17   public: 
    18     typedef std::list<host_record> host_list;  
    19     typedef std::list<std::wstring> string_list;  
    20   private: 
    21     host_list allowed_list_; 
    22     string_list lookup_list; 
    23     bool cachedAddresses_; 
    24   public: 
    25     allowedHosts() : cachedAddresses_(true) {} 
    26  
    27     unsigned int lookupMask(std::wstring mask) { 
    28       unsigned int masklen = 32; 
    29       if (!mask.empty()) { 
    30         std::wstring::size_type pos = mask.find_first_of(_T("0123456789")); 
    31         if (pos != std::wstring::npos) { 
    32           masklen = strEx::stoi(mask.substr(pos)); 
    33         } 
    34       } 
    35       if (masklen > 32) 
    36         masklen = 32; 
    37       return (~((unsigned int)0))>>(32-masklen); 
    38     } 
    39     void lookupList(boost::asio::io_service& io_service) { 
    40       allowed_list_.clear(); 
    41       for (string_list::iterator it = lookup_list.begin();it!=lookup_list.end();++it) { 
    42         std::wstring host = (*it); 
    43         host_record tmp_record; 
    44         if (!host.empty()) { 
    45           try { 
    46             std::wstring::size_type pos = host.find('/'); 
    47             if (pos == std::wstring::npos) { 
    48               tmp_record.host = host; 
    49               tmp_record.mask = lookupMask(_T("")); 
    50             } else { 
    51               tmp_record.host = host.substr(0, pos); 
    52               tmp_record.mask = lookupMask(host.substr(pos)); 
    53             } 
    54             boost::asio::ip::tcp::resolver resolver(io_service); 
    55             boost::asio::ip::tcp::resolver::query query(utf8::cvt<std::string>(tmp_record.host), ""); 
    56             boost::asio::ip::tcp::resolver::iterator endpoint_iterator = resolver.resolve(query); 
    57             boost::asio::ip::tcp::resolver::iterator end; 
    58             for (;endpoint_iterator != end; ++endpoint_iterator) { 
    59               tmp_record.in_addr = endpoint_iterator->endpoint().address().to_v4().to_ulong(); 
    60               tmp_record.host = utf8::cvt<std::wstring>(endpoint_iterator->endpoint().address().to_string()); 
    61               allowed_list_.push_back(tmp_record); 
    62             } 
    63             /* 
    64             std::cerr << "Added: "  
    65               + simpleSocket::Socket::inet_ntoa((*it).in_addr) 
    66               + " with mask " 
    67               + simpleSocket::Socket::inet_ntoa((*it).mask) 
    68               + " from " 
    69               + (*it).record << 
    70               std::endl; 
    71               */ 
    72           } catch (std::exception &e) { 
    73             std::cerr << "Filed to lookup host: " << e.what() << std::endl; 
    74           } catch (...) { 
    75             std::wcerr << _T("Filed to lookup host: ") << std::endl; 
    76           } 
    77         } 
    78       } 
    79     } 
    80  
    81     void setAllowedHosts(const std::list<std::wstring> list, bool cachedAddresses, boost::asio::io_service& io_service) { 
    82       for (std::list<std::wstring>::const_iterator it = list.begin(); it != list.end(); ++it) { 
    83         if (!(*it).empty()) 
    84           lookup_list.push_back(*it); 
    85       } 
    86       cachedAddresses_ = cachedAddresses; 
    87       lookupList(io_service); 
    88     } 
    89     bool matchHost(host_record allowed, struct in_addr remote) { 
    90       /* 
    91       if ((allowed.in_addr&allowed.mask)==(remote.S_un.S_addr&allowed.mask)) { 
    92         std::cerr << "Matched: " << simpleSocket::Socket::inet_ntoa(allowed.in_addr)  << " with " <<  
    93           simpleSocket::Socket::inet_ntoa(remote.S_un.S_addr) << std::endl; 
    94       } 
    95       */ 
    96       return true; //((allowed.in_addr&allowed.mask)==(remote.S_un.S_addr&allowed.mask)); 
    97     } 
    98     bool inAllowedHosts(boost::asio::io_service& io_service, struct in_addr remote) { 
    99       if (lookup_list.empty()) 
    100         return true; 
    101       if (!cachedAddresses_) { 
    102         lookupList(io_service); 
    103       } 
    104       for (host_list::const_iterator cit = allowed_list_.begin();cit!=allowed_list_.end();++cit) { 
    105         if (matchHost((*cit), remote)) 
    106           return true; 
    107       } 
    108       return false; 
    109     } 
    110     std::wstring to_string() { 
    111       std::wstring ret; 
    112       BOOST_FOREACH(host_record r, allowed_list_) { 
    113         if (!ret.empty()) ret += _T(", "); 
    114         ret += r.host; 
    115       } 
    116       return ret; 
    117     } 
    118   }; 
    119  
    120   namespace io { 
    121     void set_result(boost::optional<boost::system::error_code>* a, boost::system::error_code b) { 
    122       a->reset(b); 
    123     }  
    124  
    125     template <typename AsyncReadStream, typename RawSocket, typename MutableBufferSequence> 
    126     void read_with_timeout(AsyncReadStream& sock, RawSocket& rawSocket, const MutableBufferSequence& buffers, boost::posix_time::time_duration duration) { 
    127       boost::optional<boost::system::error_code> timer_result; 
    128       boost::asio::deadline_timer timer(sock.get_io_service()); 
    129       timer.expires_from_now(duration); 
    130       timer.async_wait(boost::bind(set_result, &timer_result, _1)); 
    131  
    132       boost::optional<boost::system::error_code> read_result; 
    133       async_read(sock, buffers, boost::bind(set_result, &read_result, _1)); 
    134  
    135       sock.get_io_service().reset(); 
    136       while (sock.get_io_service().run_one()) { 
    137         if (read_result) 
    138           timer.cancel(); 
    139         else if (timer_result) 
    140           rawSocket.close(); 
    141       } 
    142  
    143       if (*read_result) 
    144         throw boost::system::system_error(*read_result); 
    145     }  
    146  
    147     template <typename AsyncWriteStream, typename RawSocket, typename MutableBufferSequence> 
    148     void write_with_timeout(AsyncWriteStream& sock, RawSocket& rawSocket, const MutableBufferSequence& buffers, boost::posix_time::time_duration duration) { 
    149       boost::optional<boost::system::error_code> timer_result; 
    150       boost::asio::deadline_timer timer(sock.get_io_service()); 
    151       timer.expires_from_now(duration); 
    152       timer.async_wait(boost::bind(set_result, &timer_result, _1)); 
    153  
    154       boost::optional<boost::system::error_code> read_result; 
    155       async_write(sock, buffers, boost::bind(set_result, &read_result, _1)); 
    156  
    157       sock.get_io_service().reset(); 
    158       while (sock.get_io_service().run_one()) { 
    159         if (read_result) 
    160           timer.cancel(); 
    161         else if (timer_result) 
    162           rawSocket.close(); 
    163       } 
    164  
    165       if (*read_result) 
    166         throw boost::system::system_error(*read_result); 
    167     } 
    168  
    169   } 
    170 } 
    171  
     6//  
     7// namespace socketHelpers { 
     8//  class allowedHosts { 
     9//    struct host_record { 
     10//      host_record() : mask(0) {} 
     11//      host_record(std::wstring r) : mask(0), record(r) {} 
     12//      std::wstring record; 
     13//      std::wstring host; 
     14//      u_long in_addr; 
     15//      unsigned long mask; 
     16//    }; 
     17//  public: 
     18//    typedef std::list<host_record> host_list;  
     19//    typedef std::list<std::wstring> string_list;  
     20//  private: 
     21//    host_list allowed_list_; 
     22//    string_list lookup_list; 
     23//    bool cachedAddresses_; 
     24//  public: 
     25//    allowedHosts() : cachedAddresses_(true) {} 
     26//  
     27//    unsigned int lookupMask(std::wstring mask) { 
     28//      unsigned int masklen = 32; 
     29//      if (!mask.empty()) { 
     30//        std::wstring::size_type pos = mask.find_first_of(_T("0123456789")); 
     31//        if (pos != std::wstring::npos) { 
     32//          masklen = strEx::stoi(mask.substr(pos)); 
     33//        } 
     34//      } 
     35//      if (masklen > 32) 
     36//        masklen = 32; 
     37//      return (~((unsigned int)0))>>(32-masklen); 
     38//    } 
     39//    void lookupList(boost::asio::io_service& io_service) { 
     40//      allowed_list_.clear(); 
     41//      for (string_list::iterator it = lookup_list.begin();it!=lookup_list.end();++it) { 
     42//        std::wstring host = (*it); 
     43//        host_record tmp_record; 
     44//        if (!host.empty()) { 
     45//          try { 
     46//            std::wstring::size_type pos = host.find('/'); 
     47//            if (pos == std::wstring::npos) { 
     48//              tmp_record.host = host; 
     49//              tmp_record.mask = lookupMask(_T("")); 
     50//            } else { 
     51//              tmp_record.host = host.substr(0, pos); 
     52//              tmp_record.mask = lookupMask(host.substr(pos)); 
     53//            } 
     54//            boost::asio::ip::tcp::resolver resolver(io_service); 
     55//            boost::asio::ip::tcp::resolver::query query(utf8::cvt<std::string>(tmp_record.host), ""); 
     56//            boost::asio::ip::tcp::resolver::iterator endpoint_iterator = resolver.resolve(query); 
     57//            boost::asio::ip::tcp::resolver::iterator end; 
     58//            for (;endpoint_iterator != end; ++endpoint_iterator) { 
     59//              tmp_record.in_addr = endpoint_iterator->endpoint().address().to_v4().to_ulong(); 
     60//              tmp_record.host = utf8::cvt<std::wstring>(endpoint_iterator->endpoint().address().to_string()); 
     61//              allowed_list_.push_back(tmp_record); 
     62//            } 
     63//            /* 
     64//            std::cerr << "Added: "  
     65//              + simpleSocket::Socket::inet_ntoa((*it).in_addr) 
     66//              + " with mask " 
     67//              + simpleSocket::Socket::inet_ntoa((*it).mask) 
     68//              + " from " 
     69//              + (*it).record << 
     70//              std::endl; 
     71//              */ 
     72//          } catch (std::exception &e) { 
     73//            std::cerr << "Filed to lookup host: " << e.what() << std::endl; 
     74//          } catch (...) { 
     75//            std::wcerr << _T("Filed to lookup host: ") << std::endl; 
     76//          } 
     77//        } 
     78//      } 
     79//    } 
     80//  
     81//    void setAllowedHosts(const std::list<std::wstring> list, bool cachedAddresses, boost::asio::io_service& io_service) { 
     82//      for (std::list<std::wstring>::const_iterator it = list.begin(); it != list.end(); ++it) { 
     83//        if (!(*it).empty()) 
     84//          lookup_list.push_back(*it); 
     85//      } 
     86//      cachedAddresses_ = cachedAddresses; 
     87//      lookupList(io_service); 
     88//    } 
     89//    bool matchHost(host_record allowed, struct in_addr remote) { 
     90//      /* 
     91//      if ((allowed.in_addr&allowed.mask)==(remote.S_un.S_addr&allowed.mask)) { 
     92//        std::cerr << "Matched: " << simpleSocket::Socket::inet_ntoa(allowed.in_addr)  << " with " <<  
     93//          simpleSocket::Socket::inet_ntoa(remote.S_un.S_addr) << std::endl; 
     94//      } 
     95//      */ 
     96//      return true; //((allowed.in_addr&allowed.mask)==(remote.S_un.S_addr&allowed.mask)); 
     97//    } 
     98//    bool inAllowedHosts(boost::asio::io_service& io_service, struct in_addr remote) { 
     99//      if (lookup_list.empty()) 
     100//        return true; 
     101//      if (!cachedAddresses_) { 
     102//        lookupList(io_service); 
     103//      } 
     104//      for (host_list::const_iterator cit = allowed_list_.begin();cit!=allowed_list_.end();++cit) { 
     105//        if (matchHost((*cit), remote)) 
     106//          return true; 
     107//      } 
     108//      return false; 
     109//    } 
     110//    std::wstring to_string() { 
     111//      std::wstring ret; 
     112//      BOOST_FOREACH(host_record r, allowed_list_) { 
     113//        if (!ret.empty()) ret += _T(", "); 
     114//        ret += r.host; 
     115//      } 
     116//      return ret; 
     117//    } 
     118//  }; 
     119//  
     120// } 
     121//  
  • include/strEx.h

    r04ef932 rb9498ef  
    334334    return boost::lexical_cast<int>(s.c_str()); 
    335335  } 
     336  inline int stoi(std::string s) { 
     337    return boost::lexical_cast<int>(s.c_str()); 
     338  } 
    336339  inline double stod(std::wstring s) { 
    337340    return boost::lexical_cast<double>(s.c_str()); 
  • modules/NRPEClient/CMakeLists.txt

    r04ef932 rb9498ef  
    99  "${TARGET}.cpp" 
    1010  ${NSCP_INCLUDEDIR}/nrpe/packet.cpp 
     11  ${NSCP_INCLUDEDIR}/socket/socket_helpers.cpp 
    1112 
    1213  ${NSCP_DEF_PLUGIN_CPP} 
     
    2021    "${TARGET}.h" 
    2122    "${TARGET}.def" 
    22     ${NSCP_INCLUDEDIR}/socket_helpers.hpp 
    2323    ${NSCP_INCLUDEDIR}/nrpe/packet.hpp 
    2424    ${NSCP_INCLUDEDIR}/nrpe/client/socket.hpp 
    2525    ${NSCP_INCLUDEDIR}/swap_bytes.hpp 
     26    ${NSCP_INCLUDEDIR}/socket/socket_helpers.hpp 
    2627 
    2728    ${NSCP_DEF_PLUGIN_HPP} 
  • modules/NRPEServer/CMakeLists.txt

    r04ef932 rb9498ef  
    1717  ${NSCP_INCLUDEDIR}/nrpe/server/ssl_connection.cpp 
    1818  ${NSCP_INCLUDEDIR}/nrpe/packet.cpp 
     19  ${NSCP_INCLUDEDIR}/socket/socket_helpers.cpp 
    1920 
    2021  ${NSCP_DEF_PLUGIN_CPP} 
     
    3536    ${NSCP_INCLUDEDIR}/nrpe/server/handler.hpp 
    3637    ${NSCP_INCLUDEDIR}/nrpe/server/parser.hpp 
    37     ${NSCP_INCLUDEDIR}/socket_helpers.hpp 
    3838    ${NSCP_INCLUDEDIR}/nrpe/packet.hpp 
    3939    ${NSCP_INCLUDEDIR}/swap_bytes.hpp 
     40    ${NSCP_INCLUDEDIR}/socket/socket_helpers.hpp 
    4041 
    4142    ${NSCP_DEF_PLUGIN_HPP} 
  • modules/NRPEServer/NRPEServer.cpp

    r7ec3dd1 rb9498ef  
    3838NRPEListener::~NRPEListener() {} 
    3939 
    40 std::wstring getAllowedHosts() { 
    41   return SETTINGS_GET_STRING_FALLBACK(nrpe::ALLOWED_HOSTS, protocol_def::ALLOWED_HOSTS); 
    42 } 
    43 bool getCacheAllowedHosts() { 
    44   return SETTINGS_GET_BOOL_FALLBACK(nrpe::CACHE_ALLOWED, protocol_def::CACHE_ALLOWED); 
    45 } 
    46  
    47  
    48  
    4940bool NRPEListener::loadModule() { 
    5041  return false; 
     
    7364      _T("PORT NUMBER"), _T("Port to use for NRPE.")) 
    7465 
     66      (_T("payload length"), sh::int_fun_key<unsigned int>(boost::bind(&nrpe::server::handler::set_payload_length, info_.request_handler, _1), 1024), 
     67      _T("PAYLOAD LENGTH"), _T("Length of payload to/from the NRPE agent. This is a hard specific value so you have to \"configure\" (read recompile) your NRPE agent to use the same value for it to work.")) 
     68 
     69      (_T("allow arguments"), sh::bool_fun_key<bool>(boost::bind(&nrpe::server::handler::set_allow_arguments, info_.request_handler, _1), false), 
     70      _T("COMMAND ARGUMENT PROCESSING"), _T("This option determines whether or not the we will allow clients to specify arguments to commands that are executed.")) 
     71 
     72      (_T("allow nasty characters"), sh::bool_fun_key<bool>(boost::bind(&nrpe::server::handler::set_allow_nasty_arguments, info_.request_handler, _1), false), 
     73      _T("COMMAND ALLOW NASTY META CHARS"), _T("This option determines whether or not the we will allow clients to specify nasty (as in |`&><'\"\\[]{}) characters in arguments.")) 
     74 
     75      (_T("performance data"), sh::bool_fun_key<bool>(boost::bind(&nrpe::server::handler::set_perf_data, info_.request_handler, _1), true), 
     76      _T("PERFORMANCE DATA"), _T("Send performance data back to nagios (set this to 0 to remove all performance data).")) 
     77 
     78      ; 
     79 
     80    settings.alias().add_parent(_T("/settings/default")).add_key_to_settings() 
     81 
    7582      (_T("thread pool"), sh::uint_key(&info_.thread_pool_size, 10), 
    7683      _T("THREAD POOL"), _T("")) 
    7784 
     85      (_T("bind to"), sh::string_key(&info_.address), 
     86      _T("BIND TO ADDRESS"), _T("Allows you to bind server to a specific local address. This has to be a dotted ip address not a host name. Leaving this blank will bind to all available IP addresses.")) 
     87 
     88      (_T("socket queue size"), sh::int_key(&info_.back_log, 0), 
     89      _T("LISTEN QUEUE"), _T("Number of sockets to queue before starting to refuse new incoming connections. This can be used to tweak the amount of simultaneous sockets that the server accepts.")) 
     90 
     91      (_T("allowed hosts"), sh::string_fun_key<std::wstring>(boost::bind(&socket_helpers::allowed_hosts_manager::set_source, &info_.allowed_hosts, _1), _T("127.0.0.1")), 
     92      _T("ALLOWED HOSTS"), _T("A comaseparated list of allowed hosts. You can use netmasks (/ syntax) or * to create ranges.")) 
     93 
     94      (_T("cache allowed hosts"), sh::bool_key(&info_.allowed_hosts.cached, true), 
     95      _T("CACHE ALLOWED HOSTS"), _T("If hostnames should be cached, improves speed and security somewhat but wont allow you to have dynamic IPs for your nagios server.")) 
     96 
    7897      (_T("timeout"), sh::uint_key(&info_.timeout, 30), 
    7998      _T("TIMEOUT"), _T("Timeout when reading packets on incoming sockets. If the data has not arrived within this time we will bail out.")) 
     
    82101      _T("ENABLE SSL ENCRYPTION"), _T("This option controls if SSL should be enabled.")) 
    83102 
    84       (_T("payload length"), sh::int_fun_key<unsigned int>(boost::bind(&nrpe::server::handler::set_payload_length, info_.request_handler, _1), 1024), 
    85       _T("PAYLOAD LENGTH"), _T("Length of payload to/from the NRPE agent. This is a hard specific value so you have to \"configure\" (read recompile) your NRPE agent to use the same value for it to work.")) 
    86  
    87       (_T("allow arguments"), sh::bool_fun_key<bool>(boost::bind(&nrpe::server::handler::set_allow_arguments, info_.request_handler, _1), false), 
    88       _T("COMMAND ARGUMENT PROCESSING"), _T("This option determines whether or not the we will allow clients to specify arguments to commands that are executed.")) 
    89  
    90       (_T("allow nasty characters"), sh::bool_fun_key<bool>(boost::bind(&nrpe::server::handler::set_allow_nasty_arguments, info_.request_handler, _1), false), 
    91       _T("COMMAND ALLOW NASTY META CHARS"), _T("This option determines whether or not the we will allow clients to specify nasty (as in |`&><'\"\\[]{}) characters in arguments.")) 
    92  
    93       (_T("performance data"), sh::bool_fun_key<bool>(boost::bind(&nrpe::server::handler::set_perf_data, info_.request_handler, _1), true), 
    94       _T("PERFORMANCE DATA"), _T("Send performance data back to nagios (set this to 0 to remove all performance data).")) 
    95  
    96103      (_T("certificate"), sh::wpath_key(&info_.certificate, _T("${certificate-path}/nrpe_dh_512.pem")), 
    97104      _T("SSL CERTIFICATE"), _T("")) 
     105 
    98106      ; 
    99  
    100     settings.alias().add_parent(_T("/settings/default")).add_key_to_settings() 
    101  
    102       (_T("bind to"), sh::string_key(&info_.address), 
    103       _T("BIND TO ADDRESS"), _T("Allows you to bind server to a specific local address. This has to be a dotted ip address not a host name. Leaving this blank will bind to all available IP addresses.")) 
    104  
    105       (_T("socket queue size"), sh::int_key(&info_.back_log, 0), 
    106       _T("LISTEN QUEUE"), _T("Number of sockets to queue before starting to refuse new incoming connections. This can be used to tweak the amount of simultaneous sockets that the server accepts.")) 
    107  
    108       ; 
    109  
    110  
    111107 
    112108    settings.register_all(); 
     
    124120      NSC_LOG_ERROR_STD(_T("Certificate not found: ") + info_.certificate); 
    125121 
     122 
     123    std::list<std::string> errors; 
     124    info_.allowed_hosts.refresh(errors); 
     125    BOOST_FOREACH(const std::string &e, errors) { 
     126      NSC_LOG_ERROR_STD(utf8::cvt<std::wstring>(e)); 
     127    } 
     128    NSC_DEBUG_MSG_STD(_T("Allowed hosts definition: ") + info_.allowed_hosts.to_wstring()); 
     129 
    126130    boost::asio::io_service io_service_; 
    127  
    128     allowedHosts.setAllowedHosts(strEx::splitEx(getAllowedHosts(), _T(",")), getCacheAllowedHosts(), io_service_); 
    129     NSC_DEBUG_MSG_STD(_T("Allowed hosts: ") + allowedHosts.to_string()); 
    130131 
    131132    if (mode == NSCAPI::normalStart) { 
  • modules/NRPEServer/NRPEServer.h

    r3bdaf18 rb9498ef  
    3737  }; 
    3838 
    39   socketHelpers::allowedHosts allowedHosts; 
    4039  nrpe::server::server::connection_info info_; 
    4140 
  • modules/NSCAAgent/CMakeLists.txt

    r04ef932 rb9498ef  
    88  stdafx.cpp 
    99  "${TARGET}.cpp" 
     10  ${NSCP_INCLUDEDIR}/socket/socket_helpers.cpp 
    1011 
    1112  ${NSCP_DEF_PLUGIN_CPP} 
     
    3132    ${NSCP_INCLUDEDIR}/nsca/nsca_enrypt.hpp 
    3233    ${NSCP_INCLUDEDIR}/swap_bytes.hpp 
     34    ${NSCP_INCLUDEDIR}/socket/socket_helpers.hpp 
    3335 
    3436    ${NSCP_DEF_PLUGIN_HPP} 
  • modules/NSCAAgent/NSCAAgent.cpp

    rd66ccee rb9498ef  
    107107    settings.notify(); 
    108108 
     109  } catch (nscapi::nscapi_exception &e) { 
     110    NSC_LOG_ERROR_STD(_T("Failed to register command: ") + e.msg_); 
     111    return false; 
    109112  } catch (std::exception &e) { 
    110113    NSC_LOG_ERROR_STD(_T("Exception caught: ") + utf8::cvt<std::wstring>(e.what())); 
    111     return false; 
    112   } catch (nscapi::nscapi_exception &e) { 
    113     NSC_LOG_ERROR_STD(_T("Failed to register command: ") + e.msg_); 
    114114    return false; 
    115115  } catch (...) { 
  • modules/NSCAAgent/stdafx.h

    r3bdaf18 rb9498ef  
    2626#include <iostream> 
    2727#include <string> 
    28 #include <hash_map> 
    2928#include <list> 
    3029 
  • modules/NSClientServer/CMakeLists.txt

    rb8c44b4 rb9498ef  
    1717  ${NSCP_INCLUDEDIR}/check_nt/server/ssl_connection.cpp 
    1818  ${NSCP_INCLUDEDIR}/check_nt/packet.cpp 
     19  ${NSCP_INCLUDEDIR}/socket/socket_helpers.cpp 
    1920 
    2021  ${NSCP_DEF_PLUGIN_CPP} 
     
    3536    ${NSCP_INCLUDEDIR}/check_nt/server/handler.hpp 
    3637    ${NSCP_INCLUDEDIR}/check_nt/server/parser.hpp 
    37     ${NSCP_INCLUDEDIR}/socket_helpers.hpp 
    3838    ${NSCP_INCLUDEDIR}/check_nt/packet.hpp 
    3939    ${NSCP_INCLUDEDIR}/swap_bytes.hpp 
     40    ${NSCP_INCLUDEDIR}/socket/socket_helpers.hpp 
    4041 
    4142    ${NSCP_DEF_PLUGIN_HPP} 
  • modules/NSClientServer/NSClientServer.cpp

    rb8c44b4 rb9498ef  
    6767      _T("PORT NUMBER"), _T("Port to use for check_nt.")) 
    6868 
     69      (_T("performance data"), sh::bool_fun_key<bool>(boost::bind(&check_nt::server::handler::set_perf_data, info_.request_handler, _1), true), 
     70      _T("PERFORMANCE DATA"), _T("Send performance data back to nagios (set this to 0 to remove all performance data).")) 
     71 
     72      ; 
     73 
     74    settings.alias().add_parent(_T("/settings/default/socket")).add_key_to_settings() 
     75 
    6976      (_T("thread pool"), sh::uint_key(&info_.thread_pool_size, 10), 
    7077      _T("THREAD POOL"), _T("")) 
    7178 
     79      (_T("bind to"), sh::string_key(&info_.address), 
     80      _T("BIND TO ADDRESS"), _T("Allows you to bind server to a specific local address. This has to be a dotted ip address not a host name. Leaving this blank will bind to all available IP addresses.")) 
     81 
     82      (_T("socket queue size"), sh::int_key(&info_.back_log, 0), 
     83      _T("LISTEN QUEUE"), _T("Number of sockets to queue before starting to refuse new incoming connections. This can be used to tweak the amount of simultaneous sockets that the server accepts.")) 
     84 
     85      (_T("allowed hosts"), sh::string_fun_key<std::wstring>(boost::bind(&socket_helpers::allowed_hosts_manager::set_source, &info_.allowed_hosts, _1), _T("127.0.0.1")), 
     86      _T("ALLOWED HOSTS"), _T("A comaseparated list of allowed hosts. You can use netmasks (/ syntax) or * to create ranges.")) 
     87 
     88      (_T("cache allowed hosts"), sh::bool_key(&info_.allowed_hosts.cached, true), 
     89      _T("CACHE ALLOWED HOSTS"), _T("If hostnames should be cached, improves speed and security somewhat but wont allow you to have dynamic IPs for your nagios server.")) 
     90 
    7291      (_T("timeout"), sh::uint_key(&info_.timeout, 30), 
    7392      _T("TIMEOUT"), _T("Timeout when reading packets on incoming sockets. If the data has not arrived within this time we will bail out.")) 
     
    7695      _T("ENABLE SSL ENCRYPTION"), _T("This option controls if SSL should be enabled.")) 
    7796 
    78       (_T("allow arguments"), sh::bool_fun_key<bool>(boost::bind(&check_nt::server::handler::set_allow_arguments, info_.request_handler, _1), false), 
    79       _T("COMMAND ARGUMENT PROCESSING"), _T("This option determines whether or not the we will allow clients to specify arguments to commands that are executed.")) 
    80  
    81       (_T("allow nasty characters"), sh::bool_fun_key<bool>(boost::bind(&check_nt::server::handler::set_allow_nasty_arguments, info_.request_handler, _1), false), 
    82       _T("COMMAND ALLOW NASTY META CHARS"), _T("This option determines whether or not the we will allow clients to specify nasty (as in |`&><'\"\\[]{}) characters in arguments.")) 
    83  
    84       (_T("performance data"), sh::bool_fun_key<bool>(boost::bind(&check_nt::server::handler::set_perf_data, info_.request_handler, _1), true), 
    85       _T("PERFORMANCE DATA"), _T("Send performance data back to nagios (set this to 0 to remove all performance data).")) 
    86  
    8797      (_T("certificate"), sh::wpath_key(&info_.certificate, _T("${certificate-path}/nrpe_dh_512.pem")), 
    8898      _T("SSL CERTIFICATE"), _T("")) 
     99 
    89100      ; 
    90101 
    91102    settings.alias().add_parent(_T("/settings/default")).add_key_to_settings() 
    92103 
    93       (_T("bind to"), sh::string_key(&info_.address), 
    94       _T("BIND TO ADDRESS"), _T("Allows you to bind server to a specific local address. This has to be a dotted ip address not a host name. Leaving this blank will bind to all available IP addresses.")) 
    95  
    96       (_T("socket queue size"), sh::int_key(&info_.back_log, 0), 
    97       _T("LISTEN QUEUE"), _T("Number of sockets to queue before starting to refuse new incoming connections. This can be used to tweak the amount of simultaneous sockets that the server accepts.")) 
    98  
    99       ; 
    100  
    101  
     104      (_T("password"), sh::string_fun_key<std::wstring>(boost::bind(&check_nt::server::handler::set_password, info_.request_handler, _1), _T("")), 
     105      _T("PASSWORD"), _T("Password used to authenticate againast server")) 
     106      ; 
    102107 
    103108    settings.register_all(); 
     
    105110  } catch (...) {} 
    106111 
    107 //  allowedHosts.setAllowedHosts(strEx::splitEx(getAllowedHosts(), _T(",")), getCacheAllowedHosts()); 
    108 //  unsigned short port = SETTINGS_GET_INT(nsclient::PORT); 
    109 //  std::wstring host = SETTINGS_GET_STRING(nsclient::BINDADDR); 
    110 //  unsigned int backLog = SETTINGS_GET_INT(nsclient::LISTENQUE); 
    111 //  socketTimeout_ = SETTINGS_GET_INT(nsclient::READ_TIMEOUT); 
    112  
    113  
    114   info_.request_handler->set_password(_T("TODO")); 
    115  
    116112#ifndef USE_SSL 
    117113  if (info_.use_ssl) { 
     
    122118    NSC_LOG_ERROR_STD(_T("Certificate not found: ") + info_.certificate); 
    123119 
     120 
     121  std::list<std::string> errors; 
     122  info_.allowed_hosts.refresh(errors); 
     123  BOOST_FOREACH(const std::string &e, errors) { 
     124    NSC_LOG_ERROR_STD(utf8::cvt<std::wstring>(e)); 
     125  } 
     126  NSC_DEBUG_MSG_STD(_T("Allowed hosts definition: ") + info_.allowed_hosts.to_wstring()); 
     127 
    124128  boost::asio::io_service io_service_; 
    125  
    126   allowedHosts.setAllowedHosts(strEx::splitEx(getAllowedHosts(), _T(",")), getCacheAllowedHosts(), io_service_); 
    127   NSC_DEBUG_MSG_STD(_T("Allowed hosts: ") + allowedHosts.to_string()); 
    128129 
    129130  if (mode == NSCAPI::normalStart) { 
    130131    try { 
    131  
    132  
    133  
    134132          if (info_.use_ssl) { 
    135133#ifdef USE_SSL 
  • modules/NSClientServer/NSClientServer.h

    rb8c44b4 rb9498ef  
    2828private: 
    2929 
    30   socketHelpers::allowedHosts allowedHosts; 
    3130  check_nt::server::server::connection_info info_; 
    3231  boost::shared_ptr<check_nt::server::server> server_; 
  • modules/PythonScript/script_wrapper.cpp

    r2c95d22 rb9498ef  
    265265 
    266266void script_wrapper::command_wrapper::simple_submit(std::string channel, std::string command, status code, std::string message, std::string perf) { 
    267   core->submit_simple_message(utf8::cvt<std::wstring>(channel), utf8::cvt<std::wstring>(command), code, utf8::cvt<std::wstring>(message), utf8::cvt<std::wstring>(perf)); 
     267  NSCAPI::nagiosReturn c = NSCAPI::returnUNKNOWN; 
     268  if (code == OK) 
     269    c = NSCAPI::returnOK; 
     270  if (code == WARN) 
     271    c = NSCAPI::returnWARN; 
     272  if (code == CRIT) 
     273    c = NSCAPI::returnCRIT; 
     274  std::wstring wmessage = utf8::cvt<std::wstring>(message); 
     275  std::wstring wperf = utf8::cvt<std::wstring>(perf); 
     276  core->submit_simple_message(utf8::cvt<std::wstring>(channel), utf8::cvt<std::wstring>(command), c, wmessage, wperf); 
    268277} 
    269278 
Note: See TracChangeset for help on using the changeset viewer.