auth-worker-server.c revision 183bea41fa640dc8117f3eb45ff935cd81377a84
/* Copyright (c) 2005-2011 Dovecot authors, see the included COPYING file */
#include "auth-common.h"
#include "ioloop.h"
#include "array.h"
#include "aqueue.h"
#include "network.h"
#include "istream.h"
#include "ostream.h"
#include "hex-binary.h"
#include "str.h"
#include "eacces-error.h"
#include "auth-request.h"
#include "auth-worker-client.h"
#include "auth-worker-server.h"
#include <stdlib.h>
#include <unistd.h>
#define AUTH_WORKER_LOOKUP_TIMEOUT_SECS 60
#define AUTH_WORKER_DELAY_WARN_SECS 3
#define AUTH_WORKER_DELAY_WARN_MIN_INTERVAL_SECS 300
struct auth_worker_request {
unsigned int id;
const char *data_str;
void *context;
};
struct auth_worker_connection {
int fd;
struct auth_worker_request *request;
unsigned int id_counter;
unsigned int shutdown:1;
};
static unsigned int idle_count;
static struct aqueue *worker_request_queue;
static time_t auth_worker_last_warn;
static const char *worker_socket_path;
{
if (idle_count > 1)
else
}
{
}
struct auth_worker_request *request)
{
i_warning("auth workers: Auth request was queued for %d "
"seconds, %d left in queue",
}
idle_count--;
}
{
if (aqueue_count(worker_request_queue) == 0)
return;
}
{
unsigned char passdb_md5[MD5_RESULTLEN];
unsigned char userdb_md5[MD5_RESULTLEN];
}
static struct auth_worker_connection *auth_worker_create(void)
{
struct auth_worker_connection *conn;
int fd;
return NULL;
if (fd == -1) {
} else {
i_fatal("net_connect_unix(%s) failed: %m",
}
}
FALSE);
idle_count++;
return conn;
}
{
struct auth_worker_connection *const *conns;
unsigned int idx;
break;
}
}
idle_count--;
"FAIL\t%d", PASSDB_RESULT_INTERNAL_FAILURE),
}
i_error("close(auth worker) failed: %m");
if (idle_count == 0 && restart) {
conn = auth_worker_create();
}
}
static struct auth_worker_connection *auth_worker_find_free(void)
{
struct auth_worker_connection **conns;
if (idle_count == 0)
return NULL;
return conn;
}
i_unreached();
return NULL;
}
struct auth_worker_request *request,
const char *line)
{
/* multi-line reply, not finished yet */
} else {
idle_count++;
}
}
{
unsigned int id;
case 0:
return;
case -1:
/* disconnected */
TRUE);
return;
case -2:
/* buffer full */
i_error("BUG: Auth worker sent us more than %d bytes",
(int)AUTH_WORKER_MAX_LINE_LENGTH);
return;
}
continue;
}
continue;
line + 1);
} else {
i_error("BUG: Worker sent reply with id %u, "
} else {
i_error("BUG: Worker sent reply with id %u, "
"none was expected", id);
}
return;
}
}
/* there's still a pending request */
else
}
struct auth_worker_connection *
{
struct auth_worker_connection *conn;
struct auth_worker_request *request;
if (aqueue_count(worker_request_queue) > 0) {
/* requests are already being queued, no chance of
} else {
/* no free connections, create a new one */
conn = auth_worker_create();
}
}
else {
/* reached the limit, queue the request */
}
return conn;
}
{
}
void auth_worker_server_init(void)
{
worker_socket_path = "auth-worker";
}
void auth_worker_server_deinit(void)
{
while (array_count(&connections) > 0) {
}
}