4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
33 #include <sys/types.h>
54 * %a abbreviated weekday name
55 * %b abbreviated month name
57 * %H hour - 24 hour clock
63 extern char myhostname
[];
64 extern char progname
[];
67 static void openfail(int);
68 static void eof(void);
69 static void setsignals(void (*)());
71 static FILE *fp
; /* File pointer for receipient's terminal */
72 static char *rterm
; /* Pointer to receipient's terminal */
75 warn_send(char *receipient
, char *msg
)
77 register struct utmpx
*ubuf
;
78 static char rterminal
[] = "/dev/\0 2345678901";
83 char *rcp1
, *rcp2
, *rcp3
;
85 (void) setlocale(LC_ALL
, "");
86 #if !defined(TEXT_DOMAIN)
87 #define TEXT_DOMAIN "SYS_TEST"
89 (void) textdomain(TEXT_DOMAIN
);
92 /* Set "rterm" to location where receipient's terminal will go. */
94 rterm
= &rterminal
[sizeof ("/dev/") - 1];
97 * strip any realm or instance from principal so we can match against unix
100 rcp1
= strdup(receipient
);
101 rcp2
= strtok(rcp1
, "@");
102 rcp3
= strtok(rcp2
, "/");
105 * Scan through the "utmpx" file for the
106 * entry for the person we want to send to.
110 while ((ubuf
= getutxent()) != NULL
) {
111 if (ubuf
->ut_type
== USER_PROCESS
) {
112 if (strncmp(rcp3
, ubuf
->ut_user
,
113 sizeof (ubuf
->ut_user
)) == 0) {
114 strncpy(rterm
, &ubuf
->ut_line
[0],
115 sizeof (ubuf
->ut_line
)+1);
117 /* Try to open up the line to the receipient's terminal. */
119 signal(SIGALRM
, openfail
);
121 fp
= fopen(&rterminal
[0], "w");
124 /* Catch signals SIGHUP, SIGINT, SIGQUIT, and SIGTERM, and send */
125 /* <EOT> message to receipient. */
129 /* Get the time of day, convert it to a string and throw away the */
130 /* year information at the end of the string. */
133 cftime(time_buf
, "%c", &tod
);
134 (void) fprintf(fp
, gettext(
135 "\r\n\007\007\007\tMessage from %s@%s [ %s ] ...\r\n"),
136 progname
, myhostname
, time_buf
);
138 fprintf(fp
, gettext("\r\nMessage to %s"), msg
);
141 /* Since "end of file" received, send <EOT> message to receipient. */
151 /* Did we find a place to talk to? If we were looking for a */
152 /* specific spot and didn't find it, complain and log it. */
156 (void) syslog(LOG_ERR
, gettext("no place to send.\n"));
168 signal(SIGHUP
, catch);
169 signal(SIGINT
, catch);
170 signal(SIGQUIT
, catch);
171 signal(SIGTERM
, catch);
178 (void) fprintf(stderr
,
179 gettext("Timeout trying to open line(%s).\n"),
182 syslog(LOG_ERR
, gettext("Timeout trying to open line(%s).\n"),
192 (void) fprintf(fp
, "%s\r\n", gettext("<EOT>"));