-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbadhelo.c
63 lines (52 loc) · 1.35 KB
/
badhelo.c
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
char *chomp(char *str)
{
if (str && *str && str[strlen(str)-1]=='\n') str[strlen(str)-1]=0;
return str;
}
int search_in_file(char *fname, char *str) {
FILE *fp;
int found = 0;
char temp[512];
// check if file is readbale
if ((fp = fopen(fname, "r")) == NULL) {
return(-1);
}
while (fgets(temp, 512, fp) != NULL) {
if ((strstr(temp, str)) != NULL) {
found++;
}
}
// close file if still open
if (fp) { fclose(fp); }
return(found);
}
int main() {
// read SMTPHELOHOST from environment
const char* hostname = chomp(getenv("SMTPHELOHOST"));
// skip this test for RELAYCLIENT
// skip this test for TRUSTCLIENT
// skip this test if there is no badhelo file
if ( (getenv("RELAYCLIENT")) || (getenv("TRUSTCLIENT")) || (access("/var/qmail/control/badhelo", R_OK) == -1 ) ) {
printf("\n");
exit(0);
}
// check for empty hostname
if (hostname == NULL) {
printf("E550 No hostname provided in HELO/EHLO\n");
exit(0);
}
// search through badhelo file
if (search_in_file("/var/qmail/control/badhelo",hostname)) {
fprintf(stderr, "%d Found %s in badhelo list !\n", getpid(), hostname);
sleep(5);
printf("E550 Bad hostname [%s]\n", hostname);
exit(0);
}
// default last action
printf("\n");
exit(0);
}