GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usr.sbin/smtpd/smtpd/../esc.c Lines: 0 6 0.0 %
Date: 2017-11-07 Branches: 0 4 0.0 %

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