Revision afaa282f

View differences:

cmake/modules/FindPQXX.cmake
4 4
#   PQXX_INCLUDE_DIRECTORIES  to the directory containing mysql.h
5 5
#   PQXX_LIBRARIES            to the MySQL client library (and any dependents required)
6 6
# If PQXX_REQUIRED is defined, then a fatal error message will be generated if libpqxx is not found
7

  
8
set ( PostgreSQL_INCLUDE_DIR /opt/local/include/postgresql94 )
9
set ( PostgreSQL_LIBRARY_DIR /opt/local/lib/postgresql94 )
10
set ( PostgreSQL_TYPE_INCLUDE_DIR ${PostgreSQL_INCLUDE_DIR}/server/catalog )
7 11
if ( NOT PQXX_INCLUDE_DIRECTORIES OR NOT PQXX_LIBRARIES )
8 12

  
9
  FIND_PACKAGE( POSTGRES REQUIRED )
10
  if ( POSTGRES_FOUND )
13
    FIND_PACKAGE( PostgreSQL REQUIRED )
14
    if ( PostgreSQL_FOUND )
11 15
    file( TO_CMAKE_PATH "$ENV{PQXX_DIR}" _PQXX_DIR )
12 16

  
13 17
    find_library( PQXX_LIBRARY
......
20 24
        /usr/local/pgsql/lib
21 25
        /usr/local/lib
22 26
        /usr/lib
27
        /opt/local/lib
23 28
      DOC "Location of libpqxx library"
24 29
      NO_DEFAULT_PATH
25 30
    )
......
33 38
        /usr/local/pgsql/include
34 39
        /usr/local/include
35 40
        /usr/include
41
        /opt/local/include
36 42
      DOC "Path to pqxx/pqxx header file. Do not include the 'pqxx' directory in this value."
37 43
      NO_DEFAULT_PATH
38 44
    )
39
  endif ( POSTGRES_FOUND )
45
  else ( PostgreSQL )
46
      message( "How about libpq-fe, guys?" )
47
  endif ( PostgreSQL_FOUND )
40 48

  
41 49
  if ( PQXX_HEADER_PATH AND PQXX_LIBRARY )
42 50

  
43 51
    set( PQXX_FOUND 1 CACHE INTERNAL "PQXX found" FORCE )
44
    set( PQXX_INCLUDE_DIRECTORIES "${PQXX_HEADER_PATH};${POSTGRES_INCLUDE_DIRECTORIES}" CACHE STRING "Include directories for PostGreSQL C++ library"  FORCE )
45
    set( PQXX_LIBRARIES "${PQXX_LIBRARY};${POSTGRES_LIBRARIES}" CACHE STRING "Link libraries for PostGreSQL C++ interface" FORCE )
52
    set( PQXX_INCLUDE_DIRECTORIES "${PQXX_HEADER_PATH}" CACHE STRING "Include directories for PostGreSQL C++ library"  FORCE )
53
    set( PQXX_LIBRARIES "${PQXX_LIBRARY}" CACHE STRING "Link libraries for PostGreSQL C++ interface" FORCE )
46 54

  
47 55
    mark_as_advanced( FORCE PQXX_INCLUDE_DIRECTORIES )
48 56
    mark_as_advanced( FORCE PQXX_LIBRARIES )
49 57

  
58
    find_package( PkgConfig REQUIRED )
59
    if ( PKG_CONFIG_FOUND )
60
        pkg_check_modules( PKG_PQXX libpqxx )
61
        if ( PKG_PQXX_FOUND )
62
            if ( ${PKG_PQXX_VERSION} VERSION_LESS 4.0 )
63
                set ( PQXX_VERSION 3 CACHE INTERNAL "PQXX version is 4" FORCE )
64
            else ( ${PKG_PQXX_VERSION} VERSION_LESS 4.0 )
65
                set ( PQXX_VERSION 4 CACHE INTERNAL "PQXX version is less than 4" FORCE )
66
            endif ( ${PKG_PQXX_VERSION} VERSION_LESS 4.0 )
67
        endif ( PKG_PQXX_FOUND )
68
    else ( PKG_CONFIG_FOUND )
69
        message( "PKG_CONFIG not found" )
70
    endif ( PKG_CONFIG_FOUND )
50 71
  else ( PQXX_HEADER_PATH AND PQXX_LIBRARY )
51 72
    message( "PQXX NOT FOUND" )
52 73
  endif ( PQXX_HEADER_PATH AND PQXX_LIBRARY )
include/logger.h
15 15
        : fout(),
16 16
          consoleLog(true)
17 17
    {}
18
    Logger(const std::string & fileName)
18
    explicit Logger(const std::string & fileName)
19 19
        : fout(fileName.c_str(), std::ios::app),
20 20
          consoleLog(!fout.is_open())
21 21
    {}
include/plugin.h
3 3

  
4 4
#include <string>
5 5

  
6
#include <boost/noncopyable.hpp>
7

  
8 6
#include "settings.h"
9 7
#include "nf.h"
10 8

  
11 9
namespace NF_ANALYZER {
12 10

  
13
class Plugin : private boost::noncopyable {
11
class Plugin {
14 12
    public:
15 13
        Plugin(const SettingsGroup & s) : _settings(s) {};
16 14
        virtual ~Plugin() {};
......
21 19

  
22 20
    protected:
23 21
        const SettingsGroup _settings;
22

  
23
        Plugin(const Plugin&) = delete;
24
        Plugin& operator=(const Plugin&) = delete;
24 25
};
25 26

  
26 27
}
include/settings.h
4 4
#include <string>
5 5
#include <map>
6 6

  
7
#include <boost/noncopyable.hpp>
8
//#include <boost/cstdint.hpp>
9 7
#include <boost/program_options.hpp>
10 8

  
11 9
namespace po = boost::program_options;
......
15 13
typedef std::map<std::string, std::string> SettingsGroup;
16 14
typedef std::map<std::string, SettingsGroup> Groups;
17 15

  
18
class Settings: private boost::noncopyable {
16
class Settings {
19 17
    public:
20
        Settings(const std::string & fileName);
18
        explicit Settings(const std::string & fileName);
21 19
        ~Settings();
22 20

  
23 21
        Groups::const_iterator begin() const { return _groups.begin(); };
......
28 26
        Groups _groups;
29 27

  
30 28
        bool parseFile(const std::string & fileName);
29

  
30
        Settings(const Settings&) = delete;
31
        Settings& operator=(const Settings&) = delete;
31 32
};
32 33

  
33 34
}
plugins/ia_sniffer/CMakeLists.txt
1 1
enable_language ( CXX )
2

  
3
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W -Wall -Wextra -std=c++0x")
4

  
2 5
find_package ( PQXX 2.6.9 REQUIRED )
3 6

  
4 7
set ( Boost_USE_STATIC_LIBS on )
5 8
set ( Boost_USE_MULTITHREADED on )
6 9
find_package ( Boost 1.41.0 REQUIRED COMPONENTS system thread )
7 10

  
11
include_directories ( ${Boost_INCLUDE_DIRS} )
8 12
include_directories ( ${PROJECT_SOURCE_DIR}/include )
9 13

  
10 14
file ( GLOB CPP_PLUGIN_FILES *.cpp )
plugins/ia_sniffer/ia_sniffer_plugin.cpp
120 120
        _connPtr->prepare(
121 121
                "add_activity",
122 122
                "SELECT sp_add_activity ($1, $2, $3)"
123
        )("INET", pqxx::prepare::treat_string)("INET", pqxx::prepare::treat_string)("TIMESTAMP WITHOUT TIME ZONE", pqxx::prepare::treat_string);
123
        );
124 124

  
125 125
    }
126 126
    catch (std::exception & ex) {
......
204 204

  
205 205
void IASniffer::_flush(const Flows & flows)
206 206
{
207
    char srcIP[32];
208
    char dstIP[32];
209 207
    try {
210 208
        pqxx::work xaction(*_connPtr, "Flush transaction");
211 209

  
......
219 217
                        _servers.end(),
220 218
                        it->first.dstAddr
221 219
                )) {
220
                char srcIP[32];
222 221
                if (inet_ntop(AF_INET, &it->first.srcAddr, srcIP, sizeof(srcIP)) == NULL) {
223 222
                    std::cerr << "Source IP conversion failed: '" << strerror(errno) << "'" << std::endl;
224 223
                    return;
225 224
                }
225
                char dstIP[32];
226 226
                if (inet_ntop(AF_INET, &it->first.dstAddr, dstIP, sizeof(dstIP)) == NULL) {
227 227
                    std::cerr << "Destination IP conversion failed: '" << strerror(errno) << "'" << std::endl;
228 228
                    return;
plugins/ia_sniffer/ia_sniffer_plugin.h
22 22

  
23 23
class IASniffer : public Plugin {
24 24
    public:
25
        IASniffer(const SettingsGroup & s);
25
        explicit IASniffer(const SettingsGroup & s);
26 26
        ~IASniffer();
27 27

  
28 28
        void analyze(const NF_DATA * flow, uint32_t timeCorrection);
plugins/port_sniffer/CMakeLists.txt
1 1
enable_language ( CXX )
2

  
3
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W -Wall -Wextra -std=c++0x")
4

  
2 5
find_package ( PQXX 2.6.9 REQUIRED )
3 6

  
4 7
set ( Boost_USE_STATIC_LIBS on )
5 8
set ( Boost_USE_MULTITHREADED on )
6 9
find_package ( Boost 1.41.0 REQUIRED COMPONENTS system thread )
7 10

  
11
include_directories ( ${Boost_INCLUDE_DIRS} )
8 12
include_directories ( ${PROJECT_SOURCE_DIR}/include )
9 13

  
10 14
file ( GLOB CPP_PLUGIN_FILES *.cpp )
plugins/port_sniffer/port_sniffer_plugin.cpp
110 110
        _connPtr->prepare(
111 111
                "add_ports_activity",
112 112
                "SELECT sp_add_ports_activity ($1, $2, $3, $4, $5)"
113
        )("INET", pqxx::prepare::treat_string)("INET", pqxx::prepare::treat_string)("INTEGER", pqxx::prepare::treat_direct)("INTEGER", pqxx::prepare::treat_direct)("TIMESTAMP WITHOUT TIME ZONE", pqxx::prepare::treat_string);
113
        );
114 114

  
115 115
    }
116 116
    catch (std::exception & ex) {
......
194 194

  
195 195
void PortSniffer::_flush(const Flows & flows)
196 196
{
197
    char srcIP[32];
198
    char dstIP[32];
199 197
    try {
200 198
        pqxx::work xaction(*_connPtr, "Flush transaction");
201 199

  
......
205 203

  
206 204
        while (it != flows.end()) {
207 205
            if (_servers.empty()) {
206
                char srcIP[32];
208 207
                if (inet_ntop(AF_INET, &it->first.srcAddr, srcIP, sizeof(srcIP)) == NULL) {
209 208
                    std::cerr << "Source IP conversion failed: '" << strerror(errno) << "'" << std::endl;
210 209
                    return;
211 210
                }
211
                char dstIP[32];
212 212
                if (inet_ntop(AF_INET, &it->first.dstAddr, dstIP, sizeof(dstIP)) == NULL) {
213 213
                    std::cerr << "Destination IP conversion failed: '" << strerror(errno) << "'" << std::endl;
214 214
                    return;
......
218 218
                        _servers.begin(),
219 219
                        _servers.end(),
220 220
                        it->first.dstAddr)) {
221
                char srcIP[32];
221 222
                if (inet_ntop(AF_INET, &it->first.srcAddr, srcIP, sizeof(srcIP)) == NULL) {
222 223
                    std::cerr << "Source IP conversion failed: '" << strerror(errno) << "'" << std::endl;
223 224
                    return;
224 225
                }
226
                char dstIP[32];
225 227
                if (inet_ntop(AF_INET, &it->first.dstAddr, dstIP, sizeof(dstIP)) == NULL) {
226 228
                    std::cerr << "Destination IP conversion failed: '" << strerror(errno) << "'" << std::endl;
227 229
                    return;
plugins/port_sniffer/port_sniffer_plugin.h
23 23

  
24 24
class PortSniffer : public Plugin {
25 25
    public:
26
        PortSniffer(const SettingsGroup & s);
26
        explicit PortSniffer(const SettingsGroup & s);
27 27
        ~PortSniffer();
28 28

  
29 29
        void analyze(const NF_DATA * flow, uint32_t timeCorrection);
plugins/syn_flood/CMakeLists.txt
1 1
enable_language ( CXX )
2 2

  
3
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W -Wall -Wextra -std=c++0x")
4

  
5
set ( Boost_USE_STATIC_LIBS on )
6
set ( Boost_USE_MULTITHREADED on )
7
find_package ( Boost 1.41.0 REQUIRED COMPONENTS system thread program_options )
8

  
9
include_directories ( ${Boost_INCLUDE_DIRS} )
3 10
include_directories ( ${nfa_SOURCE_DIR}/include )
4 11

  
5 12
file ( GLOB CPP_PLUGIN_FILES *.cpp )
plugins/syn_flood/syn_flood_plugin.cpp
34 34
                std::cerr << "[" << now << "] Source IP conversion failed: '" << strerror(errno) << "'" << std::endl;
35 35
                return;
36 36
            }
37
            if (inet_ntop(AF_INET, &flow->srcAddr, srcIP, sizeof(srcIP)) == NULL) {
37
            if (inet_ntop(AF_INET, &flow->dstAddr, dstIP, sizeof(dstIP)) == NULL) {
38 38
                std::cerr << "[" << now << "] Destination IP conversion failed: '" << strerror(errno) << "'" << std::endl;
39 39
                return;
40 40
            }
plugins/syn_flood/syn_flood_plugin.h
6 6
#include <vector>
7 7
#include <map>
8 8

  
9
#include <boost/cstdint.hpp>
9
#include <cstdint>
10 10

  
11 11
#include "plugin.h"
12 12
#include "settings.h"
......
15 15

  
16 16
class SYNFlood : public Plugin {
17 17
    public:
18
        SYNFlood(const SettingsGroup & s);
18
        explicit SYNFlood(const SettingsGroup & s);
19 19
        ~SYNFlood();
20 20

  
21 21
        void analyze(const NF_DATA * flow, uint32_t timeCorrection);
src/CMakeLists.txt
1 1
enable_language ( CXX )
2 2

  
3
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W -Wall -Wextra -std=c++0x")
4

  
3 5
set ( Boost_USE_STATIC_LIBS on )
4 6
set ( Boost_USE_MULTITHREADED on )
5 7
find_package ( Boost 1.41.0 REQUIRED COMPONENTS program_options system )
src/main.cpp
178 178

  
179 179
        struct sockaddr_in remoteAddr;
180 180
        socklen_t remoteAddrLen = sizeof(remoteAddr);
181
        size_t length = recvfrom(sd, buf, bufSize, 0, reinterpret_cast<struct sockaddr *>(&remoteAddr), &remoteAddrLen);
181
        int length = recvfrom(sd, buf, bufSize, 0, reinterpret_cast<struct sockaddr *>(&remoteAddr), &remoteAddrLen);
182 182
        if (length < 0) {
183 183
            if (errno == EINTR) {
184 184
                continue;
......
219 219
        return;
220 220
    }
221 221

  
222
    const int packetLength = sizeof(NF_HEADER) + count * sizeof(NF_DATA);
222
    const size_t packetLength = sizeof(NF_HEADER) + count * sizeof(NF_DATA);
223 223
    uint32_t timeCorrection = ntohl(packet->header.timestamp) - ntohl(packet->header.uptime) / 1000;
224 224
    if (packetLength > length) {
225 225
        logger << "processBuffer() - Not enought data. Packet length is " << packetLength << ", but actual data length is " << length << ". That's fatal, offcource." << std::endl;
src/pidfile.h
9 9
class PIDFile : private boost::noncopyable {
10 10
    public:
11 11
        PIDFile();
12
        PIDFile(const std::string & file);
12
        explicit PIDFile(const std::string & file);
13 13
        ~PIDFile();
14 14
    private:
15 15
        const std::string fileName;
src/settingsfileparser.cpp
42 42
    qi::rule<Iterator> comment, space, eol;
43 43
};
44 44

  
45
inline
46
bool sectionExists(const Groups & data, const std::string & sectionName) throw()
47
{
48
    return data.find(sectionName) != data.end();
49
}
50

  
51
inline
52
bool fieldExists(const Groups & data, const std::string & sectionName, const std::string & fieldName) throw()
53
{
54
    const Groups::const_iterator sectionIterator(data.find(sectionName));
55
    if (sectionIterator == data.end())
56
        return false;
57
    return sectionIterator->second.find(fieldName) != sectionIterator->second.end();
58
}
59

  
60
inline
61
bool fieldValue(const Groups & data, const std::string & sectionName, const std::string & fieldName, std::string & value) throw()
62
{
63
    const Groups::const_iterator sectionIterator(data.find(sectionName));
64
    if (sectionIterator == data.end())
65
        return false;
66
    const SettingsGroup::const_iterator pairIterator(sectionIterator->second.find(fieldName));
67
    if (pairIterator == sectionIterator->second.end())
68
        return false;
69
    value = pairIterator->second;
70
    return true;
71
}
72

  
73 45
}
74 46

  
75 47
using NF_ANALYZER::Settings;
......
98 70
        logger << "Settings::parseFile() - failed to parse file '" << fileName << "'" << std::endl;
99 71
        return false;
100 72
    }
73

  
74
    return true;
101 75
}

Also available in: Unified diff