Coverage Report

Created: 2026-07-16 07:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/dovecot/src/lib-sasl/dsasl-client-mech-external.c
Line
Count
Source
1
/* Copyright (c) Dovecot authors, see top-level COPYING file */
2
3
#include "lib.h"
4
#include "dsasl-client-private.h"
5
6
struct external_dsasl_client {
7
  struct dsasl_client client;
8
  bool output_sent;
9
};
10
11
static enum dsasl_client_result
12
mech_external_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 external_dsasl_client *client =
17
0
    (struct external_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 {
25
0
    *error_r = "Server didn't finish authentication";
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_external_output(struct dsasl_client *_client,
33
         const unsigned char **output_r, size_t *output_len_r,
34
         const char **error_r ATTR_UNUSED)
35
0
{
36
0
  struct external_dsasl_client *client =
37
0
    (struct external_dsasl_client *)_client;
38
0
  const char *username;
39
40
0
  if (_client->set.authzid != NULL)
41
0
    username = _client->set.authzid;
42
0
  else if (_client->set.authid != NULL)
43
0
    username = _client->set.authid;
44
0
  else
45
0
    username = "";
46
47
0
  *output_r = (const void *)username;
48
0
  *output_len_r = strlen(username);
49
0
  client->output_sent = TRUE;
50
0
  return DSASL_CLIENT_RESULT_OK;
51
0
}
52
53
const struct dsasl_client_mech dsasl_client_mech_external = {
54
  .name = SASL_MECH_NAME_EXTERNAL,
55
  .struct_size = sizeof(struct external_dsasl_client),
56
  .flags = DSASL_MECH_SEC_NO_PASSWORD,
57
58
  .input = mech_external_input,
59
  .output = mech_external_output
60
};