sasl-server.c revision 325d17cdbb7a338f7c413788f5e8e42d2e80a7f8
a8c5a86d183db25a57bf193c06b41e092ec2e151Timo Sirainen/* Copyright (c) 2002-2013 Dovecot authors, see the included COPYING file */
8e361d2906b0e44f7175a20981f8d2280645b58bTimo Sirainen "Maximum number of connections from user+IP exceeded " \
3281669db44d09a087a203201248abbc81b3cc1aTimo Sirainen "(mail_max_userip_connections=%u)"
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen unsigned char cookie[MASTER_AUTH_COOKIE_SIZE];
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainensasl_server_get_advertised_mechs(struct client *client, unsigned int *count_r)
0e3f8c6edad565112d91f0a53568c0313d657e48Timo Sirainen unsigned int i, j, count;
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainen mech = auth_client_get_available_mechs(auth_client, &count);
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen ret_mech = t_new(struct auth_mech_desc, count);
d6af1e63bc7824f1cc5b9b73a1c5f8f8789788d6Timo Sirainen for (i = j = 0; i < count; i++) {
d6af1e63bc7824f1cc5b9b73a1c5f8f8789788d6Timo Sirainen /* a) transport is secured
d6af1e63bc7824f1cc5b9b73a1c5f8f8789788d6Timo Sirainen b) auth mechanism isn't plaintext
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen c) we allow insecure authentication
d6af1e63bc7824f1cc5b9b73a1c5f8f8789788d6Timo Sirainen if ((mech[i].flags & MECH_SEC_PRIVATE) == 0 &&
d6af1e63bc7824f1cc5b9b73a1c5f8f8789788d6Timo Sirainen (client->secured || !client->set->disable_plaintext_auth ||
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen ssl_proxy_has_valid_client_cert(client->ssl_proxy))
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen auth_flags |= AUTH_REQUEST_FLAG_VALID_CLIENT_CERT;
a3ea111cfdbfd4f32baeb0bd7f1d72568c60a023Timo Sirainen /* e.g. webmail */
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen auth_flags |= AUTH_REQUEST_FLAG_SUPPORT_FINAL_RESP;
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainencall_client_callback(struct client *client, enum sasl_server_reply reply,
1f57716285d4c5bc9bf2fd5569e3c85fd496afd9Timo Sirainen i_assert(reply != SASL_SERVER_REPLY_CONTINUE);
1f57716285d4c5bc9bf2fd5569e3c85fd496afd9Timo Sirainen /* NOTE: client may be destroyed now */
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainenmaster_auth_callback(const struct master_auth_reply *reply, void *context)
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen enum sasl_server_reply sasl_reply = SASL_SERVER_REPLY_MASTER_FAILED;
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen auth_client_send_cancel(auth_client, client->master_auth_id);
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen call_client_callback(client, sasl_reply, data, NULL);
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainenstatic void master_send_request(struct anvil_request *anvil_request)
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen struct client *client = anvil_request->client;
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen const unsigned char *data;
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen const char *session_id = client_get_session_id(client);
b09be485e9373be4288f5615bbce6ebed65a425aTimo Sirainen req.flags |= MAIL_AUTH_REQUEST_FLAG_TLS_COMPRESSION;
b09be485e9373be4288f5615bbce6ebed65a425aTimo Sirainen memcpy(req.cookie, anvil_request->cookie, sizeof(req.cookie));
b09be485e9373be4288f5615bbce6ebed65a425aTimo Sirainen buf = buffer_create_dynamic(pool_datastack_create(), 256);
b09be485e9373be4288f5615bbce6ebed65a425aTimo Sirainen /* session ID */
b09be485e9373be4288f5615bbce6ebed65a425aTimo Sirainen buffer_append(buf, session_id, strlen(session_id)+1);
b09be485e9373be4288f5615bbce6ebed65a425aTimo Sirainen /* protocol specific data (e.g. IMAP tag) */
b09be485e9373be4288f5615bbce6ebed65a425aTimo Sirainen buffer_append(buf, client->master_data_prefix,
b09be485e9373be4288f5615bbce6ebed65a425aTimo Sirainen /* buffered client input */
b09be485e9373be4288f5615bbce6ebed65a425aTimo Sirainen data = i_stream_get_data(client->input, &size);
22c1ec434d7323e125c150e3fd237316c74de6d5Timo Sirainen master_auth_request(master_auth, client->fd, &req, buf->data,
22c1ec434d7323e125c150e3fd237316c74de6d5Timo Sirainen master_auth_callback, client, &client->master_tag);
b09be485e9373be4288f5615bbce6ebed65a425aTimo Sirainenanvil_lookup_callback(const char *reply, void *context)
b09be485e9373be4288f5615bbce6ebed65a425aTimo Sirainen const struct login_settings *set = client->set;
b09be485e9373be4288f5615bbce6ebed65a425aTimo Sirainen strtoul(reply, NULL, 10) < set->mail_max_userip_connections)
b09be485e9373be4288f5615bbce6ebed65a425aTimo Sirainen auth_client_send_cancel(auth_client, req->auth_id);
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen errmsg = t_strdup_printf(ERR_TOO_MANY_USERIP_CONNECTIONS,
9453e8d75cfd8fab2232cf772e9b120f308fb3eeTimo Sirainen call_client_callback(client, SASL_SERVER_REPLY_MASTER_FAILED,
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainenanvil_check_too_many_connections(struct client *client,
bool nologin;
switch (status) {
case AUTH_REQUEST_STATUS_OK:
if (nologin) {
case AUTH_REQUEST_STATUS_FAIL:
const char *initial_resp_base64,
const char *auth_name =