various cleanup

This commit is contained in:
rsc 2006-02-11 23:38:55 +00:00
parent e4d832222b
commit b5f65921f3
37 changed files with 223 additions and 248 deletions

View file

@ -23,7 +23,7 @@ typedef struct {
enum {
Nonspammax = 14*60*60, /* must call back within this time if real */
};
static char whitelist[] = "/mail/lib/whitelist";
static char *whitelist = "#9/mail/lib/whitelist";
/*
* matches ip addresses or subnets in whitelist against nci->rsys.
@ -40,11 +40,11 @@ onwhitelist(void)
uchar mask[IPaddrlen], addr[IPaddrlen], addrmasked[IPaddrlen];
Biobuf *wl;
static int beenhere;
static allzero[IPaddrlen];
if (!beenhere) {
beenhere = 1;
fmtinstall('I', eipfmt);
whitelist = unsharp(whitelist);
}
parseip(ip, nci->rsys);
@ -219,8 +219,8 @@ isrcptrecent(char *rcpt)
user++;
/* check & try to update the grey list entry */
snprint(file, sizeof file, "/mail/grey/%s/%s/%s",
nci->lsys, nci->rsys, user);
snprint(file, sizeof file, "%s/mail/grey/%s/%s/%s",
get9root(), nci->lsys, nci->rsys, user);
memset(gsp, 0, sizeof *gsp);
addgreylist(file, gsp);
@ -258,10 +258,7 @@ vfysenderhostok(void)
if (fd >= 0) {
seek(fd, 0, 2); /* paranoia */
if ((fqdn = csgetvalue(nil, "ip", nci->rsys, "dom", nil)) != nil)
fprint(fd, "# %s\n%s\n\n", fqdn, nci->rsys);
else
fprint(fd, "# unknown\n%s\n\n", nci->rsys);
fprint(fd, "# %s\n%s\n\n", fqdn, nci->rsys);
close(fd);
}
} else {

View file

@ -1,12 +1,12 @@
<$PLAN9/src/mkhdr
TARG = # smtpd\
TARG=\
smtp\
smtpd\
OFILES=
LIB=../common/libcommon.a\
$PLAN9/lib/libthread.a # why do i have to explicitly put this?
LIB=../common/libcommon.a
HFILES=../common/common.h\
../common/sys.h\
@ -27,7 +27,7 @@ UPDATE=\
${TARG:%=%.c}\
<$PLAN9/src/mkmany
CFLAGS=$CFLAGS -I../common -D'SPOOL="/mail"'
CFLAGS=$CFLAGS -I../common -D'SPOOL="'$PLAN9'/mail"'
$O.smtpd: smtpd.tab.$O rmtdns.$O spam.$O rfc822.tab.$O greylist.$O
$O.smtp: rfc822.tab.$O mxdial.$O
@ -37,7 +37,7 @@ smtpd.$O: smtpd.h
smtp.$O to.$O: smtp.h
smtpd.tab.c: smtpd.y smtpd.h
yacc -o xxx smtpd.y
9 yacc -o xxx smtpd.y
sed 's/yy/zz/g' < xxx > $target
rm xxx
@ -47,8 +47,6 @@ rfc822.tab.c: rfc822.y smtp.h
clean:V:
rm -f *.[$OS] [$OS].$TARG smtpd.tab.c rfc822.tab.c y.tab.? y.debug $TARG
../common/libcommon.a$O:
@{
cd ../common
mk
}
../common/libcommon.a
cd ../common; mk

View file

@ -1,6 +1,7 @@
#include "common.h"
#include <ndb.h>
#include "smtp.h" /* to publish dial_string_parse */
#include <ip.h>
enum
{
@ -42,14 +43,20 @@ mxdial(char *addr, char *ddomain, char *gdomain)
/* try our mail gateway */
rerrstr(err, sizeof(err));
if(fd < 0 && gdomain && strstr(err, "can't translate") != 0) {
fprint(2,"dialing %s\n",gdomain);
if(fd < 0 && gdomain && strstr(err, "can't translate") != 0)
fd = dial(netmkaddr(gdomain, 0, "smtp"), 0, 0, 0);
}
return fd;
}
static int
timeout(void*, char *msg)
{
if(strstr(msg, "alarm"))
return 1;
return 0;
}
/*
* take an address and return all the mx entries for it,
* most preferred first
@ -92,7 +99,11 @@ callmx(DS *ds, char *dest, char *domain)
mx[i].host, ds->service);
if(debug)
fprint(2, "mxdial trying %s\n", addr);
atnotify(timeout, 1);
alarm(10*1000);
fd = dial(addr, 0, 0, 0);
alarm(0);
atnotify(timeout, 0);
if(fd >= 0)
return fd;
}
@ -316,6 +327,7 @@ expand_meta(DS *ds)
}
#endif /* jpc */
/* XXX */
static void
expand_meta(DS *ds)
{

View file

@ -171,7 +171,7 @@ threadmain(int argc, char **argv)
if(*argv == 0)
usage();
addr = *argv++; argc--;
// expand $smtp if necessary
// expand $smtp if necessary XXX
addr = expand_addr(addr);
farend = addr;
@ -202,12 +202,12 @@ threadmain(int argc, char **argv)
exits(0);
}
/* 10 minutes to get through the initial handshake */
atnotify(timeout, 1);
alarm(10*alarmscale);
/* mxdial uses its own timeout handler */
if((rv = connect(addr)) != 0)
exits(rv);
/* 10 minutes to get through the initial handshake */
atnotify(timeout, 1);
alarm(10*alarmscale);
if((rv = hello(hellodomain, 0)) != 0)
goto error;
@ -1097,6 +1097,7 @@ dBputc(int x)
return Bputc(&bout, x);
}
/* XXX */
char*
expand_addr(char* a)
{

View file

@ -157,7 +157,7 @@ main(int argc, char **argv)
if(debug){
close(2);
snprint(buf, sizeof(buf), "%s/smtpd", UPASLOG);
snprint(buf, sizeof(buf), "%s/smtpd.db", UPASLOG);
if (open(buf, OWRITE) >= 0) {
seek(2, 0, 2);
fprint(2, "%d smtpd %s\n", getpid(), thedate());
@ -1221,6 +1221,16 @@ data(void)
}
reply("%d mail process terminated abnormally\r\n", code);
} else {
/*
* if a message appeared on stderr, despite good status,
* log it. this can happen if rewrite.in contains a bad
* r.e., for example.
*/
if(*s_to_c(err))
syslog(0, "smtpd",
"%s returned good status, but said: %s",
s_to_c(mailer), s_to_c(err));
if(filterstate == BLOCKED)
reply("554 we believe this is spam. we don't accept it.\r\n");
else

View file

@ -62,7 +62,7 @@ findkey(char *val, Keyword *p)
char*
actstr(int a)
{
char buf[32];
static char buf[32];
Keyword *p;
for(p=actions; p->name; p++)
@ -84,7 +84,8 @@ getaction(char *s, char *type)
return ACCEPT;
for(k = actions; k->name != 0; k++){
snprint(buf, sizeof buf, "/mail/ratify/%s/%s/%s", k->name, type, s);
snprint(buf, sizeof buf, "%s/mail/ratify/%s/%s/%s",
get9root(), k->name, type, s);
if(access(buf,0) >= 0)
return k->code;
}
@ -99,7 +100,7 @@ istrusted(char *s)
if(s == nil || *s == 0)
return 0;
snprint(buf, sizeof buf, "/mail/ratify/trusted/%s", s);
snprint(buf, sizeof buf, "%s/mail/ratify/trusted/%s", get9root(), s);
return access(buf,0) >= 0;
}
@ -167,6 +168,7 @@ getconf(void)
sysclose(bp);
}
#if 0
/*
* match a user name. the only meta-char is '*' which matches all
* characters. we only allow it as "*", which matches anything or
@ -186,6 +188,7 @@ usermatch(char *pathuser, char *specuser)
}
return strcmp(pathuser, specuser);
}
#endif
static int
dommatch(char *pathdom, char *specdom)
@ -493,7 +496,7 @@ dumpfile(char *sender)
return "/dev/null";
}
char *validator = "/mail/lib/validateaddress";
char *validator = "#9/mail/lib/validateaddress";
int
recipok(char *user)
@ -504,7 +507,12 @@ recipok(char *user)
Biobuf *bp;
int pid;
Waitmsg *w;
static int beenhere;
if(!beenhere){
beenhere++;
validator = unsharp(validator);
}
if(shellchars(user)){
syslog(0, "smtpd", "shellchars in user name");
return 0;
@ -522,9 +530,7 @@ recipok(char *user)
if(w->pid != pid)
continue;
if(w->msg[0] != 0){
/*
syslog(0, "smtpd", "validateaddress %s: %s", user, w->msg);
*/
return 0;
}
break;
@ -581,7 +587,7 @@ optoutofspamfilter(char *addr)
rv = 0;
f = smprint("/mail/box/%s/nospamfiltering", p);
f = smprint("%s/mail/box/%s/nospamfiltering", get9root(), p);
if(f != nil){
rv = access(f, 0)==0;
free(f);