Coverage Report

Created: 2026-06-15 06:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/dovecot/src/lib-sasl/dsasl-client-mech-plain.c
Line
Count
Source
1
/* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */
2
3
#include "lib.h"
4
#include "str.h"
5
#include "dsasl-client-private.h"
6
7
struct plain_dsasl_client {
8
  struct dsasl_client client;
9
  bool output_sent;
10
};
11
12
static enum dsasl_client_result
13
mech_plain_input(struct dsasl_client *_client,
14
     const unsigned char *input ATTR_UNUSED, size_t input_len,
15
     const char **error_r)
16
0
{
17
0
  struct plain_dsasl_client *client =
18
0
    (struct plain_dsasl_client *)_client;
19
20
0
  if (!client->output_sent) {
21
0
    if (input_len > 0) {
22
0
      *error_r = "Server sent non-empty initial response";
23
0
      return DSASL_CLIENT_RESULT_ERR_PROTOCOL;
24
0
    }
25
0
  } else {
26
0
    *error_r = "Server didn't finish authentication";
27
0
    return DSASL_CLIENT_RESULT_ERR_PROTOCOL;
28
0
  }
29
0
  return DSASL_CLIENT_RESULT_OK;
30
0
}
31
32
static enum dsasl_client_result
33
mech_plain_output(struct dsasl_client *_client,
34
      const unsigned char **output_r, size_t *output_len_r,
35
      const char **error_r)
36
569
{
37
569
  struct plain_dsasl_client *client =
38
569
    (struct plain_dsasl_client *)_client;
39
569
  string_t *str;
40
41
569
  if (_client->set.authid == NULL) {
42
0
    *error_r = "authid not set";
43
0
    return DSASL_CLIENT_RESULT_ERR_INTERNAL;
44
0
  }
45
569
  if (_client->password == NULL) {
46
0
    *error_r = "password not set";
47
0
    return DSASL_CLIENT_RESULT_ERR_INTERNAL;
48
0
  }
49
50
569
  str = str_new(_client->pool, 64);
51
569
  if (_client->set.authzid != NULL)
52
355
    str_append(str, _client->set.authzid);
53
569
  str_append_c(str, '\0');
54
569
  str_append(str, _client->set.authid);
55
569
  str_append_c(str, '\0');
56
569
  str_append(str, _client->password);
57
58
569
  *output_r = str_data(str);
59
569
  *output_len_r = str_len(str);
60
569
  client->output_sent = TRUE;
61
569
  return 0;
62
569
}
63
64
const struct dsasl_client_mech dsasl_client_mech_plain = {
65
  .name = SASL_MECH_NAME_PLAIN,
66
  .struct_size = sizeof(struct plain_dsasl_client),
67
68
  .input = mech_plain_input,
69
  .output = mech_plain_output
70
};