227 #include <sys/stat.h>
280 #define STR(x) vstring_str(x)
281 #define STREQ(x,y) (strcmp(x,y) == 0)
305 #define STATUS_FROM_RAW_ENTRY(e) atoi(e)
309 static void verify_make_entry(
VSTRING *buf,
int status,
long probed,
310 long updated,
const char *text)
317 static int verify_parse_entry(
char *buf,
int *status,
long *probed,
318 long *updated,
char **text)
323 if ((probed_text =
split_at(buf,
':')) != 0
324 && (updated_text =
split_at(probed_text,
':')) != 0
325 && (*text =
split_at(updated_text,
':')) != 0
328 &&
alldig(updated_text)) {
329 *probed = atol(probed_text);
330 *updated = atol(updated_text);
343 && (*probed || *updated))
346 msg_warn(
"bad address verify table entry: %.100s", buf);
352 static const char *verify_stat2name(
int addr_status)
355 return (
"deliverable");
357 return (
"undeliverable");
359 return (
"undeliverable");
365 static void verify_update_service(
VSTREAM *client_stream)
371 const char *status_name;
372 const char *raw_data;
383 if ((status_name = verify_stat2name(addr_status)) == 0) {
384 msg_warn(
"bad recipient status %d for recipient %s",
385 addr_status,
STR(addr));
401 updated = (
long) time((time_t *) 0);
402 verify_make_entry(buf, addr_status, probed, updated,
STR(text));
404 msg_info(
"PUT %s status=%d probed=%ld updated=%ld text=%s",
405 STR(addr), addr_status, probed, updated,
STR(text));
420 static void verify_post_mail_fclose_action(
int unused_status,
421 void *unused_context)
428 static void verify_post_mail_action(
VSTREAM *stream,
void *context)
441 static void verify_query_service(
VSTREAM *client_stream)
446 const char *raw_data;
455 long now = (
long) time((time_t *) 0);
473 #define POSITIVE_ENTRY_EXPIRED(addr_status, updated) \
474 (addr_status == DEL_RCPT_STAT_OK && updated + var_verify_pos_exp < now)
475 #define NEGATIVE_ENTRY_EXPIRED(addr_status, updated) \
476 (addr_status != DEL_RCPT_STAT_OK && updated + var_verify_neg_exp < now)
477 #define PROBE_TTL 1000
484 verify_parse_entry(
STR(get_buf), &addr_status, &probed,
485 &updated, &text) < 0)
492 text =
"Address verification in progress";
497 msg_info(
"GOT %s status=%d probed=%ld updated=%ld text=%s",
498 STR(addr), addr_status, probed, updated, text);
520 #define POSITIVE_REFRESH_NEEDED(addr_status, updated) \
521 (addr_status == DEL_RCPT_STAT_OK && updated + var_verify_pos_try < now)
522 #define NEGATIVE_REFRESH_NEEDED(addr_status, updated) \
523 (addr_status != DEL_RCPT_STAT_OK && updated + var_verify_neg_try < now)
529 msg_info(
"PROBE %s status=%d probed=%ld updated=%ld",
530 STR(addr), addr_status, now, updated);
536 verify_post_mail_action,
540 verify_make_entry(put_buf, addr_status, now, updated, text);
542 msg_info(
"PUT %s status=%d probed=%ld updated=%ld text=%s",
543 STR(addr), addr_status, now, updated, text);
557 static int verify_cache_validator(
const char *addr,
const char *raw_data,
567 #define POS_OR_NEG_ENTRY_EXPIRED(stat, stamp) \
568 (POSITIVE_ENTRY_EXPIRED((stat), (stamp)) \
569 || NEGATIVE_ENTRY_EXPIRED((stat), (stamp)))
572 return (verify_parse_entry(
STR(get_buf), &addr_status,
573 &probed, &updated, &text) == 0
580 static void verify_service(
VSTREAM *client_stream,
char *unused_service,
589 msg_fatal(
"unexpected command-line argument: %s", argv[0]);
601 verify_update_service(client_stream);
603 verify_query_service(client_stream);
605 msg_warn(
"unrecognized request: \"%s\", ignored",
STR(request));
617 static void verify_dump(
char *unused_name,
char **unused_argv)
632 static void post_jail_init(
char *unused_name,
char **unused_argv)
665 static void pre_jail_init(
char *unused_name,
char **unused_argv)
705 #define VERIFY_DICT_OPEN_FLAGS (DICT_FLAG_DUP_REPLACE | DICT_FLAG_SYNC_UPDATE \
706 | DICT_FLAG_OPEN_LOCK | DICT_FLAG_UTF8_REQUEST)
708 saved_mask = umask(022);
714 (void) umask(saved_mask);
727 int main(
int argc,
char **argv)
#define VAR_VERIFY_NEG_TRY
#define RESTORE_SAVED_EUGID()
#define DEF_VERIFY_SENDER_TTL
#define SMTPUTF8_FLAG_NONE
#define CA_MAIL_SERVER_STR_TABLE(v)
#define NEGATIVE_ENTRY_EXPIRED(addr_status, updated)
#define DEL_RCPT_STAT_TODO
const char * dict_cache_lookup(DICT_CACHE *cp, const char *cache_key)
char * data_redirect_map(VSTRING *result, const char *map)
int var_verify_sender_ttl
#define SAVE_AND_SET_EUGID(uid, gid)
#define CA_MAIL_SERVER_EXIT(v)
#define DEF_VERIFY_SENDER
#define RECV_ATTR_INT(name, val)
#define DEL_RCPT_STAT_BOUNCE
char * translit(char *, const char *, const char *)
int alldig(const char *string)
#define CA_DICT_CACHE_CTL_INTERVAL(v)
#define POS_OR_NEG_ENTRY_EXPIRED(stat, stamp)
#define POSITIVE_REFRESH_NEEDED(addr_status, updated)
#define DEF_VERIFY_NEG_EXP
NORETURN multi_server_main(int, char **, MULTI_SERVER_FN,...)
VSTRING * vstring_strcpy(VSTRING *vp, const char *src)
#define CA_DICT_CACHE_CTL_FLAGS(v)
#define POSITIVE_ENTRY_EXPIRED(addr_status, updated)
void post_mail_fclose_async(VSTREAM *stream, void(*notify)(int status, void *context), void *context)
#define CA_MAIL_SERVER_POST_INIT(v)
#define VERIFY_DICT_OPEN_FLAGS
#define STATUS_FROM_RAW_ENTRY(e)
#define DICT_CACHE_FLAG_VERBOSE
#define VAR_VERIFY_NEG_EXP
#define DEF_VERIFY_NEG_TRY
#define VAR_VERIFY_SCAN_CACHE
void msg_warn(const char *fmt,...)
int dict_cache_delete(DICT_CACHE *cp, const char *cache_key)
VSTRING * vstring_alloc(ssize_t len)
#define DEF_VERIFY_POS_EXP
#define CA_DICT_CACHE_CTL_END
#define MAIL_SRC_MASK_VERIFY
#define CA_DICT_CACHE_CTL_VALIDATOR(v)
#define MAIL_VERSION_STAMP_ALLOCATE
#define VAR_VERIFY_SENDER_TTL
int main(int argc, char **argv)
void dict_cache_close(DICT_CACHE *cp)
VSTRING * vstring_sprintf(VSTRING *vp, const char *format,...)
#define DEF_VERIFY_SCAN_CACHE
#define CA_DICT_CACHE_CTL_CONTEXT(v)
#define CA_MAIL_SERVER_TIME_TABLE(v)
#define SEND_ATTR_INT(name, val)
NORETURN msg_fatal(const char *fmt,...)
int vstream_fflush(VSTREAM *stream)
#define DEF_VERIFY_POS_TRY
const char * make_verify_sender_addr(void)
#define MAIL_ATTR_ADDR_STATUS
void post_mail_fopen_async(const char *sender, const char *recipient, int source_class, int trace_flags, int utf8_flags, VSTRING *queue_id, void(*notify)(VSTREAM *, void *), void *context)
#define DICT_CACHE_FLAG_STATISTICS
#define VAR_VERIFY_SENDER
#define NEGATIVE_REFRESH_NEEDED(addr_status, updated)
VSTRING * vstring_free(VSTRING *vp)
MAIL_VERSION_STAMP_DECLARE
int var_verify_scan_cache
#define CA_MAIL_SERVER_SOLITARY
char * split_at(char *string, int delimiter)
int dict_cache_update(DICT_CACHE *cp, const char *cache_key, const char *cache_val)
DICT_CACHE * dict_cache_open(const char *dbname, int open_flags, int dict_flags)
#define DEL_RCPT_STAT_DEFER
#define SEND_ATTR_STR(name, val)
#define DEL_REQ_FLAG_MTA_VRFY
#define VAR_VERIFY_POS_EXP
#define VAR_VERIFY_POS_TRY
#define CA_MAIL_SERVER_PRE_INIT(v)
#define RECV_ATTR_STR(name, val)
void msg_info(const char *fmt,...)
void dict_cache_control(DICT_CACHE *cp,...)