Пример #1
0
static int
process_smtp_rcpt(int crypted)
{
    double delay;
    if (setjmp(defect_jmp_buf)) {
        if (defect_msg) {
            printf(STR_ACTION "WARN %s\n", defect_msg);
            defect_msg = 0;
        }
        else
            puts(STR_ACTION "WARN " PACKAGE_STRING " is not working properly");
        return 1;
    }
    get_grey_data();
    if (triplet_data.crypted != crypted) {
        triplet_data.crypted = crypted;
        if (debug_me) syslog(LOG_DEBUG,"crypted field changed for some reason");
    }
    delay = difftime(triplet_data.access_time, triplet_data.create_time);

    /* Block inbound mail that is from a previously unknown (ip, from, to) triplet */
    /* However we want different behavior for crypted stuff
     */

    if(crypted > 0) {
        if(delay < cryptlist_delay) {
            triplet_data.block_count++;
            fputs(STR_ACTION, stdout);
            printf_action(reject_action_fmt, cryptlist_delay - delay);
            putchar('\n');
        }
        else if (triplet_data.pass_count++)
            puts(STR_ACTION "DUNNO");
        else {
            fputs(STR_ACTION, stdout);
            printf_action(cryptlisted_action_fmt, delay);
            putchar('\n');
        }
    } else {
        if(delay < greylist_delay || block_unencrypted) {
            triplet_data.block_count++;
            fputs(STR_ACTION, stdout);
            if(block_unencrypted == 1) {
                printf_action(reject_unencrypted_action_fmt, (3600*24)); // block it for a day
            } else {
                printf_action(reject_unencrypted_action_fmt, greylist_delay - delay);
            }
            putchar('\n');
        }
        else if (triplet_data.pass_count++)
            puts(STR_ACTION "DUNNO");
        else {
            fputs(STR_ACTION, stdout);
            printf_action(greylisted_action_fmt, delay);
            putchar('\n');
        }
    }
    return put_grey_data();
}
Пример #2
0
static int
process_smtp_rcpt(int crypted)
{
    double delay;
    int rc;
    DB_ENV *dbenv;
    DB *db;
    DB_TXN *txn = NULL;
    if (setjmp(defect_jmp_buf)) {
	if (defect_msg) {
	    printf(STR_ACTION "WARN %s\n", defect_msg);
	    defect_msg = 0;
	}
	else
	    puts(STR_ACTION "WARN " PACKAGE_STRING " is not working properly");
	if (txn)
	    call_db(txn->abort(txn), "Failed to abort transaction");
	return 1;
    }
    rc = get_dbenv(&dbenv, 1);
    if (rc)
	jmperr("get_dbenv failed");
    rc = get_db(&db, 1);
    if (rc)
	jmperr("get_db failed");
    rc = call_db(dbenv->txn_begin(dbenv, NULL, &txn, 0),
		 "txn_begin failed in process_smtp_rcpt");
    if (rc)
	jmperr("txn_begin failed");
    get_grey_data(db, txn);
    if (triplet_data.crypted != crypted) {
      triplet_data.crypted = crypted;
      if (debug_me) syslog(LOG_DEBUG,"crypted field changed for some reason");
    }
    delay = difftime(triplet_data.access_time, triplet_data.create_time);
    /* Block inbound mail that is from a previously unknown (ip, from, to) triplet */
    /* However we want different behavior for crypted stuff
     */

    if(crypted > 0) {
      if(delay < cryptlist_delay) {
	triplet_data.block_count++;
	fputs(STR_ACTION, stdout);
	printf_action(reject_action_fmt, greylist_delay - delay);
	putchar('\n');
    }
    else if (triplet_data.pass_count++)
	puts(STR_ACTION "DUNNO");
      else {
        fputs(STR_ACTION, stdout);
        printf_action(cryptlisted_action_fmt, delay);
        putchar('\n');
      }
    } else {
      if(delay < greylist_delay || block_unencrypted) {
        triplet_data.block_count++;
        fputs(STR_ACTION, stdout);
        if(block_unencrypted == 1) {
          printf_action(reject_unencrypted_action_fmt, (3600*24)); // block it for a day
        } else {
          printf_action(reject_unencrypted_action_fmt, greylist_delay - delay);
        }
        putchar('\n');
      }
      else if (triplet_data.pass_count++)
        puts(STR_ACTION "DUNNO");
      else {
        fputs(STR_ACTION, stdout);
        printf_action(greylisted_action_fmt, delay);
        putchar('\n');
      }
    }
    rc = put_grey_data(db, txn);
    if (rc)
	call_db(txn->abort(txn), "abort failed");
    else
	call_db(txn->commit(txn, 0), "commit failed");
    return rc;
}