Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
1,185 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#include <unistd.h> | ||
#include "byte.h" | ||
#include "constmap.h" | ||
#include "control.h" | ||
#include "env.h" | ||
#include "fmt.h" | ||
#include "str.h" | ||
#include "stralloc.h" | ||
#include "strerr.h" | ||
|
||
extern void die_control(); | ||
extern void die_nomem(); | ||
|
||
static void _badrcptto_log_rejection(char *recipient) | ||
{ | ||
char smtpdpid[32]; | ||
char *remoteip = env_get("TCPREMOTEIP"); | ||
if (!remoteip) remoteip = "unknown"; | ||
str_copy(smtpdpid + fmt_ulong(smtpdpid,getppid())," "); | ||
strerr_warn5("rcptcheck: badrcptto ",smtpdpid,remoteip," ",recipient,0); | ||
} | ||
|
||
static int _badrcptto_reject_exact_address(struct constmap map, stralloc address) | ||
{ | ||
return (1 && constmap(&map,address.s,address.len - 1)); | ||
} | ||
|
||
static int _badrcptto_reject_whole_domain(struct constmap map, stralloc address) | ||
{ | ||
/* why not just comment out the domain in control/rcpthosts? */ | ||
int j = byte_rchr(address.s,address.len,'@'); | ||
return ((j < address.len) && (constmap(&map,address.s + j,address.len - j - 1))); | ||
} | ||
|
||
static int _badrcptto_reject_string(char *string) | ||
{ | ||
stralloc addr = {0}; | ||
stralloc brt = {0}; | ||
struct constmap mapbrt; | ||
int brtok = control_readfile(&brt,"control/badrcptto",0); | ||
if (brtok == -1) die_control(); | ||
if (!brtok) return 0; | ||
if (!constmap_init(&mapbrt,brt.s,brt.len,0)) die_nomem(); | ||
|
||
if (!stralloc_copys(&addr,string)) die_nomem(); | ||
if (!stralloc_0(&addr)) die_nomem(); | ||
|
||
if (_badrcptto_reject_exact_address(mapbrt,addr)) { | ||
_badrcptto_log_rejection(addr.s); | ||
return 1; | ||
} | ||
|
||
if (_badrcptto_reject_whole_domain(mapbrt,addr)) { | ||
_badrcptto_log_rejection(addr.s); | ||
return 1; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
int badrcptto_reject_recipient(char *recipient) | ||
{ | ||
if (env_get("RELAYCLIENT")) | ||
return 0; | ||
|
||
return _badrcptto_reject_string(recipient); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#ifndef BADRCPTTO_H | ||
#define BADRCPTTO_H | ||
|
||
int badrcptto_reject_recipient(char *); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include "case.h" | ||
|
||
int case_startb(s,len,t) | ||
register char *s; | ||
unsigned int len; | ||
register char *t; | ||
{ | ||
register unsigned char x; | ||
register unsigned char y; | ||
|
||
for (;;) { | ||
y = *t++ - 'A'; | ||
if (y <= 'Z' - 'A') y += 'a'; else y += 'A'; | ||
if (!y) return 1; | ||
if (!len) return 0; | ||
--len; | ||
x = *s++ - 'A'; | ||
if (x <= 'Z' - 'A') x += 'a'; else x += 'A'; | ||
if (x != y) return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#include <unistd.h> | ||
#include "alloc.h" | ||
#include "control.h" | ||
#include "str.h" | ||
#include "stralloc.h" | ||
#include "wait.h" | ||
|
||
void unable_to_allocate() { _exit(51); } | ||
void unable_to_execute() { _exit(71); } | ||
void unable_to_verify() { _exit(55); } | ||
|
||
static int num_lines(stralloc lines) | ||
{ | ||
int num = 0; | ||
int i; | ||
for (i = 0; i < lines.len; i++) if (lines.s[i] == '\0') num++; | ||
return num; | ||
} | ||
|
||
static void run_qmail_qfilter(stralloc filters) | ||
{ | ||
int num_args; | ||
char **args; | ||
int arg; | ||
int linestart; | ||
int i; | ||
|
||
num_args = 2 * num_lines(filters); | ||
if (num_args == 0) num_args = 1; | ||
if (!(args = (char **) alloc(sizeof(char *) * num_args))) | ||
unable_to_allocate(); | ||
|
||
args[0] = "bin/qmail-qfilter"; | ||
|
||
arg = 0; | ||
linestart = 0; | ||
for (i = 0; i < filters.len; i++) { | ||
if (filters.s[i] == '\0') { | ||
stralloc filter = {0}; | ||
stralloc_copys(&filter, filters.s + linestart); | ||
stralloc_0(&filter); | ||
args[++arg] = filter.s; | ||
args[++arg] = "--"; | ||
linestart = i + 1; | ||
} | ||
} | ||
args[num_args] = 0; | ||
|
||
execv(*args, args); | ||
unable_to_execute(); | ||
} | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
stralloc filters = {0}; | ||
|
||
if (control_readfile(&filters,"control/smtpfilters",0) == -1) | ||
unable_to_verify(); | ||
|
||
run_qmail_qfilter(filters); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include <unistd.h> | ||
#include "viruscan.h" | ||
|
||
static void accept_message() { _exit( 0); } | ||
static void reject_message() { _exit(31); } | ||
|
||
void die_control() { _exit(55); } | ||
void die_nomem() { _exit(51); } | ||
|
||
int main(void) | ||
{ | ||
if (viruscan_reject_attachment()) | ||
reject_message(); | ||
|
||
accept_message(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include <unistd.h> | ||
#include "badrcptto.h" | ||
#include "env.h" | ||
|
||
void accept_recipient() { _exit( 0); } | ||
void reject_recipient() { _exit(100); } | ||
void unable_to_verify() { _exit(111); } | ||
|
||
void die_control() { unable_to_verify(); } | ||
void die_nomem() { unable_to_verify(); } | ||
|
||
int main(void) | ||
{ | ||
char *recipient = env_get("RECIPIENT"); | ||
|
||
if (!recipient) | ||
unable_to_verify(); | ||
|
||
if (badrcptto_reject_recipient(recipient)) | ||
reject_recipient(); | ||
|
||
accept_recipient(); | ||
} |
Oops, something went wrong.