diff --git a/src/Net.h b/src/Net.h index 5a27fd434a..337e50720f 100644 --- a/src/Net.h +++ b/src/Net.h @@ -93,16 +93,20 @@ extern char* writefile; // Script file we have already scanned (or are in the process of scanning). // They are identified by inode number. struct ScannedFile { - ino_t inode; - int include_level; - string name; - string subpath; // path in BROPATH's policy/ containing the file - bool skipped; // This ScannedFile was @unload'd - bool prefixes_checked; // if loading prefixes for this file has been tried + ino_t inode; + int include_level; + string name; + string subpath; // Path in BROPATH's policy/ containing the file. + bool skipped; // This ScannedFile was @unload'd. + bool prefixes_checked; // If loading prefixes for this file has been tried. - ScannedFile(ino_t arg_inode, int arg_include_level, string arg_name, string arg_subpath = "", bool arg_skipped = false, bool arg_prefixes_checked = false) - : inode(arg_inode), include_level(arg_include_level), name(arg_name), subpath(arg_subpath), skipped(arg_skipped), prefixes_checked(arg_prefixes_checked) - { } + ScannedFile(ino_t arg_inode, int arg_include_level, string arg_name, + string arg_subpath = "", bool arg_skipped = false, + bool arg_prefixes_checked = false) + : inode(arg_inode), include_level(arg_include_level), + name(arg_name), subpath(arg_subpath), skipped(arg_skipped), + prefixes_checked(arg_prefixes_checked) + { } }; extern std::list files_scanned; diff --git a/src/main.cc b/src/main.cc index 6e852c7e0b..d3d3c446f5 100644 --- a/src/main.cc +++ b/src/main.cc @@ -962,7 +962,9 @@ int main(int argc, char** argv) // Queue events reporting loaded scripts. for ( std::list::iterator i = files_scanned.begin(); i != files_scanned.end(); i++ ) { - if ( i->skipped ) continue; + if ( i->skipped ) + continue; + val_list* vl = new val_list; vl->append(new StringVal(i->name.c_str())); vl->append(new Val(i->include_level, TYPE_COUNT)); diff --git a/src/scan.l b/src/scan.l index 036a923703..bbac148a10 100644 --- a/src/scan.l +++ b/src/scan.l @@ -806,34 +806,39 @@ int yywrap() check_capture_filter_changes(); check_dpd_config_changes(); - // For each file scanned so far, and for each @prefix, look for - // a prefixed and flattened version of the loaded file in BROPATH. - // The flattening involves taking the path in BROPATH in which - // the scanned file lives and replacing '/' path separators with a '.' - // If the scanned file is "__load__.bro", that part of the flattened file - // name is discarded. - // If the prefix is non-empty, it gets placed in front of the flattened - // path, separated with another '.' + // For each file scanned so far, and for each @prefix, look for a + // prefixed and flattened version of the loaded file in BROPATH. The + // flattening involves taking the path in BROPATH in which the + // scanned file lives and replacing '/' path separators with a '.' If + // the scanned file is "__load__.bro", that part of the flattened + // file name is discarded. If the prefix is non-empty, it gets placed + // in front of the flattened path, separated with another '.' std::list::iterator it; bool found_prefixed_files = false; for ( it = files_scanned.begin(); it != files_scanned.end(); ++it ) { - if ( it->skipped || it->prefixes_checked ) continue; + if ( it->skipped || it->prefixes_checked ) + continue; + it->prefixes_checked = true; - // prefixes are pushed onto a stack, so iterate backwards + // Prefixes are pushed onto a stack, so iterate backwards. for ( int i = prefixes.length() - 1; i >= 0; --i ) { - // don't look at empty prefixes - if ( ! prefixes[i][0] ) continue; + // Don't look at empty prefixes. + if ( ! prefixes[i][0] ) + continue; + string s; s = dot_canon(it->subpath.c_str(), it->name.c_str(), prefixes[i]); FILE* f = search_for_file(s.c_str(), "bro", 0, false, 0); + //printf("====== prefix search ======\n"); //printf("File : %s\n", it->name.c_str()); //printf("Path : %s\n", it->subpath.c_str()); //printf("Dotted: %s\n", s.c_str()); //printf("Found : %s\n", f ? "T" : "F"); //printf("===========================\n"); + if ( f ) { add_input_file(s.c_str()); @@ -842,7 +847,9 @@ int yywrap() } } } - if ( found_prefixed_files ) return 0; + + if ( found_prefixed_files ) + return 0; // Add redef statements for any X=Y command line parameters. if ( params.size() > 0 ) diff --git a/src/util.cc b/src/util.cc index f11befe0e5..aa0433e052 100644 --- a/src/util.cc +++ b/src/util.cc @@ -972,8 +972,8 @@ FILE* search_for_file(const char* filename, const char* ext, char path[1024], full_filename_buf[1024]; - // append the currently loading script's path to BROPATH so that - // @loads can be referenced relatively + // Append the currently loading script's path to BROPATH so that + // @loads can be referenced relatively. if ( current_scanned_file_path != "" ) safe_snprintf(path, sizeof(path), "%s:%s", bro_path(), current_scanned_file_path.c_str());