nwrite-1.9.2/ 40755 21733 144 0 6551226424 11257 5ustar alanccsuanwrite-1.9.2/Makefile.in100644 21733 144 4544 6551226376 13436 0ustar alanccsua# -*-Makefile-*- for nwrite 1.9.2 # # Copyright 1993 by Marco Nicosia # Copyright 1994-95 by Aaron Smith # Copyright 1995-98 by Alan Coopersmith # All rights reserved. (see README for license details) # # The makefile should be generated automatically with the correct # options by the configure script - see the INSTALL file for details ################## Configuration Section################## # Choose your compiler and other options # Options: # -DCLEAR_PROCS - allow users to clear the list of names they # are writing to from the ps output (if your # OS supports it - many don't) CC = @CC@ CFLAGS = @DEFS@ @CFLAGS@ -DSYSTEM_NWRITERC=\"${SYSTEM_NWRITERC}\" LDFLAGS = @LDFLAGS@ LIBS = @LIBS@ # Install program - choose one with BSD semantics (GNU is okay too, but # SysV install won't work) INSTALL = @INSTALL@ INSTALLFLAGS = @INSTALLFLAGS@ # Use this line if your ttys are world writable #INSTALLFLAGS=-m 755 # Use this line if your ttys are only writable by group tty #INSTALLFLAGS=-g tty -m 2755 # Where do you want the files installed? prefix = @prefix@ exec_prefix = @exec_prefix@ BIN = @bindir@ MAN = @mandir@ CONF = @sysconfdir@ # Some systems like to gzip man pages, if yours is one, set MANGZ=-gz MANGZ = @MANGZ@ ################## End of configuration ################## # You shouldn't need to change anything after this point # SYSTEM_NWRITERC=${CONF}/nwrite.rc OBJECTS=nwrite.o all: Makefile nwrite nwrite: $(OBJECTS) $(CC) $(CFLAGS) -o nwrite $(OBJECTS) $(LDFLAGS) install: Makefile installbin installman$(MANGZ) installrc installbin: nwrite -mv $(BIN)/nwrite $(BIN)/nwrite.old $(INSTALL) -c $(INSTALLFLAGS) nwrite $(BIN)/nwrite strip $(BIN)/nwrite installman: nwrite.1 -\rm $(MAN)/cat1/nwrite.1 $(INSTALL) -c -m 644 nwrite.1 $(MAN)/cat1/nwrite.1 installman-gz: installman -\rm $(MAN)/cat1/nwrite.1.gz gzip $(MAN)/cat1/nwrite.1 installrc: nwrite.rc $(INSTALL) -c -m 644 nwrite.rc $(SYSTEM_NWRITERC) Makefile: Makefile.in sh ./config.status config.h: config.h.in sh ./config.status config.h.in: configure.in acconfig.h autoheader nwrite.1: nwrite.1.in -\rm nwrite.1 sed -e "s%SYSTEM_NWRITERC%$(SYSTEM_NWRITERC)%" nwrite.1.in > nwrite.1 clean: -\rm nwrite $(OBJECTS) distclean: clean -\rm Makefile config.cache config.status config.log config.h nwrite.1 nwrite-1.9.2/nwrite.c100644 21733 144 66223 6551223523 13056 0ustar alanccsua/* * nwrite: write replacement. * * Version 1.9.2 - February 9, 1998 * **************************************************************************** * The nwrite software package and all files contained therein are covered * by this copyright notice & license: * * Copyright (c) 1993 Marco Nicosia * Copyright (c) 1994-1995 Aaron C. Smith * Copyright (c) 1995-1998 Alan Coopersmith * * Permission to use, copy, modify, and distribute this software in source * and/or binary forms and its documentation, without fee and without a * signed licensing agreement, is hereby granted, provided that the * following conditions are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The names of the authors may not be used to endorse or promote * products derived from this software without specific prior written * permission. * * IN NO EVENT SHALL THE AUTHORS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, * SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE * AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * THE AUTHORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, * PROVIDED HEREUNDER IS PROVIDED "AS IS". THE AUTHORS HAVE NO OBLIGATION TO * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. * **************************************************************************** * */ #ifndef lint const char sccsid[] = "@(#)nwrite.c $Revision: 1.9.1 $ $Date: 97/11/15 18:40:38 $ Marco Nicosia, Aaron Smith, Alan Coopersmith"; const char rcsid[] = "$Id$"; #endif #ifdef HAVE_CONFIG_H # include "config.h" #endif #include #ifdef HAVE_SYS_FILE_H # include #endif #include #if TIME_WITH_SYS_TIME # include # include #else # if HAVE_SYS_TIME_H # include # else # include # endif #endif #include #include #include #include #include #include #ifdef HAVE_UNISTD_H # include #endif #ifdef HAVE_FCNTL_H # include #endif #ifdef HAVE_LIMITS_H # include #endif #if STDC_HEADERS # include #else # ifndef HAVE_STRCHR # define strchr index # define strrchr rindex # endif #endif #ifndef TTYS_WORLD_WRITABLE # define TTYS_WORLD_WRITABLE TRUE #endif #ifdef HAVE_PATHS_H # include #endif #ifndef TTY_DIR # ifdef _PATH_DEV # define TTY_DIR _PATH_DEV # else # define TTY_DIR "/dev/" # endif #endif #ifndef TTY_PREFIX # ifdef PTS_STYLE_TTYS # define TTY_PREFIX "pts/" # else # define TTY_PREFIX "tty" # endif #endif #ifndef TTYNAMESZ # define TTYNAMESZ 24 #endif #ifndef UT_NAMESIZE # define UT_NAMESIZE sizeof(utmp_entry.ut_name) #endif #ifndef UT_LINESIZE # define UT_LINESIZE sizeof(utmp_entry.ut_line) #endif #ifndef UTMP_FILE # ifdef _PATH_UTMP /* newer BSD's */ # define UTMP_FILE _PATH_UTMP # else # define UTMP_FILE "/etc/utmp" # endif #endif #ifndef PATH_MAX /* should be in on POSIX platforms */ # define PATH_MAX 1024 #endif #ifndef HAVE_STRDUP # define strdup mystrdup static char *mystrdup(const char *); #endif #ifndef SIG_ERR # define SIG_ERR BADSIG #endif #ifndef TRUE # define FALSE 0 # define TRUE (!FALSE) #endif /* errno should be defined by including on ANSI-C platforms */ #ifdef NEED_ERRNO_DECL extern int errno; #endif /**** End of portability sections ****/ extern char *optarg; extern int optind, opterr; #define BOLD_START "\033[1m" /* vt100-series specific */ #define BOLD_END "\033[m" /* unfortunately */ const char bold_start[] = BOLD_START; const char bold_end[] = BOLD_END; #define BUFSIZE 1024 #define RC_FILENAME "/.nwriterc" /* for showtarg directive */ enum { TARG_NEVER = 0, TARG_MULTIPLE, TARG_ALWAYS }; enum { BOLD_NEVER = 0, BOLD_HEADER, BOLD_TAG, BOLD_ALL }; typedef struct pref_t { int nodelay; int beep; int bold; int headers; int whoeof; int showtarg; char preftty[TTYNAMESZ]; char *line_header; } pref_t; typedef struct tty_info_t { char name [TTYNAMESZ]; /* name of this tty */ FILE *file; /* file descriptor open & writing to it */ int found; int specified; /* was it specifically asked for by name? */ struct tty_info_t *next; } tty_info_t; typedef struct local_user_t { char *name; tty_info_t *ttys; pref_t pref; int header_sent; int ttys_requested, ttys_found; } local_user_t; typedef struct user_t { struct user_t *next; enum { LOCAL, REMOTE } type; union { local_user_t *local; } info; } user_t; /* prototypes */ char * make_idle(int); RETSIGTYPE sigint_handler(); void get_prefs(local_user_t *, char *); void read_prefs(char *, pref_t *); void send_header(user_t *); /* globals */ FILE *utmpd; /* user_t my; */ char *myname; char mytty[TTYNAMESZ]; char *myrcname; user_t *user_list = NULL; int local_req_count = 0; int local_req_found = 0; struct utmp utmp_entry; struct stat stat_buf; struct passwd pwd_stack; struct passwd *pwd = &pwd_stack; time_t now; int debugmode = 0; struct pref_t default_pref = { /* nodelay */ FALSE, /* beep */ TRUE, /* bold */ BOLD_NEVER, /* headers */ TRUE, /* whoeof */ FALSE, /* showtarg */ TARG_MULTIPLE, /* preftty */ "", /* line_header */ NULL }; tty_info_t *new_tty_info_t (void) { tty_info_t *new_tit; new_tit = calloc(1, sizeof(tty_info_t)); if (new_tit == NULL) { perror("nwrite: fatal memory allocation error"); exit(errno); } return (new_tit); } void init_globals() { char buf[BUFSIZE]; int myttyfd; /* file descriptor of input tty */ char * myttyname; #ifdef sequent extern char *ttyname(); #endif time(&now); /* store the current time in now */ pwd = getpwuid(getuid()); if (pwd == NULL) { fprintf(stderr, "nwrite: couldn't determine your login name.\n"); exit(1); } myname = strdup(pwd->pw_name); /* determine controlling terminal */ if (isatty(fileno(stdin))) myttyfd = fileno(stdin); else if (isatty(fileno(stdout))) myttyfd = fileno(stdout); else if (isatty(fileno(stderr))) myttyfd = fileno(stderr); else { fprintf(stderr, "nwrite: could not find your tty.\n"); exit(2); } if (fstat(myttyfd, &stat_buf) == -1) { fprintf(stderr, "nwrite: could not stat your tty.\n"); exit(2); } #if TTYS_WORLD_WRITABLE if (!(stat_buf.st_mode & (S_IWRITE >> 6))) fprintf(stderr, "nwrite: your tty is not%s writable.\n", debugmode ? " world" : ""); #else if (!(stat_buf.st_mode & (S_IWRITE >> 3))) fprintf(stderr, "nwrite: your tty is not%s writable.\n", debugmode ? " group" : ""); #endif myttyname = ttyname(myttyfd); if (myttyname == NULL) { fprintf(stderr, "nwrite: could not determine your tty.\n"); exit(3); } else strncpy(buf, myttyname, TTYNAMESZ); myttyname = strchr(buf + 1, '/'); if (myttyname != NULL) { strcpy(mytty, myttyname + 1); } else strcpy(mytty, buf); #ifdef SYSTEM_NWRITERC read_prefs(SYSTEM_NWRITERC, &default_pref); #endif } void get_prefs(local_user_t *usr, char *target) { char prefsFileName[PATH_MAX]; /* defaults */ usr->pref = default_pref; if (target == NULL) return; snprintf(prefsFileName, sizeof(prefsFileName), "%s%s", target, RC_FILENAME); read_prefs(prefsFileName, &(usr->pref)); } /* parse pref file */ void read_prefs(char *prefsFileName, pref_t *prefTarget) { char buf[BUFSIZE]; char option[BUFSIZE]; char pref_str[BUFSIZE]; char scratch_buf[BUFSIZE]; int value; FILE *prefs = NULL; *scratch_buf = '\0'; if (debugmode) fprintf(stderr, "Opening %s...", prefsFileName); prefs = fopen(prefsFileName, "r"); if (prefs == NULL) { if (debugmode) perror(prefsFileName); return; } if (debugmode) printf("succeeded\n"); while (fgets(buf, BUFSIZE, prefs) != NULL) { sscanf(buf, "%s%s", option, pref_str); if (debugmode) printf("option: '%s'\tpref_str: '%s'\n", option, pref_str); value = atoi(pref_str); if (strncmp(option, "beep", sizeof("beep") - 1) == 0) prefTarget->beep = value; else if (strncmp(option, "nodelay", sizeof("nodelay") -1 ) == 0) prefTarget->nodelay = value; else if (strncmp(option, "boldhdr", sizeof("boldhdr") - 1) == 0) prefTarget->bold = BOLD_TAG; else if (strncmp(option, "bold", sizeof("bold") - 1) == 0) { strcpy(scratch_buf, pref_str); if (strncmp(scratch_buf, "never", sizeof("never") - 1) == 0) prefTarget->bold = BOLD_NEVER; else if (strncmp(scratch_buf, "header", sizeof("header") - 1) == 0) prefTarget->bold = BOLD_HEADER; else if (strncmp(scratch_buf, "tag", sizeof("tag") - 1) == 0) prefTarget->bold = BOLD_TAG; else if (strncmp(scratch_buf, "all", sizeof("all") - 1) == 0) prefTarget->bold = BOLD_ALL; else if (strlen(scratch_buf) == 1) /* backwards compat */ prefTarget->bold = atoi(scratch_buf); } else if (strncmp(option, "headers", sizeof("headers") - 1) == 0) prefTarget->headers = value; else if (strncmp(option, "whoeof", sizeof("whoeof") - 1) == 0) prefTarget->whoeof = value; else if (strncmp(option, "showtarg", sizeof("showtarg") - 1) == 0) { strcpy(scratch_buf, pref_str); if (strncmp(scratch_buf, "never", sizeof("never") - 1) == 0) prefTarget->showtarg = TARG_NEVER; else if (strncmp(scratch_buf, "multi", sizeof("multi") - 1) == 0) prefTarget->showtarg = TARG_MULTIPLE; else if (strncmp(scratch_buf, "always", sizeof("always") - 1) == 0) prefTarget->showtarg = TARG_ALWAYS; } else if (strncmp(option, "preftty", sizeof("preftty") - 1) == 0) strcpy(prefTarget->preftty, pref_str); } if (debugmode) { printf("Options are:\n" "Nodelay: %d\n" "Beep: %d\n" "Bold: %d\n" "Headers: %d\n" "WhoEOF: %d\n" "ShowTarg: %d\n" "PrefTTY: %s\n", prefTarget->nodelay, prefTarget->beep, prefTarget->bold, prefTarget->headers, prefTarget->whoeof, prefTarget->showtarg, prefTarget->preftty); } } int main(int argc, char *argv[]) { char buf[BUFSIZE]; char *bufptr = buf; int IFLAG = FALSE; /* perform idle checking? */ #ifdef CLEAR_PROCS int AFLAG = FALSE; #endif time_t idle_limit = 0; char *idle_string = NULL; tty_info_t *the_tty; user_t *usr; user_t *prev; /* install signal handlers */ if (signal(SIGINT, sigint_handler) == SIG_ERR) { fprintf(stderr, "nwrite: Error installing SIGINT handler.\n"); } if (signal(SIGHUP, sigint_handler) == SIG_ERR) { fprintf(stderr, "nwrite: Error installing SIGHUP handler.\n"); } if (argc < 2) { usage: fprintf(stderr, "Usage: nwrite [flags] user[.tty] [user[.tty] ...]\n" #ifdef CLEAR_PROCS "\t-a