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

@ -39,10 +39,9 @@ main(int argc, char *argv[])
namefiles = ARGF();
break;
} ARGEND
if (chdir(unsharp(UPASLIB)) < 0) {
perror("translate(chdir):");
exit9(1);
}
if (chdir(UPASLIB) < 0)
sysfatal("aliasmail chdir %s: %r", UPASLIB);
/* get environmental info */
names = sysnames_read();

View file

@ -3,7 +3,7 @@
#include <bin.h>
#include <bio.h>
#include <regexp.h>
#include "/sys/src/libregexp/regcomp.h"
#include "../../../libregexp/regcomp.h"
#include "dfa.h"
void rdump(Reprog*);
@ -140,19 +140,19 @@ followempty(Deter *d, uchar *bits, int bol, int eol)
switch(i->type){
case RBRA:
case LBRA:
again |= add(i->next - d->p->firstinst, bits, k);
again |= add(i->u2.next - d->p->firstinst, bits, k);
break;
case OR:
again |= add(i->left - d->p->firstinst, bits, k);
again |= add(i->right - d->p->firstinst, bits, k);
again |= add(i->u2.left - d->p->firstinst, bits, k);
again |= add(i->u1.right - d->p->firstinst, bits, k);
break;
case BOL:
if(bol)
again |= add(i->next - d->p->firstinst, bits, k);
again |= add(i->u2.next - d->p->firstinst, bits, k);
break;
case EOL:
if(eol)
again |= add(i->next - d->p->firstinst, bits, k);
again |= add(i->u2.next - d->p->firstinst, bits, k);
break;
}
}
@ -209,27 +209,27 @@ transition(Deter *d, Reiset *s, Rune r, uint eol)
longjmp(d->kaboom, 1);
case RUNE:
if(r == i->r)
bits[i->next - inst0] = 1;
if(r == i->u1.r)
bits[i->u2.next - inst0] = 1;
break;
case ANY:
if(r != L'\n')
bits[i->next - inst0] = 1;
bits[i->u2.next - inst0] = 1;
break;
case ANYNL:
bits[i->next - inst0] = 1;
bits[i->u2.next - inst0] = 1;
break;
case NCCLASS:
if(r == L'\n')
break;
/* fall through */
case CCLASS:
ep = i->cp->end;
for(rp = i->cp->spans; rp < ep; rp += 2)
ep = i->u1.cp->end;
for(rp = i->u1.cp->spans; rp < ep; rp += 2)
if(rp[0] <= r && r <= rp[1])
break;
if((rp < ep) ^! (i->type == CCLASS))
bits[i->next - inst0] = 1;
bits[i->u2.next - inst0] = 1;
break;
case END:
break;
@ -290,9 +290,9 @@ findchars(Deter *d, Reprog *p)
set(d, tab, L'\n'+1);
break;
case RUNE:
set(d, tab, i->r-1);
set(d, tab, i->r);
set(d, tab, i->r+1);
set(d, tab, i->u1.r-1);
set(d, tab, i->u1.r);
set(d, tab, i->u1.r+1);
break;
case NCCLASS:
set(d, tab, L'\n'-1);
@ -300,8 +300,8 @@ findchars(Deter *d, Reprog *p)
set(d, tab, L'\n'+1);
/* fall through */
case CCLASS:
ep = i->cp->end;
for(rp = i->cp->spans; rp < ep; rp += 2){
ep = i->u1.cp->end;
for(rp = i->u1.cp->spans; rp < ep; rp += 2){
set(d, tab, rp[0]-1);
set(d, tab, rp[0]);
set(d, tab, rp[1]);

View file

@ -1,18 +1,18 @@
</$objtype/mkfile
<$PLAN9/src/mkhdr
TARG=addhash bayes msgtok
HFILES=
OFILES=
LIB=
BIN=/$objtype/bin/upas
</sys/src/cmd/mkmany
BIN=$BIN/upas
<$PLAN9/src/mkmany
# msg tokenizer
$O.regen: regcomp.$O dfa.$O
dfa.$O regcomp.$O regen.$O: dfa.h
/mail/lib/classify.re: $O.regen
$PLAN9/mail/lib/classify.re: $O.regen
if(~ $cputype $objtype)
$O.regen >x && cp x $target

View file

@ -13,7 +13,7 @@
void buildre(Dreprog*[3]);
int debug;
char *refile = "/mail/lib/classify.re";
char *refile = "#9/mail/lib/classify.re";
int maxtoklen = 20;
int trim(char*);
@ -35,6 +35,7 @@ main(int argc, char **argv)
char msg[1024+1];
char buf[1024];
refile = unsharp(refile);
buildre(re);
ARGBEGIN{
case 'D':

View file

@ -1,28 +0,0 @@
#include "common.h"
#include <auth.h>
#include <ndb.h>
/*
* become powerless user
*/
int
become(char **cmd, char *who)
{
int fd;
USED(cmd);
if(strcmp(who, "none") == 0) {
fd = open("#c/user", OWRITE);
if(fd < 0 || write(fd, "none", strlen("none")) < 0) {
werrstr("can't become none");
return -1;
}
close(fd);
// jpc if(newns("none", 0)) {
// jpc werrstr("can't set new namespace");
// jpc return -1;
// jpc }
}
return 0;
}

View file

@ -454,6 +454,7 @@ sysnames_read(void)
if(namev)
return namev;
/* XXX */
/* free(csgetvalue(0, "sys", alt_sysname_read(), "dom", &t)); jpc */
db = ndbopen(unsharp("#9/ndb/local"));
free(ndbgetvalue(db, &s, "sys", sysname(),"dom", &t));

View file

@ -1,11 +1,12 @@
#include "dat.h"
#include <thread.h>
#include "common.h"
void
usage(void)
{
fprint(2, "usage: %s recipient fromaddr-file mbox\n", argv0);
exits("usage");
threadexitsall("usage");
}
void

View file

@ -2,7 +2,7 @@
#include <libc.h>
#include <regexp.h>
#include <libsec.h>
#include <String.h>
#include <libString.h>
#include <bio.h>
#include "dat.h"
@ -188,8 +188,9 @@ readpatterns(char *path)
}
/* fuck, shit, bugger, damn */
void regerror(char*)
void regerror(char *err)
{
USED(err);
}
/*

View file

@ -1,21 +1,14 @@
</$objtype/mkfile
<$PLAN9/src/mkhdr
TARG=\
token\
list\
deliver\
LIB=../common/libcommon.a$O\
BIN=/$objtype/bin/upas
LIB=../common/libcommon.a
OFILES=readaddrs.$O
UPDATE=\
mkfile\
${TARG:%=%.c}\
pipeto.sample\
pipefrom.sample\
pipeto.sample-hold\
</sys/src/cmd/mkmany
BIN=$BIN/upas
<$PLAN9/src/mkmany
CFLAGS=$CFLAGS -I../common

View file

@ -1,7 +1,7 @@
#include <u.h>
#include <libc.h>
#include <libsec.h>
#include <String.h>
#include <libString.h>
#include "dat.h"
void

View file

@ -1,6 +1,8 @@
#include "common.h"
#include <ctype.h>
#define inline _inline
typedef struct Attach Attach;
typedef struct Alias Alias;
typedef struct Addr Addr;
@ -10,7 +12,7 @@ struct Attach {
Attach *next;
char *path;
char *type;
int tinline;
int inline;
Ctype *ctype;
};
@ -684,7 +686,7 @@ attachment(Attach *a, Biobuf *out)
if(strcmp(a->type, "text/plain") != 0)
Bprint(out, "Content-Type: %s\n", a->type);
if(a->tinline){
if(a->inline){
Bprint(out, "Content-Disposition: inline\n");
} else {
p = strrchr(a->path, '/');
@ -811,7 +813,7 @@ printinreplyto(Biobuf *out, char *dir)
}
Attach*
mkattach(char *file, char *type, int tinline)
mkattach(char *file, char *type, int inline)
{
Ctype *c;
Attach *a;
@ -829,7 +831,7 @@ mkattach(char *file, char *type, int tinline)
a->path = file;
a->next = nil;
a->type = type;
a->tinline = tinline;
a->inline = inline;
a->ctype = nil;
if(type != nil){
for(c = ctype; ; c++)
@ -1067,7 +1069,7 @@ sendmail(Addr *to, Addr *cc, int *pid, char *rcvr)
if(pipe(pfd) < 0)
fatal("%r");
switch(*pid = rfork(RFFDG|RFPROC)){ // jpc - removed |RFENVG|RFREND|
switch(*pid = fork()){
case -1:
fatal("%r");
break;
@ -1105,7 +1107,7 @@ sendmail(Addr *to, Addr *cc, int *pid, char *rcvr)
cmd = mboxpath("pipefrom", login, s_new(), 0);
exec(s_to_c(cmd), av);
exec(unsharp("#9/bin/myupassend"), av);
exec("myupassend", av);
exec(unsharp("#9/bin/upas/send"), av);
fatal("execing: %r");
break;
@ -1130,6 +1132,7 @@ pgpfilter(int *pid, int fd, int pgpflag)
v = av = emalloc(sizeof(char*)*8);
ac = 0;
v[ac++] = "pgp";
v[ac++] = "-fat"; /* operate as a filter, generate text */
if(pgpflag & PGPsign)
v[ac++] = "-s";
if(pgpflag & PGPencrypt)
@ -1148,8 +1151,10 @@ pgpfilter(int *pid, int fd, int pgpflag)
close(pfd[0]);
dup(fd, 1);
close(fd);
/* add newline to avoid confusing pgp output with 822 headers */
write(1, "\n", 1);
exec("/bin/upas/pgp", av);
exec("pgp", av);
fatal("execing: %r");
break;
default:
@ -1314,7 +1319,6 @@ readaliases(void)
Alias *a, **l, *first;
Addr *addr, **al;
String *file, *line, *token;
// jpc - static int already;
Sinstack *sp;
first = nil;
@ -1747,7 +1751,7 @@ readmimetypes(void)
mimetypes[0].ext = "";
}
b = Bopen(unsharp("#9/sys/lib/mimetype"), OREAD);
b = Bopen(unsharp("#9/lib/mimetype"), OREAD);
if(b == nil)
return;
for(;;){

View file

@ -1,4 +1,4 @@
#!/bin/rc
#!/usr/local/plan9/bin/rc
switch($#*){
case 0
exec upas/nedmail

View file

@ -2,24 +2,19 @@
RCFILES=mail.rc\
all:Q:
;
#
installall:Q: install
;
#
install:V:
cp mail.rc /rc/bin/mail
safeinstall:V:
cp mail.rc /rc/bin/mail
safeinstallall:V:
cp mail.rc /rc/bin/mail
install safeinstall safeinstallall:V:
cp mail.rc $PLAN9/bin/mail
clean:Q:
;
#
nuke:V:
rm /rc/bin/mail
rm $PLAN9/bin/mail
UPDATE=\
gone.fishing\

View file

@ -1,14 +0,0 @@
#!/bin/rc
switch($#*){
case 0
exec upas/edmail -m
}
switch($1){
case -F* -m* -f* -r* -p* -e* -c* -D*
exec upas/edmail -m $*
case '-#'* -a*
exec upas/sendmail $*
case *
exec upas/sendmail $*
}

View file

@ -1,6 +1,6 @@
#!/bin/rc
#!/usr/local/plan9/bin/rc
sender=$1
shift
addr=$1
shift
qer /mail/queue mail $sender $addr $* && runq /mail/queue /mail/lib/remotemail
qer $PLAN9/mail/queue mail $sender $addr $* && runq $PLAN9/mail/queue $PLAN9/mail/lib/remotemail

View file

@ -1,7 +1,7 @@
#!/bin/rc
#!/usr/local/plan9/bin/rc
shift
sender=$1
shift
addr=$1
shift
/bin/upas/smtp -g research.research.bell-labs.com $addr $sender $*
upas/smtp -g yourgateway $addr $sender $*

View file

@ -2,8 +2,8 @@
pOsTmAsTeR alias postmaster
# local mail
[^!@]+ translate "/bin/upas/aliasmail '&'"
local!(.*) >> /mail/box/\1/mbox
[^!@]+ translate "upas/aliasmail '&'"
local!(.*) >> $PLAN9/mail/box/\1/mbox
\l!(.*) alias \1
(helix|helix.bell-labs.com)!(.*) alias \2
@ -17,4 +17,4 @@ local!(.*) >> /mail/box/\1/mbox
([^@]+)@([^@]+) alias \2!\1
# /mail/lib/remotemail will take care of gating to systems we don't know
([^!]*)!(.*) | "/mail/lib/qmail '\s' 'net!\1'" "'\2'"
([^!]*)!(.*) | "$PLAN9/mail/lib/qmail '\s' 'net!\1'" "'\2'"

View file

@ -1,4 +1,4 @@
</$objtype/mkfile
<$PLAN9/src/mkhdr
TARG=ml\
mlowner\
@ -16,25 +16,17 @@ UHFILES= ../common/common.h\
HFILES=$UHFILES\
../smtp/y.tab.h\
LIB=../common/libcommon.a$O\
LIB=../common/libcommon.a
BIN=/$objtype/bin/upas
UPDATE=\
mkfile\
$UHFILES\
${TARG:%=%.c}\
${OFILES:%.$O=%.c}\
../smtp/rfc822.y\
</sys/src/cmd/mkmany
BIN=$BIN/upas
<$PLAN9/src/mkmany
CFLAGS=$CFLAGS -I../common
$O.ml: ../smtp/rfc822.tab.$O
$O.mlowner: ../smtp/rfc822.tab.$O
../smtp/y.tab.h ../smtp/rfc822.tab.$O:
@{
(
cd ../smtp
mk rfc822.tab.$O
}
)

View file

@ -35,7 +35,7 @@ main(int argc, char **argv)
break;
}ARGEND;
rfork(RFENVG|RFREND);
rfork(RFENVG);
if(argc < 2)
usage();

View file

@ -21,7 +21,7 @@ main(int argc, char **argv)
char *listname, *addr;
String *owner, *alfile;
rfork(RFENVG|RFREND);
rfork(RFENVG);
ARGBEGIN{
case 'c':

View file

@ -24,7 +24,7 @@ main(int argc, char **argv)
ARGBEGIN{
}ARGEND;
rfork(RFENVG|RFREND);
rfork(RFENVG);
if(argc < 2)
usage();

View file

@ -585,15 +585,15 @@ matchpat(Pattern *p, char *message, Resub *m)
if(c1 == spat->c1)
if(memcmp(s, spat->string, spat->len) == 0)
if(!isalt(message, spat->alt)){
m->sp = s;
m->ep = s + spat->len;
m->s.sp = s;
m->e.ep = s + spat->len;
return 1;
}
}
}
return 0;
}
m->sp = m->ep = 0;
m->s.sp = m->e.ep = 0;
if(regexec(p->pat, message, m, 1) == 0)
return 0;
if(isalt(message, p->alt))
@ -608,23 +608,23 @@ xprint(int fd, char *type, Resub *m)
char *p, *q;
int i;
if(m->sp == 0 || m->ep == 0)
if(m->s.sp == 0 || m->e.ep == 0)
return;
/* back up approx 30 characters to whitespace */
for(p = m->sp, i = 0; *p && i < 30; i++, p--)
for(p = m->s.sp, i = 0; *p && i < 30; i++, p--)
;
while(*p && *p != ' ')
p--;
p++;
/* grab about 30 more chars beyond the end of the match */
for(q = m->ep, i = 0; *q && i < 30; i++, q++)
for(q = m->e.ep, i = 0; *q && i < 30; i++, q++)
;
while(*q && *q != ' ')
q++;
fprint(fd, "%s %.*s~%.*s~%.*s\n", type, (int)(m->sp-p), p, (int)(m->ep-m->sp), m->sp, (int)(q-m->ep), m->ep);
fprint(fd, "%s %.*s~%.*s~%.*s\n", type, (int)(m->s.sp-p), p, (int)(m->e.ep-m->s.sp), m->s.sp, (int)(q-m->e.ep), m->e.ep);
}
enum {

View file

@ -1,4 +1,4 @@
</$objtype/mkfile
<$PLAN9/src/mkhdr
TARG=scanmail\
testscan
@ -8,17 +8,11 @@ OFILES= common.$O
HFILES= spam.h\
../common/sys.h\
LIB= ../common/libcommon.a$O\
LIB= ../common/libcommon.a
BIN=/$objtype/bin/upas
UPDATE=\
mkfile\
$HFILES\
${OFILES:%.$O=%.c}\
${TARG:%=%.c}\
</sys/src/cmd/mkmany
BIN=$BIN/upas
<$PLAN9/src/mkmany
CFLAGS=$CFLAGS -I../common
scanmail.$O: scanmail.c
$CC $CFLAGS -D'SPOOL="/mail"' scanmail.c
$CC $CFLAGS -D'SPOOL="'$PLAN9'/mail"' scanmail.c

View file

@ -313,7 +313,7 @@ matcher(char *action, Pattern *p, char *message, Resub *m)
char *cp;
String *s;
for(cp = message; matchpat(p, cp, m); cp = m->ep){
for(cp = message; matchpat(p, cp, m); cp = m->e.ep){
switch(p->action){
case SaveLine:
if(vflag)
@ -340,12 +340,12 @@ matcher(char *action, Pattern *p, char *message, Resub *m)
case Dump:
if(vflag)
xprint(2, action, m);
*(m->ep) = 0;
*m->e.ep = 0;
if(!tflag){
s = s_new();
s_append(s, sender);
s = unescapespecial(s);
syslog(0, "smtpd", "Dumped %s [%s] to %s", s_to_c(s), m->sp,
syslog(0, "smtpd", "Dumped %s [%s] to %s", s_to_c(s), m->s.sp,
s_to_c(s_restart(recips)));
s_free(s);
}
@ -367,17 +367,17 @@ saveline(char *file, char *sender, Resub *rp)
int i, c;
Biobuf *bp;
if(rp->sp == 0 || rp->ep == 0)
if(rp->s.sp == 0 || rp->e.ep == 0)
return;
/* back up approx 20 characters to whitespace */
for(p = rp->sp, i = 0; *p && i < 20; i++, p--)
for(p = rp->s.sp, i = 0; *p && i < 20; i++, p--)
;
while(*p && *p != ' ')
p--;
p++;
/* grab about 20 more chars beyond the end of the match */
for(q = rp->ep, i = 0; *q && i < 20; i++, q++)
for(q = rp->e.ep, i = 0; *q && i < 20; i++, q++)
;
while(*q && *q != ' ')
q++;

View file

@ -191,11 +191,11 @@ matchaction(Patterns *pp, char *message)
p = pp->strings;
ret = 0;
if(p)
for(cp = message; matcher(name, p, cp, m); cp = m[0].ep)
for(cp = message; matcher(name, p, cp, m); cp = m[0].e.ep)
ret++;
for(p = pp->regexps; p; p = p->next)
for(cp = message; matcher(name, p, cp, m); cp = m[0].ep)
for(cp = message; matcher(name, p, cp, m); cp = m[0].e.ep)
ret++;
return ret;
}

View file

@ -143,7 +143,7 @@ getstring(Node *p)
return s;
}
#if 0 /* jpc */
#if 0
static char *fieldname[] =
{
[WORD-WORD] "WORD",
@ -172,7 +172,7 @@ static char *fieldname[] =
[MAILER-WORD] "MAILER",
[BADTOKEN-WORD] "BADTOKEN",
};
#endif /* jpc */
#endif
/* fix 822 addresses */
static void

View file

@ -21,22 +21,13 @@ SMOBJ=main.$O\
gateway.$O\
cat_mail.$O\
LIB=../common/libcommon.av\
HFILES=send.h\
../common/common.h\
../common/sys.h\
LIB=../common/libcommon.a\
BIN=$PLAN9/bin/upas
UPDATE=\
mkfile\
$HFILES\
${UOFILES:%.$O=%.c}\
${SMOBJ:%.$O=%.c}\
${TARG:%=%.c}\
LIB=../common/libcommon.a
BIN=$BIN/upas
<$PLAN9/src/mkmany
CFLAGS=$CFLAGS -I../common
@ -46,7 +37,6 @@ $O.send: $SMOBJ $OFILES
message.$O: ../smtp/y.tab.h
../smtp/y.tab.h ../smtp/rfc822.tab.$O: ../smtp/rfc822.y
# @{
cd ../smtp
mk rfc822.tab.$O
# }

View file

@ -131,7 +131,7 @@ getrules(void)
String *type;
String *file;
file = abspath("rewrite", unsharp(UPASLIB), (String *)0);
file = abspath("rewrite", UPASLIB, (String *)0);
rfp = sysopen(s_to_c(file), "r", 0);
if(rfp == 0) {
rulep = 0;
@ -168,7 +168,7 @@ findrule(String *addrp, int authorized)
continue;
memset(rp->subexp, 0, sizeof(rp->subexp));
if(debug)
print("matching %s aginst %s\n", s_to_c(addrp), rp->matchre->base);
fprint(2, "matching %s aginst %s\n", s_to_c(addrp), rp->matchre->base);
if(regexec(rp->program, s_to_c(addrp), rp->subexp, NSUBEXP))
if(s_to_c(addrp) == rp->subexp[0].s.sp)
if((s_to_c(addrp) + strlen(s_to_c(addrp))) == rp->subexp[0].e.ep)
@ -203,17 +203,45 @@ rewrite(dest *dp, message *mp)
dp->repl2 = substitute(rp->repl2, rp->subexp, mp);
dp->status = rp->type;
if(debug){
print("\t->");
fprint(2, "\t->");
if(dp->repl1)
print("%s", s_to_c(dp->repl1));
fprint(2, "%s", s_to_c(dp->repl1));
if(dp->repl2)
print("%s", s_to_c(dp->repl2));
print("\n");
fprint(2, "%s", s_to_c(dp->repl2));
fprint(2, "\n");
}
s_free(lower);
return 0;
}
/* stolen from rc/lex.c */
static int
idchr(int c)
{
return c>' ' && !strchr("!\"#$%&'()+,-./:;<=>?@[\\]^`{|}~", c);
}
static char*
getrcvar(char* p, char** rv)
{
char* p0;
char buf[128];
char* bufe;
*rv = 0;
p0=p;
bufe=buf+sizeof buf-1;
while(p<bufe && idchr(*p))
p++;
memcpy(buf, p0, p-p0);
buf[p-p0]=0;
*rv = getenv(buf);
if (debug)
fprint(2, "varsubst: %s → %s\n", buf, *rv);
return p;
}
static String *
substitute(String *source, Resub *subexp, message *mp)
{
@ -269,6 +297,10 @@ substitute(String *source, Resub *subexp, message *mp)
for (s = subexp[0].s.sp;
s < subexp[0].e.ep; s++)
s_putc(stp, *s);
} else if(*sp == '$') {
sp = getrcvar(sp+1, &s);
s_append(stp, s);
free(s);
} else
s_putc(stp, *sp);
sp++;

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);
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);

View file

@ -1,17 +1,7 @@
</$objtype/mkfile
<$PLAN9/src/mkhdr
TARG=unesc
OFILES=unesc.$O
OFILES=unesc.$O\
BIN=/$objtype/bin/upas
CC=pcc -c
CFLAGS=-B
UPDATE=\
mkfile\
$HFILES\
${OFILES:%.$O=%.c}\
</sys/src/cmd/mkone
BIN=$BIN/upas
<$PLAN9/src/mkone

View file

@ -17,7 +17,7 @@ hex(int c)
return 0;
}
void
int
main(int argc, char **argv)
{
int c;

View file

@ -116,6 +116,13 @@ Mtype *mtypes;
int justreject;
char *savefile;
void
usage(void)
{
fprint(2, "usage: upas/vf [-r] [-s savefile]\n");
exits("usage");
}
void
main(int argc, char **argv)
{
@ -124,12 +131,15 @@ main(int argc, char **argv)
justreject = 1;
break;
case 's':
savefile = ARGF();
if(savefile == nil)
exits("usage");
savefile = EARGF(usage());
break;
default:
usage();
}ARGEND;
if(argc)
usage();
Binit(&in, 0, OREAD);
Binit(&out, 1, OWRITE);
@ -415,8 +425,7 @@ savetmp(Part *p)
}
/*
* XXX save the decoded file, run 9 unzip -tf on it, and then
* look at the file list.
* Run the external checker to do content-based checks.
*/
static int
runchecker(Part *p)
@ -483,19 +492,18 @@ problemchild(Part *p)
if(runchecker(p) > 0)
return p;
fprint(2, "x\n");
if(justreject)
return p;
syslog(0, "mail", "vf wrapped %s %s", p->type?s_to_c(p->type):"?",
p->filename?s_to_c(p->filename):"?");
fprint(2, "x\n");
boundary = mkboundary();
fprint(2, "x\n");
/* print out non-mime headers */
for(hl = p->hl; hl != nil; hl = hl->next)
if(cistrncmp(s_to_c(hl->s), "content-", 8) != 0)
Bprint(&out, "%s", s_to_c(hl->s));
fprint(2, "x\n");
/* add in our own multipart headers and message */
Bprint(&out, "Content-Type: multipart/mixed;\n");
Bprint(&out, "\tboundary=\"%s\"\n", s_to_c(boundary));
@ -539,11 +547,9 @@ fprint(2, "x\n");
break;
}
fprint(2, "z\n");
/* pass the body */
np = passbody(p, 0);
fprint(2, "w\n");
/* add the new boundary and the original terminator */
Bprint(&out, "--%s--\n", s_to_c(boundary));
if(np && np->boundary){
@ -551,7 +557,6 @@ fprint(2, "w\n");
Bwrite(&out, cp, Blinelen(&in));
}
fprint(2, "a %p\n", np);
return np;
}
@ -871,8 +876,6 @@ badfile(char *name)
return 2;
}
}
if(justreject)
return 0;
return 1;
}
@ -887,9 +890,6 @@ badtype(char *type)
char *s, *fix;
int rv = 1;
if(justreject)
return 0;
fix = s = strchr(type, '/');
if(s != nil)
*s++ = 0;