From: Josh Date: Mon, 1 Dec 2014 05:21:53 +0000 (-0600) Subject: updating CMake and Autofoo build systems X-Git-Tag: 3.0.0-233~1153 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=07d00da18d0009b467068e56896bf617472ff64d;p=thirdparty%2Fsnort3.git updating CMake and Autofoo build systems --- diff --git a/cmake/packaging_data.cmake b/cmake/packaging_data.cmake index ab1d6a612..0ff28822d 100644 --- a/cmake/packaging_data.cmake +++ b/cmake/packaging_data.cmake @@ -1,7 +1,13 @@ # use this target instead of 'make package_source' +add_custom_target(autotools + COMMAND autoreconf -isvf # FIXIT-L J -- should check for autotools the CMake way + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} +) + add_custom_target(dist COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target copy_manuals_to_source + COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target autotools COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target package_source COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target delete_manuals_in_source ) @@ -14,7 +20,6 @@ set (CPACK_PACKAGE_VERSION_MINOR "${SNORT_VERSION_MINOR}") set (CPACK_PACKAGE_VERSION_PATCH "${SNORT_VERSION_BUILD}") set (CPACK_PACKAGE_ICON "${CMAKE_SOURCE_DIR}/doc/images/snort.png") set (CPACK_PACKAGE_INSTALL_DIRECTORY "snort") -set (CPACK_PACKAGE_INSTALL_DIRECTORY "/usr/local") set (CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/COPYING") set (CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/doc/start.txt") set (CPACK_SOURCE_IGNORE_FILES "${CMAKE_BINARY_DIR}/*;tools/snort2lua/tests*;.git/*;.gitignore;m4/*") diff --git a/configure.ac b/configure.ac index 1bd14a03c..70342fa58 100644 --- a/configure.ac +++ b/configure.ac @@ -104,16 +104,26 @@ esac # Checks for programs. #-------------------------------------------------------------------------- -# FIXIT should not need AM_CONIDTIONAL() here +# FIXIT-L` should not need AM_CONDITIONAL() here AC_CHECK_PROG(have_asciidoc,asciidoc,yes,no) AM_CONDITIONAL(MAKE_HTML_DOC, [test "x$have_asciidoc" = "xyes"]) -# FIXIT should not need AM_CONIDTIONAL() here +# FIXIT-L should not need AM_CONDITIONAL() here AC_CHECK_PROG(have_dblatex,dblatex,yes,no) AM_CONDITIONAL(MAKE_PDF_DOC, [test "x$have_dblatex" = "xyes"]) +AC_CHECK_FILE($srcdir/doc/snort_manual.html, have_html_manual="yes", [ AC_CHECK_FILE($ac_confdir/doc/snort_manual.html, have_html_manual="yes") ] ) +AC_CHECK_FILE($srcdir/doc/snort_manual.pdf, have_pdf_manual="yes", [ AC_CHECK_FILE($ac_confdir/doc/snort_manual.pdf, have_pdf_manual="yes") ] ) +AC_CHECK_FILE($srcdir/doc/snort_manual.tgz, have_chunked_manual="yes", [ AC_CHECK_FILE($ac_confdir/doc/snort_manual.tgz, have_chunked_manual="yes") ] ) +AC_CHECK_FILE($srcdir/doc/images.tgz, have_images_manual="yes", [ AC_CHECK_FILE($ac_confdir/doc/images.tgz, have_images_manual="yes") ] ) + +AM_CONDITIONAL(HAVE_HTML_DOC, [test "x$have_html_manual" = "xyes"]) +AM_CONDITIONAL(HAVE_PDF_DOC, [test "x$have_pdf_manual" = "xyes"]) +AM_CONDITIONAL(HAVE_CHUNKED_DOC, [test "x$have_chunked_manual" = "xyes"]) +AM_CONDITIONAL(HAVE_IMAGES_DOC, [test "x$have_images_manual" = "xyes"]) + #-------------------------------------------------------------------------- # visibility foo #-------------------------------------------------------------------------- diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt index 8b9967318..beda417b6 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -107,9 +107,21 @@ else () NO_DEFAULT_PATH ) - add_to_list_if_true(EXTRA_DIST_PACKAGED SNORT_MANUAL_HTML_FOUND "snort_manual.html") - add_to_list_if_true(EXTRA_DIST_PACKAGED SNORT_MANUAL_TGZ_FOUND "snort_manual.tgz") - add_to_list_if_true(EXTRA_DIST_PACKAGED IMAGES_TGZ_FOUND "images.tgz") + if (SNORT_MANUAL_TGZ_FOUND) + + message(STATUS "unpacking Snort Manual") + + execute_process ( + COMMAND ${CMAKE_COMMAND} + -E tar xf ${CMAKE_CURRENT_LIST_DIR}/snort_manual.tgz + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + ) + set (SNORT_MANUAL_CHUNKED ${CMAKE_CURRENT_BINARY_DIR}/snort_manual.chunked) + endif() + + add_to_list_if_true(PACKAGED_DIST SNORT_MANUAL_TGZ_FOUND "snort_manual.tgz") + add_to_list_if_true(PACKAGED_DIST IMAGES_TGZ_FOUND "images.tgz") + add_to_list_if_true(PACKAGED_DIST SNORT_MANUAL_HTML_FOUND "snort_manual.html") mark_as_advanced (SNORT_MANUAL_HTML_FOUND) mark_as_advanced (SNORT_MANUAL_TGZ_FOUND) mark_as_advanced (IMAGES_TGZ_FOUND) @@ -131,7 +143,7 @@ else () NO_DEFAULT_PATH ) - add_to_list_if_true(EXTRA_DIST_PACKAGED SNORT_MANUAL_PDF_FOUND "snort_manual.pdf") + add_to_list_if_true(PACKAGED_DIST SNORT_MANUAL_PDF_FOUND "snort_manual.pdf") mark_as_advanced (SNORT_MANUAL_PDF_FOUND) endif () @@ -259,7 +271,7 @@ if (MAKE_PDF_DOC OR MAKE_HTML_DOC) OUTPUT ${output} COMMAND ${CMAKE_COMMAND} -E copy ${input} ${output} DEPENDS ${input} - COMMENT "Copying ${file} into binary directory" + COMMENT "Documents: Copying ${file} into binary directory" ) list(APPEND ALL_SOURCES "${CMAKE_CURRENT_BINARY_DIR}/${file}") @@ -305,8 +317,7 @@ add_custom_command(OUTPUT snort_manual.tgz --destination-dir=${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/snort_manual.txt COMMAND ${CMAKE_COMMAND} - -E tar - zcf snort_manual.tgz + -E tar zcf snort_manual.tgz ${CMAKE_CURRENT_BINARY_DIR}/snort_manual.chunked DEPENDS ${ALL_SOURCES} COMMENT "Documents: building snort_manual.tgz" @@ -330,15 +341,20 @@ add_custom_command(OUTPUT images.tgz # Specify binary path so we install the build manuals, not packaged manuals foreach (file ${EXTRA_DIST}) - list(APPEND EXTRA_DIST_BUILT "${CMAKE_CURRENT_BINARY_DIR}/${file}") + list(APPEND BUILT_DIST "${CMAKE_CURRENT_BINARY_DIR}/${file}") endforeach(file) -add_custom_target(snort_manuals ALL DEPENDS ${EXTRA_DIST_BUILT}) -install (FILES ${EXTRA_DIST_BUILT} DESTINATION "${SNORT_DATA_DIR}") -install (FILES ${EXTRA_DIST_PACKAGED} DESTINATION "${SNORT_DATA_DIR}") +add_custom_target(snort_manuals ALL DEPENDS ${BUILT_DIST}) +install (FILES ${BUILT_DIST} DESTINATION "${SNORT_DATA_DIR}") +install (FILES ${PACKAGED_DIST} DESTINATION "${SNORT_DATA_DIR}") install (FILES ${UNBUILT_SOURCES} DESTINATION "${SNORT_DATA_DIR}") +install (DIRECTORY ${SNORT_MANUAL_CHUNKED} DESTINATION "${SNORT_DATA_DIR}") - +set_property( + DIRECTORY + PROPERTY + ADDITIONAL_MAKE_CLEAN_FILES ${UNBUILT_SOURCES} snort_manual.chunked +) ############################################################################### diff --git a/doc/Makefile.am b/doc/Makefile.am index de9dfc1bc..b5b596398 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -49,6 +49,8 @@ $(BUILT_SOURCES) dist_doc_DATA = \ $(unbuilt_sources) +MANUALS = + if MAKE_HTML_DOC EXTRA_DIST = \ snort_manual.html \ @@ -59,8 +61,28 @@ if MAKE_PDF_DOC EXTRA_DIST += \ snort_manual.pdf endif + +else + +if HAVE_HTML_DOC +MANUALS += snort_manual.html +endif + +if HAVE_PDF_DOC +MANUALS += snort_manual.pdf +endif + +if HAVE_CHUNKED_DOC +MANUALS += snort_manual.tgz endif +if HAVE_IMAGES_DOC +MANUALS += images.tgz +endif +endif + + +doc_DATA = $(MANUALS) dist_doc_DATA += $(EXTRA_DIST) snort = $(top_builddir)/src/snort @@ -159,6 +181,8 @@ html_args = \ --attribute disable-javascript --attribute quirks! \ $(pdf_args) + +if MAKE_HTML_DOC # this is the docbook approach to html #snort_manual.html: snort_manual.txt $(all_sources) # a2x -f xhtml $(html_args) $< @@ -169,9 +193,6 @@ html_args = \ snort_manual.html: snort_manual.txt $(all_sources) asciidoc -b xhtml11 -a toc2 -a icons -a imagesdir=./images $< -snort_manual.pdf: snort_manual.txt $(all_sources) - a2x -f pdf $(pdf_args) $< - snort_manual.tgz: snort_manual.txt $(all_sources) a2x -f chunked $(html_args) $< tar zcf $@ -C snort_manual.chunked . @@ -183,6 +204,26 @@ images.tgz: images/ --exclude README \ . +if MAKE_PDF_DOC + +snort_manual.pdf: snort_manual.txt $(all_sources) + a2x -f pdf $(pdf_args) $< + +endif +endif + +if MAKE_HTML_DOC + +install-data-hook: + tar -xvf $(docdir)/snort_manual.tgz && mv snort_manual.chunked $(docdir) + +else +if HAVE_CHUNKED_DOC +install-data-hook: + tar -xf $(docdir)/snort_manual.tgz && mv snort_manual.chunked $(docdir) + +endif +endif delete_unbuilt = $(if $(and $(findstring $(builddir),$(srcdir)),$(findstring $(srcdir),$(builddir))), ,$(unbuilt_sources)) diff --git a/src/codecs/CMakeLists.txt b/src/codecs/CMakeLists.txt index 8345f565e..d4bbc7223 100644 --- a/src/codecs/CMakeLists.txt +++ b/src/codecs/CMakeLists.txt @@ -13,7 +13,6 @@ add_library( codecs STATIC ${CODEC_INCLUDES} codec_api.h codec_api.cc - template.cc # for development purposes. Keep the template up to date ) diff --git a/src/codecs/template.cc b/src/codecs/template.cc deleted file mode 100644 index a8615a861..000000000 --- a/src/codecs/template.cc +++ /dev/null @@ -1,287 +0,0 @@ -/* -** Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved. -** -** This program is free software; you can redistribute it and/or modify -** it under the terms of the GNU General Public License Version 2 as -** published by the Free Software Foundation. You may not use, modify or -** distribute this program under any other version of the GNU General -** Public License. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software -** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ -// template.cc author Josh Rosenbaum - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include // memcpy -#include "framework/codec.h" -#include "codecs/codec_module.h" -#include "protocols/packet.h" -#include "framework/module.h" -#include "log/text_log.h" - -// yes, macros are necessary. The API and class constructor require different strings. -// -// this macros is defined in the module to ensure identical names. However, -// if you don't want a module, define the name here. -#define CODEC_NAME "name" -#define CODEC_HELP "one line help for this codec" - -namespace -{ - -// inherit from CodecModule rather than Module so the GID for -// all codecs are identical. Additionally, all of the SIDS are -// defined in CodecModule. So, when creating new events, you -// only need to look for codec SID collisions in one locations -class NameModule : public CodecModule -{ -public: - NameModule(); - - bool set(const char*, Value&, SnortConfig*) override; - bool begin(const char*, int, SnortConfig*) override; - const RuleMap* get_rules() const override; - -private: - // any structs or options which will be used when constructing - // the Codec - bool option1; - -}; - - -static const Parameter codec_params[] = -{ - { "parameter1", Parameter::PT_BOOL, nullptr, "false", - "This is a boolean parameter" }, - - { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr } -}; - - -// rules which will loaded into snort. -// You can now reference these rules by calling a codec_event -// in your main codec's functions -const unsigned sid = 1; -static const RuleMap codec_rules[] = -{ - { sid, "alert message" }, - { 0, nullptr } -}; - -//------------------------------------------------------------------------- -// template module -//------------------------------------------------------------------------- - -NameModule::NameModule() : CodecModule(CODEC_NAME, CODEC_HELP, codec_params) -{ } - -bool NameModule::set(const char* /*fqn*/, Value& v, SnortConfig* /*sc*/) -{ - if ( v.is("parameter1") ) - option1 = v.get_bool(); - - else - return false; - - return true; -} - -bool NameModule::begin(const char*, int, SnortConfig*) -{ - option1 = false; - return true; -} - -const RuleMap* NameModule::get_rules() const -{ return codec_rules; } - - -class NameCodec : public Codec -{ -public: - NameCodec() : Codec(CODEC_NAME){}; - ~NameCodec() {}; - - - // decode(...) must be implemented!! - bool decode(const RawData&, CodecData&, DecodeData&) override; - - void log(TextLog*, const uint8_t* /*raw_pkt*/, const Packet* const) override; - void get_protocol_ids(std::vector&) override; - void get_data_link_type(std::vector&) override; - bool encode(const uint8_t* const raw_in, const uint16_t raw_len, - EncState&, Buffer&) override; - bool update(Packet*, Layer*, uint32_t* len) override; - void format(EncodeFlags, const Packet* p, Packet* c, Layer*) override; -}; - -// Create your own Hdr Struct for this layer! -struct NameHdr -{ - uint8_t ver; - uint8_t next_protocol; - uint16_t len; - // additional or different data -}; -//constexpr uint16_t NAME_HDR_LEN = 4; sizeof may return '8' on a 64 bit system - -} // namespace - - -void NameCodec::get_data_link_type(std::vector&/*v*/) -{ -// v.push_back(DLT_ID); -} - -void NameCodec::get_protocol_ids(std::vector&/*v*/) -{ -// v.push_back(PROTO_TYPE); -// v.push_back(ETHERTYPE); -} - -bool NameCodec::decode(const RawData& raw, CodecData& data, DecodeData&) -{ - // reinterpret the raw data into this codec's data format - const NameHdr* const hdr = - reinterpret_cast(raw.data); - - // DO SOME STUFF - - // set the fields which will be sent back to the packet manager - data.lyr_len = hdr->len; - data.next_prot_id = hdr->next_protocol; - - return true; -} - -void NameCodec::log(TextLog* const text_log, const uint8_t* raw_pkt, - const Packet* const) -{ - const NameHdr *hdr = reinterpret_cast(raw_pkt); - TextLog_Print(text_log, "Next:0x%04x", hdr->next_protocol); -} - -bool NameCodec::encode(const uint8_t* const raw_in, const uint16_t raw_len, - EncState& enc, Buffer& buf) -{ - - // allocate space for this protocols encoded data - if (buf.allocate(raw_len)) - return false; - - // ALTERNATIVELY, if you knwo the exact length you want to add - // if (!buf.allocate(NAME_HDR_LEN) // sizeof gives the padded result == not always accurate - // return nullptr; - - // MUST BE DONE AFTER UPDATE_BUFFER!! - // get a pointer to the raw packet input and output buffer. - - // copy raw input and new output. You probably want to do - // something slightly more useful. - memcpy(buf.base, raw_in, raw_len); - - // set any fields that we want - NameHdr* const hdr = reinterpret_cast(buf.base); - hdr->next_protocol = enc.next_proto; // set the 'next' field to the appropriate value. - // The origin next may not have been copied - hdr->len = buf.size(); // set the size to be the length from the begining of this - // packet to the end of the struct. - -// enc.next_proto = PROTO_TYPE; -// enc.next_ethertype = ETHERTYPE; - return true; -} - -bool NameCodec::update(Packet*, Layer*, uint32_t* /*len*/) -{ - return true; -} - -void NameCodec::format(EncodeFlags, - const Packet* /*p*/, - Packet* /*c*/, - Layer* /*l*/) -{ -} - - - -//------------------------------------------------------------------------- -// api -//------------------------------------------------------------------------- - -/* - * Modules create custom configuration options which can be used in snort.lua. - * If you don't want any configuration options, remove the mod_ctor - * and mod_dtor functions from the api below. See documentation for additional - * details regarding Modules - */ -static Module* mod_ctor() -{ return new NameModule; } - -static void mod_dtor(Module* m) -{ delete m; } - -// initialize global variables -static void ginit() -{ } - -// cleanup any global variables -static void gterm() -{ } - -// initialize thread_local variables -static void tinit() -{ } - -// cleanup any thread_local variables -static void tterm() -{ } - -static Codec* ctor(Module*) -{ return new NameCodec(); } - -static void dtor(Codec *cd) -{ delete cd; } - - -static const CodecApi name_api = -{ - { - PT_CODEC, - CODEC_NAME, - CODEC_HELP, - CDAPI_PLUGIN_V0, - 0, - mod_ctor, // module constructor ( see function for details ) - mod_dtor // module destructor ( see function for details ) - }, - ginit, // global initializer - gterm, // global terminate - tinit, // thread local initializer - tterm, // thread local terminate - ctor, // constructor --> REQUIRED. return a newly create Codec - dtor, // desctructor --> REQUIRED. destory the Codec. -}; - - -#ifdef BUILDING_SO -SO_PUBLIC const BaseApi* snort_plugins[] = -{ - &name_api.base, - nullptr -}; -#else -const BaseApi* cd_name = &name_api.base; -#endif diff --git a/src/detection/generators.h b/src/detection/generators.h deleted file mode 100644 index 4eb399f08..000000000 --- a/src/detection/generators.h +++ /dev/null @@ -1,37 +0,0 @@ -/* -** Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved. -** Copyright (C) 2002-2013 Sourcefire, Inc. -** Copyright (C) 1998-2002 Martin Roesch -** -** This program is free software; you can redistribute it and/or modify -** it under the terms of the GNU General Public License Version 2 as -** published by the Free Software Foundation. You may not use, modify or -** distribute this program under any other version of the GNU General -** Public License. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software -** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ - -#ifndef GENERATORS_H -#define GENERATORS_H - -// FIXIT-M migrate all defines to respective modules and delete this file - -#define GENERATOR_SNORT_ENGINE 1 - -#define GENERATOR_INTERNAL 135 -#define INTERNAL_EVENT_SYN_RECEIVED 1 -#define INTERNAL_EVENT_SESSION_ADD 2 -#define INTERNAL_EVENT_SESSION_DEL 3 - -#define GENERATOR_SPP_REPUTATION 136 - -#endif - diff --git a/src/framework/content_buffer.h b/src/framework/content_buffer.h deleted file mode 100644 index a5b410dc6..000000000 --- a/src/framework/content_buffer.h +++ /dev/null @@ -1,31 +0,0 @@ -/* -** Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved. -** -** This program is free software; you can redistribute it and/or modify -** it under the terms of the GNU General Public License Version 2 as -** published by the Free Software Foundation. You may not use, modify or -** distribute this program under any other version of the GNU General -** Public License. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software -** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ -// content_buffer.h author Russ Combs - -#ifndef CONTENT_BUFFER_H -#define CONTENT_BUFFER_H - -struct ContentBuffer -{ - const uint8_t* buf; - unsigned len; -}; - -#endif - diff --git a/src/ips_options/ips_file_data.h b/src/ips_options/ips_file_data.h deleted file mode 100644 index df605f4f1..000000000 --- a/src/ips_options/ips_file_data.h +++ /dev/null @@ -1,27 +0,0 @@ -/* -** Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved. -** Copyright (C) 2003-2013 Sourcefire, Inc. -** -** -** This program is free software; you can redistribute it and/or modify -** it under the terms of the GNU General Public License Version 2 as -** published by the Free Software Foundation. You may not use, modify or -** distribute this program under any other version of the GNU General -** Public License. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software -** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ - -#ifndef IPS_FILE_DATA_H -#define IPS_FILE_DATA_H - -bool decode_mime_file_data(void*); - -#endif diff --git a/src/service_inspectors/ftp_telnet/ftpp_ui_client_lookup.cc b/src/service_inspectors/ftp_telnet/ftpp_ui_client_lookup.cc deleted file mode 100644 index 70e0b1ee7..000000000 --- a/src/service_inspectors/ftp_telnet/ftpp_ui_client_lookup.cc +++ /dev/null @@ -1,308 +0,0 @@ -/* - * ftpp_ui_client_lookup.c - * -** Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved. - * Copyright (C) 2004-2013 Sourcefire, Inc. - * Steven A. Sturges - * Daniel J. Roelker - * Marc A. Norton - * Kevin Liu - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License Version 2 as - * published by the Free Software Foundation. You may not use, modify or - * distribute this program under any other version of the GNU General - * Public License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Description: - * - * This file contains functions to access the CLIENT_LOOKUP structure. - * - * We wrap the access to CLIENT_LOOKUP so changing the lookup algorithms - * are more modular and independent. This is the only file that would need - * to be changed to change the algorithmic lookup. - * - * NOTES: - * - 16.09.04: Initial Development. SAS - * - */ -#include -#include -#include - -#include "hi_util_kmap.h" -#include "ftpp_ui_config.h" -#include "ftpp_return_codes.h" -#include "ft_main.h" -#include "sfrt/sfrt.h" - -static void clientConfFree(void *pData); - -/* - * Function: ftpp_ui_client_lookup_init(CLIENT_LOOKUP **ClientLookup) - * - * Purpose: Initialize the client_lookup structure. - * - * We need to initialize the client_lookup structure for - * the FTP client configuration. Don't want a NULL pointer - * flying around, when we have to look for FTP clients. - * - * Arguments: ClientLookup => pointer to the pointer of the client - * lookup structure. - * - * Returns: int => return code indicating error or success - * - */ -#define FTPP_UI_CONFIG_MAX_CLIENTS 20 -int ftpp_ui_client_lookup_init(CLIENT_LOOKUP **ClientLookup) -{ - *ClientLookup = sfrt_new(DIR_16_4x4_16x5_4x4, IPv6, FTPP_UI_CONFIG_MAX_CLIENTS, 20); - - if(*ClientLookup == NULL) - { - return FTPP_MEM_ALLOC_FAIL; - } - - return FTPP_SUCCESS; -} - -/* - * Function: ftpp_ui_client_lookup_cleanup(CLIENT_LOOKUP **ClientLookup) - * - * Purpose: Free the client_lookup structure. - * We need to free the client_lookup structure. - * - * Arguments: ClientLookup => pointer to the pointer of the client - * lookup structure. - * - * Returns: int => return code indicating error or success - * - */ -int ftpp_ui_client_lookup_cleanup(CLIENT_LOOKUP **ClientLookup) -{ - if ((ClientLookup == NULL) || (*ClientLookup == NULL)) - return FTPP_INVALID_ARG; - - sfrt_cleanup(*ClientLookup, clientConfFree); - sfrt_free(*ClientLookup); - *ClientLookup = NULL; - - return FTPP_SUCCESS; -} - -/* - * Function: ftpp_ui_client_lookup_add(CLIENT_LOOKUP *ClientLookup, - * sfip_t* Ip, - * FTP_CLIENT_PROTO_CONF *ClientConf) - * - * Purpose: Add a client configuration to the list. - * We add these keys like you would normally think to add - * them, because on low endian machines the least significant - * byte is compared first. This is what we want to compare - * IPs backward, doesn't work on high endian machines, but oh - * well. Our platform is Intel. - * - * Arguments: ClientLookup => a pointer to the lookup structure - * IP => the ftp client address - * ClientConf => a pointer to the client configuration structure - * - * Returns: int => return code indicating error or success - * - */ -int ftpp_ui_client_lookup_add( - CLIENT_LOOKUP *ClientLookup, - sfip_t* Ip, FTP_CLIENT_PROTO_CONF *ClientConf) -{ - int iRet; - - if(!ClientLookup || !ClientConf) - { - return FTPP_INVALID_ARG; - } - - iRet = sfrt_insert((void *)Ip, (unsigned char)Ip->bits, - (void *)ClientConf, RT_FAVOR_SPECIFIC, ClientLookup); - - if (iRet) - { - /* - * This means the key has already been added. - */ - if(iRet == 1) - { - return FTPP_NONFATAL_ERR; - } - else - { - return FTPP_MEM_ALLOC_FAIL; - } - } - - return FTPP_SUCCESS; -} - -/* - * Function: ftpp_ui_client_lookup_find(CLIENT_LOOKUP *ClientLookup, - * const sfip_t *ip, int *iError) - * - * Purpose: Find a client configuration given a IP. - * We look up a client configuration given an IP and - * return a pointer to that client configuration if found. - * - * Arguments: ClientLookup => a pointer to the lookup structure - * IP => the ftp client address - * iError => a pointer to an error code - * - * Returns: int => return code indicating error or success - * - * Returns: FTP_CLIENT_PROTO_CONF* => Pointer to client configuration - * structure matching IP if found, NULL otherwise. - * - */ - -FTP_CLIENT_PROTO_CONF *ftpp_ui_client_lookup_find(CLIENT_LOOKUP *ClientLookup, - const sfip_t *Ip, int *iError) -{ - FTP_CLIENT_PROTO_CONF *ClientConf = NULL; - - if(!iError) - { - return NULL; - } - - if(!ClientLookup) - { - *iError = FTPP_INVALID_ARG; - return NULL; - } - - *iError = FTPP_SUCCESS; - - ClientConf = (FTP_CLIENT_PROTO_CONF *)sfrt_lookup((void *)Ip, ClientLookup); - if (!ClientConf) - { - *iError = FTPP_NOT_FOUND; - } - - return ClientConf; -} - -#if 0 -/** Obsoleted. After changing underlying KMAP to SFRT. SFRT provides an iterator with - * a callback function but does not support getFirst, getNext operations. - */ -/* - * Function: ftpp_ui_client_lookup_first(CLIENT_LOOKUP *ClientLookup, - * int *iError) - * - * Purpose: This lookups the first client configuration, so we can - * iterate through the configurations. - * - * Arguments: ClientLookup => pointer to the client lookup structure - * iError => pointer to the integer to set for errors - * - * Returns: FTP_CLIENT_PROTO_CONF* => Pointer to first client configuration - * structure - * - */ -FTP_CLIENT_PROTO_CONF *ftpp_ui_client_lookup_first(CLIENT_LOOKUP *ClientLookup, - int *iError) -{ - FTP_CLIENT_PROTO_CONF *ClientConf; - - if(!iError) - { - return NULL; - } - - if(!ClientLookup) - { - *iError = FTPP_INVALID_ARG; - return NULL; - } - - *iError = FTPP_SUCCESS; - - ClientConf = (FTP_CLIENT_PROTO_CONF *)KMapFindFirst(ClientLookup); - if (!ClientConf) - { - *iError = FTPP_NOT_FOUND; - } - - return ClientConf; -} - -/* - * Function: ftpp_ui_client_lookup_next(CLIENT_LOOKUP *ClientLookup, - * int *iError) - * - * Iterates to the next configuration, like a list it just returns - * the next config in the config list. - * - * Purpose: This lookups the next client configuration, so we can - * iterate through the configurations. - * - * Arguments: ClientLookup => pointer to the client lookup structure - * iError => pointer to the integer to set for errors - * - * Returns: FTP_CLIENT_PROTO_CONF* => Pointer to next client configuration - * structure - * - */ -FTP_CLIENT_PROTO_CONF *ftpp_ui_client_lookup_next(CLIENT_LOOKUP *ClientLookup, - int *iError) -{ - FTP_CLIENT_PROTO_CONF *ClientConf; - - if(!iError) - { - return NULL; - } - - if(!ClientLookup) - { - *iError = FTPP_INVALID_ARG; - return NULL; - } - - *iError = FTPP_SUCCESS; - - ClientConf = (FTP_CLIENT_PROTO_CONF *)KMapFindNext(ClientLookup); - if (!ClientConf) - { - *iError = FTPP_NOT_FOUND; - } - - return ClientConf; -} -#endif - -/**Free pData buffer, which may be referenced multiple times. ReferenceCount - * is the number of times the buffer is referenced. For freeing the buffer, - * we just decrement referenceCount till it reaches 0, at which time the - * buffer is also freed. - */ -static void clientConfFree(void *pData) -{ - FTP_CLIENT_PROTO_CONF *clientConf = (FTP_CLIENT_PROTO_CONF *)pData; - - if (clientConf) - { - clientConf->referenceCount--; - if (clientConf->referenceCount == 0) - { - FTPTelnetCleanupFTPClientConf((void *)clientConf); - free(clientConf); - } - } -} - diff --git a/src/service_inspectors/ftp_telnet/ftpp_ui_client_lookup.h b/src/service_inspectors/ftp_telnet/ftpp_ui_client_lookup.h deleted file mode 100644 index 7fb3c7fb3..000000000 --- a/src/service_inspectors/ftp_telnet/ftpp_ui_client_lookup.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * ftpp_ui_client_lookup.h - * -** Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved. - * Copyright (C) 2004-2013 Sourcefire, Inc. - * Steven A. Sturges - * Daniel J. Roelker - * Marc A. Norton - * Kevin Liu - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License Version 2 as - * published by the Free Software Foundation. You may not use, modify or - * distribute this program under any other version of the GNU General - * Public License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Description: - * - * This file contains function definitions for client lookups. - * - * NOTES: - * - 16.09.04: Initial Development. SAS - * - */ -#ifndef FTPP_UI_CLIENT_LOOKUP_H -#define FTPP_UI_CLIENT_LOOKUP_H - -#include "ftpp_include.h" -#include "ftpp_ui_config.h" - -int ftpp_ui_client_lookup_init(CLIENT_LOOKUP **ClientLookup); -int ftpp_ui_client_lookup_cleanup(CLIENT_LOOKUP **ClientLookup); -int ftpp_ui_client_lookup_add(CLIENT_LOOKUP *ClientLookup, sfip_t * IP, - FTP_CLIENT_PROTO_CONF *ClientConf); - -FTP_CLIENT_PROTO_CONF *ftpp_ui_client_lookup_find(CLIENT_LOOKUP *ClientLookup, - const sfip_t *Ip, int *iError); -FTP_CLIENT_PROTO_CONF *ftpp_ui_client_lookup_first(CLIENT_LOOKUP *ClientLookup, - int *iError); -FTP_CLIENT_PROTO_CONF *ftpp_ui_client_lookup_next(CLIENT_LOOKUP *ClientLookup, - int *iError); - -#endif