Coverage test fixes and whitespace/doc tweaks.

This commit is contained in:
Jon Siwek 2013-07-22 14:15:35 -05:00
parent ca5abbf13a
commit 325f0c2a3f
4 changed files with 42 additions and 40 deletions

View file

@ -164,9 +164,12 @@ rest_target(${psd} base/protocols/ssl/main.bro)
rest_target(${psd} base/protocols/ssl/mozilla-ca-list.bro) rest_target(${psd} base/protocols/ssl/mozilla-ca-list.bro)
rest_target(${psd} base/protocols/syslog/consts.bro) rest_target(${psd} base/protocols/syslog/consts.bro)
rest_target(${psd} base/protocols/syslog/main.bro) rest_target(${psd} base/protocols/syslog/main.bro)
rest_target(${psd} base/utils/active-http.bro)
rest_target(${psd} base/utils/addrs.bro) rest_target(${psd} base/utils/addrs.bro)
rest_target(${psd} base/utils/conn-ids.bro) rest_target(${psd} base/utils/conn-ids.bro)
rest_target(${psd} base/utils/dir.bro)
rest_target(${psd} base/utils/directions-and-hosts.bro) rest_target(${psd} base/utils/directions-and-hosts.bro)
rest_target(${psd} base/utils/exec.bro)
rest_target(${psd} base/utils/files.bro) rest_target(${psd} base/utils/files.bro)
rest_target(${psd} base/utils/numbers.bro) rest_target(${psd} base/utils/numbers.bro)
rest_target(${psd} base/utils/paths.bro) rest_target(${psd} base/utils/paths.bro)

View file

@ -1,21 +1,21 @@
##! A module for performing active HTTP requests and ##! A module for performing active HTTP requests and
##! getting the reply at runtime. ##! getting the reply at runtime.
@load ./exec @load ./exec
module ActiveHTTP; module ActiveHTTP;
export { export {
## The default timeout for HTTP requests. ## The default timeout for HTTP requests.
const default_max_time = 1min &redef; const default_max_time = 1min &redef;
## The default HTTP method/verb to use for requests. ## The default HTTP method/verb to use for requests.
const default_method = "GET" &redef; const default_method = "GET" &redef;
type Response: record { type Response: record {
## Numeric response code from the server. ## Numeric response code from the server.
code: count; code: count;
## String response messgae from the server. ## String response message from the server.
msg: string; msg: string;
## Full body of the response. ## Full body of the response.
body: string &optional; body: string &optional;
@ -29,24 +29,24 @@ export {
## The HTTP method/verb to use for the request. ## The HTTP method/verb to use for the request.
method: string &default=default_method; method: string &default=default_method;
## Data to send to the server in the client body. Keep in ## Data to send to the server in the client body. Keep in
## mind that you will probably need to set the $method field ## mind that you will probably need to set the *method* field
## to "POST" or "PUT". ## to "POST" or "PUT".
client_data: string &optional; client_data: string &optional;
## Arbitrary headers to pass to the server. Some headers ## Arbitrary headers to pass to the server. Some headers
## will be included by libCurl. ## will be included by libCurl.
#custom_headers: table[string] of string &optional; #custom_headers: table[string] of string &optional;
## Timeout for the request. ## Timeout for the request.
max_time: interval &default=default_max_time; max_time: interval &default=default_max_time;
## Additional curl command line arguments. Be very careful ## Additional curl command line arguments. Be very careful
## with this option since shell injection could take place ## with this option since shell injection could take place
## if careful handling of untrusted data is not applied. ## if careful handling of untrusted data is not applied.
addl_curl_args: string &optional; addl_curl_args: string &optional;
}; };
## Perform an HTTP request according to the :bro:type:`Request` record. ## Perform an HTTP request according to the :bro:type:`Request` record.
## This is an asynchronous function and must be called within a "when" ## This is an asynchronous function and must be called within a "when"
## statement. ## statement.
## ##
## req: A record instance representing all options for an HTTP request. ## req: A record instance representing all options for an HTTP request.
## ##
## Returns: A record with the full response message. ## Returns: A record with the full response message.
@ -55,7 +55,7 @@ export {
function request2curl(r: Request, bodyfile: string, headersfile: string): string function request2curl(r: Request, bodyfile: string, headersfile: string): string
{ {
local cmd = fmt("curl -s -g -o \"%s\" -D \"%s\" -X \"%s\"", local cmd = fmt("curl -s -g -o \"%s\" -D \"%s\" -X \"%s\"",
str_shell_escape(bodyfile), str_shell_escape(bodyfile),
str_shell_escape(headersfile), str_shell_escape(headersfile),
str_shell_escape(r$method)); str_shell_escape(r$method));
@ -91,7 +91,7 @@ function request(req: Request): ActiveHTTP::Response
# If there is no response line then nothing else will work either. # If there is no response line then nothing else will work either.
if ( ! (result?$files && headersfile in result$files) ) if ( ! (result?$files && headersfile in result$files) )
Reporter::error(fmt("There was a failure when requesting \"%s\" with ActiveHTTP.", req$url)); Reporter::error(fmt("There was a failure when requesting \"%s\" with ActiveHTTP.", req$url));
local headers = result$files[headersfile]; local headers = result$files[headersfile];
for ( i in headers ) for ( i in headers )
{ {

View file

@ -1,6 +1,4 @@
##! A module for executing external command line programs. ##! A module for executing external command line programs.
##! This requires code that is still in topic branches and
##! definitely won't currently work on any released version of Bro.
@load base/frameworks/input @load base/frameworks/input
@ -8,15 +6,13 @@ module Exec;
export { export {
type Command: record { type Command: record {
## The command line to execute. ## The command line to execute. Use care to avoid injection attacks.
## Use care to avoid injection attacks! ## I.e. if the command uses untrusted/variable data, sanitize it.
cmd: string; cmd: string;
## Provide standard in to the program as a ## Provide standard in to the program as a string.
## string.
stdin: string &default=""; stdin: string &default="";
## If additional files are required to be read ## If additional files are required to be read in as part of the output
## in as part of the output of the command they ## of the command they can be defined here.
## can be defined here.
read_files: set[string] &optional; read_files: set[string] &optional;
}; };
@ -27,7 +23,7 @@ export {
signal_exit: bool &default=F; signal_exit: bool &default=F;
## Each line of standard out. ## Each line of standard out.
stdout: vector of string &optional; stdout: vector of string &optional;
## Each line of standard error. ## Each line of standard error.
stderr: vector of string &optional; stderr: vector of string &optional;
## If additional files were requested to be read in ## If additional files were requested to be read in
## the content of the files will be available here. ## the content of the files will be available here.
@ -35,7 +31,7 @@ export {
}; };
## Function for running command line programs and getting ## Function for running command line programs and getting
## output. This is an asynchronous function which is meant ## output. This is an asynchronous function which is meant
## to be run with the `when` statement. ## to be run with the `when` statement.
## ##
## cmd: The command to run. Use care to avoid injection attacks! ## cmd: The command to run. Use care to avoid injection attacks!
@ -56,12 +52,12 @@ redef record Command += {
global results: table[string] of Result = table(); global results: table[string] of Result = table();
global finished_commands: set[string]; global finished_commands: set[string];
global currently_tracked_files: set[string] = set(); global currently_tracked_files: set[string] = set();
type OneLine: record { type OneLine: record {
s: string; s: string;
is_stderr: bool; is_stderr: bool;
}; };
type FileLine: record { type FileLine: record {
s: string; s: string;
}; };
@ -93,7 +89,7 @@ event Exec::file_line(description: Input::EventDescription, tpe: Input::Event, s
local result = results[name]; local result = results[name];
if ( ! result?$files ) if ( ! result?$files )
result$files = table(); result$files = table();
if ( track_file !in result$files ) if ( track_file !in result$files )
result$files[track_file] = vector(s); result$files[track_file] = vector(s);
else else
@ -136,16 +132,16 @@ function run(cmd: Command): Result
} }
} }
local config_strings: table[string] of string = { local config_strings: table[string] of string = {
["stdin"] = cmd$stdin, ["stdin"] = cmd$stdin,
["read_stderr"] = "1", ["read_stderr"] = "1",
}; };
Input::add_event([$name=cmd$uid, Input::add_event([$name=cmd$uid,
$source=fmt("%s |", cmd$cmd), $source=fmt("%s |", cmd$cmd),
$reader=Input::READER_RAW, $reader=Input::READER_RAW,
$fields=Exec::OneLine, $fields=Exec::OneLine,
$ev=Exec::line, $ev=Exec::line,
$want_record=F, $want_record=F,
$config=config_strings]); $config=config_strings]);
return when ( cmd$uid in finished_commands ) return when ( cmd$uid in finished_commands )
@ -164,4 +160,4 @@ event bro_done()
{ {
system(fmt("rm \"%s\"", str_shell_escape(fname))); system(fmt("rm \"%s\"", str_shell_escape(fname)));
} }
} }

View file

@ -3,7 +3,7 @@
#empty_field (empty) #empty_field (empty)
#unset_field - #unset_field -
#path loaded_scripts #path loaded_scripts
#open 2013-07-10-21-18-31 #open 2013-07-22-16-01-22
#fields name #fields name
#types string #types string
scripts/base/init-bare.bro scripts/base/init-bare.bro
@ -90,12 +90,17 @@ scripts/base/init-bare.bro
scripts/base/init-default.bro scripts/base/init-default.bro
scripts/base/utils/site.bro scripts/base/utils/site.bro
scripts/base/utils/patterns.bro scripts/base/utils/patterns.bro
scripts/base/utils/active-http.bro
scripts/base/utils/exec.bro
scripts/base/utils/addrs.bro scripts/base/utils/addrs.bro
scripts/base/utils/conn-ids.bro scripts/base/utils/conn-ids.bro
scripts/base/utils/dir.bro
scripts/base/frameworks/reporter/__load__.bro
scripts/base/frameworks/reporter/main.bro
scripts/base/utils/paths.bro
scripts/base/utils/directions-and-hosts.bro scripts/base/utils/directions-and-hosts.bro
scripts/base/utils/files.bro scripts/base/utils/files.bro
scripts/base/utils/numbers.bro scripts/base/utils/numbers.bro
scripts/base/utils/paths.bro
scripts/base/utils/queue.bro scripts/base/utils/queue.bro
scripts/base/utils/strings.bro scripts/base/utils/strings.bro
scripts/base/utils/thresholds.bro scripts/base/utils/thresholds.bro
@ -129,8 +134,6 @@ scripts/base/init-default.bro
scripts/base/frameworks/intel/__load__.bro scripts/base/frameworks/intel/__load__.bro
scripts/base/frameworks/intel/main.bro scripts/base/frameworks/intel/main.bro
scripts/base/frameworks/intel/input.bro scripts/base/frameworks/intel/input.bro
scripts/base/frameworks/reporter/__load__.bro
scripts/base/frameworks/reporter/main.bro
scripts/base/frameworks/sumstats/__load__.bro scripts/base/frameworks/sumstats/__load__.bro
scripts/base/frameworks/sumstats/main.bro scripts/base/frameworks/sumstats/main.bro
scripts/base/frameworks/sumstats/plugins/__load__.bro scripts/base/frameworks/sumstats/plugins/__load__.bro
@ -195,4 +198,4 @@ scripts/base/init-default.bro
scripts/base/protocols/tunnels/__load__.bro scripts/base/protocols/tunnels/__load__.bro
scripts/base/misc/find-checksum-offloading.bro scripts/base/misc/find-checksum-offloading.bro
scripts/policy/misc/loaded-scripts.bro scripts/policy/misc/loaded-scripts.bro
#close 2013-07-10-21-18-31 #close 2013-07-22-16-01-22