Some small layout tweaks that didn't get committed with the last merge.

This commit is contained in:
Robin Sommer 2011-07-22 13:35:29 -07:00
parent eb1e76600c
commit 1a46d78584
4 changed files with 38 additions and 25 deletions

View file

@ -93,16 +93,20 @@ extern char* writefile;
// Script file we have already scanned (or are in the process of scanning). // Script file we have already scanned (or are in the process of scanning).
// They are identified by inode number. // They are identified by inode number.
struct ScannedFile { struct ScannedFile {
ino_t inode; ino_t inode;
int include_level; int include_level;
string name; string name;
string subpath; // path in BROPATH's policy/ containing the file string subpath; // Path in BROPATH's policy/ containing the file.
bool skipped; // This ScannedFile was @unload'd bool skipped; // This ScannedFile was @unload'd.
bool prefixes_checked; // if loading prefixes for this file has been tried 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) ScannedFile(ino_t arg_inode, int arg_include_level, string arg_name,
: inode(arg_inode), include_level(arg_include_level), name(arg_name), subpath(arg_subpath), skipped(arg_skipped), prefixes_checked(arg_prefixes_checked) 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<ScannedFile> files_scanned; extern std::list<ScannedFile> files_scanned;

View file

@ -962,7 +962,9 @@ int main(int argc, char** argv)
// Queue events reporting loaded scripts. // Queue events reporting loaded scripts.
for ( std::list<ScannedFile>::iterator i = files_scanned.begin(); i != files_scanned.end(); i++ ) for ( std::list<ScannedFile>::iterator i = files_scanned.begin(); i != files_scanned.end(); i++ )
{ {
if ( i->skipped ) continue; if ( i->skipped )
continue;
val_list* vl = new val_list; val_list* vl = new val_list;
vl->append(new StringVal(i->name.c_str())); vl->append(new StringVal(i->name.c_str()));
vl->append(new Val(i->include_level, TYPE_COUNT)); vl->append(new Val(i->include_level, TYPE_COUNT));

View file

@ -806,34 +806,39 @@ int yywrap()
check_capture_filter_changes(); check_capture_filter_changes();
check_dpd_config_changes(); check_dpd_config_changes();
// For each file scanned so far, and for each @prefix, look for // For each file scanned so far, and for each @prefix, look for a
// a prefixed and flattened version of the loaded file in BROPATH. // prefixed and flattened version of the loaded file in BROPATH. The
// The flattening involves taking the path in BROPATH in which // flattening involves taking the path in BROPATH in which the
// the scanned file lives and replacing '/' path separators with a '.' // scanned file lives and replacing '/' path separators with a '.' If
// If the scanned file is "__load__.bro", that part of the flattened file // the scanned file is "__load__.bro", that part of the flattened
// name is discarded. // file name is discarded. If the prefix is non-empty, it gets placed
// If the prefix is non-empty, it gets placed in front of the flattened // in front of the flattened path, separated with another '.'
// path, separated with another '.'
std::list<ScannedFile>::iterator it; std::list<ScannedFile>::iterator it;
bool found_prefixed_files = false; bool found_prefixed_files = false;
for ( it = files_scanned.begin(); it != files_scanned.end(); ++it ) 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; 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 ) for ( int i = prefixes.length() - 1; i >= 0; --i )
{ {
// don't look at empty prefixes // Don't look at empty prefixes.
if ( ! prefixes[i][0] ) continue; if ( ! prefixes[i][0] )
continue;
string s; string s;
s = dot_canon(it->subpath.c_str(), it->name.c_str(), prefixes[i]); 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); FILE* f = search_for_file(s.c_str(), "bro", 0, false, 0);
//printf("====== prefix search ======\n"); //printf("====== prefix search ======\n");
//printf("File : %s\n", it->name.c_str()); //printf("File : %s\n", it->name.c_str());
//printf("Path : %s\n", it->subpath.c_str()); //printf("Path : %s\n", it->subpath.c_str());
//printf("Dotted: %s\n", s.c_str()); //printf("Dotted: %s\n", s.c_str());
//printf("Found : %s\n", f ? "T" : "F"); //printf("Found : %s\n", f ? "T" : "F");
//printf("===========================\n"); //printf("===========================\n");
if ( f ) if ( f )
{ {
add_input_file(s.c_str()); 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. // Add redef statements for any X=Y command line parameters.
if ( params.size() > 0 ) if ( params.size() > 0 )

View file

@ -972,8 +972,8 @@ FILE* search_for_file(const char* filename, const char* ext,
char path[1024], full_filename_buf[1024]; char path[1024], full_filename_buf[1024];
// append the currently loading script's path to BROPATH so that // Append the currently loading script's path to BROPATH so that
// @loads can be referenced relatively // @loads can be referenced relatively.
if ( current_scanned_file_path != "" ) if ( current_scanned_file_path != "" )
safe_snprintf(path, sizeof(path), "%s:%s", bro_path(), safe_snprintf(path, sizeof(path), "%s:%s", bro_path(),
current_scanned_file_path.c_str()); current_scanned_file_path.c_str());