auth-server-connection.c revision fd05c47210cad1f6d8effbda5cba7f7d938ca9a0
/* Copyright (c) 2003-2014 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "array.h"
#include "hash.h"
#include "hostpid.h"
#include "ioloop.h"
#include "istream.h"
#include "ostream.h"
#include "net.h"
#include "eacces-error.h"
#include "auth-client-private.h"
#include "auth-client-request.h"
#include "auth-server-connection.h"
#include <unistd.h>
#include <stdlib.h>
#define AUTH_SERVER_RECONNECT_TIMEOUT_SECS 5
static void
const char *disconnect_reason);
static int
const char *const *args)
{
struct auth_mech_desc mech_desc;
if (conn->handshake_received) {
i_error("BUG: Authentication server already sent handshake");
return -1;
}
i_error("BUG: Authentication server sent broken MECH line");
return -1;
}
}
return 0;
}
static int
const char *const *args)
{
if (conn->handshake_received) {
i_error("BUG: Authentication server already sent handshake");
return -1;
}
i_error("BUG: Authentication server sent invalid PID");
return -1;
}
return 0;
}
static int
const char *const *args)
{
if (conn->handshake_received) {
i_error("BUG: Authentication server already sent handshake");
return -1;
}
i_error("BUG: Authentication server sent broken CUID line");
return -1;
}
return 0;
}
static int
const char *const *args)
{
i_error("BUG: Authentication server already sent cookie");
return -1;
}
return 0;
}
{
i_error("BUG: Authentication server returned no mechanisms");
return -1;
}
i_error("BUG: Authentication server didn't send a cookie");
return -1;
}
}
return 0;
}
static int
struct auth_client_request **request_r)
{
struct auth_client_request *request;
unsigned int id;
i_error("BUG: Authentication server input missing ID");
return -1;
}
return -1;
}
return 0;
}
static int
const char *const *args)
{
struct auth_client_request *request;
return -1;
args + 1);
return 0;
}
const char *const *args)
{
struct auth_client_request *request;
i_error("BUG: Authentication server sent broken CONT line");
return -1;
}
return -1;
args + 1);
return 0;
}
const char *const *args)
{
struct auth_client_request *request;
return -1;
args + 1);
return 0;
}
static int
const char *line)
{
const char *const *args;
i_error("Auth server sent empty line");
return -1;
}
return auth_server_input_done(conn);
else {
return -1;
}
}
{
int ret;
case 0:
return;
case -1:
/* disconnected */
return;
case -2:
/* buffer full - can't happen unless auth is buggy */
i_error("BUG: Auth server sent us more than %d bytes of data",
return;
}
if (!conn->version_received) {
return;
/* make sure the major version matches */
i_error("Authentication server not compatible with "
"this client (mixed old and new binaries?)");
"incompatible serevr");
return;
}
}
T_BEGIN {
} T_END;
if (ret < 0) {
"Received broken input: %s", line));
break;
}
}
}
struct auth_server_connection *
{
struct auth_server_connection *conn;
return conn;
}
static void
const char *disconnect_reason)
{
struct hash_iterate_context *iter;
void *key;
struct auth_client_request *request;
unsigned int request_count = 0;
return;
if (!auth_client_request_is_aborted(request)) {
}
}
if (request_count > 0) {
i_warning("Auth connection closed with %u pending requests "
"(max %u secs, pid=%s, %s)", request_count,
(unsigned int)(ioloop_time - oldest),
}
}
const char *reason)
{
conn->server_pid = 0;
conn->connect_uid = 0;
i_error("close(auth server connection) failed: %m");
}
}
}
{
(void)auth_server_connection_connect(conn);
}
static void
const char *disconnect_reason)
{
}
{
}
{
i_error("Timeout waiting for handshake from auth server. "
"my pid=%u, input bytes=%"PRIuUOFF_T,
}
{
const char *handshake;
int fd;
/* max. 1 second wait here. */
1000);
if (fd == -1) {
i_error("auth: %s",
eacces_error_get("connect",
} else {
i_error("auth: connect(%s) failed: %m",
}
return -1;
}
FALSE);
i_warning("Error sending handshake to auth server: %m");
return -1;
}
return 0;
}
unsigned int
struct auth_client_request *request)
{
unsigned int id;
if (id == 0) {
/* wrapped - ID 0 not allowed */
}
return id;
}