Attachment 'helodnscheck.c'
Download 1 /*
2 * Copyright (C) 2007 Jason Frisvold <friz@godshell.com>
3 * Original Copyright (C) 2003-2004 Perolo Silantico <per.sil@gmx.it>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later
9 * version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 ***
20 * 1/16 Modified original version to check helo/ehlo instead of mail from
21 ***
22 *
23 * $Id$
24 *
25 */
26
27 #include <netinet/in.h>
28 #include <arpa/nameser.h>
29 #include <resolv.h>
30 #include <string.h>
31 #include <stdlib.h>
32 #include <errno.h>
33 #include <netdb.h>
34
35 void block_permanent(const char* message) {
36 printf("E553 sorry, %s (#5.7.1)\n", message);
37 fprintf(stderr, "helo-dns-check: blocked with: %s\n", message);
38 }
39
40
41 void block_temporary(const char* message) {
42 printf("E451 %s (#4.3.0)\n", message);
43 fprintf(stderr, "helo-dns-check: temporary failure: %s\n", message);
44 }
45
46 int main(void) {
47 unsigned char dns_answer[1023];
48 char *helo_domain = getenv("SMTPHELOHOST");
49 char *no_helo_check = getenv("NOHELODNSCHECK");
50
51 if (no_helo_check) {
52 return 0;
53 }
54
55 if (!helo_domain) {
56 block_permanent("no HELO/EHLO hostname has been sent.");
57 return 0;
58 }
59
60 /* init DNS library */
61 res_init();
62
63 /* check A record of host */
64 if (res_query(helo_domain, C_IN, T_A, dns_answer, sizeof(dns_answer)) <= 0)
65 {
66 if ((errno == ECONNREFUSED) || (errno == TRY_AGAIN))
67 block_temporary("DNS temporary failure.");
68 else
69 block_permanent("invalid host name in HELO/EHLO command.");
70 }
71
72 return 0;
73 }
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.