1 /* $OpenBSD: esc.c,v 1.6 2021/06/14 17:58:15 eric Exp $ */
2
3 /*
4 * Copyright (c) 2014 Gilles Chehade <gilles@poolp.org>
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 #include <sys/tree.h>
20
21 #include <limits.h>
22 #include <stdio.h>
23
24 #include "smtpd-defines.h"
25 #include "smtpd-api.h"
26
27 static struct escode {
28 enum enhanced_status_code code;
29 const char *description;
30 } esc[] = {
31 /* 0.0 */
32 { ESC_OTHER_STATUS, "Other/Undefined" },
33
34 /* 1.x */
35 { ESC_OTHER_ADDRESS_STATUS, "Other/Undefined address status" },
36 { ESC_BAD_DESTINATION_MAILBOX_ADDRESS, "Bad destination mailbox address" },
37 { ESC_BAD_DESTINATION_SYSTEM_ADDRESS, "Bad destination system address" },
38 { ESC_BAD_DESTINATION_MAILBOX_ADDRESS_SYNTAX, "Bad destination mailbox address syntax" },
39 { ESC_DESTINATION_MAILBOX_ADDRESS_AMBIGUOUS, "Destination mailbox address ambiguous" },
40 { ESC_DESTINATION_ADDRESS_VALID, "Destination address valid" },
41 { ESC_DESTINATION_MAILBOX_HAS_MOVED, "Destination mailbox has moved, No forwarding address" },
42 { ESC_BAD_SENDER_MAILBOX_ADDRESS_SYNTAX, "Bad sender's mailbox address syntax" },
43 { ESC_BAD_SENDER_SYSTEM_ADDRESS, "Bad sender's system address syntax" },
44
45 /* 2.x */
46 { ESC_OTHER_MAILBOX_STATUS, "Other/Undefined mailbox status" },
47 { ESC_MAILBOX_DISABLED, "Mailbox disabled, not accepting messages" },
48 { ESC_MAILBOX_FULL, "Mailbox full" },
49 { ESC_MESSAGE_LENGTH_TOO_LARGE, "Message length exceeds administrative limit" },
50 { ESC_MAILING_LIST_EXPANSION_PROBLEM, "Mailing list expansion problem" },
51
52 /* 3.x */
53 { ESC_OTHER_MAIL_SYSTEM_STATUS, "Other/Undefined mail system status" },
54 { ESC_MAIL_SYSTEM_FULL, "Mail system full" },
55 { ESC_SYSTEM_NOT_ACCEPTING_MESSAGES, "System not accepting network messages" },
56 { ESC_SYSTEM_NOT_CAPABLE_OF_SELECTED_FEATURES, "System not capable of selected features" },
57 { ESC_MESSAGE_TOO_BIG_FOR_SYSTEM, "Message too big for system" },
58 { ESC_SYSTEM_INCORRECTLY_CONFIGURED, "System incorrectly configured" },
59
60 /* 4.x */
61 { ESC_OTHER_NETWORK_ROUTING_STATUS, "Other/Undefined network or routing status" },
62 { ESC_NO_ANSWER_FROM_HOST, "No answer from host" },
63 { ESC_BAD_CONNECTION, "Bad connection" },
64 { ESC_DIRECTORY_SERVER_FAILURE, "Directory server failure" },
65 { ESC_UNABLE_TO_ROUTE, "Unable to route" },
66 { ESC_MAIL_SYSTEM_CONGESTION, "Mail system congestion" },
67 { ESC_ROUTING_LOOP_DETECTED, "Routing loop detected" },
68 { ESC_DELIVERY_TIME_EXPIRED, "Delivery time expired" },
69
70 /* 5.x */
71 { ESC_INVALID_RECIPIENT, "Invalid recipient" },
72 { ESC_INVALID_COMMAND, "Invalid command" },
73 { ESC_SYNTAX_ERROR, "Syntax error" },
74 { ESC_TOO_MANY_RECIPIENTS, "Too many recipients" },
75 { ESC_INVALID_COMMAND_ARGUMENTS, "Invalid command arguments" },
76 { ESC_WRONG_PROTOCOL_VERSION, "Wrong protocol version" },
77
78 /* 6.x */
79 { ESC_OTHER_MEDIA_ERROR, "Other/Undefined media error" },
80 { ESC_MEDIA_NOT_SUPPORTED, "Media not supported" },
81 { ESC_CONVERSION_REQUIRED_AND_PROHIBITED, "Conversion required and prohibited" },
82 { ESC_CONVERSION_REQUIRED_BUT_NOT_SUPPORTED, "Conversion required but not supported" },
83 { ESC_CONVERSION_WITH_LOSS_PERFORMED, "Conversion with loss performed" },
84 { ESC_CONVERSION_FAILED, "Conversion failed" },
85
86 /* 7.x */
87 { ESC_OTHER_SECURITY_STATUS, "Other/Undefined security status" },
88 { ESC_DELIVERY_NOT_AUTHORIZED_MESSAGE_REFUSED, "Delivery not authorized, message refused" },
89 { ESC_MAILING_LIST_EXPANSION_PROHIBITED, "Mailing list expansion prohibited" },
90 { ESC_SECURITY_CONVERSION_REQUIRED_NOT_POSSIBLE,"Security conversion required but not possible" },
91 { ESC_SECURITY_FEATURES_NOT_SUPPORTED, "Security features not supported" },
92 { ESC_CRYPTOGRAPHIC_FAILURE, "Cryptographic failure" },
93 { ESC_CRYPTOGRAPHIC_ALGORITHM_NOT_SUPPORTED, "Cryptographic algorithm not supported" },
94 { ESC_MESSAGE_TOO_BIG_FOR_SYSTEM, "Message integrity failure" },
95 };
96
97 const char *
esc_code(enum enhanced_status_class class,enum enhanced_status_code code)98 esc_code(enum enhanced_status_class class, enum enhanced_status_code code)
99 {
100 static char buffer[6];
101
102 (void)snprintf(buffer, sizeof buffer, "%d.%d.%d", class, code / 10, code % 10);
103 return buffer;
104
105 }
106
107 const char *
esc_description(enum enhanced_status_code code)108 esc_description(enum enhanced_status_code code)
109 {
110 uint32_t i;
111
112 for (i = 0; i < nitems(esc); ++i)
113 if (code == esc[i].code)
114 return esc[i].description;
115 return "Other/Undefined";
116 }
117