diff --git a/rhost.c b/rhost.c index 4d46071..c1b618a 100644 --- a/rhost.c +++ b/rhost.c @@ -781,15 +781,48 @@ int update_freshclam(int argc, char *argv[]) } +static char help_information(void) +{ + static const char name[] = "Rhost"; + static const char subject[] = "Reject host&scan for viruses"; + static const struct { + const char *email; + } author = { + "AIXIAO@AIXIAO.ME", + }; + + static const char usage[] = "Usage: [-?h] [-d]"; + static const char *s_help[] = { + "", + "Options:", + " -d : Background running", + " -? -h --help : help information", + " The configuration file needs to be in the same directory as the executable file!", + "", + "", + 0 + }; + + fprintf(stderr, "%s %s\n", name, subject); + fprintf(stderr, "Author: %s\n", author.email); + fprintf(stderr, "%s\n", usage); + + int l; + for (l = 0; s_help[l]; l++) { + fprintf(stderr, "%s\n", s_help[l]); + } + + BUILD("Compile、link.\n"); + + return 0; +} + int main(int argc, char *argv[], char **env) { - + signal(SIGCHLD, sig_child); // 创建捕捉子进程退出信号 - // 更新病毒库 - update_freshclam(argc, argv); - - + int pid; int i; char move[BUFFER]; @@ -800,6 +833,15 @@ int main(int argc, char *argv[], char **env) (void)get_executable_path(path, executable_filename, sizeof(path)); strcat(executable_filename, ".conf"); strcat(path, executable_filename); + + if (NULL != argv[1]) { + if (0 == strcmp(argv[1], "-v") || 0 == strcmp(argv[1], "--version") || 0 == strcmp(argv[1] , "-h") || 0 == strcmp(argv[1] , "--help") || 0 == strcmp(argv[1] , "-?")) + { + help_information(); + exit(0); + } + } + if (1 == access(path, F_OK)) { printf("配置文件不存在!\n"); @@ -809,6 +851,10 @@ int main(int argc, char *argv[], char **env) //ptintf_conf(conf); + // 更新病毒库 + update_freshclam(argc, argv); + + // 创建移除目录 if (conf->CLAMAV_ARG) { diff --git a/rhost.h b/rhost.h index 7be199c..e2ab885 100644 --- a/rhost.h +++ b/rhost.h @@ -94,6 +94,7 @@ void cron_free(void* p) #define LONG_BUFFER 1024*1000 #define ARGS_NUM 20 #define WHITELIST_IP_NUM 1024 +#define BUILD(fmt...) do { fprintf(stderr,"%s %s ",__DATE__,__TIME__); fprintf(stderr, ##fmt); } while(0) #define AWK " | awk -v num=%d '{a[$1]+=1;} END {for(i in a){if (a[i] >= num) {print i;}}}' " #define GE_10 "grep -E \"^$(LC_ALL=\"C\" date \"+%h\").$(LC_ALL=\"C\" date \"+%d\")\" /var/log/auth.log | grep failure | grep rhost"