Changeset dcd90b2 in nscp


Ignore:
Timestamp:
11/23/09 22:54:09 (3 years ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2
Children:
9b3f53c
Parents:
858ecc1
Message:

Added back openssl now builds (and presumably the NRPEClient works with it haven't tested but will do after I get the NRPEListener up and running...)

Files:
7 edited

Legend:

Unmodified
Added
Removed
  • CMakeLists.txt

    r1e0bbec rdcd90b2  
    4949ENDIF(WIN32) 
    5050 
     51SET(OPENSSL_INCLUDE_DIR ${OPENSSL_INCLUDE_DIR} CACHE PATH "Look for OPENSSL headers here") 
     52SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} CACHE PATH "Look for libraries here") 
     53 
     54FIND_PACKAGE(OpenSSL) 
     55if(OPENSSL_FOUND) 
     56  if(WIN32) 
     57    FIND_LIBRARY(LIB_EAY_DEBUG NAMES libeay32MDd libeay32) 
     58    FIND_LIBRARY(LIB_EAY_RELEASE NAMES libeay32MD libeay32) 
     59      IF(LIB_EAY_DEBUG AND LIB_EAY_RELEASE) 
     60         SET(OPENSSL_LIBRARIES ${OPENSSL_LIBRARIES} optimized ${LIB_EAY_RELEASE} debug ${LIB_EAY_DEBUG}) 
     61      ELSE(LIB_EAY_DEBUG AND LIB_EAY_RELEASE) 
     62    SET(OPENSSL_FOUND FALSE) 
     63         SET(OPENSSL_LIBRARIES NOTFOUND) 
     64         MESSAGE(STATUS "Could not find the debug and release version of openssl") 
     65      ENDIF(LIB_EAY_DEBUG AND LIB_EAY_RELEASE) 
     66  endif(WIN32) 
     67endif(OPENSSL_FOUND) 
     68 
     69if(OPENSSL_FOUND) 
     70  message(STATUS, "Found openssl: ${OPENSSL_LIBRARIES}") 
     71  SET(NSCP_GLOBAL_DEFINES ${NSCP_GLOBAL_DEFINES} -DUSE_SSL) 
     72else(OPENSSL_FOUND) 
     73  message(STATUS, "openssl NOT found (no ssl support)") 
     74endif(OPENSSL_FOUND) 
     75 
    5176FIND_PACKAGE(Boost COMPONENTS system filesystem thread REQUIRED) 
    5277 
     
    83108 
    84109 
    85 SET(NSCP_GLOBAL_DEFINES 
    86   -DUNICODE -D_UNICODE 
    87 ) 
     110SET(NSCP_GLOBAL_DEFINES ${NSCP_GLOBAL_DEFINES} -DUNICODE -D_UNICODE) 
    88111 
    89112IF(CMAKE_HOST_UNIX) 
  • build.cmake

    r1e0bbec rdcd90b2  
    44set(BOOST_USE_MULTITHREADED ON) 
    55 
    6 SET(BOOST_INCLUDEDIR D:/source/include/boost-1_40) 
    7 SET(BOOST_LIBRARYDIR d:/source/lib/x86/) 
     6SET(BOOST_INCLUDEDIR c:/src/include/boost-1_39) 
     7#SET(BOOST_LIBRARYDIR c:/src/lib/x86/) 
    88SET(BOOST_LIB_SUFFIX vc80-mt) 
    9 SET(BOOST_LIB_VERSION 1.40) 
     9#SET(BOOST_LIB_VERSION 1.40) 
     10 
     11 
     12SET(OPENSSL_INCLUDE_DIR c:/src/include/) 
     13SET(CMAKE_LIBRARY_PATH c:/src/lib/x86/) 
  • include/program_options_ex.hpp

    r1e0bbec rdcd90b2  
    77class basic_command_line_parser_ex : public boost::program_options::basic_command_line_parser<charT> { 
    88public: 
     9  /* 
    910  static boost::program_options::basic_parsed_options<charT> parse_command_line(int argc, charT* argv[], const boost::program_options::options_description& desc, 
    1011    int style = 0, boost::function1<std::pair<std::string, std::string>, const std::string&> ext = boost::program_options::ext_parser()) 
     
    1213    return basic_command_line_parser_ex<charT>(argc, argv).options(desc).style(style).extra_parser(ext).run(); 
    1314  } 
     15  */ 
    1416 
    1517  template<class charTx, class Iterator> 
     
    3133      ) 
    3234    {} 
    33     /* 
    34 #ifdef _WIN32 
    35     basic_command_line_parser_ex(const std::wstring args)  
    36       : boost::program_options::basic_command_line_parser<charT>(boost::program_options::split_winmain(args)) 
     35    basic_command_line_parser_ex(std::vector<charT> v)  
     36      : boost::program_options::basic_command_line_parser<charT>(v) 
    3737    {} 
    38 #endif 
    39     */ 
    4038 
    4139}; 
  • modules/NRPEClient/CMakeLists.txt

    r858ecc1 rdcd90b2  
    3636  ${Boost_LIBRARIES} 
    3737  ${CMAKE_THREAD_LIBS_INIT} 
     38  ${OPENSSL_LIBRARIES} 
    3839  ${EXTRA_LIBS} 
    3940) 
  • modules/NRPEClient/NRPEClient.cpp

    r1e0bbec rdcd90b2  
    2626#include <msvc_wrappers.h> 
    2727//#include <execute_process.hpp> 
    28 #include <program_options_ex.hpp> 
    2928#include <strEx.h> 
     29 
     30 
    3031 
    3132NRPEClient gNRPEClient; 
     
    3940#endif 
    4041 
    41 NRPEClient::NRPEClient() : buffer_length_(0), bInitSSL(false) { 
     42NRPEClient::NRPEClient() : buffer_length_(0) { 
    4243} 
    4344 
     
    6768  return true; 
    6869} 
    69 void NRPEClient::initSSL() { 
    70   if (bInitSSL) 
    71     return; 
    72 #ifdef USE_SSL 
    73   simpleSSL::SSL_init(); 
    74 #endif 
    75   bInitSSL = true; 
    76 } 
     70 
     71void NRPEClient::add_options(po::options_description &desc, nrpe_connection_data command_data) { 
     72  desc.add_options() 
     73    ("help,h", "Show this help message.") 
     74    ("host,H", po::wvalue<std::wstring>(&command_data.host), "The address of the host running the NRPE daemon") 
     75    ("port,p", po::value<int>(&command_data.port), "The port on which the daemon is running (default=5666)") 
     76    ("command,c", po::wvalue<std::wstring>(&command_data.command), "The name of the command that the remote daemon should run") 
     77    ("timeout,t", po::value<int>(&command_data.timeout), "Number of seconds before connection times out (default=10)") 
     78    ("buffer-length,l", po::value<unsigned int>(&command_data.buffer_length), std::string("Length of payload (has to be same as on the server (default=" + to_string(buffer_length_) + ")").c_str()) 
     79    ("no-ssl,n", po::value<bool>(&command_data.no_ssl)->zero_tokens()->default_value(false), "Do not initial an ssl handshake with the server, talk in plaintext.") 
     80    ("arguments,a", po::wvalue<std::vector<std::wstring> >(&command_data.argument_vector), "list of arguments") 
     81    ; 
     82} 
     83 
    7784 
    7885void NRPEClient::addCommand(strEx::blindstr key, std::wstring args) { 
    7986  try { 
    80     /* 
    81     TODO: reimplem,ent this! 
    82     boost::program_options::options_description desc = get_optionDesc(); 
    83     boost::program_options::positional_options_description p = get_optionsPositional(); 
    84  
     87 
     88    NRPEClient::nrpe_connection_data command_data; 
    8589    boost::program_options::variables_map vm; 
    86     boost::program_options::store( 
    87       basic_command_line_parser_ex<wchar_t>(args).options(desc).positional(p).run() 
    88       , vm); 
    89     boost::program_options::notify(vm);  
    90     nrpe_connection_data cd = get_ConectionData(vm); 
    91     NSC_DEBUG_MSG_STD(_T("Added NRPE Client: ") + key.c_str() + _T(" = ") + cd.toString()); 
    92     commands[key] = cd; 
    93     */ 
     90 
     91    po::options_description desc("Allowed options"); 
     92    buffer_length_ = SETTINGS_GET_INT(nrpe::PAYLOAD_LENGTH); 
     93    add_options(desc, command_data); 
     94 
     95    po::positional_options_description p; 
     96    p.add("arguments", -1); 
     97 
     98    std::vector<std::wstring> list; 
     99    //explicit escaped_list_separator(Char e = '\\', Char c = ',',Char q = '\"') 
     100    boost::escaped_list_separator<wchar_t> sep(L'\\', L' ', L'\"'); 
     101    typedef boost::tokenizer<boost::escaped_list_separator<wchar_t>,std::wstring::const_iterator, std::wstring > tokenizer_t; 
     102    tokenizer_t tok(args, sep); 
     103    for(tokenizer_t::iterator beg=tok.begin(); beg!=tok.end();++beg){ 
     104      std::wcout << *beg << std::endl; 
     105      list.push_back(*beg); 
     106    } 
     107 
     108    po::wparsed_options parsed = po::basic_command_line_parser<wchar_t>(list).options(desc).positional(p).run(); 
     109    po::store(parsed, vm); 
     110    po::notify(vm); 
     111    command_data.parse_arguments(); 
     112 
     113    NSC_DEBUG_MSG_STD(_T("Added NRPE Client: ") + key.c_str() + _T(" = ") + command_data.toString()); 
     114    commands[key] = command_data; 
    94115  } catch (boost::program_options::validation_error &e) { 
    95116    NSC_LOG_ERROR_STD(_T("Could not parse: ") + key.c_str() + strEx::string_to_wstring(e.what())); 
     
    138159} 
    139160 
    140 boost::program_options::options_description NRPEClient::get_optionDesc() { 
    141   boost::program_options::options_description desc("Allowed options"); 
    142   buffer_length_ = SETTINGS_GET_INT(nrpe::PAYLOAD_LENGTH); 
    143   desc.add_options() 
    144     ("help,h", "Show this help message.") 
    145     ("host,H", boost::program_options::wvalue<std::wstring>(), "The address of the host running the NRPE daemon") 
    146     ("port,p", boost::program_options::value<int>(), "The port on which the daemon is running (default=5666)") 
    147     ("command,c", boost::program_options::wvalue<std::wstring>(), "The name of the command that the remote daemon should run") 
    148     ("timeout,t", boost::program_options::value<int>(), "Number of seconds before connection times out (default=10)") 
    149     ("buffer-length,l", boost::program_options::value<int>(), std::string("Length of payload (has to be same as on the server (default=" + strEx::s::itos(buffer_length_) + ")").c_str()) 
    150     ("no-ssl,n", "Do not initial an ssl handshake with the server, talk in plaintext.") 
    151     ("arguments,a", boost::program_options::wvalue<std::vector<std::wstring> >(), "list of arguments") 
    152     ; 
    153   return desc; 
    154 } 
    155 boost::program_options::positional_options_description NRPEClient::get_optionsPositional() { 
    156   boost::program_options::positional_options_description p; 
    157   p.add("arguments", -1); 
    158   return p; 
    159 } 
    160  
    161 namespace po = boost::program_options; 
    162161int NRPEClient::commandLineExec(const unsigned int argLen, TCHAR** args) { 
    163162  try { 
     
    168167    po::options_description desc("Allowed options"); 
    169168    buffer_length_ = SETTINGS_GET_INT(nrpe::PAYLOAD_LENGTH); 
    170     desc.add_options() 
    171       ("help,h", "Show this help message.") 
    172       ("host,H", po::wvalue<std::wstring>(&command_data.host), "The address of the host running the NRPE daemon") 
    173       ("port,p", po::value<int>(&command_data.port), "The port on which the daemon is running (default=5666)") 
    174       ("command,c", po::wvalue<std::wstring>(&command_data.command), "The name of the command that the remote daemon should run") 
    175       ("timeout,t", po::value<int>(&command_data.timeout), "Number of seconds before connection times out (default=10)") 
    176       ("buffer-length,l", po::value<unsigned int>(&command_data.buffer_length), std::string("Length of payload (has to be same as on the server (default=" + to_string(buffer_length_) + ")").c_str()) 
    177       ("no-ssl,n", po::value<bool>(&command_data.no_ssl)->zero_tokens()->default_value(false), "Do not initial an ssl handshake with the server, talk in plaintext.") 
    178       ("arguments,a", po::wvalue<std::vector<std::wstring> >(&command_data.argument_vector), "list of arguments") 
    179       ; 
     169    add_options(desc, command_data); 
    180170 
    181171    po::positional_options_description p; 
     
    185175    po::notify(vm); 
    186176    command_data.parse_arguments(); 
    187  
    188     std::wcout << _T("parsed data: ") << command_data.toString()<< std::endl; 
    189177 
    190178    if (vm.count("help")) { 
     
    229217#else 
    230218   
    231   initSSL(); 
    232219  simpleSSL::Socket socket(true); 
    233220  socket.connect(host, port); 
  • modules/NRPEClient/NRPEClient.h

    r1e0bbec rdcd90b2  
    2323#include <map> 
    2424#include <nrpe/nrpepacket.hpp> 
    25 #include <boost/program_options.hpp> 
    2625 
    2726 
     
    8685  command_list commands; 
    8786  unsigned int buffer_length_; 
    88   bool bInitSSL; 
    8987 
    9088public: 
     
    125123  NRPEPacket send_nossl(std::wstring host, int port, int timeout, NRPEPacket packet); 
    126124  NRPEPacket send_ssl(std::wstring host, int port, int timeout, NRPEPacket packet); 
    127   void initSSL(); 
    128   boost::program_options::options_description get_optionDesc(); 
    129   boost::program_options::positional_options_description get_optionsPositional(); 
    130   nrpe_connection_data get_ConectionData(boost::program_options::variables_map &vm); 
     125  void add_options(po::options_description &desc, nrpe_connection_data command_data); 
    131126 
    132127 
  • modules/NRPEClient/stdafx.h

    r1e0bbec rdcd90b2  
    4646#include <boost/asio/ssl.hpp> 
    4747#endif 
     48#include <program_options_ex.hpp> 
     49namespace po = boost::program_options; 
    4850 
     51 
Note: See TracChangeset for help on using the changeset viewer.