Skip to content

Commit

Permalink
Fix help and command line arguments
Browse files Browse the repository at this point in the history
Fixes to the command line arguments and help messages in
ossec-logtest. This is related to the issues in ossec#207.
  • Loading branch information
awiddersheim committed Aug 24, 2014
1 parent 76599fe commit a57c19b
Showing 1 changed file with 17 additions and 35 deletions.
52 changes: 17 additions & 35 deletions src/analysisd/testrule.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,44 +90,36 @@ int ReadDecodeXML(char *file);
int SetDecodeXML();


void logtest_help(const char *prog)
/* print help statement */
void help_local()
{
print_out(" ");
print_out("%s %s - %s (%s)", __ossec_name, __version, __author, __contact);
print_out("%s", __site);
print_out(" ");
print_out(" %s: -[Vatfdh] [-U ut_str] [-u user] [-g group] [-c config] [-D dir]", prog);
print_header();
print_out(" %s: -[Vhdtfva] [-c config] [-D dir] [-U rule:alert:decoder]", ARGV0);
print_out(" -V Version and license message");
print_out(" -a Alerts output");
print_out(" -h This help message");
print_out(" -d Execute in debug mode. This parameter");
print_out(" can be specified multiple times");
print_out(" to increase the debug level.");
print_out(" -t Test configuration");
print_out(" -f Run in foreground");
print_out(" -a Alerts output");
print_out(" -v Verbose (full) output/rule debugging");
print_out(" -d Execute in debug mode");
print_out(" -h This help message");
print_out(" -U <rule:alert:decoder> Unit test. Refer to contrib/ossec-testing/runtests.py");
print_out(" -u <user> Run as 'user'");
print_out(" -g <group> Run as 'group'");
print_out(" -c <config> Read the 'config' file");
print_out(" -D <dir> Chroot to 'dir'");
print_out(" -U <rule:alert:decoder> Unit test. Refer to contrib/ossec-testing/runtests.py");
print_out(" ");
exit(1);
}



/** int main(int argc, char **argv)
*/
int main(int argc, char **argv)
{
int t_config = 0;
int test_config = 0;
int c = 0, m_queue = 0;
char *ut_str = NULL;

char *dir = DEFAULTDIR;
// TODO: delete or implement
char *user __attribute__((unused)) = USER;
// TODO: delete or implement
char *group __attribute__((unused)) = GROUPGLOBAL;

char *cfg = DEFAULTCPATH;

/* Setting the name */
Expand All @@ -142,16 +134,16 @@ int main(int argc, char **argv)
active_responses = NULL;
memset(prev_month, '\0', 4);

while((c = getopt(argc, argv, "VatvdhU:u:g:D:c:")) != -1){
while((c = getopt(argc, argv, "VatvdhU:D:c:")) != -1){
switch(c){
case 'V':
print_version();
break;
case 't':
t_config = 1;
test_config = 1;
break;
case 'h':
logtest_help(ARGV0);
help_local();
break;
case 'd':
nowDebug();
Expand All @@ -161,16 +153,6 @@ int main(int argc, char **argv)
ErrorExit("%s: -U needs an argument",ARGV0);
ut_str = optarg;
break;
case 'u':
if(!optarg)
ErrorExit("%s: -u needs an argument",ARGV0);
user = optarg;
break;
case 'g':
if(!optarg)
ErrorExit("%s: -g needs an argument",ARGV0);
group = optarg;
break;
case 'D':
if(!optarg)
ErrorExit("%s: -D needs an argument",ARGV0);
Expand All @@ -188,7 +170,7 @@ int main(int argc, char **argv)
full_output = 1;
break;
default:
logtest_help(ARGV0);
help_local();
break;
}

Expand Down Expand Up @@ -352,7 +334,7 @@ int main(int argc, char **argv)
}


if(t_config == 1)
if(test_config == 1)
{
exit(0);
}
Expand Down

0 comments on commit a57c19b

Please sign in to comment.