auth-worker-client.c revision e9371f899a3d4207a0ffd3923ea5ec7250cf5e75
/* Copyright (c) 2005-2011 Dovecot authors, see the included COPYING file */
#include "auth-common.h"
#include "base64.h"
#include "ioloop.h"
#include "network.h"
#include "istream.h"
#include "ostream.h"
#include "hex-binary.h"
#include "str.h"
#include "master-service.h"
#include "auth-request.h"
#include "auth-worker-client.h"
#include <stdlib.h>
struct auth_worker_client {
int refcount;
int fd;
unsigned int version_received:1;
unsigned int dbhash_received:1;
};
struct auth_worker_list_context {
struct auth_worker_client *client;
struct auth_request *auth_request;
struct userdb_iterate_context *iter;
};
struct auth_worker_client *auth_worker_client;
static void
{
/* stop reading new requests until client has read the pending
replies. */
}
}
static struct auth_request *
const char *const *args)
{
struct auth_request *auth_request;
}
}
return auth_request;
}
{
if (shutdown_request)
}
struct auth_request *request)
{
struct auth_stream_reply *reply;
if (result == PASSDB_RESULT_OK)
else {
}
if (result != PASSDB_RESULT_INTERNAL_FAILURE) {
const char *fields =
}
const char *fields =
}
}
}
static bool
{
/* verify plaintext password */
struct auth_request *auth_request;
struct auth_passdb *passdb;
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: PASSV had missing parameters");
return FALSE;
}
/* could be a masterdb */
i_error("BUG: PASSV had invalid passdb ID");
return FALSE;
}
}
return TRUE;
}
static void
struct auth_request *request)
{
struct auth_stream_reply *reply;
if (result != PASSDB_RESULT_OK) {
} else {
const char *fields =
}
const char *fields =
}
}
}
static bool
{
/* lookup credentials */
struct auth_request *auth_request;
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
{
struct auth_request *auth_request;
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:
break;
}
}
static struct auth_userdb *
{
struct auth_userdb *db;
return db;
}
return NULL;
}
static bool
{
/* lookup user */
struct auth_request *auth_request;
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;
}
{
else
}
{
else
return;
}
T_BEGIN {
} T_END;
/* avoid recursively looping to this same function */
return;
}
do {
}
{
int ret;
return 1;
}
if (ret > 0) {
}
return 1;
}
static bool
{
struct auth_worker_list_context *ctx;
struct auth_userdb *userdb;
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;
}
static bool auth_worker_verify_db_hash(const char *line)
{
unsigned char passdb_md5[MD5_RESULTLEN];
unsigned char userdb_md5[MD5_RESULTLEN];
}
{
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 *
{
struct auth_worker_client *client;
FALSE);
return client;
}
{
return;
}
{
return;
}