Skip to content

Commit

Permalink
--readscan ignores /etc/masscan
Browse files Browse the repository at this point in the history
  • Loading branch information
robertdavidgraham committed Jan 6, 2014
1 parent 387771c commit b58a138
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
28 changes: 28 additions & 0 deletions src/main-conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1690,6 +1690,22 @@ masscan_read_config_file(struct Masscan *masscan, const char *filename)
}



/***************************************************************************
***************************************************************************/
int masscan_conf_contains(const char *x, int argc, char **argv)
{
int i;

for (i=0; i<argc; i++) {
if (strcmp(argv[i], x) == 0)
return 1;
}

return 0;
}


/***************************************************************************
***************************************************************************/
int
Expand Down Expand Up @@ -1717,6 +1733,18 @@ mainconf_selftest()

}

/* */
{
int argc = 6;
char *argv[] = { "foo", "bar", "-ddd", "--readscan", "xxx", "--something" };

if (masscan_conf_contains("--nothing", argc, argv))
return 1;

if (!masscan_conf_contains("--readscan", argc, argv))
return 1;
}

return 0;
}

15 changes: 12 additions & 3 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1250,7 +1250,7 @@ main_scan(struct Masscan *masscan)

status_print(&status, masscan->resume.index, range, rate,
total_tcbs, total_synacks, total_syns,
masscan->wait - (time(0) - now));
masscan->wait + 1 - (time(0) - now));

if (time(0) - now >= masscan->wait)
control_c_pressed_again = 1;
Expand Down Expand Up @@ -1315,6 +1315,13 @@ int main(int argc, char *argv[])
".");
masscan->is_capture_cert = 1;

/*
* Pre-parse the command-line
*/
if (masscan_conf_contains("--readscan", argc, argv)) {
masscan->is_readscan = 1;
}

/*
* On non-Windows systems, read the defaults from the file in
* the /etc directory. These defaults will contain things
Expand All @@ -1324,8 +1331,10 @@ int main(int argc, char *argv[])
* makes a mistake
*/
#if !defined(WIN32)
if (access("/etc/masscan/masscan.conf", 0) == 0) {
masscan_read_config_file(masscan, "/etc/masscan/masscan.conf");
if (!masscan->is_readscan) {
if (access("/etc/masscan/masscan.conf", 0) == 0) {
masscan_read_config_file(masscan, "/etc/masscan/masscan.conf");
}
}
#endif

Expand Down
13 changes: 13 additions & 0 deletions src/masscan.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,11 @@ struct Masscan
* by incrementing the seed
*/
unsigned is_infinite:1;

/**
* --readscan
*/
unsigned is_readscan:1;
};


Expand All @@ -203,6 +208,14 @@ void masscan_usage(void);
void masscan_save_state(struct Masscan *masscan);
void main_listscan(struct Masscan *masscan);

/**
* Pre-scan the command-line looking for options that may affect how
* previous options are handled. This is a bit of a kludge, really.
*/
int masscan_conf_contains(const char *x, int argc, char **argv);



int
masscan_initialize_adapter(
struct Masscan *masscan,
Expand Down

0 comments on commit b58a138

Please sign in to comment.