/* Copyright (c) 2005-2018 Dovecot authors, see the included COPYING file */
#include "auth-common.h"
#include "base64.h"
#include "ioloop.h"
#include "net.h"
#include "istream.h"
#include "ostream.h"
#include "hex-binary.h"
#include "str.h"
#include "strescape.h"
#include "process-title.h"
#include "master-service.h"
#include "auth-request.h"
#include "auth-worker-client.h"
struct auth_worker_client {
int refcount;
int fd;
};
struct auth_worker_list_context {
};
{
return;
state = "error";
else if (auth_worker_client == NULL)
state = "waiting for connection";
}
static void
{
/* stop reading new requests until client has read the pending
replies. */
}
}
{
else {
}
}
return FALSE;
}
/* reset changed-fields, so we'll export only the ones that were
changed by this lookup. */
return TRUE;
}
struct auth_request *request,
{
const char *p;
i_warning("Auth master disconnected us while handling "
"request for %s for %ld secs (result=%s)",
}
}
static void
{
/* export only the fields changed by this lookup, so the
changed-flag gets preserved correctly on the master side as
well. */
}
/* all userdb_* fields had NULL values. we'll still
need to tell this to the master */
}
}
struct auth_request *request)
{
if (result == PASSDB_RESULT_OK)
else
else
if (result != PASSDB_RESULT_INTERNAL_FAILURE) {
}
}
static bool
{
/* verify plaintext password */
const char *password;
unsigned int passdb_id;
/* <passdb id> <password> [<args>] */
i_error("BUG: Auth worker server sent us invalid PASSV");
return FALSE;
}
i_error("BUG: Auth worker server sent us invalid PASSV");
return FALSE;
}
/* could be a masterdb */
i_error("BUG: PASSV had invalid passdb ID");
return FALSE;
}
}
return TRUE;
}
static bool
{
const char *password;
unsigned int passdb_id;
int ret;
i_error("BUG: Auth worker server sent us invalid PASSW");
return FALSE;
}
i_error("BUG: Auth worker server sent us invalid PASSW (scheme is NULL)");
return FALSE;
}
i_error("BUG: PASSW had missing parameters");
return FALSE;
}
if (ret == 1)
else if (ret == 0)
else
return TRUE;
}
static void
struct auth_request *request)
{
else {
if (result == PASSDB_RESULT_NEXT)
else
} else {
}
}
}
static bool
{
/* lookup credentials */
const char *scheme;
unsigned int passdb_id;
/* <passdb id> <scheme> [<args>] */
i_error("BUG: Auth worker server sent us invalid PASSL");
return FALSE;
}
i_error("BUG: PASSL had missing parameters");
return FALSE;
}
i_error("BUG: PASSL had invalid passdb ID");
return FALSE;
}
}
i_error("BUG: PASSL lookup not supported by given passdb");
return FALSE;
}
return TRUE;
}
static void
{
}
static bool
{
unsigned int passdb_id;
const char *creds;
/* <passdb id> <credentials> [<args>] */
i_error("BUG: Auth worker server sent us invalid SETCRED");
return FALSE;
}
i_error("BUG: SETCRED had missing parameters");
return FALSE;
}
i_error("BUG: SETCRED had invalid passdb ID");
return FALSE;
}
}
return TRUE;
}
static void
struct auth_request *auth_request)
{
switch (result) {
break;
break;
case USERDB_RESULT_OK:
/* export only the fields changed by this lookup */
break;
}
}
static struct auth_userdb *
{
return db;
}
return NULL;
}
static bool
{
/* lookup user */
unsigned int userdb_id;
/* <userdb id> [<args>] */
i_error("BUG: Auth worker server sent us invalid USER");
return FALSE;
}
i_error("BUG: USER had missing parameters");
return FALSE;
}
i_error("BUG: USER had invalid userdb ID");
return FALSE;
}
return TRUE;
}
static void
{
}
static void
{
unsigned int idle_kill_secs;
if (idle_kill_secs > 0) {
client);
}
}
{
else
}
{
else
return;
}
T_BEGIN {
} T_END;
/* avoid recursively looping to this same function */
return;
}
do {
T_BEGIN {
} T_END;
break;
}
}
else
}
{
int ret;
return 1;
}
} T_END;
return 1;
}
static bool
{
unsigned int userdb_id;
i_error("BUG: Auth worker server sent us invalid LIST");
return FALSE;
}
i_error("BUG: LIST had invalid userdb ID");
return FALSE;
}
i_error("BUG: LIST had missing parameters");
return FALSE;
}
return TRUE;
}
static bool
{
const char *const *args;
unsigned int id;
return FALSE;
}
else {
i_error("BUG: Auth-worker received unknown command: %s",
args[1]);
}
return ret;
}
{
}
{
char *line;
bool ret;
case 0:
return;
case -1:
/* disconnected */
return;
case -2:
/* buffer full */
i_error("BUG: Auth worker server sent us more than %d bytes",
(int)AUTH_WORKER_MAX_LINE_LENGTH);
return;
}
if (!client->version_received) {
return;
i_error("Auth worker not compatible with this server "
"(mixed old and new binaries?)");
return;
}
}
if (!client->dbhash_received) {
return;
if (!auth_worker_verify_db_hash(line)) {
"than auth server. Maybe config just changed "
"and this goes away automatically?");
return;
}
}
T_BEGIN {
} T_END;
if (!ret) {
break;
}
}
}
{
return 1;
}
/* allow input again */
}
return 1;
}
struct auth_worker_client *
{
return client;
}
{
return;
}
{
return;
}
void auth_worker_client_send_error(void)
{
if (auth_worker_client != NULL &&
}
}
void auth_worker_client_send_success(void)
{
if (auth_worker_client == NULL)
return;
if (auth_worker_client->error_sent) {
}
}
void auth_worker_client_send_shutdown(void)
{
if (auth_worker_client != NULL)
}