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-ping.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-12-28
|
880b
|
38 lines
/* anon-ping.c - put ping messages in ACS spool directory */
#include <stdio.h>
#include <sys/file.h>
#include <errno.h>
main()
{
char buf[512];
char fname[40];
char pbuf[6];
int mypid, fd, rdlen;
/* run as root */
if (setuid(0) != 0 ) {
perror("couldn\'t setuid root: ");
exit(1);
}
/* build the filename */
strcpy(fname,"/usr/personals/spool/PING");
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 PING tmp file: ");
exit(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 PING tmp file failed: ");
exit(1);
}
}
close(fd);
exit(0);
}