int main(int argc, char *argv[]) { if(getuid() != 0 || geteuid() != 0) { fprintf(stderr, "\n[!] You need root to run this tool\n"); /*return ERR; */ } #ifdef __linux__ /* QueMod is Linux only anyway */ setup_signal_handlers(); #endif int opt; int ret = 0; FILE *configuration_fd; char *conf_fd = "/opt/quemod/quemod.conf"; fprintf(stdout,"\n[ QueMod Framework ]\n"); if((configuration_fd = fopen(conf_fd, "r")) == NULL) { error("[!] Could not open the configuration file"); return ERR; } if((parse_configuration_file(configuration_fd)) == 0) { #ifdef DEBUG fprintf(stdout, "Parsed 0 lines in configuration file\n"); #endif } if(configuration_fd) { fclose(configuration_fd); } while((opt = getopt(argc, argv,"u:p:v:wd")) != ERR) { switch(opt) { case 'u': options.load_plugins = optarg; break; case 'p': options.plugin_dir = optarg; break; case 'v': options.ip_version = atol(optarg); break; case 'w': options.write_packets = YES; break; case 'd': options.write_packet_hdrs = YES; break; case '?': help(); break; } } ret = init_plugins(); if(ret == ERR) return ERR; memset(&stats, 0x0, sizeof(struct _stats)); ret = setup_nfq(); cleanup(); printf("\n"); return ret; }
void initialize() { time_t now = time(NULL); srand(now); startup_ts = now; if (init_log() == -1) { fprintf(stderr, "Failed to initialzie log module.\n"); exit(EXIT_FAILURE); } int ver = read_version(); if (ver < VERSION) { log_info("Previous version %d, current version %d", ver, VERSION); // this is a version update! if (need_to_delete_redis_db) { log_info("Deleting redis DB due to version update."); delete_redis_db(); } } else log_info("Current version: %d", VERSION); write_version(VERSION); start_redis_server(); if (init_socket() == -1) { log_error("Failed to initialize socket module."); exit(EXIT_FAILURE); } log_debug("Adding iptables rules."); if (add_iptables_rules() == -1) { log_error("Failed to add iptables rules."); exit(EXIT_FAILURE); } register_signal_handlers(); if (setup_nfq() == -1) { log_error("unable to setup netfilter_queue"); exit(EXIT_FAILURE); } log_debug("Init DNS client."); if (init_dns_cli() == -1) { log_error("Failed to initialize DNS module"); exit(EXIT_FAILURE); } log_debug("Init ev watchers."); init_ev_watchers(); // Begin to intercept packets //if (setup_strategy() == -1) { // log_error("Failed to setup strategy"); // exit(EXIT_FAILURE); //} log_debug("Loading TTL from file."); load_ttl_from_file("ttl"); // start a debug thread //pthread_t thread_dbg; //if (pthread_create(&thread_dbg, NULL, debug_main, NULL) != 0) { // log_error("Fail to create debug thread."); // exit(EXIT_FAILURE); //} // start a thread to handle communications with redis pthread_t thread_cache; if (pthread_create(&thread_cache, NULL, cache_main, NULL) != 0){ log_error("Fail to create caching thread."); exit(EXIT_FAILURE); } // start the DNS proxy thread pthread_t thread_dns; if (pthread_create(&thread_dns, NULL, dns_main, NULL) != 0){ log_error("Fail to create DNS thread."); exit(EXIT_FAILURE); } // Uploading diagnostic log is disabled. (2017.4.26) // start a thread to send feedback log //pthread_t thread_fb; //if (pthread_create(&thread_fb, NULL, feedback_main, NULL) != 0){ // log_error("Fail to create feedback thread."); // exit(EXIT_FAILURE); //} }