1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
/*++
/* NAME
/* ehlo_mask 3
/* SUMMARY
/* map EHLO keywords to bit mask
/* SYNOPSIS
/* #include <ehlo_mask.h>
/*
/* #define EHLO_MASK_8BITMIME (1<<0)
/* #define EHLO_MASK_PIPELINING (1<<1)
/* #define EHLO_MASK_SIZE (1<<2)
/* #define EHLO_MASK_VRFY (1<<3)
/* #define EHLO_MASK_ETRN (1<<4)
/* #define EHLO_MASK_AUTH (1<<5)
/* #define EHLO_MASK_VERP (1<<6)
/* #define EHLO_MASK_STARTTLS (1<<7)
/* #define EHLO_MASK_XCLIENT (1<<8)
/* #define EHLO_MASK_XFORWARD (1<<9)
/* #define EHLO_MASK_ENHANCEDSTATUSCODES (1<<10)
/* #define EHLO_MASK_DSN (1<<11)
/* #define EHLO_MASK_SMTPUTF8 (1<<12)
/* #define EHLO_MASK_CHUNKING (1<<13)
/* #define EHLO_MASK_SILENT (1<<15)
/*
/* int ehlo_mask(keyword_list)
/* const char *keyword_list;
/*
/* const char *str_ehlo_mask(bitmask)
/* int bitmask;
/* DESCRIPTION
/* ehlo_mask() computes the bit-wise OR of the masks that correspond
/* to the names listed in the \fIkeyword_list\fR argument, separated by
/* comma and/or whitespace characters. Undefined names are silently
/* ignored.
/*
/* str_ehlo_mask() translates a mask into its equivalent names.
/* The result is written to a static buffer that is overwritten
/* upon each call. Undefined bits cause a fatal run-time error.
/* DIAGNOSTICS
/* Fatal: str_ehlo_mask() found an undefined bit.
/* LICENSE
/* .ad
/* .fi
/* The Secure Mailer license must be distributed with this software.
/* AUTHOR(S)
/* Wietse Venema
/* IBM T.J. Watson Research
/* P.O. Box 704
/* Yorktown Heights, NY 10598, USA
/*
/* Wietse Venema
/* Google, Inc.
/* 111 8th Avenue
/* New York, NY 10011, USA
/*--*/
/* System library.*/
#include <sys_defs.h>
/* Utility library. */
#include <name_mask.h>
/* Global library. */
#include <ehlo_mask.h>
/*
* The lookup table.
*/
static const NAME_MASK ehlo_mask_table[] = {
"8BITMIME", EHLO_MASK_8BITMIME,
"AUTH", EHLO_MASK_AUTH,
"ETRN", EHLO_MASK_ETRN,
"PIPELINING", EHLO_MASK_PIPELINING,
"SIZE", EHLO_MASK_SIZE,
"VERP", EHLO_MASK_VERP,
"VRFY", EHLO_MASK_VRFY,
"XCLIENT", EHLO_MASK_XCLIENT,
"XFORWARD", EHLO_MASK_XFORWARD,
"STARTTLS", EHLO_MASK_STARTTLS,
"ENHANCEDSTATUSCODES", EHLO_MASK_ENHANCEDSTATUSCODES,
"DSN", EHLO_MASK_DSN,
"EHLO_MASK_SMTPUTF8", EHLO_MASK_SMTPUTF8,
"SMTPUTF8", EHLO_MASK_SMTPUTF8,
"CHUNKING", EHLO_MASK_CHUNKING,
"SILENT-DISCARD", EHLO_MASK_SILENT, /* XXX In-band signaling */
0,
};
/* ehlo_mask - string to bit mask */
int ehlo_mask(const char *mask_str)
{
/*
* We allow "STARTTLS" besides "starttls, because EHLO keywords are often
* spelled in uppercase. We ignore non-existent EHLO keywords so people
* can switch between Postfix versions without trouble.
*/
return (name_mask_opt("ehlo string mask", ehlo_mask_table,
mask_str, NAME_MASK_ANY_CASE | NAME_MASK_IGNORE));
}
/* str_ehlo_mask - mask to string */
const char *str_ehlo_mask(int mask_bits)
{
/*
* We don't allow non-existent bits. Doing so makes no sense at this
* time.
*/
return (str_name_mask("ehlo bitmask", ehlo_mask_table, mask_bits));
}
#ifdef TEST
/*
* Stand-alone test program.
*/
#include <stdlib.h>
#include <vstream.h>
#include <vstring.h>
#include <vstring_vstream.h>
int main(int unused_argc, char **unused_argv)
{
int mask_bits;
VSTRING *buf = vstring_alloc(1);
const char *mask_string;
while (vstring_get_nonl(buf, VSTREAM_IN) != VSTREAM_EOF) {
mask_bits = ehlo_mask(vstring_str(buf));
mask_string = str_ehlo_mask(mask_bits);
vstream_printf("%s -> 0x%x -> %s\n", vstring_str(buf), mask_bits,
mask_string);
vstream_fflush(VSTREAM_OUT);
}
vstring_free(buf);
exit(0);
}
#endif
|