auth-worker-client.c revision f93c833d644ecff0b0f80bee4f1cdde3e697b5c8
5e0ce63bb65db34d7f48b34bbb5545fa791781c4Timo Sirainen/* Copyright (c) 2005-2011 Dovecot authors, see the included COPYING file */
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainenstatic void auth_worker_input(struct auth_worker_client *client);
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenstatic int auth_worker_output(struct auth_worker_client *client);
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenvoid auth_worker_refresh_proctitle(const char *state)
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen if (!global_auth_settings->verbose_proctitle || !worker)
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen process_title_set(t_strdup_printf("worker: %s", state));
3bbe99d30871f49610aac0417ee5951d1e740b98Timo Sirainenauth_worker_client_check_throttle(struct auth_worker_client *client)
3bbe99d30871f49610aac0417ee5951d1e740b98Timo Sirainen if (o_stream_get_buffer_used_size(client->output) >=
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen /* stop reading new requests until client has read the pending
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenworker_auth_request_new(struct auth_worker_client *client, unsigned int id,
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen const char *const *args)
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen (void)auth_request_import(auth_request, key, value);
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenstatic void auth_worker_send_reply(struct auth_worker_client *client,
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen o_stream_send_str(client->output, "SHUTDOWN\n");
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen o_stream_send(client->output, str_data(str), str_len(str));
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenstatic void verify_plain_callback(enum passdb_result result,
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen struct auth_worker_client *client = request->context;
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen if (request->passdb_failure && result == PASSDB_RESULT_OK)
1060afdc2fcdf647dbb3bc11647401f1b44a3a8aTimo Sirainen reply = auth_stream_reply_init(pool_datastack_create());
1060afdc2fcdf647dbb3bc11647401f1b44a3a8aTimo Sirainen auth_stream_reply_add(reply, NULL, dec2str(request->id));
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen if (result != PASSDB_RESULT_INTERNAL_FAILURE) {
9e095dd6a77097356aca8216356d4d71ef1bea45Timo Sirainen auth_stream_reply_add(reply, NULL, request->user);
c06f4017027263cf3a08becc551f5126409e2a83Timo Sirainen const char *fields =
c06f4017027263cf3a08becc551f5126409e2a83Timo Sirainen auth_stream_reply_export(request->extra_fields);
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen const char *fields =
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen auth_stream_reply_export(request->extra_cache_fields);
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainenauth_worker_handle_passv(struct auth_worker_client *client,
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen /* verify plaintext password */
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen /* <passdb id> <password> [<args>] */
602a0434db30d8e3292d1c161a803d96a879a74fTimo Sirainen if (str_to_uint(args[0], &passdb_id) < 0 || args[1] == NULL) {
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainen i_error("BUG: Auth worker server sent us invalid PASSV");
dd62b77c932d1b518f2a3e4bf80e36542becc256Timo Sirainen auth_request = worker_auth_request_new(client, id, args + 2);
dd62b77c932d1b518f2a3e4bf80e36542becc256Timo Sirainen if (auth_request->user == NULL || auth_request->service == NULL) {
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen while (passdb != NULL && passdb->passdb->id != passdb_id)
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainen /* could be a masterdb */
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainen passdb = auth_request_get_auth(auth_request)->masterdbs;
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainen while (passdb != NULL && passdb->passdb->id != passdb_id)
cd1eef2109b4476842b7757f1d69b104196d5941Timo Sirainen verify_plain(auth_request, password, verify_plain_callback);
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainenlookup_credentials_callback(enum passdb_result result,
dd62b77c932d1b518f2a3e4bf80e36542becc256Timo Sirainen const unsigned char *credentials, size_t size,
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainen struct auth_worker_client *client = request->context;
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen if (request->passdb_failure && result == PASSDB_RESULT_OK)
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen reply = auth_stream_reply_init(pool_datastack_create());
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen auth_stream_reply_add(reply, NULL, dec2str(request->id));
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainen auth_stream_reply_add(reply, NULL, request->user);
411d6baa37f31d90730e90c4a28c43e1974bbe58Timo Sirainen str_printfa(str, "{%s.b64}", request->credentials_scheme);
c06f4017027263cf3a08becc551f5126409e2a83Timo Sirainen auth_stream_reply_add(reply, NULL, str_c(str));
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen const char *fields =
dd62b77c932d1b518f2a3e4bf80e36542becc256Timo Sirainen auth_stream_reply_export(request->extra_fields);
const char *fields =
const char *scheme;
unsigned int passdb_id;
return FALSE;
return FALSE;
return FALSE;
return FALSE;
return TRUE;
unsigned int passdb_id;
const char *creds;
return FALSE;
return FALSE;
return FALSE;
return TRUE;
switch (result) {
case USERDB_RESULT_OK:
static struct auth_userdb *
return db;
return NULL;
unsigned int userdb_id;
return FALSE;
return FALSE;
return FALSE;
return TRUE;
T_BEGIN {
} T_END;
int ret;
if (ret > 0) {
unsigned int userdb_id;
return FALSE;
return FALSE;
return FALSE;
return TRUE;
const char *const *args;
unsigned int id;
return FALSE;
return ret;
char *line;
bool ret;
(int)AUTH_WORKER_MAX_LINE_LENGTH);
T_BEGIN {
} T_END;
if (!ret) {
struct auth_worker_client *
FALSE);
return client;
void auth_worker_client_send_error(void)
void auth_worker_client_send_success(void)