home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Source Code 1992 March
/
Source_Code_CD-ROM_Walnut_Creek_March_1992.iso
/
usenet
/
altsrcs
/
1
/
1580
/
anon-reply.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-12-28
|
1KB
|
46 lines
/* anon-reply.c - put replies to be sent in ACS spool directory */
#include <stdio.h>
#include <sys/file.h>
#include <errno.h>
main(argc,argv)
int argc;
char *argv[];
{
char buf[512];
char fname[40];
char pbuf[6];
int mypid, fd, rdlen;
if ( argc != 2 ) {
exit(1);
}
/* run as root */
if (setuid(0) != 0 ) {
perror("couldn\'t setuid root: ");
exit(1);
}
/* build the filename */
strcpy(fname,"/usr/personals/spool/REP");
sprintf(pbuf,"%05d",getpid());
strcat(fname,pbuf);
while (access(fname,F_OK) == 0) {
strcat(fname,".");
if (strlen(fname) == 39 ) break;
}
if ((fd = open(fname,O_WRONLY|O_CREAT,0600)) == -1) {
perror("can\'t open REP tmp file: ");
exit(1);
}
/* write the alias in as the first line in the file */
write(fd,argv[1],strlen(argv[1]));
write(fd,"\012",1);
/* read the message on stdin and write it to fd */
while ( rdlen = read(0,buf,512) ) {
if (write(fd,buf,rdlen) != rdlen) {
perror("write to REP tmp file failed: ");
exit(1);
}
}
close(fd);
exit(0);
}