Thanks to John Cummings.
This commit is contained in:
parent
cd37451963
commit
5cdb17983a
94 changed files with 26853 additions and 0 deletions
1001
src/cmd/upas/common/libsys.c
Normal file
1001
src/cmd/upas/common/libsys.c
Normal file
File diff suppressed because it is too large
Load diff
57
src/cmd/upas/common/mail.c
Normal file
57
src/cmd/upas/common/mail.c
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
#include "common.h"
|
||||
|
||||
/* format of REMOTE FROM lines */
|
||||
char *REMFROMRE =
|
||||
"^>?From[ \t]+((\".*\")?[^\" \t]+?(\".*\")?[^\" \t]+?)[ \t]+(.+)[ \t]+remote[ \t]+from[ \t]+(.*)\n$";
|
||||
int REMSENDERMATCH = 1;
|
||||
int REMDATEMATCH = 4;
|
||||
int REMSYSMATCH = 5;
|
||||
|
||||
/* format of LOCAL FROM lines */
|
||||
char *FROMRE =
|
||||
"^>?From[ \t]+((\".*\")?[^\" \t]+?(\".*\")?[^\" \t]+?)[ \t]+(.+)\n$";
|
||||
int SENDERMATCH = 1;
|
||||
int DATEMATCH = 4;
|
||||
|
||||
/* output a unix style local header */
|
||||
int
|
||||
print_header(Biobuf *fp, char *sender, char *date)
|
||||
{
|
||||
return Bprint(fp, "From %s %s\n", sender, date);
|
||||
}
|
||||
|
||||
/* output a unix style remote header */
|
||||
int
|
||||
print_remote_header(Biobuf *fp, char *sender, char *date, char *system)
|
||||
{
|
||||
return Bprint(fp, "From %s %s remote from %s\n", sender, date, system);
|
||||
}
|
||||
|
||||
/* parse a mailbox style header */
|
||||
int
|
||||
parse_header(char *line, String *sender, String *date)
|
||||
{
|
||||
if (!IS_HEADER(line))
|
||||
return -1;
|
||||
line += sizeof("From ") - 1;
|
||||
s_restart(sender);
|
||||
while(*line==' '||*line=='\t')
|
||||
line++;
|
||||
if(*line == '"'){
|
||||
s_putc(sender, *line++);
|
||||
while(*line && *line != '"')
|
||||
s_putc(sender, *line++);
|
||||
s_putc(sender, *line++);
|
||||
} else {
|
||||
while(*line && *line != ' ' && *line != '\t')
|
||||
s_putc(sender, *line++);
|
||||
}
|
||||
s_terminate(sender);
|
||||
s_restart(date);
|
||||
while(*line==' '||*line=='\t')
|
||||
line++;
|
||||
while(*line)
|
||||
s_putc(date, *line++);
|
||||
s_terminate(date);
|
||||
return 0;
|
||||
}
|
||||
18
src/cmd/upas/common/makefile
Normal file
18
src/cmd/upas/common/makefile
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
CFLAGS=${UNIX} -g -I. -I../libc -I../common -I/usr/include ${SCFLAGS}
|
||||
OBJS=mail.o aux.o string.o ${SYSOBJ}
|
||||
AR=ar
|
||||
.c.o: ; ${CC} -c ${CFLAGS} $*.c
|
||||
|
||||
common.a: ${OBJS}
|
||||
${AR} cr common.a ${OBJS}
|
||||
-ranlib common.a
|
||||
|
||||
aux.o: aux.h string.h mail.h
|
||||
string.o: string.h mail.h
|
||||
mail.o: mail.h
|
||||
syslog.o: sys.h
|
||||
mail.h: sys.h
|
||||
|
||||
clean:
|
||||
-rm -f *.[oO] core a.out *.a *.sL common.a
|
||||
|
||||
20
src/cmd/upas/common/mkfile
Normal file
20
src/cmd/upas/common/mkfile
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<$PLAN9/src/mkhdr
|
||||
|
||||
LIB=libcommon.a
|
||||
|
||||
OFILES=aux.$O\
|
||||
become.$O\
|
||||
mail.$O\
|
||||
process.$O\
|
||||
libsys.$O\
|
||||
config.$O\
|
||||
appendfiletombox.$O\
|
||||
|
||||
HFILES=common.h\
|
||||
sys.h\
|
||||
|
||||
<$PLAN9/src/mklib
|
||||
|
||||
nuke:V:
|
||||
mk clean
|
||||
rm -f libcommon.a
|
||||
175
src/cmd/upas/common/process.c
Normal file
175
src/cmd/upas/common/process.c
Normal file
|
|
@ -0,0 +1,175 @@
|
|||
#include "common.h"
|
||||
|
||||
/* make a stream to a child process */
|
||||
extern stream *
|
||||
instream(void)
|
||||
{
|
||||
stream *rv;
|
||||
int pfd[2];
|
||||
|
||||
if ((rv = (stream *)malloc(sizeof(stream))) == 0)
|
||||
return 0;
|
||||
memset(rv, 0, sizeof(stream));
|
||||
if (pipe(pfd) < 0)
|
||||
return 0;
|
||||
if(Binit(&rv->bb, pfd[1], OWRITE) < 0){
|
||||
close(pfd[0]);
|
||||
close(pfd[1]);
|
||||
return 0;
|
||||
}
|
||||
rv->fp = &rv->bb;
|
||||
rv->fd = pfd[0];
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* make a stream from a child process */
|
||||
extern stream *
|
||||
outstream(void)
|
||||
{
|
||||
stream *rv;
|
||||
int pfd[2];
|
||||
|
||||
if ((rv = (stream *)malloc(sizeof(stream))) == 0)
|
||||
return 0;
|
||||
memset(rv, 0, sizeof(stream));
|
||||
if (pipe(pfd) < 0)
|
||||
return 0;
|
||||
if (Binit(&rv->bb, pfd[0], OREAD) < 0){
|
||||
close(pfd[0]);
|
||||
close(pfd[1]);
|
||||
return 0;
|
||||
}
|
||||
rv->fp = &rv->bb;
|
||||
rv->fd = pfd[1];
|
||||
return rv;
|
||||
}
|
||||
|
||||
extern void
|
||||
stream_free(stream *sp)
|
||||
{
|
||||
int fd;
|
||||
|
||||
close(sp->fd);
|
||||
fd = Bfildes(sp->fp);
|
||||
Bterm(sp->fp);
|
||||
close(fd);
|
||||
free((char *)sp);
|
||||
}
|
||||
|
||||
/* start a new process */
|
||||
extern process *
|
||||
noshell_proc_start(char **av, stream *inp, stream *outp, stream *errp, int newpg, char *who)
|
||||
{
|
||||
process *pp;
|
||||
int i, n;
|
||||
|
||||
if ((pp = (process *)malloc(sizeof(process))) == 0) {
|
||||
if (inp != 0)
|
||||
stream_free(inp);
|
||||
if (outp != 0)
|
||||
stream_free(outp);
|
||||
if (errp != 0)
|
||||
stream_free(errp);
|
||||
return 0;
|
||||
}
|
||||
pp->std[0] = inp;
|
||||
pp->std[1] = outp;
|
||||
pp->std[2] = errp;
|
||||
switch (pp->pid = fork()) {
|
||||
case -1:
|
||||
proc_free(pp);
|
||||
return 0;
|
||||
case 0:
|
||||
if(newpg)
|
||||
sysdetach();
|
||||
for (i=0; i<3; i++)
|
||||
if (pp->std[i] != 0){
|
||||
close(Bfildes(pp->std[i]->fp));
|
||||
while(pp->std[i]->fd < 3)
|
||||
pp->std[i]->fd = dup(pp->std[i]->fd, -1);
|
||||
}
|
||||
for (i=0; i<3; i++)
|
||||
if (pp->std[i] != 0)
|
||||
dup(pp->std[i]->fd, i);
|
||||
for (n = sysfiles(); i < n; i++)
|
||||
close(i);
|
||||
if(who) {
|
||||
fprint(2,"process.c: trying to become(%s,%s)\n",av,who);
|
||||
// jpc become(av, who);
|
||||
}
|
||||
exec(av[0], av);
|
||||
perror("proc_start");
|
||||
exits("proc_start");
|
||||
default:
|
||||
for (i=0; i<3; i++)
|
||||
if (pp->std[i] != 0) {
|
||||
close(pp->std[i]->fd);
|
||||
pp->std[i]->fd = -1;
|
||||
}
|
||||
return pp;
|
||||
}
|
||||
}
|
||||
|
||||
/* start a new process under a shell */
|
||||
extern process *
|
||||
proc_start(char *cmd, stream *inp, stream *outp, stream *errp, int newpg, char *who)
|
||||
{
|
||||
char *av[4];
|
||||
|
||||
av[0] = unsharp(SHELL);
|
||||
av[1] = "-c";
|
||||
av[2] = cmd;
|
||||
av[3] = 0;
|
||||
return noshell_proc_start(av, inp, outp, errp, newpg, who);
|
||||
}
|
||||
|
||||
/* wait for a process to stop */
|
||||
extern int
|
||||
proc_wait(process *pp)
|
||||
{
|
||||
Waitmsg *status;
|
||||
char err[Errlen];
|
||||
|
||||
for(;;){
|
||||
status = wait();
|
||||
if(status == nil){
|
||||
errstr(err, sizeof(err));
|
||||
if(strstr(err, "interrupt") == 0)
|
||||
break;
|
||||
}
|
||||
if (status->pid==pp->pid)
|
||||
break;
|
||||
}
|
||||
pp->pid = -1;
|
||||
if(status == nil)
|
||||
pp->status = -1;
|
||||
else
|
||||
pp->status = status->msg[0];
|
||||
pp->waitmsg = status;
|
||||
return pp->status;
|
||||
}
|
||||
|
||||
/* free a process */
|
||||
extern int
|
||||
proc_free(process *pp)
|
||||
{
|
||||
int i;
|
||||
|
||||
if(pp->std[1] == pp->std[2])
|
||||
pp->std[2] = 0; /* avoid freeing it twice */
|
||||
for (i = 0; i < 3; i++)
|
||||
if (pp->std[i])
|
||||
stream_free(pp->std[i]);
|
||||
if (pp->pid >= 0)
|
||||
proc_wait(pp);
|
||||
free(pp->waitmsg);
|
||||
free((char *)pp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* kill a process */
|
||||
extern int
|
||||
proc_kill(process *pp)
|
||||
{
|
||||
return syskill(pp->pid);
|
||||
}
|
||||
85
src/cmd/upas/common/sys.h
Normal file
85
src/cmd/upas/common/sys.h
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* System dependent header files for research
|
||||
*/
|
||||
|
||||
#include <u.h>
|
||||
#include <libc.h>
|
||||
#include <regexp.h>
|
||||
#include <bio.h>
|
||||
#include "libString.h" /* jpc String.h -> libString.h */
|
||||
|
||||
/*
|
||||
* for the lock routines in libsys.c
|
||||
*/
|
||||
typedef struct Mlock Mlock;
|
||||
struct Mlock {
|
||||
int fd;
|
||||
int pid;
|
||||
String *name;
|
||||
};
|
||||
|
||||
/*
|
||||
* from config.c
|
||||
*/
|
||||
extern char *MAILROOT; /* root of mail system */
|
||||
extern char *UPASLOG; /* log directory */
|
||||
extern char *UPASLIB; /* upas library directory */
|
||||
extern char *UPASBIN; /* upas binary directory */
|
||||
extern char *UPASTMP; /* temporary directory */
|
||||
extern char *SHELL; /* path name of shell */
|
||||
extern char *POST; /* path name of post server addresses */
|
||||
extern int MBOXMODE; /* default mailbox protection mode */
|
||||
|
||||
/*
|
||||
* files in libsys.c
|
||||
*/
|
||||
extern char *sysname_read(void);
|
||||
extern char *alt_sysname_read(void);
|
||||
extern char *domainname_read(void);
|
||||
extern char **sysnames_read(void);
|
||||
extern char *getlog(void);
|
||||
extern char *thedate(void);
|
||||
extern Biobuf *sysopen(char*, char*, ulong);
|
||||
extern int sysopentty(void);
|
||||
extern int sysclose(Biobuf*);
|
||||
extern int sysmkdir(char*, ulong);
|
||||
extern int syschgrp(char*, char*);
|
||||
extern Mlock *syslock(char *);
|
||||
extern void sysunlock(Mlock *);
|
||||
extern void syslockrefresh(Mlock *);
|
||||
extern int e_nonexistent(void);
|
||||
extern int e_locked(void);
|
||||
extern long sysfilelen(Biobuf*);
|
||||
extern int sysremove(char*);
|
||||
extern int sysrename(char*, char*);
|
||||
extern int sysexist(char*);
|
||||
extern int sysisdir(char*);
|
||||
extern int syskill(int);
|
||||
extern int syskillpg(int);
|
||||
extern int syscreate(char*, int, ulong);
|
||||
extern Mlock *trylock(char *);
|
||||
extern void exit9(int);
|
||||
extern void pipesig(int*);
|
||||
extern void pipesigoff(void);
|
||||
extern int holdon(void);
|
||||
extern void holdoff(int);
|
||||
extern int syscreatelocked(char*, int, int);
|
||||
extern int sysopenlocked(char*, int);
|
||||
extern int sysunlockfile(int);
|
||||
extern int sysfiles(void);
|
||||
extern int become(char**, char*);
|
||||
extern int sysdetach(void);
|
||||
extern int sysdirreadall(int, Dir**);
|
||||
extern String *username(String*);
|
||||
extern char* remoteaddr(int, char*);
|
||||
extern int creatembox(char*, char*);
|
||||
|
||||
extern String *readlock(String*);
|
||||
extern char *homedir(char*);
|
||||
extern String *mboxname(char*, String*);
|
||||
extern String *deadletter(String*);
|
||||
|
||||
/*
|
||||
* maximum size for a file path
|
||||
*/
|
||||
#define MAXPATHLEN 128
|
||||
Loading…
Add table
Add a link
Reference in a new issue