The daemon program that runs the network.
netdaemon -m mach [-r readfd] [-w writefd] [-d] [-h]
-m mach remote machine is mach (required)
-r num if simulute w/pipes, read from num
-w num if simulate w/pipes, write on num
-h use high-speed link (not implemented yet)
-ou num only send things with uid = num
/* take a time, adjust to be in PST, and divide by no of secs in a day */
/* adjust by 10 mins, and day is considered to begin at 3AM */
/* 6*3600 = 21600 +17400 = 39000 */
/* number of seconds in a day, usually 86400L */
/* number of days since time began */
# define numdays(S) ((S - 39000L)/nsecday)
/* set my priority to normal */
# define RENICE (nice(-40), nice(20), nice(0))
/* static char sheader[] = "ABCDE"; */
static char tempfile
[]= TEMPFILE
;
static char publogfile
[]= PUBLOGFILE
;
static struct stat statbuf
;
static struct direct dirbuf
;
signal(SIGTERM
,handlekill
);
/* now running alone as a daemon */
for(i=0; i<15; i++)close(i);
senddir
[strlen(senddir
)-1] = remote
; /* choose dir */
dir
= fopen(senddir
,"r");
tempfile
[strlen(tempfile
) - 7] = remote
;
fprintf(stderr
,"The network says 'The clock is set wrong.'\n");
sprintf(buf
,"net restarted to %s %d %s",longname(remote
),
dump
.lastndays
= numdays(ltime
);
if(!debugflg
)fclose(stderr
);
/* the main loop of the daemon, alternatively rcv then send, if poss.*/
for(;;){ /* begin reading file */
debug("daemon %c %d\n",remote
,getpid());
if(netd
.dp_sndorcv
>= 0){ /* if we can receive */
if(i
== -1)dump
.nabnormal
++;
if(netd
.dp_sndorcv
<= 0) /* if we can send */
/* print out statistics if the right time */
/* this code is a little strange because some machines
seem to have trouble having the date set, and time()
returns 0 until somebody remembers to set the date */
long thisndays
, thistime
;
thisndays
= numdays(thistime
);
dump
.longtime
= thistime
;
dump
.lastndays
= thisndays
;
if(thisndays
== dump
.lastndays
+ 1L) dumpit(thistime
);
dump
.lastndays
= thisndays
;
/* look for files to send */
static long lasttime
= 0;
register int uid
,uidBest
;
if(stat(senddir
,&statbuf
) < 0){
error("%s %s",senddir
,sys_errlist
[errno
]);
if(statbuf
.st_mtime
== lasttime
&& nleft
== 0)return; /* no need to search */
lasttime
= statbuf
.st_mtime
;
while(fread(&dirbuf
,1,sizeof dirbuf
,dir
) == sizeof dirbuf
){
|| dirbuf
.d_name
[0] != 'c'
|| dirbuf
.d_name
[1] != 'f'
|| dirbuf
.d_name
[2] != remote
|| stat(dirbuf
.d_name
,&statbuf
) < 0
if(stat(dirbuf
.d_name
,&statbuf
) < 0 || statbuf
.st_mode
== 0)
uid
= guid(statbuf
.st_uid
,statbuf
.st_gid
);
if(netd
.dp_onlyuid
!= 0 && uid
!= netd
.dp_onlyuid
&& uid
!= SUPERUSER
filesize
= getsize(&statbuf
);
jname
[i
] = dirbuf
.d_name
[i
];
if(nleft
> MAXSENDQ
)break;
if(lFileLen
== 10000000L)return;
addtolog(remote
,"Unknown userid %d\n",uidBest
);
addtolog(remote
,"^S %s %c: %s ",sn
,remote
,jname
+2);
if(send(jname
) == 0)return;
filesize
= getsize(&statbuf
);
if(diff
< 1)diff
= 1; /* avoid dividing by zero */
sdate
[strlen(sdate
) -9] = 0;
swait
= comptime(ot
- statbuf
.st_mtime
);
drate
= (double)filesize
/ (double)diff
;
addtolog(remote
,"^T%c(%s, %ldb, %ldsec, %4.1fb/sec, w %s)\n",
remote
,sdate
,filesize
, diff
,drate
, swait
);
addtolog(remote
,"^T%c(%s, %ldb, %ldsec, w %s)\n",
remote
,sdate
,filesize
, diff
,swait
);
addtopublic("%s: sent %-8s to %s (%s, %ld b, wait %s)\n",
sdate
,sn
,longname(remote
),jname
+3,filesize
,swait
);
dump
.bytetot
+= filesize
;
/* returns 0 if send fails, 1 otherwise */
char mbuf
[20], buf
[MAXNBUF
];
if(stat(jname
,&statbuf
) < 0)goto sfail
;
lsize
= getsize(&statbuf
);
if(lsize
< MINSIZE
){ /* all files are at least this long */
jfile
= fopen(jname
,"r");
if(jfile
== NULL
)goto sfail
;
lsize = fixuplong(lsize);
sprintf(mbuf
,"|%08ld|",lsize
);
if(xwrite(mbuf
,i
) == WRITEFAIL
)goto bwrite
;
while((n
=read(fileno(jfile
),buf
,MAXNBUF
)) > 0)
if(xwrite(buf
,n
) == WRITEFAIL
)goto bwrite
;
addtolog(remote
,"^F%c\n",remote
);
error("%s: %s",jname
,sys_errlist
[errno
]);
/* returns -2 in normal fail, -1 in abnormal fail, >= 0 otherwise */
long otime
,olength
,diff
,rcvfinish
,nt
;
char hbuf
[20], buf
[MAXNBUF
];
n = nread(hbuf,strlen(sheader));
if(n == BROKENREAD)return(-2);
if(n != strlen(sheader) || strcmp(sheader,hbuf) != 0){
error("wrong head %d %s",n,hbuf);
length = fixuplong(length);
if(n
== BROKENREAD
)return(-2);
error("bad length nread %d",n
);
if(hbuf
[0] != '|' || hbuf
[9] != '|'){
error("poor format %s",hbuf
);
if(length
< 0 || length
> 100000000L){
error("bad length %ld",length
);
debug("length = %ld\n",length
);
from local to remote (requests)
y -y simply skips login check (used by netlpr)
w -w message to be written/mailed back
if(i
== -3)goto forw
; /* being forwarded thru us */
strcpy(status
.login
, hd
.hd_snto
);
strcpy(status
.localname
,hd
.hd_snfrom
);
while(*s
&& *s
!= ' ')s
++;
if(strcmp(hd
.hd_scmdvirt
,"netlpr") == 0)dump
.nnetlpr
++;
else if(strcmp(hd
.hd_scmdvirt
,"netmail") == 0)dump
.nnetmail
++;
else if(strcmp(hd
.hd_scmdvirt
,"mail") == 0)dump
.nsmail
++;
else if(strcmp(hd
.hd_scmdvirt
,"netcp") == 0)dump
.nnetcp
++;
else if(strcmp(hd
.hd_scmdvirt
,"response") == 0)dump
.nresp
++;
/* any chars left are data */
if(length
> 0){ /* make a temp input file */
temp
= fopen(tempfile
,"w");
error("%s %s",tempfile
,sys_errlist
[errno
]);
if(hd
.hd_mchto
!= local
){
fprintf(temp
,"%c :%c :",hd
.hd_code
,hd
.hd_mchto
);
/* this is the loop to read in all the data */
while((n
= mread(buf
,MAXNBUF
)) > 0)
if(write(fileno(temp
),buf
,n
) != n
){
error("%s %s",tempfile
,sys_errlist
[errno
]);
if(n
== BROKENREAD
|| length
> 0){
if(hd
.hd_mchto
!= local
){
diff
= gettime() - otime
;
if(diff
< 1)diff
= 1; /* avoid dividing by 0 */
addtolog(remote
,"^P(to %c, %ldb, %ldsec, %4.1fb/sec)\n",
hd
.hd_mchto
,olength
,diff
,r
);
addtolog(remote
,"^P(to %c, %ldb, %ldsec)\n",
hd
.hd_mchto
,olength
,diff
);
while((pid
= fork()) == -1)sleep(2);
execl(netcmd
,"net","-x","-m",longname(hd
.hd_mchto
),
error("%s: %s",netcmd
,sys_errlist
[errno
]);
error("pass-thru rcode %d");
debug("passthru to %c code %c rcode %d",
hd
.hd_mchto
,hd
.hd_code
,rcode
);
if(length
> 0){error("file too short"); return(-1); }
while((pid
= fork()) == -1)sleep(2);
return(1); /* normal return */
while((pid
= fork()) == -1)sleep(2);
/* child process which forks and waits */
while((pid
= fork()) == -1)sleep(2);
strcpy(status
.loginshell
,Bsh
);
frommach
= hd
.hd_mchfrom
;
n
= check(&hd
,(hd
.hd_code
== 'q'));
if(!n
)errormsg(TRUE
,&hd
,NULL
,
"Bad remote login/password '%s'",hd
.hd_snto
);
temp
= fopen(resfile
,"w");
"Create file %s: %s",resfile
,sys_errlist
[errno
]);
mchown(resfile
,status
.muid
,status
.mgid
);
mchown(tempfile
,status
.muid
,status
.mgid
);
/* after this point our gid, uid is the target user's */
excmd(&hd
,resfile
,tempfile
);
rcode
= (((rcode
&077400) >>8) &0177);
now send something back to the sender
unless this was a response (file or message)
if((hd
.hd_code
== 'q' || hd
.hd_code
== 'y')
&& (hd
.hd_srespfile
[0] || !hd
.hd_fnonotify
))
diff
= rcvfinish
- otime
;
if(diff
< 1)diff
= 1; /* avoid dividing by zero */
sprintf(buf
,"%s rcv %c:%-8s (%s)",
s
,hd
.hd_mchfrom
,hd
.hd_snfrom
,hd
.hd_snto
);
addtolog(remote
,"%s C: %s\n",buf
,hd
.hd_scmdvirt
);
addtopublic("%s R: %d C: %s\n",buf
,rcode
,hd
.hd_scmdvirt
);
nt
= rcvfinish
- hd
.hd_ltimesent
;
if(nt
> 0L)sprintf(buf
," took (%s)",comptime(nt
));
addtolog(remote
,"\t\tR: %d%s %ldb %ldsec %4.1fb/sec\n",
rcode
,buf
,olength
,diff
,r
);
addtolog(remote
,"\t\t%4.1frb/sec %4.1f%% use\n",r
,(r
/linechars())*100L);
addtolog(remote
,"\t\tR: %d%s %ldb %ldsec\n",
if(netd
.dp_inspeed
== 13)return(960L);
execute the user's command
this procedure is executed with uid, gid of the user
excmd(phd
,tempresfile
,tempinfile
)
register struct header
*phd
;
char *tempresfile
, *tempinfile
;
status
.muid
= uidmask(status
.muid
);
if(uid
!= status
.muid
)error("setuid fails");
debug("uid: %u, gid: %u\n",uid
,status
.mgid
);
/* check for allowed root commands, for security reasons */
while(*s
&& *s
!= ' ')s
++;
/* these are the only commands root may execute */
if(strcmp(phd
->hd_scmdact
,"cat") != 0
&& strcmp(phd
->hd_scmdact
,"/bin/cat") != 0
&& strcmp(phd
->hd_scmdact
,MWRITECMD
) != 0
&& strcmp(phd
->hd_scmdact
,"netrm") != 0
&& strcmp(phd
->hd_scmdact
,"/usr/lib/tq") != 0
&& strcmp(phd
->hd_scmdact
,"/usr/lib/rtrrm") != 0
&& strcmp(phd
->hd_scmdact
,"lpr") != 0)
errormsg(TRUE
,phd
,tempresfile
,
"Not allowed to execute '%s' as root",
if(chdir(status
.dir
) < 0)
errormsg(TRUE
,phd
,tempresfile
,
"chdir %s: %s",status
.dir
,sys_errlist
[errno
]);
setenv(status
.dir
); /* set up v7 environment */
if(tempinfile
[0])mreopen(TRUE
,phd
,tempresfile
,tempinfile
,"r",stdin
);
else if(phd
->hd_sinfile
[0])mreopen(TRUE
,phd
,tempresfile
,phd
->hd_sinfile
,"r",stdin
);
else mreopen(TRUE
,phd
,tempresfile
,"/dev/null","r",stdin
);
if(phd
->hd_code
== 's' && phd
->hd_soutfile
[0]){
if(stat(phd
->hd_soutfile
,&statbuf
) < 0
|| getsize(&statbuf
) != 0)
errormsg(FALSE
,phd
,tempresfile
,"Bad result file '%s'",phd
->hd_soutfile
);
mreopen(TRUE
,phd
,tempresfile
,phd
->hd_soutfile
,"w",stdout
);
else if(phd
->hd_soutfile
[0]){
fd
= fopen(phd
->hd_soutfile
,"w");
errormsg(TRUE
,phd
,tempresfile
,"Open file %s: %s",
phd
->hd_soutfile
,sys_errlist
[errno
]);
mreopen(TRUE
,phd
,tempresfile
,phd
->hd_soutfile
,"w",stdout
);
else mreopen(TRUE
,phd
,tempresfile
,tempresfile
,"a",stdout
);
debug("exec '%s'\n",phd
->hd_scmdact
);
mreopen(TRUE,phd,tempresfile,tempresfile,"a",stderr);
for(i
=3;i
<15;i
++)close(i
);
if(strcmp(phd
->hd_scmdact
,"cat") == 0
|| strcmp(phd
->hd_scmdact
,"/bin/cat") == 0)excat();
mexecl(status
.loginshell
,"sh","-c",phd
->hd_scmdact
,0);
} while(errno
== ETXTBSY
);
perror(status
.loginshell
);
if errormsg was called the resfile should be unlinked,
to avoid two messages being sent there
char cmdstr
[BUFSIZ
], buf
[BUFSIZ
];
/* send response back if a response file
was given or if mail/write is allowed */
if(stat(resfile
,&statbuf
) < 0){
error("%s %s",resfile
,sys_errlist
[errno
]);
/* allow larger files between the Ingres machines */
if(machtype
[local
- 'a'] == M_INGRES
&& machtype
[remote
- 'a'] == M_INGRES
)
if(getsize(&statbuf
) >= maxfile
){
errormsg(TRUE
,phd
,"Result file too large - not sent");
if(getsize(&statbuf
) == 0){
/* response file specified, no output generated */
if(phd
->hd_srespfile
[0] != 0)return;
/* quiet option - no output and a rcode of 0 */
if(rcode
== 0 && phd
->hd_fquiet
)return;
/* use both old and new mwrite parm lists */
sprintf(cmdstr
,"-o %s cat",phd
->hd_srespfile
);
"%s -t %s -f %s -x %ld -c \"'%s'\" -y %s -e %ld -r %d",
MWRITECMD
, phd
->hd_addrfrom
, phd
->hd_addrto
, phd
->hd_lttytime
,
phd
->hd_scmdvirt
, phd
->hd_sttyname
, phd
->hd_ltimesent
-TIMEBASE
, rcode
);
sprintf(buf
,"%s -m%c -z -b -l %s -s %s -c response %s",
netcmd
,phd
->hd_mchfrom
,phd
->hd_snfrom
,resfile
,cmdstr
);
dummy
= system(buf
); /* execute command buf */
does nothing more than copy standard input to standard
output, like the cat command, but reports write errors.
Uses getc and putc rather than fwrite and fread because
the latter call getc and putc.
while((n
= read(0,buf
,BUFSIZ
)) > 0){
perror("filecat: stdout");
perror("filecat: stdin");
/* returns errors for netrcv() */
register struct header
*phd
;
char cflag
, sbuf
[BUFSIZ
], parmlist
[PARMLIST
];
if(code
!= 'q' && code
!= 'y' && code
!= 'w' && code
!= 's'){
if(phd
->hd_mchto
< 'a' || 'z' < phd
->hd_mchto
){
error("bad phd->hd_mchto");
if(phd
->hd_mchto
!= local
)return(-3); /* being forwarded through us */
phd
->hd_mchfrom
= mgetc();
phd
->hd_vmajor
= mgetc();
phd
->hd_vminor
= mgetc();
i
+= mgets(phd
->hd_snto
,NS
);
i
+= mgets(phd
->hd_spasswd
,20);
i
+= mgets(phd
->hd_sinfile
,FNS
);
i
+= mgets(phd
->hd_soutfile
,FNS
);
i
+= mgets(phd
->hd_srespfile
,FNS
);
i
+= mgets(phd
->hd_snfrom
,NS
);
/* addrfrom is the person who sent this to us,
addrto is the person who received the command, i.e.
addrto is on this machine */
if(phd
->hd_snfrom
[0] == 0)strcpy(phd
->hd_snfrom
,"root");
sprintf(phd
->hd_addrfrom
, "%s:%s",longname(phd
->hd_mchfrom
),phd
->hd_snfrom
);
sprintf(phd
->hd_addrto
, "%s:%s",longname(phd
->hd_mchto
),phd
->hd_snto
);
i
+= mgets(phd
->hd_sttyname
,20);
if(phd
->hd_sttyname
[0] == 0)strcpy(phd
->hd_sttyname
,"/dev/ttyx");
if(!phd
->hd_mchfrom
|| !phd
->hd_code
|| !cflag
|| !phd
->hd_vmajor
|| !phd
->hd_vminor
){
phd
->hd_fnonotify
= (cflag
& F_NONOTIFY
);
phd
->hd_fquiet
= (cflag
& F_QUIET
);
sscanf(sbuf
,"%lo",&phd
->hd_lttytime
);
i
+= mgets(parmlist
,PARMLIST
);
phd
->hd_ijobno
= atoi(parmlist
);
/* keep variable parameter list in jobno slot */
i
+= mgets(sbuf
,BUFSIZ
); /* time sent */
sscanf(sbuf
,"%ld",&phd
->hd_ltimesent
);
phd
->hd_ltimesent
+= TIMEBASE
;
i
+= mgetcmd(phd
->hd_scmdact
);
i
+= mgetcmd(phd
->hd_scmdvirt
);
if(i
!= 0){error("mgets fails"); return(-1);}
if(phd
->hd_scmdvirt
[0] == 0)strcpy(phd
->hd_scmdvirt
,phd
->hd_scmdact
);
check() -- verify login name and password
fverify = 1 if password must check
Returns 1 if password is ok, 0 if not.
check(phd
,fverify
) /* 1 if OK, 0 if not */
register struct header
*phd
;
char *sencpasswd
, *u
, *nullstr
= "";
if(phd
->hd_snto
[0] == 0)return(!fverify
);
if(!goodacctname(phd
->hd_snto
))return(!fverify
);
pwd
= getpwnam(phd
->hd_snto
);
if(pwd
== NULL
)return(!fverify
);
if(machtype
[local
-'a'] == M_CC
&& machtype
[frommach
-'a'] == M_CC
)
sencpasswd
= phd
->hd_spasswd
;
else if(*phd
->hd_spasswd
)sencpasswd
= crypt(phd
->hd_spasswd
,pwd
->pw_passwd
);
else sencpasswd
= nullstr
;
status
.muid
= guid(pwd
->pw_uid
,pwd
->pw_gid
);
status
.mgid
= pwd
->pw_gid
;
if(isdigit(pwd
->pw_gecos
[0]))status
.jobno
= atoi(pwd
->pw_gecos
);
else status
.jobno
= 32767;
strcpy(status
.dir
,pwd
->pw_dir
);
strcpy(status
.loginshell
,pwd
->pw_shell
);
if(u
[0] == 0 || strcmp("/bin/sbash",u
) == 0)strcpy(u
,Bsh
);
/* ignore network passwd */
/* acct is not a pair, acct is not "network", passwd is incorrect,
and verification is requested => passwd not ok */
if(!facctpaircheck(phd
) && strcmp(phd
->hd_snto
,"network") != 0
&& strcmp(pwd
->pw_passwd
,sencpasswd
) != 0 && fverify
)
return(1); /* otherwise passwd ok */
if(length
<= 0)return(0);
if(length
< n
)n
= length
;
if(n
!= BROKENREAD
)length
-= n
;
char mgetc(){ /* returns 0 if fail */
if((n
=nread(buf
,3)) == BROKENREAD
)return(0);
if(n
!= 3){error("bad read %d",n
); return(0); }
if(buf
[1] != ' ' && buf
[1] != ':'){error("Bad char %c",buf
[1]); return(0); }
if(length
< 0){error("length wrong2 %ld",length
); return(0); }
/* read in string over the network wire */
/* put string in s, max length is maxlen */
mgets(s
,maxlen
) /* returns 0 if ok, 1 if not */
if((n
=nread(&c
,1)) == BROKENREAD
){
if((n
=nread(&c
,1)) == BROKENREAD
){
if(maxlen
-- > 0) *s
++ = c
;
if(nread(&c
,1) == BROKENREAD
){
if(length
< 0){error("length wrong1 %ld %s",length
,q
); return(-1); }
error("mgets - string too long");
mgetcmd(s
) /* returns 0 if succeed, 1 otherwise */
if((n
=nread(&c
,1)) == BROKENREAD
){
if(n
<= 0 || c
== '\n')break;
if(nread(&c
,1) == BROKENREAD
){
if(s
[i
] < '0' || s
[i
] > '9'){
/* gather 24-hour stats and mail to STATADDR */
/* should also gather stats on # error msgs */
register struct dumpstruc
*p
= &dump
;
double cputime
,utime
,stime
,bs
,rawbs
;
/* if STATADDR is a file, the mail program this call will
ultimately execute must be able to deal with it,
and the remote mail program must be able to write on the
sprintf(froma
,"%s=>",longname(local
));
strcat(froma
,longname(remote
));
fdm
= mailopen(STATADDR
,froma
,1,0);
elapt
= currt
- dump
.longtime
;
ntot
= p
->nnetcp
+ p
->nnetmail
+ p
->nsmail
+ p
->nnetlpr
sstartt
= ctime(&dump
.longtime
) + 4;
sstartt
[strlen(sstartt
) - 9] = 0;
utime
= tbf
.tms_utime
+ tbf
.tms_cutime
;
stime
= tbf
.tms_stime
+ tbf
.tms_cstime
;
if(elapt
> 0)cputime
= (cputime
/elapt
) * 100.0;
if(p
->elaptot
> 0)bs
= bs
/p
->elaptot
;
/* print out the statistics */
fprintf(fdm
,"Subject: %s, %s, time %s\n",
froma
,sstartt
, comptime(elapt
));
fprintf(fdm
,"Command summary:\n");
fprintf(fdm
,"\t# sent %d\t# pass_thru %d\t# rcv %d:\t# netcp %d\n",
p
->nsend
,p
->npass
,ntot
,p
->nnetcp
);
fprintf(fdm
,"\t# netlpr %d\t# netmail %d\t# sendbmail %d\t# resp %d\n",
p
->nnetlpr
,p
->nnetmail
,p
->nsmail
,p
->nresp
);
fprintf(fdm
,"Protocol summary:\n");
fprintf(fdm
,"\t# pk_sent %d\t# pk_rcv %d\t# b_sent %ld\t# b_rcv %ld\n",
p
->npacksent
,p
->npackrcv
,p
->nbytesent
, p
->nbytercv
);
"\t# send_fails %d\t# retrans %d\t# abn %d\t\t# cksum_errs %d\n",
p
->nsendfail
,p
->nretrans
, p
->nabnormal
,p
->ncksum
);
fprintf(fdm
,"Load:\tuser %4.1f\tsys %4.1f\tpct %5.2f\trate %6.1f\n",
rawbs
= rawbs
/ linechars();
fprintf(fdm
,"\trawbytes %ld\tuse %4.1f\n", p
->brawtot
,rawbs
);
p
->nbytesent
= p
->nbytercv
= p
->elaptot
= p
->bytetot
= 0L;
p
->nretrans
= p
->nloop
= p
->nabnormal
= p
->ncksum
= 0;
p
->npacksent
= p
->npackrcv
= p
->nnetcp
= p
->nnetmail
= 0;
p
->nsmail
= p
->nnetlpr
= p
->nnet
= p
->npass
= 0;
p
->nsend
= p
->nsendfail
= 0;
/* returns 1 if n is ok, 0 if not */
if(strcmp(btable
[i
].bname
,n
) == 0 &&
local
== btable
[i
].bmach
)return(0);
makeuukey(skey,status.login,local);
strcpy(s,nbsdecrypt(s,skey,buf));
*s
&= 0177; /* strip quote bites */
*s
++ ^= 040; /* invert upper-lower */
mreopen(fsendtofmach
,phd
,sfn
,a
,b
,c
){
/* simply handles errors by giving error msg */
if(freopen(a
,b
,c
) == NULL
)
errormsg(fsendtofmach
,phd
,sfn
,"%s: %s",a
,sys_errlist
[errno
]);
add a message to the public logfile /usr/net/logfile.
note that the file must be writeable by everyone
if error messages from the netrcv subroutine
such as chdir errors are to be noticed.
addtopublic(s
,a
,b
,c
,d
,e
,f
,g
,h
,i
,j
,k
,l
,m
,n
)
if(stat(publogfile
,&statbuf
) < 0)return;
log
= fopen(publogfile
,"a");
fprintf(log
,s
,a
,b
,c
,d
,e
,f
,g
,h
,i
,j
,k
,l
,m
,n
);
/* set up a dummy environment for v7 /bin/sh */
static char *env
[3],benv
[2][50];
strcpy(env
[0],"PATH=:/bin:/usr/bin");
sprintf(env
[1],"HOME=%s",home
);
errormsg(fsendtofmach,phd,sfn,"string",arg(s))
Sends error message to user.
If fsendtofmach=TRUE, send to phd->hd_mchfrom, otherwise
Also, if error occured during return of a "response",
Note that errormsg can be called by the netrcv subroutine
after the setuid() call to the specific user, so the
user must be able to get off an error msg back to him,
and to write in the two log files.
Can't use -w,-x,-y,-z for the net cmd because must be root for those.
If sfn != NULL, then unlink sfn before exiting.
errormsg(fsendtofmach
,phd
,sfn
,s
,a
,b
,c
,d
,e
,f
,g
,h
)
char errstr
[BUFSIZ
], cmdstr
[BUFSIZ
], rcmd
[BUFSIZ
];
char toadd
[FNS
], fromadd
[FNS
], mchto
, mchfrom
;
char snto
[FNS
], snfrom
[FNS
];
if(phd
->hd_sttyname
[0] == 0)strcpy(phd
->hd_sttyname
,"/dev/ttyx");
/* will send to toadd, from fromadd */
if(!fsendtofmach
|| strcmp(phd
->hd_scmdvirt
,"response") == 0){
/* send to tomach mach, thus send to toaddr. */
/* if this is an error during a response, send to local mach. */
strcpy(toadd
, phd
->hd_addrto
);
strcpy(fromadd
,phd
->hd_addrfrom
);
else { /* send to remote mach, thus send back to addrfrom*/
strcpy(toadd
, phd
->hd_addrfrom
);
strcpy(fromadd
,phd
->hd_addrto
);
sprintf(errstr
,"Error: ");
sprintf(cmdstr
,s
,a
,b
,c
,d
,e
,f
,g
,h
);
mchto
= MchSFromAddr(snto
,toadd
);
mchfrom
= MchSFromAddr(snfrom
,fromadd
);
"%s %s %s %lo %c %s \"'%s'\" %ld -t %s -f %s -x %ld -y %s -c \"'%s'\" -e %ld",
MWRITECMD
, snto
, phd
->hd_sttyname
, phd
->hd_lttytime
,
local
, snfrom
,phd
->hd_scmdvirt
, phd
->hd_ltimesent
-TIMEBASE
,
toadd
, fromadd
, phd
->hd_lttytime
, phd
->hd_sttyname
, phd
->hd_scmdvirt
,
phd
->hd_ltimesent
-TIMEBASE
);
sprintf(cmdstr
, "echo \"%s\" | %s", errstr
,rcmd
);
"echo \"%s\" | %s -m%c -b -c errormessage -l network - %s",
errstr
,netcmd
,mchto
,rcmd
);
if(sfn
!= NULL
)unlink(sfn
);
handlekill(){ /* SIGTERM signal */
exit(EX_OK
); /* kill myself */
/* check a request to see if it is an acct pair */
/* returns 1 if it is, 0 if not */
static facctpaircheck(phd
)
register struct header
*phd
;