o_stream_nsendv(conn->output, iov, 2);
}
-void auth_master_log_error(struct auth_master_connection *conn,
- const char *fmt, ...)
+static const char *
+auth_master_event_log_callback(struct auth_master_connection *conn,
+ enum log_type log_type ATTR_UNUSED,
+ const char *message)
{
- va_list args;
string_t *str = t_str_new(128);
- str_printfa(str, "created %d msecs ago",
+ str_printfa(str, "auth-master client: %s (created %d msecs ago", message,
timeval_diff_msecs(&ioloop_timeval, &conn->create_time));
if (conn->handshake_time.tv_sec != 0) {
str_printfa(str, ", handshake %d msecs ago",
timeval_diff_msecs(&ioloop_timeval, &conn->create_time));
}
-
- va_start(args, fmt);
- i_error("%s (%s)", t_strdup_vprintf(fmt, args), str_c(str));
- va_end(args);
+ str_append_c(str, ')');
+ return str_c(str);
}
static bool
str_to_uint(list[0], &id) < 0 ||
str_to_uint(list[1], &client_pid) < 0 ||
str_to_uint(list[2], &client_id) < 0) {
- auth_master_log_error(conn, "BUG: Master sent broken REQUEST");
+ e_error(conn->event, "BUG: Master sent broken REQUEST");
return FALSE;
}
buffer_create_from_data(&buf, cookie, sizeof(cookie));
if (hex_to_binary(list[3], &buf) < 0) {
- auth_master_log_error(conn,
- "BUG: Master sent broken REQUEST cookie");
+ e_error(conn->event, "BUG: Master sent broken REQUEST cookie");
return FALSE;
}
params = list + 4;
client_conn = auth_client_connection_lookup(client_pid);
if (client_conn == NULL) {
- auth_master_log_error(conn,
+ e_error(conn->event,
"Master requested auth for nonexistent client %u",
client_pid);
o_stream_nsend_str(conn->output,
t_strdup_printf("FAIL\t%u\n", id));
} else if (!mem_equals_timing_safe(client_conn->cookie, cookie, sizeof(cookie))) {
- auth_master_log_error(conn,
+ e_error(conn->event,
"Master requested auth for client %u with invalid cookie",
client_pid);
o_stream_nsend_str(conn->output,
t_strdup_printf("FAIL\t%u\n", id));
} else if (!auth_request_handler_master_request(
client_conn->request_handler, conn, id, client_id, params)) {
- auth_master_log_error(conn,
+ e_error(conn->event,
"Master requested auth for non-login client %u",
client_pid);
o_stream_nsend_str(conn->output,
/* <id> [<user> [<user> [..]] */
list = t_strsplit_tabescaped(args);
if (list[0] == NULL) {
- auth_master_log_error(conn,
- "BUG: doveadm sent broken CACHE-FLUSH");
+ e_error(conn->event, "BUG: doveadm sent broken CACHE-FLUSH");
return FALSE;
}
list = t_strsplit_tabescaped(args);
if (list[0] == NULL || list[1] == NULL ||
str_to_uint(list[0], &id) < 0) {
- auth_master_log_error(conn, "BUG: Master sent broken %s", cmd);
+ e_error(conn->event, "BUG: Master sent broken %s", cmd);
return -1;
}
}
if (auth_request->fields.service == NULL) {
- auth_master_log_error(conn,
+ e_error(conn->event,
"BUG: Master sent %s request without service", cmd);
auth_request_unref(&auth_request);
auth_master_connection_unref(&conn);
/* <id> [<parameters>] */
list = t_strsplit_tabescaped(args);
if (list[0] == NULL || str_to_uint(list[0], &id) < 0) {
- auth_master_log_error(conn, "BUG: Master sent broken LIST");
+ e_error(conn->event, "BUG: Master sent broken LIST");
return FALSE;
}
list++;
if (conn->iter_ctx != NULL) {
- auth_master_log_error(conn,
+ e_error(conn->event,
"Auth client is already iterating users");
str = t_strdup_printf("DONE\t%u\tfail\n", id);
o_stream_nsend_str(conn->output, str);
}
if (conn->userdb_restricted_uid != 0) {
- auth_master_log_error(conn,
+ e_error(conn->event,
"Auth client doesn't have permissions to list users: %s",
auth_restricted_reason(conn));
str = t_strdup_printf("DONE\t%u\tfail\n", id);
while (userdb != NULL && userdb->userdb->iface->iterate_init == NULL)
userdb = userdb->next;
if (userdb == NULL) {
- auth_master_log_error(conn,
+ e_error(conn->event,
"Trying to iterate users, but userdbs don't support it");
str = t_strdup_printf("DONE\t%u\tfail\n", id);
o_stream_nsend_str(conn->output, str);
if (str_begins(line, "CACHE-FLUSH\t"))
return master_input_cache_flush(conn, line + 12);
if (str_begins(line, "CPID\t")) {
- auth_master_log_error(conn,
+ e_error(conn->event,
"Authentication client trying to connect to "
"master socket");
return FALSE;
}
}
- auth_master_log_error(conn, "BUG: Unknown command in %s socket: %s",
+ e_error(conn->event, "BUG: Unknown command in %s socket: %s",
conn->userdb_only ? "userdb" : "master",
str_sanitize(line, 80));
return FALSE;
return;
case -2:
/* buffer full */
- auth_master_log_error(conn,
- "BUG: Master sent us more than %d bytes",
+ e_error(conn->event, "BUG: Master sent us more than %d bytes",
(int)MAX_INBUF_SIZE);
auth_master_connection_destroy(&conn);
return;
if (!str_begins(line, "VERSION\t") ||
!str_uint_equals(t_strcut(line + 8, '\t'),
AUTH_MASTER_PROTOCOL_MAJOR_VERSION)) {
- auth_master_log_error(conn,
+ e_error(conn->event,
"Master not compatible with this server "
"(mixed old and new binaries?)");
auth_master_connection_destroy(&conn);
}
if (net_getunixcred(conn->fd, &cred) < 0) {
- auth_master_log_error(conn,
+ e_error(conn->event,
"userdb connection: Failed to get peer's credentials");
return -1;
}
o_stream_set_flush_callback(conn->output, master_output, conn);
conn->io = io_add(fd, IO_READ, master_input, conn);
conn->userdb_only = userdb_only;
+ conn->event = event_create(auth_event);
+ event_set_log_message_callback(conn->event, auth_master_event_log_callback, conn);
line = t_strdup_printf("VERSION\t%u\t%u\nSPID\t%s\n",
AUTH_MASTER_PROTOCOL_MAJOR_VERSION,
i_stream_unref(&conn->input);
o_stream_unref(&conn->output);
+ event_unref(&conn->event);
i_free(conn->path);
i_free(conn);
}