1: #include "remind.h" 2: 3: trysend(rcvr,tty) /* Returns 0 if can't send */ 4: char *rcvr, *tty; 5: { register FILE *screen; 6: char ttnm[20]; 7: char scr_buf[BUFSIZ]; 8: 9: if(m.msgbytes == 0) 10: return(1); 11: strcpy(ttnm,ttname); 12: strcat(ttnm,tty); 13: 14: if ((screen = fopen(ttnm,"w")) == NULL) 15: return(0); 16: 17: setbuf(screen,scr_buf); 18: if ((m.bits&PRIORITY)==0) 19: { if (fstat(fileno(screen),&ttstat) == -1) 20: { 21: fclose(screen); 22: return(1); /* Treat no stat as delivered */ 23: } 24: if ((ttstat.st_mode&02) == 0) 25: { 26: fclose(screen); 27: return(0); /* No write permission */ 28: } 29: } 30: 31: fprintf(screen,"%c",7); 32: send(screen,rcvr); /* Closes screen */ 33: fprintf(screen,"%c",7); 34: fclose(screen); 35: return(1); 36: } 37: 38: sendmail(rcvr) 39: char *rcvr; 40: { register int f, tries; 41: char ch, rec[9]; 42: int fd[2], fdin[2]; 43: FILE *pip; 44: 45: for (f = 0; (rec[f] = rcvr[f]) && ++f < 8; ) ; 46: rec[f] = '\0'; /* Terminator for 8 char receiver name */ 47: tries = 5; 48: do 49: { pipe(fd); 50: pipe(fdin); 51: if (spawn()) 52: { close (fd[0]); 53: close (fdin[1]); 54: if((pip=fdopen(fd[1],"w"))==NULL) 55: error("bad pipe\n"); 56: send(pip,rcvr); 57: fclose(pip); 58: f = read(fdin[0], &ch, 1); 59: close (fdin[0]); 60: } 61: else 62: { close (fd[1]); 63: close (fdin[0]); 64: if (fd[0]) 65: { close(0); 66: dup(fd[0]); 67: close(fd[0]); 68: } 69: if (fdin[1] != 1) 70: { close(1); 71: dup(fdin[1]); 72: close(fdin[1]); 73: } 74: if(Uid != -1) 75: setuid(Uid); 76: execl("/bin/mail","remindmail",rec,0); 77: exit(1); 78: } 79: } while (f && tries--); 80: return; 81: } 82: 83: send(fp,rcvr) 84: FILE *fp; 85: char *rcvr; 86: { register char *p; 87: register int i, t; 88: struct sgttyb tt; 89: int fd = fileno(fp); 90: char *t_name; 91: char *ttyname(); 92: 93: if ((t_name=ttyname(fd)) != NULL) 94: { 95: ioctl(fd,TIOCGETP,&tt); 96: if(((t=tt.sg_flags) & CRMOD) == 0) 97: { 98: tt.sg_flags = t | CRMOD; 99: ioctl(fd,TIOCSETP,&tt); 100: } 101: } 102: fprintf (fp,"\n*** REMINDER - "); 103: fprintf (fp," From %.8s to %.8s\n", m.sender, rcvr); 104: if (m.nrcvrs > 1) 105: { fprintf (fp," List: "); 106: for (i = 0; i < m.nrcvrs; ) 107: { if (i%4 == 0 && i) 108: fprintf (fp,"\n "); 109: fprintf (fp,"%-9.8s ", rcvrlist[i++]); 110: } 111: fputc('\n',fp); 112: } 113: fprintf (fp," Sent ........... %.24s\n", ctime(&m.tsent)); 114: fprintf (fp," For delivery ... %.24s\n", ctime(&m.tdeliver)); 115: if (m.dirsize) 116: fprintf(fp," The following was started as requested...\n\n"); 117: p = msg; 118: for (i = m.msgbytes; i--; ) 119: fputc(*p++,fp); 120: fprintf (fp,"\n*** END\n"); 121: fflush(fp); 122: if (t_name && t != tt.sg_flags) 123: { 124: tt.sg_flags = t; 125: ioctl(fd,TIOCSETP,&tt); 126: } 127: return(1); 128: }