auth-worker-client.c revision 9ed2951bd0bb1878a27437d7c00611b2baadd614
45312f52ff3a3d4c137447be4c7556500c2f8bf2Timo Sirainen/* Copyright (c) 2005-2010 Dovecot authors, see the included COPYING file */
f335accff54f408a8bbb328f8098ad458f2ff58eTimo Sirainen unsigned int id;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenstatic void auth_worker_input(struct auth_worker_client *client);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenstatic int auth_worker_output(struct auth_worker_client *client);
db24d60c306c9d477392ff5b61cb3fc95fef3bb7Timo Sirainenauth_worker_client_check_throttle(struct auth_worker_client *client)
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen if (o_stream_get_buffer_used_size(client->output) >=
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen /* stop reading new requests until client has read the pending
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenworker_auth_request_new(struct auth_worker_client *client, unsigned int id,
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen for (tmp = t_strsplit(args, "\t"); *tmp != NULL; tmp++) {
0f66f12eb4cdbf47670975044c88d8f388bf92dfTimo Sirainen (void)auth_request_import(auth_request, key, value);
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainenstatic void auth_worker_send_reply(struct auth_worker_client *client,
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen o_stream_send_str(client->output, "SHUTDOWN\n");
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen o_stream_send(client->output, str_data(str), str_len(str));
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainenstatic void verify_plain_callback(enum passdb_result result,
b38dd9a0b8eb6b599c346acbeea9dbe129bb086eTimo Sirainen struct auth_worker_client *client = request->context;
87b426af6a2365c6840b14281a98c23e903bf28eTimo Sirainen if (request->passdb_failure && result == PASSDB_RESULT_OK)
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen reply = auth_stream_reply_init(pool_datastack_create());
87b426af6a2365c6840b14281a98c23e903bf28eTimo Sirainen auth_stream_reply_add(reply, NULL, dec2str(request->id));
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen if (result != PASSDB_RESULT_INTERNAL_FAILURE) {
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen auth_stream_reply_add(reply, NULL, request->user);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen const char *fields =
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen auth_stream_reply_export(request->extra_fields);
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen const char *fields =
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen auth_stream_reply_export(request->extra_cache_fields);
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainenauth_worker_handle_passv(struct auth_worker_client *client,
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen /* verify plaintext password */
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen i_error("BUG: Auth worker server sent us invalid PASSV");
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen auth_request = worker_auth_request_new(client, id, args);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen if (auth_request->user == NULL || auth_request->service == NULL) {
65988f5a8abed57e9894fec77105941e046d3490Timo Sirainen while (passdb != NULL && passdb->passdb->id != passdb_id)
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen /* could be a masterdb */
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen passdb = auth_request_get_auth(auth_request)->masterdbs;
0ce8f754204c7eeb33805993807393f74faf2cd3Timo Sirainen while (passdb != NULL && passdb->passdb->id != passdb_id)
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen verify_plain(auth_request, password, verify_plain_callback);
62394a19cba1a8df01cad66eaa9331a70464441eTimo Sirainenlookup_credentials_callback(enum passdb_result result,
62394a19cba1a8df01cad66eaa9331a70464441eTimo Sirainen const unsigned char *credentials, size_t size,
62394a19cba1a8df01cad66eaa9331a70464441eTimo Sirainen struct auth_worker_client *client = request->context;
62394a19cba1a8df01cad66eaa9331a70464441eTimo Sirainen if (request->passdb_failure && result == PASSDB_RESULT_OK)
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen reply = auth_stream_reply_init(pool_datastack_create());
62394a19cba1a8df01cad66eaa9331a70464441eTimo Sirainen auth_stream_reply_add(reply, NULL, dec2str(request->id));
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen auth_stream_reply_add(reply, NULL, request->user);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen str_printfa(str, "{%s.b64}", request->credentials_scheme);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen auth_stream_reply_add(reply, NULL, str_c(str));
5cbefc6537aefbf1491416c433de00fc3e649a13Timo Sirainen const char *fields =
2e03303e721a293d796c0287829396f5caea76eaTimo Sirainen auth_stream_reply_export(request->extra_fields);
87506860556bf42f656b13f4b14cf81b75261e95Timo Sirainen const char *fields =
87506860556bf42f656b13f4b14cf81b75261e95Timo Sirainen auth_stream_reply_export(request->extra_cache_fields);
5cbefc6537aefbf1491416c433de00fc3e649a13Timo Sirainenauth_worker_handle_passl(struct auth_worker_client *client,
5cbefc6537aefbf1491416c433de00fc3e649a13Timo Sirainen /* lookup credentials */
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen i_error("BUG: Auth worker server sent us invalid PASSL");
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen auth_request = worker_auth_request_new(client, id, args);
db24d60c306c9d477392ff5b61cb3fc95fef3bb7Timo Sirainen auth_request->credentials_scheme = p_strdup(auth_request->pool, scheme);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen if (auth_request->user == NULL || auth_request->service == NULL) {
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen while (auth_request->passdb->passdb->id != passdb_id) {
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen auth_request->passdb = auth_request->passdb->next;
db24d60c306c9d477392ff5b61cb3fc95fef3bb7Timo Sirainen if (auth_request->passdb->passdb->iface.lookup_credentials == NULL) {
db24d60c306c9d477392ff5b61cb3fc95fef3bb7Timo Sirainen i_error("BUG: PASSL lookup not supported by given passdb");
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen auth_request->prefer_plain_credentials = TRUE;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen lookup_credentials(auth_request, lookup_credentials_callback);
db24d60c306c9d477392ff5b61cb3fc95fef3bb7Timo Sirainenset_credentials_callback(bool success, struct auth_request *request)
db24d60c306c9d477392ff5b61cb3fc95fef3bb7Timo Sirainen struct auth_worker_client *client = request->context;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen str_printfa(str, "%u\t%s\n", request->id, success ? "OK" : "FAIL");
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenauth_worker_handle_setcred(struct auth_worker_client *client,
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen i_error("BUG: Auth worker server sent us invalid SETCRED");
0ae99441ae9ef80f435f3eb85fad16e136036b0bTimo Sirainen auth_request = worker_auth_request_new(client, id, args);
e1b83f64e62cc3e8967c75fcc3f9b5dbb243d3b3Timo Sirainen if (auth_request->user == NULL || auth_request->service == NULL) {
7aa59f55d8a4e02c7039fbd22660c4055bfc8393Timo Sirainen i_error("BUG: SETCRED had missing parameters");
7aa59f55d8a4e02c7039fbd22660c4055bfc8393Timo Sirainen while (auth_request->passdb->passdb->id != passdb_id) {
e1b83f64e62cc3e8967c75fcc3f9b5dbb243d3b3Timo Sirainen auth_request->passdb = auth_request->passdb->next;
1dba794aa92dc13e6afd7a50a8c33cb19d6aa235Timo Sirainen i_error("BUG: SETCRED had invalid passdb ID");
7aa59f55d8a4e02c7039fbd22660c4055bfc8393Timo Sirainen set_credentials(auth_request, data, set_credentials_callback);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenlookup_user_callback(enum userdb_result result,
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen struct auth_worker_client *client = auth_request->context;
055f4599bba1874fa1148a8fa488517fa077619cTimo Sirainen struct auth_stream_reply *reply = auth_request->userdb_reply;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen str_append(str, auth_stream_reply_export(reply));
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenauth_worker_handle_user(struct auth_worker_client *client,
2e03303e721a293d796c0287829396f5caea76eaTimo Sirainen /* lookup user */
9ae664e94e6eeb5c1f900bb90642052633031832Timo Sirainen unsigned int num;
2e03303e721a293d796c0287829396f5caea76eaTimo Sirainen auth_request = worker_auth_request_new(client, id, args);
2e03303e721a293d796c0287829396f5caea76eaTimo Sirainen if (auth_request->user == NULL || auth_request->service == NULL) {
T_BEGIN {
} T_END;
int ret;
if (ret > 0)
unsigned int num;
unsigned int id;
if (p == NULL)
return FALSE;
return TRUE;
char *line;
bool ret;
(int)AUTH_WORKER_MAX_LINE_LENGTH);
T_BEGIN {
} T_END;
if (!ret) {
struct auth_worker_client *
FALSE);
return client;