auth-server-connection.c revision d5cebe7f98e63d4e2822863ef2faa4971e8b3a5d
/* Copyright (C) 2003-2004 Timo Sirainen */
#include "lib.h"
#include "buffer.h"
#include "hash.h"
#include "ioloop.h"
#include "istream.h"
#include "ostream.h"
#include "network.h"
#include "auth-client.h"
#include "auth-server-connection.h"
#include "auth-server-request.h"
#include <unistd.h>
#include <stdlib.h>
{
const struct auth_mech_desc *mech;
struct auth_mech_desc *new_mech;
unsigned int i;
for (i = 0; i < conn->available_auth_mechs_count; i++) {
}
}
}
static bool
{
const char *const *list;
struct auth_mech_desc mech_desc;
if (conn->handshake_received) {
i_error("BUG: Authentication server already sent handshake");
return FALSE;
}
i_error("BUG: Authentication server sent broken MECH line");
return FALSE;
}
}
return TRUE;
}
static bool
{
if (conn->handshake_received) {
i_error("BUG: Authentication server already sent handshake");
return FALSE;
}
return TRUE;
}
static bool
{
if (conn->handshake_received) {
i_error("BUG: Authentication server already sent handshake");
return FALSE;
}
return TRUE;
}
{
if (conn->available_auth_mechs_count == 0) {
i_error("BUG: Authentication server returned no mechanisms");
return FALSE;
}
}
return TRUE;
}
static void auth_client_input(void *context)
{
const char *line;
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?)");
return;
}
}
else {
/* ignore unknown command */
}
if (!ret) {
break;
}
}
}
struct auth_server_connection *
{
struct auth_server_connection *conn;
const char *handshake;
/* max. 1 second wait here. */
break;
/* busy. wait for a while. */
}
if (fd == -1) {
return NULL;
}
/* use blocking connection since we depend on auth server -
if it's slow, just wait */
else {
conn->ext_input_io =
}
FALSE);
i_warning("Error sending handshake to auth server: %m");
return NULL;
}
return conn;
}
bool reconnect)
{
struct auth_server_connection **pos;
return;
break;
}
}
if (!conn->handshake_received)
}
i_error("close(auth) failed: %m");
if (reconnect)
}
}
{
return;
}
struct auth_server_connection *
{
struct auth_server_connection *conn;
return conn;
}
return NULL;
}
struct auth_server_connection *
{
const struct auth_mech_desc *mech;
unsigned int i, n, match_n;
/* find a connection which has this mechanism. if there are multiple
available connections to use, do round robin load balancing */
for (i = 0; i < conn->available_auth_mechs_count; i++) {
if (n > client->last_used_auth_process) {
client->last_used_auth_process = n;
return conn;
}
match_n = n;
}
break;
}
}
}
return match;
}
*error_r = "Unsupported authentication mechanism";
else {
*error_r = "Authentication server isn't connected, "
"try again later..";
}
return NULL;
}