This way there's no need to have the "proxy: " or "proxy(user): " prefix.
This also standardizes it to always be "proxy(user): ".
if ((ssl_flags & PROXY_SSL_FLAG_STARTTLS) != 0) {
if (client->proxy_backend_capability != NULL &&
!str_array_icase_find(t_strsplit(client->proxy_backend_capability, " "), "STARTTLS")) {
- e_error(client->common.event,
- "proxy: Remote doesn't support STARTTLS");
+ e_error(login_proxy_get_event(client->common.login_proxy),
+ "Remote doesn't support STARTTLS");
return -1;
}
str_append(str, "S STARTTLS\r\n");
/* logging in normally - use LOGIN command */
if (client->proxy_logindisabled &&
login_proxy_get_ssl_flags(client->common.login_proxy) == 0) {
- e_error(client->common.event,
- "proxy: Remote advertised LOGINDISABLED and SSL/TLS not enabled");
+ e_error(login_proxy_get_event(client->common.login_proxy),
+ "Remote advertised LOGINDISABLED and SSL/TLS not enabled");
return -1;
}
str_append(str, "L LOGIN ");
if (client->proxy_sasl_ir) {
if (dsasl_client_output(client->common.proxy_sasl_client,
&output, &len, &error) < 0) {
- e_error(client->common.event,
- "proxy: SASL mechanism %s init failed: %s",
+ e_error(login_proxy_get_event(client->common.login_proxy),
+ "SASL mechanism %s init failed: %s",
mech_name, error);
return -1;
}
int ret;
if (!str_begins(line, "* OK ")) {
- e_error(client->common.event,
- "proxy: Remote returned invalid banner: %s",
+ e_error(login_proxy_get_event(client->common.login_proxy),
+ "Remote returned invalid banner: %s",
str_sanitize(line, 160));
return -1;
}
str = t_str_new(128);
if (line[1] != ' ' ||
base64_decode(line+2, strlen(line+2), NULL, str) < 0) {
- e_error(client->event,
- "proxy: Server sent invalid base64 data in AUTHENTICATE response");
+ e_error(login_proxy_get_event(client->login_proxy),
+ "Server sent invalid base64 data in AUTHENTICATE response");
client_proxy_failed(client, TRUE);
return -1;
}
&data, &data_len, &error);
}
if (ret < 0) {
- e_error(client->event,
- "proxy: Server sent invalid authentication data: %s",
+ e_error(login_proxy_get_event(client->login_proxy),
+ "Server sent invalid authentication data: %s",
error);
client_proxy_failed(client, TRUE);
return -1;
if (!str_begins(line, "S OK ")) {
/* STARTTLS failed */
- e_error(client->event,
- "proxy: Remote STARTTLS failed: %s",
+ e_error(login_proxy_get_event(client->login_proxy),
+ "Remote STARTTLS failed: %s",
str_sanitize(line + 5, 160));
client_proxy_failed(client, TRUE);
return -1;
return 0;
} else {
/* tagged reply, shouldn't happen. */
- e_error(client->event,
- "proxy: Unexpected input, ignoring: %s",
+ e_error(login_proxy_get_event(client->login_proxy),
+ "Unexpected input, ignoring: %s",
str_sanitize(line, 160));
return 0;
}
if (client->proxy_master_user != NULL)
str_printfa(str, " (master %s)", client->proxy_master_user);
+ e_info(login_proxy_get_event(client->login_proxy), "%s", str_c(str));
login_proxy_detach(client->login_proxy);
- client_destroy_success(client, str_c(str));
+ client_destroy_success(client, NULL);
}
static void client_proxy_error(struct client *client, const char *text)
{
string_t *str = t_str_new(128);
- str_printfa(str, "proxy(%s): Login failed to %s:%u",
- client->virtual_user,
+ str_printfa(str, "Login failed to %s:%u",
login_proxy_get_host(client->login_proxy),
login_proxy_get_port(client->login_proxy));
if (strcmp(client->virtual_user, client->proxy_user) != 0) {
str_printfa(str, " (master %s)", client->proxy_master_user);
str_append(str, ": ");
str_append(str, line);
- e_info(client->event, "%s", str_c(str));
+ e_info(login_proxy_get_event(client->login_proxy), "%s", str_c(str));
}
void client_proxy_failed(struct client *client, bool send_line)
switch (i_stream_read(input)) {
case -2:
- e_error(client->event, "proxy: Remote input buffer full");
+ e_error(login_proxy_get_event(client->login_proxy),
+ "Remote input buffer full");
client_proxy_failed(client, TRUE);
return;
case -1:
line = i_stream_next_line(input);
duration = ioloop_time - client->created;
- e_error(client->event, "proxy: Remote %s:%u disconnected: %s "
+ e_error(login_proxy_get_event(client->login_proxy),
+ "Remote %s:%u disconnected: %s "
"(state=%s, duration=%us)%s",
login_proxy_get_host(client->login_proxy),
login_proxy_get_port(client->login_proxy),
}
static bool
-proxy_check_start(struct client *client, const struct client_auth_reply *reply,
+proxy_check_start(struct client *client, struct event *event,
+ const struct client_auth_reply *reply,
const struct dsasl_client_mech **sasl_mech_r)
{
if (reply->password == NULL) {
- e_error(client->event, "proxy: password not given");
+ e_error(event, "password not given");
return FALSE;
}
if (reply->host == NULL || *reply->host == '\0') {
- e_error(client->event, "proxy: host not given");
+ e_error(event, "host not given");
return FALSE;
}
if (reply->proxy_mech != NULL) {
*sasl_mech_r = dsasl_client_mech_find(reply->proxy_mech);
if (*sasl_mech_r == NULL) {
- e_error(client->event,
- "proxy: Unsupported SASL mechanism %s",
+ e_error(event, "Unsupported SASL mechanism %s",
reply->proxy_mech);
return FALSE;
}
if (login_proxy_is_ourself(client, reply->host, reply->port,
reply->destuser)) {
- e_error(client->event, "Proxying loops to itself");
+ e_error(event, "Proxying loops to itself");
return FALSE;
}
return TRUE;
event_set_append_log_prefix(event, t_strdup_printf(
"proxy(%s): ", client->virtual_user));
- if (!proxy_check_start(client, reply, &sasl_mech)) {
+ if (!proxy_check_start(client, event, reply, &sasl_mech)) {
client_proxy_error(client, PROXY_FAILURE_MSG);
event_unref(&event);
return -1;
secs = ioloop_time - client->created;
user_reason = "Timeout while finishing login.";
destroy_reason = t_strdup_printf(
- "proxy: Logging in to %s:%u timed out "
+ "Logging in to %s:%u timed out "
"(state=%s, duration=%us)",
login_proxy_get_host(client->login_proxy),
login_proxy_get_port(client->login_proxy),
client_proxy_get_state(client), secs);
- e_error(client->event, "%s", destroy_reason);
+ e_error(login_proxy_get_event(client->login_proxy),
+ "%s", destroy_reason);
} else {
user_reason = "Disconnected for inactivity.";
destroy_reason = "Disconnected: Inactivity";
struct ip_addr local_ip;
in_port_t local_port;
- str_printfa(str, "proxy(%s): ", proxy->client->virtual_user);
if (!proxy->connected) {
str_printfa(str, "connect(%s, %u) failed: %m",
net_ip2addr(&proxy->ip), proxy->port);
}
str_append_c(str, ')');
- e_error(proxy->client->event, "%s", str_c(str));
+ e_error(proxy->event, "%s", str_c(str));
}
static void proxy_reconnect_timeout(struct login_proxy *proxy)
if (proxy->ip.family == 0 &&
net_addr2ip(proxy->host, &proxy->ip) < 0) {
- e_error(proxy->client->event,
- "proxy(%s): BUG: host %s is not an IP "
- "(auth should have changed it)",
- proxy->client->virtual_user, proxy->host);
+ e_error(proxy->event,
+ "BUG: host %s is not an IP (auth should have changed it)",
+ proxy->host);
return -1;
}
rec->last_failure.tv_sec - rec->last_success.tv_sec > PROXY_IMMEDIATE_FAILURE_SECS &&
rec->num_waiting_connections > 1) {
/* the server is down. fail immediately */
- e_error(proxy->client->event,
- "proxy(%s): Host %s:%u is down",
- proxy->client->virtual_user,
+ e_error(proxy->event, "Host %s:%u is down",
net_ip2addr(&proxy->ip), proxy->port);
return -1;
}
i_assert(client->login_proxy == NULL);
if (set->host == NULL || *set->host == '\0') {
- e_error(client->event,
- "proxy(%s): host not given", client->virtual_user);
+ e_error(event, "host not given");
event_unref(&event);
return -1;
}
if (client->proxy_ttl <= 1) {
- e_error(client->event,
- "proxy(%s): TTL reached zero - "
- "proxies appear to be looping?", client->virtual_user);
+ e_error(event, "TTL reached zero - proxies appear to be looping?");
event_unref(&event);
return -1;
}
delay_ms = login_proxy_delay_disconnect(proxy);
ipstr = net_ip2addr(&proxy->client->ip);
- e_info(proxy->client->event, "proxy(%s): disconnecting %s%s%s",
- proxy->client->virtual_user,
+ e_info(proxy->event, "disconnecting %s%s%s",
ipstr != NULL ? ipstr : "",
reason == NULL ? "" : t_strdup_printf(" (%s)", reason),
delay_ms == 0 ? "" : t_strdup_printf(" - disconnecting client in %ums", delay_ms));
io_remove(&proxy->server_io);
if (ssl_iostream_client_context_cache_get(&ssl_set, &ssl_ctx, &error) < 0) {
- e_error(proxy->client->event,
- "proxy: Failed to create SSL client context: %s", error);
+ e_error(proxy->event, "Failed to create SSL client context: %s",
+ error);
return -1;
}
&proxy->server_output,
&proxy->server_ssl_iostream,
&error) < 0) {
- e_error(proxy->client->event,
- "proxy: Failed to create SSL client to %s:%u: %s",
+ e_error(proxy->event,
+ "Failed to create SSL client to %s:%u: %s",
net_ip2addr(&proxy->ip), proxy->port, error);
ssl_iostream_context_unref(&ssl_ctx);
return -1;
ssl_iostream_context_unref(&ssl_ctx);
if (ssl_iostream_handshake(proxy->server_ssl_iostream) < 0) {
error = ssl_iostream_get_last_error(proxy->server_ssl_iostream);
- e_error(proxy->client->event,
- "proxy: Failed to start SSL handshake to %s:%u: %s",
+ e_error(proxy->event,
+ "Failed to start SSL handshake to %s:%u: %s",
net_ip2addr(&proxy->ip), proxy->port,
ssl_iostream_get_last_error(proxy->server_ssl_iostream));
return -1;
str_printfa(str, "AUTH %s ", mech_name);
if (dsasl_client_output(client->common.proxy_sasl_client,
&sasl_output, &len, &error) < 0) {
- e_error(client->common.event,
- "proxy: SASL mechanism %s init failed: %s",
+ e_error(login_proxy_get_event(client->common.login_proxy),
+ "SASL mechanism %s init failed: %s",
mech_name, error);
return -1;
}
str = t_str_new(128);
if (base64_decode(line, strlen(line), NULL, str) < 0) {
- e_error(client->event, "proxy: Server sent invalid base64 data in AUTH response");
+ e_error(login_proxy_get_event(client->login_proxy),
+ "Server sent invalid base64 data in AUTH response");
return -1;
}
ret = dsasl_client_input(client->proxy_sasl_client,
&data, &data_len, &error);
}
if (ret < 0) {
- e_error(client->event,
- "proxy: Server sent invalid authentication data: %s",
- error);
+ e_error(login_proxy_get_event(client->login_proxy),
+ "Server sent invalid authentication data: %s", error);
return -1;
}
i_assert(ret == 0);
case POP3_PROXY_BANNER:
/* this is a banner */
if (!str_begins(line, "+OK")) {
- e_error(client->event,
- "proxy: Remote returned invalid banner: %s",
+ e_error(login_proxy_get_event(client->login_proxy),
+ "Remote returned invalid banner: %s",
str_sanitize(line, 160));
client_proxy_failed(client, TRUE);
return -1;
return 0;
case POP3_PROXY_STARTTLS:
if (!str_begins(line, "+OK")) {
- e_error(client->event, "proxy: Remote STLS failed: %s",
+ e_error(login_proxy_get_event(client->login_proxy),
+ "Remote STLS failed: %s",
str_sanitize(line, 160));
client_proxy_failed(client, TRUE);
return -1;
return 1;
case POP3_PROXY_XCLIENT:
if (!str_begins(line, "+OK")) {
- e_error(client->event,
- "proxy: Remote XCLIENT failed: %s",
+ e_error(login_proxy_get_event(client->login_proxy),
+ "Remote XCLIENT failed: %s",
str_sanitize(line, 160));
client_proxy_failed(client, TRUE);
return -1;
if ((client->proxy_capability & SMTP_CAPABILITY_AUTH) == 0) {
/* Prevent sending credentials to a server that has login
disabled; i.e., due to the lack of TLS */
- e_error(client->common.event, "proxy: "
+ e_error(login_proxy_get_event(client->common.login_proxy),
"Server has disabled authentication (TLS required?)");
return -1;
}
str_printfa(str, "AUTH %s ", mech_name);
if (dsasl_client_output(client->common.proxy_sasl_client,
&sasl_output, &len, &error) < 0) {
- e_error(client->common.event,
- "proxy: SASL mechanism %s init failed: %s",
+ e_error(login_proxy_get_event(client->common.login_proxy),
+ "SASL mechanism %s init failed: %s",
mech_name, error);
return -1;
}
str = t_str_new(128);
if (base64_decode(line, strlen(line), NULL, str) < 0) {
- e_error(client->event, "proxy: "
+ e_error(login_proxy_get_event(client->login_proxy),
"Server sent invalid base64 data in AUTH response");
return -1;
}
&data, &data_len, &error);
}
if (ret < 0) {
- e_error(client->event,
- "proxy: Server sent invalid authentication data: %s",
- error);
+ e_error(login_proxy_get_event(client->login_proxy),
+ "Server sent invalid authentication data: %s", error);
return -1;
}
i_assert(ret == 0);
}
if (subm_client->proxy_reply_status != 0 &&
subm_client->proxy_reply_status != status) {
- e_error(client->event,
- "proxy: Remote returned inconsistent SMTP reply: %s "
+ e_error(login_proxy_get_event(client->login_proxy),
+ "Remote returned inconsistent SMTP reply: %s "
"(status != %u)", str_sanitize(line, 160),
subm_client->proxy_reply_status);
client_proxy_failed(client, TRUE);
case SUBMISSION_PROXY_BANNER:
/* this is a banner */
if (invalid_line || status != 220) {
- e_error(client->event,
- "proxy: Remote returned invalid banner: %s",
+ e_error(login_proxy_get_event(client->login_proxy),
+ "Remote returned invalid banner: %s",
str_sanitize(line, 160));
client_proxy_failed(client, TRUE);
return -1;
case SUBMISSION_PROXY_EHLO:
case SUBMISSION_PROXY_TLS_EHLO:
if (invalid_line || (status / 100) != 2) {
- e_error(client->event,
- "proxy: Remote returned invalid EHLO line: %s",
+ e_error(login_proxy_get_event(client->login_proxy),
+ "Remote returned invalid EHLO line: %s",
str_sanitize(line, 160));
client_proxy_failed(client, TRUE);
return -1;
} else {
if ((subm_client->proxy_capability &
SMTP_CAPABILITY_STARTTLS) == 0) {
- e_error(client->event, "proxy: "
+ e_error(login_proxy_get_event(client->login_proxy),
"Remote doesn't support STARTTLS");
return -1;
}
return 0;
case SUBMISSION_PROXY_STARTTLS:
if (invalid_line || status != 220) {
- e_error(client->event,
- "proxy: Remote STARTTLS failed: %s",
+ e_error(login_proxy_get_event(client->login_proxy),
+ "Remote STARTTLS failed: %s",
str_sanitize(line, 160));
client_proxy_failed(client, TRUE);
return -1;
return 0;
case SUBMISSION_PROXY_XCLIENT:
if (invalid_line || (status / 100) != 2) {
- e_error(client->event,
- "proxy: Remote XCLIENT failed: %s",
+ e_error(login_proxy_get_event(client->login_proxy),
+ "Remote XCLIENT failed: %s",
str_sanitize(line, 160));
client_proxy_failed(client, TRUE);
return -1;