/src/dovecot/src/lib-sasl/dsasl-client-mech-anonymous.c
Line | Count | Source |
1 | | /* Copyright (c) 2025 Dovecot authors, see the included COPYING file */ |
2 | | |
3 | | #include "lib.h" |
4 | | #include "dsasl-client-private.h" |
5 | | |
6 | | struct anonymous_dsasl_client { |
7 | | struct dsasl_client client; |
8 | | bool output_sent; |
9 | | }; |
10 | | |
11 | | static enum dsasl_client_result |
12 | | mech_anonymous_input(struct dsasl_client *_client, |
13 | | const unsigned char *input ATTR_UNUSED, size_t input_len, |
14 | | const char **error_r) |
15 | 0 | { |
16 | 0 | struct anonymous_dsasl_client *client = |
17 | 0 | container_of(_client, struct anonymous_dsasl_client, client); |
18 | |
|
19 | 0 | if (!client->output_sent) { |
20 | 0 | if (input_len > 0) { |
21 | 0 | *error_r = "Server sent non-empty initial response"; |
22 | 0 | return DSASL_CLIENT_RESULT_ERR_PROTOCOL; |
23 | 0 | } |
24 | 0 | } else if (input_len > 0) { |
25 | 0 | *error_r = "Server sent non-empty response"; |
26 | 0 | return DSASL_CLIENT_RESULT_ERR_PROTOCOL; |
27 | 0 | } |
28 | 0 | return DSASL_CLIENT_RESULT_OK; |
29 | 0 | } |
30 | | |
31 | | static enum dsasl_client_result |
32 | | mech_anonymous_output(struct dsasl_client *_client, |
33 | | const unsigned char **output_r, size_t *output_len_r, |
34 | | const char **error_r ATTR_UNUSED) |
35 | 2 | { |
36 | 2 | struct anonymous_dsasl_client *client = |
37 | 2 | container_of(_client, struct anonymous_dsasl_client, client); |
38 | | |
39 | 2 | const char *authid = client->client.set.authid; |
40 | 2 | if (authid == NULL) |
41 | 0 | authid = ""; |
42 | 2 | *output_r = (const unsigned char*)authid; |
43 | 2 | *output_len_r = strlen(authid); |
44 | 2 | client->output_sent = TRUE; |
45 | 2 | return DSASL_CLIENT_RESULT_OK; |
46 | 2 | } |
47 | | |
48 | | const struct dsasl_client_mech dsasl_client_mech_anonymous = { |
49 | | .name = SASL_MECH_NAME_ANONYMOUS, |
50 | | .struct_size = sizeof(struct anonymous_dsasl_client), |
51 | | .flags = DSASL_MECH_SEC_NO_PASSWORD, |
52 | | |
53 | | .input = mech_anonymous_input, |
54 | | .output = mech_anonymous_output |
55 | | }; |