summaryrefslogtreecommitdiff
path: root/usr/src/lib/libmail/common/notifyu.c
diff options
context:
space:
mode:
authorstevel@tonic-gate <none@none>2005-06-14 00:00:00 -0700
committerstevel@tonic-gate <none@none>2005-06-14 00:00:00 -0700
commit7c478bd95313f5f23a4c958a745db2134aa03244 (patch)
treec871e58545497667cbb4b0a4f2daf204743e1fe7 /usr/src/lib/libmail/common/notifyu.c
downloadillumos-joyent-7c478bd95313f5f23a4c958a745db2134aa03244.tar.gz
OpenSolaris Launch
Diffstat (limited to 'usr/src/lib/libmail/common/notifyu.c')
-rw-r--r--usr/src/lib/libmail/common/notifyu.c118
1 files changed, 118 insertions, 0 deletions
diff --git a/usr/src/lib/libmail/common/notifyu.c b/usr/src/lib/libmail/common/notifyu.c
new file mode 100644
index 0000000000..5158839ce3
--- /dev/null
+++ b/usr/src/lib/libmail/common/notifyu.c
@@ -0,0 +1,118 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+/*
+ * Copyright (c) 1998-1999 by Sun Microsystems, Inc.
+ * All rights reserved.
+ */
+#pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.4 */
+/*LINTLIBRARY*/
+
+#include "synonyms.h"
+#include "libmail.h"
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <utmpx.h>
+#include <syslog.h>
+#if !defined(__cplusplus) && !defined(c_plusplus)
+typedef void (*SIG_PF) (int);
+#endif
+#include <unistd.h>
+#include <signal.h>
+
+static SIG_PF catcher(void);
+
+static SIG_PF catcher(void)
+{
+ /* do nothing, but allow the write() to break */
+ return (0);
+}
+
+void
+notify(char *user, char *msg, int check_mesg_y, char *etcdir)
+{
+ /* search the utmp file for this user */
+ SIG_PF old;
+ unsigned int oldalarm;
+ struct utmpx utmpx, *putmpx = &utmpx;
+
+ setutxent();
+
+ /* grab the tty name */
+ while ((putmpx = getutxent()) != NULL) {
+ if (strncmp(user, utmpx.ut_name,
+ sizeof (utmpx.ut_name)) == 0) {
+ char tty[sizeof (utmpx.ut_line)+1];
+ char dev[MAXFILENAME];
+ FILE *port;
+ size_t i;
+ int fd;
+
+ for (i = 0; i < sizeof (utmpx.ut_line); i++)
+ tty[i] = utmpx.ut_line[i];
+ tty[i] = '\0';
+
+ /* stick /dev/ in front */
+ (void) sprintf(dev, "%s/dev/%s", etcdir, tty);
+
+ /* break out if write() to the tty hangs */
+ old = (SIG_PF)signal(SIGALRM, (SIG_PF)catcher);
+ oldalarm = alarm(300);
+
+ /* check if device is really a tty */
+ if ((fd = open(dev, O_WRONLY|O_NOCTTY)) == -1) {
+ (void) fprintf(stderr,
+ "Cannot open %s.\n", dev);
+ continue;
+ } else {
+ if (!isatty(fd)) {
+ (void) fprintf(stderr, "%s in utmpx is "
+ "not a tty\n", tty);
+ openlog("mail", 0, LOG_AUTH);
+ syslog(LOG_CRIT, "%s in utmp is "
+ "not a tty\n", tty);
+ closelog();
+ (void) close(fd);
+ continue;
+ }
+ }
+ (void) close(fd);
+
+ /* write to the tty */
+ port = fopen(dev, "w");
+ if (port != 0) {
+ (void) fprintf(port, "\r\n%s\r\n", msg);
+ (void) fclose(port);
+ }
+
+ /* clean up our alarm */
+ (void) alarm(0);
+ (void) signal(SIGALRM, old);
+ (void) alarm(oldalarm);
+ }
+ }
+ endutxent();
+}