head 1.13; access; symbols; locks; strict; comment @ * @; 1.13 date 94.04.21.18.20.50; author jromine; state Exp; branches; next 1.12; 1.12 date 93.08.25.17.27.27; author jromine; state Exp; branches; next 1.11; 1.11 date 92.12.15.00.20.22; author jromine; state Exp; branches; next 1.10; 1.10 date 92.11.04.00.57.54; author jromine; state Exp; branches; next 1.9; 1.9 date 92.02.12.17.49.00; author jromine; state Exp; branches; next 1.8; 1.8 date 92.02.05.07.26.30; author jromine; state Exp; branches; next 1.7; 1.7 date 92.01.31.22.25.16; author jromine; state Exp; branches; next 1.6; 1.6 date 90.11.05.13.05.54; author mh; state Exp; branches; next 1.5; 1.5 date 90.04.05.15.02.11; author sources; state Exp; branches; next 1.4; 1.4 date 90.03.17.09.54.07; author sources; state Exp; branches; next 1.3; 1.3 date 90.03.12.14.21.19; author sources; state Exp; branches; next 1.2; 1.2 date 90.02.06.13.28.40; author sources; state Exp; branches; next 1.1; 1.1 date 90.02.06.13.28.27; author sources; state Exp; branches; next ; desc @@ 1.13 log @update for scansbr.c -- overload {folder}.c_flags with hdrflg @ text @/* rcvtty.c - a rcvmail program (a lot like rcvalert) handling IPC ttys */ #ifndef lint static char ident[] = "@@(#)$Id: rcvtty.c,v 1.12 1993/08/25 17:27:27 jromine Exp jromine $"; #endif /* lint */ #ifndef BSD42 #undef TTYD #endif #include "../h/mh.h" #include "../h/rcvmail.h" #include "../h/scansbr.h" #include "../zotnet/tws.h" #include #include #ifndef TTYD #include #endif /* not TTYD */ #ifdef LOCALE #include #endif /* */ #define SCANFMT \ "%2(hour{dtimenow}):%02(min{dtimenow}): %<(size)%5(size) %>%<{encrypted}E%>\ %<(mymbox{from})%<{to}To:%14(friendly{to})%>%>%<(zero)%17(friendly{from})%> \ %{subject}%<{body}<<%{body}>>%>" static struct swit switches[] = { #define HELPSW 0 "help", 4, #define BIFFSW 1 "biff", 0, #define FORMSW 2 "form formatfile", 0, #define FMTSW 3 "format string", 5, #define NLSW 4 "newline", 0, #define NNLSW 5 "nonewline", 0, #define BELSW 6 "bell", 0, #define NBELSW 7 "nobell", 0, NULL, 0 }; /* */ static jmp_buf myctx; off_t lseek (); char *getusr (); static int message_fd(), header_fd(); static alert(); static int bell = 1; static int newline = 1; static int biff = 0; static char *form = NULL; static char *format = NULL; /* */ /* ARGSUSED */ main (argc, argv) int argc; char **argv; { int md, vecp = 0; char *cp, *user, buf[100], **ap, **argp, *arguments[MAXARGS], *vec[MAXARGS]; #ifndef TTYD char tty[BUFSIZ]; struct utmp ut; register FILE *uf; #endif /* not TTYD */ #ifdef LOCALE setlocale(LC_ALL, ""); #endif invo_name = r1bindex (argv[0], '/'); mts_init (invo_name); if ((cp = m_find (invo_name)) != NULL) { ap = brkstring (cp = getcpy (cp), " ", "\n"); ap = copyip (ap, arguments); } else ap = arguments; (void) copyip (argv + 1, ap); argp = arguments; /* */ while (cp = *argp++) { if (*cp == '-') switch (smatch (++cp, switches)) { case AMBIGSW: ambigsw (cp, switches); done (1); case UNKWNSW: vec[vecp++] = --cp; continue; case HELPSW: (void) sprintf (buf, "%s [command ...]", invo_name); help (buf, switches); done (1); case BIFFSW: biff = 1; continue; case FORMSW: if (!(form = *argp++) || *form == '-') adios (NULLCP, "missing argument to %s", argp[-2]); format = NULL; continue; case FMTSW: if (!(format = *argp++) || *format == '-') adios (NULLCP, "missing argument to %s", argp[-2]); form = NULL; continue; case NLSW: newline = 1; continue; case NNLSW: newline = 0; continue; case BELSW: bell = 1; continue; case NBELSW: bell = 0; continue; } vec[vecp++] = cp; } vec[vecp] = 0; /* */ if ((md = vecp ? message_fd (vec) : header_fd ()) == NOTOK) exit (RCV_MBX); user = getusr (); #ifndef TTYD if ((uf = fopen ("/etc/utmp", "r")) == NULL) exit (RCV_MBX); while (fread ((char *) &ut, sizeof ut, 1, uf) == 1) if (ut.ut_name[0] != 0 && strncmp (user, ut.ut_name, sizeof ut.ut_name) == 0) { (void) strncpy (tty, ut.ut_line, sizeof ut.ut_line); alert (tty, md); } (void) fclose (uf); #else /* TTYD */ alert (user, md); #endif /* TTYD */ exit (RCV_MOK); } /* */ /* ARGSUSED */ static TYPESIG alrmser (i) int i; { longjmp (myctx, DONE); } static int message_fd (vec) char *vec[]; { int bytes, child_id, fd; char tmpfil[BUFSIZ]; struct stat st; (void) unlink (mktemp (strcpy (tmpfil, "/tmp/rcvttyXXXXX"))); if ((fd = creat (tmpfil, 0600)) == NOTOK) return header_fd (); (void) close (fd); if ((fd = open (tmpfil, 2)) == NOTOK) return header_fd (); (void) unlink (tmpfil); /* */ switch (child_id = vfork ()) { case NOTOK: (void) close (fd); return header_fd (); case OK: rewind (stdin); if (dup2 (fd, 1) == NOTOK || dup2 (fd, 2) == NOTOK) _exit (-1); closefds (3); #ifdef BSD42 (void) setpgrp (0, getpid ()); #endif /* BSD42 */ execvp (vec[0], vec); _exit (-1); default: switch (setjmp (myctx)) { case OK: (void) signal (SIGALRM, alrmser); bytes = fstat (fileno (stdin), &st) != NOTOK ? (int) st.st_size : 100; if (bytes <= 0) bytes = 100; (void) alarm ((unsigned) (bytes * 60 + 300)); (void) pidwait (child_id, OK); (void) alarm (0); if (fstat (fd, &st) != NOTOK && st.st_size > (off_t)0) return fd; (void) close (fd); return header_fd (); default: #ifndef BSD42 (void) kill (child_id, SIGKILL); #else /* BSD42 */ (void) killpg (child_id, SIGKILL); #endif /* BSD42 */ (void) close (fd); return header_fd (); } } } /* */ static int header_fd () { int fd; char tmpfil[BUFSIZ]; (void) strcpy (tmpfil, m_tmpfil (invo_name)); if ((fd = creat (tmpfil, 0600)) == NOTOK) return NOTOK; (void) close (fd); if ((fd = open (tmpfil, 2)) == NOTOK) return NOTOK; (void) unlink (tmpfil); rewind (stdin); (void) scan (stdin, 0, 0, new_fs (form, format, SCANFMT), 0, 0, 0, 0, 0, 0L, 0); if ( newline ) (void) write (fd, "\n\r", 2); (void) write (fd, scanl, strlen (scanl)); if ( bell ) (void) write (fd, "\007", 1); return fd; } /* */ #ifndef TTYD static alert (tty, md) char *tty; int md; { int i, td; char buffer[BUFSIZ], ttyspec[BUFSIZ]; struct stat st; (void) sprintf (ttyspec, "/dev/%s", tty); if (stat (ttyspec, &st) == NOTOK || (st.st_mode & (biff ? S_IEXEC : #ifdef BSD43 (S_IWRITE >> 3) #else /* BSD43 */ 02 #endif /* BSD43 */ )) == 0) return; switch (setjmp (myctx)) { case OK: (void) signal (SIGALRM, alrmser); (void) alarm (2); td = open (ttyspec, 1); (void) alarm (0); if (td == NOTOK) return; break; default: (void) alarm (0); return; } (void) lseek (md, (off_t)0, 0); while ((i = read (md, buffer, sizeof buffer)) > 0) if (write (td, buffer, i) != i) break; (void) close (td); } #else /* TTYD */ /* */ static alert (user, md) register char *user; int md; { int i, td; char buffer[BUFSIZ]; if ((td = ttyw ("notify", NULLCP, NULLCP, user)) == NOTOK) return; (void) signal (SIGPIPE, SIG_IGN); (void) lseek (md, (off_t), 0); while ((i = read (md, buffer, sizeof buffer)) > 0) if (write (td, buffer, i) != i) break; (void) close (td); } #endif /* TTYD */ @ 1.12 log @off_t fixes for BSD44 @ text @d3 1 a3 1 static char ident[] = "@@(#)$Id: rcvtty.c,v 1.11 1992/12/15 00:20:22 jromine Exp jromine $"; d270 2 a271 1 (void) scan (stdin, 0, 0, new_fs (form, format, SCANFMT), 0, 0, 0, 0, 0L, 0); @ 1.11 log @endif sugar @ text @d3 1 a3 1 static char ident[] = "@@(#)$Id: rcvtty.c,v 1.10 1992/11/04 00:57:54 jromine Exp jromine $"; d56 1 a56 1 long lseek (); d237 1 a237 1 if (fstat (fd, &st) != NOTOK && st.st_size > 0L) d319 1 a319 1 (void) lseek (md, 0L, 0); d343 1 a343 1 (void) lseek (md, 0L, 0); @ 1.10 log @LOCALE TYPESIG @ text @d3 2 a4 2 static char ident[] = "@@(#)$Id: rcvtty.c,v 1.9 1992/02/12 17:49:00 jromine Exp jromine $"; #endif lint d17 1 a17 1 #endif not TTYD d89 1 a89 1 #endif not TTYD d170 1 a170 1 #else TTYD d172 1 a172 1 #endif TTYD d220 1 a220 1 #endif BSD42 d245 1 a245 1 #else BSD42 d247 1 a247 1 #endif BSD42 d327 1 a327 1 #else TTYD d350 1 a350 1 #endif TTYD @ 1.9 log @fix from/to output @ text @d3 1 a3 1 static char ident[] = "@@(#)$Id: rcvtty.c,v 1.8 1992/02/05 07:26:30 jromine Exp jromine $"; d18 3 d91 3 d181 1 a181 1 static int alrmser (i) @ 1.8 log @put unseen sequence in mh-format @ text @d3 1 a3 1 static char ident[] = "@@(#)$Id: rcvtty.c,v 1.7 1992/01/31 22:25:16 jromine Exp jromine $"; d22 1 a22 1 %<(mymbox{from})To:%14(friendly{to})%|%17(friendly{from})%> \ @ 1.7 log @kerberos @ text @d3 1 a3 1 static char ident[] = "@@(#)$Id: rcvtty.c,v 1.6 1990/11/05 13:05:54 mh Exp jromine $"; d264 1 a264 1 (void) scan (stdin, 0, 0, new_fs (form, format, SCANFMT), 0, 0, 0, 0L, 0); @ 1.6 log @fix from author -- don't display size if zero @ text @d3 1 a3 1 static char ident[] = "@@(#)$Id: rcvtty.c,v 1.5 90/04/05 15:02:11 sources Exp Locker: mh $"; d46 1 a46 1 NULL, NULL d158 1 a158 1 if (ut.ut_name[0] != NULL @ 1.5 log @add ID @ text @d3 1 a3 1 static char ident[] = "@@(#)$Id:$"; d21 1 a21 1 "%2(hour{dtimenow}):%02(min{dtimenow}): %5(size) %<{encrypted}E%>\ @ 1.4 log @fixes from jeff honig add {dtimenow} to scansbr add a bunch of options to rcvtty @ text @d2 3 @ 1.3 log @check group write on tty under BSD43 @ text @d17 4 d26 17 d55 7 d111 29 d261 3 a263 1 (void) scan (stdin, 0, 0, NULLCP, 0, 0, 0, 0L, 0); d265 2 d285 8 a292 7 if (stat (ttyspec, &st) == NOTOK || #ifndef BSD43 (st.st_mode & 02) == 0 #else BSD43 (st.st_mode & (S_IWRITE >> 3)) == 0 /* group permissions */ #endif BSD43 ) @ 1.2 log @ANSI Compilance @ text @d224 7 a230 1 if (stat (ttyspec, &st) == NOTOK || (st.st_mode & 02) == 0) @ 1.1 log @Initial revision @ text @d32 2 @