SCCS-vsn: usr.bin/write/write.c 4.17
#endif /* not lint */
#ifndef lint
#endif /* not lint */
#ifndef lint
-static char sccsid[] = "@(#)write.c 4.16 (Berkeley) %G%";
+static char sccsid[] = "@(#)write.c 4.17 (Berkeley) %G%";
#endif /* not lint */
#include <sys/param.h>
#endif /* not lint */
#include <sys/param.h>
#include <stdio.h>
#include <strings.h>
#include <stdio.h>
#include <strings.h>
-#define STRCPY(s1, s2) \
- { (void)strncpy(s1, s2, sizeof(s1)); s1[sizeof(s1) - 1] = '\0'; }
-
-int uid; /* myuid */
main(argc, argv)
int argc;
char **argv;
{
main(argc, argv)
int argc;
char **argv;
{
- char tty[MAXPATHLEN];
- int msgsok, myttyfd;
- char *mytty, *getlogin(), *ttyname();
+ uid_t myuid;
+ int msgsok, myttyfd;
+ char tty[MAXPATHLEN], *mytty, *getlogin(), *ttyname();
- /* check that sender has write enabled. */
+ /* check that sender has write enabled */
if (isatty(fileno(stdin)))
myttyfd = fileno(stdin);
else if (isatty(fileno(stdout)))
if (isatty(fileno(stdin)))
myttyfd = fileno(stdin);
else if (isatty(fileno(stdout)))
/* check args */
switch (argc) {
case 2:
/* check args */
switch (argc) {
case 2:
- search_utmp(argv[1], tty, mytty);
- do_write(tty, mytty);
+ search_utmp(argv[1], tty, mytty, myuid);
+ do_write(tty, mytty, myuid);
break;
case 3:
if (!strncmp(argv[2], "/dev/", 5))
break;
case 3:
if (!strncmp(argv[2], "/dev/", 5))
}
if (term_chk(argv[2], &msgsok, &atime, 1))
exit(1);
}
if (term_chk(argv[2], &msgsok, &atime, 1))
exit(1);
+ if (myuid && !msgsok) {
(void)fprintf(stderr,
"write: %s has messages disabled on %s\n",
argv[1], argv[2]);
exit(1);
}
(void)fprintf(stderr,
"write: %s has messages disabled on %s\n",
argv[1], argv[2]);
exit(1);
}
- do_write(argv[2], mytty);
+ do_write(argv[2], mytty, myuid);
break;
default:
(void)fprintf(stderr, "usage: write user [tty]\n");
break;
default:
(void)fprintf(stderr, "usage: write user [tty]\n");
* Special case for writing to yourself - ignore the terminal you're
* writing from, unless that's the only terminal with messages enabled.
*/
* Special case for writing to yourself - ignore the terminal you're
* writing from, unless that's the only terminal with messages enabled.
*/
-search_utmp(user, tty, mytty)
+search_utmp(user, tty, mytty, myuid)
char *user, *tty, *mytty;
char *user, *tty, *mytty;
{
struct utmp u;
time_t bestatime, atime;
{
struct utmp u;
time_t bestatime, atime;
while (read(ufd, (char *) &u, sizeof(u)) == sizeof(u))
if (strncmp(user, u.ut_name, sizeof(u.ut_name)) == 0) {
++nloggedttys;
while (read(ufd, (char *) &u, sizeof(u)) == sizeof(u))
if (strncmp(user, u.ut_name, sizeof(u.ut_name)) == 0) {
++nloggedttys;
- STRCPY(atty, u.ut_line);
+ (void)strncpy(atty, u.ut_line, UT_LINESIZE);
+ atty[UT_LINESIZE] = '\0';
if (term_chk(atty, &msgsok, &atime, 0))
continue; /* bad term? skip */
if (term_chk(atty, &msgsok, &atime, 0))
continue; /* bad term? skip */
continue; /* skip ttys with msgs off */
if (strcmp(atty, mytty) == 0) {
user_is_me = 1;
continue; /* skip ttys with msgs off */
if (strcmp(atty, mytty) == 0) {
user_is_me = 1;
(void)sprintf(path, "/dev/%s", tty);
if (stat(path, &s) < 0) {
if (showerror)
(void)sprintf(path, "/dev/%s", tty);
if (stat(path, &s) < 0) {
if (showerror)
- (void)fprintf(stderr, "write: %s: %s\n",
- path, strerror(errno));
+ (void)fprintf(stderr,
+ "write: %s: %s\n", path, strerror(errno));
return(1);
}
*msgsokP = (s.st_mode & (S_IWRITE >> 3)) != 0; /* group write bit */
return(1);
}
*msgsokP = (s.st_mode & (S_IWRITE >> 3)) != 0; /* group write bit */
/*
* do_write - actually make the connection
*/
/*
* do_write - actually make the connection
*/
+do_write(tty, mytty, myuid)
{
register char *login, *nows;
register struct passwd *pwd;
{
register char *login, *nows;
register struct passwd *pwd;
(void)signal(SIGINT, done);
(void)signal(SIGINT, done);
+ (void)signal(SIGHUP, done);
if ((login = getlogin()) == NULL)
if ((login = getlogin()) == NULL)
- if (pwd = getpwuid(getuid()))
+ if (pwd = getpwuid(myuid))
login = pwd->pw_name;
else
login = "???";
login = pwd->pw_name;
else
login = "???";
nows = ctime(&now);
nows[16] = '\0';
(void)printf("\r\n\007\007\007Message from %s@%s on %s at %s ...\r\n",
nows = ctime(&now);
nows[16] = '\0';
(void)printf("\r\n\007\007\007Message from %s@%s on %s at %s ...\r\n",
- login, host, mytty, nows + 11);
+ login, host, mytty, nows + 11);
while (fgets(line, sizeof(line), stdin) != NULL)
while (fgets(line, sizeof(line), stdin) != NULL)
- * massage_fputs - like fputs(), but makes control characters visible and
+ * wr_fputs - like fputs(), but makes control characters visible and
register char *s;
{
register char c;
register char *s;
{
register char c;