summaryrefslogtreecommitdiffstats
path: root/libexec/comsat/comsat.c
diff options
context:
space:
mode:
Diffstat (limited to 'libexec/comsat/comsat.c')
-rw-r--r--libexec/comsat/comsat.c67
1 files changed, 48 insertions, 19 deletions
diff --git a/libexec/comsat/comsat.c b/libexec/comsat/comsat.c
index e2e4477..c3b876a 100644
--- a/libexec/comsat/comsat.c
+++ b/libexec/comsat/comsat.c
@@ -29,6 +29,8 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
+ *
+ * $Id$
*/
#ifndef lint
@@ -54,7 +56,7 @@ static char sccsid[] = "@(#)comsat.c 8.1 (Berkeley) 6/4/93";
#include <netdb.h>
#include <paths.h>
#include <pwd.h>
-#include <sgtty.h>
+#include <termios.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
@@ -73,9 +75,9 @@ struct utmp *utmp = NULL;
time_t lastmsgtime;
int nutmp, uf;
-void jkfprintf __P((FILE *, char[], off_t));
+void jkfprintf __P((FILE *, char[], char[], off_t));
void mailfor __P((char *));
-void notify __P((struct utmp *, off_t));
+void notify __P((struct utmp *, char[], off_t, int));
void onalrm __P((int));
void reapchildren __P((int));
@@ -87,7 +89,7 @@ main(argc, argv)
struct sockaddr_in from;
register int cc;
int fromlen;
- char msgbuf[100];
+ char msgbuf[256];
/* verify proper invocation */
fromlen = sizeof(from);
@@ -170,27 +172,43 @@ mailfor(name)
{
register struct utmp *utp = &utmp[nutmp];
register char *cp;
+ char *file;
off_t offset;
+ int folder;
+ char buf[sizeof(_PATH_MAILDIR) + sizeof(utmp[0].ut_name) + 1];
+ char buf2[sizeof(_PATH_MAILDIR) + sizeof(utmp[0].ut_name) + 1];
if (!(cp = strchr(name, '@')))
return;
*cp = '\0';
offset = atoi(cp + 1);
+ if (!(cp = strchr(cp + 1, ':')))
+ file = name;
+ else
+ file = cp + 1;
+ sprintf(buf, "%s/%.*s", _PATH_MAILDIR, sizeof(utmp[0].ut_name), name);
+ if (*file != '/') {
+ sprintf(buf2, "%s/%.*s", _PATH_MAILDIR, sizeof(utmp[0].ut_name), file);
+ file = buf2;
+ }
+ folder = strcmp(buf, file);
while (--utp >= utmp)
if (!strncmp(utp->ut_name, name, sizeof(utmp[0].ut_name)))
- notify(utp, offset);
+ notify(utp, file, offset, folder);
}
static char *cr;
void
-notify(utp, offset)
+notify(utp, file, offset, folder)
register struct utmp *utp;
+ char file[];
off_t offset;
+ int folder;
{
FILE *tp;
struct stat stb;
- struct sgttyb gttybuf;
+ struct termios tio;
char tty[20], name[sizeof(utmp[0].ut_name) + 1];
(void)snprintf(tty, sizeof(tty), "%s%.*s",
@@ -213,22 +231,24 @@ notify(utp, offset)
dsyslog(LOG_ERR, "%s: %s", tty, strerror(errno));
_exit(-1);
}
- (void)ioctl(fileno(tp), TIOCGETP, &gttybuf);
- cr = (gttybuf.sg_flags&CRMOD) && !(gttybuf.sg_flags&RAW) ?
- "\n" : "\n\r";
+ (void)tcgetattr(fileno(tp), &tio);
+ cr = ((tio.c_oflag & (OPOST|ONLCR)) == (OPOST|ONLCR)) ? "\n" : "\n\r";
(void)strncpy(name, utp->ut_name, sizeof(utp->ut_name));
name[sizeof(name) - 1] = '\0';
- (void)fprintf(tp, "%s\007New mail for %s@%.*s\007 has arrived:%s----%s",
- cr, name, (int)sizeof(hostname), hostname, cr, cr);
- jkfprintf(tp, name, offset);
+ (void)fprintf(tp, "%s\007New mail for %s@%.*s\007 has arrived%s%s%s:%s----%s",
+ cr, name, (int)sizeof(hostname), hostname,
+ folder ? cr : "", folder ? "to " : "", folder ? file : "",
+ cr, cr);
+ jkfprintf(tp, name, file, offset);
(void)fclose(tp);
_exit(0);
}
void
-jkfprintf(tp, name, offset)
+jkfprintf(tp, user, file, offset)
register FILE *tp;
- char name[];
+ char user[];
+ char file[];
off_t offset;
{
register char *cp, ch;
@@ -238,10 +258,10 @@ jkfprintf(tp, name, offset)
char line[BUFSIZ];
/* Set effective uid to user in case mail drop is on nfs */
- if ((p = getpwnam(name)) != NULL)
+ if ((p = getpwnam(user)) != NULL)
(void) setuid(p->pw_uid);
- if ((fi = fopen(name, "r")) == NULL)
+ if ((fi = fopen(file, "r")) == NULL)
return;
(void)fseek(fi, offset, L_SET);
@@ -271,9 +291,18 @@ jkfprintf(tp, name, offset)
}
/* strip weird stuff so can't trojan horse stupid terminals */
for (cp = line; (ch = *cp) && ch != '\n'; ++cp, --charcnt) {
- ch = toascii(ch);
- if (!isprint(ch) && !isspace(ch))
+ if (!isprint(ch)) {
+ if (ch & 0x80)
+ (void)fputs("M-", tp);
+ ch &= 0177;
+ if (!isprint(ch)) {
+ if (ch == 0177)
+ ch = '?';
+ else
ch |= 0x40;
+ (void)fputc('^', tp);
+ }
+ }
(void)fputc(ch, tp);
}
(void)fputs(cr, tp);
OpenPOWER on IntegriCloud