auth-worker-client.c revision eddd9bf1a1369aea4a2715f6be1137da6d17d293
183bea41fa640dc8117f3eb45ff935cd81377a84Timo Sirainen/* Copyright (c) 2005-2007 Dovecot authors, see the included COPYING file */
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainen/* If no requests have come within this time, kill ourself */
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainenauth_worker_client_check_throttle(struct auth_worker_client *client)
1ff487015234b23c32cf8bb4c9f8c02922535b8eTimo Sirainen if (o_stream_get_buffer_used_size(client->output) >=
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainen /* stop reading new requests until client has read the pending
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainenworker_auth_request_new(struct auth_worker_client *client, unsigned int id,
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainen auth_request = auth_request_new_dummy(client->auth);
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainen for (tmp = t_strsplit(args, "\t"); *tmp != NULL; tmp++) {
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainen (void)auth_request_import(auth_request, key, value);
1ff487015234b23c32cf8bb4c9f8c02922535b8eTimo Sirainenstatic void add_userdb_replies(string_t *str, const char *data)
1ff487015234b23c32cf8bb4c9f8c02922535b8eTimo Sirainen const char *const *tmp;
675b2b1c4587a79478062b05725da61afa5d8045Timo Sirainen for (tmp = t_strsplit(data, "\t"); *tmp != NULL; tmp++)
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainenstatic void verify_plain_callback(enum passdb_result result,
c2f2a6cdf7dd55a4aabe72495cabb4deaa59cffcTimo Sirainen struct auth_worker_client *client = request->context;
675b2b1c4587a79478062b05725da61afa5d8045Timo Sirainen if (request->passdb_failure && result == PASSDB_RESULT_OK)
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainen const char *data =
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainen auth_stream_reply_export(request->userdb_reply);
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainen const char *field =
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainen auth_stream_reply_export(request->extra_fields);
675b2b1c4587a79478062b05725da61afa5d8045Timo Sirainen o_stream_send(client->output, str_data(str), str_len(str));
cc3da53f3a49304a251bfae88f814505326ac210Timo Sirainenauth_worker_handle_passv(struct auth_worker_client *client,
cc3da53f3a49304a251bfae88f814505326ac210Timo Sirainen /* verify plaintext password */
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainen i_error("BUG: Auth worker server sent us invalid PASSV");
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainen auth_request = worker_auth_request_new(client, id, args);
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainen if (auth_request->user == NULL || auth_request->service == NULL) {
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainen while (passdb != NULL && passdb->id != passdb_id)
675b2b1c4587a79478062b05725da61afa5d8045Timo Sirainen /* could be a masterdb */
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainen while (passdb != NULL && passdb->id != passdb_id)
064ccad9cea2a75a0d6caa2c679b6cd22be58174Timo Sirainen verify_plain(auth_request, password, verify_plain_callback);
064ccad9cea2a75a0d6caa2c679b6cd22be58174Timo Sirainenlookup_credentials_callback(enum passdb_result result,
064ccad9cea2a75a0d6caa2c679b6cd22be58174Timo Sirainen const unsigned char *credentials, size_t size,
064ccad9cea2a75a0d6caa2c679b6cd22be58174Timo Sirainen struct auth_worker_client *client = request->context;
064ccad9cea2a75a0d6caa2c679b6cd22be58174Timo Sirainen if (request->passdb_failure && result == PASSDB_RESULT_OK)
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainen str_printfa(str, "OK\t%s\t{%s.b64}", request->user,
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainen const char *field =
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainen auth_stream_reply_export(request->extra_fields);
f16712057c1b82c6d2a3a4267c4521d357cd4b4cTimo Sirainen const char *data =
f16712057c1b82c6d2a3a4267c4521d357cd4b4cTimo Sirainen auth_stream_reply_export(request->userdb_reply);
51c331377beb4a2acb81aee4d12bc8ef6c496625Timo Sirainen o_stream_send(client->output, str_data(str), str_len(str));
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainenauth_worker_handle_passl(struct auth_worker_client *client,
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainen /* lookup credentials */
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainen i_error("BUG: Auth worker server sent us invalid PASSL");
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainen auth_request = worker_auth_request_new(client, id, args);
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainen auth_request->credentials_scheme = p_strdup(auth_request->pool, scheme);
675b2b1c4587a79478062b05725da61afa5d8045Timo Sirainen if (auth_request->user == NULL || auth_request->service == NULL) {
675b2b1c4587a79478062b05725da61afa5d8045Timo Sirainen while (auth_request->passdb->id != passdb_id) {
675b2b1c4587a79478062b05725da61afa5d8045Timo Sirainen auth_request->passdb = auth_request->passdb->next;
cc3da53f3a49304a251bfae88f814505326ac210Timo Sirainen if (auth_request->passdb->passdb->iface.lookup_credentials == NULL) {
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainen i_error("BUG: PASSL lookup not supported by given passdb");
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainen lookup_credentials(auth_request, lookup_credentials_callback);
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainenset_credentials_callback(bool success, struct auth_request *request)
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainen struct auth_worker_client *client = request->context;
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainen str_printfa(str, "%u\t%s\n", request->id, success ? "OK" : "FAIL");
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainen o_stream_send(client->output, str_data(str), str_len(str));
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainenauth_worker_handle_setcred(struct auth_worker_client *client,
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainen i_error("BUG: Auth worker server sent us invalid SETCRED");
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainen auth_request = worker_auth_request_new(client, id, args);
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainen if (auth_request->user == NULL || auth_request->service == NULL) {
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainen i_error("BUG: SETCRED had missing parameters");
200500ebd3c93a5771e7ae2f442659b9acb16eb6Timo Sirainen while (auth_request->passdb->id != passdb_id) {
200500ebd3c93a5771e7ae2f442659b9acb16eb6Timo Sirainen auth_request->passdb = auth_request->passdb->next;
f3aff3c6bf32d5bb0a61993b76a3fbe5ad798c09Timo Sirainen i_error("BUG: SETCRED had invalid passdb ID");
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainen set_credentials(auth_request, data, set_credentials_callback);
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainenlookup_user_callback(enum userdb_result result,
1ff487015234b23c32cf8bb4c9f8c02922535b8eTimo Sirainen struct auth_worker_client *client = auth_request->context;
1ff487015234b23c32cf8bb4c9f8c02922535b8eTimo Sirainen struct auth_stream_reply *reply = auth_request->userdb_reply;
043c8a96a035379bcba04f487d58457beefdfcaaTimo Sirainen str_append(str, auth_stream_reply_export(reply));
043c8a96a035379bcba04f487d58457beefdfcaaTimo Sirainen o_stream_send(client->output, str_data(str), str_len(str));
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainenauth_worker_handle_user(struct auth_worker_client *client,
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainen /* lookup user */
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainen unsigned int num;
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainen auth_request = worker_auth_request_new(client, id, args);
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainen if (auth_request->user == NULL || auth_request->service == NULL) {
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainen auth_request->userdb = auth_request->userdb->next;
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainenauth_worker_handle_line(struct auth_worker_client *client, const char *line)
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainen const char *p;
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainen unsigned int id;
if (p == NULL)
return FALSE;
return TRUE;
char *line;
bool ret;
(int)AUTH_WORKER_MAX_LINE_LENGTH);
if (!ret) {
struct auth_worker_client *
FALSE);
return client;