diff --git a/CMakeLists.txt b/CMakeLists.txt index ce01d25b12..f1a5e0b772 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,14 +35,16 @@ endif () ## Project/Build Configuration set(BRO_ROOT_DIR ${CMAKE_INSTALL_PREFIX}) -if (NOT POLICYDIR) - # set the default policy installation path (user did not specify one) - set(POLICYDIR ${BRO_ROOT_DIR}/share/bro) +if (NOT BRO_SCRIPT_INSTALL_PATH) + # set the default Bro script installation path (user did not specify one) + set(BRO_SCRIPT_INSTALL_PATH ${BRO_ROOT_DIR}/share/bro) endif () +set(BRO_SCRIPT_SOURCE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/scripts) -# sanitize the policy install directory into an absolute path +# sanitize the Bro script install directory into an absolute path # (CMake is confused by ~ as a representation of home directory) -get_filename_component(POLICYDIR ${POLICYDIR} ABSOLUTE) +get_filename_component(BRO_SCRIPT_INSTALL_PATH ${BRO_SCRIPT_INSTALL_PATH} + ABSOLUTE) configure_file(bro-path-dev.in ${CMAKE_CURRENT_BINARY_DIR}/bro-path-dev) file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/bro-path-dev.sh @@ -212,7 +214,7 @@ message( "\n====================| Bro Build Summary |=====================" "\n" "\nInstall prefix: ${CMAKE_INSTALL_PREFIX}" - "\nPolicy dir: ${POLICYDIR}" + "\nBro Script Path: ${BRO_SCRIPT_INSTALL_PATH}" "\nDebug mode: ${ENABLE_DEBUG}" "\n" "\nCC: ${CMAKE_C_COMPILER}" diff --git a/bro-path-dev.in b/bro-path-dev.in index 57cc8fb2df..81d4f111fc 100755 --- a/bro-path-dev.in +++ b/bro-path-dev.in @@ -1,7 +1,7 @@ #!/bin/sh -# After configured by CMake, this file prints the absolute path to policy -# files that come with the source distributions of Bro as well as policy -# files that are generated by the BIF compiler at compile time. +# After configured by CMake, this file prints the absolute path to Bro scripts +# that come with the source distributions of Bro as well as scripts that are +# generated by the BIF compiler at compile time. # # The intended use of this script is to make it easier to run Bro from # the build directory, avoiding the need to install it. This could be @@ -10,10 +10,10 @@ # BROPATH=`./bro-path-dev` ./src/bro # -broPolicies=${PROJECT_SOURCE_DIR}/scripts:${PROJECT_SOURCE_DIR}/scripts/policy:${PROJECT_SOURCE_DIR}/scripts/site +broPolicies=${BRO_SCRIPT_SOURCE_PATH}:${BRO_SCRIPT_SOURCE_PATH}/policy:${BRO_SCRIPT_SOURCE_PATH}/site broGenPolicies=${CMAKE_BINARY_DIR}/src -installedPolicies=${POLICYDIR}:${POLICYDIR}/site +installedPolicies=${BRO_SCRIPT_INSTALL_PATH}:${BRO_SCRIPT_INSTALL_PATH}/site echo .:$broPolicies:$broGenPolicies diff --git a/configure b/configure index 7df0e8b759..2e168f0550 100755 --- a/configure +++ b/configure @@ -22,7 +22,7 @@ Usage: $0 [OPTION]... [VAR=VALUE]... Installation Directories: --prefix=PREFIX installation directory [/usr/local/bro] - --policydir=PATH policy file installation directory + --scriptdir=PATH root installation directory for Bro scripts [PREFIX/share/bro] Optional Features: @@ -85,7 +85,7 @@ CMakeCacheEntries="" append_cache_entry CMAKE_INSTALL_PREFIX PATH /usr/local/bro append_cache_entry BRO_ROOT_DIR PATH /usr/local/bro append_cache_entry PY_MOD_INSTALL_DIR PATH /usr/local/bro/lib/broctl -append_cache_entry POLICYDIR STRING /usr/local/bro/share/bro +append_cache_entry BRO_SCRIPT_INSTALL_PATH STRING /usr/local/bro/share/bro append_cache_entry ENABLE_DEBUG BOOL false append_cache_entry BROv6 BOOL false append_cache_entry ENABLE_PERFTOOLS BOOL false @@ -118,13 +118,13 @@ while [ $# -ne 0 ]; do append_cache_entry CMAKE_INSTALL_PREFIX PATH $optarg append_cache_entry BRO_ROOT_DIR PATH $optarg append_cache_entry PY_MOD_INSTALL_DIR PATH $optarg/lib/broctl - if [ "$user_set_policydir" != "true" ]; then - append_cache_entry POLICYDIR STRING $optarg/share/bro + if [ "$user_set_scriptdir" != "true" ]; then + append_cache_entry BRO_SCRIPT_INSTALL_PATH STRING $optarg/share/bro fi ;; - --policydir=*) - append_cache_entry POLICYDIR STRING $optarg - user_set_policydir="true" + --scriptdir=*) + append_cache_entry BRO_SCRIPT_INSTALL_PATH STRING $optarg + user_set_scriptdir="true" ;; --enable-debug) append_cache_entry ENABLE_DEBUG BOOL true diff --git a/doc/scripts/CMakeLists.txt b/doc/scripts/CMakeLists.txt index 02d24ee88a..cb7a42929c 100644 --- a/doc/scripts/CMakeLists.txt +++ b/doc/scripts/CMakeLists.txt @@ -57,10 +57,12 @@ macro(REST_TARGET srcDir broInput) get_filename_component(relDstDir ${broInput} PATH) set(sumTextSrc ${absSrcPath}) + set(ogSourceFile ${absSrcPath}) if (${extension} STREQUAL ".bif.bro") + set(ogSourceFile ${BIF_SRC_DIR}/${basename}) # the summary text is taken at configure time, but .bif.bro files # may not have been generated yet, so read .bif file instead - set(sumTextSrc ${BIF_SRC_DIR}/${basename}) + set(sumTextSrc ${ogSourceFile}) endif () if (NOT relDstDir) @@ -124,9 +126,9 @@ macro(REST_TARGET srcDir broInput) ARGS -E make_directory ${dstDir} COMMAND "${CMAKE_COMMAND}" ARGS -E copy ${restFile} ${restOutput} - # copy the bro policy script, too + # copy the bro or bif script, too COMMAND "${CMAKE_COMMAND}" - ARGS -E copy ${absSrcPath} ${dstDir} + ARGS -E copy ${ogSourceFile} ${dstDir} # clean up the build directory COMMAND rm ARGS -rf .state *.log *.rst @@ -151,6 +153,8 @@ set(MASTER_PKG_INDEX_TEXT "") foreach (pkg ${MASTER_PKG_LIST}) # strip of the trailing /index for the link name get_filename_component(lnktxt ${pkg} PATH) + # pretty-up the link name by removing common scripts/ prefix + string(REPLACE "scripts/" "" lnktxt "${lnktxt}") set(MASTER_PKG_INDEX_TEXT "${MASTER_PKG_INDEX_TEXT}\n ${lnktxt} <${pkg}>") endforeach () file(WRITE ${MASTER_PACKAGE_INDEX} "${MASTER_PKG_INDEX_TEXT}") diff --git a/doc/scripts/DocSourcesList.cmake b/doc/scripts/DocSourcesList.cmake index 38f68f53db..54783f61b3 100644 --- a/doc/scripts/DocSourcesList.cmake +++ b/doc/scripts/DocSourcesList.cmake @@ -13,22 +13,14 @@ set(psd ${PROJECT_SOURCE_DIR}/scripts) rest_target(${CMAKE_CURRENT_SOURCE_DIR} example.bro internal) -rest_target(${psd} base/bro.init internal) -rest_target(${psd} base/all.bro internal) +rest_target(${psd} base/init-default.bro internal) +rest_target(${psd} base/init-bare.bro internal) rest_target(${CMAKE_BINARY_DIR}/src bro.bif.bro) -rest_target(${CMAKE_BINARY_DIR}/src common-rw.bif.bro) rest_target(${CMAKE_BINARY_DIR}/src const.bif.bro) -rest_target(${CMAKE_BINARY_DIR}/src dns-rw.bif.bro) rest_target(${CMAKE_BINARY_DIR}/src event.bif.bro) -rest_target(${CMAKE_BINARY_DIR}/src finger-rw.bif.bro) -rest_target(${CMAKE_BINARY_DIR}/src ftp-rw.bif.bro) -rest_target(${CMAKE_BINARY_DIR}/src http-rw.bif.bro) -rest_target(${CMAKE_BINARY_DIR}/src ident-rw.bif.bro) rest_target(${CMAKE_BINARY_DIR}/src logging.bif.bro) rest_target(${CMAKE_BINARY_DIR}/src reporter.bif.bro) -rest_target(${CMAKE_BINARY_DIR}/src smb-rw.bif.bro) -rest_target(${CMAKE_BINARY_DIR}/src smtp-rw.bif.bro) rest_target(${CMAKE_BINARY_DIR}/src strings.bif.bro) rest_target(${CMAKE_BINARY_DIR}/src types.bif.bro) rest_target(${psd} base/frameworks/cluster/main.bro) @@ -56,6 +48,7 @@ rest_target(${psd} base/frameworks/packet-filter/netstats.bro) rest_target(${psd} base/frameworks/reporter/main.bro) rest_target(${psd} base/frameworks/signatures/main.bro) rest_target(${psd} base/frameworks/software/main.bro) +rest_target(${psd} base/frameworks/time-machine/notice.bro) rest_target(${psd} base/protocols/conn/contents.bro) rest_target(${psd} base/protocols/conn/inactivity.bro) rest_target(${psd} base/protocols/conn/main.bro) @@ -72,6 +65,11 @@ rest_target(${psd} base/protocols/http/partial-content.bro) rest_target(${psd} base/protocols/http/utils.bro) rest_target(${psd} base/protocols/irc/dcc-send.bro) rest_target(${psd} base/protocols/irc/main.bro) +rest_target(${psd} base/protocols/mime/base.bro) +rest_target(${psd} base/protocols/mime/file-extract.bro) +rest_target(${psd} base/protocols/mime/file-hash.bro) +rest_target(${psd} base/protocols/mime/file-ident.bro) +rest_target(${psd} base/protocols/rpc/base.bro) rest_target(${psd} base/protocols/smtp/main.bro) rest_target(${psd} base/protocols/ssh/main.bro) rest_target(${psd} base/protocols/ssl/consts.bro) @@ -105,7 +103,6 @@ rest_target(${psd} policy/misc/loaded-scripts.bro) rest_target(${psd} policy/misc/trim-trace-file.bro) rest_target(${psd} policy/protocols/conn/known-hosts.bro) rest_target(${psd} policy/protocols/conn/known-services.bro) -rest_target(${psd} policy/protocols/conn/scan.bro) rest_target(${psd} policy/protocols/dns/auth-addl.bro) rest_target(${psd} policy/protocols/dns/detect-external-names.bro) rest_target(${psd} policy/protocols/ftp/detect.bro) diff --git a/doc/scripts/README b/doc/scripts/README index bd7ec5c065..ca7f28492b 100644 --- a/doc/scripts/README +++ b/doc/scripts/README @@ -44,7 +44,7 @@ of documentation targets. This script should be run after adding new Bro script source files, and the changes commited to git. If a script shouldn't have documentation generated for it, there's also a -blacklist variable that can be maintained in the ``genDocSourcesList.sh`` +blacklist manifest that can be maintained in the ``genDocSourcesList.sh`` script. The blacklist can also be used if you want to define a certain grouping for diff --git a/doc/scripts/genDocSourcesList.sh b/doc/scripts/genDocSourcesList.sh index 0783884372..8ef4ff9c14 100755 --- a/doc/scripts/genDocSourcesList.sh +++ b/doc/scripts/genDocSourcesList.sh @@ -11,8 +11,31 @@ # Specific scripts can be blacklisted below when e.g. they currently aren't # parseable or they just aren't meant to be documented. -blacklist="__load__.bro|test-all.bro|all.bro" -blacklist_addl="hot.conn.bro" +blacklist () + { + if [[ "$blacklist" == "" ]]; then + blacklist="$1" + else + blacklist="$blacklist|$1" + fi + } + +# files passed into this function are meant to be temporary workarounds +# because they're not finished or otherwise can't be loaded for some reason +tmp_blacklist () + { + echo "Warning: temporarily blacklisted files named '$1'" 1>&2 + blacklist $1 + } + +blacklist __load__.bro +blacklist test-all.bro +blacklist all.bro +blacklist init-default.bro +blacklist init-bare.bro + +tmp_blacklist hot.conn.bro +tmp_blacklist scan.bro statictext="\ # DO NOT EDIT @@ -30,8 +53,8 @@ statictext="\ set(psd \${PROJECT_SOURCE_DIR}/scripts) rest_target(\${CMAKE_CURRENT_SOURCE_DIR} example.bro internal) -rest_target(\${psd} base/bro.init internal) -rest_target(\${psd} base/all.bro internal) +rest_target(\${psd} base/init-default.bro internal) +rest_target(\${psd} base/init-bare.bro internal) " if [[ $# -ge 1 ]]; then @@ -58,7 +81,7 @@ scriptfiles=`( cd ${sourcedir}/scripts && find . -name \*\.bro | sort )` for file in $scriptfiles do f=${file:2} - if [[ (! $f =~ $blacklist) && (! $f =~ $blacklist_addl) ]]; then + if [[ ! $f =~ $blacklist ]]; then echo "rest_target(\${psd} $f)" >> $outfile fi done diff --git a/doc/scripts/group_index_generator.py b/doc/scripts/group_index_generator.py index 74c8c14d65..e9e17f3ca9 100755 --- a/doc/scripts/group_index_generator.py +++ b/doc/scripts/group_index_generator.py @@ -1,9 +1,8 @@ #! /usr/bin/env python # This script automatically generates a reST documents that lists -# a collection of Bro policy scripts that are "grouped" together. -# The summary text (##! comments) of the policy script is embedded -# in the list. +# a collection of Bro scripts that are "grouped" together. +# The summary text (##! comments) of the script is embedded in the list # # 1st argument is the file containing list of groups # 2nd argument is the directory containing ${group}_files lists of @@ -57,6 +56,6 @@ with open(group_list, 'r') as f_group_list: f_group_file.write("\n"); with open(group_file, 'a') as f_group_file: - f_group_file.write("\n:doc:`/policy/%s`\n" % doc_names[i]) + f_group_file.write("\n:doc:`/scripts/%s`\n" % doc_names[i]) for line in summary_comments: f_group_file.write(" " + line) diff --git a/doc/scripts/source/index.rst b/doc/scripts/source/index.rst index 83bceebb0c..a144644208 100644 --- a/doc/scripts/source/index.rst +++ b/doc/scripts/source/index.rst @@ -14,7 +14,7 @@ Contents: internal bifs packages - policy/index + scripts/index Indices and tables ================== diff --git a/doc/scripts/source/internal.rst b/doc/scripts/source/internal.rst index d9b914df65..817c76e725 100644 --- a/doc/scripts/source/internal.rst +++ b/doc/scripts/source/internal.rst @@ -1,5 +1,5 @@ .. This is a stub doc to which the build process can append. -Internal Policy Scripts -======================= +Internal Scripts +================ diff --git a/doc/scripts/source/packages.rst b/doc/scripts/source/packages.rst index a7e76f097a..35f6633fd4 100644 --- a/doc/scripts/source/packages.rst +++ b/doc/scripts/source/packages.rst @@ -1,11 +1,15 @@ .. This is a stub doc to which the build process can append. -Policy Script Packages -====================== +Bro Script Packages +=================== -Bro has the following policy script packages (e.g. collections of related -policy scripts). If the package contains a ``__load__.bro`` script, it -supports being loaded in mass as a whole directory for convenience. +Bro has the following script packages (e.g. collections of related scripts in +a common directory). If the package directory contains a ``__load__.bro`` +script, it supports being loaded in mass as a whole directory for convenience. + +Packages/scripts in the ``base/`` directory are all loaded by default, while +ones in ``policy/`` provide functionality and customization options that are +more appropriate for users to decide whether they'd like to load it or not. .. toctree:: :maxdepth: 1 diff --git a/doc/scripts/source/policy/index.rst b/doc/scripts/source/policy/index.rst deleted file mode 100644 index 6b8ed9319c..0000000000 --- a/doc/scripts/source/policy/index.rst +++ /dev/null @@ -1,6 +0,0 @@ -Index of All Policy Script Documentation -======================================== - -.. toctree:: - :maxdepth: 1 - diff --git a/doc/scripts/source/scripts/index.rst b/doc/scripts/source/scripts/index.rst new file mode 100644 index 0000000000..fd11a3924e --- /dev/null +++ b/doc/scripts/source/scripts/index.rst @@ -0,0 +1,6 @@ +Index of All Bro Script Documentation +===================================== + +.. toctree:: + :maxdepth: 1 + diff --git a/scripts/CMakeLists.txt b/scripts/CMakeLists.txt index 5979e6befd..d7a321627f 100644 --- a/scripts/CMakeLists.txt +++ b/scripts/CMakeLists.txt @@ -1,9 +1,8 @@ include(InstallPackageConfigFile) -install(DIRECTORY ./ DESTINATION ${POLICYDIR} FILES_MATCHING +install(DIRECTORY ./ DESTINATION ${BRO_SCRIPT_INSTALL_PATH} FILES_MATCHING PATTERN "all.bro" EXCLUDE PATTERN "site/local.bro" EXCLUDE - PATTERN "bro.init" PATTERN "*.bro" PATTERN "*.sig" PATTERN "*.osf" @@ -13,6 +12,6 @@ install(DIRECTORY ./ DESTINATION ${POLICYDIR} FILES_MATCHING # user modify-able. InstallPackageConfigFile( ${CMAKE_CURRENT_SOURCE_DIR}/site/local.bro - ${POLICYDIR}/site + ${BRO_SCRIPT_INSTALL_PATH}/site local.bro) diff --git a/scripts/base/frameworks/cluster/setup-connections.bro b/scripts/base/frameworks/cluster/setup-connections.bro index 04d474e604..c51b59f70f 100644 --- a/scripts/base/frameworks/cluster/setup-connections.bro +++ b/scripts/base/frameworks/cluster/setup-connections.bro @@ -1,3 +1,5 @@ +@load base/frameworks/communication + module Cluster; event bro_init() &priority=9 diff --git a/scripts/base/frameworks/communication/__load__.bro b/scripts/base/frameworks/communication/__load__.bro index a854726f04..3b18043db1 100644 --- a/scripts/base/frameworks/communication/__load__.bro +++ b/scripts/base/frameworks/communication/__load__.bro @@ -2,4 +2,4 @@ # TODO: get rid of this as soon as the Expr.cc hack is changed. @if ( getenv("ENABLE_COMMUNICATION") != "" ) @load ./main -@endif \ No newline at end of file +@endif diff --git a/scripts/base/frameworks/metrics/conn-example.bro b/scripts/base/frameworks/metrics/conn-example.bro index 9e20798cc0..f4e8e71d86 100644 --- a/scripts/base/frameworks/metrics/conn-example.bro +++ b/scripts/base/frameworks/metrics/conn-example.bro @@ -1,4 +1,4 @@ -@load frameworks/metrics +@load base/frameworks/metrics redef enum Metrics::ID += { CONNS_ORIGINATED, @@ -16,4 +16,4 @@ event connection_established(c: connection) Metrics::add_data(CONNS_ORIGINATED, [$host=c$id$orig_h], 1); Metrics::add_data(CONNS_RESPONDED, [$host=c$id$resp_h], 1); } - \ No newline at end of file + diff --git a/scripts/base/frameworks/metrics/http-example.bro b/scripts/base/frameworks/metrics/http-example.bro index a91fdbb47d..6af4031fd2 100644 --- a/scripts/base/frameworks/metrics/http-example.bro +++ b/scripts/base/frameworks/metrics/http-example.bro @@ -1,4 +1,4 @@ -@load frameworks/metrics +@load base/frameworks/metrics redef enum Metrics::ID += { HTTP_REQUESTS_BY_STATUS_CODE, @@ -17,4 +17,4 @@ event HTTP::log_http(rec: HTTP::Info) Metrics::add_data(HTTP_REQUESTS_BY_HOST, [$index=rec$host], 1); if ( rec?$status_code ) Metrics::add_data(HTTP_REQUESTS_BY_STATUS_CODE, [$host=rec$id$orig_h, $index=fmt("%d", rec$status_code)], 1); - } \ No newline at end of file + } diff --git a/scripts/base/frameworks/notice/actions/email_admin.bro b/scripts/base/frameworks/notice/actions/email_admin.bro index 07a6568327..c03629d885 100644 --- a/scripts/base/frameworks/notice/actions/email_admin.bro +++ b/scripts/base/frameworks/notice/actions/email_admin.bro @@ -1,4 +1,3 @@ - module Notice; export { @@ -25,4 +24,4 @@ event notice(n: Notice::Info) &priority=-5 if ( email != "" ) email_notice_to(n, email, T); } - } \ No newline at end of file + } diff --git a/scripts/base/frameworks/notice/extend-email/hostnames.bro b/scripts/base/frameworks/notice/extend-email/hostnames.bro index 83cdc4807d..da2d0d5d0f 100644 --- a/scripts/base/frameworks/notice/extend-email/hostnames.bro +++ b/scripts/base/frameworks/notice/extend-email/hostnames.bro @@ -8,7 +8,7 @@ event Notice::notice(n: Notice::Info) &priority=10 return; # This should only be done for notices that are being sent to email. - if ( ACTION_EMAIL !in n$action ) + if ( ACTION_EMAIL !in n$actions ) return; local output = ""; @@ -37,4 +37,4 @@ event Notice::notice(n: Notice::Info) &priority=10 if ( output != "" ) n$email_body_sections[|n$email_body_sections|] = output; - } \ No newline at end of file + } diff --git a/scripts/base/frameworks/notice/weird.bro b/scripts/base/frameworks/notice/weird.bro index 4718dc204a..31ecd484e9 100644 --- a/scripts/base/frameworks/notice/weird.bro +++ b/scripts/base/frameworks/notice/weird.bro @@ -1,4 +1,3 @@ - module Weird; export { diff --git a/scripts/base/protocols/mime/base.bro b/scripts/base/protocols/mime/base.bro index d0212870a4..df495387d7 100644 --- a/scripts/base/protocols/mime/base.bro +++ b/scripts/base/protocols/mime/base.bro @@ -1,7 +1,7 @@ ##! The mime script does analysis of MIME encoded messages seen in certain ##! protocols (only SMTP and POP3 at the moment). -@load utils/strings +@load base/utils/strings module MIME; diff --git a/scripts/base/protocols/mime/file-extract.bro b/scripts/base/protocols/mime/file-extract.bro index d6989ad809..33d2c70513 100644 --- a/scripts/base/protocols/mime/file-extract.bro +++ b/scripts/base/protocols/mime/file-extract.bro @@ -1,5 +1,5 @@ -@load protocols/mime/file-ident -@load utils/files +@load ./file-ident +@load base/utils/files module MIME; @@ -57,4 +57,4 @@ event mime_end_entity(c: connection) &priority=-3 if ( c$mime?$extraction_file ) close(c$mime$extraction_file); } - \ No newline at end of file + diff --git a/scripts/base/protocols/mime/file-hash.bro b/scripts/base/protocols/mime/file-hash.bro index 3384928d58..5139810b8e 100644 --- a/scripts/base/protocols/mime/file-hash.bro +++ b/scripts/base/protocols/mime/file-hash.bro @@ -1,4 +1,4 @@ -@load protocols/mime/file-ident +@load ./file-ident module MIME; @@ -75,4 +75,4 @@ event mime_end_entity(c: connection) &priority=-3 NOTICE([$note=MD5, $msg=fmt("Calculated a hash for a MIME entity from %s", c$id$orig_h), $sub=c$mime$md5, $conn=c]); } - } \ No newline at end of file + } diff --git a/scripts/base/protocols/mime/file-ident.bro b/scripts/base/protocols/mime/file-ident.bro index ba5310d362..346fde1bba 100644 --- a/scripts/base/protocols/mime/file-ident.bro +++ b/scripts/base/protocols/mime/file-ident.bro @@ -1,4 +1,4 @@ -@load protocols/mime/base +@load ./base module MIME; diff --git a/scripts/policy/frameworks/communication/listen-clear.bro b/scripts/policy/frameworks/communication/listen-clear.bro index 4f96414172..c5dd6e1e70 100644 --- a/scripts/policy/frameworks/communication/listen-clear.bro +++ b/scripts/policy/frameworks/communication/listen-clear.bro @@ -1,5 +1,7 @@ ##! Listen for other Bro instances to make unencrypted connections. +@load base/frameworks/communication + module Communication; export { diff --git a/scripts/policy/frameworks/communication/listen-ssl.bro b/scripts/policy/frameworks/communication/listen-ssl.bro index 32c5f747c2..188d55ea5f 100644 --- a/scripts/policy/frameworks/communication/listen-ssl.bro +++ b/scripts/policy/frameworks/communication/listen-ssl.bro @@ -1,5 +1,7 @@ ##! Listen for other Bro instances and encrypt the connection with SSL. +@load base/frameworks/communication + module Communication; export { diff --git a/scripts/policy/frameworks/control/controller.bro b/scripts/policy/frameworks/control/controller.bro index 8c60ef457a..83fd5e5451 100644 --- a/scripts/policy/frameworks/control/controller.bro +++ b/scripts/policy/frameworks/control/controller.bro @@ -1,3 +1,4 @@ +@load base/frameworks/communication module Control; @@ -99,4 +100,4 @@ event remote_connection_handshake_done(p: event_peer) &priority=-10 # Signal configuration update to peer. event Control::configuration_update_request(); } - } \ No newline at end of file + } diff --git a/scripts/policy/protocols/conn/scan.bro b/scripts/policy/protocols/conn/scan.bro index fabb865093..ab715cccb3 100644 --- a/scripts/policy/protocols/conn/scan.bro +++ b/scripts/policy/protocols/conn/scan.bro @@ -1,4 +1,4 @@ -@load frameworks/notice +@load base/frameworks/notice @load port-name module Scan; diff --git a/scripts/site/local.bro b/scripts/site/local.bro index 7e758c72b0..5199cab288 100644 --- a/scripts/site/local.bro +++ b/scripts/site/local.bro @@ -43,4 +43,4 @@ redef signature_files += "frameworks/signatures/detect-windows-shells.sig"; @load protocols/ssl/known-certs # Load the script to enable SSL/TLS certificate validation. -@load protocols/ssl/validate-certs \ No newline at end of file +@load protocols/ssl/validate-certs diff --git a/src/BroDoc.cc b/src/BroDoc.cc index 7754dfc4c9..302bd04c88 100644 --- a/src/BroDoc.cc +++ b/src/BroDoc.cc @@ -20,8 +20,8 @@ BroDoc::BroDoc(const std::string& rel, const std::string& abs) if ( rel[0] == '/' || rel[0] == '.' ) { - // The Bro script must not be on a subpath of the policy/ dir of - // BROPATH, so just use the basename as the document title. + // The Bro script isn't being loaded via BROPATH, so just use basename + // as the document title. doc_title = source_filename; } else @@ -33,8 +33,14 @@ BroDoc::BroDoc(const std::string& rel, const std::string& abs) doc_title = rel + "/" + source_filename; } + downloadable_filename = source_filename; + + size_t ext_pos = downloadable_filename.find(".bif.bro"); + if ( std::string::npos != ext_pos ) + downloadable_filename.erase(ext_pos + 4); + reST_filename = doc_title; - size_t ext_pos = reST_filename.find(".bro"); + ext_pos = reST_filename.find(".bro"); if ( std::string::npos == ext_pos ) reST_filename += ".rst"; @@ -103,14 +109,14 @@ void BroDoc::AddImport(const std::string& s) { if ( subpath[0] == '/' || subpath[0] == '.' ) { - // it's not a subpath of policy/, so just add the name of it + // it's not a subpath of scripts/, so just add the name of it // as it's given in the @load directive imports.push_back(lname); } else { // combine the base file name of script in the @load directive - // with the subpath of BROPATH's policy/ directory + // with the subpath of BROPATH's scripts/ directory string fname(subpath); char* othertmp = copy_string(lname.c_str()); fname.append("/").append(basename(othertmp)); @@ -167,7 +173,7 @@ void BroDoc::WriteDocFile() const WriteSectionHeading(doc_title.c_str(), '='); WriteToDoc("\n:download:`Original Source File <%s>`\n\n", - source_filename.c_str()); + downloadable_filename.c_str()); WriteSectionHeading("Overview", '-'); WriteStringList("%s\n", "%s\n\n", summary); @@ -185,7 +191,7 @@ void BroDoc::WriteDocFile() const size_t pos = pretty.find("/index"); if ( pos != std::string::npos && pos + 6 == pretty.size() ) pretty = pretty.substr(0, pos); - WriteToDoc(":doc:`%s `", pretty.c_str(), it->c_str()); + WriteToDoc(":doc:`%s `", pretty.c_str(), it->c_str()); } WriteToDoc("\n"); } diff --git a/src/BroDoc.h b/src/BroDoc.h index 975177fc9a..112401253c 100644 --- a/src/BroDoc.h +++ b/src/BroDoc.h @@ -24,10 +24,9 @@ public: * If the filename doesn't end in ".bro", then ".rst" is just appended. * Any '/' characters in the reST file name that result from choice of * the 'rel' parameter are replaced with '^'. - * @param subpath A string representing a subpath of BROPATH's policy/ - * directory in which the source file is located. It can - * also be full path to the file or a full path that's in BROPATH, - * but in either of those cases, the parameter is essentially + * @param rel A string representing a subpath of the root Bro script + * source/install directory in which the source file is located. + * It can also be an absolute path, but then the parameter is * ignored and the document title is just derived from file name * @param abs The absolute path to the Bro script for which to generate * documentation. @@ -211,6 +210,7 @@ protected: FILE* reST_file; std::string reST_filename; std::string source_filename; // points to the basename of source file + std::string downloadable_filename; // file that will be linked for download std::string doc_title; std::string packet_filter; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1a5f096f70..6bc82ebb91 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -408,7 +408,8 @@ set(bro_SRCS collect_headers(bro_HEADERS ${bro_SRCS}) -add_definitions(-DPOLICYDEST="${POLICYDIR}") +add_definitions(-DBRO_SCRIPT_INSTALL_PATH="${BRO_SCRIPT_INSTALL_PATH}") +add_definitions(-DBRO_SCRIPT_SOURCE_PATH="${BRO_SCRIPT_SOURCE_PATH}") add_executable(bro ${bro_SRCS} ${bro_HEADERS}) @@ -423,7 +424,7 @@ set(brolibs target_link_libraries(bro ${brolibs}) install(TARGETS bro DESTINATION bin) -install(FILES ${INSTALL_BIF_OUTPUTS} DESTINATION ${POLICYDIR}) +install(FILES ${INSTALL_BIF_OUTPUTS} DESTINATION ${BRO_SCRIPT_INSTALL_PATH}) set(BRO_EXE bro CACHE STRING "Bro executable binary" FORCE) diff --git a/src/util.cc b/src/util.cc index 528a505f60..90eac56cca 100644 --- a/src/util.cc +++ b/src/util.cc @@ -757,9 +757,9 @@ const char* bro_path() const char* path = getenv("BROPATH"); if ( ! path ) path = ".:" - POLICYDEST ":" - POLICYDEST "/policy" ":" - POLICYDEST "/site"; + BRO_SCRIPT_INSTALL_PATH ":" + BRO_SCRIPT_INSTALL_PATH "/policy" ":" + BRO_SCRIPT_INSTALL_PATH "/site"; return path; } @@ -891,60 +891,36 @@ const char* normalize_path(const char* path) return copy_string(new_path.c_str()); } -// Returns the subpath of BROPATH's policy/ directory in which the loaded -// file in located. If it's not under a subpath of policy/ then the full -// path is returned, else the subpath of policy/ concatentated with any -// directory prefix of the file is returned. -void get_policy_subpath(const char* dir, const char* file, const char** subpath) +// Returns the subpath of the root Bro script install/source directory in +// which the loaded file is located. If it's not under a subpath of that +// directory (e.g. cwd or custom path) then the full path is returned. +void get_script_subpath(const std::string& full_filename, const char** subpath) { - // first figure out if this is a subpath of policy/ - const char* ploc = strstr(dir, "policy"); - if ( ploc ) - if ( ploc[6] == '\0' ) - *subpath = copy_string(ploc + 6); - else if ( ploc[6] == '/' ) - *subpath = copy_string(ploc + 7); - else - *subpath = copy_string(dir); - else - *subpath = copy_string(dir); + size_t p; + std::string my_subpath(full_filename); - // and now add any directory parts of the filename - char full_filename_buf[1024]; - safe_snprintf(full_filename_buf, sizeof(full_filename_buf), - "%s/%s", dir, file); - char* tmp = copy_string(file); - const char* fdir = 0; - - if ( is_dir(full_filename_buf) ) - fdir = file; - - if ( ! fdir ) - fdir = dirname(tmp); - - if ( ! streq(fdir, ".") ) + // get the parent directory of file (if not already a directory) + if ( ! is_dir(full_filename.c_str()) ) { - size_t full_subpath_len = strlen(*subpath) + strlen(fdir) + 1; - bool needslash = false; - if ( strlen(*subpath) != 0 && (*subpath)[strlen(*subpath) - 1] != '/' ) - { - ++full_subpath_len; - needslash = true; - } - - char* full_subpath = new char[full_subpath_len]; - strcpy(full_subpath, *subpath); - if ( needslash ) - strcat(full_subpath, "/"); - strcat(full_subpath, fdir); - delete [] *subpath; - *subpath = full_subpath; + char* tmp = copy_string(full_filename.c_str()); + my_subpath = dirname(tmp); + delete [] tmp; } - const char* normalized_subpath = normalize_path(*subpath); - delete [] tmp; - delete [] *subpath; - *subpath = normalized_subpath; + // first check if this is some subpath of the installed scripts root path, + // if not check if it's a subpath of the script source root path, + // if neither, will just use the given directory + if ( (p=my_subpath.find(BRO_SCRIPT_INSTALL_PATH)) != std::string::npos ) + my_subpath.erase(0, strlen(BRO_SCRIPT_INSTALL_PATH)); + else if ( (p=my_subpath.find(BRO_SCRIPT_SOURCE_PATH)) != std::string::npos ) + my_subpath.erase(0, strlen(BRO_SCRIPT_SOURCE_PATH)); + + // if root path found, remove path separators until next path component + if ( p != std::string::npos ) + while ( my_subpath.size() && my_subpath[0] == '/' ) + my_subpath.erase(0, 1); + + *subpath = normalize_path(my_subpath.c_str()); } extern string current_scanned_file_path; @@ -1001,7 +977,7 @@ FILE* search_for_file(const char* filename, const char* ext, ! is_dir(full_filename_buf) ) { if ( bropath_subpath ) - get_policy_subpath(dir_beginning, filename, bropath_subpath); + get_script_subpath(full_filename_buf, bropath_subpath); return open_file(full_filename_buf, full_filename, load_pkgs); } @@ -1010,7 +986,7 @@ FILE* search_for_file(const char* filename, const char* ext, if ( access(full_filename_buf, R_OK) == 0 ) { if ( bropath_subpath ) - get_policy_subpath(dir_beginning, filename, bropath_subpath); + get_script_subpath(full_filename_buf, bropath_subpath); return open_file(full_filename_buf, full_filename, load_pkgs); } diff --git a/src/util.h b/src/util.h index 82c86da950..392b2ca76a 100644 --- a/src/util.h +++ b/src/util.h @@ -179,7 +179,7 @@ extern const char* bro_path(); extern const char* bro_prefixes(); std::string dot_canon(std::string path, std::string file, std::string prefix = ""); const char* normalize_path(const char* path); -void get_policy_subpath(const char* dir, const char* file, const char** subpath); +void get_script_subpath(const std::string& full_filename, const char** subpath); extern FILE* search_for_file(const char* filename, const char* ext, const char** full_filename, bool load_pkgs, const char** bropath_subpath); diff --git a/testing/btest/Baseline/core.load-prefixes/output b/testing/btest/Baseline/core.load-prefixes/output index 733bc9a594..ea35b3a8c0 100644 --- a/testing/btest/Baseline/core.load-prefixes/output +++ b/testing/btest/Baseline/core.load-prefixes/output @@ -1,4 +1,4 @@ -loaded lcl2.site.bro -loaded lcl.site.bro -loaded lcl2.protocols.http.bro -loaded lcl.protocols.http.bro +loaded lcl2.base.utils.site.bro +loaded lcl.base.utils.site.bro +loaded lcl2.base.protocols.http.bro +loaded lcl.base.protocols.http.bro diff --git a/testing/btest/Baseline/doc.autogen-reST-example/example.rst b/testing/btest/Baseline/doc.autogen-reST-example/example.rst index 2c2ed28369..ec48477d61 100644 --- a/testing/btest/Baseline/doc.autogen-reST-example/example.rst +++ b/testing/btest/Baseline/doc.autogen-reST-example/example.rst @@ -29,7 +29,7 @@ each of "columns", "event", "filter" depending on exactly what it's doing. :Author: Jon Siwek -:Imports: :doc:`frameworks/notice ` +:Imports: :doc:`policy/frameworks/software/vulnerable ` Summary ~~~~~~~ diff --git a/testing/btest/Baseline/doc.blacklist-reminder/.stderr b/testing/btest/Baseline/doc.blacklist-reminder/.stderr new file mode 100644 index 0000000000..e69de29bb2 diff --git a/testing/btest/core/load-prefixes.bro b/testing/btest/core/load-prefixes.bro index 54c6bed0ef..1dfc3ac5dd 100644 --- a/testing/btest/core/load-prefixes.bro +++ b/testing/btest/core/load-prefixes.bro @@ -9,11 +9,11 @@ @TEST-END-FILE @TEST-START-FILE lcl.base.utils.site.bro -print "loaded lcl.base.site.bro"; +print "loaded lcl.base.utils.site.bro"; @TEST-END-FILE @TEST-START-FILE lcl2.base.utils.site.bro -print "loaded lcl2.base.site.bro"; +print "loaded lcl2.base.utils.site.bro"; @TEST-END-FILE @TEST-START-FILE lcl.base.protocols.http.bro diff --git a/testing/btest/doc/blacklist-reminder.test b/testing/btest/doc/blacklist-reminder.test new file mode 100644 index 0000000000..8b79d8a28f --- /dev/null +++ b/testing/btest/doc/blacklist-reminder.test @@ -0,0 +1,8 @@ +# This test will fail if there are Bro scripts that have been temporarily +# blacklisted from the documentation generation process for some reason +# (e.g. they're a work-in-progress or otherwise fail to parse). It's meant +# to serve as a reminder that some future action may be needed to generate +# documentation for the blacklisted scripts. +# +# @TEST-EXEC: $DIST/doc/scripts/genDocSourcesList.sh +# @TEST-EXEC: btest-diff .stderr