1/* 2 * Copyright (c) 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Jef Poskanzer and Craig Leres of the Lawrence Berkeley Laboratory. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 31 unchanged lines hidden (view full) --- 40 The Regents of the University of California. All rights reserved.\n"; 41#endif /* not lint */ 42 43#ifndef lint 44#if 0 45static char sccsid[] = "@(#)write.c 8.1 (Berkeley) 6/6/93"; 46#endif 47static const char rcsid[] = |
48 "$Id: write.c,v 1.7 1997/08/26 11:23:37 charnier Exp $"; |
49#endif /* not lint */ 50 51#include <sys/param.h> 52#include <sys/signal.h> 53#include <sys/stat.h> 54#include <sys/file.h> 55#include <sys/time.h> 56#include <ctype.h> 57#include <err.h> |
58#include <locale.h> |
59#include <paths.h> 60#include <pwd.h> 61#include <stdio.h> 62#include <string.h> 63#include <unistd.h> 64#include <utmp.h> 65 |
66void done __P((int)); |
67void do_write __P((char *, char *, uid_t)); 68static void usage __P((void)); 69int term_chk __P((char *, int *, time_t *, int)); 70void wr_fputs __P((unsigned char *s)); 71void search_utmp __P((char *, char *, char *, uid_t)); 72int utmp_chk __P((char *, char *)); 73 74int 75main(argc, argv) 76 int argc; 77 char **argv; 78{ 79 register char *cp; 80 time_t atime; 81 uid_t myuid; 82 int msgsok, myttyfd; 83 char tty[MAXPATHLEN], *mytty; 84 |
85 (void)setlocale(LC_CTYPE, ""); 86 |
87 /* check that sender has write enabled */ 88 if (isatty(fileno(stdin))) 89 myttyfd = fileno(stdin); 90 else if (isatty(fileno(stdout))) 91 myttyfd = fileno(stdout); 92 else if (isatty(fileno(stderr))) 93 myttyfd = fileno(stderr); 94 else --- 24 unchanged lines hidden (view full) --- 119 exit(1); 120 if (myuid && !msgsok) 121 errx(1, "%s has messages disabled on %s", argv[1], argv[2]); 122 do_write(argv[2], mytty, myuid); 123 break; 124 default: 125 usage(); 126 } |
127 done(0); |
128 return (0); 129} 130 131static void 132usage() 133{ 134 (void)fprintf(stderr, "usage: write user [tty]\n"); 135 exit(1); --- 148 unchanged lines hidden (view full) --- 284 while (fgets(line, sizeof(line), stdin) != NULL) 285 wr_fputs(line); 286} 287 288/* 289 * done - cleanup and exit 290 */ 291void |
292done(n) 293int n; /* signal number */ |
294{ 295 (void)printf("EOF\r\n"); 296 exit(0); 297} 298 299/* 300 * wr_fputs - like fputs(), but makes control characters visible and 301 * turns \n into \r\n 302 */ 303void 304wr_fputs(s) 305 register unsigned char *s; 306{ 307 308#define PUTC(c) if (putchar(c) == EOF) err(1, NULL); 309 310 for (; *s != '\0'; ++s) { 311 if (*s == '\n') { 312 PUTC('\r'); |
313 } else if (*s <= 0xA0 || /* disable upper controls */ 314 (!isprint(*s) && !isspace(*s) && *s != '\007') 315 ) { |
316 if (*s & 0x80) { 317 *s &= ~0x80; 318 PUTC('M'); 319 PUTC('-'); 320 } 321 if (iscntrl(*s)) { 322 *s ^= 0x40; 323 PUTC('^'); 324 } 325 } 326 PUTC(*s); 327 } 328 return; 329#undef PUTC 330} |