commit b7482b5c02da35acb2ae0fb464cf1764dd2773b3 from: Martijn van Duren date: Thu Oct 15 07:27:15 2020 UTC Make use of opensmtpd's admd feature and libopensmtpd's osmtpd_register_conf commit - 4f29629bac17e2bc8fec298499946fd7518d249e commit + b7482b5c02da35acb2ae0fb464cf1764dd2773b3 blob - 3bdfa0acc2e91c50c8f38f9078d9efa9a81251d9 blob + b5353ae314cdccbdaaeac0a6453b87121d4faea6 --- filter-admdscrub.8 +++ filter-admdscrub.8 @@ -39,12 +39,14 @@ The flag can be set to reject mails containing these headers. If .Ar authserv-id -is not specified it defaults to the system hostname. +is not specified it defaults to opensmtpd's +.Ic admd +option. For more verbose logging the .Fl v flag can be used. .Sh SEE ALSO -.Xr smtpd 8 +.Xr smtpd.conf 5 .Sh STANDARDS .Rs .%A M. Kucherawy blob - 1f776bcb78fb44859e4b8b7ad9b91cefa9e09c8a blob + 612501c6400f2181e5c364afda6f4d315c590eb6 --- main.c +++ main.c @@ -36,6 +36,7 @@ struct admd_message { }; void usage(void); +void admd_conf(const char *, const char *); void *admd_message_new(struct osmtpd_ctx *); void admd_message_free(struct osmtpd_ctx *, void *); void admd_dataline(struct osmtpd_ctx *, const char *); @@ -45,7 +46,7 @@ void admd_cache(struct admd_message *, const char *); const char *admd_authservid(struct admd_message *); void admd_freecache(struct admd_message *); -char authservid[256]; +char *authservid; int reject = 0; int verbose = 0; @@ -73,26 +74,32 @@ main(int argc, char *argv[]) argv += optind; if (argc > 1) osmtpd_errx(1, "invalid authservid count"); - if (argc == 1) { - if (strlcpy(authservid, argv[0], sizeof(authservid)) >= - sizeof(authservid)) - osmtpd_errx(1, "authserv-id is too long"); - } else { - if (gethostname(authservid, sizeof(authservid)) == -1) - osmtpd_err(1, "gethostname"); - } - if (strchr(authservid, '\r') != NULL || - strchr(authservid, '\n') != NULL) - osmtpd_errx(1, "ubsupported character in authserv-id"); + if (argc == 1) + authservid = argv[0]; osmtpd_local_message(admd_message_new, admd_message_free); osmtpd_register_filter_dataline(admd_dataline); osmtpd_register_filter_commit(admd_commit); + osmtpd_register_conf(admd_conf); osmtpd_run(); return 0; } +void +admd_conf(const char *key, const char *value) +{ + if (key == NULL) { + if (authservid == NULL) + osmtpd_errx(1, "Didn't receieve admd config option"); + return; + } + if (strcmp(key, "admd") == 0 && authservid == NULL) { + if ((authservid = strdup(value)) == NULL) + osmtpd_err(1, "malloc"); + } +} + void * admd_message_new(struct osmtpd_ctx *ctx) {