Skip to content

Commit

Permalink
smtpclient.c: use client_bind_name or servername as EHLO hostname
Browse files Browse the repository at this point in the history
  • Loading branch information
rsto authored and elliefm committed Jul 24, 2024
1 parent 7c2ba7c commit 400346f
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 4 deletions.
5 changes: 5 additions & 0 deletions cassandane/Cassandane/Instance.pm
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,11 @@ sub _generate_imapd_conf
smtp_backend => 'host',
smtp_host => $self->{smtphost},
);
if (not defined $config->get("servername")) {
# smtpclient needs client_bind_name or servername,
# falls back to servername if client_bind isn't set.
$config->set(servername => "127.0.0.1");
}
}
}
else {
Expand Down
4 changes: 2 additions & 2 deletions cassandane/Cassandane/Net/SMTPServer.pm
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ sub new_connection {
}

sub helo {
my ($Self) = @_;
$Self->mylog("SMTP: HELO");
my ($Self, $Host) = @_;
$Self->mylog("SMTP: HELO $Host");
return if $Self->override('helo');
$Self->send_client_resp(250, "localhost",
"AUTH", "DSN", "SIZE 10000", "ENHANCEDSTATUSCODES");
Expand Down
16 changes: 16 additions & 0 deletions changes/next/smtpclient_ehlo_hostname
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Description:

Changes the SMTP client EHLO hostname from "localhost" to the `client_bind_name` config option, if set and enabled, or `servername` otherwise.


Config changes:

None

Upgrade instructions:

None

GitHub issue:

4960
32 changes: 30 additions & 2 deletions imap/smtpclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,13 @@ enum {
SMTPCLIENT_CAPA_JMAPID = (1 << 10),
};

static const char *smtpclient_ehlo_hostname = NULL;

static struct protocol_t smtp_protocol =
{ "smtp", "smtp", TYPE_STD,
{ { { 0, "220 " },
{ "EHLO", "localhost", "250 ", NULL,
// EHLO hostname will be set in smtpclient_open().
{ "EHLO", NULL, "250 ", NULL,
CAPAF_ONE_PER_LINE|CAPAF_SKIP_FIRST_WORD|CAPAF_DASH_STUFFING,
{ { "AUTH", CAPA_AUTH },
{ "STARTTLS", CAPA_STARTTLS },
Expand Down Expand Up @@ -143,6 +146,31 @@ static void smtpclient_logerror(smtpclient_t *sm, const char *cmd, int r);

EXPORTED int smtpclient_open(smtpclient_t **smp)
{
if (!smtpclient_ehlo_hostname) {
if (config_getswitch(IMAPOPT_CLIENT_BIND)) {
smtpclient_ehlo_hostname =
config_getstring(IMAPOPT_CLIENT_BIND_NAME);
}
if (!smtpclient_ehlo_hostname) {
smtpclient_ehlo_hostname = config_getstring(IMAPOPT_SERVERNAME);
}
if (!smtpclient_ehlo_hostname) {
xsyslog(LOG_ERR,
"can not determine EHLO hostname, "
"either client_bind/client_bind_name or servername option must be set",
NULL);
return IMAP_INTERNAL;
}
if (smtp_protocol.type == TYPE_STD &&
!strcasecmpsafe(smtp_protocol.u.std.capa_cmd.cmd, "EHLO")) {
smtp_protocol.u.std.capa_cmd.arg = smtpclient_ehlo_hostname;
}
else {
xsyslog(LOG_ERR, "unexpected smtp_protocol value", NULL);
return IMAP_INTERNAL;
}
}

int r = 0;
const char *backend = config_getstring(IMAPOPT_SMTP_BACKEND);

Expand Down Expand Up @@ -366,7 +394,7 @@ static int smtpclient_ehlo(smtpclient_t *sm)
int r = 0;

/* Say EHLO */
buf_setcstr(&sm->buf, "EHLO localhost\r\n");
buf_printf(&sm->buf, "EHLO %s\r\n", smtpclient_ehlo_hostname);
r = smtpclient_writebuf(sm, &sm->buf, 1);
if (r) goto done;
buf_reset(&sm->buf);
Expand Down

0 comments on commit 400346f

Please sign in to comment.