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