Coverage Report

Created: 2025-11-03 07:11

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/dovecot/src/lib-smtp/smtp-server-cmd-vrfy.c
Line
Count
Source
1
/* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */
2
3
#include "lib.h"
4
#include "smtp-syntax.h"
5
6
#include "smtp-server-private.h"
7
8
/* VRFY command */
9
10
void smtp_server_cmd_vrfy(struct smtp_server_cmd_ctx *cmd,
11
        const char *params)
12
1.36k
{
13
1.36k
  struct smtp_server_connection *conn = cmd->conn;
14
1.36k
  struct smtp_server_command *command = cmd->cmd;
15
1.36k
  const struct smtp_server_callbacks *callbacks = conn->callbacks;
16
1.36k
  const char *param, *error;
17
1.36k
  int ret;
18
19
  /* vrfy = "VRFY" SP String CRLF */
20
1.36k
  ret = smtp_string_parse(params, &param, &error);
21
1.36k
  if (ret < 0) {
22
276
    smtp_server_reply(cmd, 501, "5.5.4",
23
276
          "Invalid string parameter: %s", error);
24
276
    return;
25
1.08k
  } else if (ret == 0) {
26
356
    smtp_server_reply(cmd, 501, "5.5.4", "Invalid parameters");
27
356
    return;
28
356
  }
29
30
733
  smtp_server_command_ref(command);
31
733
  if (callbacks != NULL && callbacks->conn_cmd_vrfy != NULL) {
32
    /* specific implementation of VRFY command */
33
0
    ret = callbacks->conn_cmd_vrfy(conn->context, cmd, param);
34
0
    if (ret <= 0) {
35
0
      i_assert(ret == 0 ||
36
0
         smtp_server_command_is_replied(command));
37
      /* command is waiting for external event or it failed */
38
0
      smtp_server_command_unref(&command);
39
0
      return;
40
0
    }
41
0
  }
42
43
  /* RFC 5321, Section 3.5.3:
44
45
     A server MUST NOT return a 250 code in response to a VRFY or EXPN
46
     command unless it has actually verified the address. In particular,
47
     a server MUST NOT return 250 if all it has done is to verify that the
48
     syntax given is valid. In that case, 502 (Command not implemented)
49
     or 500 (Syntax error, command unrecognized) SHOULD be returned. As
50
     stated elsewhere, implementation (in the sense of actually validating
51
     addresses and returning information) of VRFY and EXPN are strongly
52
     recommended. Hence, implementations that return 500 or 502 for VRFY
53
     are not in full compliance with this specification.
54
55
     There may be circumstances where an address appears to be valid but
56
     cannot reasonably be verified in real time, particularly when a
57
     server is acting as a mail exchanger for another server or domain.
58
     "Apparent validity", in this case, would normally involve at least
59
     syntax checking and might involve verification that any domains
60
     specified were ones to which the host expected to be able to relay
61
     mail. In these situations, reply code 252 SHOULD be returned.
62
   */
63
733
  if (!smtp_server_command_is_replied(command))
64
733
    smtp_server_cmd_vrfy_reply_default(cmd);
65
733
  smtp_server_command_unref(&command);
66
733
}
67
68
void smtp_server_cmd_vrfy_reply_default(struct smtp_server_cmd_ctx *cmd)
69
733
{
70
733
  i_assert(cmd->cmd->reg->func == smtp_server_cmd_vrfy);
71
72
733
  smtp_server_reply(cmd, 252, "2.3.3", "Try RCPT instead");
73
733
}