struct imap_client *imap_client = (struct imap_client *)client;
struct ostream *output;
string_t *str;
- const unsigned char *data;
- size_t data_len;
- const char *suffix, *error;
+ const char *suffix;
int ret;
i_assert(!client->destroyed);
LOGIN_PROXY_FAILURE_TYPE_PROTOCOL, reason);
return -1;
}
- enum dsasl_client_result sasl_res =
- dsasl_client_input(client->proxy_sasl_client,
- str_data(str), str_len(str), &error);
- if (sasl_res == DSASL_CLIENT_RESULT_OK) {
- sasl_res = dsasl_client_output(client->proxy_sasl_client,
- &data, &data_len, &error);
- }
- if (sasl_res != DSASL_CLIENT_RESULT_OK) {
- const char *reason = t_strdup_printf(
- "Invalid authentication data: %s", error);
- login_proxy_failed(client->login_proxy,
- login_proxy_get_event(client->login_proxy),
- LOGIN_PROXY_FAILURE_TYPE_PROTOCOL, reason);
+ if (login_proxy_sasl_step(client, str) < 0)
return -1;
- }
-
- str_truncate(str, 0);
- base64_encode(data, data_len, str);
str_append(str, "\r\n");
imap_client->proxy_sent_state |= IMAP_PROXY_SENT_STATE_AUTH_CONTINUE;
#include "iostream-ssl.h"
#include "llist.h"
#include "array.h"
+#include "base64.h"
#include "hash.h"
#include "str.h"
#include "strescape.h"
#include "time-util.h"
#include "settings.h"
#include "master-service.h"
+#include "dsasl-client.h"
#include "client-common.h"
#include "login-proxy-state.h"
#include "login-proxy.h"
return FALSE;
}
+int login_proxy_sasl_step(struct client *client, string_t *str)
+{
+ const unsigned char *data;
+ size_t data_len;
+ const char *error;
+
+ enum dsasl_client_result sasl_res =
+ dsasl_client_input(client->proxy_sasl_client,
+ str_data(str), str_len(str), &error);
+ if (sasl_res == DSASL_CLIENT_RESULT_OK) {
+ sasl_res = dsasl_client_output(client->proxy_sasl_client,
+ &data, &data_len, &error);
+ }
+ if (sasl_res != DSASL_CLIENT_RESULT_OK) {
+ const char *reason = t_strdup_printf(
+ "Invalid authentication data: %s", error);
+ login_proxy_failed(client->login_proxy,
+ login_proxy_get_event(client->login_proxy),
+ LOGIN_PROXY_FAILURE_TYPE_PROTOCOL, reason);
+ return -1;
+ }
+ str_truncate(str, 0);
+ base64_encode(data, data_len, str);
+ return 0;
+}
+
bool login_proxy_is_ourself(const struct client *client, const char *host,
const struct ip_addr *hostip,
in_port_t port, const char *destuser)
bool login_proxy_failed(struct login_proxy *proxy, struct event *event,
enum login_proxy_failure_type type, const char *reason);
+/* Handle SASL input in str, and write the SASL output to str. */
+int login_proxy_sasl_step(struct client *client, string_t *str);
+
/* Return TRUE if host/port/destuser combination points to same as current
connection. */
bool login_proxy_is_ourself(const struct client *client, const char *host,
const char *line)
{
string_t *str;
- const unsigned char *data;
- size_t data_len;
- const char *error;
str = t_str_new(128);
if (base64_decode(line, strlen(line), str) < 0) {
LOGIN_PROXY_FAILURE_TYPE_PROTOCOL, reason);
return -1;
}
- enum dsasl_client_result sasl_res =
- dsasl_client_input(client->proxy_sasl_client,
- str_data(str), str_len(str), &error);
- if (sasl_res == DSASL_CLIENT_RESULT_OK) {
- sasl_res = dsasl_client_output(client->proxy_sasl_client,
- &data, &data_len, &error);
- }
- if (sasl_res != DSASL_CLIENT_RESULT_OK) {
- const char *reason = t_strdup_printf(
- "Invalid authentication data: %s", error);
- login_proxy_failed(client->login_proxy,
- login_proxy_get_event(client->login_proxy),
- LOGIN_PROXY_FAILURE_TYPE_PROTOCOL, reason);
+ if (login_proxy_sasl_step(client, str) < 0)
return -1;
- }
-
- str_truncate(str, 0);
- base64_encode(data, data_len, str);
str_append(str, "\r\n");
-
o_stream_nsend(output, str_data(str), str_len(str));
return 0;
}
struct submission_client *subm_client =
container_of(client, struct submission_client, common);
string_t *str;
- const unsigned char *data;
- size_t data_len;
- const char *error;
if (!last_line) {
const char *reason = t_strdup_printf(
return -1;
}
- enum dsasl_client_result sasl_res =
- dsasl_client_input(client->proxy_sasl_client,
- str_data(str), str_len(str), &error);
- if (sasl_res == DSASL_CLIENT_RESULT_OK) {
- sasl_res = dsasl_client_output(client->proxy_sasl_client,
- &data, &data_len, &error);
- }
- if (sasl_res != DSASL_CLIENT_RESULT_OK) {
- const char *reason = t_strdup_printf(
- "Invalid authentication data: %s", error);
- login_proxy_failed(client->login_proxy,
- login_proxy_get_event(client->login_proxy),
- LOGIN_PROXY_FAILURE_TYPE_PROTOCOL, reason);
+ if (login_proxy_sasl_step(client, str) < 0)
return -1;
- }
-
- str_truncate(str, 0);
- base64_encode(data, data_len, str);
str_append(str, "\r\n");
-
o_stream_nsend(output, str_data(str), str_len(str));
return 0;
}