xref: /openbsd-src/usr.sbin/smtpd/esc.c (revision 50b7afb2c2c0993b0894d4e34bf857cb13ed9c80)
1 /* $OpenBSD: esc.c,v 1.2 2014/04/19 17:32:58 gilles 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 <stdio.h>
20 
21 #include "smtpd-defines.h"
22 #include "smtpd-api.h"
23 
24 static struct escode {
25 	enum enhanced_status_code	code;
26 	const char		       *description;
27 } esc[] = {
28 	/* 0.0 */
29 	{ ESC_OTHER_STATUS,				"Other/Undefined" },
30 
31 	/* 1.x */
32 	{ ESC_OTHER_ADDRESS_STATUS,			"Other/Undefined address status" },
33 	{ ESC_BAD_DESTINATION_MAILBOX_ADDRESS,		"Bad destination mailbox address" },
34 	{ ESC_BAD_DESTINATION_SYSTEM_ADDRESS,		"Bad destination system address" },
35 	{ ESC_BAD_DESTINATION_MAILBOX_ADDRESS_SYNTAX,	"Bad destination mailbox address syntax" },
36 	{ ESC_DESTINATION_MAILBOX_ADDRESS_AMBIGUOUS,	"Destination mailbox address ambiguous" },
37 	{ ESC_DESTINATION_ADDRESS_VALID,		"Destination address valid" },
38 	{ ESC_DESTINATION_MAILBOX_HAS_MOVED,		"Destination mailbox has moved, No forwarding address" },
39 	{ ESC_BAD_SENDER_MAILBOX_ADDRESS_SYNTAX,	"Bad sender's mailbox address syntax" },
40 	{ ESC_BAD_SENDER_SYSTEM_ADDRESS,		"Bad sender's system address syntax" },
41 
42 	/* 2.x */
43 	{ ESC_OTHER_MAILBOX_STATUS,			"Other/Undefined mailbox status" },
44 	{ ESC_MAILBOX_DISABLED,				"Mailbox disabled, not accepting messages" },
45 	{ ESC_MAILBOX_FULL,				"Mailbox full" },
46 	{ ESC_MESSAGE_LENGTH_TOO_LARGE,			"Message length exceeds administrative limit" },
47 	{ ESC_MAILING_LIST_EXPANSION_PROBLEM,		"Mailing list expansion problem" },
48 
49 	/* 3.x */
50 	{ ESC_OTHER_MAIL_SYSTEM_STATUS,			"Other/Undefined mail system status" },
51 	{ ESC_MAIL_SYSTEM_FULL,				"Mail system full" },
52 	{ ESC_SYSTEM_NOT_ACCEPTING_MESSAGES,		"System not accepting network messages" },
53 	{ ESC_SYSTEM_NOT_CAPABLE_OF_SELECTED_FEATURES,	"System not capable of selected features" },
54 	{ ESC_MESSAGE_TOO_BIG_FOR_SYSTEM,		"Message too big for system" },
55 	{ ESC_SYSTEM_INCORRECTLY_CONFIGURED,		"System incorrectly configured" },
56 
57 	/* 4.x */
58 	{ ESC_OTHER_NETWORK_ROUTING_STATUS,		"Other/Undefined network or routing status" },
59 	{ ESC_NO_ANSWER_FROM_HOST,			"No answer from host" },
60 	{ ESC_BAD_CONNECTION,				"Bad connection" },
61 	{ ESC_DIRECTORY_SERVER_FAILURE,			"Directory server failure" },
62 	{ ESC_UNABLE_TO_ROUTE,				"Unable to route" },
63 	{ ESC_MAIL_SYSTEM_CONGESTION,			"Mail system congestion" },
64 	{ ESC_ROUTING_LOOP_DETECTED,			"Routing loop detected" },
65 	{ ESC_DELIVERY_TIME_EXPIRED,			"Delivery time expired" },
66 
67 	/* 5.x */
68 	{ ESC_OTHER_PROTOCOL_STATUS,			"Other/Undefined protocol status" },
69 	{ ESC_INVALID_COMMAND,				"Invalid command" },
70 	{ ESC_SYNTAX_ERROR,				"Syntax error" },
71 	{ ESC_TOO_MANY_RECIPIENTS,			"Too many recipients" },
72 	{ ESC_INVALID_COMMAND_ARGUMENTS,		"Invalid command arguments" },
73 	{ ESC_WRONG_PROTOCOL_VERSION,			"Wrong protocol version" },
74 
75 	/* 6.x */
76 	{ ESC_OTHER_MEDIA_ERROR,			"Other/Undefined media error" },
77 	{ ESC_MEDIA_NOT_SUPPORTED,			"Media not supported" },
78 	{ ESC_CONVERSION_REQUIRED_AND_PROHIBITED,	"Conversion required and prohibited" },
79 	{ ESC_CONVERSION_REQUIRED_BUT_NOT_SUPPORTED,	"Conversion required but not supported" },
80 	{ ESC_CONVERSION_WITH_LOSS_PERFORMED,		"Conversion with loss performed" },
81 	{ ESC_CONVERSION_FAILED,			"Conversion failed" },
82 
83 	/* 7.x */
84 	{ ESC_OTHER_SECURITY_STATUS,			"Other/Undefined security status" },
85 	{ ESC_DELIVERY_NOT_AUTHORIZED_MESSAGE_REFUSED,	"Delivery not authorized, message refused" },
86 	{ ESC_MAILING_LIST_EXPANSION_PROHIBITED,       	"Mailing list expansion prohibited" },
87 	{ ESC_SECURITY_CONVERSION_REQUIRED_NOT_POSSIBLE,"Security conversion required but not possible" },
88 	{ ESC_SECURITY_FEATURES_NOT_SUPPORTED,		"Security features not supported" },
89 	{ ESC_CRYPTOGRAPHIC_FAILURE,			"Cryptographic failure" },
90 	{ ESC_CRYPTOGRAPHIC_ALGORITHM_NOT_SUPPORTED,	"Cryptographic algorithm not supported" },
91 	{ ESC_MESSAGE_TOO_BIG_FOR_SYSTEM,		"Message integrity failure" },
92 };
93 
94 #if 0
95 struct esc_map {
96 	uint8_t		code;
97 	const char     *description;
98 };
99 
100 static struct esc_map esc_class[] = {
101 	{ 2, "Success" },
102 	{ 4, "Persistent Transient Failure"},
103 	{ 5, "Permanent Failure" },
104 };
105 
106 static struct esc_map esc_subclass[] = {
107 	{ 0, "Other/Undefined" },
108 	{ 1, "Addressing Status" },
109 	{ 2, "Mailbox Status" },
110 	{ 3, "Mail System Status" },
111 	{ 4, "Network and Routing Status" },
112 	{ 5, "Mail Delivery Protocol Status" },
113 	{ 6, "Message Content or Media Status" },
114 	{ 7, "Security or Policy Status" },
115 };
116 #endif
117 
118 const char *
119 esc_code(enum enhanced_status_class class, enum enhanced_status_code code)
120 {
121 	static char buffer[6];
122 
123 	(void)snprintf(buffer, sizeof buffer, "%d.%d.%d", class, code / 10, code % 10);
124 	return buffer;
125 
126 }
127 
128 const char *
129 esc_description(enum enhanced_status_code code)
130 {
131 	uint32_t	i;
132 
133 	for (i = 0; i < nitems(esc); ++i)
134 		if (code == esc[i].code)
135 			return esc[i].description;
136 	return "Other/Undefined";
137 }
138