void io (const char *what) { static int first_time = 1; long clock_timeout = 0, timer_timeout = 0, real_timeout = 0; static struct timeval my_now, my_timer, *time_ptr = &my_timer; int hold_over, rc; fd_set rd, wd; get_time(&my_now); now = my_now.tv_sec; /* CHECK FOR CPU SAVER MODE */ if (!cpu_saver && get_int_var(CPU_SAVER_AFTER_VAR)) if (now - idle_time > get_int_var(CPU_SAVER_AFTER_VAR) * 60) cpu_saver_on(0, NULL); rd = readables; wd = writables; FD_ZERO(&wd); FD_ZERO(&rd); set_screens(&rd, &wd); set_server_bits(&rd, &wd); set_process_bits(&rd); set_socket_read(&rd, &wd); icmp_sockets(&rd, &wd); #if defined(WANT_THREAD) #ifdef WANT_NSLOOKUP set_dns_output_fd(&rd); #endif #ifdef WANT_PTEST set_ptest_output_fd(&rd); #endif #ifdef WANT_MP3PLAYER set_mp3_output_fd(&rd); #endif # if defined(GTK) if (tgtk_okay()) tgtk_set_output_fd(&rd); # endif #endif clock_timeout = (timeout_select - (my_now.tv_sec % timeout_select)) * 1000; if (cpu_saver && get_int_var(CPU_SAVER_EVERY_VAR)) clock_timeout += (get_int_var(CPU_SAVER_EVERY_VAR) - 1) * 60000; timer_timeout = TimerTimeout(); if ((hold_over = unhold_windows())) real_timeout = 0; else if (timer_timeout <= clock_timeout) real_timeout = timer_timeout; else real_timeout = clock_timeout; if (real_timeout == -1) time_ptr = NULL; else { time_ptr->tv_sec = real_timeout / 1000; time_ptr->tv_usec = ((real_timeout % 1000) * 1000); } /* GO AHEAD AND WAIT FOR SOME DATA TO COME IN */ switch ((rc = new_select(&rd, &wd, time_ptr))) { case 0: break; case -1: { /* if we just got a sigint */ first_time = 0; if (cntl_c_hit) edit_char('\003'); else if (errno && errno != EINTR) { int ii = 0; fd_set rd1, wd1; char ii_buff_r[500]; char ii_buff_w[500]; int ii_r[FD_SETSIZE]; int ii_w[FD_SETSIZE]; yell("Select failed with [%d:%s]", errno, strerror(errno)); /* Reseed fd_sets so we can dig further */ yell("Packing fd_sets... Dump of fd's set in fd_set"); ii_buff_r[0] = '\0'; ii_buff_w[0] = '\0'; for (ii = 0; ii < FD_SETSIZE; ii++) { ii_r[ii] = 0; ii_w[ii] = 0; } FD_ZERO(&wd1); FD_ZERO(&rd1); set_screens(&rd1, &wd1); set_server_bits(&rd1, &wd1); set_process_bits(&rd1); set_socket_read(&rd1, &wd1); icmp_sockets(&rd1, &wd1); #if defined(WANT_THREAD) #ifdef WANT_NSLOOKUP set_dns_output_fd(&rd1); #endif #ifdef WANT_PTEST set_ptest_output_fd(&rd1); #endif #ifdef WANT_MP3PLAYER set_mp3_output_fd(&rd1); #endif # if defined(GTK) if (tgtk_okay()) tgtk_set_output_fd(&rd1); # endif #endif for (ii = 0; ii <= global_max_fd; ii++) { fd_set rblah, wblah; memcpy(&rblah, &rd1, sizeof(fd_set)); FD_SET(ii, &rblah); if (memcmp(&rblah, &rd1, sizeof(fd_set)) == 0) { char blahblah[20]; sprintf(blahblah, "%d ", ii); strcat(ii_buff_r, blahblah); ii_r[ii] = 1; } memcpy(&wblah, &wd1, sizeof(fd_set)); FD_SET(ii, &wblah); if (memcmp(&wblah, &wd1, sizeof(fd_set)) == 0) { char blahblah[20]; yell("blah"); sprintf(blahblah, "%d ", ii); strcat(ii_buff_w, blahblah); ii_w[ii] = 1; } } yell("Read fd's in set: %s", (ii_buff_r[0] == '\0') ? "<NONE>" : ii_buff_r); for (ii = 0; ii <= global_max_fd; ii++) { if (ii_r[ii] == 1) { struct stat st; if (fstat(ii, &st) == -1) { yell("READ FD %d is causing the select failure!", ii); } else { if (S_ISSOCK(st.st_mode)) yell("READ FD %d is a socket!", ii); else if (S_ISREG(st.st_mode)) yell("READ FD %d is a regular file!", ii); else if (S_ISFIFO(st.st_mode)) yell("READ FD %d is a FIFO!", ii); else ; } } } yell("Write fd's in set: %s", (ii_buff_w[0] == '\0') ? "<NONE>" : ii_buff_w); for (ii = 0; ii <= global_max_fd; ii++) { if (ii_w[ii] == 1) { struct stat st; if (fstat(ii, &st) == -1) { yell("WRITE FD %d is causing the select failure!", ii); } else { if (S_ISSOCK(st.st_mode)) yell("WRITE FD %d is a socket!", ii); else if (S_ISREG(st.st_mode)) yell("WRITE FD %d is a regular file!", ii); else if (S_ISFIFO(st.st_mode)) yell("WRITE FD %d is a FIFO!", ii); else ; } } } sleep(10); } else { #if 0 yell("errno 0 rc = -1, maybe it'll go away"); sleep(10); #endif } break; } /* we got something on one of the descriptors */ default: { cntl_c_hit = 0; now = time(NULL); make_window_current(NULL); do_screens(&rd); check_icmpresult(&rd, &wd); #if defined(WANT_THREAD) #ifdef WANT_NSLOOKUP dns_check(&rd); #endif #ifdef WANT_PTEST ptest_check(&rd); #endif #ifdef WANT_MP3PLAYER mp3_check(&rd); #endif # if defined(GTK) if (tgtk_okay()) tgtk_check(&rd); # endif #endif do_server(&rd, &wd); do_processes(&rd); scan_sockets(&rd, &wd); clean_sockets(); break; } } now = time(NULL); ExecuteTimers(); get_child_exit(-1); if (update_refresh) { update_refresh = 0; refresh_screen(0, NULL); } if (!hold_over) cursor_to_input(); if (update_clock(RESET_TIME)) { if (get_int_var(CLOCK_VAR)) { update_all_status(current_window, NULL, 0); cursor_to_input(); } clean_queue(get_int_var(TRANSFER_TIMEOUT_VAR)); /* timeout if send time is greater than 5 minutes */ } /* (set in term.c) -- we should redraw the screen here */ if (need_redraw) refresh_screen(0, NULL); #ifdef WANT_THREAD if (scan_done) scan_is_done(); #endif alloca(0); return; }
static sfsistat mlfi_dnslcheck(SMFICTX * ctx) { struct mlfiPriv *priv = GETCONTEXT(ctx); struct listNode *blp; uint8_t blisted; struct listNode *wlp; uint8_t wlisted; size_t len; char *msg; uint8_t a = (priv->hostaddr & 0xff000000) >> 24; uint8_t b = (priv->hostaddr & 0x00ff0000) >> 16; uint8_t c = (priv->hostaddr & 0x0000ff00) >> 8; uint8_t d = (priv->hostaddr & 0x000000ff); switch (a) { /* Loopback */ case 127: priv->stamp = STAMP_SKIPPED; return SMFIS_CONTINUE; break; /* RFC1910 (Private networks) */ case 10: /* Class A (10.0.0.0/8) */ priv->stamp = STAMP_SKIPPED; return SMFIS_CONTINUE; break; case 172: /* Class B (172.16.0.0/12) */ if ((b & 0xf0) == 0x10) { priv->stamp = STAMP_SKIPPED; return SMFIS_CONTINUE; } break; case 192: /* Class C (192.168.0.0/16) */ if (b == 168) { priv->stamp = STAMP_SKIPPED; return SMFIS_CONTINUE; } break; default: break; } /* blacklist */ blp = blacklist; blisted = 0; while ((blp != NULL) && (blisted == 0)) { #ifdef DEBUG mlog(LOG_DEBUG, "%s: Looking up %u.%u.%u.%u.%s.", (priv->msgid != NULL)? priv->msgid : priv->connectfrom, d, c, b, a, blp->dnsl); #endif if (dns_check(a, b, c, d, blp->dnsl) == DNSL_EXIST) { mlog(LOG_INFO, "%s: %s [%u.%u.%u.%u] is blacklisted on %s", (priv->msgid != NULL)? priv->msgid : priv->connectfrom, priv->connectfrom, a, b, c, d, blp->dnsl); blisted = 1; } else blp = blp->next; } if (blisted == 0) { priv->stamp = STAMP_PASSED; return SMFIS_CONTINUE; } /* whitelist */ wlp = whitelist; wlisted = 0; while ((wlp != NULL) && (wlisted == 0)) { #ifdef DEBUG mlog(LOG_DEBUG, "%s: Looking up %u.%u.%u.%u.%s.", (priv->msgid != NULL)? priv->msgid : priv->connectfrom, d, c, b, a, wlp->dnsl); #endif if (dns_check(a, b, c, d, wlp->dnsl) == DNSL_EXIST) { mlog(LOG_INFO, "%s: %s [%u.%u.%u.%u] is whitelisted on %s", (priv->msgid != NULL)? priv->msgid : priv->connectfrom, priv->connectfrom, a, b, c, d, wlp->dnsl); wlisted = 1; } else wlp = wlp->next; } if (wlisted != 0) { priv->stamp = STAMP_WHITELISTED; return SMFIS_CONTINUE; } priv->stamp = STAMP_BLACKLISTED; if(config.drymode) return SMFIS_CONTINUE; /* "Client address [aaa.bbb.ccc.ddd] blocked. " + msg + "aaa.bbb.ccc.ddd" + '\0' */ len = 43 + strlen(blp->msg) + 15 + 1; msg = malloc(len); if (msg == NULL) { mlog(LOG_ERR, "%s: %s: Memory allocation failed", (priv->msgid != NULL)? priv->msgid : priv->connectfrom, "mlfi_dnslcheck()"); smfi_setreply(ctx, "550", "5.7.1", blp->msg); } else { snprintf(msg, len, "Client address [%u.%u.%u.%u] blocked. %s%u.%u.%u.%u", (unsigned int) a, (unsigned int) b, (unsigned int) c, (unsigned int) d, blp->msg, (unsigned int) a, (unsigned int) b, (unsigned int) c, (unsigned int) d); smfi_setreply(ctx, "550", "5.7.1", msg); free(msg); msg = NULL; } mlfi_cleanup(ctx); return SMFIS_REJECT; }