home *** CD-ROM | disk | FTP | other *** search
- /* 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);
- }
-